mod_autoindex.c revision ab5581cc78e9d865b0a6ab1404c53347b3276968
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor/* ====================================================================
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * Redistribution and use in source and binary forms, with or without
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * modification, are permitted provided that the following conditions
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc * 1. Redistributions of source code must retain the above copyright
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * notice, this list of conditions and the following disclaimer.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * 2. Redistributions in binary form must reproduce the above copyright
2e545ce2450a9953665f701bb05350f0d3f26275nd * notice, this list of conditions and the following disclaimer in
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * the documentation and/or other materials provided with the
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * distribution.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * 3. All advertising materials mentioning features or use of this
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * software must display the following acknowledgment:
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * "This product includes software developed by the Apache Group
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * for use in the Apache HTTP server project (http://www.apache.org/)."
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * 4. The names "Apache Server" and "Apache Group" must not be used to
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * endorse or promote products derived from this software without
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * prior written permission. For written permission, please contact
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * apache@apache.org.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * 5. Products derived from this software may not be called "Apache"
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * nor may "Apache" appear in their names without prior written
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * permission of the Apache Group.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * 6. Redistributions of any form whatsoever must retain the following
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * acknowledgment:
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * "This product includes software developed by the Apache Group
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * for use in the Apache HTTP server project (http://www.apache.org/)."
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * OF THE POSSIBILITY OF SUCH DAMAGE.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * ====================================================================
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * This software consists of voluntary contributions made by many
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * individuals on behalf of the Apache Group and was originally based
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * on public domain software written at the National Center for
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * Supercomputing Applications, University of Illinois, Urbana-Champaign.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * For more information on the Apache Group and the Apache HTTP server
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * project, please see <http://www.apache.org/>.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * mod_autoindex.c: Handles the on-the-fly html index generation
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * Rob McCool
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * Adapted to Apache by rst.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor/****************************************************************
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * Handling configuration directives...
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * Define keys for sorting.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor#define K_SIZE 'S' /* Size (absolute, not as displayed) */
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * These are the dimensions of the default icons supplied with Apache.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * Other default dimensions.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzortypedef struct ai_desc_t {
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * Return true if the specified string refers to the parent directory (i.e.,
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * matches ".." or "../"). Hopefully this one call is significantly less
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * expensive than multiple strcmp() calls.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * Now, IFF the first two bytes are dots, and the third byte is either
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * EOS (\0) or a slash followed by EOS, we have a match.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * This routine puts the standard HTML header at the top of the index page.
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * We include the DOCTYPE because we may be using features therefrom (i.e.,
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
32f5dfaca53f31a4ccb791a811607367ce16e832gryzorstatic void emit_preamble(request_rec *r, char *title)
32f5dfaca53f31a4ccb791a811607367ce16e832gryzorstatic void push_item(ap_array_header_t *arr, char *type, char *to, char *path,
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor p->apply_path = ap_pstrcat(arr->cont, path, "*", NULL);
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor else if (to) {
32f5dfaca53f31a4ccb791a811607367ce16e832gryzorstatic const char *add_alt(cmd_parms *cmd, void *d, char *alt, char *to)
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor push_item(((autoindex_config_rec *) d)->alt_list, cmd->info, to,
32f5dfaca53f31a4ccb791a811607367ce16e832gryzorstatic const char *add_icon(cmd_parms *cmd, void *d, char *icon, char *to)
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor return "missing closing paren";
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor push_item(((autoindex_config_rec *) d)->icon_list, cmd->info, to,
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * Add description text for a filename pattern. If the pattern has
07dc96d063d49299da433f84b5c5681da9bbdf68rbowen * wildcards already (or we need to add them), add leading and
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * trailing wildcards to it to ensure substring processing. If the
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * pattern contains a '/' anywhere, force wildcard matching mode,
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * add a slash to the prefix so that "bar/bletch" won't be matched
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * by "foobar/bletch", and make a note that there's a delimiter;
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * the matching routine simplifies to just the actual filename
32f5dfaca53f31a4ccb791a811607367ce16e832gryzor * whenever it can. This allows definitions in parent directories
#ifdef CASE_BLIND_FILESYSTEM
#define WILDCARDS_REQUIRED 0
return NULL;
return NULL;
name);
return NULL;
name);
return NULL;
int curopts;
int newopts;
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;
char *key)
return NULL;
{NULL}
return (void *) new;
return new;
struct ent {
char *name;
char *icon;
char *alt;
char *desc;
int ascending;
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 i, n, c, ch;
while (!ap_eof(f)) {
n = sizeof(char) * IOBUFSIZE;
char *title)
ap_file_t *f;
* 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);
ap_close(f);
emit_H1 = 0;
if (emit_amble) {
if (emit_H1) {
ap_file_t *f;
int suppress_post = 0;
int suppress_sig = 0;
* text/anything-else. The former is allowed to be processed for
do_emit_plain(r, f);
ap_close(f);
if (!suppress_sig) {
if (!suppress_post) {
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;
char direction)
struct ent *p;
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;
d->icon_height,
d->icon_width
int nwidth;
ap_getparents(t);
t2 = t;
: d->default_icon),
NULL);
autoindex_opts), r);
int result = 0;
case K_LAST_MOD:
case K_SIZE:
case K_DESC:
if (result) {
return result;
char *title_endp;
ap_dir_t *d;
int num_ent = 0, x;
const char *qstring;
char keyid;
char direction;
return HTTP_FORBIDDEN;
if (r->header_only) {
ap_closedir(d);
while (ap_readdir(d)) {
char *d_name;
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);
ap_closedir(d);
return DECLINED;
return index_directory(r, d);
return HTTP_FORBIDDEN;
{NULL}