comparison src/http/ngx_http.c @ 98:c9b243802a17

nginx-0.0.1-2003-05-30-18:27:59 import
author Igor Sysoev <igor@sysoev.ru>
date Fri, 30 May 2003 14:27:59 +0000
parents a23d010f356d
children 7ebc8b7fb816
comparison
equal deleted inserted replaced
97:70d2345a903f 98:c9b243802a17
149 149
150 /* init http{} main_conf's, merge the server{}s' srv_conf's 150 /* init http{} main_conf's, merge the server{}s' srv_conf's
151 and its location{}s' loc_conf's */ 151 and its location{}s' loc_conf's */
152 152
153 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index]; 153 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
154 cscfp = (ngx_http_core_srv_conf_t **)cmcf->servers.elts; 154 cscfp = cmcf->servers.elts;
155 155
156 for (m = 0; ngx_modules[m]; m++) { 156 for (m = 0; ngx_modules[m]; m++) {
157 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { 157 if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
158 continue; 158 continue;
159 } 159 }
160 160
161 module = (ngx_http_module_t *) ngx_modules[m]->ctx; 161 module = ngx_modules[m]->ctx;
162 mi = ngx_modules[m]->ctx_index; 162 mi = ngx_modules[m]->ctx_index;
163 163
164 /* init http{} main_conf's */ 164 /* init http{} main_conf's */
165 165
166 if (module->init_main_conf) { 166 if (module->init_main_conf) {
225 225
226 ngx_init_array(in_ports, cf->pool, 10, sizeof(ngx_http_in_port_t), 226 ngx_init_array(in_ports, cf->pool, 10, sizeof(ngx_http_in_port_t),
227 NGX_CONF_ERROR); 227 NGX_CONF_ERROR);
228 228
229 /* "server" directives */ 229 /* "server" directives */
230 cscfp = (ngx_http_core_srv_conf_t **) cmcf->servers.elts; 230 cscfp = cmcf->servers.elts;
231 for (s = 0; s < cmcf->servers.nelts; s++) { 231 for (s = 0; s < cmcf->servers.nelts; s++) {
232 232
233 /* "listen" directives */ 233 /* "listen" directives */
234 lscf = (ngx_http_listen_t *) cscfp[s]->listen.elts; 234 lscf = cscfp[s]->listen.elts;
235 for (l = 0; l < cscfp[s]->listen.nelts; l++) { 235 for (l = 0; l < cscfp[s]->listen.nelts; l++) {
236 236
237 port_found = 0; 237 port_found = 0;
238 238
239 /* AF_INET only */ 239 /* AF_INET only */
240 240
241 in_port = (ngx_http_in_port_t *) in_ports.elts; 241 in_port = in_ports.elts;
242 for (p = 0; p < in_ports.nelts; p++) { 242 for (p = 0; p < in_ports.nelts; p++) {
243 243
244 if (lscf[l].port == in_port[p].port) { 244 if (lscf[l].port == in_port[p].port) {
245 245
246 /* the port is already in the port list */ 246 /* the port is already in the port list */
247 247
248 port_found = 1; 248 port_found = 1;
249 addr_found = 0; 249 addr_found = 0;
250 250
251 in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts; 251 in_addr = in_port[p].addrs.elts;
252 for (a = 0; a < in_port[p].addrs.nelts; a++) { 252 for (a = 0; a < in_port[p].addrs.nelts; a++) {
253 253
254 if (lscf[l].addr == in_addr[a].addr) { 254 if (lscf[l].addr == in_addr[a].addr) {
255 255
256 /* the address is already bound to this port */ 256 /* the address is already bound to this port */
257 257
258 /* "server_name" directives */ 258 /* "server_name" directives */
259 s_name = (ngx_http_server_name_t *) 259 s_name = cscfp[s]->server_names.elts;
260 cscfp[s]->server_names.elts;
261 for (n = 0; n < cscfp[s]->server_names.nelts; n++) { 260 for (n = 0; n < cscfp[s]->server_names.nelts; n++) {
262 261
263 /* add the server name and server core module 262 /* add the server name and server core module
264 configuration to the address:port */ 263 configuration to the address:port */
265 264
392 391
393 /* optimize the lists of the ports, the addresses and the server names */ 392 /* optimize the lists of the ports, the addresses and the server names */
394 393
395 /* AF_INET only */ 394 /* AF_INET only */
396 395
397 in_port = (ngx_http_in_port_t *) in_ports.elts; 396 in_port = in_ports.elts;
398 for (p = 0; p < in_ports.nelts; p++) { 397 for (p = 0; p < in_ports.nelts; p++) {
399 398
400 /* check whether the all server names point to the same server */ 399 /* check whether the all server names point to the same server */
401 400
402 in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts; 401 in_addr = in_port[p].addrs.elts;
403 for (a = 0; a < in_port[p].addrs.nelts; a++) { 402 for (a = 0; a < in_port[p].addrs.nelts; a++) {
404 403
405 virtual_names = 0; 404 virtual_names = 0;
406 405
407 name = (ngx_http_server_name_t *) in_addr[a].names.elts; 406 name = in_addr[a].names.elts;
408 for (n = 0; n < in_addr[a].names.nelts; n++) { 407 for (n = 0; n < in_addr[a].names.nelts; n++) {
409 if (in_addr[a].core_srv_conf != name[n].core_srv_conf) { 408 if (in_addr[a].core_srv_conf != name[n].core_srv_conf) {
410 virtual_names = 1; 409 virtual_names = 1;
411 break; 410 break;
412 } 411 }
428 427
429 } else { 428 } else {
430 a = 0; 429 a = 0;
431 } 430 }
432 431
433 in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts; 432 in_addr = in_port[p].addrs.elts;
434 while (a < in_port[p].addrs.nelts) { 433 while (a < in_port[p].addrs.nelts) {
435 434
436 ngx_test_null(ls, ngx_push_array(&ngx_listening_sockets), 435 ngx_test_null(ls, ngx_push_array(&ngx_listening_sockets),
437 NGX_CONF_ERROR); 436 NGX_CONF_ERROR);
438 ngx_memzero(ls, sizeof(ngx_listen_t)); 437 ngx_memzero(ls, sizeof(ngx_listen_t));
441 ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)), 440 ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)),
442 NGX_CONF_ERROR); 441 NGX_CONF_ERROR);
443 442
444 addr_in->sin_family = AF_INET; 443 addr_in->sin_family = AF_INET;
445 addr_in->sin_addr.s_addr = in_addr[a].addr; 444 addr_in->sin_addr.s_addr = in_addr[a].addr;
446 addr_in->sin_port = htons(in_port[p].port); 445 addr_in->sin_port = htons((u_short) in_port[p].port);
447 446
448 ngx_test_null(ls->addr_text.data, 447 ngx_test_null(ls->addr_text.data,
449 ngx_palloc(cf->pool, INET_ADDRSTRLEN + 6), 448 ngx_palloc(cf->pool, INET_ADDRSTRLEN + 6),
450 NGX_CONF_ERROR); 449 NGX_CONF_ERROR);
451 450
476 ls->post_accept_timeout = cmcf->post_accept_timeout; 475 ls->post_accept_timeout = cmcf->post_accept_timeout;
477 ls->ctx = ctx; 476 ls->ctx = ctx;
478 477
479 if (in_port[p].addrs.nelts > 1) { 478 if (in_port[p].addrs.nelts > 1) {
480 479
481 in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts; 480 in_addr = in_port[p].addrs.elts;
482 if (in_addr[in_port[p].addrs.nelts - 1].addr != INADDR_ANY) { 481 if (in_addr[in_port[p].addrs.nelts - 1].addr != INADDR_ANY) {
483 482
484 /* if this port has not the "*:port" binding then create 483 /* if this port has not the "*:port" binding then create
485 the separate ngx_http_in_port_t for the all bindings */ 484 the separate ngx_http_in_port_t for the all bindings */
486 485
521 a++; 520 a++;
522 } 521 }
523 } 522 }
524 523
525 /* DEBUG STUFF */ 524 /* DEBUG STUFF */
526 in_port = (ngx_http_in_port_t *) in_ports.elts; 525 in_port = in_ports.elts;
527 for (p = 0; p < in_ports.nelts; p++) { 526 for (p = 0; p < in_ports.nelts; p++) {
528 ngx_log_debug(cf->log, "port: %d" _ in_port[p].port); 527 ngx_log_debug(cf->log, "port: %d" _ in_port[p].port);
529 in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts; 528 in_addr = in_port[p].addrs.elts;
530 for (a = 0; a < in_port[p].addrs.nelts; a++) { 529 for (a = 0; a < in_port[p].addrs.nelts; a++) {
531 char ip[20]; 530 char ip[20];
532 ngx_inet_ntop(AF_INET, (char *) &in_addr[a].addr, ip, 20); 531 ngx_inet_ntop(AF_INET, (char *) &in_addr[a].addr, ip, 20);
533 ngx_log_debug(cf->log, "%s %08x" _ ip _ in_addr[a].core_srv_conf); 532 ngx_log_debug(cf->log, "%s %08x" _ ip _ in_addr[a].core_srv_conf);
533 s_name = in_addr[a].names.elts;
534 for (n = 0; n < in_addr[a].names.nelts; n++) {
535 ngx_log_debug(cf->log, "%s %08x" _ s_name[n].name.data _
536 s_name[n].core_srv_conf);
537 }
534 } 538 }
535 } 539 }
536 /**/ 540 /**/
537 541
538 return NGX_CONF_OK; 542 return NGX_CONF_OK;