comparison src/core/ngx_conf_file.c @ 4768:1c5e2e4d5b35

Improved diagnostics when a directive is specified in the wrong context.
author Ruslan Ermilov <ru@nginx.com>
date Sun, 29 Jul 2012 19:59:06 +0000
parents 4c36e15651f7
children 6e46016ea276
comparison
equal deleted inserted replaced
4767:d9190c84e594 4768:1c5e2e4d5b35
280 static ngx_int_t 280 static ngx_int_t
281 ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last) 281 ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last)
282 { 282 {
283 char *rv; 283 char *rv;
284 void *conf, **confp; 284 void *conf, **confp;
285 ngx_uint_t i, multi; 285 ngx_uint_t i, found;
286 ngx_str_t *name; 286 ngx_str_t *name;
287 ngx_command_t *cmd; 287 ngx_command_t *cmd;
288 288
289 name = cf->args->elts; 289 name = cf->args->elts;
290 290
291 multi = 0; 291 found = 0;
292 292
293 for (i = 0; ngx_modules[i]; i++) { 293 for (i = 0; ngx_modules[i]; i++) {
294
295 /* look up the directive in the appropriate modules */
296
297 if (ngx_modules[i]->type != NGX_CONF_MODULE
298 && ngx_modules[i]->type != cf->module_type)
299 {
300 continue;
301 }
302 294
303 cmd = ngx_modules[i]->commands; 295 cmd = ngx_modules[i]->commands;
304 if (cmd == NULL) { 296 if (cmd == NULL) {
305 continue; 297 continue;
306 } 298 }
313 305
314 if (ngx_strcmp(name->data, cmd->name.data) != 0) { 306 if (ngx_strcmp(name->data, cmd->name.data) != 0) {
315 continue; 307 continue;
316 } 308 }
317 309
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 }
318 317
319 /* is the directive's location right ? */ 318 /* is the directive's location right ? */
320 319
321 if (!(cmd->type & cf->cmd_type)) { 320 if (!(cmd->type & cf->cmd_type)) {
322 if (cmd->type & NGX_CONF_MULTI) { 321 continue;
323 multi = 1;
324 continue;
325 }
326
327 goto not_allowed;
328 } 322 }
329 323
330 if (!(cmd->type & NGX_CONF_BLOCK) && last != NGX_OK) { 324 if (!(cmd->type & NGX_CONF_BLOCK) && last != NGX_OK) {
331 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 325 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
332 "directive \"%s\" is not terminated by \";\"", 326 "directive \"%s\" is not terminated by \";\"",
406 400
407 return NGX_ERROR; 401 return NGX_ERROR;
408 } 402 }
409 } 403 }
410 404
411 if (multi == 0) { 405 if (found) {
412 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 406 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
413 "unknown directive \"%s\"", name->data); 407 "\"%s\" directive is not allowed here", name->data);
414 408
415 return NGX_ERROR; 409 return NGX_ERROR;
416 } 410 }
417 411
418 not_allowed:
419
420 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 412 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
421 "\"%s\" directive is not allowed here", name->data); 413 "unknown directive \"%s\"", name->data);
414
422 return NGX_ERROR; 415 return NGX_ERROR;
423 416
424 invalid: 417 invalid:
425 418
426 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 419 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,