Mercurial > hg > nginx-quic
annotate src/http/ngx_http.c @ 2160:e21f3b073843
consider log_not_found while testing index files
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 11 Aug 2008 15:22:40 +0000 |
parents | fb3b084e7d42 |
children | 723df5089c05 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
5 |
2
ffffe1499bce
nginx-0.0.1-2002-08-16-19:27:03 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
2
diff
changeset
|
7 #include <ngx_config.h> |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
8 #include <ngx_core.h> |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
9 #include <ngx_event.h> |
2
ffffe1499bce
nginx-0.0.1-2002-08-16-19:27:03 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
ffffe1499bce
nginx-0.0.1-2002-08-16-19:27:03 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
12 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
13 static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
2021 | 14 static ngx_int_t ngx_http_init_phases(ngx_conf_t *cf, |
15 ngx_http_core_main_conf_t *cmcf); | |
16 static ngx_int_t ngx_http_init_headers_in_hash(ngx_conf_t *cf, | |
17 ngx_http_core_main_conf_t *cmcf); | |
18 static ngx_int_t ngx_http_init_phase_handlers(ngx_conf_t *cf, | |
19 ngx_http_core_main_conf_t *cmcf); | |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
20 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
21 static ngx_int_t ngx_http_init_server_lists(ngx_conf_t *cf, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
22 ngx_array_t *servers, ngx_array_t *in_ports); |
455 | 23 static ngx_int_t ngx_http_add_address(ngx_conf_t *cf, |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
24 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_in_port_t *in_port, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
25 ngx_http_listen_t *listen); |
455 | 26 static ngx_int_t ngx_http_add_names(ngx_conf_t *cf, |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
27 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_in_addr_t *in_addr); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
28 |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
29 static char *ngx_http_merge_locations(ngx_conf_t *cf, |
2027 | 30 ngx_queue_t *locations, void **loc_conf, ngx_http_module_t *module, |
499 | 31 ngx_uint_t ctx_index); |
2027 | 32 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); | |
34 static ngx_int_t ngx_http_init_static_location_trees(ngx_conf_t *cf, | |
35 ngx_http_core_loc_conf_t *pclcf); | |
36 static ngx_int_t ngx_http_cmp_locations(const ngx_queue_t *one, | |
37 const ngx_queue_t *two); | |
38 static ngx_int_t ngx_http_join_exact_locations(ngx_conf_t *cf, | |
39 ngx_queue_t *locations); | |
40 static void ngx_http_create_locations_list(ngx_queue_t *locations, | |
41 ngx_queue_t *q); | |
42 static ngx_http_location_tree_node_t * | |
43 ngx_http_create_locations_tree(ngx_conf_t *cf, ngx_queue_t *locations, | |
44 size_t prefix); | |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
45 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
46 static ngx_int_t ngx_http_optimize_servers(ngx_conf_t *cf, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
47 ngx_http_core_main_conf_t *cmcf, ngx_array_t *in_ports); |
1956
cb8c0c8e0c27
use ngx_int_t in ngx_sort() callback
Igor Sysoev <igor@sysoev.ru>
parents:
1910
diff
changeset
|
48 static ngx_int_t ngx_http_cmp_conf_in_addrs(const void *one, const void *two); |
593 | 49 static int ngx_libc_cdecl ngx_http_cmp_dns_wildcards(const void *one, |
50 const void *two); | |
212
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
201
diff
changeset
|
51 |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
52 static ngx_int_t ngx_http_init_listening(ngx_conf_t *cf, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
53 ngx_http_conf_in_port_t *in_port); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
54 |
593 | 55 ngx_uint_t ngx_http_max_module; |
56 | |
45
f1ee46c036a4
nginx-0.0.1-2003-01-10-09:09:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
44
diff
changeset
|
57 |
356
2e3cbc1bbe3c
nginx-0.0.7-2004-06-16-19:32:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
58 ngx_int_t (*ngx_http_top_header_filter) (ngx_http_request_t *r); |
2e3cbc1bbe3c
nginx-0.0.7-2004-06-16-19:32:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
59 ngx_int_t (*ngx_http_top_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch); |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
60 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
61 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
62 static ngx_command_t ngx_http_commands[] = { |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
63 |
499 | 64 { ngx_string("http"), |
65 NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, | |
66 ngx_http_block, | |
67 0, | |
68 0, | |
69 NULL }, | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
70 |
499 | 71 ngx_null_command |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
72 }; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
73 |
577 | 74 |
311
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
75 static ngx_core_module_t ngx_http_module_ctx = { |
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
76 ngx_string("http"), |
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
77 NULL, |
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
78 NULL |
577 | 79 }; |
311
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
80 |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
81 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
82 ngx_module_t ngx_http_module = { |
509 | 83 NGX_MODULE_V1, |
311
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
84 &ngx_http_module_ctx, /* module context */ |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
85 ngx_http_commands, /* module directives */ |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
86 NGX_CORE_MODULE, /* module type */ |
541 | 87 NULL, /* init master */ |
116
571bcbff82c5
nginx-0.0.1-2003-07-11-08:50:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
114
diff
changeset
|
88 NULL, /* init module */ |
541 | 89 NULL, /* init process */ |
90 NULL, /* init thread */ | |
91 NULL, /* exit thread */ | |
92 NULL, /* exit process */ | |
93 NULL, /* exit master */ | |
94 NGX_MODULE_V1_PADDING | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
95 }; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
96 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
97 |
499 | 98 static char * |
99 ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
100 { |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
101 char *rv; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
102 ngx_uint_t mi, m, s; |
216
f1d0e5f09c1e
nginx-0.0.1-2003-12-25-23:26:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
103 ngx_conf_t pcf; |
2021 | 104 ngx_array_t in_ports; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
105 ngx_http_module_t *module; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
106 ngx_http_conf_ctx_t *ctx; |
2027 | 107 ngx_http_core_loc_conf_t *clcf; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
108 ngx_http_core_srv_conf_t **cscfp; |
216
f1d0e5f09c1e
nginx-0.0.1-2003-12-25-23:26:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
109 ngx_http_core_main_conf_t *cmcf; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
110 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
111 /* the main http context */ |
477 | 112 |
501 | 113 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); |
114 if (ctx == NULL) { | |
485 | 115 return NGX_CONF_ERROR; |
116 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
117 |
90
37530da31268
nginx-0.0.1-2003-05-16-19:27:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
89
diff
changeset
|
118 *(ngx_http_conf_ctx_t **) conf = ctx; |
37530da31268
nginx-0.0.1-2003-05-16-19:27:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
89
diff
changeset
|
119 |
485 | 120 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
121 /* count the number of the http modules and set up their indices */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
122 |
71
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
123 ngx_http_max_module = 0; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
124 for (m = 0; ngx_modules[m]; m++) { |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
125 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
126 continue; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
127 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
128 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
129 ngx_modules[m]->ctx_index = ngx_http_max_module++; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
130 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
131 |
477 | 132 |
485 | 133 /* the http main_conf context, it is the same in the all http contexts */ |
90
37530da31268
nginx-0.0.1-2003-05-16-19:27:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
89
diff
changeset
|
134 |
485 | 135 ctx->main_conf = ngx_pcalloc(cf->pool, |
136 sizeof(void *) * ngx_http_max_module); | |
137 if (ctx->main_conf == NULL) { | |
138 return NGX_CONF_ERROR; | |
139 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
140 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
141 |
485 | 142 /* |
143 * the http null srv_conf context, it is used to merge | |
144 * the server{}s' srv_conf's | |
145 */ | |
146 | |
147 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
148 if (ctx->srv_conf == NULL) { | |
149 return NGX_CONF_ERROR; | |
150 } | |
151 | |
152 | |
153 /* | |
154 * the http null loc_conf context, it is used to merge | |
155 * the server{}s' loc_conf's | |
156 */ | |
157 | |
158 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
159 if (ctx->loc_conf == NULL) { | |
160 return NGX_CONF_ERROR; | |
161 } | |
162 | |
163 | |
164 /* | |
165 * create the main_conf's, the null srv_conf's, and the null loc_conf's | |
166 * of the all http modules | |
167 */ | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
168 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
169 for (m = 0; ngx_modules[m]; m++) { |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
170 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
171 continue; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
172 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
173 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
174 module = ngx_modules[m]->ctx; |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
175 mi = ngx_modules[m]->ctx_index; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
176 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
177 if (module->create_main_conf) { |
501 | 178 ctx->main_conf[mi] = module->create_main_conf(cf); |
179 if (ctx->main_conf[mi] == NULL) { | |
485 | 180 return NGX_CONF_ERROR; |
181 } | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
182 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
183 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
184 if (module->create_srv_conf) { |
501 | 185 ctx->srv_conf[mi] = module->create_srv_conf(cf); |
186 if (ctx->srv_conf[mi] == NULL) { | |
485 | 187 return NGX_CONF_ERROR; |
188 } | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
189 } |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
190 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
191 if (module->create_loc_conf) { |
501 | 192 ctx->loc_conf[mi] = module->create_loc_conf(cf); |
193 if (ctx->loc_conf[mi] == NULL) { | |
485 | 194 return NGX_CONF_ERROR; |
195 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
196 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
197 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
198 |
509 | 199 pcf = *cf; |
200 cf->ctx = ctx; | |
201 | |
202 for (m = 0; ngx_modules[m]; m++) { | |
203 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { | |
204 continue; | |
205 } | |
206 | |
207 module = ngx_modules[m]->ctx; | |
208 | |
209 if (module->preconfiguration) { | |
210 if (module->preconfiguration(cf) != NGX_OK) { | |
211 return NGX_CONF_ERROR; | |
212 } | |
213 } | |
214 } | |
485 | 215 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
216 /* parse inside the http{} block */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
217 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
218 cf->module_type = NGX_HTTP_MODULE; |
88
674d333f4296
nginx-0.0.1-2003-05-14-21:13:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
81
diff
changeset
|
219 cf->cmd_type = NGX_HTTP_MAIN_CONF; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
220 rv = ngx_conf_parse(cf, NULL); |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
221 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
222 if (rv != NGX_CONF_OK) { |
2027 | 223 goto failed; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
224 } |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
225 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
226 /* |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
227 * init http{} main_conf's, merge the server{}s' srv_conf's |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
228 * and its location{}s' loc_conf's |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
229 */ |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
230 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
231 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index]; |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
232 cscfp = cmcf->servers.elts; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
233 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
234 for (m = 0; ngx_modules[m]; m++) { |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
235 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
236 continue; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
237 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
238 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
239 module = ngx_modules[m]->ctx; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
240 mi = ngx_modules[m]->ctx_index; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
241 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
242 /* init http{} main_conf's */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
243 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
244 if (module->init_main_conf) { |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
116
diff
changeset
|
245 rv = module->init_main_conf(cf, ctx->main_conf[mi]); |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
246 if (rv != NGX_CONF_OK) { |
2027 | 247 goto failed; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
248 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
249 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
250 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
251 for (s = 0; s < cmcf->servers.nelts; s++) { |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
252 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
253 /* merge the server{}s' srv_conf's */ |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
254 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
255 if (module->merge_srv_conf) { |
2027 | 256 rv = module->merge_srv_conf(cf, ctx->srv_conf[mi], |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
257 cscfp[s]->ctx->srv_conf[mi]); |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
258 if (rv != NGX_CONF_OK) { |
2027 | 259 goto failed; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
260 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
261 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
262 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
263 if (module->merge_loc_conf) { |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
264 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
265 /* merge the server{}'s loc_conf */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
266 |
2027 | 267 rv = module->merge_loc_conf(cf, ctx->loc_conf[mi], |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
268 cscfp[s]->ctx->loc_conf[mi]); |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
269 if (rv != NGX_CONF_OK) { |
2027 | 270 goto failed; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
271 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
272 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
273 /* merge the locations{}' loc_conf's */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
274 |
2027 | 275 clcf = cscfp[s]->ctx->loc_conf[ngx_http_core_module.ctx_index]; |
276 | |
277 rv = ngx_http_merge_locations(cf, clcf->locations, | |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
278 cscfp[s]->ctx->loc_conf, |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
279 module, mi); |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
280 if (rv != NGX_CONF_OK) { |
2027 | 281 goto failed; |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
282 } |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
283 } |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
284 } |
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
285 } |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
286 |
485 | 287 |
2027 | 288 /* create location trees */ |
289 | |
290 for (s = 0; s < cmcf->servers.nelts; s++) { | |
291 | |
292 clcf = cscfp[s]->ctx->loc_conf[ngx_http_core_module.ctx_index]; | |
293 | |
294 if (ngx_http_init_locations(cf, cscfp[s], clcf) != NGX_OK) { | |
295 return NGX_CONF_ERROR; | |
296 } | |
297 | |
298 if (ngx_http_init_static_location_trees(cf, clcf) != NGX_OK) { | |
299 return NGX_CONF_ERROR; | |
300 } | |
301 } | |
302 | |
303 | |
2021 | 304 if (ngx_http_init_phases(cf, cmcf) != NGX_OK) { |
485 | 305 return NGX_CONF_ERROR; |
306 } | |
307 | |
2021 | 308 if (ngx_http_init_headers_in_hash(cf, cmcf) != NGX_OK) { |
649 | 309 return NGX_CONF_ERROR; |
310 } | |
311 | |
509 | 312 |
313 for (m = 0; ngx_modules[m]; m++) { | |
314 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { | |
315 continue; | |
316 } | |
317 | |
318 module = ngx_modules[m]->ctx; | |
319 | |
320 if (module->postconfiguration) { | |
321 if (module->postconfiguration(cf) != NGX_OK) { | |
322 return NGX_CONF_ERROR; | |
323 } | |
324 } | |
325 } | |
326 | |
573 | 327 if (ngx_http_variables_init_vars(cf) != NGX_OK) { |
328 return NGX_CONF_ERROR; | |
329 } | |
509 | 330 |
331 /* | |
332 * http{}'s cf->ctx was needed while the configuration merging | |
333 * and in postconfiguration process | |
334 */ | |
335 | |
336 *cf = pcf; | |
337 | |
507 | 338 |
2021 | 339 if (ngx_http_init_phase_handlers(cf, cmcf) != NGX_OK) { |
681 | 340 return NGX_CONF_ERROR; |
341 } | |
342 | |
343 | |
238
674f85a4d00f
nginx-0.0.1-2004-01-23-12:26:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
344 /* |
455 | 345 * create the lists of ports, addresses and server names |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
346 * to find quickly the server core module configuration at run-time |
238
674f85a4d00f
nginx-0.0.1-2004-01-23-12:26:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
347 */ |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
348 |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
349 /* AF_INET only */ |
455 | 350 |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
351 if (ngx_http_init_server_lists(cf, &cmcf->servers, &in_ports) != NGX_OK) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
352 return NGX_CONF_ERROR; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
353 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
354 |
455 | 355 |
356 /* optimize the lists of ports, addresses and server names */ | |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
357 |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
358 /* AF_INET only */ |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
359 |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
360 if (ngx_http_optimize_servers(cf, cmcf, &in_ports) != NGX_OK) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
361 return NGX_CONF_ERROR; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
362 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
363 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
364 return NGX_CONF_OK; |
2027 | 365 |
366 failed: | |
367 | |
368 *cf = pcf; | |
369 | |
370 return rv; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
371 } |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
372 |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
373 |
2021 | 374 static ngx_int_t |
375 ngx_http_init_phases(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf) | |
376 { | |
377 if (ngx_array_init(&cmcf->phases[NGX_HTTP_POST_READ_PHASE].handlers, | |
378 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
379 != NGX_OK) | |
380 { | |
381 return NGX_ERROR; | |
382 } | |
383 | |
384 if (ngx_array_init(&cmcf->phases[NGX_HTTP_SERVER_REWRITE_PHASE].handlers, | |
385 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
386 != NGX_OK) | |
387 { | |
388 return NGX_ERROR; | |
389 } | |
390 | |
391 if (ngx_array_init(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers, | |
392 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
393 != NGX_OK) | |
394 { | |
395 return NGX_ERROR; | |
396 } | |
397 | |
398 if (ngx_array_init(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers, | |
399 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
400 != NGX_OK) | |
401 { | |
402 return NGX_ERROR; | |
403 } | |
404 | |
405 if (ngx_array_init(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers, | |
406 cf->pool, 2, sizeof(ngx_http_handler_pt)) | |
407 != NGX_OK) | |
408 { | |
409 return NGX_ERROR; | |
410 } | |
411 | |
412 if (ngx_array_init(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers, | |
413 cf->pool, 4, sizeof(ngx_http_handler_pt)) | |
414 != NGX_OK) | |
415 { | |
416 return NGX_ERROR; | |
417 } | |
418 | |
419 if (ngx_array_init(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers, | |
420 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
421 != NGX_OK) | |
422 { | |
423 return NGX_ERROR; | |
424 } | |
425 | |
426 return NGX_OK; | |
427 } | |
428 | |
429 | |
430 static ngx_int_t | |
431 ngx_http_init_headers_in_hash(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf) | |
432 { | |
433 ngx_array_t headers_in; | |
434 ngx_hash_key_t *hk; | |
435 ngx_hash_init_t hash; | |
436 ngx_http_header_t *header; | |
437 | |
438 if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t)) | |
439 != NGX_OK) | |
440 { | |
441 return NGX_ERROR; | |
442 } | |
443 | |
444 for (header = ngx_http_headers_in; header->name.len; header++) { | |
445 hk = ngx_array_push(&headers_in); | |
446 if (hk == NULL) { | |
447 return NGX_ERROR; | |
448 } | |
449 | |
450 hk->key = header->name; | |
451 hk->key_hash = ngx_hash_key_lc(header->name.data, header->name.len); | |
452 hk->value = header; | |
453 } | |
454 | |
455 hash.hash = &cmcf->headers_in_hash; | |
456 hash.key = ngx_hash_key_lc; | |
457 hash.max_size = 512; | |
458 hash.bucket_size = ngx_align(64, ngx_cacheline_size); | |
459 hash.name = "headers_in_hash"; | |
460 hash.pool = cf->pool; | |
461 hash.temp_pool = NULL; | |
462 | |
463 if (ngx_hash_init(&hash, headers_in.elts, headers_in.nelts) != NGX_OK) { | |
464 return NGX_ERROR; | |
465 } | |
466 | |
467 return NGX_OK; | |
468 } | |
469 | |
470 | |
471 static ngx_int_t | |
472 ngx_http_init_phase_handlers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf) | |
473 { | |
474 ngx_int_t j; | |
475 ngx_uint_t i, n; | |
476 ngx_uint_t find_config_index, use_rewrite, use_access; | |
477 ngx_http_handler_pt *h; | |
478 ngx_http_phase_handler_t *ph; | |
479 ngx_http_phase_handler_pt checker; | |
480 | |
481 cmcf->phase_engine.server_rewrite_index = (ngx_uint_t) -1; | |
482 cmcf->phase_engine.location_rewrite_index = (ngx_uint_t) -1; | |
483 find_config_index = 0; | |
484 use_rewrite = cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers.nelts ? 1 : 0; | |
485 use_access = cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers.nelts ? 1 : 0; | |
486 | |
487 n = use_rewrite + use_access + 1; /* find config phase */ | |
488 | |
489 for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) { | |
490 n += cmcf->phases[i].handlers.nelts; | |
491 } | |
492 | |
493 ph = ngx_pcalloc(cf->pool, | |
494 n * sizeof(ngx_http_phase_handler_t) + sizeof(void *)); | |
495 if (ph == NULL) { | |
496 return NGX_ERROR; | |
497 } | |
498 | |
499 cmcf->phase_engine.handlers = ph; | |
500 n = 0; | |
501 | |
502 for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) { | |
503 h = cmcf->phases[i].handlers.elts; | |
504 | |
505 switch (i) { | |
506 | |
507 case NGX_HTTP_SERVER_REWRITE_PHASE: | |
508 if (cmcf->phase_engine.server_rewrite_index == (ngx_uint_t) -1) { | |
509 cmcf->phase_engine.server_rewrite_index = n; | |
510 } | |
511 checker = ngx_http_core_generic_phase; | |
512 | |
513 break; | |
514 | |
515 case NGX_HTTP_FIND_CONFIG_PHASE: | |
516 find_config_index = n; | |
517 | |
518 ph->checker = ngx_http_core_find_config_phase; | |
519 n++; | |
520 ph++; | |
521 | |
522 continue; | |
523 | |
524 case NGX_HTTP_REWRITE_PHASE: | |
525 if (cmcf->phase_engine.location_rewrite_index == (ngx_uint_t) -1) { | |
526 cmcf->phase_engine.location_rewrite_index = n; | |
527 } | |
528 checker = ngx_http_core_generic_phase; | |
529 | |
530 break; | |
531 | |
532 case NGX_HTTP_POST_REWRITE_PHASE: | |
533 if (use_rewrite) { | |
534 ph->checker = ngx_http_core_post_rewrite_phase; | |
535 ph->next = find_config_index; | |
536 n++; | |
537 ph++; | |
538 } | |
539 | |
540 continue; | |
541 | |
542 case NGX_HTTP_ACCESS_PHASE: | |
543 checker = ngx_http_core_access_phase; | |
544 n++; | |
545 break; | |
546 | |
547 case NGX_HTTP_POST_ACCESS_PHASE: | |
548 if (use_access) { | |
549 ph->checker = ngx_http_core_post_access_phase; | |
550 ph->next = n; | |
551 ph++; | |
552 } | |
553 | |
554 continue; | |
555 | |
556 case NGX_HTTP_CONTENT_PHASE: | |
557 checker = ngx_http_core_content_phase; | |
558 break; | |
559 | |
560 default: | |
561 checker = ngx_http_core_generic_phase; | |
562 } | |
563 | |
564 n += cmcf->phases[i].handlers.nelts; | |
565 | |
566 for (j = cmcf->phases[i].handlers.nelts - 1; j >=0; j--) { | |
567 ph->checker = checker; | |
568 ph->handler = h[j]; | |
569 ph->next = n; | |
570 ph++; | |
571 } | |
572 } | |
573 | |
574 return NGX_OK; | |
575 } | |
576 | |
577 | |
2027 | 578 static char * |
579 ngx_http_merge_locations(ngx_conf_t *cf, ngx_queue_t *locations, | |
580 void **loc_conf, ngx_http_module_t *module, ngx_uint_t ctx_index) | |
581 { | |
582 char *rv; | |
583 ngx_queue_t *q; | |
584 ngx_http_core_loc_conf_t *clcf; | |
585 ngx_http_location_queue_t *lq; | |
586 | |
587 if (locations == NULL) { | |
588 return NGX_CONF_OK; | |
589 } | |
590 | |
591 for (q = ngx_queue_head(locations); | |
592 q != ngx_queue_sentinel(locations); | |
593 q = ngx_queue_next(q)) | |
594 { | |
595 lq = (ngx_http_location_queue_t *) q; | |
596 | |
597 clcf = lq->exact ? lq->exact : lq->inclusive; | |
598 | |
599 rv = module->merge_loc_conf(cf, loc_conf[ctx_index], | |
600 clcf->loc_conf[ctx_index]); | |
601 if (rv != NGX_CONF_OK) { | |
602 return rv; | |
603 } | |
604 | |
605 rv = ngx_http_merge_locations(cf, clcf->locations, clcf->loc_conf, | |
606 module, ctx_index); | |
607 if (rv != NGX_CONF_OK) { | |
608 return rv; | |
609 } | |
610 } | |
611 | |
612 return NGX_CONF_OK; | |
613 } | |
614 | |
615 | |
616 static ngx_int_t | |
617 ngx_http_init_locations(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, | |
618 ngx_http_core_loc_conf_t *pclcf) | |
619 { | |
620 ngx_uint_t n; | |
621 ngx_queue_t *q, *locations, *named, tail; | |
622 ngx_http_core_loc_conf_t *clcf; | |
623 ngx_http_location_queue_t *lq; | |
624 ngx_http_core_loc_conf_t **clcfp; | |
625 #if (NGX_PCRE) | |
626 ngx_uint_t r; | |
627 ngx_queue_t *regex; | |
628 #endif | |
629 | |
630 locations = pclcf->locations; | |
631 | |
632 if (locations == NULL) { | |
633 return NGX_OK; | |
634 } | |
635 | |
636 ngx_queue_sort(locations, ngx_http_cmp_locations); | |
637 | |
638 named = NULL; | |
639 n = 0; | |
640 #if (NGX_PCRE) | |
641 regex = NULL; | |
642 r = 0; | |
643 #endif | |
644 | |
645 for (q = ngx_queue_head(locations); | |
646 q != ngx_queue_sentinel(locations); | |
647 q = ngx_queue_next(q)) | |
648 { | |
649 lq = (ngx_http_location_queue_t *) q; | |
650 | |
651 clcf = lq->exact ? lq->exact : lq->inclusive; | |
652 | |
653 if (ngx_http_init_locations(cf, NULL, clcf) != NGX_OK) { | |
654 return NGX_ERROR; | |
655 } | |
656 | |
657 #if (NGX_PCRE) | |
658 | |
659 if (clcf->regex) { | |
660 r++; | |
661 | |
662 if (regex == NULL) { | |
663 regex = q; | |
664 } | |
665 | |
666 continue; | |
667 } | |
668 | |
669 #endif | |
670 | |
671 if (clcf->named) { | |
672 n++; | |
673 | |
674 if (named == NULL) { | |
675 named = q; | |
676 } | |
677 | |
678 continue; | |
679 } | |
680 | |
681 if (clcf->noname) { | |
682 break; | |
683 } | |
684 } | |
685 | |
686 if (q != ngx_queue_sentinel(locations)) { | |
687 ngx_queue_split(locations, q, &tail); | |
688 } | |
689 | |
690 if (named) { | |
691 clcfp = ngx_palloc(cf->pool, | |
692 (n + 1) * sizeof(ngx_http_core_loc_conf_t **)); | |
693 if (clcfp == NULL) { | |
694 return NGX_ERROR; | |
695 } | |
696 | |
697 cscf->named_locations = clcfp; | |
698 | |
699 for (q = named; | |
700 q != ngx_queue_sentinel(locations); | |
701 q = ngx_queue_next(q)) | |
702 { | |
703 lq = (ngx_http_location_queue_t *) q; | |
704 | |
705 *(clcfp++) = lq->exact; | |
706 } | |
707 | |
708 *clcfp = NULL; | |
709 | |
710 ngx_queue_split(locations, named, &tail); | |
711 } | |
712 | |
713 #if (NGX_PCRE) | |
714 | |
715 if (regex) { | |
716 | |
717 clcfp = ngx_palloc(cf->pool, | |
718 (r + 1) * sizeof(ngx_http_core_loc_conf_t **)); | |
719 if (clcfp == NULL) { | |
720 return NGX_ERROR; | |
721 } | |
722 | |
723 pclcf->regex_locations = clcfp; | |
724 | |
725 for (q = regex; | |
726 q != ngx_queue_sentinel(locations); | |
727 q = ngx_queue_next(q)) | |
728 { | |
729 lq = (ngx_http_location_queue_t *) q; | |
730 | |
731 *(clcfp++) = lq->exact; | |
732 } | |
733 | |
734 *clcfp = NULL; | |
735 | |
736 ngx_queue_split(locations, regex, &tail); | |
737 } | |
738 | |
739 #endif | |
740 | |
741 return NGX_OK; | |
742 } | |
743 | |
744 | |
745 static ngx_int_t | |
746 ngx_http_init_static_location_trees(ngx_conf_t *cf, | |
747 ngx_http_core_loc_conf_t *pclcf) | |
748 { | |
749 ngx_queue_t *q, *locations; | |
750 ngx_http_core_loc_conf_t *clcf; | |
751 ngx_http_location_queue_t *lq; | |
752 | |
753 locations = pclcf->locations; | |
754 | |
755 if (locations == NULL) { | |
756 return NGX_OK; | |
757 } | |
758 | |
759 if (ngx_queue_empty(locations)) { | |
760 return NGX_OK; | |
761 } | |
762 | |
763 for (q = ngx_queue_head(locations); | |
764 q != ngx_queue_sentinel(locations); | |
765 q = ngx_queue_next(q)) | |
766 { | |
767 lq = (ngx_http_location_queue_t *) q; | |
768 | |
769 clcf = lq->exact ? lq->exact : lq->inclusive; | |
770 | |
771 if (ngx_http_init_static_location_trees(cf, clcf) != NGX_OK) { | |
772 return NGX_ERROR; | |
773 } | |
774 } | |
775 | |
776 if (ngx_http_join_exact_locations(cf, locations) != NGX_OK) { | |
777 return NGX_ERROR; | |
778 } | |
779 | |
780 ngx_http_create_locations_list(locations, ngx_queue_head(locations)); | |
781 | |
782 pclcf->static_locations = ngx_http_create_locations_tree(cf, locations, 0); | |
783 if (pclcf->static_locations == NULL) { | |
784 return NGX_ERROR; | |
785 } | |
786 | |
787 return NGX_OK; | |
788 } | |
789 | |
790 | |
791 ngx_int_t | |
792 ngx_http_add_location(ngx_conf_t *cf, ngx_queue_t **locations, | |
793 ngx_http_core_loc_conf_t *clcf) | |
794 { | |
795 ngx_http_location_queue_t *lq; | |
796 | |
797 if (*locations == NULL) { | |
798 *locations = ngx_palloc(cf->temp_pool, | |
799 sizeof(ngx_http_location_queue_t)); | |
800 if (*locations == NULL) { | |
801 return NGX_ERROR; | |
802 } | |
803 | |
804 ngx_queue_init(*locations); | |
805 } | |
806 | |
807 lq = ngx_palloc(cf->temp_pool, sizeof(ngx_http_location_queue_t)); | |
808 if (lq == NULL) { | |
809 return NGX_ERROR; | |
810 } | |
811 | |
812 if (clcf->exact_match | |
813 #if (NGX_PCRE) | |
814 || clcf->regex | |
815 #endif | |
816 || clcf->named || clcf->noname) | |
817 { | |
818 lq->exact = clcf; | |
819 lq->inclusive = NULL; | |
820 | |
821 } else { | |
822 lq->exact = NULL; | |
823 lq->inclusive = clcf; | |
824 } | |
825 | |
826 lq->name = &clcf->name; | |
827 lq->file_name = cf->conf_file->file.name.data; | |
828 lq->line = cf->conf_file->line; | |
829 | |
830 ngx_queue_init(&lq->list); | |
831 | |
832 ngx_queue_insert_tail(*locations, &lq->queue); | |
833 | |
834 return NGX_OK; | |
835 } | |
836 | |
837 | |
838 static ngx_int_t | |
839 ngx_http_cmp_locations(const ngx_queue_t *one, const ngx_queue_t *two) | |
840 { | |
841 ngx_int_t rc; | |
842 ngx_http_core_loc_conf_t *first, *second; | |
843 ngx_http_location_queue_t *lq1, *lq2; | |
844 | |
845 lq1 = (ngx_http_location_queue_t *) one; | |
846 lq2 = (ngx_http_location_queue_t *) two; | |
847 | |
848 first = lq1->exact ? lq1->exact : lq1->inclusive; | |
849 second = lq2->exact ? lq2->exact : lq2->inclusive; | |
850 | |
851 if (first->noname && !second->noname) { | |
852 /* shift no named locations to the end */ | |
853 return 1; | |
854 } | |
855 | |
856 if (!first->noname && second->noname) { | |
857 /* shift no named locations to the end */ | |
858 return -1; | |
859 } | |
860 | |
861 if (first->noname || second->noname) { | |
862 /* do not sort no named locations */ | |
863 return 0; | |
864 } | |
865 | |
866 if (first->named && !second->named) { | |
867 /* shift named locations to the end */ | |
868 return 1; | |
869 } | |
870 | |
871 if (!first->named && second->named) { | |
872 /* shift named locations to the end */ | |
873 return -1; | |
874 } | |
875 | |
876 if (first->named && second->named) { | |
877 return ngx_strcmp(first->name.data, second->name.data); | |
878 } | |
879 | |
880 #if (NGX_PCRE) | |
881 | |
882 if (first->regex && !second->regex) { | |
883 /* shift the regex matches to the end */ | |
884 return 1; | |
885 } | |
886 | |
887 if (!first->regex && second->regex) { | |
888 /* shift the regex matches to the end */ | |
889 return -1; | |
890 } | |
891 | |
892 if (first->regex || second->regex) { | |
893 /* do not sort the regex matches */ | |
894 return 0; | |
895 } | |
896 | |
897 #endif | |
898 | |
899 rc = ngx_strcmp(first->name.data, second->name.data); | |
900 | |
901 if (rc == 0 && !first->exact_match && second->exact_match) { | |
902 /* an exact match must be before the same inclusive one */ | |
903 return 1; | |
904 } | |
905 | |
906 return rc; | |
907 } | |
908 | |
909 | |
910 static ngx_int_t | |
911 ngx_http_join_exact_locations(ngx_conf_t *cf, ngx_queue_t *locations) | |
912 { | |
913 ngx_queue_t *q, *x; | |
914 ngx_http_location_queue_t *lq, *lx; | |
915 | |
916 q = ngx_queue_head(locations); | |
917 | |
918 while (q != ngx_queue_last(locations)) { | |
919 | |
920 x = ngx_queue_next(q); | |
921 | |
922 lq = (ngx_http_location_queue_t *) q; | |
923 lx = (ngx_http_location_queue_t *) x; | |
924 | |
925 if (ngx_strcmp(lq->name->data, lx->name->data) == 0) { | |
926 | |
927 if ((lq->exact && lx->exact) || (lq->inclusive && lx->inclusive)) { | |
928 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
929 "duplicate location \"%V\" in %s:%ui", | |
930 lx->name, lx->file_name, lx->line); | |
931 | |
932 return NGX_ERROR; | |
933 } | |
934 | |
935 lq->inclusive = lx->inclusive; | |
936 | |
937 ngx_queue_remove(x); | |
938 | |
939 continue; | |
940 } | |
941 | |
942 q = ngx_queue_next(q); | |
943 } | |
944 | |
945 return NGX_OK; | |
946 } | |
947 | |
948 | |
949 static void | |
950 ngx_http_create_locations_list(ngx_queue_t *locations, ngx_queue_t *q) | |
951 { | |
952 u_char *name; | |
953 size_t len; | |
954 ngx_queue_t *x, tail; | |
955 ngx_http_location_queue_t *lq, *lx; | |
956 | |
957 if (q == ngx_queue_last(locations)) { | |
958 return; | |
959 } | |
960 | |
961 lq = (ngx_http_location_queue_t *) q; | |
962 | |
963 if (lq->inclusive == NULL) { | |
964 ngx_http_create_locations_list(locations, ngx_queue_next(q)); | |
965 return; | |
966 } | |
967 | |
968 len = lq->name->len; | |
969 name = lq->name->data; | |
970 | |
971 for (x = ngx_queue_next(q); | |
972 x != ngx_queue_sentinel(locations); | |
973 x = ngx_queue_next(x)) | |
974 { | |
975 lx = (ngx_http_location_queue_t *) x; | |
976 | |
977 if (len > lx->name->len | |
978 || (ngx_strncmp(name, lx->name->data, len) != 0)) | |
979 { | |
980 break; | |
981 } | |
982 } | |
983 | |
984 q = ngx_queue_next(q); | |
985 | |
986 if (q == x) { | |
987 ngx_http_create_locations_list(locations, x); | |
988 return; | |
989 } | |
990 | |
991 ngx_queue_split(locations, q, &tail); | |
992 ngx_queue_add(&lq->list, &tail); | |
993 | |
994 if (x == ngx_queue_sentinel(locations)) { | |
995 ngx_http_create_locations_list(&lq->list, ngx_queue_head(&lq->list)); | |
996 return; | |
997 } | |
998 | |
999 ngx_queue_split(&lq->list, x, &tail); | |
1000 ngx_queue_add(locations, &tail); | |
1001 | |
1002 ngx_http_create_locations_list(&lq->list, ngx_queue_head(&lq->list)); | |
1003 | |
1004 ngx_http_create_locations_list(locations, x); | |
1005 } | |
1006 | |
1007 | |
1008 /* | |
1009 * to keep cache locality for left leaf nodes, allocate nodes in following | |
1010 * order: node, left subtree, right subtree, inclusive subtree | |
1011 */ | |
1012 | |
1013 static ngx_http_location_tree_node_t * | |
1014 ngx_http_create_locations_tree(ngx_conf_t *cf, ngx_queue_t *locations, | |
1015 size_t prefix) | |
1016 { | |
1017 size_t len; | |
1018 ngx_queue_t *q, tail; | |
1019 ngx_http_location_queue_t *lq; | |
1020 ngx_http_location_tree_node_t *node; | |
1021 | |
1022 q = ngx_queue_middle(locations); | |
1023 | |
1024 lq = (ngx_http_location_queue_t *) q; | |
1025 len = lq->name->len - prefix; | |
1026 | |
2049 | 1027 node = ngx_palloc(cf->pool, |
1028 offsetof(ngx_http_location_tree_node_t, name) + len); | |
2027 | 1029 if (node == NULL) { |
1030 return NULL; | |
1031 } | |
1032 | |
2039
4d8140271204
*) add ngx_palloc_aligned() to allocate explicitlty aligned memory
Igor Sysoev <igor@sysoev.ru>
parents:
2029
diff
changeset
|
1033 node->left = NULL; |
4d8140271204
*) add ngx_palloc_aligned() to allocate explicitlty aligned memory
Igor Sysoev <igor@sysoev.ru>
parents:
2029
diff
changeset
|
1034 node->right = NULL; |
4d8140271204
*) add ngx_palloc_aligned() to allocate explicitlty aligned memory
Igor Sysoev <igor@sysoev.ru>
parents:
2029
diff
changeset
|
1035 node->tree = NULL; |
2027 | 1036 node->exact = lq->exact; |
1037 node->inclusive = lq->inclusive; | |
1038 | |
1039 node->auto_redirect = (u_char) ((lq->exact && lq->exact->auto_redirect) | |
1040 || (lq->inclusive && lq->inclusive->auto_redirect)); | |
1041 | |
1042 node->len = (u_char) len; | |
1043 ngx_memcpy(node->name, &lq->name->data[prefix], len); | |
1044 | |
1045 ngx_queue_split(locations, q, &tail); | |
1046 | |
1047 if (ngx_queue_empty(locations)) { | |
1048 /* | |
1049 * ngx_queue_split() insures that if left part is empty, | |
1050 * then right one is empty too | |
1051 */ | |
1052 goto inclusive; | |
1053 } | |
1054 | |
1055 node->left = ngx_http_create_locations_tree(cf, locations, prefix); | |
1056 if (node->left == NULL) { | |
1057 return NULL; | |
1058 } | |
1059 | |
1060 ngx_queue_remove(q); | |
1061 | |
1062 if (ngx_queue_empty(&tail)) { | |
1063 goto inclusive; | |
1064 } | |
1065 | |
1066 node->right = ngx_http_create_locations_tree(cf, &tail, prefix); | |
1067 if (node->right == NULL) { | |
1068 return NULL; | |
1069 } | |
1070 | |
1071 inclusive: | |
1072 | |
1073 if (ngx_queue_empty(&lq->list)) { | |
1074 return node; | |
1075 } | |
1076 | |
1077 node->tree = ngx_http_create_locations_tree(cf, &lq->list, prefix + len); | |
1078 if (node->tree == NULL) { | |
1079 return NULL; | |
1080 } | |
1081 | |
1082 return node; | |
1083 } | |
1084 | |
1085 | |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1086 static ngx_int_t |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1087 ngx_http_init_server_lists(ngx_conf_t *cf, ngx_array_t *servers, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1088 ngx_array_t *in_ports) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1089 { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1090 ngx_uint_t s, l, p, a; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1091 ngx_http_listen_t *listen; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1092 ngx_http_conf_in_port_t *in_port; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1093 ngx_http_conf_in_addr_t *in_addr; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1094 ngx_http_core_srv_conf_t **cscfp; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1095 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1096 if (ngx_array_init(in_ports, cf->temp_pool, 2, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1097 sizeof(ngx_http_conf_in_port_t)) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1098 != NGX_OK) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1099 { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1100 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1101 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1102 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1103 /* "server" directives */ |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1104 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1105 cscfp = servers->elts; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1106 for (s = 0; s < servers->nelts; s++) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1107 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1108 /* "listen" directives */ |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1109 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1110 listen = cscfp[s]->listen.elts; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1111 for (l = 0; l < cscfp[s]->listen.nelts; l++) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1112 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1113 /* AF_INET only */ |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1114 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1115 in_port = in_ports->elts; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1116 for (p = 0; p < in_ports->nelts; p++) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1117 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1118 if (listen[l].port != in_port[p].port) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1119 continue; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1120 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1121 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1122 /* the port is already in the port list */ |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1123 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1124 in_addr = in_port[p].addrs.elts; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1125 for (a = 0; a < in_port[p].addrs.nelts; a++) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1126 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1127 if (listen[l].addr != in_addr[a].addr) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1128 continue; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1129 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1130 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1131 /* the address is already in the address list */ |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1132 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1133 if (ngx_http_add_names(cf, cscfp[s], &in_addr[a]) != NGX_OK) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1134 { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1135 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1136 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1137 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1138 /* |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1139 * check the duplicate "default" server |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1140 * for this address:port |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1141 */ |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1142 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1143 if (listen[l].conf.default_server) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1144 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1145 if (in_addr[a].default_server) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1146 ngx_log_error(NGX_LOG_ERR, cf->log, 0, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1147 "the duplicate default server in %s:%ui", |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1148 listen[l].file_name, listen[l].line); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1149 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1150 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1151 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1152 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1153 in_addr[a].core_srv_conf = cscfp[s]; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1154 in_addr[a].default_server = 1; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1155 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1156 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1157 goto found; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1158 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1159 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1160 /* |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1161 * add the address to the addresses list that |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1162 * bound to this port |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1163 */ |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1164 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1165 if (ngx_http_add_address(cf, cscfp[s], &in_port[p], &listen[l]) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1166 != NGX_OK) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1167 { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1168 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1169 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1170 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1171 goto found; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1172 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1173 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1174 /* add the port to the in_port list */ |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1175 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1176 in_port = ngx_array_push(in_ports); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1177 if (in_port == NULL) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1178 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1179 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1180 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1181 in_port->port = listen[l].port; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1182 in_port->addrs.elts = NULL; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1183 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1184 if (ngx_http_add_address(cf, cscfp[s], in_port, &listen[l]) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1185 != NGX_OK) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1186 { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1187 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1188 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1189 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1190 found: |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1191 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1192 continue; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1193 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1194 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1195 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1196 return NGX_OK; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1197 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1198 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1199 |
455 | 1200 /* |
1201 * add the server address, the server names and the server core module | |
1202 * configurations to the port (in_port) | |
1203 */ | |
1204 | |
499 | 1205 static ngx_int_t |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1206 ngx_http_add_address(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1207 ngx_http_conf_in_port_t *in_port, ngx_http_listen_t *listen) |
455 | 1208 { |
593 | 1209 ngx_http_conf_in_addr_t *in_addr; |
455 | 1210 |
1211 if (in_port->addrs.elts == NULL) { | |
593 | 1212 if (ngx_array_init(&in_port->addrs, cf->temp_pool, 4, |
1385 | 1213 sizeof(ngx_http_conf_in_addr_t)) |
1214 != NGX_OK) | |
455 | 1215 { |
1216 return NGX_ERROR; | |
1217 } | |
1218 } | |
1219 | |
501 | 1220 in_addr = ngx_array_push(&in_port->addrs); |
1221 if (in_addr == NULL) { | |
455 | 1222 return NGX_ERROR; |
1223 } | |
1224 | |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1225 in_addr->addr = listen->addr; |
593 | 1226 in_addr->hash.buckets = NULL; |
1227 in_addr->hash.size = 0; | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
1236
diff
changeset
|
1228 in_addr->wc_head = NULL; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
1236
diff
changeset
|
1229 in_addr->wc_tail = NULL; |
455 | 1230 in_addr->names.elts = NULL; |
1387 | 1231 #if (NGX_PCRE) |
1232 in_addr->nregex = 0; | |
1233 in_addr->regex = NULL; | |
1234 #endif | |
455 | 1235 in_addr->core_srv_conf = cscf; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1236 in_addr->default_server = listen->conf.default_server; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1237 in_addr->bind = listen->conf.bind; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1238 in_addr->listen_conf = &listen->conf; |
455 | 1239 |
1240 #if (NGX_DEBUG) | |
1241 { | |
1242 u_char text[20]; | |
1243 ngx_inet_ntop(AF_INET, &in_addr->addr, text, 20); | |
1244 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0, "address: %s:%d", | |
1245 text, in_port->port); | |
1246 } | |
1247 #endif | |
1248 | |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1249 return ngx_http_add_names(cf, cscf, in_addr); |
455 | 1250 } |
1251 | |
1252 | |
1253 /* | |
1254 * add the server names and the server core module | |
1255 * configurations to the address:port (in_addr) | |
1256 */ | |
1257 | |
499 | 1258 static ngx_int_t |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1259 ngx_http_add_names(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1260 ngx_http_conf_in_addr_t *in_addr) |
455 | 1261 { |
2135 | 1262 ngx_uint_t i; |
455 | 1263 ngx_http_server_name_t *server_names, *name; |
1264 | |
1265 if (in_addr->names.elts == NULL) { | |
593 | 1266 if (ngx_array_init(&in_addr->names, cf->temp_pool, 4, |
1385 | 1267 sizeof(ngx_http_server_name_t)) |
1268 != NGX_OK) | |
477 | 1269 { |
1270 return NGX_ERROR; | |
1271 } | |
1272 } | |
1273 | |
455 | 1274 server_names = cscf->server_names.elts; |
1387 | 1275 |
455 | 1276 for (i = 0; i < cscf->server_names.nelts; i++) { |
1277 | |
2135 | 1278 ngx_strlow(server_names[i].name.data, server_names[i].name.data, |
1279 server_names[i].name.len); | |
477 | 1280 |
455 | 1281 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0, |
461 | 1282 "name: %V", &server_names[i].name); |
455 | 1283 |
593 | 1284 name = ngx_array_push(&in_addr->names); |
501 | 1285 if (name == NULL) { |
455 | 1286 return NGX_ERROR; |
1287 } | |
1288 | |
1289 *name = server_names[i]; | |
1290 } | |
1291 | |
1292 return NGX_OK; | |
1293 } | |
1294 | |
1295 | |
1956
cb8c0c8e0c27
use ngx_int_t in ngx_sort() callback
Igor Sysoev <igor@sysoev.ru>
parents:
1910
diff
changeset
|
1296 static ngx_int_t |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1297 ngx_http_optimize_servers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1298 ngx_array_t *in_ports) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1299 { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1300 ngx_int_t rc; |
2042
6389d4accacf
fix building without PCRE introduced in r2023
Igor Sysoev <igor@sysoev.ru>
parents:
2039
diff
changeset
|
1301 ngx_uint_t s, p, a; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1302 ngx_hash_init_t hash; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1303 ngx_http_server_name_t *name; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1304 ngx_hash_keys_arrays_t ha; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1305 ngx_http_conf_in_port_t *in_port; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1306 ngx_http_conf_in_addr_t *in_addr; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1307 #if (NGX_PCRE) |
2042
6389d4accacf
fix building without PCRE introduced in r2023
Igor Sysoev <igor@sysoev.ru>
parents:
2039
diff
changeset
|
1308 ngx_uint_t regex, i; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1309 #endif |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1310 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1311 in_port = in_ports->elts; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1312 for (p = 0; p < in_ports->nelts; p++) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1313 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1314 ngx_sort(in_port[p].addrs.elts, (size_t) in_port[p].addrs.nelts, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1315 sizeof(ngx_http_conf_in_addr_t), ngx_http_cmp_conf_in_addrs); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1316 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1317 /* |
2029
c036922f6f07
*) remove optimize_host_names
Igor Sysoev <igor@sysoev.ru>
parents:
2027
diff
changeset
|
1318 * check whether all name-based servers have |
c036922f6f07
*) remove optimize_host_names
Igor Sysoev <igor@sysoev.ru>
parents:
2027
diff
changeset
|
1319 * the same configuraiton as the default server |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1320 */ |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1321 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1322 in_addr = in_port[p].addrs.elts; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1323 for (a = 0; a < in_port[p].addrs.nelts; a++) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1324 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1325 name = in_addr[a].names.elts; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1326 for (s = 0; s < in_addr[a].names.nelts; s++) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1327 |
2029
c036922f6f07
*) remove optimize_host_names
Igor Sysoev <igor@sysoev.ru>
parents:
2027
diff
changeset
|
1328 if (in_addr[a].core_srv_conf != name[s].core_srv_conf) { |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1329 goto virtual_names; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1330 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1331 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1332 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1333 /* |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1334 * if all name-based servers have the same configuration |
2029
c036922f6f07
*) remove optimize_host_names
Igor Sysoev <igor@sysoev.ru>
parents:
2027
diff
changeset
|
1335 * as the default server, then we do not need to check |
c036922f6f07
*) remove optimize_host_names
Igor Sysoev <igor@sysoev.ru>
parents:
2027
diff
changeset
|
1336 * them at run-time at all |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1337 */ |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1338 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1339 in_addr[a].names.nelts = 0; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1340 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1341 continue; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1342 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1343 virtual_names: |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1344 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1345 ngx_memzero(&ha, sizeof(ngx_hash_keys_arrays_t)); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1346 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1347 ha.temp_pool = ngx_create_pool(16384, cf->log); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1348 if (ha.temp_pool == NULL) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1349 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1350 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1351 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1352 ha.pool = cf->pool; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1353 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1354 if (ngx_hash_keys_array_init(&ha, NGX_HASH_LARGE) != NGX_OK) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1355 goto failed; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1356 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1357 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1358 #if (NGX_PCRE) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1359 regex = 0; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1360 #endif |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1361 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1362 name = in_addr[a].names.elts; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1363 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1364 for (s = 0; s < in_addr[a].names.nelts; s++) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1365 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1366 #if (NGX_PCRE) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1367 if (name[s].regex) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1368 regex++; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1369 continue; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1370 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1371 #endif |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1372 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1373 rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1374 NGX_HASH_WILDCARD_KEY); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1375 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1376 if (rc == NGX_ERROR) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1377 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1378 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1379 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1380 if (rc == NGX_DECLINED) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1381 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1382 "invalid server name or wildcard \"%V\" on %s", |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1383 &name[s].name, in_addr[a].listen_conf->addr); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1384 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1385 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1386 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1387 if (rc == NGX_BUSY) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1388 ngx_log_error(NGX_LOG_WARN, cf->log, 0, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1389 "conflicting server name \"%V\" on %s, ignored", |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1390 &name[s].name, in_addr[a].listen_conf->addr); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1391 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1392 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1393 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1394 hash.key = ngx_hash_key_lc; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1395 hash.max_size = cmcf->server_names_hash_max_size; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1396 hash.bucket_size = cmcf->server_names_hash_bucket_size; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1397 hash.name = "server_names_hash"; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1398 hash.pool = cf->pool; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1399 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1400 if (ha.keys.nelts) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1401 hash.hash = &in_addr[a].hash; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1402 hash.temp_pool = NULL; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1403 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1404 if (ngx_hash_init(&hash, ha.keys.elts, ha.keys.nelts) != NGX_OK) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1405 { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1406 goto failed; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1407 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1408 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1409 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1410 if (ha.dns_wc_head.nelts) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1411 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1412 ngx_qsort(ha.dns_wc_head.elts, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1413 (size_t) ha.dns_wc_head.nelts, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1414 sizeof(ngx_hash_key_t), |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1415 ngx_http_cmp_dns_wildcards); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1416 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1417 hash.hash = NULL; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1418 hash.temp_pool = ha.temp_pool; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1419 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1420 if (ngx_hash_wildcard_init(&hash, ha.dns_wc_head.elts, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1421 ha.dns_wc_head.nelts) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1422 != NGX_OK) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1423 { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1424 goto failed; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1425 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1426 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1427 in_addr[a].wc_head = (ngx_hash_wildcard_t *) hash.hash; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1428 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1429 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1430 if (ha.dns_wc_tail.nelts) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1431 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1432 ngx_qsort(ha.dns_wc_tail.elts, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1433 (size_t) ha.dns_wc_tail.nelts, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1434 sizeof(ngx_hash_key_t), |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1435 ngx_http_cmp_dns_wildcards); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1436 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1437 hash.hash = NULL; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1438 hash.temp_pool = ha.temp_pool; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1439 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1440 if (ngx_hash_wildcard_init(&hash, ha.dns_wc_tail.elts, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1441 ha.dns_wc_tail.nelts) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1442 != NGX_OK) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1443 { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1444 goto failed; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1445 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1446 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1447 in_addr[a].wc_tail = (ngx_hash_wildcard_t *) hash.hash; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1448 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1449 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1450 ngx_destroy_pool(ha.temp_pool); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1451 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1452 #if (NGX_PCRE) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1453 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1454 if (regex == 0) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1455 continue; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1456 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1457 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1458 in_addr[a].nregex = regex; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1459 in_addr[a].regex = ngx_palloc(cf->pool, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1460 regex * sizeof(ngx_http_server_name_t)); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1461 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1462 if (in_addr[a].regex == NULL) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1463 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1464 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1465 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1466 for (i = 0, s = 0; s < in_addr[a].names.nelts; s++) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1467 if (name[s].regex) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1468 in_addr[a].regex[i++] = name[s]; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1469 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1470 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1471 #endif |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1472 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1473 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1474 if (ngx_http_init_listening(cf, &in_port[p]) != NGX_OK) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1475 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1476 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1477 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1478 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1479 return NGX_OK; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1480 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1481 failed: |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1482 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1483 ngx_destroy_pool(ha.temp_pool); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1484 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1485 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1486 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1487 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1488 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1489 static ngx_int_t |
593 | 1490 ngx_http_cmp_conf_in_addrs(const void *one, const void *two) |
1491 { | |
1492 ngx_http_conf_in_addr_t *first, *second; | |
1493 | |
1494 first = (ngx_http_conf_in_addr_t *) one; | |
1495 second = (ngx_http_conf_in_addr_t *) two; | |
1496 | |
1497 if (first->addr == INADDR_ANY) { | |
1498 /* the INADDR_ANY must be the last resort, shift it to the end */ | |
1499 return 1; | |
1500 } | |
1501 | |
1502 if (first->bind && !second->bind) { | |
1503 /* shift explicit bind()ed addresses to the start */ | |
1504 return -1; | |
1505 } | |
1506 | |
1507 if (!first->bind && second->bind) { | |
1508 /* shift explicit bind()ed addresses to the start */ | |
1509 return 1; | |
1510 } | |
1511 | |
1512 /* do not sort by default */ | |
1513 | |
1514 return 0; | |
1515 } | |
1516 | |
1517 | |
1518 static int ngx_libc_cdecl | |
1519 ngx_http_cmp_dns_wildcards(const void *one, const void *two) | |
1520 { | |
1521 ngx_hash_key_t *first, *second; | |
1522 | |
1523 first = (ngx_hash_key_t *) one; | |
1524 second = (ngx_hash_key_t *) two; | |
1525 | |
1526 return ngx_strcmp(first->key.data, second->key.data); | |
1527 } | |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1528 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1529 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1530 static ngx_int_t |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1531 ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_in_port_t *in_port) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1532 { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1533 ngx_uint_t i, a, last, bind_all, done; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1534 ngx_listening_t *ls; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1535 ngx_http_in_port_t *hip; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1536 ngx_http_conf_in_addr_t *in_addr; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1537 ngx_http_virtual_names_t *vn; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1538 ngx_http_core_loc_conf_t *clcf; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1539 ngx_http_core_srv_conf_t *cscf; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1540 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1541 in_addr = in_port->addrs.elts; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1542 last = in_port->addrs.nelts; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1543 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1544 /* |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1545 * if there is a binding to a "*:port" then we need to bind() |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1546 * to the "*:port" only and ignore other bindings |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1547 */ |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1548 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1549 if (in_addr[last - 1].addr == INADDR_ANY) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1550 in_addr[last - 1].bind = 1; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1551 bind_all = 0; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1552 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1553 } else { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1554 bind_all = 1; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1555 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1556 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1557 a = 0; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1558 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1559 while (a < last) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1560 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1561 if (!bind_all && !in_addr[a].bind) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1562 a++; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1563 continue; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1564 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1565 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1566 ls = ngx_listening_inet_stream_socket(cf, in_addr[a].addr, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1567 in_port->port); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1568 if (ls == NULL) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1569 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1570 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1571 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1572 ls->addr_ntop = 1; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1573 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1574 ls->handler = ngx_http_init_connection; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1575 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1576 cscf = in_addr[a].core_srv_conf; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1577 ls->pool_size = cscf->connection_pool_size; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1578 ls->post_accept_timeout = cscf->client_header_timeout; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1579 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1580 clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index]; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1581 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1582 ls->log = *clcf->err_log; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1583 ls->log.data = &ls->addr_text; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1584 ls->log.handler = ngx_accept_log_error; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1585 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1586 #if (NGX_WIN32) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1587 { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1588 ngx_iocp_conf_t *iocpcf; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1589 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1590 iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1591 if (iocpcf->acceptex_read) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1592 ls->post_accept_buffer_size = cscf->client_header_buffer_size; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1593 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1594 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1595 #endif |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1596 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1597 ls->backlog = in_addr[a].listen_conf->backlog; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1598 ls->rcvbuf = in_addr[a].listen_conf->rcvbuf; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1599 ls->sndbuf = in_addr[a].listen_conf->sndbuf; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1600 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1601 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1602 ls->accept_filter = in_addr[a].listen_conf->accept_filter; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1603 #endif |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1604 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1605 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1606 ls->deferred_accept = in_addr[a].listen_conf->deferred_accept; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1607 #endif |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1608 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1609 hip = ngx_palloc(cf->pool, sizeof(ngx_http_in_port_t)); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1610 if (hip == NULL) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1611 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1612 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1613 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1614 hip->port = in_port->port; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1615 |
2049 | 1616 hip->port_text.data = ngx_pnalloc(cf->pool, 7); |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1617 if (hip->port_text.data == NULL) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1618 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1619 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1620 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1621 ls->servers = hip; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1622 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1623 hip->port_text.len = ngx_sprintf(hip->port_text.data, ":%d", hip->port) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1624 - hip->port_text.data; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1625 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1626 in_addr = in_port->addrs.elts; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1627 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1628 if (in_addr[a].bind && in_addr[a].addr != INADDR_ANY) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1629 hip->naddrs = 1; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1630 done = 0; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1631 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1632 } else if (in_port->addrs.nelts > 1 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1633 && in_addr[last - 1].addr == INADDR_ANY) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1634 { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1635 hip->naddrs = last; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1636 done = 1; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1637 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1638 } else { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1639 hip->naddrs = 1; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1640 done = 0; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1641 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1642 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1643 hip->addrs = ngx_pcalloc(cf->pool, |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1644 hip->naddrs * sizeof(ngx_http_in_addr_t)); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1645 if (hip->addrs == NULL) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1646 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1647 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1648 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1649 for (i = 0; i < hip->naddrs; i++) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1650 hip->addrs[i].addr = in_addr[i].addr; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1651 hip->addrs[i].core_srv_conf = in_addr[i].core_srv_conf; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1652 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1653 if (in_addr[i].hash.buckets == NULL |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1654 && (in_addr[i].wc_head == NULL |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1655 || in_addr[i].wc_head->hash.buckets == NULL) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1656 && (in_addr[i].wc_head == NULL |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1657 || in_addr[i].wc_head->hash.buckets == NULL)) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1658 { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1659 continue; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1660 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1661 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1662 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t)); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1663 if (vn == NULL) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1664 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1665 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1666 hip->addrs[i].virtual_names = vn; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1667 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1668 vn->names.hash = in_addr[i].hash; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1669 vn->names.wc_head = in_addr[i].wc_head; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1670 vn->names.wc_tail = in_addr[i].wc_tail; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1671 #if (NGX_PCRE) |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1672 vn->nregex = in_addr[i].nregex; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1673 vn->regex = in_addr[i].regex; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1674 #endif |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1675 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1676 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1677 if (done) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1678 return NGX_OK; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1679 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1680 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1681 in_addr++; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1682 in_port->addrs.elts = in_addr; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1683 last--; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1684 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1685 a = 0; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1686 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1687 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1688 return NGX_OK; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1689 } |
2138 | 1690 |
1691 | |
1692 char * | |
1693 ngx_http_types_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1694 { | |
1695 char *p = conf; | |
1696 | |
1697 ngx_array_t **types; | |
1698 ngx_str_t *value, *default_type; | |
1699 ngx_uint_t i, n, hash; | |
1700 ngx_hash_key_t *type; | |
1701 | |
1702 types = (ngx_array_t **) (p + cmd->offset); | |
1703 | |
1704 default_type = cmd->post; | |
1705 | |
1706 if (*types == NULL) { | |
1707 *types = ngx_array_create(cf->temp_pool, 1, sizeof(ngx_hash_key_t)); | |
1708 if (*types == NULL) { | |
1709 return NGX_CONF_ERROR; | |
1710 } | |
1711 | |
1712 if (default_type) { | |
1713 type = ngx_array_push(*types); | |
1714 if (type == NULL) { | |
1715 return NGX_CONF_ERROR; | |
1716 } | |
1717 | |
1718 type->key = *default_type; | |
1719 type->key_hash = ngx_hash_key(default_type->data, | |
1720 default_type->len); | |
1721 type->value = (void *) 4; | |
1722 } | |
1723 } | |
1724 | |
1725 value = cf->args->elts; | |
1726 | |
1727 for (i = 1; i < cf->args->nelts; i++) { | |
1728 | |
1729 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len); | |
1730 value[i].data[value[i].len] = '\0'; | |
1731 | |
1732 type = (*types)->elts; | |
1733 for (n = 0; n < (*types)->nelts; n++) { | |
1734 | |
1735 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) { | |
1736 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
1737 "duplicate MIME type \"%V\"", &value[i]); | |
1738 continue; | |
1739 } | |
1740 } | |
1741 | |
1742 type = ngx_array_push(*types); | |
1743 if (type == NULL) { | |
1744 return NGX_CONF_ERROR; | |
1745 } | |
1746 | |
1747 type->key = value[i]; | |
1748 type->key_hash = hash; | |
1749 type->value = (void *) 4; | |
1750 } | |
1751 | |
1752 return NGX_CONF_OK; | |
1753 } | |
1754 | |
1755 | |
1756 char * | |
1757 ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t *keys, ngx_hash_t *types_hash, | |
1758 ngx_array_t *prev_keys, ngx_hash_t *prev_types_hash, | |
1759 ngx_str_t *default_types) | |
1760 { | |
1761 ngx_hash_init_t hash; | |
1762 | |
1763 if (keys == NULL) { | |
1764 | |
1765 if (prev_keys) { | |
1766 *types_hash = *prev_types_hash; | |
1767 return NGX_CONF_OK; | |
1768 } | |
1769 | |
1770 if (ngx_http_set_default_types(cf, &keys, default_types) | |
1771 != NGX_CONF_OK) | |
1772 { | |
1773 return NGX_CONF_ERROR; | |
1774 } | |
1775 } | |
1776 | |
1777 hash.hash = types_hash; | |
1778 hash.key = NULL; | |
1779 hash.max_size = 2048; | |
1780 hash.bucket_size = 64; | |
1781 hash.name = "test_types_hash"; | |
1782 hash.pool = cf->pool; | |
1783 hash.temp_pool = NULL; | |
1784 | |
1785 if (ngx_hash_init(&hash, keys->elts, keys->nelts) != NGX_OK) { | |
1786 return NGX_CONF_ERROR; | |
1787 } | |
1788 | |
1789 return NGX_CONF_OK; | |
1790 | |
1791 } | |
1792 | |
1793 | |
1794 char * | |
1795 ngx_http_set_default_types(ngx_conf_t *cf, ngx_array_t **types, | |
1796 ngx_str_t *default_type) | |
1797 { | |
1798 ngx_hash_key_t *type; | |
1799 | |
1800 *types = ngx_array_create(cf->temp_pool, 1, sizeof(ngx_hash_key_t)); | |
1801 if (*types == NULL) { | |
1802 return NGX_CONF_ERROR; | |
1803 } | |
1804 | |
1805 while (default_type->len) { | |
1806 | |
1807 type = ngx_array_push(*types); | |
1808 if (type == NULL) { | |
1809 return NGX_CONF_ERROR; | |
1810 } | |
1811 | |
1812 type->key = *default_type; | |
1813 type->key_hash = ngx_hash_key(default_type->data, | |
1814 default_type->len); | |
1815 type->value = (void *) 4; | |
1816 | |
1817 default_type++; | |
1818 } | |
1819 | |
1820 return NGX_CONF_OK; | |
1821 } |