21 } ngx_http_autoindex_ctx_t;
46 #define NGX_HTTP_AUTOINDEX_PREALLOCATE 50
48 #define NGX_HTTP_AUTOINDEX_NAME_LEN 50
51 static int ngx_libc_cdecl ngx_http_autoindex_cmp_entries(
const void *one,
56 static void *ngx_http_autoindex_create_loc_conf(
ngx_conf_t *cf);
57 static char *ngx_http_autoindex_merge_loc_conf(
ngx_conf_t *cf,
58 void *parent,
void *child);
90 ngx_http_autoindex_init,
98 ngx_http_autoindex_create_loc_conf,
99 ngx_http_autoindex_merge_loc_conf
105 &ngx_http_autoindex_module_ctx,
106 ngx_http_autoindex_commands,
119 static u_char title[] =
121 "<head><title>Index of "
125 static u_char header[] =
126 "</title></head>" CRLF
127 "<body bgcolor=\"white\">" CRLF
131 static u_char tail[] =
140 u_char *last, *filename, scale;
142 size_t len, char_len, escape_html, allocated, root;
157 static char *months[] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
158 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" };
182 allocated = path.
len;
190 "http autoindex: \"%s\"", path.
data);
217 #if (NGX_SUPPRESS_WARN)
230 return ngx_http_autoindex_error(r, &dir, &path);
248 filename = path.
data;
249 filename[path.
len] =
'/';
270 return ngx_http_autoindex_error(r, &dir, &path);
289 if (path.
len + 1 + len + 1 > allocated) {
290 allocated = path.
len + 1 + len + 1
294 if (filename == NULL) {
295 return ngx_http_autoindex_error(r, &dir, &path);
315 return ngx_http_autoindex_error(r, &dir, &path);
322 return ngx_http_autoindex_error(r, &dir, &path);
329 return ngx_http_autoindex_error(r, &dir, &path);
336 return ngx_http_autoindex_error(r, &dir, &path);
365 len =
sizeof(title) - 1
366 + r->
uri.
len + escape_html
368 + r->
uri.
len + escape_html
369 +
sizeof(
"</h1>") - 1
370 +
sizeof(
"<hr><pre><a href=\"../\">../</a>" CRLF) - 1
371 +
sizeof(
"</pre><hr>") - 1
374 entry = entries.
elts;
375 for (i = 0; i < entries.
nelts; i++) {
376 len +=
sizeof(
"<a href=\"") - 1
377 + entry[i].name.len + entry[i].
escape
384 +
sizeof(
" 28-Sep-1970 12:00 ") - 1
394 if (entries.
nelts > 1) {
397 ngx_http_autoindex_cmp_entries);
416 sizeof(
"<hr><pre><a href=\"../\">../</a>" CRLF) - 1);
420 for (i = 0; i < entries.
nelts; i++) {
423 if (entry[i].escape) {
443 if (entry[i].name.len != len) {
453 char_len, entry[i].
name.
len + 1);
455 if (entry[i].escape_html) {
463 if (entry[i].escape_html) {
483 b->
last =
ngx_cpymem(last,
"..></a>",
sizeof(
"..></a>") - 1);
505 months[tm.ngx_tm_mon - 1],
524 length = entry[
i].
size;
526 if (length > 1024 * 1024 * 1024 - 1) {
527 size = (
ngx_int_t) (length / (1024 * 1024 * 1024));
528 if ((length % (1024 * 1024 * 1024))
529 > (1024 * 1024 * 1024 / 2 - 1))
535 }
else if (length > 1024 * 1024 - 1) {
536 size = (
ngx_int_t) (length / (1024 * 1024));
537 if ((length % (1024 * 1024)) > (1024 * 1024 / 2 - 1)) {
542 }
else if (length > 9999) {
544 if (length % 1024 > 511) {
587 ngx_http_autoindex_cmp_entries(
const void *one,
const void *two)
592 if (first->
dir && !second->
dir) {
597 if (!first->
dir && second->
dir) {
609 ngx_http_autoindex_alloc(ngx_http_autoindex_ctx_t *ctx,
size_t size)
615 if ((
size_t) (ctx->buf->end - ctx->buf->last) >= size) {
619 ctx->size += ctx->buf->
last - ctx->buf->pos;
623 if (ctx->buf == NULL) {
636 ctx->last_out = &cl->
next;
657 ngx_http_autoindex_create_loc_conf(
ngx_conf_t *cf)
675 ngx_http_autoindex_merge_loc_conf(
ngx_conf_t *cf,
void *parent,
void *child)
701 *h = ngx_http_autoindex_handler;