diff options
Diffstat (limited to 'src/http')
| -rw-r--r-- | src/http/modules/ngx_http_geo_module.c | 36 | ||||
| -rw-r--r-- | src/http/ngx_http_variables.c | 84 | ||||
| -rw-r--r-- | src/http/ngx_http_variables.h | 13 |
3 files changed, 22 insertions, 111 deletions
diff --git a/src/http/modules/ngx_http_geo_module.c b/src/http/modules/ngx_http_geo_module.c index a184a7ae3..913a1d919 100644 --- a/src/http/modules/ngx_http_geo_module.c +++ b/src/http/modules/ngx_http_geo_module.c @@ -29,6 +29,12 @@ typedef struct { typedef struct { + ngx_str_node_t sn; + ngx_http_variable_value_t *value; +} ngx_http_geo_variable_value_node_t; + + +typedef struct { ngx_http_variable_value_t *value; ngx_str_t *net; ngx_http_geo_high_ranges_t *high; @@ -307,8 +313,7 @@ ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_ERROR; } - ngx_rbtree_init(&ctx.rbtree, &ctx.sentinel, - ngx_http_variable_value_rbtree_insert); + ngx_rbtree_init(&ctx.rbtree, &ctx.sentinel, ngx_str_rbtree_insert_value); ctx.high = NULL; ctx.tree = NULL; @@ -929,16 +934,17 @@ static ngx_http_variable_value_t * ngx_http_geo_value(ngx_conf_t *cf, ngx_http_geo_conf_ctx_t *ctx, ngx_str_t *value) { - uint32_t hash; - ngx_http_variable_value_t *val; - ngx_http_variable_value_node_t *vvn; + uint32_t hash; + ngx_http_variable_value_t *val; + ngx_http_geo_variable_value_node_t *gvvn; hash = ngx_crc32_long(value->data, value->len); - val = ngx_http_variable_value_lookup(&ctx->rbtree, value, hash); + gvvn = (ngx_http_geo_variable_value_node_t *) + ngx_str_rbtree_lookup(&ctx->rbtree, value, hash); - if (val) { - return val; + if (gvvn) { + return gvvn->value; } val = ngx_palloc(ctx->pool, sizeof(ngx_http_variable_value_t)); @@ -956,16 +962,18 @@ ngx_http_geo_value(ngx_conf_t *cf, ngx_http_geo_conf_ctx_t *ctx, val->no_cacheable = 0; val->not_found = 0; - vvn = ngx_palloc(ctx->temp_pool, sizeof(ngx_http_variable_value_node_t)); - if (vvn == NULL) { + gvvn = ngx_palloc(ctx->temp_pool, + sizeof(ngx_http_geo_variable_value_node_t)); + if (gvvn == NULL) { return NULL; } - vvn->node.key = hash; - vvn->len = val->len; - vvn->value = val; + gvvn->sn.node.key = hash; + gvvn->sn.str.len = val->len; + gvvn->sn.str.data = val->data; + gvvn->value = val; - ngx_rbtree_insert(&ctx->rbtree, &vvn->node); + ngx_rbtree_insert(&ctx->rbtree, &gvvn->sn.node); return val; } diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c index 0bba28128..00d9d5eb4 100644 --- a/src/http/ngx_http_variables.c +++ b/src/http/ngx_http_variables.c @@ -1973,87 +1973,3 @@ ngx_http_variables_init_vars(ngx_conf_t *cf) return NGX_OK; } - - -void -ngx_http_variable_value_rbtree_insert(ngx_rbtree_node_t *temp, - ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel) -{ - ngx_rbtree_node_t **p; - ngx_http_variable_value_node_t *vvn, *vvt; - - for ( ;; ) { - - vvn = (ngx_http_variable_value_node_t *) node; - vvt = (ngx_http_variable_value_node_t *) temp; - - if (node->key != temp->key) { - - p = (node->key < temp->key) ? &temp->left : &temp->right; - - } else if (vvn->len != vvt->len) { - - p = (vvn->len < vvt->len) ? &temp->left : &temp->right; - - } else { - p = (ngx_memcmp(vvn->value->data, vvt->value->data, vvn->len) < 0) - ? &temp->left : &temp->right; - } - - if (*p == sentinel) { - break; - } - - temp = *p; - } - - *p = node; - node->parent = temp; - node->left = sentinel; - node->right = sentinel; - ngx_rbt_red(node); -} - - -ngx_http_variable_value_t * -ngx_http_variable_value_lookup(ngx_rbtree_t *rbtree, ngx_str_t *val, - uint32_t hash) -{ - ngx_int_t rc; - ngx_rbtree_node_t *node, *sentinel; - ngx_http_variable_value_node_t *vvn; - - node = rbtree->root; - sentinel = rbtree->sentinel; - - while (node != sentinel) { - - vvn = (ngx_http_variable_value_node_t *) node; - - if (hash != node->key) { - node = (hash < node->key) ? node->left : node->right; - continue; - } - - if (val->len != vvn->len) { - node = (val->len < vvn->len) ? node->left : node->right; - continue; - } - - rc = ngx_memcmp(val->data, vvn->value->data, val->len); - - if (rc < 0) { - node = node->left; - continue; - } - - if (rc > 0) { - node = node->right; - continue; - } - - return vvn->value; - } - - return NULL; -} diff --git a/src/http/ngx_http_variables.h b/src/http/ngx_http_variables.h index 9d4b29e08..588f5caf5 100644 --- a/src/http/ngx_http_variables.h +++ b/src/http/ngx_http_variables.h @@ -88,19 +88,6 @@ ngx_int_t ngx_http_variables_add_core_vars(ngx_conf_t *cf); ngx_int_t ngx_http_variables_init_vars(ngx_conf_t *cf); -typedef struct { - ngx_rbtree_node_t node; - size_t len; - ngx_http_variable_value_t *value; -} ngx_http_variable_value_node_t; - - -void ngx_http_variable_value_rbtree_insert(ngx_rbtree_node_t *temp, - ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel); -ngx_http_variable_value_t *ngx_http_variable_value_lookup(ngx_rbtree_t *rbtree, - ngx_str_t *name, uint32_t hash); - - extern ngx_http_variable_value_t ngx_http_variable_null_value; extern ngx_http_variable_value_t ngx_http_variable_true_value; |
