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