comparison src/http/modules/ngx_http_geo_module.c @ 38:2879cd3a40cb NGINX_0_1_19

nginx 0.1.19 *) Bugfix: now, if request contains the zero, then the 404 error is returned for the local requests. *) Bugfix: nginx could not be built on NetBSD 2.0. *) Bugfix: the timeout may occur while reading of the the client request body via SSL connections.
author Igor Sysoev <http://sysoev.ru>
date Wed, 16 Feb 2005 00:00:00 +0300
parents a39d1b793287
children 72eb30262aac
comparison
equal deleted inserted replaced
37:3376a7dea5d6 38:2879cd3a40cb
8 #include <ngx_core.h> 8 #include <ngx_core.h>
9 #include <ngx_http.h> 9 #include <ngx_http.h>
10 10
11 11
12 typedef struct { 12 typedef struct {
13 ngx_radix_tree_t *tree; 13 ngx_radix_tree_t *tree;
14 ngx_pool_t *pool; 14 ngx_pool_t *pool;
15 ngx_array_t values; 15 ngx_array_t values;
16 } ngx_http_geo_conf_t; 16 } ngx_http_geo_conf_t;
17 17
18 18
19 static char *ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 19 static char *ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
20 static char *ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf); 20 static char *ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf);
61 { 0, ngx_string("0") }; 61 { 0, ngx_string("0") };
62 62
63 63
64 /* AF_INET only */ 64 /* AF_INET only */
65 65
66 static ngx_http_variable_value_t *ngx_http_geo_variable(ngx_http_request_t *r, 66 static ngx_http_variable_value_t *
67 void *data) 67 ngx_http_geo_variable(ngx_http_request_t *r, void *data)
68 { 68 {
69 ngx_radix_tree_t *tree = data; 69 ngx_radix_tree_t *tree = data;
70 70
71 struct sockaddr_in *sin; 71 struct sockaddr_in *sin;
72 ngx_http_variable_value_t *var;
72 73
73 sin = (struct sockaddr_in *) r->connection->sockaddr; 74 sin = (struct sockaddr_in *) r->connection->sockaddr;
74 75
75 return (ngx_http_variable_value_t *) 76 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
77 "http geo started");
78
79 var = (ngx_http_variable_value_t *)
76 ngx_radix32tree_find(tree, ntohl(sin->sin_addr.s_addr)); 80 ngx_radix32tree_find(tree, ntohl(sin->sin_addr.s_addr));
81
82 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
83 "http geo: %V %V", &r->connection->addr_text, &var->text);
84
85 return var;
77 } 86 }
78 87
79 88
80 static char *ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 89 static char *
90 ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
81 { 91 {
82 char *rv; 92 char *rv;
83 ngx_str_t *value; 93 ngx_str_t *value;
84 ngx_conf_t save; 94 ngx_conf_t save;
85 ngx_pool_t *pool; 95 ngx_pool_t *pool;
89 99
90 if (!(var = ngx_http_add_variable(cf))) { 100 if (!(var = ngx_http_add_variable(cf))) {
91 return NGX_CONF_ERROR; 101 return NGX_CONF_ERROR;
92 } 102 }
93 103
94 if (!(tree = ngx_radix_tree_create(cf->pool, 8))) { 104 if (!(tree = ngx_radix_tree_create(cf->pool, -1))) {
95 return NGX_CONF_ERROR; 105 return NGX_CONF_ERROR;
96 } 106 }
97 107
98 value = cf->args->elts; 108 value = cf->args->elts;
99 109
146 } 156 }
147 157
148 158
149 /* AF_INET only */ 159 /* AF_INET only */
150 160
151 static char *ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) 161 static char *
162 ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
152 { 163 {
153 ngx_int_t rc, n; 164 ngx_int_t rc, n;
154 ngx_uint_t i; 165 ngx_uint_t i;
155 ngx_str_t *value, file; 166 ngx_str_t *value, file;
156 ngx_inet_cidr_t cidrin; 167 ngx_inet_cidr_t cidrin;