]> git.kaiwu.me - nginx.git/commitdiff
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
authorIgor Sysoev <igor@sysoev.ru>
Mon, 18 May 2009 12:58:19 +0000 (12:58 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 18 May 2009 12:58:19 +0000 (12:58 +0000)
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

index 5ffb1d02b4de82d01477b7401faf023b69a517e3..3462f649cb50f5438f00a4e93040ffc484204769 100644 (file)
@@ -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)
index a08cadafe45e1bfcd39fdb20fb8e1478ed127cb6..3d146291c09991eea593e60f83a040ec3e0493fa 100644 (file)
@@ -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
index 6abfc6e2388e56c77fe1d62fc7c06da1155e3f84..dfc07facc7520c78b2a885532829ba8f1ebbf813 100644 (file)
@@ -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
index 332fceb8a0437ec3b3a07e9e58d93a713e14dc2b..9044c4040007f2d89881b1565e1b4f69d4d03469 100644 (file)
@@ -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 */
index 39bf57ee282906ec730bd634da9c6abd575a9b3c..1761a88ff7439bc9e1d53ec2424334c98a45c569 100644 (file)
@@ -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;
         }
index dd28888fae2d7490fc8a4cc76b96faeac96b4dea..28c82ef2f704bd3ba2b6587315572a5894c7c0ef 100644 (file)
@@ -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;
     }