comparison src/http/modules/ngx_http_index_module.c @ 230:38e7b94d63ac NGINX_0_4_0

nginx 0.4.0 *) Change in internal API: the HTTP modules initialization was moved from the init module phase to the HTTP postconfiguration phase. *) Change: now the request body is not read beforehand for the ngx_http_perl_module: it's required to start the reading using the $r->has_request_body method. *) Feature: the ngx_http_perl_module supports the DECLINED return code. *) Feature: the ngx_http_dav_module supports the incoming "Date" header line for the PUT method. *) Feature: the "ssi" directive is available inside the "if" block. *) Bugfix: a segmentation fault occurred if there was an "index" directive with variables and the first index name was without variables; bug appeared in 0.1.29.
author Igor Sysoev <http://sysoev.ru>
date Wed, 30 Aug 2006 00:00:00 +0400
parents fa32d59d9a15
children d8f5c91a5c07
comparison
equal deleted inserted replaced
229:1965c8e23be7 230:38e7b94d63ac
38 static ngx_int_t ngx_http_index_test_dir(ngx_http_request_t *r, 38 static ngx_int_t ngx_http_index_test_dir(ngx_http_request_t *r,
39 ngx_http_index_ctx_t *ctx); 39 ngx_http_index_ctx_t *ctx);
40 static ngx_int_t ngx_http_index_error(ngx_http_request_t *r, 40 static ngx_int_t ngx_http_index_error(ngx_http_request_t *r,
41 ngx_http_index_ctx_t *ctx, ngx_err_t err); 41 ngx_http_index_ctx_t *ctx, ngx_err_t err);
42 42
43 static ngx_int_t ngx_http_index_init(ngx_cycle_t *cycle); 43 static ngx_int_t ngx_http_index_init(ngx_conf_t *cf);
44 static void *ngx_http_index_create_loc_conf(ngx_conf_t *cf); 44 static void *ngx_http_index_create_loc_conf(ngx_conf_t *cf);
45 static char *ngx_http_index_merge_loc_conf(ngx_conf_t *cf, 45 static char *ngx_http_index_merge_loc_conf(ngx_conf_t *cf,
46 void *parent, void *child); 46 void *parent, void *child);
47 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, 47 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd,
48 void *conf); 48 void *conf);
72 }; 72 };
73 73
74 74
75 static ngx_http_module_t ngx_http_index_module_ctx = { 75 static ngx_http_module_t ngx_http_index_module_ctx = {
76 NULL, /* preconfiguration */ 76 NULL, /* preconfiguration */
77 NULL, /* postconfiguration */ 77 ngx_http_index_init, /* postconfiguration */
78 78
79 NULL, /* create main configuration */ 79 NULL, /* create main configuration */
80 NULL, /* init main configuration */ 80 NULL, /* init main configuration */
81 81
82 NULL, /* create server configuration */ 82 NULL, /* create server configuration */
91 NGX_MODULE_V1, 91 NGX_MODULE_V1,
92 &ngx_http_index_module_ctx, /* module context */ 92 &ngx_http_index_module_ctx, /* module context */
93 ngx_http_index_commands, /* module directives */ 93 ngx_http_index_commands, /* module directives */
94 NGX_HTTP_MODULE, /* module type */ 94 NGX_HTTP_MODULE, /* module type */
95 NULL, /* init master */ 95 NULL, /* init master */
96 ngx_http_index_init, /* init module */ 96 NULL, /* init module */
97 NULL, /* init process */ 97 NULL, /* init process */
98 NULL, /* init thread */ 98 NULL, /* init thread */
99 NULL, /* exit thread */ 99 NULL, /* exit thread */
100 NULL, /* exit process */ 100 NULL, /* exit process */
101 NULL, /* exit master */ 101 NULL, /* exit master */
196 /* 16 bytes are preallocation */ 196 /* 16 bytes are preallocation */
197 197
198 len += 16; 198 len += 16;
199 } 199 }
200 200
201 if (len > ctx->path.len) { 201 if (len > (size_t) (ctx->path.data + ctx->path.len - ctx->index.data)) {
202 202
203 last = ngx_http_map_uri_to_path(r, &ctx->path, len); 203 last = ngx_http_map_uri_to_path(r, &ctx->path, len);
204 if (last == NULL) { 204 if (last == NULL) {
205 return NGX_ERROR; 205 return NGX_ERROR;
206 } 206 }
376 if (conf == NULL) { 376 if (conf == NULL) {
377 return NGX_CONF_ERROR; 377 return NGX_CONF_ERROR;
378 } 378 }
379 379
380 conf->indices = NULL; 380 conf->indices = NULL;
381 conf->max_index_len = 1; 381 conf->max_index_len = 0;
382 382
383 return conf; 383 return conf;
384 } 384 }
385 385
386 386
420 420
421 return NGX_CONF_OK; 421 return NGX_CONF_OK;
422 } 422 }
423 423
424 424
425 static ngx_int_t
426 ngx_http_index_init(ngx_conf_t *cf)
427 {
428 ngx_http_handler_pt *h;
429 ngx_http_core_main_conf_t *cmcf;
430
431 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
432
433 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
434 if (h == NULL) {
435 return NGX_ERROR;
436 }
437
438 *h = ngx_http_index_handler;
439
440 return NGX_OK;
441 }
442
443
425 /* TODO: warn about duplicate indices */ 444 /* TODO: warn about duplicate indices */
426 445
427 static char * 446 static char *
428 ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 447 ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
429 { 448 {
430 ngx_http_index_loc_conf_t *ilcf = conf; 449 ngx_http_index_loc_conf_t *ilcf = conf;
431 450
451 ngx_str_t *value;
432 ngx_uint_t i, n; 452 ngx_uint_t i, n;
433 ngx_str_t *value;
434 ngx_http_index_t *index; 453 ngx_http_index_t *index;
435 ngx_http_script_compile_t sc; 454 ngx_http_script_compile_t sc;
436 455
437 if (ilcf->indices == NULL) { 456 if (ilcf->indices == NULL) {
438 ilcf->indices = ngx_array_create(cf->pool, 2, sizeof(ngx_http_index_t)); 457 ilcf->indices = ngx_array_create(cf->pool, 2, sizeof(ngx_http_index_t));
469 index->values = NULL; 488 index->values = NULL;
470 489
471 n = ngx_http_script_variables_count(&value[i]); 490 n = ngx_http_script_variables_count(&value[i]);
472 491
473 if (n == 0) { 492 if (n == 0) {
474 if (ilcf->max_index_len != 0 493 if (ilcf->max_index_len < index->name.len) {
475 && ilcf->max_index_len < index->name.len)
476 {
477 ilcf->max_index_len = index->name.len; 494 ilcf->max_index_len = index->name.len;
478 } 495 }
479 496
480 /* include the terminating '\0' to the length to use ngx_copy() */ 497 /* include the terminating '\0' to the length to use ngx_copy() */
481 index->name.len++; 498 index->name.len++;
494 sc.complete_values = 1; 511 sc.complete_values = 1;
495 512
496 if (ngx_http_script_compile(&sc) != NGX_OK) { 513 if (ngx_http_script_compile(&sc) != NGX_OK) {
497 return NGX_CONF_ERROR; 514 return NGX_CONF_ERROR;
498 } 515 }
499
500 ilcf->max_index_len = 0;
501 } 516 }
502 517
503 return NGX_CONF_OK; 518 return NGX_CONF_OK;
504 } 519 }
505
506
507 static ngx_int_t
508 ngx_http_index_init(ngx_cycle_t *cycle)
509 {
510 ngx_http_handler_pt *h;
511 ngx_http_core_main_conf_t *cmcf;
512
513 cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
514
515 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
516 if (h == NULL) {
517 return NGX_ERROR;
518 }
519
520 *h = ngx_http_index_handler;
521
522 return NGX_OK;
523 }