coar 97/07/15 08:51:12
Modified: src CHANGES mod_autoindex.c
Log:
Add IndexOptions SuppressHTMLPreamble, which tells the module
*not* to generate the <HTML>, <HEAD>, and so IFF there's an
header file in the directory.
Submitted by: <[EMAIL PROTECTED]> (reworking done)
Revision Changes Path
1.336 +5 -0 apache/src/CHANGES
Index: CHANGES
===================================================================
RCS file: /export/home/cvs/apache/src/CHANGES,v
retrieving revision 1.335
retrieving revision 1.336
diff -C3 -r1.335 -r1.336
*** CHANGES 1997/07/14 11:28:54 1.335
--- CHANGES 1997/07/15 15:51:08 1.336
***************
*** 1,5 ****
--- 1,10 ----
Changes with Apache 1.3
+ *) IndexOptions SuppressHTMLPreamble now causes the actual HTML of
+ directory indices to start with the contents of the HeaderName file
+ if there is one. If there isn't one, the behaviour is unchanged.
+ [Ken Coar, based upon code and an idea submitted by <[EMAIL
PROTECTED]>]
+
*) On Win32, modules can now be dynamically loaded DLLs using the
LoadModule/LoadFile directives. Note that module DLLs must be
compiled with the multithreaded DLL version of the runtime library.
1.37 +329 -281 apache/src/mod_autoindex.c
Index: mod_autoindex.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_autoindex.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -C3 -r1.36 -r1.37
*** mod_autoindex.c 1997/07/15 07:33:29 1.36
--- mod_autoindex.c 1997/07/15 15:51:09 1.37
***************
*** 75,86 ****
* Handling configuration directives...
*/
! #define FANCY_INDEXING 1 /* Indexing options */
#define ICONS_ARE_LINKS 2
#define SCAN_HTML_TITLES 4
#define SUPPRESS_LAST_MOD 8
#define SUPPRESS_SIZE 16
#define SUPPRESS_DESC 32
/*
* These are the dimensions of the default icons supplied with Apache.
--- 75,92 ----
* Handling configuration directives...
*/
! #define HRULE 1
! #define NO_HRULE 0
! #define FRONT_MATTER 1
! #define END_MATTER 0
!
! #define FANCY_INDEXING 1 /* Indexing options */
#define ICONS_ARE_LINKS 2
#define SCAN_HTML_TITLES 4
#define SUPPRESS_LAST_MOD 8
#define SUPPRESS_SIZE 16
#define SUPPRESS_DESC 32
+ #define SUPPRESS_PREAMBLE 64
/*
* These are the dimensions of the default icons supplied with Apache.
***************
*** 112,117 ****
--- 118,141 ----
#define BY_TYPE &c_by_type
#define BY_PATH &c_by_path
+ /*
+ * This routine puts the standard HTML header at the top of the index page.
+ * We include the DOCTYPE because we may be using features therefrom (i.e.,
+ * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
+ */
+ static void emit_preamble(request_rec *r, char *title)
+ {
+ rvputs
+ (
+ r,
+ "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n",
+ "<HTML>\n <HEAD>\n <TITLE>Index of ",
+ title,
+ "</TITLE>\n </HEAD>\n <BODY>\n",
+ NULL
+ );
+ }
+
static void push_item(array_header *arr, char *type, char *to, char *path,
char *data)
{
***************
*** 124,130 ****
p->data = data ? pstrdup(arr->pool, data): NULL;
p->apply_path = pstrcat(arr->pool, path, "*", NULL);
! if((type == BY_PATH) && (!is_matchexp(to)))
p->apply_to = pstrcat (arr->pool, "*", to, NULL);
else if (to)
p->apply_to = pstrdup (arr->pool, to);
--- 148,154 ----
p->data = data ? pstrdup(arr->pool, data): NULL;
p->apply_path = pstrcat(arr->pool, path, "*", NULL);
! if ((type == BY_PATH) && (!is_matchexp(to)))
p->apply_to = pstrcat (arr->pool, "*", to, NULL);
else if (to)
p->apply_to = pstrdup (arr->pool, to);
***************
*** 135,141 ****
static const char *add_alt(cmd_parms *cmd, void *d, char *alt, char *to)
{
if (cmd->info == BY_PATH)
! if(!strcmp(to,"**DIRECTORY**"))
to = "^^DIRECTORY^^";
push_item(((autoindex_config_rec *)d)->alt_list, cmd->info, to,
cmd->path, alt);
--- 159,165 ----
static const char *add_alt(cmd_parms *cmd, void *d, char *alt, char *to)
{
if (cmd->info == BY_PATH)
! if (!strcmp(to, "**DIRECTORY**"))
to = "^^DIRECTORY^^";
push_item(((autoindex_config_rec *)d)->alt_list, cmd->info, to,
cmd->path, alt);
***************
*** 146,196 ****
{
char *iconbak = pstrdup (cmd->pool, icon);
! if(icon[0] == '(') {
char *alt = getword_nc (cmd->pool, &iconbak, ',');
iconbak[strlen(iconbak) - 1] = '\0'; /* Lose closing paren */
add_alt(cmd, d, &alt[1], to);
}
! if(cmd->info == BY_PATH)
! if(!strcmp(to,"**DIRECTORY**"))
to = "^^DIRECTORY^^";
push_item(((autoindex_config_rec *)d)->icon_list, cmd->info, to,
cmd->path,
! iconbak);
return NULL;
}
static const char *add_desc(cmd_parms *cmd, void *d, char *desc, char *to)
{
! push_item(((autoindex_config_rec *)d)->desc_list, cmd->info, to,
cmd->path,desc);
return NULL;
}
! static const char *add_ignore(cmd_parms *cmd, void *d, char *ext) {
push_item(((autoindex_config_rec *)d)->ign_list, 0, ext, cmd->path,
NULL);
return NULL;
}
! static const char *add_header(cmd_parms *cmd, void *d, char *name) {
if (strchr (name, '/')) {
! return "HeaderName cannot contain a /";
}
push_item(((autoindex_config_rec *)d)->hdr_list, 0, NULL, cmd->path,
name);
return NULL;
}
! static const char *add_readme(cmd_parms *cmd, void *d, char *name) {
if (strchr (name, '/')) {
! return "ReadmeName cannot contain a /";
}
push_item(((autoindex_config_rec *)d)->rdme_list, 0, NULL, cmd->path,
name);
return NULL;
}
! static const char *add_opts_int(cmd_parms *cmd, void *d, int opts) {
push_item(((autoindex_config_rec *)d)->opts_list, (char*)opts, NULL,
! cmd->path, NULL);
return NULL;
}
--- 170,231 ----
{
char *iconbak = pstrdup (cmd->pool, icon);
! if (icon[0] == '(') {
char *alt = getword_nc (cmd->pool, &iconbak, ',');
iconbak[strlen(iconbak) - 1] = '\0'; /* Lose closing paren */
add_alt(cmd, d, &alt[1], to);
}
! if (cmd->info == BY_PATH)
! if (!strcmp(to, "**DIRECTORY**"))
to = "^^DIRECTORY^^";
push_item(((autoindex_config_rec *)d)->icon_list, cmd->info, to,
cmd->path,
! iconbak);
return NULL;
}
static const char *add_desc(cmd_parms *cmd, void *d, char *desc, char *to)
{
! push_item
! (
! ((autoindex_config_rec *) d)->desc_list,
! cmd->info,
! to,
! cmd->path,
! desc
! );
return NULL;
}
! static const char *add_ignore(cmd_parms *cmd, void *d, char *ext)
! {
push_item(((autoindex_config_rec *)d)->ign_list, 0, ext, cmd->path,
NULL);
return NULL;
}
! static const char *add_header(cmd_parms *cmd, void *d, char *name)
! {
if (strchr (name, '/')) {
! return "HeaderName cannot contain a /";
}
push_item(((autoindex_config_rec *)d)->hdr_list, 0, NULL, cmd->path,
name);
return NULL;
}
! static const char *add_readme(cmd_parms *cmd, void *d, char *name)
! {
if (strchr (name, '/')) {
! return "ReadmeName cannot contain a /";
}
push_item(((autoindex_config_rec *)d)->rdme_list, 0, NULL, cmd->path,
name);
return NULL;
}
! static const char *add_opts_int(cmd_parms *cmd, void *d, int opts)
! {
push_item(((autoindex_config_rec *)d)->opts_list, (char*)opts, NULL,
! cmd->path, NULL);
return NULL;
}
***************
*** 204,251 ****
int opts = 0;
autoindex_config_rec *d_cfg = (autoindex_config_rec *) d;
! while(optstr[0]) {
w = getword_conf(cmd->pool, &optstr);
! if(!strcasecmp(w,"FancyIndexing"))
opts |= FANCY_INDEXING;
! else if(!strcasecmp(w,"IconsAreLinks"))
opts |= ICONS_ARE_LINKS;
! else if(!strcasecmp(w,"ScanHTMLTitles"))
opts |= SCAN_HTML_TITLES;
! else if(!strcasecmp(w,"SuppressLastModified"))
opts |= SUPPRESS_LAST_MOD;
! else if(!strcasecmp(w,"SuppressSize"))
opts |= SUPPRESS_SIZE;
! else if(!strcasecmp(w,"SuppressDescription"))
opts |= SUPPRESS_DESC;
! else if(!strcasecmp(w,"None"))
opts = 0;
! else if (! strncasecmp (w, "IconWidth", 9)) {
! if (strchr (w, '=') != NULL) {
! const char *x = pstrdup (cmd->pool, w);
! char *val;
! val = getword (cmd->pool, &x, '=');
! val = getword (cmd->pool, &x, '=');
! d_cfg->icon_width = atoi(val);
! }
! else {
! d_cfg->icon_width = DEFAULT_ICON_WIDTH;
! }
! }
! else if (! strncasecmp (w, "IconHeight", 10)) {
! if (strchr (w, '=') != NULL) {
! const char *x = pstrdup (cmd->pool, w);
! char *val;
! val = getword (cmd->pool, &x, '=');
! val = getword (cmd->pool, &x, '=');
! d_cfg->icon_height = atoi(val);
! }
! else {
! d_cfg->icon_height = DEFAULT_ICON_HEIGHT;
! }
! }
! else
! return "Invalid directory indexing option";
}
return add_opts_int(cmd, d, opts);
}
--- 239,288 ----
int opts = 0;
autoindex_config_rec *d_cfg = (autoindex_config_rec *) d;
! while (optstr[0]) {
w = getword_conf(cmd->pool, &optstr);
! if (!strcasecmp(w, "FancyIndexing"))
opts |= FANCY_INDEXING;
! else if (!strcasecmp(w, "IconsAreLinks"))
opts |= ICONS_ARE_LINKS;
! else if (!strcasecmp(w, "ScanHTMLTitles"))
opts |= SCAN_HTML_TITLES;
! else if (!strcasecmp(w, "SuppressLastModified"))
opts |= SUPPRESS_LAST_MOD;
! else if (!strcasecmp(w, "SuppressSize"))
opts |= SUPPRESS_SIZE;
! else if (!strcasecmp(w, "SuppressDescription"))
opts |= SUPPRESS_DESC;
! else if (!strcasecmp(w,"SuppressHTMLPreamble"))
! opts |= SUPPRESS_PREAMBLE;
! else if (!strcasecmp(w, "None"))
opts = 0;
! else if (! strncasecmp (w, "IconWidth", 9)) {
! if (strchr (w, '=') != NULL) {
! const char *x = pstrdup (cmd->pool, w);
! char *val;
! val = getword (cmd->pool, &x, '=');
! val = getword (cmd->pool, &x, '=');
! d_cfg->icon_width = atoi(val);
! }
! else {
! d_cfg->icon_width = DEFAULT_ICON_WIDTH;
! }
! }
! else if (! strncasecmp (w, "IconHeight", 10)) {
! if (strchr (w, '=') != NULL) {
! const char *x = pstrdup (cmd->pool, w);
! char *val;
! val = getword (cmd->pool, &x, '=');
! val = getword (cmd->pool, &x, '=');
! d_cfg->icon_height = atoi(val);
! }
! else {
! d_cfg->icon_height = DEFAULT_ICON_HEIGHT;
! }
! }
! else
! return "Invalid directory indexing option";
}
return add_opts_int(cmd, d, opts);
}
***************
*** 301,307 ****
static void *merge_autoindex_configs (pool *p, void *basev, void *addv)
{
! autoindex_config_rec *new=(autoindex_config_rec*)pcalloc (p,
sizeof(autoindex_config_rec));
autoindex_config_rec *base = (autoindex_config_rec *)basev;
autoindex_config_rec *add = (autoindex_config_rec *)addv;
--- 338,344 ----
static void *merge_autoindex_configs (pool *p, void *basev, void *addv)
{
! autoindex_config_rec *new = (autoindex_config_rec*)pcalloc (p,
sizeof(autoindex_config_rec));
autoindex_config_rec *base = (autoindex_config_rec *)basev;
autoindex_config_rec *add = (autoindex_config_rec *)addv;
***************
*** 349,369 ****
struct item *p = &items[i];
/* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */
! if((path[0] == '^') || (!strcmp_match(path,p->apply_path))) {
! if(!*(p->apply_to))
return p->data;
! else if(p->type == BY_PATH || path[0] == '^') {
! if(!strcmp_match(path,p->apply_to))
return p->data;
! } else if(!path_only) {
! if(!content_encoding) {
! if(p->type == BY_TYPE) {
! if(content_type &&
!strcmp_match(content_type,p->apply_to))
return p->data;
}
} else {
! if(p->type == BY_ENCODING) {
! if(!strcmp_match(content_encoding,p->apply_to))
return p->data;
}
}
--- 386,406 ----
struct item *p = &items[i];
/* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */
! if ((path[0] == '^') || (!strcmp_match(path, p->apply_path))) {
! if (!*(p->apply_to))
return p->data;
! else if (p->type == BY_PATH || path[0] == '^') {
! if (!strcmp_match(path, p->apply_to))
return p->data;
! } else if (!path_only) {
! if (!content_encoding) {
! if (p->type == BY_TYPE) {
! if (content_type && !strcmp_match(content_type,
p->apply_to))
return p->data;
}
} else {
! if (p->type == BY_ENCODING) {
! if (!strcmp_match(content_encoding, p->apply_to))
return p->data;
}
}
***************
*** 400,422 ****
char *tt;
int i;
! if((tt=strrchr(path,'/')) == NULL)
! tt=path;
else {
tt++;
}
for (i = 0; i < list->nelts; ++i) {
struct item *p = &items[i];
! char *ap;
! if((ap=strrchr(p->apply_to,'/')) == NULL)
! ap=p->apply_to;
! else
! ap++;
! if(!strcmp_match(path,p->apply_path) && !strcmp_match(tt,ap))
! return 1;
}
return 0;
}
--- 437,459 ----
char *tt;
int i;
! if ((tt = strrchr(path, '/')) == NULL)
! tt = path;
else {
tt++;
}
for (i = 0; i < list->nelts; ++i) {
struct item *p = &items[i];
! char *ap;
! if ((ap = strrchr(p->apply_to, '/')) == NULL)
! ap = p->apply_to;
! else
! ap++;
! if (!strcmp_match(path, p->apply_path) && !strcmp_match(tt, ap))
! return 1;
}
return 0;
}
***************
*** 429,436 ****
for (i = 0; i < list->nelts; ++i) {
struct item *p = &items[i];
!
! if(!strcmp_match(path,p->apply_path))
return (int)p->type;
}
return 0;
--- 466,473 ----
for (i = 0; i < list->nelts; ++i) {
struct item *p = &items[i];
!
! if (!strcmp_match(path, p->apply_path))
return (int)p->type;
}
return 0;
***************
*** 441,508 ****
* Actually generating output
*/
!
! static int insert_readme(char *name, char *readme_fname, int rule,
! request_rec *r)
{
char *fn;
FILE *f;
struct stat finfo;
! int plaintext=0;
request_rec *rr;
/* XXX: this is a load of crap, it needs to do a full
sub_req_lookup_uri */
fn = make_full_path(r->pool, name, readme_fname);
fn = pstrcat(r->pool, fn, ".html", NULL);
! if(stat(fn,&finfo) == -1) {
/* A brief fake multiviews search for README.html */
fn[strlen(fn)-5] = '\0';
! if(stat(fn,&finfo) == -1)
return 0;
! plaintext=1;
! if(rule) rputs("<HR>\n", r);
rputs("<PRE>\n", r);
}
! else if (rule) rputs("<HR>\n", r);
/* XXX: when the above is rewritten properly, this necessary security
* check will be redundant. -djg */
rr = sub_req_lookup_file (fn, r);
if (rr->status != HTTP_OK) {
! destroy_sub_req (rr);
! return 0;
}
destroy_sub_req (rr);
! if(!(f = pfopen(r->pool,fn,"r")))
return 0;
! if (!plaintext)
! send_fd(f, r);
! else
! {
! char buf[IOBUFSIZE+1];
! int i, n, c, ch;
! while (!feof(f))
! {
! do n = fread(buf, sizeof(char), IOBUFSIZE, f);
! while (n == -1 && ferror(f) && errno == EINTR);
! if (n == -1 || n == 0) break;
! buf[n] = '\0';
! c = 0;
! while (c < n)
! {
! for (i=c; i < n; i++)
! if (buf[i] == '<' || buf[i] == '>' || buf[i] == '&') break;
! ch = buf[i];
! buf[i] = '\0';
! rputs(&buf[c], r);
! if (ch == '<') rputs("<", r);
! else if (ch == '>') rputs(">", r);
! else if (ch == '&') rputs("&", r);
! c = i + 1;
! }
! }
}
pfclose(r->pool, f);
! if(plaintext)
rputs("</PRE>\n", r);
return 1;
}
--- 478,560 ----
* Actually generating output
*/
! /*
! * Look for the specified file, and pump it into the response stream if we
! * find it.
! */
! static int insert_readme(char *name, char *readme_fname, char *title, int
hrule,
! int whichend, request_rec *r)
{
char *fn;
FILE *f;
struct stat finfo;
! int plaintext = 0;
request_rec *rr;
+ autoindex_config_rec *cfg =
+ (autoindex_config_rec *) get_module_config
+ (
+ r->per_dir_config,
+ &autoindex_module
+ );
+ int autoindex_opts = find_opts(cfg, r);
/* XXX: this is a load of crap, it needs to do a full
sub_req_lookup_uri */
fn = make_full_path(r->pool, name, readme_fname);
fn = pstrcat(r->pool, fn, ".html", NULL);
! if (stat(fn, &finfo) == -1) {
/* A brief fake multiviews search for README.html */
fn[strlen(fn)-5] = '\0';
! if (stat(fn, &finfo) == -1)
return 0;
! plaintext = 1;
! if (hrule) rputs("<HR>\n", r);
rputs("<PRE>\n", r);
}
! else if (hrule) rputs("<HR>\n", r);
/* XXX: when the above is rewritten properly, this necessary security
* check will be redundant. -djg */
rr = sub_req_lookup_file (fn, r);
if (rr->status != HTTP_OK) {
! destroy_sub_req (rr);
! return 0;
}
destroy_sub_req (rr);
! if (!(f = pfopen(r->pool, fn, "r")))
return 0;
! if (
! (whichend == FRONT_MATTER) &&
! (! (autoindex_opts & SUPPRESS_PREAMBLE))
! ) {
! emit_preamble (r, title);
! }
! if (!plaintext) {
! send_fd(f, r);
! }
! else {
! char buf[IOBUFSIZE+1];
! int i, n, c, ch;
! while (!feof(f))
! {
! do n = fread(buf, sizeof(char), IOBUFSIZE, f);
! while (n == -1 && ferror(f) && errno == EINTR);
! if (n == -1 || n == 0) break;
! buf[n] = '\0';
! c = 0;
! while (c < n) {
! for (i = c; i < n; i++)
! if (buf[i] == '<' || buf[i] == '>' || buf[i] == '&')
break;
! ch = buf[i];
! buf[i] = '\0';
! rputs(&buf[c], r);
! if (ch == '<') rputs("<", r);
! else if (ch == '>') rputs(">", r);
! else if (ch == '&') rputs("&", r);
! c = i + 1;
! }
! }
}
pfclose(r->pool, f);
! if (plaintext)
rputs("</PRE>\n", r);
return 1;
}
***************
*** 511,557 ****
static char *find_title(request_rec *r) {
char titlebuf[MAX_STRING_LEN], *find = "<TITLE>";
FILE *thefile = NULL;
! int x,y,n,p;
if (r->status != HTTP_OK) {
! return NULL;
}
! if (r->content_type && !strcmp(r->content_type,"text/html") &&
!r->content_encoding) {
! if(!(thefile = pfopen(r->pool, r->filename,"r")))
return NULL;
! n = fread(titlebuf,sizeof(char),MAX_STRING_LEN - 1,thefile);
titlebuf[n] = '\0';
! for(x=0,p=0;titlebuf[x];x++) {
! if(toupper(titlebuf[x]) == find[p]) {
! if(!find[++p]) {
! if((p = ind(&titlebuf[++x],'<')) != -1)
titlebuf[x+p] = '\0';
/* Scan for line breaks for Tanmoy's secretary */
! for(y=x;titlebuf[y];y++)
! if((titlebuf[y] == CR) || (titlebuf[y] == LF))
titlebuf[y] = ' ';
! pfclose (r->pool, thefile);
return pstrdup(r->pool, &titlebuf[x]);
}
! } else p=0;
}
! pfclose(r->pool, thefile);
}
return NULL;
}
static struct ent *make_autoindex_entry(char *name, int autoindex_opts,
! autoindex_config_rec *d, request_rec *r)
{
struct ent *p;
! if((name[0] == '.') && (!name[1]))
return(NULL);
if (ignore_entry(d, make_full_path (r->pool, r->filename, name)))
return(NULL);
! p=(struct ent *)pcalloc(r->pool, sizeof(struct ent));
p->name = pstrdup (r->pool, name);
p->size = 0;
p->icon = NULL;
--- 563,609 ----
static char *find_title(request_rec *r) {
char titlebuf[MAX_STRING_LEN], *find = "<TITLE>";
FILE *thefile = NULL;
! int x, y, n, p;
if (r->status != HTTP_OK) {
! return NULL;
}
! if (r->content_type && !strcmp(r->content_type, "text/html") &&
!r->content_encoding) {
! if (!(thefile = pfopen(r->pool, r->filename, "r")))
return NULL;
! n = fread(titlebuf, sizeof(char), MAX_STRING_LEN - 1, thefile);
titlebuf[n] = '\0';
! for (x = 0, p = 0; titlebuf[x]; x++) {
! if (toupper(titlebuf[x]) == find[p]) {
! if (!find[++p]) {
! if ((p = ind(&titlebuf[++x], '<')) != -1)
titlebuf[x+p] = '\0';
/* Scan for line breaks for Tanmoy's secretary */
! for (y = x; titlebuf[y]; y++)
! if ((titlebuf[y] == CR) || (titlebuf[y] == LF))
titlebuf[y] = ' ';
! pfclose (r->pool, thefile);
return pstrdup(r->pool, &titlebuf[x]);
}
! } else p = 0;
}
! pfclose(r->pool, thefile);
}
return NULL;
}
static struct ent *make_autoindex_entry(char *name, int autoindex_opts,
! autoindex_config_rec *d, request_rec *r)
{
struct ent *p;
! if ((name[0] == '.') && (!name[1]))
return(NULL);
if (ignore_entry(d, make_full_path (r->pool, r->filename, name)))
return(NULL);
! p = (struct ent *)pcalloc(r->pool, sizeof(struct ent));
p->name = pstrdup (r->pool, name);
p->size = 0;
p->icon = NULL;
***************
*** 559,576 ****
p->desc = NULL;
p->lm = -1;
! if(autoindex_opts & FANCY_INDEXING) {
request_rec *rr = sub_req_lookup_file (name, r);
!
! if (rr->finfo.st_mode != 0) {
p->lm = rr->finfo.st_mtime;
! if(S_ISDIR(rr->finfo.st_mode)) {
! if(!(p->icon = find_icon(d,rr,1)))
! p->icon = find_default_icon(d,"^^DIRECTORY^^");
! if(!(p->alt = find_alt(d,rr,1)))
p->alt = "DIR";
p->size = 0;
! p->name = pstrcat (r->pool, name, "/", NULL);
}
else {
p->icon = find_icon(d, rr, 0);
--- 611,628 ----
p->desc = NULL;
p->lm = -1;
! if (autoindex_opts & FANCY_INDEXING) {
request_rec *rr = sub_req_lookup_file (name, r);
!
! if (rr->finfo.st_mode != 0) {
p->lm = rr->finfo.st_mtime;
! if (S_ISDIR(rr->finfo.st_mode)) {
! if (!(p->icon = find_icon(d, rr, 1)))
! p->icon = find_default_icon(d, "^^DIRECTORY^^");
! if (!(p->alt = find_alt(d, rr, 1)))
p->alt = "DIR";
p->size = 0;
! p->name = pstrcat (r->pool, name, "/", NULL);
}
else {
p->icon = find_icon(d, rr, 0);
***************
*** 578,590 ****
p->size = rr->finfo.st_size;
}
}
!
p->desc = find_desc(d, rr);
!
! if((!p->desc) && (autoindex_opts & SCAN_HTML_TITLES))
p->desc = pstrdup (r->pool, find_title(rr));
! destroy_sub_req (rr);
}
return(p);
}
--- 630,642 ----
p->size = rr->finfo.st_size;
}
}
!
p->desc = find_desc(d, rr);
!
! if ((!p->desc) && (autoindex_opts & SCAN_HTML_TITLES))
p->desc = pstrdup (r->pool, find_title(rr));
! destroy_sub_req (rr);
}
return(p);
}
***************
*** 595,607 ****
int maxsize = 23;
register int x;
! if(autoindex_opts & SUPPRESS_LAST_MOD) maxsize += 17;
! if(autoindex_opts & SUPPRESS_SIZE) maxsize += 7;
! for(x=0;desc[x] && maxsize;x++) {
! if(desc[x] == '<') {
! while(desc[x] != '>') {
! if(!desc[x]) {
maxsize = 0;
break;
}
--- 647,659 ----
int maxsize = 23;
register int x;
! if (autoindex_opts & SUPPRESS_LAST_MOD) maxsize += 17;
! if (autoindex_opts & SUPPRESS_SIZE) maxsize += 7;
! for (x = 0; desc[x] && maxsize; x++) {
! if (desc[x] == '<') {
! while (desc[x] != '>') {
! if (!desc[x]) {
maxsize = 0;
break;
}
***************
*** 610,618 ****
}
else --maxsize;
}
! if(!maxsize) {
! desc[x-1] = '>'; /* Grump. */
! desc[x] = '\0'; /* Double Grump! */
}
return desc;
}
--- 662,670 ----
}
else --maxsize;
}
! if (!maxsize) {
! desc[x-1] = '>'; /* Grump. */
! desc[x] = '\0'; /* Double Grump! */
}
return desc;
}
***************
*** 625,747 ****
char *tp;
pool *scratch = make_sub_pool (r->pool);
! if(name[0] == '\0') name = "/";
! if(autoindex_opts & FANCY_INDEXING) {
rputs("<PRE>", r);
! if((tp = find_default_icon(d,"^^BLANKICON^^"))) {
rvputs(r, "<IMG SRC=\"", escape_html(scratch, tp),
! "\" ALT=\" \"", NULL);
! if (d->icon_width && d->icon_height) {
! rprintf
! (
! r,
! " HEIGHT=\"%d\" WIDTH=\"%d\"",
! d->icon_height,
! d->icon_width
! );
! }
! rputs ("> ", r);
! }
rputs("Name ", r);
! if(!(autoindex_opts & SUPPRESS_LAST_MOD))
rputs("Last modified ", r);
! if(!(autoindex_opts & SUPPRESS_SIZE))
rputs("Size ", r);
! if(!(autoindex_opts & SUPPRESS_DESC))
rputs("Description", r);
rputs("\n<HR>\n", r);
}
else {
rputs("<UL>", r);
}
! for(x=0;x<n;x++) {
! char *anchor = NULL, *t = NULL, *t2 = NULL;
!
! clear_pool (scratch);
!
! if((!strcmp(ar[x]->name,"../")) || (!strcmp(ar[x]->name,".."))) {
char *t = make_full_path (scratch, name, "../");
getparents(t);
! if(t[0] == '\0') t = "/";
! anchor = pstrcat (scratch, "<A HREF=\"",
! escape_html(scratch, os_escape_path(scratch, t,
0)),
! "\">", NULL);
! t2 = "Parent Directory</A> ";
}
else {
! t = ar[x]->name;
! len = strlen(t);
! if(len > 23) {
! t2 = pstrdup(scratch, t);
! t2[21] = '.';
! t2[22] = '.';
t2[23] = '\0';
! t2 = escape_html(scratch, t2);
! t2 = pstrcat(scratch, t2, "</A>", NULL);
} else
! {
! char buff[24]=" ";
! t2 = escape_html(scratch, t);
! buff[23-len] = '\0';
! t2 = pstrcat(scratch, t2, "</A>", buff, NULL);
! }
! anchor = pstrcat (scratch, "<A HREF=\"",
! escape_html(scratch, os_escape_path(scratch, t,
0)),
! "\">", NULL);
}
! if(autoindex_opts & FANCY_INDEXING) {
! if(autoindex_opts & ICONS_ARE_LINKS)
rputs(anchor, r);
! if((ar[x]->icon) || d->default_icon) {
rvputs(r, "<IMG SRC=\"",
! escape_html(scratch, ar[x]->icon ?
! ar[x]->icon : d->default_icon),
! "\" ALT=\"[", (ar[x]->alt ? ar[x]->alt : " "),
! "]\"", NULL);
! if (d->icon_width && d->icon_height) {
! rprintf
! (
! r,
! " HEIGHT=\"%d\" WIDTH=\"%d\"",
! d->icon_height,
! d->icon_width
! );
! }
! rputs (">", r);
! }
! if(autoindex_opts & ICONS_ARE_LINKS)
rputs("</A>", r);
! rvputs(r," ", anchor, t2, NULL);
! if(!(autoindex_opts & SUPPRESS_LAST_MOD)) {
! if(ar[x]->lm != -1) {
! char time[MAX_STRING_LEN];
struct tm *ts = localtime(&ar[x]->lm);
! strftime(time,MAX_STRING_LEN,"%d-%b-%y %H:%M ",ts);
! rputs(time, r);
}
else {
rputs(" ", r);
}
}
! if(!(autoindex_opts & SUPPRESS_SIZE)) {
! send_size(ar[x]->size,r);
rputs(" ", r);
}
! if(!(autoindex_opts & SUPPRESS_DESC)) {
! if(ar[x]->desc) {
rputs(terminate_description(d, ar[x]->desc,
autoindex_opts), r);
}
}
}
else
! rvputs(r, "<LI> ", anchor," ", t2, NULL);
rputc('\n', r);
}
! if(autoindex_opts & FANCY_INDEXING) {
rputs("</PRE>", r);
}
else {
--- 677,799 ----
char *tp;
pool *scratch = make_sub_pool (r->pool);
! if (name[0] == '\0') name = "/";
! if (autoindex_opts & FANCY_INDEXING) {
rputs("<PRE>", r);
! if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
rvputs(r, "<IMG SRC=\"", escape_html(scratch, tp),
! "\" ALT=\" \"", NULL);
! if (d->icon_width && d->icon_height) {
! rprintf
! (
! r,
! " HEIGHT=\"%d\" WIDTH=\"%d\"",
! d->icon_height,
! d->icon_width
! );
! }
! rputs ("> ", r);
! }
rputs("Name ", r);
! if (!(autoindex_opts & SUPPRESS_LAST_MOD))
rputs("Last modified ", r);
! if (!(autoindex_opts & SUPPRESS_SIZE))
rputs("Size ", r);
! if (!(autoindex_opts & SUPPRESS_DESC))
rputs("Description", r);
rputs("\n<HR>\n", r);
}
else {
rputs("<UL>", r);
}
+
+ for (x = 0; x<n; x++) {
+ char *anchor = NULL, *t = NULL, *t2 = NULL;
+
+ clear_pool (scratch);
! if ((!strcmp(ar[x]->name, "../")) || (!strcmp(ar[x]->name, ".."))) {
char *t = make_full_path (scratch, name, "../");
getparents(t);
! if (t[0] == '\0') t = "/";
! anchor = pstrcat (scratch, "<A HREF=\"",
! escape_html(scratch, os_escape_path(scratch,
t, 0)),
! "\">", NULL);
! t2 = "Parent Directory</A> ";
}
else {
! t = ar[x]->name;
! len = strlen(t);
! if (len > 23) {
! t2 = pstrdup(scratch, t);
! t2[21] = '.';
! t2[22] = '.';
t2[23] = '\0';
! t2 = escape_html(scratch, t2);
! t2 = pstrcat(scratch, t2, "</A>", NULL);
} else
! {
! char buff[24] = " ";
! t2 = escape_html(scratch, t);
! buff[23-len] = '\0';
! t2 = pstrcat(scratch, t2, "</A>", buff, NULL);
! }
! anchor = pstrcat (scratch, "<A HREF=\"",
! escape_html(scratch, os_escape_path(scratch,
t, 0)),
! "\">", NULL);
}
! if (autoindex_opts & FANCY_INDEXING) {
! if (autoindex_opts & ICONS_ARE_LINKS)
rputs(anchor, r);
! if ((ar[x]->icon) || d->default_icon) {
rvputs(r, "<IMG SRC=\"",
! escape_html(scratch, ar[x]->icon ?
! ar[x]->icon : d->default_icon),
! "\" ALT=\"[", (ar[x]->alt ? ar[x]->alt : " "),
! "]\"", NULL);
! if (d->icon_width && d->icon_height) {
! rprintf
! (
! r,
! " HEIGHT=\"%d\" WIDTH=\"%d\"",
! d->icon_height,
! d->icon_width
! );
! }
! rputs (">", r);
! }
! if (autoindex_opts & ICONS_ARE_LINKS)
rputs("</A>", r);
! rvputs(r, " ", anchor, t2, NULL);
! if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
! if (ar[x]->lm != -1) {
! char time[MAX_STRING_LEN];
struct tm *ts = localtime(&ar[x]->lm);
! strftime(time, MAX_STRING_LEN, "%d-%b-%y %H:%M ", ts);
! rputs(time, r);
}
else {
rputs(" ", r);
}
}
! if (!(autoindex_opts & SUPPRESS_SIZE)) {
! send_size(ar[x]->size, r);
rputs(" ", r);
}
! if (!(autoindex_opts & SUPPRESS_DESC)) {
! if (ar[x]->desc) {
rputs(terminate_description(d, ar[x]->desc,
autoindex_opts), r);
}
}
}
else
! rvputs(r, "<LI> ", anchor, " ", t2, NULL);
rputc('\n', r);
}
! if (autoindex_opts & FANCY_INDEXING) {
rputs("</PRE>", r);
}
else {
***************
*** 750,758 ****
}
! static int dsortf(struct ent **s1,struct ent **s2)
{
! return(strcmp((*s1)->name,(*s2)->name));
}
--- 802,810 ----
}
! static int dsortf(struct ent **s1, struct ent **s2)
{
! return(strcmp((*s1)->name, (*s2)->name));
}
***************
*** 764,776 ****
DIR *d;
struct DIR_TYPE *dstruct;
! int num_ent=0,x;
! struct ent *head,*p;
struct ent **ar = NULL;
char *tmp;
int autoindex_opts = find_opts(autoindex_conf, r);
! if(!(d=popendir(r->pool, name))) {
log_reason ("Can't open directory for index", r->filename, r);
return HTTP_FORBIDDEN;
}
--- 816,828 ----
DIR *d;
struct DIR_TYPE *dstruct;
! int num_ent = 0, x;
! struct ent *head, *p;
struct ent **ar = NULL;
char *tmp;
int autoindex_opts = find_opts(autoindex_conf, r);
! if (!(d = popendir(r->pool, name))) {
log_reason ("Can't open directory for index", r->filename, r);
return HTTP_FORBIDDEN;
}
***************
*** 780,787 ****
send_http_header(r);
if (r->header_only) {
! pclosedir (r->pool, d);
! return 0;
}
hard_timeout("send directory", r);
--- 832,839 ----
send_http_header(r);
if (r->header_only) {
! pclosedir (r->pool, d);
! return 0;
}
hard_timeout("send directory", r);
***************
*** 790,843 ****
title_endp = title_name + strlen(title_name) - 1;
while (title_endp > title_name && *title_endp == '/')
! *title_endp-- = '\0';
! rvputs
! (
! r,
! "<HTML><HEAD>\n<TITLE>Index of ",
! title_name,
! "</TITLE>\n</HEAD><BODY>\n",
! NULL
! );
!
! if((!(tmp = find_header(autoindex_conf,r))) ||
(!(insert_readme(name,tmp,0,r))))
rvputs(r, "<H1>Index of ", title_name, "</H1>\n", NULL);
/*
* Since we don't know how many dir. entries there are, put them into a
* linked list and then arrayificate them so qsort can use them.
*/
! head=NULL;
! while((dstruct=readdir(d))) {
! if((p = make_autoindex_entry(dstruct->d_name, autoindex_opts,
autoindex_conf, r))) {
! p->next=head;
! head=p;
num_ent++;
}
}
if (num_ent > 0) {
! ar=(struct ent **) palloc(r->pool, num_ent*sizeof(struct ent *));
! p=head;
! x=0;
! while(p) {
! ar[x++]=p;
p = p->next;
}
! qsort((void *)ar,num_ent,sizeof(struct ent *),
#ifdef ULTRIX_BRAIN_DEATH
! (int (*))dsortf);
#else
! (int (*)(const void *,const void *))dsortf);
#endif
}
output_directories(ar, num_ent, autoindex_conf, r, autoindex_opts);
pclosedir(r->pool, d);
if (autoindex_opts & FANCY_INDEXING)
! if((tmp = find_readme(autoindex_conf, r)))
! insert_readme(name,tmp,1,r);
else {
rputs("</UL>", r);
}
--- 842,891 ----
title_endp = title_name + strlen(title_name) - 1;
while (title_endp > title_name && *title_endp == '/')
! *title_endp-- = '\0';
! if (
! (! (tmp = find_header(autoindex_conf, r))) ||
! (! (insert_readme(name, tmp, title_name, NO_HRULE, FRONT_MATTER,
r)))
! ) {
! emit_preamble (r, title_name);
rvputs(r, "<H1>Index of ", title_name, "</H1>\n", NULL);
+ }
/*
* Since we don't know how many dir. entries there are, put them into a
* linked list and then arrayificate them so qsort can use them.
*/
! head = NULL;
! while ((dstruct = readdir(d))) {
! if ((p = make_autoindex_entry(dstruct->d_name, autoindex_opts,
autoindex_conf, r))) {
! p->next = head;
! head = p;
num_ent++;
}
}
if (num_ent > 0) {
! ar = (struct ent **) palloc(r->pool, num_ent*sizeof(struct ent *));
! p = head;
! x = 0;
! while (p) {
! ar[x++] = p;
p = p->next;
}
! qsort((void *)ar, num_ent, sizeof(struct ent *),
#ifdef ULTRIX_BRAIN_DEATH
! (int (*))dsortf);
#else
! (int (*)(const void *, const void *))dsortf);
#endif
}
output_directories(ar, num_ent, autoindex_conf, r, autoindex_opts);
pclosedir(r->pool, d);
if (autoindex_opts & FANCY_INDEXING)
! if ((tmp = find_readme(autoindex_conf, r)))
! insert_readme(name, tmp, "", HRULE, END_MATTER, r);
else {
rputs("</UL>", r);
}
***************
*** 862,875 ****
/* OK, nothing easy. Trot out the heavy artillery... */
if (allow_opts & OPT_INDEXES) {
! /* KLUDGE --- make the sub_req lookups happen in the right directory.
! * Fixing this in the sub_req_lookup functions themselves is difficult,
! * and would probably break virtual includes...
! */
!
! if (r->filename[strlen (r->filename) - 1] != '/') {
! r->filename = pstrcat (r->pool, r->filename, "/", NULL);
! }
return index_directory (r, d);
} else {
log_reason ("Directory index forbidden by rule", r->filename, r);
--- 910,923 ----
/* OK, nothing easy. Trot out the heavy artillery... */
if (allow_opts & OPT_INDEXES) {
! /* KLUDGE --- make the sub_req lookups happen in the right
directory.
! * Fixing this in the sub_req_lookup functions themselves is
difficult,
! * and would probably break virtual includes...
! */
!
! if (r->filename[strlen (r->filename) - 1] != '/') {
! r->filename = pstrcat (r->pool, r->filename, "/", NULL);
! }
return index_directory (r, d);
} else {
log_reason ("Directory index forbidden by rule", r->filename, r);
***************
*** 885,903 ****
module autoindex_module = {
STANDARD_MODULE_STUFF,
! NULL, /* initializer */
! create_autoindex_config, /* dir config creater */
! merge_autoindex_configs, /* dir merger --- default is to override */
! NULL, /* server config */
! NULL, /* merge server config */
! autoindex_cmds, /* command table */
! autoindex_handlers, /* handlers */
! NULL, /* filename translation */
! NULL, /* check_user_id */
! NULL, /* check auth */
! NULL, /* check access */
! NULL, /* type_checker */
! NULL, /* fixups */
! NULL, /* logger */
! NULL /* header parser */
};
--- 933,951 ----
module autoindex_module = {
STANDARD_MODULE_STUFF,
! NULL, /* initializer */
! create_autoindex_config, /* dir config creater */
! merge_autoindex_configs, /* dir merger --- default is to override */
! NULL, /* server config */
! NULL, /* merge server config */
! autoindex_cmds, /* command table */
! autoindex_handlers, /* handlers */
! NULL, /* filename translation */
! NULL, /* check_user_id */
! NULL, /* check auth */
! NULL, /* check access */
! NULL, /* type_checker */
! NULL, /* fixups */
! NULL, /* logger */
! NULL /* header parser */
};