upstream nginx-0.7.37
[nginx.git] / nginx / src / core / ngx_conf_file.h
1
2 /*
3  * Copyright (C) Igor Sysoev
4  */
5
6
7 #ifndef _NGX_HTTP_CONF_FILE_H_INCLUDED_
8 #define _NGX_HTTP_CONF_FILE_H_INCLUDED_
9
10
11 #include <ngx_config.h>
12 #include <ngx_core.h>
13
14
15 /*
16  *        AAAA  number of agruments
17  *      FF      command flags
18  *    TT        command type, i.e. HTTP "location" or "server" command
19  */
20
21 #define NGX_CONF_NOARGS      0x00000001
22 #define NGX_CONF_TAKE1       0x00000002
23 #define NGX_CONF_TAKE2       0x00000004
24 #define NGX_CONF_TAKE3       0x00000008
25 #define NGX_CONF_TAKE4       0x00000010
26 #define NGX_CONF_TAKE5       0x00000020
27 #define NGX_CONF_TAKE6       0x00000040
28 #define NGX_CONF_TAKE7       0x00000080
29
30 #define NGX_CONF_MAX_ARGS    8
31
32 #define NGX_CONF_TAKE12      (NGX_CONF_TAKE1|NGX_CONF_TAKE2)
33 #define NGX_CONF_TAKE13      (NGX_CONF_TAKE1|NGX_CONF_TAKE3)
34
35 #define NGX_CONF_TAKE23      (NGX_CONF_TAKE2|NGX_CONF_TAKE3)
36
37 #define NGX_CONF_TAKE123     (NGX_CONF_TAKE1|NGX_CONF_TAKE2|NGX_CONF_TAKE3)
38 #define NGX_CONF_TAKE1234    (NGX_CONF_TAKE1|NGX_CONF_TAKE2|NGX_CONF_TAKE3   \
39                               |NGX_CONF_TAKE4)
40
41 #define NGX_CONF_ARGS_NUMBER 0x000000ff
42 #define NGX_CONF_BLOCK       0x00000100
43 #define NGX_CONF_FLAG        0x00000200
44 #define NGX_CONF_ANY         0x00000400
45 #define NGX_CONF_1MORE       0x00000800
46 #define NGX_CONF_2MORE       0x00001000
47 #define NGX_CONF_MULTI       0x00002000
48
49 #define NGX_DIRECT_CONF      0x00010000
50
51 #define NGX_MAIN_CONF        0x01000000
52 #define NGX_ANY_CONF         0x0F000000
53
54
55
56 #define NGX_CONF_UNSET       -1
57 #define NGX_CONF_UNSET_UINT  (ngx_uint_t) -1
58 #define NGX_CONF_UNSET_PTR   (void *) -1
59 #define NGX_CONF_UNSET_SIZE  (size_t) -1
60 #define NGX_CONF_UNSET_MSEC  (ngx_msec_t) -1
61
62
63 #define NGX_CONF_OK          NULL
64 #define NGX_CONF_ERROR       (void *) -1
65
66 #define NGX_CONF_BLOCK_START 1
67 #define NGX_CONF_BLOCK_DONE  2
68 #define NGX_CONF_FILE_DONE   3
69
70 #define NGX_CORE_MODULE      0x45524F43  /* "CORE" */
71 #define NGX_CONF_MODULE      0x464E4F43  /* "CONF" */
72
73
74 #define NGX_MAX_CONF_ERRSTR  1024
75
76
77 struct ngx_command_s {
78     ngx_str_t             name;
79     ngx_uint_t            type;
80     char               *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
81     ngx_uint_t            conf;
82     ngx_uint_t            offset;
83     void                 *post;
84 };
85
86 #define ngx_null_command  { ngx_null_string, 0, NULL, 0, 0, NULL }
87
88
89 struct ngx_open_file_s {
90     ngx_fd_t              fd;
91     ngx_str_t             name;
92
93     u_char               *buffer;
94     u_char               *pos;
95     u_char               *last;
96
97 #if 0
98     /* e.g. append mode, error_log */
99     ngx_uint_t            flags;
100     /* e.g. reopen db file */
101     ngx_uint_t          (*handler)(void *data, ngx_open_file_t *file);
102     void                 *data;
103 #endif
104 };
105
106
107 #define NGX_MODULE_V1          0, 0, 0, 0, 0, 0, 1
108 #define NGX_MODULE_V1_PADDING  0, 0, 0, 0, 0, 0, 0, 0
109
110 struct ngx_module_s {
111     ngx_uint_t            ctx_index;
112     ngx_uint_t            index;
113
114     ngx_uint_t            spare0;
115     ngx_uint_t            spare1;
116     ngx_uint_t            spare2;
117     ngx_uint_t            spare3;
118
119     ngx_uint_t            version;
120
121     void                 *ctx;
122     ngx_command_t        *commands;
123     ngx_uint_t            type;
124
125     ngx_int_t           (*init_master)(ngx_log_t *log);
126
127     ngx_int_t           (*init_module)(ngx_cycle_t *cycle);
128
129     ngx_int_t           (*init_process)(ngx_cycle_t *cycle);
130     ngx_int_t           (*init_thread)(ngx_cycle_t *cycle);
131     void                (*exit_thread)(ngx_cycle_t *cycle);
132     void                (*exit_process)(ngx_cycle_t *cycle);
133
134     void                (*exit_master)(ngx_cycle_t *cycle);
135
136     uintptr_t             spare_hook0;
137     uintptr_t             spare_hook1;
138     uintptr_t             spare_hook2;
139     uintptr_t             spare_hook3;
140     uintptr_t             spare_hook4;
141     uintptr_t             spare_hook5;
142     uintptr_t             spare_hook6;
143     uintptr_t             spare_hook7;
144 };
145
146
147 typedef struct {
148     ngx_str_t             name;
149     void               *(*create_conf)(ngx_cycle_t *cycle);
150     char               *(*init_conf)(ngx_cycle_t *cycle, void *conf);
151 } ngx_core_module_t;
152
153
154 typedef struct {
155     ngx_file_t            file;
156     ngx_buf_t            *buffer;
157     ngx_uint_t            line;
158 } ngx_conf_file_t;
159
160
161 typedef char *(*ngx_conf_handler_pt)(ngx_conf_t *cf,
162     ngx_command_t *dummy, void *conf);
163
164
165 struct ngx_conf_s {
166     char                 *name;
167     ngx_array_t          *args;
168
169     ngx_cycle_t          *cycle;
170     ngx_pool_t           *pool;
171     ngx_pool_t           *temp_pool;
172     ngx_conf_file_t      *conf_file;
173     ngx_log_t            *log;
174
175     void                 *ctx;
176     ngx_uint_t            module_type;
177     ngx_uint_t            cmd_type;
178
179     ngx_conf_handler_pt   handler;
180     char                 *handler_conf;
181 };
182
183
184 typedef char *(*ngx_conf_post_handler_pt) (ngx_conf_t *cf,
185     void *data, void *conf);
186
187 typedef struct {
188     ngx_conf_post_handler_pt  post_handler;
189 } ngx_conf_post_t;
190
191
192 typedef struct {
193     ngx_conf_post_handler_pt  post_handler;
194     char                     *old_name;
195     char                     *new_name;
196 } ngx_conf_deprecated_t;
197
198
199 typedef struct {
200     ngx_conf_post_handler_pt  post_handler;
201     ngx_int_t                 low;
202     ngx_int_t                 high;
203 } ngx_conf_num_bounds_t;
204
205
206 typedef struct {
207     ngx_str_t                 name;
208     ngx_uint_t                value;
209 } ngx_conf_enum_t;
210
211
212 #define NGX_CONF_BITMASK_SET  1
213
214 typedef struct {
215     ngx_str_t                 name;
216     ngx_uint_t                mask;
217 } ngx_conf_bitmask_t;
218
219
220
221 char * ngx_conf_deprecated(ngx_conf_t *cf, void *post, void *data);
222 char *ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data);
223
224
225 #define ngx_get_conf(conf_ctx, module)  conf_ctx[module.index]
226
227
228
229 #define ngx_conf_init_value(conf, default)                                   \
230     if (conf == NGX_CONF_UNSET) {                                            \
231         conf = default;                                                      \
232     }
233
234 #define ngx_conf_init_ptr_value(conf, default)                               \
235     if (conf == NGX_CONF_UNSET_PTR) {                                        \
236         conf = default;                                                      \
237     }
238
239 #define ngx_conf_init_uint_value(conf, default)                              \
240     if (conf == NGX_CONF_UNSET_UINT) {                                       \
241         conf = default;                                                      \
242     }
243
244 #define ngx_conf_init_size_value(conf, default)                              \
245     if (conf == NGX_CONF_UNSET_SIZE) {                                       \
246         conf = default;                                                      \
247     }
248
249 #define ngx_conf_init_msec_value(conf, default)                              \
250     if (conf == NGX_CONF_UNSET_MSEC) {                                       \
251         conf = default;                                                      \
252     }
253
254 #define ngx_conf_merge_value(conf, prev, default)                            \
255     if (conf == NGX_CONF_UNSET) {                                            \
256         conf = (prev == NGX_CONF_UNSET) ? default : prev;                    \
257     }
258
259 #define ngx_conf_merge_ptr_value(conf, prev, default)                        \
260     if (conf == NGX_CONF_UNSET_PTR) {                                        \
261         conf = (prev == NGX_CONF_UNSET_PTR) ? default : prev;                \
262     }
263
264 #define ngx_conf_merge_uint_value(conf, prev, default)                       \
265     if (conf == NGX_CONF_UNSET_UINT) {                                       \
266         conf = (prev == NGX_CONF_UNSET_UINT) ? default : prev;               \
267     }
268
269 #define ngx_conf_merge_msec_value(conf, prev, default)                       \
270     if (conf == NGX_CONF_UNSET_MSEC) {                                       \
271         conf = (prev == NGX_CONF_UNSET_MSEC) ? default : prev;               \
272     }
273
274 #define ngx_conf_merge_sec_value(conf, prev, default)                        \
275     if (conf == NGX_CONF_UNSET) {                                            \
276         conf = (prev == NGX_CONF_UNSET) ? default : prev;                    \
277     }
278
279 #define ngx_conf_merge_size_value(conf, prev, default)                       \
280     if (conf == NGX_CONF_UNSET_SIZE) {                                       \
281         conf = (prev == NGX_CONF_UNSET_SIZE) ? default : prev;               \
282     }
283
284 #define ngx_conf_merge_off_value(conf, prev, default)                        \
285     if (conf == NGX_CONF_UNSET) {                                            \
286         conf = (prev == NGX_CONF_UNSET) ? default : prev;                    \
287     }
288
289 #define ngx_conf_merge_str_value(conf, prev, default)                        \
290     if (conf.data == NULL) {                                                 \
291         if (prev.data) {                                                     \
292             conf.len = prev.len;                                             \
293             conf.data = prev.data;                                           \
294         } else {                                                             \
295             conf.len = sizeof(default) - 1;                                  \
296             conf.data = (u_char *) default;                                  \
297         }                                                                    \
298     }
299
300 #define ngx_conf_merge_bufs_value(conf, prev, default_num, default_size)     \
301     if (conf.num == 0) {                                                     \
302         if (prev.num) {                                                      \
303             conf.num = prev.num;                                             \
304             conf.size = prev.size;                                           \
305         } else {                                                             \
306             conf.num = default_num;                                          \
307             conf.size = default_size;                                        \
308         }                                                                    \
309     }
310
311 #define ngx_conf_merge_bitmask_value(conf, prev, default)                    \
312     if (conf == 0) {                                                         \
313         conf = (prev == 0) ? default : prev;                                 \
314     }
315
316
317 char *ngx_conf_param(ngx_conf_t *cf);
318 char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename);
319
320
321 ngx_int_t ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name,
322     ngx_uint_t conf_prefix);
323 ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name);
324 void ngx_cdecl ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf,
325     ngx_err_t err, char *fmt, ...);
326
327
328 char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
329 char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
330 char *ngx_conf_set_str_array_slot(ngx_conf_t *cf, ngx_command_t *cmd,
331     void *conf);
332 char *ngx_conf_set_keyval_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
333 char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
334 char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
335 char *ngx_conf_set_off_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
336 char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
337 char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
338 char *ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
339 char *ngx_conf_set_enum_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
340 char *ngx_conf_set_bitmask_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
341
342
343 extern ngx_uint_t     ngx_max_module;
344 extern ngx_module_t  *ngx_modules[];
345
346
347 #endif /* _NGX_HTTP_CONF_FILE_H_INCLUDED_ */