Mercurial > hg > nginx
comparison src/http/ngx_http_core_module.c @ 55:cad6c2f43283
nginx-0.0.1-2003-01-29-10:25:51 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 29 Jan 2003 07:25:51 +0000 |
parents | 27b628ef907e |
children | 058f01f78761 |
comparison
equal
deleted
inserted
replaced
54:27b628ef907e | 55:cad6c2f43283 |
---|---|
20 int ngx_http_static_handler(ngx_http_request_t *r); | 20 int ngx_http_static_handler(ngx_http_request_t *r); |
21 int ngx_http_proxy_handler(ngx_http_request_t *r); | 21 int ngx_http_proxy_handler(ngx_http_request_t *r); |
22 /**/ | 22 /**/ |
23 | 23 |
24 static int ngx_http_core_index_handler(ngx_http_request_t *r); | 24 static int ngx_http_core_index_handler(ngx_http_request_t *r); |
25 static ngx_http_conf_ctx_t *ngx_http_find_server_conf(ngx_http_request_t *r, | |
26 void *addr); | |
27 | 25 |
28 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy); | 26 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy); |
29 static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, | 27 static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, |
30 char *dummy); | 28 char *dummy); |
31 static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool); | 29 static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool); |
96 }; | 94 }; |
97 | 95 |
98 | 96 |
99 int ngx_http_handler(ngx_http_request_t *r) | 97 int ngx_http_handler(ngx_http_request_t *r) |
100 { | 98 { |
101 int rc, i; | 99 int rc, a, n, i; |
102 ngx_http_module_t *module; | 100 ngx_http_module_t *module; |
103 ngx_http_conf_ctx_t *ctx; | 101 ngx_http_conf_ctx_t *ctx; |
102 ngx_http_in_port_t *in_port; | |
103 ngx_http_in_addr_t *in_addr; | |
104 ngx_http_server_name_t *name; | |
104 | 105 |
105 r->connection->unexpected_eof = 0; | 106 r->connection->unexpected_eof = 0; |
106 r->lingering_close = 1; | 107 r->lingering_close = 1; |
107 r->keepalive = 1; | 108 r->keepalive = 1; |
108 | 109 |
110 | 111 |
111 if (r->connection->servers == NULL) { | 112 if (r->connection->servers == NULL) { |
112 ctx = (ngx_http_conf_ctx_t *) r->connection->ctx; | 113 ctx = (ngx_http_conf_ctx_t *) r->connection->ctx; |
113 | 114 |
114 } else { | 115 } else { |
115 ctx = ngx_http_find_server_conf(r, r->connection->servers); | 116 |
117 /* AF_INET only */ | |
118 | |
119 in_port = (ngx_http_in_port_t *) r->connection->servers; | |
120 | |
121 a = 0; | |
122 | |
123 if (in_port->addr.nelts > 1) { | |
124 /* find r->in_addr, getsockname() */ | |
125 | |
126 in_addr = (ngx_http_in_addr_t *) in_port->addr.elts; | |
127 for ( /* void */ ; a < in_port->addr.nelts; a++) { | |
128 | |
129 if (in_addr[a].addr == INADDR_ANY) { | |
130 break; | |
131 } | |
132 | |
133 if (in_addr[a].addr == r->in_addr) { | |
134 break; | |
135 } | |
136 } | |
137 } | |
138 | |
139 ctx = in_addr[a].core_srv_conf->ctx; | |
140 | |
141 if (r->headers_in.host_name_len > 0) { | |
142 | |
143 name = (ngx_http_server_name_t *) in_addr[a].names.elts; | |
144 for (n = 0; n < in_addr[a].names.nelts; n++) { | |
145 if (r->headers_in.host_name_len != name[n].name.len) { | |
146 continue; | |
147 } | |
148 | |
149 if (ngx_strncasecmp(r->headers_in.host->value.data, | |
150 name[n].name.data, | |
151 r->headers_in.host_name_len) == 0) { | |
152 ctx = name->core_srv_conf->ctx; | |
153 break; | |
154 } | |
155 } | |
156 } | |
116 } | 157 } |
117 | 158 |
118 r->srv_conf = ctx->srv_conf; | 159 r->srv_conf = ctx->srv_conf; |
119 r->loc_conf = ctx->loc_conf; | 160 r->loc_conf = ctx->loc_conf; |
120 | 161 |
452 | 493 |
453 return ngx_http_handler(r); | 494 return ngx_http_handler(r); |
454 } | 495 } |
455 | 496 |
456 | 497 |
457 static ngx_http_conf_ctx_t *ngx_http_find_server_conf(ngx_http_request_t *r, | |
458 void *addr) | |
459 { | |
460 int i, len; | |
461 ngx_http_in_addr_t *in_addr; | |
462 ngx_http_server_name_t *name; | |
463 | |
464 /* AF_INET only */ | |
465 | |
466 /* BUG: need cycle thru addr[]->elts */ | |
467 | |
468 in_addr = (ngx_http_in_addr_t *) addr; | |
469 | |
470 if (r->headers_in.host == NULL) { | |
471 return in_addr->core_srv_conf->ctx; | |
472 } | |
473 | |
474 len = r->headers_in.host_name.len; | |
475 name = (ngx_http_server_name_t *) in_addr->names.elts; | |
476 for (i = 0; i < in_addr->names.nelts; i++) { | |
477 if (len != name->name.len) { | |
478 continue; | |
479 } | |
480 | |
481 if (ngx_strncasecmp(r->headers_in.host_name.data, | |
482 name->name.data, len) == 0) { | |
483 return name->core_srv_conf->ctx; | |
484 } | |
485 } | |
486 | |
487 return in_addr->core_srv_conf->ctx; | |
488 } | |
489 | |
490 | |
491 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy) | 498 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy) |
492 { | 499 { |
493 int i, j; | 500 int i, j; |
494 char *rv; | 501 char *rv; |
495 ngx_http_module_t *module; | 502 ngx_http_module_t *module; |
794 /* AF_INET only */ | 801 /* AF_INET only */ |
795 | 802 |
796 ls->family = AF_INET; | 803 ls->family = AF_INET; |
797 ls->addr = INADDR_ANY; | 804 ls->addr = INADDR_ANY; |
798 ls->flags = 0; | 805 ls->flags = 0; |
799 ls->conf_file = cf->conf_file; | 806 ls->file_name = cf->conf_file->file.name; |
800 ls->line = cf->conf_file->line; | 807 ls->line = cf->conf_file->line; |
801 | 808 |
802 args = (ngx_str_t *) cf->args->elts; | 809 args = (ngx_str_t *) cf->args->elts; |
803 | 810 |
804 ls->port = atoi(args[1].data); | 811 ls->port = atoi(args[1].data); |