Use safestack.h exclusively internally.
[openssl.git] / include / openssl / conf.h
1 /*
2  * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #ifndef  HEADER_CONF_H
11 # define HEADER_CONF_H
12
13 # include <openssl/bio.h>
14 # include <openssl/lhash.h>
15 # include <openssl/e_os2.h>
16 # include <openssl/ossl_typ.h>
17 # include <openssl/conferr.h>
18
19 #ifdef  __cplusplus
20 extern "C" {
21 #endif
22
23 typedef struct {
24     char *section;
25     char *name;
26     char *value;
27 } CONF_VALUE;
28
29 DEFINE_STACK_OF(CONF_VALUE)
30 DEFINE_LHASH_OF(CONF_VALUE);
31
32 struct conf_st;
33 struct conf_method_st;
34 typedef struct conf_method_st CONF_METHOD;
35
36 struct conf_method_st {
37     const char *name;
38     CONF *(*create) (CONF_METHOD *meth);
39     int (*init) (CONF *conf);
40     int (*destroy) (CONF *conf);
41     int (*destroy_data) (CONF *conf);
42     int (*load_bio) (CONF *conf, BIO *bp, long *eline);
43     int (*dump) (const CONF *conf, BIO *bp);
44     int (*is_number) (const CONF *conf, char c);
45     int (*to_int) (const CONF *conf, char c);
46     int (*load) (CONF *conf, const char *name, long *eline);
47 };
48
49 /* Module definitions */
50
51 typedef struct conf_imodule_st CONF_IMODULE;
52 typedef struct conf_module_st CONF_MODULE;
53
54 DEFINE_STACK_OF(CONF_MODULE)
55 DEFINE_STACK_OF(CONF_IMODULE)
56
57 /* DSO module function typedefs */
58 typedef int conf_init_func (CONF_IMODULE *md, const CONF *cnf);
59 typedef void conf_finish_func (CONF_IMODULE *md);
60
61 # define CONF_MFLAGS_IGNORE_ERRORS       0x1
62 # define CONF_MFLAGS_IGNORE_RETURN_CODES 0x2
63 # define CONF_MFLAGS_SILENT              0x4
64 # define CONF_MFLAGS_NO_DSO              0x8
65 # define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10
66 # define CONF_MFLAGS_DEFAULT_SECTION     0x20
67
68 int CONF_set_default_method(CONF_METHOD *meth);
69 void CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash);
70 LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file,
71                                 long *eline);
72 # ifndef OPENSSL_NO_STDIO
73 LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp,
74                                    long *eline);
75 # endif
76 LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp,
77                                     long *eline);
78 STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf,
79                                        const char *section);
80 char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf, const char *group,
81                       const char *name);
82 long CONF_get_number(LHASH_OF(CONF_VALUE) *conf, const char *group,
83                      const char *name);
84 void CONF_free(LHASH_OF(CONF_VALUE) *conf);
85 #ifndef OPENSSL_NO_STDIO
86 int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out);
87 #endif
88 int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out);
89
90 DEPRECATEDIN_1_1_0(void OPENSSL_config(const char *config_name))
91
92 #if OPENSSL_API_COMPAT < 0x10100000L
93 # define OPENSSL_no_config() \
94     OPENSSL_init_crypto(OPENSSL_INIT_NO_LOAD_CONFIG, NULL)
95 #endif
96
97 /*
98  * New conf code.  The semantics are different from the functions above. If
99  * that wasn't the case, the above functions would have been replaced
100  */
101
102 struct conf_st {
103     CONF_METHOD *meth;
104     void *meth_data;
105     LHASH_OF(CONF_VALUE) *data;
106 };
107
108 CONF *NCONF_new(CONF_METHOD *meth);
109 CONF_METHOD *NCONF_default(void);
110 CONF_METHOD *NCONF_WIN32(void);
111 void NCONF_free(CONF *conf);
112 void NCONF_free_data(CONF *conf);
113
114 int NCONF_load(CONF *conf, const char *file, long *eline);
115 # ifndef OPENSSL_NO_STDIO
116 int NCONF_load_fp(CONF *conf, FILE *fp, long *eline);
117 # endif
118 int NCONF_load_bio(CONF *conf, BIO *bp, long *eline);
119 STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,
120                                         const char *section);
121 char *NCONF_get_string(const CONF *conf, const char *group, const char *name);
122 int NCONF_get_number_e(const CONF *conf, const char *group, const char *name,
123                        long *result);
124 #ifndef OPENSSL_NO_STDIO
125 int NCONF_dump_fp(const CONF *conf, FILE *out);
126 #endif
127 int NCONF_dump_bio(const CONF *conf, BIO *out);
128
129 #define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r)
130
131 /* Module functions */
132
133 int CONF_modules_load(const CONF *cnf, const char *appname,
134                       unsigned long flags);
135 int CONF_modules_load_file(const char *filename, const char *appname,
136                            unsigned long flags);
137 void CONF_modules_unload(int all);
138 void CONF_modules_finish(void);
139 #if OPENSSL_API_COMPAT < 0x10100000L
140 # define CONF_modules_free() while(0) continue
141 #endif
142 int CONF_module_add(const char *name, conf_init_func *ifunc,
143                     conf_finish_func *ffunc);
144
145 const char *CONF_imodule_get_name(const CONF_IMODULE *md);
146 const char *CONF_imodule_get_value(const CONF_IMODULE *md);
147 void *CONF_imodule_get_usr_data(const CONF_IMODULE *md);
148 void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data);
149 CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md);
150 unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md);
151 void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags);
152 void *CONF_module_get_usr_data(CONF_MODULE *pmod);
153 void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data);
154
155 char *CONF_get1_default_config_file(void);
156
157 int CONF_parse_list(const char *list, int sep, int nospc,
158                     int (*list_cb) (const char *elem, int len, void *usr),
159                     void *arg);
160
161 void OPENSSL_load_builtin_modules(void);
162
163 int ERR_load_CONF_strings(void);
164
165 # ifdef  __cplusplus
166 }
167 # endif
168 #endif