Merged weekend changes. Closes #201.

pull/4/head
Adrian Perez 2007-08-29 12:42:08 +02:00
commit d7129e30f9
7 changed files with 203 additions and 36 deletions

26
.todo Normal file
View File

@ -0,0 +1,26 @@
<todo version="0.1.19">
<note priority="medium" time="1187975642" done="1188304701">
readme:iframe
<comment>
done in r23
</comment>
</note>
<note priority="medium" time="1187975645">
readme:div
</note>
<note priority="medium" time="1187975648">
readme:pre
</note>
<note priority="medium" time="1187975662">
header:inline
</note>
<note priority="medium" time="1187975665">
header:cache
</note>
<note priority="medium" time="1187975708">
footer:inline
</note>
<note priority="medium" time="1187975712">
footer:cache
</note>
</todo>

View File

@ -32,7 +32,7 @@ Building
4. Build and install the software::
$ make
And then, as ``root``::
# make install
@ -130,6 +130,23 @@ fancyindex_readme_options
will instruct the client to perform an additional request in order to
fetch the contents of the frame.
fancyindex_mode
:Syntax: *fancyindex_mode* *static* | *cached*
:Default: *fancyindex_mode static*
:Context: http, server, location
:Description:
Controls how to include the header and footer specified by
`fancyindex_header`_ and `fancyindex_footer`_, Available options are:
static
Read file contents on each request. This is the less efficient method,
but generated content will always follow on-disk changes of head and
footer templates.
cached
Header and footer contents will be read the first time they are
needed, and kept in memory for thei use in subsequent requests. If the
modification time of files changes, they will be re-read as needed.
.. _nginx: http://nginx.net

View File

@ -36,13 +36,6 @@ typedef struct {
#endif
#define NGX_HTTP_FANCYINDEX_README_TOP 0x00
#define NGX_HTTP_FANCYINDEX_README_PRE 0x00
#define NGX_HTTP_FANCYINDEX_README_ASIS 0x01
#define NGX_HTTP_FANCYINDEX_README_BOTTOM 0x02
#define NGX_HTTP_FANCYINDEX_README_DIV 0x04
#define NGX_HTTP_FANCYINDEX_README_IFRAME 0x08
typedef struct {
ngx_str_t name;
@ -54,23 +47,46 @@ typedef struct {
} ngx_http_fancyindex_entry_t;
#define NGX_HTTP_FANCYINDEX_README_TOP 0x00
#define NGX_HTTP_FANCYINDEX_README_PRE 0x00
#define NGX_HTTP_FANCYINDEX_README_ASIS 0x01
#define NGX_HTTP_FANCYINDEX_README_BOTTOM 0x02
#define NGX_HTTP_FANCYINDEX_README_DIV 0x04
#define NGX_HTTP_FANCYINDEX_README_IFRAME 0x08
typedef enum {
NGX_HTTP_FANCYINDEX_INCLUDE_STATIC, /* Cache file contents on first request */
NGX_HTTP_FANCYINDEX_INCLUDE_CACHED, /* Cache file contents on first request,
and re-read if needed afterwards */
} ngx_http_fancyindex_include_mode_t;
typedef struct {
ngx_flag_t enable;
ngx_flag_t localtime;
ngx_flag_t exact_size;
ngx_flag_t enable;
ngx_flag_t localtime;
ngx_flag_t exact_size;
ngx_str_t header;
ngx_str_t footer;
ngx_str_t readme;
ngx_str_t header;
ngx_str_t footer;
ngx_str_t readme;
ngx_uint_t readme_flags;
ngx_uint_t readme_flags;
ngx_http_fancyindex_include_mode_t include_mode;
} ngx_http_fancyindex_loc_conf_t;
#define nfi_conf_path_set(_c, _n) ((_c)->((_n).len) > 0)
#define NGX_HTTP_FANCYINDEX_PREALLOCATE 50
#define NGX_HTTP_FANCYINDEX_NAME_LEN 50
static ngx_inline ngx_str_t
nfi_get_readme_path(ngx_http_request_t *r, const ngx_str_t *last);
static int ngx_libc_cdecl ngx_http_fancyindex_cmp_entries(const void *one,
const void *two);
static ngx_int_t ngx_http_fancyindex_error(ngx_http_request_t *r,
@ -82,7 +98,7 @@ static char *ngx_http_fancyindex_merge_loc_conf(ngx_conf_t *cf,
static ngx_conf_bitmask_t ngx_http_fancyindex_readme_flags[] = {
static const ngx_conf_bitmask_t ngx_http_fancyindex_readme_flags[] = {
{ ngx_string("pre"), NGX_HTTP_FANCYINDEX_README_PRE },
{ ngx_string("asis"), NGX_HTTP_FANCYINDEX_README_ASIS },
{ ngx_string("top"), NGX_HTTP_FANCYINDEX_README_TOP },
@ -93,6 +109,14 @@ static ngx_conf_bitmask_t ngx_http_fancyindex_readme_flags[] = {
};
static const ngx_conf_enum_t ngx_http_fancyindex_include_modes[] = {
{ ngx_string("static"), NGX_HTTP_FANCYINDEX_INCLUDE_STATIC },
{ ngx_string("cached"), NGX_HTTP_FANCYINDEX_INCLUDE_CACHED },
{ ngx_null_string, 0 },
};
static ngx_command_t ngx_http_fancyindex_commands[] = {
{ ngx_string("fancyindex"),
@ -144,6 +168,13 @@ static ngx_command_t ngx_http_fancyindex_commands[] = {
offsetof(ngx_http_fancyindex_loc_conf_t, readme_flags),
&ngx_http_fancyindex_readme_flags },
{ ngx_string("fancyindex_mode"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_enum_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_fancyindex_loc_conf_t, include_mode),
&ngx_http_fancyindex_include_modes },
ngx_null_command
};
@ -192,6 +223,7 @@ ngx_http_fancyindex_handler(ngx_http_request_t *r)
ngx_buf_t *b;
ngx_int_t rc, size;
ngx_str_t path;
ngx_str_t readme_path;
ngx_dir_t dir;
ngx_uint_t i, level;
ngx_pool_t *pool;
@ -264,11 +296,9 @@ ngx_http_fancyindex_handler(ngx_http_request_t *r)
}
#if (NGX_SUPPRESS_WARN)
/* MSVC thinks 'entries' may be used without having been initialized */
ngx_memzero(&entries, sizeof(ngx_array_t));
#endif
#endif /* NGX_SUPPRESS_WARN */
/* TODO: pool should be temporary pool */
pool = r->pool;
@ -391,6 +421,29 @@ ngx_http_fancyindex_handler(ngx_http_request_t *r)
+ r->uri.len /* HTML head and as an <h1> in the HTML body */
;
/*
* If including an <iframe> for the readme file, add the length of the
* URI, plus the length of the readme file name and the length of the
* needed markup.
*/
readme_path = nfi_get_readme_path(r, &path);
if (readme_path.len == 0) goto skip_readme_len;
if (nfi_has_flag(alcf->readme_flags, NGX_HTTP_FANCYINDEX_README_IFRAME)) {
len += 3 /* CR+LF+'/' */
+ nfi_sizeof_ssz("<iframe id=\"readme\" src=\"")
+ r->uri.len + alcf->readme.len
+ nfi_sizeof_ssz("\">(readme file)</iframe>")
;
}
else {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"fancyindex: bad readme_flags combination %#x",
alcf->readme_flags);
}
skip_readme_len:
entry = entries.elts;
for (i = 0; i < entries.nelts; i++) {
/*
@ -435,6 +488,32 @@ ngx_http_fancyindex_handler(ngx_http_request_t *r)
b->last = nfi_cpymem_str(b->last, r->uri);
b->last = nfi_cpymem_ssz(b->last, t04_body2);
/* Insert readme at top, if appropriate */
if ((readme_path.len == 0) ||
!nfi_has_flag(alcf->readme_flags, NGX_HTTP_FANCYINDEX_README_TOP))
goto skip_readme_top;
#define nfi_add_readme_iframe( ) \
do { \
b->last = nfi_cpymem_ssz(b->last, "<iframe id=\"readme\" src=\""); \
b->last = nfi_cpymem_str(b->last, r->uri); \
*b->last++ = '/'; \
b->last = nfi_cpymem_str(b->last, alcf->readme); \
b->last = nfi_cpymem_ssz(b->last, "\">(readme file)</iframe>"); \
*b->last++ = CR; \
*b->last++ = LF; \
} while (0)
if (nfi_has_flag(alcf->readme_flags, NGX_HTTP_FANCYINDEX_README_IFRAME))
nfi_add_readme_iframe();
else {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"fancyindex: bad readme_flags combination %#x",
alcf->readme_flags);
}
skip_readme_top:
/* Output table header */
b->last = nfi_cpymem_ssz(b->last, t05_list1);
@ -572,6 +651,21 @@ ngx_http_fancyindex_handler(ngx_http_request_t *r)
* TODO: Output readme
*/
b->last = nfi_cpymem_ssz(b->last, t07_body3);
/* Insert readme at bottom, if appropriate */
if ((readme_path.len == 0) ||
!nfi_has_flag(alcf->readme_flags, NGX_HTTP_FANCYINDEX_README_BOTTOM))
goto skip_readme_bottom;
if (nfi_has_flag(alcf->readme_flags, NGX_HTTP_FANCYINDEX_README_IFRAME))
nfi_add_readme_iframe();
else {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"fancyindex: bad readme_flags combination %#x",
alcf->readme_flags);
}
skip_readme_bottom:
b->last = nfi_cpymem_ssz(b->last, t08_body4);
/* Output page footer */
@ -648,6 +742,32 @@ ngx_http_fancyindex_alloc(ngx_http_fancyindex_ctx_t *ctx, size_t size)
#endif
static ngx_inline ngx_str_t
nfi_get_readme_path(ngx_http_request_t *r, const ngx_str_t *path)
{
u_char *last;
ngx_file_info_t info;
ngx_str_t fullpath = ngx_null_string;
ngx_http_fancyindex_loc_conf_t *alcf =
ngx_http_get_module_loc_conf(r, ngx_http_fancyindex_module);
if (alcf->readme.len == 0) /* Readme files are disabled */
return fullpath;
fullpath.len = path->len + 2 + alcf->readme.len;
fullpath.data = ngx_palloc(r->pool, fullpath.len);
last = nfi_cpymem_str(fullpath.data, *path); *last++ = '/';
last = nfi_cpymem_str(last, alcf->readme); *last++ = '\0';
/* File does not exists, or cannot be accessed */
if (ngx_file_info(fullpath.data, &info) != 0)
fullpath.len = 0;
return fullpath;
}
static ngx_int_t
ngx_http_fancyindex_error(ngx_http_request_t *r, ngx_dir_t *dir, ngx_str_t *name)
{
@ -683,6 +803,7 @@ ngx_http_fancyindex_create_loc_conf(ngx_conf_t *cf)
conf->localtime = NGX_CONF_UNSET;
conf->exact_size = NGX_CONF_UNSET;
conf->readme_flags = NGX_CONF_UNSET;
conf->include_mode = NGX_CONF_UNSET;
return conf;
}
@ -697,6 +818,8 @@ ngx_http_fancyindex_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
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->include_mode, prev->include_mode,
NGX_HTTP_FANCYINDEX_INCLUDE_STATIC);
ngx_conf_merge_str_value(conf->header, prev->header, "");
ngx_conf_merge_str_value(conf->footer, prev->footer, "");

View File

@ -34,6 +34,9 @@
#define nfi_maybe_cpymem_ssz(__p, __t) \
if ((__t)[0] != '\0') nfi_cpymem_ssz((__p), (__t))
#define nfi_has_flag(_where, _what) \
(((_where) & (_what)) == (_what))
#endif /* !__ngx_http_fancyindex_module_h__ */
/* vim:ft=c
*/

View File

@ -28,7 +28,7 @@ BEGIN {
{
if (!varname) next;
# Order matters
gsub(/[\t\v\n\r\f\g]+/, "");
gsub(/[\t\v\n\r\f]+/, "");
gsub(/\\/, "\\\\");
gsub(/"/, "\\\"");
print "\"" $0 "\""

View File

@ -1,24 +1,23 @@
/* Automagically generated, do not edit! */
static const u_char t01_head1[] = ""
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
"\"http://www.w3.or/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
"<html xmlns=\"http://www.w3.or/1999/xhtml\">"
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
"<html xmlns=\"http://www.w3.org/1999/xhtml\">"
"<head>"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>"
"<style type=\"text/css\">"
"body,html {"
"backround:#fff;"
"background:#fff;"
"}"
"tr.o {"
"backround:#f4f4f4;"
"background:#f4f4f4;"
"}"
"th,td {"
"paddin:0.1em 0.5em;"
"padding:0.1em 0.5em;"
"}"
"th {"
"text-alin:left;"
"font-weiht:bold;"
"backround:#eee;"
"text-align:left;"
"font-weight:bold;"
"background:#eee;"
"border-bottom:1px solid #aaa;"
"}"
"#list {"
@ -46,12 +45,12 @@ static const u_char t04_body2[] = ""
"</h1>"
;
static const u_char t05_list1[] = ""
"<table id=\"list\" cellpaddin=\"0.1em\" cellspacin=\"0\">"
"<colroup>"
"<table id=\"list\" cellpadding=\"0.1em\" cellspacing=\"0\">"
"<colgroup>"
"<col width=\"55%\"/>"
"<col width=\"20%\"/>"
"<col width=\"25%\"/>"
"</colroup>"
"</colgroup>"
"<thead>"
"<tr>"
"<th>File Name</th>"
@ -61,7 +60,7 @@ static const u_char t05_list1[] = ""
"</thead>"
"<tbody>"
"<tr class=\"e\">"
"<td><a href=\"../\">Parent Directory</a></td>"
"<td><a href=\"../\">Parent directory/</a></td>"
"<td>-</td>"
"<td>-</td>"
"</tr>"

View File

@ -1,6 +1,5 @@
<!-- var t01_head1 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
@ -60,7 +59,7 @@
</thead>
<tbody>
<tr class="e">
<td><a href="../">Parent Directory</a></td>
<td><a href="../">Parent directory/</a></td>
<td>-</td>
<td>-</td>
</tr>