Mercurial > hg > nginx
comparison src/http/modules/ngx_http_geo_module.c @ 5047:852f40088278 stable-1.2
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.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 11 Feb 2013 12:26:33 +0000 |
parents | 05beaa2d87b3 |
children | 2f0862333985 |
comparison
equal
deleted
inserted
replaced
5046:f4809ba58b15 | 5047:852f40088278 |
---|---|
187 ngx_uint_t n; | 187 ngx_uint_t n; |
188 ngx_http_geo_range_t *range; | 188 ngx_http_geo_range_t *range; |
189 | 189 |
190 *v = *ctx->u.high.default_value; | 190 *v = *ctx->u.high.default_value; |
191 | 191 |
192 addr = ngx_http_geo_addr(r, ctx); | 192 if (ctx->u.high.low) { |
193 | 193 addr = ngx_http_geo_addr(r, ctx); |
194 range = ctx->u.high.low[addr >> 16]; | 194 |
195 | 195 range = ctx->u.high.low[addr >> 16]; |
196 if (range) { | 196 |
197 n = addr & 0xffff; | 197 if (range) { |
198 do { | 198 n = addr & 0xffff; |
199 if (n >= (ngx_uint_t) range->start && n <= (ngx_uint_t) range->end) | 199 do { |
200 { | 200 if (n >= (ngx_uint_t) range->start |
201 *v = *range->value; | 201 && n <= (ngx_uint_t) range->end) |
202 break; | 202 { |
203 } | 203 *v = *range->value; |
204 } while ((++range)->value); | 204 break; |
205 } | |
206 } while ((++range)->value); | |
207 } | |
205 } | 208 } |
206 | 209 |
207 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 210 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
208 "http geo: %v", v); | 211 "http geo: %v", v); |
209 | 212 |
301 | 304 |
302 static char * | 305 static char * |
303 ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 306 ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
304 { | 307 { |
305 char *rv; | 308 char *rv; |
306 void **p; | |
307 size_t len; | 309 size_t len; |
308 ngx_str_t *value, name; | 310 ngx_str_t *value, name; |
309 ngx_uint_t i; | 311 ngx_uint_t i; |
310 ngx_conf_t save; | 312 ngx_conf_t save; |
311 ngx_pool_t *pool; | 313 ngx_pool_t *pool; |
390 *cf = save; | 392 *cf = save; |
391 | 393 |
392 geo->proxies = ctx.proxies; | 394 geo->proxies = ctx.proxies; |
393 geo->proxy_recursive = ctx.proxy_recursive; | 395 geo->proxy_recursive = ctx.proxy_recursive; |
394 | 396 |
395 if (ctx.high.low) { | 397 if (ctx.ranges) { |
396 | 398 |
397 if (!ctx.binary_include) { | 399 if (ctx.high.low && !ctx.binary_include) { |
398 for (i = 0; i < 0x10000; i++) { | 400 for (i = 0; i < 0x10000; i++) { |
399 a = (ngx_array_t *) ctx.high.low[i]; | 401 a = (ngx_array_t *) ctx.high.low[i]; |
400 | 402 |
401 if (a == NULL || a->nelts == 0) { | 403 if (a == NULL || a->nelts == 0) { |
402 continue; | 404 continue; |
407 ctx.high.low[i] = ngx_palloc(cf->pool, len + sizeof(void *)); | 409 ctx.high.low[i] = ngx_palloc(cf->pool, len + sizeof(void *)); |
408 if (ctx.high.low[i] == NULL) { | 410 if (ctx.high.low[i] == NULL) { |
409 return NGX_CONF_ERROR; | 411 return NGX_CONF_ERROR; |
410 } | 412 } |
411 | 413 |
412 p = (void **) ngx_cpymem(ctx.high.low[i], a->elts, len); | 414 ngx_memcpy(ctx.high.low[i], a->elts, len); |
413 *p = NULL; | 415 ctx.high.low[i][a->nelts].value = NULL; |
414 ctx.data_size += len + sizeof(void *); | 416 ctx.data_size += len + sizeof(void *); |
415 } | 417 } |
416 | 418 |
417 if (ctx.allow_binary_include | 419 if (ctx.allow_binary_include |
418 && !ctx.outside_entries | 420 && !ctx.outside_entries |
449 var->data = (uintptr_t) geo; | 451 var->data = (uintptr_t) geo; |
450 | 452 |
451 ngx_destroy_pool(ctx.temp_pool); | 453 ngx_destroy_pool(ctx.temp_pool); |
452 ngx_destroy_pool(pool); | 454 ngx_destroy_pool(pool); |
453 | 455 |
454 if (ngx_radix32tree_find(ctx.tree, 0) != NGX_RADIX_NO_VALUE) { | |
455 return rv; | |
456 } | |
457 | |
458 if (ngx_radix32tree_insert(ctx.tree, 0, 0, | 456 if (ngx_radix32tree_insert(ctx.tree, 0, 0, |
459 (uintptr_t) &ngx_http_variable_null_value) | 457 (uintptr_t) &ngx_http_variable_null_value) |
460 == NGX_ERROR) | 458 == NGX_ERROR) |
461 { | 459 { |
462 return NGX_CONF_ERROR; | 460 return NGX_CONF_ERROR; |
463 } | 461 } |
462 | |
463 /* NGX_BUSY is okay (default was set explicitly) */ | |
464 } | 464 } |
465 | 465 |
466 return rv; | 466 return rv; |
467 } | 467 } |
468 | 468 |
994 } | 994 } |
995 | 995 |
996 /* rc == NGX_BUSY */ | 996 /* rc == NGX_BUSY */ |
997 | 997 |
998 old = (ngx_http_variable_value_t *) | 998 old = (ngx_http_variable_value_t *) |
999 ngx_radix32tree_find(ctx->tree, cidr.u.in.addr & cidr.u.in.mask); | 999 ngx_radix32tree_find(ctx->tree, cidr.u.in.addr); |
1000 | 1000 |
1001 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | 1001 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
1002 "duplicate network \"%V\", value: \"%v\", old value: \"%v\"", | 1002 "duplicate network \"%V\", value: \"%v\", old value: \"%v\"", |
1003 net, val, old); | 1003 net, val, old); |
1004 | 1004 |