Mercurial > hg > nginx
comparison src/core/ngx_conf_file.c @ 645:4946078f0a79 release-0.3.44
nginx-0.3.44-RELEASE import
*) Feature: the "wait" parameter in the "include" SSI command.
*) Feature: the Ukrainian and Byelorussian characters were added to
koi-win conversion table.
*) Bugfix: in the SSI.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 04 May 2006 15:32:46 +0000 |
parents | 65bf042c0b4f |
children | 1e720b0be7ec |
comparison
equal
deleted
inserted
replaced
644:610ff734a8cc | 645:4946078f0a79 |
---|---|
219 static ngx_int_t | 219 static ngx_int_t |
220 ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last) | 220 ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last) |
221 { | 221 { |
222 char *rv; | 222 char *rv; |
223 void *conf, **confp; | 223 void *conf, **confp; |
224 ngx_uint_t i, valid; | 224 ngx_uint_t i, multi; |
225 ngx_str_t *name; | 225 ngx_str_t *name; |
226 ngx_command_t *cmd; | 226 ngx_command_t *cmd; |
227 | 227 |
228 name = cf->args->elts; | 228 name = cf->args->elts; |
229 | |
230 multi = 0; | |
229 | 231 |
230 for (i = 0; ngx_modules[i]; i++) { | 232 for (i = 0; ngx_modules[i]; i++) { |
231 | 233 |
232 /* look up the directive in the appropriate modules */ | 234 /* look up the directive in the appropriate modules */ |
233 | 235 |
240 cmd = ngx_modules[i]->commands; | 242 cmd = ngx_modules[i]->commands; |
241 if (cmd == NULL) { | 243 if (cmd == NULL) { |
242 continue; | 244 continue; |
243 } | 245 } |
244 | 246 |
245 while (cmd->name.len) { | 247 for ( /* void */ ; cmd->name.len; cmd++) { |
246 | 248 |
247 if (name->len == cmd->name.len | 249 if (name->len != cmd->name.len) { |
248 && ngx_strcmp(name->data, cmd->name.data) == 0) | 250 continue; |
249 { | 251 } |
250 /* is the directive's location right ? */ | 252 |
251 | 253 if (ngx_strcmp(name->data, cmd->name.data) != 0) { |
252 if (!(cmd->type & cf->cmd_type)) { | 254 continue; |
253 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | 255 } |
254 "directive \"%s\" in %s:%ui " | 256 |
255 "is not allowed here", | 257 |
256 name->data, cf->conf_file->file.name.data, | 258 /* is the directive's location right ? */ |
257 cf->conf_file->line); | 259 |
258 return NGX_ERROR; | 260 if (!(cmd->type & cf->cmd_type)) { |
259 } | 261 if (cmd->type & NGX_CONF_MULTI) { |
260 | 262 multi = 1; |
261 if (!(cmd->type & NGX_CONF_BLOCK) && last != NGX_OK) { | 263 continue; |
262 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | 264 } |
263 "directive \"%s\" in %s:%ui " | 265 |
264 "is not terminated by \";\"", | 266 goto not_allowed; |
265 name->data, cf->conf_file->file.name.data, | 267 } |
266 cf->conf_file->line); | 268 |
267 return NGX_ERROR; | 269 if (!(cmd->type & NGX_CONF_BLOCK) && last != NGX_OK) { |
268 } | 270 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
269 | 271 "directive \"%s\" in %s:%ui " |
270 if ((cmd->type & NGX_CONF_BLOCK) | 272 "is not terminated by \";\"", |
271 && last != NGX_CONF_BLOCK_START) | 273 name->data, cf->conf_file->file.name.data, |
274 cf->conf_file->line); | |
275 return NGX_ERROR; | |
276 } | |
277 | |
278 if ((cmd->type & NGX_CONF_BLOCK) && last != NGX_CONF_BLOCK_START) { | |
279 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
280 "directive \"%s\" in %s:%ui " | |
281 "has not the opening \"{\"", | |
282 name->data, cf->conf_file->file.name.data, | |
283 cf->conf_file->line); | |
284 return NGX_ERROR; | |
285 } | |
286 | |
287 /* is the directive's argument count right ? */ | |
288 | |
289 if (!(cmd->type & NGX_CONF_ANY)) { | |
290 | |
291 if (cmd->type & NGX_CONF_FLAG) { | |
292 | |
293 if (cf->args->nelts != 2) { | |
294 goto invalid; | |
295 } | |
296 | |
297 } else if (cmd->type & NGX_CONF_1MORE) { | |
298 | |
299 if (cf->args->nelts < 2) { | |
300 goto invalid; | |
301 } | |
302 | |
303 } else if (cmd->type & NGX_CONF_2MORE) { | |
304 | |
305 if (cf->args->nelts < 3) { | |
306 goto invalid; | |
307 } | |
308 | |
309 } else if (cf->args->nelts > NGX_CONF_MAX_ARGS) { | |
310 | |
311 goto invalid; | |
312 | |
313 } else if (!(cmd->type & argument_number[cf->args->nelts - 1])) | |
272 { | 314 { |
273 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | 315 goto invalid; |
274 "directive \"%s\" in %s:%ui " | 316 } |
275 "has not the opening \"{\"", | 317 } |
276 name->data, cf->conf_file->file.name.data, | 318 |
277 cf->conf_file->line); | 319 /* set up the directive's configuration context */ |
278 return NGX_ERROR; | 320 |
279 } | 321 conf = NULL; |
280 | 322 |
281 /* is the directive's argument count right ? */ | 323 if (cmd->type & NGX_DIRECT_CONF) { |
282 | 324 conf = ((void **) cf->ctx)[ngx_modules[i]->index]; |
283 if (cmd->type & NGX_CONF_ANY) { | 325 |
284 valid = 1; | 326 } else if (cmd->type & NGX_MAIN_CONF) { |
285 | 327 conf = &(((void **) cf->ctx)[ngx_modules[i]->index]); |
286 } else if (cmd->type & NGX_CONF_FLAG) { | 328 |
287 | 329 } else if (cf->ctx) { |
288 if (cf->args->nelts == 2) { | 330 confp = *(void **) ((char *) cf->ctx + cmd->conf); |
289 valid = 1; | 331 |
290 } else { | 332 if (confp) { |
291 valid = 0; | 333 conf = confp[ngx_modules[i]->ctx_index]; |
292 } | 334 } |
293 | 335 } |
294 } else if (cmd->type & NGX_CONF_1MORE) { | 336 |
295 | 337 rv = cmd->set(cf, cmd, conf); |
296 if (cf->args->nelts > 1) { | 338 |
297 valid = 1; | 339 if (rv == NGX_CONF_OK) { |
298 } else { | 340 return NGX_OK; |
299 valid = 0; | 341 } |
300 } | 342 |
301 | 343 if (rv == NGX_CONF_ERROR) { |
302 } else if (cmd->type & NGX_CONF_2MORE) { | |
303 | |
304 if (cf->args->nelts > 2) { | |
305 valid = 1; | |
306 } else { | |
307 valid = 0; | |
308 } | |
309 | |
310 } else if (cf->args->nelts <= NGX_CONF_MAX_ARGS | |
311 && (cmd->type | |
312 & argument_number[cf->args->nelts - 1])) | |
313 { | |
314 valid = 1; | |
315 | |
316 } else { | |
317 valid = 0; | |
318 } | |
319 | |
320 if (!valid) { | |
321 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
322 "invalid number arguments in " | |
323 "directive \"%s\" in %s:%ui", | |
324 name->data, cf->conf_file->file.name.data, | |
325 cf->conf_file->line); | |
326 return NGX_ERROR; | |
327 } | |
328 | |
329 /* set up the directive's configuration context */ | |
330 | |
331 conf = NULL; | |
332 | |
333 if (cmd->type & NGX_DIRECT_CONF) { | |
334 conf = ((void **) cf->ctx)[ngx_modules[i]->index]; | |
335 | |
336 } else if (cmd->type & NGX_MAIN_CONF) { | |
337 conf = &(((void **) cf->ctx)[ngx_modules[i]->index]); | |
338 | |
339 } else if (cf->ctx) { | |
340 confp = *(void **) ((char *) cf->ctx + cmd->conf); | |
341 | |
342 if (confp) { | |
343 conf = confp[ngx_modules[i]->ctx_index]; | |
344 } | |
345 } | |
346 | |
347 rv = cmd->set(cf, cmd, conf); | |
348 | |
349 if (rv == NGX_CONF_OK) { | |
350 return NGX_OK; | |
351 } | |
352 | |
353 if (rv == NGX_CONF_ERROR) { | |
354 return NGX_ERROR; | |
355 } | |
356 | |
357 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
358 "the \"%s\" directive %s in %s:%ui", | |
359 name->data, rv, cf->conf_file->file.name.data, | |
360 cf->conf_file->line); | |
361 | |
362 return NGX_ERROR; | 344 return NGX_ERROR; |
363 } | 345 } |
364 | 346 |
365 cmd++; | 347 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
366 } | 348 "the \"%s\" directive %s in %s:%ui", |
367 } | 349 name->data, rv, cf->conf_file->file.name.data, |
350 cf->conf_file->line); | |
351 | |
352 return NGX_ERROR; | |
353 } | |
354 } | |
355 | |
356 if (multi == 0) { | |
357 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
358 "unknown directive \"%s\" in %s:%ui", | |
359 name->data, cf->conf_file->file.name.data, | |
360 cf->conf_file->line); | |
361 | |
362 return NGX_ERROR; | |
363 } | |
364 | |
365 not_allowed: | |
368 | 366 |
369 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | 367 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
370 "unknown directive \"%s\" in %s:%ui", | 368 "directive \"%s\" in %s:%ui " |
369 "is not allowed here", | |
370 name->data, cf->conf_file->file.name.data, | |
371 cf->conf_file->line); | |
372 return NGX_ERROR; | |
373 | |
374 invalid: | |
375 | |
376 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
377 "invalid number arguments in " | |
378 "directive \"%s\" in %s:%ui", | |
371 name->data, cf->conf_file->file.name.data, | 379 name->data, cf->conf_file->file.name.data, |
372 cf->conf_file->line); | 380 cf->conf_file->line); |
373 | 381 |
374 return NGX_ERROR; | 382 return NGX_ERROR; |
375 } | 383 } |