comparison src/http/modules/ngx_http_autoindex_module.c @ 527:7fa11e5c6e96 release-0.1.38

nginx-0.1.38-RELEASE import *) Feature: the "limit_rate" directive is supported in in proxy and FastCGI mode. *) Feature: the "X-Accel-Limit-Rate" response header line is supported in proxy and FastCGI mode. *) Feature: the "break" directive. *) Feature: the "log_not_found" directive. *) Bugfix: the response status code was not changed when request was redirected by the ""X-Accel-Redirect" header line. *) Bugfix: the variables set by the "set" directive could not be used in SSI. *) Bugfix: the segmentation fault may occurred if the SSI page has more than one remote subrequest. *) Bugfix: nginx treated the backend response as invalid if the status line in the header was transferred in two packets; the bug had appeared in 0.1.29. *) Feature: the "ssi_types" directive. *) Feature: the "autoindex_exact_size" directive. *) Bugfix: the ngx_http_autoindex_module did not support the long file names in UTF-8. *) Feature: the IMAP/POP3 proxy.
author Igor Sysoev <igor@sysoev.ru>
date Fri, 08 Jul 2005 14:34:20 +0000
parents 09b42134ac0c
children e5d7d0334fdb
comparison
equal deleted inserted replaced
526:e31ce4d8b8e6 527:7fa11e5c6e96
33 33
34 34
35 typedef struct { 35 typedef struct {
36 ngx_flag_t enable; 36 ngx_flag_t enable;
37 ngx_flag_t localtime; 37 ngx_flag_t localtime;
38 ngx_flag_t exact_size;
38 } ngx_http_autoindex_loc_conf_t; 39 } ngx_http_autoindex_loc_conf_t;
39 40
40 41
41 #define NGX_HTTP_AUTOINDEX_NAME_LEN 50 42 #define NGX_HTTP_AUTOINDEX_NAME_LEN 50
42 43
65 ngx_conf_set_flag_slot, 66 ngx_conf_set_flag_slot,
66 NGX_HTTP_LOC_CONF_OFFSET, 67 NGX_HTTP_LOC_CONF_OFFSET,
67 offsetof(ngx_http_autoindex_loc_conf_t, localtime), 68 offsetof(ngx_http_autoindex_loc_conf_t, localtime),
68 NULL }, 69 NULL },
69 70
71 { ngx_string("autoindex_exact_size"),
72 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
73 ngx_conf_set_flag_slot,
74 NGX_HTTP_LOC_CONF_OFFSET,
75 offsetof(ngx_http_autoindex_loc_conf_t, exact_size),
76 NULL },
77
70 ngx_null_command 78 ngx_null_command
71 }; 79 };
72 80
73 81
74 ngx_http_module_t ngx_http_autoindex_module_ctx = { 82 ngx_http_module_t ngx_http_autoindex_module_ctx = {
115 123
116 124
117 static ngx_int_t 125 static ngx_int_t
118 ngx_http_autoindex_handler(ngx_http_request_t *r) 126 ngx_http_autoindex_handler(ngx_http_request_t *r)
119 { 127 {
120 u_char *last; 128 u_char *last, scale;
121 size_t len; 129 off_t length;
130 size_t len, copy;
122 ngx_tm_t tm; 131 ngx_tm_t tm;
123 ngx_int_t rc; 132 ngx_int_t rc, size;
124 ngx_uint_t i, level; 133 ngx_uint_t i, level;
125 ngx_err_t err; 134 ngx_err_t err;
126 ngx_buf_t *b; 135 ngx_buf_t *b;
127 ngx_chain_t out; 136 ngx_chain_t out;
128 ngx_str_t dname, fname; 137 ngx_str_t dname, fname;
349 + sizeof("\">") - 1 358 + sizeof("\">") - 1
350 + entry[i].name.len - entry[i].utf_len 359 + entry[i].name.len - entry[i].utf_len
351 + NGX_HTTP_AUTOINDEX_NAME_LEN + sizeof("&gt;") - 2 360 + NGX_HTTP_AUTOINDEX_NAME_LEN + sizeof("&gt;") - 2
352 + sizeof("</a>") - 1 361 + sizeof("</a>") - 1
353 + sizeof(" 28-Sep-1970 12:00 ") - 1 362 + sizeof(" 28-Sep-1970 12:00 ") - 1
354 + 19 363 + 20
355 + 2; 364 + 2;
356 } 365 }
357 366
358 b = ngx_create_temp_buf(r->pool, len); 367 b = ngx_create_temp_buf(r->pool, len);
359 if (b == NULL) { 368 if (b == NULL) {
394 } 403 }
395 404
396 *b->last++ = '"'; 405 *b->last++ = '"';
397 *b->last++ = '>'; 406 *b->last++ = '>';
398 407
399 b->last = ngx_cpystrn(b->last, entry[i].name.data,
400 NGX_HTTP_AUTOINDEX_NAME_LEN + 1);
401
402 len = entry[i].utf_len; 408 len = entry[i].utf_len;
403 409
410 if (len) {
411 if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) {
412 copy = NGX_HTTP_AUTOINDEX_NAME_LEN - 3 + 1;
413
414 } else {
415 copy = NGX_HTTP_AUTOINDEX_NAME_LEN + 1;
416 }
417
418 b->last = ngx_utf_cpystrn(b->last, entry[i].name.data, copy);
419 last = b->last;
420
421 } else {
422 b->last = ngx_cpystrn(b->last, entry[i].name.data,
423 NGX_HTTP_AUTOINDEX_NAME_LEN + 1);
424 last = b->last - 3;
425 }
426
404 if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) { 427 if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) {
405 b->last = ngx_cpymem(b->last - 3, "..&gt;</a>", 428 b->last = ngx_cpymem(last, "..&gt;</a>", sizeof("..&gt;</a>") - 1);
406 sizeof("..&gt;</a>") - 1);
407 429
408 } else { 430 } else {
409 if (entry[i].dir && NGX_HTTP_AUTOINDEX_NAME_LEN - len > 0) { 431 if (entry[i].dir && NGX_HTTP_AUTOINDEX_NAME_LEN - len > 0) {
410 *b->last++ = '/'; 432 *b->last++ = '/';
411 len++; 433 len++;
425 months[tm.ngx_tm_mon - 1], 447 months[tm.ngx_tm_mon - 1],
426 tm.ngx_tm_year, 448 tm.ngx_tm_year,
427 tm.ngx_tm_hour, 449 tm.ngx_tm_hour,
428 tm.ngx_tm_min); 450 tm.ngx_tm_min);
429 451
430 if (entry[i].dir) { 452 if (alcf->exact_size) {
431 b->last = ngx_cpymem(b->last, " -", 453 if (entry[i].dir) {
432 sizeof(" -") - 1); 454 b->last = ngx_cpymem(b->last, " -",
455 sizeof(" -") - 1);
456 } else {
457 b->last = ngx_sprintf(b->last, "%19O", entry[i].size);
458 }
433 459
434 } else { 460 } else {
435 b->last = ngx_sprintf(b->last, "%19O", entry[i].size); 461 if (entry[i].dir) {
462 b->last = ngx_cpymem(b->last, " -", sizeof(" -") - 1);
463
464 } else {
465 length = entry[i].size;
466
467 if (length > 1024 * 1024 * 1024 - 1) {
468 size = (ngx_int_t) (length / (1024 * 1024 * 1024));
469 if ((length % (1024 * 1024 * 1024))
470 > (1024 * 1024 * 1024 / 2 - 1))
471 {
472 size++;
473 }
474 scale = 'G';
475
476 } else if (length > 1024 * 1024 - 1) {
477 size = (ngx_int_t) (length / (1024 * 1024));
478 if ((length % (1024 * 1024)) > (1024 * 1024 / 2 - 1)) {
479 size++;
480 }
481 scale = 'M';
482
483 } else if (length > 9999) {
484 size = (ngx_int_t) (length / 1024);
485 if (length % 1024 > 511) {
486 size++;
487 }
488 scale = 'K';
489
490 } else {
491 size = (ngx_int_t) length;
492 scale = ' ';
493 }
494
495 b->last = ngx_sprintf(b->last, "%6i", size);
496
497 if (scale != ' ') {
498 *b->last++ = scale;
499 }
500 }
436 } 501 }
437 502
438 *b->last++ = CR; 503 *b->last++ = CR;
439 *b->last++ = LF; 504 *b->last++ = LF;
440 } 505 }
557 return NGX_CONF_ERROR; 622 return NGX_CONF_ERROR;
558 } 623 }
559 624
560 conf->enable = NGX_CONF_UNSET; 625 conf->enable = NGX_CONF_UNSET;
561 conf->localtime = NGX_CONF_UNSET; 626 conf->localtime = NGX_CONF_UNSET;
627 conf->exact_size = NGX_CONF_UNSET;
562 628
563 return conf; 629 return conf;
564 } 630 }
565 631
566 632
570 ngx_http_autoindex_loc_conf_t *prev = parent; 636 ngx_http_autoindex_loc_conf_t *prev = parent;
571 ngx_http_autoindex_loc_conf_t *conf = child; 637 ngx_http_autoindex_loc_conf_t *conf = child;
572 638
573 ngx_conf_merge_value(conf->enable, prev->enable, 0); 639 ngx_conf_merge_value(conf->enable, prev->enable, 0);
574 ngx_conf_merge_value(conf->localtime, prev->localtime, 0); 640 ngx_conf_merge_value(conf->localtime, prev->localtime, 0);
641 ngx_conf_merge_value(conf->exact_size, prev->exact_size, 1);
575 642
576 return NGX_CONF_OK; 643 return NGX_CONF_OK;
577 } 644 }