mirror of
https://github.com/nginx/nginx.git
synced 2025-08-06 14:56:15 +08:00
ngx_hash_strlow()
This commit is contained in:
parent
777b019c73
commit
6a07833d47
@ -620,6 +620,24 @@ ngx_hash_key_lc(u_char *data, size_t len)
|
||||
}
|
||||
|
||||
|
||||
ngx_uint_t
|
||||
ngx_hash_strlow(u_char *dst, u_char *src, size_t n)
|
||||
{
|
||||
ngx_uint_t key;
|
||||
|
||||
key = 0;
|
||||
|
||||
while (n--) {
|
||||
*dst = ngx_tolower(*src);
|
||||
key = ngx_hash(key, *dst);
|
||||
dst++;
|
||||
src++;
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ngx_hash_keys_array_init(ngx_hash_keys_arrays_t *ha, ngx_uint_t type)
|
||||
{
|
||||
@ -794,12 +812,7 @@ wildcard:
|
||||
|
||||
/* wildcard hash */
|
||||
|
||||
k = 0;
|
||||
|
||||
for (i = skip; i < last; i++) {
|
||||
key->data[i] = ngx_tolower(key->data[i]);
|
||||
k = ngx_hash(k, key->data[i]);
|
||||
}
|
||||
k = ngx_hash_strlow(&key->data[skip], &key->data[skip], last - skip);
|
||||
|
||||
k %= ha->hsize;
|
||||
|
||||
|
@ -110,6 +110,8 @@ ngx_int_t ngx_hash_wildcard_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names,
|
||||
#define ngx_hash(key, c) ((ngx_uint_t) key * 31 + c)
|
||||
ngx_uint_t ngx_hash_key(u_char *data, size_t len);
|
||||
ngx_uint_t ngx_hash_key_lc(u_char *data, size_t len);
|
||||
ngx_uint_t ngx_hash_strlow(u_char *dst, u_char *src, size_t n);
|
||||
|
||||
|
||||
ngx_int_t ngx_hash_keys_array_init(ngx_hash_keys_arrays_t *ha, ngx_uint_t type);
|
||||
ngx_int_t ngx_hash_add_key(ngx_hash_keys_arrays_t *ha, ngx_str_t *key,
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -1305,7 +1305,7 @@ ngx_http_core_send_continue(ngx_http_request_t *r)
|
||||
ngx_int_t
|
||||
ngx_http_set_content_type(ngx_http_request_t *r)
|
||||
{
|
||||
u_char c, *p, *exten;
|
||||
u_char c, *exten;
|
||||
ngx_str_t *type;
|
||||
ngx_uint_t i, hash;
|
||||
ngx_http_core_loc_conf_t *clcf;
|
||||
@ -1325,19 +1325,12 @@ ngx_http_set_content_type(ngx_http_request_t *r)
|
||||
|
||||
if (c >= 'A' && c <= 'Z') {
|
||||
|
||||
p = ngx_pnalloc(r->pool, r->exten.len);
|
||||
if (p == NULL) {
|
||||
exten = ngx_pnalloc(r->pool, r->exten.len);
|
||||
if (exten == NULL) {
|
||||
return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
|
||||
hash = 0;
|
||||
exten = p;
|
||||
|
||||
for (i = 0; i < r->exten.len; i++) {
|
||||
c = ngx_tolower(r->exten.data[i]);
|
||||
hash = ngx_hash(hash, c);
|
||||
*p++ = c;
|
||||
}
|
||||
hash = ngx_hash_strlow(exten, r->exten.data, r->exten.len);
|
||||
|
||||
r->exten.data = exten;
|
||||
|
||||
@ -2316,7 +2309,7 @@ ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
||||
ngx_http_core_loc_conf_t *lcf = conf;
|
||||
|
||||
ngx_str_t *value, *content_type, *old, file;
|
||||
ngx_uint_t i, n;
|
||||
ngx_uint_t i, n, hash;
|
||||
ngx_hash_key_t *type;
|
||||
|
||||
value = cf->args->elts;
|
||||
@ -2342,9 +2335,7 @@ ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
||||
|
||||
for (i = 1; i < cf->args->nelts; i++) {
|
||||
|
||||
for (n = 0; n < value[i].len; n++) {
|
||||
value[i].data[n] = ngx_tolower(value[i].data[n]);
|
||||
}
|
||||
hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
|
||||
|
||||
type = lcf->types->elts;
|
||||
for (n = 0; n < lcf->types->nelts; n++) {
|
||||
@ -2368,7 +2359,7 @@ ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
||||
}
|
||||
|
||||
type->key = value[i];
|
||||
type->key_hash = ngx_hash_key(value[i].data, value[i].len);
|
||||
type->key_hash = hash;
|
||||
type->value = content_type;
|
||||
}
|
||||
|
||||
|
@ -1549,8 +1549,8 @@ ngx_http_validate_host(u_char *host, size_t len)
|
||||
static ngx_int_t
|
||||
ngx_http_find_virtual_server(ngx_http_request_t *r, u_char *host, size_t len)
|
||||
{
|
||||
u_char *server, ch;
|
||||
ngx_uint_t i, hash;
|
||||
u_char *server;
|
||||
ngx_uint_t hash;
|
||||
ngx_http_core_loc_conf_t *clcf;
|
||||
ngx_http_core_srv_conf_t *cscf;
|
||||
u_char buf[32];
|
||||
@ -1569,16 +1569,7 @@ ngx_http_find_virtual_server(ngx_http_request_t *r, u_char *host, size_t len)
|
||||
}
|
||||
}
|
||||
|
||||
hash = 0;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
ch = host[i];
|
||||
|
||||
ch = ngx_tolower(ch);
|
||||
server[i] = ch;
|
||||
|
||||
hash = ngx_hash(hash, ch);
|
||||
}
|
||||
hash = ngx_hash_strlow(server, host, len);
|
||||
|
||||
cscf = ngx_hash_find_combined(&r->virtual_names->names, hash, server, len);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user