Mercurial > hg > nginx
changeset 2857:507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 18 May 2009 12:58:19 +0000 |
parents | f9b5dfcc96d8 |
children | 87f4a49a9cc3 |
files | src/http/modules/ngx_http_userid_filter_module.c src/http/ngx_http_core_module.c src/http/ngx_http_core_module.h src/http/ngx_http_header_filter_module.c src/http/ngx_http_request.c src/http/ngx_http_variables.c |
diffstat | 6 files changed, 17 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
--- a/src/http/modules/ngx_http_userid_filter_module.c Mon May 18 12:21:00 2009 +0000 +++ b/src/http/modules/ngx_http_userid_filter_module.c Mon May 18 12:58:19 2009 +0000 @@ -390,12 +390,13 @@ } else { if (conf->service == NGX_CONF_UNSET) { - if (ngx_http_server_addr(r, NULL) != NGX_OK) { + + c = r->connection; + + if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) { return NGX_ERROR; } - c = r->connection; - switch (c->local_sockaddr->sa_family) { #if (NGX_HAVE_INET6)
--- a/src/http/ngx_http_core_module.c Mon May 18 12:21:00 2009 +0000 +++ b/src/http/ngx_http_core_module.c Mon May 18 12:58:19 2009 +0000 @@ -1828,68 +1828,6 @@ } -ngx_int_t -ngx_http_server_addr(ngx_http_request_t *r, ngx_str_t *s) -{ - socklen_t len; - ngx_uint_t addr; - ngx_connection_t *c; - u_char sa[NGX_SOCKADDRLEN]; - struct sockaddr_in *sin; -#if (NGX_HAVE_INET6) - ngx_uint_t i; - struct sockaddr_in6 *sin6; -#endif - - c = r->connection; - - switch (c->local_sockaddr->sa_family) { - -#if (NGX_HAVE_INET6) - case AF_INET6: - sin6 = (struct sockaddr_in6 *) c->local_sockaddr; - - for (addr = 0, i = 0; addr == 0 && i < 16; i++) { - addr |= sin6->sin6_addr.s6_addr[i]; - } - - break; -#endif - - default: /* AF_INET */ - sin = (struct sockaddr_in *) c->local_sockaddr; - addr = sin->sin_addr.s_addr; - break; - } - - if (addr == 0) { - - len = NGX_SOCKADDRLEN; - - if (getsockname(c->fd, (struct sockaddr *) &sa, &len) == -1) { - ngx_connection_error(c, ngx_socket_errno, "getsockname() failed"); - return NGX_ERROR; - } - - c->local_sockaddr = ngx_palloc(r->connection->pool, len); - if (c->local_sockaddr == NULL) { - return NGX_ERROR; - } - - c->local_socklen = len; - ngx_memcpy(c->local_sockaddr, &sa, len); - } - - if (s == NULL) { - return NGX_OK; - } - - s->len = ngx_sock_ntop(c->local_sockaddr, s->data, s->len, 0); - - return NGX_OK; -} - - #if (NGX_HTTP_GZIP) ngx_int_t
--- a/src/http/ngx_http_core_module.h Mon May 18 12:21:00 2009 +0000 +++ b/src/http/ngx_http_core_module.h Mon May 18 12:58:19 2009 +0000 @@ -440,7 +440,6 @@ u_char *ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *name, size_t *root_length, size_t reserved); ngx_int_t ngx_http_auth_basic_user(ngx_http_request_t *r); -ngx_int_t ngx_http_server_addr(ngx_http_request_t *r, ngx_str_t *s); #if (NGX_HTTP_GZIP) ngx_int_t ngx_http_gzip_ok(ngx_http_request_t *r); #endif
--- a/src/http/ngx_http_header_filter_module.c Mon May 18 12:21:00 2009 +0000 +++ b/src/http/ngx_http_header_filter_module.c Mon May 18 12:58:19 2009 +0000 @@ -165,6 +165,7 @@ ngx_chain_t out; ngx_list_part_t *part; ngx_table_elt_t *header; + ngx_connection_t *c; ngx_http_core_loc_conf_t *clcf; ngx_http_core_srv_conf_t *cscf; struct sockaddr_in *sin; @@ -309,6 +310,8 @@ len += sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1; } + c = r->connection; + if (r->headers_out.location && r->headers_out.location->value.len && r->headers_out.location->value.data[0] == '/') @@ -326,21 +329,21 @@ host.len = NGX_SOCKADDR_STRLEN; host.data = addr; - if (ngx_http_server_addr(r, &host) != NGX_OK) { + if (ngx_connection_local_sockaddr(c, &host, 0) != NGX_OK) { return NGX_ERROR; } } - switch (r->connection->local_sockaddr->sa_family) { + switch (c->local_sockaddr->sa_family) { #if (NGX_HAVE_INET6) case AF_INET6: - sin6 = (struct sockaddr_in6 *) r->connection->local_sockaddr; + sin6 = (struct sockaddr_in6 *) c->local_sockaddr; port = ntohs(sin6->sin6_port); break; #endif default: /* AF_INET */ - sin = (struct sockaddr_in *) r->connection->local_sockaddr; + sin = (struct sockaddr_in *) c->local_sockaddr; port = ntohs(sin->sin_port); break; } @@ -352,7 +355,7 @@ if (clcf->port_in_redirect) { #if (NGX_HTTP_SSL) - if (r->connection->ssl) + if (c->ssl) port = (port == 443) ? 0 : port; else #endif @@ -511,7 +514,7 @@ sizeof("Location: http") - 1); #if (NGX_HTTP_SSL) - if (r->connection->ssl) { + if (c->ssl) { *b->last++ ='s'; } #endif @@ -588,7 +591,7 @@ *b->last++ = CR; *b->last++ = LF; } - ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "%*s", (size_t) (b->last - b->pos), b->pos); /* the end of HTTP header */
--- a/src/http/ngx_http_request.c Mon May 18 12:21:00 2009 +0000 +++ b/src/http/ngx_http_request.c Mon May 18 12:58:19 2009 +0000 @@ -310,7 +310,7 @@ * is required to determine a server address */ - if (ngx_http_server_addr(r, NULL) != NGX_OK) { + if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) { ngx_http_close_connection(c); return; }
--- a/src/http/ngx_http_variables.c Mon May 18 12:21:00 2009 +0000 +++ b/src/http/ngx_http_variables.c Mon May 18 12:58:19 2009 +0000 @@ -938,7 +938,7 @@ s.len = NGX_SOCKADDR_STRLEN; s.data = addr; - if (ngx_http_server_addr(r, &s) != NGX_OK) { + if (ngx_connection_local_sockaddr(r->connection, &s, 0) != NGX_OK) { return NGX_ERROR; } @@ -974,7 +974,7 @@ v->no_cacheable = 0; v->not_found = 0; - if (ngx_http_server_addr(r, NULL) != NGX_OK) { + if (ngx_connection_local_sockaddr(r->connection, NULL, 0) != NGX_OK) { return NGX_ERROR; }