comparison src/http/ngx_http_core_module.c @ 2136:7a7c9e9024dd

ngx_hash_strlow()
author Igor Sysoev <igor@sysoev.ru>
date Mon, 04 Aug 2008 10:18:36 +0000
parents 25add486e7aa
children fb3b084e7d42
comparison
equal deleted inserted replaced
2135:8c6521eedf84 2136:7a7c9e9024dd
1303 1303
1304 1304
1305 ngx_int_t 1305 ngx_int_t
1306 ngx_http_set_content_type(ngx_http_request_t *r) 1306 ngx_http_set_content_type(ngx_http_request_t *r)
1307 { 1307 {
1308 u_char c, *p, *exten; 1308 u_char c, *exten;
1309 ngx_str_t *type; 1309 ngx_str_t *type;
1310 ngx_uint_t i, hash; 1310 ngx_uint_t i, hash;
1311 ngx_http_core_loc_conf_t *clcf; 1311 ngx_http_core_loc_conf_t *clcf;
1312 1312
1313 if (r->headers_out.content_type.len) { 1313 if (r->headers_out.content_type.len) {
1323 for (i = 0; i < r->exten.len; i++) { 1323 for (i = 0; i < r->exten.len; i++) {
1324 c = r->exten.data[i]; 1324 c = r->exten.data[i];
1325 1325
1326 if (c >= 'A' && c <= 'Z') { 1326 if (c >= 'A' && c <= 'Z') {
1327 1327
1328 p = ngx_pnalloc(r->pool, r->exten.len); 1328 exten = ngx_pnalloc(r->pool, r->exten.len);
1329 if (p == NULL) { 1329 if (exten == NULL) {
1330 return NGX_HTTP_INTERNAL_SERVER_ERROR; 1330 return NGX_HTTP_INTERNAL_SERVER_ERROR;
1331 } 1331 }
1332 1332
1333 hash = 0; 1333 hash = ngx_hash_strlow(exten, r->exten.data, r->exten.len);
1334 exten = p;
1335
1336 for (i = 0; i < r->exten.len; i++) {
1337 c = ngx_tolower(r->exten.data[i]);
1338 hash = ngx_hash(hash, c);
1339 *p++ = c;
1340 }
1341 1334
1342 r->exten.data = exten; 1335 r->exten.data = exten;
1343 1336
1344 break; 1337 break;
1345 } 1338 }
2314 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) 2307 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
2315 { 2308 {
2316 ngx_http_core_loc_conf_t *lcf = conf; 2309 ngx_http_core_loc_conf_t *lcf = conf;
2317 2310
2318 ngx_str_t *value, *content_type, *old, file; 2311 ngx_str_t *value, *content_type, *old, file;
2319 ngx_uint_t i, n; 2312 ngx_uint_t i, n, hash;
2320 ngx_hash_key_t *type; 2313 ngx_hash_key_t *type;
2321 2314
2322 value = cf->args->elts; 2315 value = cf->args->elts;
2323 2316
2324 if (ngx_strcmp(value[0].data, "include") == 0) { 2317 if (ngx_strcmp(value[0].data, "include") == 0) {
2340 2333
2341 *content_type = value[0]; 2334 *content_type = value[0];
2342 2335
2343 for (i = 1; i < cf->args->nelts; i++) { 2336 for (i = 1; i < cf->args->nelts; i++) {
2344 2337
2345 for (n = 0; n < value[i].len; n++) { 2338 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
2346 value[i].data[n] = ngx_tolower(value[i].data[n]);
2347 }
2348 2339
2349 type = lcf->types->elts; 2340 type = lcf->types->elts;
2350 for (n = 0; n < lcf->types->nelts; n++) { 2341 for (n = 0; n < lcf->types->nelts; n++) {
2351 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) { 2342 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
2352 old = type[n].value; 2343 old = type[n].value;
2366 if (type == NULL) { 2357 if (type == NULL) {
2367 return NGX_CONF_ERROR; 2358 return NGX_CONF_ERROR;
2368 } 2359 }
2369 2360
2370 type->key = value[i]; 2361 type->key = value[i];
2371 type->key_hash = ngx_hash_key(value[i].data, value[i].len); 2362 type->key_hash = hash;
2372 type->value = content_type; 2363 type->value = content_type;
2373 } 2364 }
2374 2365
2375 return NGX_CONF_OK; 2366 return NGX_CONF_OK;
2376 } 2367 }