diff src/http/ngx_http.c @ 34:aab2ea7c0458 NGINX_0_1_17

nginx 0.1.17 *) Change: the ngx_http_rewrite_module was rewritten from the scratch. Now it is possible to redirect, to return the error codes, to check the variables and referrers. The directives can be used inside locations. The redirect directive was canceled. *) Feature: the ngx_http_geo_module. *) Feature: the proxy_set_x_var and fastcgi_set_var directives. *) Bugfix: the location configuration with "=" modifier may be used in another location. *) Bugfix: the correct content type was set only for requests that use small caps letters in extension. *) Bugfix: if the proxy_pass or fastcgi_pass directives were set in the location, and access was denied, and the error was redirected to a static page, then the segmentation fault occurred. *) Bugfix: if in a proxied "Location" header was a relative URL, then a host name and a slash were added to them; bug appeared in 0.1.14. *) Bugfix: the system error message was not logged on Linux.
author Igor Sysoev <http://sysoev.ru>
date Thu, 03 Feb 2005 00:00:00 +0300
parents 45fe5b98a9de
children 6cfc63e68377
line wrap: on
line diff
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -26,7 +26,7 @@ static char *ngx_http_merge_locations(ng
                                       ngx_http_module_t *module,
                                       ngx_uint_t ctx_index);
 
-int         ngx_http_max_module;
+ngx_uint_t  ngx_http_max_module;
 
 ngx_uint_t  ngx_http_total_requests;
 uint64_t    ngx_http_total_sent;
@@ -89,19 +89,20 @@ static char *ngx_http_block(ngx_conf_t *
 #endif
 
 #if (NGX_SUPPRESS_WARN)
-    /* MSVC thinks 'in_ports' may be used without having been initialized */
+    /* MSVC thinks "in_ports" may be used without having been initialized */
     ngx_memzero(&in_ports, sizeof(ngx_array_t));
 #endif
 
 
     /* the main http context */
 
-    ngx_test_null(ctx,
-                  ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)),
-                  NGX_CONF_ERROR);
+    if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) {
+        return NGX_CONF_ERROR;
+    }
 
     *(ngx_http_conf_ctx_t **) conf = ctx;
 
+
     /* count the number of the http modules and set up their indices */
 
     ngx_http_max_module = 0;
@@ -113,24 +114,42 @@ static char *ngx_http_block(ngx_conf_t *
         ngx_modules[m]->ctx_index = ngx_http_max_module++;
     }
 
-    /* the main http main_conf, it's the same in the all http contexts */
 
-    ngx_test_null(ctx->main_conf,
-                  ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
-                  NGX_CONF_ERROR);
+    /* the http main_conf context, it is the same in the all http contexts */
 
-    /* the http null srv_conf, it's used to merge the server{}s' srv_conf's */
-    ngx_test_null(ctx->srv_conf,
-                  ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
-                  NGX_CONF_ERROR);
-
-    /* the http null loc_conf, it's used to merge the server{}s' loc_conf's */
-    ngx_test_null(ctx->loc_conf,
-                  ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
-                  NGX_CONF_ERROR);
+    ctx->main_conf = ngx_pcalloc(cf->pool,
+                                 sizeof(void *) * ngx_http_max_module);
+    if (ctx->main_conf == NULL) {
+        return NGX_CONF_ERROR;
+    }
 
 
-    /* create the main_conf, srv_conf and loc_conf in all http modules */
+    /*
+     * the http null srv_conf context, it is used to merge
+     * the server{}s' srv_conf's
+     */
+
+    ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
+    if (ctx->srv_conf == NULL) {
+        return NGX_CONF_ERROR;
+    }
+
+
+    /*
+     * the http null loc_conf context, it is used to merge
+     * the server{}s' loc_conf's
+     */
+
+    ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
+    if (ctx->loc_conf == NULL) {
+        return NGX_CONF_ERROR;
+    }
+
+
+    /*
+     * create the main_conf's, the null srv_conf's, and the null loc_conf's
+     * of the all http modules
+     */
 
     for (m = 0; ngx_modules[m]; m++) {
         if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
@@ -147,21 +166,25 @@ static char *ngx_http_block(ngx_conf_t *
         }
 
         if (module->create_main_conf) {
-            ngx_test_null(ctx->main_conf[mi], module->create_main_conf(cf),
-                          NGX_CONF_ERROR);
+            if (!(ctx->main_conf[mi] = module->create_main_conf(cf))) {
+                return NGX_CONF_ERROR;
+            }
         }
 
         if (module->create_srv_conf) {
-            ngx_test_null(ctx->srv_conf[mi], module->create_srv_conf(cf),
-                          NGX_CONF_ERROR);
+            if (!(ctx->srv_conf[mi] = module->create_srv_conf(cf))) {
+                return NGX_CONF_ERROR;
+            }
         }
 
         if (module->create_loc_conf) {
-            ngx_test_null(ctx->loc_conf[mi], module->create_loc_conf(cf),
-                          NGX_CONF_ERROR);
+            if (!(ctx->loc_conf[mi] = module->create_loc_conf(cf))) {
+                return NGX_CONF_ERROR;
+            }
         }
     }
 
+
     /* parse inside the http{} block */
 
     pcf = *cf;
@@ -236,57 +259,59 @@ static char *ngx_http_block(ngx_conf_t *
                     *cf = pcf;
                     return rv;
                 }
-
-#if 0
-                clcfp = (ngx_http_core_loc_conf_t **) cscfp[s]->locations.elts;
-
-                for (l = 0; l < cscfp[s]->locations.nelts; l++) {
-                    rv = module->merge_loc_conf(cf,
-                                                cscfp[s]->ctx->loc_conf[mi],
-                                                clcfp[l]->loc_conf[mi]);
-                    if (rv != NGX_CONF_OK) {
-                        *cf = pcf;
-                        return rv;
-                    }
-                }
-#endif
             }
         }
     }
 
-    /* we needed "http"'s cf->ctx while merging configuration */
+
+    /* we needed http{}'s cf->ctx while the merging configuration */
     *cf = pcf;
 
+
     /* init lists of the handlers */
 
-    ngx_init_array(cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers,
-                   cf->cycle->pool, 10, sizeof(ngx_http_handler_pt),
-                   NGX_CONF_ERROR);
+    if (ngx_array_init(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers,
+                       cf->pool, 1, sizeof(ngx_http_handler_pt)) == NGX_ERROR)
+    {
+        return NGX_CONF_ERROR;
+    }
+
     cmcf->phases[NGX_HTTP_REWRITE_PHASE].type = NGX_OK;
 
 
-    /* the special find config phase for single handler */
+    /* the special find config phase for a single handler */
 
-    ngx_init_array(cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].handlers,
-                   cf->cycle->pool, 1, sizeof(ngx_http_handler_pt),
-                   NGX_CONF_ERROR);
+    if (ngx_array_init(&cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].handlers,
+                       cf->pool, 1, sizeof(ngx_http_handler_pt)) == NGX_ERROR)
+    {
+        return NGX_CONF_ERROR;
+    }
+
     cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].type = NGX_OK;
 
-    ngx_test_null(h, ngx_push_array(
-                           &cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].handlers),
-                  NGX_CONF_ERROR);
+    h = ngx_push_array(&cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].handlers);
+    if (h == NULL) {
+        return NGX_CONF_ERROR;
+    }
+
     *h = ngx_http_find_location_config;
 
 
-    ngx_init_array(cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers,
-                   cf->cycle->pool, 10, sizeof(ngx_http_handler_pt),
-                   NGX_CONF_ERROR);
+    if (ngx_array_init(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers,
+                       cf->pool, 1, sizeof(ngx_http_handler_pt)) == NGX_ERROR)
+    {
+        return NGX_CONF_ERROR;
+    }
+
     cmcf->phases[NGX_HTTP_ACCESS_PHASE].type = NGX_DECLINED;
 
 
-    ngx_init_array(cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers,
-                   cf->cycle->pool, 10, sizeof(ngx_http_handler_pt),
-                   NGX_CONF_ERROR);
+    if (ngx_array_init(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers,
+                       cf->pool, 4, sizeof(ngx_http_handler_pt)) == NGX_ERROR)
+    {
+        return NGX_CONF_ERROR;
+    }
+
     cmcf->phases[NGX_HTTP_CONTENT_PHASE].type = NGX_OK;