blob: 2e91d0b8c6a5df97c4c608678203325b99f1e810 [file] [log] [blame]
Igor Sysoevd90282d2004-09-28 08:34:51 +00001
2/*
Igor Sysoevff8da912004-09-29 16:00:49 +00003 * Copyright (C) Igor Sysoev
Igor Sysoevd90282d2004-09-28 08:34:51 +00004 */
5
6
Igor Sysoevc1817842002-12-27 16:22:50 +00007#ifndef _NGX_HTTP_CONF_FILE_H_INCLUDED_
8#define _NGX_HTTP_CONF_FILE_H_INCLUDED_
Igor Sysoev88092572002-12-19 07:08:55 +00009
10
11#include <ngx_config.h>
Igor Sysoev1c104622003-06-03 15:42:58 +000012#include <ngx_core.h>
Igor Sysoev88092572002-12-19 07:08:55 +000013
Igor Sysoev960ffa42002-12-26 07:24:21 +000014
Igor Sysoev79a80482003-05-14 17:13:13 +000015/*
Igor Sysoev6ddfbf02003-05-15 15:42:53 +000016 * AAAA number of agruments
17 * FF command flags
18 * TT command type, i.e. HTTP "location" or "server" command
Igor Sysoev79a80482003-05-14 17:13:13 +000019 */
20
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +000021#define NGX_CONF_NOARGS 0x00000001
22#define NGX_CONF_TAKE1 0x00000002
23#define NGX_CONF_TAKE2 0x00000004
Igor Sysoevdc9dd432003-10-22 16:38:26 +000024#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
Igor Sysoevdc9dd432003-10-22 16:38:26 +000029
Igor Sysoev3362b8d2005-05-14 18:42:03 +000030#define NGX_CONF_MAX_ARGS 8
31
Igor Sysoev74e95c22003-11-09 20:03:38 +000032#define NGX_CONF_TAKE12 (NGX_CONF_TAKE1|NGX_CONF_TAKE2)
Igor Sysoev74e95c22003-11-09 20:03:38 +000033#define NGX_CONF_TAKE13 (NGX_CONF_TAKE1|NGX_CONF_TAKE3)
34
Igor Sysoev3b30a902003-12-25 20:26:58 +000035#define NGX_CONF_TAKE23 (NGX_CONF_TAKE2|NGX_CONF_TAKE3)
36
Igor Sysoev697d1ae2005-10-27 15:46:13 +000037#define NGX_CONF_TAKE123 (NGX_CONF_TAKE1|NGX_CONF_TAKE2|NGX_CONF_TAKE3)
Igor Sysoevdc9dd432003-10-22 16:38:26 +000038#define NGX_CONF_TAKE1234 (NGX_CONF_TAKE1|NGX_CONF_TAKE2|NGX_CONF_TAKE3 \
39 |NGX_CONF_TAKE4)
40
Igor Sysoev43f13192004-04-12 16:38:09 +000041#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
Igor Sysoevac72bd12006-05-04 15:32:46 +000047#define NGX_CONF_MULTI 0x00002000
Igor Sysoev88092572002-12-19 07:08:55 +000048
Igor Sysoev43f13192004-04-12 16:38:09 +000049#define NGX_DIRECT_CONF 0x00010000
Igor Sysoevab517d52004-05-18 15:29:08 +000050
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +000051#define NGX_MAIN_CONF 0x01000000
Igor Sysoevab517d52004-05-18 15:29:08 +000052#define NGX_ANY_CONF 0x0F000000
Igor Sysoev79a80482003-05-14 17:13:13 +000053
54
Igor Sysoev88092572002-12-19 07:08:55 +000055
Igor Sysoevc1817842002-12-27 16:22:50 +000056#define NGX_CONF_UNSET -1
Igor Sysoeva3677242004-04-14 05:57:36 +000057#define NGX_CONF_UNSET_UINT (ngx_uint_t) -1
Igor Sysoev75569452004-07-08 15:17:47 +000058#define NGX_CONF_UNSET_PTR (void *) -1
Igor Sysoev10a543a2004-03-16 07:10:12 +000059#define NGX_CONF_UNSET_SIZE (size_t) -1
60#define NGX_CONF_UNSET_MSEC (ngx_msec_t) -1
Igor Sysoev88092572002-12-19 07:08:55 +000061
62
Igor Sysoev4e9393a2003-01-09 05:36:00 +000063#define NGX_CONF_OK NULL
Igor Sysoev6f134cc2006-05-23 14:54:58 +000064#define NGX_CONF_ERROR (void *) -1
Igor Sysoevc1817842002-12-27 16:22:50 +000065
Igor Sysoev1b735832004-11-11 14:07:14 +000066#define NGX_CONF_BLOCK_START 1
67#define NGX_CONF_BLOCK_DONE 2
68#define NGX_CONF_FILE_DONE 3
Igor Sysoev960ffa42002-12-26 07:24:21 +000069
Igor Sysoev6253ca12003-05-27 12:18:54 +000070#define NGX_CORE_MODULE 0x45524F43 /* "CORE" */
71#define NGX_CONF_MODULE 0x464E4F43 /* "CONF" */
72
73
Igor Sysoeva8fa0a62003-11-25 20:44:56 +000074#define NGX_MAX_CONF_ERRSTR 256
75
76
Igor Sysoevf1079102003-10-23 06:13:16 +000077struct ngx_command_s {
Igor Sysoev02f742b2005-04-08 15:18:55 +000078 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;
Igor Sysoevf1079102003-10-23 06:13:16 +000084};
85
Igor Sysoev09c684b2005-11-09 17:25:55 +000086#define ngx_null_command { ngx_null_string, 0, NULL, 0, 0, NULL }
Igor Sysoev960ffa42002-12-26 07:24:21 +000087
Igor Sysoev1c104622003-06-03 15:42:58 +000088
Igor Sysoev96c56c92003-07-02 14:41:17 +000089struct ngx_open_file_s {
Igor Sysoev02f742b2005-04-08 15:18:55 +000090 ngx_fd_t fd;
91 ngx_str_t name;
Igor Sysoev697d1ae2005-10-27 15:46:13 +000092
93 u_char *buffer;
94 u_char *pos;
95 u_char *last;
96
Igor Sysoev890fc962003-07-20 21:15:59 +000097#if 0
98 /* e.g. append mode, error_log */
Igor Sysoev02f742b2005-04-08 15:18:55 +000099 ngx_uint_t flags;
Igor Sysoev890fc962003-07-20 21:15:59 +0000100 /* e.g. reopen db file */
Igor Sysoev02f742b2005-04-08 15:18:55 +0000101 ngx_uint_t (*handler)(void *data, ngx_open_file_t *file);
102 void *data;
Igor Sysoev890fc962003-07-20 21:15:59 +0000103#endif
Igor Sysoev96c56c92003-07-02 14:41:17 +0000104};
105
106
Igor Sysoev09a24392005-09-23 14:43:49 +0000107#define NGX_MODULE_V1 0, 0, 0, 0, 0, 0, 1
Igor Sysoeve5733802005-09-08 14:36:09 +0000108#define NGX_MODULE_V1_PADDING 0, 0, 0, 0, 0, 0, 0, 0
109
Igor Sysoev1c104622003-06-03 15:42:58 +0000110struct ngx_module_s {
Igor Sysoev02f742b2005-04-08 15:18:55 +0000111 ngx_uint_t ctx_index;
112 ngx_uint_t index;
Igor Sysoeve5733802005-09-08 14:36:09 +0000113
Igor Sysoev899b44e2005-05-12 14:58:06 +0000114 ngx_uint_t spare0;
115 ngx_uint_t spare1;
Igor Sysoeve5733802005-09-08 14:36:09 +0000116 ngx_uint_t spare2;
117 ngx_uint_t spare3;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000118
Igor Sysoev09a24392005-09-23 14:43:49 +0000119 ngx_uint_t version;
120
Igor Sysoev02f742b2005-04-08 15:18:55 +0000121 void *ctx;
122 ngx_command_t *commands;
123 ngx_uint_t type;
Igor Sysoeve5733802005-09-08 14:36:09 +0000124
125 ngx_int_t (*init_master)(ngx_log_t *log);
126
Igor Sysoev02f742b2005-04-08 15:18:55 +0000127 ngx_int_t (*init_module)(ngx_cycle_t *cycle);
Igor Sysoeve5733802005-09-08 14:36:09 +0000128
Igor Sysoev02f742b2005-04-08 15:18:55 +0000129 ngx_int_t (*init_process)(ngx_cycle_t *cycle);
Igor Sysoev02f742b2005-04-08 15:18:55 +0000130 ngx_int_t (*init_thread)(ngx_cycle_t *cycle);
Igor Sysoev697d1ae2005-10-27 15:46:13 +0000131 void (*exit_thread)(ngx_cycle_t *cycle);
132 void (*exit_process)(ngx_cycle_t *cycle);
Igor Sysoeve5733802005-09-08 14:36:09 +0000133
Igor Sysoev697d1ae2005-10-27 15:46:13 +0000134 void (*exit_master)(ngx_cycle_t *cycle);
Igor Sysoeve5733802005-09-08 14:36:09 +0000135
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;
Igor Sysoev1c104622003-06-03 15:42:58 +0000144};
Igor Sysoeva6717c42002-12-23 06:29:22 +0000145
146
Igor Sysoev88092572002-12-19 07:08:55 +0000147typedef struct {
Igor Sysoev02f742b2005-04-08 15:18:55 +0000148 ngx_str_t name;
149 void *(*create_conf)(ngx_cycle_t *cycle);
150 char *(*init_conf)(ngx_cycle_t *cycle, void *conf);
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000151} ngx_core_module_t;
Igor Sysoev43f13192004-04-12 16:38:09 +0000152
153
154typedef struct {
Igor Sysoev02f742b2005-04-08 15:18:55 +0000155 ngx_file_t file;
156 ngx_buf_t *buffer;
157 ngx_uint_t line;
Igor Sysoev88092572002-12-19 07:08:55 +0000158} ngx_conf_file_t;
159
Igor Sysoev960ffa42002-12-26 07:24:21 +0000160
Igor Sysoev79a80482003-05-14 17:13:13 +0000161typedef char *(*ngx_conf_handler_pt)(ngx_conf_t *cf,
Igor Sysoev02f742b2005-04-08 15:18:55 +0000162 ngx_command_t *dummy, void *conf);
Igor Sysoev79a80482003-05-14 17:13:13 +0000163
164
Igor Sysoev88092572002-12-19 07:08:55 +0000165struct ngx_conf_s {
Igor Sysoev79a80482003-05-14 17:13:13 +0000166 char *name;
167 ngx_array_t *args;
Igor Sysoev88092572002-12-19 07:08:55 +0000168
Igor Sysoev6abfde62003-07-01 15:00:03 +0000169 ngx_cycle_t *cycle;
Igor Sysoev79a80482003-05-14 17:13:13 +0000170 ngx_pool_t *pool;
Igor Sysoev305a9d82005-12-26 17:07:48 +0000171 ngx_pool_t *temp_pool;
Igor Sysoev79a80482003-05-14 17:13:13 +0000172 ngx_conf_file_t *conf_file;
173 ngx_log_t *log;
Igor Sysoev88092572002-12-19 07:08:55 +0000174
Igor Sysoev79a80482003-05-14 17:13:13 +0000175 void *ctx;
Igor Sysoev2f657222004-06-16 15:32:11 +0000176 ngx_uint_t module_type;
177 ngx_uint_t cmd_type;
Igor Sysoev79a80482003-05-14 17:13:13 +0000178
179 ngx_conf_handler_pt handler;
180 char *handler_conf;
Igor Sysoev88092572002-12-19 07:08:55 +0000181};
182
183
Igor Sysoev12b4b002003-10-24 06:53:41 +0000184typedef char *(*ngx_conf_post_handler_pt) (ngx_conf_t *cf,
Igor Sysoev4d656dc2005-03-22 16:02:46 +0000185 void *data, void *conf);
Igor Sysoev12b4b002003-10-24 06:53:41 +0000186
187typedef struct {
188 ngx_conf_post_handler_pt post_handler;
189} ngx_conf_post_t;
190
191
192typedef struct {
193 ngx_conf_post_handler_pt post_handler;
Igor Sysoevc31a9bb2005-11-26 10:11:11 +0000194 char *old_name;
195 char *new_name;
196} ngx_conf_deprecated_t;
197
198
199typedef struct {
200 ngx_conf_post_handler_pt post_handler;
Igor Sysoev02f742b2005-04-08 15:18:55 +0000201 ngx_int_t low;
202 ngx_int_t high;
Igor Sysoev12b4b002003-10-24 06:53:41 +0000203} ngx_conf_num_bounds_t;
204
205
Igor Sysoeva3677242004-04-14 05:57:36 +0000206typedef struct {
Igor Sysoev02f742b2005-04-08 15:18:55 +0000207 ngx_str_t name;
208 ngx_uint_t value;
Igor Sysoeva3677242004-04-14 05:57:36 +0000209} ngx_conf_enum_t;
210
211
Igor Sysoev65977492003-11-02 22:56:18 +0000212#define NGX_CONF_BITMASK_SET 1
213
Igor Sysoev68ee8f12003-10-30 08:51:06 +0000214typedef struct {
Igor Sysoev02f742b2005-04-08 15:18:55 +0000215 ngx_str_t name;
216 ngx_uint_t mask;
Igor Sysoev68ee8f12003-10-30 08:51:06 +0000217} ngx_conf_bitmask_t;
218
219
Igor Sysoevc31a9bb2005-11-26 10:11:11 +0000220
221char * ngx_conf_deprecated(ngx_conf_t *cf, void *post, void *data);
Igor Sysoev12b4b002003-10-24 06:53:41 +0000222char *ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data);
223
224
Igor Sysoev340b03b2003-07-04 15:10:33 +0000225#define ngx_get_conf(conf_ctx, module) conf_ctx[module.index]
Igor Sysoeva9830112003-05-19 16:39:14 +0000226
227
Igor Sysoev8e1fbe62003-07-18 14:44:05 +0000228
Igor Sysoeva9830112003-05-19 16:39:14 +0000229#define ngx_conf_init_value(conf, default) \
230 if (conf == NGX_CONF_UNSET) { \
231 conf = default; \
232 }
233
Igor Sysoev2b58fbf2003-12-09 15:08:11 +0000234#define ngx_conf_init_ptr_value(conf, default) \
Igor Sysoev75569452004-07-08 15:17:47 +0000235 if (conf == NGX_CONF_UNSET_PTR) { \
Igor Sysoev2b58fbf2003-12-09 15:08:11 +0000236 conf = default; \
237 }
238
Igor Sysoev1765f472006-07-07 16:33:19 +0000239#define ngx_conf_init_uint_value(conf, default) \
240 if (conf == NGX_CONF_UNSET_UINT) { \
Igor Sysoevbe2cfc32003-06-15 18:32:13 +0000241 conf = default; \
242 }
243
Igor Sysoeva9830112003-05-19 16:39:14 +0000244#define ngx_conf_init_size_value(conf, default) \
Igor Sysoev9a864bd2004-04-04 20:32:09 +0000245 if (conf == NGX_CONF_UNSET_SIZE) { \
Igor Sysoeva9830112003-05-19 16:39:14 +0000246 conf = default; \
247 }
248
249#define ngx_conf_init_msec_value(conf, default) \
Igor Sysoev9a864bd2004-04-04 20:32:09 +0000250 if (conf == NGX_CONF_UNSET_MSEC) { \
Igor Sysoeva9830112003-05-19 16:39:14 +0000251 conf = default; \
252 }
253
254#define ngx_conf_merge_value(conf, prev, default) \
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000255 if (conf == NGX_CONF_UNSET) { \
256 conf = (prev == NGX_CONF_UNSET) ? default : prev; \
257 }
Igor Sysoev88092572002-12-19 07:08:55 +0000258
Igor Sysoev75569452004-07-08 15:17:47 +0000259#define ngx_conf_merge_ptr_value(conf, prev, default) \
260 if (conf == NULL) { \
261 conf = (prev == NULL) ? default : prev; \
262 }
263
Igor Sysoev1765f472006-07-07 16:33:19 +0000264#define ngx_conf_merge_uint_value(conf, prev, default) \
Igor Sysoeva3677242004-04-14 05:57:36 +0000265 if (conf == NGX_CONF_UNSET_UINT) { \
266 conf = (prev == NGX_CONF_UNSET_UINT) ? default : prev; \
267 }
268
Igor Sysoeva9830112003-05-19 16:39:14 +0000269#define ngx_conf_merge_msec_value(conf, prev, default) \
Igor Sysoev10a543a2004-03-16 07:10:12 +0000270 if (conf == NGX_CONF_UNSET_MSEC) { \
271 conf = (prev == NGX_CONF_UNSET_MSEC) ? default : prev; \
Igor Sysoev79a80482003-05-14 17:13:13 +0000272 }
Igor Sysoev3a17f242002-12-24 17:30:59 +0000273
Igor Sysoevcf80a702003-11-03 22:20:44 +0000274#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
Igor Sysoeva9830112003-05-19 16:39:14 +0000279#define ngx_conf_merge_size_value(conf, prev, default) \
Igor Sysoev10a543a2004-03-16 07:10:12 +0000280 if (conf == NGX_CONF_UNSET_SIZE) { \
281 conf = (prev == NGX_CONF_UNSET_SIZE) ? default : prev; \
Igor Sysoev73009772003-02-06 17:21:13 +0000282 }
283
Igor Sysoev1765f472006-07-07 16:33:19 +0000284#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
Igor Sysoev6253ca12003-05-27 12:18:54 +0000289#define ngx_conf_merge_str_value(conf, prev, default) \
Igor Sysoev02025fd2005-01-18 13:03:58 +0000290 if (conf.data == NULL) { \
Igor Sysoev8fea8852006-03-15 09:53:04 +0000291 if (prev.data) { \
Igor Sysoev6253ca12003-05-27 12:18:54 +0000292 conf.len = prev.len; \
293 conf.data = prev.data; \
294 } else { \
295 conf.len = sizeof(default) - 1; \
Igor Sysoevda85f7f2004-03-16 21:26:01 +0000296 conf.data = (u_char *) default; \
Igor Sysoev6253ca12003-05-27 12:18:54 +0000297 } \
298 }
299
Igor Sysoev3ae32482003-10-08 15:32:54 +0000300#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
Igor Sysoev68ee8f12003-10-30 08:51:06 +0000311#define ngx_conf_merge_bitmask_value(conf, prev, default) \
312 if (conf == 0) { \
313 conf = (prev == 0) ? default : prev; \
314 }
315
Igor Sysoev73009772003-02-06 17:21:13 +0000316
Igor Sysoev6a644c62003-03-04 06:33:48 +0000317#define addressof(addr) ((int) &addr)
318
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000319
320char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename);
321
322
Igor Sysoeva1df4162007-07-29 18:05:45 +0000323ngx_int_t ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name,
324 ngx_uint_t conf_prefix);
Igor Sysoev890fc962003-07-20 21:15:59 +0000325ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name);
Igor Sysoev4d656dc2005-03-22 16:02:46 +0000326void ngx_cdecl ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf,
327 ngx_err_t err, char *fmt, ...);
Igor Sysoev8e1fbe62003-07-18 14:44:05 +0000328
329
Igor Sysoev6253ca12003-05-27 12:18:54 +0000330char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
331char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000332char *ngx_conf_set_str_array_slot(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoev899b44e2005-05-12 14:58:06 +0000333 void *conf);
Igor Sysoev3338cfd2006-05-11 14:43:47 +0000334char *ngx_conf_set_keyval_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
Igor Sysoev6253ca12003-05-27 12:18:54 +0000335char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
336char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
Igor Sysoev1765f472006-07-07 16:33:19 +0000337char *ngx_conf_set_off_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
Igor Sysoev6253ca12003-05-27 12:18:54 +0000338char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
Igor Sysoevcf80a702003-11-03 22:20:44 +0000339char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
Igor Sysoev3ae32482003-10-08 15:32:54 +0000340char *ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
Igor Sysoeva3677242004-04-14 05:57:36 +0000341char *ngx_conf_set_enum_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
Igor Sysoev68ee8f12003-10-30 08:51:06 +0000342char *ngx_conf_set_bitmask_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
Igor Sysoev207ed5a2002-12-26 16:26:23 +0000343
Igor Sysoev890fc962003-07-20 21:15:59 +0000344
Igor Sysoev3f4685f2004-04-25 20:13:21 +0000345extern ngx_uint_t ngx_max_module;
Igor Sysoev3c3ca172004-01-05 20:55:48 +0000346extern ngx_module_t *ngx_modules[];
Igor Sysoev88092572002-12-19 07:08:55 +0000347
Igor Sysoev890fc962003-07-20 21:15:59 +0000348
Igor Sysoev73009772003-02-06 17:21:13 +0000349#endif /* _NGX_HTTP_CONF_FILE_H_INCLUDED_ */