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