Mercurial > hg > nginx-quic
annotate src/http/ngx_http.c @ 6230:2a621245f4cf
Win32: MSVC 2015 compatibility.
Resolved warnings about declarations that hide previous local declarations.
Warnings about WSASocketA() being deprecated resolved by explicit use of
WSASocketW() instead of WSASocket(). When compiling without IPv6 support,
WinSock deprecated warnings are disabled to allow use of gethostbyname().
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 17 Aug 2015 18:09:17 +0300 |
parents | 78c06e5e1d76 |
children | 257b51c37c5a |
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 |
4412 | 4 * Copyright (C) Nginx, Inc. |
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
|
5 */ |
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
|
6 |
2
ffffe1499bce
nginx-0.0.1-2002-08-16-19:27:03 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
2
diff
changeset
|
8 #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
|
9 #include <ngx_core.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 |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
21 static ngx_int_t ngx_http_add_addresses(ngx_conf_t *cf, |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
22 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port, |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
23 ngx_http_listen_opt_t *lsopt); |
455 | 24 static ngx_int_t ngx_http_add_address(ngx_conf_t *cf, |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
25 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port, |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
26 ngx_http_listen_opt_t *lsopt); |
3219 | 27 static ngx_int_t ngx_http_add_server(ngx_conf_t *cf, |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
28 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_addr_t *addr); |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
29 |
3730
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
30 static char *ngx_http_merge_servers(ngx_conf_t *cf, |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
31 ngx_http_core_main_conf_t *cmcf, ngx_http_module_t *module, |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
32 ngx_uint_t ctx_index); |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
33 static char *ngx_http_merge_locations(ngx_conf_t *cf, |
2027 | 34 ngx_queue_t *locations, void **loc_conf, ngx_http_module_t *module, |
499 | 35 ngx_uint_t ctx_index); |
2027 | 36 static ngx_int_t ngx_http_init_locations(ngx_conf_t *cf, |
37 ngx_http_core_srv_conf_t *cscf, ngx_http_core_loc_conf_t *pclcf); | |
38 static ngx_int_t ngx_http_init_static_location_trees(ngx_conf_t *cf, | |
39 ngx_http_core_loc_conf_t *pclcf); | |
40 static ngx_int_t ngx_http_cmp_locations(const ngx_queue_t *one, | |
41 const ngx_queue_t *two); | |
42 static ngx_int_t ngx_http_join_exact_locations(ngx_conf_t *cf, | |
43 ngx_queue_t *locations); | |
44 static void ngx_http_create_locations_list(ngx_queue_t *locations, | |
45 ngx_queue_t *q); | |
46 static ngx_http_location_tree_node_t * | |
47 ngx_http_create_locations_tree(ngx_conf_t *cf, ngx_queue_t *locations, | |
48 size_t prefix); | |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
49 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
50 static ngx_int_t ngx_http_optimize_servers(ngx_conf_t *cf, |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
51 ngx_http_core_main_conf_t *cmcf, ngx_array_t *ports); |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
52 static ngx_int_t ngx_http_server_names(ngx_conf_t *cf, |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
53 ngx_http_core_main_conf_t *cmcf, ngx_http_conf_addr_t *addr); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
54 static ngx_int_t ngx_http_cmp_conf_addrs(const void *one, const void *two); |
593 | 55 static int ngx_libc_cdecl ngx_http_cmp_dns_wildcards(const void *one, |
56 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
|
57 |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
58 static ngx_int_t ngx_http_init_listening(ngx_conf_t *cf, |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
59 ngx_http_conf_port_t *port); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
60 static ngx_listening_t *ngx_http_add_listening(ngx_conf_t *cf, |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
61 ngx_http_conf_addr_t *addr); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
62 static ngx_int_t ngx_http_add_addrs(ngx_conf_t *cf, ngx_http_port_t *hport, |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
63 ngx_http_conf_addr_t *addr); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
64 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
65 static ngx_int_t ngx_http_add_addrs6(ngx_conf_t *cf, ngx_http_port_t *hport, |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
66 ngx_http_conf_addr_t *addr); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
67 #endif |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
68 |
593 | 69 ngx_uint_t ngx_http_max_module; |
70 | |
45
f1ee46c036a4
nginx-0.0.1-2003-01-10-09:09:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
44
diff
changeset
|
71 |
6049
42d9beeb22db
Request body: filters support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5856
diff
changeset
|
72 ngx_http_output_header_filter_pt ngx_http_top_header_filter; |
42d9beeb22db
Request body: filters support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5856
diff
changeset
|
73 ngx_http_output_body_filter_pt ngx_http_top_body_filter; |
42d9beeb22db
Request body: filters support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5856
diff
changeset
|
74 ngx_http_request_body_filter_pt ngx_http_top_request_body_filter; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
75 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
76 |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2138
diff
changeset
|
77 ngx_str_t ngx_http_html_default_types[] = { |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2138
diff
changeset
|
78 ngx_string("text/html"), |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2138
diff
changeset
|
79 ngx_null_string |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2138
diff
changeset
|
80 }; |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2138
diff
changeset
|
81 |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2138
diff
changeset
|
82 |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
83 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
|
84 |
499 | 85 { ngx_string("http"), |
86 NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, | |
87 ngx_http_block, | |
88 0, | |
89 0, | |
90 NULL }, | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
91 |
499 | 92 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
|
93 }; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
94 |
577 | 95 |
311
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
96 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
|
97 ngx_string("http"), |
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
98 NULL, |
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
99 NULL |
577 | 100 }; |
311
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
101 |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
102 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
103 ngx_module_t ngx_http_module = { |
509 | 104 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
|
105 &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
|
106 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
|
107 NGX_CORE_MODULE, /* module type */ |
541 | 108 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
|
109 NULL, /* init module */ |
541 | 110 NULL, /* init process */ |
111 NULL, /* init thread */ | |
112 NULL, /* exit thread */ | |
113 NULL, /* exit process */ | |
114 NULL, /* exit master */ | |
115 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
|
116 }; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
117 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
118 |
499 | 119 static char * |
120 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
|
121 { |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
122 char *rv; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
123 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
|
124 ngx_conf_t pcf; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
125 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
|
126 ngx_http_conf_ctx_t *ctx; |
2027 | 127 ngx_http_core_loc_conf_t *clcf; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
128 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
|
129 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
|
130 |
6193
78c06e5e1d76
Disabled duplicate http, mail, and stream blocks.
Vladimir Homutov <vl@nginx.com>
parents:
6153
diff
changeset
|
131 if (*(ngx_http_conf_ctx_t **) conf) { |
78c06e5e1d76
Disabled duplicate http, mail, and stream blocks.
Vladimir Homutov <vl@nginx.com>
parents:
6153
diff
changeset
|
132 return "is duplicate"; |
78c06e5e1d76
Disabled duplicate http, mail, and stream blocks.
Vladimir Homutov <vl@nginx.com>
parents:
6153
diff
changeset
|
133 } |
78c06e5e1d76
Disabled duplicate http, mail, and stream blocks.
Vladimir Homutov <vl@nginx.com>
parents:
6153
diff
changeset
|
134 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
135 /* the main http context */ |
477 | 136 |
501 | 137 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); |
138 if (ctx == NULL) { | |
485 | 139 return NGX_CONF_ERROR; |
140 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
141 |
90
37530da31268
nginx-0.0.1-2003-05-16-19:27:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
89
diff
changeset
|
142 *(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
|
143 |
485 | 144 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
145 /* 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
|
146 |
71
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 continue; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
151 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
152 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
153 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
|
154 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
155 |
477 | 156 |
485 | 157 /* 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
|
158 |
485 | 159 ctx->main_conf = ngx_pcalloc(cf->pool, |
160 sizeof(void *) * ngx_http_max_module); | |
161 if (ctx->main_conf == NULL) { | |
162 return NGX_CONF_ERROR; | |
163 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
164 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
165 |
485 | 166 /* |
167 * the http null srv_conf context, it is used to merge | |
168 * the server{}s' srv_conf's | |
169 */ | |
170 | |
171 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
172 if (ctx->srv_conf == NULL) { | |
173 return NGX_CONF_ERROR; | |
174 } | |
175 | |
176 | |
177 /* | |
178 * the http null loc_conf context, it is used to merge | |
179 * the server{}s' loc_conf's | |
180 */ | |
181 | |
182 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
183 if (ctx->loc_conf == NULL) { | |
184 return NGX_CONF_ERROR; | |
185 } | |
186 | |
187 | |
188 /* | |
189 * create the main_conf's, the null srv_conf's, and the null loc_conf's | |
190 * of the all http modules | |
191 */ | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
192 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
193 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
|
194 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
|
195 continue; |
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 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
198 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
|
199 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
|
200 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
201 if (module->create_main_conf) { |
501 | 202 ctx->main_conf[mi] = module->create_main_conf(cf); |
203 if (ctx->main_conf[mi] == NULL) { | |
485 | 204 return NGX_CONF_ERROR; |
205 } | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
206 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
207 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
208 if (module->create_srv_conf) { |
501 | 209 ctx->srv_conf[mi] = module->create_srv_conf(cf); |
210 if (ctx->srv_conf[mi] == NULL) { | |
485 | 211 return NGX_CONF_ERROR; |
212 } | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
213 } |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
214 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
215 if (module->create_loc_conf) { |
501 | 216 ctx->loc_conf[mi] = module->create_loc_conf(cf); |
217 if (ctx->loc_conf[mi] == NULL) { | |
485 | 218 return NGX_CONF_ERROR; |
219 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
220 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
221 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
222 |
509 | 223 pcf = *cf; |
224 cf->ctx = ctx; | |
225 | |
226 for (m = 0; ngx_modules[m]; m++) { | |
227 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { | |
228 continue; | |
229 } | |
230 | |
231 module = ngx_modules[m]->ctx; | |
232 | |
233 if (module->preconfiguration) { | |
234 if (module->preconfiguration(cf) != NGX_OK) { | |
235 return NGX_CONF_ERROR; | |
236 } | |
237 } | |
238 } | |
485 | 239 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
240 /* 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
|
241 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
246 if (rv != NGX_CONF_OK) { |
2027 | 247 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
|
248 } |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
249 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
250 /* |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
251 * 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
|
252 * 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
|
253 */ |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
254 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
255 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
|
256 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
|
257 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
258 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
|
259 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
|
260 continue; |
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 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
263 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
|
264 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
|
265 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
266 /* 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
|
267 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
268 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
|
269 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
|
270 if (rv != NGX_CONF_OK) { |
2027 | 271 goto failed; |
91
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 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
274 |
3730
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
275 rv = ngx_http_merge_servers(cf, cmcf, module, mi); |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
276 if (rv != NGX_CONF_OK) { |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
277 goto failed; |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
278 } |
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
279 } |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
280 |
485 | 281 |
2027 | 282 /* create location trees */ |
283 | |
284 for (s = 0; s < cmcf->servers.nelts; s++) { | |
285 | |
286 clcf = cscfp[s]->ctx->loc_conf[ngx_http_core_module.ctx_index]; | |
287 | |
288 if (ngx_http_init_locations(cf, cscfp[s], clcf) != NGX_OK) { | |
289 return NGX_CONF_ERROR; | |
290 } | |
291 | |
292 if (ngx_http_init_static_location_trees(cf, clcf) != NGX_OK) { | |
293 return NGX_CONF_ERROR; | |
294 } | |
295 } | |
296 | |
297 | |
2021 | 298 if (ngx_http_init_phases(cf, cmcf) != NGX_OK) { |
485 | 299 return NGX_CONF_ERROR; |
300 } | |
301 | |
2021 | 302 if (ngx_http_init_headers_in_hash(cf, cmcf) != NGX_OK) { |
649 | 303 return NGX_CONF_ERROR; |
304 } | |
305 | |
509 | 306 |
307 for (m = 0; ngx_modules[m]; m++) { | |
308 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { | |
309 continue; | |
310 } | |
311 | |
312 module = ngx_modules[m]->ctx; | |
313 | |
314 if (module->postconfiguration) { | |
315 if (module->postconfiguration(cf) != NGX_OK) { | |
316 return NGX_CONF_ERROR; | |
317 } | |
318 } | |
319 } | |
320 | |
573 | 321 if (ngx_http_variables_init_vars(cf) != NGX_OK) { |
322 return NGX_CONF_ERROR; | |
323 } | |
509 | 324 |
325 /* | |
326 * http{}'s cf->ctx was needed while the configuration merging | |
327 * and in postconfiguration process | |
328 */ | |
329 | |
330 *cf = pcf; | |
331 | |
507 | 332 |
2021 | 333 if (ngx_http_init_phase_handlers(cf, cmcf) != NGX_OK) { |
681 | 334 return NGX_CONF_ERROR; |
335 } | |
336 | |
337 | |
455 | 338 /* 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
|
339 |
3217 | 340 if (ngx_http_optimize_servers(cf, cmcf, cmcf->ports) != NGX_OK) { |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
341 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
|
342 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
343 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
344 return NGX_CONF_OK; |
2027 | 345 |
346 failed: | |
347 | |
348 *cf = pcf; | |
349 | |
350 return rv; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
351 } |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
352 |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
353 |
2021 | 354 static ngx_int_t |
355 ngx_http_init_phases(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf) | |
356 { | |
357 if (ngx_array_init(&cmcf->phases[NGX_HTTP_POST_READ_PHASE].handlers, | |
358 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
359 != NGX_OK) | |
360 { | |
361 return NGX_ERROR; | |
362 } | |
363 | |
364 if (ngx_array_init(&cmcf->phases[NGX_HTTP_SERVER_REWRITE_PHASE].handlers, | |
365 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
366 != NGX_OK) | |
367 { | |
368 return NGX_ERROR; | |
369 } | |
370 | |
371 if (ngx_array_init(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers, | |
372 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
373 != NGX_OK) | |
374 { | |
375 return NGX_ERROR; | |
376 } | |
377 | |
378 if (ngx_array_init(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers, | |
379 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
380 != NGX_OK) | |
381 { | |
382 return NGX_ERROR; | |
383 } | |
384 | |
385 if (ngx_array_init(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers, | |
386 cf->pool, 2, sizeof(ngx_http_handler_pt)) | |
387 != NGX_OK) | |
388 { | |
389 return NGX_ERROR; | |
390 } | |
391 | |
392 if (ngx_array_init(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers, | |
393 cf->pool, 4, sizeof(ngx_http_handler_pt)) | |
394 != NGX_OK) | |
395 { | |
396 return NGX_ERROR; | |
397 } | |
398 | |
399 if (ngx_array_init(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers, | |
400 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
401 != NGX_OK) | |
402 { | |
403 return NGX_ERROR; | |
404 } | |
405 | |
406 return NGX_OK; | |
407 } | |
408 | |
409 | |
410 static ngx_int_t | |
411 ngx_http_init_headers_in_hash(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf) | |
412 { | |
413 ngx_array_t headers_in; | |
414 ngx_hash_key_t *hk; | |
415 ngx_hash_init_t hash; | |
416 ngx_http_header_t *header; | |
417 | |
418 if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t)) | |
419 != NGX_OK) | |
420 { | |
421 return NGX_ERROR; | |
422 } | |
423 | |
424 for (header = ngx_http_headers_in; header->name.len; header++) { | |
425 hk = ngx_array_push(&headers_in); | |
426 if (hk == NULL) { | |
427 return NGX_ERROR; | |
428 } | |
429 | |
430 hk->key = header->name; | |
431 hk->key_hash = ngx_hash_key_lc(header->name.data, header->name.len); | |
432 hk->value = header; | |
433 } | |
434 | |
435 hash.hash = &cmcf->headers_in_hash; | |
436 hash.key = ngx_hash_key_lc; | |
437 hash.max_size = 512; | |
438 hash.bucket_size = ngx_align(64, ngx_cacheline_size); | |
439 hash.name = "headers_in_hash"; | |
440 hash.pool = cf->pool; | |
441 hash.temp_pool = NULL; | |
442 | |
443 if (ngx_hash_init(&hash, headers_in.elts, headers_in.nelts) != NGX_OK) { | |
444 return NGX_ERROR; | |
445 } | |
446 | |
447 return NGX_OK; | |
448 } | |
449 | |
450 | |
451 static ngx_int_t | |
452 ngx_http_init_phase_handlers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf) | |
453 { | |
454 ngx_int_t j; | |
455 ngx_uint_t i, n; | |
456 ngx_uint_t find_config_index, use_rewrite, use_access; | |
457 ngx_http_handler_pt *h; | |
458 ngx_http_phase_handler_t *ph; | |
459 ngx_http_phase_handler_pt checker; | |
460 | |
461 cmcf->phase_engine.server_rewrite_index = (ngx_uint_t) -1; | |
462 cmcf->phase_engine.location_rewrite_index = (ngx_uint_t) -1; | |
463 find_config_index = 0; | |
464 use_rewrite = cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers.nelts ? 1 : 0; | |
465 use_access = cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers.nelts ? 1 : 0; | |
466 | |
2407 | 467 n = use_rewrite + use_access + cmcf->try_files + 1 /* find config phase */; |
2021 | 468 |
469 for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) { | |
470 n += cmcf->phases[i].handlers.nelts; | |
471 } | |
472 | |
473 ph = ngx_pcalloc(cf->pool, | |
474 n * sizeof(ngx_http_phase_handler_t) + sizeof(void *)); | |
475 if (ph == NULL) { | |
476 return NGX_ERROR; | |
477 } | |
478 | |
479 cmcf->phase_engine.handlers = ph; | |
480 n = 0; | |
481 | |
482 for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) { | |
483 h = cmcf->phases[i].handlers.elts; | |
484 | |
485 switch (i) { | |
486 | |
487 case NGX_HTTP_SERVER_REWRITE_PHASE: | |
488 if (cmcf->phase_engine.server_rewrite_index == (ngx_uint_t) -1) { | |
489 cmcf->phase_engine.server_rewrite_index = n; | |
490 } | |
3633 | 491 checker = ngx_http_core_rewrite_phase; |
2021 | 492 |
493 break; | |
494 | |
495 case NGX_HTTP_FIND_CONFIG_PHASE: | |
496 find_config_index = n; | |
497 | |
498 ph->checker = ngx_http_core_find_config_phase; | |
499 n++; | |
500 ph++; | |
501 | |
502 continue; | |
503 | |
504 case NGX_HTTP_REWRITE_PHASE: | |
505 if (cmcf->phase_engine.location_rewrite_index == (ngx_uint_t) -1) { | |
506 cmcf->phase_engine.location_rewrite_index = n; | |
507 } | |
3633 | 508 checker = ngx_http_core_rewrite_phase; |
2021 | 509 |
510 break; | |
511 | |
512 case NGX_HTTP_POST_REWRITE_PHASE: | |
513 if (use_rewrite) { | |
514 ph->checker = ngx_http_core_post_rewrite_phase; | |
515 ph->next = find_config_index; | |
516 n++; | |
517 ph++; | |
518 } | |
519 | |
520 continue; | |
521 | |
522 case NGX_HTTP_ACCESS_PHASE: | |
523 checker = ngx_http_core_access_phase; | |
524 n++; | |
525 break; | |
526 | |
527 case NGX_HTTP_POST_ACCESS_PHASE: | |
528 if (use_access) { | |
529 ph->checker = ngx_http_core_post_access_phase; | |
530 ph->next = n; | |
531 ph++; | |
532 } | |
533 | |
534 continue; | |
535 | |
2407 | 536 case NGX_HTTP_TRY_FILES_PHASE: |
537 if (cmcf->try_files) { | |
538 ph->checker = ngx_http_core_try_files_phase; | |
539 n++; | |
540 ph++; | |
541 } | |
542 | |
543 continue; | |
544 | |
2021 | 545 case NGX_HTTP_CONTENT_PHASE: |
546 checker = ngx_http_core_content_phase; | |
547 break; | |
548 | |
549 default: | |
550 checker = ngx_http_core_generic_phase; | |
551 } | |
552 | |
553 n += cmcf->phases[i].handlers.nelts; | |
554 | |
555 for (j = cmcf->phases[i].handlers.nelts - 1; j >=0; j--) { | |
556 ph->checker = checker; | |
557 ph->handler = h[j]; | |
558 ph->next = n; | |
559 ph++; | |
560 } | |
561 } | |
562 | |
563 return NGX_OK; | |
564 } | |
565 | |
566 | |
2027 | 567 static char * |
3730
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
568 ngx_http_merge_servers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf, |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
569 ngx_http_module_t *module, ngx_uint_t ctx_index) |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
570 { |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
571 char *rv; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
572 ngx_uint_t s; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
573 ngx_http_conf_ctx_t *ctx, saved; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
574 ngx_http_core_loc_conf_t *clcf; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
575 ngx_http_core_srv_conf_t **cscfp; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
576 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
577 cscfp = cmcf->servers.elts; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
578 ctx = (ngx_http_conf_ctx_t *) cf->ctx; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
579 saved = *ctx; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
580 rv = NGX_CONF_OK; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
581 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
582 for (s = 0; s < cmcf->servers.nelts; s++) { |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
583 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
584 /* merge the server{}s' srv_conf's */ |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
585 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
586 ctx->srv_conf = cscfp[s]->ctx->srv_conf; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
587 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
588 if (module->merge_srv_conf) { |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
589 rv = module->merge_srv_conf(cf, saved.srv_conf[ctx_index], |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
590 cscfp[s]->ctx->srv_conf[ctx_index]); |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
591 if (rv != NGX_CONF_OK) { |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
592 goto failed; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
593 } |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
594 } |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
595 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
596 if (module->merge_loc_conf) { |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
597 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
598 /* merge the server{}'s loc_conf */ |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
599 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
600 ctx->loc_conf = cscfp[s]->ctx->loc_conf; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
601 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
602 rv = module->merge_loc_conf(cf, saved.loc_conf[ctx_index], |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
603 cscfp[s]->ctx->loc_conf[ctx_index]); |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
604 if (rv != NGX_CONF_OK) { |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
605 goto failed; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
606 } |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
607 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
608 /* merge the locations{}' loc_conf's */ |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
609 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
610 clcf = cscfp[s]->ctx->loc_conf[ngx_http_core_module.ctx_index]; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
611 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
612 rv = ngx_http_merge_locations(cf, clcf->locations, |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
613 cscfp[s]->ctx->loc_conf, |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
614 module, ctx_index); |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
615 if (rv != NGX_CONF_OK) { |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
616 goto failed; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
617 } |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
618 } |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
619 } |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
620 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
621 failed: |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
622 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
623 *ctx = saved; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
624 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
625 return rv; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
626 } |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
627 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
628 |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
629 static char * |
2027 | 630 ngx_http_merge_locations(ngx_conf_t *cf, ngx_queue_t *locations, |
631 void **loc_conf, ngx_http_module_t *module, ngx_uint_t ctx_index) | |
632 { | |
633 char *rv; | |
634 ngx_queue_t *q; | |
3730
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
635 ngx_http_conf_ctx_t *ctx, saved; |
2027 | 636 ngx_http_core_loc_conf_t *clcf; |
637 ngx_http_location_queue_t *lq; | |
638 | |
639 if (locations == NULL) { | |
640 return NGX_CONF_OK; | |
641 } | |
642 | |
3730
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
643 ctx = (ngx_http_conf_ctx_t *) cf->ctx; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
644 saved = *ctx; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
645 |
2027 | 646 for (q = ngx_queue_head(locations); |
647 q != ngx_queue_sentinel(locations); | |
648 q = ngx_queue_next(q)) | |
649 { | |
650 lq = (ngx_http_location_queue_t *) q; | |
651 | |
652 clcf = lq->exact ? lq->exact : lq->inclusive; | |
3730
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
653 ctx->loc_conf = clcf->loc_conf; |
2027 | 654 |
655 rv = module->merge_loc_conf(cf, loc_conf[ctx_index], | |
656 clcf->loc_conf[ctx_index]); | |
657 if (rv != NGX_CONF_OK) { | |
658 return rv; | |
659 } | |
660 | |
661 rv = ngx_http_merge_locations(cf, clcf->locations, clcf->loc_conf, | |
662 module, ctx_index); | |
663 if (rv != NGX_CONF_OK) { | |
664 return rv; | |
665 } | |
666 } | |
667 | |
3730
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
668 *ctx = saved; |
d094e237abf4
ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
669 |
2027 | 670 return NGX_CONF_OK; |
671 } | |
672 | |
673 | |
674 static ngx_int_t | |
675 ngx_http_init_locations(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, | |
676 ngx_http_core_loc_conf_t *pclcf) | |
677 { | |
678 ngx_uint_t n; | |
679 ngx_queue_t *q, *locations, *named, tail; | |
680 ngx_http_core_loc_conf_t *clcf; | |
681 ngx_http_location_queue_t *lq; | |
682 ngx_http_core_loc_conf_t **clcfp; | |
683 #if (NGX_PCRE) | |
684 ngx_uint_t r; | |
685 ngx_queue_t *regex; | |
686 #endif | |
687 | |
688 locations = pclcf->locations; | |
689 | |
690 if (locations == NULL) { | |
691 return NGX_OK; | |
692 } | |
693 | |
694 ngx_queue_sort(locations, ngx_http_cmp_locations); | |
695 | |
696 named = NULL; | |
697 n = 0; | |
698 #if (NGX_PCRE) | |
699 regex = NULL; | |
700 r = 0; | |
701 #endif | |
702 | |
703 for (q = ngx_queue_head(locations); | |
704 q != ngx_queue_sentinel(locations); | |
705 q = ngx_queue_next(q)) | |
706 { | |
707 lq = (ngx_http_location_queue_t *) q; | |
708 | |
709 clcf = lq->exact ? lq->exact : lq->inclusive; | |
710 | |
711 if (ngx_http_init_locations(cf, NULL, clcf) != NGX_OK) { | |
712 return NGX_ERROR; | |
713 } | |
714 | |
715 #if (NGX_PCRE) | |
716 | |
717 if (clcf->regex) { | |
718 r++; | |
719 | |
720 if (regex == NULL) { | |
721 regex = q; | |
722 } | |
723 | |
724 continue; | |
725 } | |
726 | |
727 #endif | |
728 | |
729 if (clcf->named) { | |
730 n++; | |
731 | |
732 if (named == NULL) { | |
733 named = q; | |
734 } | |
735 | |
736 continue; | |
737 } | |
738 | |
739 if (clcf->noname) { | |
740 break; | |
741 } | |
742 } | |
743 | |
744 if (q != ngx_queue_sentinel(locations)) { | |
745 ngx_queue_split(locations, q, &tail); | |
746 } | |
747 | |
748 if (named) { | |
749 clcfp = ngx_palloc(cf->pool, | |
5741
b490bfbf8cfa
Fixed wrong sizeof() in ngx_http_init_locations().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5605
diff
changeset
|
750 (n + 1) * sizeof(ngx_http_core_loc_conf_t *)); |
2027 | 751 if (clcfp == NULL) { |
752 return NGX_ERROR; | |
753 } | |
754 | |
755 cscf->named_locations = clcfp; | |
756 | |
757 for (q = named; | |
758 q != ngx_queue_sentinel(locations); | |
759 q = ngx_queue_next(q)) | |
760 { | |
761 lq = (ngx_http_location_queue_t *) q; | |
762 | |
763 *(clcfp++) = lq->exact; | |
764 } | |
765 | |
766 *clcfp = NULL; | |
767 | |
768 ngx_queue_split(locations, named, &tail); | |
769 } | |
770 | |
771 #if (NGX_PCRE) | |
772 | |
773 if (regex) { | |
774 | |
775 clcfp = ngx_palloc(cf->pool, | |
5741
b490bfbf8cfa
Fixed wrong sizeof() in ngx_http_init_locations().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5605
diff
changeset
|
776 (r + 1) * sizeof(ngx_http_core_loc_conf_t *)); |
2027 | 777 if (clcfp == NULL) { |
778 return NGX_ERROR; | |
779 } | |
780 | |
781 pclcf->regex_locations = clcfp; | |
782 | |
783 for (q = regex; | |
784 q != ngx_queue_sentinel(locations); | |
785 q = ngx_queue_next(q)) | |
786 { | |
787 lq = (ngx_http_location_queue_t *) q; | |
788 | |
789 *(clcfp++) = lq->exact; | |
790 } | |
791 | |
792 *clcfp = NULL; | |
793 | |
794 ngx_queue_split(locations, regex, &tail); | |
795 } | |
796 | |
797 #endif | |
798 | |
799 return NGX_OK; | |
800 } | |
801 | |
802 | |
803 static ngx_int_t | |
804 ngx_http_init_static_location_trees(ngx_conf_t *cf, | |
805 ngx_http_core_loc_conf_t *pclcf) | |
806 { | |
807 ngx_queue_t *q, *locations; | |
808 ngx_http_core_loc_conf_t *clcf; | |
809 ngx_http_location_queue_t *lq; | |
810 | |
811 locations = pclcf->locations; | |
812 | |
813 if (locations == NULL) { | |
814 return NGX_OK; | |
815 } | |
816 | |
817 if (ngx_queue_empty(locations)) { | |
818 return NGX_OK; | |
819 } | |
820 | |
821 for (q = ngx_queue_head(locations); | |
822 q != ngx_queue_sentinel(locations); | |
823 q = ngx_queue_next(q)) | |
824 { | |
825 lq = (ngx_http_location_queue_t *) q; | |
826 | |
827 clcf = lq->exact ? lq->exact : lq->inclusive; | |
828 | |
829 if (ngx_http_init_static_location_trees(cf, clcf) != NGX_OK) { | |
830 return NGX_ERROR; | |
831 } | |
832 } | |
833 | |
834 if (ngx_http_join_exact_locations(cf, locations) != NGX_OK) { | |
835 return NGX_ERROR; | |
836 } | |
837 | |
838 ngx_http_create_locations_list(locations, ngx_queue_head(locations)); | |
839 | |
840 pclcf->static_locations = ngx_http_create_locations_tree(cf, locations, 0); | |
841 if (pclcf->static_locations == NULL) { | |
842 return NGX_ERROR; | |
843 } | |
844 | |
845 return NGX_OK; | |
846 } | |
847 | |
848 | |
849 ngx_int_t | |
850 ngx_http_add_location(ngx_conf_t *cf, ngx_queue_t **locations, | |
851 ngx_http_core_loc_conf_t *clcf) | |
852 { | |
853 ngx_http_location_queue_t *lq; | |
854 | |
855 if (*locations == NULL) { | |
856 *locations = ngx_palloc(cf->temp_pool, | |
857 sizeof(ngx_http_location_queue_t)); | |
858 if (*locations == NULL) { | |
859 return NGX_ERROR; | |
860 } | |
861 | |
862 ngx_queue_init(*locations); | |
863 } | |
864 | |
865 lq = ngx_palloc(cf->temp_pool, sizeof(ngx_http_location_queue_t)); | |
866 if (lq == NULL) { | |
867 return NGX_ERROR; | |
868 } | |
869 | |
870 if (clcf->exact_match | |
871 #if (NGX_PCRE) | |
872 || clcf->regex | |
873 #endif | |
874 || clcf->named || clcf->noname) | |
875 { | |
876 lq->exact = clcf; | |
877 lq->inclusive = NULL; | |
878 | |
879 } else { | |
880 lq->exact = NULL; | |
881 lq->inclusive = clcf; | |
882 } | |
883 | |
884 lq->name = &clcf->name; | |
885 lq->file_name = cf->conf_file->file.name.data; | |
886 lq->line = cf->conf_file->line; | |
887 | |
888 ngx_queue_init(&lq->list); | |
889 | |
890 ngx_queue_insert_tail(*locations, &lq->queue); | |
891 | |
892 return NGX_OK; | |
893 } | |
894 | |
895 | |
896 static ngx_int_t | |
897 ngx_http_cmp_locations(const ngx_queue_t *one, const ngx_queue_t *two) | |
898 { | |
899 ngx_int_t rc; | |
900 ngx_http_core_loc_conf_t *first, *second; | |
901 ngx_http_location_queue_t *lq1, *lq2; | |
902 | |
903 lq1 = (ngx_http_location_queue_t *) one; | |
904 lq2 = (ngx_http_location_queue_t *) two; | |
905 | |
906 first = lq1->exact ? lq1->exact : lq1->inclusive; | |
907 second = lq2->exact ? lq2->exact : lq2->inclusive; | |
908 | |
909 if (first->noname && !second->noname) { | |
910 /* shift no named locations to the end */ | |
911 return 1; | |
912 } | |
913 | |
914 if (!first->noname && second->noname) { | |
915 /* shift no named locations to the end */ | |
916 return -1; | |
917 } | |
918 | |
919 if (first->noname || second->noname) { | |
920 /* do not sort no named locations */ | |
921 return 0; | |
922 } | |
923 | |
924 if (first->named && !second->named) { | |
925 /* shift named locations to the end */ | |
926 return 1; | |
927 } | |
928 | |
929 if (!first->named && second->named) { | |
930 /* shift named locations to the end */ | |
931 return -1; | |
932 } | |
933 | |
934 if (first->named && second->named) { | |
935 return ngx_strcmp(first->name.data, second->name.data); | |
936 } | |
937 | |
938 #if (NGX_PCRE) | |
939 | |
940 if (first->regex && !second->regex) { | |
941 /* shift the regex matches to the end */ | |
942 return 1; | |
943 } | |
944 | |
945 if (!first->regex && second->regex) { | |
946 /* shift the regex matches to the end */ | |
947 return -1; | |
948 } | |
949 | |
950 if (first->regex || second->regex) { | |
951 /* do not sort the regex matches */ | |
952 return 0; | |
953 } | |
954 | |
955 #endif | |
956 | |
5388
fbaae7d1c033
Caseless location tree construction (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5124
diff
changeset
|
957 rc = ngx_filename_cmp(first->name.data, second->name.data, |
fbaae7d1c033
Caseless location tree construction (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5124
diff
changeset
|
958 ngx_min(first->name.len, second->name.len) + 1); |
2027 | 959 |
960 if (rc == 0 && !first->exact_match && second->exact_match) { | |
961 /* an exact match must be before the same inclusive one */ | |
962 return 1; | |
963 } | |
964 | |
965 return rc; | |
966 } | |
967 | |
968 | |
969 static ngx_int_t | |
970 ngx_http_join_exact_locations(ngx_conf_t *cf, ngx_queue_t *locations) | |
971 { | |
972 ngx_queue_t *q, *x; | |
973 ngx_http_location_queue_t *lq, *lx; | |
974 | |
975 q = ngx_queue_head(locations); | |
976 | |
977 while (q != ngx_queue_last(locations)) { | |
978 | |
979 x = ngx_queue_next(q); | |
980 | |
981 lq = (ngx_http_location_queue_t *) q; | |
982 lx = (ngx_http_location_queue_t *) x; | |
983 | |
5388
fbaae7d1c033
Caseless location tree construction (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5124
diff
changeset
|
984 if (lq->name->len == lx->name->len |
fbaae7d1c033
Caseless location tree construction (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5124
diff
changeset
|
985 && ngx_filename_cmp(lq->name->data, lx->name->data, lx->name->len) |
fbaae7d1c033
Caseless location tree construction (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5124
diff
changeset
|
986 == 0) |
fbaae7d1c033
Caseless location tree construction (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5124
diff
changeset
|
987 { |
2027 | 988 if ((lq->exact && lx->exact) || (lq->inclusive && lx->inclusive)) { |
989 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
990 "duplicate location \"%V\" in %s:%ui", | |
991 lx->name, lx->file_name, lx->line); | |
992 | |
993 return NGX_ERROR; | |
994 } | |
995 | |
996 lq->inclusive = lx->inclusive; | |
997 | |
998 ngx_queue_remove(x); | |
999 | |
1000 continue; | |
1001 } | |
1002 | |
1003 q = ngx_queue_next(q); | |
1004 } | |
1005 | |
1006 return NGX_OK; | |
1007 } | |
1008 | |
1009 | |
1010 static void | |
1011 ngx_http_create_locations_list(ngx_queue_t *locations, ngx_queue_t *q) | |
1012 { | |
1013 u_char *name; | |
1014 size_t len; | |
1015 ngx_queue_t *x, tail; | |
1016 ngx_http_location_queue_t *lq, *lx; | |
1017 | |
1018 if (q == ngx_queue_last(locations)) { | |
1019 return; | |
1020 } | |
1021 | |
1022 lq = (ngx_http_location_queue_t *) q; | |
1023 | |
1024 if (lq->inclusive == NULL) { | |
1025 ngx_http_create_locations_list(locations, ngx_queue_next(q)); | |
1026 return; | |
1027 } | |
1028 | |
1029 len = lq->name->len; | |
1030 name = lq->name->data; | |
1031 | |
1032 for (x = ngx_queue_next(q); | |
1033 x != ngx_queue_sentinel(locations); | |
1034 x = ngx_queue_next(x)) | |
1035 { | |
1036 lx = (ngx_http_location_queue_t *) x; | |
1037 | |
1038 if (len > lx->name->len | |
5388
fbaae7d1c033
Caseless location tree construction (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5124
diff
changeset
|
1039 || ngx_filename_cmp(name, lx->name->data, len) != 0) |
2027 | 1040 { |
1041 break; | |
1042 } | |
1043 } | |
1044 | |
1045 q = ngx_queue_next(q); | |
1046 | |
1047 if (q == x) { | |
1048 ngx_http_create_locations_list(locations, x); | |
1049 return; | |
1050 } | |
1051 | |
1052 ngx_queue_split(locations, q, &tail); | |
1053 ngx_queue_add(&lq->list, &tail); | |
1054 | |
1055 if (x == ngx_queue_sentinel(locations)) { | |
1056 ngx_http_create_locations_list(&lq->list, ngx_queue_head(&lq->list)); | |
1057 return; | |
1058 } | |
1059 | |
1060 ngx_queue_split(&lq->list, x, &tail); | |
1061 ngx_queue_add(locations, &tail); | |
1062 | |
1063 ngx_http_create_locations_list(&lq->list, ngx_queue_head(&lq->list)); | |
1064 | |
1065 ngx_http_create_locations_list(locations, x); | |
1066 } | |
1067 | |
1068 | |
1069 /* | |
1070 * to keep cache locality for left leaf nodes, allocate nodes in following | |
1071 * order: node, left subtree, right subtree, inclusive subtree | |
1072 */ | |
1073 | |
1074 static ngx_http_location_tree_node_t * | |
1075 ngx_http_create_locations_tree(ngx_conf_t *cf, ngx_queue_t *locations, | |
1076 size_t prefix) | |
1077 { | |
1078 size_t len; | |
1079 ngx_queue_t *q, tail; | |
1080 ngx_http_location_queue_t *lq; | |
1081 ngx_http_location_tree_node_t *node; | |
1082 | |
1083 q = ngx_queue_middle(locations); | |
1084 | |
1085 lq = (ngx_http_location_queue_t *) q; | |
1086 len = lq->name->len - prefix; | |
1087 | |
2049 | 1088 node = ngx_palloc(cf->pool, |
1089 offsetof(ngx_http_location_tree_node_t, name) + len); | |
2027 | 1090 if (node == NULL) { |
1091 return NULL; | |
1092 } | |
1093 | |
2039
4d8140271204
*) add ngx_palloc_aligned() to allocate explicitlty aligned memory
Igor Sysoev <igor@sysoev.ru>
parents:
2029
diff
changeset
|
1094 node->left = NULL; |
4d8140271204
*) add ngx_palloc_aligned() to allocate explicitlty aligned memory
Igor Sysoev <igor@sysoev.ru>
parents:
2029
diff
changeset
|
1095 node->right = NULL; |
4d8140271204
*) add ngx_palloc_aligned() to allocate explicitlty aligned memory
Igor Sysoev <igor@sysoev.ru>
parents:
2029
diff
changeset
|
1096 node->tree = NULL; |
2027 | 1097 node->exact = lq->exact; |
1098 node->inclusive = lq->inclusive; | |
1099 | |
1100 node->auto_redirect = (u_char) ((lq->exact && lq->exact->auto_redirect) | |
1101 || (lq->inclusive && lq->inclusive->auto_redirect)); | |
1102 | |
1103 node->len = (u_char) len; | |
1104 ngx_memcpy(node->name, &lq->name->data[prefix], len); | |
1105 | |
1106 ngx_queue_split(locations, q, &tail); | |
1107 | |
1108 if (ngx_queue_empty(locations)) { | |
1109 /* | |
1110 * ngx_queue_split() insures that if left part is empty, | |
1111 * then right one is empty too | |
1112 */ | |
1113 goto inclusive; | |
1114 } | |
1115 | |
1116 node->left = ngx_http_create_locations_tree(cf, locations, prefix); | |
1117 if (node->left == NULL) { | |
1118 return NULL; | |
1119 } | |
1120 | |
1121 ngx_queue_remove(q); | |
1122 | |
1123 if (ngx_queue_empty(&tail)) { | |
1124 goto inclusive; | |
1125 } | |
1126 | |
1127 node->right = ngx_http_create_locations_tree(cf, &tail, prefix); | |
1128 if (node->right == NULL) { | |
1129 return NULL; | |
1130 } | |
1131 | |
1132 inclusive: | |
1133 | |
1134 if (ngx_queue_empty(&lq->list)) { | |
1135 return node; | |
1136 } | |
1137 | |
1138 node->tree = ngx_http_create_locations_tree(cf, &lq->list, prefix + len); | |
1139 if (node->tree == NULL) { | |
1140 return NULL; | |
1141 } | |
1142 | |
1143 return node; | |
1144 } | |
1145 | |
1146 | |
3217 | 1147 ngx_int_t |
1148 ngx_http_add_listen(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, | |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
1149 ngx_http_listen_opt_t *lsopt) |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1150 { |
3217 | 1151 in_port_t p; |
1152 ngx_uint_t i; | |
1153 struct sockaddr *sa; | |
1154 struct sockaddr_in *sin; | |
1155 ngx_http_conf_port_t *port; | |
1156 ngx_http_core_main_conf_t *cmcf; | |
1157 #if (NGX_HAVE_INET6) | |
1158 struct sockaddr_in6 *sin6; | |
1159 #endif | |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1160 |
3217 | 1161 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1162 |
3217 | 1163 if (cmcf->ports == NULL) { |
1164 cmcf->ports = ngx_array_create(cf->temp_pool, 2, | |
1165 sizeof(ngx_http_conf_port_t)); | |
1166 if (cmcf->ports == NULL) { | |
1167 return NGX_ERROR; | |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1168 } |
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 |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1171 sa = &lsopt->u.sockaddr; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1172 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1173 switch (sa->sa_family) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1174 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1175 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1176 case AF_INET6: |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1177 sin6 = &lsopt->u.sockaddr_in6; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1178 p = sin6->sin6_port; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1179 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1180 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1181 |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1182 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1183 case AF_UNIX: |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1184 p = 0; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1185 break; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1186 #endif |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1187 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1188 default: /* AF_INET */ |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1189 sin = &lsopt->u.sockaddr_in; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1190 p = sin->sin_port; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1191 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1192 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1193 |
3217 | 1194 port = cmcf->ports->elts; |
1195 for (i = 0; i < cmcf->ports->nelts; i++) { | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1196 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1197 if (p != port[i].port || sa->sa_family != port[i].family) { |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1198 continue; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1199 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1200 |
2852
dfe04af9d30b
update comments missed in r2513
Igor Sysoev <igor@sysoev.ru>
parents:
2851
diff
changeset
|
1201 /* a port is already in the port list */ |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1202 |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
1203 return ngx_http_add_addresses(cf, cscf, &port[i], lsopt); |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1204 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1205 |
2852
dfe04af9d30b
update comments missed in r2513
Igor Sysoev <igor@sysoev.ru>
parents:
2851
diff
changeset
|
1206 /* add a port to the port list */ |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1207 |
3217 | 1208 port = ngx_array_push(cmcf->ports); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1209 if (port == NULL) { |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1210 return NGX_ERROR; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1211 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1212 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1213 port->family = sa->sa_family; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1214 port->port = p; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1215 port->addrs.elts = NULL; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1216 |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
1217 return ngx_http_add_address(cf, cscf, port, lsopt); |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1218 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1219 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1220 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1221 static ngx_int_t |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1222 ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
1223 ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt) |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1224 { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1225 u_char *p; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1226 size_t len, off; |
6128
69ad3e77922b
Merge proxy_protocol setting of listen directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6049
diff
changeset
|
1227 ngx_uint_t i, default_server, proxy_protocol; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1228 struct sockaddr *sa; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1229 ngx_http_conf_addr_t *addr; |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1230 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1231 struct sockaddr_un *saun; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1232 #endif |
3764
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1233 #if (NGX_HTTP_SSL) |
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1234 ngx_uint_t ssl; |
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1235 #endif |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1236 #if (NGX_HTTP_SPDY) |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1237 ngx_uint_t spdy; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1238 #endif |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1239 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1240 /* |
4133
59b99f217c6d
Replaced "can not" with "cannot" and "could not" in a bunch of places.
Ruslan Ermilov <ru@nginx.com>
parents:
3825
diff
changeset
|
1241 * we cannot compare whole sockaddr struct's as kernel |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1242 * may fill some fields in inherited sockaddr struct's |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1243 */ |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1244 |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1245 sa = &lsopt->u.sockaddr; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1246 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1247 switch (sa->sa_family) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1248 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1249 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1250 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1251 off = offsetof(struct sockaddr_in6, sin6_addr); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1252 len = 16; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1253 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1254 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1255 |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1256 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1257 case AF_UNIX: |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1258 off = offsetof(struct sockaddr_un, sun_path); |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1259 len = sizeof(saun->sun_path); |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1260 break; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1261 #endif |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1262 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1263 default: /* AF_INET */ |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1264 off = offsetof(struct sockaddr_in, sin_addr); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1265 len = 4; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1266 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1267 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1268 |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1269 p = lsopt->u.sockaddr_data + off; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1270 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1271 addr = port->addrs.elts; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1272 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1273 for (i = 0; i < port->addrs.nelts; i++) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1274 |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1275 if (ngx_memcmp(p, addr[i].opt.u.sockaddr_data + off, len) != 0) { |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1276 continue; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1277 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1278 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1279 /* the address is already in the address list */ |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1280 |
3219 | 1281 if (ngx_http_add_server(cf, cscf, &addr[i]) != NGX_OK) { |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1282 return NGX_ERROR; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1283 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1284 |
3229
a632dc9f3e73
fix r3225 and r3227: preserve default_server bit during listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3227
diff
changeset
|
1285 /* preserve default_server bit during listen options overwriting */ |
a632dc9f3e73
fix r3225 and r3227: preserve default_server bit during listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3227
diff
changeset
|
1286 default_server = addr[i].opt.default_server; |
a632dc9f3e73
fix r3225 and r3227: preserve default_server bit during listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3227
diff
changeset
|
1287 |
6128
69ad3e77922b
Merge proxy_protocol setting of listen directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6049
diff
changeset
|
1288 proxy_protocol = lsopt->proxy_protocol || addr[i].opt.proxy_protocol; |
69ad3e77922b
Merge proxy_protocol setting of listen directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6049
diff
changeset
|
1289 |
3764
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1290 #if (NGX_HTTP_SSL) |
3768
098cd8119861
nginx uses SSL mode for a listen socket with any option set,
Igor Sysoev <igor@sysoev.ru>
parents:
3764
diff
changeset
|
1291 ssl = lsopt->ssl || addr[i].opt.ssl; |
3764
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1292 #endif |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1293 #if (NGX_HTTP_SPDY) |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1294 spdy = lsopt->spdy || addr[i].opt.spdy; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1295 #endif |
3764
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1296 |
3226
4872f86df719
fix r3225: it overrode the listen options by default server default options
Igor Sysoev <igor@sysoev.ru>
parents:
3224
diff
changeset
|
1297 if (lsopt->set) { |
4872f86df719
fix r3225: it overrode the listen options by default server default options
Igor Sysoev <igor@sysoev.ru>
parents:
3224
diff
changeset
|
1298 |
4872f86df719
fix r3225: it overrode the listen options by default server default options
Igor Sysoev <igor@sysoev.ru>
parents:
3224
diff
changeset
|
1299 if (addr[i].opt.set) { |
4872f86df719
fix r3225: it overrode the listen options by default server default options
Igor Sysoev <igor@sysoev.ru>
parents:
3224
diff
changeset
|
1300 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
4142 | 1301 "duplicate listen options for %s", addr[i].opt.addr); |
3226
4872f86df719
fix r3225: it overrode the listen options by default server default options
Igor Sysoev <igor@sysoev.ru>
parents:
3224
diff
changeset
|
1302 return NGX_ERROR; |
4872f86df719
fix r3225: it overrode the listen options by default server default options
Igor Sysoev <igor@sysoev.ru>
parents:
3224
diff
changeset
|
1303 } |
4872f86df719
fix r3225: it overrode the listen options by default server default options
Igor Sysoev <igor@sysoev.ru>
parents:
3224
diff
changeset
|
1304 |
4872f86df719
fix r3225: it overrode the listen options by default server default options
Igor Sysoev <igor@sysoev.ru>
parents:
3224
diff
changeset
|
1305 addr[i].opt = *lsopt; |
3224
8e76e636ae3b
allow to set listen options in any server
Igor Sysoev <igor@sysoev.ru>
parents:
3223
diff
changeset
|
1306 } |
8e76e636ae3b
allow to set listen options in any server
Igor Sysoev <igor@sysoev.ru>
parents:
3223
diff
changeset
|
1307 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1308 /* check the duplicate "default" server for this address:port */ |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1309 |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
1310 if (lsopt->default_server) { |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1311 |
3229
a632dc9f3e73
fix r3225 and r3227: preserve default_server bit during listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3227
diff
changeset
|
1312 if (default_server) { |
3217 | 1313 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3223
bfcc1a6dd184
add listen address in error message
Igor Sysoev <igor@sysoev.ru>
parents:
3221
diff
changeset
|
1314 "a duplicate default server for %s", addr[i].opt.addr); |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1315 return NGX_ERROR; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1316 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1317 |
3229
a632dc9f3e73
fix r3225 and r3227: preserve default_server bit during listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3227
diff
changeset
|
1318 default_server = 1; |
3221
c8de5a8b6d17
rename core_srv_conf fields to more understandable default_server and server
Igor Sysoev <igor@sysoev.ru>
parents:
3220
diff
changeset
|
1319 addr[i].default_server = cscf; |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1320 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1321 |
3229
a632dc9f3e73
fix r3225 and r3227: preserve default_server bit during listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3227
diff
changeset
|
1322 addr[i].opt.default_server = default_server; |
6128
69ad3e77922b
Merge proxy_protocol setting of listen directives.
Roman Arutyunyan <arut@nginx.com>
parents:
6049
diff
changeset
|
1323 addr[i].opt.proxy_protocol = proxy_protocol; |
3764
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1324 #if (NGX_HTTP_SSL) |
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1325 addr[i].opt.ssl = ssl; |
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1326 #endif |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1327 #if (NGX_HTTP_SPDY) |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1328 addr[i].opt.spdy = spdy; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1329 #endif |
3229
a632dc9f3e73
fix r3225 and r3227: preserve default_server bit during listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3227
diff
changeset
|
1330 |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1331 return NGX_OK; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1332 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1333 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1334 /* add the address to the addresses list that bound to this port */ |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1335 |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
1336 return ngx_http_add_address(cf, cscf, port, lsopt); |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1337 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1338 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1339 |
455 | 1340 /* |
1341 * add the server address, the server names and the server core module | |
2852
dfe04af9d30b
update comments missed in r2513
Igor Sysoev <igor@sysoev.ru>
parents:
2851
diff
changeset
|
1342 * configurations to the port list |
455 | 1343 */ |
1344 | |
499 | 1345 static ngx_int_t |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1346 ngx_http_add_address(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
1347 ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt) |
455 | 1348 { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1349 ngx_http_conf_addr_t *addr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1350 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1351 if (port->addrs.elts == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1352 if (ngx_array_init(&port->addrs, cf->temp_pool, 4, |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1353 sizeof(ngx_http_conf_addr_t)) |
1385 | 1354 != NGX_OK) |
455 | 1355 { |
1356 return NGX_ERROR; | |
1357 } | |
1358 } | |
1359 | |
5545
01e2a5bcdd8f
SSL: support ALPN (IETF's successor to NPN).
Piotr Sikora <piotr@cloudflare.com>
parents:
5456
diff
changeset
|
1360 #if (NGX_HTTP_SPDY && NGX_HTTP_SSL \ |
01e2a5bcdd8f
SSL: support ALPN (IETF's successor to NPN).
Piotr Sikora <piotr@cloudflare.com>
parents:
5456
diff
changeset
|
1361 && !defined TLSEXT_TYPE_application_layer_protocol_negotiation \ |
01e2a5bcdd8f
SSL: support ALPN (IETF's successor to NPN).
Piotr Sikora <piotr@cloudflare.com>
parents:
5456
diff
changeset
|
1362 && !defined TLSEXT_TYPE_next_proto_neg) |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1363 if (lsopt->spdy && lsopt->ssl) { |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1364 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
5545
01e2a5bcdd8f
SSL: support ALPN (IETF's successor to NPN).
Piotr Sikora <piotr@cloudflare.com>
parents:
5456
diff
changeset
|
1365 "nginx was built without OpenSSL ALPN or NPN " |
01e2a5bcdd8f
SSL: support ALPN (IETF's successor to NPN).
Piotr Sikora <piotr@cloudflare.com>
parents:
5456
diff
changeset
|
1366 "support, SPDY is not enabled for %s", lsopt->addr); |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1367 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1368 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1369 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1370 addr = ngx_array_push(&port->addrs); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1371 if (addr == NULL) { |
455 | 1372 return NGX_ERROR; |
1373 } | |
1374 | |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
1375 addr->opt = *lsopt; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1376 addr->hash.buckets = NULL; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1377 addr->hash.size = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1378 addr->wc_head = NULL; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1379 addr->wc_tail = NULL; |
1387 | 1380 #if (NGX_PCRE) |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1381 addr->nregex = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1382 addr->regex = NULL; |
1387 | 1383 #endif |
3221
c8de5a8b6d17
rename core_srv_conf fields to more understandable default_server and server
Igor Sysoev <igor@sysoev.ru>
parents:
3220
diff
changeset
|
1384 addr->default_server = cscf; |
3219 | 1385 addr->servers.elts = NULL; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1386 |
3219 | 1387 return ngx_http_add_server(cf, cscf, addr); |
455 | 1388 } |
1389 | |
1390 | |
3219 | 1391 /* add the server core module configuration to the address:port */ |
455 | 1392 |
499 | 1393 static ngx_int_t |
3219 | 1394 ngx_http_add_server(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1395 ngx_http_conf_addr_t *addr) |
455 | 1396 { |
3227
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1397 ngx_uint_t i; |
3219 | 1398 ngx_http_core_srv_conf_t **server; |
455 | 1399 |
3219 | 1400 if (addr->servers.elts == NULL) { |
1401 if (ngx_array_init(&addr->servers, cf->temp_pool, 4, | |
1402 sizeof(ngx_http_core_srv_conf_t *)) | |
1385 | 1403 != NGX_OK) |
477 | 1404 { |
1405 return NGX_ERROR; | |
1406 } | |
3227
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1407 |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1408 } else { |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1409 server = addr->servers.elts; |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1410 for (i = 0; i < addr->servers.nelts; i++) { |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1411 if (server[i] == cscf) { |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1412 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1413 "a duplicate listen %s", addr->opt.addr); |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1414 return NGX_ERROR; |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1415 } |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1416 } |
477 | 1417 } |
1418 | |
3219 | 1419 server = ngx_array_push(&addr->servers); |
1420 if (server == NULL) { | |
1421 return NGX_ERROR; | |
1422 } | |
477 | 1423 |
3219 | 1424 *server = cscf; |
455 | 1425 |
1426 return NGX_OK; | |
1427 } | |
1428 | |
1429 | |
1956
cb8c0c8e0c27
use ngx_int_t in ngx_sort() callback
Igor Sysoev <igor@sysoev.ru>
parents:
1910
diff
changeset
|
1430 static ngx_int_t |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1431 ngx_http_optimize_servers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf, |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1432 ngx_array_t *ports) |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1433 { |
3258 | 1434 ngx_uint_t p, a; |
3219 | 1435 ngx_http_conf_port_t *port; |
1436 ngx_http_conf_addr_t *addr; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1437 |
3257
8bd88de8fecd
fix segfault if http {} block is empty, the bug had been introduced in r3218
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
1438 if (ports == NULL) { |
8bd88de8fecd
fix segfault if http {} block is empty, the bug had been introduced in r3218
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
1439 return NGX_OK; |
8bd88de8fecd
fix segfault if http {} block is empty, the bug had been introduced in r3218
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
1440 } |
8bd88de8fecd
fix segfault if http {} block is empty, the bug had been introduced in r3218
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
1441 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1442 port = ports->elts; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1443 for (p = 0; p < ports->nelts; p++) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1444 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1445 ngx_sort(port[p].addrs.elts, (size_t) port[p].addrs.nelts, |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1446 sizeof(ngx_http_conf_addr_t), ngx_http_cmp_conf_addrs); |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1447 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1448 /* |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1449 * check whether all name-based servers have the same |
4572
67653855682e
Fixed spelling in multiline C comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
1450 * configuration as a default server for given address:port |
2022
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 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1453 addr = port[p].addrs.elts; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1454 for (a = 0; a < port[p].addrs.nelts; a++) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1455 |
3219 | 1456 if (addr[a].servers.nelts > 1 |
2583
1fb5e7e05a4e
always run regex in server_name to get captures
Igor Sysoev <igor@sysoev.ru>
parents:
2580
diff
changeset
|
1457 #if (NGX_PCRE) |
3221
c8de5a8b6d17
rename core_srv_conf fields to more understandable default_server and server
Igor Sysoev <igor@sysoev.ru>
parents:
3220
diff
changeset
|
1458 || addr[a].default_server->captures |
2583
1fb5e7e05a4e
always run regex in server_name to get captures
Igor Sysoev <igor@sysoev.ru>
parents:
2580
diff
changeset
|
1459 #endif |
3219 | 1460 ) |
1461 { | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1462 if (ngx_http_server_names(cf, cmcf, &addr[a]) != NGX_OK) { |
2022
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 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1467 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1468 if (ngx_http_init_listening(cf, &port[p]) != NGX_OK) { |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1469 return NGX_ERROR; |
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 } |
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 return NGX_OK; |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1474 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1475 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1476 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1477 static ngx_int_t |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1478 ngx_http_server_names(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf, |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1479 ngx_http_conf_addr_t *addr) |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1480 { |
3219 | 1481 ngx_int_t rc; |
1482 ngx_uint_t n, s; | |
1483 ngx_hash_init_t hash; | |
1484 ngx_hash_keys_arrays_t ha; | |
1485 ngx_http_server_name_t *name; | |
1486 ngx_http_core_srv_conf_t **cscfp; | |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1487 #if (NGX_PCRE) |
3219 | 1488 ngx_uint_t regex, i; |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1489 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1490 regex = 0; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1491 #endif |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1492 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1493 ngx_memzero(&ha, sizeof(ngx_hash_keys_arrays_t)); |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1494 |
5124
5482671df278
Use NGX_DEFAULT_POOL_SIZE macro where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
1495 ha.temp_pool = ngx_create_pool(NGX_DEFAULT_POOL_SIZE, cf->log); |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1496 if (ha.temp_pool == NULL) { |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1497 return NGX_ERROR; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1498 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1499 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1500 ha.pool = cf->pool; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1501 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1502 if (ngx_hash_keys_array_init(&ha, NGX_HASH_LARGE) != NGX_OK) { |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1503 goto failed; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1504 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1505 |
3219 | 1506 cscfp = addr->servers.elts; |
1507 | |
1508 for (s = 0; s < addr->servers.nelts; s++) { | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1509 |
3219 | 1510 name = cscfp[s]->server_names.elts; |
1511 | |
1512 for (n = 0; n < cscfp[s]->server_names.nelts; n++) { | |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1513 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1514 #if (NGX_PCRE) |
3219 | 1515 if (name[n].regex) { |
1516 regex++; | |
1517 continue; | |
1518 } | |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1519 #endif |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1520 |
3221
c8de5a8b6d17
rename core_srv_conf fields to more understandable default_server and server
Igor Sysoev <igor@sysoev.ru>
parents:
3220
diff
changeset
|
1521 rc = ngx_hash_add_key(&ha, &name[n].name, name[n].server, |
3219 | 1522 NGX_HASH_WILDCARD_KEY); |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1523 |
3219 | 1524 if (rc == NGX_ERROR) { |
1525 return NGX_ERROR; | |
1526 } | |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1527 |
3219 | 1528 if (rc == NGX_DECLINED) { |
1529 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
1530 "invalid server name or wildcard \"%V\" on %s", | |
1531 &name[n].name, addr->opt.addr); | |
1532 return NGX_ERROR; | |
1533 } | |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1534 |
3219 | 1535 if (rc == NGX_BUSY) { |
3823 | 1536 ngx_log_error(NGX_LOG_WARN, cf->log, 0, |
3219 | 1537 "conflicting server name \"%V\" on %s, ignored", |
1538 &name[n].name, addr->opt.addr); | |
1539 } | |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1540 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1541 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1542 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1543 hash.key = ngx_hash_key_lc; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1544 hash.max_size = cmcf->server_names_hash_max_size; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1545 hash.bucket_size = cmcf->server_names_hash_bucket_size; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1546 hash.name = "server_names_hash"; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1547 hash.pool = cf->pool; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1548 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1549 if (ha.keys.nelts) { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1550 hash.hash = &addr->hash; |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1551 hash.temp_pool = NULL; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1552 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1553 if (ngx_hash_init(&hash, ha.keys.elts, ha.keys.nelts) != NGX_OK) { |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1554 goto failed; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1555 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1556 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1557 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1558 if (ha.dns_wc_head.nelts) { |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1559 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1560 ngx_qsort(ha.dns_wc_head.elts, (size_t) ha.dns_wc_head.nelts, |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1561 sizeof(ngx_hash_key_t), ngx_http_cmp_dns_wildcards); |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1562 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1563 hash.hash = NULL; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1564 hash.temp_pool = ha.temp_pool; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1565 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1566 if (ngx_hash_wildcard_init(&hash, ha.dns_wc_head.elts, |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1567 ha.dns_wc_head.nelts) |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1568 != NGX_OK) |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1569 { |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1570 goto failed; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1571 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1572 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1573 addr->wc_head = (ngx_hash_wildcard_t *) hash.hash; |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1574 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1575 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1576 if (ha.dns_wc_tail.nelts) { |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1577 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1578 ngx_qsort(ha.dns_wc_tail.elts, (size_t) ha.dns_wc_tail.nelts, |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1579 sizeof(ngx_hash_key_t), ngx_http_cmp_dns_wildcards); |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1580 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1581 hash.hash = NULL; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1582 hash.temp_pool = ha.temp_pool; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1583 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1584 if (ngx_hash_wildcard_init(&hash, ha.dns_wc_tail.elts, |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1585 ha.dns_wc_tail.nelts) |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1586 != NGX_OK) |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1587 { |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1588 goto failed; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1589 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1590 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1591 addr->wc_tail = (ngx_hash_wildcard_t *) hash.hash; |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1592 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1593 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1594 ngx_destroy_pool(ha.temp_pool); |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1595 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1596 #if (NGX_PCRE) |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1597 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1598 if (regex == 0) { |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1599 return NGX_OK; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1600 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1601 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1602 addr->nregex = regex; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1603 addr->regex = ngx_palloc(cf->pool, regex * sizeof(ngx_http_server_name_t)); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1604 if (addr->regex == NULL) { |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1605 return NGX_ERROR; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1606 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1607 |
3219 | 1608 i = 0; |
1609 | |
1610 for (s = 0; s < addr->servers.nelts; s++) { | |
1611 | |
1612 name = cscfp[s]->server_names.elts; | |
1613 | |
1614 for (n = 0; n < cscfp[s]->server_names.nelts; n++) { | |
1615 if (name[n].regex) { | |
1616 addr->regex[i++] = name[n]; | |
1617 } | |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1618 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1619 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1620 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1621 #endif |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1622 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1623 return NGX_OK; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1624 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1625 failed: |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1626 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1627 ngx_destroy_pool(ha.temp_pool); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1628 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1629 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1630 } |
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 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1633 static ngx_int_t |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1634 ngx_http_cmp_conf_addrs(const void *one, const void *two) |
593 | 1635 { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1636 ngx_http_conf_addr_t *first, *second; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1637 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1638 first = (ngx_http_conf_addr_t *) one; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1639 second = (ngx_http_conf_addr_t *) two; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1640 |
3218
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1641 if (first->opt.wildcard) { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1642 /* a wildcard address must be the last resort, shift it to the end */ |
593 | 1643 return 1; |
1644 } | |
1645 | |
4755
7ab10517ae58
Fixed sorting of listen addresses so that wildcard address is always at
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
1646 if (second->opt.wildcard) { |
7ab10517ae58
Fixed sorting of listen addresses so that wildcard address is always at
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
1647 /* a wildcard address must be the last resort, shift it to the end */ |
7ab10517ae58
Fixed sorting of listen addresses so that wildcard address is always at
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
1648 return -1; |
7ab10517ae58
Fixed sorting of listen addresses so that wildcard address is always at
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
1649 } |
7ab10517ae58
Fixed sorting of listen addresses so that wildcard address is always at
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
1650 |
3218
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1651 if (first->opt.bind && !second->opt.bind) { |
593 | 1652 /* shift explicit bind()ed addresses to the start */ |
1653 return -1; | |
1654 } | |
1655 | |
3218
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1656 if (!first->opt.bind && second->opt.bind) { |
593 | 1657 /* shift explicit bind()ed addresses to the start */ |
1658 return 1; | |
1659 } | |
1660 | |
1661 /* do not sort by default */ | |
1662 | |
1663 return 0; | |
1664 } | |
1665 | |
1666 | |
1667 static int ngx_libc_cdecl | |
1668 ngx_http_cmp_dns_wildcards(const void *one, const void *two) | |
1669 { | |
1670 ngx_hash_key_t *first, *second; | |
1671 | |
1672 first = (ngx_hash_key_t *) one; | |
1673 second = (ngx_hash_key_t *) two; | |
1674 | |
3116
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
2852
diff
changeset
|
1675 return ngx_dns_strcmp(first->key.data, second->key.data); |
593 | 1676 } |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1677 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1678 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1679 static ngx_int_t |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1680 ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_port_t *port) |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1681 { |
2533 | 1682 ngx_uint_t i, last, bind_wildcard; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1683 ngx_listening_t *ls; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1684 ngx_http_port_t *hport; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1685 ngx_http_conf_addr_t *addr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1686 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1687 addr = port->addrs.elts; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1688 last = port->addrs.nelts; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1689 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1690 /* |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1691 * If there is a binding to an "*:port" then we need to bind() to |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1692 * the "*:port" only and ignore other implicit bindings. The bindings |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1693 * have been already sorted: explicit bindings are on the start, then |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1694 * implicit bindings go, and wildcard binding is in the end. |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1695 */ |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1696 |
3218
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1697 if (addr[last - 1].opt.wildcard) { |
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1698 addr[last - 1].opt.bind = 1; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1699 bind_wildcard = 1; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1700 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1701 } else { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1702 bind_wildcard = 0; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1703 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1704 |
2533 | 1705 i = 0; |
1706 | |
1707 while (i < last) { | |
1708 | |
3218
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1709 if (bind_wildcard && !addr[i].opt.bind) { |
2533 | 1710 i++; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1711 continue; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1712 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1713 |
2533 | 1714 ls = ngx_http_add_listening(cf, &addr[i]); |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1715 if (ls == NULL) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1716 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1717 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1718 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1719 hport = ngx_pcalloc(cf->pool, sizeof(ngx_http_port_t)); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1720 if (hport == NULL) { |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1721 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1722 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1723 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1724 ls->servers = hport; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1725 |
6152
3c344ea7d88b
Simplified ngx_http_init_listening().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6128
diff
changeset
|
1726 hport->naddrs = i + 1; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1727 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1728 switch (ls->sockaddr->sa_family) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1729 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1730 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1731 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1732 if (ngx_http_add_addrs6(cf, hport, addr) != NGX_OK) { |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1733 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1734 } |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1735 break; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1736 #endif |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1737 default: /* AF_INET */ |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1738 if (ngx_http_add_addrs(cf, hport, addr) != NGX_OK) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1739 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1740 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1741 break; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1742 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1743 |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6152
diff
changeset
|
1744 if (ngx_clone_listening(cf, ls) != NGX_OK) { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6152
diff
changeset
|
1745 return NGX_ERROR; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6152
diff
changeset
|
1746 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6152
diff
changeset
|
1747 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1748 addr++; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1749 last--; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1750 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1751 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1752 return NGX_OK; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1753 } |
2138 | 1754 |
1755 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1756 static ngx_listening_t * |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1757 ngx_http_add_listening(ngx_conf_t *cf, ngx_http_conf_addr_t *addr) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1758 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1759 ngx_listening_t *ls; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1760 ngx_http_core_loc_conf_t *clcf; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1761 ngx_http_core_srv_conf_t *cscf; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1762 |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1763 ls = ngx_create_listening(cf, &addr->opt.u.sockaddr, addr->opt.socklen); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1764 if (ls == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1765 return NULL; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1766 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1767 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1768 ls->addr_ntop = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1769 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1770 ls->handler = ngx_http_init_connection; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1771 |
3221
c8de5a8b6d17
rename core_srv_conf fields to more understandable default_server and server
Igor Sysoev <igor@sysoev.ru>
parents:
3220
diff
changeset
|
1772 cscf = addr->default_server; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1773 ls->pool_size = cscf->connection_pool_size; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1774 ls->post_accept_timeout = cscf->client_header_timeout; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1775 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1776 clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index]; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1777 |
2785
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2689
diff
changeset
|
1778 ls->logp = clcf->error_log; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1779 ls->log.data = &ls->addr_text; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1780 ls->log.handler = ngx_accept_log_error; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1781 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1782 #if (NGX_WIN32) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1783 { |
4154
57d45d345651
Fixed segmentation fault with empty config on Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4142
diff
changeset
|
1784 ngx_iocp_conf_t *iocpcf = NULL; |
57d45d345651
Fixed segmentation fault with empty config on Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4142
diff
changeset
|
1785 |
57d45d345651
Fixed segmentation fault with empty config on Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4142
diff
changeset
|
1786 if (ngx_get_conf(cf->cycle->conf_ctx, ngx_events_module)) { |
57d45d345651
Fixed segmentation fault with empty config on Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4142
diff
changeset
|
1787 iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module); |
57d45d345651
Fixed segmentation fault with empty config on Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4142
diff
changeset
|
1788 } |
57d45d345651
Fixed segmentation fault with empty config on Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4142
diff
changeset
|
1789 if (iocpcf && iocpcf->acceptex_read) { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1790 ls->post_accept_buffer_size = cscf->client_header_buffer_size; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1791 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1792 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1793 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1794 |
3217 | 1795 ls->backlog = addr->opt.backlog; |
1796 ls->rcvbuf = addr->opt.rcvbuf; | |
1797 ls->sndbuf = addr->opt.sndbuf; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1798 |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4154
diff
changeset
|
1799 ls->keepalive = addr->opt.so_keepalive; |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4154
diff
changeset
|
1800 #if (NGX_HAVE_KEEPALIVE_TUNABLE) |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4154
diff
changeset
|
1801 ls->keepidle = addr->opt.tcp_keepidle; |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4154
diff
changeset
|
1802 ls->keepintvl = addr->opt.tcp_keepintvl; |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4154
diff
changeset
|
1803 ls->keepcnt = addr->opt.tcp_keepcnt; |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4154
diff
changeset
|
1804 #endif |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4154
diff
changeset
|
1805 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1806 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) |
3217 | 1807 ls->accept_filter = addr->opt.accept_filter; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1808 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1809 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1810 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) |
3217 | 1811 ls->deferred_accept = addr->opt.deferred_accept; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1812 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1813 |
2562 | 1814 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) |
3217 | 1815 ls->ipv6only = addr->opt.ipv6only; |
2562 | 1816 #endif |
1817 | |
3676 | 1818 #if (NGX_HAVE_SETFIB) |
1819 ls->setfib = addr->opt.setfib; | |
1820 #endif | |
1821 | |
5456
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5388
diff
changeset
|
1822 #if (NGX_HAVE_TCP_FASTOPEN) |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5388
diff
changeset
|
1823 ls->fastopen = addr->opt.fastopen; |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5388
diff
changeset
|
1824 #endif |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5388
diff
changeset
|
1825 |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6152
diff
changeset
|
1826 #if (NGX_HAVE_REUSEPORT) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6152
diff
changeset
|
1827 ls->reuseport = addr->opt.reuseport; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6152
diff
changeset
|
1828 #endif |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6152
diff
changeset
|
1829 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1830 return ls; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1831 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1832 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1833 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1834 static ngx_int_t |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1835 ngx_http_add_addrs(ngx_conf_t *cf, ngx_http_port_t *hport, |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1836 ngx_http_conf_addr_t *addr) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1837 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1838 ngx_uint_t i; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1839 ngx_http_in_addr_t *addrs; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1840 struct sockaddr_in *sin; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1841 ngx_http_virtual_names_t *vn; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1842 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1843 hport->addrs = ngx_pcalloc(cf->pool, |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1844 hport->naddrs * sizeof(ngx_http_in_addr_t)); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1845 if (hport->addrs == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1846 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1847 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1848 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1849 addrs = hport->addrs; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1850 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1851 for (i = 0; i < hport->naddrs; i++) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1852 |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1853 sin = &addr[i].opt.u.sockaddr_in; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1854 addrs[i].addr = sin->sin_addr.s_addr; |
3221
c8de5a8b6d17
rename core_srv_conf fields to more understandable default_server and server
Igor Sysoev <igor@sysoev.ru>
parents:
3220
diff
changeset
|
1855 addrs[i].conf.default_server = addr[i].default_server; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1856 #if (NGX_HTTP_SSL) |
3218
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1857 addrs[i].conf.ssl = addr[i].opt.ssl; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1858 #endif |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1859 #if (NGX_HTTP_SPDY) |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1860 addrs[i].conf.spdy = addr[i].opt.spdy; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1861 #endif |
5605
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5545
diff
changeset
|
1862 addrs[i].conf.proxy_protocol = addr[i].opt.proxy_protocol; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1863 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1864 if (addr[i].hash.buckets == NULL |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1865 && (addr[i].wc_head == NULL |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1866 || addr[i].wc_head->hash.buckets == NULL) |
2580
684ca3b0ae14
test wildcard tail hash existance
Igor Sysoev <igor@sysoev.ru>
parents:
2562
diff
changeset
|
1867 && (addr[i].wc_tail == NULL |
2583
1fb5e7e05a4e
always run regex in server_name to get captures
Igor Sysoev <igor@sysoev.ru>
parents:
2580
diff
changeset
|
1868 || addr[i].wc_tail->hash.buckets == NULL) |
1fb5e7e05a4e
always run regex in server_name to get captures
Igor Sysoev <igor@sysoev.ru>
parents:
2580
diff
changeset
|
1869 #if (NGX_PCRE) |
1fb5e7e05a4e
always run regex in server_name to get captures
Igor Sysoev <igor@sysoev.ru>
parents:
2580
diff
changeset
|
1870 && addr[i].nregex == 0 |
1fb5e7e05a4e
always run regex in server_name to get captures
Igor Sysoev <igor@sysoev.ru>
parents:
2580
diff
changeset
|
1871 #endif |
1fb5e7e05a4e
always run regex in server_name to get captures
Igor Sysoev <igor@sysoev.ru>
parents:
2580
diff
changeset
|
1872 ) |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1873 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1874 continue; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1875 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1876 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1877 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t)); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1878 if (vn == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1879 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1880 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1881 |
2689
6caf687a831f
backout r2535: virtual names is a property of address:port pair,
Igor Sysoev <igor@sysoev.ru>
parents:
2688
diff
changeset
|
1882 addrs[i].conf.virtual_names = vn; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1883 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1884 vn->names.hash = addr[i].hash; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1885 vn->names.wc_head = addr[i].wc_head; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1886 vn->names.wc_tail = addr[i].wc_tail; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1887 #if (NGX_PCRE) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1888 vn->nregex = addr[i].nregex; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1889 vn->regex = addr[i].regex; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1890 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1891 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1892 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1893 return NGX_OK; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1894 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1895 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1896 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1897 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1898 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1899 static ngx_int_t |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1900 ngx_http_add_addrs6(ngx_conf_t *cf, ngx_http_port_t *hport, |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1901 ngx_http_conf_addr_t *addr) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1902 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1903 ngx_uint_t i; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1904 ngx_http_in6_addr_t *addrs6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1905 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1906 ngx_http_virtual_names_t *vn; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1907 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1908 hport->addrs = ngx_pcalloc(cf->pool, |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1909 hport->naddrs * sizeof(ngx_http_in6_addr_t)); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1910 if (hport->addrs == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1911 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1912 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1913 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1914 addrs6 = hport->addrs; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1915 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1916 for (i = 0; i < hport->naddrs; i++) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1917 |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1918 sin6 = &addr[i].opt.u.sockaddr_in6; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1919 addrs6[i].addr6 = sin6->sin6_addr; |
3221
c8de5a8b6d17
rename core_srv_conf fields to more understandable default_server and server
Igor Sysoev <igor@sysoev.ru>
parents:
3220
diff
changeset
|
1920 addrs6[i].conf.default_server = addr[i].default_server; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1921 #if (NGX_HTTP_SSL) |
3218
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1922 addrs6[i].conf.ssl = addr[i].opt.ssl; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1923 #endif |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1924 #if (NGX_HTTP_SPDY) |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1925 addrs6[i].conf.spdy = addr[i].opt.spdy; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1926 #endif |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1927 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1928 if (addr[i].hash.buckets == NULL |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1929 && (addr[i].wc_head == NULL |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1930 || addr[i].wc_head->hash.buckets == NULL) |
3824
4ee02b872591
test wildcard tail hash existance for IPv6 addresses,
Igor Sysoev <igor@sysoev.ru>
parents:
3823
diff
changeset
|
1931 && (addr[i].wc_tail == NULL |
3825
3770119af0b5
always run regex in server_name to get captures for IPv6 addresses,
Igor Sysoev <igor@sysoev.ru>
parents:
3824
diff
changeset
|
1932 || addr[i].wc_tail->hash.buckets == NULL) |
3770119af0b5
always run regex in server_name to get captures for IPv6 addresses,
Igor Sysoev <igor@sysoev.ru>
parents:
3824
diff
changeset
|
1933 #if (NGX_PCRE) |
3770119af0b5
always run regex in server_name to get captures for IPv6 addresses,
Igor Sysoev <igor@sysoev.ru>
parents:
3824
diff
changeset
|
1934 && addr[i].nregex == 0 |
3770119af0b5
always run regex in server_name to get captures for IPv6 addresses,
Igor Sysoev <igor@sysoev.ru>
parents:
3824
diff
changeset
|
1935 #endif |
3770119af0b5
always run regex in server_name to get captures for IPv6 addresses,
Igor Sysoev <igor@sysoev.ru>
parents:
3824
diff
changeset
|
1936 ) |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1937 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1938 continue; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1939 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1940 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1941 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t)); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1942 if (vn == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1943 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1944 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1945 |
2689
6caf687a831f
backout r2535: virtual names is a property of address:port pair,
Igor Sysoev <igor@sysoev.ru>
parents:
2688
diff
changeset
|
1946 addrs6[i].conf.virtual_names = vn; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1947 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1948 vn->names.hash = addr[i].hash; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1949 vn->names.wc_head = addr[i].wc_head; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1950 vn->names.wc_tail = addr[i].wc_tail; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1951 #if (NGX_PCRE) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1952 vn->nregex = addr[i].nregex; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1953 vn->regex = addr[i].regex; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1954 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1955 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1956 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1957 return NGX_OK; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1958 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1959 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1960 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1961 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1962 |
2138 | 1963 char * |
1964 ngx_http_types_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1965 { | |
1966 char *p = conf; | |
1967 | |
1968 ngx_array_t **types; | |
1969 ngx_str_t *value, *default_type; | |
1970 ngx_uint_t i, n, hash; | |
1971 ngx_hash_key_t *type; | |
1972 | |
1973 types = (ngx_array_t **) (p + cmd->offset); | |
1974 | |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
1975 if (*types == (void *) -1) { |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
1976 return NGX_CONF_OK; |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
1977 } |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
1978 |
2138 | 1979 default_type = cmd->post; |
1980 | |
1981 if (*types == NULL) { | |
1982 *types = ngx_array_create(cf->temp_pool, 1, sizeof(ngx_hash_key_t)); | |
1983 if (*types == NULL) { | |
1984 return NGX_CONF_ERROR; | |
1985 } | |
1986 | |
1987 if (default_type) { | |
1988 type = ngx_array_push(*types); | |
1989 if (type == NULL) { | |
1990 return NGX_CONF_ERROR; | |
1991 } | |
1992 | |
1993 type->key = *default_type; | |
1994 type->key_hash = ngx_hash_key(default_type->data, | |
1995 default_type->len); | |
1996 type->value = (void *) 4; | |
1997 } | |
1998 } | |
1999 | |
2000 value = cf->args->elts; | |
2001 | |
2002 for (i = 1; i < cf->args->nelts; i++) { | |
2003 | |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2004 if (value[i].len == 1 && value[i].data[0] == '*') { |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2005 *types = (void *) -1; |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2006 return NGX_CONF_OK; |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2007 } |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2008 |
2138 | 2009 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len); |
2010 value[i].data[value[i].len] = '\0'; | |
2011 | |
2012 type = (*types)->elts; | |
2013 for (n = 0; n < (*types)->nelts; n++) { | |
2014 | |
2015 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) { | |
2016 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
2017 "duplicate MIME type \"%V\"", &value[i]); | |
5856
1b8459a53e4b
Avoided to add duplicate hash key in ngx_http_types_slot().
Gu Feng <flygoast@126.com>
parents:
5741
diff
changeset
|
2018 goto next; |
2138 | 2019 } |
2020 } | |
2021 | |
2022 type = ngx_array_push(*types); | |
2023 if (type == NULL) { | |
2024 return NGX_CONF_ERROR; | |
2025 } | |
2026 | |
2027 type->key = value[i]; | |
2028 type->key_hash = hash; | |
2029 type->value = (void *) 4; | |
5856
1b8459a53e4b
Avoided to add duplicate hash key in ngx_http_types_slot().
Gu Feng <flygoast@126.com>
parents:
5741
diff
changeset
|
2030 |
1b8459a53e4b
Avoided to add duplicate hash key in ngx_http_types_slot().
Gu Feng <flygoast@126.com>
parents:
5741
diff
changeset
|
2031 next: |
1b8459a53e4b
Avoided to add duplicate hash key in ngx_http_types_slot().
Gu Feng <flygoast@126.com>
parents:
5741
diff
changeset
|
2032 |
1b8459a53e4b
Avoided to add duplicate hash key in ngx_http_types_slot().
Gu Feng <flygoast@126.com>
parents:
5741
diff
changeset
|
2033 continue; |
2138 | 2034 } |
2035 | |
2036 return NGX_CONF_OK; | |
2037 } | |
2038 | |
2039 | |
2040 char * | |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2041 ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t **keys, ngx_hash_t *types_hash, |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2042 ngx_array_t **prev_keys, ngx_hash_t *prev_types_hash, |
2138 | 2043 ngx_str_t *default_types) |
2044 { | |
2045 ngx_hash_init_t hash; | |
2046 | |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2047 if (*keys) { |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2048 |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2049 if (*keys == (void *) -1) { |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2050 return NGX_CONF_OK; |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2051 } |
2138 | 2052 |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2053 hash.hash = types_hash; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2054 hash.key = NULL; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2055 hash.max_size = 2048; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2056 hash.bucket_size = 64; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2057 hash.name = "test_types_hash"; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2058 hash.pool = cf->pool; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2059 hash.temp_pool = NULL; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2060 |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2061 if (ngx_hash_init(&hash, (*keys)->elts, (*keys)->nelts) != NGX_OK) { |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2062 return NGX_CONF_ERROR; |
2138 | 2063 } |
2064 | |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2065 return NGX_CONF_OK; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2066 } |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2067 |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2068 if (prev_types_hash->buckets == NULL) { |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2069 |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2070 if (*prev_keys == NULL) { |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2071 |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2072 if (ngx_http_set_default_types(cf, prev_keys, default_types) |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2073 != NGX_OK) |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2074 { |
2223
005fc65f7ce7
style fix: remove tabs and trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
2219
diff
changeset
|
2075 return NGX_CONF_ERROR; |
005fc65f7ce7
style fix: remove tabs and trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
2219
diff
changeset
|
2076 } |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2077 |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2078 } else if (*prev_keys == (void *) -1) { |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2079 *keys = *prev_keys; |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2080 return NGX_CONF_OK; |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2081 } |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2082 |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2083 hash.hash = prev_types_hash; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2084 hash.key = NULL; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2085 hash.max_size = 2048; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2086 hash.bucket_size = 64; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2087 hash.name = "test_types_hash"; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2088 hash.pool = cf->pool; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2089 hash.temp_pool = NULL; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2090 |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2091 if (ngx_hash_init(&hash, (*prev_keys)->elts, (*prev_keys)->nelts) |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2092 != NGX_OK) |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2093 { |
2138 | 2094 return NGX_CONF_ERROR; |
2095 } | |
2096 } | |
2097 | |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2098 *types_hash = *prev_types_hash; |
2138 | 2099 |
2100 return NGX_CONF_OK; | |
2101 | |
2102 } | |
2103 | |
2104 | |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2105 ngx_int_t |
2138 | 2106 ngx_http_set_default_types(ngx_conf_t *cf, ngx_array_t **types, |
2107 ngx_str_t *default_type) | |
2108 { | |
2109 ngx_hash_key_t *type; | |
2110 | |
2111 *types = ngx_array_create(cf->temp_pool, 1, sizeof(ngx_hash_key_t)); | |
2112 if (*types == NULL) { | |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2113 return NGX_ERROR; |
2138 | 2114 } |
2115 | |
2116 while (default_type->len) { | |
2117 | |
2118 type = ngx_array_push(*types); | |
2119 if (type == NULL) { | |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2120 return NGX_ERROR; |
2138 | 2121 } |
2122 | |
2123 type->key = *default_type; | |
2124 type->key_hash = ngx_hash_key(default_type->data, | |
2125 default_type->len); | |
2126 type->value = (void *) 4; | |
2127 | |
2128 default_type++; | |
2129 } | |
2130 | |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2131 return NGX_OK; |
2138 | 2132 } |