Klaus Demo nginx / 9857082
variable value rbtree support Igor Sysoev 13 years ago
2 changed file(s) with 97 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
16321632
16331633 return NGX_OK;
16341634 }
1635
1636
1637 void
1638 ngx_http_variable_value_rbtree_insert(ngx_rbtree_node_t *temp,
1639 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
1640 {
1641 ngx_rbtree_node_t **p;
1642 ngx_http_variable_value_node_t *vvn, *vvt;
1643
1644 for ( ;; ) {
1645
1646 vvn = (ngx_http_variable_value_node_t *) node;
1647 vvt = (ngx_http_variable_value_node_t *) temp;
1648
1649 if (node->key != temp->key) {
1650
1651 p = (node->key < temp->key) ? &temp->left : &temp->right;
1652
1653 } else if (vvn->len != vvt->len) {
1654
1655 p = (vvn->len < vvt->len) ? &temp->left : &temp->right;
1656
1657 } else {
1658 p = (ngx_memcmp(vvn->value->data, vvt->value->data, vvn->len) < 0)
1659 ? &temp->left : &temp->right;
1660 }
1661
1662 if (*p == sentinel) {
1663 break;
1664 }
1665
1666 temp = *p;
1667 }
1668
1669 *p = node;
1670 node->parent = temp;
1671 node->left = sentinel;
1672 node->right = sentinel;
1673 ngx_rbt_red(node);
1674 }
1675
1676
1677 ngx_http_variable_value_t *
1678 ngx_http_variable_value_lookup(ngx_rbtree_t *rbtree, ngx_str_t *val,
1679 uint32_t hash)
1680 {
1681 ngx_int_t rc;
1682 ngx_rbtree_node_t *node, *sentinel;
1683 ngx_http_variable_value_node_t *vvn;
1684
1685 node = rbtree->root;
1686 sentinel = rbtree->sentinel;
1687
1688 while (node != sentinel) {
1689
1690 vvn = (ngx_http_variable_value_node_t *) node;
1691
1692 if (hash != node->key) {
1693 node = (hash < node->key) ? node->left : node->right;
1694 continue;
1695 }
1696
1697 if (val->len != vvn->len) {
1698 node = (val->len < vvn->len) ? node->left : node->right;
1699 continue;
1700 }
1701
1702 rc = ngx_memcmp(val->data, vvn->value->data, val->len);
1703
1704 if (rc < 0) {
1705 node = node->left;
1706 continue;
1707 }
1708
1709 if (rc > 0) {
1710 node = node->right;
1711 continue;
1712 }
1713
1714 return vvn->value;
1715 }
1716
1717 return NULL;
1718 }
6262 ngx_int_t ngx_http_variables_init_vars(ngx_conf_t *cf);
6363
6464
65 typedef struct {
66 ngx_rbtree_node_t node;
67 size_t len;
68 ngx_http_variable_value_t *value;
69 } ngx_http_variable_value_node_t;
70
71
72 void ngx_http_variable_value_rbtree_insert(ngx_rbtree_node_t *temp,
73 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
74 ngx_http_variable_value_t *ngx_http_variable_value_lookup(ngx_rbtree_t *rbtree,
75 ngx_str_t *name, uint32_t hash);
76
77
6578 extern ngx_http_variable_value_t ngx_http_variable_null_value;
6679 extern ngx_http_variable_value_t ngx_http_variable_true_value;
6780