blob: e02b8c4b557b9f7384b07927de4f03037f8cbde9 [file] [log] [blame]
Igor Sysoev88092572002-12-19 07:08:55 +00001
2#include <ngx_config.h>
Igor Sysoev88092572002-12-19 07:08:55 +00003#include <ngx_core.h>
Igor Sysoev88092572002-12-19 07:08:55 +00004
5
Igor Sysoevab517d52004-05-18 15:29:08 +00006static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
7
8
9static ngx_command_t ngx_conf_commands[] = {
10
11 { ngx_string("include"),
12 NGX_ANY_CONF|NGX_CONF_TAKE1,
13 ngx_conf_include,
14 0,
15 0,
16 NULL },
17
18 ngx_null_command
19};
20
21
22ngx_module_t ngx_conf_module = {
23 NGX_MODULE,
24 NULL, /* module context */
25 ngx_conf_commands, /* module directives */
26 NGX_CONF_MODULE, /* module type */
27 NULL, /* init module */
28 NULL /* init child */
29};
30
31
32
33/* The ten fixed arguments */
Igor Sysoevdc9dd432003-10-22 16:38:26 +000034
Igor Sysoev88092572002-12-19 07:08:55 +000035static int argument_number[] = {
36 NGX_CONF_NOARGS,
37 NGX_CONF_TAKE1,
Igor Sysoevdc9dd432003-10-22 16:38:26 +000038 NGX_CONF_TAKE2,
39 NGX_CONF_TAKE3,
40 NGX_CONF_TAKE4,
41 NGX_CONF_TAKE5,
42 NGX_CONF_TAKE6,
Igor Sysoev43f13192004-04-12 16:38:09 +000043 NGX_CONF_TAKE7
Igor Sysoev88092572002-12-19 07:08:55 +000044};
45
Igor Sysoev960ffa42002-12-26 07:24:21 +000046static int ngx_conf_read_token(ngx_conf_t *cf);
Igor Sysoev960ffa42002-12-26 07:24:21 +000047
Igor Sysoev88092572002-12-19 07:08:55 +000048
Igor Sysoev4e9393a2003-01-09 05:36:00 +000049char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
Igor Sysoev88092572002-12-19 07:08:55 +000050{
Igor Sysoevaa3436c2003-05-30 14:27:59 +000051 int m, rc, found, valid;
Igor Sysoev4e9393a2003-01-09 05:36:00 +000052 char *rv;
Igor Sysoeva9830112003-05-19 16:39:14 +000053 void *conf, **confp;
Igor Sysoev960ffa42002-12-26 07:24:21 +000054 ngx_fd_t fd;
Igor Sysoev369145c2004-05-28 15:49:23 +000055 ngx_str_t *name;
Igor Sysoev88092572002-12-19 07:08:55 +000056 ngx_conf_file_t *prev;
Igor Sysoev960ffa42002-12-26 07:24:21 +000057 ngx_command_t *cmd;
Igor Sysoev88092572002-12-19 07:08:55 +000058
Igor Sysoev9d639522003-07-07 06:11:50 +000059#if (NGX_SUPPRESS_WARN)
60 fd = NGX_INVALID_FILE;
61 prev = NULL;
62#endif
63
Igor Sysoev88092572002-12-19 07:08:55 +000064 if (filename) {
65
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +000066 /* open configuration file */
67
Igor Sysoev7578ec92003-06-02 15:24:30 +000068 fd = ngx_open_file(filename->data, NGX_FILE_RDONLY, NGX_FILE_OPEN);
Igor Sysoev88092572002-12-19 07:08:55 +000069 if (fd == NGX_INVALID_FILE) {
70 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
Igor Sysoeva6717c42002-12-23 06:29:22 +000071 ngx_open_file_n " %s failed", filename->data);
Igor Sysoev4e9393a2003-01-09 05:36:00 +000072 return NGX_CONF_ERROR;
Igor Sysoev88092572002-12-19 07:08:55 +000073 }
74
Igor Sysoeva6717c42002-12-23 06:29:22 +000075 prev = cf->conf_file;
Igor Sysoev369145c2004-05-28 15:49:23 +000076 if (!(cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)))) {
77 return NGX_CONF_ERROR;
78 }
Igor Sysoev88092572002-12-19 07:08:55 +000079
Igor Sysoevf2e676a2003-11-16 21:49:42 +000080 if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) {
Igor Sysoeva6717c42002-12-23 06:29:22 +000081 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
Igor Sysoevf2e676a2003-11-16 21:49:42 +000082 ngx_fd_info_n " %s failed", filename->data);
Igor Sysoeva6717c42002-12-23 06:29:22 +000083 }
84
Igor Sysoev369145c2004-05-28 15:49:23 +000085 if (!(cf->conf_file->buffer = ngx_create_temp_buf(cf->pool, 1024))) {
86 return NGX_CONF_ERROR;
87 }
Igor Sysoeva6717c42002-12-23 06:29:22 +000088
89 cf->conf_file->file.fd = fd;
90 cf->conf_file->file.name.len = filename->len;
91 cf->conf_file->file.name.data = filename->data;
Igor Sysoev9d639522003-07-07 06:11:50 +000092 cf->conf_file->file.offset = 0;
Igor Sysoeva6717c42002-12-23 06:29:22 +000093 cf->conf_file->file.log = cf->log;;
94 cf->conf_file->line = 1;
Igor Sysoev88092572002-12-19 07:08:55 +000095 }
96
97 for ( ;; ) {
98 rc = ngx_conf_read_token(cf);
99
Igor Sysoev369145c2004-05-28 15:49:23 +0000100 /*
101 * ngx_conf_read_token() returns NGX_OK, NGX_ERROR,
102 * NGX_CONF_FILE_DONE or NGX_CONF_BLOCK_DONE
103 */
Igor Sysoev88092572002-12-19 07:08:55 +0000104
Igor Sysoev73009772003-02-06 17:21:13 +0000105#if 0
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000106ngx_log_debug(cf->log, "token %d" _ rc);
Igor Sysoev73009772003-02-06 17:21:13 +0000107#endif
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000108
109 if (rc == NGX_ERROR) {
Igor Sysoev9d639522003-07-07 06:11:50 +0000110 break;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000111 }
112
113 if (rc != NGX_OK) {
Igor Sysoev9d639522003-07-07 06:11:50 +0000114 break;
Igor Sysoev88092572002-12-19 07:08:55 +0000115 }
116
Igor Sysoev88092572002-12-19 07:08:55 +0000117 if (cf->handler) {
118
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000119 /* custom handler, i.e. used in http "types { ... }" directive */
120
Igor Sysoev79a80482003-05-14 17:13:13 +0000121 rv = (*cf->handler)(cf, NULL, cf->handler_conf);
122 if (rv == NGX_CONF_OK) {
123 continue;
124
125 } else if (rv == NGX_CONF_ERROR) {
Igor Sysoev9d639522003-07-07 06:11:50 +0000126 rc = NGX_ERROR;
127 break;
Igor Sysoev79a80482003-05-14 17:13:13 +0000128
129 } else {
130 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
Igor Sysoev6ddfbf02003-05-15 15:42:53 +0000131 "%s in %s:%d",
132 rv,
Igor Sysoev79a80482003-05-14 17:13:13 +0000133 cf->conf_file->file.name.data,
134 cf->conf_file->line);
Igor Sysoev9d639522003-07-07 06:11:50 +0000135 rc = NGX_ERROR;
136 break;
Igor Sysoev88092572002-12-19 07:08:55 +0000137 }
Igor Sysoev88092572002-12-19 07:08:55 +0000138 }
139
Igor Sysoev207ed5a2002-12-26 16:26:23 +0000140 name = (ngx_str_t *) cf->args->elts;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000141 found = 0;
Igor Sysoev207ed5a2002-12-26 16:26:23 +0000142
Igor Sysoev9d639522003-07-07 06:11:50 +0000143 for (m = 0; rc != NGX_ERROR && !found && ngx_modules[m]; m++) {
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000144
145 /* look up the directive in the appropriate modules */
146
Igor Sysoev6253ca12003-05-27 12:18:54 +0000147 if (ngx_modules[m]->type != NGX_CONF_MODULE
148 && ngx_modules[m]->type != cf->module_type)
Igor Sysoevc1817842002-12-27 16:22:50 +0000149 {
Igor Sysoev207ed5a2002-12-26 16:26:23 +0000150 continue;
151 }
152
Igor Sysoev6253ca12003-05-27 12:18:54 +0000153 cmd = ngx_modules[m]->commands;
Igor Sysoev207ed5a2002-12-26 16:26:23 +0000154 if (cmd == NULL) {
155 continue;
156 }
157
158 while (cmd->name.len) {
159 if (name->len == cmd->name.len
160 && ngx_strcmp(name->data, cmd->name.data) == 0)
161 {
Igor Sysoevc1817842002-12-27 16:22:50 +0000162
Igor Sysoev8e1fbe62003-07-18 14:44:05 +0000163 found = 1;
Igor Sysoev73009772003-02-06 17:21:13 +0000164#if 0
Igor Sysoev207ed5a2002-12-26 16:26:23 +0000165ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data);
Igor Sysoev73009772003-02-06 17:21:13 +0000166#endif
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000167 /* is the directive's location right ? */
Igor Sysoevc1817842002-12-27 16:22:50 +0000168
Igor Sysoev79a80482003-05-14 17:13:13 +0000169 if ((cmd->type & cf->cmd_type) == 0) {
170 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
171 "directive \"%s\" in %s:%d "
172 "is not allowed here",
173 name->data,
174 cf->conf_file->file.name.data,
175 cf->conf_file->line);
Igor Sysoev9d639522003-07-07 06:11:50 +0000176 rc = NGX_ERROR;
177 break;
Igor Sysoev79a80482003-05-14 17:13:13 +0000178 }
179
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000180 /* is the directive's argument count right ? */
181
Igor Sysoevdc9dd432003-10-22 16:38:26 +0000182 if (cmd->type & NGX_CONF_ANY) {
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000183 valid = 1;
184
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000185 } else if (cmd->type & NGX_CONF_FLAG) {
186
187 if (cf->args->nelts == 2) {
188 valid = 1;
189 } else {
190 valid = 0;
191 }
192
Igor Sysoevdc9dd432003-10-22 16:38:26 +0000193 } else if (cmd->type & NGX_CONF_1MORE) {
194
Igor Sysoev74e95c22003-11-09 20:03:38 +0000195 if (cf->args->nelts > 1) {
196 valid = 1;
197 } else {
198 valid = 0;
199 }
200
201 } else if (cmd->type & NGX_CONF_2MORE) {
202
203 if (cf->args->nelts > 2) {
Igor Sysoevdc9dd432003-10-22 16:38:26 +0000204 valid = 1;
205 } else {
206 valid = 0;
207 }
208
209 } else if (cf->args->nelts <= 10
210 && (cmd->type
211 & argument_number[cf->args->nelts - 1]))
212 {
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000213 valid = 1;
214
215 } else {
216 valid = 0;
217 }
218
219 if (!valid) {
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000220 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
221 "invalid number arguments in "
222 "directive \"%s\" in %s:%d",
223 name->data,
224 cf->conf_file->file.name.data,
225 cf->conf_file->line);
Igor Sysoev9d639522003-07-07 06:11:50 +0000226 rc = NGX_ERROR;
227 break;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000228 }
229
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000230 /* set up the directive's configuration context */
231
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000232 conf = NULL;
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000233
Igor Sysoev43f13192004-04-12 16:38:09 +0000234 if (cmd->type & NGX_DIRECT_CONF) {
235 conf = ((void **) cf->ctx)[ngx_modules[m]->index];
236
237 } else if (cmd->type & NGX_MAIN_CONF) {
Igor Sysoev6253ca12003-05-27 12:18:54 +0000238 conf = &(((void **) cf->ctx)[ngx_modules[m]->index]);
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000239
240 } else if (cf->ctx) {
Igor Sysoeva9830112003-05-19 16:39:14 +0000241 confp = *(void **) ((char *) cf->ctx + cmd->conf);
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000242
Igor Sysoeva9830112003-05-19 16:39:14 +0000243 if (confp) {
Igor Sysoev6253ca12003-05-27 12:18:54 +0000244 conf = confp[ngx_modules[m]->ctx_index];
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000245 }
246 }
247
248 rv = cmd->set(cf, cmd, conf);
249
Igor Sysoev73009772003-02-06 17:21:13 +0000250#if 0
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000251ngx_log_debug(cf->log, "rv: %d" _ rv);
Igor Sysoev73009772003-02-06 17:21:13 +0000252#endif
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000253
254 if (rv == NGX_CONF_OK) {
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000255 break;
256
257 } else if (rv == NGX_CONF_ERROR) {
Igor Sysoev9d639522003-07-07 06:11:50 +0000258 rc = NGX_ERROR;
259 break;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000260
261 } else {
Igor Sysoev890fc962003-07-20 21:15:59 +0000262 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
Igor Sysoev2b58fbf2003-12-09 15:08:11 +0000263 "the \"%s\" directive %s in %s:%d",
Igor Sysoev890fc962003-07-20 21:15:59 +0000264 name->data, rv,
265 cf->conf_file->file.name.data,
266 cf->conf_file->line);
Igor Sysoev6a644c62003-03-04 06:33:48 +0000267
Igor Sysoev9d639522003-07-07 06:11:50 +0000268 rc = NGX_ERROR;
269 break;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000270 }
Igor Sysoev207ed5a2002-12-26 16:26:23 +0000271 }
272
273 cmd++;
274 }
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000275 }
Igor Sysoev960ffa42002-12-26 07:24:21 +0000276
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000277 if (!found) {
Igor Sysoev88092572002-12-19 07:08:55 +0000278 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
279 "unknown directive \"%s\" in %s:%d",
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000280 name->data,
281 cf->conf_file->file.name.data,
282 cf->conf_file->line);
283
Igor Sysoev9d639522003-07-07 06:11:50 +0000284 rc = NGX_ERROR;
285 break;
Igor Sysoev88092572002-12-19 07:08:55 +0000286 }
Igor Sysoev8e1fbe62003-07-18 14:44:05 +0000287
288 if (rc == NGX_ERROR) {
289 break;
290 }
Igor Sysoeva6717c42002-12-23 06:29:22 +0000291 }
Igor Sysoev88092572002-12-19 07:08:55 +0000292
293 if (filename) {
Igor Sysoeva6717c42002-12-23 06:29:22 +0000294 cf->conf_file = prev;
Igor Sysoev88092572002-12-19 07:08:55 +0000295
296 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000297 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
Igor Sysoeva6717c42002-12-23 06:29:22 +0000298 ngx_close_file_n " %s failed",
299 cf->conf_file->file.name.data);
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000300 return NGX_CONF_ERROR;
Igor Sysoev88092572002-12-19 07:08:55 +0000301 }
302 }
303
Igor Sysoev9d639522003-07-07 06:11:50 +0000304 if (rc == NGX_ERROR) {
305 return NGX_CONF_ERROR;
306 }
307
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000308 return NGX_CONF_OK;
Igor Sysoeva6717c42002-12-23 06:29:22 +0000309}
Igor Sysoev88092572002-12-19 07:08:55 +0000310
Igor Sysoev88092572002-12-19 07:08:55 +0000311
Igor Sysoev960ffa42002-12-26 07:24:21 +0000312static int ngx_conf_read_token(ngx_conf_t *cf)
Igor Sysoev88092572002-12-19 07:08:55 +0000313{
Igor Sysoev10a543a2004-03-16 07:10:12 +0000314 u_char *start, ch, *src, *dst;
Igor Sysoev960ffa42002-12-26 07:24:21 +0000315 int len;
316 int found, need_space, last_space, sharp_comment;
317 int quoted, s_quoted, d_quoted;
Igor Sysoeva6717c42002-12-23 06:29:22 +0000318 ssize_t n;
319 ngx_str_t *word;
Igor Sysoev369145c2004-05-28 15:49:23 +0000320 ngx_buf_t *b;
Igor Sysoev88092572002-12-19 07:08:55 +0000321
Igor Sysoeva6717c42002-12-23 06:29:22 +0000322 found = 0;
Igor Sysoev88092572002-12-19 07:08:55 +0000323 need_space = 0;
324 last_space = 1;
Igor Sysoev960ffa42002-12-26 07:24:21 +0000325 sharp_comment = 0;
Igor Sysoev88092572002-12-19 07:08:55 +0000326 quoted = s_quoted = d_quoted = 0;
327
328 cf->args->nelts = 0;
Igor Sysoev369145c2004-05-28 15:49:23 +0000329 b = cf->conf_file->buffer;
330 start = b->pos;
Igor Sysoev88092572002-12-19 07:08:55 +0000331
Igor Sysoev73009772003-02-06 17:21:13 +0000332#if 0
Igor Sysoeva6717c42002-12-23 06:29:22 +0000333ngx_log_debug(cf->log, "TOKEN START");
Igor Sysoev73009772003-02-06 17:21:13 +0000334#endif
Igor Sysoeva6717c42002-12-23 06:29:22 +0000335
Igor Sysoev295bb632002-12-23 18:22:18 +0000336 for ( ;; ) {
Igor Sysoev88092572002-12-19 07:08:55 +0000337
Igor Sysoev369145c2004-05-28 15:49:23 +0000338 if (b->pos >= b->last) {
Igor Sysoeva6717c42002-12-23 06:29:22 +0000339 if (cf->conf_file->file.offset
Igor Sysoev369145c2004-05-28 15:49:23 +0000340 >= ngx_file_size(&cf->conf_file->file.info)) {
Igor Sysoev960ffa42002-12-26 07:24:21 +0000341 return NGX_CONF_FILE_DONE;
Igor Sysoeva6717c42002-12-23 06:29:22 +0000342 }
343
Igor Sysoev369145c2004-05-28 15:49:23 +0000344 if (b->pos - start) {
345 ngx_memcpy(b->start, start, b->pos - start);
Igor Sysoev88092572002-12-19 07:08:55 +0000346 }
347
Igor Sysoeva6717c42002-12-23 06:29:22 +0000348 n = ngx_read_file(&cf->conf_file->file,
Igor Sysoev369145c2004-05-28 15:49:23 +0000349 b->start + (b->pos - start),
350 b->end - (b->start + (b->pos - start)),
Igor Sysoev88092572002-12-19 07:08:55 +0000351 cf->conf_file->file.offset);
352
353 if (n == NGX_ERROR) {
354 return NGX_ERROR;
355 }
356
Igor Sysoev369145c2004-05-28 15:49:23 +0000357 b->pos = b->start + (b->pos - start);
358 start = b->start;
359 b->last = b->pos + n;
Igor Sysoev88092572002-12-19 07:08:55 +0000360 }
361
Igor Sysoev369145c2004-05-28 15:49:23 +0000362 ch = *b->pos++;
Igor Sysoeva6717c42002-12-23 06:29:22 +0000363
Igor Sysoev295bb632002-12-23 18:22:18 +0000364#if 0
Igor Sysoeva6717c42002-12-23 06:29:22 +0000365ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
366 last_space _ need_space _
367 quoted _ s_quoted _ d_quoted _ ch);
Igor Sysoev295bb632002-12-23 18:22:18 +0000368#endif
Igor Sysoev88092572002-12-19 07:08:55 +0000369
370 if (ch == LF) {
371 cf->conf_file->line++;
Igor Sysoev960ffa42002-12-26 07:24:21 +0000372
373 if (sharp_comment) {
374 sharp_comment = 0;
375 }
376 }
377
378 if (sharp_comment) {
379 continue;
Igor Sysoev88092572002-12-19 07:08:55 +0000380 }
381
Igor Sysoev295bb632002-12-23 18:22:18 +0000382 if (quoted) {
383 quoted = 0;
384 continue;
385 }
386
Igor Sysoeva6717c42002-12-23 06:29:22 +0000387 if (need_space) {
388 if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
389 last_space = 1;
390 need_space = 0;
391 continue;
392 }
393
394 if (ch == ';' || ch == '{') {
395 return NGX_OK;
396 }
397
Igor Sysoev78329332003-11-10 17:17:31 +0000398 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
399 "unexpected '%c' in %s:%d",
400 ch, cf->conf_file->file.name.data,
401 cf->conf_file->line);
402
Igor Sysoeva6717c42002-12-23 06:29:22 +0000403 return NGX_ERROR;
404 }
405
Igor Sysoev88092572002-12-19 07:08:55 +0000406 if (last_space) {
Igor Sysoev88092572002-12-19 07:08:55 +0000407 if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
Igor Sysoeva6717c42002-12-23 06:29:22 +0000408 continue;
409 }
410
Igor Sysoev369145c2004-05-28 15:49:23 +0000411 start = b->pos - 1;
Igor Sysoeva6717c42002-12-23 06:29:22 +0000412
413 switch (ch) {
414
Igor Sysoev295bb632002-12-23 18:22:18 +0000415 case ';':
416 case '{':
Igor Sysoev960ffa42002-12-26 07:24:21 +0000417 if (cf->args->nelts == 0) {
418 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
419 "unexpected '%c' in %s:%d",
420 ch, cf->conf_file->file.name.data,
421 cf->conf_file->line);
422 return NGX_ERROR;
423 }
424
Igor Sysoev295bb632002-12-23 18:22:18 +0000425 return NGX_OK;
426
Igor Sysoev960ffa42002-12-26 07:24:21 +0000427 case '}':
428 if (cf->args->nelts > 0) {
429 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
430 "unexpected '}' in %s:%d",
431 cf->conf_file->file.name.data,
432 cf->conf_file->line);
433 return NGX_ERROR;
434 }
435
436 return NGX_CONF_BLOCK_DONE;
437
438 case '#':
439 sharp_comment = 1;
440 continue;
441
Igor Sysoeva6717c42002-12-23 06:29:22 +0000442 case '\\':
443 quoted = 1;
444 last_space = 0;
445 continue;
446
447 case '"':
Igor Sysoev88092572002-12-19 07:08:55 +0000448 start++;
Igor Sysoeva6717c42002-12-23 06:29:22 +0000449 d_quoted = 1;
450 last_space = 0;
Igor Sysoev88092572002-12-19 07:08:55 +0000451 continue;
Igor Sysoev88092572002-12-19 07:08:55 +0000452
Igor Sysoeva6717c42002-12-23 06:29:22 +0000453 case '\'':
454 start++;
Igor Sysoeva6717c42002-12-23 06:29:22 +0000455 s_quoted = 1;
456 last_space = 0;
Igor Sysoev88092572002-12-19 07:08:55 +0000457 continue;
Igor Sysoev88092572002-12-19 07:08:55 +0000458
Igor Sysoeva6717c42002-12-23 06:29:22 +0000459 default:
460 last_space = 0;
Igor Sysoev88092572002-12-19 07:08:55 +0000461 }
462
463 } else {
Igor Sysoeva6717c42002-12-23 06:29:22 +0000464 if (ch == '\\') {
465 quoted = 1;
466 continue;
467 }
Igor Sysoev88092572002-12-19 07:08:55 +0000468
Igor Sysoeva6717c42002-12-23 06:29:22 +0000469 if (d_quoted) {
470 if (ch == '"') {
Igor Sysoeva6717c42002-12-23 06:29:22 +0000471 d_quoted = 0;
472 need_space = 1;
473 found = 1;
474 }
475
476 } else if (s_quoted) {
477 if (ch == '\'') {
Igor Sysoeva6717c42002-12-23 06:29:22 +0000478 s_quoted = 0;
479 need_space = 1;
480 found = 1;
481 }
482
483 } else if (ch == ' ' || ch == '\t' || ch == CR || ch == LF
484 || ch == ';' || ch == '{') {
Igor Sysoeva6717c42002-12-23 06:29:22 +0000485 last_space = 1;
486 found = 1;
487 }
488
489 if (found) {
Igor Sysoev369145c2004-05-28 15:49:23 +0000490 if (!(word = ngx_push_array(cf->args))) {
491 return NGX_ERROR;
492 }
493
494 if (!(word->data = ngx_palloc(cf->pool, b->pos - start + 1))) {
495 return NGX_ERROR;
496 }
Igor Sysoev88092572002-12-19 07:08:55 +0000497
Igor Sysoev295bb632002-12-23 18:22:18 +0000498 for (dst = word->data, src = start, len = 0;
Igor Sysoev369145c2004-05-28 15:49:23 +0000499 src < b->pos - 1;
Igor Sysoev295bb632002-12-23 18:22:18 +0000500 len++)
Igor Sysoeva6717c42002-12-23 06:29:22 +0000501 {
502 if (*src == '\\') {
Igor Sysoeva8fa0a62003-11-25 20:44:56 +0000503 switch (src[1]) {
504 case '"':
505 case '\'':
506 case '\\':
507 src++;
508 break;
509
510 case 't':
511 *dst++ = '\t';
512 src += 2;
513 continue;
514
515 case 'r':
516 *dst++ = '\r';
517 src += 2;
518 continue;
519
520 case 'n':
521 *dst++ = '\n';
522 src += 2;
523 continue;
524 }
525
Igor Sysoeva6717c42002-12-23 06:29:22 +0000526 }
Igor Sysoev88092572002-12-19 07:08:55 +0000527 *dst++ = *src++;
528 }
529 *dst = '\0';
Igor Sysoev295bb632002-12-23 18:22:18 +0000530 word->len = len;
Igor Sysoev88092572002-12-19 07:08:55 +0000531
Igor Sysoev73009772003-02-06 17:21:13 +0000532#if 0
Igor Sysoeva6717c42002-12-23 06:29:22 +0000533ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data);
Igor Sysoev73009772003-02-06 17:21:13 +0000534#endif
Igor Sysoev88092572002-12-19 07:08:55 +0000535
Igor Sysoeva6717c42002-12-23 06:29:22 +0000536 if (ch == ';' || ch == '{') {
537 return NGX_OK;
Igor Sysoev88092572002-12-19 07:08:55 +0000538 }
539
Igor Sysoeva6717c42002-12-23 06:29:22 +0000540 found = 0;
Igor Sysoev88092572002-12-19 07:08:55 +0000541 }
Igor Sysoev88092572002-12-19 07:08:55 +0000542 }
543 }
544}
545
Igor Sysoev88092572002-12-19 07:08:55 +0000546
Igor Sysoevab517d52004-05-18 15:29:08 +0000547static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
548{
549 ngx_str_t *value, file;
550
551 value = cf->args->elts;
552
Igor Sysoev090849d2004-05-18 20:28:54 +0000553 if (value[1].data[0] == '/') {
554 return ngx_conf_parse(cf, &value[1]);
555 }
556
Igor Sysoevab517d52004-05-18 15:29:08 +0000557 file.len = cf->cycle->root.len + value[1].len;
558 if (!(file.data = ngx_palloc(cf->pool, file.len + 1))) {
559 return NGX_CONF_ERROR;
560 }
561
562 ngx_cpystrn(ngx_cpymem(file.data, cf->cycle->root.data,
563 cf->cycle->root.len),
564 value[1].data, value[1].len + 1);
565
566 ngx_log_error(NGX_LOG_INFO, cf->log, 0, "include %s", file.data);
567
568 return ngx_conf_parse(cf, &file);
569}
570
571
Igor Sysoev890fc962003-07-20 21:15:59 +0000572ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
573{
Igor Sysoev10a543a2004-03-16 07:10:12 +0000574 ngx_uint_t i;
Igor Sysoevb9e34412004-09-03 15:50:30 +0000575 ngx_list_part_t *part;
Igor Sysoev890fc962003-07-20 21:15:59 +0000576 ngx_open_file_t *file;
577
578 if (name) {
Igor Sysoevb9e34412004-09-03 15:50:30 +0000579 part = &cycle->open_files.part;
580 file = part->elts;
581
582 for (i = 0; /* void */ ; i++) {
583
584 if (i >= part->nelts) {
585 if (part->next == NULL) {
586 break;
587 }
588 part = part->next;
589 file = part->elts;
590 i = 0;
591 }
592
Igor Sysoev890fc962003-07-20 21:15:59 +0000593 if (name->len != file[i].name.len) {
594 continue;
595 }
596
597 if (ngx_strcmp(name->data, file[i].name.data) == 0) {
598 return &file[i];
599 }
600 }
601 }
602
Igor Sysoevaab4d8c2004-09-06 18:45:00 +0000603 if (!(file = ngx_list_push(&cycle->open_files))) {
Igor Sysoev369145c2004-05-28 15:49:23 +0000604 return NULL;
605 }
606
Igor Sysoev890fc962003-07-20 21:15:59 +0000607 file->fd = NGX_INVALID_FILE;
Igor Sysoev369145c2004-05-28 15:49:23 +0000608
Igor Sysoev890fc962003-07-20 21:15:59 +0000609 if (name) {
610 file->name = *name;
Igor Sysoev980a9242004-09-05 19:54:02 +0000611 } else {
612 file->name.len = 0;
613 file->name.data = NULL;
Igor Sysoev890fc962003-07-20 21:15:59 +0000614 }
615
616 return file;
617}
618
619
Igor Sysoev54498db2004-02-11 17:08:49 +0000620void ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
Igor Sysoev8e1fbe62003-07-18 14:44:05 +0000621 char *fmt, ...)
622{
623 int len;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +0000624 char errstr[NGX_MAX_CONF_ERRSTR];
Igor Sysoev8e1fbe62003-07-18 14:44:05 +0000625 va_list args;
626
627 va_start(args, fmt);
628 len = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args);
629 va_end(args);
630
631 if (err) {
632 len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
633 " (%d: ", err);
634 len += ngx_strerror_r(err, errstr + len, sizeof(errstr) - len - 1);
635 errstr[len++] = ')';
Igor Sysoev11dbe972004-03-29 17:43:58 +0000636 errstr[len] = '\0';
Igor Sysoev8e1fbe62003-07-18 14:44:05 +0000637 }
638
639 ngx_log_error(level, cf->log, 0, "%s in %s:%d",
640 errstr, cf->conf_file->file.name.data, cf->conf_file->line);
641}
642
643
Igor Sysoev6253ca12003-05-27 12:18:54 +0000644char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev6a644c62003-03-04 06:33:48 +0000645{
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000646 char *p = conf;
647
Igor Sysoev85080d02004-09-22 16:18:21 +0000648 ngx_str_t *value;
649 ngx_flag_t *fp;
650 ngx_conf_post_t *post;
Igor Sysoev6a644c62003-03-04 06:33:48 +0000651
Igor Sysoev85080d02004-09-22 16:18:21 +0000652 fp = (ngx_flag_t *) (p + cmd->offset);
Igor Sysoevf1079102003-10-23 06:13:16 +0000653
Igor Sysoev85080d02004-09-22 16:18:21 +0000654 if (*fp != NGX_CONF_UNSET) {
Igor Sysoev1c13c662003-05-20 15:37:55 +0000655 return "is duplicate";
656 }
657
Igor Sysoeva3677242004-04-14 05:57:36 +0000658 value = cf->args->elts;
Igor Sysoev6a644c62003-03-04 06:33:48 +0000659
660 if (ngx_strcasecmp(value[1].data, "on") == 0) {
Igor Sysoev85080d02004-09-22 16:18:21 +0000661 *fp = 1;
Igor Sysoev6a644c62003-03-04 06:33:48 +0000662
663 } else if (ngx_strcasecmp(value[1].data, "off") == 0) {
Igor Sysoev85080d02004-09-22 16:18:21 +0000664 *fp = 0;
Igor Sysoev6a644c62003-03-04 06:33:48 +0000665
666 } else {
Igor Sysoev890fc962003-07-20 21:15:59 +0000667 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
668 "invalid value \"%s\" in \"%s\" directive, "
669 "it must be \"on\" or \"off\"",
670 value[1].data, cmd->name.data);
671 return NGX_CONF_ERROR;
Igor Sysoev6a644c62003-03-04 06:33:48 +0000672 }
673
Igor Sysoev85080d02004-09-22 16:18:21 +0000674 if (cmd->post) {
675 post = cmd->post;
676 return post->post_handler(cf, post, fp);
677 }
Igor Sysoev6a644c62003-03-04 06:33:48 +0000678
679 return NGX_CONF_OK;
680}
681
682
Igor Sysoev6253ca12003-05-27 12:18:54 +0000683char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000684{
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000685 char *p = conf;
686
Igor Sysoev13836ce2004-08-31 15:32:52 +0000687 ngx_str_t *field, *value;
688 ngx_conf_post_t *post;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000689
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000690 field = (ngx_str_t *) (p + cmd->offset);
Igor Sysoev1c13c662003-05-20 15:37:55 +0000691
Igor Sysoev6253ca12003-05-27 12:18:54 +0000692 if (field->data) {
Igor Sysoev1c13c662003-05-20 15:37:55 +0000693 return "is duplicate";
694 }
695
Igor Sysoeva3677242004-04-14 05:57:36 +0000696 value = cf->args->elts;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000697
Igor Sysoevdc9dd432003-10-22 16:38:26 +0000698 *field = value[1];
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000699
Igor Sysoev13836ce2004-08-31 15:32:52 +0000700 if (cmd->post) {
701 post = cmd->post;
702 return post->post_handler(cf, post, field);
703 }
704
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000705 return NGX_CONF_OK;
706}
707
708
Igor Sysoev6253ca12003-05-27 12:18:54 +0000709char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000710{
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000711 char *p = conf;
712
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000713 ngx_int_t *np;
Igor Sysoev12b4b002003-10-24 06:53:41 +0000714 ngx_str_t *value;
715 ngx_conf_post_t *post;
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000716
Igor Sysoevf1079102003-10-23 06:13:16 +0000717
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000718 np = (ngx_int_t *) (p + cmd->offset);
Igor Sysoevf1079102003-10-23 06:13:16 +0000719
720 if (*np != NGX_CONF_UNSET) {
Igor Sysoev1c13c662003-05-20 15:37:55 +0000721 return "is duplicate";
722 }
723
Igor Sysoeva3677242004-04-14 05:57:36 +0000724 value = cf->args->elts;
Igor Sysoevf1079102003-10-23 06:13:16 +0000725 *np = ngx_atoi(value[1].data, value[1].len);
726 if (*np == NGX_ERROR) {
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000727 return "invalid number";
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000728 }
729
Igor Sysoev12b4b002003-10-24 06:53:41 +0000730 if (cmd->post) {
731 post = cmd->post;
732 return post->post_handler(cf, post, np);
Igor Sysoevf1079102003-10-23 06:13:16 +0000733 }
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000734
735 return NGX_CONF_OK;
736}
737
738
Igor Sysoev6253ca12003-05-27 12:18:54 +0000739char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev960ffa42002-12-26 07:24:21 +0000740{
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000741 char *p = conf;
742
Igor Sysoev10a543a2004-03-16 07:10:12 +0000743 size_t *sp;
Igor Sysoev12b4b002003-10-24 06:53:41 +0000744 ngx_str_t *value;
745 ngx_conf_post_t *post;
Igor Sysoev960ffa42002-12-26 07:24:21 +0000746
Igor Sysoevf1079102003-10-23 06:13:16 +0000747
Igor Sysoev10a543a2004-03-16 07:10:12 +0000748 sp = (size_t *) (p + cmd->offset);
749 if (*sp != NGX_CONF_UNSET_SIZE) {
Igor Sysoev1c13c662003-05-20 15:37:55 +0000750 return "is duplicate";
751 }
752
Igor Sysoeva3677242004-04-14 05:57:36 +0000753 value = cf->args->elts;
Igor Sysoev960ffa42002-12-26 07:24:21 +0000754
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000755 *sp = ngx_parse_size(&value[1]);
Igor Sysoev10a543a2004-03-16 07:10:12 +0000756 if (*sp == (size_t) NGX_ERROR) {
Igor Sysoev3d09c8d2003-05-06 17:03:16 +0000757 return "invalid value";
Igor Sysoev960ffa42002-12-26 07:24:21 +0000758 }
Igor Sysoev88092572002-12-19 07:08:55 +0000759
Igor Sysoev12b4b002003-10-24 06:53:41 +0000760 if (cmd->post) {
761 post = cmd->post;
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000762 return post->post_handler(cf, post, sp);
Igor Sysoevf1079102003-10-23 06:13:16 +0000763 }
Igor Sysoev960ffa42002-12-26 07:24:21 +0000764
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000765 return NGX_CONF_OK;
Igor Sysoev88092572002-12-19 07:08:55 +0000766}
767
Igor Sysoev88092572002-12-19 07:08:55 +0000768
Igor Sysoev6253ca12003-05-27 12:18:54 +0000769char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev960ffa42002-12-26 07:24:21 +0000770{
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000771 char *p = conf;
772
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000773 ngx_msec_t *msp;
Igor Sysoev12b4b002003-10-24 06:53:41 +0000774 ngx_str_t *value;
775 ngx_conf_post_t *post;
Igor Sysoev960ffa42002-12-26 07:24:21 +0000776
Igor Sysoevf1079102003-10-23 06:13:16 +0000777
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000778 msp = (ngx_msec_t *) (p + cmd->offset);
Igor Sysoev10a543a2004-03-16 07:10:12 +0000779 if (*msp != NGX_CONF_UNSET_MSEC) {
Igor Sysoev1c13c662003-05-20 15:37:55 +0000780 return "is duplicate";
781 }
782
Igor Sysoeva3677242004-04-14 05:57:36 +0000783 value = cf->args->elts;
Igor Sysoev960ffa42002-12-26 07:24:21 +0000784
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000785 *msp = ngx_parse_time(&value[1], 0);
786 if (*msp == (ngx_msec_t) NGX_ERROR) {
Igor Sysoev8556e6d2003-10-23 15:54:19 +0000787 return "invalid value";
Igor Sysoev1d8d9ee2003-04-28 15:06:39 +0000788 }
789
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000790 if (*msp == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
Igor Sysoev8556e6d2003-10-23 15:54:19 +0000791 return "value must be less than 597 hours";
792 }
Igor Sysoevf1079102003-10-23 06:13:16 +0000793
Igor Sysoev12b4b002003-10-24 06:53:41 +0000794 if (cmd->post) {
795 post = cmd->post;
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000796 return post->post_handler(cf, post, msp);
Igor Sysoevf1079102003-10-23 06:13:16 +0000797 }
Igor Sysoev960ffa42002-12-26 07:24:21 +0000798
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000799 return NGX_CONF_OK;
Igor Sysoev88092572002-12-19 07:08:55 +0000800}
Igor Sysoev6a644c62003-03-04 06:33:48 +0000801
Igor Sysoev3d09c8d2003-05-06 17:03:16 +0000802
Igor Sysoev6253ca12003-05-27 12:18:54 +0000803char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev3d09c8d2003-05-06 17:03:16 +0000804{
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000805 char *p = conf;
806
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000807 time_t *sp;
Igor Sysoev12b4b002003-10-24 06:53:41 +0000808 ngx_str_t *value;
809 ngx_conf_post_t *post;
Igor Sysoev3d09c8d2003-05-06 17:03:16 +0000810
Igor Sysoevf1079102003-10-23 06:13:16 +0000811
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000812 sp = (time_t *) (p + cmd->offset);
813 if (*sp != NGX_CONF_UNSET) {
Igor Sysoev1c13c662003-05-20 15:37:55 +0000814 return "is duplicate";
815 }
816
Igor Sysoeva3677242004-04-14 05:57:36 +0000817 value = cf->args->elts;
Igor Sysoev3d09c8d2003-05-06 17:03:16 +0000818
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000819 *sp = ngx_parse_time(&value[1], 1);
820 if (*sp == NGX_ERROR) {
Igor Sysoev8556e6d2003-10-23 15:54:19 +0000821 return "invalid value";
Igor Sysoev3d09c8d2003-05-06 17:03:16 +0000822 }
823
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000824 if (*sp == NGX_PARSE_LARGE_TIME) {
Igor Sysoev8556e6d2003-10-23 15:54:19 +0000825 return "value must be less than 68 years";
826 }
Igor Sysoevf1079102003-10-23 06:13:16 +0000827
Igor Sysoev12b4b002003-10-24 06:53:41 +0000828 if (cmd->post) {
829 post = cmd->post;
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000830 return post->post_handler(cf, post, sp);
Igor Sysoevf1079102003-10-23 06:13:16 +0000831 }
Igor Sysoev3d09c8d2003-05-06 17:03:16 +0000832
833 return NGX_CONF_OK;
834}
835
836
Igor Sysoev3ae32482003-10-08 15:32:54 +0000837char *ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
838{
Igor Sysoev68ee8f12003-10-30 08:51:06 +0000839 char *p = conf;
Igor Sysoev3ae32482003-10-08 15:32:54 +0000840
Igor Sysoev3ae32482003-10-08 15:32:54 +0000841 ngx_str_t *value;
842 ngx_bufs_t *bufs;
843
844
845 bufs = (ngx_bufs_t *) (p + cmd->offset);
Igor Sysoev3ae32482003-10-08 15:32:54 +0000846 if (bufs->num) {
847 return "is duplicate";
848 }
849
Igor Sysoeva3677242004-04-14 05:57:36 +0000850 value = cf->args->elts;
Igor Sysoev3ae32482003-10-08 15:32:54 +0000851
852 bufs->num = ngx_atoi(value[1].data, value[1].len);
853 if (bufs->num == NGX_ERROR || bufs->num == 0) {
854 return "invalid value";
855 }
856
Igor Sysoev8556e6d2003-10-23 15:54:19 +0000857 bufs->size = ngx_parse_size(&value[2]);
Igor Sysoevb5910d42003-10-30 16:51:33 +0000858 if (bufs->size == (size_t) NGX_ERROR || bufs->size == 0) {
Igor Sysoev3ae32482003-10-08 15:32:54 +0000859 return "invalid value";
860 }
861
Igor Sysoev3ae32482003-10-08 15:32:54 +0000862 return NGX_CONF_OK;
863}
864
865
Igor Sysoeva3677242004-04-14 05:57:36 +0000866char *ngx_conf_set_enum_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
867{
868 char *p = conf;
869
870 ngx_uint_t *np, i;
871 ngx_str_t *value;
872 ngx_conf_enum_t *e;
873
874 np = (ngx_uint_t *) (p + cmd->offset);
875
876 if (*np != NGX_CONF_UNSET_UINT) {
877 return "is duplicate";
878 }
879
880 value = cf->args->elts;
881 e = cmd->post;
882
883 for (i = 0; e[i].name.len != 0; i++) {
884 if (e[i].name.len != value[1].len
885 || ngx_strcasecmp(e[i].name.data, value[1].data) != 0)
886 {
887 continue;
888 }
889
890 *np = e[i].value;
891
892 return NGX_CONF_OK;
893 }
894
895 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
896 "invalid value \"%s\"", value[1].data);
897
898 return NGX_CONF_ERROR;
899}
900
901
Igor Sysoev68ee8f12003-10-30 08:51:06 +0000902char *ngx_conf_set_bitmask_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
903{
904 char *p = conf;
905
Igor Sysoev10a543a2004-03-16 07:10:12 +0000906 ngx_uint_t *np, i, m;
Igor Sysoev68ee8f12003-10-30 08:51:06 +0000907 ngx_str_t *value;
908 ngx_conf_bitmask_t *mask;
909
910
Igor Sysoev10a543a2004-03-16 07:10:12 +0000911 np = (ngx_uint_t *) (p + cmd->offset);
Igor Sysoeva3677242004-04-14 05:57:36 +0000912 value = cf->args->elts;
Igor Sysoev68ee8f12003-10-30 08:51:06 +0000913 mask = cmd->post;
914
915 for (i = 1; i < cf->args->nelts; i++) {
916 for (m = 0; mask[m].name.len != 0; m++) {
917
918 if (mask[m].name.len != value[i].len
Igor Sysoeva3677242004-04-14 05:57:36 +0000919 || ngx_strcasecmp(mask[m].name.data, value[i].data) != 0)
Igor Sysoev68ee8f12003-10-30 08:51:06 +0000920 {
921 continue;
922 }
923
924 if (*np & mask[m].mask) {
925 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
926 "duplicate value \"%s\"", value[i].data);
927
928 } else {
929 *np |= mask[m].mask;
930 }
931
932 break;
933 }
934
935 if (mask[m].name.len == 0) {
936 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
937 "invalid value \"%s\"", value[i].data);
938
939 return NGX_CONF_ERROR;
940 }
941 }
942
943 return NGX_CONF_OK;
944}
945
946
Igor Sysoev6253ca12003-05-27 12:18:54 +0000947char *ngx_conf_unsupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev6a644c62003-03-04 06:33:48 +0000948{
949 return "unsupported on this platform";
950}
Igor Sysoevf1079102003-10-23 06:13:16 +0000951
952
Igor Sysoev12b4b002003-10-24 06:53:41 +0000953char *ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data)
Igor Sysoevf1079102003-10-23 06:13:16 +0000954{
Igor Sysoev369145c2004-05-28 15:49:23 +0000955 ngx_conf_num_bounds_t *bounds = post;
956 ngx_int_t *np = data;
Igor Sysoevf1079102003-10-23 06:13:16 +0000957
Igor Sysoevcf80a702003-11-03 22:20:44 +0000958 if (bounds->high == -1) {
959 if (*np >= bounds->low) {
960 return NGX_CONF_OK;
961 }
962
963 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoevf60b1a52003-11-04 17:09:19 +0000964 "value must be equal or more than %d", bounds->low);
Igor Sysoevcf80a702003-11-03 22:20:44 +0000965
966 return NGX_CONF_ERROR;
967 }
968
969 if (*np >= bounds->low && *np <= bounds->high) {
Igor Sysoevf1079102003-10-23 06:13:16 +0000970 return NGX_CONF_OK;
Igor Sysoevf1079102003-10-23 06:13:16 +0000971 }
972
Igor Sysoevcf80a702003-11-03 22:20:44 +0000973 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
974 "value must be between %d and %d",
975 bounds->low, bounds->high);
976
977 return NGX_CONF_ERROR;
Igor Sysoevf1079102003-10-23 06:13:16 +0000978}