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