aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_conf_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/ngx_conf_file.c')
-rw-r--r--src/core/ngx_conf_file.c184
1 files changed, 96 insertions, 88 deletions
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 7c22948a3..b895910d5 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -221,12 +221,14 @@ ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last)
{
char *rv;
void *conf, **confp;
- ngx_uint_t i, valid;
+ ngx_uint_t i, multi;
ngx_str_t *name;
ngx_command_t *cmd;
name = cf->args->elts;
+ multi = 0;
+
for (i = 0; ngx_modules[i]; i++) {
/* look up the directive in the appropriate modules */
@@ -242,132 +244,138 @@ ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last)
continue;
}
- while (cmd->name.len) {
+ for ( /* void */ ; cmd->name.len; cmd++) {
- if (name->len == cmd->name.len
- && ngx_strcmp(name->data, cmd->name.data) == 0)
- {
- /* is the directive's location right ? */
+ if (name->len != cmd->name.len) {
+ continue;
+ }
- if (!(cmd->type & cf->cmd_type)) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "directive \"%s\" in %s:%ui "
- "is not allowed here",
- name->data, cf->conf_file->file.name.data,
- cf->conf_file->line);
- return NGX_ERROR;
- }
+ if (ngx_strcmp(name->data, cmd->name.data) != 0) {
+ continue;
+ }
- if (!(cmd->type & NGX_CONF_BLOCK) && last != NGX_OK) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "directive \"%s\" in %s:%ui "
- "is not terminated by \";\"",
- name->data, cf->conf_file->file.name.data,
- cf->conf_file->line);
- return NGX_ERROR;
- }
- if ((cmd->type & NGX_CONF_BLOCK)
- && last != NGX_CONF_BLOCK_START)
- {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "directive \"%s\" in %s:%ui "
- "has not the opening \"{\"",
- name->data, cf->conf_file->file.name.data,
- cf->conf_file->line);
- return NGX_ERROR;
+ /* is the directive's location right ? */
+
+ if (!(cmd->type & cf->cmd_type)) {
+ if (cmd->type & NGX_CONF_MULTI) {
+ multi = 1;
+ continue;
}
- /* is the directive's argument count right ? */
+ goto not_allowed;
+ }
+
+ if (!(cmd->type & NGX_CONF_BLOCK) && last != NGX_OK) {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "directive \"%s\" in %s:%ui "
+ "is not terminated by \";\"",
+ name->data, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ return NGX_ERROR;
+ }
+
+ if ((cmd->type & NGX_CONF_BLOCK) && last != NGX_CONF_BLOCK_START) {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "directive \"%s\" in %s:%ui "
+ "has not the opening \"{\"",
+ name->data, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ return NGX_ERROR;
+ }
+
+ /* is the directive's argument count right ? */
- if (cmd->type & NGX_CONF_ANY) {
- valid = 1;
+ if (!(cmd->type & NGX_CONF_ANY)) {
- } else if (cmd->type & NGX_CONF_FLAG) {
+ if (cmd->type & NGX_CONF_FLAG) {
- if (cf->args->nelts == 2) {
- valid = 1;
- } else {
- valid = 0;
+ if (cf->args->nelts != 2) {
+ goto invalid;
}
} else if (cmd->type & NGX_CONF_1MORE) {
- if (cf->args->nelts > 1) {
- valid = 1;
- } else {
- valid = 0;
+ if (cf->args->nelts < 2) {
+ goto invalid;
}
} else if (cmd->type & NGX_CONF_2MORE) {
- if (cf->args->nelts > 2) {
- valid = 1;
- } else {
- valid = 0;
+ if (cf->args->nelts < 3) {
+ goto invalid;
}
- } else if (cf->args->nelts <= NGX_CONF_MAX_ARGS
- && (cmd->type
- & argument_number[cf->args->nelts - 1]))
- {
- valid = 1;
+ } else if (cf->args->nelts > NGX_CONF_MAX_ARGS) {
- } else {
- valid = 0;
- }
+ goto invalid;
- if (!valid) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "invalid number arguments in "
- "directive \"%s\" in %s:%ui",
- name->data, cf->conf_file->file.name.data,
- cf->conf_file->line);
- return NGX_ERROR;
+ } else if (!(cmd->type & argument_number[cf->args->nelts - 1]))
+ {
+ goto invalid;
}
+ }
- /* set up the directive's configuration context */
-
- conf = NULL;
-
- if (cmd->type & NGX_DIRECT_CONF) {
- conf = ((void **) cf->ctx)[ngx_modules[i]->index];
+ /* set up the directive's configuration context */
- } else if (cmd->type & NGX_MAIN_CONF) {
- conf = &(((void **) cf->ctx)[ngx_modules[i]->index]);
+ conf = NULL;
- } else if (cf->ctx) {
- confp = *(void **) ((char *) cf->ctx + cmd->conf);
+ if (cmd->type & NGX_DIRECT_CONF) {
+ conf = ((void **) cf->ctx)[ngx_modules[i]->index];
- if (confp) {
- conf = confp[ngx_modules[i]->ctx_index];
- }
- }
+ } else if (cmd->type & NGX_MAIN_CONF) {
+ conf = &(((void **) cf->ctx)[ngx_modules[i]->index]);
- rv = cmd->set(cf, cmd, conf);
+ } else if (cf->ctx) {
+ confp = *(void **) ((char *) cf->ctx + cmd->conf);
- if (rv == NGX_CONF_OK) {
- return NGX_OK;
+ if (confp) {
+ conf = confp[ngx_modules[i]->ctx_index];
}
+ }
- if (rv == NGX_CONF_ERROR) {
- return NGX_ERROR;
- }
+ rv = cmd->set(cf, cmd, conf);
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "the \"%s\" directive %s in %s:%ui",
- name->data, rv, cf->conf_file->file.name.data,
- cf->conf_file->line);
+ if (rv == NGX_CONF_OK) {
+ return NGX_OK;
+ }
+ if (rv == NGX_CONF_ERROR) {
return NGX_ERROR;
}
- cmd++;
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "the \"%s\" directive %s in %s:%ui",
+ name->data, rv, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+
+ return NGX_ERROR;
}
}
+ if (multi == 0) {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "unknown directive \"%s\" in %s:%ui",
+ name->data, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+
+ return NGX_ERROR;
+ }
+
+not_allowed:
+
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "directive \"%s\" in %s:%ui "
+ "is not allowed here",
+ name->data, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ return NGX_ERROR;
+
+invalid:
+
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "unknown directive \"%s\" in %s:%ui",
+ "invalid number arguments in "
+ "directive \"%s\" in %s:%ui",
name->data, cf->conf_file->file.name.data,
cf->conf_file->line);