comparison src/http/ngx_http.c @ 635:e67b227c8dbb default tip

Merge with current.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 25 Apr 2011 04:07:55 +0400
parents 7ea1bba9a4f6
children
comparison
equal deleted inserted replaced
578:f3a9e57d2e17 635:e67b227c8dbb
24 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port, 24 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port,
25 ngx_http_listen_opt_t *lsopt); 25 ngx_http_listen_opt_t *lsopt);
26 static ngx_int_t ngx_http_add_server(ngx_conf_t *cf, 26 static ngx_int_t ngx_http_add_server(ngx_conf_t *cf,
27 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_addr_t *addr); 27 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_addr_t *addr);
28 28
29 static char *ngx_http_merge_servers(ngx_conf_t *cf,
30 ngx_http_core_main_conf_t *cmcf, ngx_http_module_t *module,
31 ngx_uint_t ctx_index);
29 static char *ngx_http_merge_locations(ngx_conf_t *cf, 32 static char *ngx_http_merge_locations(ngx_conf_t *cf,
30 ngx_queue_t *locations, void **loc_conf, ngx_http_module_t *module, 33 ngx_queue_t *locations, void **loc_conf, ngx_http_module_t *module,
31 ngx_uint_t ctx_index); 34 ngx_uint_t ctx_index);
32 static ngx_int_t ngx_http_init_locations(ngx_conf_t *cf, 35 static ngx_int_t ngx_http_init_locations(ngx_conf_t *cf,
33 ngx_http_core_srv_conf_t *cscf, ngx_http_core_loc_conf_t *pclcf); 36 ngx_http_core_srv_conf_t *cscf, ngx_http_core_loc_conf_t *pclcf);
261 if (rv != NGX_CONF_OK) { 264 if (rv != NGX_CONF_OK) {
262 goto failed; 265 goto failed;
263 } 266 }
264 } 267 }
265 268
266 for (s = 0; s < cmcf->servers.nelts; s++) { 269 rv = ngx_http_merge_servers(cf, cmcf, module, mi);
267 270 if (rv != NGX_CONF_OK) {
268 /* merge the server{}s' srv_conf's */ 271 goto failed;
269
270 if (module->merge_srv_conf) {
271 rv = module->merge_srv_conf(cf, ctx->srv_conf[mi],
272 cscfp[s]->ctx->srv_conf[mi]);
273 if (rv != NGX_CONF_OK) {
274 goto failed;
275 }
276 }
277
278 if (module->merge_loc_conf) {
279
280 /* merge the server{}'s loc_conf */
281
282 rv = module->merge_loc_conf(cf, ctx->loc_conf[mi],
283 cscfp[s]->ctx->loc_conf[mi]);
284 if (rv != NGX_CONF_OK) {
285 goto failed;
286 }
287
288 /* merge the locations{}' loc_conf's */
289
290 clcf = cscfp[s]->ctx->loc_conf[ngx_http_core_module.ctx_index];
291
292 rv = ngx_http_merge_locations(cf, clcf->locations,
293 cscfp[s]->ctx->loc_conf,
294 module, mi);
295 if (rv != NGX_CONF_OK) {
296 goto failed;
297 }
298 }
299 } 272 }
300 } 273 }
301 274
302 275
303 /* create location trees */ 276 /* create location trees */
507 480
508 case NGX_HTTP_SERVER_REWRITE_PHASE: 481 case NGX_HTTP_SERVER_REWRITE_PHASE:
509 if (cmcf->phase_engine.server_rewrite_index == (ngx_uint_t) -1) { 482 if (cmcf->phase_engine.server_rewrite_index == (ngx_uint_t) -1) {
510 cmcf->phase_engine.server_rewrite_index = n; 483 cmcf->phase_engine.server_rewrite_index = n;
511 } 484 }
512 checker = ngx_http_core_generic_phase; 485 checker = ngx_http_core_rewrite_phase;
513 486
514 break; 487 break;
515 488
516 case NGX_HTTP_FIND_CONFIG_PHASE: 489 case NGX_HTTP_FIND_CONFIG_PHASE:
517 find_config_index = n; 490 find_config_index = n;
524 497
525 case NGX_HTTP_REWRITE_PHASE: 498 case NGX_HTTP_REWRITE_PHASE:
526 if (cmcf->phase_engine.location_rewrite_index == (ngx_uint_t) -1) { 499 if (cmcf->phase_engine.location_rewrite_index == (ngx_uint_t) -1) {
527 cmcf->phase_engine.location_rewrite_index = n; 500 cmcf->phase_engine.location_rewrite_index = n;
528 } 501 }
529 checker = ngx_http_core_generic_phase; 502 checker = ngx_http_core_rewrite_phase;
530 503
531 break; 504 break;
532 505
533 case NGX_HTTP_POST_REWRITE_PHASE: 506 case NGX_HTTP_POST_REWRITE_PHASE:
534 if (use_rewrite) { 507 if (use_rewrite) {
584 return NGX_OK; 557 return NGX_OK;
585 } 558 }
586 559
587 560
588 static char * 561 static char *
562 ngx_http_merge_servers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf,
563 ngx_http_module_t *module, ngx_uint_t ctx_index)
564 {
565 char *rv;
566 ngx_uint_t s;
567 ngx_http_conf_ctx_t *ctx, saved;
568 ngx_http_core_loc_conf_t *clcf;
569 ngx_http_core_srv_conf_t **cscfp;
570
571 cscfp = cmcf->servers.elts;
572 ctx = (ngx_http_conf_ctx_t *) cf->ctx;
573 saved = *ctx;
574 rv = NGX_CONF_OK;
575
576 for (s = 0; s < cmcf->servers.nelts; s++) {
577
578 /* merge the server{}s' srv_conf's */
579
580 ctx->srv_conf = cscfp[s]->ctx->srv_conf;
581
582 if (module->merge_srv_conf) {
583 rv = module->merge_srv_conf(cf, saved.srv_conf[ctx_index],
584 cscfp[s]->ctx->srv_conf[ctx_index]);
585 if (rv != NGX_CONF_OK) {
586 goto failed;
587 }
588 }
589
590 if (module->merge_loc_conf) {
591
592 /* merge the server{}'s loc_conf */
593
594 ctx->loc_conf = cscfp[s]->ctx->loc_conf;
595
596 rv = module->merge_loc_conf(cf, saved.loc_conf[ctx_index],
597 cscfp[s]->ctx->loc_conf[ctx_index]);
598 if (rv != NGX_CONF_OK) {
599 goto failed;
600 }
601
602 /* merge the locations{}' loc_conf's */
603
604 clcf = cscfp[s]->ctx->loc_conf[ngx_http_core_module.ctx_index];
605
606 rv = ngx_http_merge_locations(cf, clcf->locations,
607 cscfp[s]->ctx->loc_conf,
608 module, ctx_index);
609 if (rv != NGX_CONF_OK) {
610 goto failed;
611 }
612 }
613 }
614
615 failed:
616
617 *ctx = saved;
618
619 return rv;
620 }
621
622
623 static char *
589 ngx_http_merge_locations(ngx_conf_t *cf, ngx_queue_t *locations, 624 ngx_http_merge_locations(ngx_conf_t *cf, ngx_queue_t *locations,
590 void **loc_conf, ngx_http_module_t *module, ngx_uint_t ctx_index) 625 void **loc_conf, ngx_http_module_t *module, ngx_uint_t ctx_index)
591 { 626 {
592 char *rv; 627 char *rv;
593 ngx_queue_t *q; 628 ngx_queue_t *q;
629 ngx_http_conf_ctx_t *ctx, saved;
594 ngx_http_core_loc_conf_t *clcf; 630 ngx_http_core_loc_conf_t *clcf;
595 ngx_http_location_queue_t *lq; 631 ngx_http_location_queue_t *lq;
596 632
597 if (locations == NULL) { 633 if (locations == NULL) {
598 return NGX_CONF_OK; 634 return NGX_CONF_OK;
599 } 635 }
636
637 ctx = (ngx_http_conf_ctx_t *) cf->ctx;
638 saved = *ctx;
600 639
601 for (q = ngx_queue_head(locations); 640 for (q = ngx_queue_head(locations);
602 q != ngx_queue_sentinel(locations); 641 q != ngx_queue_sentinel(locations);
603 q = ngx_queue_next(q)) 642 q = ngx_queue_next(q))
604 { 643 {
605 lq = (ngx_http_location_queue_t *) q; 644 lq = (ngx_http_location_queue_t *) q;
606 645
607 clcf = lq->exact ? lq->exact : lq->inclusive; 646 clcf = lq->exact ? lq->exact : lq->inclusive;
647 ctx->loc_conf = clcf->loc_conf;
608 648
609 rv = module->merge_loc_conf(cf, loc_conf[ctx_index], 649 rv = module->merge_loc_conf(cf, loc_conf[ctx_index],
610 clcf->loc_conf[ctx_index]); 650 clcf->loc_conf[ctx_index]);
611 if (rv != NGX_CONF_OK) { 651 if (rv != NGX_CONF_OK) {
612 return rv; 652 return rv;
616 module, ctx_index); 656 module, ctx_index);
617 if (rv != NGX_CONF_OK) { 657 if (rv != NGX_CONF_OK) {
618 return rv; 658 return rv;
619 } 659 }
620 } 660 }
661
662 *ctx = saved;
621 663
622 return NGX_CONF_OK; 664 return NGX_CONF_OK;
623 } 665 }
624 666
625 667
1177 struct sockaddr *sa; 1219 struct sockaddr *sa;
1178 ngx_http_conf_addr_t *addr; 1220 ngx_http_conf_addr_t *addr;
1179 #if (NGX_HAVE_UNIX_DOMAIN) 1221 #if (NGX_HAVE_UNIX_DOMAIN)
1180 struct sockaddr_un *saun; 1222 struct sockaddr_un *saun;
1181 #endif 1223 #endif
1224 #if (NGX_HTTP_SSL)
1225 ngx_uint_t ssl;
1226 #endif
1182 1227
1183 /* 1228 /*
1184 * we can not compare whole sockaddr struct's as kernel 1229 * we can not compare whole sockaddr struct's as kernel
1185 * may fill some fields in inherited sockaddr struct's 1230 * may fill some fields in inherited sockaddr struct's
1186 */ 1231 */
1226 } 1271 }
1227 1272
1228 /* preserve default_server bit during listen options overwriting */ 1273 /* preserve default_server bit during listen options overwriting */
1229 default_server = addr[i].opt.default_server; 1274 default_server = addr[i].opt.default_server;
1230 1275
1276 #if (NGX_HTTP_SSL)
1277 ssl = lsopt->ssl || addr[i].opt.ssl;
1278 #endif
1279
1231 if (lsopt->set) { 1280 if (lsopt->set) {
1232 1281
1233 if (addr[i].opt.set) { 1282 if (addr[i].opt.set) {
1234 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 1283 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1235 "a duplicate listen options for %s", addr[i].opt.addr); 1284 "a duplicate listen options for %s", addr[i].opt.addr);
1252 default_server = 1; 1301 default_server = 1;
1253 addr[i].default_server = cscf; 1302 addr[i].default_server = cscf;
1254 } 1303 }
1255 1304
1256 addr[i].opt.default_server = default_server; 1305 addr[i].opt.default_server = default_server;
1306 #if (NGX_HTTP_SSL)
1307 addr[i].opt.ssl = ssl;
1308 #endif
1257 1309
1258 return NGX_OK; 1310 return NGX_OK;
1259 } 1311 }
1260 1312
1261 /* add the address to the addresses list that bound to this port */ 1313 /* add the address to the addresses list that bound to this port */
1448 &name[n].name, addr->opt.addr); 1500 &name[n].name, addr->opt.addr);
1449 return NGX_ERROR; 1501 return NGX_ERROR;
1450 } 1502 }
1451 1503
1452 if (rc == NGX_BUSY) { 1504 if (rc == NGX_BUSY) {
1453 ngx_log_error(NGX_LOG_WARN, cf->log, 0, 1505 ngx_log_error(NGX_LOG_WARN, cf->log, 0,
1454 "conflicting server name \"%V\" on %s, ignored", 1506 "conflicting server name \"%V\" on %s, ignored",
1455 &name[n].name, addr->opt.addr); 1507 &name[n].name, addr->opt.addr);
1456 } 1508 }
1457 } 1509 }
1458 } 1510 }
1716 ls->deferred_accept = addr->opt.deferred_accept; 1768 ls->deferred_accept = addr->opt.deferred_accept;
1717 #endif 1769 #endif
1718 1770
1719 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) 1771 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
1720 ls->ipv6only = addr->opt.ipv6only; 1772 ls->ipv6only = addr->opt.ipv6only;
1773 #endif
1774
1775 #if (NGX_HAVE_SETFIB)
1776 ls->setfib = addr->opt.setfib;
1721 #endif 1777 #endif
1722 1778
1723 return ls; 1779 return ls;
1724 } 1780 }
1725 1781
1812 #endif 1868 #endif
1813 1869
1814 if (addr[i].hash.buckets == NULL 1870 if (addr[i].hash.buckets == NULL
1815 && (addr[i].wc_head == NULL 1871 && (addr[i].wc_head == NULL
1816 || addr[i].wc_head->hash.buckets == NULL) 1872 || addr[i].wc_head->hash.buckets == NULL)
1817 && (addr[i].wc_head == NULL 1873 && (addr[i].wc_tail == NULL
1818 || addr[i].wc_head->hash.buckets == NULL)) 1874 || addr[i].wc_tail->hash.buckets == NULL)
1875 #if (NGX_PCRE)
1876 && addr[i].nregex == 0
1877 #endif
1878 )
1819 { 1879 {
1820 continue; 1880 continue;
1821 } 1881 }
1822 1882
1823 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t)); 1883 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t));