diff src/http/modules/ngx_http_geo_module.c @ 50:72eb30262aac NGINX_0_1_25

nginx 0.1.25 *) Bugfix: nginx did run on Linux parisc. *) Feature: nginx now does not start under FreeBSD if the sysctl kern.ipc.somaxconn value is too big. *) Bugfix: if a request was internally redirected by the ngx_http_index_module module to the ngx_http_proxy_module or ngx_http_fastcgi_module modules, then the index file was not closed after request completion. *) Feature: the "proxy_pass" can be used in location with regular expression. *) Feature: the ngx_http_rewrite_filter_module module supports the condition like "if ($HTTP_USER_AGENT ~ MSIE)". *) Bugfix: nginx started too slow if the large number of addresses and text values were used in the "geo" directive. *) Change: a variable name must be declared as "$name" in the "geo" directive. The previous variant without "$" is still supported, but will be removed soon. *) Feature: the "%{VARIABLE}v" logging parameter. *) Feature: the "set $name value" directive. *) Bugfix: gcc 4.0 compatibility. *) Feature: the --with-openssl-opt=OPTIONS autoconfiguration directive.
author Igor Sysoev <http://sysoev.ru>
date Sat, 19 Mar 2005 00:00:00 +0300
parents 2879cd3a40cb
children b55cbf18157e
line wrap: on
line diff
--- a/src/http/modules/ngx_http_geo_module.c
+++ b/src/http/modules/ngx_http_geo_module.c
@@ -64,9 +64,9 @@ static ngx_http_variable_value_t  ngx_ht
 /* AF_INET only */
 
 static ngx_http_variable_value_t *
-ngx_http_geo_variable(ngx_http_request_t *r, void *data)
+ngx_http_geo_variable(ngx_http_request_t *r, uintptr_t data)
 {
-    ngx_radix_tree_t *tree = data;
+    ngx_radix_tree_t *tree = (ngx_radix_tree_t *) data;
 
     struct sockaddr_in         *sin;
     ngx_http_variable_value_t  *var;
@@ -90,33 +90,46 @@ static char *
 ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
     char                 *rv;
-    ngx_str_t            *value;
+    ngx_str_t            *value, name;
     ngx_conf_t            save;
     ngx_pool_t           *pool;
     ngx_radix_tree_t     *tree;
     ngx_http_geo_conf_t   geo;
     ngx_http_variable_t  *var;
 
-    if (!(var = ngx_http_add_variable(cf))) {
+    value = cf->args->elts;
+
+    name = value[1];
+
+    if (name.data[0] != '$') {
+        ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
+                           "\"%V\" variable name should start with '$'",
+                           &value[1]);
+    } else {
+        name.len--;
+        name.data++;
+    }
+
+    var = ngx_http_add_variable(cf, &name, 1);
+    if (var == NULL) {
         return NGX_CONF_ERROR;
     }
 
-    if (!(tree = ngx_radix_tree_create(cf->pool, -1))) {
+    tree = ngx_radix_tree_create(cf->pool, -1);
+    if (tree == NULL) {
         return NGX_CONF_ERROR;
     }
 
-    value = cf->args->elts;
-
-    var->name = value[1];
     var->handler = ngx_http_geo_variable;
-    var->data = tree;
+    var->data = (uintptr_t) tree;
 
     /*
      * create the temporary pool of a huge initial size
      * to process quickly a large number of geo lines
      */
 
-    if (!(pool = ngx_create_pool(512 * 1024, cf->log))) {
+    pool = ngx_create_pool(512 * 1024, cf->log);
+    if (pool == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -212,7 +225,12 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command
 
     if (n == NGX_ERROR) {
         for (i = 0; i < geo->values.nelts; i++) {
-            if (ngx_strcmp(value[1].data, v[i]->text.data) == 0) {
+            if (v[i]->text.len != value[1].len) {
+                continue;
+            }
+
+            if (ngx_strncmp(value[1].data, v[i]->text.data, value[1].len) == 0)
+            {
                 var = v[i];
                 break;
             }
@@ -227,20 +245,22 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command
         }
     }
 
-    if (i == geo->values.nelts) {
+    if (var == NULL) {
         var = ngx_palloc(geo->pool, sizeof(ngx_http_variable_value_t));
         if (var == NULL) {
             return NGX_CONF_ERROR;
         }
 
         var->text.len = value[1].len;
-        if (!(var->text.data = ngx_pstrdup(geo->pool, &value[1]))) {
+        var->text.data = ngx_pstrdup(geo->pool, &value[1]);
+        if (var->text.data == NULL) {
             return NGX_CONF_ERROR;
         }
 
         var->value = (n == NGX_ERROR) ? 0 : n;
 
-        if (!(v = ngx_array_push(&geo->values))) {
+        v = ngx_array_push(&geo->values);
+        if (v == NULL) {
             return NGX_CONF_ERROR;
         }