diff src/http/ngx_http_request.c @ 142:84910468f6de NGINX_0_3_18

nginx 0.3.18 *) Feature: the "server_names" directive supports the ".domain.tld" names. *) Feature: the "server_names" directive uses the hash for the "*.domain.tld" names and more effective hash for usual names. *) Change: the "server_names_hash_max_size" and "server_names_hash_bucket_size" directives. *) Change: the "server_names_hash" and "server_names_hash_threshold" directives were canceled. *) Feature: the "valid_referers" directive uses the hash site names. *) Change: now the "valid_referers" directive checks the site names only without the URI part. *) Bugfix: some ".domain.tld" names incorrectly processed by the ngx_http_map_module. *) Bugfix: segmentation fault was occurred if configuration file did not exist; bug appeared in 0.3.12. *) Bugfix: on 64-bit platforms segmentation fault may occurred on start; bug appeared in 0.3.16.
author Igor Sysoev <http://sysoev.ru>
date Mon, 26 Dec 2005 00:00:00 +0300
parents 8e6d4d96ec4c
children 36af50a5582d
line wrap: on
line diff
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -203,11 +203,10 @@ void ngx_http_init_request(ngx_event_t *
     struct sockaddr_in          sin;
     ngx_connection_t           *c;
     ngx_http_request_t         *r;
-    ngx_http_in_port_t         *in_port;
-    ngx_http_in_addr_t         *in_addr;
+    ngx_http_in_port_t         *hip;
+    ngx_http_in_addr_t         *hia;
     ngx_http_log_ctx_t         *ctx;
     ngx_http_connection_t      *hc;
-    ngx_http_server_name_t     *server_name;
     ngx_http_core_srv_conf_t   *cscf;
     ngx_http_core_loc_conf_t   *clcf;
     ngx_http_core_main_conf_t  *cmcf;
@@ -269,15 +268,15 @@ void ngx_http_init_request(ngx_event_t *
 
     /* AF_INET only */
 
-    in_port = c->servers;
-    in_addr = in_port->addrs.elts;
-
-    r->port = in_port->port;
-    r->port_text = &in_port->port_text;
+    hip = c->servers;
+    hia = hip->addrs;
+
+    r->port = hip->port;
+    r->port_text = &hip->port_text;
 
     i = 0;
 
-    if (in_port->addrs.nelts > 1) {
+    if (hip->naddrs > 1) {
 
         /*
          * There are several addresses on this port and one of them
@@ -308,25 +307,27 @@ void ngx_http_init_request(ngx_event_t *
 
         /* the last in_port->addrs address is "*" */
 
-        for ( /* void */ ; i < in_port->addrs.nelts - 1; i++) {
-            if (in_addr[i].addr == r->in_addr) {
+        for ( /* void */ ; i < hip->naddrs - 1; i++) {
+            if (hia[i].addr == r->in_addr) {
                 break;
             }
         }
 
     } else {
-        r->in_addr = in_addr[0].addr;
+        r->in_addr = hia[0].addr;
     }
 
-    r->virtual_names = &in_addr[i];
+    r->virtual_names = hia[i].virtual_names;
 
     /* the default server configuration for the address:port */
-    cscf = in_addr[i].core_srv_conf;
+    cscf = hia[i].core_srv_conf;
 
     r->main_conf = cscf->ctx->main_conf;
     r->srv_conf = cscf->ctx->srv_conf;
     r->loc_conf = cscf->ctx->loc_conf;
 
+    r->server_name = cscf->server_name;
+
     rev->handler = ngx_http_process_request_line;
 
 #if (NGX_HTTP_SSL)
@@ -350,9 +351,6 @@ void ngx_http_init_request(ngx_event_t *
 
 #endif
 
-    server_name = cscf->server_names.elts;
-    r->server_name = server_name->name;
-
     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
     c->log->file = clcf->err_log->file;
     if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
@@ -1321,78 +1319,35 @@ ngx_http_process_request_header(ngx_http
 static ngx_int_t
 ngx_http_find_virtual_server(ngx_http_request_t *r)
 {
-    ngx_int_t                   rc;
-    ngx_uint_t                  i, n, key;
-    ngx_http_server_name_t     *name;
-    ngx_http_core_loc_conf_t   *clcf;
-    ngx_http_core_srv_conf_t   *cscf;
-    ngx_http_core_main_conf_t  *cmcf;
-
-    if (r->virtual_names->hash) {
-        cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
-
-        ngx_http_server_names_hash_key(key,
-                                       r->headers_in.host->value.data,
-                                       r->headers_in.host_name_len,
-                                       cmcf->server_names_hash);
-
-        name = r->virtual_names->hash[key].elts;
-        n = r->virtual_names->hash[key].nelts;
-
-    } else {
-        name = r->virtual_names->names.elts;
-        n = r->virtual_names->names.nelts;
+    size_t                     len;
+    u_char                    *host;
+    ngx_http_virtual_names_t  *vn;
+    ngx_http_core_loc_conf_t  *clcf;
+    ngx_http_core_srv_conf_t  *cscf;
+
+    vn = r->virtual_names;
+
+    if (vn == NULL) {
+        return NGX_OK;
     }
 
-    for (i = 0; i < n; i++) {
-
-        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                       "server name: %V", &name[i].name);
-
-        if (r->headers_in.host_name_len != name[i].name.len) {
-            continue;
-        }
-
-        rc = ngx_strncmp(r->headers_in.host->value.data,
-                         name[i].name.data, name[i].name.len);
-
-        if (rc == 0) {
-            r->server_name = name[i].name;
+    host = r->headers_in.host->value.data;
+    len = r->headers_in.host_name_len;
+
+    /* STUB: ngx_hash_key() here is STUB */
+
+    if (vn->hash.buckets) {
+        cscf = ngx_hash_find(&vn->hash, ngx_hash_key(host, len), host, len);
+        if (cscf) {
             goto found;
         }
-
-        if (rc < 0) {
-            /* the server names are lexicographically sorted */
-            break;
-        }
     }
 
-    if (r->virtual_names->wildcards.nelts) {
-
-        name = r->virtual_names->wildcards.elts;
-        for (i = 0; i < r->virtual_names->wildcards.nelts; i++) {
-
-            ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                           "server name: %V", &name[i].name);
-
-            if (r->headers_in.host_name_len <= name[i].name.len) {
-                continue;
-            }
-
-            ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                           "server name: %s",
-                           r->headers_in.host->value.data
-                           + (r->headers_in.host_name_len - name[i].name.len));
-
-            if (ngx_strncmp(r->headers_in.host->value.data
-                            + (r->headers_in.host_name_len - name[i].name.len),
-                            name[i].name.data, name[i].name.len) == 0)
-            {
-                r->server_name.len = r->headers_in.host_name_len;
-                r->server_name.data = r->headers_in.host->value.data;
-
-                goto found;
-            }
+    if (vn->dns_wildcards && vn->dns_wildcards->hash.buckets) {
+        cscf = ngx_hash_find_wildcard(vn->dns_wildcards, host, len);
+
+        if (cscf) {
+            goto found;
         }
     }
 
@@ -1406,8 +1361,11 @@ ngx_http_find_virtual_server(ngx_http_re
 
 found:
 
-    r->srv_conf = name[i].core_srv_conf->ctx->srv_conf;
-    r->loc_conf = name[i].core_srv_conf->ctx->loc_conf;
+    r->server_name.len = len;
+    r->server_name.data = host;
+
+    r->srv_conf = cscf->ctx->srv_conf;
+    r->loc_conf = cscf->ctx->loc_conf;
 
     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
     r->connection->log->file = clcf->err_log->file;