comparison src/http/ngx_http_core_module.c @ 180:4cd3e70c4d60 NGINX_0_3_37

nginx 0.3.37 *) Feature: the "limit_except" directive. *) Feature: the "if" directive supports the "!~", "!~*", "-f", and "!-f" operators. *) Feature: the ngx_http_perl_module supports the $r->request_body method. *) Bugfix: in the ngx_http_addition_filter_module.
author Igor Sysoev <http://sysoev.ru>
date Fri, 07 Apr 2006 00:00:00 +0400
parents 3080c5392b89
children 13710a1813ad
comparison
equal deleted inserted replaced
179:654cbdc0401d 180:4cd3e70c4d60
7 #include <ngx_config.h> 7 #include <ngx_config.h>
8 #include <ngx_core.h> 8 #include <ngx_core.h>
9 #include <ngx_event.h> 9 #include <ngx_event.h>
10 #include <ngx_http.h> 10 #include <ngx_http.h>
11 #include <nginx.h> 11 #include <nginx.h>
12
13
14 typedef struct {
15 char *name;
16 uint32_t method;
17 } ngx_http_method_name_t;
12 18
13 19
14 #define NGX_HTTP_LOCATION_EXACT 1 20 #define NGX_HTTP_LOCATION_EXACT 1
15 #define NGX_HTTP_LOCATION_AUTO_REDIRECT 2 21 #define NGX_HTTP_LOCATION_AUTO_REDIRECT 2
16 #define NGX_HTTP_LOCATION_NOREGEX 3 22 #define NGX_HTTP_LOCATION_NOREGEX 3
46 static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, 52 static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
47 void *conf); 53 void *conf);
48 static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, 54 static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd,
49 void *conf); 55 void *conf);
50 static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 56 static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
57 static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd,
58 void *conf);
51 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, 59 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
52 void *conf); 60 void *conf);
53 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, 61 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
54 void *conf); 62 void *conf);
55 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, 63 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
219 NULL }, 227 NULL },
220 228
221 { ngx_string("alias"), 229 { ngx_string("alias"),
222 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 230 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
223 ngx_http_core_root, 231 ngx_http_core_root,
232 NGX_HTTP_LOC_CONF_OFFSET,
233 0,
234 NULL },
235
236 { ngx_string("limit_except"),
237 NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_1MORE,
238 ngx_http_core_limit_except,
224 NGX_HTTP_LOC_CONF_OFFSET, 239 NGX_HTTP_LOC_CONF_OFFSET,
225 0, 240 0,
226 NULL }, 241 NULL },
227 242
228 { ngx_string("client_max_body_size"), 243 { ngx_string("client_max_body_size"),
709 { 724 {
710 ngx_http_core_loc_conf_t *clcf; 725 ngx_http_core_loc_conf_t *clcf;
711 726
712 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 727 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
713 728
729 if (r->method & clcf->limit_except) {
730 r->loc_conf = clcf->limit_except_loc_conf;
731 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
732 }
733
714 r->connection->log->file = clcf->err_log->file; 734 r->connection->log->file = clcf->err_log->file;
715 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { 735 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
716 r->connection->log->log_level = clcf->err_log->log_level; 736 r->connection->log->log_level = clcf->err_log->log_level;
717 } 737 }
718 738
1947 1967
1948 /* 1968 /*
1949 * set by ngx_pcalloc(): 1969 * set by ngx_pcalloc():
1950 * 1970 *
1951 * lcf->root = { 0, NULL }; 1971 * lcf->root = { 0, NULL };
1972 * lcf->limit_except = 0;
1952 * lcf->post_action = { 0, NULL }; 1973 * lcf->post_action = { 0, NULL };
1953 * lcf->types = NULL; 1974 * lcf->types = NULL;
1954 * lcf->default_type = { 0, NULL }; 1975 * lcf->default_type = { 0, NULL };
1955 * lcf->err_log = NULL; 1976 * lcf->err_log = NULL;
1956 * lcf->error_pages = NULL; 1977 * lcf->error_pages = NULL;
2243 2264
2244 } else { 2265 } else {
2245 ls->addr = INADDR_ANY; 2266 ls->addr = INADDR_ANY;
2246 } 2267 }
2247 2268
2269 n = ngx_inet_ntop(AF_INET, &ls->addr, ls->conf.addr, INET_ADDRSTRLEN + 6);
2270 ngx_sprintf(&ls->conf.addr[n], ":%ui", ls->port);
2271
2248 if (cf->args->nelts == 2) { 2272 if (cf->args->nelts == 2) {
2249 return NGX_CONF_OK; 2273 return NGX_CONF_OK;
2250 } 2274 }
2251 2275
2252 if (ngx_strcmp(value[2].data, "default") == 0) { 2276 if (ngx_strcmp(value[2].data, "default") == 0) {
2478 2502
2479 return NGX_CONF_OK; 2503 return NGX_CONF_OK;
2480 } 2504 }
2481 2505
2482 2506
2507 static ngx_http_method_name_t ngx_methods_names[] = {
2508 { "GET", (uint32_t) ~NGX_HTTP_GET },
2509 { "HEAD", (uint32_t) ~NGX_HTTP_HEAD },
2510 { NULL, 0 }
2511 };
2512
2513
2514 static char *
2515 ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2516 {
2517 ngx_http_core_loc_conf_t *clcf = conf;
2518
2519 char *rv;
2520 void *mconf;
2521 ngx_str_t *value;
2522 ngx_uint_t i;
2523 ngx_conf_t save;
2524 ngx_http_module_t *module;
2525 ngx_http_conf_ctx_t *ctx, *pctx;
2526 ngx_http_method_name_t *name;
2527 ngx_http_core_loc_conf_t *lcf, **clcfp;
2528
2529 if (clcf->limit_except) {
2530 return "duplicate";
2531 }
2532
2533 clcf->limit_except = 0xffffffff;
2534
2535 value = cf->args->elts;
2536
2537 for (i = 1; i < cf->args->nelts; i++) {
2538 for (name = ngx_methods_names; name->name; name++) {
2539
2540 if (ngx_strcasecmp(value[i].data, name->name) == 0) {
2541 clcf->limit_except &= name->method;
2542 goto next;
2543 }
2544 }
2545
2546 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2547 "invalid method \"%V\"", &value[i]);
2548 return NGX_CONF_ERROR;
2549
2550 next:
2551 continue;
2552 }
2553
2554 if (!(clcf->limit_except & NGX_HTTP_GET)) {
2555 clcf->limit_except &= (uint32_t) ~NGX_HTTP_HEAD;
2556 }
2557
2558 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
2559 if (ctx == NULL) {
2560 return NGX_CONF_ERROR;
2561 }
2562
2563 pctx = cf->ctx;
2564 ctx->main_conf = pctx->main_conf;
2565 ctx->srv_conf = pctx->srv_conf;
2566
2567 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
2568 if (ctx->loc_conf == NULL) {
2569 return NGX_CONF_ERROR;
2570 }
2571
2572 for (i = 0; ngx_modules[i]; i++) {
2573 if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
2574 continue;
2575 }
2576
2577 module = ngx_modules[i]->ctx;
2578
2579 if (module->create_loc_conf) {
2580
2581 mconf = module->create_loc_conf(cf);
2582 if (mconf == NULL) {
2583 return NGX_CONF_ERROR;
2584 }
2585
2586 ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
2587 }
2588 }
2589
2590
2591 lcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
2592 clcf->limit_except_loc_conf = ctx->loc_conf;
2593 lcf->loc_conf = ctx->loc_conf;
2594 lcf->name = clcf->name;
2595 lcf->noname = 1;
2596
2597 if (clcf->locations.elts == NULL) {
2598 if (ngx_array_init(&clcf->locations, cf->pool, 4, sizeof(void *))
2599 == NGX_ERROR)
2600 {
2601 return NGX_CONF_ERROR;
2602 }
2603 }
2604
2605 clcfp = ngx_array_push(&clcf->locations);
2606 if (clcfp == NULL) {
2607 return NGX_CONF_ERROR;
2608 }
2609
2610 *clcfp = lcf;
2611
2612
2613 save = *cf;
2614 cf->ctx = ctx;
2615 cf->cmd_type = NGX_HTTP_LMT_CONF;
2616
2617 rv = ngx_conf_parse(cf, NULL);
2618
2619 *cf = save;
2620
2621 return rv;
2622 }
2623
2624
2483 static char * 2625 static char *
2484 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 2626 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2485 { 2627 {
2486 ngx_http_core_loc_conf_t *lcf = conf; 2628 ngx_http_core_loc_conf_t *lcf = conf;
2487 2629