Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_map_module.c @ 7524:deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
This ensures that correct ctx is always available, including after
filter finalization. In particular, this fixes a segmentation fault
with the following configuration:
location / {
image_filter test;
perl 'sub {
my $r = shift;
$r->send_http_header();
$r->print("foo\n");
$r->print("bar\n");
}';
}
This also seems to be the only way to correctly handle filter finalization
in various complex cases, for example, when embedded perl is used both
in the original handler and in an error page called after filter
finalization.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 12 Jul 2019 11:29:22 +0300 |
parents | ec10ce307dc0 |
children |
rev | line source |
---|---|
589 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
589 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
13 typedef struct { | |
14 ngx_uint_t hash_max_size; | |
15 ngx_uint_t hash_bucket_size; | |
16 } ngx_http_map_conf_t; | |
17 | |
18 | |
19 typedef struct { | |
593 | 20 ngx_hash_keys_arrays_t keys; |
589 | 21 |
22 ngx_array_t *values_hash; | |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
23 #if (NGX_PCRE) |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
24 ngx_array_t regexes; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
25 #endif |
589 | 26 |
27 ngx_http_variable_value_t *default_value; | |
3792
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
28 ngx_conf_t *cf; |
6832
ec10ce307dc0
Map: the "volatile" parameter.
Ruslan Ermilov <ru@nginx.com>
parents:
6831
diff
changeset
|
29 unsigned hostnames:1; |
ec10ce307dc0
Map: the "volatile" parameter.
Ruslan Ermilov <ru@nginx.com>
parents:
6831
diff
changeset
|
30 unsigned no_cacheable:1; |
589 | 31 } ngx_http_map_conf_ctx_t; |
32 | |
33 | |
34 typedef struct { | |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
35 ngx_http_map_t map; |
3789
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
36 ngx_http_complex_value_t value; |
589 | 37 ngx_http_variable_value_t *default_value; |
38 ngx_uint_t hostnames; /* unsigned hostnames:1 */ | |
39 } ngx_http_map_ctx_t; | |
40 | |
41 | |
42 static int ngx_libc_cdecl ngx_http_map_cmp_dns_wildcards(const void *one, | |
43 const void *two); | |
44 static void *ngx_http_map_create_conf(ngx_conf_t *cf); | |
45 static char *ngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | |
46 static char *ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf); | |
47 | |
48 | |
49 static ngx_command_t ngx_http_map_commands[] = { | |
50 | |
51 { ngx_string("map"), | |
52 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE2, | |
53 ngx_http_map_block, | |
54 NGX_HTTP_MAIN_CONF_OFFSET, | |
55 0, | |
56 NULL }, | |
57 | |
58 { ngx_string("map_hash_max_size"), | |
59 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, | |
60 ngx_conf_set_num_slot, | |
61 NGX_HTTP_MAIN_CONF_OFFSET, | |
62 offsetof(ngx_http_map_conf_t, hash_max_size), | |
63 NULL }, | |
64 | |
65 { ngx_string("map_hash_bucket_size"), | |
66 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, | |
67 ngx_conf_set_num_slot, | |
68 NGX_HTTP_MAIN_CONF_OFFSET, | |
69 offsetof(ngx_http_map_conf_t, hash_bucket_size), | |
70 NULL }, | |
71 | |
72 ngx_null_command | |
73 }; | |
74 | |
75 | |
76 static ngx_http_module_t ngx_http_map_module_ctx = { | |
77 NULL, /* preconfiguration */ | |
78 NULL, /* postconfiguration */ | |
79 | |
80 ngx_http_map_create_conf, /* create main configuration */ | |
81 NULL, /* init main configuration */ | |
82 | |
83 NULL, /* create server configuration */ | |
84 NULL, /* merge server configuration */ | |
85 | |
86 NULL, /* create location configuration */ | |
87 NULL /* merge location configuration */ | |
88 }; | |
89 | |
90 | |
91 ngx_module_t ngx_http_map_module = { | |
92 NGX_MODULE_V1, | |
93 &ngx_http_map_module_ctx, /* module context */ | |
94 ngx_http_map_commands, /* module directives */ | |
95 NGX_HTTP_MODULE, /* module type */ | |
96 NULL, /* init master */ | |
97 NULL, /* init module */ | |
98 NULL, /* init process */ | |
99 NULL, /* init thread */ | |
100 NULL, /* exit thread */ | |
101 NULL, /* exit process */ | |
102 NULL, /* exit master */ | |
103 NGX_MODULE_V1_PADDING | |
104 }; | |
105 | |
106 | |
107 static ngx_int_t | |
108 ngx_http_map_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
109 uintptr_t data) | |
110 { | |
111 ngx_http_map_ctx_t *map = (ngx_http_map_ctx_t *) data; | |
112 | |
6535
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
113 ngx_str_t val, str; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
114 ngx_http_complex_value_t *cv; |
3789
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
115 ngx_http_variable_value_t *value; |
589 | 116 |
117 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
118 "http map started"); | |
119 | |
3789
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
120 if (ngx_http_complex_value(r, &map->value, &val) != NGX_OK) { |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
121 return NGX_ERROR; |
797
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
637
diff
changeset
|
122 } |
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
637
diff
changeset
|
123 |
4712
fd3eefefa5f9
map: strip final dot before looking up in a map of hostnames.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
124 if (map->hostnames && val.len > 0 && val.data[val.len - 1] == '.') { |
fd3eefefa5f9
map: strip final dot before looking up in a map of hostnames.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
125 val.len--; |
589 | 126 } |
127 | |
3929
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3874
diff
changeset
|
128 value = ngx_http_map_find(r, &map->map, &val); |
589 | 129 |
3792
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
130 if (value == NULL) { |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
131 value = map->default_value; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
132 } |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
133 |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
134 if (!value->valid) { |
6535
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
135 cv = (ngx_http_complex_value_t *) value->data; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
136 |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
137 if (ngx_http_complex_value(r, cv, &str) != NGX_OK) { |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
138 return NGX_ERROR; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
139 } |
589 | 140 |
6535
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
141 v->valid = 1; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
142 v->no_cacheable = 0; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
143 v->not_found = 0; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
144 v->len = str.len; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
145 v->data = str.data; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
146 |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
147 } else { |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
148 *v = *value; |
589 | 149 } |
150 | |
151 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
6480 | 152 "http map: \"%V\" \"%v\"", &val, v); |
589 | 153 |
154 return NGX_OK; | |
155 } | |
156 | |
157 | |
158 static void * | |
159 ngx_http_map_create_conf(ngx_conf_t *cf) | |
160 { | |
161 ngx_http_map_conf_t *mcf; | |
162 | |
163 mcf = ngx_palloc(cf->pool, sizeof(ngx_http_map_conf_t)); | |
164 if (mcf == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
165 return NULL; |
589 | 166 } |
167 | |
168 mcf->hash_max_size = NGX_CONF_UNSET_UINT; | |
169 mcf->hash_bucket_size = NGX_CONF_UNSET_UINT; | |
170 | |
171 return mcf; | |
172 } | |
173 | |
174 | |
175 static char * | |
176 ngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
177 { | |
178 ngx_http_map_conf_t *mcf = conf; | |
179 | |
3789
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
180 char *rv; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
181 ngx_str_t *value, name; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
182 ngx_conf_t save; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
183 ngx_pool_t *pool; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
184 ngx_hash_init_t hash; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
185 ngx_http_map_ctx_t *map; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
186 ngx_http_variable_t *var; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
187 ngx_http_map_conf_ctx_t ctx; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
188 ngx_http_compile_complex_value_t ccv; |
589 | 189 |
190 if (mcf->hash_max_size == NGX_CONF_UNSET_UINT) { | |
191 mcf->hash_max_size = 2048; | |
192 } | |
193 | |
194 if (mcf->hash_bucket_size == NGX_CONF_UNSET_UINT) { | |
195 mcf->hash_bucket_size = ngx_cacheline_size; | |
196 | |
197 } else { | |
198 mcf->hash_bucket_size = ngx_align(mcf->hash_bucket_size, | |
199 ngx_cacheline_size); | |
200 } | |
201 | |
202 map = ngx_pcalloc(cf->pool, sizeof(ngx_http_map_ctx_t)); | |
203 if (map == NULL) { | |
204 return NGX_CONF_ERROR; | |
205 } | |
206 | |
207 value = cf->args->elts; | |
208 | |
3789
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
209 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
589 | 210 |
3789
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
211 ccv.cf = cf; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
212 ccv.value = &value[1]; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
213 ccv.complex_value = &map->value; |
589 | 214 |
3789
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
215 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
589 | 216 return NGX_CONF_ERROR; |
217 } | |
218 | |
219 name = value[2]; | |
4972
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4827
diff
changeset
|
220 |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4827
diff
changeset
|
221 if (name.data[0] != '$') { |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4827
diff
changeset
|
222 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4827
diff
changeset
|
223 "invalid variable name \"%V\"", &name); |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4827
diff
changeset
|
224 return NGX_CONF_ERROR; |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4827
diff
changeset
|
225 } |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4827
diff
changeset
|
226 |
589 | 227 name.len--; |
228 name.data++; | |
229 | |
1565 | 230 var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE); |
589 | 231 if (var == NULL) { |
232 return NGX_CONF_ERROR; | |
233 } | |
234 | |
637 | 235 var->get_handler = ngx_http_map_variable; |
589 | 236 var->data = (uintptr_t) map; |
237 | |
5124
5482671df278
Use NGX_DEFAULT_POOL_SIZE macro where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
238 pool = ngx_create_pool(NGX_DEFAULT_POOL_SIZE, cf->log); |
589 | 239 if (pool == NULL) { |
240 return NGX_CONF_ERROR; | |
241 } | |
242 | |
593 | 243 ctx.keys.pool = cf->pool; |
244 ctx.keys.temp_pool = pool; | |
589 | 245 |
593 | 246 if (ngx_hash_keys_array_init(&ctx.keys, NGX_HASH_LARGE) != NGX_OK) { |
589 | 247 ngx_destroy_pool(pool); |
248 return NGX_CONF_ERROR; | |
249 } | |
250 | |
593 | 251 ctx.values_hash = ngx_pcalloc(pool, sizeof(ngx_array_t) * ctx.keys.hsize); |
589 | 252 if (ctx.values_hash == NULL) { |
253 ngx_destroy_pool(pool); | |
254 return NGX_CONF_ERROR; | |
255 } | |
256 | |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
257 #if (NGX_PCRE) |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
258 if (ngx_array_init(&ctx.regexes, cf->pool, 2, sizeof(ngx_http_map_regex_t)) |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
259 != NGX_OK) |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
260 { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
261 ngx_destroy_pool(pool); |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
262 return NGX_CONF_ERROR; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
263 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
264 #endif |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
265 |
589 | 266 ctx.default_value = NULL; |
3792
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
267 ctx.cf = &save; |
589 | 268 ctx.hostnames = 0; |
6832
ec10ce307dc0
Map: the "volatile" parameter.
Ruslan Ermilov <ru@nginx.com>
parents:
6831
diff
changeset
|
269 ctx.no_cacheable = 0; |
589 | 270 |
271 save = *cf; | |
272 cf->pool = pool; | |
273 cf->ctx = &ctx; | |
274 cf->handler = ngx_http_map; | |
275 cf->handler_conf = conf; | |
276 | |
277 rv = ngx_conf_parse(cf, NULL); | |
278 | |
279 *cf = save; | |
280 | |
281 if (rv != NGX_CONF_OK) { | |
282 ngx_destroy_pool(pool); | |
283 return rv; | |
284 } | |
285 | |
6832
ec10ce307dc0
Map: the "volatile" parameter.
Ruslan Ermilov <ru@nginx.com>
parents:
6831
diff
changeset
|
286 if (ctx.no_cacheable) { |
ec10ce307dc0
Map: the "volatile" parameter.
Ruslan Ermilov <ru@nginx.com>
parents:
6831
diff
changeset
|
287 var->flags |= NGX_HTTP_VAR_NOCACHEABLE; |
ec10ce307dc0
Map: the "volatile" parameter.
Ruslan Ermilov <ru@nginx.com>
parents:
6831
diff
changeset
|
288 } |
ec10ce307dc0
Map: the "volatile" parameter.
Ruslan Ermilov <ru@nginx.com>
parents:
6831
diff
changeset
|
289 |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
290 map->default_value = ctx.default_value ? ctx.default_value: |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
291 &ngx_http_variable_null_value; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
292 |
4712
fd3eefefa5f9
map: strip final dot before looking up in a map of hostnames.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
293 map->hostnames = ctx.hostnames; |
fd3eefefa5f9
map: strip final dot before looking up in a map of hostnames.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
294 |
589 | 295 hash.key = ngx_hash_key_lc; |
296 hash.max_size = mcf->hash_max_size; | |
297 hash.bucket_size = mcf->hash_bucket_size; | |
298 hash.name = "map_hash"; | |
299 hash.pool = cf->pool; | |
300 | |
593 | 301 if (ctx.keys.keys.nelts) { |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
302 hash.hash = &map->map.hash.hash; |
589 | 303 hash.temp_pool = NULL; |
304 | |
593 | 305 if (ngx_hash_init(&hash, ctx.keys.keys.elts, ctx.keys.keys.nelts) |
591 | 306 != NGX_OK) |
307 { | |
593 | 308 ngx_destroy_pool(pool); |
589 | 309 return NGX_CONF_ERROR; |
310 } | |
311 } | |
312 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
313 if (ctx.keys.dns_wc_head.nelts) { |
589 | 314 |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
315 ngx_qsort(ctx.keys.dns_wc_head.elts, |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
316 (size_t) ctx.keys.dns_wc_head.nelts, |
589 | 317 sizeof(ngx_hash_key_t), ngx_http_map_cmp_dns_wildcards); |
318 | |
319 hash.hash = NULL; | |
320 hash.temp_pool = pool; | |
321 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
322 if (ngx_hash_wildcard_init(&hash, ctx.keys.dns_wc_head.elts, |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
323 ctx.keys.dns_wc_head.nelts) |
589 | 324 != NGX_OK) |
325 { | |
593 | 326 ngx_destroy_pool(pool); |
589 | 327 return NGX_CONF_ERROR; |
328 } | |
329 | |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
330 map->map.hash.wc_head = (ngx_hash_wildcard_t *) hash.hash; |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
331 } |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
332 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
333 if (ctx.keys.dns_wc_tail.nelts) { |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
334 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
335 ngx_qsort(ctx.keys.dns_wc_tail.elts, |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
336 (size_t) ctx.keys.dns_wc_tail.nelts, |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
337 sizeof(ngx_hash_key_t), ngx_http_map_cmp_dns_wildcards); |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
338 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
339 hash.hash = NULL; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
340 hash.temp_pool = pool; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
341 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
342 if (ngx_hash_wildcard_init(&hash, ctx.keys.dns_wc_tail.elts, |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
343 ctx.keys.dns_wc_tail.nelts) |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
344 != NGX_OK) |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
345 { |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
346 ngx_destroy_pool(pool); |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
347 return NGX_CONF_ERROR; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
348 } |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
349 |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
350 map->map.hash.wc_tail = (ngx_hash_wildcard_t *) hash.hash; |
589 | 351 } |
352 | |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
353 #if (NGX_PCRE) |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
354 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
355 if (ctx.regexes.nelts) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
356 map->map.regex = ctx.regexes.elts; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
357 map->map.nregex = ctx.regexes.nelts; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
358 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
359 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
360 #endif |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
361 |
589 | 362 ngx_destroy_pool(pool); |
363 | |
364 return rv; | |
365 } | |
366 | |
367 | |
368 static int ngx_libc_cdecl | |
369 ngx_http_map_cmp_dns_wildcards(const void *one, const void *two) | |
370 { | |
371 ngx_hash_key_t *first, *second; | |
372 | |
373 first = (ngx_hash_key_t *) one; | |
374 second = (ngx_hash_key_t *) two; | |
375 | |
3116
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
376 return ngx_dns_strcmp(first->key.data, second->key.data); |
589 | 377 } |
378 | |
379 | |
380 static char * | |
381 ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) | |
382 { | |
6535
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
383 u_char *data; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
384 size_t len; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
385 ngx_int_t rv; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
386 ngx_str_t *value, v; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
387 ngx_uint_t i, key; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
388 ngx_http_map_conf_ctx_t *ctx; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
389 ngx_http_complex_value_t cv, *cvp; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
390 ngx_http_variable_value_t *var, **vp; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
391 ngx_http_compile_complex_value_t ccv; |
589 | 392 |
393 ctx = cf->ctx; | |
394 | |
395 value = cf->args->elts; | |
396 | |
397 if (cf->args->nelts == 1 | |
398 && ngx_strcmp(value[0].data, "hostnames") == 0) | |
399 { | |
400 ctx->hostnames = 1; | |
401 return NGX_CONF_OK; | |
6831
014905eb7b3d
Map: simplified "map" block parser.
Ruslan Ermilov <ru@nginx.com>
parents:
6535
diff
changeset
|
402 } |
589 | 403 |
6832
ec10ce307dc0
Map: the "volatile" parameter.
Ruslan Ermilov <ru@nginx.com>
parents:
6831
diff
changeset
|
404 if (cf->args->nelts == 1 |
ec10ce307dc0
Map: the "volatile" parameter.
Ruslan Ermilov <ru@nginx.com>
parents:
6831
diff
changeset
|
405 && ngx_strcmp(value[0].data, "volatile") == 0) |
ec10ce307dc0
Map: the "volatile" parameter.
Ruslan Ermilov <ru@nginx.com>
parents:
6831
diff
changeset
|
406 { |
ec10ce307dc0
Map: the "volatile" parameter.
Ruslan Ermilov <ru@nginx.com>
parents:
6831
diff
changeset
|
407 ctx->no_cacheable = 1; |
ec10ce307dc0
Map: the "volatile" parameter.
Ruslan Ermilov <ru@nginx.com>
parents:
6831
diff
changeset
|
408 return NGX_CONF_OK; |
ec10ce307dc0
Map: the "volatile" parameter.
Ruslan Ermilov <ru@nginx.com>
parents:
6831
diff
changeset
|
409 } |
ec10ce307dc0
Map: the "volatile" parameter.
Ruslan Ermilov <ru@nginx.com>
parents:
6831
diff
changeset
|
410 |
6831
014905eb7b3d
Map: simplified "map" block parser.
Ruslan Ermilov <ru@nginx.com>
parents:
6535
diff
changeset
|
411 if (cf->args->nelts != 2) { |
589 | 412 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
413 "invalid number of the map parameters"); | |
414 return NGX_CONF_ERROR; | |
415 } | |
416 | |
417 if (ngx_strcmp(value[0].data, "include") == 0) { | |
4827
6e46016ea276
Fixed the "include" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4814
diff
changeset
|
418 return ngx_conf_include(cf, dummy, conf); |
589 | 419 } |
420 | |
421 key = 0; | |
422 | |
423 for (i = 0; i < value[1].len; i++) { | |
424 key = ngx_hash(key, value[1].data[i]); | |
425 } | |
426 | |
593 | 427 key %= ctx->keys.hsize; |
589 | 428 |
429 vp = ctx->values_hash[key].elts; | |
430 | |
431 if (vp) { | |
432 for (i = 0; i < ctx->values_hash[key].nelts; i++) { | |
6535
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
433 |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
434 if (vp[i]->valid) { |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
435 data = vp[i]->data; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
436 len = vp[i]->len; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
437 |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
438 } else { |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
439 cvp = (ngx_http_complex_value_t *) vp[i]->data; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
440 data = cvp->value.data; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
441 len = cvp->value.len; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
442 } |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
443 |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
444 if (value[1].len != len) { |
589 | 445 continue; |
446 } | |
447 | |
6535
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
448 if (ngx_strncmp(value[1].data, data, len) == 0) { |
589 | 449 var = vp[i]; |
450 goto found; | |
451 } | |
452 } | |
453 | |
454 } else { | |
455 if (ngx_array_init(&ctx->values_hash[key], cf->pool, 4, | |
456 sizeof(ngx_http_variable_value_t *)) | |
457 != NGX_OK) | |
458 { | |
459 return NGX_CONF_ERROR; | |
460 } | |
461 } | |
462 | |
593 | 463 var = ngx_palloc(ctx->keys.pool, sizeof(ngx_http_variable_value_t)); |
589 | 464 if (var == NULL) { |
465 return NGX_CONF_ERROR; | |
466 } | |
467 | |
6535
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
468 v.len = value[1].len; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
469 v.data = ngx_pstrdup(ctx->keys.pool, &value[1]); |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
470 if (v.data == NULL) { |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
471 return NGX_CONF_ERROR; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
472 } |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
473 |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
474 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
475 |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
476 ccv.cf = ctx->cf; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
477 ccv.value = &v; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
478 ccv.complex_value = &cv; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
479 |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
480 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
589 | 481 return NGX_CONF_ERROR; |
482 } | |
483 | |
6535
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
484 if (cv.lengths != NULL) { |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
485 cvp = ngx_palloc(ctx->keys.pool, sizeof(ngx_http_complex_value_t)); |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
486 if (cvp == NULL) { |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
487 return NGX_CONF_ERROR; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
488 } |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
489 |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
490 *cvp = cv; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
491 |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
492 var->len = 0; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
493 var->data = (u_char *) cvp; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
494 var->valid = 0; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
495 |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
496 } else { |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
497 var->len = v.len; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
498 var->data = v.data; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
499 var->valid = 1; |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
500 } |
db699978a33f
Map: support of complex values in resulting strings.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6480
diff
changeset
|
501 |
1565 | 502 var->no_cacheable = 0; |
589 | 503 var->not_found = 0; |
504 | |
505 vp = ngx_array_push(&ctx->values_hash[key]); | |
506 if (vp == NULL) { | |
507 return NGX_CONF_ERROR; | |
508 } | |
509 | |
510 *vp = var; | |
511 | |
512 found: | |
513 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
514 if (ngx_strcmp(value[0].data, "default") == 0) { |
589 | 515 |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
516 if (ctx->default_value) { |
589 | 517 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
518 "duplicate default map parameter"); |
589 | 519 return NGX_CONF_ERROR; |
520 } | |
521 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
522 ctx->default_value = var; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
523 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
524 return NGX_CONF_OK; |
589 | 525 } |
526 | |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
527 #if (NGX_PCRE) |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
528 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
529 if (value[0].len && value[0].data[0] == '~') { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
530 ngx_regex_compile_t rc; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
531 ngx_http_map_regex_t *regex; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
532 u_char errstr[NGX_MAX_CONF_ERRSTR]; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
533 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
534 regex = ngx_array_push(&ctx->regexes); |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
535 if (regex == NULL) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
536 return NGX_CONF_ERROR; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
537 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
538 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
539 value[0].len--; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
540 value[0].data++; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
541 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
542 ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
543 |
3930
ace14fd91086
revert r3875 since now map uses case sensetive regexes by default
Igor Sysoev <igor@sysoev.ru>
parents:
3929
diff
changeset
|
544 if (value[0].data[0] == '*') { |
ace14fd91086
revert r3875 since now map uses case sensetive regexes by default
Igor Sysoev <igor@sysoev.ru>
parents:
3929
diff
changeset
|
545 value[0].len--; |
ace14fd91086
revert r3875 since now map uses case sensetive regexes by default
Igor Sysoev <igor@sysoev.ru>
parents:
3929
diff
changeset
|
546 value[0].data++; |
ace14fd91086
revert r3875 since now map uses case sensetive regexes by default
Igor Sysoev <igor@sysoev.ru>
parents:
3929
diff
changeset
|
547 rc.options = NGX_REGEX_CASELESS; |
ace14fd91086
revert r3875 since now map uses case sensetive regexes by default
Igor Sysoev <igor@sysoev.ru>
parents:
3929
diff
changeset
|
548 } |
ace14fd91086
revert r3875 since now map uses case sensetive regexes by default
Igor Sysoev <igor@sysoev.ru>
parents:
3929
diff
changeset
|
549 |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
550 rc.pattern = value[0]; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
551 rc.err.len = NGX_MAX_CONF_ERRSTR; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
552 rc.err.data = errstr; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
553 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
554 regex->regex = ngx_http_regex_compile(ctx->cf, &rc); |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
555 if (regex->regex == NULL) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
556 return NGX_CONF_ERROR; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
557 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
558 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
559 regex->value = var; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
560 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
561 return NGX_CONF_OK; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
562 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
563 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
564 #endif |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
565 |
3791
11701c4c0358
use "\" to escape "default", "include", and "hostnames" values instead of "!"
Igor Sysoev <igor@sysoev.ru>
parents:
3790
diff
changeset
|
566 if (value[0].len && value[0].data[0] == '\\') { |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
567 value[0].len--; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
568 value[0].data++; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
569 } |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
570 |
6230
2a621245f4cf
Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5362
diff
changeset
|
571 rv = ngx_hash_add_key(&ctx->keys, &value[0], var, |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
572 (ctx->hostnames) ? NGX_HASH_WILDCARD_KEY : 0); |
589 | 573 |
6230
2a621245f4cf
Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5362
diff
changeset
|
574 if (rv == NGX_OK) { |
591 | 575 return NGX_CONF_OK; |
576 } | |
589 | 577 |
6230
2a621245f4cf
Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5362
diff
changeset
|
578 if (rv == NGX_DECLINED) { |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
579 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
580 "invalid hostname or wildcard \"%V\"", &value[0]); |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
581 } |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
582 |
6230
2a621245f4cf
Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5362
diff
changeset
|
583 if (rv == NGX_BUSY) { |
591 | 584 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
585 "conflicting parameter \"%V\"", &value[0]); | |
586 } | |
589 | 587 |
591 | 588 return NGX_CONF_ERROR; |
589 | 589 } |