mod_autoindex.c revision 2dcfdce30a4dabc6a194c367c9ef5e53d37df638
842ae4bd224140319ae7feec1872b93dfd491143fielding/* ====================================================================
842ae4bd224140319ae7feec1872b93dfd491143fielding * The Apache Software License, Version 1.1
842ae4bd224140319ae7feec1872b93dfd491143fielding *
842ae4bd224140319ae7feec1872b93dfd491143fielding * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
842ae4bd224140319ae7feec1872b93dfd491143fielding * reserved.
842ae4bd224140319ae7feec1872b93dfd491143fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Redistribution and use in source and binary forms, with or without
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * modification, are permitted provided that the following conditions
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * are met:
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 1. Redistributions of source code must retain the above copyright
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * notice, this list of conditions and the following disclaimer.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 2. Redistributions in binary form must reproduce the above copyright
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * notice, this list of conditions and the following disclaimer in
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the documentation and/or other materials provided with the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * distribution.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * 3. The end-user documentation included with the redistribution,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * if any, must include the following acknowledgment:
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * "This product includes software developed by the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Apache Software Foundation (http://www.apache.org/)."
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Alternately, this acknowledgment may appear in the software itself,
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * if and wherever such third-party acknowledgments normally appear.
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein *
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * 4. The names "Apache" and "Apache Software Foundation" must
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * not be used to endorse or promote products derived from this
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * software without prior written permission. For written
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * permission, please contact apache@apache.org.
be3223a6a18d9a3a3cf7155d5430a5d92bcddceegstein *
573394373c777e1624a481160f3d02f8fb09f3ffrjung * 5. Products derived from this software may not be called "Apache",
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * nor may "Apache" appear in their name, without prior written
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * permission of the Apache Software Foundation.
1b21d7b3d97def358b2e923655edeb16613a1c31gstein *
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
d633ae407c3c956cb2d67ff27055ff0e640967adfuankg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
d633ae407c3c956cb2d67ff27055ff0e640967adfuankg * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
d633ae407c3c956cb2d67ff27055ff0e640967adfuankg * SUCH DAMAGE.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ====================================================================
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * This software consists of voluntary contributions made by many
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * individuals on behalf of the Apache Software Foundation. For more
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * information on the Apache Software Foundation, please see
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * <http://www.apache.org/>.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
cf8fe49d9d89cfa4b62cb2b1376ca6f25b81b362trawick * Portions of this software are based upon public domain software
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * originally written at the National Center for Supercomputing Applications,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * University of Illinois, Urbana-Champaign.
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf */
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf/*
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf * mod_autoindex.c: Handles the on-the-fly html index generation
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf *
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf * Rob McCool
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf * 3/23/93
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf *
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf * Adapted to Apache by rst.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi * Version sort added by Martin Pool <mbp@humbug.org.au>.
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "apr_strings.h"
a7318397b355119d990d1f311b951dea2aafc53arbb#include "apr_fnmatch.h"
a7318397b355119d990d1f311b951dea2aafc53arbb#include "apr_strings.h"
ce4dc40a4e87991087488f70d96d3447d7557294sf#include "apr_lib.h"
a7318397b355119d990d1f311b951dea2aafc53arbb
a7318397b355119d990d1f311b951dea2aafc53arbb#define APR_WANT_STRFUNC
cb9e6e5c78f5a1690214e9548250fc6af1fc73b5wrowe#include "apr_want.h"
cb9e6e5c78f5a1690214e9548250fc6af1fc73b5wrowe
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "ap_config.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "httpd.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_config.h"
8a3228198adb03e6996f7738c361a612777ecab6aaron#include "http_core.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_request.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_protocol.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_log.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_main.h"
8a3228198adb03e6996f7738c361a612777ecab6aaron#include "util_script.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "mod_core.h"
8a3228198adb03e6996f7738c361a612777ecab6aaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingmodule AP_MODULE_DECLARE_DATA autoindex_module;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
8a3228198adb03e6996f7738c361a612777ecab6aaron/****************************************************************
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Handling configuration directives...
8a3228198adb03e6996f7738c361a612777ecab6aaron */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define NO_OPTIONS 0x0001 /* Indexing options */
8a3228198adb03e6996f7738c361a612777ecab6aaron#define ICONS_ARE_LINKS 0x0002
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SCAN_HTML_TITLES 0x0004
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_ICON 0x0008
8a3228198adb03e6996f7738c361a612777ecab6aaron#define SUPPRESS_LAST_MOD 0x0010
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_SIZE 0x0020
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_DESC 0x0040
8a3228198adb03e6996f7738c361a612777ecab6aaron#define SUPPRESS_PREAMBLE 0x0080
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_COLSORT 0x0100
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_RULES 0x0200
8a3228198adb03e6996f7738c361a612777ecab6aaron#define FOLDERS_FIRST 0x0400
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define VERSION_SORT 0x0800
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define TRACK_MODIFIED 0x1000
8a3228198adb03e6996f7738c361a612777ecab6aaron#define FANCY_INDEXING 0x2000
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define TABLE_INDEXING 0x4000
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define IGNORE_CLIENT 0x8000
8a3228198adb03e6996f7738c361a612777ecab6aaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_NOADJUST 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_ADJUST 1
8a3228198adb03e6996f7738c361a612777ecab6aaron#define K_UNSET 2
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
8a3228198adb03e6996f7738c361a612777ecab6aaron * Define keys for sorting.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_NAME 'N' /* Sort by file name (default) */
8a3228198adb03e6996f7738c361a612777ecab6aaron#define K_LAST_MOD 'M' /* Last modification date */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_SIZE 'S' /* Size (absolute, not as displayed) */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_DESC 'D' /* Description */
8a3228198adb03e6996f7738c361a612777ecab6aaron#define K_VALID "NMSD" /* String containing _all_ valid K_ opts */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define D_ASCENDING 'A'
8a3228198adb03e6996f7738c361a612777ecab6aaron#define D_DESCENDING 'D'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define D_VALID "AD" /* String containing _all_ valid D_ opts */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
8a3228198adb03e6996f7738c361a612777ecab6aaron/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * These are the dimensions of the default icons supplied with Apache.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
8a3228198adb03e6996f7738c361a612777ecab6aaron#define DEFAULT_ICON_WIDTH 20
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define DEFAULT_ICON_HEIGHT 22
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
8a3228198adb03e6996f7738c361a612777ecab6aaron/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Other default dimensions.
8a3228198adb03e6996f7738c361a612777ecab6aaron */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define DEFAULT_NAME_WIDTH 23
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define DEFAULT_DESC_WIDTH 23
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstruct item {
8a3228198adb03e6996f7738c361a612777ecab6aaron char *type;
8a3228198adb03e6996f7738c361a612777ecab6aaron char *apply_to;
8a3228198adb03e6996f7738c361a612777ecab6aaron char *apply_path;
8a3228198adb03e6996f7738c361a612777ecab6aaron char *data;
8a3228198adb03e6996f7738c361a612777ecab6aaron};
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aarontypedef struct ai_desc_t {
8a3228198adb03e6996f7738c361a612777ecab6aaron char *pattern;
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf char *description;
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf int full_path;
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf int wildcards;
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf} ai_desc_t;
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sftypedef struct autoindex_config_struct {
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf char *default_icon;
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_int32_t opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_int32_t incremented_opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_int32_t decremented_opts;
649c9dd342a580016d29c2866de88a4609eb6457wrowe int name_width;
649c9dd342a580016d29c2866de88a4609eb6457wrowe int name_adjust;
0f57a69cc84c59eacda1179763ae42ca88f1a577wrowe int desc_width;
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick int desc_adjust;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick int icon_width;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick int icon_height;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick char default_keyid;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick char default_direction;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick apr_array_header_t *icon_list;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick apr_array_header_t *alt_list;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick apr_array_header_t *desc_list;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton apr_array_header_t *ign_list;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim apr_array_header_t *hdr_list;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton apr_array_header_t *rdme_list;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton} autoindex_config_rec;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jortonstatic char c_by_encoding, c_by_type, c_by_path;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton#define BY_ENCODING &c_by_encoding
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton#define BY_TYPE &c_by_type
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton#define BY_PATH &c_by_path
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton/*
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton * This routine puts the standard HTML header at the top of the index page.
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton * We include the DOCTYPE because we may be using features therefrom (i.e.,
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe */
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowestatic void emit_preamble(request_rec *r, char *title)
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton{
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton ap_rvputs(r, DOCTYPE_HTML_3_2,
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton "<html>\n <head>\n <title>Index of ", title,
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton "</title>\n </head>\n <body>\n", NULL);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton}
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jortonstatic void push_item(apr_array_header_t *arr, char *type, const char *to,
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton const char *path, const char *data)
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton{
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton struct item *p = (struct item *) apr_array_push(arr);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton if (!to) {
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton to = "";
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe }
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe if (!path) {
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe path = "";
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe }
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe p->type = type;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim p->data = data ? apr_pstrdup(arr->pool, data) : NULL;
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe p->apply_path = apr_pstrcat(arr->pool, path, "*", NULL);
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe if ((type == BY_PATH) && (!ap_is_matchexp(to))) {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick p->apply_to = apr_pstrcat(arr->pool, "*", to, NULL);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick }
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe else if (to) {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick p->apply_to = apr_pstrdup(arr->pool, to);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick }
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick else {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick p->apply_to = NULL;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick }
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick}
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickstatic const char *add_alt(cmd_parms *cmd, void *d, const char *alt,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick const char *to)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick{
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick if (cmd->info == BY_PATH) {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick if (!strcmp(to, "**DIRECTORY**")) {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick to = "^^DIRECTORY^^";
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick }
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick }
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick if (cmd->info == BY_ENCODING) {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick char *tmp = apr_pstrdup(cmd->pool, to);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick ap_str_tolower(tmp);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick to = tmp;
ebc18d48bea83ee5ed7a1b4e30007e5192539829wrowe }
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick
066877f1a045103acfdd376d48cdd473c33f409bdougm push_item(((autoindex_config_rec *) d)->alt_list, cmd->info, to,
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick cmd->path, alt);
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick return NULL;
e8f95a682820a599fe41b22977010636be5c2717jim}
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowestatic const char *add_icon(cmd_parms *cmd, void *d, const char *icon,
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe const char *to)
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe{
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe char *iconbak = apr_pstrdup(cmd->pool, icon);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe if (icon[0] == '(') {
185aa71728867671e105178b4c66fbc22b65ae26sf char *alt;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe char *cl = strchr(iconbak, ')');
85c435ceda98eab940615e4466d9c5955252e745wrowe
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe if (cl == NULL) {
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe return "missing closing paren";
92eed7d377d8be7cd8e48d1299412fc8c742b7f5jorton }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe alt = ap_getword_nc(cmd->pool, &iconbak, ',');
185aa71728867671e105178b4c66fbc22b65ae26sf *cl = '\0'; /* Lose closing paren */
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe add_alt(cmd, d, &alt[1], to);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe if (cmd->info == BY_PATH) {
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe if (!strcmp(to, "**DIRECTORY**")) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe to = "^^DIRECTORY^^";
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (cmd->info == BY_ENCODING) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe char *tmp = apr_pstrdup(cmd->pool, to);
649c9dd342a580016d29c2866de88a4609eb6457wrowe ap_str_tolower(tmp);
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim to = tmp;
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim push_item(((autoindex_config_rec *) d)->icon_list, cmd->info, to,
649c9dd342a580016d29c2866de88a4609eb6457wrowe cmd->path, iconbak);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe return NULL;
649c9dd342a580016d29c2866de88a4609eb6457wrowe}
649c9dd342a580016d29c2866de88a4609eb6457wrowe
649c9dd342a580016d29c2866de88a4609eb6457wrowe/*
649c9dd342a580016d29c2866de88a4609eb6457wrowe * Add description text for a filename pattern. If the pattern has
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * wildcards already (or we need to add them), add leading and
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * trailing wildcards to it to ensure substring processing. If the
649c9dd342a580016d29c2866de88a4609eb6457wrowe * pattern contains a '/' anywhere, force wildcard matching mode,
649c9dd342a580016d29c2866de88a4609eb6457wrowe * add a slash to the prefix so that "bar/bletch" won't be matched
649c9dd342a580016d29c2866de88a4609eb6457wrowe * by "foobar/bletch", and make a note that there's a delimiter;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe * the matching routine simplifies to just the actual filename
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe * whenever it can. This allows definitions in parent directories
649c9dd342a580016d29c2866de88a4609eb6457wrowe * to be made for files in subordinate ones using relative paths.
649c9dd342a580016d29c2866de88a4609eb6457wrowe */
649c9dd342a580016d29c2866de88a4609eb6457wrowe
649c9dd342a580016d29c2866de88a4609eb6457wrowe/*
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe * Absent a strcasestr() function, we have to force wildcards on
185aa71728867671e105178b4c66fbc22b65ae26sf * systems for which "AAA" and "aaa" mean the same file.
760b90f5b0bb414646deb6a3a2a53c14bf49bf3dwrowe */
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe#ifdef CASE_BLIND_FILESYSTEM
15405e91bb3fad5a80f7abe828a00b44a3a65bf8jerenkrantz#define WILDCARDS_REQUIRED 1
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe#else
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe#define WILDCARDS_REQUIRED 0
76185d819b745e953dd2cd636fbdd515c333e4a4trawick#endif
76185d819b745e953dd2cd636fbdd515c333e4a4trawick
76185d819b745e953dd2cd636fbdd515c333e4a4trawickstatic const char *add_desc(cmd_parms *cmd, void *d, const char *desc,
185aa71728867671e105178b4c66fbc22b65ae26sf const char *to)
76185d819b745e953dd2cd636fbdd515c333e4a4trawick{
76185d819b745e953dd2cd636fbdd515c333e4a4trawick autoindex_config_rec *dcfg = (autoindex_config_rec *) d;
76185d819b745e953dd2cd636fbdd515c333e4a4trawick ai_desc_t *desc_entry;
399cf0e5e061b49593817421b94305889fa6bc1fjorton char *prefix = "";
399cf0e5e061b49593817421b94305889fa6bc1fjorton
399cf0e5e061b49593817421b94305889fa6bc1fjorton desc_entry = (ai_desc_t *) apr_array_push(dcfg->desc_list);
399cf0e5e061b49593817421b94305889fa6bc1fjorton desc_entry->full_path = (ap_strchr_c(to, '/') == NULL) ? 0 : 1;
399cf0e5e061b49593817421b94305889fa6bc1fjorton desc_entry->wildcards = (WILDCARDS_REQUIRED
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm || desc_entry->full_path
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe || apr_is_fnmatch(to));
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe if (desc_entry->wildcards) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding prefix = desc_entry->full_path ? "*/" : "*";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding desc_entry->pattern = apr_pstrcat(dcfg->desc_list->pool,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding prefix, to, "*", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick desc_entry->pattern = apr_pstrdup(dcfg->desc_list->pool, to);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm desc_entry->description = apr_pstrdup(dcfg->desc_list->pool, desc);
399cf0e5e061b49593817421b94305889fa6bc1fjorton return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
5a6a87d8920e385b1ed14177d74ab9786f3acddfwrowestatic const char *add_ignore(cmd_parms *cmd, void *d, const char *ext)
5a6a87d8920e385b1ed14177d74ab9786f3acddfwrowe{
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe push_item(((autoindex_config_rec *) d)->ign_list, 0, ext, cmd->path, NULL);
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh return NULL;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh}
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
76185d819b745e953dd2cd636fbdd515c333e4a4trawickstatic const char *add_header(cmd_parms *cmd, void *d, const char *name)
76185d819b745e953dd2cd636fbdd515c333e4a4trawick{
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim push_item(((autoindex_config_rec *) d)->hdr_list, 0, NULL, cmd->path,
ff0436077dc959b17a6f87825e4a106d211224c1wrowe name);
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb return NULL;
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb}
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic const char *add_readme(cmd_parms *cmd, void *d, const char *name)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm{
8a3228198adb03e6996f7738c361a612777ecab6aaron push_item(((autoindex_config_rec *) d)->rdme_list, 0, NULL, cmd->path,
ff0436077dc959b17a6f87825e4a106d211224c1wrowe name);
ff0436077dc959b17a6f87825e4a106d211224c1wrowe return NULL;
ff0436077dc959b17a6f87825e4a106d211224c1wrowe}
ff0436077dc959b17a6f87825e4a106d211224c1wrowe
ff0436077dc959b17a6f87825e4a106d211224c1wrowestatic const char *add_opts(cmd_parms *cmd, void *d, const char *optstr)
ff0436077dc959b17a6f87825e4a106d211224c1wrowe{
066877f1a045103acfdd376d48cdd473c33f409bdougm char *w;
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_int32_t opts;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh apr_int32_t opts_add;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb apr_int32_t opts_remove;
d521bfef0e1a65993d5e302628ac68a2c91a195ftrawick char action;
20c85ca0d404e29972fb94c3d6236a264d1c77abstoddard autoindex_config_rec *d_cfg = (autoindex_config_rec *) d;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick opts = d_cfg->opts;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick opts_add = d_cfg->incremented_opts;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb opts_remove = d_cfg->decremented_opts;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb while (optstr[0]) {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb int option = 0;
8a3228198adb03e6996f7738c361a612777ecab6aaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding w = ap_getword_conf(cmd->pool, &optstr);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((*w == '+') || (*w == '-')) {
399cf0e5e061b49593817421b94305889fa6bc1fjorton action = *(w++);
399cf0e5e061b49593817421b94305889fa6bc1fjorton }
399cf0e5e061b49593817421b94305889fa6bc1fjorton else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding action = '\0';
061c3874622b67beff724876b9bd1b1f291f2eaafielding }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (!strcasecmp(w, "FancyIndexing")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = FANCY_INDEXING;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung else if (!strcasecmp(w, "FoldersFirst")) {
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe option = FOLDERS_FIRST;
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb else if (!strcasecmp(w, "HTMLTable")) {
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe option = TABLE_INDEXING;
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe }
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim else if (!strcasecmp(w, "IconsAreLinks")) {
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe option = ICONS_ARE_LINKS;
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe }
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe else if (!strcasecmp(w, "IgnoreClient")) {
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe option = IGNORE_CLIENT;
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe }
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe else if (!strcasecmp(w, "ScanHTMLTitles")) {
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe option = SCAN_HTML_TITLES;
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else if (!strcasecmp(w, "SuppressColumnSorting")) {
399cf0e5e061b49593817421b94305889fa6bc1fjorton option = SUPPRESS_COLSORT;
399cf0e5e061b49593817421b94305889fa6bc1fjorton }
399cf0e5e061b49593817421b94305889fa6bc1fjorton else if (!strcasecmp(w, "SuppressDescription")) {
399cf0e5e061b49593817421b94305889fa6bc1fjorton option = SUPPRESS_DESC;
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe }
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung else if (!strcasecmp(w, "SuppressHTMLPreamble")) {
185aa71728867671e105178b4c66fbc22b65ae26sf option = SUPPRESS_PREAMBLE;
19702a9985f3b2f794d22be9102d9d4fbf6bebe7rjung }
783e3e4bd40b8c276b72b49470bfabb8693fb5c2rjung else if (!strcasecmp(w, "SuppressIcon")) {
85c435ceda98eab940615e4466d9c5955252e745wrowe option = SUPPRESS_ICON;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung else if (!strcasecmp(w, "SuppressLastModified")) {
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung option = SUPPRESS_LAST_MOD;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "SuppressSize")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SUPPRESS_SIZE;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
8a3228198adb03e6996f7738c361a612777ecab6aaron else if (!strcasecmp(w, "SuppressRules")) {
8a3228198adb03e6996f7738c361a612777ecab6aaron option = SUPPRESS_RULES;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron else if (!strcasecmp(w, "TrackModified")) {
8a3228198adb03e6996f7738c361a612777ecab6aaron option = TRACK_MODIFIED;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron else if (!strcasecmp(w, "VersionSort")) {
8a3228198adb03e6996f7738c361a612777ecab6aaron option = VERSION_SORT;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
85c435ceda98eab940615e4466d9c5955252e745wrowe else if (!strcasecmp(w, "None")) {
8a3228198adb03e6996f7738c361a612777ecab6aaron if (action != '\0') {
8a3228198adb03e6996f7738c361a612777ecab6aaron return "Cannot combine '+' or '-' with 'None' keyword";
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron opts = NO_OPTIONS;
8a3228198adb03e6996f7738c361a612777ecab6aaron opts_add = 0;
8a3228198adb03e6996f7738c361a612777ecab6aaron opts_remove = 0;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron else if (!strcasecmp(w, "IconWidth")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action != '-') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->icon_width = DEFAULT_ICON_WIDTH;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
8a3228198adb03e6996f7738c361a612777ecab6aaron else {
32c4bc04f89b16521718145dc731f750144d7b38wrowe d_cfg->icon_width = 0;
185aa71728867671e105178b4c66fbc22b65ae26sf }
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung }
32c4bc04f89b16521718145dc731f750144d7b38wrowe else if (!strncasecmp(w, "IconWidth=", 10)) {
85c435ceda98eab940615e4466d9c5955252e745wrowe if (action == '-') {
32c4bc04f89b16521718145dc731f750144d7b38wrowe return "Cannot combine '-' with IconWidth=n";
32c4bc04f89b16521718145dc731f750144d7b38wrowe }
92eed7d377d8be7cd8e48d1299412fc8c742b7f5jorton d_cfg->icon_width = atoi(&w[10]);
32c4bc04f89b16521718145dc731f750144d7b38wrowe }
185aa71728867671e105178b4c66fbc22b65ae26sf else if (!strcasecmp(w, "IconHeight")) {
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung if (action != '-') {
c25e9633c29be3a5b74f0bf75079d54e5417115dwrowe d_cfg->icon_height = DEFAULT_ICON_HEIGHT;
85c435ceda98eab940615e4466d9c5955252e745wrowe }
8a3228198adb03e6996f7738c361a612777ecab6aaron else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->icon_height = 0;
85c435ceda98eab940615e4466d9c5955252e745wrowe }
85c435ceda98eab940615e4466d9c5955252e745wrowe }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strncasecmp(w, "IconHeight=", 11)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action == '-') {
e8f95a682820a599fe41b22977010636be5c2717jim return "Cannot combine '-' with IconHeight=n";
85c435ceda98eab940615e4466d9c5955252e745wrowe }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->icon_height = atoi(&w[11]);
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "NameWidth")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action != '-') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "NameWidth with no value may only appear as "
649c9dd342a580016d29c2866de88a4609eb6457wrowe "'-NameWidth'";
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe d_cfg->name_width = DEFAULT_NAME_WIDTH;
649c9dd342a580016d29c2866de88a4609eb6457wrowe d_cfg->name_adjust = K_NOADJUST;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim }
649c9dd342a580016d29c2866de88a4609eb6457wrowe else if (!strncasecmp(w, "NameWidth=", 10)) {
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim if (action == '-') {
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim return "Cannot combine '-' with NameWidth=n";
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (w[10] == '*') {
f6e47621625cca111811e84e407be84b5b18e9c5sf d_cfg->name_adjust = K_ADJUST;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick }
649c9dd342a580016d29c2866de88a4609eb6457wrowe else {
649c9dd342a580016d29c2866de88a4609eb6457wrowe int width = atoi(&w[10]);
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (width && (width < 5)) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe return "NameWidth value must be greater than 5";
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe d_cfg->name_width = width;
649c9dd342a580016d29c2866de88a4609eb6457wrowe d_cfg->name_adjust = K_NOADJUST;
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
aef88024529c64e3e634c6f3f255e4419ad9182drjung }
649c9dd342a580016d29c2866de88a4609eb6457wrowe else if (!strcasecmp(w, "DescriptionWidth")) {
85c435ceda98eab940615e4466d9c5955252e745wrowe if (action != '-') {
85c435ceda98eab940615e4466d9c5955252e745wrowe return "DescriptionWidth with no value may only appear as "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "'-DescriptionWidth'";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->desc_width = DEFAULT_DESC_WIDTH;
ab43b4a17b2ac31ccb1cf280be8c42a8a314cecbjorton d_cfg->desc_adjust = K_NOADJUST;
aef88024529c64e3e634c6f3f255e4419ad9182drjung }
ab43b4a17b2ac31ccb1cf280be8c42a8a314cecbjorton else if (!strncasecmp(w, "DescriptionWidth=", 17)) {
066877f1a045103acfdd376d48cdd473c33f409bdougm if (action == '-') {
649c9dd342a580016d29c2866de88a4609eb6457wrowe return "Cannot combine '-' with DescriptionWidth=n";
ab43b4a17b2ac31ccb1cf280be8c42a8a314cecbjorton }
185aa71728867671e105178b4c66fbc22b65ae26sf if (w[17] == '*') {
ec727afb817df0e5202135278c0d2902923cc980stoddard d_cfg->desc_adjust = K_ADJUST;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh else {
649c9dd342a580016d29c2866de88a4609eb6457wrowe int width = atoi(&w[17]);
649c9dd342a580016d29c2866de88a4609eb6457wrowe
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (width && (width < 12)) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe return "DescriptionWidth value must be greater than 12";
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe d_cfg->desc_width = width;
ec727afb817df0e5202135278c0d2902923cc980stoddard d_cfg->desc_adjust = K_NOADJUST;
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe }
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe }
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe else {
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe return "Invalid directory indexing option";
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe }
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe if (action == '\0') {
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe opts |= option;
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe opts_add = 0;
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe opts_remove = 0;
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe }
ec727afb817df0e5202135278c0d2902923cc980stoddard else if (action == '+') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding opts_add |= option;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding opts_remove &= ~option;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
0f57a69cc84c59eacda1179763ae42ca88f1a577wrowe opts_remove |= option;
6850c836b8c7c688ef8a8ec280e798e1d0bfbf01trawick opts_add &= ~option;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
185aa71728867671e105178b4c66fbc22b65ae26sf if ((opts & NO_OPTIONS) && (opts & ~NO_OPTIONS)) {
8a3228198adb03e6996f7738c361a612777ecab6aaron return "Cannot combine other IndexOptions keywords with 'None'";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->incremented_opts = opts_add;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->decremented_opts = opts_remove;
8a3228198adb03e6996f7738c361a612777ecab6aaron d_cfg->opts = opts;
8a3228198adb03e6996f7738c361a612777ecab6aaron return NULL;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh}
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
2261031aa94be82d7e6b1b8c367afc1b282317f5ianhstatic const char *set_default_order(cmd_parms *cmd, void *m,
8a3228198adb03e6996f7738c361a612777ecab6aaron const char *direction, const char *key)
8a3228198adb03e6996f7738c361a612777ecab6aaron{
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh autoindex_config_rec *d_cfg = (autoindex_config_rec *) m;
8a3228198adb03e6996f7738c361a612777ecab6aaron
399cf0e5e061b49593817421b94305889fa6bc1fjorton if (!strcasecmp(direction, "Ascending")) {
85c435ceda98eab940615e4466d9c5955252e745wrowe d_cfg->default_direction = D_ASCENDING;
85c435ceda98eab940615e4466d9c5955252e745wrowe }
8a3228198adb03e6996f7738c361a612777ecab6aaron else if (!strcasecmp(direction, "Descending")) {
8a3228198adb03e6996f7738c361a612777ecab6aaron d_cfg->default_direction = D_DESCENDING;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron else {
8a3228198adb03e6996f7738c361a612777ecab6aaron return "First keyword must be 'Ascending' or 'Descending'";
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaron if (!strcasecmp(key, "Name")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->default_keyid = K_NAME;
85c435ceda98eab940615e4466d9c5955252e745wrowe }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(key, "Date")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->default_keyid = K_LAST_MOD;
3d96ee83babeec32482c9082c9426340cee8c44dwrowe }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm else if (!strcasecmp(key, "Size")) {
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb d_cfg->default_keyid = K_SIZE;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh }
4e1e8abb2a6e588366a4680b039b460fc5fe1ccdstoddard else if (!strcasecmp(key, "Description")) {
bdf833c0329ee171eb99efe9c037b6ed653c5007aaron d_cfg->default_keyid = K_DESC;
40303323ae9960bd38a0f03d2c10e897a7badd88rbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Second keyword must be 'Name', 'Date', 'Size', or "
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "'Description'";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#define DIR_CMD_PERMS OR_INDEXES
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const command_rec autoindex_cmds[] =
e34223f72e630187c4d8ac7c22da5096c833eb20trawick{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_ITERATE2("AddIcon", add_icon, BY_PATH, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "an icon URL followed by one or more filenames"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_ITERATE2("AddIconByType", add_icon, BY_TYPE, DIR_CMD_PERMS,
c6c1730850cd8c7149f62efb3f5e8afa25e24f4fminfrin "an icon URL followed by one or more MIME types"),
4240daa133bbeddbc3141553879eda4fccfe93feminfrin AP_INIT_ITERATE2("AddIconByEncoding", add_icon, BY_ENCODING, DIR_CMD_PERMS,
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf "an icon URL followed by one or more content encodings"),
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin AP_INIT_ITERATE2("AddAlt", add_alt, BY_PATH, DIR_CMD_PERMS,
c41be3600a58bd39a76d1215abcdbbd8e9b1c356minfrin "alternate descriptive text followed by one or more filenames"),
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf AP_INIT_ITERATE2("AddAltByType", add_alt, BY_TYPE, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "alternate descriptive text followed by one or more MIME types"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_ITERATE2("AddAltByEncoding", add_alt, BY_ENCODING, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "alternate descriptive text followed by one or more content encodings"),
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh AP_INIT_RAW_ARGS("IndexOptions", add_opts, NULL, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "one or more index options [+|-][]"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_TAKE2("IndexOrderDefault", set_default_order, NULL, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "{Ascending,Descending} {Name,Size,Description,Date}"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_ITERATE("IndexIgnore", add_ignore, NULL, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "one or more file extensions"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_ITERATE2("AddDescription", add_desc, BY_PATH, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "Descriptive text followed by one or more filenames"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_TAKE1("HeaderName", add_header, NULL, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "a filename"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_TAKE1("ReadmeName", add_readme, NULL, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "a filename"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_RAW_ARGS("FancyIndexing", ap_set_deprecated, NULL, OR_ALL,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "The FancyIndexing directive is no longer supported. Use IndexOptions FancyIndexing."),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_TAKE1("DefaultIcon", ap_set_string_slot,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf (void *)APR_OFFSETOF(autoindex_config_rec, default_icon),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf DIR_CMD_PERMS, "an icon URL"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf {NULL}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf};
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic void *create_autoindex_config(apr_pool_t *p, char *dummy)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf autoindex_config_rec *new =
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf new->icon_width = 0;
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf new->icon_height = 0;
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf new->name_width = DEFAULT_NAME_WIDTH;
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf new->name_adjust = K_UNSET;
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf new->desc_width = DEFAULT_DESC_WIDTH;
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf new->desc_adjust = K_UNSET;
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf new->icon_list = apr_array_make(p, 4, sizeof(struct item));
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf new->alt_list = apr_array_make(p, 4, sizeof(struct item));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->desc_list = apr_array_make(p, 4, sizeof(ai_desc_t));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->ign_list = apr_array_make(p, 4, sizeof(struct item));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->hdr_list = apr_array_make(p, 4, sizeof(struct item));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->rdme_list = apr_array_make(p, 4, sizeof(struct item));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->opts = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->incremented_opts = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->decremented_opts = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->default_keyid = '\0';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->default_direction = '\0';
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return (void *) new;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic void *merge_autoindex_configs(apr_pool_t *p, void *basev, void *addv)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf autoindex_config_rec *new;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf autoindex_config_rec *base = (autoindex_config_rec *) basev;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf autoindex_config_rec *add = (autoindex_config_rec *) addv;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new = (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->default_icon = add->default_icon ? add->default_icon
e302f38fd646764ce1a1e1c578d794aef514a9e5sf : base->default_icon;
8a3228198adb03e6996f7738c361a612777ecab6aaron new->icon_height = add->icon_height ? add->icon_height : base->icon_height;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->icon_width = add->icon_width ? add->icon_width : base->icon_width;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->alt_list = apr_array_append(p, add->alt_list, base->alt_list);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->ign_list = apr_array_append(p, add->ign_list, base->ign_list);
baf4649272f3dabd48b095a23b3180cc0105dce6rjung new->hdr_list = apr_array_append(p, add->hdr_list, base->hdr_list);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->desc_list = apr_array_append(p, add->desc_list, base->desc_list);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->icon_list = apr_array_append(p, add->icon_list, base->icon_list);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->rdme_list = apr_array_append(p, add->rdme_list, base->rdme_list);
573394373c777e1624a481160f3d02f8fb09f3ffrjung if (add->opts & NO_OPTIONS) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If the current directory says 'no options' then we also
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * clear any incremental mods from being inheritable further down.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->opts = NO_OPTIONS;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->incremented_opts = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->decremented_opts = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
fcf27b53e98b61c652f3e832561193b21046dd2drjung else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If there were any nonincremental options selected for
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * this directory, they dominate and we don't inherit *anything.*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Contrariwise, we *do* inherit if the only settings here are
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * incremental ones.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (add->opts == 0) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->incremented_opts = (base->incremented_opts
e302f38fd646764ce1a1e1c578d794aef514a9e5sf | add->incremented_opts)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf & ~add->decremented_opts;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->decremented_opts = (base->decremented_opts
573394373c777e1624a481160f3d02f8fb09f3ffrjung | add->decremented_opts);
2b484455736f4c30447aa852764f53282cbeb5ddrbb /*
6c266c0dc27ed2972bfb14a8bd5428065c4b3a8bsf * We may have incremental settings, so make sure we don't
6c266c0dc27ed2972bfb14a8bd5428065c4b3a8bsf * inadvertently inherit an IndexOptions None from above.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->opts = (base->opts & ~NO_OPTIONS);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * There are local nonincremental settings, which clear
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * all inheritance from above. They *are* the new base settings.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->opts = add->opts;;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * We're guaranteed that there'll be no overlap between
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * the add-options and the remove-options.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->opts |= new->incremented_opts;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->opts &= ~new->decremented_opts;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Inherit the NameWidth settings if there aren't any specific to
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * the new location; otherwise we'll end up using the defaults set in the
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * config-rec creation routine.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (add->name_adjust == K_UNSET) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->name_width = base->name_width;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->name_adjust = base->name_adjust;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
0ef41d8e4b94d343e5b093c4dbd6ee61c1279401trawick new->name_width = add->name_width;
8a3228198adb03e6996f7738c361a612777ecab6aaron new->name_adjust = add->name_adjust;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard /*
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard * Likewise for DescriptionWidth.
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard */
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard if (add->desc_adjust == K_UNSET) {
8a3228198adb03e6996f7738c361a612777ecab6aaron new->desc_width = base->desc_width;
8a3228198adb03e6996f7738c361a612777ecab6aaron new->desc_adjust = base->desc_adjust;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron else {
8a3228198adb03e6996f7738c361a612777ecab6aaron new->desc_width = add->desc_width;
8a3228198adb03e6996f7738c361a612777ecab6aaron new->desc_adjust = add->desc_adjust;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaron new->default_keyid = add->default_keyid ? add->default_keyid
8a3228198adb03e6996f7738c361a612777ecab6aaron : base->default_keyid;
8a3228198adb03e6996f7738c361a612777ecab6aaron new->default_direction = add->default_direction ? add->default_direction
8a3228198adb03e6996f7738c361a612777ecab6aaron : base->default_direction;
8a3228198adb03e6996f7738c361a612777ecab6aaron return new;
8a3228198adb03e6996f7738c361a612777ecab6aaron}
8a3228198adb03e6996f7738c361a612777ecab6aaron
50e421c0e069853bb724f3d816cef543e447c844jorton/****************************************************************
50e421c0e069853bb724f3d816cef543e447c844jorton *
50e421c0e069853bb724f3d816cef543e447c844jorton * Looking things up in config entries...
50e421c0e069853bb724f3d816cef543e447c844jorton */
50e421c0e069853bb724f3d816cef543e447c844jorton
50e421c0e069853bb724f3d816cef543e447c844jorton/* Structure used to hold entries when we're actually building an index */
50e421c0e069853bb724f3d816cef543e447c844jorton
50e421c0e069853bb724f3d816cef543e447c844jortonstruct ent {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *name;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *icon;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *alt;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *desc;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_off_t size;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_time_t lm;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf struct ent *next;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int ascending, version_sort;
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf char key;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int isdir;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf};
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic char *find_item(request_rec *r, apr_array_header_t *list, int path_only)
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const char *content_type = ap_field_noparam(r->pool, r->content_type);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const char *content_encoding = r->content_encoding;
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf char *path = r->filename;
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf struct item *items = (struct item *) list->elts;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int i;
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf for (i = 0; i < list->nelts; ++i) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf struct item *p = &items[i];
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf /* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf if ((path[0] == '^') || (!ap_strcmp_match(path, p->apply_path))) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!*(p->apply_to)) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return p->data;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else if (p->type == BY_PATH || path[0] == '^') {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!ap_strcmp_match(path, p->apply_to)) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return p->data;
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf }
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf }
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf else if (!path_only) {
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf if (!content_encoding) {
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf if (p->type == BY_TYPE) {
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf if (content_type
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf && !ap_strcasecmp_match(content_type,
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf p->apply_to)) {
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf return p->data;
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf }
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf }
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf }
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf else {
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf if (p->type == BY_ENCODING) {
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf if (!ap_strcasecmp_match(content_encoding,
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf p->apply_to)) {
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf return p->data;
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf }
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf }
4497075b5e08b0c8ee89425a1758258ae80550fcsf }
4497075b5e08b0c8ee89425a1758258ae80550fcsf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
4497075b5e08b0c8ee89425a1758258ae80550fcsf return NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
4497075b5e08b0c8ee89425a1758258ae80550fcsf#define find_icon(d,p,t) find_item(p,d->icon_list,t)
4497075b5e08b0c8ee89425a1758258ae80550fcsf#define find_alt(d,p,t) find_item(p,d->alt_list,t)
4497075b5e08b0c8ee89425a1758258ae80550fcsf#define find_header(d,p) find_item(p,d->hdr_list,0)
4497075b5e08b0c8ee89425a1758258ae80550fcsf#define find_readme(d,p) find_item(p,d->rdme_list,0)
4497075b5e08b0c8ee89425a1758258ae80550fcsf
4497075b5e08b0c8ee89425a1758258ae80550fcsfstatic char *find_default_item(char *bogus_name, apr_array_header_t *list)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
4497075b5e08b0c8ee89425a1758258ae80550fcsf request_rec r;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* Bleah. I tried to clean up find_item, and it lead to this bit
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * of ugliness. Note that the fields initialized are precisely
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * those that find_item looks at...
4497075b5e08b0c8ee89425a1758258ae80550fcsf */
4497075b5e08b0c8ee89425a1758258ae80550fcsf r.filename = bogus_name;
4497075b5e08b0c8ee89425a1758258ae80550fcsf r.content_type = r.content_encoding = NULL;
4497075b5e08b0c8ee89425a1758258ae80550fcsf return find_item(&r, list, 1);
4497075b5e08b0c8ee89425a1758258ae80550fcsf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
4497075b5e08b0c8ee89425a1758258ae80550fcsf#define find_default_icon(d,n) find_default_item(n, d->icon_list)
4497075b5e08b0c8ee89425a1758258ae80550fcsf#define find_default_alt(d,n) find_default_item(n, d->alt_list)
4497075b5e08b0c8ee89425a1758258ae80550fcsf
4497075b5e08b0c8ee89425a1758258ae80550fcsf/*
4497075b5e08b0c8ee89425a1758258ae80550fcsf * Look through the list of pattern/description pairs and return the first one
4497075b5e08b0c8ee89425a1758258ae80550fcsf * if any) that matches the filename in the request. If multiple patterns
4497075b5e08b0c8ee89425a1758258ae80550fcsf * match, only the first one is used; since the order in the array is the
4497075b5e08b0c8ee89425a1758258ae80550fcsf * same as the order in which directives were processed, earlier matching
4497075b5e08b0c8ee89425a1758258ae80550fcsf * directives will dominate.
4497075b5e08b0c8ee89425a1758258ae80550fcsf */
4497075b5e08b0c8ee89425a1758258ae80550fcsf
4497075b5e08b0c8ee89425a1758258ae80550fcsf#ifdef CASE_BLIND_FILESYSTEM
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#define MATCH_FLAGS FNM_CASE_BLIND
4497075b5e08b0c8ee89425a1758258ae80550fcsf#else
4497075b5e08b0c8ee89425a1758258ae80550fcsf#define MATCH_FLAGS 0
4497075b5e08b0c8ee89425a1758258ae80550fcsf#endif
4497075b5e08b0c8ee89425a1758258ae80550fcsf
4497075b5e08b0c8ee89425a1758258ae80550fcsfstatic char *find_desc(autoindex_config_rec *dcfg, const char *filename_full)
4497075b5e08b0c8ee89425a1758258ae80550fcsf{
4497075b5e08b0c8ee89425a1758258ae80550fcsf int i;
4497075b5e08b0c8ee89425a1758258ae80550fcsf ai_desc_t *list = (ai_desc_t *) dcfg->desc_list->elts;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const char *filename_only;
ce4dc40a4e87991087488f70d96d3447d7557294sf const char *filename;
ce4dc40a4e87991087488f70d96d3447d7557294sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If the filename includes a path, extract just the name itself
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * for the simple matches.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if ((filename_only = ap_strrchr_c(filename_full, '/')) == NULL) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf filename_only = filename_full;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf filename_only++;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf for (i = 0; i < dcfg->desc_list->nelts; ++i) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ai_desc_t *tuple = &list[i];
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh int found;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Only use the full-path filename if the pattern contains '/'s.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf filename = (tuple->full_path) ? filename_full : filename_only;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Make the comparison using the cheapest method; only do
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * wildcard checking if we must.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (tuple->wildcards) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf found = (apr_fnmatch(tuple->pattern, filename, MATCH_FLAGS) == 0);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf found = (ap_strstr_c(filename, tuple->pattern) != NULL);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (found) {
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf return tuple->description;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int ignore_entry(autoindex_config_rec *d, char *path)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
06bc0ed097a567a63ec01ce7b8044221478cb5cdsf apr_array_header_t *list = d->ign_list;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf struct item *items = (struct item *) list->elts;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *tt;
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf int i;
06bc0ed097a567a63ec01ce7b8044221478cb5cdsf
ce4dc40a4e87991087488f70d96d3447d7557294sf if ((tt = strrchr(path, '/')) == NULL) {
ce4dc40a4e87991087488f70d96d3447d7557294sf tt = path;
ce4dc40a4e87991087488f70d96d3447d7557294sf }
ce4dc40a4e87991087488f70d96d3447d7557294sf else {
ce4dc40a4e87991087488f70d96d3447d7557294sf tt++;
ce4dc40a4e87991087488f70d96d3447d7557294sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
ce4dc40a4e87991087488f70d96d3447d7557294sf for (i = 0; i < list->nelts; ++i) {
ce4dc40a4e87991087488f70d96d3447d7557294sf struct item *p = &items[i];
ce4dc40a4e87991087488f70d96d3447d7557294sf char *ap;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if ((ap = strrchr(p->apply_to, '/')) == NULL) {
ce4dc40a4e87991087488f70d96d3447d7557294sf ap = p->apply_to;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
ce4dc40a4e87991087488f70d96d3447d7557294sf ap++;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
ce4dc40a4e87991087488f70d96d3447d7557294sf
ce4dc40a4e87991087488f70d96d3447d7557294sf#ifndef CASE_BLIND_FILESYSTEM
ce4dc40a4e87991087488f70d96d3447d7557294sf if (!ap_strcmp_match(path, p->apply_path)
ce4dc40a4e87991087488f70d96d3447d7557294sf && !ap_strcmp_match(tt, ap)) {
ce4dc40a4e87991087488f70d96d3447d7557294sf return 1;
ce4dc40a4e87991087488f70d96d3447d7557294sf }
ce4dc40a4e87991087488f70d96d3447d7557294sf#else /* !CASE_BLIND_FILESYSTEM */
ce4dc40a4e87991087488f70d96d3447d7557294sf /*
ce4dc40a4e87991087488f70d96d3447d7557294sf * On some platforms, the match must be case-blind. This is really
ce4dc40a4e87991087488f70d96d3447d7557294sf * a factor of the filesystem involved, but we can't detect that
ce4dc40a4e87991087488f70d96d3447d7557294sf * reliably - so we have to granularise at the OS level.
ce4dc40a4e87991087488f70d96d3447d7557294sf */
ce4dc40a4e87991087488f70d96d3447d7557294sf if (!ap_strcasecmp_match(path, p->apply_path)
ce4dc40a4e87991087488f70d96d3447d7557294sf && !ap_strcasecmp_match(tt, ap)) {
ce4dc40a4e87991087488f70d96d3447d7557294sf return 1;
ce4dc40a4e87991087488f70d96d3447d7557294sf }
ce4dc40a4e87991087488f70d96d3447d7557294sf#endif /* !CASE_BLIND_FILESYSTEM */
ce4dc40a4e87991087488f70d96d3447d7557294sf }
ce4dc40a4e87991087488f70d96d3447d7557294sf return 0;
ce4dc40a4e87991087488f70d96d3447d7557294sf}
ce4dc40a4e87991087488f70d96d3447d7557294sf
ce4dc40a4e87991087488f70d96d3447d7557294sf/*****************************************************************
ce4dc40a4e87991087488f70d96d3447d7557294sf *
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf * Actually generating output
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf/*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Elements of the emitted document:
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Preamble
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * succeeds for the (content_type == text/html) header file.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Header file
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Emitted if found (and able).
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * H1 tag line
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Emitted if a header file is NOT emitted.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Directory stuff
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Always emitted.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * HR
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Emitted if FANCY_INDEXING is set.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Readme file
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Emitted if found (and able).
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * ServerSig
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Emitted if ServerSignature is not Off AND a readme file
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * is NOT emitted.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Postamble
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * succeeds for the (content_type == text/html) readme file.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf/*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * emit a plain text file
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic void do_emit_plain(request_rec *r, apr_file_t *f)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char buf[AP_IOBUFSIZE + 1];
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int ch;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_size_t i, c, n;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_status_t rv;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ap_rputs("<pre>\n", r);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf while (!apr_file_eof(f)) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf do {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf n = sizeof(char) * AP_IOBUFSIZE;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf rv = apr_file_read(f, buf, &n);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf } while (APR_STATUS_IS_EINTR(rv));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (n == 0 || rv != APR_SUCCESS) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* ###: better error here? */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf break;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf buf[n] = '\0';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf c = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf while (c < n) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf for (i = c; i < n; i++) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (buf[i] == '<' || buf[i] == '>' || buf[i] == '&') {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf break;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ch = buf[i];
e302f38fd646764ce1a1e1c578d794aef514a9e5sf buf[i] = '\0';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ap_rputs(&buf[c], r);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (ch == '<') {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ap_rputs("&lt;", r);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else if (ch == '>') {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ap_rputs("&gt;", r);
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin }
c41be3600a58bd39a76d1215abcdbbd8e9b1c356minfrin else if (ch == '&') {
4240daa133bbeddbc3141553879eda4fccfe93feminfrin ap_rputs("&amp;", r);
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin }
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin c = i + 1;
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin }
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin }
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf ap_rputs("</pre>\n", r);
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf}
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin/*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Handle the preamble through the H1 tag line, inclusive. Locate
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * the file with a subrequests. Process text/html documents by actually
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf * running the subrequest; text/xxx documents get copied verbatim,
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf * and any other content type is ignored. This means that a non-text
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * document (such as HEADER.gif) might get multiviewed as the result
82acfa3f57607ae78326104c420a317260554a47nd * instead of a text document, meaning nothing will be displayed, but
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * oh well.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
9fe315e66ef597a158db81bcbd230d7a5d65785dndstatic void emit_head(request_rec *r, char *header_fname, int suppress_amble,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *title)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_table_t *hdrs = r->headers_in;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_file_t *f = NULL;
82acfa3f57607ae78326104c420a317260554a47nd request_rec *rr = NULL;
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd int emit_amble = 1;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int emit_H1 = 1;
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd const char *r_accept;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const char *r_accept_enc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If there's a header file, send a subrequest to look for it. If it's
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * found and html do the subrequest, otherwise handle it
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf r_accept = apr_table_get(hdrs, "Accept");
e302f38fd646764ce1a1e1c578d794aef514a9e5sf r_accept_enc = apr_table_get(hdrs, "Accept-Encoding");
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_table_setn(hdrs, "Accept", "text/html, text/plain");
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_table_unset(hdrs, "Accept-Encoding");
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if ((header_fname != NULL) && r->args) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf header_fname = apr_pstrcat(r->pool, header_fname, "?", r->args, NULL);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if ((header_fname != NULL)
9fe315e66ef597a158db81bcbd230d7a5d65785dnd && (rr = ap_sub_req_lookup_uri(header_fname, r, r->output_filters))
e302f38fd646764ce1a1e1c578d794aef514a9e5sf && (rr->status == HTTP_OK)
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd && (rr->filename != NULL)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf && (rr->finfo.filetype == APR_REG)) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Check for the two specific cases we allow: text/html and
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * text/anything-else. The former is allowed to be processed for
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * SSIs.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (rr->content_type != NULL) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!strcasecmp(ap_field_noparam(r->pool, rr->content_type),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "text/html")) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ap_filter_t *f;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* Hope everything will work... */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf emit_amble = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf emit_H1 = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (! suppress_amble) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf emit_preamble(r, title);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* This is a hack, but I can't find any better way to do this.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * The problem is that we have already created the sub-request,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * but we just inserted the OLD_WRITE filter, and the
9fe315e66ef597a158db81bcbd230d7a5d65785dnd * sub-request needs to pass its data through the OLD_WRITE
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * filter, or things go horribly wrong (missing data, data in
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * the wrong order, etc). To fix it, if you create a
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * sub-request and then insert the OLD_WRITE filter before you
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * run the request, you need to make sure that the sub-request
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * data goes through the OLD_WRITE filter. Just steal this
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd * code. The long-term solution is to remove the ap_r*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * functions.
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf for (f=rr->output_filters;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf f->frec != ap_subreq_core_filter_handle; f = f->next);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf f->next = r->output_filters;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
ee2c610570b9e159784e87e72d1c17f459b85768sf * If there's a problem running the subrequest, display the
b5c4b00201fdc3ed11c6cc05cf3f9a7912ac0cfbsf * preamble if we didn't do it before -- the header file
b5c4b00201fdc3ed11c6cc05cf3f9a7912ac0cfbsf * didn't get displayed.
b5c4b00201fdc3ed11c6cc05cf3f9a7912ac0cfbsf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (ap_run_sub_req(rr) != OK) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* It didn't work */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf emit_amble = suppress_amble;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf emit_H1 = 1;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else if (!strncasecmp("text/", rr->content_type, 5)) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If we can open the file, prefix it with the preamble
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * regardless; since we'll be sending a <pre> block around
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * the file's contents, any HTML header it had won't end up
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * where it belongs.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (apr_file_open(&f, rr->filename, APR_READ,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf emit_preamble(r, title);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf emit_amble = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf do_emit_plain(r, f);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_file_close(f);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf emit_H1 = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (r_accept) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_table_setn(hdrs, "Accept", r_accept);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_table_unset(hdrs, "Accept");
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
8a3228198adb03e6996f7738c361a612777ecab6aaron
e7daae8d2ef0165e83627188bf33655c0b8266e8wrowe if (r_accept_enc) {
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_table_setn(hdrs, "Accept-Encoding", r_accept_enc);
a1de70bda57b72d8cc6b47ea744e0973ed424f56wrowe }
066877f1a045103acfdd376d48cdd473c33f409bdougm
8a3228198adb03e6996f7738c361a612777ecab6aaron if (emit_amble) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding emit_preamble(r, title);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (emit_H1) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ap_rvputs(r, "<h1>Index of ", title, "</h1>\n", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (rr != NULL) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ap_destroy_sub_req(rr);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf/*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Handle the Readme file through the postamble, inclusive. Locate
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * the file with a subrequests. Process text/html documents by actually
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * running the subrequest; text/xxx documents get copied verbatim,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * and any other content type is ignored. This means that a non-text
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * document (such as FOOTER.gif) might get multiviewed as the result
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * instead of a text document, meaning nothing will be displayed, but
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * oh well.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_file_t *f = NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf request_rec *rr = NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int suppress_post = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int suppress_sig = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If there's a readme file, send a subrequest to look for it. If it's
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * found and a text file, handle it -- otherwise fall through and
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * pretend there's nothing there.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if ((readme_fname != NULL)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf && (rr = ap_sub_req_lookup_uri(readme_fname, r, r->output_filters))
e302f38fd646764ce1a1e1c578d794aef514a9e5sf && (rr->status == HTTP_OK)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf && (rr->filename != NULL)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf && rr->finfo.filetype == APR_REG) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Check for the two specific cases we allow: text/html and
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * text/anything-else. The former is allowed to be processed for
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * SSIs.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (rr->content_type != NULL) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!strcasecmp(ap_field_noparam(r->pool, rr->content_type),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "text/html")) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ap_filter_t *f;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf for (f=rr->output_filters;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf f->frec != ap_subreq_core_filter_handle; f = f->next);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf f->next = r->output_filters;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (ap_run_sub_req(rr) == OK) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* worked... */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf suppress_sig = 1;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf suppress_post = suppress_amble;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else if (!strncasecmp("text/", rr->content_type, 5)) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If we can open the file, suppress the signature.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (apr_file_open(&f, rr->filename, APR_READ,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf do_emit_plain(r, f);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_file_close(f);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf suppress_sig = 1;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!suppress_sig) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ap_rputs(ap_psignature("", r), r);
a8eeeed944c5d1986ab92649271d29839abd1155sf }
a8eeeed944c5d1986ab92649271d29839abd1155sf if (!suppress_post) {
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf ap_rputs("</body></html>\n", r);
a8eeeed944c5d1986ab92649271d29839abd1155sf }
a8eeeed944c5d1986ab92649271d29839abd1155sf if (rr != NULL) {
a8eeeed944c5d1986ab92649271d29839abd1155sf ap_destroy_sub_req(rr);
a8eeeed944c5d1986ab92649271d29839abd1155sf }
a8eeeed944c5d1986ab92649271d29839abd1155sf}
a8eeeed944c5d1986ab92649271d29839abd1155sf
a8eeeed944c5d1986ab92649271d29839abd1155sf
a8eeeed944c5d1986ab92649271d29839abd1155sfstatic char *find_title(request_rec *r)
a8eeeed944c5d1986ab92649271d29839abd1155sf{
a8eeeed944c5d1986ab92649271d29839abd1155sf char titlebuf[MAX_STRING_LEN], *find = "<title>";
a8eeeed944c5d1986ab92649271d29839abd1155sf apr_file_t *thefile = NULL;
a8eeeed944c5d1986ab92649271d29839abd1155sf int x, y, p;
a8eeeed944c5d1986ab92649271d29839abd1155sf apr_size_t n;
a8eeeed944c5d1986ab92649271d29839abd1155sf
a8eeeed944c5d1986ab92649271d29839abd1155sf if (r->status != HTTP_OK) {
a8eeeed944c5d1986ab92649271d29839abd1155sf return NULL;
a8eeeed944c5d1986ab92649271d29839abd1155sf }
a8eeeed944c5d1986ab92649271d29839abd1155sf if ((r->content_type != NULL)
a8eeeed944c5d1986ab92649271d29839abd1155sf && (!strcasecmp(ap_field_noparam(r->pool, r->content_type),
a8eeeed944c5d1986ab92649271d29839abd1155sf "text/html")
a8eeeed944c5d1986ab92649271d29839abd1155sf || !strcmp(r->content_type, INCLUDES_MAGIC_TYPE))
e302f38fd646764ce1a1e1c578d794aef514a9e5sf && !r->content_encoding) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (apr_file_open(&thefile, r->filename, APR_READ,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf APR_OS_DEFAULT, r->pool) != APR_SUCCESS) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf n = sizeof(char) * (MAX_STRING_LEN - 1);
f91e8c44b15a74bedaa027128a695950807e2968sf apr_file_read(thefile, titlebuf, &n);
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf if (n <= 0) {
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf apr_file_close(thefile);
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf return NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf titlebuf[n] = '\0';
7f630e66c9c37e797e1c06bf7b259c0859538978trawick for (x = 0, p = 0; titlebuf[x]; x++) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (apr_tolower(titlebuf[x]) == find[p]) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!find[++p]) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if ((p = ap_ind(&titlebuf[++x], '<')) != -1) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf titlebuf[x + p] = '\0';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* Scan for line breaks for Tanmoy's secretary */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf for (y = x; titlebuf[y]; y++) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if ((titlebuf[y] == CR) || (titlebuf[y] == LF)) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (y == x) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf x++;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf titlebuf[y] = ' ';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_file_close(thefile);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return apr_pstrdup(r->pool, &titlebuf[x]);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf p = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_file_close(thefile);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic struct ent *make_parent_entry(apr_int32_t autoindex_opts,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf autoindex_config_rec *d,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf request_rec *r, char keyid,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char direction)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf struct ent *p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *testpath;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * p->name is now the true parent URI.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * testpath is a crafted lie, so that the syntax '/some/..'
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * (or simply '..')be used to describe 'up' from '/some/'
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * when processeing IndexIgnore, and Icon|Alt|Desc configs.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf /* The output has always been to the parent. Don't make ourself
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf * our own parent (worthless cyclical reference).
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!(p->name = ap_make_full_path(r->pool, r->uri, "../"))) {
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf return (NULL);
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf }
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf ap_getparents(p->name);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!*p->name) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return (NULL);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* IndexIgnore has always compared "/thispath/.." */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf testpath = ap_make_full_path(r->pool, r->filename, "..");
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (ignore_entry(d, testpath)) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return (NULL);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf p->size = -1;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf p->lm = -1;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf p->key = apr_toupper(keyid);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf p->ascending = (apr_toupper(direction) == D_ASCENDING);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf p->version_sort = autoindex_opts & VERSION_SORT;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (autoindex_opts & FANCY_INDEXING) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!(p->icon = find_default_icon(d, testpath))) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf p->icon = find_default_icon(d, "^^DIRECTORY^^");
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!(p->alt = find_default_alt(d, testpath))) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!(p->alt = find_default_alt(d, "^^DIRECTORY^^"))) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf p->alt = "DIR";
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf p->desc = find_desc(d, testpath);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return p;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e11c9fa326e7bfa48bd9be5bae7037ae76b2612dsf
e11c9fa326e7bfa48bd9be5bae7037ae76b2612dsfstatic struct ent *make_autoindex_entry(const apr_finfo_t *dirent,
e11c9fa326e7bfa48bd9be5bae7037ae76b2612dsf int autoindex_opts,
e11c9fa326e7bfa48bd9be5bae7037ae76b2612dsf autoindex_config_rec *d,
e11c9fa326e7bfa48bd9be5bae7037ae76b2612dsf request_rec *r, char keyid,
e11c9fa326e7bfa48bd9be5bae7037ae76b2612dsf char direction,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const char *pattern)
f91e8c44b15a74bedaa027128a695950807e2968sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf request_rec *rr;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf struct ent *p;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* Dot is ignored, Parent is handled by make_parent_entry() */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((dirent->name[0] == '.') && (!dirent->name[1]
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh || ((dirent->name[1] == '.') && !dirent->name[2])))
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf return (NULL);
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf#ifndef CASE_BLIND_FILESYSTEM
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (pattern && (apr_fnmatch(pattern, dirent->name,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding FNM_NOESCAPE | FNM_PERIOD)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding != APR_SUCCESS))
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (NULL);
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf#else /* !CASE_BLIND_FILESYSTEM */
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf /*
3597d6b10c88c252f156fe8061b659a38dea38c2rbb * On some platforms, the match must be case-blind. This is really
3597d6b10c88c252f156fe8061b659a38dea38c2rbb * a factor of the filesystem involved, but we can't detect that
3597d6b10c88c252f156fe8061b659a38dea38c2rbb * reliably - so we have to granularise at the OS level.
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf */
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf if (pattern && (apr_fnmatch(pattern, dirent->name,
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf FNM_NOESCAPE | FNM_PERIOD | FNM_CASE_BLIND)
3597d6b10c88c252f156fe8061b659a38dea38c2rbb != APR_SUCCESS))
3597d6b10c88c252f156fe8061b659a38dea38c2rbb return (NULL);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb#endif /* !CASE_BLIND_FILESYSTEM */
3597d6b10c88c252f156fe8061b659a38dea38c2rbb
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf if (ignore_entry(d, ap_make_full_path(r->pool,
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf r->filename, dirent->name))) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf if (!(rr = ap_sub_req_lookup_dirent(dirent, r, AP_SUBREQ_NO_ARGS, NULL))) {
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf return (NULL);
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((rr->finfo.filetype != APR_DIR && rr->finfo.filetype != APR_REG)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding || !(rr->status == OK || ap_is_HTTP_SUCCESS(rr->status)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding || ap_is_HTTP_REDIRECT(rr->status))) {
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf ap_destroy_sub_req(rr);
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf return (NULL);
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent));
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard if (dirent->filetype == APR_DIR) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p->name = apr_pstrcat(r->pool, dirent->name, "/", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p->name = apr_pstrdup(r->pool, dirent->name);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh p->size = -1;
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard p->icon = NULL;
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard p->alt = NULL;
8a3228198adb03e6996f7738c361a612777ecab6aaron p->desc = NULL;
8a3228198adb03e6996f7738c361a612777ecab6aaron p->lm = -1;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh p->isdir = 0;
8a3228198adb03e6996f7738c361a612777ecab6aaron p->key = apr_toupper(keyid);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p->ascending = (apr_toupper(direction) == D_ASCENDING);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p->version_sort = !!(autoindex_opts & VERSION_SORT);
e34223f72e630187c4d8ac7c22da5096c833eb20trawick
e34223f72e630187c4d8ac7c22da5096c833eb20trawick if (autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING)) {
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf p->lm = rr->finfo.mtime;
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf if (dirent->filetype == APR_DIR) {
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf if (autoindex_opts & FOLDERS_FIRST) {
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf p->isdir = 1;
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf }
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf if (!(p->icon = find_icon(d, rr, 1))) {
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf p->icon = find_default_icon(d, "^^DIRECTORY^^");
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf }
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf if (!(p->alt = find_alt(d, rr, 1))) {
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf if (!(p->alt = find_default_alt(d, "^^DIRECTORY^^"))) {
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf p->alt = "DIR";
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf }
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf }
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf }
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf else {
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf p->icon = find_icon(d, rr, 0);
e34223f72e630187c4d8ac7c22da5096c833eb20trawick p->alt = find_alt(d, rr, 0);
e34223f72e630187c4d8ac7c22da5096c833eb20trawick p->size = rr->finfo.size;
e34223f72e630187c4d8ac7c22da5096c833eb20trawick }
e34223f72e630187c4d8ac7c22da5096c833eb20trawick
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf p->desc = find_desc(d, rr->filename);
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf
e34223f72e630187c4d8ac7c22da5096c833eb20trawick if ((!p->desc) && (autoindex_opts & SCAN_HTML_TITLES)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p->desc = apr_pstrdup(r->pool, find_title(rr));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
bd27541a0c96caa881f17a490e23cdd220d480c8poirier }
bd27541a0c96caa881f17a490e23cdd220d480c8poirier ap_destroy_sub_req(rr);
bd27541a0c96caa881f17a490e23cdd220d480c8poirier /*
bd27541a0c96caa881f17a490e23cdd220d480c8poirier * We don't need to take any special action for the file size key.
bd27541a0c96caa881f17a490e23cdd220d480c8poirier * If we did, it would go here.
bd27541a0c96caa881f17a490e23cdd220d480c8poirier */
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim if (keyid == K_LAST_MOD) {
bd27541a0c96caa881f17a490e23cdd220d480c8poirier if (p->lm < 0) {
bd27541a0c96caa881f17a490e23cdd220d480c8poirier p->lm = 0;
bd27541a0c96caa881f17a490e23cdd220d480c8poirier }
bd27541a0c96caa881f17a490e23cdd220d480c8poirier }
bd27541a0c96caa881f17a490e23cdd220d480c8poirier return (p);
bd27541a0c96caa881f17a490e23cdd220d480c8poirier}
bd27541a0c96caa881f17a490e23cdd220d480c8poirier
bd27541a0c96caa881f17a490e23cdd220d480c8poirierstatic char *terminate_description(autoindex_config_rec *d, char *desc,
bd27541a0c96caa881f17a490e23cdd220d480c8poirier apr_int32_t autoindex_opts, int desc_width)
bd27541a0c96caa881f17a490e23cdd220d480c8poirier{
bd27541a0c96caa881f17a490e23cdd220d480c8poirier int maxsize = desc_width;
bd27541a0c96caa881f17a490e23cdd220d480c8poirier register int x;
bd27541a0c96caa881f17a490e23cdd220d480c8poirier
bd27541a0c96caa881f17a490e23cdd220d480c8poirier /*
bd27541a0c96caa881f17a490e23cdd220d480c8poirier * If there's no DescriptionWidth in effect, default to the old
bd27541a0c96caa881f17a490e23cdd220d480c8poirier * behaviour of adjusting the description size depending upon
185aa71728867671e105178b4c66fbc22b65ae26sf * what else is being displayed. Otherwise, stick with the
bd27541a0c96caa881f17a490e23cdd220d480c8poirier * setting.
bd27541a0c96caa881f17a490e23cdd220d480c8poirier */
bd27541a0c96caa881f17a490e23cdd220d480c8poirier if (d->desc_adjust == K_UNSET) {
20e0c71be778348516719e1e58a9f55c8e78c570trawick if (autoindex_opts & SUPPRESS_ICON) {
20e0c71be778348516719e1e58a9f55c8e78c570trawick maxsize += 6;
20e0c71be778348516719e1e58a9f55c8e78c570trawick }
1ec73fc12d4912ea9f4841c301458454589b32d9trawick if (autoindex_opts & SUPPRESS_LAST_MOD) {
20e0c71be778348516719e1e58a9f55c8e78c570trawick maxsize += 19;
20e0c71be778348516719e1e58a9f55c8e78c570trawick }
20e0c71be778348516719e1e58a9f55c8e78c570trawick if (autoindex_opts & SUPPRESS_SIZE) {
20e0c71be778348516719e1e58a9f55c8e78c570trawick maxsize += 7;
185aa71728867671e105178b4c66fbc22b65ae26sf }
20e0c71be778348516719e1e58a9f55c8e78c570trawick }
20e0c71be778348516719e1e58a9f55c8e78c570trawick for (x = 0; desc[x] && ((maxsize > 0) || (desc[x] == '<')); x++) {
20e0c71be778348516719e1e58a9f55c8e78c570trawick if (desc[x] == '<') {
185aa71728867671e105178b4c66fbc22b65ae26sf while (desc[x] != '>') {
20e0c71be778348516719e1e58a9f55c8e78c570trawick if (!desc[x]) {
20e0c71be778348516719e1e58a9f55c8e78c570trawick maxsize = 0;
20e0c71be778348516719e1e58a9f55c8e78c570trawick break;
20e0c71be778348516719e1e58a9f55c8e78c570trawick }
20e0c71be778348516719e1e58a9f55c8e78c570trawick ++x;
20e0c71be778348516719e1e58a9f55c8e78c570trawick }
32c4bc04f89b16521718145dc731f750144d7b38wrowe }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (desc[x] == '&') {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* entities like &auml; count as one character */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm --maxsize;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for ( ; desc[x] != ';'; ++x) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (desc[x] == '\0') {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm maxsize = 0;
32c4bc04f89b16521718145dc731f750144d7b38wrowe break;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
32c4bc04f89b16521718145dc731f750144d7b38wrowe }
32c4bc04f89b16521718145dc731f750144d7b38wrowe }
32c4bc04f89b16521718145dc731f750144d7b38wrowe else {
32c4bc04f89b16521718145dc731f750144d7b38wrowe --maxsize;
1ec73fc12d4912ea9f4841c301458454589b32d9trawick }
32c4bc04f89b16521718145dc731f750144d7b38wrowe }
e8f95a682820a599fe41b22977010636be5c2717jim if (!maxsize && desc[x] != '\0') {
185aa71728867671e105178b4c66fbc22b65ae26sf desc[x - 1] = '>'; /* Grump. */
32c4bc04f89b16521718145dc731f750144d7b38wrowe desc[x] = '\0'; /* Double Grump! */
32c4bc04f89b16521718145dc731f750144d7b38wrowe }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return desc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
8a3228198adb03e6996f7738c361a612777ecab6aaron/*
8a3228198adb03e6996f7738c361a612777ecab6aaron * Emit the anchor for the specified field. If a field is the key for the
8a3228198adb03e6996f7738c361a612777ecab6aaron * current request, the link changes its meaning to reverse the order when
8a3228198adb03e6996f7738c361a612777ecab6aaron * selected again. Non-active fields always start in ascending order.
8a3228198adb03e6996f7738c361a612777ecab6aaron */
8a3228198adb03e6996f7738c361a612777ecab6aaronstatic void emit_link(request_rec *r, const char *anchor, char column,
8a3228198adb03e6996f7738c361a612777ecab6aaron char curkey, char curdirection,
8a3228198adb03e6996f7738c361a612777ecab6aaron const char *colargs, int nosort)
185aa71728867671e105178b4c66fbc22b65ae26sf{
4bb7ba7c1f9972b443562faf99151ccec854446fjorton char qvalue[13];
4bb7ba7c1f9972b443562faf99151ccec854446fjorton int reverse;
4bb7ba7c1f9972b443562faf99151ccec854446fjorton
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!nosort) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding reverse = ((curkey == column) && (curdirection == D_ASCENDING));
8a3228198adb03e6996f7738c361a612777ecab6aaron qvalue[0] = '?';
8a3228198adb03e6996f7738c361a612777ecab6aaron qvalue[1] = 'C';
8a3228198adb03e6996f7738c361a612777ecab6aaron qvalue[2] = '=';
8a3228198adb03e6996f7738c361a612777ecab6aaron qvalue[3] = column;
185aa71728867671e105178b4c66fbc22b65ae26sf qvalue[4] = '&';
cf5ace98ead10d803fda70674cb4dda30fddb832trawick qvalue[5] = 'a';
185aa71728867671e105178b4c66fbc22b65ae26sf qvalue[6] = 'm';
2b484455736f4c30447aa852764f53282cbeb5ddrbb qvalue[7] = 'p';
8a3228198adb03e6996f7738c361a612777ecab6aaron qvalue[8] = ';';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding qvalue[9] = 'O';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding qvalue[10] = '=';
95dc871e605e3b1b347adbbbdd9a9caede71c38eminfrin qvalue[11] = reverse ? D_DESCENDING : D_ASCENDING;
066877f1a045103acfdd376d48cdd473c33f409bdougm qvalue[12] = '\0';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, "<a href=\"", qvalue, colargs ? colargs : "",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "\">", anchor, "</a>", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick else {
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick ap_rputs(anchor, r);
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick }
dc64949d88a97fef0bfcb2eed2115dddafc41666wrowe}
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawickstatic void output_directories(struct ent **ar, int n,
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick autoindex_config_rec *d, request_rec *r,
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick apr_int32_t autoindex_opts, char keyid,
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz char direction, const char *colargs)
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick{
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick int x;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick apr_size_t rv;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick char *name = r->uri;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick char *tp;
1ec73fc12d4912ea9f4841c301458454589b32d9trawick int static_columns = !!(autoindex_opts & SUPPRESS_COLSORT);
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick apr_pool_t *scratch;
e8f95a682820a599fe41b22977010636be5c2717jim int name_width;
185aa71728867671e105178b4c66fbc22b65ae26sf int desc_width;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick char *name_scratch;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick char *pad_scratch;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick char *breakrow = "";
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick apr_pool_create(&scratch, r->pool);
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick if (name[0] == '\0') {
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick name = "/";
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick }
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz name_width = d->name_width;
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz desc_width = d->desc_width;
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz if ((autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING))
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick == FANCY_INDEXING) {
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick if (d->name_adjust == K_ADJUST) {
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz for (x = 0; x < n; x++) {
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz int t = strlen(ar[x]->name);
f2b43354f9ac8496ab7003ae01211af739efba1atrawick if (t > name_width) {
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick name_width = t;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick }
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick }
f2b43354f9ac8496ab7003ae01211af739efba1atrawick }
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz if (d->desc_adjust == K_ADJUST) {
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick for (x = 0; x < n; x++) {
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick if (ar[x]->desc != NULL) {
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick int t = strlen(ar[x]->desc);
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick if (t > desc_width) {
8a3228198adb03e6996f7738c361a612777ecab6aaron desc_width = t;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe }
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet }
066877f1a045103acfdd376d48cdd473c33f409bdougm }
185aa71728867671e105178b4c66fbc22b65ae26sf name_scratch = apr_palloc(r->pool, name_width + 1);
2b484455736f4c30447aa852764f53282cbeb5ddrbb pad_scratch = apr_palloc(r->pool, name_width + 1);
8a3228198adb03e6996f7738c361a612777ecab6aaron memset(pad_scratch, ' ', name_width);
8f0d7adca1c0719b3b1863fb2b9d333d7822567awrowe pad_scratch[name_width] = '\0';
8f0d7adca1c0719b3b1863fb2b9d333d7822567awrowe
8f0d7adca1c0719b3b1863fb2b9d333d7822567awrowe if (autoindex_opts & TABLE_INDEXING) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int cols = 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs("<table><tr>", r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!(autoindex_opts & SUPPRESS_ICON)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs("<th title=\"Icon\">", r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, "<img src=\"", ap_escape_html(scratch, tp),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "\" alt=\"[ICO]\"", NULL);
7646be5b9ab5b098bc81d3a08a47e1931dc87597rbb if (d->icon_width) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rprintf(r, " width=\"%d\"", d->icon_width);
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (d->icon_height) {
f5308a6d396448120986bed14412954788af3e5cjorton ap_rprintf(r, " height=\"%d\"", d->icon_height);
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs(" /></th>", r);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
db2ef76dc744b13b9a9929ebb9e6f94712a81717rbb else {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_rputs("&nbsp;</th>", r);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb }
066877f1a045103acfdd376d48cdd473c33f409bdougm
5a6a87d8920e385b1ed14177d74ab9786f3acddfwrowe ++cols;
5a6a87d8920e385b1ed14177d74ab9786f3acddfwrowe }
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe ap_rputs("<th>", r);
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe emit_link(r, "Name", K_NAME, keyid, direction,
8a3228198adb03e6996f7738c361a612777ecab6aaron colargs, static_columns);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton ap_rputs("</th><th>", r);
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe emit_link(r, "Last modified", K_LAST_MOD, keyid, direction,
76185d819b745e953dd2cd636fbdd515c333e4a4trawick colargs, static_columns);
76185d819b745e953dd2cd636fbdd515c333e4a4trawick ++cols;
76185d819b745e953dd2cd636fbdd515c333e4a4trawick }
e4c4fcc82268e0192db234c74a6db784b879fffdrbb if (!(autoindex_opts & SUPPRESS_SIZE)) {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb ap_rputs("</th><th>", r);
185aa71728867671e105178b4c66fbc22b65ae26sf emit_link(r, "Size", K_SIZE, keyid, direction,
8a3228198adb03e6996f7738c361a612777ecab6aaron colargs, static_columns);
8a3228198adb03e6996f7738c361a612777ecab6aaron ++cols;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (!(autoindex_opts & SUPPRESS_DESC)) {
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb ap_rputs("</th><th>", r);
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb emit_link(r, "Description", K_DESC, keyid, direction,
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb colargs, static_columns);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ++cols;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
db2ef76dc744b13b9a9929ebb9e6f94712a81717rbb if (!(autoindex_opts & SUPPRESS_RULES)) {
76185d819b745e953dd2cd636fbdd515c333e4a4trawick breakrow = apr_psprintf(r->pool,
76185d819b745e953dd2cd636fbdd515c333e4a4trawick "<tr><th colspan=\"%d\">"
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh "<hr /></th></tr>\n", cols);
76185d819b745e953dd2cd636fbdd515c333e4a4trawick }
20c85ca0d404e29972fb94c3d6236a264d1c77abstoddard ap_rvputs(r, "</th></tr>", breakrow, NULL);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton }
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton else if (autoindex_opts & FANCY_INDEXING) {
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton ap_rputs("<pre>", r);
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton if (!(autoindex_opts & SUPPRESS_ICON)) {
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung ap_rvputs(r, "<img src=\"", ap_escape_html(scratch, tp),
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton "\" alt=\"Icon \"", NULL);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton if (d->icon_width) {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb ap_rprintf(r, " width=\"%d\"", d->icon_width);
76185d819b745e953dd2cd636fbdd515c333e4a4trawick }
76185d819b745e953dd2cd636fbdd515c333e4a4trawick if (d->icon_height) {
76185d819b745e953dd2cd636fbdd515c333e4a4trawick ap_rprintf(r, " height=\"%d\"", d->icon_height);
185aa71728867671e105178b4c66fbc22b65ae26sf }
76185d819b745e953dd2cd636fbdd515c333e4a4trawick ap_rputs(" /> ", r);
76185d819b745e953dd2cd636fbdd515c333e4a4trawick }
76185d819b745e953dd2cd636fbdd515c333e4a4trawick else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs(" ", r);
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh }
f5308a6d396448120986bed14412954788af3e5cjorton }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding emit_link(r, "Name", K_NAME, keyid, direction,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding colargs, static_columns);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs(pad_scratch + 4, r);
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Emit the guaranteed-at-least-one-space-between-columns byte.
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_rputs(" ", r);
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding emit_link(r, "Last modified", K_LAST_MOD, keyid, direction,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding colargs, static_columns);
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb ap_rputs(" ", r);
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb }
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick if (!(autoindex_opts & SUPPRESS_SIZE)) {
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick emit_link(r, "Size", K_SIZE, keyid, direction,
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick colargs, static_columns);
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung ap_rputs(" ", r);
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick }
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick if (!(autoindex_opts & SUPPRESS_DESC)) {
185aa71728867671e105178b4c66fbc22b65ae26sf emit_link(r, "Description", K_DESC, keyid, direction,
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick colargs, static_columns);
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick }
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick if (!(autoindex_opts & SUPPRESS_RULES)) {
8a3228198adb03e6996f7738c361a612777ecab6aaron ap_rputs("<hr />", r);
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick }
185aa71728867671e105178b4c66fbc22b65ae26sf else {
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick ap_rputc('\n', r);
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick }
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung }
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick else {
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick ap_rputs("<ul>", r);
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung }
185aa71728867671e105178b4c66fbc22b65ae26sf
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick for (x = 0; x < n; x++) {
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung char *anchor, *t, *t2;
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick int nwidth;
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_pool_clear(scratch);
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb t = ar[x]->name;
ffb048955d9939c0ab6ff99c2efc412d8e7a191dwrowe anchor = ap_escape_html(scratch, ap_os_escape_path(scratch, t, 0));
ffb048955d9939c0ab6ff99c2efc412d8e7a191dwrowe
8a3228198adb03e6996f7738c361a612777ecab6aaron if (!x && t[0] == '/') {
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh t2 = "Parent Directory";
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb }
8a3228198adb03e6996f7738c361a612777ecab6aaron else {
8a3228198adb03e6996f7738c361a612777ecab6aaron t2 = t;
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick }
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaron if (autoindex_opts & TABLE_INDEXING) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!(autoindex_opts & SUPPRESS_ICON)) {
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb ap_rputs("<tr><td valign=\"top\">", r);
8a3228198adb03e6996f7738c361a612777ecab6aaron if (autoindex_opts & ICONS_ARE_LINKS) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, "<a href=\"", anchor, "\">", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((ar[x]->icon) || d->default_icon) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, "<img src=\"",
c54189c4d2d06d8b374940b32acf20287effff07wrowe ap_escape_html(scratch,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ar[x]->icon ? ar[x]->icon
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding : d->default_icon),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "\" alt=\"[", (ar[x]->alt ? ar[x]->alt : " "),
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton "]\"", NULL);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton if (d->icon_width) {
2a7d0035b5594ddc0907a9cc545e14ae5140c541manoj ap_rprintf(r, " width=\"%d\"", d->icon_width);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (d->icon_height) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rprintf(r, " height=\"%d\"", d->icon_height);
c54189c4d2d06d8b374940b32acf20287effff07wrowe }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs(" />", r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
c54189c4d2d06d8b374940b32acf20287effff07wrowe ap_rputs("&nbsp;", r);
c54189c4d2d06d8b374940b32acf20287effff07wrowe }
c54189c4d2d06d8b374940b32acf20287effff07wrowe if (autoindex_opts & ICONS_ARE_LINKS) {
c54189c4d2d06d8b374940b32acf20287effff07wrowe ap_rputs("</a></td>", r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
c54189c4d2d06d8b374940b32acf20287effff07wrowe ap_rputs("</td>", r);
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe }
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe }
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe if (d->name_adjust == K_ADJUST) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, "<td><a href=\"", anchor, "\">",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_escape_html(scratch, t2), "</a>", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding nwidth = strlen(t2);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (nwidth > name_width) {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb memcpy(name_scratch, t2, name_width - 3);
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe name_scratch[name_width - 3] = '.';
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton name_scratch[name_width - 2] = '.';
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton name_scratch[name_width - 1] = '>';
52bdaf788c70b03fe6f68a5a489cdbe11fb184efwrowe name_scratch[name_width] = 0;
8a3228198adb03e6996f7738c361a612777ecab6aaron t2 = name_scratch;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding nwidth = name_width;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron ap_rvputs(r, "<td><a href=\"", anchor, "\">",
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung ap_escape_html(scratch, t2),
8a3228198adb03e6996f7738c361a612777ecab6aaron "</a>", pad_scratch + nwidth, NULL);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton }
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
8a3228198adb03e6996f7738c361a612777ecab6aaron if (ar[x]->lm != -1) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char time_str[MAX_STRING_LEN];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_time_exp_t ts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_time_exp_lt(&ts, ar[x]->lm);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_strftime(time_str, &rv, MAX_STRING_LEN,
cddad5fd27fd3b9f4375d76d04bbbeaebec00548wrowe "</td><td align=\"right\">%d-%b-%Y %H:%M ", &ts);
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb ap_rputs(time_str, r);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb ap_rputs("</td><td>&nbsp;", r);
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb }
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton }
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb if (!(autoindex_opts & SUPPRESS_SIZE)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char buf[5];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, "</td><td align=\"right\">",
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe apr_strfsize(ar[x]->size, buf), NULL);
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe }
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe if (!(autoindex_opts & SUPPRESS_DESC)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ar[x]->desc) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (d->desc_adjust == K_ADJUST) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_rvputs(r, "</td><td>", ar[x]->desc, NULL);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe ap_rvputs(r, "</td><td>",
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb terminate_description(d, ar[x]->desc,
185aa71728867671e105178b4c66fbc22b65ae26sf autoindex_opts,
19702a9985f3b2f794d22be9102d9d4fbf6bebe7rjung desc_width), NULL);
19702a9985f3b2f794d22be9102d9d4fbf6bebe7rjung }
85c435ceda98eab940615e4466d9c5955252e745wrowe }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb else {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_rputs("</td><td>&nbsp;", r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton ap_rputs("</td></tr>\n", r);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton }
066877f1a045103acfdd376d48cdd473c33f409bdougm else if (autoindex_opts & FANCY_INDEXING) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!(autoindex_opts & SUPPRESS_ICON)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (autoindex_opts & ICONS_ARE_LINKS) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, "<a href=\"", anchor, "\">", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb if ((ar[x]->icon) || d->default_icon) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, "<img src=\"",
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe ap_escape_html(scratch,
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe ar[x]->icon ? ar[x]->icon
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe : d->default_icon),
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe "\" alt=\"[", (ar[x]->alt ? ar[x]->alt : " "),
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe "]\"", NULL);
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe if (d->icon_width) {
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe ap_rprintf(r, " width=\"%d\"", d->icon_width);
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim }
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe if (d->icon_height) {
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe ap_rprintf(r, " height=\"%d\"", d->icon_height);
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe }
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe ap_rputs(" />", r);
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe }
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe else {
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe ap_rputs(" ", r);
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe }
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe if (autoindex_opts & ICONS_ARE_LINKS) {
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe ap_rputs("</a> ", r);
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe }
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe else {
3d96ee83babeec32482c9082c9426340cee8c44dwrowe ap_rputc(' ', r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
066877f1a045103acfdd376d48cdd473c33f409bdougm }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding nwidth = strlen(t2);
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb if (nwidth > name_width) {
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf memcpy(name_scratch, t2, name_width - 3);
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf name_scratch[name_width - 3] = '.';
1119f286db67c139106e274e0814430cd600b901sf name_scratch[name_width - 2] = '.';
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf name_scratch[name_width - 1] = '>';
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf name_scratch[name_width] = 0;
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf t2 = name_scratch;
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf nwidth = name_width;
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf }
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf ap_rvputs(r, "<a href=\"", anchor, "\">",
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf ap_escape_html(scratch, t2),
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf "</a>", pad_scratch + nwidth, NULL);
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf /*
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf * The blank before the storm.. er, before the next field.
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf */
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf ap_rputs(" ", r);
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf if (ar[x]->lm != -1) {
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf char time_str[MAX_STRING_LEN];
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf apr_time_exp_t ts;
a7318397b355119d990d1f311b951dea2aafc53arbb apr_time_exp_lt(&ts, ar[x]->lm);
f91e8c44b15a74bedaa027128a695950807e2968sf apr_strftime(time_str, &rv, MAX_STRING_LEN,
f91e8c44b15a74bedaa027128a695950807e2968sf "%d-%b-%Y %H:%M ", &ts);
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_rputs(time_str, r);
ce4dc40a4e87991087488f70d96d3447d7557294sf }
ce4dc40a4e87991087488f70d96d3447d7557294sf else {
ce4dc40a4e87991087488f70d96d3447d7557294sf /*Length="22-Feb-1998 23:42 " (see 4 lines above) */
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_rputs(" ", r);
}
}
if (!(autoindex_opts & SUPPRESS_SIZE)) {
char buf[5];
ap_rputs(apr_strfsize(ar[x]->size, buf), r);
ap_rputs(" ", r);
}
if (!(autoindex_opts & SUPPRESS_DESC)) {
if (ar[x]->desc) {
ap_rputs(terminate_description(d, ar[x]->desc,
autoindex_opts,
desc_width), r);
}
}
ap_rputc('\n', r);
}
else {
ap_rvputs(r, "<li><a href=\"", anchor, "\"> ", t2,
"</a></li>\n", NULL);
}
}
if (autoindex_opts & TABLE_INDEXING) {
ap_rvputs(r, breakrow, "</table>\n", NULL);
}
else if (autoindex_opts & FANCY_INDEXING) {
if (!(autoindex_opts & SUPPRESS_RULES)) {
ap_rputs("<hr /></pre>\n", r);
}
else {
ap_rputs("</pre>\n", r);
}
}
else {
ap_rputs("</ul>\n", r);
}
}
/*
* Compare two file entries according to the sort criteria. The return
* is essentially a signum function value.
*/
static int dsortf(struct ent **e1, struct ent **e2)
{
struct ent *c1;
struct ent *c2;
int result = 0;
/*
* First, see if either of the entries is for the parent directory.
* If so, that *always* sorts lower than anything else.
*/
if ((*e1)->name[0] == '/') {
return -1;
}
if ((*e2)->name[0] == '/') {
return 1;
}
/*
* Now see if one's a directory and one isn't, if we're set
* isdir for FOLDERS_FIRST.
*/
if ((*e1)->isdir != (*e2)->isdir) {
return (*e1)->isdir ? -1 : 1;
}
/*
* All of our comparisons will be of the c1 entry against the c2 one,
* so assign them appropriately to take care of the ordering.
*/
if ((*e1)->ascending) {
c1 = *e1;
c2 = *e2;
}
else {
c1 = *e2;
c2 = *e1;
}
switch (c1->key) {
case K_LAST_MOD:
if (c1->lm > c2->lm) {
return 1;
}
else if (c1->lm < c2->lm) {
return -1;
}
break;
case K_SIZE:
if (c1->size > c2->size) {
return 1;
}
else if (c1->size < c2->size) {
return -1;
}
break;
case K_DESC:
if (c1->version_sort) {
result = apr_strnatcmp(c1->desc ? c1->desc : "",
c2->desc ? c2->desc : "");
}
else {
result = strcmp(c1->desc ? c1->desc : "",
c2->desc ? c2->desc : "");
}
if (result) {
return result;
}
break;
}
if (c1->version_sort) {
return apr_strnatcmp(c1->name, c2->name);
}
else {
return strcmp(c1->name, c2->name);
}
}
static int index_directory(request_rec *r,
autoindex_config_rec *autoindex_conf)
{
char *title_name = ap_escape_html(r->pool, r->uri);
char *title_endp;
char *name = r->filename;
char *pstring = NULL;
apr_finfo_t dirent;
apr_dir_t *thedir;
apr_status_t status;
int num_ent = 0, x;
struct ent *head, *p;
struct ent **ar = NULL;
const char *qstring;
apr_int32_t autoindex_opts = autoindex_conf->opts;
char keyid;
char direction;
char *colargs;
char *fullpath;
apr_size_t dirpathlen;
if ((status = apr_dir_open(&thedir, name, r->pool)) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r,
"Can't open directory for index: %s", r->filename);
return HTTP_FORBIDDEN;
}
#if APR_HAS_UNICODE_FS
ap_set_content_type(r, "text/html;charset=utf-8");
#else
ap_set_content_type(r, "text/html");
#endif
if (autoindex_opts & TRACK_MODIFIED) {
ap_update_mtime(r, r->finfo.mtime);
ap_set_last_modified(r);
ap_set_etag(r);
}
if (r->header_only) {
apr_dir_close(thedir);
return 0;
}
/*
* If there is no specific ordering defined for this directory,
* default to ascending by filename.
*/
keyid = autoindex_conf->default_keyid
? autoindex_conf->default_keyid : K_NAME;
direction = autoindex_conf->default_direction
? autoindex_conf->default_direction : D_ASCENDING;
/*
* Figure out what sort of indexing (if any) we're supposed to use.
*
* If no QUERY_STRING was specified or client query strings have been
* explicitly disabled.
* If we are ignoring the client, suppress column sorting as well.
*/
if (autoindex_opts & IGNORE_CLIENT) {
qstring = NULL;
autoindex_opts |= SUPPRESS_COLSORT;
colargs = "";
}
else {
char fval[5], vval[5], *ppre = "";
fval[0] = '\0'; vval[0] = '\0';
qstring = r->args;
while (qstring && *qstring) {
if (qstring[0] == 'C' && qstring[1] == '='
&& qstring[2] && strchr(K_VALID, qstring[2])
&& (qstring[3] == '&' || !qstring[3])) {
keyid = qstring[2];
qstring += qstring[3] ? 4 : 3;
}
else if (qstring[0] == 'O' && qstring[1] == '='
&& ((qstring[2] == D_ASCENDING)
|| (qstring[2] == D_DESCENDING))
&& (qstring[3] == '&' || !qstring[3])) {
direction = qstring[2];
qstring += qstring[3] ? 4 : 3;
}
else if (qstring[0] == 'F' && qstring[1] == '='
&& qstring[2] && strchr("012", qstring[2])
&& (qstring[3] == '&' || !qstring[3])) {
if (qstring[2] == '0') {
autoindex_opts &= ~(FANCY_INDEXING | TABLE_INDEXING);
}
else if (qstring[2] == '1') {
autoindex_opts = (autoindex_opts | FANCY_INDEXING)
& ~TABLE_INDEXING;
}
else if (qstring[2] == '2') {
autoindex_opts |= FANCY_INDEXING | TABLE_INDEXING;
}
strcpy(fval, "&F= ");
fval[3] = qstring[2];
qstring += qstring[3] ? 4 : 3;
}
else if (qstring[0] == 'V' && qstring[1] == '='
&& (qstring[2] == '0' || qstring[2] == '1')
&& (qstring[3] == '&' || !qstring[3])) {
if (qstring[2] == '0') {
autoindex_opts &= ~VERSION_SORT;
}
else if (qstring[2] == '1') {
autoindex_opts |= VERSION_SORT;
}
strcpy(fval, "&V= ");
vval[3] = qstring[2];
qstring += qstring[3] ? 4 : 3;
}
else if (qstring[0] == 'P' && qstring[1] == '=') {
const char *eos = ap_strchr_c(qstring, '&');
if (eos) {
pstring = apr_pstrndup(r->pool, qstring + 2,
eos - qstring - 2);
qstring = eos + 1;
}
else {
pstring = apr_pstrdup(r->pool, qstring + 2);
qstring = NULL;
}
if (*pstring) {
ppre = "&P=";
}
else {
pstring = NULL;
}
}
else { /* Syntax error? Ignore the remainder! */
qstring = NULL;
}
}
colargs = apr_pstrcat(r->pool, fval, vval, ppre, pstring, NULL);
}
/* Spew HTML preamble */
title_endp = title_name + strlen(title_name) - 1;
while (title_endp > title_name && *title_endp == '/') {
*title_endp-- = '\0';
}
emit_head(r, find_header(autoindex_conf, r),
autoindex_opts & SUPPRESS_PREAMBLE, title_name);
/*
* Since we don't know how many dir. entries there are, put them into a
* linked list and then arrayificate them so qsort can use them.
*/
head = NULL;
p = make_parent_entry(autoindex_opts, autoindex_conf, r, keyid, direction);
if (p != NULL) {
p->next = head;
head = p;
num_ent++;
}
fullpath = apr_palloc(r->pool, APR_PATH_MAX);
dirpathlen = strlen(name);
memcpy(fullpath, name, dirpathlen);
while (apr_dir_read(&dirent, APR_FINFO_MIN | APR_FINFO_NAME, thedir) == APR_SUCCESS) {
/* We want to explode symlinks here. */
if (dirent.filetype == APR_LNK) {
const char *savename;
apr_finfo_t fi;
/* We *must* have FNAME. */
savename = dirent.name;
apr_cpystrn(fullpath + dirpathlen, dirent.name,
APR_PATH_MAX - dirpathlen);
status = apr_stat(&fi, fullpath,
dirent.valid & ~(APR_FINFO_NAME), r->pool);
if (status != APR_SUCCESS) {
/* Something bad happened, skip this file. */
continue;
}
memcpy(&dirent, &fi, sizeof(fi));
dirent.name = savename;
dirent.valid |= APR_FINFO_NAME;
}
p = make_autoindex_entry(&dirent, autoindex_opts, autoindex_conf, r,
keyid, direction, pstring);
if (p != NULL) {
p->next = head;
head = p;
num_ent++;
}
}
if (num_ent > 0) {
ar = (struct ent **) apr_palloc(r->pool,
num_ent * sizeof(struct ent *));
p = head;
x = 0;
while (p) {
ar[x++] = p;
p = p->next;
}
qsort((void *) ar, num_ent, sizeof(struct ent *),
(int (*)(const void *, const void *)) dsortf);
}
output_directories(ar, num_ent, autoindex_conf, r, autoindex_opts,
keyid, direction, colargs);
apr_dir_close(thedir);
emit_tail(r, find_readme(autoindex_conf, r),
autoindex_opts & SUPPRESS_PREAMBLE);
return 0;
}
/* The formal handler... */
static int handle_autoindex(request_rec *r)
{
autoindex_config_rec *d;
int allow_opts;
if(strcmp(r->handler,DIR_MAGIC_TYPE)) {
return DECLINED;
}
allow_opts = ap_allow_options(r);
d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config,
&autoindex_module);
r->allowed |= (AP_METHOD_BIT << M_GET);
if (r->method_number != M_GET) {
return DECLINED;
}
/* OK, nothing easy. Trot out the heavy artillery... */
if (allow_opts & OPT_INDEXES) {
/* KLUDGE --- make the sub_req lookups happen in the right directory.
* Fixing this in the sub_req_lookup functions themselves is difficult,
* and would probably break virtual includes...
*/
if (r->filename[strlen(r->filename) - 1] != '/') {
r->filename = apr_pstrcat(r->pool, r->filename, "/", NULL);
}
return index_directory(r, d);
}
else {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"Directory index forbidden by rule: %s", r->filename);
return HTTP_FORBIDDEN;
}
}
static void register_hooks(apr_pool_t *p)
{
ap_hook_handler(handle_autoindex,NULL,NULL,APR_HOOK_MIDDLE);
}
module AP_MODULE_DECLARE_DATA autoindex_module =
{
STANDARD20_MODULE_STUFF,
create_autoindex_config, /* dir config creater */
merge_autoindex_configs, /* dir merger --- default is to override */
NULL, /* server config */
NULL, /* merge server config */
autoindex_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};