diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2007-06-11 19:49:22 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2007-06-11 19:49:22 +0000 |
| commit | 9d8a75c5256ada429fdeff93584044eca6cf1a56 (patch) | |
| tree | 98226bea23d49242292bd5ee4ec0c969d07099b6 /src/http/ngx_http.c | |
| parent | ad39e5c7464bebda27c1ccb85fa4872265a399d0 (diff) | |
| download | nginx-9d8a75c5256ada429fdeff93584044eca6cf1a56.tar.gz nginx-9d8a75c5256ada429fdeff93584044eca6cf1a56.tar.bz2 | |
the "www.example.*" wildcard hash support
Diffstat (limited to 'src/http/ngx_http.c')
| -rw-r--r-- | src/http/ngx_http.c | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c index c6bc6c581..5823a2b91 100644 --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -73,7 +73,6 @@ static char * 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 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } 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; - } + for (s = 0; s < in_addr[a].names.nelts; s++) { 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 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } } - if (ha.dns_wildcards.nelts) { + if (ha.dns_wc_head.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_wc_head.elts, + ha.dns_wc_head.nelts) + != NGX_OK) + { + ngx_destroy_pool(ha.temp_pool); + return NGX_CONF_ERROR; + } + + in_addr[a].wc_head = (ngx_hash_wildcard_t *) hash.hash; + } + + if (ha.dns_wc_tail.nelts) { - ngx_qsort(ha.dns_wildcards.elts, - (size_t) ha.dns_wildcards.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_wildcards.elts, - ha.dns_wildcards.nelts) + 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].dns_wildcards = (ngx_hash_wildcard_t *) hash.hash; + in_addr[a].wc_tail = (ngx_hash_wildcard_t *) hash.hash; } ngx_destroy_pool(ha.temp_pool); @@ -848,8 +848,10 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 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 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 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 @@ ngx_http_add_address(ngx_conf_t *cf, ngx_http_conf_in_port_t *in_port, 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; |
