1e1051a39Sopenharmony_ci=pod
2e1051a39Sopenharmony_ci
3e1051a39Sopenharmony_ci=head1 NAME
4e1051a39Sopenharmony_ci
5e1051a39Sopenharmony_ciUI_METHOD,
6e1051a39Sopenharmony_ciUI_create_method, UI_destroy_method, UI_method_set_opener,
7e1051a39Sopenharmony_ciUI_method_set_writer, UI_method_set_flusher, UI_method_set_reader,
8e1051a39Sopenharmony_ciUI_method_set_closer, UI_method_set_data_duplicator,
9e1051a39Sopenharmony_ciUI_method_set_prompt_constructor, UI_method_set_ex_data,
10e1051a39Sopenharmony_ciUI_method_get_opener, UI_method_get_writer, UI_method_get_flusher,
11e1051a39Sopenharmony_ciUI_method_get_reader, UI_method_get_closer,
12e1051a39Sopenharmony_ciUI_method_get_data_duplicator, UI_method_get_data_destructor,
13e1051a39Sopenharmony_ciUI_method_get_prompt_constructor, UI_method_get_ex_data - user
14e1051a39Sopenharmony_ciinterface method creation and destruction
15e1051a39Sopenharmony_ci
16e1051a39Sopenharmony_ci=head1 SYNOPSIS
17e1051a39Sopenharmony_ci
18e1051a39Sopenharmony_ci #include <openssl/ui.h>
19e1051a39Sopenharmony_ci
20e1051a39Sopenharmony_ci typedef struct ui_method_st UI_METHOD;
21e1051a39Sopenharmony_ci
22e1051a39Sopenharmony_ci UI_METHOD *UI_create_method(const char *name);
23e1051a39Sopenharmony_ci void UI_destroy_method(UI_METHOD *ui_method);
24e1051a39Sopenharmony_ci int UI_method_set_opener(UI_METHOD *method, int (*opener) (UI *ui));
25e1051a39Sopenharmony_ci int UI_method_set_writer(UI_METHOD *method,
26e1051a39Sopenharmony_ci                          int (*writer) (UI *ui, UI_STRING *uis));
27e1051a39Sopenharmony_ci int UI_method_set_flusher(UI_METHOD *method, int (*flusher) (UI *ui));
28e1051a39Sopenharmony_ci int UI_method_set_reader(UI_METHOD *method,
29e1051a39Sopenharmony_ci                          int (*reader) (UI *ui, UI_STRING *uis));
30e1051a39Sopenharmony_ci int UI_method_set_closer(UI_METHOD *method, int (*closer) (UI *ui));
31e1051a39Sopenharmony_ci int UI_method_set_data_duplicator(UI_METHOD *method,
32e1051a39Sopenharmony_ci                                   void *(*duplicator) (UI *ui, void *ui_data),
33e1051a39Sopenharmony_ci                                   void (*destructor)(UI *ui, void *ui_data));
34e1051a39Sopenharmony_ci int UI_method_set_prompt_constructor(UI_METHOD *method,
35e1051a39Sopenharmony_ci                                      char *(*prompt_constructor) (UI *ui,
36e1051a39Sopenharmony_ci                                                                   const char
37e1051a39Sopenharmony_ci                                                                   *object_desc,
38e1051a39Sopenharmony_ci                                                                   const char
39e1051a39Sopenharmony_ci                                                                   *object_name));
40e1051a39Sopenharmony_ci int UI_method_set_ex_data(UI_METHOD *method, int idx, void *data);
41e1051a39Sopenharmony_ci int (*UI_method_get_opener(const UI_METHOD *method)) (UI *);
42e1051a39Sopenharmony_ci int (*UI_method_get_writer(const UI_METHOD *method)) (UI *, UI_STRING *);
43e1051a39Sopenharmony_ci int (*UI_method_get_flusher(const UI_METHOD *method)) (UI *);
44e1051a39Sopenharmony_ci int (*UI_method_get_reader(const UI_METHOD *method)) (UI *, UI_STRING *);
45e1051a39Sopenharmony_ci int (*UI_method_get_closer(const UI_METHOD *method)) (UI *);
46e1051a39Sopenharmony_ci char *(*UI_method_get_prompt_constructor(const UI_METHOD *method))
47e1051a39Sopenharmony_ci     (UI *, const char *, const char *);
48e1051a39Sopenharmony_ci void *(*UI_method_get_data_duplicator(const UI_METHOD *method)) (UI *, void *);
49e1051a39Sopenharmony_ci void (*UI_method_get_data_destructor(const UI_METHOD *method)) (UI *, void *);
50e1051a39Sopenharmony_ci const void *UI_method_get_ex_data(const UI_METHOD *method, int idx);
51e1051a39Sopenharmony_ci
52e1051a39Sopenharmony_ci=head1 DESCRIPTION
53e1051a39Sopenharmony_ci
54e1051a39Sopenharmony_ciA method contains a few functions that implement the low-level of the
55e1051a39Sopenharmony_ciUser Interface.
56e1051a39Sopenharmony_ciThese functions are:
57e1051a39Sopenharmony_ci
58e1051a39Sopenharmony_ci=over 4
59e1051a39Sopenharmony_ci
60e1051a39Sopenharmony_ci=item an opener
61e1051a39Sopenharmony_ci
62e1051a39Sopenharmony_ciThis function takes a reference to a UI and starts a session, for
63e1051a39Sopenharmony_ciexample by opening a channel to a tty, or by creating a dialog box.
64e1051a39Sopenharmony_ci
65e1051a39Sopenharmony_ci=item a writer
66e1051a39Sopenharmony_ci
67e1051a39Sopenharmony_ciThis function takes a reference to a UI and a UI String, and writes
68e1051a39Sopenharmony_cithe string where appropriate, maybe to the tty, maybe added as a field
69e1051a39Sopenharmony_cilabel in a dialog box.
70e1051a39Sopenharmony_ciNote that this gets fed all strings associated with a UI, one after
71e1051a39Sopenharmony_cithe other, so care must be taken which ones it actually uses.
72e1051a39Sopenharmony_ci
73e1051a39Sopenharmony_ci=item a flusher
74e1051a39Sopenharmony_ci
75e1051a39Sopenharmony_ciThis function takes a reference to a UI, and flushes everything that
76e1051a39Sopenharmony_cihas been output so far.
77e1051a39Sopenharmony_ciFor example, if the method builds up a dialog box, this can be used to
78e1051a39Sopenharmony_ciactually display it and accepting input ended with a pressed button.
79e1051a39Sopenharmony_ci
80e1051a39Sopenharmony_ci=item a reader
81e1051a39Sopenharmony_ci
82e1051a39Sopenharmony_ciThis function takes a reference to a UI and a UI string and reads off
83e1051a39Sopenharmony_cithe given prompt, maybe from the tty, maybe from a field in a dialog
84e1051a39Sopenharmony_cibox.
85e1051a39Sopenharmony_ciNote that this gets fed all strings associated with a UI, one after
86e1051a39Sopenharmony_cithe other, so care must be taken which ones it actually uses.
87e1051a39Sopenharmony_ci
88e1051a39Sopenharmony_ci=item a closer
89e1051a39Sopenharmony_ci
90e1051a39Sopenharmony_ciThis function takes a reference to a UI, and closes the session, maybe
91e1051a39Sopenharmony_ciby closing the channel to the tty, maybe by destroying a dialog box.
92e1051a39Sopenharmony_ci
93e1051a39Sopenharmony_ci=back
94e1051a39Sopenharmony_ci
95e1051a39Sopenharmony_ciAll of these functions are expected to return 0 on error, 1 on
96e1051a39Sopenharmony_cisuccess, or -1 on out-off-band events, for example if some prompting
97e1051a39Sopenharmony_cihas been cancelled (by pressing Ctrl-C, for example).
98e1051a39Sopenharmony_ciOnly the flusher or the reader are expected to return -1.
99e1051a39Sopenharmony_ciIf returned by another of the functions, it's treated as if 0 was
100e1051a39Sopenharmony_cireturned.
101e1051a39Sopenharmony_ci
102e1051a39Sopenharmony_ciRegarding the writer and the reader, don't assume the former should
103e1051a39Sopenharmony_cionly write and don't assume the latter should only read.
104e1051a39Sopenharmony_ciThis depends on the needs of the method.
105e1051a39Sopenharmony_ci
106e1051a39Sopenharmony_ciFor example, a typical tty reader wouldn't write the prompts in the
107e1051a39Sopenharmony_ciwrite, but would rather do so in the reader, because of the sequential
108e1051a39Sopenharmony_cinature of prompting on a tty.
109e1051a39Sopenharmony_ciThis is how the UI_OpenSSL() method does it.
110e1051a39Sopenharmony_ci
111e1051a39Sopenharmony_ciIn contrast, a method that builds up a dialog box would add all prompt
112e1051a39Sopenharmony_citext in the writer, have all input read in the flusher and store the
113e1051a39Sopenharmony_ciresults in some temporary buffer, and finally have the reader just
114e1051a39Sopenharmony_cifetch those results.
115e1051a39Sopenharmony_ci
116e1051a39Sopenharmony_ciThe central function that uses these method functions is UI_process(),
117e1051a39Sopenharmony_ciand it does it in five steps:
118e1051a39Sopenharmony_ci
119e1051a39Sopenharmony_ci=over 4
120e1051a39Sopenharmony_ci
121e1051a39Sopenharmony_ci=item 1.
122e1051a39Sopenharmony_ci
123e1051a39Sopenharmony_ciOpen the session using the opener function if that one's defined.
124e1051a39Sopenharmony_ciIf an error occurs, jump to 5.
125e1051a39Sopenharmony_ci
126e1051a39Sopenharmony_ci=item 2.
127e1051a39Sopenharmony_ci
128e1051a39Sopenharmony_ciFor every UI String associated with the UI, call the writer function
129e1051a39Sopenharmony_ciif that one's defined.
130e1051a39Sopenharmony_ciIf an error occurs, jump to 5.
131e1051a39Sopenharmony_ci
132e1051a39Sopenharmony_ci=item 3.
133e1051a39Sopenharmony_ci
134e1051a39Sopenharmony_ciFlush everything using the flusher function if that one's defined.
135e1051a39Sopenharmony_ciIf an error occurs, jump to 5.
136e1051a39Sopenharmony_ci
137e1051a39Sopenharmony_ci=item 4.
138e1051a39Sopenharmony_ci
139e1051a39Sopenharmony_ciFor every UI String associated with the UI, call the reader function
140e1051a39Sopenharmony_ciif that one's defined.
141e1051a39Sopenharmony_ciIf an error occurs, jump to 5.
142e1051a39Sopenharmony_ci
143e1051a39Sopenharmony_ci=item 5.
144e1051a39Sopenharmony_ci
145e1051a39Sopenharmony_ciClose the session using the closer function if that one's defined.
146e1051a39Sopenharmony_ci
147e1051a39Sopenharmony_ci=back
148e1051a39Sopenharmony_ci
149e1051a39Sopenharmony_ciUI_create_method() creates a new UI method with a given B<name>.
150e1051a39Sopenharmony_ci
151e1051a39Sopenharmony_ciUI_destroy_method() destroys the given UI method B<ui_method>.
152e1051a39Sopenharmony_ci
153e1051a39Sopenharmony_ciUI_method_set_opener(), UI_method_set_writer(),
154e1051a39Sopenharmony_ciUI_method_set_flusher(), UI_method_set_reader() and
155e1051a39Sopenharmony_ciUI_method_set_closer() set the five main method function to the given
156e1051a39Sopenharmony_cifunction pointer.
157e1051a39Sopenharmony_ci
158e1051a39Sopenharmony_ciUI_method_set_data_duplicator() sets the user data duplicator and destructor.
159e1051a39Sopenharmony_ciSee L<UI_dup_user_data(3)>.
160e1051a39Sopenharmony_ci
161e1051a39Sopenharmony_ciUI_method_set_prompt_constructor() sets the prompt constructor.
162e1051a39Sopenharmony_ciSee L<UI_construct_prompt(3)>.
163e1051a39Sopenharmony_ci
164e1051a39Sopenharmony_ciUI_method_set_ex_data() sets application specific data with a given
165e1051a39Sopenharmony_ciEX_DATA index.
166e1051a39Sopenharmony_ciSee L<CRYPTO_get_ex_new_index(3)> for general information on how to
167e1051a39Sopenharmony_ciget that index.
168e1051a39Sopenharmony_ci
169e1051a39Sopenharmony_ciUI_method_get_opener(), UI_method_get_writer(),
170e1051a39Sopenharmony_ciUI_method_get_flusher(), UI_method_get_reader(),
171e1051a39Sopenharmony_ciUI_method_get_closer(), UI_method_get_data_duplicator(),
172e1051a39Sopenharmony_ciUI_method_get_data_destructor() and UI_method_get_prompt_constructor()
173e1051a39Sopenharmony_cireturn the different method functions.
174e1051a39Sopenharmony_ci
175e1051a39Sopenharmony_ciUI_method_get_ex_data() returns the application data previously stored
176e1051a39Sopenharmony_ciwith UI_method_set_ex_data().
177e1051a39Sopenharmony_ci
178e1051a39Sopenharmony_ci=head1 RETURN VALUES
179e1051a39Sopenharmony_ci
180e1051a39Sopenharmony_ciUI_create_method() returns a UI_METHOD pointer on success, NULL on
181e1051a39Sopenharmony_cierror.
182e1051a39Sopenharmony_ci
183e1051a39Sopenharmony_ciUI_method_set_opener(), UI_method_set_writer(),
184e1051a39Sopenharmony_ciUI_method_set_flusher(), UI_method_set_reader(),
185e1051a39Sopenharmony_ciUI_method_set_closer(), UI_method_set_data_duplicator() and
186e1051a39Sopenharmony_ciUI_method_set_prompt_constructor()
187e1051a39Sopenharmony_cireturn 0 on success, -1 if the given B<method> is NULL.
188e1051a39Sopenharmony_ci
189e1051a39Sopenharmony_ciUI_method_set_ex_data() returns 1 on success and 0 on error (because
190e1051a39Sopenharmony_ciCRYPTO_set_ex_data() does so).
191e1051a39Sopenharmony_ci
192e1051a39Sopenharmony_ciUI_method_get_opener(), UI_method_get_writer(),
193e1051a39Sopenharmony_ciUI_method_get_flusher(), UI_method_get_reader(),
194e1051a39Sopenharmony_ciUI_method_get_closer(), UI_method_get_data_duplicator(),
195e1051a39Sopenharmony_ciUI_method_get_data_destructor() and UI_method_get_prompt_constructor()
196e1051a39Sopenharmony_cireturn the requested function pointer if it's set in the method,
197e1051a39Sopenharmony_ciotherwise NULL.
198e1051a39Sopenharmony_ci
199e1051a39Sopenharmony_ciUI_method_get_ex_data() returns a pointer to the application specific
200e1051a39Sopenharmony_cidata associated with the method.
201e1051a39Sopenharmony_ci
202e1051a39Sopenharmony_ci=head1 SEE ALSO
203e1051a39Sopenharmony_ci
204e1051a39Sopenharmony_ciL<UI(3)>, L<CRYPTO_get_ex_data(3)>, L<UI_STRING(3)>
205e1051a39Sopenharmony_ci
206e1051a39Sopenharmony_ci=head1 HISTORY
207e1051a39Sopenharmony_ci
208e1051a39Sopenharmony_ciThe UI_method_set_data_duplicator(), UI_method_get_data_duplicator()
209e1051a39Sopenharmony_ciand UI_method_get_data_destructor() functions were added in OpenSSL 1.1.1.
210e1051a39Sopenharmony_ci
211e1051a39Sopenharmony_ci=head1 COPYRIGHT
212e1051a39Sopenharmony_ci
213e1051a39Sopenharmony_ciCopyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
214e1051a39Sopenharmony_ci
215e1051a39Sopenharmony_ciLicensed under the Apache License 2.0 (the "License").  You may not use
216e1051a39Sopenharmony_cithis file except in compliance with the License.  You can obtain a copy
217e1051a39Sopenharmony_ciin the file LICENSE in the source distribution or at
218e1051a39Sopenharmony_ciL<https://www.openssl.org/source/license.html>.
219e1051a39Sopenharmony_ci
220e1051a39Sopenharmony_ci=cut
221