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