Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_map_module.c @ 1822:935427c55e04
test URI/Destination collection/non-collection and Depth
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 03 Jan 2008 20:09:51 +0000 |
parents | 4c43e25d11ea |
children | 2a92804f4109 |
rev | line source |
---|---|
589 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_http.h> | |
10 | |
11 | |
12 typedef struct { | |
13 ngx_uint_t hash_max_size; | |
14 ngx_uint_t hash_bucket_size; | |
15 } ngx_http_map_conf_t; | |
16 | |
17 | |
18 typedef struct { | |
593 | 19 ngx_hash_keys_arrays_t keys; |
589 | 20 |
21 ngx_array_t *values_hash; | |
22 | |
23 ngx_http_variable_value_t *default_value; | |
24 ngx_uint_t hostnames; /* unsigned hostnames:1 */ | |
25 } ngx_http_map_conf_ctx_t; | |
26 | |
27 | |
28 typedef struct { | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
29 ngx_hash_combined_t hash; |
589 | 30 ngx_int_t index; |
31 ngx_http_variable_value_t *default_value; | |
32 ngx_uint_t hostnames; /* unsigned hostnames:1 */ | |
33 } ngx_http_map_ctx_t; | |
34 | |
35 | |
36 static int ngx_libc_cdecl ngx_http_map_cmp_dns_wildcards(const void *one, | |
37 const void *two); | |
38 static void *ngx_http_map_create_conf(ngx_conf_t *cf); | |
39 static char *ngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | |
40 static char *ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf); | |
41 | |
42 | |
43 static ngx_command_t ngx_http_map_commands[] = { | |
44 | |
45 { ngx_string("map"), | |
46 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE2, | |
47 ngx_http_map_block, | |
48 NGX_HTTP_MAIN_CONF_OFFSET, | |
49 0, | |
50 NULL }, | |
51 | |
52 { ngx_string("map_hash_max_size"), | |
53 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, | |
54 ngx_conf_set_num_slot, | |
55 NGX_HTTP_MAIN_CONF_OFFSET, | |
56 offsetof(ngx_http_map_conf_t, hash_max_size), | |
57 NULL }, | |
58 | |
59 { ngx_string("map_hash_bucket_size"), | |
60 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, | |
61 ngx_conf_set_num_slot, | |
62 NGX_HTTP_MAIN_CONF_OFFSET, | |
63 offsetof(ngx_http_map_conf_t, hash_bucket_size), | |
64 NULL }, | |
65 | |
66 ngx_null_command | |
67 }; | |
68 | |
69 | |
70 static ngx_http_module_t ngx_http_map_module_ctx = { | |
71 NULL, /* preconfiguration */ | |
72 NULL, /* postconfiguration */ | |
73 | |
74 ngx_http_map_create_conf, /* create main configuration */ | |
75 NULL, /* init main configuration */ | |
76 | |
77 NULL, /* create server configuration */ | |
78 NULL, /* merge server configuration */ | |
79 | |
80 NULL, /* create location configuration */ | |
81 NULL /* merge location configuration */ | |
82 }; | |
83 | |
84 | |
85 ngx_module_t ngx_http_map_module = { | |
86 NGX_MODULE_V1, | |
87 &ngx_http_map_module_ctx, /* module context */ | |
88 ngx_http_map_commands, /* module directives */ | |
89 NGX_HTTP_MODULE, /* module type */ | |
90 NULL, /* init master */ | |
91 NULL, /* init module */ | |
92 NULL, /* init process */ | |
93 NULL, /* init thread */ | |
94 NULL, /* exit thread */ | |
95 NULL, /* exit process */ | |
96 NULL, /* exit master */ | |
97 NGX_MODULE_V1_PADDING | |
98 }; | |
99 | |
100 | |
101 static ngx_int_t | |
102 ngx_http_map_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
103 uintptr_t data) | |
104 { | |
105 ngx_http_map_ctx_t *map = (ngx_http_map_ctx_t *) data; | |
106 | |
107 size_t len; | |
108 u_char *name; | |
109 ngx_uint_t key, i; | |
110 ngx_http_variable_value_t *vv, *value; | |
111 | |
112 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
113 "http map started"); | |
114 | |
115 vv = ngx_http_get_flushed_variable(r, map->index); | |
116 | |
797
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
637
diff
changeset
|
117 if (vv == NULL || vv->not_found) { |
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
637
diff
changeset
|
118 *v = *map->default_value; |
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
637
diff
changeset
|
119 return NGX_OK; |
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
637
diff
changeset
|
120 } |
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
637
diff
changeset
|
121 |
589 | 122 len = vv->len; |
123 | |
124 if (len && map->hostnames && vv->data[len - 1] == '.') { | |
125 len--; | |
126 } | |
127 | |
128 if (len == 0) { | |
129 *v = *map->default_value; | |
130 return NGX_OK; | |
131 } | |
132 | |
133 name = ngx_palloc(r->pool, len); | |
134 if (name == NULL) { | |
135 return NGX_ERROR; | |
136 } | |
137 | |
138 key = 0; | |
139 for (i = 0; i < len; i++) { | |
140 name[i] = ngx_tolower(vv->data[i]); | |
141 key = ngx_hash(key, name[i]); | |
142 } | |
143 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
144 value = ngx_hash_find_combined(&map->hash, key, name, len); |
589 | 145 |
146 if (value) { | |
147 *v = *value; | |
148 | |
149 } else { | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
150 *v = *map->default_value; |
589 | 151 } |
152 | |
153 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1406
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1352
diff
changeset
|
154 "http map: \"%v\" \"%v\"", vv, v); |
589 | 155 |
156 return NGX_OK; | |
157 } | |
158 | |
159 | |
160 static void * | |
161 ngx_http_map_create_conf(ngx_conf_t *cf) | |
162 { | |
163 ngx_http_map_conf_t *mcf; | |
164 | |
165 mcf = ngx_palloc(cf->pool, sizeof(ngx_http_map_conf_t)); | |
166 if (mcf == NULL) { | |
167 return NGX_CONF_ERROR; | |
168 } | |
169 | |
170 mcf->hash_max_size = NGX_CONF_UNSET_UINT; | |
171 mcf->hash_bucket_size = NGX_CONF_UNSET_UINT; | |
172 | |
173 return mcf; | |
174 } | |
175 | |
176 | |
177 static char * | |
178 ngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
179 { | |
180 ngx_http_map_conf_t *mcf = conf; | |
181 | |
182 char *rv; | |
183 ngx_str_t *value, name; | |
184 ngx_conf_t save; | |
185 ngx_pool_t *pool; | |
186 ngx_hash_init_t hash; | |
187 ngx_http_map_ctx_t *map; | |
188 ngx_http_variable_t *var; | |
189 ngx_http_map_conf_ctx_t ctx; | |
190 | |
191 if (mcf->hash_max_size == NGX_CONF_UNSET_UINT) { | |
192 mcf->hash_max_size = 2048; | |
193 } | |
194 | |
195 if (mcf->hash_bucket_size == NGX_CONF_UNSET_UINT) { | |
196 mcf->hash_bucket_size = ngx_cacheline_size; | |
197 | |
198 } else { | |
199 mcf->hash_bucket_size = ngx_align(mcf->hash_bucket_size, | |
200 ngx_cacheline_size); | |
201 } | |
202 | |
203 map = ngx_pcalloc(cf->pool, sizeof(ngx_http_map_ctx_t)); | |
204 if (map == NULL) { | |
205 return NGX_CONF_ERROR; | |
206 } | |
207 | |
208 value = cf->args->elts; | |
209 | |
210 name = value[1]; | |
211 name.len--; | |
212 name.data++; | |
213 | |
214 map->index = ngx_http_get_variable_index(cf, &name); | |
215 | |
216 if (map->index == NGX_ERROR) { | |
217 return NGX_CONF_ERROR; | |
218 } | |
219 | |
220 name = value[2]; | |
221 name.len--; | |
222 name.data++; | |
223 | |
1565 | 224 var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE); |
589 | 225 if (var == NULL) { |
226 return NGX_CONF_ERROR; | |
227 } | |
228 | |
637 | 229 var->get_handler = ngx_http_map_variable; |
589 | 230 var->data = (uintptr_t) map; |
231 | |
232 pool = ngx_create_pool(16384, cf->log); | |
233 if (pool == NULL) { | |
234 return NGX_CONF_ERROR; | |
235 } | |
236 | |
593 | 237 ctx.keys.pool = cf->pool; |
238 ctx.keys.temp_pool = pool; | |
589 | 239 |
593 | 240 if (ngx_hash_keys_array_init(&ctx.keys, NGX_HASH_LARGE) != NGX_OK) { |
589 | 241 ngx_destroy_pool(pool); |
242 return NGX_CONF_ERROR; | |
243 } | |
244 | |
593 | 245 ctx.values_hash = ngx_pcalloc(pool, sizeof(ngx_array_t) * ctx.keys.hsize); |
589 | 246 if (ctx.values_hash == NULL) { |
247 ngx_destroy_pool(pool); | |
248 return NGX_CONF_ERROR; | |
249 } | |
250 | |
251 ctx.default_value = NULL; | |
252 ctx.hostnames = 0; | |
253 | |
254 save = *cf; | |
255 cf->pool = pool; | |
256 cf->ctx = &ctx; | |
257 cf->handler = ngx_http_map; | |
258 cf->handler_conf = conf; | |
259 | |
260 rv = ngx_conf_parse(cf, NULL); | |
261 | |
262 *cf = save; | |
263 | |
264 if (rv != NGX_CONF_OK) { | |
265 ngx_destroy_pool(pool); | |
266 return rv; | |
267 } | |
268 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
269 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
|
270 &ngx_http_variable_null_value; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
271 |
589 | 272 hash.key = ngx_hash_key_lc; |
273 hash.max_size = mcf->hash_max_size; | |
274 hash.bucket_size = mcf->hash_bucket_size; | |
275 hash.name = "map_hash"; | |
276 hash.pool = cf->pool; | |
277 | |
593 | 278 if (ctx.keys.keys.nelts) { |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
279 hash.hash = &map->hash.hash; |
589 | 280 hash.temp_pool = NULL; |
281 | |
593 | 282 if (ngx_hash_init(&hash, ctx.keys.keys.elts, ctx.keys.keys.nelts) |
591 | 283 != NGX_OK) |
284 { | |
593 | 285 ngx_destroy_pool(pool); |
589 | 286 return NGX_CONF_ERROR; |
287 } | |
288 } | |
289 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
290 if (ctx.keys.dns_wc_head.nelts) { |
589 | 291 |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
292 ngx_qsort(ctx.keys.dns_wc_head.elts, |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
293 (size_t) ctx.keys.dns_wc_head.nelts, |
589 | 294 sizeof(ngx_hash_key_t), ngx_http_map_cmp_dns_wildcards); |
295 | |
296 hash.hash = NULL; | |
297 hash.temp_pool = pool; | |
298 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
299 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
|
300 ctx.keys.dns_wc_head.nelts) |
589 | 301 != NGX_OK) |
302 { | |
593 | 303 ngx_destroy_pool(pool); |
589 | 304 return NGX_CONF_ERROR; |
305 } | |
306 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
307 map->hash.wc_head = (ngx_hash_wildcard_t *) hash.hash; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
308 } |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
309 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
310 if (ctx.keys.dns_wc_tail.nelts) { |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
311 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
312 ngx_qsort(ctx.keys.dns_wc_tail.elts, |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
313 (size_t) ctx.keys.dns_wc_tail.nelts, |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
314 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
|
315 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
316 hash.hash = NULL; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
317 hash.temp_pool = pool; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
318 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
319 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
|
320 ctx.keys.dns_wc_tail.nelts) |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
321 != NGX_OK) |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
322 { |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
323 ngx_destroy_pool(pool); |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
324 return NGX_CONF_ERROR; |
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 map->hash.wc_tail = (ngx_hash_wildcard_t *) hash.hash; |
589 | 328 } |
329 | |
330 ngx_destroy_pool(pool); | |
331 | |
332 return rv; | |
333 } | |
334 | |
335 | |
336 static int ngx_libc_cdecl | |
337 ngx_http_map_cmp_dns_wildcards(const void *one, const void *two) | |
338 { | |
339 ngx_hash_key_t *first, *second; | |
340 | |
341 first = (ngx_hash_key_t *) one; | |
342 second = (ngx_hash_key_t *) two; | |
343 | |
344 return ngx_strcmp(first->key.data, second->key.data); | |
345 } | |
346 | |
347 | |
348 static char * | |
349 ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) | |
350 { | |
591 | 351 ngx_int_t rc; |
352 ngx_str_t *value, file; | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
353 ngx_uint_t i, key; |
589 | 354 ngx_http_map_conf_ctx_t *ctx; |
591 | 355 ngx_http_variable_value_t *var, **vp; |
589 | 356 |
357 ctx = cf->ctx; | |
358 | |
359 value = cf->args->elts; | |
360 | |
361 if (cf->args->nelts == 1 | |
362 && ngx_strcmp(value[0].data, "hostnames") == 0) | |
363 { | |
364 ctx->hostnames = 1; | |
365 return NGX_CONF_OK; | |
366 | |
367 } else if (cf->args->nelts != 2) { | |
368 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
369 "invalid number of the map parameters"); | |
370 return NGX_CONF_ERROR; | |
371 | |
372 } else if (value[0].len == 0) { | |
373 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
374 "invalid first parameter"); | |
375 return NGX_CONF_ERROR; | |
376 } | |
377 | |
378 if (ngx_strcmp(value[0].data, "include") == 0) { | |
379 file = value[1]; | |
380 | |
1352 | 381 if (ngx_conf_full_name(cf->cycle, &file, 1) == NGX_ERROR){ |
589 | 382 return NGX_CONF_ERROR; |
383 } | |
384 | |
385 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data); | |
386 | |
387 return ngx_conf_parse(cf, &file); | |
388 } | |
389 | |
390 key = 0; | |
391 | |
392 for (i = 0; i < value[1].len; i++) { | |
393 key = ngx_hash(key, value[1].data[i]); | |
394 } | |
395 | |
593 | 396 key %= ctx->keys.hsize; |
589 | 397 |
398 vp = ctx->values_hash[key].elts; | |
399 | |
400 if (vp) { | |
401 for (i = 0; i < ctx->values_hash[key].nelts; i++) { | |
402 if (value[1].len != (size_t) vp[i]->len) { | |
403 continue; | |
404 } | |
405 | |
406 if (ngx_strncmp(value[1].data, vp[i]->data, value[1].len) == 0) { | |
407 var = vp[i]; | |
408 goto found; | |
409 } | |
410 } | |
411 | |
412 } else { | |
413 if (ngx_array_init(&ctx->values_hash[key], cf->pool, 4, | |
414 sizeof(ngx_http_variable_value_t *)) | |
415 != NGX_OK) | |
416 { | |
417 return NGX_CONF_ERROR; | |
418 } | |
419 } | |
420 | |
593 | 421 var = ngx_palloc(ctx->keys.pool, sizeof(ngx_http_variable_value_t)); |
589 | 422 if (var == NULL) { |
423 return NGX_CONF_ERROR; | |
424 } | |
425 | |
426 var->len = value[1].len; | |
593 | 427 var->data = ngx_pstrdup(ctx->keys.pool, &value[1]); |
589 | 428 if (var->data == NULL) { |
429 return NGX_CONF_ERROR; | |
430 } | |
431 | |
432 var->valid = 1; | |
1565 | 433 var->no_cacheable = 0; |
589 | 434 var->not_found = 0; |
435 | |
436 vp = ngx_array_push(&ctx->values_hash[key]); | |
437 if (vp == NULL) { | |
438 return NGX_CONF_ERROR; | |
439 } | |
440 | |
441 *vp = var; | |
442 | |
443 found: | |
444 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
445 if (ngx_strcmp(value[0].data, "default") == 0) { |
589 | 446 |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
447 if (ctx->default_value) { |
589 | 448 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
|
449 "duplicate default map parameter"); |
589 | 450 return NGX_CONF_ERROR; |
451 } | |
452 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
453 ctx->default_value = var; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
454 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
455 return NGX_CONF_OK; |
589 | 456 } |
457 | |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
458 if (value[0].len && value[0].data[0] == '!') { |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
459 value[0].len--; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
460 value[0].data++; |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
461 } |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
462 |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
463 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
|
464 (ctx->hostnames) ? NGX_HASH_WILDCARD_KEY : 0); |
589 | 465 |
591 | 466 if (rc == NGX_OK) { |
467 return NGX_CONF_OK; | |
468 } | |
589 | 469 |
1253
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
470 if (rc == NGX_DECLINED) { |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
471 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
|
472 "invalid hostname or wildcard \"%V\"", &value[0]); |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
473 } |
8ef04207c84f
the "www.example.*" wildcard hash support
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
474 |
591 | 475 if (rc == NGX_BUSY) { |
476 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
477 "conflicting parameter \"%V\"", &value[0]); | |
478 } | |
589 | 479 |
591 | 480 return NGX_CONF_ERROR; |
589 | 481 } |