Mercurial > hg > nginx
annotate src/http/ngx_http.c @ 6059:c81d79a7befd
SPDY: always push pending data.
This helps to avoid suboptimal behavior when a client waits for a control
frame or more data to increase window size, but the frames have been delayed
in the socket buffer.
The delays can be caused by bad interaction between Nagle's algorithm on
nginx side and delayed ACK on the client side or by TCP_CORK/TCP_NOPUSH
if SPDY was working without SSL and sendfile() was used.
The pushing code is now very similar to ngx_http_set_keepalive().
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Mon, 23 Mar 2015 21:04:13 +0300 |
parents | 42d9beeb22db |
children | 69ad3e77922b |
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 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
131 /* the main http context */ |
477 | 132 |
501 | 133 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); |
134 if (ctx == NULL) { | |
485 | 135 return NGX_CONF_ERROR; |
136 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
137 |
90
37530da31268
nginx-0.0.1-2003-05-16-19:27:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
89
diff
changeset
|
138 *(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
|
139 |
485 | 140 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
141 /* 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
|
142 |
71
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
143 ngx_http_max_module = 0; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
144 for (m = 0; ngx_modules[m]; m++) { |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
145 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
146 continue; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
147 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
148 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
149 ngx_modules[m]->ctx_index = ngx_http_max_module++; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
150 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
151 |
477 | 152 |
485 | 153 /* 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
|
154 |
485 | 155 ctx->main_conf = ngx_pcalloc(cf->pool, |
156 sizeof(void *) * ngx_http_max_module); | |
157 if (ctx->main_conf == NULL) { | |
158 return NGX_CONF_ERROR; | |
159 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
160 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
161 |
485 | 162 /* |
163 * the http null srv_conf context, it is used to merge | |
164 * the server{}s' srv_conf's | |
165 */ | |
166 | |
167 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
168 if (ctx->srv_conf == NULL) { | |
169 return NGX_CONF_ERROR; | |
170 } | |
171 | |
172 | |
173 /* | |
174 * the http null loc_conf context, it is used to merge | |
175 * the server{}s' loc_conf's | |
176 */ | |
177 | |
178 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
179 if (ctx->loc_conf == NULL) { | |
180 return NGX_CONF_ERROR; | |
181 } | |
182 | |
183 | |
184 /* | |
185 * create the main_conf's, the null srv_conf's, and the null loc_conf's | |
186 * of the all http modules | |
187 */ | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
188 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
189 for (m = 0; ngx_modules[m]; m++) { |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
190 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
191 continue; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
192 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
193 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
194 module = ngx_modules[m]->ctx; |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
195 mi = ngx_modules[m]->ctx_index; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
196 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
197 if (module->create_main_conf) { |
501 | 198 ctx->main_conf[mi] = module->create_main_conf(cf); |
199 if (ctx->main_conf[mi] == NULL) { | |
485 | 200 return NGX_CONF_ERROR; |
201 } | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
202 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
203 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
204 if (module->create_srv_conf) { |
501 | 205 ctx->srv_conf[mi] = module->create_srv_conf(cf); |
206 if (ctx->srv_conf[mi] == NULL) { | |
485 | 207 return NGX_CONF_ERROR; |
208 } | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
209 } |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
210 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
211 if (module->create_loc_conf) { |
501 | 212 ctx->loc_conf[mi] = module->create_loc_conf(cf); |
213 if (ctx->loc_conf[mi] == NULL) { | |
485 | 214 return NGX_CONF_ERROR; |
215 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
216 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
217 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
218 |
509 | 219 pcf = *cf; |
220 cf->ctx = ctx; | |
221 | |
222 for (m = 0; ngx_modules[m]; m++) { | |
223 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { | |
224 continue; | |
225 } | |
226 | |
227 module = ngx_modules[m]->ctx; | |
228 | |
229 if (module->preconfiguration) { | |
230 if (module->preconfiguration(cf) != NGX_OK) { | |
231 return NGX_CONF_ERROR; | |
232 } | |
233 } | |
234 } | |
485 | 235 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
236 /* 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
|
237 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
238 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
|
239 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
|
240 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
|
241 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
242 if (rv != NGX_CONF_OK) { |
2027 | 243 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
|
244 } |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
245 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
246 /* |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
247 * 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
|
248 * 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
|
249 */ |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
250 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
251 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
|
252 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
|
253 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
254 for (m = 0; ngx_modules[m]; m++) { |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
255 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
256 continue; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
257 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
258 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
259 module = ngx_modules[m]->ctx; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
260 mi = ngx_modules[m]->ctx_index; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
261 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
262 /* 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
|
263 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
264 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
|
265 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
|
266 if (rv != NGX_CONF_OK) { |
2027 | 267 goto failed; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
268 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
269 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
270 |
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
|
271 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
|
272 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
|
273 goto failed; |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
274 } |
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
275 } |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
276 |
485 | 277 |
2027 | 278 /* create location trees */ |
279 | |
280 for (s = 0; s < cmcf->servers.nelts; s++) { | |
281 | |
282 clcf = cscfp[s]->ctx->loc_conf[ngx_http_core_module.ctx_index]; | |
283 | |
284 if (ngx_http_init_locations(cf, cscfp[s], clcf) != NGX_OK) { | |
285 return NGX_CONF_ERROR; | |
286 } | |
287 | |
288 if (ngx_http_init_static_location_trees(cf, clcf) != NGX_OK) { | |
289 return NGX_CONF_ERROR; | |
290 } | |
291 } | |
292 | |
293 | |
2021 | 294 if (ngx_http_init_phases(cf, cmcf) != NGX_OK) { |
485 | 295 return NGX_CONF_ERROR; |
296 } | |
297 | |
2021 | 298 if (ngx_http_init_headers_in_hash(cf, cmcf) != NGX_OK) { |
649 | 299 return NGX_CONF_ERROR; |
300 } | |
301 | |
509 | 302 |
303 for (m = 0; ngx_modules[m]; m++) { | |
304 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { | |
305 continue; | |
306 } | |
307 | |
308 module = ngx_modules[m]->ctx; | |
309 | |
310 if (module->postconfiguration) { | |
311 if (module->postconfiguration(cf) != NGX_OK) { | |
312 return NGX_CONF_ERROR; | |
313 } | |
314 } | |
315 } | |
316 | |
573 | 317 if (ngx_http_variables_init_vars(cf) != NGX_OK) { |
318 return NGX_CONF_ERROR; | |
319 } | |
509 | 320 |
321 /* | |
322 * http{}'s cf->ctx was needed while the configuration merging | |
323 * and in postconfiguration process | |
324 */ | |
325 | |
326 *cf = pcf; | |
327 | |
507 | 328 |
2021 | 329 if (ngx_http_init_phase_handlers(cf, cmcf) != NGX_OK) { |
681 | 330 return NGX_CONF_ERROR; |
331 } | |
332 | |
333 | |
455 | 334 /* 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
|
335 |
3217 | 336 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
|
337 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
|
338 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
339 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
340 return NGX_CONF_OK; |
2027 | 341 |
342 failed: | |
343 | |
344 *cf = pcf; | |
345 | |
346 return rv; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
347 } |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
348 |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
349 |
2021 | 350 static ngx_int_t |
351 ngx_http_init_phases(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf) | |
352 { | |
353 if (ngx_array_init(&cmcf->phases[NGX_HTTP_POST_READ_PHASE].handlers, | |
354 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
355 != NGX_OK) | |
356 { | |
357 return NGX_ERROR; | |
358 } | |
359 | |
360 if (ngx_array_init(&cmcf->phases[NGX_HTTP_SERVER_REWRITE_PHASE].handlers, | |
361 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
362 != NGX_OK) | |
363 { | |
364 return NGX_ERROR; | |
365 } | |
366 | |
367 if (ngx_array_init(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers, | |
368 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
369 != NGX_OK) | |
370 { | |
371 return NGX_ERROR; | |
372 } | |
373 | |
374 if (ngx_array_init(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers, | |
375 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
376 != NGX_OK) | |
377 { | |
378 return NGX_ERROR; | |
379 } | |
380 | |
381 if (ngx_array_init(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers, | |
382 cf->pool, 2, sizeof(ngx_http_handler_pt)) | |
383 != NGX_OK) | |
384 { | |
385 return NGX_ERROR; | |
386 } | |
387 | |
388 if (ngx_array_init(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers, | |
389 cf->pool, 4, sizeof(ngx_http_handler_pt)) | |
390 != NGX_OK) | |
391 { | |
392 return NGX_ERROR; | |
393 } | |
394 | |
395 if (ngx_array_init(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers, | |
396 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
397 != NGX_OK) | |
398 { | |
399 return NGX_ERROR; | |
400 } | |
401 | |
402 return NGX_OK; | |
403 } | |
404 | |
405 | |
406 static ngx_int_t | |
407 ngx_http_init_headers_in_hash(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf) | |
408 { | |
409 ngx_array_t headers_in; | |
410 ngx_hash_key_t *hk; | |
411 ngx_hash_init_t hash; | |
412 ngx_http_header_t *header; | |
413 | |
414 if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t)) | |
415 != NGX_OK) | |
416 { | |
417 return NGX_ERROR; | |
418 } | |
419 | |
420 for (header = ngx_http_headers_in; header->name.len; header++) { | |
421 hk = ngx_array_push(&headers_in); | |
422 if (hk == NULL) { | |
423 return NGX_ERROR; | |
424 } | |
425 | |
426 hk->key = header->name; | |
427 hk->key_hash = ngx_hash_key_lc(header->name.data, header->name.len); | |
428 hk->value = header; | |
429 } | |
430 | |
431 hash.hash = &cmcf->headers_in_hash; | |
432 hash.key = ngx_hash_key_lc; | |
433 hash.max_size = 512; | |
434 hash.bucket_size = ngx_align(64, ngx_cacheline_size); | |
435 hash.name = "headers_in_hash"; | |
436 hash.pool = cf->pool; | |
437 hash.temp_pool = NULL; | |
438 | |
439 if (ngx_hash_init(&hash, headers_in.elts, headers_in.nelts) != NGX_OK) { | |
440 return NGX_ERROR; | |
441 } | |
442 | |
443 return NGX_OK; | |
444 } | |
445 | |
446 | |
447 static ngx_int_t | |
448 ngx_http_init_phase_handlers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf) | |
449 { | |
450 ngx_int_t j; | |
451 ngx_uint_t i, n; | |
452 ngx_uint_t find_config_index, use_rewrite, use_access; | |
453 ngx_http_handler_pt *h; | |
454 ngx_http_phase_handler_t *ph; | |
455 ngx_http_phase_handler_pt checker; | |
456 | |
457 cmcf->phase_engine.server_rewrite_index = (ngx_uint_t) -1; | |
458 cmcf->phase_engine.location_rewrite_index = (ngx_uint_t) -1; | |
459 find_config_index = 0; | |
460 use_rewrite = cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers.nelts ? 1 : 0; | |
461 use_access = cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers.nelts ? 1 : 0; | |
462 | |
2407 | 463 n = use_rewrite + use_access + cmcf->try_files + 1 /* find config phase */; |
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 struct sockaddr_in *sin; | |
1151 ngx_http_conf_port_t *port; | |
1152 ngx_http_core_main_conf_t *cmcf; | |
1153 #if (NGX_HAVE_INET6) | |
1154 struct sockaddr_in6 *sin6; | |
1155 #endif | |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1156 |
3217 | 1157 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
|
1158 |
3217 | 1159 if (cmcf->ports == NULL) { |
1160 cmcf->ports = ngx_array_create(cf->temp_pool, 2, | |
1161 sizeof(ngx_http_conf_port_t)); | |
1162 if (cmcf->ports == NULL) { | |
1163 return NGX_ERROR; | |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1164 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1165 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1166 |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1167 sa = &lsopt->u.sockaddr; |
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 switch (sa->sa_family) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1170 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1171 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1172 case AF_INET6: |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1173 sin6 = &lsopt->u.sockaddr_in6; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1174 p = sin6->sin6_port; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1175 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1176 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1177 |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1178 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1179 case AF_UNIX: |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1180 p = 0; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1181 break; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1182 #endif |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1183 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1184 default: /* AF_INET */ |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1185 sin = &lsopt->u.sockaddr_in; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1186 p = sin->sin_port; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1187 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1188 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1189 |
3217 | 1190 port = cmcf->ports->elts; |
1191 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
|
1192 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1193 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
|
1194 continue; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1195 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1196 |
2852
dfe04af9d30b
update comments missed in r2513
Igor Sysoev <igor@sysoev.ru>
parents:
2851
diff
changeset
|
1197 /* 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
|
1198 |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
1199 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
|
1200 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1201 |
2852
dfe04af9d30b
update comments missed in r2513
Igor Sysoev <igor@sysoev.ru>
parents:
2851
diff
changeset
|
1202 /* 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
|
1203 |
3217 | 1204 port = ngx_array_push(cmcf->ports); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1205 if (port == NULL) { |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1206 return NGX_ERROR; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1207 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1208 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1209 port->family = sa->sa_family; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1210 port->port = p; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1211 port->addrs.elts = NULL; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1212 |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
1213 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
|
1214 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1215 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1216 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1217 static ngx_int_t |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1218 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
|
1219 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
|
1220 { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1221 u_char *p; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1222 size_t len, off; |
3229
a632dc9f3e73
fix r3225 and r3227: preserve default_server bit during listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3227
diff
changeset
|
1223 ngx_uint_t i, default_server; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1224 struct sockaddr *sa; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1225 ngx_http_conf_addr_t *addr; |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1226 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1227 struct sockaddr_un *saun; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1228 #endif |
3764
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1229 #if (NGX_HTTP_SSL) |
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1230 ngx_uint_t ssl; |
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1231 #endif |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1232 #if (NGX_HTTP_SPDY) |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1233 ngx_uint_t spdy; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1234 #endif |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1235 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1236 /* |
4133
59b99f217c6d
Replaced "can not" with "cannot" and "could not" in a bunch of places.
Ruslan Ermilov <ru@nginx.com>
parents:
3825
diff
changeset
|
1237 * 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
|
1238 * 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
|
1239 */ |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1240 |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1241 sa = &lsopt->u.sockaddr; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1242 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1243 switch (sa->sa_family) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1244 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1245 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1246 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1247 off = offsetof(struct sockaddr_in6, sin6_addr); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1248 len = 16; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1249 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1250 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1251 |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1252 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1253 case AF_UNIX: |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1254 off = offsetof(struct sockaddr_un, sun_path); |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1255 len = sizeof(saun->sun_path); |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1256 break; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1257 #endif |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3229
diff
changeset
|
1258 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1259 default: /* AF_INET */ |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1260 off = offsetof(struct sockaddr_in, sin_addr); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1261 len = 4; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1262 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1263 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1264 |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1265 p = lsopt->u.sockaddr_data + off; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1266 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1267 addr = port->addrs.elts; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1268 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1269 for (i = 0; i < port->addrs.nelts; i++) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1270 |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1271 if (ngx_memcmp(p, addr[i].opt.u.sockaddr_data + off, len) != 0) { |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1272 continue; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1273 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1274 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1275 /* 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
|
1276 |
3219 | 1277 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
|
1278 return NGX_ERROR; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1279 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1280 |
3229
a632dc9f3e73
fix r3225 and r3227: preserve default_server bit during listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3227
diff
changeset
|
1281 /* 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
|
1282 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
|
1283 |
3764
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1284 #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
|
1285 ssl = lsopt->ssl || addr[i].opt.ssl; |
3764
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1286 #endif |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1287 #if (NGX_HTTP_SPDY) |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1288 spdy = lsopt->spdy || addr[i].opt.spdy; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1289 #endif |
3764
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1290 |
3226
4872f86df719
fix r3225: it overrode the listen options by default server default options
Igor Sysoev <igor@sysoev.ru>
parents:
3224
diff
changeset
|
1291 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
|
1292 |
4872f86df719
fix r3225: it overrode the listen options by default server default options
Igor Sysoev <igor@sysoev.ru>
parents:
3224
diff
changeset
|
1293 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
|
1294 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
4142 | 1295 "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
|
1296 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
|
1297 } |
4872f86df719
fix r3225: it overrode the listen options by default server default options
Igor Sysoev <igor@sysoev.ru>
parents:
3224
diff
changeset
|
1298 |
4872f86df719
fix r3225: it overrode the listen options by default server default options
Igor Sysoev <igor@sysoev.ru>
parents:
3224
diff
changeset
|
1299 addr[i].opt = *lsopt; |
3224
8e76e636ae3b
allow to set listen options in any server
Igor Sysoev <igor@sysoev.ru>
parents:
3223
diff
changeset
|
1300 } |
8e76e636ae3b
allow to set listen options in any server
Igor Sysoev <igor@sysoev.ru>
parents:
3223
diff
changeset
|
1301 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1302 /* 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
|
1303 |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
1304 if (lsopt->default_server) { |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1305 |
3229
a632dc9f3e73
fix r3225 and r3227: preserve default_server bit during listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3227
diff
changeset
|
1306 if (default_server) { |
3217 | 1307 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
|
1308 "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
|
1309 return NGX_ERROR; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1310 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1311 |
3229
a632dc9f3e73
fix r3225 and r3227: preserve default_server bit during listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3227
diff
changeset
|
1312 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
|
1313 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
|
1314 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1315 |
3229
a632dc9f3e73
fix r3225 and r3227: preserve default_server bit during listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3227
diff
changeset
|
1316 addr[i].opt.default_server = default_server; |
3764
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1317 #if (NGX_HTTP_SSL) |
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1318 addr[i].opt.ssl = ssl; |
d1983670b586
allow duplicate listen ssl options
Igor Sysoev <igor@sysoev.ru>
parents:
3730
diff
changeset
|
1319 #endif |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1320 #if (NGX_HTTP_SPDY) |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1321 addr[i].opt.spdy = spdy; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1322 #endif |
3229
a632dc9f3e73
fix r3225 and r3227: preserve default_server bit during listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3227
diff
changeset
|
1323 |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1324 return NGX_OK; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1325 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1326 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1327 /* 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
|
1328 |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
1329 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
|
1330 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1331 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1332 |
455 | 1333 /* |
1334 * 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
|
1335 * configurations to the port list |
455 | 1336 */ |
1337 | |
499 | 1338 static ngx_int_t |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1339 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
|
1340 ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt) |
455 | 1341 { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1342 ngx_http_conf_addr_t *addr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1343 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1344 if (port->addrs.elts == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1345 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
|
1346 sizeof(ngx_http_conf_addr_t)) |
1385 | 1347 != NGX_OK) |
455 | 1348 { |
1349 return NGX_ERROR; | |
1350 } | |
1351 } | |
1352 | |
5545
01e2a5bcdd8f
SSL: support ALPN (IETF's successor to NPN).
Piotr Sikora <piotr@cloudflare.com>
parents:
5456
diff
changeset
|
1353 #if (NGX_HTTP_SPDY && NGX_HTTP_SSL \ |
01e2a5bcdd8f
SSL: support ALPN (IETF's successor to NPN).
Piotr Sikora <piotr@cloudflare.com>
parents:
5456
diff
changeset
|
1354 && !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
|
1355 && !defined TLSEXT_TYPE_next_proto_neg) |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1356 if (lsopt->spdy && lsopt->ssl) { |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1357 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
5545
01e2a5bcdd8f
SSL: support ALPN (IETF's successor to NPN).
Piotr Sikora <piotr@cloudflare.com>
parents:
5456
diff
changeset
|
1358 "nginx was built without OpenSSL ALPN or NPN " |
01e2a5bcdd8f
SSL: support ALPN (IETF's successor to NPN).
Piotr Sikora <piotr@cloudflare.com>
parents:
5456
diff
changeset
|
1359 "support, SPDY is not enabled for %s", lsopt->addr); |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1360 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1361 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1362 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1363 addr = ngx_array_push(&port->addrs); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1364 if (addr == NULL) { |
455 | 1365 return NGX_ERROR; |
1366 } | |
1367 | |
3220
cdcd9e29c589
*) move sockaddr to the listen options
Igor Sysoev <igor@sysoev.ru>
parents:
3219
diff
changeset
|
1368 addr->opt = *lsopt; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1369 addr->hash.buckets = NULL; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1370 addr->hash.size = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1371 addr->wc_head = NULL; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1372 addr->wc_tail = NULL; |
1387 | 1373 #if (NGX_PCRE) |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1374 addr->nregex = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1375 addr->regex = NULL; |
1387 | 1376 #endif |
3221
c8de5a8b6d17
rename core_srv_conf fields to more understandable default_server and server
Igor Sysoev <igor@sysoev.ru>
parents:
3220
diff
changeset
|
1377 addr->default_server = cscf; |
3219 | 1378 addr->servers.elts = NULL; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1379 |
3219 | 1380 return ngx_http_add_server(cf, cscf, addr); |
455 | 1381 } |
1382 | |
1383 | |
3219 | 1384 /* add the server core module configuration to the address:port */ |
455 | 1385 |
499 | 1386 static ngx_int_t |
3219 | 1387 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
|
1388 ngx_http_conf_addr_t *addr) |
455 | 1389 { |
3227
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1390 ngx_uint_t i; |
3219 | 1391 ngx_http_core_srv_conf_t **server; |
455 | 1392 |
3219 | 1393 if (addr->servers.elts == NULL) { |
1394 if (ngx_array_init(&addr->servers, cf->temp_pool, 4, | |
1395 sizeof(ngx_http_core_srv_conf_t *)) | |
1385 | 1396 != NGX_OK) |
477 | 1397 { |
1398 return NGX_ERROR; | |
1399 } | |
3227
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1400 |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1401 } else { |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1402 server = addr->servers.elts; |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1403 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
|
1404 if (server[i] == cscf) { |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1405 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
|
1406 "a duplicate listen %s", addr->opt.addr); |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1407 return NGX_ERROR; |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1408 } |
a610008bdc1a
test a duplicate listen in a server
Igor Sysoev <igor@sysoev.ru>
parents:
3226
diff
changeset
|
1409 } |
477 | 1410 } |
1411 | |
3219 | 1412 server = ngx_array_push(&addr->servers); |
1413 if (server == NULL) { | |
1414 return NGX_ERROR; | |
1415 } | |
477 | 1416 |
3219 | 1417 *server = cscf; |
455 | 1418 |
1419 return NGX_OK; | |
1420 } | |
1421 | |
1422 | |
1956
cb8c0c8e0c27
use ngx_int_t in ngx_sort() callback
Igor Sysoev <igor@sysoev.ru>
parents:
1910
diff
changeset
|
1423 static ngx_int_t |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1424 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
|
1425 ngx_array_t *ports) |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1426 { |
3258 | 1427 ngx_uint_t p, a; |
3219 | 1428 ngx_http_conf_port_t *port; |
1429 ngx_http_conf_addr_t *addr; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1430 |
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
|
1431 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
|
1432 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
|
1433 } |
8bd88de8fecd
fix segfault if http {} block is empty, the bug had been introduced in r3218
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
1434 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1435 port = ports->elts; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1436 for (p = 0; p < ports->nelts; p++) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1437 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1438 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
|
1439 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
|
1440 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1441 /* |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1442 * 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
|
1443 * 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
|
1444 */ |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1445 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1446 addr = port[p].addrs.elts; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1447 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
|
1448 |
3219 | 1449 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
|
1450 #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
|
1451 || 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
|
1452 #endif |
3219 | 1453 ) |
1454 { | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1455 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
|
1456 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1457 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1458 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1459 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1460 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1461 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
|
1462 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1463 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1464 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1465 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1466 return NGX_OK; |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1467 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1468 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1469 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1470 static ngx_int_t |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1471 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
|
1472 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
|
1473 { |
3219 | 1474 ngx_int_t rc; |
1475 ngx_uint_t n, s; | |
1476 ngx_hash_init_t hash; | |
1477 ngx_hash_keys_arrays_t ha; | |
1478 ngx_http_server_name_t *name; | |
1479 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
|
1480 #if (NGX_PCRE) |
3219 | 1481 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
|
1482 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1483 regex = 0; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1484 #endif |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1485 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1486 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
|
1487 |
5124
5482671df278
Use NGX_DEFAULT_POOL_SIZE macro where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
5121
diff
changeset
|
1488 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
|
1489 if (ha.temp_pool == NULL) { |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1490 return NGX_ERROR; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1491 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1492 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1493 ha.pool = cf->pool; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1494 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1495 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
|
1496 goto failed; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1497 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1498 |
3219 | 1499 cscfp = addr->servers.elts; |
1500 | |
1501 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
|
1502 |
3219 | 1503 name = cscfp[s]->server_names.elts; |
1504 | |
1505 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
|
1506 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1507 #if (NGX_PCRE) |
3219 | 1508 if (name[n].regex) { |
1509 regex++; | |
1510 continue; | |
1511 } | |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1512 #endif |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1513 |
3221
c8de5a8b6d17
rename core_srv_conf fields to more understandable default_server and server
Igor Sysoev <igor@sysoev.ru>
parents:
3220
diff
changeset
|
1514 rc = ngx_hash_add_key(&ha, &name[n].name, name[n].server, |
3219 | 1515 NGX_HASH_WILDCARD_KEY); |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1516 |
3219 | 1517 if (rc == NGX_ERROR) { |
1518 return NGX_ERROR; | |
1519 } | |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1520 |
3219 | 1521 if (rc == NGX_DECLINED) { |
1522 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
1523 "invalid server name or wildcard \"%V\" on %s", | |
1524 &name[n].name, addr->opt.addr); | |
1525 return NGX_ERROR; | |
1526 } | |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1527 |
3219 | 1528 if (rc == NGX_BUSY) { |
3823 | 1529 ngx_log_error(NGX_LOG_WARN, cf->log, 0, |
3219 | 1530 "conflicting server name \"%V\" on %s, ignored", |
1531 &name[n].name, addr->opt.addr); | |
1532 } | |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1533 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1534 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1535 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1536 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
|
1537 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
|
1538 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
|
1539 hash.name = "server_names_hash"; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1540 hash.pool = cf->pool; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1541 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1542 if (ha.keys.nelts) { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1543 hash.hash = &addr->hash; |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1544 hash.temp_pool = NULL; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1545 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1546 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
|
1547 goto failed; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1548 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1549 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1550 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1551 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
|
1552 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1553 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
|
1554 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
|
1555 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1556 hash.hash = NULL; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1557 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
|
1558 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1559 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
|
1560 ha.dns_wc_head.nelts) |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1561 != NGX_OK) |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1562 { |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1563 goto failed; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1564 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1565 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1566 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
|
1567 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1568 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1569 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
|
1570 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1571 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
|
1572 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
|
1573 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1574 hash.hash = NULL; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1575 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
|
1576 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1577 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
|
1578 ha.dns_wc_tail.nelts) |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1579 != NGX_OK) |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1580 { |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1581 goto failed; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1582 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1583 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1584 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
|
1585 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1586 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1587 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
|
1588 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1589 #if (NGX_PCRE) |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1590 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1591 if (regex == 0) { |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1592 return NGX_OK; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1593 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1594 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1595 addr->nregex = regex; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1596 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
|
1597 if (addr->regex == NULL) { |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1598 return NGX_ERROR; |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1599 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1600 |
3219 | 1601 i = 0; |
1602 | |
1603 for (s = 0; s < addr->servers.nelts; s++) { | |
1604 | |
1605 name = cscfp[s]->server_names.elts; | |
1606 | |
1607 for (n = 0; n < cscfp[s]->server_names.nelts; n++) { | |
1608 if (name[n].regex) { | |
1609 addr->regex[i++] = name[n]; | |
1610 } | |
2511
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1611 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1612 } |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1613 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1614 #endif |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1615 |
f91c5c964e61
split ports, addresses, and server names preparation and optimization
Igor Sysoev <igor@sysoev.ru>
parents:
2407
diff
changeset
|
1616 return NGX_OK; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1617 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1618 failed: |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1619 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1620 ngx_destroy_pool(ha.temp_pool); |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1621 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1622 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1623 } |
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_cmp_conf_addrs(const void *one, const void *two) |
593 | 1628 { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1629 ngx_http_conf_addr_t *first, *second; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1630 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1631 first = (ngx_http_conf_addr_t *) one; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1632 second = (ngx_http_conf_addr_t *) two; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1633 |
3218
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1634 if (first->opt.wildcard) { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1635 /* a wildcard address must be the last resort, shift it to the end */ |
593 | 1636 return 1; |
1637 } | |
1638 | |
4755
7ab10517ae58
Fixed sorting of listen addresses so that wildcard address is always at
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
1639 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
|
1640 /* 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
|
1641 return -1; |
7ab10517ae58
Fixed sorting of listen addresses so that wildcard address is always at
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
1642 } |
7ab10517ae58
Fixed sorting of listen addresses so that wildcard address is always at
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
1643 |
3218
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1644 if (first->opt.bind && !second->opt.bind) { |
593 | 1645 /* shift explicit bind()ed addresses to the start */ |
1646 return -1; | |
1647 } | |
1648 | |
3218
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1649 if (!first->opt.bind && second->opt.bind) { |
593 | 1650 /* shift explicit bind()ed addresses to the start */ |
1651 return 1; | |
1652 } | |
1653 | |
1654 /* do not sort by default */ | |
1655 | |
1656 return 0; | |
1657 } | |
1658 | |
1659 | |
1660 static int ngx_libc_cdecl | |
1661 ngx_http_cmp_dns_wildcards(const void *one, const void *two) | |
1662 { | |
1663 ngx_hash_key_t *first, *second; | |
1664 | |
1665 first = (ngx_hash_key_t *) one; | |
1666 second = (ngx_hash_key_t *) two; | |
1667 | |
3116
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
2852
diff
changeset
|
1668 return ngx_dns_strcmp(first->key.data, second->key.data); |
593 | 1669 } |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1670 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1671 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1672 static ngx_int_t |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1673 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
|
1674 { |
2533 | 1675 ngx_uint_t i, last, bind_wildcard; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1676 ngx_listening_t *ls; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1677 ngx_http_port_t *hport; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1678 ngx_http_conf_addr_t *addr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1679 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1680 addr = port->addrs.elts; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1681 last = port->addrs.nelts; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1682 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1683 /* |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1684 * 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
|
1685 * 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
|
1686 * 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
|
1687 * 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
|
1688 */ |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1689 |
3218
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1690 if (addr[last - 1].opt.wildcard) { |
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1691 addr[last - 1].opt.bind = 1; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1692 bind_wildcard = 1; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1693 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1694 } else { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1695 bind_wildcard = 0; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1696 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1697 |
2533 | 1698 i = 0; |
1699 | |
1700 while (i < last) { | |
1701 | |
3218
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1702 if (bind_wildcard && !addr[i].opt.bind) { |
2533 | 1703 i++; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1704 continue; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1705 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1706 |
2533 | 1707 ls = ngx_http_add_listening(cf, &addr[i]); |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1708 if (ls == NULL) { |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1709 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1710 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1711 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1712 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
|
1713 if (hport == NULL) { |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1714 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1715 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1716 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1717 ls->servers = hport; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1718 |
2533 | 1719 if (i == last - 1) { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1720 hport->naddrs = last; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1721 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1722 } else { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1723 hport->naddrs = 1; |
2533 | 1724 i = 0; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1725 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1726 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1727 switch (ls->sockaddr->sa_family) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1728 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1729 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1730 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1731 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
|
1732 return NGX_ERROR; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1733 } |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1734 break; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1735 #endif |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1736 default: /* AF_INET */ |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1737 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
|
1738 return NGX_ERROR; |
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 break; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1741 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1742 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1743 addr++; |
2022
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1744 last--; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1745 } |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1746 |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1747 return NGX_OK; |
35b35b84f5ef
split ngx_http_block() further
Igor Sysoev <igor@sysoev.ru>
parents:
2021
diff
changeset
|
1748 } |
2138 | 1749 |
1750 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1751 static ngx_listening_t * |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1752 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
|
1753 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1754 ngx_listening_t *ls; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1755 ngx_http_core_loc_conf_t *clcf; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1756 ngx_http_core_srv_conf_t *cscf; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1757 |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1758 ls = ngx_create_listening(cf, &addr->opt.u.sockaddr, addr->opt.socklen); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1759 if (ls == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1760 return NULL; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1761 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1762 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1763 ls->addr_ntop = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1764 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1765 ls->handler = ngx_http_init_connection; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1766 |
3221
c8de5a8b6d17
rename core_srv_conf fields to more understandable default_server and server
Igor Sysoev <igor@sysoev.ru>
parents:
3220
diff
changeset
|
1767 cscf = addr->default_server; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1768 ls->pool_size = cscf->connection_pool_size; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1769 ls->post_accept_timeout = cscf->client_header_timeout; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1770 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1771 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
|
1772 |
2785
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2689
diff
changeset
|
1773 ls->logp = clcf->error_log; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1774 ls->log.data = &ls->addr_text; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1775 ls->log.handler = ngx_accept_log_error; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1776 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1777 #if (NGX_WIN32) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1778 { |
4154
57d45d345651
Fixed segmentation fault with empty config on Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4142
diff
changeset
|
1779 ngx_iocp_conf_t *iocpcf = NULL; |
57d45d345651
Fixed segmentation fault with empty config on Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4142
diff
changeset
|
1780 |
57d45d345651
Fixed segmentation fault with empty config on Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4142
diff
changeset
|
1781 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
|
1782 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
|
1783 } |
57d45d345651
Fixed segmentation fault with empty config on Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4142
diff
changeset
|
1784 if (iocpcf && iocpcf->acceptex_read) { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1785 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
|
1786 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1787 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1788 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1789 |
3217 | 1790 ls->backlog = addr->opt.backlog; |
1791 ls->rcvbuf = addr->opt.rcvbuf; | |
1792 ls->sndbuf = addr->opt.sndbuf; | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1793 |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4154
diff
changeset
|
1794 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
|
1795 #if (NGX_HAVE_KEEPALIVE_TUNABLE) |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4154
diff
changeset
|
1796 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
|
1797 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
|
1798 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
|
1799 #endif |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4154
diff
changeset
|
1800 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1801 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) |
3217 | 1802 ls->accept_filter = addr->opt.accept_filter; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1803 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1804 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1805 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) |
3217 | 1806 ls->deferred_accept = addr->opt.deferred_accept; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1807 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1808 |
2562 | 1809 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) |
3217 | 1810 ls->ipv6only = addr->opt.ipv6only; |
2562 | 1811 #endif |
1812 | |
3676 | 1813 #if (NGX_HAVE_SETFIB) |
1814 ls->setfib = addr->opt.setfib; | |
1815 #endif | |
1816 | |
5456
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5388
diff
changeset
|
1817 #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
|
1818 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
|
1819 #endif |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5388
diff
changeset
|
1820 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1821 return ls; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1822 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1823 |
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 static ngx_int_t |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1826 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
|
1827 ngx_http_conf_addr_t *addr) |
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 ngx_uint_t i; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1830 ngx_http_in_addr_t *addrs; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1831 struct sockaddr_in *sin; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1832 ngx_http_virtual_names_t *vn; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1833 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1834 hport->addrs = ngx_pcalloc(cf->pool, |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1835 hport->naddrs * sizeof(ngx_http_in_addr_t)); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1836 if (hport->addrs == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1837 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1838 } |
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 addrs = hport->addrs; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1841 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1842 for (i = 0; i < hport->naddrs; i++) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1843 |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1844 sin = &addr[i].opt.u.sockaddr_in; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1845 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
|
1846 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
|
1847 #if (NGX_HTTP_SSL) |
3218
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1848 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
|
1849 #endif |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1850 #if (NGX_HTTP_SPDY) |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1851 addrs[i].conf.spdy = addr[i].opt.spdy; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1852 #endif |
5605
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5545
diff
changeset
|
1853 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
|
1854 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1855 if (addr[i].hash.buckets == NULL |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1856 && (addr[i].wc_head == NULL |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1857 || addr[i].wc_head->hash.buckets == NULL) |
2580
684ca3b0ae14
test wildcard tail hash existance
Igor Sysoev <igor@sysoev.ru>
parents:
2562
diff
changeset
|
1858 && (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
|
1859 || 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
|
1860 #if (NGX_PCRE) |
1fb5e7e05a4e
always run regex in server_name to get captures
Igor Sysoev <igor@sysoev.ru>
parents:
2580
diff
changeset
|
1861 && addr[i].nregex == 0 |
1fb5e7e05a4e
always run regex in server_name to get captures
Igor Sysoev <igor@sysoev.ru>
parents:
2580
diff
changeset
|
1862 #endif |
1fb5e7e05a4e
always run regex in server_name to get captures
Igor Sysoev <igor@sysoev.ru>
parents:
2580
diff
changeset
|
1863 ) |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1864 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1865 continue; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1866 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1867 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1868 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
|
1869 if (vn == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1870 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1871 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1872 |
2689
6caf687a831f
backout r2535: virtual names is a property of address:port pair,
Igor Sysoev <igor@sysoev.ru>
parents:
2688
diff
changeset
|
1873 addrs[i].conf.virtual_names = vn; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1874 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1875 vn->names.hash = addr[i].hash; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1876 vn->names.wc_head = addr[i].wc_head; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1877 vn->names.wc_tail = addr[i].wc_tail; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1878 #if (NGX_PCRE) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1879 vn->nregex = addr[i].nregex; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1880 vn->regex = addr[i].regex; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1881 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1882 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1883 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1884 return NGX_OK; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1885 } |
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 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1888 #if (NGX_HAVE_INET6) |
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 static ngx_int_t |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1891 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
|
1892 ngx_http_conf_addr_t *addr) |
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 ngx_uint_t i; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1895 ngx_http_in6_addr_t *addrs6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1896 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1897 ngx_http_virtual_names_t *vn; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1898 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1899 hport->addrs = ngx_pcalloc(cf->pool, |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1900 hport->naddrs * sizeof(ngx_http_in6_addr_t)); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1901 if (hport->addrs == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1902 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1903 } |
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 addrs6 = hport->addrs; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1906 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1907 for (i = 0; i < hport->naddrs; i++) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1908 |
3395
4e15548b29d4
fix building by gcc 4.4 with -O2/3/s:
Igor Sysoev <igor@sysoev.ru>
parents:
3372
diff
changeset
|
1909 sin6 = &addr[i].opt.u.sockaddr_in6; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1910 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
|
1911 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
|
1912 #if (NGX_HTTP_SSL) |
3218
022a7662b4ed
refactor http listen code: remove duplicate options fields
Igor Sysoev <igor@sysoev.ru>
parents:
3217
diff
changeset
|
1913 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
|
1914 #endif |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1915 #if (NGX_HTTP_SPDY) |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1916 addrs6[i].conf.spdy = addr[i].opt.spdy; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
4755
diff
changeset
|
1917 #endif |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1918 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1919 if (addr[i].hash.buckets == NULL |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1920 && (addr[i].wc_head == NULL |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1921 || 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
|
1922 && (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
|
1923 || 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
|
1924 #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
|
1925 && 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
|
1926 #endif |
3770119af0b5
always run regex in server_name to get captures for IPv6 addresses,
Igor Sysoev <igor@sysoev.ru>
parents:
3824
diff
changeset
|
1927 ) |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1928 { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1929 continue; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1930 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1931 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1932 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
|
1933 if (vn == NULL) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1934 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1935 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1936 |
2689
6caf687a831f
backout r2535: virtual names is a property of address:port pair,
Igor Sysoev <igor@sysoev.ru>
parents:
2688
diff
changeset
|
1937 addrs6[i].conf.virtual_names = vn; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1938 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1939 vn->names.hash = addr[i].hash; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1940 vn->names.wc_head = addr[i].wc_head; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1941 vn->names.wc_tail = addr[i].wc_tail; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1942 #if (NGX_PCRE) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1943 vn->nregex = addr[i].nregex; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1944 vn->regex = addr[i].regex; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1945 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1946 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1947 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1948 return NGX_OK; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1949 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1950 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1951 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1952 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2511
diff
changeset
|
1953 |
2138 | 1954 char * |
1955 ngx_http_types_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1956 { | |
1957 char *p = conf; | |
1958 | |
1959 ngx_array_t **types; | |
1960 ngx_str_t *value, *default_type; | |
1961 ngx_uint_t i, n, hash; | |
1962 ngx_hash_key_t *type; | |
1963 | |
1964 types = (ngx_array_t **) (p + cmd->offset); | |
1965 | |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
1966 if (*types == (void *) -1) { |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
1967 return NGX_CONF_OK; |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
1968 } |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
1969 |
2138 | 1970 default_type = cmd->post; |
1971 | |
1972 if (*types == NULL) { | |
1973 *types = ngx_array_create(cf->temp_pool, 1, sizeof(ngx_hash_key_t)); | |
1974 if (*types == NULL) { | |
1975 return NGX_CONF_ERROR; | |
1976 } | |
1977 | |
1978 if (default_type) { | |
1979 type = ngx_array_push(*types); | |
1980 if (type == NULL) { | |
1981 return NGX_CONF_ERROR; | |
1982 } | |
1983 | |
1984 type->key = *default_type; | |
1985 type->key_hash = ngx_hash_key(default_type->data, | |
1986 default_type->len); | |
1987 type->value = (void *) 4; | |
1988 } | |
1989 } | |
1990 | |
1991 value = cf->args->elts; | |
1992 | |
1993 for (i = 1; i < cf->args->nelts; i++) { | |
1994 | |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
1995 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
|
1996 *types = (void *) -1; |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
1997 return NGX_CONF_OK; |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
1998 } |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
1999 |
2138 | 2000 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len); |
2001 value[i].data[value[i].len] = '\0'; | |
2002 | |
2003 type = (*types)->elts; | |
2004 for (n = 0; n < (*types)->nelts; n++) { | |
2005 | |
2006 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) { | |
2007 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
2008 "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
|
2009 goto next; |
2138 | 2010 } |
2011 } | |
2012 | |
2013 type = ngx_array_push(*types); | |
2014 if (type == NULL) { | |
2015 return NGX_CONF_ERROR; | |
2016 } | |
2017 | |
2018 type->key = value[i]; | |
2019 type->key_hash = hash; | |
2020 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
|
2021 |
1b8459a53e4b
Avoided to add duplicate hash key in ngx_http_types_slot().
Gu Feng <flygoast@126.com>
parents:
5741
diff
changeset
|
2022 next: |
1b8459a53e4b
Avoided to add duplicate hash key in ngx_http_types_slot().
Gu Feng <flygoast@126.com>
parents:
5741
diff
changeset
|
2023 |
1b8459a53e4b
Avoided to add duplicate hash key in ngx_http_types_slot().
Gu Feng <flygoast@126.com>
parents:
5741
diff
changeset
|
2024 continue; |
2138 | 2025 } |
2026 | |
2027 return NGX_CONF_OK; | |
2028 } | |
2029 | |
2030 | |
2031 char * | |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2032 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
|
2033 ngx_array_t **prev_keys, ngx_hash_t *prev_types_hash, |
2138 | 2034 ngx_str_t *default_types) |
2035 { | |
2036 ngx_hash_init_t hash; | |
2037 | |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2038 if (*keys) { |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2039 |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2040 if (*keys == (void *) -1) { |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2041 return NGX_CONF_OK; |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2042 } |
2138 | 2043 |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2044 hash.hash = types_hash; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2045 hash.key = NULL; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2046 hash.max_size = 2048; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2047 hash.bucket_size = 64; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2048 hash.name = "test_types_hash"; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2049 hash.pool = cf->pool; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2050 hash.temp_pool = NULL; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2051 |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2052 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
|
2053 return NGX_CONF_ERROR; |
2138 | 2054 } |
2055 | |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2056 return NGX_CONF_OK; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2057 } |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2058 |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2059 if (prev_types_hash->buckets == NULL) { |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2060 |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2061 if (*prev_keys == NULL) { |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2062 |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2063 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
|
2064 != NGX_OK) |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2065 { |
2223
005fc65f7ce7
style fix: remove tabs and trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
2219
diff
changeset
|
2066 return NGX_CONF_ERROR; |
005fc65f7ce7
style fix: remove tabs and trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
2219
diff
changeset
|
2067 } |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2068 |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2069 } else if (*prev_keys == (void *) -1) { |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2070 *keys = *prev_keys; |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2071 return NGX_CONF_OK; |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2072 } |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2073 |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2074 hash.hash = prev_types_hash; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2075 hash.key = NULL; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2076 hash.max_size = 2048; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2077 hash.bucket_size = 64; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2078 hash.name = "test_types_hash"; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2079 hash.pool = cf->pool; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2080 hash.temp_pool = NULL; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2081 |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2082 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
|
2083 != NGX_OK) |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3258
diff
changeset
|
2084 { |
2138 | 2085 return NGX_CONF_ERROR; |
2086 } | |
2087 } | |
2088 | |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2089 *types_hash = *prev_types_hash; |
2138 | 2090 |
2091 return NGX_CONF_OK; | |
2092 | |
2093 } | |
2094 | |
2095 | |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2096 ngx_int_t |
2138 | 2097 ngx_http_set_default_types(ngx_conf_t *cf, ngx_array_t **types, |
2098 ngx_str_t *default_type) | |
2099 { | |
2100 ngx_hash_key_t *type; | |
2101 | |
2102 *types = ngx_array_create(cf->temp_pool, 1, sizeof(ngx_hash_key_t)); | |
2103 if (*types == NULL) { | |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2104 return NGX_ERROR; |
2138 | 2105 } |
2106 | |
2107 while (default_type->len) { | |
2108 | |
2109 type = ngx_array_push(*types); | |
2110 if (type == NULL) { | |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2111 return NGX_ERROR; |
2138 | 2112 } |
2113 | |
2114 type->key = *default_type; | |
2115 type->key_hash = ngx_hash_key(default_type->data, | |
2116 default_type->len); | |
2117 type->value = (void *) 4; | |
2118 | |
2119 default_type++; | |
2120 } | |
2121 | |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
2122 return NGX_OK; |
2138 | 2123 } |