mod_autoindex.c revision 59b2e3432a30c3684570bc033949a5d0713e0bb2
0ad489b182ebb3789322345e22cf750f88ae167and/* ====================================================================
0ad489b182ebb3789322345e22cf750f88ae167and * The Apache Software License, Version 1.1
6aadbc6fd703e73d1d419e9f06b84a4338c898f1maczniak * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
0ad489b182ebb3789322345e22cf750f88ae167and * reserved.
0ad489b182ebb3789322345e22cf750f88ae167and * Redistribution and use in source and binary forms, with or without
0ad489b182ebb3789322345e22cf750f88ae167and * modification, are permitted provided that the following conditions
0ad489b182ebb3789322345e22cf750f88ae167and * are met:
0ad489b182ebb3789322345e22cf750f88ae167and * 1. Redistributions of source code must retain the above copyright
0ad489b182ebb3789322345e22cf750f88ae167and * notice, this list of conditions and the following disclaimer.
0ad489b182ebb3789322345e22cf750f88ae167and * 2. Redistributions in binary form must reproduce the above copyright
0ad489b182ebb3789322345e22cf750f88ae167and * notice, this list of conditions and the following disclaimer in
0ad489b182ebb3789322345e22cf750f88ae167and * the documentation and/or other materials provided with the
0ad489b182ebb3789322345e22cf750f88ae167and * distribution.
0ad489b182ebb3789322345e22cf750f88ae167and * 3. The end-user documentation included with the redistribution,
0ad489b182ebb3789322345e22cf750f88ae167and * if any, must include the following acknowledgment:
0ad489b182ebb3789322345e22cf750f88ae167and * "This product includes software developed by the
0ad489b182ebb3789322345e22cf750f88ae167and * Apache Software Foundation (http://www.apache.org/)."
0ad489b182ebb3789322345e22cf750f88ae167and * Alternately, this acknowledgment may appear in the software itself,
0ad489b182ebb3789322345e22cf750f88ae167and * if and wherever such third-party acknowledgments normally appear.
0ad489b182ebb3789322345e22cf750f88ae167and * 4. The names "Apache" and "Apache Software Foundation" must
0ad489b182ebb3789322345e22cf750f88ae167and * not be used to endorse or promote products derived from this
0ad489b182ebb3789322345e22cf750f88ae167and * software without prior written permission. For written
0ad489b182ebb3789322345e22cf750f88ae167and * permission, please contact apache@apache.org.
0ad489b182ebb3789322345e22cf750f88ae167and * 5. Products derived from this software may not be called "Apache",
0ad489b182ebb3789322345e22cf750f88ae167and * nor may "Apache" appear in their name, without prior written
0ad489b182ebb3789322345e22cf750f88ae167and * permission of the Apache Software Foundation.
0ad489b182ebb3789322345e22cf750f88ae167and * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0ad489b182ebb3789322345e22cf750f88ae167and * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0ad489b182ebb3789322345e22cf750f88ae167and * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0ad489b182ebb3789322345e22cf750f88ae167and * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0ad489b182ebb3789322345e22cf750f88ae167and * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0ad489b182ebb3789322345e22cf750f88ae167and * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0ad489b182ebb3789322345e22cf750f88ae167and * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
0ad489b182ebb3789322345e22cf750f88ae167and * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0ad489b182ebb3789322345e22cf750f88ae167and * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0ad489b182ebb3789322345e22cf750f88ae167and * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
6aadbc6fd703e73d1d419e9f06b84a4338c898f1maczniak * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6aadbc6fd703e73d1d419e9f06b84a4338c898f1maczniak * SUCH DAMAGE.
6aadbc6fd703e73d1d419e9f06b84a4338c898f1maczniak * ====================================================================
6aadbc6fd703e73d1d419e9f06b84a4338c898f1maczniak * This software consists of voluntary contributions made by many
0ad489b182ebb3789322345e22cf750f88ae167and * individuals on behalf of the Apache Software Foundation. For more
0ad489b182ebb3789322345e22cf750f88ae167and * information on the Apache Software Foundation, please see
0ad489b182ebb3789322345e22cf750f88ae167and * Portions of this software are based upon public domain software
0ad489b182ebb3789322345e22cf750f88ae167and * originally written at the National Center for Supercomputing Applications,
0ad489b182ebb3789322345e22cf750f88ae167and * University of Illinois, Urbana-Champaign.
0ad489b182ebb3789322345e22cf750f88ae167and * mod_autoindex.c: Handles the on-the-fly html index generation
0ad489b182ebb3789322345e22cf750f88ae167and * Rob McCool
0ad489b182ebb3789322345e22cf750f88ae167and * Adapted to Apache by rst.
0ad489b182ebb3789322345e22cf750f88ae167and * Version sort added by Martin Pool <mbp@humbug.org.au>.
0ad489b182ebb3789322345e22cf750f88ae167and/****************************************************************
0ad489b182ebb3789322345e22cf750f88ae167and * Handling configuration directives...
0ad489b182ebb3789322345e22cf750f88ae167and * Define keys for sorting.
0ad489b182ebb3789322345e22cf750f88ae167and#define K_SIZE 'S' /* Size (absolute, not as displayed) */
0ad489b182ebb3789322345e22cf750f88ae167and * These are the dimensions of the default icons supplied with Apache.
0ad489b182ebb3789322345e22cf750f88ae167and * Other default dimensions.
0ad489b182ebb3789322345e22cf750f88ae167andtypedef struct ai_desc_t {
0ad489b182ebb3789322345e22cf750f88ae167andtypedef struct autoindex_config_struct {
0ad489b182ebb3789322345e22cf750f88ae167and * Return true if the specified string refers to the parent directory (i.e.,
0ad489b182ebb3789322345e22cf750f88ae167and * matches ".." or "../"). Hopefully this one call is significantly less
0ad489b182ebb3789322345e22cf750f88ae167and * expensive than multiple strcmp() calls.
0ad489b182ebb3789322345e22cf750f88ae167and * Now, IFF the first two bytes are dots, and the third byte is either
0ad489b182ebb3789322345e22cf750f88ae167and * EOS (\0) or a slash followed by EOS, we have a match.
0ad489b182ebb3789322345e22cf750f88ae167and * This routine puts the standard HTML header at the top of the index page.
0ad489b182ebb3789322345e22cf750f88ae167and * We include the DOCTYPE because we may be using features therefrom (i.e.,
0ad489b182ebb3789322345e22cf750f88ae167and * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
0ad489b182ebb3789322345e22cf750f88ae167andstatic void push_item(apr_array_header_t *arr, char *type, const char *to,
0ad489b182ebb3789322345e22cf750f88ae167and else if (to) {
0ad489b182ebb3789322345e22cf750f88ae167andstatic const char *add_alt(cmd_parms *cmd, void *d, const char *alt,
0ad489b182ebb3789322345e22cf750f88ae167and const char *to)
0ad489b182ebb3789322345e22cf750f88ae167and push_item(((autoindex_config_rec *) d)->alt_list, cmd->info, to,
0ad489b182ebb3789322345e22cf750f88ae167andstatic const char *add_icon(cmd_parms *cmd, void *d, const char *icon,
0ad489b182ebb3789322345e22cf750f88ae167and const char *to)
0ad489b182ebb3789322345e22cf750f88ae167and return "missing closing paren";
0ad489b182ebb3789322345e22cf750f88ae167and push_item(((autoindex_config_rec *) d)->icon_list, cmd->info, to,
0ad489b182ebb3789322345e22cf750f88ae167and * Add description text for a filename pattern. If the pattern has
0ad489b182ebb3789322345e22cf750f88ae167and * wildcards already (or we need to add them), add leading and
0ad489b182ebb3789322345e22cf750f88ae167and * trailing wildcards to it to ensure substring processing. If the
0ad489b182ebb3789322345e22cf750f88ae167and * pattern contains a '/' anywhere, force wildcard matching mode,
0ad489b182ebb3789322345e22cf750f88ae167and * add a slash to the prefix so that "bar/bletch" won't be matched
0ad489b182ebb3789322345e22cf750f88ae167and * by "foobar/bletch", and make a note that there's a delimiter;
0ad489b182ebb3789322345e22cf750f88ae167and * the matching routine simplifies to just the actual filename
0ad489b182ebb3789322345e22cf750f88ae167and * whenever it can. This allows definitions in parent directories
0ad489b182ebb3789322345e22cf750f88ae167and * to be made for files in subordinate ones using relative paths.
0ad489b182ebb3789322345e22cf750f88ae167and * Absent a strcasestr() function, we have to force wildcards on
0ad489b182ebb3789322345e22cf750f88ae167and * systems for which "AAA" and "aaa" mean the same file.
0ad489b182ebb3789322345e22cf750f88ae167andstatic const char *add_desc(cmd_parms *cmd, void *d, const char *desc,
0ad489b182ebb3789322345e22cf750f88ae167and const char *to)
0ad489b182ebb3789322345e22cf750f88ae167and desc_entry = (ai_desc_t *) apr_array_push(dcfg->desc_list);
0ad489b182ebb3789322345e22cf750f88ae167and desc_entry->full_path = (ap_strchr_c(to, '/') == NULL) ? 0 : 1;
0ad489b182ebb3789322345e22cf750f88ae167and desc_entry->pattern = apr_pstrdup(dcfg->desc_list->pool, to);
0ad489b182ebb3789322345e22cf750f88ae167and desc_entry->description = apr_pstrdup(dcfg->desc_list->pool, desc);
0ad489b182ebb3789322345e22cf750f88ae167andstatic const char *add_ignore(cmd_parms *cmd, void *d, const char *ext)
0ad489b182ebb3789322345e22cf750f88ae167and push_item(((autoindex_config_rec *) d)->ign_list, 0, ext, cmd->path, NULL);
return NULL;
name);
return NULL;
name);
return NULL;
int opts;
int opts_add;
int opts_remove;
char action;
while (optstr[0]) {
int option = 0;
action = *(w++);
opts_add = 0;
opts_remove = 0;
opts_add = 0;
opts_remove = 0;
return NULL;
const char *key)
return NULL;
{NULL}
return (void *) new;
return new;
struct ent {
char *name;
char *icon;
char *alt;
char *desc;
char key;
if (!*(p->apply_to)) {
return p->data;
return p->data;
else if (!path_only) {
if (!content_encoding) {
if (content_type
p->apply_to)) {
return p->data;
p->apply_to)) {
return p->data;
return NULL;
request_rec r;
* Look through the list of pattern/description pairs and return the first one
#ifdef CASE_BLIND_FILESYSTEM
#define MATCH_FLAGS 0
const char *filename_only;
const char *filename;
int found;
if (found) {
return NULL;
char *tt;
tt++;
char *ap;
ap++;
#ifndef CASE_BLIND_FILESYSTEM
int ch;
apr_size_t i, c, n;
while (!apr_file_eof(f)) {
n = sizeof(char) * AP_IOBUFSIZE;
char *title)
* text/anything-else. The former is allowed to be processed for
emit_amble = 0;
emit_H1 = 0;
if (! suppress_amble) {
emit_amble = 0;
do_emit_plain(r, f);
apr_file_close(f);
emit_H1 = 0;
if (emit_amble) {
if (emit_H1) {
int suppress_post = 0;
int suppress_sig = 0;
* text/anything-else. The former is allowed to be processed for
do_emit_plain(r, f);
apr_file_close(f);
if (!suppress_sig) {
if (!suppress_post) {
apr_size_t n;
return NULL;
&& !r->content_encoding) {
return NULL;
return NULL;
for (x = 0, p = 0; titlebuf[x]; x++) {
if (!find[++p]) {
for (y = x; titlebuf[y]; y++) {
return NULL;
int autoindex_opts,
char direction)
struct ent *p;
return (NULL);
return (NULL);
return (NULL);
return (NULL);
if (p->lm < 0) {
p->lm = 0;
int autoindex_opts)
if (!desc[x]) {
maxsize = 0;
--maxsize;
maxsize = 0;
--maxsize;
return desc;
int reverse;
if (!nosort) {
char *tp;
int name_width;
char *name_scratch;
char *pad_scratch;
if (t > name_width) {
name_width = t;
if (d->icon_width)
if (d->icon_height)
int nwidth;
ap_getparents(t);
t2 = t;
: d->default_icon),
if (d->icon_width)
if (d->icon_height)
NULL);
autoindex_opts), r);
int result = 0;
case K_LAST_MOD:
case K_SIZE:
case K_DESC:
if (result) {
return result;
char *title_endp;
int num_ent = 0, x;
const char *qstring;
char keyid;
char direction;
return HTTP_FORBIDDEN;
ap_set_etag(r);
if (r->header_only) {
if (p != NULL) {
head = p;
num_ent++;
if (num_ent > 0) {
p = head;
ar[x++] = p;
p = p->next;
(int (*)(const void *, const void *)) dsortf);
int allow_opts;
return DECLINED;
return DECLINED;
return index_directory(r, d);
return HTTP_FORBIDDEN;