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