Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2009-05-18 16:58:19 +0400
committerIgor Sysoev <igor@sysoev.ru>2009-05-18 16:58:19 +0400
commit2a9ce6263164bedc4db70e0ad9fc6591605e38b0 (patch)
treeeee93b330dc9ac4ab4db3d14618bc3455be4b619
parent739e29b651dc0f6f176884cce697018b4b522a67 (diff)
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
-rw-r--r--src/http/modules/ngx_http_userid_filter_module.c7
-rw-r--r--src/http/ngx_http_core_module.c62
-rw-r--r--src/http/ngx_http_core_module.h1
-rw-r--r--src/http/ngx_http_header_filter_module.c17
-rw-r--r--src/http/ngx_http_request.c2
-rw-r--r--src/http/ngx_http_variables.c4
6 files changed, 17 insertions, 76 deletions
diff --git a/src/http/modules/ngx_http_userid_filter_module.c b/src/http/modules/ngx_http_userid_filter_module.c
index 5ffb1d02b..3462f649c 100644
--- a/src/http/modules/ngx_http_userid_filter_module.c
+++ b/src/http/modules/ngx_http_userid_filter_module.c
@@ -390,12 +390,13 @@ ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
} else {
if (conf->service == NGX_CONF_UNSET) {
- if (ngx_http_server_addr(r, NULL) != NGX_OK) {
- return NGX_ERROR;
- }
c = r->connection;
+ if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) {
+ return NGX_ERROR;
+ }
+
switch (c->local_sockaddr->sa_family) {
#if (NGX_HAVE_INET6)
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index a08cadafe..3d146291c 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1828,68 +1828,6 @@ 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)
-{
- 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
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index 6abfc6e23..dfc07facc 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -440,7 +440,6 @@ ngx_int_t ngx_http_set_exten(ngx_http_request_t *r);
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
diff --git a/src/http/ngx_http_header_filter_module.c b/src/http/ngx_http_header_filter_module.c
index 332fceb8a..9044c4040 100644
--- a/src/http/ngx_http_header_filter_module.c
+++ b/src/http/ngx_http_header_filter_module.c
@@ -165,6 +165,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
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 @@ ngx_http_header_filter(ngx_http_request_t *r)
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 @@ ngx_http_header_filter(ngx_http_request_t *r)
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 @@ ngx_http_header_filter(ngx_http_request_t *r)
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 @@ ngx_http_header_filter(ngx_http_request_t *r)
sizeof("Location: http") - 1);
#if (NGX_HTTP_SSL)
- if (r->connection->ssl) {
+ if (c->ssl) {
*b->last++ ='s';
}
#endif
@@ -588,7 +591,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
*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 */
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index 39bf57ee2..1761a88ff 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -310,7 +310,7 @@ ngx_http_init_request(ngx_event_t *rev)
* 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;
}
diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c
index dd28888fa..28c82ef2f 100644
--- a/src/http/ngx_http_variables.c
+++ b/src/http/ngx_http_variables.c
@@ -938,7 +938,7 @@ ngx_http_variable_server_addr(ngx_http_request_t *r,
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 @@ ngx_http_variable_server_port(ngx_http_request_t *r,
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;
}