0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
660
|
4 * Copyright (C) Nginx, Inc.
|
0
|
5 */
|
|
6
|
|
7
|
|
8 #include <ngx_config.h>
|
|
9 #include <ngx_core.h>
|
|
10
|
404
|
11 #define NGX_CONF_BUFFER 4096
|
0
|
12
|
50
|
13 static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last);
|
52
|
14 static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf);
|
0
|
15 static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
496
|
16 static ngx_int_t ngx_conf_test_full_name(ngx_str_t *name);
|
120
|
17 static void ngx_conf_flush_files(ngx_cycle_t *cycle);
|
0
|
18
|
|
19
|
|
20 static ngx_command_t ngx_conf_commands[] = {
|
|
21
|
|
22 { ngx_string("include"),
|
|
23 NGX_ANY_CONF|NGX_CONF_TAKE1,
|
|
24 ngx_conf_include,
|
|
25 0,
|
|
26 0,
|
|
27 NULL },
|
|
28
|
|
29 ngx_null_command
|
|
30 };
|
|
31
|
|
32
|
|
33 ngx_module_t ngx_conf_module = {
|
58
|
34 NGX_MODULE_V1,
|
0
|
35 NULL, /* module context */
|
|
36 ngx_conf_commands, /* module directives */
|
|
37 NGX_CONF_MODULE, /* module type */
|
90
|
38 NULL, /* init master */
|
0
|
39 NULL, /* init module */
|
90
|
40 NULL, /* init process */
|
|
41 NULL, /* init thread */
|
|
42 NULL, /* exit thread */
|
120
|
43 ngx_conf_flush_files, /* exit process */
|
90
|
44 NULL, /* exit master */
|
|
45 NGX_MODULE_V1_PADDING
|
0
|
46 };
|
|
47
|
|
48
|
404
|
49 /* The eight fixed arguments */
|
0
|
50
|
404
|
51 static ngx_uint_t argument_number[] = {
|
0
|
52 NGX_CONF_NOARGS,
|
|
53 NGX_CONF_TAKE1,
|
|
54 NGX_CONF_TAKE2,
|
|
55 NGX_CONF_TAKE3,
|
|
56 NGX_CONF_TAKE4,
|
|
57 NGX_CONF_TAKE5,
|
|
58 NGX_CONF_TAKE6,
|
|
59 NGX_CONF_TAKE7
|
|
60 };
|
|
61
|
|
62
|
52
|
63 char *
|
384
|
64 ngx_conf_param(ngx_conf_t *cf)
|
|
65 {
|
484
|
66 char *rv;
|
384
|
67 ngx_str_t *param;
|
|
68 ngx_buf_t b;
|
|
69 ngx_conf_file_t conf_file;
|
|
70
|
|
71 param = &cf->cycle->conf_param;
|
|
72
|
|
73 if (param->len == 0) {
|
|
74 return NGX_CONF_OK;
|
|
75 }
|
|
76
|
|
77 ngx_memzero(&conf_file, sizeof(ngx_conf_file_t));
|
|
78
|
|
79 ngx_memzero(&b, sizeof(ngx_buf_t));
|
|
80
|
|
81 b.start = param->data;
|
|
82 b.pos = param->data;
|
|
83 b.last = param->data + param->len;
|
|
84 b.end = b.last;
|
|
85 b.temporary = 1;
|
|
86
|
|
87 conf_file.file.fd = NGX_INVALID_FILE;
|
484
|
88 conf_file.file.name.data = NULL;
|
|
89 conf_file.line = 0;
|
384
|
90
|
|
91 cf->conf_file = &conf_file;
|
|
92 cf->conf_file->buffer = &b;
|
|
93
|
484
|
94 rv = ngx_conf_parse(cf, NULL);
|
|
95
|
|
96 cf->conf_file = NULL;
|
|
97
|
|
98 return rv;
|
384
|
99 }
|
|
100
|
|
101
|
|
102 char *
|
52
|
103 ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
|
0
|
104 {
|
|
105 char *rv;
|
|
106 ngx_fd_t fd;
|
50
|
107 ngx_int_t rc;
|
422
|
108 ngx_buf_t buf;
|
|
109 ngx_conf_file_t *prev, conf_file;
|
384
|
110 enum {
|
|
111 parse_file = 0,
|
|
112 parse_block,
|
|
113 parse_param
|
|
114 } type;
|
0
|
115
|
|
116 #if (NGX_SUPPRESS_WARN)
|
|
117 fd = NGX_INVALID_FILE;
|
|
118 prev = NULL;
|
|
119 #endif
|
|
120
|
|
121 if (filename) {
|
|
122
|
|
123 /* open configuration file */
|
|
124
|
276
|
125 fd = ngx_open_file(filename->data, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0);
|
0
|
126 if (fd == NGX_INVALID_FILE) {
|
130
|
127 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
|
142
|
128 ngx_open_file_n " \"%s\" failed",
|
|
129 filename->data);
|
0
|
130 return NGX_CONF_ERROR;
|
|
131 }
|
|
132
|
|
133 prev = cf->conf_file;
|
50
|
134
|
422
|
135 cf->conf_file = &conf_file;
|
0
|
136
|
|
137 if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) {
|
|
138 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
|
10
|
139 ngx_fd_info_n " \"%s\" failed", filename->data);
|
0
|
140 }
|
|
141
|
422
|
142 cf->conf_file->buffer = &buf;
|
|
143
|
|
144 buf.start = ngx_alloc(NGX_CONF_BUFFER, cf->log);
|
|
145 if (buf.start == NULL) {
|
|
146 goto failed;
|
0
|
147 }
|
|
148
|
422
|
149 buf.pos = buf.start;
|
|
150 buf.last = buf.start;
|
|
151 buf.end = buf.last + NGX_CONF_BUFFER;
|
|
152 buf.temporary = 1;
|
178
|
153
|
0
|
154 cf->conf_file->file.fd = fd;
|
|
155 cf->conf_file->file.name.len = filename->len;
|
|
156 cf->conf_file->file.name.data = filename->data;
|
|
157 cf->conf_file->file.offset = 0;
|
340
|
158 cf->conf_file->file.log = cf->log;
|
0
|
159 cf->conf_file->line = 1;
|
92
|
160
|
384
|
161 type = parse_file;
|
|
162
|
|
163 } else if (cf->conf_file->file.fd != NGX_INVALID_FILE) {
|
|
164
|
|
165 type = parse_block;
|
92
|
166
|
|
167 } else {
|
384
|
168 type = parse_param;
|
0
|
169 }
|
|
170
|
92
|
171
|
0
|
172 for ( ;; ) {
|
|
173 rc = ngx_conf_read_token(cf);
|
|
174
|
|
175 /*
|
10
|
176 * ngx_conf_read_token() may return
|
92
|
177 *
|
10
|
178 * NGX_ERROR there is error
|
|
179 * NGX_OK the token terminated by ";" was found
|
|
180 * NGX_CONF_BLOCK_START the token terminated by "{" was found
|
|
181 * NGX_CONF_BLOCK_DONE the "}" was found
|
|
182 * NGX_CONF_FILE_DONE the configuration file is done
|
0
|
183 */
|
|
184
|
|
185 if (rc == NGX_ERROR) {
|
288
|
186 goto done;
|
0
|
187 }
|
|
188
|
92
|
189 if (rc == NGX_CONF_BLOCK_DONE) {
|
384
|
190
|
|
191 if (type != parse_block) {
|
288
|
192 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "unexpected \"}\"");
|
|
193 goto failed;
|
|
194 }
|
|
195
|
384
|
196 goto done;
|
92
|
197 }
|
|
198
|
384
|
199 if (rc == NGX_CONF_FILE_DONE) {
|
|
200
|
|
201 if (type == parse_block) {
|
|
202 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
203 "unexpected end of file, expecting \"}\"");
|
|
204 goto failed;
|
|
205 }
|
|
206
|
|
207 goto done;
|
92
|
208 }
|
|
209
|
384
|
210 if (rc == NGX_CONF_BLOCK_START) {
|
|
211
|
|
212 if (type == parse_param) {
|
|
213 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
214 "block directives are not supported "
|
|
215 "in -g option");
|
|
216 goto failed;
|
|
217 }
|
0
|
218 }
|
|
219
|
384
|
220 /* rc == NGX_OK || rc == NGX_CONF_BLOCK_START */
|
|
221
|
0
|
222 if (cf->handler) {
|
|
223
|
10
|
224 /*
|
|
225 * the custom handler, i.e., that is used in the http's
|
|
226 * "types { ... }" directive
|
|
227 */
|
0
|
228
|
|
229 rv = (*cf->handler)(cf, NULL, cf->handler_conf);
|
|
230 if (rv == NGX_CONF_OK) {
|
|
231 continue;
|
50
|
232 }
|
0
|
233
|
50
|
234 if (rv == NGX_CONF_ERROR) {
|
288
|
235 goto failed;
|
0
|
236 }
|
|
237
|
288
|
238 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, rv);
|
|
239
|
|
240 goto failed;
|
0
|
241 }
|
|
242
|
50
|
243
|
|
244 rc = ngx_conf_handler(cf, rc);
|
|
245
|
0
|
246 if (rc == NGX_ERROR) {
|
288
|
247 goto failed;
|
0
|
248 }
|
|
249 }
|
|
250
|
288
|
251 failed:
|
|
252
|
|
253 rc = NGX_ERROR;
|
|
254
|
|
255 done:
|
50
|
256
|
0
|
257 if (filename) {
|
422
|
258 if (cf->conf_file->buffer->start) {
|
|
259 ngx_free(cf->conf_file->buffer->start);
|
|
260 }
|
0
|
261
|
|
262 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
|
|
263 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
|
|
264 ngx_close_file_n " %s failed",
|
542
|
265 filename->data);
|
0
|
266 return NGX_CONF_ERROR;
|
|
267 }
|
422
|
268
|
|
269 cf->conf_file = prev;
|
0
|
270 }
|
|
271
|
|
272 if (rc == NGX_ERROR) {
|
|
273 return NGX_CONF_ERROR;
|
|
274 }
|
|
275
|
|
276 return NGX_CONF_OK;
|
|
277 }
|
|
278
|
|
279
|
52
|
280 static ngx_int_t
|
|
281 ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last)
|
50
|
282 {
|
|
283 char *rv;
|
|
284 void *conf, **confp;
|
682
|
285 ngx_uint_t i, found;
|
50
|
286 ngx_str_t *name;
|
|
287 ngx_command_t *cmd;
|
|
288
|
|
289 name = cf->args->elts;
|
|
290
|
682
|
291 found = 0;
|
194
|
292
|
50
|
293 for (i = 0; ngx_modules[i]; i++) {
|
|
294
|
|
295 cmd = ngx_modules[i]->commands;
|
|
296 if (cmd == NULL) {
|
|
297 continue;
|
|
298 }
|
|
299
|
194
|
300 for ( /* void */ ; cmd->name.len; cmd++) {
|
50
|
301
|
194
|
302 if (name->len != cmd->name.len) {
|
|
303 continue;
|
|
304 }
|
50
|
305
|
194
|
306 if (ngx_strcmp(name->data, cmd->name.data) != 0) {
|
|
307 continue;
|
|
308 }
|
|
309
|
682
|
310 found = 1;
|
|
311
|
|
312 if (ngx_modules[i]->type != NGX_CONF_MODULE
|
|
313 && ngx_modules[i]->type != cf->module_type)
|
|
314 {
|
|
315 continue;
|
|
316 }
|
194
|
317
|
|
318 /* is the directive's location right ? */
|
|
319
|
|
320 if (!(cmd->type & cf->cmd_type)) {
|
682
|
321 continue;
|
194
|
322 }
|
|
323
|
|
324 if (!(cmd->type & NGX_CONF_BLOCK) && last != NGX_OK) {
|
288
|
325 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
326 "directive \"%s\" is not terminated by \";\"",
|
|
327 name->data);
|
194
|
328 return NGX_ERROR;
|
|
329 }
|
50
|
330
|
194
|
331 if ((cmd->type & NGX_CONF_BLOCK) && last != NGX_CONF_BLOCK_START) {
|
288
|
332 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
333 "directive \"%s\" has no opening \"{\"",
|
|
334 name->data);
|
194
|
335 return NGX_ERROR;
|
|
336 }
|
50
|
337
|
194
|
338 /* is the directive's argument count right ? */
|
50
|
339
|
194
|
340 if (!(cmd->type & NGX_CONF_ANY)) {
|
50
|
341
|
194
|
342 if (cmd->type & NGX_CONF_FLAG) {
|
50
|
343
|
194
|
344 if (cf->args->nelts != 2) {
|
|
345 goto invalid;
|
50
|
346 }
|
|
347
|
|
348 } else if (cmd->type & NGX_CONF_1MORE) {
|
|
349
|
194
|
350 if (cf->args->nelts < 2) {
|
|
351 goto invalid;
|
50
|
352 }
|
|
353
|
|
354 } else if (cmd->type & NGX_CONF_2MORE) {
|
|
355
|
194
|
356 if (cf->args->nelts < 3) {
|
|
357 goto invalid;
|
50
|
358 }
|
|
359
|
194
|
360 } else if (cf->args->nelts > NGX_CONF_MAX_ARGS) {
|
50
|
361
|
194
|
362 goto invalid;
|
50
|
363
|
194
|
364 } else if (!(cmd->type & argument_number[cf->args->nelts - 1]))
|
|
365 {
|
|
366 goto invalid;
|
50
|
367 }
|
194
|
368 }
|
50
|
369
|
194
|
370 /* set up the directive's configuration context */
|
50
|
371
|
194
|
372 conf = NULL;
|
50
|
373
|
194
|
374 if (cmd->type & NGX_DIRECT_CONF) {
|
|
375 conf = ((void **) cf->ctx)[ngx_modules[i]->index];
|
50
|
376
|
194
|
377 } else if (cmd->type & NGX_MAIN_CONF) {
|
|
378 conf = &(((void **) cf->ctx)[ngx_modules[i]->index]);
|
50
|
379
|
194
|
380 } else if (cf->ctx) {
|
|
381 confp = *(void **) ((char *) cf->ctx + cmd->conf);
|
50
|
382
|
194
|
383 if (confp) {
|
|
384 conf = confp[ngx_modules[i]->ctx_index];
|
50
|
385 }
|
194
|
386 }
|
50
|
387
|
194
|
388 rv = cmd->set(cf, cmd, conf);
|
50
|
389
|
194
|
390 if (rv == NGX_CONF_OK) {
|
|
391 return NGX_OK;
|
|
392 }
|
|
393
|
|
394 if (rv == NGX_CONF_ERROR) {
|
50
|
395 return NGX_ERROR;
|
|
396 }
|
|
397
|
288
|
398 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
308
|
399 "\"%s\" directive %s", name->data, rv);
|
194
|
400
|
|
401 return NGX_ERROR;
|
50
|
402 }
|
|
403 }
|
|
404
|
682
|
405 if (found) {
|
288
|
406 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
682
|
407 "\"%s\" directive is not allowed here", name->data);
|
194
|
408
|
|
409 return NGX_ERROR;
|
|
410 }
|
|
411
|
682
|
412 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
413 "unknown directive \"%s\"", name->data);
|
194
|
414
|
|
415 return NGX_ERROR;
|
|
416
|
|
417 invalid:
|
|
418
|
288
|
419 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
332
|
420 "invalid number of arguments in \"%s\" directive",
|
288
|
421 name->data);
|
50
|
422
|
|
423 return NGX_ERROR;
|
|
424 }
|
|
425
|
|
426
|
52
|
427 static ngx_int_t
|
|
428 ngx_conf_read_token(ngx_conf_t *cf)
|
0
|
429 {
|
|
430 u_char *start, ch, *src, *dst;
|
404
|
431 off_t file_size;
|
|
432 size_t len;
|
|
433 ssize_t n, size;
|
|
434 ngx_uint_t found, need_space, last_space, sharp_comment, variable;
|
|
435 ngx_uint_t quoted, s_quoted, d_quoted, start_line;
|
0
|
436 ngx_str_t *word;
|
|
437 ngx_buf_t *b;
|
|
438
|
|
439 found = 0;
|
|
440 need_space = 0;
|
|
441 last_space = 1;
|
|
442 sharp_comment = 0;
|
58
|
443 variable = 0;
|
492
|
444 quoted = 0;
|
|
445 s_quoted = 0;
|
|
446 d_quoted = 0;
|
0
|
447
|
|
448 cf->args->nelts = 0;
|
|
449 b = cf->conf_file->buffer;
|
|
450 start = b->pos;
|
404
|
451 start_line = cf->conf_file->line;
|
|
452
|
|
453 file_size = ngx_file_size(&cf->conf_file->file.info);
|
0
|
454
|
|
455 for ( ;; ) {
|
|
456
|
|
457 if (b->pos >= b->last) {
|
384
|
458
|
404
|
459 if (cf->conf_file->file.offset >= file_size) {
|
|
460
|
672
|
461 if (cf->args->nelts > 0 || !last_space) {
|
384
|
462
|
|
463 if (cf->conf_file->file.fd == NGX_INVALID_FILE) {
|
|
464 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
465 "unexpected end of parameter, "
|
|
466 "expecting \";\"");
|
|
467 return NGX_ERROR;
|
|
468 }
|
|
469
|
288
|
470 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
471 "unexpected end of file, "
|
|
472 "expecting \";\" or \"}\"");
|
36
|
473 return NGX_ERROR;
|
|
474 }
|
|
475
|
0
|
476 return NGX_CONF_FILE_DONE;
|
|
477 }
|
|
478
|
404
|
479 len = b->pos - start;
|
|
480
|
|
481 if (len == NGX_CONF_BUFFER) {
|
|
482 cf->conf_file->line = start_line;
|
|
483
|
|
484 if (d_quoted) {
|
|
485 ch = '"';
|
|
486
|
|
487 } else if (s_quoted) {
|
|
488 ch = '\'';
|
|
489
|
|
490 } else {
|
|
491 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
492 "too long parameter \"%*s...\" started",
|
|
493 10, start);
|
|
494 return NGX_ERROR;
|
|
495 }
|
|
496
|
|
497 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
498 "too long parameter, probably "
|
|
499 "missing terminating \"%c\" character", ch);
|
|
500 return NGX_ERROR;
|
0
|
501 }
|
|
502
|
404
|
503 if (len) {
|
620
|
504 ngx_memmove(b->start, start, len);
|
404
|
505 }
|
|
506
|
|
507 size = (ssize_t) (file_size - cf->conf_file->file.offset);
|
|
508
|
|
509 if (size > b->end - (b->start + len)) {
|
|
510 size = b->end - (b->start + len);
|
|
511 }
|
|
512
|
|
513 n = ngx_read_file(&cf->conf_file->file, b->start + len, size,
|
0
|
514 cf->conf_file->file.offset);
|
|
515
|
|
516 if (n == NGX_ERROR) {
|
|
517 return NGX_ERROR;
|
|
518 }
|
|
519
|
404
|
520 if (n != size) {
|
|
521 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
522 ngx_read_file_n " returned "
|
|
523 "only %z bytes instead of %z",
|
|
524 n, size);
|
|
525 return NGX_ERROR;
|
|
526 }
|
|
527
|
|
528 b->pos = b->start + len;
|
|
529 b->last = b->pos + n;
|
0
|
530 start = b->start;
|
|
531 }
|
|
532
|
|
533 ch = *b->pos++;
|
|
534
|
|
535 if (ch == LF) {
|
|
536 cf->conf_file->line++;
|
|
537
|
|
538 if (sharp_comment) {
|
|
539 sharp_comment = 0;
|
|
540 }
|
|
541 }
|
|
542
|
|
543 if (sharp_comment) {
|
|
544 continue;
|
|
545 }
|
|
546
|
|
547 if (quoted) {
|
|
548 quoted = 0;
|
|
549 continue;
|
|
550 }
|
|
551
|
|
552 if (need_space) {
|
|
553 if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
|
|
554 last_space = 1;
|
|
555 need_space = 0;
|
|
556 continue;
|
|
557 }
|
|
558
|
10
|
559 if (ch == ';') {
|
0
|
560 return NGX_OK;
|
|
561 }
|
|
562
|
10
|
563 if (ch == '{') {
|
|
564 return NGX_CONF_BLOCK_START;
|
|
565 }
|
|
566
|
130
|
567 if (ch == ')') {
|
|
568 last_space = 1;
|
|
569 need_space = 0;
|
0
|
570
|
130
|
571 } else {
|
288
|
572 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
573 "unexpected \"%c\"", ch);
|
130
|
574 return NGX_ERROR;
|
|
575 }
|
0
|
576 }
|
|
577
|
|
578 if (last_space) {
|
|
579 if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
|
|
580 continue;
|
|
581 }
|
|
582
|
|
583 start = b->pos - 1;
|
404
|
584 start_line = cf->conf_file->line;
|
0
|
585
|
|
586 switch (ch) {
|
|
587
|
|
588 case ';':
|
|
589 case '{':
|
|
590 if (cf->args->nelts == 0) {
|
288
|
591 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
592 "unexpected \"%c\"", ch);
|
0
|
593 return NGX_ERROR;
|
|
594 }
|
|
595
|
10
|
596 if (ch == '{') {
|
|
597 return NGX_CONF_BLOCK_START;
|
|
598 }
|
|
599
|
0
|
600 return NGX_OK;
|
|
601
|
|
602 case '}':
|
66
|
603 if (cf->args->nelts != 0) {
|
288
|
604 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
605 "unexpected \"}\"");
|
0
|
606 return NGX_ERROR;
|
|
607 }
|
|
608
|
|
609 return NGX_CONF_BLOCK_DONE;
|
|
610
|
|
611 case '#':
|
|
612 sharp_comment = 1;
|
|
613 continue;
|
|
614
|
|
615 case '\\':
|
|
616 quoted = 1;
|
|
617 last_space = 0;
|
|
618 continue;
|
|
619
|
|
620 case '"':
|
|
621 start++;
|
|
622 d_quoted = 1;
|
|
623 last_space = 0;
|
|
624 continue;
|
|
625
|
|
626 case '\'':
|
|
627 start++;
|
|
628 s_quoted = 1;
|
|
629 last_space = 0;
|
|
630 continue;
|
|
631
|
|
632 default:
|
|
633 last_space = 0;
|
|
634 }
|
|
635
|
|
636 } else {
|
58
|
637 if (ch == '{' && variable) {
|
|
638 continue;
|
|
639 }
|
|
640
|
|
641 variable = 0;
|
|
642
|
0
|
643 if (ch == '\\') {
|
|
644 quoted = 1;
|
|
645 continue;
|
|
646 }
|
|
647
|
58
|
648 if (ch == '$') {
|
|
649 variable = 1;
|
|
650 continue;
|
|
651 }
|
|
652
|
0
|
653 if (d_quoted) {
|
|
654 if (ch == '"') {
|
|
655 d_quoted = 0;
|
|
656 need_space = 1;
|
|
657 found = 1;
|
|
658 }
|
|
659
|
|
660 } else if (s_quoted) {
|
|
661 if (ch == '\'') {
|
|
662 s_quoted = 0;
|
|
663 need_space = 1;
|
|
664 found = 1;
|
|
665 }
|
|
666
|
|
667 } else if (ch == ' ' || ch == '\t' || ch == CR || ch == LF
|
582
|
668 || ch == ';' || ch == '{')
|
|
669 {
|
0
|
670 last_space = 1;
|
|
671 found = 1;
|
|
672 }
|
|
673
|
|
674 if (found) {
|
50
|
675 word = ngx_array_push(cf->args);
|
|
676 if (word == NULL) {
|
0
|
677 return NGX_ERROR;
|
|
678 }
|
|
679
|
382
|
680 word->data = ngx_pnalloc(cf->pool, b->pos - start + 1);
|
50
|
681 if (word->data == NULL) {
|
0
|
682 return NGX_ERROR;
|
|
683 }
|
|
684
|
|
685 for (dst = word->data, src = start, len = 0;
|
|
686 src < b->pos - 1;
|
|
687 len++)
|
|
688 {
|
|
689 if (*src == '\\') {
|
|
690 switch (src[1]) {
|
|
691 case '"':
|
|
692 case '\'':
|
|
693 case '\\':
|
|
694 src++;
|
|
695 break;
|
|
696
|
|
697 case 't':
|
|
698 *dst++ = '\t';
|
|
699 src += 2;
|
|
700 continue;
|
|
701
|
|
702 case 'r':
|
|
703 *dst++ = '\r';
|
|
704 src += 2;
|
|
705 continue;
|
|
706
|
|
707 case 'n':
|
|
708 *dst++ = '\n';
|
|
709 src += 2;
|
|
710 continue;
|
|
711 }
|
|
712
|
|
713 }
|
|
714 *dst++ = *src++;
|
|
715 }
|
|
716 *dst = '\0';
|
|
717 word->len = len;
|
|
718
|
10
|
719 if (ch == ';') {
|
0
|
720 return NGX_OK;
|
|
721 }
|
|
722
|
10
|
723 if (ch == '{') {
|
|
724 return NGX_CONF_BLOCK_START;
|
|
725 }
|
|
726
|
0
|
727 found = 0;
|
|
728 }
|
|
729 }
|
|
730 }
|
|
731 }
|
|
732
|
|
733
|
52
|
734 static char *
|
|
735 ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
736 {
|
238
|
737 char *rv;
|
|
738 ngx_int_t n;
|
366
|
739 ngx_str_t *value, file, name;
|
238
|
740 ngx_glob_t gl;
|
0
|
741
|
|
742 value = cf->args->elts;
|
|
743 file = value[1];
|
|
744
|
238
|
745 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
|
|
746
|
454
|
747 if (ngx_conf_full_name(cf->cycle, &file, 1) != NGX_OK) {
|
0
|
748 return NGX_CONF_ERROR;
|
|
749 }
|
|
750
|
372
|
751 if (strpbrk((char *) file.data, "*?[") == NULL) {
|
|
752
|
|
753 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
|
|
754
|
|
755 return ngx_conf_parse(cf, &file);
|
|
756 }
|
|
757
|
238
|
758 ngx_memzero(&gl, sizeof(ngx_glob_t));
|
|
759
|
|
760 gl.pattern = file.data;
|
|
761 gl.log = cf->log;
|
372
|
762 gl.test = 1;
|
238
|
763
|
|
764 if (ngx_open_glob(&gl) != NGX_OK) {
|
|
765 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
|
|
766 ngx_open_glob_n " \"%s\" failed", file.data);
|
|
767 return NGX_CONF_ERROR;
|
|
768 }
|
|
769
|
|
770 rv = NGX_CONF_OK;
|
|
771
|
|
772 for ( ;; ) {
|
366
|
773 n = ngx_read_glob(&gl, &name);
|
0
|
774
|
238
|
775 if (n != NGX_OK) {
|
|
776 break;
|
|
777 }
|
|
778
|
366
|
779 file.len = name.len++;
|
|
780 file.data = ngx_pstrdup(cf->pool, &name);
|
|
781
|
238
|
782 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
|
|
783
|
|
784 rv = ngx_conf_parse(cf, &file);
|
|
785
|
|
786 if (rv != NGX_CONF_OK) {
|
|
787 break;
|
|
788 }
|
|
789 }
|
|
790
|
|
791 ngx_close_glob(&gl);
|
|
792
|
|
793 return rv;
|
0
|
794 }
|
|
795
|
|
796
|
52
|
797 ngx_int_t
|
324
|
798 ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name, ngx_uint_t conf_prefix)
|
0
|
799 {
|
324
|
800 size_t len;
|
496
|
801 u_char *p, *n, *prefix;
|
|
802 ngx_int_t rc;
|
10
|
803
|
496
|
804 rc = ngx_conf_test_full_name(name);
|
10
|
805
|
496
|
806 if (rc == NGX_OK) {
|
|
807 return rc;
|
482
|
808 }
|
|
809
|
324
|
810 if (conf_prefix) {
|
482
|
811 len = cycle->conf_prefix.len;
|
|
812 prefix = cycle->conf_prefix.data;
|
0
|
813
|
324
|
814 } else {
|
482
|
815 len = cycle->prefix.len;
|
|
816 prefix = cycle->prefix.data;
|
324
|
817 }
|
|
818
|
496
|
819 #if (NGX_WIN32)
|
|
820
|
|
821 if (rc == 2) {
|
|
822 len = rc;
|
|
823 }
|
|
824
|
|
825 #endif
|
|
826
|
|
827 n = ngx_pnalloc(cycle->pool, len + name->len + 1);
|
|
828 if (n == NULL) {
|
422
|
829 return NGX_ERROR;
|
0
|
830 }
|
|
831
|
496
|
832 p = ngx_cpymem(n, prefix, len);
|
|
833 ngx_cpystrn(p, name->data, name->len + 1);
|
|
834
|
|
835 name->len += len;
|
|
836 name->data = n;
|
0
|
837
|
|
838 return NGX_OK;
|
|
839 }
|
|
840
|
|
841
|
496
|
842 static ngx_int_t
|
|
843 ngx_conf_test_full_name(ngx_str_t *name)
|
|
844 {
|
|
845 #if (NGX_WIN32)
|
|
846 u_char c0, c1;
|
|
847
|
|
848 c0 = name->data[0];
|
|
849
|
|
850 if (name->len < 2) {
|
|
851 if (c0 == '/') {
|
|
852 return 2;
|
|
853 }
|
|
854
|
|
855 return NGX_DECLINED;
|
|
856 }
|
|
857
|
|
858 c1 = name->data[1];
|
|
859
|
|
860 if (c1 == ':') {
|
|
861 c0 |= 0x20;
|
|
862
|
|
863 if ((c0 >= 'a' && c0 <= 'z')) {
|
|
864 return NGX_OK;
|
|
865 }
|
|
866
|
|
867 return NGX_DECLINED;
|
|
868 }
|
|
869
|
|
870 if (c1 == '/') {
|
|
871 return NGX_OK;
|
|
872 }
|
|
873
|
|
874 if (c0 == '/') {
|
|
875 return 2;
|
|
876 }
|
|
877
|
|
878 return NGX_DECLINED;
|
|
879
|
|
880 #else
|
|
881
|
|
882 if (name->data[0] == '/') {
|
|
883 return NGX_OK;
|
|
884 }
|
|
885
|
|
886 return NGX_DECLINED;
|
|
887
|
|
888 #endif
|
|
889 }
|
|
890
|
|
891
|
52
|
892 ngx_open_file_t *
|
|
893 ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
|
0
|
894 {
|
|
895 ngx_str_t full;
|
|
896 ngx_uint_t i;
|
|
897 ngx_list_part_t *part;
|
|
898 ngx_open_file_t *file;
|
|
899
|
|
900 #if (NGX_SUPPRESS_WARN)
|
570
|
901 ngx_str_null(&full);
|
0
|
902 #endif
|
|
903
|
484
|
904 if (name->len) {
|
0
|
905 full = *name;
|
|
906
|
454
|
907 if (ngx_conf_full_name(cycle, &full, 0) != NGX_OK) {
|
0
|
908 return NULL;
|
|
909 }
|
|
910
|
|
911 part = &cycle->open_files.part;
|
|
912 file = part->elts;
|
|
913
|
|
914 for (i = 0; /* void */ ; i++) {
|
|
915
|
|
916 if (i >= part->nelts) {
|
|
917 if (part->next == NULL) {
|
|
918 break;
|
|
919 }
|
|
920 part = part->next;
|
|
921 file = part->elts;
|
|
922 i = 0;
|
|
923 }
|
|
924
|
|
925 if (full.len != file[i].name.len) {
|
|
926 continue;
|
|
927 }
|
|
928
|
|
929 if (ngx_strcmp(full.data, file[i].name.data) == 0) {
|
|
930 return &file[i];
|
|
931 }
|
|
932 }
|
|
933 }
|
|
934
|
50
|
935 file = ngx_list_push(&cycle->open_files);
|
|
936 if (file == NULL) {
|
0
|
937 return NULL;
|
|
938 }
|
|
939
|
484
|
940 if (name->len) {
|
0
|
941 file->fd = NGX_INVALID_FILE;
|
|
942 file->name = full;
|
|
943
|
|
944 } else {
|
482
|
945 file->fd = ngx_stderr;
|
484
|
946 file->name = *name;
|
0
|
947 }
|
|
948
|
120
|
949 file->buffer = NULL;
|
|
950
|
0
|
951 return file;
|
|
952 }
|
|
953
|
|
954
|
120
|
955 static void
|
|
956 ngx_conf_flush_files(ngx_cycle_t *cycle)
|
|
957 {
|
418
|
958 ssize_t n, len;
|
120
|
959 ngx_uint_t i;
|
|
960 ngx_list_part_t *part;
|
|
961 ngx_open_file_t *file;
|
|
962
|
|
963 ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0, "flush files");
|
|
964
|
|
965 part = &cycle->open_files.part;
|
|
966 file = part->elts;
|
|
967
|
|
968 for (i = 0; /* void */ ; i++) {
|
|
969
|
|
970 if (i >= part->nelts) {
|
|
971 if (part->next == NULL) {
|
|
972 break;
|
|
973 }
|
|
974 part = part->next;
|
|
975 file = part->elts;
|
|
976 i = 0;
|
|
977 }
|
|
978
|
418
|
979 len = file[i].pos - file[i].buffer;
|
|
980
|
|
981 if (file[i].buffer == NULL || len == 0) {
|
120
|
982 continue;
|
|
983 }
|
|
984
|
418
|
985 n = ngx_write_fd(file[i].fd, file[i].buffer, len);
|
|
986
|
|
987 if (n == NGX_FILE_ERROR) {
|
|
988 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
|
989 ngx_write_fd_n " to \"%s\" failed",
|
|
990 file[i].name.data);
|
|
991
|
|
992 } else if (n != len) {
|
|
993 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
|
|
994 ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz",
|
|
995 file[i].name.data, n, len);
|
|
996 }
|
120
|
997 }
|
|
998 }
|
|
999
|
|
1000
|
52
|
1001 void ngx_cdecl
|
|
1002 ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
|
564
|
1003 const char *fmt, ...)
|
0
|
1004 {
|
422
|
1005 u_char errstr[NGX_MAX_CONF_ERRSTR], *p, *last;
|
0
|
1006 va_list args;
|
|
1007
|
10
|
1008 last = errstr + NGX_MAX_CONF_ERRSTR;
|
|
1009
|
0
|
1010 va_start(args, fmt);
|
484
|
1011 p = ngx_vslprintf(errstr, last, fmt, args);
|
0
|
1012 va_end(args);
|
|
1013
|
422
|
1014 if (err) {
|
484
|
1015 p = ngx_log_errno(p, last, err);
|
0
|
1016 }
|
|
1017
|
142
|
1018 if (cf->conf_file == NULL) {
|
422
|
1019 ngx_log_error(level, cf->log, 0, "%*s", p - errstr, errstr);
|
142
|
1020 return;
|
|
1021 }
|
|
1022
|
484
|
1023 if (cf->conf_file->file.fd == NGX_INVALID_FILE) {
|
|
1024 ngx_log_error(level, cf->log, 0, "%*s in command line",
|
|
1025 p - errstr, errstr);
|
|
1026 return;
|
|
1027 }
|
|
1028
|
422
|
1029 ngx_log_error(level, cf->log, 0, "%*s in %s:%ui",
|
|
1030 p - errstr, errstr,
|
|
1031 cf->conf_file->file.name.data, cf->conf_file->line);
|
0
|
1032 }
|
|
1033
|
|
1034
|
52
|
1035 char *
|
|
1036 ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1037 {
|
|
1038 char *p = conf;
|
|
1039
|
|
1040 ngx_str_t *value;
|
|
1041 ngx_flag_t *fp;
|
|
1042 ngx_conf_post_t *post;
|
|
1043
|
|
1044 fp = (ngx_flag_t *) (p + cmd->offset);
|
|
1045
|
|
1046 if (*fp != NGX_CONF_UNSET) {
|
|
1047 return "is duplicate";
|
|
1048 }
|
|
1049
|
|
1050 value = cf->args->elts;
|
|
1051
|
286
|
1052 if (ngx_strcasecmp(value[1].data, (u_char *) "on") == 0) {
|
0
|
1053 *fp = 1;
|
|
1054
|
286
|
1055 } else if (ngx_strcasecmp(value[1].data, (u_char *) "off") == 0) {
|
0
|
1056 *fp = 0;
|
|
1057
|
|
1058 } else {
|
|
1059 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
1060 "invalid value \"%s\" in \"%s\" directive, "
|
|
1061 "it must be \"on\" or \"off\"",
|
|
1062 value[1].data, cmd->name.data);
|
|
1063 return NGX_CONF_ERROR;
|
|
1064 }
|
|
1065
|
|
1066 if (cmd->post) {
|
|
1067 post = cmd->post;
|
|
1068 return post->post_handler(cf, post, fp);
|
|
1069 }
|
|
1070
|
|
1071 return NGX_CONF_OK;
|
|
1072 }
|
|
1073
|
|
1074
|
52
|
1075 char *
|
|
1076 ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1077 {
|
|
1078 char *p = conf;
|
|
1079
|
|
1080 ngx_str_t *field, *value;
|
|
1081 ngx_conf_post_t *post;
|
|
1082
|
|
1083 field = (ngx_str_t *) (p + cmd->offset);
|
|
1084
|
|
1085 if (field->data) {
|
|
1086 return "is duplicate";
|
|
1087 }
|
|
1088
|
|
1089 value = cf->args->elts;
|
|
1090
|
|
1091 *field = value[1];
|
|
1092
|
|
1093 if (cmd->post) {
|
|
1094 post = cmd->post;
|
|
1095 return post->post_handler(cf, post, field);
|
|
1096 }
|
|
1097
|
|
1098 return NGX_CONF_OK;
|
|
1099 }
|
|
1100
|
|
1101
|
52
|
1102 char *
|
198
|
1103 ngx_conf_set_str_array_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
58
|
1104 {
|
|
1105 char *p = conf;
|
|
1106
|
198
|
1107 ngx_str_t *value, *s;
|
58
|
1108 ngx_array_t **a;
|
|
1109 ngx_conf_post_t *post;
|
|
1110
|
|
1111 a = (ngx_array_t **) (p + cmd->offset);
|
|
1112
|
356
|
1113 if (*a == NGX_CONF_UNSET_PTR) {
|
198
|
1114 *a = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t));
|
58
|
1115 if (*a == NULL) {
|
|
1116 return NGX_CONF_ERROR;
|
|
1117 }
|
|
1118 }
|
|
1119
|
198
|
1120 s = ngx_array_push(*a);
|
|
1121 if (s == NULL) {
|
58
|
1122 return NGX_CONF_ERROR;
|
|
1123 }
|
|
1124
|
|
1125 value = cf->args->elts;
|
|
1126
|
198
|
1127 *s = value[1];
|
58
|
1128
|
|
1129 if (cmd->post) {
|
|
1130 post = cmd->post;
|
198
|
1131 return post->post_handler(cf, post, s);
|
|
1132 }
|
|
1133
|
|
1134 return NGX_CONF_OK;
|
|
1135 }
|
|
1136
|
|
1137
|
|
1138 char *
|
|
1139 ngx_conf_set_keyval_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
1140 {
|
|
1141 char *p = conf;
|
|
1142
|
|
1143 ngx_str_t *value;
|
|
1144 ngx_array_t **a;
|
|
1145 ngx_keyval_t *kv;
|
|
1146 ngx_conf_post_t *post;
|
|
1147
|
|
1148 a = (ngx_array_t **) (p + cmd->offset);
|
|
1149
|
|
1150 if (*a == NULL) {
|
|
1151 *a = ngx_array_create(cf->pool, 4, sizeof(ngx_keyval_t));
|
|
1152 if (*a == NULL) {
|
|
1153 return NGX_CONF_ERROR;
|
|
1154 }
|
|
1155 }
|
|
1156
|
|
1157 kv = ngx_array_push(*a);
|
|
1158 if (kv == NULL) {
|
|
1159 return NGX_CONF_ERROR;
|
|
1160 }
|
|
1161
|
|
1162 value = cf->args->elts;
|
|
1163
|
|
1164 kv->key = value[1];
|
|
1165 kv->value = value[2];
|
|
1166
|
|
1167 if (cmd->post) {
|
|
1168 post = cmd->post;
|
|
1169 return post->post_handler(cf, post, kv);
|
58
|
1170 }
|
|
1171
|
|
1172 return NGX_CONF_OK;
|
|
1173 }
|
|
1174
|
|
1175
|
|
1176 char *
|
52
|
1177 ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1178 {
|
|
1179 char *p = conf;
|
|
1180
|
|
1181 ngx_int_t *np;
|
|
1182 ngx_str_t *value;
|
|
1183 ngx_conf_post_t *post;
|
|
1184
|
|
1185
|
|
1186 np = (ngx_int_t *) (p + cmd->offset);
|
|
1187
|
|
1188 if (*np != NGX_CONF_UNSET) {
|
|
1189 return "is duplicate";
|
|
1190 }
|
|
1191
|
|
1192 value = cf->args->elts;
|
|
1193 *np = ngx_atoi(value[1].data, value[1].len);
|
|
1194 if (*np == NGX_ERROR) {
|
|
1195 return "invalid number";
|
|
1196 }
|
|
1197
|
|
1198 if (cmd->post) {
|
|
1199 post = cmd->post;
|
|
1200 return post->post_handler(cf, post, np);
|
|
1201 }
|
|
1202
|
|
1203 return NGX_CONF_OK;
|
|
1204 }
|
|
1205
|
|
1206
|
52
|
1207 char *
|
|
1208 ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1209 {
|
|
1210 char *p = conf;
|
|
1211
|
|
1212 size_t *sp;
|
|
1213 ngx_str_t *value;
|
|
1214 ngx_conf_post_t *post;
|
|
1215
|
|
1216
|
|
1217 sp = (size_t *) (p + cmd->offset);
|
|
1218 if (*sp != NGX_CONF_UNSET_SIZE) {
|
|
1219 return "is duplicate";
|
|
1220 }
|
|
1221
|
|
1222 value = cf->args->elts;
|
|
1223
|
|
1224 *sp = ngx_parse_size(&value[1]);
|
|
1225 if (*sp == (size_t) NGX_ERROR) {
|
|
1226 return "invalid value";
|
|
1227 }
|
|
1228
|
|
1229 if (cmd->post) {
|
|
1230 post = cmd->post;
|
|
1231 return post->post_handler(cf, post, sp);
|
|
1232 }
|
|
1233
|
|
1234 return NGX_CONF_OK;
|
|
1235 }
|
|
1236
|
|
1237
|
52
|
1238 char *
|
212
|
1239 ngx_conf_set_off_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
1240 {
|
|
1241 char *p = conf;
|
|
1242
|
|
1243 off_t *op;
|
|
1244 ngx_str_t *value;
|
|
1245 ngx_conf_post_t *post;
|
|
1246
|
|
1247
|
|
1248 op = (off_t *) (p + cmd->offset);
|
|
1249 if (*op != NGX_CONF_UNSET) {
|
|
1250 return "is duplicate";
|
|
1251 }
|
|
1252
|
|
1253 value = cf->args->elts;
|
|
1254
|
|
1255 *op = ngx_parse_offset(&value[1]);
|
|
1256 if (*op == (off_t) NGX_ERROR) {
|
|
1257 return "invalid value";
|
|
1258 }
|
|
1259
|
|
1260 if (cmd->post) {
|
|
1261 post = cmd->post;
|
|
1262 return post->post_handler(cf, post, op);
|
|
1263 }
|
|
1264
|
|
1265 return NGX_CONF_OK;
|
|
1266 }
|
|
1267
|
|
1268
|
|
1269 char *
|
52
|
1270 ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1271 {
|
|
1272 char *p = conf;
|
|
1273
|
|
1274 ngx_msec_t *msp;
|
|
1275 ngx_str_t *value;
|
|
1276 ngx_conf_post_t *post;
|
|
1277
|
|
1278
|
|
1279 msp = (ngx_msec_t *) (p + cmd->offset);
|
|
1280 if (*msp != NGX_CONF_UNSET_MSEC) {
|
|
1281 return "is duplicate";
|
|
1282 }
|
|
1283
|
|
1284 value = cf->args->elts;
|
|
1285
|
|
1286 *msp = ngx_parse_time(&value[1], 0);
|
|
1287 if (*msp == (ngx_msec_t) NGX_ERROR) {
|
|
1288 return "invalid value";
|
|
1289 }
|
|
1290
|
|
1291 if (cmd->post) {
|
|
1292 post = cmd->post;
|
|
1293 return post->post_handler(cf, post, msp);
|
|
1294 }
|
|
1295
|
|
1296 return NGX_CONF_OK;
|
|
1297 }
|
|
1298
|
|
1299
|
52
|
1300 char *
|
|
1301 ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1302 {
|
|
1303 char *p = conf;
|
|
1304
|
|
1305 time_t *sp;
|
|
1306 ngx_str_t *value;
|
|
1307 ngx_conf_post_t *post;
|
|
1308
|
|
1309
|
|
1310 sp = (time_t *) (p + cmd->offset);
|
|
1311 if (*sp != NGX_CONF_UNSET) {
|
|
1312 return "is duplicate";
|
|
1313 }
|
|
1314
|
|
1315 value = cf->args->elts;
|
|
1316
|
|
1317 *sp = ngx_parse_time(&value[1], 1);
|
662
|
1318 if (*sp == (time_t) NGX_ERROR) {
|
0
|
1319 return "invalid value";
|
|
1320 }
|
|
1321
|
|
1322 if (cmd->post) {
|
|
1323 post = cmd->post;
|
|
1324 return post->post_handler(cf, post, sp);
|
|
1325 }
|
|
1326
|
|
1327 return NGX_CONF_OK;
|
|
1328 }
|
|
1329
|
|
1330
|
52
|
1331 char *
|
|
1332 ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1333 {
|
|
1334 char *p = conf;
|
|
1335
|
|
1336 ngx_str_t *value;
|
|
1337 ngx_bufs_t *bufs;
|
|
1338
|
|
1339
|
|
1340 bufs = (ngx_bufs_t *) (p + cmd->offset);
|
|
1341 if (bufs->num) {
|
|
1342 return "is duplicate";
|
|
1343 }
|
|
1344
|
|
1345 value = cf->args->elts;
|
|
1346
|
|
1347 bufs->num = ngx_atoi(value[1].data, value[1].len);
|
|
1348 if (bufs->num == NGX_ERROR || bufs->num == 0) {
|
|
1349 return "invalid value";
|
|
1350 }
|
|
1351
|
|
1352 bufs->size = ngx_parse_size(&value[2]);
|
|
1353 if (bufs->size == (size_t) NGX_ERROR || bufs->size == 0) {
|
|
1354 return "invalid value";
|
|
1355 }
|
|
1356
|
|
1357 return NGX_CONF_OK;
|
|
1358 }
|
|
1359
|
|
1360
|
52
|
1361 char *
|
|
1362 ngx_conf_set_enum_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1363 {
|
|
1364 char *p = conf;
|
|
1365
|
|
1366 ngx_uint_t *np, i;
|
|
1367 ngx_str_t *value;
|
|
1368 ngx_conf_enum_t *e;
|
|
1369
|
|
1370 np = (ngx_uint_t *) (p + cmd->offset);
|
|
1371
|
|
1372 if (*np != NGX_CONF_UNSET_UINT) {
|
|
1373 return "is duplicate";
|
|
1374 }
|
|
1375
|
|
1376 value = cf->args->elts;
|
|
1377 e = cmd->post;
|
|
1378
|
|
1379 for (i = 0; e[i].name.len != 0; i++) {
|
|
1380 if (e[i].name.len != value[1].len
|
|
1381 || ngx_strcasecmp(e[i].name.data, value[1].data) != 0)
|
|
1382 {
|
|
1383 continue;
|
|
1384 }
|
|
1385
|
|
1386 *np = e[i].value;
|
|
1387
|
|
1388 return NGX_CONF_OK;
|
|
1389 }
|
|
1390
|
|
1391 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
1392 "invalid value \"%s\"", value[1].data);
|
|
1393
|
|
1394 return NGX_CONF_ERROR;
|
|
1395 }
|
|
1396
|
|
1397
|
52
|
1398 char *
|
|
1399 ngx_conf_set_bitmask_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1400 {
|
|
1401 char *p = conf;
|
|
1402
|
|
1403 ngx_uint_t *np, i, m;
|
|
1404 ngx_str_t *value;
|
|
1405 ngx_conf_bitmask_t *mask;
|
|
1406
|
|
1407
|
|
1408 np = (ngx_uint_t *) (p + cmd->offset);
|
|
1409 value = cf->args->elts;
|
|
1410 mask = cmd->post;
|
|
1411
|
|
1412 for (i = 1; i < cf->args->nelts; i++) {
|
|
1413 for (m = 0; mask[m].name.len != 0; m++) {
|
|
1414
|
|
1415 if (mask[m].name.len != value[i].len
|
|
1416 || ngx_strcasecmp(mask[m].name.data, value[i].data) != 0)
|
|
1417 {
|
|
1418 continue;
|
|
1419 }
|
|
1420
|
|
1421 if (*np & mask[m].mask) {
|
|
1422 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
1423 "duplicate value \"%s\"", value[i].data);
|
|
1424
|
|
1425 } else {
|
|
1426 *np |= mask[m].mask;
|
|
1427 }
|
|
1428
|
|
1429 break;
|
|
1430 }
|
|
1431
|
|
1432 if (mask[m].name.len == 0) {
|
|
1433 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
1434 "invalid value \"%s\"", value[i].data);
|
|
1435
|
|
1436 return NGX_CONF_ERROR;
|
|
1437 }
|
|
1438 }
|
|
1439
|
|
1440 return NGX_CONF_OK;
|
|
1441 }
|
|
1442
|
|
1443
|
682
|
1444 #if 0
|
|
1445
|
52
|
1446 char *
|
|
1447 ngx_conf_unsupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
0
|
1448 {
|
|
1449 return "unsupported on this platform";
|
|
1450 }
|
|
1451
|
682
|
1452 #endif
|
|
1453
|
0
|
1454
|
52
|
1455 char *
|
130
|
1456 ngx_conf_deprecated(ngx_conf_t *cf, void *post, void *data)
|
|
1457 {
|
|
1458 ngx_conf_deprecated_t *d = post;
|
|
1459
|
|
1460 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
|
1461 "the \"%s\" directive is deprecated, "
|
|
1462 "use the \"%s\" directive instead",
|
|
1463 d->old_name, d->new_name);
|
|
1464
|
|
1465 return NGX_CONF_OK;
|
|
1466 }
|
|
1467
|
|
1468
|
|
1469 char *
|
52
|
1470 ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data)
|
0
|
1471 {
|
|
1472 ngx_conf_num_bounds_t *bounds = post;
|
|
1473 ngx_int_t *np = data;
|
|
1474
|
|
1475 if (bounds->high == -1) {
|
|
1476 if (*np >= bounds->low) {
|
|
1477 return NGX_CONF_OK;
|
|
1478 }
|
|
1479
|
|
1480 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
672
|
1481 "value must be equal to or greater than %i",
|
|
1482 bounds->low);
|
0
|
1483
|
|
1484 return NGX_CONF_ERROR;
|
|
1485 }
|
|
1486
|
|
1487 if (*np >= bounds->low && *np <= bounds->high) {
|
|
1488 return NGX_CONF_OK;
|
|
1489 }
|
|
1490
|
|
1491 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
56
|
1492 "value must be between %i and %i",
|
0
|
1493 bounds->low, bounds->high);
|
|
1494
|
|
1495 return NGX_CONF_ERROR;
|
|
1496 }
|