1295016Sjkim/* crypto/ui/ui.h */
2280304Sjkim/*
3280304Sjkim * Written by Richard Levitte (richard@levitte.org) for the OpenSSL project
4280304Sjkim * 2001.
5109998Smarkm */
6109998Smarkm/* ====================================================================
7109998Smarkm * Copyright (c) 2001 The OpenSSL Project.  All rights reserved.
8109998Smarkm *
9109998Smarkm * Redistribution and use in source and binary forms, with or without
10109998Smarkm * modification, are permitted provided that the following conditions
11109998Smarkm * are met:
12109998Smarkm *
13109998Smarkm * 1. Redistributions of source code must retain the above copyright
14280304Sjkim *    notice, this list of conditions and the following disclaimer.
15109998Smarkm *
16109998Smarkm * 2. Redistributions in binary form must reproduce the above copyright
17109998Smarkm *    notice, this list of conditions and the following disclaimer in
18109998Smarkm *    the documentation and/or other materials provided with the
19109998Smarkm *    distribution.
20109998Smarkm *
21109998Smarkm * 3. All advertising materials mentioning features or use of this
22109998Smarkm *    software must display the following acknowledgment:
23109998Smarkm *    "This product includes software developed by the OpenSSL Project
24109998Smarkm *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25109998Smarkm *
26109998Smarkm * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27109998Smarkm *    endorse or promote products derived from this software without
28109998Smarkm *    prior written permission. For written permission, please contact
29109998Smarkm *    openssl-core@openssl.org.
30109998Smarkm *
31109998Smarkm * 5. Products derived from this software may not be called "OpenSSL"
32109998Smarkm *    nor may "OpenSSL" appear in their names without prior written
33109998Smarkm *    permission of the OpenSSL Project.
34109998Smarkm *
35109998Smarkm * 6. Redistributions of any form whatsoever must retain the following
36109998Smarkm *    acknowledgment:
37109998Smarkm *    "This product includes software developed by the OpenSSL Project
38109998Smarkm *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39109998Smarkm *
40109998Smarkm * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41109998Smarkm * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42109998Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43109998Smarkm * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
44109998Smarkm * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45109998Smarkm * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46109998Smarkm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47109998Smarkm * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48109998Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49109998Smarkm * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50109998Smarkm * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51109998Smarkm * OF THE POSSIBILITY OF SUCH DAMAGE.
52109998Smarkm * ====================================================================
53109998Smarkm *
54109998Smarkm * This product includes cryptographic software written by Eric Young
55109998Smarkm * (eay@cryptsoft.com).  This product includes software written by Tim
56109998Smarkm * Hudson (tjh@cryptsoft.com).
57109998Smarkm *
58109998Smarkm */
59109998Smarkm
60109998Smarkm#ifndef HEADER_UI_LOCL_H
61280304Sjkim# define HEADER_UI_LOCL_H
62109998Smarkm
63280304Sjkim# include <openssl/ui.h>
64280304Sjkim# include <openssl/crypto.h>
65109998Smarkm
66280304Sjkim# ifdef _
67280304Sjkim#  undef _
68280304Sjkim# endif
69160814Ssimon
70280304Sjkimstruct ui_method_st {
71280304Sjkim    char *name;
72280304Sjkim    /*
73280304Sjkim     * All the functions return 1 or non-NULL for success and 0 or NULL for
74280304Sjkim     * failure
75280304Sjkim     */
76280304Sjkim    /*
77280304Sjkim     * Open whatever channel for this, be it the console, an X window or
78280304Sjkim     * whatever. This function should use the ex_data structure to save
79280304Sjkim     * intermediate data.
80280304Sjkim     */
81280304Sjkim    int (*ui_open_session) (UI *ui);
82280304Sjkim    int (*ui_write_string) (UI *ui, UI_STRING *uis);
83280304Sjkim    /*
84280304Sjkim     * Flush the output.  If a GUI dialog box is used, this function can be
85280304Sjkim     * used to actually display it.
86280304Sjkim     */
87280304Sjkim    int (*ui_flush) (UI *ui);
88280304Sjkim    int (*ui_read_string) (UI *ui, UI_STRING *uis);
89280304Sjkim    int (*ui_close_session) (UI *ui);
90280304Sjkim    /*
91280304Sjkim     * Construct a prompt in a user-defined manner.  object_desc is a textual
92280304Sjkim     * short description of the object, for example "pass phrase", and
93280304Sjkim     * object_name is the name of the object (might be a card name or a file
94280304Sjkim     * name. The returned string shall always be allocated on the heap with
95280304Sjkim     * OPENSSL_malloc(), and need to be free'd with OPENSSL_free().
96280304Sjkim     */
97280304Sjkim    char *(*ui_construct_prompt) (UI *ui, const char *object_desc,
98280304Sjkim                                  const char *object_name);
99280304Sjkim};
100109998Smarkm
101280304Sjkimstruct ui_string_st {
102280304Sjkim    enum UI_string_types type;  /* Input */
103280304Sjkim    const char *out_string;     /* Input */
104280304Sjkim    int input_flags;            /* Flags from the user */
105280304Sjkim    /*
106280304Sjkim     * The following parameters are completely irrelevant for UIT_INFO, and
107280304Sjkim     * can therefore be set to 0 or NULL
108280304Sjkim     */
109280304Sjkim    char *result_buf;           /* Input and Output: If not NULL,
110280304Sjkim                                 * user-defined with size in result_maxsize.
111280304Sjkim                                 * Otherwise, it may be allocated by the UI
112280304Sjkim                                 * routine, meaning result_minsize is going
113280304Sjkim                                 * to be overwritten. */
114280304Sjkim    union {
115280304Sjkim        struct {
116280304Sjkim            int result_minsize; /* Input: minimum required size of the
117280304Sjkim                                 * result. */
118280304Sjkim            int result_maxsize; /* Input: maximum permitted size of the
119280304Sjkim                                 * result */
120280304Sjkim            const char *test_buf; /* Input: test string to verify against */
121280304Sjkim        } string_data;
122280304Sjkim        struct {
123280304Sjkim            const char *action_desc; /* Input */
124280304Sjkim            const char *ok_chars; /* Input */
125280304Sjkim            const char *cancel_chars; /* Input */
126280304Sjkim        } boolean_data;
127280304Sjkim    } _;
128109998Smarkm
129280304Sjkim# define OUT_STRING_FREEABLE 0x01
130280304Sjkim    int flags;                  /* flags for internal use */
131280304Sjkim};
132109998Smarkm
133280304Sjkimstruct ui_st {
134280304Sjkim    const UI_METHOD *meth;
135280304Sjkim    STACK_OF(UI_STRING) *strings; /* We might want to prompt for more than
136280304Sjkim                                   * one thing at a time, and with different
137280304Sjkim                                   * echoing status.  */
138280304Sjkim    void *user_data;
139280304Sjkim    CRYPTO_EX_DATA ex_data;
140280304Sjkim# define UI_FLAG_REDOABLE        0x0001
141280304Sjkim# define UI_FLAG_PRINT_ERRORS    0x0100
142280304Sjkim    int flags;
143280304Sjkim};
144109998Smarkm
145109998Smarkm#endif
146