02 custom autoindex.patch (7646B)
- diff --git a/src/http/modules/ngx_http_autoindex_module.c.old b/src/http/modules/ngx_http_autoindex_module.c
- index 2af88a0..18c7570 100644
- --- a/src/http/modules/ngx_http_autoindex_module.c.old
- +++ b/src/http/modules/ngx_http_autoindex_module.c
- @@ -52,9 +52,6 @@ typedef struct {
- #define NGX_HTTP_AUTOINDEX_PREALLOCATE 50
- -#define NGX_HTTP_AUTOINDEX_NAME_LEN 50
- -
- -
- static ngx_buf_t *ngx_http_autoindex_html(ngx_http_request_t *r,
- ngx_array_t *entries);
- static ngx_buf_t *ngx_http_autoindex_json(ngx_http_request_t *r,
- @@ -476,7 +475,8 @@ ngx_http_autoindex_html(ngx_http_request_t *r, ngx_array_t *entries)
- + sizeof(header) - 1
- + r->uri.len + escape_html
- + sizeof("</h1>") - 1
- - + sizeof("<hr><pre><a href=\"../\">../</a>" CRLF) - 1
- + + sizeof("<table><tr><th>Name</th><th>Date</th><th>Size</th></tr>" CRLF) - 1
- + + sizeof("<tr><td><a href=\"../\">../</a></td></tr>" CRLF) - 1
- + sizeof("</pre><hr>") - 1
- + sizeof(tail) - 1;
- @@ -498,12 +498,11 @@ ngx_http_autoindex_html(ngx_http_request_t *r, ngx_array_t *entries)
- + entry[i].name.len + entry[i].escape
- + 1 /* 1 is for "/" */
- + sizeof("\">") - 1
- - + entry[i].name.len - entry[i].utf_len
- + + entry[i].utf_len
- + entry[i].escape_html
- - + NGX_HTTP_AUTOINDEX_NAME_LEN + sizeof(">") - 2
- + sizeof("</a>") - 1
- + sizeof(" 28-Sep-1970 12:00 ") - 1
- - + 20 /* the file size */
- + + 256 /* the file size */
- + 2;
- if (len > NGX_MAX_SIZE_T_VALUE - entry_len) {
- @@ -531,14 +527,14 @@ ngx_http_autoindex_html(ngx_http_request_t *r, ngx_array_t *entries)
- b->last = ngx_cpymem(b->last, "</h1>", sizeof("</h1>") - 1);
- - b->last = ngx_cpymem(b->last, "<hr><pre><a href=\"../\">../</a>" CRLF,
- - sizeof("<hr><pre><a href=\"../\">../</a>" CRLF) - 1);
- + b->last = ngx_cpymem(b->last, "<hr><table><tr><th>Name</th><th>Date</th><th>Size</th></tr>" CRLF "<tr><td><a href=\"../\">../</a></td></tr>" CRLF,
- + sizeof("<hr><table><tr><th>Name</th><th>Date</th><th>Size</th></tr>" CRLF "<tr><td><a href=\"../\">../</a></td></tr>" CRLF) - 1);
- alcf = ngx_http_get_module_loc_conf(r, ngx_http_autoindex_module);
- tp = ngx_timeofday();
- for (i = 0; i < entries->nelts; i++) {
- - b->last = ngx_cpymem(b->last, "<a href=\"", sizeof("<a href=\"") - 1);
- + b->last = ngx_cpymem(b->last, "<tr><td><a href=\"", sizeof("<tr><td><a href=\"") - 1);
- if (entry[i].escape) {
- ngx_escape_uri(b->last, entry[i].name.data, entry[i].name.len,
- @@ -558,69 +556,27 @@ ngx_http_autoindex_html(ngx_http_request_t *r, ngx_array_t *entries)
- *b->last++ = '"';
- *b->last++ = '>';
- len = entry[i].utf_len;
- - if (entry[i].name.len != len) {
- - if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) {
- - char_len = NGX_HTTP_AUTOINDEX_NAME_LEN - 3 + 1;
- -
- - } else {
- - char_len = NGX_HTTP_AUTOINDEX_NAME_LEN + 1;
- - }
- -
- - last = b->last;
- - b->last = ngx_utf8_cpystrn(b->last, entry[i].name.data,
- - char_len, entry[i].name.len + 1);
- + last = b->last;
- + b->last = ngx_cpymem(b->last, entry[i].name.data,
- + entry[i].name.len);
- - if (entry[i].escape_html) {
- - b->last = (u_char *) ngx_escape_html(last, entry[i].name.data,
- - b->last - last);
- - }
- + if (entry[i].escape_html) {
- + b->last = (u_char *) ngx_escape_html(last, entry[i].name.data,
- + b->last - last);
- + }
- - last = b->last;
- -
- - } else {
- - if (entry[i].escape_html) {
- - if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) {
- - char_len = NGX_HTTP_AUTOINDEX_NAME_LEN - 3;
- -
- - } else {
- - char_len = len;
- - }
- -
- - b->last = (u_char *) ngx_escape_html(b->last,
- - entry[i].name.data, char_len);
- - last = b->last;
- -
- - } else {
- - b->last = ngx_cpystrn(b->last, entry[i].name.data,
- - NGX_HTTP_AUTOINDEX_NAME_LEN + 1);
- - last = b->last - 3;
- - }
- - }
- -
- - if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) {
- - b->last = ngx_cpymem(last, "..></a>", sizeof("..></a>") - 1);
- -
- - } else {
- - if (entry[i].dir && NGX_HTTP_AUTOINDEX_NAME_LEN - len > 0) {
- - *b->last++ = '/';
- - len++;
- - }
- -
- - b->last = ngx_cpymem(b->last, "</a>", sizeof("</a>") - 1);
- -
- - if (NGX_HTTP_AUTOINDEX_NAME_LEN - len > 0) {
- - ngx_memset(b->last, ' ', NGX_HTTP_AUTOINDEX_NAME_LEN - len);
- - b->last += NGX_HTTP_AUTOINDEX_NAME_LEN - len;
- - }
- + if (entry[i].dir) {
- + *b->last++ = '/';
- + len++;
- }
- - *b->last++ = ' ';
- + b->last = ngx_cpymem(b->last, "</a></td>", sizeof("</a></td>") - 1);
- ngx_gmtime(entry[i].mtime + tp->gmtoff * 60 * alcf->localtime, &tm);
- - b->last = ngx_sprintf(b->last, "%02d-%02d-%02d %02d:%02d ",
- + b->last = ngx_sprintf(b->last, "<td>%02d-%02d-%02d %02d:%02d</td>",
- tm.ngx_tm_year,
- tm.ngx_tm_mon,
- tm.ngx_tm_mday,
- @@ -628,19 +574,12 @@ ngx_http_autoindex_html(ngx_http_request_t *r, ngx_array_t *entries)
- tm.ngx_tm_min);
- if (alcf->exact_size) {
- - if (entry[i].dir) {
- - b->last = ngx_cpymem(b->last, " -",
- - sizeof(" -") - 1);
- - } else {
- - b->last = ngx_sprintf(b->last, "%19O", entry[i].size);
- + if (!entry[i].dir) {
- + b->last = ngx_sprintf(b->last, "<td>%O</td>", entry[i].size);
- }
- } else {
- - if (entry[i].dir) {
- - b->last = ngx_cpymem(b->last, " -",
- - sizeof(" -") - 1);
- -
- - } else {
- + if (!entry[i].dir) {
- length = entry[i].size;
- if (length > 1024 * 1024 * 1024 - 1) {
- @@ -672,19 +611,18 @@ ngx_http_autoindex_html(ngx_http_request_t *r, ngx_array_t *entries)
- }
- if (scale) {
- - b->last = ngx_sprintf(b->last, "%6i%c", size, scale);
- + b->last = ngx_sprintf(b->last, "<td>%i%c</td>", size, scale);
- } else {
- - b->last = ngx_sprintf(b->last, " %6i", size);
- + b->last = ngx_sprintf(b->last, "<td>%i</td>", size);
- }
- }
- }
- - *b->last++ = CR;
- - *b->last++ = LF;
- + b->last = ngx_sprintf(b->last, "</tr>" CRLF);
- }
- - b->last = ngx_cpymem(b->last, "</pre><hr>", sizeof("</pre><hr>") - 1);
- + b->last = ngx_cpymem(b->last, "</table>", sizeof("</table>") - 1);
- b->last = ngx_cpymem(b->last, tail, sizeof(tail) - 1);