Mercurial > hg > nginx-vendor-0-8
comparison src/http/modules/ngx_http_map_module.c @ 142:84910468f6de NGINX_0_3_18
nginx 0.3.18
*) Feature: the "server_names" directive supports the ".domain.tld"
names.
*) Feature: the "server_names" directive uses the hash for the
"*.domain.tld" names and more effective hash for usual names.
*) Change: the "server_names_hash_max_size" and
"server_names_hash_bucket_size" directives.
*) Change: the "server_names_hash" and "server_names_hash_threshold"
directives were canceled.
*) Feature: the "valid_referers" directive uses the hash site names.
*) Change: now the "valid_referers" directive checks the site names
only without the URI part.
*) Bugfix: some ".domain.tld" names incorrectly processed by the
ngx_http_map_module.
*) Bugfix: segmentation fault was occurred if configuration file did
not exist; bug appeared in 0.3.12.
*) Bugfix: on 64-bit platforms segmentation fault may occurred on
start; bug appeared in 0.3.16.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 26 Dec 2005 00:00:00 +0300 |
parents | 55a211e5eeb7 |
children | 54aabf2b0bc6 |
comparison
equal
deleted
inserted
replaced
141:249e67502bf3 | 142:84910468f6de |
---|---|
14 ngx_uint_t hash_bucket_size; | 14 ngx_uint_t hash_bucket_size; |
15 } ngx_http_map_conf_t; | 15 } ngx_http_map_conf_t; |
16 | 16 |
17 | 17 |
18 typedef struct { | 18 typedef struct { |
19 ngx_http_hash_conf_t hash; | 19 ngx_hash_keys_arrays_t keys; |
20 | 20 |
21 ngx_array_t *values_hash; | 21 ngx_array_t *values_hash; |
22 | 22 |
23 ngx_http_variable_value_t *default_value; | 23 ngx_http_variable_value_t *default_value; |
24 ngx_uint_t hostnames; /* unsigned hostnames:1 */ | 24 ngx_uint_t hostnames; /* unsigned hostnames:1 */ |
243 pool = ngx_create_pool(16384, cf->log); | 243 pool = ngx_create_pool(16384, cf->log); |
244 if (pool == NULL) { | 244 if (pool == NULL) { |
245 return NGX_CONF_ERROR; | 245 return NGX_CONF_ERROR; |
246 } | 246 } |
247 | 247 |
248 if (ngx_array_init(&ctx.hash.keys, pool, 16384, sizeof(ngx_hash_key_t)) | 248 ctx.keys.pool = cf->pool; |
249 != NGX_OK) | 249 ctx.keys.temp_pool = pool; |
250 { | 250 |
251 if (ngx_hash_keys_array_init(&ctx.keys, NGX_HASH_LARGE) != NGX_OK) { | |
251 ngx_destroy_pool(pool); | 252 ngx_destroy_pool(pool); |
252 return NGX_CONF_ERROR; | 253 return NGX_CONF_ERROR; |
253 } | 254 } |
254 | 255 |
255 if (ngx_array_init(&ctx.hash.dns_wildcards, pool, 16384, | 256 ctx.values_hash = ngx_pcalloc(pool, sizeof(ngx_array_t) * ctx.keys.hsize); |
256 sizeof(ngx_hash_key_t)) | |
257 != NGX_OK) | |
258 { | |
259 ngx_destroy_pool(pool); | |
260 return NGX_CONF_ERROR; | |
261 } | |
262 | |
263 ctx.hash.keys_hash = ngx_pcalloc(pool, | |
264 sizeof(ngx_array_t) * NGX_HTTP_CONFIG_HASH); | |
265 if (ctx.hash.keys_hash == NULL) { | |
266 ngx_destroy_pool(pool); | |
267 return NGX_CONF_ERROR; | |
268 } | |
269 | |
270 ctx.hash.dns_hash = ngx_pcalloc(pool, | |
271 sizeof(ngx_array_t) * NGX_HTTP_CONFIG_HASH); | |
272 if (ctx.hash.dns_hash == NULL) { | |
273 ngx_destroy_pool(pool); | |
274 return NGX_CONF_ERROR; | |
275 } | |
276 | |
277 ctx.values_hash = ngx_pcalloc(pool, | |
278 sizeof(ngx_array_t) * NGX_HTTP_CONFIG_HASH); | |
279 if (ctx.values_hash == NULL) { | 257 if (ctx.values_hash == NULL) { |
280 ngx_destroy_pool(pool); | 258 ngx_destroy_pool(pool); |
281 return NGX_CONF_ERROR; | 259 return NGX_CONF_ERROR; |
282 } | 260 } |
283 | 261 |
284 ctx.hash.pool = cf->pool; | |
285 ctx.hash.temp_pool = pool; | |
286 ctx.default_value = NULL; | 262 ctx.default_value = NULL; |
287 ctx.hostnames = 0; | 263 ctx.hostnames = 0; |
288 | 264 |
289 save = *cf; | 265 save = *cf; |
290 cf->pool = pool; | 266 cf->pool = pool; |
296 | 272 |
297 *cf = save; | 273 *cf = save; |
298 | 274 |
299 if (rv != NGX_CONF_OK) { | 275 if (rv != NGX_CONF_OK) { |
300 ngx_destroy_pool(pool); | 276 ngx_destroy_pool(pool); |
301 | |
302 return rv; | 277 return rv; |
303 } | 278 } |
304 | 279 |
305 hash.key = ngx_hash_key_lc; | 280 hash.key = ngx_hash_key_lc; |
306 hash.max_size = mcf->hash_max_size; | 281 hash.max_size = mcf->hash_max_size; |
307 hash.bucket_size = mcf->hash_bucket_size; | 282 hash.bucket_size = mcf->hash_bucket_size; |
308 hash.name = "map_hash"; | 283 hash.name = "map_hash"; |
309 hash.pool = cf->pool; | 284 hash.pool = cf->pool; |
310 | 285 |
311 if (ctx.hash.keys.nelts) { | 286 if (ctx.keys.keys.nelts) { |
312 hash.hash = &map->hash; | 287 hash.hash = &map->hash; |
313 hash.temp_pool = NULL; | 288 hash.temp_pool = NULL; |
314 | 289 |
315 if (ngx_hash_init(&hash, ctx.hash.keys.elts, ctx.hash.keys.nelts) | 290 if (ngx_hash_init(&hash, ctx.keys.keys.elts, ctx.keys.keys.nelts) |
316 != NGX_OK) | 291 != NGX_OK) |
317 { | 292 { |
293 ngx_destroy_pool(pool); | |
318 return NGX_CONF_ERROR; | 294 return NGX_CONF_ERROR; |
319 } | 295 } |
320 } | 296 } |
321 | 297 |
322 map->default_value = ctx.default_value ? ctx.default_value: | 298 map->default_value = ctx.default_value ? ctx.default_value: |
323 &ngx_http_variable_null_value; | 299 &ngx_http_variable_null_value; |
324 | 300 |
325 if (ctx.hash.dns_wildcards.nelts) { | 301 if (ctx.keys.dns_wildcards.nelts) { |
326 | 302 |
327 ngx_qsort(ctx.hash.dns_wildcards.elts, | 303 ngx_qsort(ctx.keys.dns_wildcards.elts, |
328 (size_t) ctx.hash.dns_wildcards.nelts, | 304 (size_t) ctx.keys.dns_wildcards.nelts, |
329 sizeof(ngx_hash_key_t), ngx_http_map_cmp_dns_wildcards); | 305 sizeof(ngx_hash_key_t), ngx_http_map_cmp_dns_wildcards); |
330 | 306 |
331 hash.hash = NULL; | 307 hash.hash = NULL; |
332 hash.temp_pool = pool; | 308 hash.temp_pool = pool; |
333 | 309 |
334 if (ngx_hash_wildcard_init(&hash, ctx.hash.dns_wildcards.elts, | 310 if (ngx_hash_wildcard_init(&hash, ctx.keys.dns_wildcards.elts, |
335 ctx.hash.dns_wildcards.nelts) | 311 ctx.keys.dns_wildcards.nelts) |
336 != NGX_OK) | 312 != NGX_OK) |
337 { | 313 { |
314 ngx_destroy_pool(pool); | |
338 return NGX_CONF_ERROR; | 315 return NGX_CONF_ERROR; |
339 } | 316 } |
340 | 317 |
341 map->dns_wildcards = (ngx_hash_wildcard_t *) hash.hash; | 318 map->dns_wildcards = (ngx_hash_wildcard_t *) hash.hash; |
342 } | 319 } |
406 | 383 |
407 for (i = 0; i < value[1].len; i++) { | 384 for (i = 0; i < value[1].len; i++) { |
408 key = ngx_hash(key, value[1].data[i]); | 385 key = ngx_hash(key, value[1].data[i]); |
409 } | 386 } |
410 | 387 |
411 key %= NGX_HTTP_CONFIG_HASH; | 388 key %= ctx->keys.hsize; |
412 | 389 |
413 vp = ctx->values_hash[key].elts; | 390 vp = ctx->values_hash[key].elts; |
414 | 391 |
415 if (vp) { | 392 if (vp) { |
416 for (i = 0; i < ctx->values_hash[key].nelts; i++) { | 393 for (i = 0; i < ctx->values_hash[key].nelts; i++) { |
431 { | 408 { |
432 return NGX_CONF_ERROR; | 409 return NGX_CONF_ERROR; |
433 } | 410 } |
434 } | 411 } |
435 | 412 |
436 var = ngx_palloc(ctx->hash.pool, sizeof(ngx_http_variable_value_t)); | 413 var = ngx_palloc(ctx->keys.pool, sizeof(ngx_http_variable_value_t)); |
437 if (var == NULL) { | 414 if (var == NULL) { |
438 return NGX_CONF_ERROR; | 415 return NGX_CONF_ERROR; |
439 } | 416 } |
440 | 417 |
441 var->len = value[1].len; | 418 var->len = value[1].len; |
442 var->data = ngx_pstrdup(ctx->hash.pool, &value[1]); | 419 var->data = ngx_pstrdup(ctx->keys.pool, &value[1]); |
443 if (var->data == NULL) { | 420 if (var->data == NULL) { |
444 return NGX_CONF_ERROR; | 421 return NGX_CONF_ERROR; |
445 } | 422 } |
446 | 423 |
447 var->valid = 1; | 424 var->valid = 1; |
490 "invalid DNS wildcard \"%V\"", &value[0]); | 467 "invalid DNS wildcard \"%V\"", &value[0]); |
491 | 468 |
492 return NGX_CONF_ERROR; | 469 return NGX_CONF_ERROR; |
493 } | 470 } |
494 | 471 |
495 flags = NGX_HTTP_WILDCARD_HASH; | 472 flags = NGX_HASH_WILDCARD_KEY; |
496 } | 473 } |
497 | 474 |
498 rc = ngx_http_config_add_hash(&ctx->hash, &value[0], var, flags); | 475 rc = ngx_hash_add_key(&ctx->keys, &value[0], var, flags); |
499 | 476 |
500 if (rc == NGX_OK) { | 477 if (rc == NGX_OK) { |
501 return NGX_CONF_OK; | 478 return NGX_CONF_OK; |
502 } | 479 } |
503 | 480 |