Mercurial > hg > nginx
comparison src/http/modules/ngx_http_geo_module.c @ 501:d4ea69372b94 release-0.1.25
nginx-0.1.25-RELEASE import
*) 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 <igor@sysoev.ru> |
---|---|
date | Sat, 19 Mar 2005 12:38:37 +0000 |
parents | 45a460f82aec |
children | 9b8c906f6e63 |
comparison
equal
deleted
inserted
replaced
500:9a0f304470f5 | 501:d4ea69372b94 |
---|---|
62 | 62 |
63 | 63 |
64 /* AF_INET only */ | 64 /* AF_INET only */ |
65 | 65 |
66 static ngx_http_variable_value_t * | 66 static ngx_http_variable_value_t * |
67 ngx_http_geo_variable(ngx_http_request_t *r, void *data) | 67 ngx_http_geo_variable(ngx_http_request_t *r, uintptr_t data) |
68 { | 68 { |
69 ngx_radix_tree_t *tree = data; | 69 ngx_radix_tree_t *tree = (ngx_radix_tree_t *) data; |
70 | 70 |
71 struct sockaddr_in *sin; | 71 struct sockaddr_in *sin; |
72 ngx_http_variable_value_t *var; | 72 ngx_http_variable_value_t *var; |
73 | 73 |
74 sin = (struct sockaddr_in *) r->connection->sockaddr; | 74 sin = (struct sockaddr_in *) r->connection->sockaddr; |
88 | 88 |
89 static char * | 89 static char * |
90 ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 90 ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
91 { | 91 { |
92 char *rv; | 92 char *rv; |
93 ngx_str_t *value; | 93 ngx_str_t *value, name; |
94 ngx_conf_t save; | 94 ngx_conf_t save; |
95 ngx_pool_t *pool; | 95 ngx_pool_t *pool; |
96 ngx_radix_tree_t *tree; | 96 ngx_radix_tree_t *tree; |
97 ngx_http_geo_conf_t geo; | 97 ngx_http_geo_conf_t geo; |
98 ngx_http_variable_t *var; | 98 ngx_http_variable_t *var; |
99 | 99 |
100 if (!(var = ngx_http_add_variable(cf))) { | |
101 return NGX_CONF_ERROR; | |
102 } | |
103 | |
104 if (!(tree = ngx_radix_tree_create(cf->pool, -1))) { | |
105 return NGX_CONF_ERROR; | |
106 } | |
107 | |
108 value = cf->args->elts; | 100 value = cf->args->elts; |
109 | 101 |
110 var->name = value[1]; | 102 name = value[1]; |
103 | |
104 if (name.data[0] != '$') { | |
105 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
106 "\"%V\" variable name should start with '$'", | |
107 &value[1]); | |
108 } else { | |
109 name.len--; | |
110 name.data++; | |
111 } | |
112 | |
113 var = ngx_http_add_variable(cf, &name, 1); | |
114 if (var == NULL) { | |
115 return NGX_CONF_ERROR; | |
116 } | |
117 | |
118 tree = ngx_radix_tree_create(cf->pool, -1); | |
119 if (tree == NULL) { | |
120 return NGX_CONF_ERROR; | |
121 } | |
122 | |
111 var->handler = ngx_http_geo_variable; | 123 var->handler = ngx_http_geo_variable; |
112 var->data = tree; | 124 var->data = (uintptr_t) tree; |
113 | 125 |
114 /* | 126 /* |
115 * create the temporary pool of a huge initial size | 127 * create the temporary pool of a huge initial size |
116 * to process quickly a large number of geo lines | 128 * to process quickly a large number of geo lines |
117 */ | 129 */ |
118 | 130 |
119 if (!(pool = ngx_create_pool(512 * 1024, cf->log))) { | 131 pool = ngx_create_pool(512 * 1024, cf->log); |
132 if (pool == NULL) { | |
120 return NGX_CONF_ERROR; | 133 return NGX_CONF_ERROR; |
121 } | 134 } |
122 | 135 |
123 if (ngx_array_init(&geo.values, pool, 512, | 136 if (ngx_array_init(&geo.values, pool, 512, |
124 sizeof(ngx_http_variable_value_t *)) == NGX_ERROR) | 137 sizeof(ngx_http_variable_value_t *)) == NGX_ERROR) |
210 var = NULL; | 223 var = NULL; |
211 v = geo->values.elts; | 224 v = geo->values.elts; |
212 | 225 |
213 if (n == NGX_ERROR) { | 226 if (n == NGX_ERROR) { |
214 for (i = 0; i < geo->values.nelts; i++) { | 227 for (i = 0; i < geo->values.nelts; i++) { |
215 if (ngx_strcmp(value[1].data, v[i]->text.data) == 0) { | 228 if (v[i]->text.len != value[1].len) { |
229 continue; | |
230 } | |
231 | |
232 if (ngx_strncmp(value[1].data, v[i]->text.data, value[1].len) == 0) | |
233 { | |
216 var = v[i]; | 234 var = v[i]; |
217 break; | 235 break; |
218 } | 236 } |
219 } | 237 } |
220 | 238 |
225 break; | 243 break; |
226 } | 244 } |
227 } | 245 } |
228 } | 246 } |
229 | 247 |
230 if (i == geo->values.nelts) { | 248 if (var == NULL) { |
231 var = ngx_palloc(geo->pool, sizeof(ngx_http_variable_value_t)); | 249 var = ngx_palloc(geo->pool, sizeof(ngx_http_variable_value_t)); |
232 if (var == NULL) { | 250 if (var == NULL) { |
233 return NGX_CONF_ERROR; | 251 return NGX_CONF_ERROR; |
234 } | 252 } |
235 | 253 |
236 var->text.len = value[1].len; | 254 var->text.len = value[1].len; |
237 if (!(var->text.data = ngx_pstrdup(geo->pool, &value[1]))) { | 255 var->text.data = ngx_pstrdup(geo->pool, &value[1]); |
256 if (var->text.data == NULL) { | |
238 return NGX_CONF_ERROR; | 257 return NGX_CONF_ERROR; |
239 } | 258 } |
240 | 259 |
241 var->value = (n == NGX_ERROR) ? 0 : n; | 260 var->value = (n == NGX_ERROR) ? 0 : n; |
242 | 261 |
243 if (!(v = ngx_array_push(&geo->values))) { | 262 v = ngx_array_push(&geo->values); |
263 if (v == NULL) { | |
244 return NGX_CONF_ERROR; | 264 return NGX_CONF_ERROR; |
245 } | 265 } |
246 | 266 |
247 *v = var; | 267 *v = var; |
248 } | 268 } |