xref: /dragonfly/crypto/libressl/include/openssl/ui.h (revision de0e0e4d)
1*de0e0e4dSAntonio Huete Jimenez /* $OpenBSD: ui.h,v 1.14 2022/07/12 18:43:56 jsing Exp $ */
2f5b1c8a1SJohn Marino /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3f5b1c8a1SJohn Marino  * project 2001.
4f5b1c8a1SJohn Marino  */
5f5b1c8a1SJohn Marino /* ====================================================================
6f5b1c8a1SJohn Marino  * Copyright (c) 2001 The OpenSSL Project.  All rights reserved.
7f5b1c8a1SJohn Marino  *
8f5b1c8a1SJohn Marino  * Redistribution and use in source and binary forms, with or without
9f5b1c8a1SJohn Marino  * modification, are permitted provided that the following conditions
10f5b1c8a1SJohn Marino  * are met:
11f5b1c8a1SJohn Marino  *
12f5b1c8a1SJohn Marino  * 1. Redistributions of source code must retain the above copyright
13f5b1c8a1SJohn Marino  *    notice, this list of conditions and the following disclaimer.
14f5b1c8a1SJohn Marino  *
15f5b1c8a1SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
16f5b1c8a1SJohn Marino  *    notice, this list of conditions and the following disclaimer in
17f5b1c8a1SJohn Marino  *    the documentation and/or other materials provided with the
18f5b1c8a1SJohn Marino  *    distribution.
19f5b1c8a1SJohn Marino  *
20f5b1c8a1SJohn Marino  * 3. All advertising materials mentioning features or use of this
21f5b1c8a1SJohn Marino  *    software must display the following acknowledgment:
22f5b1c8a1SJohn Marino  *    "This product includes software developed by the OpenSSL Project
23f5b1c8a1SJohn Marino  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24f5b1c8a1SJohn Marino  *
25f5b1c8a1SJohn Marino  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26f5b1c8a1SJohn Marino  *    endorse or promote products derived from this software without
27f5b1c8a1SJohn Marino  *    prior written permission. For written permission, please contact
28f5b1c8a1SJohn Marino  *    openssl-core@openssl.org.
29f5b1c8a1SJohn Marino  *
30f5b1c8a1SJohn Marino  * 5. Products derived from this software may not be called "OpenSSL"
31f5b1c8a1SJohn Marino  *    nor may "OpenSSL" appear in their names without prior written
32f5b1c8a1SJohn Marino  *    permission of the OpenSSL Project.
33f5b1c8a1SJohn Marino  *
34f5b1c8a1SJohn Marino  * 6. Redistributions of any form whatsoever must retain the following
35f5b1c8a1SJohn Marino  *    acknowledgment:
36f5b1c8a1SJohn Marino  *    "This product includes software developed by the OpenSSL Project
37f5b1c8a1SJohn Marino  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38f5b1c8a1SJohn Marino  *
39f5b1c8a1SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40f5b1c8a1SJohn Marino  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41f5b1c8a1SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42f5b1c8a1SJohn Marino  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43f5b1c8a1SJohn Marino  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44f5b1c8a1SJohn Marino  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45f5b1c8a1SJohn Marino  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46f5b1c8a1SJohn Marino  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47f5b1c8a1SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48f5b1c8a1SJohn Marino  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49f5b1c8a1SJohn Marino  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50f5b1c8a1SJohn Marino  * OF THE POSSIBILITY OF SUCH DAMAGE.
51f5b1c8a1SJohn Marino  * ====================================================================
52f5b1c8a1SJohn Marino  *
53f5b1c8a1SJohn Marino  * This product includes cryptographic software written by Eric Young
54f5b1c8a1SJohn Marino  * (eay@cryptsoft.com).  This product includes software written by Tim
55f5b1c8a1SJohn Marino  * Hudson (tjh@cryptsoft.com).
56f5b1c8a1SJohn Marino  *
57f5b1c8a1SJohn Marino  */
58f5b1c8a1SJohn Marino 
59f5b1c8a1SJohn Marino #ifndef HEADER_UI_H
60f5b1c8a1SJohn Marino #define HEADER_UI_H
61f5b1c8a1SJohn Marino 
62f5b1c8a1SJohn Marino #include <openssl/opensslconf.h>
63f5b1c8a1SJohn Marino 
64f5b1c8a1SJohn Marino #ifndef OPENSSL_NO_DEPRECATED
65f5b1c8a1SJohn Marino #include <openssl/crypto.h>
66f5b1c8a1SJohn Marino #endif
67f5b1c8a1SJohn Marino #include <openssl/safestack.h>
68f5b1c8a1SJohn Marino #include <openssl/ossl_typ.h>
69f5b1c8a1SJohn Marino 
70f5b1c8a1SJohn Marino #ifdef  __cplusplus
71f5b1c8a1SJohn Marino extern "C" {
72f5b1c8a1SJohn Marino #endif
73f5b1c8a1SJohn Marino 
74f5b1c8a1SJohn Marino /* Declared already in ossl_typ.h */
75f5b1c8a1SJohn Marino /* typedef struct ui_st UI; */
76f5b1c8a1SJohn Marino /* typedef struct ui_method_st UI_METHOD; */
77f5b1c8a1SJohn Marino 
78f5b1c8a1SJohn Marino 
798edacedfSDaniel Fojt /*
808edacedfSDaniel Fojt  * All the following functions return -1 or NULL on error and in some cases
818edacedfSDaniel Fojt  * (UI_process()) -2 if interrupted or in some other way cancelled.
828edacedfSDaniel Fojt  * When everything is fine, they return 0, a positive value or a non-NULL
838edacedfSDaniel Fojt  * pointer, all depending on their purpose.
848edacedfSDaniel Fojt  */
85f5b1c8a1SJohn Marino 
86f5b1c8a1SJohn Marino /* Creators and destructor.   */
87f5b1c8a1SJohn Marino UI *UI_new(void);
88f5b1c8a1SJohn Marino UI *UI_new_method(const UI_METHOD *method);
89f5b1c8a1SJohn Marino void UI_free(UI *ui);
90f5b1c8a1SJohn Marino 
918edacedfSDaniel Fojt /*
928edacedfSDaniel Fojt  * The following functions are used to add strings to be printed and prompt
938edacedfSDaniel Fojt  * strings to prompt for data.  The names are UI_{add,dup}_<function>_string
948edacedfSDaniel Fojt  * and UI_{add,dup}_input_boolean.
958edacedfSDaniel Fojt  *
968edacedfSDaniel Fojt  * UI_{add,dup}_<function>_string have the following meanings:
978edacedfSDaniel Fojt  *	add	add a text or prompt string.  The pointers given to these
988edacedfSDaniel Fojt  *		functions are used verbatim, no copying is done.
998edacedfSDaniel Fojt  *	dup	make a copy of the text or prompt string, then add the copy
1008edacedfSDaniel Fojt  *		to the collection of strings in the user interface.
1018edacedfSDaniel Fojt  *	<function>
1028edacedfSDaniel Fojt  *		The function is a name for the functionality that the given
1038edacedfSDaniel Fojt  *		string shall be used for.  It can be one of:
1048edacedfSDaniel Fojt  *			input	use the string as data prompt.
1058edacedfSDaniel Fojt  *			verify	use the string as verification prompt.  This
1068edacedfSDaniel Fojt  *				is used to verify a previous input.
1078edacedfSDaniel Fojt  *			info	use the string for informational output.
1088edacedfSDaniel Fojt  *			error	use the string for error output.
1098edacedfSDaniel Fojt  * Honestly, there's currently no difference between info and error for the
1108edacedfSDaniel Fojt  * moment.
1118edacedfSDaniel Fojt  *
1128edacedfSDaniel Fojt  * UI_{add,dup}_input_boolean have the same semantics for "add" and "dup",
1138edacedfSDaniel Fojt  * and are typically used when one wants to prompt for a yes/no response.
1148edacedfSDaniel Fojt  *
1158edacedfSDaniel Fojt  * All of the functions in this group take a UI and a prompt string.
1168edacedfSDaniel Fojt  * The string input and verify addition functions also take a flag argument,
1178edacedfSDaniel Fojt  * a buffer for the result to end up in, a minimum input size and a maximum
1188edacedfSDaniel Fojt  * input size (the result buffer MUST be large enough to be able to contain
1198edacedfSDaniel Fojt  * the maximum number of characters).  Additionally, the verify addition
1208edacedfSDaniel Fojt  * functions takes another buffer to compare the result against.
1218edacedfSDaniel Fojt  * The boolean input functions take an action description string (which should
1228edacedfSDaniel Fojt  * be safe to ignore if the expected user action is obvious, for example with
1238edacedfSDaniel Fojt  * a dialog box with an OK button and a Cancel button), a string of acceptable
1248edacedfSDaniel Fojt  * characters to mean OK and to mean Cancel.  The two last strings are checked
1258edacedfSDaniel Fojt  * to make sure they don't have common characters.  Additionally, the same
1268edacedfSDaniel Fojt  * flag argument as for the string input is taken, as well as a result buffer.
1278edacedfSDaniel Fojt  * The result buffer is required to be at least one byte long.  Depending on
1288edacedfSDaniel Fojt  * the answer, the first character from the OK or the Cancel character strings
1298edacedfSDaniel Fojt  * will be stored in the first byte of the result buffer.  No NUL will be
1308edacedfSDaniel Fojt  * added, so the result is *not* a string.
1318edacedfSDaniel Fojt  *
1328edacedfSDaniel Fojt  * On success, the functions all return an index of the added information.
1338edacedfSDaniel Fojt  * That index is useful when retrieving results with UI_get0_result().
1348edacedfSDaniel Fojt  */
135f5b1c8a1SJohn Marino int UI_add_input_string(UI *ui, const char *prompt, int flags,
136f5b1c8a1SJohn Marino     char *result_buf, int minsize, int maxsize);
137f5b1c8a1SJohn Marino int UI_dup_input_string(UI *ui, const char *prompt, int flags,
138f5b1c8a1SJohn Marino     char *result_buf, int minsize, int maxsize);
139f5b1c8a1SJohn Marino int UI_add_verify_string(UI *ui, const char *prompt, int flags,
140f5b1c8a1SJohn Marino     char *result_buf, int minsize, int maxsize, const char *test_buf);
141f5b1c8a1SJohn Marino int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
142f5b1c8a1SJohn Marino     char *result_buf, int minsize, int maxsize, const char *test_buf);
143f5b1c8a1SJohn Marino int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
144f5b1c8a1SJohn Marino     const char *ok_chars, const char *cancel_chars,
145f5b1c8a1SJohn Marino     int flags, char *result_buf);
146f5b1c8a1SJohn Marino int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
147f5b1c8a1SJohn Marino     const char *ok_chars, const char *cancel_chars,
148f5b1c8a1SJohn Marino     int flags, char *result_buf);
149f5b1c8a1SJohn Marino int UI_add_info_string(UI *ui, const char *text);
150f5b1c8a1SJohn Marino int UI_dup_info_string(UI *ui, const char *text);
151f5b1c8a1SJohn Marino int UI_add_error_string(UI *ui, const char *text);
152f5b1c8a1SJohn Marino int UI_dup_error_string(UI *ui, const char *text);
153f5b1c8a1SJohn Marino 
154f5b1c8a1SJohn Marino /* These are the possible flags.  They can be or'ed together. */
155f5b1c8a1SJohn Marino /* Use to have echoing of input */
156f5b1c8a1SJohn Marino #define UI_INPUT_FLAG_ECHO		0x01
1578edacedfSDaniel Fojt /*
1588edacedfSDaniel Fojt  * Use a default password.  Where that password is found is completely
1598edacedfSDaniel Fojt  * up to the application, it might for example be in the user data set
1608edacedfSDaniel Fojt  * with UI_add_user_data().  It is not recommended to have more than
1618edacedfSDaniel Fojt  * one input in each UI being marked with this flag, or the application
1628edacedfSDaniel Fojt  * might get confused.
1638edacedfSDaniel Fojt  */
164f5b1c8a1SJohn Marino #define UI_INPUT_FLAG_DEFAULT_PWD	0x02
165f5b1c8a1SJohn Marino 
1668edacedfSDaniel Fojt /*
1678edacedfSDaniel Fojt  * Users of these routines may want to define flags of their own.  The core
1688edacedfSDaniel Fojt  * UI won't look at those, but will pass them on to the method routines.  They
1698edacedfSDaniel Fojt  * must use higher bits so they don't get confused with the UI bits above.
1708edacedfSDaniel Fojt  * UI_INPUT_FLAG_USER_BASE tells which is the lowest bit to use.  A good
1718edacedfSDaniel Fojt  * example of use is this:
1728edacedfSDaniel Fojt  *
1738edacedfSDaniel Fojt  *	#define MY_UI_FLAG1	(0x01 << UI_INPUT_FLAG_USER_BASE)
174f5b1c8a1SJohn Marino  */
175f5b1c8a1SJohn Marino #define UI_INPUT_FLAG_USER_BASE	16
176f5b1c8a1SJohn Marino 
177f5b1c8a1SJohn Marino 
1788edacedfSDaniel Fojt /*
1798edacedfSDaniel Fojt  * The following function helps construct a prompt.  object_desc is a
1808edacedfSDaniel Fojt  * textual short description of the object, for example "pass phrase",
1818edacedfSDaniel Fojt  * and object_name is the name of the object (might be a card name or
1828edacedfSDaniel Fojt  * a file name.
1838edacedfSDaniel Fojt  * The returned string shall always be allocated on the heap with
1848edacedfSDaniel Fojt  * malloc(), and need to be free'd with free().
1858edacedfSDaniel Fojt  *
1868edacedfSDaniel Fojt  * If the ui_method doesn't contain a pointer to a user-defined prompt
1878edacedfSDaniel Fojt  * constructor, a default string is built, looking like this:
1888edacedfSDaniel Fojt  *
1898edacedfSDaniel Fojt  *	"Enter {object_desc} for {object_name}:"
1908edacedfSDaniel Fojt  *
1918edacedfSDaniel Fojt  * So, if object_desc has the value "pass phrase" and object_name has
1928edacedfSDaniel Fojt  * the value "foo.key", the resulting string is:
1938edacedfSDaniel Fojt  *
1948edacedfSDaniel Fojt  *	"Enter pass phrase for foo.key:"
195f5b1c8a1SJohn Marino  */
196f5b1c8a1SJohn Marino char *UI_construct_prompt(UI *ui_method, const char *object_desc,
197f5b1c8a1SJohn Marino     const char *object_name);
198f5b1c8a1SJohn Marino 
199f5b1c8a1SJohn Marino 
2008edacedfSDaniel Fojt /*
2018edacedfSDaniel Fojt  * The following function is used to store a pointer to user-specific data.
2028edacedfSDaniel Fojt  * Any previous such pointer will be returned and replaced.
2038edacedfSDaniel Fojt  *
2048edacedfSDaniel Fojt  * For callback purposes, this function makes a lot more sense than using
2058edacedfSDaniel Fojt  * ex_data, since the latter requires that different parts of OpenSSL or
2068edacedfSDaniel Fojt  * applications share the same ex_data index.
2078edacedfSDaniel Fojt  *
2088edacedfSDaniel Fojt  * Note that the UI_OpenSSL() method completely ignores the user data.
2098edacedfSDaniel Fojt  * Other methods may not, however.
2108edacedfSDaniel Fojt  */
211f5b1c8a1SJohn Marino void *UI_add_user_data(UI *ui, void *user_data);
212f5b1c8a1SJohn Marino /* We need a user data retrieving function as well.  */
213f5b1c8a1SJohn Marino void *UI_get0_user_data(UI *ui);
214f5b1c8a1SJohn Marino 
215f5b1c8a1SJohn Marino /* Return the result associated with a prompt given with the index i. */
216f5b1c8a1SJohn Marino const char *UI_get0_result(UI *ui, int i);
217f5b1c8a1SJohn Marino 
218f5b1c8a1SJohn Marino /* When all strings have been added, process the whole thing. */
219f5b1c8a1SJohn Marino int UI_process(UI *ui);
220f5b1c8a1SJohn Marino 
2218edacedfSDaniel Fojt /*
2228edacedfSDaniel Fojt  * Give a user interface parametrised control commands.  This can be used to
2238edacedfSDaniel Fojt  * send down an integer, a data pointer or a function pointer, as well as
2248edacedfSDaniel Fojt  * be used to get information from a UI.
2258edacedfSDaniel Fojt  */
226f5b1c8a1SJohn Marino int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void));
227f5b1c8a1SJohn Marino 
228f5b1c8a1SJohn Marino /* The commands */
2298edacedfSDaniel Fojt /*
2308edacedfSDaniel Fojt  * Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the
2318edacedfSDaniel Fojt  * OpenSSL error stack before printing any info or added error messages and
2328edacedfSDaniel Fojt  * before any prompting.
2338edacedfSDaniel Fojt  */
234f5b1c8a1SJohn Marino #define UI_CTRL_PRINT_ERRORS		1
2358edacedfSDaniel Fojt /*
2368edacedfSDaniel Fojt  * Check if a UI_process() is possible to do again with the same instance of
2378edacedfSDaniel Fojt  * a user interface.  This makes UI_ctrl() return 1 if it is redoable, and 0
2388edacedfSDaniel Fojt  * if not.
2398edacedfSDaniel Fojt  */
240f5b1c8a1SJohn Marino #define UI_CTRL_IS_REDOABLE		2
241f5b1c8a1SJohn Marino 
242f5b1c8a1SJohn Marino 
243f5b1c8a1SJohn Marino /* Some methods may use extra data */
244f5b1c8a1SJohn Marino #define UI_set_app_data(s,arg)         UI_set_ex_data(s,0,arg)
245f5b1c8a1SJohn Marino #define UI_get_app_data(s)             UI_get_ex_data(s,0)
246f5b1c8a1SJohn Marino int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
247f5b1c8a1SJohn Marino     CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
248f5b1c8a1SJohn Marino int UI_set_ex_data(UI *r, int idx, void *arg);
249f5b1c8a1SJohn Marino void *UI_get_ex_data(UI *r, int idx);
250f5b1c8a1SJohn Marino 
251f5b1c8a1SJohn Marino /* Use specific methods instead of the built-in one */
252f5b1c8a1SJohn Marino void UI_set_default_method(const UI_METHOD *meth);
253f5b1c8a1SJohn Marino const UI_METHOD *UI_get_default_method(void);
254f5b1c8a1SJohn Marino const UI_METHOD *UI_get_method(UI *ui);
255f5b1c8a1SJohn Marino const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth);
256f5b1c8a1SJohn Marino 
257f5b1c8a1SJohn Marino /* The method with all the built-in thingies */
258f5b1c8a1SJohn Marino UI_METHOD *UI_OpenSSL(void);
259f5b1c8a1SJohn Marino 
260f5b1c8a1SJohn Marino 
2618edacedfSDaniel Fojt /*
2628edacedfSDaniel Fojt  * ---------- For method writers ----------
2638edacedfSDaniel Fojt  * A method contains a number of functions that implement the low level
2648edacedfSDaniel Fojt  * of the User Interface.  The functions are:
2658edacedfSDaniel Fojt  *
2668edacedfSDaniel Fojt  *	an opener	This function starts a session, maybe by opening
2678edacedfSDaniel Fojt  *			a channel to a tty, or by opening a window.
2688edacedfSDaniel Fojt  *	a writer	This function is called to write a given string,
2698edacedfSDaniel Fojt  *			maybe to the tty, maybe as a field label in a
2708edacedfSDaniel Fojt  *			window.
2718edacedfSDaniel Fojt  *	a flusher	This function is called to flush everything that
2728edacedfSDaniel Fojt  *			has been output so far.  It can be used to actually
2738edacedfSDaniel Fojt  *			display a dialog box after it has been built.
2748edacedfSDaniel Fojt  *	a reader	This function is called to read a given prompt,
2758edacedfSDaniel Fojt  *			maybe from the tty, maybe from a field in a
2768edacedfSDaniel Fojt  *			window.  Note that it's called wth all string
2778edacedfSDaniel Fojt  *			structures, not only the prompt ones, so it must
2788edacedfSDaniel Fojt  *			check such things itself.
2798edacedfSDaniel Fojt  *	a closer	This function closes the session, maybe by closing
2808edacedfSDaniel Fojt  *			the channel to the tty, or closing the window.
2818edacedfSDaniel Fojt  *
2828edacedfSDaniel Fojt  * All these functions are expected to return:
2838edacedfSDaniel Fojt  *
2848edacedfSDaniel Fojt  *	 0	on error.
2858edacedfSDaniel Fojt  *	 1	on success.
2868edacedfSDaniel Fojt  *	-1	on out-of-band events, for example if some prompting has
2878edacedfSDaniel Fojt  *		been canceled (by pressing Ctrl-C, for example).  This is
2888edacedfSDaniel Fojt  *		only checked when returned by the flusher or the reader.
2898edacedfSDaniel Fojt  *
2908edacedfSDaniel Fojt  * The way this is used, the opener is first called, then the writer for all
2918edacedfSDaniel Fojt  * strings, then the flusher, then the reader for all strings and finally the
2928edacedfSDaniel Fojt  * closer.  Note that if you want to prompt from a terminal or other command
2938edacedfSDaniel Fojt  * line interface, the best is to have the reader also write the prompts
2948edacedfSDaniel Fojt  * instead of having the writer do it.  If you want to prompt from a dialog
2958edacedfSDaniel Fojt  * box, the writer can be used to build up the contents of the box, and the
2968edacedfSDaniel Fojt  * flusher to actually display the box and run the event loop until all data
2978edacedfSDaniel Fojt  * has been given, after which the reader only grabs the given data and puts
2988edacedfSDaniel Fojt  * them back into the UI strings.
2998edacedfSDaniel Fojt  *
3008edacedfSDaniel Fojt  * All method functions take a UI as argument.  Additionally, the writer and
3018edacedfSDaniel Fojt  * the reader take a UI_STRING.
302f5b1c8a1SJohn Marino  */
303f5b1c8a1SJohn Marino 
3048edacedfSDaniel Fojt /*
3058edacedfSDaniel Fojt  * The UI_STRING type is the data structure that contains all the needed info
3068edacedfSDaniel Fojt  * about a string or a prompt, including test data for a verification prompt.
307f5b1c8a1SJohn Marino  */
308f5b1c8a1SJohn Marino typedef struct ui_string_st UI_STRING;
309f5b1c8a1SJohn Marino DECLARE_STACK_OF(UI_STRING)
310f5b1c8a1SJohn Marino 
3118edacedfSDaniel Fojt /*
3128edacedfSDaniel Fojt  * The different types of strings that are currently supported.
3138edacedfSDaniel Fojt  * This is only needed by method authors.
3148edacedfSDaniel Fojt  */
315f5b1c8a1SJohn Marino enum UI_string_types {
316f5b1c8a1SJohn Marino 	UIT_NONE = 0,
317f5b1c8a1SJohn Marino 	UIT_PROMPT,		/* Prompt for a string */
318f5b1c8a1SJohn Marino 	UIT_VERIFY,		/* Prompt for a string and verify */
319f5b1c8a1SJohn Marino 	UIT_BOOLEAN,		/* Prompt for a yes/no response */
320f5b1c8a1SJohn Marino 	UIT_INFO,		/* Send info to the user */
321f5b1c8a1SJohn Marino 	UIT_ERROR		/* Send an error message to the user */
322f5b1c8a1SJohn Marino };
323f5b1c8a1SJohn Marino 
324f5b1c8a1SJohn Marino /* Create and manipulate methods */
32572c33676SMaxim Ag UI_METHOD *UI_create_method(const char *name);
326f5b1c8a1SJohn Marino void UI_destroy_method(UI_METHOD *ui_method);
327f5b1c8a1SJohn Marino int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui));
3288edacedfSDaniel Fojt int UI_method_set_writer(UI_METHOD *method,
3298edacedfSDaniel Fojt     int (*writer)(UI *ui, UI_STRING *uis));
330f5b1c8a1SJohn Marino int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui));
3318edacedfSDaniel Fojt int UI_method_set_reader(UI_METHOD *method,
3328edacedfSDaniel Fojt     int (*reader)(UI *ui, UI_STRING *uis));
333f5b1c8a1SJohn Marino int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui));
3348edacedfSDaniel Fojt int UI_method_set_prompt_constructor(UI_METHOD *method,
3358edacedfSDaniel Fojt     char *(*prompt_constructor)(UI *ui, const char *object_desc,
3368edacedfSDaniel Fojt     const char *object_name));
33772c33676SMaxim Ag int (*UI_method_get_opener(const UI_METHOD *method))(UI *);
33872c33676SMaxim Ag int (*UI_method_get_writer(const UI_METHOD *method))(UI *, UI_STRING *);
33972c33676SMaxim Ag int (*UI_method_get_flusher(const UI_METHOD *method))(UI *);
34072c33676SMaxim Ag int (*UI_method_get_reader(const UI_METHOD *method))(UI *, UI_STRING *);
34172c33676SMaxim Ag int (*UI_method_get_closer(const UI_METHOD *method))(UI *);
3428edacedfSDaniel Fojt char *(*UI_method_get_prompt_constructor(const UI_METHOD *method))(UI *,
3438edacedfSDaniel Fojt     const char *, const char *);
344f5b1c8a1SJohn Marino 
3458edacedfSDaniel Fojt /*
3468edacedfSDaniel Fojt  * The following functions are helpers for method writers to access relevant
3478edacedfSDaniel Fojt  * data from a UI_STRING.
3488edacedfSDaniel Fojt  */
349f5b1c8a1SJohn Marino /* Return type of the UI_STRING */
350f5b1c8a1SJohn Marino enum UI_string_types UI_get_string_type(UI_STRING *uis);
351f5b1c8a1SJohn Marino /* Return input flags of the UI_STRING */
352f5b1c8a1SJohn Marino int UI_get_input_flags(UI_STRING *uis);
353f5b1c8a1SJohn Marino /* Return the actual string to output (the prompt, info or error) */
354f5b1c8a1SJohn Marino const char *UI_get0_output_string(UI_STRING *uis);
3558edacedfSDaniel Fojt /* Return the optional action string to output (boolean prompt instruction) */
356f5b1c8a1SJohn Marino const char *UI_get0_action_string(UI_STRING *uis);
357f5b1c8a1SJohn Marino /* Return the result of a prompt */
358f5b1c8a1SJohn Marino const char *UI_get0_result_string(UI_STRING *uis);
359f5b1c8a1SJohn Marino /* Return the string to test the result against.  Only useful with verifies. */
360f5b1c8a1SJohn Marino const char *UI_get0_test_string(UI_STRING *uis);
361f5b1c8a1SJohn Marino /* Return the required minimum size of the result */
362f5b1c8a1SJohn Marino int UI_get_result_minsize(UI_STRING *uis);
363f5b1c8a1SJohn Marino /* Return the required maximum size of the result */
364f5b1c8a1SJohn Marino int UI_get_result_maxsize(UI_STRING *uis);
365f5b1c8a1SJohn Marino /* Set the result of a UI_STRING. */
366f5b1c8a1SJohn Marino int UI_set_result(UI *ui, UI_STRING *uis, const char *result);
367f5b1c8a1SJohn Marino 
368f5b1c8a1SJohn Marino /* A couple of popular utility functions */
3698edacedfSDaniel Fojt int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt,
3708edacedfSDaniel Fojt     int verify);
3718edacedfSDaniel Fojt int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt,
3728edacedfSDaniel Fojt     int verify);
373f5b1c8a1SJohn Marino 
374f5b1c8a1SJohn Marino void ERR_load_UI_strings(void);
375f5b1c8a1SJohn Marino 
376f5b1c8a1SJohn Marino /* Error codes for the UI functions. */
377f5b1c8a1SJohn Marino 
378f5b1c8a1SJohn Marino /* Function codes. */
379f5b1c8a1SJohn Marino #define UI_F_GENERAL_ALLOCATE_BOOLEAN			 108
380f5b1c8a1SJohn Marino #define UI_F_GENERAL_ALLOCATE_PROMPT			 109
381f5b1c8a1SJohn Marino #define UI_F_GENERAL_ALLOCATE_STRING			 100
382f5b1c8a1SJohn Marino #define UI_F_UI_CTRL					 111
383f5b1c8a1SJohn Marino #define UI_F_UI_DUP_ERROR_STRING			 101
384f5b1c8a1SJohn Marino #define UI_F_UI_DUP_INFO_STRING				 102
385f5b1c8a1SJohn Marino #define UI_F_UI_DUP_INPUT_BOOLEAN			 110
386f5b1c8a1SJohn Marino #define UI_F_UI_DUP_INPUT_STRING			 103
387f5b1c8a1SJohn Marino #define UI_F_UI_DUP_VERIFY_STRING			 106
388f5b1c8a1SJohn Marino #define UI_F_UI_GET0_RESULT				 107
389f5b1c8a1SJohn Marino #define UI_F_UI_NEW_METHOD				 104
390f5b1c8a1SJohn Marino #define UI_F_UI_SET_RESULT				 105
391f5b1c8a1SJohn Marino 
392f5b1c8a1SJohn Marino /* Reason codes. */
393f5b1c8a1SJohn Marino #define UI_R_COMMON_OK_AND_CANCEL_CHARACTERS		 104
394f5b1c8a1SJohn Marino #define UI_R_INDEX_TOO_LARGE				 102
395f5b1c8a1SJohn Marino #define UI_R_INDEX_TOO_SMALL				 103
396f5b1c8a1SJohn Marino #define UI_R_NO_RESULT_BUFFER				 105
397f5b1c8a1SJohn Marino #define UI_R_RESULT_TOO_LARGE				 100
398f5b1c8a1SJohn Marino #define UI_R_RESULT_TOO_SMALL				 101
399f5b1c8a1SJohn Marino #define UI_R_UNKNOWN_CONTROL_COMMAND			 106
400f5b1c8a1SJohn Marino 
401f5b1c8a1SJohn Marino #ifdef  __cplusplus
402f5b1c8a1SJohn Marino }
403f5b1c8a1SJohn Marino #endif
404f5b1c8a1SJohn Marino #endif
405