From 6a07833d478a9b969dfa8a66041fc8537ee2b8d1 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Mon, 4 Aug 2008 10:18:36 +0000 Subject: ngx_hash_strlow() --- src/http/modules/ngx_http_map_module.c | 8 ++----- src/http/modules/ngx_http_ssi_filter_module.c | 32 +++++---------------------- src/http/modules/perl/nginx.xs | 12 ++-------- 3 files changed, 9 insertions(+), 43 deletions(-) (limited to 'src/http/modules') diff --git a/src/http/modules/ngx_http_map_module.c b/src/http/modules/ngx_http_map_module.c index cedc50879..c2459f271 100644 --- a/src/http/modules/ngx_http_map_module.c +++ b/src/http/modules/ngx_http_map_module.c @@ -106,7 +106,7 @@ ngx_http_map_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, size_t len; u_char *name; - ngx_uint_t key, i; + ngx_uint_t key; ngx_http_variable_value_t *vv, *value; ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, @@ -135,11 +135,7 @@ ngx_http_map_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, return NGX_ERROR; } - key = 0; - for (i = 0; i < len; i++) { - name[i] = ngx_tolower(vv->data[i]); - key = ngx_hash(key, name[i]); - } + key = ngx_hash_strlow(name, vv->data, len); value = ngx_hash_find_combined(&map->hash, key, name, len); diff --git a/src/http/modules/ngx_http_ssi_filter_module.c b/src/http/modules/ngx_http_ssi_filter_module.c index d8fc8f3fc..5de41f325 100644 --- a/src/http/modules/ngx_http_ssi_filter_module.c +++ b/src/http/modules/ngx_http_ssi_filter_module.c @@ -1605,7 +1605,7 @@ ngx_http_ssi_evaluate_string(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, size_t *size, len, prefix, part_len; ngx_str_t var, *val; ngx_int_t key; - ngx_uint_t i, j, n, bracket, quoted; + ngx_uint_t i, n, bracket, quoted; ngx_array_t lengths, values; ngx_http_variable_value_t *vv; @@ -1731,12 +1731,7 @@ ngx_http_ssi_evaluate_string(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, goto invalid_variable; } - key = 0; - - for (j = 0; j < var.len; j++) { - var.data[j] = ngx_tolower(var.data[j]); - key = ngx_hash(key, var.data[j]); - } + key = ngx_hash_strlow(var.data, var.data, var.len); val = ngx_http_ssi_get_variable(r, &var, key); @@ -2025,12 +2020,7 @@ ngx_http_ssi_include(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, } if (set) { - key = 0; - - for (i = 0; i < set->len; i++) { - set->data[i] = ngx_tolower(set->data[i]); - key = ngx_hash(key, set->data[i]); - } + key = ngx_hash_strlow(set->data, set->data, set->len); psr = ngx_palloc(r->pool, sizeof(ngx_http_post_subrequest_t)); if (psr == NULL) { @@ -2141,7 +2131,6 @@ ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, u_char *p; uintptr_t len; ngx_int_t key; - ngx_uint_t i; ngx_buf_t *b; ngx_str_t *var, *value, *enc, text; ngx_chain_t *cl; @@ -2152,12 +2141,7 @@ ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "ssi echo \"%V\"", var); - key = 0; - - for (i = 0; i < var->len; i++) { - var->data[i] = ngx_tolower(var->data[i]); - key = ngx_hash(key, var->data[i]); - } + key = ngx_hash_strlow(var->data, var->data, var->len); value = ngx_http_ssi_get_variable(r, var, key); @@ -2310,7 +2294,6 @@ ngx_http_ssi_set(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, ngx_str_t **params) { ngx_int_t key, rc; - ngx_uint_t i; ngx_str_t *name, *value, *vv; ngx_http_ssi_var_t *var; ngx_http_ssi_ctx_t *mctx; @@ -2337,12 +2320,7 @@ ngx_http_ssi_set(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, return rc; } - key = 0; - - for (i = 0; i < name->len; i++) { - name->data[i] = ngx_tolower(name->data[i]); - key = ngx_hash(key, name->data[i]); - } + key = ngx_hash_strlow(name->data, name->data, name->len); vv = ngx_http_ssi_get_variable(r, name, key); diff --git a/src/http/modules/perl/nginx.xs b/src/http/modules/perl/nginx.xs index 6e7ad7760..fbc7f59be 100644 --- a/src/http/modules/perl/nginx.xs +++ b/src/http/modules/perl/nginx.xs @@ -247,11 +247,7 @@ header_in(r, key) XSRETURN_UNDEF; } - hash = 0; - for (i = 0; i < len; i++) { - lowcase_key[i] = ngx_tolower(p[i]); - hash = ngx_hash(hash, lowcase_key[i]); - } + hash = ngx_hash_strlow(lowcase_key, p, len); cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); @@ -833,11 +829,7 @@ variable(r, name, value = NULL) XSRETURN_UNDEF; } - hash = 0; - for (i = 0; i < len; i++) { - lowcase[i] = ngx_tolower(p[i]); - hash = ngx_hash(hash, lowcase[i]); - } + hash = ngx_hash_strlow(lowcase, p, len); var.len = len; var.data = lowcase; -- cgit