mod_autoindex.c revision 6db54801798f6021bb464de7b3fdcc9dc3150f7b
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering/* ====================================================================
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * Redistribution and use in source and binary forms, with or without
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * modification, are permitted provided that the following conditions
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * 1. Redistributions of source code must retain the above copyright
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * notice, this list of conditions and the following disclaimer.
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * 2. Redistributions in binary form must reproduce the above copyright
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * notice, this list of conditions and the following disclaimer in
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * the documentation and/or other materials provided with the
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * distribution.
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * 3. All advertising materials mentioning features or use of this
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * software must display the following acknowledgment:
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * "This product includes software developed by the Apache Group
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * for use in the Apache HTTP server project (http://www.apache.org/)."
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * 4. The names "Apache Server" and "Apache Group" must not be used to
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * endorse or promote products derived from this software without
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * prior written permission. For written permission, please contact
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * apache@apache.org.
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * 5. Products derived from this software may not be called "Apache"
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * nor may "Apache" appear in their names without prior written
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * permission of the Apache Group.
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * 6. Redistributions of any form whatsoever must retain the following
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * acknowledgment:
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * "This product includes software developed by the Apache Group
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * for use in the Apache HTTP server project (http://www.apache.org/)."
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * OF THE POSSIBILITY OF SUCH DAMAGE.
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * ====================================================================
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * This software consists of voluntary contributions made by many
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * individuals on behalf of the Apache Group and was originally based
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * on public domain software written at the National Center for
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * Supercomputing Applications, University of Illinois, Urbana-Champaign.
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * For more information on the Apache Group and the Apache HTTP server
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * project, please see <http://www.apache.org/>.
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * mod_autoindex.c: Handles the on-the-fly html index generation
d7c7c334f56edab8cfc102b657366277a65738cfLennart Poettering * Adapted to Apache by rst.
#include "http_core.h"
#include "http_request.h"
#include "http_protocol.h"
#include "http_log.h"
#include "http_main.h"
#include "util_script.h"
#include "apr_fnmatch.h"
#define NO_HRULE 0
#define END_MATTER 0
#define K_NOPAD 0
#define K_NOADJUST 0
struct item {
char *type;
char *apply_to;
char *apply_path;
char *data;
typedef struct ai_desc_t {
char *pattern;
char *description;
int full_path;
int wildcards;
} ai_desc_t;
typedef struct autoindex_config_struct {
char *default_icon;
int opts;
int incremented_opts;
int decremented_opts;
int name_width;
int name_adjust;
int icon_width;
int icon_height;
char *default_order;
char *data)
if (!to) {
if (!path) {
else if (to) {
return NULL;
char *alt;
return NULL;
#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, 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) {
int x, rv;
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}