Klaus Demo nginx / bbf7043
Simplified URL parsing code. Except for the "listen" directive, "*" specified as a hostname is no longer treated specially. Ruslan Ermilov 9 years ago
1 changed file(s) with 34 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
704704 }
705705
706706 u->no_port = 1;
707
708 if (!u->no_resolve) {
709 u->port = u->default_port;
710 sin->sin_port = htons(u->default_port);
711 }
707712 }
708713
709714 len = last - host;
713718 return NGX_ERROR;
714719 }
715720
716 if (len == 1 && *host == '*') {
717 len = 0;
718 }
719
720721 u->host.len = len;
721722 u->host.data = host;
722723
724 if (u->listen && len == 1 && *host == '*') {
725 sin->sin_addr.s_addr = INADDR_ANY;
726 u->wildcard = 1;
727 return NGX_OK;
728 }
729
723730 if (u->no_resolve) {
724731 return NGX_OK;
725732 }
726733
727 if (len) {
728 sin->sin_addr.s_addr = ngx_inet_addr(host, len);
729
730 if (sin->sin_addr.s_addr == INADDR_NONE) {
731 p = ngx_alloc(++len, pool->log);
732 if (p == NULL) {
733 return NGX_ERROR;
734 }
735
736 (void) ngx_cpystrn(p, host, len);
737
738 h = gethostbyname((const char *) p);
739
740 ngx_free(p);
741
742 if (h == NULL || h->h_addr_list[0] == NULL) {
743 u->err = "host not found";
744 return NGX_ERROR;
745 }
746
747 sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[0]);
748 }
749
750 if (sin->sin_addr.s_addr == INADDR_ANY) {
751 u->wildcard = 1;
752 }
753
754 } else {
755 sin->sin_addr.s_addr = INADDR_ANY;
734 sin->sin_addr.s_addr = ngx_inet_addr(host, len);
735
736 if (sin->sin_addr.s_addr == INADDR_NONE) {
737 p = ngx_alloc(++len, pool->log);
738 if (p == NULL) {
739 return NGX_ERROR;
740 }
741
742 (void) ngx_cpystrn(p, host, len);
743
744 h = gethostbyname((const char *) p);
745
746 ngx_free(p);
747
748 if (h == NULL || h->h_addr_list[0] == NULL) {
749 u->err = "host not found";
750 return NGX_ERROR;
751 }
752
753 sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[0]);
754 }
755
756 if (sin->sin_addr.s_addr == INADDR_ANY) {
756757 u->wildcard = 1;
757 }
758
759 if (u->no_port) {
760 u->port = u->default_port;
761 sin->sin_port = htons(u->default_port);
762758 }
763759
764760 if (u->listen) {