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