mod_autoindex.c revision 53bb9198689cfcc08182c9bb27005368bcba42a2
842ae4bd224140319ae7feec1872b93dfd491143fielding/* ====================================================================
842ae4bd224140319ae7feec1872b93dfd491143fielding * The Apache Software License, Version 1.1
842ae4bd224140319ae7feec1872b93dfd491143fielding *
842ae4bd224140319ae7feec1872b93dfd491143fielding * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
842ae4bd224140319ae7feec1872b93dfd491143fielding * reserved.
842ae4bd224140319ae7feec1872b93dfd491143fielding *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Redistribution and use in source and binary forms, with or without
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * modification, are permitted provided that the following conditions
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * are met:
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 1. Redistributions of source code must retain the above copyright
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * notice, this list of conditions and the following disclaimer.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 2. Redistributions in binary form must reproduce the above copyright
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * notice, this list of conditions and the following disclaimer in
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * the documentation and/or other materials provided with the
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * distribution.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 3. The end-user documentation included with the redistribution,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * if any, must include the following acknowledgment:
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * "This product includes software developed by the
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Apache Software Foundation (http://www.apache.org/)."
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Alternately, this acknowledgment may appear in the software itself,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * if and wherever such third-party acknowledgments normally appear.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 4. The names "Apache" and "Apache Software Foundation" must
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * not be used to endorse or promote products derived from this
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * software without prior written permission. For written
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * permission, please contact apache@apache.org.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 5. Products derived from this software may not be called "Apache",
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * nor may "Apache" appear in their name, without prior written
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * permission of the Apache Software Foundation.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
806b50b4d37ade77f1c767a1593fac5a2d7786c8minfrin * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
c07866e582be4daac7f6a0a8754fa12fca044663fuankg * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
07ed2f9227b98d2cac21a7121ef7ea5328fa3f98fuankg * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
15ff8c621815e8337abc10638f2b2853ee6fd076minfrin * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * SUCH DAMAGE.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * ====================================================================
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * This software consists of voluntary contributions made by many
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * individuals on behalf of the Apache Software Foundation. For more
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * information on the Apache Software Foundation, please see
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * <http://www.apache.org/>.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Portions of this software are based upon public domain software
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * originally written at the National Center for Supercomputing Applications,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * University of Illinois, Urbana-Champaign.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/*
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * mod_autoindex.c: Handles the on-the-fly html index generation
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Rob McCool
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 3/23/93
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Adapted to Apache by rst.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Version sort added by Martin Pool <mbp@humbug.org.au>. */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include "apr_strings.h"
15351ab1a34130c1f880daef4e5dc15407a75969colm#include "ap_config.h"
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include "httpd.h"
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include "http_config.h"
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include "http_core.h"
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#include "http_request.h"
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include "http_protocol.h"
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#include "http_log.h"
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#include "http_main.h"
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#include "util_script.h"
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#include "apr_fnmatch.h"
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#include "apr_strings.h"
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#ifdef HAVE_STRING_H
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include <string.h>
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#endif
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#ifdef HAVE_STRINGS_H
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include <strings.h>
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#endif
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndmodule AP_MODULE_DECLARE_DATA autoindex_module;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd/****************************************************************
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd *
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * Handling configuration directives...
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#define HRULE 1
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#define NO_HRULE 0
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#define FRONT_MATTER 1
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#define END_MATTER 0
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#define FANCY_INDEXING 1 /* Indexing options */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#define ICONS_ARE_LINKS 2
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#define SCAN_HTML_TITLES 4
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantz#define SUPPRESS_LAST_MOD 8
5876f43a746f688a32b7201bced8591ddf19bd43minfrin#define SUPPRESS_SIZE 16
5876f43a746f688a32b7201bced8591ddf19bd43minfrin#define SUPPRESS_DESC 32
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#define SUPPRESS_PREAMBLE 64
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#define SUPPRESS_COLSORT 128
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#define NO_OPTIONS 256
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#define VERSION_SORT 512
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#define K_PAD 1
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#define K_NOPAD 0
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#define K_NOADJUST 0
2d728410bcf9e6e53698bb035f516e18efd76d8bnd#define K_ADJUST 1
2d728410bcf9e6e53698bb035f516e18efd76d8bnd#define K_UNSET 2
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin/*
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin * Define keys for sorting.
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin */
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin#define K_NAME 'N' /* Sort by file name (default) */
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin#define K_LAST_MOD 'M' /* Last modification date */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#define K_SIZE 'S' /* Size (absolute, not as displayed) */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#define K_DESC 'D' /* Description */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin#define D_ASCENDING 'A'
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin#define D_DESCENDING 'D'
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin/*
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin * These are the dimensions of the default icons supplied with Apache.
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin */
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin#define DEFAULT_ICON_WIDTH 20
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin#define DEFAULT_ICON_HEIGHT 22
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/*
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Other default dimensions.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#define DEFAULT_NAME_WIDTH 23
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstruct item {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz char *type;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz char *apply_to;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz char *apply_path;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz char *data;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz};
a51acf58d9d82f52e0ee56106cd9282030f3f3bend
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantztypedef struct ai_desc_t {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz char *pattern;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz char *description;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int full_path;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int wildcards;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz} ai_desc_t;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantztypedef struct autoindex_config_struct {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
a51acf58d9d82f52e0ee56106cd9282030f3f3bend char *default_icon;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int opts;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int incremented_opts;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int decremented_opts;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int name_width;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int name_adjust;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int icon_width;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int icon_height;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz char *default_order;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_array_header_t *icon_list;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_array_header_t *alt_list;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_array_header_t *desc_list;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_array_header_t *ign_list;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_array_header_t *hdr_list;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_array_header_t *rdme_list;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz} autoindex_config_rec;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic char c_by_encoding, c_by_type, c_by_path;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#define BY_ENCODING &c_by_encoding
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#define BY_TYPE &c_by_type
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin#define BY_PATH &c_by_path
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd/*
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * Return true if the specified string refers to the parent directory (i.e.,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * matches ".." or "../"). Hopefully this one call is significantly less
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * expensive than multiple strcmp() calls.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic apr_inline int is_parent(const char *name)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz{
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /*
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin * Now, IFF the first two bytes are dots, and the third byte is either
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin * EOS (\0) or a slash followed by EOS, we have a match.
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (((name[0] == '.') && (name[1] == '.'))
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin && ((name[2] == '\0')
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin || ((name[2] == '/') && (name[3] == '\0')))) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return 1;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return 0;
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin}
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin/*
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * This routine puts the standard HTML header at the top of the index page.
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin * We include the DOCTYPE because we may be using features therefrom (i.e.,
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic void emit_preamble(request_rec *r, char *title)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz{
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin ap_rvputs(r, DOCTYPE_HTML_3_2,
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin "<HTML>\n <HEAD>\n <TITLE>Index of ", title,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "</TITLE>\n </HEAD>\n <BODY>\n", NULL);
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin}
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic void push_item(apr_array_header_t *arr, char *type, const char *to,
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin const char *path, const char *data)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz{
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz struct item *p = (struct item *) apr_array_push(arr);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (!to) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz to = "";
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (!path) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz path = "";
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz p->type = type;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz p->data = data ? apr_pstrdup(arr->cont, data) : NULL;
a51acf58d9d82f52e0ee56106cd9282030f3f3bend p->apply_path = apr_pstrcat(arr->cont, path, "*", NULL);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if ((type == BY_PATH) && (!ap_is_matchexp(to))) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin p->apply_to = apr_pstrcat(arr->cont, "*", to, NULL);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin else if (to) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin p->apply_to = apr_pstrdup(arr->cont, to);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin else {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin p->apply_to = NULL;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin}
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinstatic const char *add_alt(cmd_parms *cmd, void *d, const char *alt,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin const char *to)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin{
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (cmd->info == BY_PATH) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (!strcmp(to, "**DIRECTORY**")) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin to = "^^DIRECTORY^^";
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (cmd->info == BY_ENCODING) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin char *tmp = apr_pstrdup(cmd->pool, to);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_str_tolower(tmp);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin to = tmp;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin push_item(((autoindex_config_rec *) d)->alt_list, cmd->info, to,
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin cmd->path, alt);
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin return NULL;
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin}
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin
289a94d4157967ac04dc5c865b94e361400eae0afuankgstatic const char *add_icon(cmd_parms *cmd, void *d, const char *icon,
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin const char *to)
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin{
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin char *iconbak = apr_pstrdup(cmd->pool, icon);
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (icon[0] == '(') {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin char *alt;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz char *cl = strchr(iconbak, ')');
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (cl == NULL) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return "missing closing paren";
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd alt = ap_getword_nc(cmd->pool, &iconbak, ',');
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *cl = '\0'; /* Lose closing paren */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin add_alt(cmd, d, &alt[1], to);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (cmd->info == BY_PATH) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (!strcmp(to, "**DIRECTORY**")) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin to = "^^DIRECTORY^^";
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (cmd->info == BY_ENCODING) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin char *tmp = apr_pstrdup(cmd->pool, to);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_str_tolower(tmp);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin to = tmp;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin push_item(((autoindex_config_rec *) d)->icon_list, cmd->info, to,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin cmd->path, iconbak);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return NULL;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin}
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin/*
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * Add description text for a filename pattern. If the pattern has
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * wildcards already (or we need to add them), add leading and
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * trailing wildcards to it to ensure substring processing. If the
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * pattern contains a '/' anywhere, force wildcard matching mode,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * add a slash to the prefix so that "bar/bletch" won't be matched
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * by "foobar/bletch", and make a note that there's a delimiter;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * the matching routine simplifies to just the actual filename
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * whenever it can. This allows definitions in parent directories
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * to be made for files in subordinate ones using relative paths.
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin/*
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * Absent a strcasestr() function, we have to force wildcards on
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * systems for which "AAA" and "aaa" mean the same file.
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#ifdef CASE_BLIND_FILESYSTEM
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#define WILDCARDS_REQUIRED 1
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#else
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#define WILDCARDS_REQUIRED 0
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#endif
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinstatic const char *add_desc(cmd_parms *cmd, void *d, const char *desc,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin const char *to)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin{
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin autoindex_config_rec *dcfg = (autoindex_config_rec *) d;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ai_desc_t *desc_entry;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin char *prefix = "";
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin desc_entry = (ai_desc_t *) apr_array_push(dcfg->desc_list);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin desc_entry->full_path = (ap_strchr_c(to, '/') == NULL) ? 0 : 1;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin desc_entry->wildcards = (WILDCARDS_REQUIRED
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin || desc_entry->full_path
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin || apr_is_fnmatch(to));
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (desc_entry->wildcards) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin prefix = desc_entry->full_path ? "*/" : "*";
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin desc_entry->pattern = apr_pstrcat(dcfg->desc_list->cont,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin prefix, to, "*", NULL);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd else {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd desc_entry->pattern = apr_pstrdup(dcfg->desc_list->cont, to);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin desc_entry->description = apr_pstrdup(dcfg->desc_list->cont, desc);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return NULL;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin}
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinstatic const char *add_ignore(cmd_parms *cmd, void *d, const char *ext)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin{
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin push_item(((autoindex_config_rec *) d)->ign_list, 0, ext, cmd->path, NULL);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return NULL;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin}
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndstatic const char *add_header(cmd_parms *cmd, void *d, const char *name)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd{
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd push_item(((autoindex_config_rec *) d)->hdr_list, 0, NULL, cmd->path,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd name);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd return NULL;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd}
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndstatic const char *add_readme(cmd_parms *cmd, void *d, const char *name)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin{
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin push_item(((autoindex_config_rec *) d)->rdme_list, 0, NULL, cmd->path,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin name);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return NULL;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz}
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/* A legacy directive, FancyIndexing is superseded by the IndexOptions
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * keyword. But for compatibility..
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinstatic const char *fancy_indexing(cmd_parms *cmd, void *d, int arg)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz{
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd int curopts;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd int newopts;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz autoindex_config_rec *cfg;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd cfg = (autoindex_config_rec *) d;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz curopts = cfg->opts;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (curopts & NO_OPTIONS) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return "FancyIndexing directive conflicts with existing "
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin "IndexOptions None";
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin newopts = (arg ? (curopts | FANCY_INDEXING) : (curopts & ~FANCY_INDEXING));
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin cfg->opts = newopts;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return NULL;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin}
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinstatic const char *add_opts(cmd_parms *cmd, void *d, const char *optstr)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz{
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd char *w;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin int opts;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin int opts_add;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin int opts_remove;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin char action;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin autoindex_config_rec *d_cfg = (autoindex_config_rec *) d;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin opts = d_cfg->opts;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin opts_add = d_cfg->incremented_opts;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin opts_remove = d_cfg->decremented_opts;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz while (optstr[0]) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd int option = 0;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd w = ap_getword_conf(cmd->pool, &optstr);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if ((*w == '+') || (*w == '-')) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd action = *(w++);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd else {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd action = '\0';
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (!strcasecmp(w, "FancyIndexing")) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin option = FANCY_INDEXING;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz else if (!strcasecmp(w, "IconsAreLinks")) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz option = ICONS_ARE_LINKS;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(w, "ScanHTMLTitles")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin option = SCAN_HTML_TITLES;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(w, "SuppressLastModified")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin option = SUPPRESS_LAST_MOD;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(w, "SuppressSize")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin option = SUPPRESS_SIZE;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(w, "SuppressDescription")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin option = SUPPRESS_DESC;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(w, "SuppressHTMLPreamble")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin option = SUPPRESS_PREAMBLE;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(w, "SuppressColumnSorting")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin option = SUPPRESS_COLSORT;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(w, "VersionSort")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin option = VERSION_SORT;
717473b4288c54ef043f016a4ee801aba477303erjung }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(w, "None")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (action != '\0') {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return "Cannot combine '+' or '-' with 'None' keyword";
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin opts = NO_OPTIONS;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin opts_add = 0;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin opts_remove = 0;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(w, "IconWidth")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (action != '-') {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->icon_width = DEFAULT_ICON_WIDTH;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->icon_width = 0;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
c840604b10dc1d368a2da321ec51362373d502a3minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strncasecmp(w, "IconWidth=", 10)) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (action == '-') {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return "Cannot combine '-' with IconWidth=n";
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->icon_width = atoi(&w[10]);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(w, "IconHeight")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (action != '-') {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->icon_height = DEFAULT_ICON_HEIGHT;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->icon_height = 0;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strncasecmp(w, "IconHeight=", 11)) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (action == '-') {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return "Cannot combine '-' with IconHeight=n";
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->icon_height = atoi(&w[11]);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(w, "NameWidth")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (action != '-') {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return "NameWidth with no value may only appear as "
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "'-NameWidth'";
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->name_width = DEFAULT_NAME_WIDTH;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->name_adjust = K_NOADJUST;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strncasecmp(w, "NameWidth=", 10)) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (action == '-') {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return "Cannot combine '-' with NameWidth=n";
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (w[10] == '*') {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->name_adjust = K_ADJUST;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin int width = atoi(&w[10]);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (width < 5) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return "NameWidth value must be greater than 5";
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->name_width = width;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->name_adjust = K_NOADJUST;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return "Invalid directory indexing option";
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (action == '\0') {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin opts |= option;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin opts_add = 0;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin opts_remove = 0;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (action == '+') {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin opts_add |= option;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin opts_remove &= ~option;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin opts_remove |= option;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin opts_add &= ~option;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if ((opts & NO_OPTIONS) && (opts & ~NO_OPTIONS)) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return "Cannot combine other IndexOptions keywords with 'None'";
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->incremented_opts = opts_add;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->decremented_opts = opts_remove;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->opts = opts;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return NULL;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin}
51c6a215cedf19fe46a20b5cbb57f01ec4d5e8c4fuankg
5876f43a746f688a32b7201bced8591ddf19bd43minfrinstatic const char *set_default_order(cmd_parms *cmd, void *m, const char *direction,
51c6a215cedf19fe46a20b5cbb57f01ec4d5e8c4fuankg const char *key)
5876f43a746f688a32b7201bced8591ddf19bd43minfrin{
5876f43a746f688a32b7201bced8591ddf19bd43minfrin char temp[4];
5876f43a746f688a32b7201bced8591ddf19bd43minfrin autoindex_config_rec *d_cfg = (autoindex_config_rec *) m;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin apr_cpystrn(temp, "k=d", sizeof(temp));
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (!strcasecmp(direction, "Ascending")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin temp[2] = D_ASCENDING;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(direction, "Descending")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin temp[2] = D_DESCENDING;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return "First keyword must be 'Ascending' or 'Descending'";
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (!strcasecmp(key, "Name")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin temp[0] = K_NAME;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(key, "Date")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin temp[0] = K_LAST_MOD;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(key, "Size")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin temp[0] = K_SIZE;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (!strcasecmp(key, "Description")) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin temp[0] = K_DESC;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return "Second keyword must be 'Name', 'Date', 'Size', or "
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "'Description'";
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (d_cfg->default_order == NULL) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->default_order = apr_palloc(cmd->pool, 4);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin d_cfg->default_order[3] = '\0';
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin apr_cpystrn(d_cfg->default_order, temp, sizeof(temp));
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return NULL;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin}
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin#define DIR_CMD_PERMS OR_INDEXES
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrinstatic const command_rec autoindex_cmds[] =
5876f43a746f688a32b7201bced8591ddf19bd43minfrin{
5876f43a746f688a32b7201bced8591ddf19bd43minfrin AP_INIT_ITERATE2("AddIcon", add_icon, BY_PATH, DIR_CMD_PERMS,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "an icon URL followed by one or more filenames"),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin AP_INIT_ITERATE2("AddIconByType", add_icon, BY_TYPE, DIR_CMD_PERMS,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "an icon URL followed by one or more MIME types"),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin AP_INIT_ITERATE2("AddIconByEncoding", add_icon, BY_ENCODING, DIR_CMD_PERMS,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "an icon URL followed by one or more content encodings"),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin AP_INIT_ITERATE2("AddAlt", add_alt, BY_PATH, DIR_CMD_PERMS,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "alternate descriptive text followed by one or more filenames"),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin AP_INIT_ITERATE2("AddAltByType", add_alt, BY_TYPE, DIR_CMD_PERMS,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "alternate descriptive text followed by one or more MIME types"),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin AP_INIT_ITERATE2("AddAltByEncoding", add_alt, BY_ENCODING, DIR_CMD_PERMS,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "alternate descriptive text followed by one or more content encodings"),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin AP_INIT_RAW_ARGS("IndexOptions", add_opts, NULL, DIR_CMD_PERMS,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "one or more index options"),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin AP_INIT_TAKE2("IndexOrderDefault", set_default_order, NULL, DIR_CMD_PERMS,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "{Ascending,Descending} {Name,Size,Description,Date}"),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin AP_INIT_ITERATE("IndexIgnore", add_ignore, NULL, DIR_CMD_PERMS,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "one or more file extensions"),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin AP_INIT_ITERATE2("AddDescription", add_desc, BY_PATH, DIR_CMD_PERMS,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "Descriptive text followed by one or more filenames"),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin AP_INIT_TAKE1("HeaderName", add_header, NULL, DIR_CMD_PERMS,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "a filename"),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin AP_INIT_TAKE1("ReadmeName", add_readme, NULL, DIR_CMD_PERMS,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "a filename"),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin AP_INIT_FLAG("FancyIndexing", fancy_indexing, NULL, DIR_CMD_PERMS,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "Limited to 'on' or 'off' (superseded by IndexOptions FancyIndexing)"),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin AP_INIT_TAKE1("DefaultIcon", ap_set_string_slot,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin (void *) XtOffsetOf(autoindex_config_rec, default_icon),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin DIR_CMD_PERMS, "an icon URL"),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin {NULL}
5876f43a746f688a32b7201bced8591ddf19bd43minfrin};
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrinstatic void *create_autoindex_config(apr_pool_t *p, char *dummy)
5876f43a746f688a32b7201bced8591ddf19bd43minfrin{
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz autoindex_config_rec *new =
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin new->icon_width = 0;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz new->icon_height = 0;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->name_width = DEFAULT_NAME_WIDTH;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->name_adjust = K_UNSET;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->icon_list = apr_array_make(p, 4, sizeof(struct item));
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->alt_list = apr_array_make(p, 4, sizeof(struct item));
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->desc_list = apr_array_make(p, 4, sizeof(ai_desc_t));
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->ign_list = apr_array_make(p, 4, sizeof(struct item));
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->hdr_list = apr_array_make(p, 4, sizeof(struct item));
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->rdme_list = apr_array_make(p, 4, sizeof(struct item));
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->opts = 0;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin new->incremented_opts = 0;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->decremented_opts = 0;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->default_order = NULL;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd return (void *) new;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd}
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndstatic void *merge_autoindex_configs(apr_pool_t *p, void *basev, void *addv)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd{
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd autoindex_config_rec *new;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd autoindex_config_rec *base = (autoindex_config_rec *) basev;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd autoindex_config_rec *add = (autoindex_config_rec *) addv;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new = (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->default_icon = add->default_icon ? add->default_icon
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd : base->default_icon;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz new->icon_height = add->icon_height ? add->icon_height : base->icon_height;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->icon_width = add->icon_width ? add->icon_width : base->icon_width;
0ecc05d02d9ee3d110cb9e263080aaa2b77a12f9jim
07d000c26f08bb7d590da25057748b28b8b59741jim new->alt_list = apr_array_append(p, add->alt_list, base->alt_list);
07d000c26f08bb7d590da25057748b28b8b59741jim new->ign_list = apr_array_append(p, add->ign_list, base->ign_list);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->hdr_list = apr_array_append(p, add->hdr_list, base->hdr_list);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->desc_list = apr_array_append(p, add->desc_list, base->desc_list);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->icon_list = apr_array_append(p, add->icon_list, base->icon_list);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin new->rdme_list = apr_array_append(p, add->rdme_list, base->rdme_list);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (add->opts & NO_OPTIONS) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /*
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * If the current directory says 'no options' then we also
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * clear any incremental mods from being inheritable further down.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->opts = NO_OPTIONS;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->incremented_opts = 0;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz new->decremented_opts = 0;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd else {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /*
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * If there were any nonincremental options selected for
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * this directory, they dominate and we don't inherit *anything.*
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * Contrariwise, we *do* inherit if the only settings here are
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * incremental ones.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (add->opts == 0) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->incremented_opts = (base->incremented_opts
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd | add->incremented_opts)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd & ~add->decremented_opts;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->decremented_opts = (base->decremented_opts
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd | add->decremented_opts);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /*
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * We may have incremental settings, so make sure we don't
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * inadvertently inherit an IndexOptions None from above.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->opts = (base->opts & ~NO_OPTIONS);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd else {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /*
6850c836b8c7c688ef8a8ec280e798e1d0bfbf01trawick * There are local nonincremental settings, which clear
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * all inheritance from above. They *are* the new base settings.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->opts = add->opts;;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /*
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * We're guaranteed that there'll be no overlap between
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * the add-options and the remove-options.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->opts |= new->incremented_opts;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->opts &= ~new->decremented_opts;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /*
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * Inherit the NameWidth settings if there aren't any specific to
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * the new location; otherwise we'll end up using the defaults set in the
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * config-rec creation routine.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (add->name_adjust == K_UNSET) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->name_width = base->name_width;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->name_adjust = base->name_adjust;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd else {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->name_width = add->name_width;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd new->name_adjust = add->name_adjust;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin new->default_order = (add->default_order != NULL)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ? add->default_order : base->default_order;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd return new;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd}
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd/****************************************************************
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd *
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * Looking things up in config entries...
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd/* Structure used to hold entries when we're actually building an index */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndstruct ent {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd char *name;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd char *icon;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd char *alt;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd char *desc;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd off_t size;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd apr_time_t lm;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd struct ent *next;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd int ascending, version_sort;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd char key;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd};
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndstatic char *find_item(request_rec *r, apr_array_header_t *list, int path_only)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd{
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd const char *content_type = ap_field_noparam(r->pool, r->content_type);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd const char *content_encoding = r->content_encoding;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd char *path = r->filename;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd struct item *items = (struct item *) list->elts;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd int i;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd for (i = 0; i < list->nelts; ++i) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd struct item *p = &items[i];
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if ((path[0] == '^') || (!ap_strcmp_match(path, p->apply_path))) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (!*(p->apply_to)) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd return p->data;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd else if (p->type == BY_PATH || path[0] == '^') {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (!ap_strcmp_match(path, p->apply_to)) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd return p->data;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd else if (!path_only) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (!content_encoding) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (p->type == BY_TYPE) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (content_type
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd && !ap_strcasecmp_match(content_type,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd p->apply_to)) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd return p->data;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz else {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (p->type == BY_ENCODING) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (!ap_strcasecmp_match(content_encoding,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz p->apply_to)) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return p->data;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
7585f3892ce3057554a5bef740302dd479b223b2nd }
13be69a729c912bea7d0aa22596b92717df92551pquerna }
7585f3892ce3057554a5bef740302dd479b223b2nd }
7585f3892ce3057554a5bef740302dd479b223b2nd return NULL;
7585f3892ce3057554a5bef740302dd479b223b2nd}
7585f3892ce3057554a5bef740302dd479b223b2nd
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#define find_icon(d,p,t) find_item(p,d->icon_list,t)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#define find_alt(d,p,t) find_item(p,d->alt_list,t)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#define find_header(d,p) find_item(p,d->hdr_list,0)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#define find_readme(d,p) find_item(p,d->rdme_list,0)
e8f95a682820a599fe41b22977010636be5c2717jim
85fa7868b2734d79c4e27b74d54b6846a1f9176fcolmstatic char *find_default_icon(autoindex_config_rec *d, char *bogus_name)
13be69a729c912bea7d0aa22596b92717df92551pquerna{
e8f95a682820a599fe41b22977010636be5c2717jim request_rec r;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
13be69a729c912bea7d0aa22596b92717df92551pquerna /* Bleah. I tried to clean up find_item, and it lead to this bit
13be69a729c912bea7d0aa22596b92717df92551pquerna * of ugliness. Note that the fields initialized are precisely
13be69a729c912bea7d0aa22596b92717df92551pquerna * those that find_item looks at...
13be69a729c912bea7d0aa22596b92717df92551pquerna */
13be69a729c912bea7d0aa22596b92717df92551pquerna
13be69a729c912bea7d0aa22596b92717df92551pquerna r.filename = bogus_name;
13be69a729c912bea7d0aa22596b92717df92551pquerna r.content_type = r.content_encoding = NULL;
13be69a729c912bea7d0aa22596b92717df92551pquerna
13be69a729c912bea7d0aa22596b92717df92551pquerna return find_item(&r, d->icon_list, 1);
13be69a729c912bea7d0aa22596b92717df92551pquerna}
13be69a729c912bea7d0aa22596b92717df92551pquerna
13be69a729c912bea7d0aa22596b92717df92551pquerna/*
13be69a729c912bea7d0aa22596b92717df92551pquerna * Look through the list of pattern/description pairs and return the first one
13be69a729c912bea7d0aa22596b92717df92551pquerna * if any) that matches the filename in the request. If multiple patterns
13be69a729c912bea7d0aa22596b92717df92551pquerna * match, only the first one is used; since the order in the array is the
13be69a729c912bea7d0aa22596b92717df92551pquerna * same as the order in which directives were processed, earlier matching
13be69a729c912bea7d0aa22596b92717df92551pquerna * directives will dominate.
13be69a729c912bea7d0aa22596b92717df92551pquerna */
0696197a54f186a65abacba1037f6fbe0cb975a1niq
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin#ifdef CASE_BLIND_FILESYSTEM
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#define MATCH_FLAGS FNM_CASE_BLIND
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#else
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#define MATCH_FLAGS 0
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin#endif
13be69a729c912bea7d0aa22596b92717df92551pquerna
13be69a729c912bea7d0aa22596b92717df92551pquernastatic char *find_desc(autoindex_config_rec *dcfg, request_rec *r)
13be69a729c912bea7d0aa22596b92717df92551pquerna{
13be69a729c912bea7d0aa22596b92717df92551pquerna int i;
13be69a729c912bea7d0aa22596b92717df92551pquerna ai_desc_t *list = (ai_desc_t *) dcfg->desc_list->elts;
13be69a729c912bea7d0aa22596b92717df92551pquerna const char *filename_full = r->filename;
13be69a729c912bea7d0aa22596b92717df92551pquerna const char *filename_only;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin const char *filename;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
e8f95a682820a599fe41b22977010636be5c2717jim /*
13be69a729c912bea7d0aa22596b92717df92551pquerna * If the filename includes a path, extract just the name itself
13be69a729c912bea7d0aa22596b92717df92551pquerna * for the simple matches.
13be69a729c912bea7d0aa22596b92717df92551pquerna */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if ((filename_only = ap_strrchr_c(filename_full, '/')) == NULL) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin filename_only = filename_full;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin else {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin filename_only++;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin for (i = 0; i < dcfg->desc_list->nelts; ++i) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ai_desc_t *tuple = &list[i];
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin int found;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin /*
9de73d09e50d2daa2b0ba263d01cf6bf972a27fdrpluem * Only use the full-path filename if the pattern contains '/'s.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
af91703d7657e52921bb36c44ff093b2d2077d0cminfrin filename = (tuple->full_path) ? filename_full : filename_only;
af91703d7657e52921bb36c44ff093b2d2077d0cminfrin /*
af91703d7657e52921bb36c44ff093b2d2077d0cminfrin * Make the comparison using the cheapest method; only do
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * wildcard checking if we must.
af91703d7657e52921bb36c44ff093b2d2077d0cminfrin */
af91703d7657e52921bb36c44ff093b2d2077d0cminfrin if (tuple->wildcards) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz found = (apr_fnmatch(tuple->pattern, filename, MATCH_FLAGS) == 0);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz else {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz found = (ap_strstr_c(filename, tuple->pattern) != NULL);
13be69a729c912bea7d0aa22596b92717df92551pquerna }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (found) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return tuple->description;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return NULL;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz}
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic int ignore_entry(autoindex_config_rec *d, char *path)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz{
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd apr_array_header_t *list = d->ign_list;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd struct item *items = (struct item *) list->elts;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin char *tt;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int i;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if ((tt = strrchr(path, '/')) == NULL) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz tt = path;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz else {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz tt++;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz for (i = 0; i < list->nelts; ++i) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz struct item *p = &items[i];
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz char *ap;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
13be69a729c912bea7d0aa22596b92717df92551pquerna if ((ap = strrchr(p->apply_to, '/')) == NULL) {
13be69a729c912bea7d0aa22596b92717df92551pquerna ap = p->apply_to;
85fa7868b2734d79c4e27b74d54b6846a1f9176fcolm }
85fa7868b2734d79c4e27b74d54b6846a1f9176fcolm else {
13be69a729c912bea7d0aa22596b92717df92551pquerna ap++;
e8f95a682820a599fe41b22977010636be5c2717jim }
13be69a729c912bea7d0aa22596b92717df92551pquerna
13be69a729c912bea7d0aa22596b92717df92551pquerna#ifndef CASE_BLIND_FILESYSTEM
13be69a729c912bea7d0aa22596b92717df92551pquerna if (!ap_strcmp_match(path, p->apply_path)
13be69a729c912bea7d0aa22596b92717df92551pquerna && !ap_strcmp_match(tt, ap)) {
13be69a729c912bea7d0aa22596b92717df92551pquerna return 1;
13be69a729c912bea7d0aa22596b92717df92551pquerna }
a059fab04e8584e8bfdcaf1103e2ec6f53f97a14pquerna#else /* !CASE_BLIND_FILESYSTEM */
a059fab04e8584e8bfdcaf1103e2ec6f53f97a14pquerna /*
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * On some platforms, the match must be case-blind. This is really
13be69a729c912bea7d0aa22596b92717df92551pquerna * a factor of the filesystem involved, but we can't detect that
be60e23cacdadb070a83d40086a6d689410acc38rpluem * reliably - so we have to granularise at the OS level.
13be69a729c912bea7d0aa22596b92717df92551pquerna */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (!ap_strcasecmp_match(path, p->apply_path)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin && !ap_strcasecmp_match(tt, ap)) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return 1;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#endif /* !CASE_BLIND_FILESYSTEM */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return 0;
be60e23cacdadb070a83d40086a6d689410acc38rpluem}
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
be60e23cacdadb070a83d40086a6d689410acc38rpluem/*****************************************************************
13be69a729c912bea7d0aa22596b92717df92551pquerna *
13be69a729c912bea7d0aa22596b92717df92551pquerna * Actually generating output
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin */
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin/*
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * Elements of the emitted document:
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * Preamble
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * succeeds for the (content_type == text/html) header file.
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * Header file
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * Emitted if found (and able).
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * H1 tag line
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * Emitted if a header file is NOT emitted.
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * Directory stuff
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * Always emitted.
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * HR
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * Emitted if FANCY_INDEXING is set.
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * Readme file
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * Emitted if found (and able).
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * ServerSig
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * Emitted if ServerSignature is not Off AND a readme file
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * is NOT emitted.
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * Postamble
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin * succeeds for the (content_type == text/html) readme file.
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin */
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin/*
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * emit a plain text file
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin */
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrinstatic void do_emit_plain(request_rec *r, apr_file_t *f)
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin{
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin char buf[IOBUFSIZE + 1];
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin int i, c, ch;
13be69a729c912bea7d0aa22596b92717df92551pquerna apr_size_t n;
13be69a729c912bea7d0aa22596b92717df92551pquerna apr_status_t stat;
13be69a729c912bea7d0aa22596b92717df92551pquerna
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_rputs("<PRE>\n", r);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd while (!apr_file_eof(f)) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin do {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd n = sizeof(char) * IOBUFSIZE;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd stat = apr_file_read(f, buf, &n);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz while (stat != APR_SUCCESS && APR_STATUS_IS_EINTR(stat));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (n == -1 || n == 0) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz break;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd buf[n] = '\0';
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin c = 0;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd while (c < n) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd for (i = c; i < n; i++) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (buf[i] == '<' || buf[i] == '>' || buf[i] == '&') {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz break;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ch = buf[i];
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz buf[i] = '\0';
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_rputs(&buf[c], r);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (ch == '<') {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_rputs("&lt;", r);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz else if (ch == '>') {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_rputs("&gt;", r);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz else if (ch == '&') {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_rputs("&amp;", r);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz c = i + 1;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_rputs("</PRE>\n", r);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz}
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/*
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * Handle the preamble through the H1 tag line, inclusive. Locate
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * the file with a subrequests. Process text/html documents by actually
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * running the subrequest; text/xxx documents get copied verbatim,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * and any other content type is ignored. This means that a non-text
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * document (such as HEADER.gif) might get multiviewed as the result
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * instead of a text document, meaning nothing will be displayed, but
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * oh well.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic void emit_head(request_rec *r, char *header_fname, int suppress_amble,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin char *title)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin{
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_file_t *f = NULL;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd request_rec *rr = NULL;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int emit_amble = 1;
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin int emit_H1 = 1;
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin /*
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin * If there's a header file, send a subrequest to look for it. If it's
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin * found and a text file, handle it -- otherwise fall through and
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin * pretend there's nothing there.
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if ((header_fname != NULL)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin && (rr = ap_sub_req_lookup_uri(header_fname, r, NULL))
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin && (rr->status == HTTP_OK)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz && (rr->filename != NULL)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz && rr->finfo.filetype == APR_REG) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /*
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Check for the two specific cases we allow: text/html and
51c6a215cedf19fe46a20b5cbb57f01ec4d5e8c4fuankg * text/anything-else. The former is allowed to be processed for
51c6a215cedf19fe46a20b5cbb57f01ec4d5e8c4fuankg * SSIs.
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (rr->content_type != NULL) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (!strcasecmp(ap_field_noparam(r->pool, rr->content_type),
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin "text/html")) {
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin /* Hope everything will work... */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz emit_amble = 0;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin emit_H1 = 0;
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (! suppress_amble) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz emit_preamble(r, title);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /*
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * If there's a problem running the subrequest, display the
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * preamble if we didn't do it before -- the header file
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * didn't get displayed.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (ap_run_sub_req(rr) != OK) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* It didn't work */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz emit_amble = suppress_amble;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin emit_H1 = 1;
51c6a215cedf19fe46a20b5cbb57f01ec4d5e8c4fuankg }
51c6a215cedf19fe46a20b5cbb57f01ec4d5e8c4fuankg }
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin else if (!strncasecmp("text/", rr->content_type, 5)) {
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin /*
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * If we can open the file, prefix it with the preamble
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * regardless; since we'll be sending a <PRE> block around
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * the file's contents, any HTML header it had won't end up
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin * where it belongs.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (apr_file_open(&f, rr->filename, APR_READ,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz emit_preamble(r, title);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz emit_amble = 0;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz do_emit_plain(r, f);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_file_close(f);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz emit_H1 = 0;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (emit_amble) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz emit_preamble(r, title);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (emit_H1) {
51c6a215cedf19fe46a20b5cbb57f01ec4d5e8c4fuankg ap_rvputs(r, "<H1>Index of ", title, "</H1>\n", NULL);
51c6a215cedf19fe46a20b5cbb57f01ec4d5e8c4fuankg }
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin if (rr != NULL) {
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin ap_destroy_sub_req(rr);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin}
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd/*
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Handle the Readme file through the postamble, inclusive. Locate
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * the file with a subrequests. Process text/html documents by actually
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * running the subrequest; text/xxx documents get copied verbatim,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * and any other content type is ignored. This means that a non-text
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * document (such as FOOTER.gif) might get multiviewed as the result
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * instead of a text document, meaning nothing will be displayed, but
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * oh well.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz{
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_file_t *f = NULL;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz request_rec *rr = NULL;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int suppress_post = 0;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int suppress_sig = 0;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin /*
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * If there's a readme file, send a subrequest to look for it. If it's
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * found and a text file, handle it -- otherwise fall through and
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * pretend there's nothing there.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if ((readme_fname != NULL)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd && (rr = ap_sub_req_lookup_uri(readme_fname, r, NULL))
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz && (rr->status == HTTP_OK)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz && (rr->filename != NULL)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz && rr->finfo.filetype == APR_REG) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /*
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Check for the two specific cases we allow: text/html and
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * text/anything-else. The former is allowed to be processed for
51c6a215cedf19fe46a20b5cbb57f01ec4d5e8c4fuankg * SSIs.
51c6a215cedf19fe46a20b5cbb57f01ec4d5e8c4fuankg */
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin if (rr->content_type != NULL) {
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin if (!strcasecmp(ap_field_noparam(r->pool, rr->content_type),
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "text/html")) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (ap_run_sub_req(rr) == OK) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* worked... */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz suppress_sig = 1;
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin suppress_post = suppress_amble;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz else if (!strncasecmp("text/", rr->content_type, 5)) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin /*
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin * If we can open the file, suppress the signature.
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin */
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (apr_file_open(&f, rr->filename, APR_READ,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin do_emit_plain(r, f);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin apr_file_close(f);
2c2ced9d18f0b065f620b0ead09ba25e955c3cc7sf suppress_sig = 1;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (!suppress_sig) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin ap_rputs(ap_psignature("", r), r);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (!suppress_post) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin ap_rputs("</BODY></HTML>\n", r);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (rr != NULL) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin ap_destroy_sub_req(rr);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin}
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic char *find_title(request_rec *r)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin{
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin char titlebuf[MAX_STRING_LEN], *find = "<TITLE>";
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin apr_file_t *thefile = NULL;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin int x, y, p;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin apr_size_t n;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (r->status != HTTP_OK) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return NULL;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if ((r->content_type != NULL)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin && (!strcasecmp(ap_field_noparam(r->pool, r->content_type),
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin "text/html")
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin || !strcmp(r->content_type, INCLUDES_MAGIC_TYPE))
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin && !r->content_encoding) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (apr_file_open(&thefile, r->filename, APR_READ,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin APR_OS_DEFAULT, r->pool) != APR_SUCCESS) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return NULL;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin n = sizeof(char) * (MAX_STRING_LEN - 1);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin apr_file_read(thefile, titlebuf, &n);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (n <= 0) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin apr_file_close(thefile);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return NULL;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin titlebuf[n] = '\0';
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin for (x = 0, p = 0; titlebuf[x]; x++) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (apr_toupper(titlebuf[x]) == find[p]) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (!find[++p]) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if ((p = ap_ind(&titlebuf[++x], '<')) != -1) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin titlebuf[x + p] = '\0';
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin /* Scan for line breaks for Tanmoy's secretary */
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin for (y = x; titlebuf[y]; y++) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if ((titlebuf[y] == CR) || (titlebuf[y] == LF)) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (y == x) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin x++;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin else {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin titlebuf[y] = ' ';
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin apr_file_close(thefile);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return apr_pstrdup(r->pool, &titlebuf[x]);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin else {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p = 0;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin apr_file_close(thefile);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return NULL;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin}
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic struct ent *make_autoindex_entry(const char *name, int autoindex_opts,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin autoindex_config_rec *d,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin request_rec *r, char keyid,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin char direction)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin{
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin struct ent *p;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if ((name[0] == '.') && (!name[1])) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return (NULL);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (ignore_entry(d, ap_make_full_path(r->pool, r->filename, name))) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return (NULL);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent));
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->name = apr_pstrdup(r->pool, name);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->size = -1;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->icon = NULL;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->alt = NULL;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->desc = NULL;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->lm = -1;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->key = apr_toupper(keyid);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->ascending = (apr_toupper(direction) == D_ASCENDING);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->version_sort = autoindex_opts & VERSION_SORT;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (autoindex_opts & FANCY_INDEXING) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin request_rec *rr = ap_sub_req_lookup_file(name, r, NULL);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (rr->finfo.filetype != 0) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->lm = rr->finfo.mtime;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (rr->finfo.filetype == APR_DIR) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (!(p->icon = find_icon(d, rr, 1))) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->icon = find_default_icon(d, "^^DIRECTORY^^");
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (!(p->alt = find_alt(d, rr, 1))) {
2c2ced9d18f0b065f620b0ead09ba25e955c3cc7sf p->alt = "DIR";
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->size = -1;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->name = apr_pstrcat(r->pool, name, "/", NULL);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin else {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->icon = find_icon(d, rr, 0);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->alt = find_alt(d, rr, 0);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->size = rr->finfo.size;
2c2ced9d18f0b065f620b0ead09ba25e955c3cc7sf }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->desc = find_desc(d, rr);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if ((!p->desc) && (autoindex_opts & SCAN_HTML_TITLES)) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->desc = apr_pstrdup(r->pool, find_title(rr));
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
2c2ced9d18f0b065f620b0ead09ba25e955c3cc7sf
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin ap_destroy_sub_req(rr);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin /*
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin * We don't need to take any special action for the file size key. If
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin * we did, it would go here.
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin */
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (keyid == K_LAST_MOD) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (p->lm < 0) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->lm = 0;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return (p);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin}
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic char *terminate_description(autoindex_config_rec *d, char *desc,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin int autoindex_opts)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin{
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin int maxsize = 23;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin register int x;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (autoindex_opts & SUPPRESS_LAST_MOD) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin maxsize += 19;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (autoindex_opts & SUPPRESS_SIZE) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin maxsize += 7;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin for (x = 0; desc[x] && (maxsize > 0 || desc[x]=='<'); x++) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (desc[x] == '<') {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin while (desc[x] != '>') {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (!desc[x]) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin maxsize = 0;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin break;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin ++x;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin else if (desc[x] == '&') {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin /* entities like &auml; count as one character */
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin --maxsize;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin for ( ; desc[x] != ';'; ++x) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (desc[x] == '\0') {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin maxsize = 0;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin break;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin else {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin --maxsize;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (!maxsize && desc[x] != '\0') {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin desc[x - 1] = '>'; /* Grump. */
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin desc[x] = '\0'; /* Double Grump! */
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return desc;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin}
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/*
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Emit the anchor for the specified field. If a field is the key for the
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * current request, the link changes its meaning to reverse the order when
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * selected again. Non-active fields always start in ascending order.
1018201f5223624476334c6e23aead02db7c4040minfrin */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic void emit_link(request_rec *r, char *anchor, char fname, char curkey,
1018201f5223624476334c6e23aead02db7c4040minfrin char curdirection, int nosort)
9333012aa2af9e669db651f0ade3e044ccc3ec84rpluem{
1018201f5223624476334c6e23aead02db7c4040minfrin char qvalue[5];
9333012aa2af9e669db651f0ade3e044ccc3ec84rpluem int reverse;
2d728410bcf9e6e53698bb035f516e18efd76d8bnd
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (!nosort) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin qvalue[0] = '?';
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin qvalue[1] = fname;
487d8b4e063696dd9698792a13c8e426635f1072nd qvalue[2] = '=';
2d728410bcf9e6e53698bb035f516e18efd76d8bnd qvalue[4] = '\0';
2d728410bcf9e6e53698bb035f516e18efd76d8bnd reverse = ((curkey == fname) && (curdirection == D_ASCENDING));
2d728410bcf9e6e53698bb035f516e18efd76d8bnd qvalue[3] = reverse ? D_DESCENDING : D_ASCENDING;
2d728410bcf9e6e53698bb035f516e18efd76d8bnd ap_rvputs(r, "<A HREF=\"", qvalue, "\">", anchor, "</A>", NULL);
487d8b4e063696dd9698792a13c8e426635f1072nd }
2d728410bcf9e6e53698bb035f516e18efd76d8bnd else {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_rputs(anchor, r);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin}
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
487d8b4e063696dd9698792a13c8e426635f1072ndstatic void output_directories(struct ent **ar, int n,
2d728410bcf9e6e53698bb035f516e18efd76d8bnd autoindex_config_rec *d, request_rec *r,
2d728410bcf9e6e53698bb035f516e18efd76d8bnd int autoindex_opts, char keyid, char direction)
487d8b4e063696dd9698792a13c8e426635f1072nd{
2d728410bcf9e6e53698bb035f516e18efd76d8bnd int x;
2d728410bcf9e6e53698bb035f516e18efd76d8bnd apr_size_t rv;
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantz char *name = r->uri;
487d8b4e063696dd9698792a13c8e426635f1072nd char *tp;
2d728410bcf9e6e53698bb035f516e18efd76d8bnd int static_columns = (autoindex_opts & SUPPRESS_COLSORT);
2d728410bcf9e6e53698bb035f516e18efd76d8bnd apr_pool_t *scratch;
487d8b4e063696dd9698792a13c8e426635f1072nd int name_width;
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantz char *name_scratch;
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantz char *pad_scratch;
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantz
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantz apr_pool_create(&scratch, r->pool);
2d728410bcf9e6e53698bb035f516e18efd76d8bnd if (name[0] == '\0') {
487d8b4e063696dd9698792a13c8e426635f1072nd name = "/";
4dd97ffc9c529494e0ec820fe9de80b39b589d42minfrin }
5dc4220fc22561537ce1421a03e11846a5b719ebminfrin
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin name_width = d->name_width;
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin if (d->name_adjust == K_ADJUST) {
487d8b4e063696dd9698792a13c8e426635f1072nd for (x = 0; x < n; x++) {
487d8b4e063696dd9698792a13c8e426635f1072nd int t = strlen(ar[x]->name);
487d8b4e063696dd9698792a13c8e426635f1072nd if (t > name_width) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin name_width = t;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
2d728410bcf9e6e53698bb035f516e18efd76d8bnd }
2d728410bcf9e6e53698bb035f516e18efd76d8bnd }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin name_scratch = apr_palloc(r->pool, name_width + 1);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin pad_scratch = apr_palloc(r->pool, name_width + 1);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin memset(pad_scratch, ' ', name_width);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin pad_scratch[name_width] = '\0';
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (autoindex_opts & FANCY_INDEXING) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ap_rputs("<PRE>", r);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ap_rvputs(r, "<IMG SRC=\"", ap_escape_html(scratch, tp),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "\" ALT=\" \"", NULL);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (d->icon_width && d->icon_height) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin ap_rprintf
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin (
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin r,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin " HEIGHT=\"%d\" WIDTH=\"%d\"",
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin d->icon_height,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin d->icon_width
2d728410bcf9e6e53698bb035f516e18efd76d8bnd );
2d728410bcf9e6e53698bb035f516e18efd76d8bnd }
2d728410bcf9e6e53698bb035f516e18efd76d8bnd ap_rputs("> ", r);
2d728410bcf9e6e53698bb035f516e18efd76d8bnd }
2d728410bcf9e6e53698bb035f516e18efd76d8bnd emit_link(r, "Name", K_NAME, keyid, direction, static_columns);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_rputs(pad_scratch + 4, r);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /*
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * Emit the guaranteed-at-least-one-space-between-columns byte.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick ap_rputs(" ", r);
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick emit_link(r, "Last modified", K_LAST_MOD, keyid, direction,
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick static_columns);
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick ap_rputs(" ", r);
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick }
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin if (!(autoindex_opts & SUPPRESS_SIZE)) {
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin emit_link(r, "Size", K_SIZE, keyid, direction, static_columns);
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin ap_rputs(" ", r);
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin }
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin if (!(autoindex_opts & SUPPRESS_DESC)) {
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin emit_link(r, "Description", K_DESC, keyid, direction,
5c345baea74f2eb2d74548bed271370b972499e5minfrin static_columns);
5c345baea74f2eb2d74548bed271370b972499e5minfrin }
5c345baea74f2eb2d74548bed271370b972499e5minfrin ap_rputs("\n<HR>\n", r);
5c345baea74f2eb2d74548bed271370b972499e5minfrin }
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin else {
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin ap_rputs("<UL>", r);
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin }
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin for (x = 0; x < n; x++) {
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin char *anchor, *t, *t2;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim int nwidth;
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin apr_pool_clear(scratch);
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin if (is_parent(ar[x]->name)) {
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin t = ap_make_full_path(scratch, name, "../");
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin ap_getparents(t);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (t[0] == '\0') {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz t = "/";
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz t2 = "Parent Directory";
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz anchor = ap_escape_html(scratch, ap_os_escape_path(scratch, t, 0));
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd else {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz t = ar[x]->name;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd t2 = t;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz anchor = ap_escape_html(scratch, ap_os_escape_path(scratch, t, 0));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (autoindex_opts & FANCY_INDEXING) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (autoindex_opts & ICONS_ARE_LINKS) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_rvputs(r, "<A HREF=\"", anchor, "\">", NULL);
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin }
ef20451e98932c1245225b211c7198cb6c0a8624minfrin if ((ar[x]->icon) || d->default_icon) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_rvputs(r, "<IMG SRC=\"",
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_escape_html(scratch,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ar[x]->icon ? ar[x]->icon
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz : d->default_icon),
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "\" ALT=\"[", (ar[x]->alt ? ar[x]->alt : " "),
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "]\"", NULL);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (d->icon_width && d->icon_height) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_rprintf(r, " HEIGHT=\"%d\" WIDTH=\"%d\"",
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin d->icon_height, d->icon_width);
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_rputs(">", r);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (autoindex_opts & ICONS_ARE_LINKS) {
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantz ap_rputs("</A>", r);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
f81f966693feefb53f11dc3363b864779873a608nd
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz nwidth = strlen(t2);
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin if (nwidth > name_width) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz memcpy(name_scratch, t2, name_width - 3);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz name_scratch[name_width - 3] = '.';
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz name_scratch[name_width - 2] = '.';
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz name_scratch[name_width - 1] = '>';
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz name_scratch[name_width] = 0;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz t2 = name_scratch;
2d728410bcf9e6e53698bb035f516e18efd76d8bnd nwidth = name_width;
2d728410bcf9e6e53698bb035f516e18efd76d8bnd }
2d728410bcf9e6e53698bb035f516e18efd76d8bnd ap_rvputs(r, " <A HREF=\"", anchor, "\">",
2d728410bcf9e6e53698bb035f516e18efd76d8bnd ap_escape_html(scratch, t2), "</A>", pad_scratch + nwidth,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz NULL);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /*
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * The blank before the storm.. er, before the next field.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_rputs(" ", r);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (ar[x]->lm != -1) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz char time_str[MAX_STRING_LEN];
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_exploded_time_t ts;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_explode_localtime(&ts, ar[x]->lm);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_strftime(time_str, &rv, MAX_STRING_LEN,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "%d-%b-%Y %H:%M ", &ts);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_rputs(time_str, r);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz else {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /*Length="22-Feb-1998 23:42 " (see 4 lines above) */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_rputs(" ", r);
1018201f5223624476334c6e23aead02db7c4040minfrin }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (!(autoindex_opts & SUPPRESS_SIZE)) {
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin ap_send_size(ar[x]->size, r);
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin ap_rputs(" ", r);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (!(autoindex_opts & SUPPRESS_DESC)) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (ar[x]->desc) {
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick ap_rputs(terminate_description(d, ar[x]->desc,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd autoindex_opts), r);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz else {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_rvputs(r, "<LI><A HREF=\"", anchor, "\"> ", t2,
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick "</A>", NULL);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_rputc('\n', r);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (autoindex_opts & FANCY_INDEXING) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_rputs("</PRE>", r);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick else {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_rputs("</UL>", r);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd}
e8f95a682820a599fe41b22977010636be5c2717jim
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantz/*
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantz * Compare two file entries according to the sort criteria. The return
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick * is essentially a signum function value.
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantz */
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantz
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantzstatic int dsortf(struct ent **e1, struct ent **e2)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd{
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd struct ent *c1;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd struct ent *c2;
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick int result = 0;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /*
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * First, see if either of the entries is for the parent directory.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * If so, that *always* sorts lower than anything else.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (is_parent((*e1)->name)) {
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick return -1;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (is_parent((*e2)->name)) {
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantz return 1;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /*
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * All of our comparisons will be of the c1 entry against the c2 one,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * so assign them appropriately to take care of the ordering.
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if ((*e1)->ascending) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz c1 = *e1;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz c2 = *e2;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz else {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz c1 = *e2;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd c2 = *e1;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick switch (c1->key) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd case K_LAST_MOD:
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (c1->lm > c2->lm) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd return 1;
487d8b4e063696dd9698792a13c8e426635f1072nd }
487d8b4e063696dd9698792a13c8e426635f1072nd else if (c1->lm < c2->lm) {
487d8b4e063696dd9698792a13c8e426635f1072nd return -1;
487d8b4e063696dd9698792a13c8e426635f1072nd }
487d8b4e063696dd9698792a13c8e426635f1072nd break;
487d8b4e063696dd9698792a13c8e426635f1072nd case K_SIZE:
487d8b4e063696dd9698792a13c8e426635f1072nd if (c1->size > c2->size) {
487d8b4e063696dd9698792a13c8e426635f1072nd return 1;
487d8b4e063696dd9698792a13c8e426635f1072nd }
15351ab1a34130c1f880daef4e5dc15407a75969colm else if (c1->size < c2->size) {
15351ab1a34130c1f880daef4e5dc15407a75969colm return -1;
15351ab1a34130c1f880daef4e5dc15407a75969colm }
487d8b4e063696dd9698792a13c8e426635f1072nd break;
487d8b4e063696dd9698792a13c8e426635f1072nd case K_DESC:
487d8b4e063696dd9698792a13c8e426635f1072nd if (c1->version_sort)
487d8b4e063696dd9698792a13c8e426635f1072nd result = apr_strnatcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : "");
487d8b4e063696dd9698792a13c8e426635f1072nd else
487d8b4e063696dd9698792a13c8e426635f1072nd result = strcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : "");
1018201f5223624476334c6e23aead02db7c4040minfrin if (result) {
1018201f5223624476334c6e23aead02db7c4040minfrin return result;
487d8b4e063696dd9698792a13c8e426635f1072nd }
487d8b4e063696dd9698792a13c8e426635f1072nd break;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (c1->version_sort)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return apr_strnatcmp(c1->name, c2->name);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin else
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return strcmp(c1->name, c2->name);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin}
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinstatic int index_directory(request_rec *r,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin autoindex_config_rec *autoindex_conf)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin{
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin char *title_name = ap_escape_html(r->pool, r->uri);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin char *title_endp;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin char *name = r->filename;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin apr_finfo_t dirent;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin apr_dir_t *thedir;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin apr_status_t status;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin int num_ent = 0, x;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin struct ent *head, *p;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin struct ent **ar = NULL;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin const char *qstring;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin int autoindex_opts = autoindex_conf->opts;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin char keyid;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin char direction;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if ((status = apr_dir_open(&thedir, name, r->pool)) != APR_SUCCESS) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin "Can't open directory for index: %s", r->filename);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return HTTP_FORBIDDEN;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#if APR_HAS_UNICODE_FS
5876f43a746f688a32b7201bced8591ddf19bd43minfrin r->content_type = "text/html;charset=utf-8";
5876f43a746f688a32b7201bced8591ddf19bd43minfrin#else
5876f43a746f688a32b7201bced8591ddf19bd43minfrin r->content_type = "text/html";
5876f43a746f688a32b7201bced8591ddf19bd43minfrin#endif
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ap_update_mtime(r, r->finfo.mtime);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ap_set_last_modified(r);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ap_set_etag(r);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ap_send_http_header(r);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (r->header_only) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin apr_dir_close(thedir);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return 0;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Spew HTML preamble */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick title_endp = title_name + strlen(title_name) - 1;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd while (title_endp > title_name && *title_endp == '/') {
1018201f5223624476334c6e23aead02db7c4040minfrin *title_endp-- = '\0';
1018201f5223624476334c6e23aead02db7c4040minfrin }
c42b94a839cae93073d33b0d21f0ff1118d958e8poirier
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd emit_head(r, find_header(autoindex_conf, r),
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz autoindex_opts & SUPPRESS_PREAMBLE, title_name);
5dc4220fc22561537ce1421a03e11846a5b719ebminfrin
5dc4220fc22561537ce1421a03e11846a5b719ebminfrin /*
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin * Figure out what sort of indexing (if any) we're supposed to use.
5dc4220fc22561537ce1421a03e11846a5b719ebminfrin *
5dc4220fc22561537ce1421a03e11846a5b719ebminfrin * If no QUERY_STRING was specified or column sorting has been
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin * explicitly disabled, we use the default specified by the
5dc4220fc22561537ce1421a03e11846a5b719ebminfrin * IndexOrderDefault directive (if there is one); otherwise,
5dc4220fc22561537ce1421a03e11846a5b719ebminfrin * we fall back to ascending by name.
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin */
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin qstring = r->args;
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin if ((autoindex_opts & SUPPRESS_COLSORT)
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin || ((qstring == NULL) || (*qstring == '\0'))) {
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin qstring = autoindex_conf->default_order;
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin }
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin /*
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin * If there is no specific ordering defined for this directory,
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin * default to ascending by filename.
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin */
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin if ((qstring == NULL) || (*qstring == '\0')) {
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin keyid = K_NAME;
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin direction = D_ASCENDING;
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin }
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin else {
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin keyid = *qstring;
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin ap_getword(r->pool, &qstring, '=');
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin if (qstring != '\0') {
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin direction = *qstring;
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin }
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin else {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd direction = D_ASCENDING;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
1018201f5223624476334c6e23aead02db7c4040minfrin /*
c42b94a839cae93073d33b0d21f0ff1118d958e8poirier * Since we don't know how many dir. entries there are, put them into a
1018201f5223624476334c6e23aead02db7c4040minfrin * linked list and then arrayificate them so qsort can use them.
1018201f5223624476334c6e23aead02db7c4040minfrin */
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin head = NULL;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin while (apr_dir_read(&dirent, APR_FINFO_DIRENT, thedir) == APR_SUCCESS) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p = make_autoindex_entry(dirent.name, autoindex_opts,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin autoindex_conf, r, keyid, direction);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (p != NULL) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p->next = head;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin head = p;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin num_ent++;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (num_ent > 0) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin ar = (struct ent **) apr_palloc(r->pool,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin num_ent * sizeof(struct ent *));
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p = head;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin x = 0;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin while (p) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin ar[x++] = p;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin p = p->next;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin qsort((void *) ar, num_ent, sizeof(struct ent *),
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin (int (*)(const void *, const void *)) dsortf);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin output_directories(ar, num_ent, autoindex_conf, r, autoindex_opts, keyid,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin direction);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin apr_dir_close(thedir);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin if (autoindex_opts & FANCY_INDEXING) {
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin ap_rputs("<HR>\n", r);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin }
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin emit_tail(r, find_readme(autoindex_conf, r),
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin autoindex_opts & SUPPRESS_PREAMBLE);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return 0;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin}
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin/* The formal handler... */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic int handle_autoindex(request_rec *r)
1018201f5223624476334c6e23aead02db7c4040minfrin{
1018201f5223624476334c6e23aead02db7c4040minfrin autoindex_config_rec *d;
1018201f5223624476334c6e23aead02db7c4040minfrin int allow_opts;
1018201f5223624476334c6e23aead02db7c4040minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if(strcmp(r->handler,DIR_MAGIC_TYPE))
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return DECLINED;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz allow_opts = ap_allow_options(r);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
1018201f5223624476334c6e23aead02db7c4040minfrin d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config,
1018201f5223624476334c6e23aead02db7c4040minfrin &autoindex_module);
1018201f5223624476334c6e23aead02db7c4040minfrin
1018201f5223624476334c6e23aead02db7c4040minfrin r->allowed |= (1 << M_GET);
1018201f5223624476334c6e23aead02db7c4040minfrin if (r->method_number != M_GET) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return DECLINED;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin /* OK, nothing easy. Trot out the heavy artillery... */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (allow_opts & OPT_INDEXES) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* KLUDGE --- make the sub_req lookups happen in the right directory.
1018201f5223624476334c6e23aead02db7c4040minfrin * Fixing this in the sub_req_lookup functions themselves is difficult,
c42b94a839cae93073d33b0d21f0ff1118d958e8poirier * and would probably break virtual includes...
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (r->filename[strlen(r->filename) - 1] != '/') {
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin r->filename = apr_pstrcat(r->pool, r->filename, "/", NULL);
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin }
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin return index_directory(r, d);
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin }
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin else {
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "Directory index forbidden by rule: %s", r->filename);
03ee592beedc99301c3c79838af79a333af47361minfrin return HTTP_FORBIDDEN;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin}
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic void register_hooks(apr_pool_t *p)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz{
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_hook_handler(handle_autoindex,NULL,NULL,APR_HOOK_MIDDLE);
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin}
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrinmodule AP_MODULE_DECLARE_DATA autoindex_module =
5dc4220fc22561537ce1421a03e11846a5b719ebminfrin{
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin STANDARD20_MODULE_STUFF,
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin create_autoindex_config, /* dir config creater */
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin merge_autoindex_configs, /* dir merger --- default is to override */
5dc4220fc22561537ce1421a03e11846a5b719ebminfrin NULL, /* server config */
5dc4220fc22561537ce1421a03e11846a5b719ebminfrin NULL, /* merge server config */
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin autoindex_cmds, /* command apr_table_t */
5dc4220fc22561537ce1421a03e11846a5b719ebminfrin register_hooks /* register hooks */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd};
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz