comparison src/http/modules/ngx_http_autoindex_handler.c @ 48:6cfc63e68377 NGINX_0_1_24

nginx 0.1.24 *) Feature: the ngx_http_ssi_filter_module supports the QUERY_STRING and DOCUMENT_URI variables. *) Bugfix: the ngx_http_autoindex_module may some times return the 404 response for existent directory, if this directory was used in "alias" directive. *) Bugfix: the ngx_http_ssi_filter_module ran incorrectly for large responses. *) Bugfix: the lack of the "Referer" header line was always accounted as valid referrer.
author Igor Sysoev <http://sysoev.ru>
date Fri, 04 Mar 2005 00:00:00 +0300
parents 9f3205d496a0
children
comparison
equal deleted inserted replaced
47:4ae32548452c 48:6cfc63e68377
38 38
39 #define NGX_HTTP_AUTOINDEX_NAME_LEN 50 39 #define NGX_HTTP_AUTOINDEX_NAME_LEN 50
40 40
41 41
42 static int ngx_http_autoindex_cmp_entries(const void *one, const void *two); 42 static int ngx_http_autoindex_cmp_entries(const void *one, const void *two);
43 static ngx_int_t ngx_http_autoindex_error(ngx_http_request_t *r, ngx_dir_t *dir, 43 static ngx_int_t ngx_http_autoindex_error(ngx_http_request_t *r,
44 u_char *name); 44 ngx_dir_t *dir, u_char *name);
45 static ngx_int_t ngx_http_autoindex_init(ngx_cycle_t *cycle); 45 static ngx_int_t ngx_http_autoindex_init(ngx_cycle_t *cycle);
46 static void *ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf); 46 static void *ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf);
47 static char *ngx_http_autoindex_merge_loc_conf(ngx_conf_t *cf, 47 static char *ngx_http_autoindex_merge_loc_conf(ngx_conf_t *cf,
48 void *parent, void *child); 48 void *parent, void *child);
49 49
50 50
51 static ngx_command_t ngx_http_autoindex_commands[] = { 51 static ngx_command_t ngx_http_autoindex_commands[] = {
52 52
53 { ngx_string("autoindex"), 53 { ngx_string("autoindex"),
79 NGX_MODULE, 79 NGX_MODULE,
80 &ngx_http_autoindex_module_ctx, /* module context */ 80 &ngx_http_autoindex_module_ctx, /* module context */
81 ngx_http_autoindex_commands, /* module directives */ 81 ngx_http_autoindex_commands, /* module directives */
82 NGX_HTTP_MODULE, /* module type */ 82 NGX_HTTP_MODULE, /* module type */
83 ngx_http_autoindex_init, /* init module */ 83 ngx_http_autoindex_init, /* init module */
84 NULL /* init child */ 84 NULL /* init process */
85 }; 85 };
86 86
87 87
88 static u_char title[] = 88 static u_char title[] =
89 "<html>" CRLF 89 "<html>" CRLF
101 "</body>" CRLF 101 "</body>" CRLF
102 "</html>" CRLF 102 "</html>" CRLF
103 ; 103 ;
104 104
105 105
106 static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r) 106 static ngx_int_t
107 ngx_http_autoindex_handler(ngx_http_request_t *r)
107 { 108 {
108 u_char *last; 109 u_char *last;
109 size_t len; 110 size_t len;
110 ngx_tm_t tm; 111 ngx_tm_t tm;
111 ngx_int_t rc; 112 ngx_int_t rc;
144 145
145 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 146 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
146 147
147 if (clcf->alias) { 148 if (clcf->alias) {
148 dname.data = ngx_palloc(pool, clcf->root.len + r->uri.len 149 dname.data = ngx_palloc(pool, clcf->root.len + r->uri.len
149 + NGX_DIR_MASK_LEN 150 + NGX_DIR_MASK_LEN + 1
150 - clcf->name.len); 151 - clcf->name.len);
151 if (dname.data == NULL) { 152 if (dname.data == NULL) {
152 return NGX_HTTP_INTERNAL_SERVER_ERROR; 153 return NGX_HTTP_INTERNAL_SERVER_ERROR;
153 } 154 }
154 155
155 last = ngx_cpymem(dname.data, clcf->root.data, clcf->root.len); 156 last = ngx_cpymem(dname.data, clcf->root.data, clcf->root.len);
156 last = ngx_cpystrn(last, r->uri.data + clcf->name.len, 157 last = ngx_cpystrn(last, r->uri.data + clcf->name.len,
157 r->uri.len - clcf->name.len); 158 r->uri.len - clcf->name.len + 1);
158 159
159 } else { 160 } else {
160 dname.data = ngx_palloc(pool, clcf->root.len + r->uri.len 161 dname.data = ngx_palloc(pool, clcf->root.len + r->uri.len
161 + NGX_DIR_MASK_LEN); 162 + NGX_DIR_MASK_LEN);
162 if (dname.data == NULL) { 163 if (dname.data == NULL) {
163 return NGX_HTTP_INTERNAL_SERVER_ERROR; 164 return NGX_HTTP_INTERNAL_SERVER_ERROR;
164 } 165 }
165 166
166 last = ngx_cpymem(dname.data, clcf->root.data, clcf->root.len); 167 last = ngx_cpymem(dname.data, clcf->root.data, clcf->root.len);
167 last = ngx_cpystrn(last, r->uri.data, r->uri.len); 168 last = ngx_cpystrn(last, r->uri.data, r->uri.len);
168
169 } 169 }
170 170
171 dname.len = last - dname.data; 171 dname.len = last - dname.data;
172 172
173 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 173 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
443 443
444 return ngx_http_output_filter(r, &out); 444 return ngx_http_output_filter(r, &out);
445 } 445 }
446 446
447 447
448 static int ngx_http_autoindex_cmp_entries(const void *one, const void *two) 448 static int
449 ngx_http_autoindex_cmp_entries(const void *one, const void *two)
449 { 450 {
450 ngx_http_autoindex_entry_t *first = (ngx_http_autoindex_entry_t *) one; 451 ngx_http_autoindex_entry_t *first = (ngx_http_autoindex_entry_t *) one;
451 ngx_http_autoindex_entry_t *second = (ngx_http_autoindex_entry_t *) two; 452 ngx_http_autoindex_entry_t *second = (ngx_http_autoindex_entry_t *) two;
452 453
453 if (first->dir && !second->dir) { 454 if (first->dir && !second->dir) {
464 } 465 }
465 466
466 467
467 #if 0 468 #if 0
468 469
469 static ngx_buf_t *ngx_http_autoindex_alloc(ngx_http_autoindex_ctx_t *ctx, 470 static ngx_buf_t *
470 size_t size) 471 ngx_http_autoindex_alloc(ngx_http_autoindex_ctx_t *ctx, size_t size)
471 { 472 {
472 ngx_chain_t *cl; 473 ngx_chain_t *cl;
473 474
474 if (ctx->buf) { 475 if (ctx->buf) {
475 476
498 } 499 }
499 500
500 #endif 501 #endif
501 502
502 503
503 static ngx_int_t ngx_http_autoindex_error(ngx_http_request_t *r, ngx_dir_t *dir, 504 static ngx_int_t
504 u_char *name) 505 ngx_http_autoindex_error(ngx_http_request_t *r, ngx_dir_t *dir, u_char *name)
505 { 506 {
506 if (ngx_close_dir(dir) == NGX_ERROR) { 507 if (ngx_close_dir(dir) == NGX_ERROR) {
507 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, 508 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
508 ngx_close_dir_n " \"%s\" failed", name); 509 ngx_close_dir_n " \"%s\" failed", name);
509 } 510 }
510 511
511 return NGX_HTTP_INTERNAL_SERVER_ERROR; 512 return NGX_HTTP_INTERNAL_SERVER_ERROR;
512 } 513 }
513 514
514 515
515 static ngx_int_t ngx_http_autoindex_init(ngx_cycle_t *cycle) 516 static ngx_int_t
517 ngx_http_autoindex_init(ngx_cycle_t *cycle)
516 { 518 {
517 ngx_http_handler_pt *h; 519 ngx_http_handler_pt *h;
518 ngx_http_core_main_conf_t *cmcf; 520 ngx_http_core_main_conf_t *cmcf;
519 521
520 cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module); 522 cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
528 530
529 return NGX_OK; 531 return NGX_OK;
530 } 532 }
531 533
532 534
533 static void *ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf) 535 static void *
536 ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf)
534 { 537 {
535 ngx_http_autoindex_loc_conf_t *conf; 538 ngx_http_autoindex_loc_conf_t *conf;
536 539
537 conf = ngx_palloc(cf->pool, sizeof(ngx_http_autoindex_loc_conf_t)); 540 conf = ngx_palloc(cf->pool, sizeof(ngx_http_autoindex_loc_conf_t));
538 if (conf == NULL) { 541 if (conf == NULL) {
543 546
544 return conf; 547 return conf;
545 } 548 }
546 549
547 550
548 static char *ngx_http_autoindex_merge_loc_conf(ngx_conf_t *cf, 551 static char *
549 void *parent, void *child) 552 ngx_http_autoindex_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
550 { 553 {
551 ngx_http_autoindex_loc_conf_t *prev = parent; 554 ngx_http_autoindex_loc_conf_t *prev = parent;
552 ngx_http_autoindex_loc_conf_t *conf = child; 555 ngx_http_autoindex_loc_conf_t *conf = child;
553 556
554 ngx_conf_merge_value(conf->enable, prev->enable, 0); 557 ngx_conf_merge_value(conf->enable, prev->enable, 0);