diff --git a/HACKING.rst b/HACKING.rst new file mode 100644 index 0000000..b31d5fe --- /dev/null +++ b/HACKING.rst @@ -0,0 +1,44 @@ +=================================== + Fancy Index module Hacking HOW-TO +=================================== + +.. contents:: + + +How to modify templates +======================= + +Templates are in the ``templates/`` subdirectory of the source distribution. +They are included both as regular HTML text snippets (files ending in ``.t``) +and ready for inclusion in a C program (files ending in ``.inc``). Also +there is a small C program + + +Template order +~~~~~~~~~~~~~~ +01-head1 + Outputs the HTML header and must end with something like + ``Index of``, because the code inserts the path of the URI just + after this piece. +02-head2 + Outputs the rest of the header, usually will close the ```` tag + opened in the previous template and add further output until the closing + ```` tag. +03-body1 + - +04-body2 + - +05-list1 + - +06-list2 + - +07-body3 + - +08-body4 + - +09-foot1 + - + + +.. vim: spell spelllang=en expandtab + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9fd66ee --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. diff --git a/ngx_http_fancyindex_module.c b/ngx_http_fancyindex_module.c index b59c6e9..35f4c3e 100644 --- a/ngx_http_fancyindex_module.c +++ b/ngx_http_fancyindex_module.c @@ -1,6 +1,6 @@ /* * ngx_http_fancyindex_module.c - * Copyright (C) 2007 Adrian Perez + * Copyright © 2007 Adrian Perez * * Module used for fancy indexing of directories. Features and differences * with the stock nginx autoindex module: @@ -13,9 +13,10 @@ * - Proper HTML is generated: it should validate both as XHTML 1.0 Strict * and HTML 4.01. * - * Base functionality heavy based upon the stock nginx autoindex module. + * Base functionality heavy based upon the stock nginx autoindex module, + * which in turn was made by Igor Sysoev, like the majority of nginx. * - * Distributed under terms of the MIT license. + * Distributed under terms of the BSD license. */ #include @@ -178,22 +179,7 @@ ngx_module_t ngx_http_fancyindex_module = { }; -static u_char title[] = -"" CRLF -"Index of " -; - - -static u_char header[] = -"" CRLF -"" CRLF -"

Index of " -; - -static u_char tail[] = -"" CRLF -"" CRLF -; +#include "templates/templates.inc" static ngx_int_t @@ -402,14 +388,12 @@ ngx_http_fancyindex_handler(ngx_http_request_t *r) ngx_close_dir_n " \"%s\" failed", &path); } - len = sizeof(title) - 1 + len = NGX_HTTP_FANCYINDEX_TEMPLATE_SIZE + r->uri.len - + sizeof(header) - 1 + r->uri.len + sizeof("

") - 1 + sizeof("
../" CRLF) - 1
-          + sizeof("

") - 1 - + sizeof(tail) - 1; + + sizeof("
") - 1; entry = entries.elts; for (i = 0; i < entries.nelts; i++) { @@ -436,10 +420,13 @@ ngx_http_fancyindex_handler(ngx_http_request_t *r) ngx_http_fancyindex_cmp_entries); } - b->last = ngx_cpymem(b->last, title, sizeof(title) - 1); + b->last = ngx_cpymem(b->last, t01_head1, sizeof(t01_head1) - 1); b->last = ngx_cpymem(b->last, r->uri.data, r->uri.len); - b->last = ngx_cpymem(b->last, header, sizeof(header) - 1); + b->last = ngx_cpymem(b->last, t02_head2, sizeof(t02_head2) - 1); + + b->last = ngx_cpymem(b->last, t03_body1, sizeof(t03_body1) - 1); b->last = ngx_cpymem(b->last, r->uri.data, r->uri.len); + b->last = ngx_cpymem(b->last, t03_body1, sizeof(t03_body1) - 1); b->last = ngx_cpymem(b->last, "", sizeof("") - 1); b->last = ngx_cpymem(b->last, "
../" CRLF,
@@ -573,7 +560,7 @@ ngx_http_fancyindex_handler(ngx_http_request_t *r)
 
     b->last = ngx_cpymem(b->last, "

", sizeof("
") - 1); - b->last = ngx_cpymem(b->last, tail, sizeof(tail) - 1); + b->last = ngx_cpymem(b->last, t09_foot1, sizeof(t09_foot1) - 1); if (r == r->main) { b->last_buf = 1; diff --git a/templates/before-title.inc b/templates/01-head1.inc similarity index 96% rename from templates/before-title.inc rename to templates/01-head1.inc index b99276f..63c409b 100644 --- a/templates/before-title.inc +++ b/templates/01-head1.inc @@ -3,4 +3,4 @@ "99/xhtml\"><" "meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>" +"le>Index of " diff --git a/templates/before-title.t b/templates/01-head1.t similarity index 95% rename from templates/before-title.t rename to templates/01-head1.t index 177228c..2f62c69 100644 --- a/templates/before-title.t +++ b/templates/01-head1.t @@ -15,4 +15,4 @@ } - + <title>Index of diff --git a/templates/02-head2.inc b/templates/02-head2.inc new file mode 100644 index 0000000..1608ceb --- /dev/null +++ b/templates/02-head2.inc @@ -0,0 +1 @@ +"" diff --git a/templates/after-title.t b/templates/02-head2.t similarity index 57% rename from templates/after-title.t rename to templates/02-head2.t index 7d60701..aa643e8 100644 --- a/templates/after-title.t +++ b/templates/02-head2.t @@ -1,4 +1,2 @@ - -

diff --git a/templates/03-body1.inc b/templates/03-body1.inc new file mode 100644 index 0000000..a0bf4d4 --- /dev/null +++ b/templates/03-body1.inc @@ -0,0 +1 @@ +"

" diff --git a/templates/03-body1.t b/templates/03-body1.t new file mode 100644 index 0000000..ee48479 --- /dev/null +++ b/templates/03-body1.t @@ -0,0 +1,2 @@ + +

diff --git a/templates/04-body2.inc b/templates/04-body2.inc new file mode 100644 index 0000000..41afb01 --- /dev/null +++ b/templates/04-body2.inc @@ -0,0 +1 @@ +"

" diff --git a/templates/04-body2.t b/templates/04-body2.t new file mode 100644 index 0000000..d210ccf --- /dev/null +++ b/templates/04-body2.t @@ -0,0 +1 @@ + diff --git a/templates/05-list1.inc b/templates/05-list1.inc new file mode 100644 index 0000000..322797e --- /dev/null +++ b/templates/05-list1.inc @@ -0,0 +1,4 @@ +"" diff --git a/templates/before-listing.t b/templates/05-list1.t similarity index 75% rename from templates/before-listing.t rename to templates/05-list1.t index 4b7d2fc..8ccc5e1 100644 --- a/templates/before-listing.t +++ b/templates/05-list1.t @@ -1,4 +1,3 @@ -
File Name" +"File SizeDate
Parent Directory
@@ -13,3 +12,6 @@ + + + diff --git a/templates/06-list2.inc b/templates/06-list2.inc new file mode 100644 index 0000000..634832b --- /dev/null +++ b/templates/06-list2.inc @@ -0,0 +1 @@ +"
Parent Directory
" diff --git a/templates/06-list2.t b/templates/06-list2.t new file mode 100644 index 0000000..da8b0a0 --- /dev/null +++ b/templates/06-list2.t @@ -0,0 +1,2 @@ + + diff --git a/templates/07-body3.inc b/templates/07-body3.inc new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/templates/07-body3.inc @@ -0,0 +1 @@ +"" diff --git a/templates/07-body3.t b/templates/07-body3.t new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/templates/07-body3.t @@ -0,0 +1 @@ + diff --git a/templates/08-body4.inc b/templates/08-body4.inc new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/templates/08-body4.inc @@ -0,0 +1 @@ +"" diff --git a/templates/08-body4.t b/templates/08-body4.t new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/templates/08-body4.t @@ -0,0 +1 @@ + diff --git a/templates/09-foot1.inc b/templates/09-foot1.inc new file mode 100644 index 0000000..5df4a51 --- /dev/null +++ b/templates/09-foot1.inc @@ -0,0 +1 @@ +"" diff --git a/templates/09-foot1.t b/templates/09-foot1.t new file mode 100644 index 0000000..7fb2bd6 --- /dev/null +++ b/templates/09-foot1.t @@ -0,0 +1,2 @@ + + diff --git a/templates/after-listing.inc b/templates/after-listing.inc deleted file mode 100644 index 8d0ff82..0000000 --- a/templates/after-listing.inc +++ /dev/null @@ -1 +0,0 @@ -"" diff --git a/templates/after-listing.t b/templates/after-listing.t deleted file mode 100644 index c8d5db3..0000000 --- a/templates/after-listing.t +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/templates/after-title.inc b/templates/after-title.inc deleted file mode 100644 index cec6cd8..0000000 --- a/templates/after-title.inc +++ /dev/null @@ -1 +0,0 @@ -"

" diff --git a/templates/before-listing.inc b/templates/before-listing.inc deleted file mode 100644 index 067b633..0000000 --- a/templates/before-listing.inc +++ /dev/null @@ -1,3 +0,0 @@ -"

" diff --git a/templates/templates.inc b/templates/templates.inc new file mode 100644 index 0000000..1ad9cc8 --- /dev/null +++ b/templates/templates.inc @@ -0,0 +1,33 @@ + +#ifndef __templates_inc__ +#define __templates_inc__ + +static const u_char t01_head1[] = +#include "01-head1.inc" +; +static const u_char t02_head2[] = +#include "02-head2.inc" +; +static const u_char t03_body1[] = +#include "03-body1.inc" +; +static const u_char t04_body2[] = +#include "04-body2.inc" +; + + +static const u_char t09_foot1[] = +#include "09-foot1.inc" +; + +#define NGX_HTTP_FANCYINDEX_TEMPLATE_SIZE \ + ( (sizeof(t01_head1) - 1) \ + + (sizeof(t02_head2) - 1) \ + + (sizeof(t03_body1) - 1) \ + + (sizeof(t04_body2) - 1) \ + \ + + (sizeof(t09_foot1) - 1) ) + +#endif /* !__templates_inc__ */ +/* vim:ft=c + */
File NameFile SizeDate