diff src/http/modules/ngx_http_geo_module.c @ 138:8e6d4d96ec4c NGINX_0_3_16

nginx 0.3.16 *) Feature: the ngx_http_map_module. *) Feature: the "types_hash_max_size" and "types_hash_bucket_size" directives. *) Feature: the "ssi_value_length" directive. *) Feature: the "worker_rlimit_core" directive. *) Workaround: the connection number in logs was always 1 if nginx was built by the icc 8.1 or 9.0 compilers with optimization for Pentium 4. *) Bugfix: the "config timefmt" SSI command set incorrect time format. *) Bugfix: nginx did not close connection to IMAP/POP3 backend for the SSL connections; bug appeared in 0.3.13. Thanks to Rob Mueller. *) Bugfix: segmentation fault may occurred in at SSL shutdown; bug appeared in 0.3.13.
author Igor Sysoev <http://sysoev.ru>
date Fri, 16 Dec 2005 00:00:00 +0300
parents 91372f004adf
children 54aabf2b0bc6
line wrap: on
line diff
--- a/src/http/modules/ngx_http_geo_module.c
+++ b/src/http/modules/ngx_http_geo_module.c
@@ -13,7 +13,7 @@ typedef struct {
     ngx_radix_tree_t  *tree;
     ngx_pool_t        *pool;
     ngx_array_t        values;
-} ngx_http_geo_conf_t;
+} ngx_http_geo_conf_ctx_t;
 
 
 static char *ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
@@ -95,12 +95,12 @@ ngx_http_geo_variable(ngx_http_request_t
 static char *
 ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
-    char                 *rv;
-    ngx_str_t            *value, name;
-    ngx_conf_t            save;
-    ngx_pool_t           *pool;
-    ngx_radix_tree_t     *tree;
-    ngx_http_geo_conf_t   geo;
+    char                     *rv;
+    ngx_str_t                *value, name;
+    ngx_conf_t                save;
+    ngx_pool_t               *pool;
+    ngx_radix_tree_t         *tree;
+    ngx_http_geo_conf_ctx_t   ctx;
     ngx_http_variable_t  *var;
 
     value = cf->args->elts;
@@ -135,20 +135,20 @@ ngx_http_geo_block(ngx_conf_t *cf, ngx_c
         return NGX_CONF_ERROR;
     }
 
-    if (ngx_array_init(&geo.values, pool, 512,
+    if (ngx_array_init(&ctx.values, pool, 512,
                        sizeof(ngx_http_variable_value_t *))
-        == NGX_ERROR)
+        != NGX_OK)
     {
         ngx_destroy_pool(pool);
         return NGX_CONF_ERROR;
     }
 
-    geo.tree = tree;
-    geo.pool = cf->pool;
+    ctx.tree = tree;
+    ctx.pool = cf->pool;
 
     save = *cf;
     cf->pool = pool;
-    cf->ctx = &geo;
+    cf->ctx = &ctx;
     cf->handler = ngx_http_geo;
     cf->handler_conf = conf;
 
@@ -182,10 +182,10 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command
     ngx_str_t                  *value, file;
     ngx_uint_t                  i;
     ngx_inet_cidr_t             cidrin;
-    ngx_http_geo_conf_t        *geo;
+    ngx_http_geo_conf_ctx_t    *ctx;
     ngx_http_variable_value_t  *var, *old, **v;
 
-    geo = cf->ctx;
+    ctx = cf->ctx;
 
     if (cf->args->nelts != 2) {
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
@@ -223,28 +223,27 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command
     }
 
     var = NULL;
-    v = geo->values.elts;
+    v = ctx->values.elts;
 
-    for (i = 0; i < geo->values.nelts; i++) {
+    for (i = 0; i < ctx->values.nelts; i++) {
         if ((size_t) v[i]->len != value[1].len) {
             continue;
         }
 
-        if (ngx_strncmp(value[1].data, v[i]->data, value[1].len) == 0)
-        {
+        if (ngx_strncmp(value[1].data, v[i]->data, value[1].len) == 0) {
             var = v[i];
             break;
         }
     }
 
     if (var == NULL) {
-        var = ngx_palloc(geo->pool, sizeof(ngx_http_variable_value_t));
+        var = ngx_palloc(ctx->pool, sizeof(ngx_http_variable_value_t));
         if (var == NULL) {
             return NGX_CONF_ERROR;
         }
 
         var->len = value[1].len;
-        var->data = ngx_pstrdup(geo->pool, &value[1]);
+        var->data = ngx_pstrdup(ctx->pool, &value[1]);
         if (var->data == NULL) {
             return NGX_CONF_ERROR;
         }
@@ -253,7 +252,7 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command
         var->no_cachable = 0;
         var->not_found = 0;
 
-        v = ngx_array_push(&geo->values);
+        v = ngx_array_push(&ctx->values);
         if (v == NULL) {
             return NGX_CONF_ERROR;
         }
@@ -262,7 +261,7 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command
     }
 
     for (i = 2; i; i--) {
-        rc = ngx_radix32tree_insert(geo->tree, cidrin.addr, cidrin.mask,
+        rc = ngx_radix32tree_insert(ctx->tree, cidrin.addr, cidrin.mask,
                                     (uintptr_t) var);
         if (rc == NGX_OK) {
             return NGX_CONF_OK;
@@ -275,14 +274,14 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command
         /* rc == NGX_BUSY */
 
         old  = (ngx_http_variable_value_t *)
-                    ngx_radix32tree_find(geo->tree, cidrin.addr & cidrin.mask);
+                    ngx_radix32tree_find(ctx->tree, cidrin.addr & cidrin.mask);
 
         ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
                            "duplicate parameter \"%V\", value: \"%V\", "
                            "old value: \"%V\"",
                            &value[0], var, old);
 
-        rc = ngx_radix32tree_delete(geo->tree, cidrin.addr, cidrin.mask);
+        rc = ngx_radix32tree_delete(ctx->tree, cidrin.addr, cidrin.mask);
 
         if (rc == NGX_ERROR) {
             return NGX_CONF_ERROR;