comparison src/http/ngx_http_variables.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 dd1570b6f237
children 83cd1910329c
comparison
equal deleted inserted replaced
3640:6a767188e365 3641:6802ba529ec4
1971 1971
1972 cmcf->variables_keys = NULL; 1972 cmcf->variables_keys = NULL;
1973 1973
1974 return NGX_OK; 1974 return NGX_OK;
1975 } 1975 }
1976
1977
1978 void
1979 ngx_http_variable_value_rbtree_insert(ngx_rbtree_node_t *temp,
1980 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
1981 {
1982 ngx_rbtree_node_t **p;
1983 ngx_http_variable_value_node_t *vvn, *vvt;
1984
1985 for ( ;; ) {
1986
1987 vvn = (ngx_http_variable_value_node_t *) node;
1988 vvt = (ngx_http_variable_value_node_t *) temp;
1989
1990 if (node->key != temp->key) {
1991
1992 p = (node->key < temp->key) ? &temp->left : &temp->right;
1993
1994 } else if (vvn->len != vvt->len) {
1995
1996 p = (vvn->len < vvt->len) ? &temp->left : &temp->right;
1997
1998 } else {
1999 p = (ngx_memcmp(vvn->value->data, vvt->value->data, vvn->len) < 0)
2000 ? &temp->left : &temp->right;
2001 }
2002
2003 if (*p == sentinel) {
2004 break;
2005 }
2006
2007 temp = *p;
2008 }
2009
2010 *p = node;
2011 node->parent = temp;
2012 node->left = sentinel;
2013 node->right = sentinel;
2014 ngx_rbt_red(node);
2015 }
2016
2017
2018 ngx_http_variable_value_t *
2019 ngx_http_variable_value_lookup(ngx_rbtree_t *rbtree, ngx_str_t *val,
2020 uint32_t hash)
2021 {
2022 ngx_int_t rc;
2023 ngx_rbtree_node_t *node, *sentinel;
2024 ngx_http_variable_value_node_t *vvn;
2025
2026 node = rbtree->root;
2027 sentinel = rbtree->sentinel;
2028
2029 while (node != sentinel) {
2030
2031 vvn = (ngx_http_variable_value_node_t *) node;
2032
2033 if (hash != node->key) {
2034 node = (hash < node->key) ? node->left : node->right;
2035 continue;
2036 }
2037
2038 if (val->len != vvn->len) {
2039 node = (val->len < vvn->len) ? node->left : node->right;
2040 continue;
2041 }
2042
2043 rc = ngx_memcmp(val->data, vvn->value->data, val->len);
2044
2045 if (rc < 0) {
2046 node = node->left;
2047 continue;
2048 }
2049
2050 if (rc > 0) {
2051 node = node->right;
2052 continue;
2053 }
2054
2055 return vvn->value;
2056 }
2057
2058 return NULL;
2059 }