xref: /dflybsd-src/crypto/libressl/include/openssl/ui.h (revision f5b1c8a1e6dbe9333aed363dba27c2ff58be6174)
1*f5b1c8a1SJohn Marino /* $OpenBSD: ui.h,v 1.8 2014/06/12 15:49:31 deraadt Exp $ */
2*f5b1c8a1SJohn Marino /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3*f5b1c8a1SJohn Marino  * project 2001.
4*f5b1c8a1SJohn Marino  */
5*f5b1c8a1SJohn Marino /* ====================================================================
6*f5b1c8a1SJohn Marino  * Copyright (c) 2001 The OpenSSL Project.  All rights reserved.
7*f5b1c8a1SJohn Marino  *
8*f5b1c8a1SJohn Marino  * Redistribution and use in source and binary forms, with or without
9*f5b1c8a1SJohn Marino  * modification, are permitted provided that the following conditions
10*f5b1c8a1SJohn Marino  * are met:
11*f5b1c8a1SJohn Marino  *
12*f5b1c8a1SJohn Marino  * 1. Redistributions of source code must retain the above copyright
13*f5b1c8a1SJohn Marino  *    notice, this list of conditions and the following disclaimer.
14*f5b1c8a1SJohn Marino  *
15*f5b1c8a1SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
16*f5b1c8a1SJohn Marino  *    notice, this list of conditions and the following disclaimer in
17*f5b1c8a1SJohn Marino  *    the documentation and/or other materials provided with the
18*f5b1c8a1SJohn Marino  *    distribution.
19*f5b1c8a1SJohn Marino  *
20*f5b1c8a1SJohn Marino  * 3. All advertising materials mentioning features or use of this
21*f5b1c8a1SJohn Marino  *    software must display the following acknowledgment:
22*f5b1c8a1SJohn Marino  *    "This product includes software developed by the OpenSSL Project
23*f5b1c8a1SJohn Marino  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24*f5b1c8a1SJohn Marino  *
25*f5b1c8a1SJohn Marino  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26*f5b1c8a1SJohn Marino  *    endorse or promote products derived from this software without
27*f5b1c8a1SJohn Marino  *    prior written permission. For written permission, please contact
28*f5b1c8a1SJohn Marino  *    openssl-core@openssl.org.
29*f5b1c8a1SJohn Marino  *
30*f5b1c8a1SJohn Marino  * 5. Products derived from this software may not be called "OpenSSL"
31*f5b1c8a1SJohn Marino  *    nor may "OpenSSL" appear in their names without prior written
32*f5b1c8a1SJohn Marino  *    permission of the OpenSSL Project.
33*f5b1c8a1SJohn Marino  *
34*f5b1c8a1SJohn Marino  * 6. Redistributions of any form whatsoever must retain the following
35*f5b1c8a1SJohn Marino  *    acknowledgment:
36*f5b1c8a1SJohn Marino  *    "This product includes software developed by the OpenSSL Project
37*f5b1c8a1SJohn Marino  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38*f5b1c8a1SJohn Marino  *
39*f5b1c8a1SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40*f5b1c8a1SJohn Marino  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41*f5b1c8a1SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42*f5b1c8a1SJohn Marino  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43*f5b1c8a1SJohn Marino  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44*f5b1c8a1SJohn Marino  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45*f5b1c8a1SJohn Marino  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46*f5b1c8a1SJohn Marino  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47*f5b1c8a1SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48*f5b1c8a1SJohn Marino  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49*f5b1c8a1SJohn Marino  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50*f5b1c8a1SJohn Marino  * OF THE POSSIBILITY OF SUCH DAMAGE.
51*f5b1c8a1SJohn Marino  * ====================================================================
52*f5b1c8a1SJohn Marino  *
53*f5b1c8a1SJohn Marino  * This product includes cryptographic software written by Eric Young
54*f5b1c8a1SJohn Marino  * (eay@cryptsoft.com).  This product includes software written by Tim
55*f5b1c8a1SJohn Marino  * Hudson (tjh@cryptsoft.com).
56*f5b1c8a1SJohn Marino  *
57*f5b1c8a1SJohn Marino  */
58*f5b1c8a1SJohn Marino 
59*f5b1c8a1SJohn Marino #ifndef HEADER_UI_H
60*f5b1c8a1SJohn Marino #define HEADER_UI_H
61*f5b1c8a1SJohn Marino 
62*f5b1c8a1SJohn Marino #include <openssl/opensslconf.h>
63*f5b1c8a1SJohn Marino 
64*f5b1c8a1SJohn Marino #ifndef OPENSSL_NO_DEPRECATED
65*f5b1c8a1SJohn Marino #include <openssl/crypto.h>
66*f5b1c8a1SJohn Marino #endif
67*f5b1c8a1SJohn Marino #include <openssl/safestack.h>
68*f5b1c8a1SJohn Marino #include <openssl/ossl_typ.h>
69*f5b1c8a1SJohn Marino 
70*f5b1c8a1SJohn Marino #ifdef  __cplusplus
71*f5b1c8a1SJohn Marino extern "C" {
72*f5b1c8a1SJohn Marino #endif
73*f5b1c8a1SJohn Marino 
74*f5b1c8a1SJohn Marino /* Declared already in ossl_typ.h */
75*f5b1c8a1SJohn Marino /* typedef struct ui_st UI; */
76*f5b1c8a1SJohn Marino /* typedef struct ui_method_st UI_METHOD; */
77*f5b1c8a1SJohn Marino 
78*f5b1c8a1SJohn Marino 
79*f5b1c8a1SJohn Marino /* All the following functions return -1 or NULL on error and in some cases
80*f5b1c8a1SJohn Marino    (UI_process()) -2 if interrupted or in some other way cancelled.
81*f5b1c8a1SJohn Marino    When everything is fine, they return 0, a positive value or a non-NULL
82*f5b1c8a1SJohn Marino    pointer, all depending on their purpose. */
83*f5b1c8a1SJohn Marino 
84*f5b1c8a1SJohn Marino /* Creators and destructor.   */
85*f5b1c8a1SJohn Marino UI *UI_new(void);
86*f5b1c8a1SJohn Marino UI *UI_new_method(const UI_METHOD *method);
87*f5b1c8a1SJohn Marino void UI_free(UI *ui);
88*f5b1c8a1SJohn Marino 
89*f5b1c8a1SJohn Marino /* The following functions are used to add strings to be printed and prompt
90*f5b1c8a1SJohn Marino    strings to prompt for data.  The names are UI_{add,dup}_<function>_string
91*f5b1c8a1SJohn Marino    and UI_{add,dup}_input_boolean.
92*f5b1c8a1SJohn Marino 
93*f5b1c8a1SJohn Marino    UI_{add,dup}_<function>_string have the following meanings:
94*f5b1c8a1SJohn Marino 	add	add a text or prompt string.  The pointers given to these
95*f5b1c8a1SJohn Marino 		functions are used verbatim, no copying is done.
96*f5b1c8a1SJohn Marino 	dup	make a copy of the text or prompt string, then add the copy
97*f5b1c8a1SJohn Marino 		to the collection of strings in the user interface.
98*f5b1c8a1SJohn Marino 	<function>
99*f5b1c8a1SJohn Marino 		The function is a name for the functionality that the given
100*f5b1c8a1SJohn Marino 		string shall be used for.  It can be one of:
101*f5b1c8a1SJohn Marino 			input	use the string as data prompt.
102*f5b1c8a1SJohn Marino 			verify	use the string as verification prompt.  This
103*f5b1c8a1SJohn Marino 				is used to verify a previous input.
104*f5b1c8a1SJohn Marino 			info	use the string for informational output.
105*f5b1c8a1SJohn Marino 			error	use the string for error output.
106*f5b1c8a1SJohn Marino    Honestly, there's currently no difference between info and error for the
107*f5b1c8a1SJohn Marino    moment.
108*f5b1c8a1SJohn Marino 
109*f5b1c8a1SJohn Marino    UI_{add,dup}_input_boolean have the same semantics for "add" and "dup",
110*f5b1c8a1SJohn Marino    and are typically used when one wants to prompt for a yes/no response.
111*f5b1c8a1SJohn Marino 
112*f5b1c8a1SJohn Marino 
113*f5b1c8a1SJohn Marino    All of the functions in this group take a UI and a prompt string.
114*f5b1c8a1SJohn Marino    The string input and verify addition functions also take a flag argument,
115*f5b1c8a1SJohn Marino    a buffer for the result to end up with, a minimum input size and a maximum
116*f5b1c8a1SJohn Marino    input size (the result buffer MUST be large enough to be able to contain
117*f5b1c8a1SJohn Marino    the maximum number of characters).  Additionally, the verify addition
118*f5b1c8a1SJohn Marino    functions takes another buffer to compare the result against.
119*f5b1c8a1SJohn Marino    The boolean input functions take an action description string (which should
120*f5b1c8a1SJohn Marino    be safe to ignore if the expected user action is obvious, for example with
121*f5b1c8a1SJohn Marino    a dialog box with an OK button and a Cancel button), a string of acceptable
122*f5b1c8a1SJohn Marino    characters to mean OK and to mean Cancel.  The two last strings are checked
123*f5b1c8a1SJohn Marino    to make sure they don't have common characters.  Additionally, the same
124*f5b1c8a1SJohn Marino    flag argument as for the string input is taken, as well as a result buffer.
125*f5b1c8a1SJohn Marino    The result buffer is required to be at least one byte long.  Depending on
126*f5b1c8a1SJohn Marino    the answer, the first character from the OK or the Cancel character strings
127*f5b1c8a1SJohn Marino    will be stored in the first byte of the result buffer.  No NUL will be
128*f5b1c8a1SJohn Marino    added, so the result is *not* a string.
129*f5b1c8a1SJohn Marino 
130*f5b1c8a1SJohn Marino    On success, the all return an index of the added information.  That index
131*f5b1c8a1SJohn Marino    is usefull when retrieving results with UI_get0_result(). */
132*f5b1c8a1SJohn Marino int UI_add_input_string(UI *ui, const char *prompt, int flags,
133*f5b1c8a1SJohn Marino     char *result_buf, int minsize, int maxsize);
134*f5b1c8a1SJohn Marino int UI_dup_input_string(UI *ui, const char *prompt, int flags,
135*f5b1c8a1SJohn Marino     char *result_buf, int minsize, int maxsize);
136*f5b1c8a1SJohn Marino int UI_add_verify_string(UI *ui, const char *prompt, int flags,
137*f5b1c8a1SJohn Marino     char *result_buf, int minsize, int maxsize, const char *test_buf);
138*f5b1c8a1SJohn Marino int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
139*f5b1c8a1SJohn Marino     char *result_buf, int minsize, int maxsize, const char *test_buf);
140*f5b1c8a1SJohn Marino int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
141*f5b1c8a1SJohn Marino     const char *ok_chars, const char *cancel_chars,
142*f5b1c8a1SJohn Marino     int flags, char *result_buf);
143*f5b1c8a1SJohn Marino int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
144*f5b1c8a1SJohn Marino     const char *ok_chars, const char *cancel_chars,
145*f5b1c8a1SJohn Marino     int flags, char *result_buf);
146*f5b1c8a1SJohn Marino int UI_add_info_string(UI *ui, const char *text);
147*f5b1c8a1SJohn Marino int UI_dup_info_string(UI *ui, const char *text);
148*f5b1c8a1SJohn Marino int UI_add_error_string(UI *ui, const char *text);
149*f5b1c8a1SJohn Marino int UI_dup_error_string(UI *ui, const char *text);
150*f5b1c8a1SJohn Marino 
151*f5b1c8a1SJohn Marino /* These are the possible flags.  They can be or'ed together. */
152*f5b1c8a1SJohn Marino /* Use to have echoing of input */
153*f5b1c8a1SJohn Marino #define UI_INPUT_FLAG_ECHO		0x01
154*f5b1c8a1SJohn Marino /* Use a default password.  Where that password is found is completely
155*f5b1c8a1SJohn Marino    up to the application, it might for example be in the user data set
156*f5b1c8a1SJohn Marino    with UI_add_user_data().  It is not recommended to have more than
157*f5b1c8a1SJohn Marino    one input in each UI being marked with this flag, or the application
158*f5b1c8a1SJohn Marino    might get confused. */
159*f5b1c8a1SJohn Marino #define UI_INPUT_FLAG_DEFAULT_PWD	0x02
160*f5b1c8a1SJohn Marino 
161*f5b1c8a1SJohn Marino /* The user of these routines may want to define flags of their own.  The core
162*f5b1c8a1SJohn Marino    UI won't look at those, but will pass them on to the method routines.  They
163*f5b1c8a1SJohn Marino    must use higher bits so they don't get confused with the UI bits above.
164*f5b1c8a1SJohn Marino    UI_INPUT_FLAG_USER_BASE tells which is the lowest bit to use.  A good
165*f5b1c8a1SJohn Marino    example of use is this:
166*f5b1c8a1SJohn Marino 
167*f5b1c8a1SJohn Marino 	#define MY_UI_FLAG1	(0x01 << UI_INPUT_FLAG_USER_BASE)
168*f5b1c8a1SJohn Marino 
169*f5b1c8a1SJohn Marino */
170*f5b1c8a1SJohn Marino #define UI_INPUT_FLAG_USER_BASE	16
171*f5b1c8a1SJohn Marino 
172*f5b1c8a1SJohn Marino 
173*f5b1c8a1SJohn Marino /* The following function helps construct a prompt.  object_desc is a
174*f5b1c8a1SJohn Marino    textual short description of the object, for example "pass phrase",
175*f5b1c8a1SJohn Marino    and object_name is the name of the object (might be a card name or
176*f5b1c8a1SJohn Marino    a file name.
177*f5b1c8a1SJohn Marino    The returned string shall always be allocated on the heap with
178*f5b1c8a1SJohn Marino    malloc(), and need to be free'd with free().
179*f5b1c8a1SJohn Marino 
180*f5b1c8a1SJohn Marino    If the ui_method doesn't contain a pointer to a user-defined prompt
181*f5b1c8a1SJohn Marino    constructor, a default string is built, looking like this:
182*f5b1c8a1SJohn Marino 
183*f5b1c8a1SJohn Marino 	"Enter {object_desc} for {object_name}:"
184*f5b1c8a1SJohn Marino 
185*f5b1c8a1SJohn Marino    So, if object_desc has the value "pass phrase" and object_name has
186*f5b1c8a1SJohn Marino    the value "foo.key", the resulting string is:
187*f5b1c8a1SJohn Marino 
188*f5b1c8a1SJohn Marino 	"Enter pass phrase for foo.key:"
189*f5b1c8a1SJohn Marino */
190*f5b1c8a1SJohn Marino char *UI_construct_prompt(UI *ui_method, const char *object_desc,
191*f5b1c8a1SJohn Marino     const char *object_name);
192*f5b1c8a1SJohn Marino 
193*f5b1c8a1SJohn Marino 
194*f5b1c8a1SJohn Marino /* The following function is used to store a pointer to user-specific data.
195*f5b1c8a1SJohn Marino    Any previous such pointer will be returned and replaced.
196*f5b1c8a1SJohn Marino 
197*f5b1c8a1SJohn Marino    For callback purposes, this function makes a lot more sense than using
198*f5b1c8a1SJohn Marino    ex_data, since the latter requires that different parts of OpenSSL or
199*f5b1c8a1SJohn Marino    applications share the same ex_data index.
200*f5b1c8a1SJohn Marino 
201*f5b1c8a1SJohn Marino    Note that the UI_OpenSSL() method completely ignores the user data.
202*f5b1c8a1SJohn Marino    Other methods may not, however.  */
203*f5b1c8a1SJohn Marino void *UI_add_user_data(UI *ui, void *user_data);
204*f5b1c8a1SJohn Marino /* We need a user data retrieving function as well.  */
205*f5b1c8a1SJohn Marino void *UI_get0_user_data(UI *ui);
206*f5b1c8a1SJohn Marino 
207*f5b1c8a1SJohn Marino /* Return the result associated with a prompt given with the index i. */
208*f5b1c8a1SJohn Marino const char *UI_get0_result(UI *ui, int i);
209*f5b1c8a1SJohn Marino 
210*f5b1c8a1SJohn Marino /* When all strings have been added, process the whole thing. */
211*f5b1c8a1SJohn Marino int UI_process(UI *ui);
212*f5b1c8a1SJohn Marino 
213*f5b1c8a1SJohn Marino /* Give a user interface parametrised control commands.  This can be used to
214*f5b1c8a1SJohn Marino    send down an integer, a data pointer or a function pointer, as well as
215*f5b1c8a1SJohn Marino    be used to get information from a UI. */
216*f5b1c8a1SJohn Marino int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void));
217*f5b1c8a1SJohn Marino 
218*f5b1c8a1SJohn Marino /* The commands */
219*f5b1c8a1SJohn Marino /* Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the
220*f5b1c8a1SJohn Marino    OpenSSL error stack before printing any info or added error messages and
221*f5b1c8a1SJohn Marino    before any prompting. */
222*f5b1c8a1SJohn Marino #define UI_CTRL_PRINT_ERRORS		1
223*f5b1c8a1SJohn Marino /* Check if a UI_process() is possible to do again with the same instance of
224*f5b1c8a1SJohn Marino    a user interface.  This makes UI_ctrl() return 1 if it is redoable, and 0
225*f5b1c8a1SJohn Marino    if not. */
226*f5b1c8a1SJohn Marino #define UI_CTRL_IS_REDOABLE		2
227*f5b1c8a1SJohn Marino 
228*f5b1c8a1SJohn Marino 
229*f5b1c8a1SJohn Marino /* Some methods may use extra data */
230*f5b1c8a1SJohn Marino #define UI_set_app_data(s,arg)         UI_set_ex_data(s,0,arg)
231*f5b1c8a1SJohn Marino #define UI_get_app_data(s)             UI_get_ex_data(s,0)
232*f5b1c8a1SJohn Marino int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
233*f5b1c8a1SJohn Marino     CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
234*f5b1c8a1SJohn Marino int UI_set_ex_data(UI *r, int idx, void *arg);
235*f5b1c8a1SJohn Marino void *UI_get_ex_data(UI *r, int idx);
236*f5b1c8a1SJohn Marino 
237*f5b1c8a1SJohn Marino /* Use specific methods instead of the built-in one */
238*f5b1c8a1SJohn Marino void UI_set_default_method(const UI_METHOD *meth);
239*f5b1c8a1SJohn Marino const UI_METHOD *UI_get_default_method(void);
240*f5b1c8a1SJohn Marino const UI_METHOD *UI_get_method(UI *ui);
241*f5b1c8a1SJohn Marino const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth);
242*f5b1c8a1SJohn Marino 
243*f5b1c8a1SJohn Marino /* The method with all the built-in thingies */
244*f5b1c8a1SJohn Marino UI_METHOD *UI_OpenSSL(void);
245*f5b1c8a1SJohn Marino 
246*f5b1c8a1SJohn Marino 
247*f5b1c8a1SJohn Marino /* ---------- For method writers ---------- */
248*f5b1c8a1SJohn Marino /* A method contains a number of functions that implement the low level
249*f5b1c8a1SJohn Marino    of the User Interface.  The functions are:
250*f5b1c8a1SJohn Marino 
251*f5b1c8a1SJohn Marino 	an opener	This function starts a session, maybe by opening
252*f5b1c8a1SJohn Marino 			a channel to a tty, or by opening a window.
253*f5b1c8a1SJohn Marino 	a writer	This function is called to write a given string,
254*f5b1c8a1SJohn Marino 			maybe to the tty, maybe as a field label in a
255*f5b1c8a1SJohn Marino 			window.
256*f5b1c8a1SJohn Marino 	a flusher	This function is called to flush everything that
257*f5b1c8a1SJohn Marino 			has been output so far.  It can be used to actually
258*f5b1c8a1SJohn Marino 			display a dialog box after it has been built.
259*f5b1c8a1SJohn Marino 	a reader	This function is called to read a given prompt,
260*f5b1c8a1SJohn Marino 			maybe from the tty, maybe from a field in a
261*f5b1c8a1SJohn Marino 			window.  Note that it's called wth all string
262*f5b1c8a1SJohn Marino 			structures, not only the prompt ones, so it must
263*f5b1c8a1SJohn Marino 			check such things itself.
264*f5b1c8a1SJohn Marino 	a closer	This function closes the session, maybe by closing
265*f5b1c8a1SJohn Marino 			the channel to the tty, or closing the window.
266*f5b1c8a1SJohn Marino 
267*f5b1c8a1SJohn Marino    All these functions are expected to return:
268*f5b1c8a1SJohn Marino 
269*f5b1c8a1SJohn Marino 	0	on error.
270*f5b1c8a1SJohn Marino 	1	on success.
271*f5b1c8a1SJohn Marino 	-1	on out-of-band events, for example if some prompting has
272*f5b1c8a1SJohn Marino 		been canceled (by pressing Ctrl-C, for example).  This is
273*f5b1c8a1SJohn Marino 		only checked when returned by the flusher or the reader.
274*f5b1c8a1SJohn Marino 
275*f5b1c8a1SJohn Marino    The way this is used, the opener is first called, then the writer for all
276*f5b1c8a1SJohn Marino    strings, then the flusher, then the reader for all strings and finally the
277*f5b1c8a1SJohn Marino    closer.  Note that if you want to prompt from a terminal or other command
278*f5b1c8a1SJohn Marino    line interface, the best is to have the reader also write the prompts
279*f5b1c8a1SJohn Marino    instead of having the writer do it.  If you want to prompt from a dialog
280*f5b1c8a1SJohn Marino    box, the writer can be used to build up the contents of the box, and the
281*f5b1c8a1SJohn Marino    flusher to actually display the box and run the event loop until all data
282*f5b1c8a1SJohn Marino    has been given, after which the reader only grabs the given data and puts
283*f5b1c8a1SJohn Marino    them back into the UI strings.
284*f5b1c8a1SJohn Marino 
285*f5b1c8a1SJohn Marino    All method functions take a UI as argument.  Additionally, the writer and
286*f5b1c8a1SJohn Marino    the reader take a UI_STRING.
287*f5b1c8a1SJohn Marino */
288*f5b1c8a1SJohn Marino 
289*f5b1c8a1SJohn Marino /* The UI_STRING type is the data structure that contains all the needed info
290*f5b1c8a1SJohn Marino    about a string or a prompt, including test data for a verification prompt.
291*f5b1c8a1SJohn Marino */
292*f5b1c8a1SJohn Marino typedef struct ui_string_st UI_STRING;
293*f5b1c8a1SJohn Marino DECLARE_STACK_OF(UI_STRING)
294*f5b1c8a1SJohn Marino 
295*f5b1c8a1SJohn Marino /* The different types of strings that are currently supported.
296*f5b1c8a1SJohn Marino    This is only needed by method authors. */
297*f5b1c8a1SJohn Marino enum UI_string_types {
298*f5b1c8a1SJohn Marino 	UIT_NONE = 0,
299*f5b1c8a1SJohn Marino 	UIT_PROMPT,		/* Prompt for a string */
300*f5b1c8a1SJohn Marino 	UIT_VERIFY,		/* Prompt for a string and verify */
301*f5b1c8a1SJohn Marino 	UIT_BOOLEAN,		/* Prompt for a yes/no response */
302*f5b1c8a1SJohn Marino 	UIT_INFO,		/* Send info to the user */
303*f5b1c8a1SJohn Marino 	UIT_ERROR		/* Send an error message to the user */
304*f5b1c8a1SJohn Marino };
305*f5b1c8a1SJohn Marino 
306*f5b1c8a1SJohn Marino /* Create and manipulate methods */
307*f5b1c8a1SJohn Marino UI_METHOD *UI_create_method(char *name);
308*f5b1c8a1SJohn Marino void UI_destroy_method(UI_METHOD *ui_method);
309*f5b1c8a1SJohn Marino int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui));
310*f5b1c8a1SJohn Marino int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis));
311*f5b1c8a1SJohn Marino int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui));
312*f5b1c8a1SJohn Marino int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis));
313*f5b1c8a1SJohn Marino int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui));
314*f5b1c8a1SJohn Marino int UI_method_set_prompt_constructor(UI_METHOD *method, char *(*prompt_constructor)(UI* ui, const char* object_desc, const char* object_name));
315*f5b1c8a1SJohn Marino int (*UI_method_get_opener(UI_METHOD *method))(UI*);
316*f5b1c8a1SJohn Marino int (*UI_method_get_writer(UI_METHOD *method))(UI*, UI_STRING*);
317*f5b1c8a1SJohn Marino int (*UI_method_get_flusher(UI_METHOD *method))(UI*);
318*f5b1c8a1SJohn Marino int (*UI_method_get_reader(UI_METHOD *method))(UI*, UI_STRING*);
319*f5b1c8a1SJohn Marino int (*UI_method_get_closer(UI_METHOD *method))(UI*);
320*f5b1c8a1SJohn Marino char * (*UI_method_get_prompt_constructor(UI_METHOD *method))(UI*, const char*, const char*);
321*f5b1c8a1SJohn Marino 
322*f5b1c8a1SJohn Marino /* The following functions are helpers for method writers to access relevant
323*f5b1c8a1SJohn Marino    data from a UI_STRING. */
324*f5b1c8a1SJohn Marino 
325*f5b1c8a1SJohn Marino /* Return type of the UI_STRING */
326*f5b1c8a1SJohn Marino enum UI_string_types UI_get_string_type(UI_STRING *uis);
327*f5b1c8a1SJohn Marino /* Return input flags of the UI_STRING */
328*f5b1c8a1SJohn Marino int UI_get_input_flags(UI_STRING *uis);
329*f5b1c8a1SJohn Marino /* Return the actual string to output (the prompt, info or error) */
330*f5b1c8a1SJohn Marino const char *UI_get0_output_string(UI_STRING *uis);
331*f5b1c8a1SJohn Marino /* Return the optional action string to output (the boolean promtp instruction) */
332*f5b1c8a1SJohn Marino const char *UI_get0_action_string(UI_STRING *uis);
333*f5b1c8a1SJohn Marino /* Return the result of a prompt */
334*f5b1c8a1SJohn Marino const char *UI_get0_result_string(UI_STRING *uis);
335*f5b1c8a1SJohn Marino /* Return the string to test the result against.  Only useful with verifies. */
336*f5b1c8a1SJohn Marino const char *UI_get0_test_string(UI_STRING *uis);
337*f5b1c8a1SJohn Marino /* Return the required minimum size of the result */
338*f5b1c8a1SJohn Marino int UI_get_result_minsize(UI_STRING *uis);
339*f5b1c8a1SJohn Marino /* Return the required maximum size of the result */
340*f5b1c8a1SJohn Marino int UI_get_result_maxsize(UI_STRING *uis);
341*f5b1c8a1SJohn Marino /* Set the result of a UI_STRING. */
342*f5b1c8a1SJohn Marino int UI_set_result(UI *ui, UI_STRING *uis, const char *result);
343*f5b1c8a1SJohn Marino 
344*f5b1c8a1SJohn Marino 
345*f5b1c8a1SJohn Marino /* A couple of popular utility functions */
346*f5b1c8a1SJohn Marino int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify);
347*f5b1c8a1SJohn Marino int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, int verify);
348*f5b1c8a1SJohn Marino 
349*f5b1c8a1SJohn Marino 
350*f5b1c8a1SJohn Marino /* BEGIN ERROR CODES */
351*f5b1c8a1SJohn Marino /* The following lines are auto generated by the script mkerr.pl. Any changes
352*f5b1c8a1SJohn Marino  * made after this point may be overwritten when the script is next run.
353*f5b1c8a1SJohn Marino  */
354*f5b1c8a1SJohn Marino void ERR_load_UI_strings(void);
355*f5b1c8a1SJohn Marino 
356*f5b1c8a1SJohn Marino /* Error codes for the UI functions. */
357*f5b1c8a1SJohn Marino 
358*f5b1c8a1SJohn Marino /* Function codes. */
359*f5b1c8a1SJohn Marino #define UI_F_GENERAL_ALLOCATE_BOOLEAN			 108
360*f5b1c8a1SJohn Marino #define UI_F_GENERAL_ALLOCATE_PROMPT			 109
361*f5b1c8a1SJohn Marino #define UI_F_GENERAL_ALLOCATE_STRING			 100
362*f5b1c8a1SJohn Marino #define UI_F_UI_CTRL					 111
363*f5b1c8a1SJohn Marino #define UI_F_UI_DUP_ERROR_STRING			 101
364*f5b1c8a1SJohn Marino #define UI_F_UI_DUP_INFO_STRING				 102
365*f5b1c8a1SJohn Marino #define UI_F_UI_DUP_INPUT_BOOLEAN			 110
366*f5b1c8a1SJohn Marino #define UI_F_UI_DUP_INPUT_STRING			 103
367*f5b1c8a1SJohn Marino #define UI_F_UI_DUP_VERIFY_STRING			 106
368*f5b1c8a1SJohn Marino #define UI_F_UI_GET0_RESULT				 107
369*f5b1c8a1SJohn Marino #define UI_F_UI_NEW_METHOD				 104
370*f5b1c8a1SJohn Marino #define UI_F_UI_SET_RESULT				 105
371*f5b1c8a1SJohn Marino 
372*f5b1c8a1SJohn Marino /* Reason codes. */
373*f5b1c8a1SJohn Marino #define UI_R_COMMON_OK_AND_CANCEL_CHARACTERS		 104
374*f5b1c8a1SJohn Marino #define UI_R_INDEX_TOO_LARGE				 102
375*f5b1c8a1SJohn Marino #define UI_R_INDEX_TOO_SMALL				 103
376*f5b1c8a1SJohn Marino #define UI_R_NO_RESULT_BUFFER				 105
377*f5b1c8a1SJohn Marino #define UI_R_RESULT_TOO_LARGE				 100
378*f5b1c8a1SJohn Marino #define UI_R_RESULT_TOO_SMALL				 101
379*f5b1c8a1SJohn Marino #define UI_R_UNKNOWN_CONTROL_COMMAND			 106
380*f5b1c8a1SJohn Marino 
381*f5b1c8a1SJohn Marino #ifdef  __cplusplus
382*f5b1c8a1SJohn Marino }
383*f5b1c8a1SJohn Marino #endif
384*f5b1c8a1SJohn Marino #endif
385