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