[PATCH] HTTP: Add 'autoindex_max_length' directive
sfan5
sfan5 at live.de
Sun Mar 30 15:54:43 UTC 2014
# HG changeset patch
# User sfan5 <sfan5 at live.de>
# Date 1396194835 -7200
# Sun Mar 30 17:53:55 2014 +0200
# Node ID 35328d85f9b629e3593b1f862af61af9bd743b3f
# Parent a24f88eff684889a203b04e8be70ce0e3899dc30
HTTP: Add 'autoindex_max_length' directive
The 'autoindex_max_length' directive controls the length after which a
filename is cut-off by the http_autoindex module.
diff -r a24f88eff684 -r 35328d85f9b6
src/http/modules/ngx_http_autoindex_module.c
--- a/src/http/modules/ngx_http_autoindex_module.c Fri Mar 28
20:22:57 2014 +0400
+++ b/src/http/modules/ngx_http_autoindex_module.c Sun Mar 30
17:53:55 2014 +0200
@@ -40,13 +40,12 @@
ngx_flag_t enable;
ngx_flag_t localtime;
ngx_flag_t exact_size;
+ ngx_uint_t max_length;
} ngx_http_autoindex_loc_conf_t;
#define NGX_HTTP_AUTOINDEX_PREALLOCATE 50
-#define NGX_HTTP_AUTOINDEX_NAME_LEN 50
-
static int ngx_libc_cdecl ngx_http_autoindex_cmp_entries(const void *one,
const void *two);
@@ -81,6 +80,13 @@
offsetof(ngx_http_autoindex_loc_conf_t, exact_size),
NULL },
+ { ngx_string("autoindex_max_length"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_num_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_autoindex_loc_conf_t, max_length),
+ NULL },
+
ngx_null_command
};
@@ -380,7 +386,7 @@
+ sizeof("\">") - 1
+ entry[i].name.len - entry[i].utf_len
+ entry[i].escape_html
- + NGX_HTTP_AUTOINDEX_NAME_LEN + sizeof(">") - 2
+ + alcf->max_length + sizeof(">") - 2
+ sizeof("</a>") - 1
+ sizeof(" 28-Sep-1970 12:00 ") - 1
+ 20 /* the file
size */
@@ -442,11 +448,11 @@
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;
+ if (len > alcf->max_length) {
+ char_len = alcf->max_length - 3 + 1;
} else {
- char_len = NGX_HTTP_AUTOINDEX_NAME_LEN + 1;
+ char_len = alcf->max_length + 1;
}
last = b->last;
@@ -462,8 +468,8 @@
} else {
if (entry[i].escape_html) {
- if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) {
- char_len = NGX_HTTP_AUTOINDEX_NAME_LEN - 3;
+ if (len > alcf->max_length) {
+ char_len = alcf->max_length - 3;
} else {
char_len = len;
@@ -475,25 +481,25 @@
} else {
b->last = ngx_cpystrn(b->last, entry[i].name.data,
- NGX_HTTP_AUTOINDEX_NAME_LEN + 1);
+ alcf->max_length + 1);
last = b->last - 3;
}
}
- if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) {
+ if (len > alcf->max_length) {
b->last = ngx_cpymem(last, "..></a>",
sizeof("..></a>") - 1);
} else {
- if (entry[i].dir && NGX_HTTP_AUTOINDEX_NAME_LEN - len > 0) {
+ if (entry[i].dir && alcf->max_length - 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 (alcf->max_length - len > 0) {
+ ngx_memset(b->last, ' ', alcf->max_length - len);
+ b->last += alcf->max_length - len;
}
}
@@ -667,6 +673,7 @@
conf->enable = NGX_CONF_UNSET;
conf->localtime = NGX_CONF_UNSET;
conf->exact_size = NGX_CONF_UNSET;
+ conf->max_length = NGX_CONF_UNSET_UINT;
return conf;
}
@@ -681,6 +688,7 @@
ngx_conf_merge_value(conf->enable, prev->enable, 0);
ngx_conf_merge_value(conf->localtime, prev->localtime, 0);
ngx_conf_merge_value(conf->exact_size, prev->exact_size, 1);
+ ngx_conf_merge_uint_value(conf->max_length, prev->max_length, 50);
return NGX_CONF_OK;
}
More information about the nginx-devel
mailing list