[nginx] svn commit: r5048 - in branches/stable-1.2: . src/core src/http/modules

mdounin at mdounin.ru mdounin at mdounin.ru
Mon Feb 11 12:26:34 UTC 2013


Author: mdounin
Date: 2013-02-11 12:26:33 +0000 (Mon, 11 Feb 2013)
New Revision: 5048
URL: http://trac.nginx.org/nginx/changeset/5048/nginx

Log:
Merge of r4968, r4969, r4977, r4980, r4981, r4990: geo fixes.

*) Geo: improved ngx_http_geo_block() code readability.

*) Geo: fixed the "ranges" without ranges case.  The following
   configuration returned an empty value for $geo:

       geo $geo {
           ranges;
           default default;
       }

*) Fixed return type of internal function that allocates radix tree nodes.

*) There's no need to normalize address returned by ngx_ptocidr().

*) Geo: ensure that default entry is always present.  If 0.0.0.0/32 entry
   was present and there was no explicit "default", we failed to add an
   empty string as a default value.

*) Trailing whitespace fix.


Modified:
   branches/stable-1.2/
   branches/stable-1.2/src/core/ngx_radix_tree.c
   branches/stable-1.2/src/http/modules/ngx_http_geo_module.c

Index: branches/stable-1.2
===================================================================
--- branches/stable-1.2	2013-02-10 03:55:18 UTC (rev 5047)
+++ branches/stable-1.2	2013-02-11 12:26:33 UTC (rev 5048)

Property changes on: branches/stable-1.2
___________________________________________________________________
Modified: svn:mergeinfo
## -1 +1 ##
-/trunk:4611-4632,4636-4657,4671-4672,4674-4676,4682,4684-4699,4704-4706,4713,4736-4741,4754,4756-4771,4775,4777-4780,4782-4785,4795,4811-4820,4822-4824,4828-4835,4840-4844,4865-4872,4885-4887,4890-4896,4913-4925,4933-4934,4939,4944-4949,4961-4967,4973,4978,4984,5011
+/trunk:4611-4632,4636-4657,4671-4672,4674-4676,4682,4684-4699,4704-4706,4713,4736-4741,4754,4756-4771,4775,4777-4780,4782-4785,4795,4811-4820,4822-4824,4828-4835,4840-4844,4865-4872,4885-4887,4890-4896,4913-4925,4933-4934,4939,4944-4949,4961-4969,4973,4977-4978,4980-4981,4984,4990,5011
\ No newline at end of property
Modified: branches/stable-1.2/src/core/ngx_radix_tree.c
===================================================================
--- branches/stable-1.2/src/core/ngx_radix_tree.c	2013-02-10 03:55:18 UTC (rev 5047)
+++ branches/stable-1.2/src/core/ngx_radix_tree.c	2013-02-11 12:26:33 UTC (rev 5048)
@@ -9,7 +9,7 @@
 #include <ngx_core.h>
 
 
-static void *ngx_radix_alloc(ngx_radix_tree_t *tree);
+static ngx_radix_node_t *ngx_radix_alloc(ngx_radix_tree_t *tree);
 
 
 ngx_radix_tree_t *
@@ -263,13 +263,13 @@
 }
 
 
-static void *
+static ngx_radix_node_t *
 ngx_radix_alloc(ngx_radix_tree_t *tree)
 {
-    char  *p;
+    ngx_radix_node_t  *p;
 
     if (tree->free) {
-        p = (char *) tree->free;
+        p = tree->free;
         tree->free = tree->free->right;
         return p;
     }
@@ -283,7 +283,7 @@
         tree->size = ngx_pagesize;
     }
 
-    p = tree->start;
+    p = (ngx_radix_node_t *) tree->start;
     tree->start += sizeof(ngx_radix_node_t);
     tree->size -= sizeof(ngx_radix_node_t);
 

Modified: branches/stable-1.2/src/http/modules/ngx_http_geo_module.c
===================================================================
--- branches/stable-1.2/src/http/modules/ngx_http_geo_module.c	2013-02-10 03:55:18 UTC (rev 5047)
+++ branches/stable-1.2/src/http/modules/ngx_http_geo_module.c	2013-02-11 12:26:33 UTC (rev 5048)
@@ -189,19 +189,22 @@
 
     *v = *ctx->u.high.default_value;
 
-    addr = ngx_http_geo_addr(r, ctx);
+    if (ctx->u.high.low) {
+        addr = ngx_http_geo_addr(r, ctx);
 
-    range = ctx->u.high.low[addr >> 16];
+        range = ctx->u.high.low[addr >> 16];
 
-    if (range) {
-        n = addr & 0xffff;
-        do {
-            if (n >= (ngx_uint_t) range->start && n <= (ngx_uint_t) range->end)
-            {
-                *v = *range->value;
-                break;
-            }
-        } while ((++range)->value);
+        if (range) {
+            n = addr & 0xffff;
+            do {
+                if (n >= (ngx_uint_t) range->start
+                    && n <= (ngx_uint_t) range->end)
+                {
+                    *v = *range->value;
+                    break;
+                }
+            } while ((++range)->value);
+        }
     }
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
@@ -303,7 +306,6 @@
 ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
     char                     *rv;
-    void                    **p;
     size_t                    len;
     ngx_str_t                *value, name;
     ngx_uint_t                i;
@@ -392,9 +394,9 @@
     geo->proxies = ctx.proxies;
     geo->proxy_recursive = ctx.proxy_recursive;
 
-    if (ctx.high.low) {
+    if (ctx.ranges) {
 
-        if (!ctx.binary_include) {
+        if (ctx.high.low && !ctx.binary_include) {
             for (i = 0; i < 0x10000; i++) {
                 a = (ngx_array_t *) ctx.high.low[i];
 
@@ -409,8 +411,8 @@
                     return NGX_CONF_ERROR;
                 }
 
-                p = (void **) ngx_cpymem(ctx.high.low[i], a->elts, len);
-                *p = NULL;
+                ngx_memcpy(ctx.high.low[i], a->elts, len);
+                ctx.high.low[i][a->nelts].value = NULL;
                 ctx.data_size += len + sizeof(void *);
             }
 
@@ -451,16 +453,14 @@
         ngx_destroy_pool(ctx.temp_pool);
         ngx_destroy_pool(pool);
 
-        if (ngx_radix32tree_find(ctx.tree, 0) != NGX_RADIX_NO_VALUE) {
-            return rv;
-        }
-
         if (ngx_radix32tree_insert(ctx.tree, 0, 0,
                                    (uintptr_t) &ngx_http_variable_null_value)
             == NGX_ERROR)
         {
             return NGX_CONF_ERROR;
         }
+
+        /* NGX_BUSY is okay (default was set explicitly) */
     }
 
     return rv;
@@ -996,7 +996,7 @@
         /* rc == NGX_BUSY */
 
         old = (ngx_http_variable_value_t *)
-              ngx_radix32tree_find(ctx->tree, cidr.u.in.addr & cidr.u.in.mask);
+              ngx_radix32tree_find(ctx->tree, cidr.u.in.addr);
 
         ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
                 "duplicate network \"%V\", value: \"%v\", old value: \"%v\"",



More information about the nginx-devel mailing list