comparison src/http/ngx_http.c @ 665:0b460e61bdcd default tip

Merge with nginx 1.0.0.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 25 Apr 2011 04:22:17 +0400
parents 7ea1bba9a4f6
children
comparison
equal deleted inserted replaced
572:06419a2298a9 665:0b460e61bdcd
15 static ngx_int_t ngx_http_init_headers_in_hash(ngx_conf_t *cf, 15 static ngx_int_t ngx_http_init_headers_in_hash(ngx_conf_t *cf,
16 ngx_http_core_main_conf_t *cmcf); 16 ngx_http_core_main_conf_t *cmcf);
17 static ngx_int_t ngx_http_init_phase_handlers(ngx_conf_t *cf, 17 static ngx_int_t ngx_http_init_phase_handlers(ngx_conf_t *cf,
18 ngx_http_core_main_conf_t *cmcf); 18 ngx_http_core_main_conf_t *cmcf);
19 19
20 static ngx_int_t ngx_http_init_server_lists(ngx_conf_t *cf,
21 ngx_array_t *servers, ngx_array_t *ports);
22 static ngx_int_t ngx_http_add_ports(ngx_conf_t *cf,
23 ngx_http_core_srv_conf_t *cscf, ngx_array_t *ports,
24 ngx_http_listen_t *listen);
25 static ngx_int_t ngx_http_add_addresses(ngx_conf_t *cf, 20 static ngx_int_t ngx_http_add_addresses(ngx_conf_t *cf,
26 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port, 21 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port,
27 ngx_http_listen_t *listen); 22 ngx_http_listen_opt_t *lsopt);
28 static ngx_int_t ngx_http_add_address(ngx_conf_t *cf, 23 static ngx_int_t ngx_http_add_address(ngx_conf_t *cf,
29 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,
30 ngx_http_listen_t *listen); 25 ngx_http_listen_opt_t *lsopt);
31 static ngx_int_t ngx_http_add_names(ngx_conf_t *cf, 26 static ngx_int_t ngx_http_add_server(ngx_conf_t *cf,
32 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);
33 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);
34 static char *ngx_http_merge_locations(ngx_conf_t *cf, 32 static char *ngx_http_merge_locations(ngx_conf_t *cf,
35 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,
36 ngx_uint_t ctx_index); 34 ngx_uint_t ctx_index);
37 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,
38 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);
120 ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 118 ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
121 { 119 {
122 char *rv; 120 char *rv;
123 ngx_uint_t mi, m, s; 121 ngx_uint_t mi, m, s;
124 ngx_conf_t pcf; 122 ngx_conf_t pcf;
125 ngx_array_t ports;
126 ngx_http_module_t *module; 123 ngx_http_module_t *module;
127 ngx_http_conf_ctx_t *ctx; 124 ngx_http_conf_ctx_t *ctx;
128 ngx_http_core_loc_conf_t *clcf; 125 ngx_http_core_loc_conf_t *clcf;
129 ngx_http_core_srv_conf_t **cscfp; 126 ngx_http_core_srv_conf_t **cscfp;
130 ngx_http_core_main_conf_t *cmcf; 127 ngx_http_core_main_conf_t *cmcf;
267 if (rv != NGX_CONF_OK) { 264 if (rv != NGX_CONF_OK) {
268 goto failed; 265 goto failed;
269 } 266 }
270 } 267 }
271 268
272 for (s = 0; s < cmcf->servers.nelts; s++) { 269 rv = ngx_http_merge_servers(cf, cmcf, module, mi);
273 270 if (rv != NGX_CONF_OK) {
274 /* merge the server{}s' srv_conf's */ 271 goto failed;
275
276 if (module->merge_srv_conf) {
277 rv = module->merge_srv_conf(cf, ctx->srv_conf[mi],
278 cscfp[s]->ctx->srv_conf[mi]);
279 if (rv != NGX_CONF_OK) {
280 goto failed;
281 }
282 }
283
284 if (module->merge_loc_conf) {
285
286 /* merge the server{}'s loc_conf */
287
288 rv = module->merge_loc_conf(cf, ctx->loc_conf[mi],
289 cscfp[s]->ctx->loc_conf[mi]);
290 if (rv != NGX_CONF_OK) {
291 goto failed;
292 }
293
294 /* merge the locations{}' loc_conf's */
295
296 clcf = cscfp[s]->ctx->loc_conf[ngx_http_core_module.ctx_index];
297
298 rv = ngx_http_merge_locations(cf, clcf->locations,
299 cscfp[s]->ctx->loc_conf,
300 module, mi);
301 if (rv != NGX_CONF_OK) {
302 goto failed;
303 }
304 }
305 } 272 }
306 } 273 }
307 274
308 275
309 /* create location trees */ 276 /* create location trees */
360 if (ngx_http_init_phase_handlers(cf, cmcf) != NGX_OK) { 327 if (ngx_http_init_phase_handlers(cf, cmcf) != NGX_OK) {
361 return NGX_CONF_ERROR; 328 return NGX_CONF_ERROR;
362 } 329 }
363 330
364 331
365 /*
366 * create the lists of ports, addresses and server names
367 * to find quickly the server core module configuration at run-time
368 */
369
370 if (ngx_http_init_server_lists(cf, &cmcf->servers, &ports) != NGX_OK) {
371 return NGX_CONF_ERROR;
372 }
373
374
375 /* optimize the lists of ports, addresses and server names */ 332 /* optimize the lists of ports, addresses and server names */
376 333
377 if (ngx_http_optimize_servers(cf, cmcf, &ports) != NGX_OK) { 334 if (ngx_http_optimize_servers(cf, cmcf, cmcf->ports) != NGX_OK) {
378 return NGX_CONF_ERROR; 335 return NGX_CONF_ERROR;
379 } 336 }
380 337
381 return NGX_CONF_OK; 338 return NGX_CONF_OK;
382 339
523 480
524 case NGX_HTTP_SERVER_REWRITE_PHASE: 481 case NGX_HTTP_SERVER_REWRITE_PHASE:
525 if (cmcf->phase_engine.server_rewrite_index == (ngx_uint_t) -1) { 482 if (cmcf->phase_engine.server_rewrite_index == (ngx_uint_t) -1) {
526 cmcf->phase_engine.server_rewrite_index = n; 483 cmcf->phase_engine.server_rewrite_index = n;
527 } 484 }
528 checker = ngx_http_core_generic_phase; 485 checker = ngx_http_core_rewrite_phase;
529 486
530 break; 487 break;
531 488
532 case NGX_HTTP_FIND_CONFIG_PHASE: 489 case NGX_HTTP_FIND_CONFIG_PHASE:
533 find_config_index = n; 490 find_config_index = n;
540 497
541 case NGX_HTTP_REWRITE_PHASE: 498 case NGX_HTTP_REWRITE_PHASE:
542 if (cmcf->phase_engine.location_rewrite_index == (ngx_uint_t) -1) { 499 if (cmcf->phase_engine.location_rewrite_index == (ngx_uint_t) -1) {
543 cmcf->phase_engine.location_rewrite_index = n; 500 cmcf->phase_engine.location_rewrite_index = n;
544 } 501 }
545 checker = ngx_http_core_generic_phase; 502 checker = ngx_http_core_rewrite_phase;
546 503
547 break; 504 break;
548 505
549 case NGX_HTTP_POST_REWRITE_PHASE: 506 case NGX_HTTP_POST_REWRITE_PHASE:
550 if (use_rewrite) { 507 if (use_rewrite) {
600 return NGX_OK; 557 return NGX_OK;
601 } 558 }
602 559
603 560
604 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 *
605 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,
606 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)
607 { 626 {
608 char *rv; 627 char *rv;
609 ngx_queue_t *q; 628 ngx_queue_t *q;
629 ngx_http_conf_ctx_t *ctx, saved;
610 ngx_http_core_loc_conf_t *clcf; 630 ngx_http_core_loc_conf_t *clcf;
611 ngx_http_location_queue_t *lq; 631 ngx_http_location_queue_t *lq;
612 632
613 if (locations == NULL) { 633 if (locations == NULL) {
614 return NGX_CONF_OK; 634 return NGX_CONF_OK;
615 } 635 }
636
637 ctx = (ngx_http_conf_ctx_t *) cf->ctx;
638 saved = *ctx;
616 639
617 for (q = ngx_queue_head(locations); 640 for (q = ngx_queue_head(locations);
618 q != ngx_queue_sentinel(locations); 641 q != ngx_queue_sentinel(locations);
619 q = ngx_queue_next(q)) 642 q = ngx_queue_next(q))
620 { 643 {
621 lq = (ngx_http_location_queue_t *) q; 644 lq = (ngx_http_location_queue_t *) q;
622 645
623 clcf = lq->exact ? lq->exact : lq->inclusive; 646 clcf = lq->exact ? lq->exact : lq->inclusive;
647 ctx->loc_conf = clcf->loc_conf;
624 648
625 rv = module->merge_loc_conf(cf, loc_conf[ctx_index], 649 rv = module->merge_loc_conf(cf, loc_conf[ctx_index],
626 clcf->loc_conf[ctx_index]); 650 clcf->loc_conf[ctx_index]);
627 if (rv != NGX_CONF_OK) { 651 if (rv != NGX_CONF_OK) {
628 return rv; 652 return rv;
632 module, ctx_index); 656 module, ctx_index);
633 if (rv != NGX_CONF_OK) { 657 if (rv != NGX_CONF_OK) {
634 return rv; 658 return rv;
635 } 659 }
636 } 660 }
661
662 *ctx = saved;
637 663
638 return NGX_CONF_OK; 664 return NGX_CONF_OK;
639 } 665 }
640 666
641 667
1107 1133
1108 return node; 1134 return node;
1109 } 1135 }
1110 1136
1111 1137
1112 static ngx_int_t 1138 ngx_int_t
1113 ngx_http_init_server_lists(ngx_conf_t *cf, ngx_array_t *servers, 1139 ngx_http_add_listen(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
1114 ngx_array_t *ports) 1140 ngx_http_listen_opt_t *lsopt)
1115 { 1141 {
1116 ngx_uint_t s, i; 1142 in_port_t p;
1117 ngx_http_listen_t *listen; 1143 ngx_uint_t i;
1118 ngx_http_core_srv_conf_t **cscfp; 1144 struct sockaddr *sa;
1119 1145 struct sockaddr_in *sin;
1120 if (ngx_array_init(ports, cf->temp_pool, 2, sizeof(ngx_http_conf_port_t)) 1146 ngx_http_conf_port_t *port;
1121 != NGX_OK) 1147 ngx_http_core_main_conf_t *cmcf;
1122 {
1123 return NGX_ERROR;
1124 }
1125
1126 /* "server" directives */
1127
1128 cscfp = servers->elts;
1129 for (s = 0; s < servers->nelts; s++) {
1130
1131 /* "listen" directives */
1132
1133 listen = cscfp[s]->listen.elts;
1134 for (i = 0; i < cscfp[s]->listen.nelts; i++) {
1135
1136 if (ngx_http_add_ports(cf, cscfp[s], ports, &listen[i]) != NGX_OK) {
1137 return NGX_ERROR;
1138 }
1139 }
1140 }
1141
1142 return NGX_OK;
1143 }
1144
1145
1146 static ngx_int_t
1147 ngx_http_add_ports(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
1148 ngx_array_t *ports, ngx_http_listen_t *listen)
1149 {
1150 in_port_t p;
1151 ngx_uint_t i;
1152 struct sockaddr *sa;
1153 struct sockaddr_in *sin;
1154 ngx_http_conf_port_t *port;
1155 #if (NGX_HAVE_INET6) 1148 #if (NGX_HAVE_INET6)
1156 struct sockaddr_in6 *sin6; 1149 struct sockaddr_in6 *sin6;
1157 #endif 1150 #endif
1158 1151
1159 sa = (struct sockaddr *) &listen->sockaddr; 1152 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
1153
1154 if (cmcf->ports == NULL) {
1155 cmcf->ports = ngx_array_create(cf->temp_pool, 2,
1156 sizeof(ngx_http_conf_port_t));
1157 if (cmcf->ports == NULL) {
1158 return NGX_ERROR;
1159 }
1160 }
1161
1162 sa = &lsopt->u.sockaddr;
1160 1163
1161 switch (sa->sa_family) { 1164 switch (sa->sa_family) {
1162 1165
1163 #if (NGX_HAVE_INET6) 1166 #if (NGX_HAVE_INET6)
1164 case AF_INET6: 1167 case AF_INET6:
1165 sin6 = (struct sockaddr_in6 *) sa; 1168 sin6 = &lsopt->u.sockaddr_in6;
1166 p = sin6->sin6_port; 1169 p = sin6->sin6_port;
1167 break; 1170 break;
1168 #endif 1171 #endif
1169 1172
1173 #if (NGX_HAVE_UNIX_DOMAIN)
1174 case AF_UNIX:
1175 p = 0;
1176 break;
1177 #endif
1178
1170 default: /* AF_INET */ 1179 default: /* AF_INET */
1171 sin = (struct sockaddr_in *) sa; 1180 sin = &lsopt->u.sockaddr_in;
1172 p = sin->sin_port; 1181 p = sin->sin_port;
1173 break; 1182 break;
1174 } 1183 }
1175 1184
1176 port = ports->elts; 1185 port = cmcf->ports->elts;
1177 for (i = 0; i < ports->nelts; i++) { 1186 for (i = 0; i < cmcf->ports->nelts; i++) {
1178 1187
1179 if (p != port[i].port || sa->sa_family != port[i].family) { 1188 if (p != port[i].port || sa->sa_family != port[i].family) {
1180 continue; 1189 continue;
1181 } 1190 }
1182 1191
1183 /* a port is already in the port list */ 1192 /* a port is already in the port list */
1184 1193
1185 return ngx_http_add_addresses(cf, cscf, &port[i], listen); 1194 return ngx_http_add_addresses(cf, cscf, &port[i], lsopt);
1186 } 1195 }
1187 1196
1188 /* add a port to the port list */ 1197 /* add a port to the port list */
1189 1198
1190 port = ngx_array_push(ports); 1199 port = ngx_array_push(cmcf->ports);
1191 if (port == NULL) { 1200 if (port == NULL) {
1192 return NGX_ERROR; 1201 return NGX_ERROR;
1193 } 1202 }
1194 1203
1195 port->family = sa->sa_family; 1204 port->family = sa->sa_family;
1196 port->port = p; 1205 port->port = p;
1197 port->addrs.elts = NULL; 1206 port->addrs.elts = NULL;
1198 1207
1199 return ngx_http_add_address(cf, cscf, port, listen); 1208 return ngx_http_add_address(cf, cscf, port, lsopt);
1200 } 1209 }
1201 1210
1202 1211
1203 static ngx_int_t 1212 static ngx_int_t
1204 ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, 1213 ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
1205 ngx_http_conf_port_t *port, ngx_http_listen_t *listen) 1214 ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt)
1206 { 1215 {
1207 u_char *p; 1216 u_char *p;
1208 size_t len, off; 1217 size_t len, off;
1209 ngx_uint_t i; 1218 ngx_uint_t i, default_server;
1210 struct sockaddr *sa; 1219 struct sockaddr *sa;
1211 ngx_http_conf_addr_t *addr; 1220 ngx_http_conf_addr_t *addr;
1221 #if (NGX_HAVE_UNIX_DOMAIN)
1222 struct sockaddr_un *saun;
1223 #endif
1224 #if (NGX_HTTP_SSL)
1225 ngx_uint_t ssl;
1226 #endif
1212 1227
1213 /* 1228 /*
1214 * we can not compare whole sockaddr struct's as kernel 1229 * we can not compare whole sockaddr struct's as kernel
1215 * may fill some fields in inherited sockaddr struct's 1230 * may fill some fields in inherited sockaddr struct's
1216 */ 1231 */
1217 1232
1218 sa = (struct sockaddr *) &listen->sockaddr; 1233 sa = &lsopt->u.sockaddr;
1219 1234
1220 switch (sa->sa_family) { 1235 switch (sa->sa_family) {
1221 1236
1222 #if (NGX_HAVE_INET6) 1237 #if (NGX_HAVE_INET6)
1223 case AF_INET6: 1238 case AF_INET6:
1224 off = offsetof(struct sockaddr_in6, sin6_addr); 1239 off = offsetof(struct sockaddr_in6, sin6_addr);
1225 len = 16; 1240 len = 16;
1226 break; 1241 break;
1227 #endif 1242 #endif
1228 1243
1244 #if (NGX_HAVE_UNIX_DOMAIN)
1245 case AF_UNIX:
1246 off = offsetof(struct sockaddr_un, sun_path);
1247 len = sizeof(saun->sun_path);
1248 break;
1249 #endif
1250
1229 default: /* AF_INET */ 1251 default: /* AF_INET */
1230 off = offsetof(struct sockaddr_in, sin_addr); 1252 off = offsetof(struct sockaddr_in, sin_addr);
1231 len = 4; 1253 len = 4;
1232 break; 1254 break;
1233 } 1255 }
1234 1256
1235 p = listen->sockaddr + off; 1257 p = lsopt->u.sockaddr_data + off;
1236 1258
1237 addr = port->addrs.elts; 1259 addr = port->addrs.elts;
1238 1260
1239 for (i = 0; i < port->addrs.nelts; i++) { 1261 for (i = 0; i < port->addrs.nelts; i++) {
1240 1262
1241 if (ngx_memcmp(p, (u_char *) addr[i].sockaddr + off, len) != 0) { 1263 if (ngx_memcmp(p, addr[i].opt.u.sockaddr_data + off, len) != 0) {
1242 continue; 1264 continue;
1243 } 1265 }
1244 1266
1245 /* the address is already in the address list */ 1267 /* the address is already in the address list */
1246 1268
1247 if (ngx_http_add_names(cf, cscf, &addr[i]) != NGX_OK) { 1269 if (ngx_http_add_server(cf, cscf, &addr[i]) != NGX_OK) {
1248 return NGX_ERROR; 1270 return NGX_ERROR;
1249 } 1271 }
1250 1272
1273 /* preserve default_server bit during listen options overwriting */
1274 default_server = addr[i].opt.default_server;
1275
1276 #if (NGX_HTTP_SSL)
1277 ssl = lsopt->ssl || addr[i].opt.ssl;
1278 #endif
1279
1280 if (lsopt->set) {
1281
1282 if (addr[i].opt.set) {
1283 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1284 "a duplicate listen options for %s", addr[i].opt.addr);
1285 return NGX_ERROR;
1286 }
1287
1288 addr[i].opt = *lsopt;
1289 }
1290
1251 /* check the duplicate "default" server for this address:port */ 1291 /* check the duplicate "default" server for this address:port */
1252 1292
1253 if (listen->conf.default_server) { 1293 if (lsopt->default_server) {
1254 1294
1255 if (addr[i].default_server) { 1295 if (default_server) {
1256 ngx_log_error(NGX_LOG_ERR, cf->log, 0, 1296 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1257 "the duplicate default server in %s:%ui", 1297 "a duplicate default server for %s", addr[i].opt.addr);
1258 listen->file_name, listen->line);
1259
1260 return NGX_ERROR; 1298 return NGX_ERROR;
1261 } 1299 }
1262 1300
1263 addr[i].core_srv_conf = cscf; 1301 default_server = 1;
1264 addr[i].default_server = 1; 1302 addr[i].default_server = cscf;
1303 }
1304
1305 addr[i].opt.default_server = default_server;
1265 #if (NGX_HTTP_SSL) 1306 #if (NGX_HTTP_SSL)
1266 addr[i].ssl = listen->conf.ssl; 1307 addr[i].opt.ssl = ssl;
1267 #endif 1308 #endif
1268 addr[i].listen_conf = &listen->conf;
1269 }
1270 1309
1271 return NGX_OK; 1310 return NGX_OK;
1272 } 1311 }
1273 1312
1274 /* 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 */
1275 1314
1276 return ngx_http_add_address(cf, cscf, port, listen); 1315 return ngx_http_add_address(cf, cscf, port, lsopt);
1277 } 1316 }
1278 1317
1279 1318
1280 /* 1319 /*
1281 * add the server address, the server names and the server core module 1320 * add the server address, the server names and the server core module
1282 * configurations to the port list 1321 * configurations to the port list
1283 */ 1322 */
1284 1323
1285 static ngx_int_t 1324 static ngx_int_t
1286 ngx_http_add_address(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, 1325 ngx_http_add_address(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
1287 ngx_http_conf_port_t *port, ngx_http_listen_t *listen) 1326 ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt)
1288 { 1327 {
1289 ngx_http_conf_addr_t *addr; 1328 ngx_http_conf_addr_t *addr;
1290 1329
1291 if (port->addrs.elts == NULL) { 1330 if (port->addrs.elts == NULL) {
1292 if (ngx_array_init(&port->addrs, cf->temp_pool, 4, 1331 if (ngx_array_init(&port->addrs, cf->temp_pool, 4,
1300 addr = ngx_array_push(&port->addrs); 1339 addr = ngx_array_push(&port->addrs);
1301 if (addr == NULL) { 1340 if (addr == NULL) {
1302 return NGX_ERROR; 1341 return NGX_ERROR;
1303 } 1342 }
1304 1343
1305 addr->sockaddr = (struct sockaddr *) &listen->sockaddr; 1344 addr->opt = *lsopt;
1306 addr->socklen = listen->socklen;
1307 addr->hash.buckets = NULL; 1345 addr->hash.buckets = NULL;
1308 addr->hash.size = 0; 1346 addr->hash.size = 0;
1309 addr->wc_head = NULL; 1347 addr->wc_head = NULL;
1310 addr->wc_tail = NULL; 1348 addr->wc_tail = NULL;
1311 addr->names.elts = NULL;
1312 #if (NGX_PCRE) 1349 #if (NGX_PCRE)
1313 addr->nregex = 0; 1350 addr->nregex = 0;
1314 addr->regex = NULL; 1351 addr->regex = NULL;
1315 #endif 1352 #endif
1316 addr->core_srv_conf = cscf; 1353 addr->default_server = cscf;
1317 addr->default_server = listen->conf.default_server; 1354 addr->servers.elts = NULL;
1318 addr->bind = listen->conf.bind; 1355
1319 addr->wildcard = listen->conf.wildcard; 1356 return ngx_http_add_server(cf, cscf, addr);
1320 #if (NGX_HTTP_SSL) 1357 }
1321 addr->ssl = listen->conf.ssl; 1358
1322 #endif 1359
1323 addr->listen_conf = &listen->conf; 1360 /* add the server core module configuration to the address:port */
1324
1325 return ngx_http_add_names(cf, cscf, addr);
1326 }
1327
1328
1329 /*
1330 * add the server names and the server core module
1331 * configurations to the address:port
1332 */
1333 1361
1334 static ngx_int_t 1362 static ngx_int_t
1335 ngx_http_add_names(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, 1363 ngx_http_add_server(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
1336 ngx_http_conf_addr_t *addr) 1364 ngx_http_conf_addr_t *addr)
1337 { 1365 {
1338 ngx_uint_t i; 1366 ngx_uint_t i;
1339 ngx_http_server_name_t *server_names, *name; 1367 ngx_http_core_srv_conf_t **server;
1340 1368
1341 if (addr->names.elts == NULL) { 1369 if (addr->servers.elts == NULL) {
1342 if (ngx_array_init(&addr->names, cf->temp_pool, 4, 1370 if (ngx_array_init(&addr->servers, cf->temp_pool, 4,
1343 sizeof(ngx_http_server_name_t)) 1371 sizeof(ngx_http_core_srv_conf_t *))
1344 != NGX_OK) 1372 != NGX_OK)
1345 { 1373 {
1346 return NGX_ERROR; 1374 return NGX_ERROR;
1347 } 1375 }
1348 } 1376
1349 1377 } else {
1350 server_names = cscf->server_names.elts; 1378 server = addr->servers.elts;
1351 1379 for (i = 0; i < addr->servers.nelts; i++) {
1352 for (i = 0; i < cscf->server_names.nelts; i++) { 1380 if (server[i] == cscf) {
1353 1381 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1354 ngx_strlow(server_names[i].name.data, server_names[i].name.data, 1382 "a duplicate listen %s", addr->opt.addr);
1355 server_names[i].name.len); 1383 return NGX_ERROR;
1356 1384 }
1357 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0, 1385 }
1358 "name: %V", &server_names[i].name); 1386 }
1359 1387
1360 name = ngx_array_push(&addr->names); 1388 server = ngx_array_push(&addr->servers);
1361 if (name == NULL) { 1389 if (server == NULL) {
1362 return NGX_ERROR; 1390 return NGX_ERROR;
1363 } 1391 }
1364 1392
1365 *name = server_names[i]; 1393 *server = cscf;
1366 }
1367 1394
1368 return NGX_OK; 1395 return NGX_OK;
1369 } 1396 }
1370 1397
1371 1398
1372 static ngx_int_t 1399 static ngx_int_t
1373 ngx_http_optimize_servers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf, 1400 ngx_http_optimize_servers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf,
1374 ngx_array_t *ports) 1401 ngx_array_t *ports)
1375 { 1402 {
1376 ngx_uint_t s, p, a; 1403 ngx_uint_t p, a;
1377 ngx_http_conf_port_t *port; 1404 ngx_http_conf_port_t *port;
1378 ngx_http_conf_addr_t *addr; 1405 ngx_http_conf_addr_t *addr;
1379 ngx_http_server_name_t *name; 1406
1407 if (ports == NULL) {
1408 return NGX_OK;
1409 }
1380 1410
1381 port = ports->elts; 1411 port = ports->elts;
1382 for (p = 0; p < ports->nelts; p++) { 1412 for (p = 0; p < ports->nelts; p++) {
1383 1413
1384 ngx_sort(port[p].addrs.elts, (size_t) port[p].addrs.nelts, 1414 ngx_sort(port[p].addrs.elts, (size_t) port[p].addrs.nelts,
1390 */ 1420 */
1391 1421
1392 addr = port[p].addrs.elts; 1422 addr = port[p].addrs.elts;
1393 for (a = 0; a < port[p].addrs.nelts; a++) { 1423 for (a = 0; a < port[p].addrs.nelts; a++) {
1394 1424
1395 name = addr[a].names.elts; 1425 if (addr[a].servers.nelts > 1
1396 for (s = 0; s < addr[a].names.nelts; s++) {
1397
1398 if (addr[a].core_srv_conf == name[s].core_srv_conf
1399 #if (NGX_PCRE) 1426 #if (NGX_PCRE)
1400 && name[s].captures == 0 1427 || addr[a].default_server->captures
1401 #endif 1428 #endif
1402 ) 1429 )
1403 { 1430 {
1404 continue;
1405 }
1406
1407 if (ngx_http_server_names(cf, cmcf, &addr[a]) != NGX_OK) { 1431 if (ngx_http_server_names(cf, cmcf, &addr[a]) != NGX_OK) {
1408 return NGX_ERROR; 1432 return NGX_ERROR;
1409 } 1433 }
1410
1411 break;
1412 } 1434 }
1413 } 1435 }
1414 1436
1415 if (ngx_http_init_listening(cf, &port[p]) != NGX_OK) { 1437 if (ngx_http_init_listening(cf, &port[p]) != NGX_OK) {
1416 return NGX_ERROR; 1438 return NGX_ERROR;
1423 1445
1424 static ngx_int_t 1446 static ngx_int_t
1425 ngx_http_server_names(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf, 1447 ngx_http_server_names(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf,
1426 ngx_http_conf_addr_t *addr) 1448 ngx_http_conf_addr_t *addr)
1427 { 1449 {
1428 ngx_int_t rc; 1450 ngx_int_t rc;
1429 ngx_uint_t s; 1451 ngx_uint_t n, s;
1430 ngx_hash_init_t hash; 1452 ngx_hash_init_t hash;
1431 ngx_hash_keys_arrays_t ha; 1453 ngx_hash_keys_arrays_t ha;
1432 ngx_http_server_name_t *name; 1454 ngx_http_server_name_t *name;
1455 ngx_http_core_srv_conf_t **cscfp;
1433 #if (NGX_PCRE) 1456 #if (NGX_PCRE)
1434 ngx_uint_t regex, i; 1457 ngx_uint_t regex, i;
1435 1458
1436 regex = 0; 1459 regex = 0;
1437 #endif 1460 #endif
1438 1461
1439 ngx_memzero(&ha, sizeof(ngx_hash_keys_arrays_t)); 1462 ngx_memzero(&ha, sizeof(ngx_hash_keys_arrays_t));
1447 1470
1448 if (ngx_hash_keys_array_init(&ha, NGX_HASH_LARGE) != NGX_OK) { 1471 if (ngx_hash_keys_array_init(&ha, NGX_HASH_LARGE) != NGX_OK) {
1449 goto failed; 1472 goto failed;
1450 } 1473 }
1451 1474
1452 name = addr->names.elts; 1475 cscfp = addr->servers.elts;
1453 1476
1454 for (s = 0; s < addr->names.nelts; s++) { 1477 for (s = 0; s < addr->servers.nelts; s++) {
1478
1479 name = cscfp[s]->server_names.elts;
1480
1481 for (n = 0; n < cscfp[s]->server_names.nelts; n++) {
1455 1482
1456 #if (NGX_PCRE) 1483 #if (NGX_PCRE)
1457 if (name[s].regex) { 1484 if (name[n].regex) {
1458 regex++; 1485 regex++;
1459 continue; 1486 continue;
1460 } 1487 }
1461 #endif 1488 #endif
1462 1489
1463 rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf, 1490 rc = ngx_hash_add_key(&ha, &name[n].name, name[n].server,
1464 NGX_HASH_WILDCARD_KEY); 1491 NGX_HASH_WILDCARD_KEY);
1465 1492
1466 if (rc == NGX_ERROR) { 1493 if (rc == NGX_ERROR) {
1467 return NGX_ERROR; 1494 return NGX_ERROR;
1468 } 1495 }
1469 1496
1470 if (rc == NGX_DECLINED) { 1497 if (rc == NGX_DECLINED) {
1471 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, 1498 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
1472 "invalid server name or wildcard \"%V\" on %s", 1499 "invalid server name or wildcard \"%V\" on %s",
1473 &name[s].name, addr->listen_conf->addr); 1500 &name[n].name, addr->opt.addr);
1474 return NGX_ERROR; 1501 return NGX_ERROR;
1475 } 1502 }
1476 1503
1477 if (rc == NGX_BUSY) { 1504 if (rc == NGX_BUSY) {
1478 ngx_log_error(NGX_LOG_WARN, cf->log, 0, 1505 ngx_log_error(NGX_LOG_WARN, cf->log, 0,
1479 "conflicting server name \"%V\" on %s, ignored", 1506 "conflicting server name \"%V\" on %s, ignored",
1480 &name[s].name, addr->listen_conf->addr); 1507 &name[n].name, addr->opt.addr);
1508 }
1481 } 1509 }
1482 } 1510 }
1483 1511
1484 hash.key = ngx_hash_key_lc; 1512 hash.key = ngx_hash_key_lc;
1485 hash.max_size = cmcf->server_names_hash_max_size; 1513 hash.max_size = cmcf->server_names_hash_max_size;
1544 addr->regex = ngx_palloc(cf->pool, regex * sizeof(ngx_http_server_name_t)); 1572 addr->regex = ngx_palloc(cf->pool, regex * sizeof(ngx_http_server_name_t));
1545 if (addr->regex == NULL) { 1573 if (addr->regex == NULL) {
1546 return NGX_ERROR; 1574 return NGX_ERROR;
1547 } 1575 }
1548 1576
1549 for (i = 0, s = 0; s < addr->names.nelts; s++) { 1577 i = 0;
1550 if (name[s].regex) { 1578
1551 addr->regex[i++] = name[s]; 1579 for (s = 0; s < addr->servers.nelts; s++) {
1580
1581 name = cscfp[s]->server_names.elts;
1582
1583 for (n = 0; n < cscfp[s]->server_names.nelts; n++) {
1584 if (name[n].regex) {
1585 addr->regex[i++] = name[n];
1586 }
1552 } 1587 }
1553 } 1588 }
1554 1589
1555 #endif 1590 #endif
1556 1591
1570 ngx_http_conf_addr_t *first, *second; 1605 ngx_http_conf_addr_t *first, *second;
1571 1606
1572 first = (ngx_http_conf_addr_t *) one; 1607 first = (ngx_http_conf_addr_t *) one;
1573 second = (ngx_http_conf_addr_t *) two; 1608 second = (ngx_http_conf_addr_t *) two;
1574 1609
1575 if (first->wildcard) { 1610 if (first->opt.wildcard) {
1576 /* a wildcard address must be the last resort, shift it to the end */ 1611 /* a wildcard address must be the last resort, shift it to the end */
1577 return 1; 1612 return 1;
1578 } 1613 }
1579 1614
1580 if (first->bind && !second->bind) { 1615 if (first->opt.bind && !second->opt.bind) {
1581 /* shift explicit bind()ed addresses to the start */ 1616 /* shift explicit bind()ed addresses to the start */
1582 return -1; 1617 return -1;
1583 } 1618 }
1584 1619
1585 if (!first->bind && second->bind) { 1620 if (!first->opt.bind && second->opt.bind) {
1586 /* shift explicit bind()ed addresses to the start */ 1621 /* shift explicit bind()ed addresses to the start */
1587 return 1; 1622 return 1;
1588 } 1623 }
1589 1624
1590 /* do not sort by default */ 1625 /* do not sort by default */
1621 * the "*:port" only and ignore other implicit bindings. The bindings 1656 * the "*:port" only and ignore other implicit bindings. The bindings
1622 * have been already sorted: explicit bindings are on the start, then 1657 * have been already sorted: explicit bindings are on the start, then
1623 * implicit bindings go, and wildcard binding is in the end. 1658 * implicit bindings go, and wildcard binding is in the end.
1624 */ 1659 */
1625 1660
1626 if (addr[last - 1].wildcard) { 1661 if (addr[last - 1].opt.wildcard) {
1627 addr[last - 1].bind = 1; 1662 addr[last - 1].opt.bind = 1;
1628 bind_wildcard = 1; 1663 bind_wildcard = 1;
1629 1664
1630 } else { 1665 } else {
1631 bind_wildcard = 0; 1666 bind_wildcard = 0;
1632 } 1667 }
1633 1668
1634 i = 0; 1669 i = 0;
1635 1670
1636 while (i < last) { 1671 while (i < last) {
1637 1672
1638 if (bind_wildcard && !addr[i].bind) { 1673 if (bind_wildcard && !addr[i].opt.bind) {
1639 i++; 1674 i++;
1640 continue; 1675 continue;
1641 } 1676 }
1642 1677
1643 ls = ngx_http_add_listening(cf, &addr[i]); 1678 ls = ngx_http_add_listening(cf, &addr[i]);
1689 { 1724 {
1690 ngx_listening_t *ls; 1725 ngx_listening_t *ls;
1691 ngx_http_core_loc_conf_t *clcf; 1726 ngx_http_core_loc_conf_t *clcf;
1692 ngx_http_core_srv_conf_t *cscf; 1727 ngx_http_core_srv_conf_t *cscf;
1693 1728
1694 ls = ngx_create_listening(cf, addr->sockaddr, addr->socklen); 1729 ls = ngx_create_listening(cf, &addr->opt.u.sockaddr, addr->opt.socklen);
1695 if (ls == NULL) { 1730 if (ls == NULL) {
1696 return NULL; 1731 return NULL;
1697 } 1732 }
1698 1733
1699 ls->addr_ntop = 1; 1734 ls->addr_ntop = 1;
1700 1735
1701 ls->handler = ngx_http_init_connection; 1736 ls->handler = ngx_http_init_connection;
1702 1737
1703 cscf = addr->core_srv_conf; 1738 cscf = addr->default_server;
1704 ls->pool_size = cscf->connection_pool_size; 1739 ls->pool_size = cscf->connection_pool_size;
1705 ls->post_accept_timeout = cscf->client_header_timeout; 1740 ls->post_accept_timeout = cscf->client_header_timeout;
1706 1741
1707 clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index]; 1742 clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index];
1708 1743
1719 ls->post_accept_buffer_size = cscf->client_header_buffer_size; 1754 ls->post_accept_buffer_size = cscf->client_header_buffer_size;
1720 } 1755 }
1721 } 1756 }
1722 #endif 1757 #endif
1723 1758
1724 ls->backlog = addr->listen_conf->backlog; 1759 ls->backlog = addr->opt.backlog;
1725 ls->rcvbuf = addr->listen_conf->rcvbuf; 1760 ls->rcvbuf = addr->opt.rcvbuf;
1726 ls->sndbuf = addr->listen_conf->sndbuf; 1761 ls->sndbuf = addr->opt.sndbuf;
1727 1762
1728 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) 1763 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
1729 ls->accept_filter = addr->listen_conf->accept_filter; 1764 ls->accept_filter = addr->opt.accept_filter;
1730 #endif 1765 #endif
1731 1766
1732 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) 1767 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
1733 ls->deferred_accept = addr->listen_conf->deferred_accept; 1768 ls->deferred_accept = addr->opt.deferred_accept;
1734 #endif 1769 #endif
1735 1770
1736 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) 1771 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
1737 ls->ipv6only = addr->listen_conf->ipv6only; 1772 ls->ipv6only = addr->opt.ipv6only;
1773 #endif
1774
1775 #if (NGX_HAVE_SETFIB)
1776 ls->setfib = addr->opt.setfib;
1738 #endif 1777 #endif
1739 1778
1740 return ls; 1779 return ls;
1741 } 1780 }
1742 1781
1758 1797
1759 addrs = hport->addrs; 1798 addrs = hport->addrs;
1760 1799
1761 for (i = 0; i < hport->naddrs; i++) { 1800 for (i = 0; i < hport->naddrs; i++) {
1762 1801
1763 sin = (struct sockaddr_in *) addr[i].sockaddr; 1802 sin = &addr[i].opt.u.sockaddr_in;
1764 addrs[i].addr = sin->sin_addr.s_addr; 1803 addrs[i].addr = sin->sin_addr.s_addr;
1765 addrs[i].conf.core_srv_conf = addr[i].core_srv_conf; 1804 addrs[i].conf.default_server = addr[i].default_server;
1766 #if (NGX_HTTP_SSL) 1805 #if (NGX_HTTP_SSL)
1767 addrs[i].conf.ssl = addr[i].ssl; 1806 addrs[i].conf.ssl = addr[i].opt.ssl;
1768 #endif 1807 #endif
1769 1808
1770 if (addr[i].hash.buckets == NULL 1809 if (addr[i].hash.buckets == NULL
1771 && (addr[i].wc_head == NULL 1810 && (addr[i].wc_head == NULL
1772 || addr[i].wc_head->hash.buckets == NULL) 1811 || addr[i].wc_head->hash.buckets == NULL)
1819 1858
1820 addrs6 = hport->addrs; 1859 addrs6 = hport->addrs;
1821 1860
1822 for (i = 0; i < hport->naddrs; i++) { 1861 for (i = 0; i < hport->naddrs; i++) {
1823 1862
1824 sin6 = (struct sockaddr_in6 *) addr[i].sockaddr; 1863 sin6 = &addr[i].opt.u.sockaddr_in6;
1825 addrs6[i].addr6 = sin6->sin6_addr; 1864 addrs6[i].addr6 = sin6->sin6_addr;
1826 addrs6[i].conf.core_srv_conf = addr[i].core_srv_conf; 1865 addrs6[i].conf.default_server = addr[i].default_server;
1827 #if (NGX_HTTP_SSL) 1866 #if (NGX_HTTP_SSL)
1828 addrs6[i].conf.ssl = addr[i].ssl; 1867 addrs6[i].conf.ssl = addr[i].opt.ssl;
1829 #endif 1868 #endif
1830 1869
1831 if (addr[i].hash.buckets == NULL 1870 if (addr[i].hash.buckets == NULL
1832 && (addr[i].wc_head == NULL 1871 && (addr[i].wc_head == NULL
1833 || addr[i].wc_head->hash.buckets == NULL) 1872 || addr[i].wc_head->hash.buckets == NULL)
1834 && (addr[i].wc_head == NULL 1873 && (addr[i].wc_tail == NULL
1835 || 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 )
1836 { 1879 {
1837 continue; 1880 continue;
1838 } 1881 }
1839 1882
1840 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t)); 1883 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t));
1869 ngx_uint_t i, n, hash; 1912 ngx_uint_t i, n, hash;
1870 ngx_hash_key_t *type; 1913 ngx_hash_key_t *type;
1871 1914
1872 types = (ngx_array_t **) (p + cmd->offset); 1915 types = (ngx_array_t **) (p + cmd->offset);
1873 1916
1917 if (*types == (void *) -1) {
1918 return NGX_CONF_OK;
1919 }
1920
1874 default_type = cmd->post; 1921 default_type = cmd->post;
1875 1922
1876 if (*types == NULL) { 1923 if (*types == NULL) {
1877 *types = ngx_array_create(cf->temp_pool, 1, sizeof(ngx_hash_key_t)); 1924 *types = ngx_array_create(cf->temp_pool, 1, sizeof(ngx_hash_key_t));
1878 if (*types == NULL) { 1925 if (*types == NULL) {
1894 1941
1895 value = cf->args->elts; 1942 value = cf->args->elts;
1896 1943
1897 for (i = 1; i < cf->args->nelts; i++) { 1944 for (i = 1; i < cf->args->nelts; i++) {
1898 1945
1946 if (value[i].len == 1 && value[i].data[0] == '*') {
1947 *types = (void *) -1;
1948 return NGX_CONF_OK;
1949 }
1950
1899 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len); 1951 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
1900 value[i].data[value[i].len] = '\0'; 1952 value[i].data[value[i].len] = '\0';
1901 1953
1902 type = (*types)->elts; 1954 type = (*types)->elts;
1903 for (n = 0; n < (*types)->nelts; n++) { 1955 for (n = 0; n < (*types)->nelts; n++) {
1922 return NGX_CONF_OK; 1974 return NGX_CONF_OK;
1923 } 1975 }
1924 1976
1925 1977
1926 char * 1978 char *
1927 ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t *keys, ngx_hash_t *types_hash, 1979 ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t **keys, ngx_hash_t *types_hash,
1928 ngx_array_t *prev_keys, ngx_hash_t *prev_types_hash, 1980 ngx_array_t **prev_keys, ngx_hash_t *prev_types_hash,
1929 ngx_str_t *default_types) 1981 ngx_str_t *default_types)
1930 { 1982 {
1931 ngx_hash_init_t hash; 1983 ngx_hash_init_t hash;
1932 1984
1933 if (keys) { 1985 if (*keys) {
1986
1987 if (*keys == (void *) -1) {
1988 return NGX_CONF_OK;
1989 }
1934 1990
1935 hash.hash = types_hash; 1991 hash.hash = types_hash;
1936 hash.key = NULL; 1992 hash.key = NULL;
1937 hash.max_size = 2048; 1993 hash.max_size = 2048;
1938 hash.bucket_size = 64; 1994 hash.bucket_size = 64;
1939 hash.name = "test_types_hash"; 1995 hash.name = "test_types_hash";
1940 hash.pool = cf->pool; 1996 hash.pool = cf->pool;
1941 hash.temp_pool = NULL; 1997 hash.temp_pool = NULL;
1942 1998
1943 if (ngx_hash_init(&hash, keys->elts, keys->nelts) != NGX_OK) { 1999 if (ngx_hash_init(&hash, (*keys)->elts, (*keys)->nelts) != NGX_OK) {
1944 return NGX_CONF_ERROR; 2000 return NGX_CONF_ERROR;
1945 } 2001 }
1946 2002
1947 return NGX_CONF_OK; 2003 return NGX_CONF_OK;
1948 } 2004 }
1949 2005
1950 if (prev_types_hash->buckets == NULL) { 2006 if (prev_types_hash->buckets == NULL) {
1951 2007
1952 if (prev_keys == NULL) { 2008 if (*prev_keys == NULL) {
1953 2009
1954 if (ngx_http_set_default_types(cf, &prev_keys, default_types) 2010 if (ngx_http_set_default_types(cf, prev_keys, default_types)
1955 != NGX_OK) 2011 != NGX_OK)
1956 { 2012 {
1957 return NGX_CONF_ERROR; 2013 return NGX_CONF_ERROR;
1958 } 2014 }
2015
2016 } else if (*prev_keys == (void *) -1) {
2017 *keys = *prev_keys;
2018 return NGX_CONF_OK;
1959 } 2019 }
1960 2020
1961 hash.hash = prev_types_hash; 2021 hash.hash = prev_types_hash;
1962 hash.key = NULL; 2022 hash.key = NULL;
1963 hash.max_size = 2048; 2023 hash.max_size = 2048;
1964 hash.bucket_size = 64; 2024 hash.bucket_size = 64;
1965 hash.name = "test_types_hash"; 2025 hash.name = "test_types_hash";
1966 hash.pool = cf->pool; 2026 hash.pool = cf->pool;
1967 hash.temp_pool = NULL; 2027 hash.temp_pool = NULL;
1968 2028
1969 if (ngx_hash_init(&hash, prev_keys->elts, prev_keys->nelts) != NGX_OK) { 2029 if (ngx_hash_init(&hash, (*prev_keys)->elts, (*prev_keys)->nelts)
2030 != NGX_OK)
2031 {
1970 return NGX_CONF_ERROR; 2032 return NGX_CONF_ERROR;
1971 } 2033 }
1972 } 2034 }
1973 2035
1974 *types_hash = *prev_types_hash; 2036 *types_hash = *prev_types_hash;