ngx_strlow()

This commit is contained in:
Igor Sysoev 2008-08-04 10:07:00 +00:00
parent eb3e4c8be0
commit 777b019c73
9 changed files with 24 additions and 30 deletions

View File

@ -390,9 +390,7 @@ found:
elt->value = names[n].value; elt->value = names[n].value;
elt->len = (u_char) names[n].key.len; elt->len = (u_char) names[n].key.len;
for (i = 0; i < names[n].key.len; i++) { ngx_strlow(elt->name, names[n].key.data, names[n].key.len);
elt->name[i] = ngx_tolower(names[n].key.data[i]);
}
test[key] = (u_short) (test[key] + NGX_HASH_ELT_SIZE(&names[n])); test[key] = (u_short) (test[key] + NGX_HASH_ELT_SIZE(&names[n]));
} }

View File

@ -8,6 +8,17 @@
#include <ngx_core.h> #include <ngx_core.h>
void
ngx_strlow(u_char *dst, u_char *src, size_t n)
{
while (n--) {
*dst = ngx_tolower(*src);
dst++;
src++;
}
}
u_char * u_char *
ngx_cpystrn(u_char *dst, u_char *src, size_t n) ngx_cpystrn(u_char *dst, u_char *src, size_t n)
{ {

View File

@ -43,6 +43,8 @@ typedef struct {
#define ngx_tolower(c) (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c) #define ngx_tolower(c) (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c)
#define ngx_toupper(c) (u_char) ((c >= 'a' && c <= 'z') ? (c & ~0x20) : c) #define ngx_toupper(c) (u_char) ((c >= 'a' && c <= 'z') ? (c & ~0x20) : c)
void ngx_strlow(u_char *dst, u_char *src, size_t n);
#define ngx_strncmp(s1, s2, n) strncmp((const char *) s1, (const char *) s2, n) #define ngx_strncmp(s1, s2, n) strncmp((const char *) s1, (const char *) s2, n)

View File

@ -1120,9 +1120,7 @@ ngx_http_fastcgi_process_header(ngx_http_request_t *r)
ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len); ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);
} else { } else {
for (i = 0; i < h->key.len; i++) { ngx_strlow(h->lowcase_key, h->key.data, h->key.len);
h->lowcase_key[i] = ngx_tolower(h->key.data[i]);
}
} }
hh = ngx_hash_find(&umcf->headers_in_hash, h->hash, hh = ngx_hash_find(&umcf->headers_in_hash, h->hash,

View File

@ -1196,7 +1196,6 @@ static ngx_int_t
ngx_http_proxy_process_header(ngx_http_request_t *r) ngx_http_proxy_process_header(ngx_http_request_t *r)
{ {
ngx_int_t rc; ngx_int_t rc;
ngx_uint_t i;
ngx_table_elt_t *h; ngx_table_elt_t *h;
ngx_http_upstream_header_t *hh; ngx_http_upstream_header_t *hh;
ngx_http_upstream_main_conf_t *umcf; ngx_http_upstream_main_conf_t *umcf;
@ -1237,9 +1236,7 @@ ngx_http_proxy_process_header(ngx_http_request_t *r)
ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len); ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);
} else { } else {
for (i = 0; i < h->key.len; i++) { ngx_strlow(h->lowcase_key, h->key.data, h->key.len);
h->lowcase_key[i] = ngx_tolower(h->key.data[i]);
}
} }
hh = ngx_hash_find(&umcf->headers_in_hash, h->hash, hh = ngx_hash_find(&umcf->headers_in_hash, h->hash,

View File

@ -632,7 +632,6 @@ ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_str_t *value; ngx_str_t *value;
ngx_int_t n; ngx_int_t n;
ngx_uint_t i;
ngx_http_script_compile_t sc; ngx_http_script_compile_t sc;
if (slcf->match.len) { if (slcf->match.len) {
@ -641,11 +640,9 @@ ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
value = cf->args->elts; value = cf->args->elts;
slcf->match = value[1]; ngx_strlow(value[1].data, value[1].data, value[1].len);
for (i = 0; i < value[1].len; i++) { slcf->match = value[1];
value[1].data[i] = ngx_tolower(value[1].data[i]);
}
n = ngx_http_script_variables_count(&value[2]); n = ngx_http_script_variables_count(&value[2]);

View File

@ -1259,7 +1259,7 @@ static ngx_int_t
ngx_http_add_names(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, ngx_http_add_names(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
ngx_http_conf_in_addr_t *in_addr) ngx_http_conf_in_addr_t *in_addr)
{ {
ngx_uint_t i, n; ngx_uint_t i;
ngx_http_server_name_t *server_names, *name; ngx_http_server_name_t *server_names, *name;
if (in_addr->names.elts == NULL) { if (in_addr->names.elts == NULL) {
@ -1275,10 +1275,8 @@ ngx_http_add_names(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
for (i = 0; i < cscf->server_names.nelts; i++) { for (i = 0; i < cscf->server_names.nelts; i++) {
for (n = 0; n < server_names[i].name.len; n++) { ngx_strlow(server_names[i].name.data, server_names[i].name.data,
server_names[i].name.data[n] = server_names[i].name.len);
ngx_tolower(server_names[i].name.data[n]);
}
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
"name: %V", &server_names[i].name); "name: %V", &server_names[i].name);

View File

@ -818,7 +818,6 @@ ngx_http_process_request_headers(ngx_event_t *rev)
ssize_t n; ssize_t n;
ngx_int_t rc, rv; ngx_int_t rc, rv;
ngx_str_t header; ngx_str_t header;
ngx_uint_t i;
ngx_table_elt_t *h; ngx_table_elt_t *h;
ngx_connection_t *c; ngx_connection_t *c;
ngx_http_header_t *hh; ngx_http_header_t *hh;
@ -928,9 +927,7 @@ ngx_http_process_request_headers(ngx_event_t *rev)
ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len); ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len);
} else { } else {
for (i = 0; i < h->key.len; i++) { ngx_strlow(h->lowcase_key, h->key.data, h->key.len);
h->lowcase_key[i] = ngx_tolower(h->key.data[i]);
}
} }
hh = ngx_hash_find(&cmcf->headers_in_hash, h->hash, hh = ngx_hash_find(&cmcf->headers_in_hash, h->hash,

View File

@ -277,9 +277,7 @@ ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t flags)
return NULL; return NULL;
} }
for (i = 0; i < name->len; i++) { ngx_strlow(v->name.data, name->data, name->len);
v->name.data[i] = ngx_tolower(name->data[i]);
}
v->set_handler = NULL; v->set_handler = NULL;
v->get_handler = NULL; v->get_handler = NULL;
@ -344,9 +342,7 @@ ngx_http_get_variable_index(ngx_conf_t *cf, ngx_str_t *name)
return NGX_ERROR; return NGX_ERROR;
} }
for (i = 0; i < name->len; i++) { ngx_strlow(v->name.data, name->data, name->len);
v->name.data[i] = ngx_tolower(name->data[i]);
}
v->set_handler = NULL; v->set_handler = NULL;
v->get_handler = NULL; v->get_handler = NULL;