Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_map_module.c @ 6081:12ab5cd445c0 stable-1.6
Core: fixed potential buffer overrun when initializing hash.
Initial size as calculated from the number of elements may be bigger
than max_size. If this happens, make sure to set size to max_size.
Reported by Chris West.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 24 Feb 2015 18:37:14 +0300 |
parents | 79b9101cecf4 |
children | 2a621245f4cf |
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; | |
3792
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
23 ngx_array_t var_values; |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
24 #if (NGX_PCRE) |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
25 ngx_array_t regexes; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
26 #endif |
589 | 27 |
28 ngx_http_variable_value_t *default_value; | |
3792
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
29 ngx_conf_t *cf; |
589 | 30 ngx_uint_t hostnames; /* unsigned hostnames:1 */ |
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 | |
3789
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
113 ngx_str_t val; |
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) { |
5362
79b9101cecf4
Handling of ngx_int_t != intptr_t case.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5124
diff
changeset
|
134 value = ngx_http_get_flushed_variable(r, (uintptr_t) value->data); |
589 | 135 |
3792
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
136 if (value == NULL || value->not_found) { |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
137 value = &ngx_http_variable_null_value; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
138 } |
589 | 139 } |
140 | |
3792
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
141 *v = *value; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
142 |
589 | 143 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3789
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
144 "http map: \"%v\" \"%v\"", &val, v); |
589 | 145 |
146 return NGX_OK; | |
147 } | |
148 | |
149 | |
150 static void * | |
151 ngx_http_map_create_conf(ngx_conf_t *cf) | |
152 { | |
153 ngx_http_map_conf_t *mcf; | |
154 | |
155 mcf = ngx_palloc(cf->pool, sizeof(ngx_http_map_conf_t)); | |
156 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
|
157 return NULL; |
589 | 158 } |
159 | |
160 mcf->hash_max_size = NGX_CONF_UNSET_UINT; | |
161 mcf->hash_bucket_size = NGX_CONF_UNSET_UINT; | |
162 | |
163 return mcf; | |
164 } | |
165 | |
166 | |
167 static char * | |
168 ngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
169 { | |
170 ngx_http_map_conf_t *mcf = conf; | |
171 | |
3789
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
172 char *rv; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
173 ngx_str_t *value, name; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
174 ngx_conf_t save; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
175 ngx_pool_t *pool; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
176 ngx_hash_init_t hash; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
177 ngx_http_map_ctx_t *map; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
178 ngx_http_variable_t *var; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
179 ngx_http_map_conf_ctx_t ctx; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
180 ngx_http_compile_complex_value_t ccv; |
589 | 181 |
182 if (mcf->hash_max_size == NGX_CONF_UNSET_UINT) { | |
183 mcf->hash_max_size = 2048; | |
184 } | |
185 | |
186 if (mcf->hash_bucket_size == NGX_CONF_UNSET_UINT) { | |
187 mcf->hash_bucket_size = ngx_cacheline_size; | |
188 | |
189 } else { | |
190 mcf->hash_bucket_size = ngx_align(mcf->hash_bucket_size, | |
191 ngx_cacheline_size); | |
192 } | |
193 | |
194 map = ngx_pcalloc(cf->pool, sizeof(ngx_http_map_ctx_t)); | |
195 if (map == NULL) { | |
196 return NGX_CONF_ERROR; | |
197 } | |
198 | |
199 value = cf->args->elts; | |
200 | |
3789
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
201 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
589 | 202 |
3789
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
203 ccv.cf = cf; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
204 ccv.value = &value[1]; |
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
205 ccv.complex_value = &map->value; |
589 | 206 |
3789
19c931be8b98
allow expressions in the first "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
207 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
589 | 208 return NGX_CONF_ERROR; |
209 } | |
210 | |
211 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
|
212 |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4827
diff
changeset
|
213 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
|
214 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
|
215 "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
|
216 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
|
217 } |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4827
diff
changeset
|
218 |
589 | 219 name.len--; |
220 name.data++; | |
221 | |
1565 | 222 var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE); |
589 | 223 if (var == NULL) { |
224 return NGX_CONF_ERROR; | |
225 } | |
226 | |
637 | 227 var->get_handler = ngx_http_map_variable; |
589 | 228 var->data = (uintptr_t) map; |
229 | |
5124
5482671df278
Use NGX_DEFAULT_POOL_SIZE macro where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
230 pool = ngx_create_pool(NGX_DEFAULT_POOL_SIZE, cf->log); |
589 | 231 if (pool == NULL) { |
232 return NGX_CONF_ERROR; | |
233 } | |
234 | |
593 | 235 ctx.keys.pool = cf->pool; |
236 ctx.keys.temp_pool = pool; | |
589 | 237 |
593 | 238 if (ngx_hash_keys_array_init(&ctx.keys, NGX_HASH_LARGE) != NGX_OK) { |
589 | 239 ngx_destroy_pool(pool); |
240 return NGX_CONF_ERROR; | |
241 } | |
242 | |
593 | 243 ctx.values_hash = ngx_pcalloc(pool, sizeof(ngx_array_t) * ctx.keys.hsize); |
589 | 244 if (ctx.values_hash == NULL) { |
245 ngx_destroy_pool(pool); | |
246 return NGX_CONF_ERROR; | |
247 } | |
248 | |
3792
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
249 if (ngx_array_init(&ctx.var_values, cf->pool, 2, |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
250 sizeof(ngx_http_variable_value_t)) |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
251 != NGX_OK) |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
252 { |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
253 ngx_destroy_pool(pool); |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
254 return NGX_CONF_ERROR; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
255 } |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
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; |
269 | |
270 save = *cf; | |
271 cf->pool = pool; | |
272 cf->ctx = &ctx; | |
273 cf->handler = ngx_http_map; | |
274 cf->handler_conf = conf; | |
275 | |
276 rv = ngx_conf_parse(cf, NULL); | |
277 | |
278 *cf = save; | |
279 | |
280 if (rv != NGX_CONF_OK) { | |
281 ngx_destroy_pool(pool); | |
282 return rv; | |
283 } | |
284 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
285 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
|
286 &ngx_http_variable_null_value; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
287 |
4712
fd3eefefa5f9
map: strip final dot before looking up in a map of hostnames.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
288 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
|
289 |
589 | 290 hash.key = ngx_hash_key_lc; |
291 hash.max_size = mcf->hash_max_size; | |
292 hash.bucket_size = mcf->hash_bucket_size; | |
293 hash.name = "map_hash"; | |
294 hash.pool = cf->pool; | |
295 | |
593 | 296 if (ctx.keys.keys.nelts) { |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
297 hash.hash = &map->map.hash.hash; |
589 | 298 hash.temp_pool = NULL; |
299 | |
593 | 300 if (ngx_hash_init(&hash, ctx.keys.keys.elts, ctx.keys.keys.nelts) |
591 | 301 != NGX_OK) |
302 { | |
593 | 303 ngx_destroy_pool(pool); |
589 | 304 return NGX_CONF_ERROR; |
305 } | |
306 } | |
307 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
308 if (ctx.keys.dns_wc_head.nelts) { |
589 | 309 |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
310 ngx_qsort(ctx.keys.dns_wc_head.elts, |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
311 (size_t) ctx.keys.dns_wc_head.nelts, |
589 | 312 sizeof(ngx_hash_key_t), ngx_http_map_cmp_dns_wildcards); |
313 | |
314 hash.hash = NULL; | |
315 hash.temp_pool = pool; | |
316 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
317 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
|
318 ctx.keys.dns_wc_head.nelts) |
589 | 319 != NGX_OK) |
320 { | |
593 | 321 ngx_destroy_pool(pool); |
589 | 322 return NGX_CONF_ERROR; |
323 } | |
324 | |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
325 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
|
326 } |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
327 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
328 if (ctx.keys.dns_wc_tail.nelts) { |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
329 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
330 ngx_qsort(ctx.keys.dns_wc_tail.elts, |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
331 (size_t) ctx.keys.dns_wc_tail.nelts, |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
332 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
|
333 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
334 hash.hash = NULL; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
335 hash.temp_pool = pool; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
336 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
337 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
|
338 ctx.keys.dns_wc_tail.nelts) |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
339 != NGX_OK) |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
340 { |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
341 ngx_destroy_pool(pool); |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
342 return NGX_CONF_ERROR; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
343 } |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
344 |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
345 map->map.hash.wc_tail = (ngx_hash_wildcard_t *) hash.hash; |
589 | 346 } |
347 | |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
348 #if (NGX_PCRE) |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
349 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
350 if (ctx.regexes.nelts) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
351 map->map.regex = ctx.regexes.elts; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
352 map->map.nregex = ctx.regexes.nelts; |
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 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
355 #endif |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
356 |
589 | 357 ngx_destroy_pool(pool); |
358 | |
359 return rv; | |
360 } | |
361 | |
362 | |
363 static int ngx_libc_cdecl | |
364 ngx_http_map_cmp_dns_wildcards(const void *one, const void *two) | |
365 { | |
366 ngx_hash_key_t *first, *second; | |
367 | |
368 first = (ngx_hash_key_t *) one; | |
369 second = (ngx_hash_key_t *) two; | |
370 | |
3116
98e288c6dac3
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
371 return ngx_dns_strcmp(first->key.data, second->key.data); |
589 | 372 } |
373 | |
374 | |
375 static char * | |
376 ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) | |
377 { | |
3792
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
378 ngx_int_t rc, index; |
4827
6e46016ea276
Fixed the "include" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4814
diff
changeset
|
379 ngx_str_t *value, name; |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
380 ngx_uint_t i, key; |
589 | 381 ngx_http_map_conf_ctx_t *ctx; |
591 | 382 ngx_http_variable_value_t *var, **vp; |
589 | 383 |
384 ctx = cf->ctx; | |
385 | |
386 value = cf->args->elts; | |
387 | |
388 if (cf->args->nelts == 1 | |
389 && ngx_strcmp(value[0].data, "hostnames") == 0) | |
390 { | |
391 ctx->hostnames = 1; | |
392 return NGX_CONF_OK; | |
393 | |
394 } else if (cf->args->nelts != 2) { | |
395 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
396 "invalid number of the map parameters"); | |
397 return NGX_CONF_ERROR; | |
398 } | |
399 | |
400 if (ngx_strcmp(value[0].data, "include") == 0) { | |
4827
6e46016ea276
Fixed the "include" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4814
diff
changeset
|
401 return ngx_conf_include(cf, dummy, conf); |
589 | 402 } |
403 | |
3792
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
404 if (value[1].data[0] == '$') { |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
405 name = value[1]; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
406 name.len--; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
407 name.data++; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
408 |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
409 index = ngx_http_get_variable_index(ctx->cf, &name); |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
410 if (index == NGX_ERROR) { |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
411 return NGX_CONF_ERROR; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
412 } |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
413 |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
414 var = ctx->var_values.elts; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
415 |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
416 for (i = 0; i < ctx->var_values.nelts; i++) { |
5362
79b9101cecf4
Handling of ngx_int_t != intptr_t case.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5124
diff
changeset
|
417 if (index == (intptr_t) var[i].data) { |
4814
0656cfe8f7cb
Map: fixed optimization of variables as values.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4712
diff
changeset
|
418 var = &var[i]; |
3792
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
419 goto found; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
420 } |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
421 } |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
422 |
4814
0656cfe8f7cb
Map: fixed optimization of variables as values.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4712
diff
changeset
|
423 var = ngx_array_push(&ctx->var_values); |
3792
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
424 if (var == NULL) { |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
425 return NGX_CONF_ERROR; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
426 } |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
427 |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
428 var->valid = 0; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
429 var->no_cacheable = 0; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
430 var->not_found = 0; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
431 var->len = 0; |
5362
79b9101cecf4
Handling of ngx_int_t != intptr_t case.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5124
diff
changeset
|
432 var->data = (u_char *) (intptr_t) index; |
3792
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
433 |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
434 goto found; |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
435 } |
164a7f8df979
allow variable as "map" value
Igor Sysoev <igor@sysoev.ru>
parents:
3791
diff
changeset
|
436 |
589 | 437 key = 0; |
438 | |
439 for (i = 0; i < value[1].len; i++) { | |
440 key = ngx_hash(key, value[1].data[i]); | |
441 } | |
442 | |
593 | 443 key %= ctx->keys.hsize; |
589 | 444 |
445 vp = ctx->values_hash[key].elts; | |
446 | |
447 if (vp) { | |
448 for (i = 0; i < ctx->values_hash[key].nelts; i++) { | |
449 if (value[1].len != (size_t) vp[i]->len) { | |
450 continue; | |
451 } | |
452 | |
453 if (ngx_strncmp(value[1].data, vp[i]->data, value[1].len) == 0) { | |
454 var = vp[i]; | |
455 goto found; | |
456 } | |
457 } | |
458 | |
459 } else { | |
460 if (ngx_array_init(&ctx->values_hash[key], cf->pool, 4, | |
461 sizeof(ngx_http_variable_value_t *)) | |
462 != NGX_OK) | |
463 { | |
464 return NGX_CONF_ERROR; | |
465 } | |
466 } | |
467 | |
593 | 468 var = ngx_palloc(ctx->keys.pool, sizeof(ngx_http_variable_value_t)); |
589 | 469 if (var == NULL) { |
470 return NGX_CONF_ERROR; | |
471 } | |
472 | |
473 var->len = value[1].len; | |
593 | 474 var->data = ngx_pstrdup(ctx->keys.pool, &value[1]); |
589 | 475 if (var->data == NULL) { |
476 return NGX_CONF_ERROR; | |
477 } | |
478 | |
479 var->valid = 1; | |
1565 | 480 var->no_cacheable = 0; |
589 | 481 var->not_found = 0; |
482 | |
483 vp = ngx_array_push(&ctx->values_hash[key]); | |
484 if (vp == NULL) { | |
485 return NGX_CONF_ERROR; | |
486 } | |
487 | |
488 *vp = var; | |
489 | |
490 found: | |
491 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
492 if (ngx_strcmp(value[0].data, "default") == 0) { |
589 | 493 |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
494 if (ctx->default_value) { |
589 | 495 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
|
496 "duplicate default map parameter"); |
589 | 497 return NGX_CONF_ERROR; |
498 } | |
499 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
500 ctx->default_value = var; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
501 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
502 return NGX_CONF_OK; |
589 | 503 } |
504 | |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
505 #if (NGX_PCRE) |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
506 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
507 if (value[0].len && value[0].data[0] == '~') { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
508 ngx_regex_compile_t rc; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
509 ngx_http_map_regex_t *regex; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
510 u_char errstr[NGX_MAX_CONF_ERRSTR]; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
511 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
512 regex = ngx_array_push(&ctx->regexes); |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
513 if (regex == NULL) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
514 return NGX_CONF_ERROR; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
515 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
516 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
517 value[0].len--; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
518 value[0].data++; |
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 ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
521 |
3930
ace14fd91086
revert r3875 since now map uses case sensetive regexes by default
Igor Sysoev <igor@sysoev.ru>
parents:
3929
diff
changeset
|
522 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
|
523 value[0].len--; |
ace14fd91086
revert r3875 since now map uses case sensetive regexes by default
Igor Sysoev <igor@sysoev.ru>
parents:
3929
diff
changeset
|
524 value[0].data++; |
ace14fd91086
revert r3875 since now map uses case sensetive regexes by default
Igor Sysoev <igor@sysoev.ru>
parents:
3929
diff
changeset
|
525 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
|
526 } |
ace14fd91086
revert r3875 since now map uses case sensetive regexes by default
Igor Sysoev <igor@sysoev.ru>
parents:
3929
diff
changeset
|
527 |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
528 rc.pattern = value[0]; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
529 rc.err.len = NGX_MAX_CONF_ERRSTR; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
530 rc.err.data = errstr; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
531 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
532 regex->regex = ngx_http_regex_compile(ctx->cf, &rc); |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
533 if (regex->regex == NULL) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
534 return NGX_CONF_ERROR; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
535 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
536 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
537 regex->value = var; |
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 return NGX_CONF_OK; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
540 } |
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 #endif |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3792
diff
changeset
|
543 |
3791
11701c4c0358
use "\" to escape "default", "include", and "hostnames" values instead of "!"
Igor Sysoev <igor@sysoev.ru>
parents:
3790
diff
changeset
|
544 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
|
545 value[0].len--; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
546 value[0].data++; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
547 } |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
548 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
549 rc = ngx_hash_add_key(&ctx->keys, &value[0], var, |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
550 (ctx->hostnames) ? NGX_HASH_WILDCARD_KEY : 0); |
589 | 551 |
591 | 552 if (rc == NGX_OK) { |
553 return NGX_CONF_OK; | |
554 } | |
589 | 555 |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
556 if (rc == NGX_DECLINED) { |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
557 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
|
558 "invalid hostname or wildcard \"%V\"", &value[0]); |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
559 } |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
560 |
591 | 561 if (rc == NGX_BUSY) { |
562 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
563 "conflicting parameter \"%V\"", &value[0]); | |
564 } | |
589 | 565 |
591 | 566 return NGX_CONF_ERROR; |
589 | 567 } |