Mercurial > hg > nginx-quic
comparison src/http/ngx_http.c @ 501:d4ea69372b94 release-0.1.25
nginx-0.1.25-RELEASE import
*) Bugfix: nginx did run on Linux parisc.
*) Feature: nginx now does not start under FreeBSD if the sysctl
kern.ipc.somaxconn value is too big.
*) Bugfix: if a request was internally redirected by the
ngx_http_index_module module to the ngx_http_proxy_module or
ngx_http_fastcgi_module modules, then the index file was not closed
after request completion.
*) Feature: the "proxy_pass" can be used in location with regular
expression.
*) Feature: the ngx_http_rewrite_filter_module module supports the
condition like "if ($HTTP_USER_AGENT ~ MSIE)".
*) Bugfix: nginx started too slow if the large number of addresses and
text values were used in the "geo" directive.
*) Change: a variable name must be declared as "$name" in the "geo"
directive. The previous variant without "$" is still supported, but
will be removed soon.
*) Feature: the "%{VARIABLE}v" logging parameter.
*) Feature: the "set $name value" directive.
*) Bugfix: gcc 4.0 compatibility.
*) Feature: the --with-openssl-opt=OPTIONS autoconfiguration directive.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sat, 19 Mar 2005 12:38:37 +0000 |
parents | 64d9afb209da |
children | b1648294f693 |
comparison
equal
deleted
inserted
replaced
500:9a0f304470f5 | 501:d4ea69372b94 |
---|---|
90 #endif | 90 #endif |
91 | 91 |
92 | 92 |
93 /* the main http context */ | 93 /* the main http context */ |
94 | 94 |
95 if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) { | 95 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); |
96 if (ctx == NULL) { | |
96 return NGX_CONF_ERROR; | 97 return NGX_CONF_ERROR; |
97 } | 98 } |
98 | 99 |
99 *(ngx_http_conf_ctx_t **) conf = ctx; | 100 *(ngx_http_conf_ctx_t **) conf = ctx; |
100 | 101 |
160 return NGX_CONF_ERROR; | 161 return NGX_CONF_ERROR; |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
164 if (module->create_main_conf) { | 165 if (module->create_main_conf) { |
165 if (!(ctx->main_conf[mi] = module->create_main_conf(cf))) { | 166 ctx->main_conf[mi] = module->create_main_conf(cf); |
167 if (ctx->main_conf[mi] == NULL) { | |
166 return NGX_CONF_ERROR; | 168 return NGX_CONF_ERROR; |
167 } | 169 } |
168 } | 170 } |
169 | 171 |
170 if (module->create_srv_conf) { | 172 if (module->create_srv_conf) { |
171 if (!(ctx->srv_conf[mi] = module->create_srv_conf(cf))) { | 173 ctx->srv_conf[mi] = module->create_srv_conf(cf); |
174 if (ctx->srv_conf[mi] == NULL) { | |
172 return NGX_CONF_ERROR; | 175 return NGX_CONF_ERROR; |
173 } | 176 } |
174 } | 177 } |
175 | 178 |
176 if (module->create_loc_conf) { | 179 if (module->create_loc_conf) { |
177 if (!(ctx->loc_conf[mi] = module->create_loc_conf(cf))) { | 180 ctx->loc_conf[mi] = module->create_loc_conf(cf); |
181 if (ctx->loc_conf[mi] == NULL) { | |
178 return NGX_CONF_ERROR; | 182 return NGX_CONF_ERROR; |
179 } | 183 } |
180 } | 184 } |
181 } | 185 } |
182 | 186 |
259 } | 263 } |
260 } | 264 } |
261 | 265 |
262 | 266 |
263 /* we needed http{}'s cf->ctx while the merging configuration */ | 267 /* we needed http{}'s cf->ctx while the merging configuration */ |
268 | |
264 *cf = pcf; | 269 *cf = pcf; |
265 | 270 |
266 | 271 |
267 /* init lists of the handlers */ | 272 /* init lists of the handlers */ |
268 | 273 |
269 if (ngx_array_init(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers, | 274 if (ngx_array_init(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers, |
270 cf->pool, 1, sizeof(ngx_http_handler_pt)) == NGX_ERROR) | 275 cf->pool, 1, sizeof(ngx_http_handler_pt)) != NGX_OK) |
271 { | 276 { |
272 return NGX_CONF_ERROR; | 277 return NGX_CONF_ERROR; |
273 } | 278 } |
274 | 279 |
275 cmcf->phases[NGX_HTTP_REWRITE_PHASE].type = NGX_OK; | 280 cmcf->phases[NGX_HTTP_REWRITE_PHASE].type = NGX_OK; |
276 | 281 |
277 | 282 |
278 /* the special find config phase for a single handler */ | 283 /* the special find config phase for a single handler */ |
279 | 284 |
280 if (ngx_array_init(&cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].handlers, | 285 if (ngx_array_init(&cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].handlers, |
281 cf->pool, 1, sizeof(ngx_http_handler_pt)) == NGX_ERROR) | 286 cf->pool, 1, sizeof(ngx_http_handler_pt)) != NGX_OK) |
282 { | 287 { |
283 return NGX_CONF_ERROR; | 288 return NGX_CONF_ERROR; |
284 } | 289 } |
285 | 290 |
286 cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].type = NGX_OK; | 291 cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].type = NGX_OK; |
287 | 292 |
288 h = ngx_push_array(&cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].handlers); | 293 h = ngx_array_push(&cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].handlers); |
289 if (h == NULL) { | 294 if (h == NULL) { |
290 return NGX_CONF_ERROR; | 295 return NGX_CONF_ERROR; |
291 } | 296 } |
292 | 297 |
293 *h = ngx_http_find_location_config; | 298 *h = ngx_http_find_location_config; |
294 | 299 |
295 | 300 |
296 if (ngx_array_init(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers, | 301 if (ngx_array_init(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers, |
297 cf->pool, 1, sizeof(ngx_http_handler_pt)) == NGX_ERROR) | 302 cf->pool, 1, sizeof(ngx_http_handler_pt)) != NGX_OK) |
298 { | 303 { |
299 return NGX_CONF_ERROR; | 304 return NGX_CONF_ERROR; |
300 } | 305 } |
301 | 306 |
302 cmcf->phases[NGX_HTTP_ACCESS_PHASE].type = NGX_DECLINED; | 307 cmcf->phases[NGX_HTTP_ACCESS_PHASE].type = NGX_DECLINED; |
303 | 308 |
304 | 309 |
305 if (ngx_array_init(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers, | 310 if (ngx_array_init(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers, |
306 cf->pool, 4, sizeof(ngx_http_handler_pt)) == NGX_ERROR) | 311 cf->pool, 4, sizeof(ngx_http_handler_pt)) != NGX_OK) |
307 { | 312 { |
308 return NGX_CONF_ERROR; | 313 return NGX_CONF_ERROR; |
309 } | 314 } |
310 | 315 |
311 cmcf->phases[NGX_HTTP_CONTENT_PHASE].type = NGX_OK; | 316 cmcf->phases[NGX_HTTP_CONTENT_PHASE].type = NGX_OK; |
315 * create the lists of ports, addresses and server names | 320 * create the lists of ports, addresses and server names |
316 * to quickly find the server core module configuration at run-time | 321 * to quickly find the server core module configuration at run-time |
317 */ | 322 */ |
318 | 323 |
319 if (ngx_array_init(&in_ports, cf->pool, 10, sizeof(ngx_http_in_port_t)) | 324 if (ngx_array_init(&in_ports, cf->pool, 10, sizeof(ngx_http_in_port_t)) |
320 == NGX_ERROR) | 325 != NGX_OK) |
321 { | 326 { |
322 return NGX_CONF_ERROR; | 327 return NGX_CONF_ERROR; |
323 } | 328 } |
324 | 329 |
325 /* "server" directives */ | 330 /* "server" directives */ |
352 if (lscf[l].addr == in_addr[a].addr) { | 357 if (lscf[l].addr == in_addr[a].addr) { |
353 | 358 |
354 /* the address is already in the address list */ | 359 /* the address is already in the address list */ |
355 | 360 |
356 if (ngx_http_add_names(cf, &in_addr[a], cscfp[s]) | 361 if (ngx_http_add_names(cf, &in_addr[a], cscfp[s]) |
357 == NGX_ERROR) | 362 != NGX_OK) |
358 { | 363 { |
359 return NGX_CONF_ERROR; | 364 return NGX_CONF_ERROR; |
360 } | 365 } |
361 | 366 |
362 /* | 367 /* |
384 | 389 |
385 } else if (in_addr[a].addr == INADDR_ANY) { | 390 } else if (in_addr[a].addr == INADDR_ANY) { |
386 | 391 |
387 /* the INADDR_ANY is always the last address */ | 392 /* the INADDR_ANY is always the last address */ |
388 | 393 |
389 if (!(inaddr = ngx_array_push(&in_port[p].addrs))) { | 394 inaddr = ngx_array_push(&in_port[p].addrs); |
395 if (inaddr == NULL) { | |
390 return NGX_CONF_ERROR; | 396 return NGX_CONF_ERROR; |
391 } | 397 } |
392 | 398 |
393 /* | 399 /* |
394 * the INADDR_ANY must be the last resort | 400 * the INADDR_ANY must be the last resort |
405 in_addr[a].wildcards.elts = NULL; | 411 in_addr[a].wildcards.elts = NULL; |
406 in_addr[a].default_server = lscf[l].default_server; | 412 in_addr[a].default_server = lscf[l].default_server; |
407 in_addr[a].core_srv_conf = cscfp[s]; | 413 in_addr[a].core_srv_conf = cscfp[s]; |
408 | 414 |
409 if (ngx_http_add_names(cf, &in_addr[a], cscfp[s]) | 415 if (ngx_http_add_names(cf, &in_addr[a], cscfp[s]) |
410 == NGX_ERROR) | 416 != NGX_OK) |
411 { | 417 { |
412 return NGX_CONF_ERROR; | 418 return NGX_CONF_ERROR; |
413 } | 419 } |
414 | 420 |
415 addr_found = 1; | 421 addr_found = 1; |
424 * add the address to the addresses list that | 430 * add the address to the addresses list that |
425 * bound to this port | 431 * bound to this port |
426 */ | 432 */ |
427 | 433 |
428 if (ngx_http_add_address(cf, &in_port[p], &lscf[l], | 434 if (ngx_http_add_address(cf, &in_port[p], &lscf[l], |
429 cscfp[s]) == NGX_ERROR) | 435 cscfp[s]) != NGX_OK) |
430 { | 436 { |
431 return NGX_CONF_ERROR; | 437 return NGX_CONF_ERROR; |
432 } | 438 } |
433 } | 439 } |
434 } | 440 } |
436 | 442 |
437 if (!port_found) { | 443 if (!port_found) { |
438 | 444 |
439 /* add the port to the in_port list */ | 445 /* add the port to the in_port list */ |
440 | 446 |
441 if (!(in_port = ngx_array_push(&in_ports))) { | 447 in_port = ngx_array_push(&in_ports); |
448 if (in_port == NULL) { | |
442 return NGX_CONF_ERROR; | 449 return NGX_CONF_ERROR; |
443 } | 450 } |
444 | 451 |
445 in_port->port = lscf[l].port; | 452 in_port->port = lscf[l].port; |
446 in_port->addrs.elts = NULL; | 453 in_port->addrs.elts = NULL; |
447 | 454 |
448 if (!(in_port->port_text.data = ngx_palloc(cf->pool, 7))) { | 455 in_port->port_text.data = ngx_palloc(cf->pool, 7); |
456 if (in_port->port_text.data == NULL) { | |
449 return NGX_CONF_ERROR; | 457 return NGX_CONF_ERROR; |
450 } | 458 } |
451 | 459 |
452 in_port->port_text.len = ngx_sprintf(in_port->port_text.data, | 460 in_port->port_text.len = ngx_sprintf(in_port->port_text.data, |
453 ":%d", in_port->port) | 461 ":%d", in_port->port) |
454 - in_port->port_text.data; | 462 - in_port->port_text.data; |
455 | 463 |
456 if (ngx_http_add_address(cf, in_port, &lscf[l], cscfp[s]) | 464 if (ngx_http_add_address(cf, in_port, &lscf[l], cscfp[s]) |
457 == NGX_ERROR) | 465 != NGX_OK) |
458 { | 466 { |
459 return NGX_CONF_ERROR; | 467 return NGX_CONF_ERROR; |
460 } | 468 } |
461 } | 469 } |
462 } | 470 } |
482 | 490 |
483 name = in_addr[a].names.elts; | 491 name = in_addr[a].names.elts; |
484 for (n = 0; n < in_addr[a].names.nelts; n++) { | 492 for (n = 0; n < in_addr[a].names.nelts; n++) { |
485 if (in_addr[a].core_srv_conf != name[n].core_srv_conf | 493 if (in_addr[a].core_srv_conf != name[n].core_srv_conf |
486 || name[n].core_srv_conf->restrict_host_names | 494 || name[n].core_srv_conf->restrict_host_names |
487 != NGX_HTTP_RESTRICT_HOST_OFF) | 495 != NGX_HTTP_RESTRICT_HOST_OFF) |
488 { | 496 { |
489 virtual_names = 1; | 497 virtual_names = 1; |
490 break; | 498 break; |
491 } | 499 } |
492 } | 500 } |
494 if (!virtual_names) { | 502 if (!virtual_names) { |
495 name = in_addr[a].wildcards.elts; | 503 name = in_addr[a].wildcards.elts; |
496 for (n = 0; n < in_addr[a].wildcards.nelts; n++) { | 504 for (n = 0; n < in_addr[a].wildcards.nelts; n++) { |
497 if (in_addr[a].core_srv_conf != name[n].core_srv_conf | 505 if (in_addr[a].core_srv_conf != name[n].core_srv_conf |
498 || name[n].core_srv_conf->restrict_host_names | 506 || name[n].core_srv_conf->restrict_host_names |
499 != NGX_HTTP_RESTRICT_HOST_OFF) | 507 != NGX_HTTP_RESTRICT_HOST_OFF) |
500 { | 508 { |
501 virtual_names = 1; | 509 virtual_names = 1; |
502 break; | 510 break; |
503 } | 511 } |
504 } | 512 } |
530 return NGX_CONF_ERROR; | 538 return NGX_CONF_ERROR; |
531 } | 539 } |
532 | 540 |
533 for (n = 0; n < cmcf->server_names_hash; n++) { | 541 for (n = 0; n < cmcf->server_names_hash; n++) { |
534 if (ngx_array_init(&in_addr[a].hash[n], cf->pool, 5, | 542 if (ngx_array_init(&in_addr[a].hash[n], cf->pool, 5, |
535 sizeof(ngx_http_server_name_t)) == NGX_ERROR) | 543 sizeof(ngx_http_server_name_t)) != NGX_OK) |
536 { | 544 { |
537 return NGX_CONF_ERROR; | 545 return NGX_CONF_ERROR; |
538 } | 546 } |
539 } | 547 } |
540 | 548 |
542 for (s = 0; s < in_addr[a].names.nelts; s++) { | 550 for (s = 0; s < in_addr[a].names.nelts; s++) { |
543 ngx_http_server_names_hash_key(key, name[s].name.data, | 551 ngx_http_server_names_hash_key(key, name[s].name.data, |
544 name[s].name.len, | 552 name[s].name.len, |
545 cmcf->server_names_hash); | 553 cmcf->server_names_hash); |
546 | 554 |
547 if (!(s_name = ngx_array_push(&in_addr[a].hash[key]))) { | 555 s_name = ngx_array_push(&in_addr[a].hash[key]); |
556 if (s_name == NULL) { | |
548 return NGX_CONF_ERROR; | 557 return NGX_CONF_ERROR; |
549 } | 558 } |
550 | 559 |
551 *s_name = name[s]; | 560 *s_name = name[s]; |
552 } | 561 } |
573 if (ls == NULL) { | 582 if (ls == NULL) { |
574 return NGX_CONF_ERROR; | 583 return NGX_CONF_ERROR; |
575 } | 584 } |
576 | 585 |
577 ls->backlog = -1; | 586 ls->backlog = -1; |
578 #if 0 | 587 |
579 #if 0 | |
580 ls->nonblocking = 1; | |
581 #else | |
582 ls->nonblocking = 0; | |
583 #endif | |
584 #endif | |
585 ls->addr_ntop = 1; | 588 ls->addr_ntop = 1; |
586 | 589 |
587 ls->handler = ngx_http_init_connection; | 590 ls->handler = ngx_http_init_connection; |
588 | 591 |
589 cscf = in_addr[a].core_srv_conf; | 592 cscf = in_addr[a].core_srv_conf; |
610 /* | 613 /* |
611 * if this port has not the "*:port" binding then create | 614 * if this port has not the "*:port" binding then create |
612 * the separate ngx_http_in_port_t for the all bindings | 615 * the separate ngx_http_in_port_t for the all bindings |
613 */ | 616 */ |
614 | 617 |
615 ngx_test_null(inport, | 618 inport = ngx_palloc(cf->pool, sizeof(ngx_http_in_port_t)); |
616 ngx_palloc(cf->pool, | 619 if (inport == NULL) { |
617 sizeof(ngx_http_in_port_t)), | 620 return NGX_CONF_ERROR; |
618 NGX_CONF_ERROR); | 621 } |
619 | 622 |
620 inport->port = in_port[p].port; | 623 inport->port = in_port[p].port; |
621 inport->port_text = in_port[p].port_text; | 624 inport->port_text = in_port[p].port_text; |
622 | 625 |
623 /* init list of the addresses ... */ | 626 /* init list of the addresses ... */ |
624 | 627 |
625 ngx_init_array(inport->addrs, cf->pool, 1, | 628 if (ngx_array_init(&inport->addrs, cf->pool, 1, |
626 sizeof(ngx_http_in_addr_t), | 629 sizeof(ngx_http_in_addr_t)) != NGX_OK) |
627 NGX_CONF_ERROR); | 630 { |
631 return NGX_CONF_ERROR; | |
632 } | |
628 | 633 |
629 /* ... and set up it with the first address */ | 634 /* ... and set up it with the first address */ |
630 | 635 |
631 inport->addrs.nelts = 1; | 636 inport->addrs.nelts = 1; |
632 inport->addrs.elts = in_port[p].addrs.elts; | 637 inport->addrs.elts = in_port[p].addrs.elts; |
634 ls->servers = inport; | 639 ls->servers = inport; |
635 | 640 |
636 /* prepare for the next cycle */ | 641 /* prepare for the next cycle */ |
637 | 642 |
638 in_port[p].addrs.elts = (char *) in_port[p].addrs.elts | 643 in_port[p].addrs.elts = (char *) in_port[p].addrs.elts |
639 + in_port[p].addrs.size; | 644 + in_port[p].addrs.size; |
640 in_port[p].addrs.nelts--; | 645 in_port[p].addrs.nelts--; |
641 | 646 |
642 in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts; | 647 in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts; |
643 a = 0; | 648 a = 0; |
644 | 649 |
703 { | 708 { |
704 ngx_http_in_addr_t *in_addr; | 709 ngx_http_in_addr_t *in_addr; |
705 | 710 |
706 if (in_port->addrs.elts == NULL) { | 711 if (in_port->addrs.elts == NULL) { |
707 if (ngx_array_init(&in_port->addrs, cf->pool, 10, | 712 if (ngx_array_init(&in_port->addrs, cf->pool, 10, |
708 sizeof(ngx_http_in_addr_t)) == NGX_ERROR) | 713 sizeof(ngx_http_in_addr_t)) != NGX_OK) |
709 { | 714 { |
710 return NGX_ERROR; | 715 return NGX_ERROR; |
711 } | 716 } |
712 } | 717 } |
713 | 718 |
714 if (!(in_addr = ngx_array_push(&in_port->addrs))) { | 719 in_addr = ngx_array_push(&in_port->addrs); |
720 if (in_addr == NULL) { | |
715 return NGX_ERROR; | 721 return NGX_ERROR; |
716 } | 722 } |
717 | 723 |
718 in_addr->addr = lscf->addr; | 724 in_addr->addr = lscf->addr; |
719 in_addr->names.elts = NULL; | 725 in_addr->names.elts = NULL; |
748 ngx_array_t *array; | 754 ngx_array_t *array; |
749 ngx_http_server_name_t *server_names, *name; | 755 ngx_http_server_name_t *server_names, *name; |
750 | 756 |
751 if (in_addr->names.elts == NULL) { | 757 if (in_addr->names.elts == NULL) { |
752 if (ngx_array_init(&in_addr->names, cf->pool, 10, | 758 if (ngx_array_init(&in_addr->names, cf->pool, 10, |
753 sizeof(ngx_http_server_name_t)) == NGX_ERROR) | 759 sizeof(ngx_http_server_name_t)) != NGX_OK) |
754 { | 760 { |
755 return NGX_ERROR; | 761 return NGX_ERROR; |
756 } | 762 } |
757 } | 763 } |
758 | 764 |
759 if (in_addr->wildcards.elts == NULL) { | 765 if (in_addr->wildcards.elts == NULL) { |
760 if (ngx_array_init(&in_addr->wildcards, cf->pool, 10, | 766 if (ngx_array_init(&in_addr->wildcards, cf->pool, 10, |
761 sizeof(ngx_http_server_name_t)) == NGX_ERROR) | 767 sizeof(ngx_http_server_name_t)) != NGX_OK) |
762 { | 768 { |
763 return NGX_ERROR; | 769 return NGX_ERROR; |
764 } | 770 } |
765 } | 771 } |
766 | 772 |
783 | 789 |
784 } else { | 790 } else { |
785 array = &in_addr->names; | 791 array = &in_addr->names; |
786 } | 792 } |
787 | 793 |
788 if (!(name = ngx_array_push(array))) { | 794 name = ngx_array_push(array); |
795 if (name == NULL) { | |
789 return NGX_ERROR; | 796 return NGX_ERROR; |
790 } | 797 } |
791 | 798 |
792 *name = server_names[i]; | 799 *name = server_names[i]; |
793 } | 800 } |