Mercurial > hg > nginx-mail
comparison src/http/ngx_http_core_module.c @ 487:76a79816b771 NGINX_0_7_36
nginx 0.7.36
*) Feature: a preliminary IPv6 support; the "listen" directive of the
HTTP module supports IPv6.
*) Bugfix: the $ancient_browser variable did not work for browsers
preset by a "modern_browser" directives.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Sat, 21 Feb 2009 00:00:00 +0300 |
parents | 15a022ee809b |
children | 20962db0117c |
comparison
equal
deleted
inserted
replaced
486:40964c811e59 | 487:76a79816b771 |
---|---|
1774 ngx_int_t | 1774 ngx_int_t |
1775 ngx_http_server_addr(ngx_http_request_t *r, ngx_str_t *s) | 1775 ngx_http_server_addr(ngx_http_request_t *r, ngx_str_t *s) |
1776 { | 1776 { |
1777 socklen_t len; | 1777 socklen_t len; |
1778 ngx_connection_t *c; | 1778 ngx_connection_t *c; |
1779 struct sockaddr_in sin; | 1779 struct sockaddr_in *sin; |
1780 | 1780 u_char sa[NGX_SOCKADDRLEN]; |
1781 /* AF_INET only */ | |
1782 | 1781 |
1783 c = r->connection; | 1782 c = r->connection; |
1784 | 1783 |
1785 if (r->in_addr == 0) { | 1784 if (c->local_sockaddr == NULL) { |
1786 len = sizeof(struct sockaddr_in); | 1785 |
1787 if (getsockname(c->fd, (struct sockaddr *) &sin, &len) == -1) { | 1786 len = NGX_SOCKADDRLEN; |
1787 | |
1788 if (getsockname(c->fd, (struct sockaddr *) &sa, &len) == -1) { | |
1788 ngx_connection_error(c, ngx_socket_errno, "getsockname() failed"); | 1789 ngx_connection_error(c, ngx_socket_errno, "getsockname() failed"); |
1789 return NGX_ERROR; | 1790 return NGX_ERROR; |
1790 } | 1791 } |
1791 | 1792 |
1792 r->in_addr = sin.sin_addr.s_addr; | 1793 c->local_sockaddr = ngx_palloc(r->connection->pool, len); |
1793 | 1794 if (c->local_sockaddr == NULL) { |
1794 } else { | 1795 return NGX_ERROR; |
1795 sin.sin_family = c->sockaddr->sa_family; | 1796 } |
1796 sin.sin_addr.s_addr = r->in_addr; | 1797 |
1797 } | 1798 c->local_socklen = len; |
1799 ngx_memcpy(c->local_sockaddr, &sa, len); | |
1800 } | |
1801 | |
1802 sin = (struct sockaddr_in *) c->local_sockaddr; | |
1803 r->in_addr = sin->sin_addr.s_addr; | |
1798 | 1804 |
1799 if (s == NULL) { | 1805 if (s == NULL) { |
1800 return NGX_OK; | 1806 return NGX_OK; |
1801 } | 1807 } |
1802 | 1808 |
1803 s->len = ngx_sock_ntop((struct sockaddr *) &sin, s->data, | 1809 s->len = ngx_sock_ntop(c->local_sockaddr, s->data, s->len, 0); |
1804 NGX_INET_ADDRSTRLEN); | |
1805 | 1810 |
1806 return NGX_OK; | 1811 return NGX_OK; |
1807 } | 1812 } |
1808 | 1813 |
1809 | 1814 |
2727 * set by ngx_pcalloc(): | 2732 * set by ngx_pcalloc(): |
2728 * | 2733 * |
2729 * conf->client_large_buffers.num = 0; | 2734 * conf->client_large_buffers.num = 0; |
2730 */ | 2735 */ |
2731 | 2736 |
2732 if (ngx_array_init(&cscf->listen, cf->pool, 4, sizeof(ngx_http_listen_t)) | 2737 if (ngx_array_init(&cscf->listen, cf->temp_pool, 4, |
2738 sizeof(ngx_http_listen_t)) | |
2733 == NGX_ERROR) | 2739 == NGX_ERROR) |
2734 { | 2740 { |
2735 return NGX_CONF_ERROR; | 2741 return NGX_CONF_ERROR; |
2736 } | 2742 } |
2737 | 2743 |
2759 { | 2765 { |
2760 ngx_http_core_srv_conf_t *prev = parent; | 2766 ngx_http_core_srv_conf_t *prev = parent; |
2761 ngx_http_core_srv_conf_t *conf = child; | 2767 ngx_http_core_srv_conf_t *conf = child; |
2762 | 2768 |
2763 ngx_http_listen_t *ls; | 2769 ngx_http_listen_t *ls; |
2770 struct sockaddr_in *sin; | |
2764 ngx_http_server_name_t *sn; | 2771 ngx_http_server_name_t *sn; |
2765 | 2772 |
2766 /* TODO: it does not merge, it inits only */ | 2773 /* TODO: it does not merge, it inits only */ |
2767 | 2774 |
2768 if (conf->listen.nelts == 0) { | 2775 if (conf->listen.nelts == 0) { |
2771 return NGX_CONF_ERROR; | 2778 return NGX_CONF_ERROR; |
2772 } | 2779 } |
2773 | 2780 |
2774 ngx_memzero(ls, sizeof(ngx_http_listen_t)); | 2781 ngx_memzero(ls, sizeof(ngx_http_listen_t)); |
2775 | 2782 |
2776 ls->addr = INADDR_ANY; | 2783 sin = (struct sockaddr_in *) &ls->sockaddr; |
2784 | |
2785 sin->sin_family = AF_INET; | |
2777 #if (NGX_WIN32) | 2786 #if (NGX_WIN32) |
2778 ls->port = 80; | 2787 sin->sin_port = htons(80); |
2779 #else | 2788 #else |
2780 /* STUB: getuid() should be cached */ | 2789 sin->sin_port = htons((getuid() == 0) ? 80 : 8000); |
2781 ls->port = (getuid() == 0) ? 80 : 8000; | |
2782 #endif | 2790 #endif |
2783 ls->family = AF_INET; | 2791 sin->sin_addr.s_addr = INADDR_ANY; |
2784 | 2792 |
2785 ls->conf.backlog = NGX_LISTEN_BACKLOG; | 2793 ls->conf.backlog = NGX_LISTEN_BACKLOG; |
2786 ls->conf.rcvbuf = -1; | 2794 ls->conf.rcvbuf = -1; |
2787 ls->conf.sndbuf = -1; | 2795 ls->conf.sndbuf = -1; |
2788 } | 2796 } |
3157 | 3165 |
3158 return NGX_CONF_OK; | 3166 return NGX_CONF_OK; |
3159 } | 3167 } |
3160 | 3168 |
3161 | 3169 |
3162 /* AF_INET only */ | |
3163 | |
3164 static char * | 3170 static char * |
3165 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 3171 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
3166 { | 3172 { |
3167 ngx_http_core_srv_conf_t *scf = conf; | 3173 ngx_http_core_srv_conf_t *scf = conf; |
3168 | 3174 |
3199 return NGX_CONF_ERROR; | 3205 return NGX_CONF_ERROR; |
3200 } | 3206 } |
3201 | 3207 |
3202 ngx_memzero(ls, sizeof(ngx_http_listen_t)); | 3208 ngx_memzero(ls, sizeof(ngx_http_listen_t)); |
3203 | 3209 |
3204 ls->family = u.family; | 3210 ngx_memcpy(ls->sockaddr, u.sockaddr, u.socklen); |
3205 ls->addr = u.addr.in_addr; | 3211 |
3206 ls->port = u.port; | 3212 ls->socklen = u.socklen; |
3207 ls->file_name = cf->conf_file->file.name.data; | 3213 ls->file_name = cf->conf_file->file.name.data; |
3208 ls->line = cf->conf_file->line; | 3214 ls->line = cf->conf_file->line; |
3209 ls->conf.backlog = NGX_LISTEN_BACKLOG; | 3215 ls->conf.backlog = NGX_LISTEN_BACKLOG; |
3210 ls->conf.rcvbuf = -1; | 3216 ls->conf.rcvbuf = -1; |
3211 ls->conf.sndbuf = -1; | 3217 ls->conf.sndbuf = -1; |
3212 | 3218 ls->conf.wildcard = u.wildcard; |
3213 n = ngx_inet_ntop(AF_INET, &ls->addr, ls->conf.addr, NGX_INET_ADDRSTRLEN); | 3219 |
3214 ngx_sprintf(&ls->conf.addr[n], ":%ui", ls->port); | 3220 (void) ngx_sock_ntop((struct sockaddr *) &ls->sockaddr, ls->conf.addr, |
3221 NGX_SOCKADDR_STRLEN, 1); | |
3215 | 3222 |
3216 if (cf->args->nelts == 2) { | 3223 if (cf->args->nelts == 2) { |
3217 return NGX_CONF_OK; | 3224 return NGX_CONF_OK; |
3218 } | 3225 } |
3219 | 3226 |