Mercurial > hg > nginx
diff src/http/ngx_http.c @ 1253:8ef04207c84f
the "www.example.*" wildcard hash support
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 11 Jun 2007 19:49:22 +0000 |
parents | 5e4d3b5d7ad0 |
children | 7443fbe0b013 |
line wrap: on
line diff
--- a/src/http/ngx_http.c Mon Jun 11 19:32:29 2007 +0000 +++ b/src/http/ngx_http.c Mon Jun 11 19:49:22 2007 +0000 @@ -73,7 +73,6 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { char *rv; - u_char ch; ngx_int_t rc, j; ngx_uint_t mi, m, s, l, p, a, i, n; ngx_uint_t find_config_index, use_rewrite, use_access; @@ -648,40 +647,20 @@ } name = in_addr[a].names.elts; + for (s = 0; s < in_addr[a].names.nelts; s++) { - ch = name[s].name.data[0]; - - if (ch == '*' || ch == '.') { - continue; - } - rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf, - 0); + NGX_HASH_WILDCARD_KEY); if (rc == NGX_ERROR) { return NGX_CONF_ERROR; } - if (rc == NGX_BUSY) { - ngx_log_error(NGX_LOG_WARN, cf->log, 0, - "conflicting server name \"%V\" on %s, ignored", + if (rc == NGX_DECLINED) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "invalid server name or wildcard \"%V\" on %s", &name[s].name, in_addr[a].listen_conf->addr); - } - } - - for (s = 0; s < in_addr[a].names.nelts; s++) { - - ch = name[s].name.data[0]; - - if (ch != '*' && ch != '.') { - continue; - } - - rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf, - NGX_HASH_WILDCARD_KEY); - - if (rc == NGX_ERROR) { return NGX_CONF_ERROR; } @@ -709,25 +688,46 @@ } } - if (ha.dns_wildcards.nelts) { + if (ha.dns_wc_head.nelts) { - ngx_qsort(ha.dns_wildcards.elts, - (size_t) ha.dns_wildcards.nelts, + ngx_qsort(ha.dns_wc_head.elts, + (size_t) ha.dns_wc_head.nelts, sizeof(ngx_hash_key_t), ngx_http_cmp_dns_wildcards); hash.hash = NULL; hash.temp_pool = ha.temp_pool; - if (ngx_hash_wildcard_init(&hash, ha.dns_wildcards.elts, - ha.dns_wildcards.nelts) + if (ngx_hash_wildcard_init(&hash, ha.dns_wc_head.elts, + ha.dns_wc_head.nelts) != NGX_OK) { ngx_destroy_pool(ha.temp_pool); return NGX_CONF_ERROR; } - in_addr[a].dns_wildcards = (ngx_hash_wildcard_t *) hash.hash; + in_addr[a].wc_head = (ngx_hash_wildcard_t *) hash.hash; + } + + if (ha.dns_wc_tail.nelts) { + + ngx_qsort(ha.dns_wc_tail.elts, + (size_t) ha.dns_wc_tail.nelts, + sizeof(ngx_hash_key_t), + ngx_http_cmp_dns_wildcards); + + hash.hash = NULL; + hash.temp_pool = ha.temp_pool; + + if (ngx_hash_wildcard_init(&hash, ha.dns_wc_tail.elts, + ha.dns_wc_tail.nelts) + != NGX_OK) + { + ngx_destroy_pool(ha.temp_pool); + return NGX_CONF_ERROR; + } + + in_addr[a].wc_tail = (ngx_hash_wildcard_t *) hash.hash; } ngx_destroy_pool(ha.temp_pool); @@ -848,8 +848,10 @@ hip->addrs[i].core_srv_conf = in_addr[i].core_srv_conf; if (in_addr[i].hash.buckets == NULL - && (in_addr[i].dns_wildcards == NULL - || in_addr[i].dns_wildcards->hash.buckets == NULL)) + && (in_addr[i].wc_head == NULL + || in_addr[i].wc_head->hash.buckets == NULL) + && (in_addr[i].wc_head == NULL + || in_addr[i].wc_head->hash.buckets == NULL)) { continue; } @@ -861,7 +863,8 @@ hip->addrs[i].virtual_names = vn; vn->hash = in_addr[i].hash; - vn->dns_wildcards = in_addr[i].dns_wildcards; + vn->wc_head = in_addr[i].wc_head; + vn->wc_tail = in_addr[i].wc_tail; } if (done) { @@ -934,7 +937,8 @@ in_addr->addr = lscf->addr; in_addr->hash.buckets = NULL; in_addr->hash.size = 0; - in_addr->dns_wildcards = NULL; + in_addr->wc_head = NULL; + in_addr->wc_tail = NULL; in_addr->names.elts = NULL; in_addr->core_srv_conf = cscf; in_addr->default_server = lscf->conf.default_server;