mod_autoindex.c revision d41217398f0e1031adbb6f5bd37f45737c805def
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder/* ====================================================================
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * The Apache Software License, Version 1.1
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * Copyright (c) 2000 The Apache Software Foundation. All rights
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * Redistribution and use in source and binary forms, with or without
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * modification, are permitted provided that the following conditions
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * 1. Redistributions of source code must retain the above copyright
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * notice, this list of conditions and the following disclaimer.
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * 2. Redistributions in binary form must reproduce the above copyright
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * notice, this list of conditions and the following disclaimer in
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * the documentation and/or other materials provided with the
05b9abe2e7d9e6126bf4ae29be6ef3693f32de73Christian Maeder * distribution.
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * 3. The end-user documentation included with the redistribution,
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder * if any, must include the following acknowledgment:
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * "This product includes software developed by the
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * Apache Software Foundation (http://www.apache.org/)."
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * Alternately, this acknowledgment may appear in the software itself,
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * if and wherever such third-party acknowledgments normally appear.
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder * 4. The names "Apache" and "Apache Software Foundation" must
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder * not be used to endorse or promote products derived from this
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder * software without prior written permission. For written
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder * permission, please contact apache@apache.org.
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder * 5. Products derived from this software may not be called "Apache",
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * nor may "Apache" appear in their name, without prior written
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * permission of the Apache Software Foundation.
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * SUCH DAMAGE.
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * ====================================================================
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * This software consists of voluntary contributions made by many
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * individuals on behalf of the Apache Software Foundation. For more
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * information on the Apache Software Foundation, please see
d4aed7a2eea6b546c0d9520d85038addb7beb12fChristian Maeder * Portions of this software are based upon public domain software
d4aed7a2eea6b546c0d9520d85038addb7beb12fChristian Maeder * originally written at the National Center for Supercomputing Applications,
d4aed7a2eea6b546c0d9520d85038addb7beb12fChristian Maeder * University of Illinois, Urbana-Champaign.
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder * mod_autoindex.c: Handles the on-the-fly html index generation
05b9abe2e7d9e6126bf4ae29be6ef3693f32de73Christian Maeder * Adapted to Apache by rst.
ca0d4947f7b0fdcbf7eac627659e6cff6d3863baChristian Maeder * Version sort added by Martin Pool <mbp@humbug.org.au>. */
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder/****************************************************************
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder * Handling configuration directives...
e92e93922166c81167de83cc7400403c5d9bb26cChristian Maeder#define FANCY_INDEXING 1 /* Indexing options */
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder * Define keys for sorting.
38f35f2c4a3b6a778f4f68e7af047a174e93abbeChristian Maeder#define K_NAME 'N' /* Sort by file name (default) */
38f35f2c4a3b6a778f4f68e7af047a174e93abbeChristian Maeder#define K_LAST_MOD 'M' /* Last modification date */
13140d161d2d2d11d87283d01d57ee3a738a833dChristian Maeder#define K_SIZE 'S' /* Size (absolute, not as displayed) */
05b9abe2e7d9e6126bf4ae29be6ef3693f32de73Christian Maeder * These are the dimensions of the default icons supplied with Apache.
13140d161d2d2d11d87283d01d57ee3a738a833dChristian Maeder * Other default dimensions.
05b9abe2e7d9e6126bf4ae29be6ef3693f32de73Christian Maedertypedef struct ai_desc_t {
if (!to) {
if (!path) {
else if (to) {
const char *to)
return NULL;
const char *to)
char *alt;
return NULL;
#ifdef CASE_BLIND_FILESYSTEM
#define WILDCARDS_REQUIRED 0
const char *to)
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;
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 i, c, ch;
ap_ssize_t n;
while (!ap_eof(f)) {
n = sizeof(char) * 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);
ap_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);
ap_close(f);
if (!suppress_sig) {
if (!suppress_post) {
ap_ssize_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;
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);
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}