Mercurial > hg > nginx-quic
changeset 4969:2efa05bbbc1e
Simplified URL parsing code.
Except for the "listen" directive, "*" specified as a hostname is
no longer treated specially.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Mon, 17 Dec 2012 09:31:53 +0000 |
parents | 90d8c3400769 |
children | ed2219d58518 |
files | src/core/ngx_inet.c |
diffstat | 1 files changed, 28 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/src/core/ngx_inet.c +++ b/src/core/ngx_inet.c @@ -705,6 +705,11 @@ ngx_parse_inet_url(ngx_pool_t *pool, ngx } u->no_port = 1; + + if (!u->no_resolve) { + u->port = u->default_port; + sin->sin_port = htons(u->default_port); + } } len = last - host; @@ -714,52 +719,43 @@ ngx_parse_inet_url(ngx_pool_t *pool, ngx return NGX_ERROR; } - if (len == 1 && *host == '*') { - len = 0; - } - u->host.len = len; u->host.data = host; + if (u->listen && len == 1 && *host == '*') { + sin->sin_addr.s_addr = INADDR_ANY; + u->wildcard = 1; + return NGX_OK; + } + if (u->no_resolve) { return NGX_OK; } - if (len) { - sin->sin_addr.s_addr = ngx_inet_addr(host, len); - - if (sin->sin_addr.s_addr == INADDR_NONE) { - p = ngx_alloc(++len, pool->log); - if (p == NULL) { - return NGX_ERROR; - } - - (void) ngx_cpystrn(p, host, len); + sin->sin_addr.s_addr = ngx_inet_addr(host, len); - h = gethostbyname((const char *) p); - - ngx_free(p); - - if (h == NULL || h->h_addr_list[0] == NULL) { - u->err = "host not found"; - return NGX_ERROR; - } - - sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[0]); + if (sin->sin_addr.s_addr == INADDR_NONE) { + p = ngx_alloc(++len, pool->log); + if (p == NULL) { + return NGX_ERROR; } - if (sin->sin_addr.s_addr == INADDR_ANY) { - u->wildcard = 1; + (void) ngx_cpystrn(p, host, len); + + h = gethostbyname((const char *) p); + + ngx_free(p); + + if (h == NULL || h->h_addr_list[0] == NULL) { + u->err = "host not found"; + return NGX_ERROR; } - } else { - sin->sin_addr.s_addr = INADDR_ANY; - u->wildcard = 1; + sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[0]); } - if (u->no_port) { - u->port = u->default_port; - sin->sin_port = htons(u->default_port); + if (sin->sin_addr.s_addr == INADDR_ANY) { + u->wildcard = 1; } if (u->listen) {