comparison src/http/ngx_http_variables.c @ 635:e67b227c8dbb default tip

Merge with current.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 25 Apr 2011 04:07:55 +0400
parents 8214eaef3530
children
comparison
equal deleted inserted replaced
578:f3a9e57d2e17 635:e67b227c8dbb
439 return ngx_http_get_indexed_variable(r, index); 439 return ngx_http_get_indexed_variable(r, index);
440 } 440 }
441 441
442 442
443 ngx_http_variable_value_t * 443 ngx_http_variable_value_t *
444 ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name, ngx_uint_t key, 444 ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name, ngx_uint_t key)
445 ngx_uint_t nowarn)
446 { 445 {
447 ngx_http_variable_t *v; 446 ngx_http_variable_t *v;
448 ngx_http_variable_value_t *vv; 447 ngx_http_variable_value_t *vv;
449 ngx_http_core_main_conf_t *cmcf; 448 ngx_http_core_main_conf_t *cmcf;
450 449
452 451
453 v = ngx_hash_find(&cmcf->variables_hash, key, name->data, name->len); 452 v = ngx_hash_find(&cmcf->variables_hash, key, name->data, name->len);
454 453
455 if (v) { 454 if (v) {
456 if (v->flags & NGX_HTTP_VAR_INDEXED) { 455 if (v->flags & NGX_HTTP_VAR_INDEXED) {
457 return ngx_http_get_indexed_variable(r, v->index); 456 return ngx_http_get_flushed_variable(r, v->index);
458 457
459 } else { 458 } else {
460 459
461 vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)); 460 vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
462 461
523 522
524 return NULL; 523 return NULL;
525 } 524 }
526 525
527 vv->not_found = 1; 526 vv->not_found = 1;
528
529 if (nowarn == 0) {
530 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
531 "unknown \"%V\" variable", name);
532 }
533 527
534 return vv; 528 return vv;
535 } 529 }
536 530
537 531
1394 v->data = r->headers_out.location->value.data; 1388 v->data = r->headers_out.location->value.data;
1395 1389
1396 return NGX_OK; 1390 return NGX_OK;
1397 } 1391 }
1398 1392
1399 name.len = sizeof("sent_http_location") - 1; 1393 ngx_str_set(&name, "sent_http_location");
1400 name.data = (u_char *) "sent_http_location";
1401 1394
1402 return ngx_http_variable_unknown_header(v, &name, 1395 return ngx_http_variable_unknown_header(v, &name,
1403 &r->headers_out.headers.part, 1396 &r->headers_out.headers.part,
1404 sizeof("sent_http_") - 1); 1397 sizeof("sent_http_") - 1);
1405 } 1398 }
1662 v->no_cacheable = 0; 1655 v->no_cacheable = 0;
1663 v->not_found = 0; 1656 v->not_found = 0;
1664 v->data = p; 1657 v->data = p;
1665 1658
1666 return NGX_OK; 1659 return NGX_OK;
1660 }
1661
1662
1663 void *
1664 ngx_http_map_find(ngx_http_request_t *r, ngx_http_map_t *map, ngx_uint_t key,
1665 u_char *text, size_t len, ngx_str_t *match)
1666 {
1667 void *p;
1668
1669 p = ngx_hash_find_combined(&map->hash, key, text, len);
1670 if (p) {
1671 return p;
1672 }
1673
1674 #if (NGX_PCRE)
1675
1676 if (len && map->nregex) {
1677 ngx_int_t n;
1678 ngx_uint_t i;
1679 ngx_http_map_regex_t *reg;
1680
1681 reg = map->regex;
1682
1683 for (i = 0; i < map->nregex; i++) {
1684
1685 n = ngx_http_regex_exec(r, reg[i].regex, match);
1686
1687 if (n == NGX_OK) {
1688 return reg[i].value;
1689 }
1690
1691 if (n == NGX_DECLINED) {
1692 continue;
1693 }
1694
1695 /* NGX_ERROR */
1696
1697 return NULL;
1698 }
1699 }
1700
1701 #endif
1702
1703 return NULL;
1667 } 1704 }
1668 1705
1669 1706
1670 #if (NGX_PCRE) 1707 #if (NGX_PCRE)
1671 1708
1935 } 1972 }
1936 1973
1937 if (ngx_strncmp(v[i].name.data, "arg_", 4) == 0) { 1974 if (ngx_strncmp(v[i].name.data, "arg_", 4) == 0) {
1938 v[i].get_handler = ngx_http_variable_argument; 1975 v[i].get_handler = ngx_http_variable_argument;
1939 v[i].data = (uintptr_t) &v[i].name; 1976 v[i].data = (uintptr_t) &v[i].name;
1977 v[i].flags = NGX_HTTP_VAR_NOCACHEABLE;
1940 1978
1941 continue; 1979 continue;
1942 } 1980 }
1943 1981
1944 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, 1982 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
1977 2015
1978 cmcf->variables_keys = NULL; 2016 cmcf->variables_keys = NULL;
1979 2017
1980 return NGX_OK; 2018 return NGX_OK;
1981 } 2019 }
1982
1983
1984 void
1985 ngx_http_variable_value_rbtree_insert(ngx_rbtree_node_t *temp,
1986 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
1987 {
1988 ngx_rbtree_node_t **p;
1989 ngx_http_variable_value_node_t *vvn, *vvt;
1990
1991 for ( ;; ) {
1992
1993 vvn = (ngx_http_variable_value_node_t *) node;
1994 vvt = (ngx_http_variable_value_node_t *) temp;
1995
1996 if (node->key != temp->key) {
1997
1998 p = (node->key < temp->key) ? &temp->left : &temp->right;
1999
2000 } else if (vvn->len != vvt->len) {
2001
2002 p = (vvn->len < vvt->len) ? &temp->left : &temp->right;
2003
2004 } else {
2005 p = (ngx_memcmp(vvn->value->data, vvt->value->data, vvn->len) < 0)
2006 ? &temp->left : &temp->right;
2007 }
2008
2009 if (*p == sentinel) {
2010 break;
2011 }
2012
2013 temp = *p;
2014 }
2015
2016 *p = node;
2017 node->parent = temp;
2018 node->left = sentinel;
2019 node->right = sentinel;
2020 ngx_rbt_red(node);
2021 }
2022
2023
2024 ngx_http_variable_value_t *
2025 ngx_http_variable_value_lookup(ngx_rbtree_t *rbtree, ngx_str_t *val,
2026 uint32_t hash)
2027 {
2028 ngx_int_t rc;
2029 ngx_rbtree_node_t *node, *sentinel;
2030 ngx_http_variable_value_node_t *vvn;
2031
2032 node = rbtree->root;
2033 sentinel = rbtree->sentinel;
2034
2035 while (node != sentinel) {
2036
2037 vvn = (ngx_http_variable_value_node_t *) node;
2038
2039 if (hash != node->key) {
2040 node = (hash < node->key) ? node->left : node->right;
2041 continue;
2042 }
2043
2044 if (val->len != vvn->len) {
2045 node = (val->len < vvn->len) ? node->left : node->right;
2046 continue;
2047 }
2048
2049 rc = ngx_memcmp(val->data, vvn->value->data, val->len);
2050
2051 if (rc < 0) {
2052 node = node->left;
2053 continue;
2054 }
2055
2056 if (rc > 0) {
2057 node = node->right;
2058 continue;
2059 }
2060
2061 return vvn->value;
2062 }
2063
2064 return NULL;
2065 }