1178355Ssam/* crypto/conf/conf.h */
2178355Ssam/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3178355Ssam * All rights reserved.
4208060Sdougb *
5178355Ssam * This package is an SSL implementation written
6178355Ssam * by Eric Young (eay@cryptsoft.com).
7178355Ssam * The implementation was written so as to conform with Netscapes SSL.
8178355Ssam *
9178355Ssam * This library is free for commercial and non-commercial use as long as
10178355Ssam * the following conditions are aheared to.  The following conditions
11178355Ssam * apply to all code found in this distribution, be it the RC4, RSA,
12178355Ssam * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13208060Sdougb * included with this distribution is covered by the same copyright terms
14178355Ssam * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15178355Ssam *
16178355Ssam * Copyright remains Eric Young's, and as such any Copyright notices in
17178355Ssam * the code are not to be removed.
18178355Ssam * If this package is used in a product, Eric Young should be given attribution
19178355Ssam * as the author of the parts of the library used.
20178355Ssam * This can be in the form of a textual message at program startup or
21178355Ssam * in documentation (online or textual) provided with the package.
22178355Ssam *
23178355Ssam * Redistribution and use in source and binary forms, with or without
24208060Sdougb * modification, are permitted provided that the following conditions
25178355Ssam * are met:
26178355Ssam * 1. Redistributions of source code must retain the copyright
27178355Ssam *    notice, this list of conditions and the following disclaimer.
28178355Ssam * 2. Redistributions in binary form must reproduce the above copyright
29178355Ssam *    notice, this list of conditions and the following disclaimer in the
30178355Ssam *    documentation and/or other materials provided with the distribution.
31178355Ssam * 3. All advertising materials mentioning features or use of this software
32178355Ssam *    must display the following acknowledgement:
33178355Ssam *    "This product includes cryptographic software written by
34178355Ssam *     Eric Young (eay@cryptsoft.com)"
35178355Ssam *    The word 'cryptographic' can be left out if the rouines from the library
36178355Ssam *    being used are not cryptographic related :-).
37178355Ssam * 4. If you include any Windows specific code (or a derivative thereof) from
38178355Ssam *    the apps directory (application code) you must include an acknowledgement:
39178355Ssam *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40178355Ssam *
41178355Ssam * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42186106Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43178355Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44178355Ssam * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45178355Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46178355Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47178355Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48178355Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49178355Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50178355Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51178355Ssam * SUCH DAMAGE.
52178355Ssam *
53178355Ssam * The licence and distribution terms for any publically available version or
54178355Ssam * derivative of this code cannot be changed.  i.e. this code cannot simply be
55178355Ssam * copied and put under another distribution licence
56178355Ssam * [including the GNU Public Licence.]
57178355Ssam */
58178355Ssam
59178355Ssam#ifndef  HEADER_CONF_H
60178355Ssam# define HEADER_CONF_H
61178355Ssam
62178355Ssam# include <openssl/bio.h>
63178355Ssam# include <openssl/lhash.h>
64178355Ssam# include <openssl/stack.h>
65178355Ssam# include <openssl/safestack.h>
66178355Ssam# include <openssl/e_os2.h>
67178355Ssam
68178355Ssam# include <openssl/ossl_typ.h>
69178355Ssam
70178355Ssam#ifdef  __cplusplus
71178355Ssamextern "C" {
72178355Ssam#endif
73178355Ssam
74178355Ssamtypedef struct {
75178355Ssam    char *section;
76178355Ssam    char *name;
77178355Ssam    char *value;
78178355Ssam} CONF_VALUE;
79178355Ssam
80178355SsamDECLARE_STACK_OF(CONF_VALUE)
81178355SsamDECLARE_LHASH_OF(CONF_VALUE);
82178355Ssam
83178355Ssamstruct conf_st;
84178355Ssamstruct conf_method_st;
85178355Ssamtypedef struct conf_method_st CONF_METHOD;
86223497Sadrian
87178355Ssamstruct conf_method_st {
88178355Ssam    const char *name;
89178355Ssam    CONF *(*create) (CONF_METHOD *meth);
90178355Ssam    int (*init) (CONF *conf);
91178355Ssam    int (*destroy) (CONF *conf);
92178355Ssam    int (*destroy_data) (CONF *conf);
93178355Ssam    int (*load_bio) (CONF *conf, BIO *bp, long *eline);
94178355Ssam    int (*dump) (const CONF *conf, BIO *bp);
95178355Ssam    int (*is_number) (const CONF *conf, char c);
96178355Ssam    int (*to_int) (const CONF *conf, char c);
97178355Ssam    int (*load) (CONF *conf, const char *name, long *eline);
98178355Ssam};
99223498Sadrian
100178355Ssam/* Module definitions */
101178355Ssam
102178355Ssamtypedef struct conf_imodule_st CONF_IMODULE;
103178355Ssamtypedef struct conf_module_st CONF_MODULE;
104178355Ssam
105178355SsamDECLARE_STACK_OF(CONF_MODULE)
106178355SsamDECLARE_STACK_OF(CONF_IMODULE)
107178355Ssam
108178355Ssam/* DSO module function typedefs */
109223498Sadriantypedef int conf_init_func (CONF_IMODULE *md, const CONF *cnf);
110178355Ssamtypedef void conf_finish_func (CONF_IMODULE *md);
111178355Ssam
112178355Ssam# define CONF_MFLAGS_IGNORE_ERRORS       0x1
113178355Ssam# define CONF_MFLAGS_IGNORE_RETURN_CODES 0x2
114178355Ssam# define CONF_MFLAGS_SILENT              0x4
115178355Ssam# define CONF_MFLAGS_NO_DSO              0x8
116178355Ssam# define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10
117178355Ssam# define CONF_MFLAGS_DEFAULT_SECTION     0x20
118178355Ssam
119178355Ssamint CONF_set_default_method(CONF_METHOD *meth);
120178355Ssamvoid CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash);
121178355SsamLHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file,
122178355Ssam                                long *eline);
123178355Ssam# ifndef OPENSSL_NO_FP_API
124178355SsamLHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp,
125178355Ssam                                   long *eline);
126178355Ssam# endif
127178355SsamLHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp,
128178355Ssam                                    long *eline);
129178355SsamSTACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf,
130178355Ssam                                       const char *section);
131178355Ssamchar *CONF_get_string(LHASH_OF(CONF_VALUE) *conf, const char *group,
132178355Ssam                      const char *name);
133178355Ssamlong CONF_get_number(LHASH_OF(CONF_VALUE) *conf, const char *group,
134178355Ssam                     const char *name);
135178355Ssamvoid CONF_free(LHASH_OF(CONF_VALUE) *conf);
136178355Ssamint CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out);
137178355Ssamint CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out);
138178355Ssam
139178355Ssamvoid OPENSSL_config(const char *config_name);
140178355Ssamvoid OPENSSL_no_config(void);
141223496Sadrian
142223496Sadrian/*
143223496Sadrian * New conf code.  The semantics are different from the functions above. If
144223496Sadrian * that wasn't the case, the above functions would have been replaced
145223496Sadrian */
146223496Sadrian
147178355Ssamstruct conf_st {
148178355Ssam    CONF_METHOD *meth;
149178355Ssam    void *meth_data;
150178355Ssam    LHASH_OF(CONF_VALUE) *data;
151178355Ssam};
152178355Ssam
153178355SsamCONF *NCONF_new(CONF_METHOD *meth);
154178355SsamCONF_METHOD *NCONF_default(void);
155178355SsamCONF_METHOD *NCONF_WIN32(void);
156178355Ssam# if 0                          /* Just to give you an idea of what I have in
157178355Ssam                                 * mind */
158178355SsamCONF_METHOD *NCONF_XML(void);
159178355Ssam# endif
160178355Ssamvoid NCONF_free(CONF *conf);
161178355Ssamvoid NCONF_free_data(CONF *conf);
162178355Ssam
163178355Ssamint NCONF_load(CONF *conf, const char *file, long *eline);
164178355Ssam# ifndef OPENSSL_NO_FP_API
165178355Ssamint NCONF_load_fp(CONF *conf, FILE *fp, long *eline);
166178355Ssam# endif
167178355Ssamint NCONF_load_bio(CONF *conf, BIO *bp, long *eline);
168178355SsamSTACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,
169178355Ssam                                        const char *section);
170178355Ssamchar *NCONF_get_string(const CONF *conf, const char *group, const char *name);
171178355Ssamint NCONF_get_number_e(const CONF *conf, const char *group, const char *name,
172178355Ssam                       long *result);
173178355Ssamint NCONF_dump_fp(const CONF *conf, FILE *out);
174178355Ssamint NCONF_dump_bio(const CONF *conf, BIO *out);
175178355Ssam
176178355Ssam# if 0                          /* The following function has no error
177178355Ssam                                 * checking, and should therefore be avoided */
178178355Ssamlong NCONF_get_number(CONF *conf, char *group, char *name);
179178355Ssam# else
180178355Ssam#  define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r)
181178355Ssam# endif
182178355Ssam
183178355Ssam/* Module functions */
184178355Ssam
185223496Sadrianint CONF_modules_load(const CONF *cnf, const char *appname,
186223496Sadrian                      unsigned long flags);
187223496Sadrianint CONF_modules_load_file(const char *filename, const char *appname,
188223496Sadrian                           unsigned long flags);
189223496Sadrianvoid CONF_modules_unload(int all);
190223496Sadrianvoid CONF_modules_finish(void);
191223496Sadrianvoid CONF_modules_free(void);
192223496Sadrianint CONF_module_add(const char *name, conf_init_func *ifunc,
193223496Sadrian                    conf_finish_func *ffunc);
194223496Sadrian
195223496Sadrianconst char *CONF_imodule_get_name(const CONF_IMODULE *md);
196223496Sadrianconst char *CONF_imodule_get_value(const CONF_IMODULE *md);
197223496Sadrianvoid *CONF_imodule_get_usr_data(const CONF_IMODULE *md);
198223496Sadrianvoid CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data);
199178355SsamCONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md);
200178355Ssamunsigned long CONF_imodule_get_flags(const CONF_IMODULE *md);
201178355Ssamvoid CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags);
202178355Ssamvoid *CONF_module_get_usr_data(CONF_MODULE *pmod);
203178355Ssamvoid CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data);
204178355Ssam
205178355Ssamchar *CONF_get1_default_config_file(void);
206178355Ssam
207178355Ssamint CONF_parse_list(const char *list, int sep, int nospc,
208178355Ssam                    int (*list_cb) (const char *elem, int len, void *usr),
209178355Ssam                    void *arg);
210178355Ssam
211178355Ssamvoid OPENSSL_load_builtin_modules(void);
212178355Ssam
213187343Ssam/* BEGIN ERROR CODES */
214187343Ssam/*
215187343Ssam * The following lines are auto generated by the script mkerr.pl. Any changes
216187343Ssam * made after this point may be overwritten when the script is next run.
217187343Ssam */
218187343Ssamvoid ERR_load_CONF_strings(void);
219187343Ssam
220187343Ssam/* Error codes for the CONF functions. */
221187343Ssam
222187343Ssam/* Function codes. */
223187343Ssam# define CONF_F_CONF_DUMP_FP                              104
224187343Ssam# define CONF_F_CONF_LOAD                                 100
225187343Ssam# define CONF_F_CONF_LOAD_BIO                             102
226187343Ssam# define CONF_F_CONF_LOAD_FP                              103
227187343Ssam# define CONF_F_CONF_MODULES_LOAD                         116
228187343Ssam# define CONF_F_CONF_PARSE_LIST                           119
229187343Ssam# define CONF_F_DEF_LOAD                                  120
230187343Ssam# define CONF_F_DEF_LOAD_BIO                              121
231187343Ssam# define CONF_F_MODULE_INIT                               115
232187343Ssam# define CONF_F_MODULE_LOAD_DSO                           117
233187343Ssam# define CONF_F_MODULE_RUN                                118
234187343Ssam# define CONF_F_NCONF_DUMP_BIO                            105
235187343Ssam# define CONF_F_NCONF_DUMP_FP                             106
236187343Ssam# define CONF_F_NCONF_GET_NUMBER                          107
237187343Ssam# define CONF_F_NCONF_GET_NUMBER_E                        112
238187343Ssam# define CONF_F_NCONF_GET_SECTION                         108
239187343Ssam# define CONF_F_NCONF_GET_STRING                          109
240187343Ssam# define CONF_F_NCONF_LOAD                                113
241187343Ssam# define CONF_F_NCONF_LOAD_BIO                            110
242187343Ssam# define CONF_F_NCONF_LOAD_FP                             114
243187343Ssam# define CONF_F_NCONF_NEW                                 111
244187343Ssam# define CONF_F_STR_COPY                                  101
245187343Ssam
246187343Ssam/* Reason codes. */
247187343Ssam# define CONF_R_ERROR_LOADING_DSO                         110
248187343Ssam# define CONF_R_LIST_CANNOT_BE_NULL                       115
249187343Ssam# define CONF_R_MISSING_CLOSE_SQUARE_BRACKET              100
250187343Ssam# define CONF_R_MISSING_EQUAL_SIGN                        101
251187343Ssam# define CONF_R_MISSING_FINISH_FUNCTION                   111
252187343Ssam# define CONF_R_MISSING_INIT_FUNCTION                     112
253187343Ssam# define CONF_R_MODULE_INITIALIZATION_ERROR               109
254223504Sadrian# define CONF_R_NO_CLOSE_BRACE                            102
255187343Ssam# define CONF_R_NO_CONF                                   105
256187343Ssam# define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE           106
257187343Ssam# define CONF_R_NO_SECTION                                107
258187343Ssam# define CONF_R_NO_SUCH_FILE                              114
259187343Ssam# define CONF_R_NO_VALUE                                  108
260187343Ssam# define CONF_R_UNABLE_TO_CREATE_NEW_SECTION              103
261187343Ssam# define CONF_R_UNKNOWN_MODULE_NAME                       113
262178355Ssam# define CONF_R_VARIABLE_HAS_NO_VALUE                     104
263178355Ssam
264178355Ssam#ifdef  __cplusplus
265178355Ssam}
266178355Ssam#endif
267178355Ssam#endif
268178355Ssam