xref: /freebsd/crypto/openssl/doc/man3/UI_create_method.pod (revision e71b70530d95c4f34d8bdbd78d1242df1ba4a945)
1*e71b7053SJung-uk Kim=pod
2*e71b7053SJung-uk Kim
3*e71b7053SJung-uk Kim=head1 NAME
4*e71b7053SJung-uk Kim
5*e71b7053SJung-uk KimUI_METHOD,
6*e71b7053SJung-uk KimUI_create_method, UI_destroy_method, UI_method_set_opener,
7*e71b7053SJung-uk KimUI_method_set_writer, UI_method_set_flusher, UI_method_set_reader,
8*e71b7053SJung-uk KimUI_method_set_closer, UI_method_set_data_duplicator,
9*e71b7053SJung-uk KimUI_method_set_prompt_constructor, UI_method_set_ex_data,
10*e71b7053SJung-uk KimUI_method_get_opener, UI_method_get_writer, UI_method_get_flusher,
11*e71b7053SJung-uk KimUI_method_get_reader, UI_method_get_closer,
12*e71b7053SJung-uk KimUI_method_get_data_duplicator, UI_method_get_data_destructor,
13*e71b7053SJung-uk KimUI_method_get_prompt_constructor, UI_method_get_ex_data - user
14*e71b7053SJung-uk Kiminterface method creation and destruction
15*e71b7053SJung-uk Kim
16*e71b7053SJung-uk Kim=head1 SYNOPSIS
17*e71b7053SJung-uk Kim
18*e71b7053SJung-uk Kim #include <openssl/ui.h>
19*e71b7053SJung-uk Kim
20*e71b7053SJung-uk Kim typedef struct ui_method_st UI_METHOD;
21*e71b7053SJung-uk Kim
22*e71b7053SJung-uk Kim UI_METHOD *UI_create_method(const char *name);
23*e71b7053SJung-uk Kim void UI_destroy_method(UI_METHOD *ui_method);
24*e71b7053SJung-uk Kim int UI_method_set_opener(UI_METHOD *method, int (*opener) (UI *ui));
25*e71b7053SJung-uk Kim int UI_method_set_writer(UI_METHOD *method,
26*e71b7053SJung-uk Kim                          int (*writer) (UI *ui, UI_STRING *uis));
27*e71b7053SJung-uk Kim int UI_method_set_flusher(UI_METHOD *method, int (*flusher) (UI *ui));
28*e71b7053SJung-uk Kim int UI_method_set_reader(UI_METHOD *method,
29*e71b7053SJung-uk Kim                          int (*reader) (UI *ui, UI_STRING *uis));
30*e71b7053SJung-uk Kim int UI_method_set_closer(UI_METHOD *method, int (*closer) (UI *ui));
31*e71b7053SJung-uk Kim int UI_method_set_data_duplicator(UI_METHOD *method,
32*e71b7053SJung-uk Kim                                   void *(*duplicator) (UI *ui, void *ui_data),
33*e71b7053SJung-uk Kim                                   void (*destructor)(UI *ui, void *ui_data));
34*e71b7053SJung-uk Kim int UI_method_set_prompt_constructor(UI_METHOD *method,
35*e71b7053SJung-uk Kim                                      char *(*prompt_constructor) (UI *ui,
36*e71b7053SJung-uk Kim                                                                   const char
37*e71b7053SJung-uk Kim                                                                   *object_desc,
38*e71b7053SJung-uk Kim                                                                   const char
39*e71b7053SJung-uk Kim                                                                   *object_name));
40*e71b7053SJung-uk Kim int UI_method_set_ex_data(UI_METHOD *method, int idx, void *data);
41*e71b7053SJung-uk Kim int (*UI_method_get_opener(const UI_METHOD *method)) (UI *);
42*e71b7053SJung-uk Kim int (*UI_method_get_writer(const UI_METHOD *method)) (UI *, UI_STRING *);
43*e71b7053SJung-uk Kim int (*UI_method_get_flusher(const UI_METHOD *method)) (UI *);
44*e71b7053SJung-uk Kim int (*UI_method_get_reader(const UI_METHOD *method)) (UI *, UI_STRING *);
45*e71b7053SJung-uk Kim int (*UI_method_get_closer(const UI_METHOD *method)) (UI *);
46*e71b7053SJung-uk Kim char *(*UI_method_get_prompt_constructor(const UI_METHOD *method))
47*e71b7053SJung-uk Kim     (UI *, const char *, const char *);
48*e71b7053SJung-uk Kim void *(*UI_method_get_data_duplicator(const UI_METHOD *method)) (UI *, void *);
49*e71b7053SJung-uk Kim void (*UI_method_get_data_destructor(const UI_METHOD *method)) (UI *, void *);
50*e71b7053SJung-uk Kim const void *UI_method_get_ex_data(const UI_METHOD *method, int idx);
51*e71b7053SJung-uk Kim
52*e71b7053SJung-uk Kim=head1 DESCRIPTION
53*e71b7053SJung-uk Kim
54*e71b7053SJung-uk KimA method contains a few functions that implement the low level of the
55*e71b7053SJung-uk KimUser Interface.
56*e71b7053SJung-uk KimThese functions are:
57*e71b7053SJung-uk Kim
58*e71b7053SJung-uk Kim=over 4
59*e71b7053SJung-uk Kim
60*e71b7053SJung-uk Kim=item an opener
61*e71b7053SJung-uk Kim
62*e71b7053SJung-uk KimThis function takes a reference to a UI and starts a session, for
63*e71b7053SJung-uk Kimexample by opening a channel to a tty, or by creating a dialog box.
64*e71b7053SJung-uk Kim
65*e71b7053SJung-uk Kim=item a writer
66*e71b7053SJung-uk Kim
67*e71b7053SJung-uk KimThis function takes a reference to a UI and a UI String, and writes
68*e71b7053SJung-uk Kimthe string where appropriate, maybe to the tty, maybe added as a field
69*e71b7053SJung-uk Kimlabel in a dialog box.
70*e71b7053SJung-uk KimNote that this gets fed all strings associated with a UI, one after
71*e71b7053SJung-uk Kimthe other, so care must be taken which ones it actually uses.
72*e71b7053SJung-uk Kim
73*e71b7053SJung-uk Kim=item a flusher
74*e71b7053SJung-uk Kim
75*e71b7053SJung-uk KimThis function takes a reference to a UI, and flushes everything that
76*e71b7053SJung-uk Kimhas been output so far.
77*e71b7053SJung-uk KimFor example, if the method builds up a dialog box, this can be used to
78*e71b7053SJung-uk Kimactually display it and accepting input ended with a pressed button.
79*e71b7053SJung-uk Kim
80*e71b7053SJung-uk Kim=item a reader
81*e71b7053SJung-uk Kim
82*e71b7053SJung-uk KimThis function takes a reference to a UI and a UI string and reads off
83*e71b7053SJung-uk Kimthe given prompt, maybe from the tty, maybe from a field in a dialog
84*e71b7053SJung-uk Kimbox.
85*e71b7053SJung-uk KimNote that this gets fed all strings associated with a UI, one after
86*e71b7053SJung-uk Kimthe other, so care must be taken which ones it actually uses.
87*e71b7053SJung-uk Kim
88*e71b7053SJung-uk Kim=item a closer
89*e71b7053SJung-uk Kim
90*e71b7053SJung-uk KimThis function takes a reference to a UI, and closes the session, maybe
91*e71b7053SJung-uk Kimby closing the channel to the tty, maybe by destroying a dialog box.
92*e71b7053SJung-uk Kim
93*e71b7053SJung-uk Kim=back
94*e71b7053SJung-uk Kim
95*e71b7053SJung-uk KimAll of these functions are expected to return 0 on error, 1 on
96*e71b7053SJung-uk Kimsuccess, or -1 on out-off-band events, for example if some prompting
97*e71b7053SJung-uk Kimhas been cancelled (by pressing Ctrl-C, for example).
98*e71b7053SJung-uk KimOnly the flusher or the reader are expected to return -1.
99*e71b7053SJung-uk KimIf returned by another of the functions, it's treated as if 0 was
100*e71b7053SJung-uk Kimreturned.
101*e71b7053SJung-uk Kim
102*e71b7053SJung-uk KimRegarding the writer and the reader, don't assume the former should
103*e71b7053SJung-uk Kimonly write and don't assume the latter should only read.
104*e71b7053SJung-uk KimThis depends on the needs of the method.
105*e71b7053SJung-uk Kim
106*e71b7053SJung-uk KimFor example, a typical tty reader wouldn't write the prompts in the
107*e71b7053SJung-uk Kimwrite, but would rather do so in the reader, because of the sequential
108*e71b7053SJung-uk Kimnature of prompting on a tty.
109*e71b7053SJung-uk KimThis is how the UI_OpenSSL() method does it.
110*e71b7053SJung-uk Kim
111*e71b7053SJung-uk KimIn contrast, a method that builds up a dialog box would add all prompt
112*e71b7053SJung-uk Kimtext in the writer, have all input read in the flusher and store the
113*e71b7053SJung-uk Kimresults in some temporary buffer, and finally have the reader just
114*e71b7053SJung-uk Kimfetch those results.
115*e71b7053SJung-uk Kim
116*e71b7053SJung-uk KimThe central function that uses these method functions is UI_process(),
117*e71b7053SJung-uk Kimand it does it in five steps:
118*e71b7053SJung-uk Kim
119*e71b7053SJung-uk Kim=over 4
120*e71b7053SJung-uk Kim
121*e71b7053SJung-uk Kim=item 1.
122*e71b7053SJung-uk Kim
123*e71b7053SJung-uk KimOpen the session using the opener function if that one's defined.
124*e71b7053SJung-uk KimIf an error occurs, jump to 5.
125*e71b7053SJung-uk Kim
126*e71b7053SJung-uk Kim=item 2.
127*e71b7053SJung-uk Kim
128*e71b7053SJung-uk KimFor every UI String associated with the UI, call the writer function
129*e71b7053SJung-uk Kimif that one's defined.
130*e71b7053SJung-uk KimIf an error occurs, jump to 5.
131*e71b7053SJung-uk Kim
132*e71b7053SJung-uk Kim=item 3.
133*e71b7053SJung-uk Kim
134*e71b7053SJung-uk KimFlush everything using the flusher function if that one's defined.
135*e71b7053SJung-uk KimIf an error occurs, jump to 5.
136*e71b7053SJung-uk Kim
137*e71b7053SJung-uk Kim=item 4.
138*e71b7053SJung-uk Kim
139*e71b7053SJung-uk KimFor every UI String associated with the UI, call the reader function
140*e71b7053SJung-uk Kimif that one's defined.
141*e71b7053SJung-uk KimIf an error occurs, jump to 5.
142*e71b7053SJung-uk Kim
143*e71b7053SJung-uk Kim=item 5.
144*e71b7053SJung-uk Kim
145*e71b7053SJung-uk KimClose the session using the closer function if that one's defined.
146*e71b7053SJung-uk Kim
147*e71b7053SJung-uk Kim=back
148*e71b7053SJung-uk Kim
149*e71b7053SJung-uk KimUI_create_method() creates a new UI method with a given B<name>.
150*e71b7053SJung-uk Kim
151*e71b7053SJung-uk KimUI_destroy_method() destroys the given UI method B<ui_method>.
152*e71b7053SJung-uk Kim
153*e71b7053SJung-uk KimUI_method_set_opener(), UI_method_set_writer(),
154*e71b7053SJung-uk KimUI_method_set_flusher(), UI_method_set_reader() and
155*e71b7053SJung-uk KimUI_method_set_closer() set the five main method function to the given
156*e71b7053SJung-uk Kimfunction pointer.
157*e71b7053SJung-uk Kim
158*e71b7053SJung-uk KimUI_method_set_data_duplicator() sets the user data duplicator and destructor.
159*e71b7053SJung-uk KimSee L<UI_dup_user_data(3)>.
160*e71b7053SJung-uk Kim
161*e71b7053SJung-uk KimUI_method_set_prompt_constructor() sets the prompt constructor.
162*e71b7053SJung-uk KimSee L<UI_construct_prompt(3)>.
163*e71b7053SJung-uk Kim
164*e71b7053SJung-uk KimUI_method_set_ex_data() sets application specific data with a given
165*e71b7053SJung-uk KimEX_DATA index.
166*e71b7053SJung-uk KimSee L<CRYPTO_get_ex_new_index(3)> for general information on how to
167*e71b7053SJung-uk Kimget that index.
168*e71b7053SJung-uk Kim
169*e71b7053SJung-uk KimUI_method_get_opener(), UI_method_get_writer(),
170*e71b7053SJung-uk KimUI_method_get_flusher(), UI_method_get_reader(),
171*e71b7053SJung-uk KimUI_method_get_closer(), UI_method_get_data_duplicator(),
172*e71b7053SJung-uk KimUI_method_get_data_destructor() and UI_method_get_prompt_constructor()
173*e71b7053SJung-uk Kimreturn the different method functions.
174*e71b7053SJung-uk Kim
175*e71b7053SJung-uk KimUI_method_get_ex_data() returns the application data previously stored
176*e71b7053SJung-uk Kimwith UI_method_set_ex_data().
177*e71b7053SJung-uk Kim
178*e71b7053SJung-uk Kim=head1 RETURN VALUES
179*e71b7053SJung-uk Kim
180*e71b7053SJung-uk KimUI_create_method() returns a UI_METHOD pointer on success, NULL on
181*e71b7053SJung-uk Kimerror.
182*e71b7053SJung-uk Kim
183*e71b7053SJung-uk KimUI_method_set_opener(), UI_method_set_writer(),
184*e71b7053SJung-uk KimUI_method_set_flusher(), UI_method_set_reader(),
185*e71b7053SJung-uk KimUI_method_set_closer(), UI_method_set_data_duplicator() and
186*e71b7053SJung-uk KimUI_method_set_prompt_constructor()
187*e71b7053SJung-uk Kimreturn 0 on success, -1 if the given B<method> is NULL.
188*e71b7053SJung-uk Kim
189*e71b7053SJung-uk KimUI_method_set_ex_data() returns 1 on success and 0 on error (because
190*e71b7053SJung-uk KimCRYPTO_set_ex_data() does so).
191*e71b7053SJung-uk Kim
192*e71b7053SJung-uk KimUI_method_get_opener(), UI_method_get_writer(),
193*e71b7053SJung-uk KimUI_method_get_flusher(), UI_method_get_reader(),
194*e71b7053SJung-uk KimUI_method_get_closer(), UI_method_get_data_duplicator(),
195*e71b7053SJung-uk KimUI_method_get_data_destructor() and UI_method_get_prompt_constructor()
196*e71b7053SJung-uk Kimreturn the requested function pointer if it's set in the method,
197*e71b7053SJung-uk Kimotherwise NULL.
198*e71b7053SJung-uk Kim
199*e71b7053SJung-uk KimUI_method_get_ex_data() returns a pointer to the application specific
200*e71b7053SJung-uk Kimdata associated with the method.
201*e71b7053SJung-uk Kim
202*e71b7053SJung-uk Kim=head1 SEE ALSO
203*e71b7053SJung-uk Kim
204*e71b7053SJung-uk KimL<UI(3)>, L<CRYPTO_get_ex_data(3)>, L<UI_STRING(3)>
205*e71b7053SJung-uk Kim
206*e71b7053SJung-uk Kim=head1 HISTORY
207*e71b7053SJung-uk Kim
208*e71b7053SJung-uk KimUI_method_set_data_duplicator(), UI_method_get_data_duplicator() and
209*e71b7053SJung-uk KimUI_method_get_data_destructor()
210*e71b7053SJung-uk Kimwere added in OpenSSL 1.1.1.
211*e71b7053SJung-uk Kim
212*e71b7053SJung-uk Kim=head1 COPYRIGHT
213*e71b7053SJung-uk Kim
214*e71b7053SJung-uk KimCopyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
215*e71b7053SJung-uk Kim
216*e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License").  You may not use
217*e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
218*e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
219*e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
220*e71b7053SJung-uk Kim
221*e71b7053SJung-uk Kim=cut
222