diff src/core/ngx_conf_file.c @ 194:003bd800ec2a NGINX_0_3_44

nginx 0.3.44 *) 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 <http://sysoev.ru>
date Thu, 04 May 2006 00:00:00 +0400
parents 87699398f955
children e6da4931e0e0
line wrap: on
line diff
--- 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
 {
     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
             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;
+            }
+
+
+            /* is the directive's location right ? */
+
+            if (!(cmd->type & cf->cmd_type)) {
+                if (cmd->type & NGX_CONF_MULTI) {
+                    multi = 1;
+                    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;
-                }
+                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;
-                }
+            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 ? */
+            /* 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 */
+            /* set up the directive's configuration context */
 
-                conf = NULL;
+            conf = NULL;
 
-                if (cmd->type & NGX_DIRECT_CONF) {
-                    conf = ((void **) cf->ctx)[ngx_modules[i]->index];
+            if (cmd->type & NGX_DIRECT_CONF) {
+                conf = ((void **) cf->ctx)[ngx_modules[i]->index];
 
-                } else if (cmd->type & NGX_MAIN_CONF) {
-                    conf = &(((void **) cf->ctx)[ngx_modules[i]->index]);
-
-                } else if (cf->ctx) {
-                    confp = *(void **) ((char *) cf->ctx + cmd->conf);
+            } else if (cmd->type & NGX_MAIN_CONF) {
+                conf = &(((void **) cf->ctx)[ngx_modules[i]->index]);
 
-                    if (confp) {
-                        conf = confp[ngx_modules[i]->ctx_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 (rv == NGX_CONF_ERROR) {
-                    return NGX_ERROR;
+                if (confp) {
+                    conf = confp[ngx_modules[i]->ctx_index];
                 }
+            }
 
-                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);
+            rv = cmd->set(cf, cmd, conf);
 
+            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,
-                  "unknown directive \"%s\" in %s:%ui",
+                  "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,
+                  "invalid number arguments in "
+                  "directive \"%s\" in %s:%ui",
                   name->data, cf->conf_file->file.name.data,
                   cf->conf_file->line);