blob: d546fe6675d5ff52dc3ff49e32c46c6a54d39c58 [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
593#if 0
Igor Sysoev890fc962003-07-20 21:15:59 +0000594 file = cycle->open_files.elts;
595 for (i = 0; i < cycle->open_files.nelts; i++) {
Igor Sysoevb9e34412004-09-03 15:50:30 +0000596#endif
Igor Sysoev890fc962003-07-20 21:15:59 +0000597 if (name->len != file[i].name.len) {
598 continue;
599 }
600
601 if (ngx_strcmp(name->data, file[i].name.data) == 0) {
602 return &file[i];
603 }
604 }
605 }
606
Igor Sysoevb9e34412004-09-03 15:50:30 +0000607 if (!(file = ngx_push_list(&cycle->open_files))) {
Igor Sysoev369145c2004-05-28 15:49:23 +0000608 return NULL;
609 }
610
Igor Sysoev890fc962003-07-20 21:15:59 +0000611 file->fd = NGX_INVALID_FILE;
Igor Sysoev369145c2004-05-28 15:49:23 +0000612
Igor Sysoev890fc962003-07-20 21:15:59 +0000613 if (name) {
614 file->name = *name;
615 }
616
617 return file;
618}
619
620
Igor Sysoev54498db2004-02-11 17:08:49 +0000621void ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
Igor Sysoev8e1fbe62003-07-18 14:44:05 +0000622 char *fmt, ...)
623{
624 int len;
Igor Sysoeva8fa0a62003-11-25 20:44:56 +0000625 char errstr[NGX_MAX_CONF_ERRSTR];
Igor Sysoev8e1fbe62003-07-18 14:44:05 +0000626 va_list args;
627
628 va_start(args, fmt);
629 len = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args);
630 va_end(args);
631
632 if (err) {
633 len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
634 " (%d: ", err);
635 len += ngx_strerror_r(err, errstr + len, sizeof(errstr) - len - 1);
636 errstr[len++] = ')';
Igor Sysoev11dbe972004-03-29 17:43:58 +0000637 errstr[len] = '\0';
Igor Sysoev8e1fbe62003-07-18 14:44:05 +0000638 }
639
640 ngx_log_error(level, cf->log, 0, "%s in %s:%d",
641 errstr, cf->conf_file->file.name.data, cf->conf_file->line);
642}
643
644
Igor Sysoev6253ca12003-05-27 12:18:54 +0000645char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev6a644c62003-03-04 06:33:48 +0000646{
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000647 char *p = conf;
648
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000649 ngx_flag_t flag;
650 ngx_str_t *value;
Igor Sysoev6a644c62003-03-04 06:33:48 +0000651
Igor Sysoevf1079102003-10-23 06:13:16 +0000652
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000653 if (*(ngx_flag_t *) (p + cmd->offset) != NGX_CONF_UNSET) {
Igor Sysoev1c13c662003-05-20 15:37:55 +0000654 return "is duplicate";
655 }
656
Igor Sysoeva3677242004-04-14 05:57:36 +0000657 value = cf->args->elts;
Igor Sysoev6a644c62003-03-04 06:33:48 +0000658
659 if (ngx_strcasecmp(value[1].data, "on") == 0) {
660 flag = 1;
661
662 } else if (ngx_strcasecmp(value[1].data, "off") == 0) {
663 flag = 0;
664
665 } else {
Igor Sysoev890fc962003-07-20 21:15:59 +0000666 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
667 "invalid value \"%s\" in \"%s\" directive, "
668 "it must be \"on\" or \"off\"",
669 value[1].data, cmd->name.data);
670 return NGX_CONF_ERROR;
Igor Sysoev6a644c62003-03-04 06:33:48 +0000671 }
672
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000673 *(ngx_flag_t *) (p + cmd->offset) = flag;
Igor Sysoev6a644c62003-03-04 06:33:48 +0000674
675 return NGX_CONF_OK;
676}
677
678
Igor Sysoev6253ca12003-05-27 12:18:54 +0000679char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000680{
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000681 char *p = conf;
682
Igor Sysoev13836ce2004-08-31 15:32:52 +0000683 ngx_str_t *field, *value;
684 ngx_conf_post_t *post;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000685
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000686 field = (ngx_str_t *) (p + cmd->offset);
Igor Sysoev1c13c662003-05-20 15:37:55 +0000687
Igor Sysoev6253ca12003-05-27 12:18:54 +0000688 if (field->data) {
Igor Sysoev1c13c662003-05-20 15:37:55 +0000689 return "is duplicate";
690 }
691
Igor Sysoeva3677242004-04-14 05:57:36 +0000692 value = cf->args->elts;
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000693
Igor Sysoevdc9dd432003-10-22 16:38:26 +0000694 *field = value[1];
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000695
Igor Sysoev13836ce2004-08-31 15:32:52 +0000696 if (cmd->post) {
697 post = cmd->post;
698 return post->post_handler(cf, post, field);
699 }
700
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000701 return NGX_CONF_OK;
702}
703
704
Igor Sysoev6253ca12003-05-27 12:18:54 +0000705char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000706{
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000707 char *p = conf;
708
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000709 ngx_int_t *np;
Igor Sysoev12b4b002003-10-24 06:53:41 +0000710 ngx_str_t *value;
711 ngx_conf_post_t *post;
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000712
Igor Sysoevf1079102003-10-23 06:13:16 +0000713
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000714 np = (ngx_int_t *) (p + cmd->offset);
Igor Sysoevf1079102003-10-23 06:13:16 +0000715
716 if (*np != NGX_CONF_UNSET) {
Igor Sysoev1c13c662003-05-20 15:37:55 +0000717 return "is duplicate";
718 }
719
Igor Sysoeva3677242004-04-14 05:57:36 +0000720 value = cf->args->elts;
Igor Sysoevf1079102003-10-23 06:13:16 +0000721 *np = ngx_atoi(value[1].data, value[1].len);
722 if (*np == NGX_ERROR) {
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000723 return "invalid number";
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000724 }
725
Igor Sysoev12b4b002003-10-24 06:53:41 +0000726 if (cmd->post) {
727 post = cmd->post;
728 return post->post_handler(cf, post, np);
Igor Sysoevf1079102003-10-23 06:13:16 +0000729 }
Igor Sysoevbb4ec5c2003-05-16 15:27:48 +0000730
731 return NGX_CONF_OK;
732}
733
734
Igor Sysoev6253ca12003-05-27 12:18:54 +0000735char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev960ffa42002-12-26 07:24:21 +0000736{
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000737 char *p = conf;
738
Igor Sysoev10a543a2004-03-16 07:10:12 +0000739 size_t *sp;
Igor Sysoev12b4b002003-10-24 06:53:41 +0000740 ngx_str_t *value;
741 ngx_conf_post_t *post;
Igor Sysoev960ffa42002-12-26 07:24:21 +0000742
Igor Sysoevf1079102003-10-23 06:13:16 +0000743
Igor Sysoev10a543a2004-03-16 07:10:12 +0000744 sp = (size_t *) (p + cmd->offset);
745 if (*sp != NGX_CONF_UNSET_SIZE) {
Igor Sysoev1c13c662003-05-20 15:37:55 +0000746 return "is duplicate";
747 }
748
Igor Sysoeva3677242004-04-14 05:57:36 +0000749 value = cf->args->elts;
Igor Sysoev960ffa42002-12-26 07:24:21 +0000750
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000751 *sp = ngx_parse_size(&value[1]);
Igor Sysoev10a543a2004-03-16 07:10:12 +0000752 if (*sp == (size_t) NGX_ERROR) {
Igor Sysoev3d09c8d2003-05-06 17:03:16 +0000753 return "invalid value";
Igor Sysoev960ffa42002-12-26 07:24:21 +0000754 }
Igor Sysoev88092572002-12-19 07:08:55 +0000755
Igor Sysoev12b4b002003-10-24 06:53:41 +0000756 if (cmd->post) {
757 post = cmd->post;
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000758 return post->post_handler(cf, post, sp);
Igor Sysoevf1079102003-10-23 06:13:16 +0000759 }
Igor Sysoev960ffa42002-12-26 07:24:21 +0000760
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000761 return NGX_CONF_OK;
Igor Sysoev88092572002-12-19 07:08:55 +0000762}
763
Igor Sysoev88092572002-12-19 07:08:55 +0000764
Igor Sysoev6253ca12003-05-27 12:18:54 +0000765char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev960ffa42002-12-26 07:24:21 +0000766{
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000767 char *p = conf;
768
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000769 ngx_msec_t *msp;
Igor Sysoev12b4b002003-10-24 06:53:41 +0000770 ngx_str_t *value;
771 ngx_conf_post_t *post;
Igor Sysoev960ffa42002-12-26 07:24:21 +0000772
Igor Sysoevf1079102003-10-23 06:13:16 +0000773
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000774 msp = (ngx_msec_t *) (p + cmd->offset);
Igor Sysoev10a543a2004-03-16 07:10:12 +0000775 if (*msp != NGX_CONF_UNSET_MSEC) {
Igor Sysoev1c13c662003-05-20 15:37:55 +0000776 return "is duplicate";
777 }
778
Igor Sysoeva3677242004-04-14 05:57:36 +0000779 value = cf->args->elts;
Igor Sysoev960ffa42002-12-26 07:24:21 +0000780
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000781 *msp = ngx_parse_time(&value[1], 0);
782 if (*msp == (ngx_msec_t) NGX_ERROR) {
Igor Sysoev8556e6d2003-10-23 15:54:19 +0000783 return "invalid value";
Igor Sysoev1d8d9ee2003-04-28 15:06:39 +0000784 }
785
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000786 if (*msp == (ngx_msec_t) NGX_PARSE_LARGE_TIME) {
Igor Sysoev8556e6d2003-10-23 15:54:19 +0000787 return "value must be less than 597 hours";
788 }
Igor Sysoevf1079102003-10-23 06:13:16 +0000789
Igor Sysoev12b4b002003-10-24 06:53:41 +0000790 if (cmd->post) {
791 post = cmd->post;
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000792 return post->post_handler(cf, post, msp);
Igor Sysoevf1079102003-10-23 06:13:16 +0000793 }
Igor Sysoev960ffa42002-12-26 07:24:21 +0000794
Igor Sysoev4e9393a2003-01-09 05:36:00 +0000795 return NGX_CONF_OK;
Igor Sysoev88092572002-12-19 07:08:55 +0000796}
Igor Sysoev6a644c62003-03-04 06:33:48 +0000797
Igor Sysoev3d09c8d2003-05-06 17:03:16 +0000798
Igor Sysoev6253ca12003-05-27 12:18:54 +0000799char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev3d09c8d2003-05-06 17:03:16 +0000800{
Igor Sysoevaa3436c2003-05-30 14:27:59 +0000801 char *p = conf;
802
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000803 time_t *sp;
Igor Sysoev12b4b002003-10-24 06:53:41 +0000804 ngx_str_t *value;
805 ngx_conf_post_t *post;
Igor Sysoev3d09c8d2003-05-06 17:03:16 +0000806
Igor Sysoevf1079102003-10-23 06:13:16 +0000807
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000808 sp = (time_t *) (p + cmd->offset);
809 if (*sp != NGX_CONF_UNSET) {
Igor Sysoev1c13c662003-05-20 15:37:55 +0000810 return "is duplicate";
811 }
812
Igor Sysoeva3677242004-04-14 05:57:36 +0000813 value = cf->args->elts;
Igor Sysoev3d09c8d2003-05-06 17:03:16 +0000814
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000815 *sp = ngx_parse_time(&value[1], 1);
816 if (*sp == NGX_ERROR) {
Igor Sysoev8556e6d2003-10-23 15:54:19 +0000817 return "invalid value";
Igor Sysoev3d09c8d2003-05-06 17:03:16 +0000818 }
819
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000820 if (*sp == NGX_PARSE_LARGE_TIME) {
Igor Sysoev8556e6d2003-10-23 15:54:19 +0000821 return "value must be less than 68 years";
822 }
Igor Sysoevf1079102003-10-23 06:13:16 +0000823
Igor Sysoev12b4b002003-10-24 06:53:41 +0000824 if (cmd->post) {
825 post = cmd->post;
Igor Sysoev0ee5d3c2004-02-20 16:48:59 +0000826 return post->post_handler(cf, post, sp);
Igor Sysoevf1079102003-10-23 06:13:16 +0000827 }
Igor Sysoev3d09c8d2003-05-06 17:03:16 +0000828
829 return NGX_CONF_OK;
830}
831
832
Igor Sysoev3ae32482003-10-08 15:32:54 +0000833char *ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
834{
Igor Sysoev68ee8f12003-10-30 08:51:06 +0000835 char *p = conf;
Igor Sysoev3ae32482003-10-08 15:32:54 +0000836
Igor Sysoev3ae32482003-10-08 15:32:54 +0000837 ngx_str_t *value;
838 ngx_bufs_t *bufs;
839
840
841 bufs = (ngx_bufs_t *) (p + cmd->offset);
Igor Sysoev3ae32482003-10-08 15:32:54 +0000842 if (bufs->num) {
843 return "is duplicate";
844 }
845
Igor Sysoeva3677242004-04-14 05:57:36 +0000846 value = cf->args->elts;
Igor Sysoev3ae32482003-10-08 15:32:54 +0000847
848 bufs->num = ngx_atoi(value[1].data, value[1].len);
849 if (bufs->num == NGX_ERROR || bufs->num == 0) {
850 return "invalid value";
851 }
852
Igor Sysoev8556e6d2003-10-23 15:54:19 +0000853 bufs->size = ngx_parse_size(&value[2]);
Igor Sysoevb5910d42003-10-30 16:51:33 +0000854 if (bufs->size == (size_t) NGX_ERROR || bufs->size == 0) {
Igor Sysoev3ae32482003-10-08 15:32:54 +0000855 return "invalid value";
856 }
857
Igor Sysoev3ae32482003-10-08 15:32:54 +0000858 return NGX_CONF_OK;
859}
860
861
Igor Sysoeva3677242004-04-14 05:57:36 +0000862char *ngx_conf_set_enum_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
863{
864 char *p = conf;
865
866 ngx_uint_t *np, i;
867 ngx_str_t *value;
868 ngx_conf_enum_t *e;
869
870 np = (ngx_uint_t *) (p + cmd->offset);
871
872 if (*np != NGX_CONF_UNSET_UINT) {
873 return "is duplicate";
874 }
875
876 value = cf->args->elts;
877 e = cmd->post;
878
879 for (i = 0; e[i].name.len != 0; i++) {
880 if (e[i].name.len != value[1].len
881 || ngx_strcasecmp(e[i].name.data, value[1].data) != 0)
882 {
883 continue;
884 }
885
886 *np = e[i].value;
887
888 return NGX_CONF_OK;
889 }
890
891 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
892 "invalid value \"%s\"", value[1].data);
893
894 return NGX_CONF_ERROR;
895}
896
897
Igor Sysoev68ee8f12003-10-30 08:51:06 +0000898char *ngx_conf_set_bitmask_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
899{
900 char *p = conf;
901
Igor Sysoev10a543a2004-03-16 07:10:12 +0000902 ngx_uint_t *np, i, m;
Igor Sysoev68ee8f12003-10-30 08:51:06 +0000903 ngx_str_t *value;
904 ngx_conf_bitmask_t *mask;
905
906
Igor Sysoev10a543a2004-03-16 07:10:12 +0000907 np = (ngx_uint_t *) (p + cmd->offset);
Igor Sysoeva3677242004-04-14 05:57:36 +0000908 value = cf->args->elts;
Igor Sysoev68ee8f12003-10-30 08:51:06 +0000909 mask = cmd->post;
910
911 for (i = 1; i < cf->args->nelts; i++) {
912 for (m = 0; mask[m].name.len != 0; m++) {
913
914 if (mask[m].name.len != value[i].len
Igor Sysoeva3677242004-04-14 05:57:36 +0000915 || ngx_strcasecmp(mask[m].name.data, value[i].data) != 0)
Igor Sysoev68ee8f12003-10-30 08:51:06 +0000916 {
917 continue;
918 }
919
920 if (*np & mask[m].mask) {
921 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
922 "duplicate value \"%s\"", value[i].data);
923
924 } else {
925 *np |= mask[m].mask;
926 }
927
928 break;
929 }
930
931 if (mask[m].name.len == 0) {
932 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
933 "invalid value \"%s\"", value[i].data);
934
935 return NGX_CONF_ERROR;
936 }
937 }
938
939 return NGX_CONF_OK;
940}
941
942
Igor Sysoev6253ca12003-05-27 12:18:54 +0000943char *ngx_conf_unsupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
Igor Sysoev6a644c62003-03-04 06:33:48 +0000944{
945 return "unsupported on this platform";
946}
Igor Sysoevf1079102003-10-23 06:13:16 +0000947
948
Igor Sysoev12b4b002003-10-24 06:53:41 +0000949char *ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data)
Igor Sysoevf1079102003-10-23 06:13:16 +0000950{
Igor Sysoev369145c2004-05-28 15:49:23 +0000951 ngx_conf_num_bounds_t *bounds = post;
952 ngx_int_t *np = data;
Igor Sysoevf1079102003-10-23 06:13:16 +0000953
Igor Sysoevcf80a702003-11-03 22:20:44 +0000954 if (bounds->high == -1) {
955 if (*np >= bounds->low) {
956 return NGX_CONF_OK;
957 }
958
959 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
Igor Sysoevf60b1a52003-11-04 17:09:19 +0000960 "value must be equal or more than %d", bounds->low);
Igor Sysoevcf80a702003-11-03 22:20:44 +0000961
962 return NGX_CONF_ERROR;
963 }
964
965 if (*np >= bounds->low && *np <= bounds->high) {
Igor Sysoevf1079102003-10-23 06:13:16 +0000966 return NGX_CONF_OK;
Igor Sysoevf1079102003-10-23 06:13:16 +0000967 }
968
Igor Sysoevcf80a702003-11-03 22:20:44 +0000969 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
970 "value must be between %d and %d",
971 bounds->low, bounds->high);
972
973 return NGX_CONF_ERROR;
Igor Sysoevf1079102003-10-23 06:13:16 +0000974}