comparison src/http/modules/ngx_http_geo_module.c @ 3641:6802ba529ec4

change ngx_http_variable_value_node_t to more generic ngx_str_node_t
author Igor Sysoev <igor@sysoev.ru>
date Wed, 23 Jun 2010 15:31:33 +0000
parents 91cff7f97a50
children ac33852faaac
comparison
equal deleted inserted replaced
3640:6a767188e365 3641:6802ba529ec4
24 24
25 typedef struct { 25 typedef struct {
26 ngx_http_geo_low_ranges_t low[0x10000]; 26 ngx_http_geo_low_ranges_t low[0x10000];
27 ngx_http_variable_value_t *default_value; 27 ngx_http_variable_value_t *default_value;
28 } ngx_http_geo_high_ranges_t; 28 } ngx_http_geo_high_ranges_t;
29
30
31 typedef struct {
32 ngx_str_node_t sn;
33 ngx_http_variable_value_t *value;
34 } ngx_http_geo_variable_value_node_t;
29 35
30 36
31 typedef struct { 37 typedef struct {
32 ngx_http_variable_value_t *value; 38 ngx_http_variable_value_t *value;
33 ngx_str_t *net; 39 ngx_str_t *net;
305 ctx.temp_pool = ngx_create_pool(16384, cf->log); 311 ctx.temp_pool = ngx_create_pool(16384, cf->log);
306 if (ctx.temp_pool == NULL) { 312 if (ctx.temp_pool == NULL) {
307 return NGX_CONF_ERROR; 313 return NGX_CONF_ERROR;
308 } 314 }
309 315
310 ngx_rbtree_init(&ctx.rbtree, &ctx.sentinel, 316 ngx_rbtree_init(&ctx.rbtree, &ctx.sentinel, ngx_str_rbtree_insert_value);
311 ngx_http_variable_value_rbtree_insert);
312 317
313 ctx.high = NULL; 318 ctx.high = NULL;
314 ctx.tree = NULL; 319 ctx.tree = NULL;
315 ctx.proxies = NULL; 320 ctx.proxies = NULL;
316 ctx.pool = cf->pool; 321 ctx.pool = cf->pool;
927 932
928 static ngx_http_variable_value_t * 933 static ngx_http_variable_value_t *
929 ngx_http_geo_value(ngx_conf_t *cf, ngx_http_geo_conf_ctx_t *ctx, 934 ngx_http_geo_value(ngx_conf_t *cf, ngx_http_geo_conf_ctx_t *ctx,
930 ngx_str_t *value) 935 ngx_str_t *value)
931 { 936 {
932 uint32_t hash; 937 uint32_t hash;
933 ngx_http_variable_value_t *val; 938 ngx_http_variable_value_t *val;
934 ngx_http_variable_value_node_t *vvn; 939 ngx_http_geo_variable_value_node_t *gvvn;
935 940
936 hash = ngx_crc32_long(value->data, value->len); 941 hash = ngx_crc32_long(value->data, value->len);
937 942
938 val = ngx_http_variable_value_lookup(&ctx->rbtree, value, hash); 943 gvvn = (ngx_http_geo_variable_value_node_t *)
939 944 ngx_str_rbtree_lookup(&ctx->rbtree, value, hash);
940 if (val) { 945
941 return val; 946 if (gvvn) {
947 return gvvn->value;
942 } 948 }
943 949
944 val = ngx_palloc(ctx->pool, sizeof(ngx_http_variable_value_t)); 950 val = ngx_palloc(ctx->pool, sizeof(ngx_http_variable_value_t));
945 if (val == NULL) { 951 if (val == NULL) {
946 return NULL; 952 return NULL;
954 960
955 val->valid = 1; 961 val->valid = 1;
956 val->no_cacheable = 0; 962 val->no_cacheable = 0;
957 val->not_found = 0; 963 val->not_found = 0;
958 964
959 vvn = ngx_palloc(ctx->temp_pool, sizeof(ngx_http_variable_value_node_t)); 965 gvvn = ngx_palloc(ctx->temp_pool,
960 if (vvn == NULL) { 966 sizeof(ngx_http_geo_variable_value_node_t));
967 if (gvvn == NULL) {
961 return NULL; 968 return NULL;
962 } 969 }
963 970
964 vvn->node.key = hash; 971 gvvn->sn.node.key = hash;
965 vvn->len = val->len; 972 gvvn->sn.str.len = val->len;
966 vvn->value = val; 973 gvvn->sn.str.data = val->data;
967 974 gvvn->value = val;
968 ngx_rbtree_insert(&ctx->rbtree, &vvn->node); 975
976 ngx_rbtree_insert(&ctx->rbtree, &gvvn->sn.node);
969 977
970 return val; 978 return val;
971 } 979 }
972 980
973 981