mod_autoindex.c revision 2e1aa1e99dea843ed25edc8f680ec22c2833d721
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * http://www.apache.org/licenses/LICENSE-2.0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * mod_autoindex.c: Handles the on-the-fly html index generation
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Rob McCool
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * 3/23/93
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Adapted to Apache by rst.
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein *
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * Version sort added by Martin Pool <mbp@humbug.org.au>.
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein */
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein#include "apr_strings.h"
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#include "apr_fnmatch.h"
be3223a6a18d9a3a3cf7155d5430a5d92bcddceegstein#include "apr_strings.h"
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#include "apr_lib.h"
1b21d7b3d97def358b2e923655edeb16613a1c31gstein
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#define APR_WANT_STRFUNC
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#include "apr_want.h"
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein#include "ap_config.h"
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein#include "httpd.h"
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein#include "http_config.h"
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#include "http_core.h"
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#include "http_request.h"
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#include "http_protocol.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_log.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_main.h"
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein#include "util_script.h"
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "mod_core.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingmodule AP_MODULE_DECLARE_DATA autoindex_module;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/****************************************************************
cf8fe49d9d89cfa4b62cb2b1376ca6f25b81b362trawick *
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * Handling configuration directives...
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
8a3228198adb03e6996f7738c361a612777ecab6aaron#define NO_OPTIONS (1 << 0) /* Indexing options */
8a3228198adb03e6996f7738c361a612777ecab6aaron#define ICONS_ARE_LINKS (1 << 1)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SCAN_HTML_TITLES (1 << 2)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_ICON (1 << 3)
a7318397b355119d990d1f311b951dea2aafc53arbb#define SUPPRESS_LAST_MOD (1 << 4)
a7318397b355119d990d1f311b951dea2aafc53arbb#define SUPPRESS_SIZE (1 << 5)
a7318397b355119d990d1f311b951dea2aafc53arbb#define SUPPRESS_DESC (1 << 6)
a7318397b355119d990d1f311b951dea2aafc53arbb#define SUPPRESS_PREAMBLE (1 << 7)
cb9e6e5c78f5a1690214e9548250fc6af1fc73b5wrowe#define SUPPRESS_COLSORT (1 << 8)
cb9e6e5c78f5a1690214e9548250fc6af1fc73b5wrowe#define SUPPRESS_RULES (1 << 9)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define FOLDERS_FIRST (1 << 10)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define VERSION_SORT (1 << 11)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define TRACK_MODIFIED (1 << 12)
8a3228198adb03e6996f7738c361a612777ecab6aaron#define FANCY_INDEXING (1 << 13)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define TABLE_INDEXING (1 << 14)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define IGNORE_CLIENT (1 << 15)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define IGNORE_CASE (1 << 16)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define EMIT_XHTML (1 << 17)
8a3228198adb03e6996f7738c361a612777ecab6aaron#define SHOW_FORBIDDEN (1 << 18)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define ADDALTCLASS (1 << 19)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define OPTION_UNSET (1 << 20)
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.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
8a3228198adb03e6996f7738c361a612777ecab6aaron#define DEFAULT_NAME_WIDTH 23
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define DEFAULT_DESC_WIDTH 23
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
8a3228198adb03e6996f7738c361a612777ecab6aaronstruct item {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *type;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *apply_to;
8a3228198adb03e6996f7738c361a612777ecab6aaron char *apply_path;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *data;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
8a3228198adb03e6996f7738c361a612777ecab6aaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct ai_desc_t {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *pattern;
8a3228198adb03e6996f7738c361a612777ecab6aaron char *description;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int full_path;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int wildcards;
8a3228198adb03e6996f7738c361a612777ecab6aaron} ai_desc_t;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct autoindex_config_struct {
8a3228198adb03e6996f7738c361a612777ecab6aaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *default_icon;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *style_sheet;
8a3228198adb03e6996f7738c361a612777ecab6aaron char *head_insert;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *header;
8a3228198adb03e6996f7738c361a612777ecab6aaron char *readme;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_int32_t opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_int32_t incremented_opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_int32_t decremented_opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int name_width;
8a3228198adb03e6996f7738c361a612777ecab6aaron int name_adjust;
8a3228198adb03e6996f7738c361a612777ecab6aaron int desc_width;
8a3228198adb03e6996f7738c361a612777ecab6aaron int desc_adjust;
8a3228198adb03e6996f7738c361a612777ecab6aaron int icon_width;
8a3228198adb03e6996f7738c361a612777ecab6aaron int icon_height;
8a3228198adb03e6996f7738c361a612777ecab6aaron char default_keyid;
8a3228198adb03e6996f7738c361a612777ecab6aaron char default_direction;
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_array_header_t *icon_list;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_array_header_t *alt_list;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_array_header_t *desc_list;
649c9dd342a580016d29c2866de88a4609eb6457wrowe apr_array_header_t *ign_list;
649c9dd342a580016d29c2866de88a4609eb6457wrowe int ign_noinherit;
0f57a69cc84c59eacda1179763ae42ca88f1a577wrowe
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick char *ctype;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick char *charset;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick} autoindex_config_rec;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickstatic char c_by_encoding, c_by_type, c_by_path;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick#define BY_ENCODING &c_by_encoding
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick#define BY_TYPE &c_by_type
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick#define BY_PATH &c_by_path
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickstatic APR_INLINE int response_is_html(request_rec *r)
649c9dd342a580016d29c2866de88a4609eb6457wrowe{
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick char *ctype = ap_field_noparam(r->pool, r->content_type);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick ap_str_tolower(ctype);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick return !strcmp(ctype, "text/html")
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick || !strcmp(ctype, "application/xhtml+xml");
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick}
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick/*
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick * This routine puts the standard HTML header at the top of the index page.
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick * We include the DOCTYPE because we may be using features therefrom (i.e.,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick */
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickstatic void emit_preamble(request_rec *r, int xhtml, const char *title)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick{
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick autoindex_config_rec *d;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick &autoindex_module);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick if (xhtml) {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick ap_rvputs(r, DOCTYPE_XHTML_1_0T,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick " <head>\n <title>Index of ", title,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick "</title>\n", NULL);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick } else {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick ap_rvputs(r, DOCTYPE_HTML_3_2,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick "<html>\n <head>\n"
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick " <title>Index of ", title,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick "</title>\n", NULL);
ebc18d48bea83ee5ed7a1b4e30007e5192539829wrowe }
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick
066877f1a045103acfdd376d48cdd473c33f409bdougm if (d->style_sheet != NULL) {
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick ap_rvputs(r, " <link rel=\"stylesheet\" href=\"", d->style_sheet,
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick "\" type=\"text/css\"", xhtml ? " />\n" : ">\n", NULL);
e8f95a682820a599fe41b22977010636be5c2717jim }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe if (d->head_insert != NULL) {
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe ap_rputs(d->head_insert, r);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe ap_rputs(" </head>\n <body>\n", r);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe}
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowestatic void push_item(apr_array_header_t *arr, char *type, const char *to,
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe const char *path, const char *data)
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe{
85c435ceda98eab940615e4466d9c5955252e745wrowe struct item *p = (struct item *) apr_array_push(arr);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe if (!to) {
92eed7d377d8be7cd8e48d1299412fc8c742b7f5jorton to = "";
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe if (!path) {
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe path = "";
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe p->type = type;
649c9dd342a580016d29c2866de88a4609eb6457wrowe p->data = apr_pstrdup(arr->pool, data);
649c9dd342a580016d29c2866de88a4609eb6457wrowe p->apply_path = apr_pstrcat(arr->pool, path, "*", NULL);
649c9dd342a580016d29c2866de88a4609eb6457wrowe
649c9dd342a580016d29c2866de88a4609eb6457wrowe if ((type == BY_PATH) && (!ap_is_matchexp(to))) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe p->apply_to = apr_pstrcat(arr->pool, "*", to, NULL);
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe else if (to) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe p->apply_to = apr_pstrdup(arr->pool, to);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe else {
649c9dd342a580016d29c2866de88a4609eb6457wrowe p->apply_to = NULL;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe}
649c9dd342a580016d29c2866de88a4609eb6457wrowe
649c9dd342a580016d29c2866de88a4609eb6457wrowestatic const char *add_alt(cmd_parms *cmd, void *d, const char *alt,
649c9dd342a580016d29c2866de88a4609eb6457wrowe const char *to)
649c9dd342a580016d29c2866de88a4609eb6457wrowe{
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (cmd->info == BY_PATH) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (!strcmp(to, "**DIRECTORY**")) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe to = "^^DIRECTORY^^";
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe if (cmd->info == BY_ENCODING) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe char *tmp = apr_pstrdup(cmd->pool, to);
649c9dd342a580016d29c2866de88a4609eb6457wrowe ap_str_tolower(tmp);
649c9dd342a580016d29c2866de88a4609eb6457wrowe to = tmp;
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe push_item(((autoindex_config_rec *) d)->alt_list, cmd->info, to,
760b90f5b0bb414646deb6a3a2a53c14bf49bf3dwrowe cmd->path, alt);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe return NULL;
15405e91bb3fad5a80f7abe828a00b44a3a65bf8jerenkrantz}
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowestatic const char *add_icon(cmd_parms *cmd, void *d, const char *icon,
76185d819b745e953dd2cd636fbdd515c333e4a4trawick const char *to)
76185d819b745e953dd2cd636fbdd515c333e4a4trawick{
76185d819b745e953dd2cd636fbdd515c333e4a4trawick char *iconbak = apr_pstrdup(cmd->pool, icon);
76185d819b745e953dd2cd636fbdd515c333e4a4trawick
76185d819b745e953dd2cd636fbdd515c333e4a4trawick if (icon[0] == '(') {
76185d819b745e953dd2cd636fbdd515c333e4a4trawick char *alt;
76185d819b745e953dd2cd636fbdd515c333e4a4trawick char *cl = strchr(iconbak, ')');
399cf0e5e061b49593817421b94305889fa6bc1fjorton
399cf0e5e061b49593817421b94305889fa6bc1fjorton if (cl == NULL) {
399cf0e5e061b49593817421b94305889fa6bc1fjorton return "missing closing paren";
399cf0e5e061b49593817421b94305889fa6bc1fjorton }
399cf0e5e061b49593817421b94305889fa6bc1fjorton alt = ap_getword_nc(cmd->pool, &iconbak, ',');
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm *cl = '\0'; /* Lose closing paren */
399cf0e5e061b49593817421b94305889fa6bc1fjorton add_alt(cmd, d, &alt[1], to);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (cmd->info == BY_PATH) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!strcmp(to, "**DIRECTORY**")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding to = "^^DIRECTORY^^";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (cmd->info == BY_ENCODING) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm char *tmp = apr_pstrdup(cmd->pool, to);
399cf0e5e061b49593817421b94305889fa6bc1fjorton ap_str_tolower(tmp);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding to = tmp;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh }
7d77917ef4b13a5d97e9cd85898630c0f106d7c8trawick
d406be0d6a4f9e61bbdfa6c8cde2e09338dd650atrawick push_item(((autoindex_config_rec *) d)->icon_list, cmd->info, to,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh cmd->path, iconbak);
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh return NULL;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh}
76185d819b745e953dd2cd636fbdd515c333e4a4trawick
76185d819b745e953dd2cd636fbdd515c333e4a4trawick/*
ff0436077dc959b17a6f87825e4a106d211224c1wrowe * Add description text for a filename pattern. If the pattern has
ff0436077dc959b17a6f87825e4a106d211224c1wrowe * wildcards already (or we need to add them), add leading and
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb * trailing wildcards to it to ensure substring processing. If the
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb * pattern contains a '/' anywhere, force wildcard matching mode,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * add a slash to the prefix so that "bar/bletch" won't be matched
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * by "foobar/bletch", and make a note that there's a delimiter;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * the matching routine simplifies to just the actual filename
8a3228198adb03e6996f7738c361a612777ecab6aaron * whenever it can. This allows definitions in parent directories
ff0436077dc959b17a6f87825e4a106d211224c1wrowe * to be made for files in subordinate ones using relative paths.
ff0436077dc959b17a6f87825e4a106d211224c1wrowe */
ff0436077dc959b17a6f87825e4a106d211224c1wrowe
ff0436077dc959b17a6f87825e4a106d211224c1wrowe/*
ff0436077dc959b17a6f87825e4a106d211224c1wrowe * Absent a strcasestr() function, we have to force wildcards on
ff0436077dc959b17a6f87825e4a106d211224c1wrowe * systems for which "AAA" and "aaa" mean the same file.
066877f1a045103acfdd376d48cdd473c33f409bdougm */
8a3228198adb03e6996f7738c361a612777ecab6aaron#ifdef CASE_BLIND_FILESYSTEM
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh#define WILDCARDS_REQUIRED 1
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb#else
d521bfef0e1a65993d5e302628ac68a2c91a195ftrawick#define WILDCARDS_REQUIRED 0
20c85ca0d404e29972fb94c3d6236a264d1c77abstoddard#endif
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickstatic const char *add_desc(cmd_parms *cmd, void *d, const char *desc,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick const char *to)
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb{
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb autoindex_config_rec *dcfg = (autoindex_config_rec *) d;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb ai_desc_t *desc_entry;
8a3228198adb03e6996f7738c361a612777ecab6aaron char *prefix = "";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding 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
399cf0e5e061b49593817421b94305889fa6bc1fjorton || desc_entry->full_path
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding || apr_fnmatch_test(to));
061c3874622b67beff724876b9bd1b1f291f2eaafielding if (desc_entry->wildcards) {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb prefix = desc_entry->full_path ? "*/" : "*";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding desc_entry->pattern = apr_pstrcat(dcfg->desc_list->pool,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding prefix, to, "*", NULL);
8a3228198adb03e6996f7738c361a612777ecab6aaron }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb else {
399cf0e5e061b49593817421b94305889fa6bc1fjorton desc_entry->pattern = apr_pstrdup(dcfg->desc_list->pool, to);
399cf0e5e061b49593817421b94305889fa6bc1fjorton }
399cf0e5e061b49593817421b94305889fa6bc1fjorton desc_entry->description = apr_pstrdup(dcfg->desc_list->pool, desc);
399cf0e5e061b49593817421b94305889fa6bc1fjorton return NULL;
399cf0e5e061b49593817421b94305889fa6bc1fjorton}
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
2261031aa94be82d7e6b1b8c367afc1b282317f5ianhstatic const char *add_ignore(cmd_parms *cmd, void *d, const char *ext)
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick{
85c435ceda98eab940615e4466d9c5955252e745wrowe push_item(((autoindex_config_rec *) d)->ign_list, 0, ext, cmd->path, NULL);
8a3228198adb03e6996f7738c361a612777ecab6aaron return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const char *add_opts(cmd_parms *cmd, void *d, int argc, char *const argv[])
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int i;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *w;
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_int32_t opts;
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_int32_t opts_add;
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_int32_t opts_remove;
8a3228198adb03e6996f7738c361a612777ecab6aaron char action;
8a3228198adb03e6996f7738c361a612777ecab6aaron autoindex_config_rec *d_cfg = (autoindex_config_rec *) d;
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaron opts = d_cfg->opts;
8a3228198adb03e6996f7738c361a612777ecab6aaron opts_add = d_cfg->incremented_opts;
8a3228198adb03e6996f7738c361a612777ecab6aaron opts_remove = d_cfg->decremented_opts;
85c435ceda98eab940615e4466d9c5955252e745wrowe
8a3228198adb03e6996f7738c361a612777ecab6aaron for (i = 0; i < argc; i++) {
8a3228198adb03e6996f7738c361a612777ecab6aaron int option = 0;
8a3228198adb03e6996f7738c361a612777ecab6aaron w = argv[i];
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaron if ((*w == '+') || (*w == '-')) {
8a3228198adb03e6996f7738c361a612777ecab6aaron action = *(w++);
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding action = '\0';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!strcasecmp(w, "FancyIndexing")) {
8a3228198adb03e6996f7738c361a612777ecab6aaron option = FANCY_INDEXING;
32c4bc04f89b16521718145dc731f750144d7b38wrowe }
32c4bc04f89b16521718145dc731f750144d7b38wrowe else if (!strcasecmp(w, "FoldersFirst")) {
32c4bc04f89b16521718145dc731f750144d7b38wrowe option = FOLDERS_FIRST;
32c4bc04f89b16521718145dc731f750144d7b38wrowe }
85c435ceda98eab940615e4466d9c5955252e745wrowe else if (!strcasecmp(w, "HTMLTable")) {
32c4bc04f89b16521718145dc731f750144d7b38wrowe option = TABLE_INDEXING;
32c4bc04f89b16521718145dc731f750144d7b38wrowe }
92eed7d377d8be7cd8e48d1299412fc8c742b7f5jorton else if (!strcasecmp(w, "IconsAreLinks")) {
32c4bc04f89b16521718145dc731f750144d7b38wrowe option = ICONS_ARE_LINKS;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh }
2b484455736f4c30447aa852764f53282cbeb5ddrbb else if (!strcasecmp(w, "IgnoreCase")) {
c25e9633c29be3a5b74f0bf75079d54e5417115dwrowe option = IGNORE_CASE;
85c435ceda98eab940615e4466d9c5955252e745wrowe }
8a3228198adb03e6996f7738c361a612777ecab6aaron else if (!strcasecmp(w, "IgnoreClient")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = IGNORE_CLIENT;
85c435ceda98eab940615e4466d9c5955252e745wrowe }
85c435ceda98eab940615e4466d9c5955252e745wrowe else if (!strcasecmp(w, "ScanHTMLTitles")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SCAN_HTML_TITLES;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
e8f95a682820a599fe41b22977010636be5c2717jim else if (!strcasecmp(w, "SuppressColumnSorting")) {
85c435ceda98eab940615e4466d9c5955252e745wrowe option = SUPPRESS_COLSORT;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
649c9dd342a580016d29c2866de88a4609eb6457wrowe else if (!strcasecmp(w, "SuppressDescription")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SUPPRESS_DESC;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "SuppressHTMLPreamble")) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe option = SUPPRESS_PREAMBLE;
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe else if (!strcasecmp(w, "SuppressIcon")) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe option = SUPPRESS_ICON;
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe else if (!strcasecmp(w, "SuppressLastModified")) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe option = SUPPRESS_LAST_MOD;
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe else if (!strcasecmp(w, "SuppressSize")) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe option = SUPPRESS_SIZE;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick }
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick else if (!strcasecmp(w, "SuppressRules")) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe option = SUPPRESS_RULES;
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe else if (!strcasecmp(w, "TrackModified")) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe option = TRACK_MODIFIED;
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe else if (!strcasecmp(w, "VersionSort")) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe option = VERSION_SORT;
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe else if (!strcasecmp(w, "XHTML")) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe option = EMIT_XHTML;
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
85c435ceda98eab940615e4466d9c5955252e745wrowe else if (!strcasecmp(w, "ShowForbidden")) {
85c435ceda98eab940615e4466d9c5955252e745wrowe option = SHOW_FORBIDDEN;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "AddAltClass")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = ADDALTCLASS;
ab43b4a17b2ac31ccb1cf280be8c42a8a314cecbjorton }
ab43b4a17b2ac31ccb1cf280be8c42a8a314cecbjorton else if (!strcasecmp(w, "None")) {
ab43b4a17b2ac31ccb1cf280be8c42a8a314cecbjorton if (action != '\0') {
066877f1a045103acfdd376d48cdd473c33f409bdougm return "Cannot combine '+' or '-' with 'None' keyword";
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
ab43b4a17b2ac31ccb1cf280be8c42a8a314cecbjorton opts = NO_OPTIONS;
ab43b4a17b2ac31ccb1cf280be8c42a8a314cecbjorton opts_add = 0;
ec727afb817df0e5202135278c0d2902923cc980stoddard opts_remove = 0;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh else if (!strcasecmp(w, "IconWidth")) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (action != '-') {
649c9dd342a580016d29c2866de88a4609eb6457wrowe d_cfg->icon_width = DEFAULT_ICON_WIDTH;
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe else {
649c9dd342a580016d29c2866de88a4609eb6457wrowe d_cfg->icon_width = 0;
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
ec727afb817df0e5202135278c0d2902923cc980stoddard }
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe else if (!strncasecmp(w, "IconWidth=", 10)) {
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe if (action == '-') {
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe return "Cannot combine '-' with IconWidth=n";
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe }
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe d_cfg->icon_width = atoi(&w[10]);
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe }
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe else if (!strcasecmp(w, "IconHeight")) {
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe if (action != '-') {
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe d_cfg->icon_height = DEFAULT_ICON_HEIGHT;
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe }
ec727afb817df0e5202135278c0d2902923cc980stoddard else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->icon_height = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strncasecmp(w, "IconHeight=", 11)) {
0f57a69cc84c59eacda1179763ae42ca88f1a577wrowe if (action == '-') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Cannot combine '-' with IconHeight=n";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
8a3228198adb03e6996f7738c361a612777ecab6aaron d_cfg->icon_height = atoi(&w[11]);
8a3228198adb03e6996f7738c361a612777ecab6aaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "NameWidth")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action != '-') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "NameWidth with no value may only appear as "
8a3228198adb03e6996f7738c361a612777ecab6aaron "'-NameWidth'";
8a3228198adb03e6996f7738c361a612777ecab6aaron }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh d_cfg->name_width = DEFAULT_NAME_WIDTH;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh d_cfg->name_adjust = K_NOADJUST;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh }
8a3228198adb03e6996f7738c361a612777ecab6aaron else if (!strncasecmp(w, "NameWidth=", 10)) {
8a3228198adb03e6996f7738c361a612777ecab6aaron if (action == '-') {
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh return "Cannot combine '-' with NameWidth=n";
8a3228198adb03e6996f7738c361a612777ecab6aaron }
399cf0e5e061b49593817421b94305889fa6bc1fjorton if (w[10] == '*') {
85c435ceda98eab940615e4466d9c5955252e745wrowe d_cfg->name_adjust = K_ADJUST;
85c435ceda98eab940615e4466d9c5955252e745wrowe }
8a3228198adb03e6996f7738c361a612777ecab6aaron else {
8a3228198adb03e6996f7738c361a612777ecab6aaron int width = atoi(&w[10]);
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaron if (width && (width < 5)) {
8a3228198adb03e6996f7738c361a612777ecab6aaron return "NameWidth value must be greater than 5";
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron d_cfg->name_width = width;
8a3228198adb03e6996f7738c361a612777ecab6aaron d_cfg->name_adjust = K_NOADJUST;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
85c435ceda98eab940615e4466d9c5955252e745wrowe }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "DescriptionWidth")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action != '-') {
3d96ee83babeec32482c9082c9426340cee8c44dwrowe return "DescriptionWidth with no value may only appear as "
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm "'-DescriptionWidth'";
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh d_cfg->desc_width = DEFAULT_DESC_WIDTH;
4e1e8abb2a6e588366a4680b039b460fc5fe1ccdstoddard d_cfg->desc_adjust = K_NOADJUST;
bdf833c0329ee171eb99efe9c037b6ed653c5007aaron }
40303323ae9960bd38a0f03d2c10e897a7badd88rbb else if (!strncasecmp(w, "DescriptionWidth=", 17)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action == '-') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Cannot combine '-' with DescriptionWidth=n";
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh if (w[17] == '*') {
e34223f72e630187c4d8ac7c22da5096c833eb20trawick d_cfg->desc_adjust = K_ADJUST;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
3597d6b10c88c252f156fe8061b659a38dea38c2rbb else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int width = atoi(&w[17]);
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd
9fe315e66ef597a158db81bcbd230d7a5d65785dnd if (width && (width < 12)) {
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd return "DescriptionWidth value must be greater than 12";
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd }
58fd79b56eb624bf011772994e9761d3c2e228c1orlikowski d_cfg->desc_width = width;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm d_cfg->desc_adjust = K_NOADJUST;
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb }
39b67927abc1c24834e165444655939ea52c908aorlikowski }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strncasecmp(w, "Type=", 5)) {
e34223f72e630187c4d8ac7c22da5096c833eb20trawick d_cfg->ctype = apr_pstrdup(cmd->pool, &w[5]);
e34223f72e630187c4d8ac7c22da5096c833eb20trawick }
e34223f72e630187c4d8ac7c22da5096c833eb20trawick else if (!strncasecmp(w, "Charset=", 8)) {
e34223f72e630187c4d8ac7c22da5096c833eb20trawick d_cfg->charset = apr_pstrdup(cmd->pool, &w[8]);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
8a3228198adb03e6996f7738c361a612777ecab6aaron else {
8a3228198adb03e6996f7738c361a612777ecab6aaron return "Invalid directory indexing option";
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron if (action == '\0') {
8a3228198adb03e6996f7738c361a612777ecab6aaron opts |= option;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh opts_add = 0;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh opts_remove = 0;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron else if (action == '+') {
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh opts_add |= option;
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick opts_remove &= ~option;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
8a3228198adb03e6996f7738c361a612777ecab6aaron opts_remove |= option;
8a3228198adb03e6996f7738c361a612777ecab6aaron opts_add &= ~option;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh if ((opts & NO_OPTIONS) && (opts & ~NO_OPTIONS)) {
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh return "Cannot combine other IndexOptions keywords with 'None'";
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron d_cfg->incremented_opts = opts_add;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh d_cfg->decremented_opts = opts_remove;
8a3228198adb03e6996f7738c361a612777ecab6aaron d_cfg->opts = opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
8a3228198adb03e6996f7738c361a612777ecab6aaronstatic const char *set_default_order(cmd_parms *cmd, void *m,
8a3228198adb03e6996f7738c361a612777ecab6aaron const char *direction, const char *key)
8a3228198adb03e6996f7738c361a612777ecab6aaron{
8a3228198adb03e6996f7738c361a612777ecab6aaron autoindex_config_rec *d_cfg = (autoindex_config_rec *) m;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh if (!strcasecmp(direction, "Ascending")) {
8a3228198adb03e6996f7738c361a612777ecab6aaron d_cfg->default_direction = D_ASCENDING;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh else if (!strcasecmp(direction, "Descending")) {
8a3228198adb03e6996f7738c361a612777ecab6aaron d_cfg->default_direction = D_DESCENDING;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "First keyword must be 'Ascending' or 'Descending'";
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaron if (!strcasecmp(key, "Name")) {
8a3228198adb03e6996f7738c361a612777ecab6aaron d_cfg->default_keyid = K_NAME;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron else if (!strcasecmp(key, "Date")) {
8a3228198adb03e6996f7738c361a612777ecab6aaron d_cfg->default_keyid = K_LAST_MOD;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(key, "Size")) {
2b484455736f4c30447aa852764f53282cbeb5ddrbb d_cfg->default_keyid = K_SIZE;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
b5033962c73a470b6f36a3ac796c542a6ab4ddf6brianp else if (!strcasecmp(key, "Description")) {
8a3228198adb03e6996f7738c361a612777ecab6aaron d_cfg->default_keyid = K_DESC;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Second keyword must be 'Name', 'Date', 'Size', or "
8a3228198adb03e6996f7738c361a612777ecab6aaron "'Description'";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2b484455736f4c30447aa852764f53282cbeb5ddrbb return NULL;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
8a3228198adb03e6996f7738c361a612777ecab6aaron
2b484455736f4c30447aa852764f53282cbeb5ddrbb#define DIR_CMD_PERMS OR_INDEXES
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const command_rec autoindex_cmds[] =
39b67927abc1c24834e165444655939ea52c908aorlikowski{
0ef41d8e4b94d343e5b093c4dbd6ee61c1279401trawick AP_INIT_ITERATE2("AddIcon", add_icon, BY_PATH, DIR_CMD_PERMS,
8a3228198adb03e6996f7738c361a612777ecab6aaron "an icon URL followed by one or more filenames"),
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_ITERATE2("AddIconByType", add_icon, BY_TYPE, DIR_CMD_PERMS,
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard "an icon URL followed by one or more MIME types"),
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard AP_INIT_ITERATE2("AddIconByEncoding", add_icon, BY_ENCODING, DIR_CMD_PERMS,
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard "an icon URL followed by one or more content encodings"),
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard AP_INIT_ITERATE2("AddAlt", add_alt, BY_PATH, DIR_CMD_PERMS,
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard "alternate descriptive text followed by one or more "
8a3228198adb03e6996f7738c361a612777ecab6aaron "filenames"),
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_ITERATE2("AddAltByType", add_alt, BY_TYPE, DIR_CMD_PERMS,
8a3228198adb03e6996f7738c361a612777ecab6aaron "alternate descriptive text followed by one or more MIME "
8a3228198adb03e6996f7738c361a612777ecab6aaron "types"),
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_ITERATE2("AddAltByEncoding", add_alt, BY_ENCODING, DIR_CMD_PERMS,
8a3228198adb03e6996f7738c361a612777ecab6aaron "alternate descriptive text followed by one or more "
8a3228198adb03e6996f7738c361a612777ecab6aaron "content encodings"),
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_TAKE_ARGV("IndexOptions", add_opts, NULL, DIR_CMD_PERMS,
8a3228198adb03e6996f7738c361a612777ecab6aaron "one or more index options [+|-][]"),
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_TAKE2("IndexOrderDefault", set_default_order, NULL, DIR_CMD_PERMS,
8a3228198adb03e6996f7738c361a612777ecab6aaron "{Ascending,Descending} {Name,Size,Description,Date}"),
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_ITERATE("IndexIgnore", add_ignore, NULL, DIR_CMD_PERMS,
8a3228198adb03e6996f7738c361a612777ecab6aaron "one or more file extensions"),
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_FLAG("IndexIgnoreReset", ap_set_flag_slot,
8a3228198adb03e6996f7738c361a612777ecab6aaron (void *)APR_OFFSETOF(autoindex_config_rec, ign_noinherit),
50e421c0e069853bb724f3d816cef543e447c844jorton DIR_CMD_PERMS,
50e421c0e069853bb724f3d816cef543e447c844jorton "Reset the inherited list of IndexIgnore filenames"),
50e421c0e069853bb724f3d816cef543e447c844jorton AP_INIT_ITERATE2("AddDescription", add_desc, BY_PATH, DIR_CMD_PERMS,
50e421c0e069853bb724f3d816cef543e447c844jorton "Descriptive text followed by one or more filenames"),
50e421c0e069853bb724f3d816cef543e447c844jorton AP_INIT_TAKE1("HeaderName", ap_set_string_slot,
50e421c0e069853bb724f3d816cef543e447c844jorton (void *)APR_OFFSETOF(autoindex_config_rec, header),
50e421c0e069853bb724f3d816cef543e447c844jorton DIR_CMD_PERMS, "a filename"),
50e421c0e069853bb724f3d816cef543e447c844jorton AP_INIT_TAKE1("ReadmeName", ap_set_string_slot,
8a3228198adb03e6996f7738c361a612777ecab6aaron (void *)APR_OFFSETOF(autoindex_config_rec, readme),
8a3228198adb03e6996f7738c361a612777ecab6aaron DIR_CMD_PERMS, "a filename"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_RAW_ARGS("FancyIndexing", ap_set_deprecated, NULL, OR_ALL,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "The FancyIndexing directive is no longer supported. "
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh "Use IndexOptions FancyIndexing."),
e34223f72e630187c4d8ac7c22da5096c833eb20trawick AP_INIT_TAKE1("DefaultIcon", ap_set_string_slot,
8a3228198adb03e6996f7738c361a612777ecab6aaron (void *)APR_OFFSETOF(autoindex_config_rec, default_icon),
8a3228198adb03e6996f7738c361a612777ecab6aaron DIR_CMD_PERMS, "an icon URL"),
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_TAKE1("IndexStyleSheet", ap_set_string_slot,
8a3228198adb03e6996f7738c361a612777ecab6aaron (void *)APR_OFFSETOF(autoindex_config_rec, style_sheet),
8a3228198adb03e6996f7738c361a612777ecab6aaron DIR_CMD_PERMS, "URL to style sheet"),
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_TAKE1("IndexHeadInsert", ap_set_string_slot,
e34223f72e630187c4d8ac7c22da5096c833eb20trawick (void *)APR_OFFSETOF(autoindex_config_rec, head_insert),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DIR_CMD_PERMS, "String to insert in HTML HEAD section"),
127c81d6b2c9ba8932273c2e1b13e3ea3d673b07trawick {NULL}
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe};
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowestatic void *create_autoindex_config(apr_pool_t *p, char *dummy)
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe{
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe autoindex_config_rec *new =
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->icon_width = 0;
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->icon_height = 0;
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->name_width = DEFAULT_NAME_WIDTH;
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->name_adjust = K_UNSET;
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->desc_width = DEFAULT_DESC_WIDTH;
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->desc_adjust = K_UNSET;
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->icon_list = apr_array_make(p, 4, sizeof(struct item));
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->alt_list = apr_array_make(p, 4, sizeof(struct item));
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->desc_list = apr_array_make(p, 4, sizeof(ai_desc_t));
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->ign_list = apr_array_make(p, 4, sizeof(struct item));
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->opts = OPTION_UNSET;
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->incremented_opts = 0;
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->decremented_opts = 0;
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->default_keyid = '\0';
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->default_direction = '\0';
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (void *) new;
82acfa3f57607ae78326104c420a317260554a47nd}
3c09db9ce04e444548e386a4b822e76ea0dabbebrbb
9fe315e66ef597a158db81bcbd230d7a5d65785dndstatic void *merge_autoindex_configs(apr_pool_t *p, void *basev, void *addv)
82acfa3f57607ae78326104c420a317260554a47nd{
82acfa3f57607ae78326104c420a317260554a47nd autoindex_config_rec *new;
82acfa3f57607ae78326104c420a317260554a47nd autoindex_config_rec *base = (autoindex_config_rec *) basev;
82acfa3f57607ae78326104c420a317260554a47nd autoindex_config_rec *add = (autoindex_config_rec *) addv;
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd new = (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd new->default_icon = add->default_icon ? add->default_icon
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding : base->default_icon;
82acfa3f57607ae78326104c420a317260554a47nd new->style_sheet = add->style_sheet ? add->style_sheet
9fe315e66ef597a158db81bcbd230d7a5d65785dnd : base->style_sheet;
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd new->head_insert = add->head_insert ? add->head_insert
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd : base->head_insert;
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd new->header = add->header ? add->header
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb : base->header;
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd new->readme = add->readme ? add->readme
9fe315e66ef597a158db81bcbd230d7a5d65785dnd : base->readme;
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd new->icon_height = add->icon_height ? add->icon_height : base->icon_height;
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd new->icon_width = add->icon_width ? add->icon_width : base->icon_width;
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd new->ctype = add->ctype ? add->ctype : base->ctype;
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd new->charset = add->charset ? add->charset : base->charset;
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb new->alt_list = apr_array_append(p, add->alt_list, base->alt_list);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->desc_list = apr_array_append(p, add->desc_list, base->desc_list);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->icon_list = apr_array_append(p, add->icon_list, base->icon_list);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm new->ign_list = add->ign_noinherit ? add->ign_list : apr_array_append(p, add->ign_list, base->ign_list);
8a3228198adb03e6996f7738c361a612777ecab6aaron if (add->opts == NO_OPTIONS) {
e7daae8d2ef0165e83627188bf33655c0b8266e8wrowe /*
8a3228198adb03e6996f7738c361a612777ecab6aaron * If the current directory explicitly says 'no options' then we also
a1de70bda57b72d8cc6b47ea744e0973ed424f56wrowe * clear any incremental mods from being inheritable further down.
066877f1a045103acfdd376d48cdd473c33f409bdougm */
8a3228198adb03e6996f7738c361a612777ecab6aaron new->opts = NO_OPTIONS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->incremented_opts = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->decremented_opts = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
8a3228198adb03e6996f7738c361a612777ecab6aaron else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If there were any nonincremental options selected for
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * this directory, they dominate and we don't inherit *anything.*
3c09db9ce04e444548e386a4b822e76ea0dabbebrbb * Contrariwise, we *do* inherit if the only settings here are
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * incremental ones.
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh */
3d96ee83babeec32482c9082c9426340cee8c44dwrowe if (add->opts == OPTION_UNSET) {
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh new->incremented_opts = (base->incremented_opts
0942697a9b5de44865676345a3828741c827efe6rbb | add->incremented_opts)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding & ~add->decremented_opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->decremented_opts = (base->decremented_opts
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding | add->decremented_opts);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
e34223f72e630187c4d8ac7c22da5096c833eb20trawick * We may have incremental settings, so make sure we don't
3597d6b10c88c252f156fe8061b659a38dea38c2rbb * inadvertently inherit an IndexOptions None from above.
3597d6b10c88c252f156fe8061b659a38dea38c2rbb */
3597d6b10c88c252f156fe8061b659a38dea38c2rbb new->opts = (base->opts & ~NO_OPTIONS);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh else {
8a3228198adb03e6996f7738c361a612777ecab6aaron /*
3597d6b10c88c252f156fe8061b659a38dea38c2rbb * There are local nonincremental settings, which clear
3597d6b10c88c252f156fe8061b659a38dea38c2rbb * all inheritance from above. They *are* the new base settings.
3597d6b10c88c252f156fe8061b659a38dea38c2rbb */
3597d6b10c88c252f156fe8061b659a38dea38c2rbb new->opts = add->opts;
e34223f72e630187c4d8ac7c22da5096c833eb20trawick }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * We're guaranteed that there'll be no overlap between
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the add-options and the remove-options.
3d96ee83babeec32482c9082c9426340cee8c44dwrowe */
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh new->opts |= new->incremented_opts;
0942697a9b5de44865676345a3828741c827efe6rbb new->opts &= ~new->decremented_opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Inherit the NameWidth settings if there aren't any specific to
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the new location; otherwise we'll end up using the defaults set in the
e34223f72e630187c4d8ac7c22da5096c833eb20trawick * config-rec creation routine.
e34223f72e630187c4d8ac7c22da5096c833eb20trawick */
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh if (add->name_adjust == K_UNSET) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->name_width = base->name_width;
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard new->name_adjust = base->name_adjust;
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->name_width = add->name_width;
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard new->name_adjust = add->name_adjust;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh /*
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard * Likewise for DescriptionWidth.
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard */
8a3228198adb03e6996f7738c361a612777ecab6aaron if (add->desc_adjust == K_UNSET) {
8a3228198adb03e6996f7738c361a612777ecab6aaron new->desc_width = base->desc_width;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh new->desc_adjust = base->desc_adjust;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->desc_width = add->desc_width;
e34223f72e630187c4d8ac7c22da5096c833eb20trawick new->desc_adjust = add->desc_adjust;
e34223f72e630187c4d8ac7c22da5096c833eb20trawick }
e34223f72e630187c4d8ac7c22da5096c833eb20trawick
e34223f72e630187c4d8ac7c22da5096c833eb20trawick new->default_keyid = add->default_keyid ? add->default_keyid
e34223f72e630187c4d8ac7c22da5096c833eb20trawick : base->default_keyid;
e34223f72e630187c4d8ac7c22da5096c833eb20trawick new->default_direction = add->default_direction ? add->default_direction
e34223f72e630187c4d8ac7c22da5096c833eb20trawick : base->default_direction;
e34223f72e630187c4d8ac7c22da5096c833eb20trawick return new;
e34223f72e630187c4d8ac7c22da5096c833eb20trawick}
e34223f72e630187c4d8ac7c22da5096c833eb20trawick
e34223f72e630187c4d8ac7c22da5096c833eb20trawick/****************************************************************
e34223f72e630187c4d8ac7c22da5096c833eb20trawick *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Looking things up in config entries...
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
32c4bc04f89b16521718145dc731f750144d7b38wrowe
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* Structure used to hold entries when we're actually building an index */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstruct ent {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *name;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *icon;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm char *alt;
32c4bc04f89b16521718145dc731f750144d7b38wrowe char *desc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_off_t size;
32c4bc04f89b16521718145dc731f750144d7b38wrowe apr_time_t lm;
32c4bc04f89b16521718145dc731f750144d7b38wrowe struct ent *next;
32c4bc04f89b16521718145dc731f750144d7b38wrowe int ascending, ignore_case, version_sort;
32c4bc04f89b16521718145dc731f750144d7b38wrowe char key;
32c4bc04f89b16521718145dc731f750144d7b38wrowe int isdir;
32c4bc04f89b16521718145dc731f750144d7b38wrowe};
e8f95a682820a599fe41b22977010636be5c2717jim
32c4bc04f89b16521718145dc731f750144d7b38wrowestatic char *find_item(const char *content_type, const char *content_encoding,
32c4bc04f89b16521718145dc731f750144d7b38wrowe char *path, apr_array_header_t *list, int path_only)
32c4bc04f89b16521718145dc731f750144d7b38wrowe{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding struct item *items = (struct item *) list->elts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int i;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
8a3228198adb03e6996f7738c361a612777ecab6aaron for (i = 0; i < list->nelts; ++i) {
8a3228198adb03e6996f7738c361a612777ecab6aaron struct item *p = &items[i];
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaron /* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */
8a3228198adb03e6996f7738c361a612777ecab6aaron if ((path[0] == '^') || (!ap_strcmp_match(path, p->apply_path))) {
8a3228198adb03e6996f7738c361a612777ecab6aaron if (!*(p->apply_to)) {
8a3228198adb03e6996f7738c361a612777ecab6aaron return p->data;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick else if (p->type == BY_PATH || path[0] == '^') {
4bb7ba7c1f9972b443562faf99151ccec854446fjorton if (!ap_strcmp_match(path, p->apply_to)) {
4bb7ba7c1f9972b443562faf99151ccec854446fjorton return p->data;
4bb7ba7c1f9972b443562faf99151ccec854446fjorton }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!path_only) {
8a3228198adb03e6996f7738c361a612777ecab6aaron if (!content_encoding) {
8a3228198adb03e6996f7738c361a612777ecab6aaron if (p->type == BY_TYPE) {
8a3228198adb03e6996f7738c361a612777ecab6aaron if (content_type
8a3228198adb03e6996f7738c361a612777ecab6aaron && !ap_strcasecmp_match(content_type,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh p->apply_to)) {
cf5ace98ead10d803fda70674cb4dda30fddb832trawick return p->data;
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick }
2b484455736f4c30447aa852764f53282cbeb5ddrbb }
8a3228198adb03e6996f7738c361a612777ecab6aaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (p->type == BY_ENCODING) {
066877f1a045103acfdd376d48cdd473c33f409bdougm if (!ap_strcasecmp_match(content_encoding,
066877f1a045103acfdd376d48cdd473c33f409bdougm p->apply_to)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return p->data;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick }
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick }
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick }
dc64949d88a97fef0bfcb2eed2115dddafc41666wrowe }
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick return NULL;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick}
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawickstatic char *find_item_by_request(request_rec *r, apr_array_header_t *list, int path_only)
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz{
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick return find_item(ap_field_noparam(r->pool, r->content_type),
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick r->content_encoding, r->filename, list, path_only);
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick}
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick#define find_icon(d,p,t) find_item_by_request(p,d->icon_list,t)
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick#define find_alt(d,p,t) find_item_by_request(p,d->alt_list,t)
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick#define find_default_icon(d,n) find_item(NULL, NULL, n, d->icon_list, 1)
e8f95a682820a599fe41b22977010636be5c2717jim#define find_default_alt(d,n) find_item(NULL, NULL, n, d->alt_list, 1)
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick/*
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick * Look through the list of pattern/description pairs and return the first one
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick * if any) that matches the filename in the request. If multiple patterns
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick * match, only the first one is used; since the order in the array is the
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick * same as the order in which directives were processed, earlier matching
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick * directives will dominate.
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick */
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz#ifdef CASE_BLIND_FILESYSTEM
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz#define MATCH_FLAGS APR_FNM_CASE_BLIND
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz#else
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz#define MATCH_FLAGS 0
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz#endif
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawickstatic char *find_desc(autoindex_config_rec *dcfg, const char *filename_full)
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz{
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz int i;
f2b43354f9ac8496ab7003ae01211af739efba1atrawick ai_desc_t *list = (ai_desc_t *) dcfg->desc_list->elts;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick const char *filename_only;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick const char *filename;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
f2b43354f9ac8496ab7003ae01211af739efba1atrawick /*
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz * If the filename includes a path, extract just the name itself
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz * for the simple matches.
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick */
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick if ((filename_only = ap_strrchr_c(filename_full, '/')) == NULL) {
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick filename_only = filename_full;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick }
8a3228198adb03e6996f7738c361a612777ecab6aaron else {
8a3228198adb03e6996f7738c361a612777ecab6aaron filename_only++;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe for (i = 0; i < dcfg->desc_list->nelts; ++i) {
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet ai_desc_t *tuple = &list[i];
066877f1a045103acfdd376d48cdd473c33f409bdougm int found;
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick
2b484455736f4c30447aa852764f53282cbeb5ddrbb /*
8a3228198adb03e6996f7738c361a612777ecab6aaron * Only use the full-path filename if the pattern contains '/'s.
8f0d7adca1c0719b3b1863fb2b9d333d7822567awrowe */
8f0d7adca1c0719b3b1863fb2b9d333d7822567awrowe filename = (tuple->full_path) ? filename_full : filename_only;
8f0d7adca1c0719b3b1863fb2b9d333d7822567awrowe /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Make the comparison using the cheapest method; only do
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * wildcard checking if we must.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (tuple->wildcards) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding found = (apr_fnmatch(tuple->pattern, filename, MATCH_FLAGS) == 0);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
7646be5b9ab5b098bc81d3a08a47e1931dc87597rbb found = (ap_strstr_c(filename, tuple->pattern) != NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe if (found) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return tuple->description;
f5308a6d396448120986bed14412954788af3e5cjorton }
f5308a6d396448120986bed14412954788af3e5cjorton }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
db2ef76dc744b13b9a9929ebb9e6f94712a81717rbb
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic int ignore_entry(autoindex_config_rec *d, char *path)
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb{
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_array_header_t *list = d->ign_list;
269e0a31aa0f6aafe7292e932a182ccb535e55a9trawick struct item *items = (struct item *) list->elts;
e8f95a682820a599fe41b22977010636be5c2717jim char *tt;
8a3228198adb03e6996f7738c361a612777ecab6aaron int i;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
8a3228198adb03e6996f7738c361a612777ecab6aaron if ((tt = strrchr(path, '/')) == NULL) {
76185d819b745e953dd2cd636fbdd515c333e4a4trawick tt = path;
76185d819b745e953dd2cd636fbdd515c333e4a4trawick }
76185d819b745e953dd2cd636fbdd515c333e4a4trawick else {
76185d819b745e953dd2cd636fbdd515c333e4a4trawick tt++;
e4c4fcc82268e0192db234c74a6db784b879fffdrbb }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick for (i = 0; i < list->nelts; ++i) {
8a3228198adb03e6996f7738c361a612777ecab6aaron struct item *p = &items[i];
8a3228198adb03e6996f7738c361a612777ecab6aaron char *ap;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if ((ap = strrchr(p->apply_to, '/')) == NULL) {
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb ap = p->apply_to;
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb }
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb else {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap++;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
db2ef76dc744b13b9a9929ebb9e6f94712a81717rbb
76185d819b745e953dd2cd636fbdd515c333e4a4trawick#ifndef CASE_BLIND_FILESYSTEM
76185d819b745e953dd2cd636fbdd515c333e4a4trawick if (!ap_strcmp_match(path, p->apply_path)
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh && !ap_strcmp_match(tt, ap)) {
76185d819b745e953dd2cd636fbdd515c333e4a4trawick return 1;
20c85ca0d404e29972fb94c3d6236a264d1c77abstoddard }
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton#else /* !CASE_BLIND_FILESYSTEM */
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton /*
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton * On some platforms, the match must be case-blind. This is really
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton * a factor of the filesystem involved, but we can't detect that
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton * reliably - so we have to granularise at the OS level.
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh */
8a3228198adb03e6996f7738c361a612777ecab6aaron if (!ap_strcasecmp_match(path, p->apply_path)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick && !ap_strcasecmp_match(tt, ap)) {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb return 1;
76185d819b745e953dd2cd636fbdd515c333e4a4trawick }
76185d819b745e953dd2cd636fbdd515c333e4a4trawick#endif /* !CASE_BLIND_FILESYSTEM */
76185d819b745e953dd2cd636fbdd515c333e4a4trawick }
76185d819b745e953dd2cd636fbdd515c333e4a4trawick return 0;
76185d819b745e953dd2cd636fbdd515c333e4a4trawick}
76185d819b745e953dd2cd636fbdd515c333e4a4trawick
76185d819b745e953dd2cd636fbdd515c333e4a4trawick/*****************************************************************
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * Actually generating output
f5308a6d396448120986bed14412954788af3e5cjorton */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Elements of the emitted document:
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe * Preamble
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * succeeds for the (content_type == text/html) header file.
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * Header file
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * Emitted if found (and able).
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * H1 tag line
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Emitted if a header file is NOT emitted.
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb * Directory stuff
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb * Always emitted.
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * HR
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * Emitted if FANCY_INDEXING is set.
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * Readme file
8a3228198adb03e6996f7738c361a612777ecab6aaron * Emitted if found (and able).
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * ServerSig
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * Emitted if ServerSignature is not Off AND a readme file
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * is NOT emitted.
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * Postamble
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * succeeds for the (content_type == text/html) readme file.
8a3228198adb03e6996f7738c361a612777ecab6aaron */
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick/*
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * emit a plain text file
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick */
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawickstatic void do_emit_plain(request_rec *r, apr_file_t *f)
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick{
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick char buf[AP_IOBUFSIZE + 1];
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick int ch;
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick apr_size_t i, c, n;
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick apr_status_t rv;
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick
8a3228198adb03e6996f7738c361a612777ecab6aaron ap_rputs("<pre>\n", r);
8a3228198adb03e6996f7738c361a612777ecab6aaron while (!apr_file_eof(f)) {
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh do {
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb n = sizeof(char) * AP_IOBUFSIZE;
ffb048955d9939c0ab6ff99c2efc412d8e7a191dwrowe rv = apr_file_read(f, buf, &n);
ffb048955d9939c0ab6ff99c2efc412d8e7a191dwrowe } while (APR_STATUS_IS_EINTR(rv));
8a3228198adb03e6996f7738c361a612777ecab6aaron if (n == 0 || rv != APR_SUCCESS) {
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh /* ###: better error here? */
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb break;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron buf[n] = '\0';
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick c = 0;
8a3228198adb03e6996f7738c361a612777ecab6aaron while (c < n) {
8a3228198adb03e6996f7738c361a612777ecab6aaron for (i = c; i < n; i++) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (buf[i] == '<' || buf[i] == '>' || buf[i] == '&') {
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb break;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ch = buf[i];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding buf[i] = '\0';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs(&buf[c], r);
c54189c4d2d06d8b374940b32acf20287effff07wrowe if (ch == '<') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs("&lt;", r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (ch == '>') {
066877f1a045103acfdd376d48cdd473c33f409bdougm ap_rputs("&gt;", r);
066877f1a045103acfdd376d48cdd473c33f409bdougm }
2a7d0035b5594ddc0907a9cc545e14ae5140c541manoj else if (ch == '&') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs("&amp;", r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding c = i + 1;
c54189c4d2d06d8b374940b32acf20287effff07wrowe }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs("</pre>\n", r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
c54189c4d2d06d8b374940b32acf20287effff07wrowe
c54189c4d2d06d8b374940b32acf20287effff07wrowe/*
c54189c4d2d06d8b374940b32acf20287effff07wrowe * Handle the preamble through the H1 tag line, inclusive. Locate
c54189c4d2d06d8b374940b32acf20287effff07wrowe * the file with a subrequests. Process text/html documents by actually
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * running the subrequest; text/xxx documents get copied verbatim,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * and any other content type is ignored. This means that a non-text
c54189c4d2d06d8b374940b32acf20287effff07wrowe * document (such as HEADER.gif) might get multiviewed as the result
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * instead of a text document, meaning nothing will be displayed, but
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * oh well.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void emit_head(request_rec *r, char *header_fname, int suppress_amble,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm int emit_xhtml, char *title)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm autoindex_config_rec *d;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb apr_table_t *hdrs = r->headers_in;
52bdaf788c70b03fe6f68a5a489cdbe11fb184efwrowe apr_file_t *f = NULL;
52bdaf788c70b03fe6f68a5a489cdbe11fb184efwrowe request_rec *rr = NULL;
52bdaf788c70b03fe6f68a5a489cdbe11fb184efwrowe int emit_amble = 1;
8a3228198adb03e6996f7738c361a612777ecab6aaron int emit_H1 = 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *r_accept;
8a3228198adb03e6996f7738c361a612777ecab6aaron const char *r_accept_enc;
8a3228198adb03e6996f7738c361a612777ecab6aaron
f5308a6d396448120986bed14412954788af3e5cjorton /*
8a3228198adb03e6996f7738c361a612777ecab6aaron * If there's a header file, send a subrequest to look for it. If it's
8a3228198adb03e6996f7738c361a612777ecab6aaron * found and html do the subrequest, otherwise handle it
8a3228198adb03e6996f7738c361a612777ecab6aaron */
8a3228198adb03e6996f7738c361a612777ecab6aaron r_accept = apr_table_get(hdrs, "Accept");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r_accept_enc = apr_table_get(hdrs, "Accept-Encoding");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_table_setn(hdrs, "Accept", "text/html, text/plain");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_table_unset(hdrs, "Accept-Encoding");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
cddad5fd27fd3b9f4375d76d04bbbeaebec00548wrowe
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb if ((header_fname != NULL) && r->args) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm header_fname = apr_pstrcat(r->pool, header_fname, "?", r->args, NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb if ((header_fname != NULL)
066877f1a045103acfdd376d48cdd473c33f409bdougm && (rr = ap_sub_req_lookup_uri(header_fname, r, r->output_filters))
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb && (rr->status == HTTP_OK)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && (rr->filename != NULL)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && (rr->finfo.filetype == APR_REG)) {
3d96ee83babeec32482c9082c9426340cee8c44dwrowe /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Check for the two specific cases we allow: text/html and
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * text/anything-else. The former is allowed to be processed for
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * SSIs.
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (rr->content_type != NULL) {
399cf0e5e061b49593817421b94305889fa6bc1fjorton if (response_is_html(rr)) {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb ap_filter_t *f;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh /* Hope everything will work... */
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick emit_amble = 0;
85c435ceda98eab940615e4466d9c5955252e745wrowe emit_H1 = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (! suppress_amble) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm emit_preamble(r, emit_xhtml, title);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb /* This is a hack, but I can't find any better way to do this.
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb * The problem is that we have already created the sub-request,
066877f1a045103acfdd376d48cdd473c33f409bdougm * but we just inserted the OLD_WRITE filter, and the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * sub-request needs to pass its data through the OLD_WRITE
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * filter, or things go horribly wrong (missing data, data in
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the wrong order, etc). To fix it, if you create a
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * sub-request and then insert the OLD_WRITE filter before you
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb * run the request, you need to make sure that the sub-request
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * data goes through the OLD_WRITE filter. Just steal this
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * code. The long-term solution is to remove the ap_r*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * functions.
066877f1a045103acfdd376d48cdd473c33f409bdougm */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (f=rr->output_filters;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb f->frec != ap_subreq_core_filter_handle; f = f->next);
a7318397b355119d990d1f311b951dea2aafc53arbb f->next = r->output_filters;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh /*
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * If there's a problem running the subrequest, display the
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * preamble if we didn't do it before -- the header file
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * didn't get displayed.
a7318397b355119d990d1f311b951dea2aafc53arbb */
if (ap_run_sub_req(rr) != OK) {
/* It didn't work */
emit_amble = suppress_amble;
emit_H1 = 1;
}
}
else if (!strncasecmp("text/", rr->content_type, 5)) {
/*
* If we can open the file, prefix it with the preamble
* regardless; since we'll be sending a <pre> block around
* the file's contents, any HTML header it had won't end up
* where it belongs.
*/
if (apr_file_open(&f, rr->filename, APR_READ,
APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
emit_preamble(r, emit_xhtml, title);
emit_amble = 0;
do_emit_plain(r, f);
apr_file_close(f);
emit_H1 = 0;
}
}
}
}
if (r_accept) {
apr_table_setn(hdrs, "Accept", r_accept);
}
else {
apr_table_unset(hdrs, "Accept");
}
if (r_accept_enc) {
apr_table_setn(hdrs, "Accept-Encoding", r_accept_enc);
}
if (emit_amble) {
emit_preamble(r, emit_xhtml, title);
}
d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config, &autoindex_module);
if (emit_H1) {
if (d->style_sheet != NULL) {
/* Insert style id if stylesheet used */
ap_rvputs(r, " <h1 id=\"indextitle\">Index of ", title, "</h1>\n", NULL);
} else {
ap_rvputs(r, "<h1>Index of ", title, "</h1>\n", NULL);
}
}
if (rr != NULL) {
ap_destroy_sub_req(rr);
}
}
/*
* Handle the Readme file through the postamble, inclusive. Locate
* the file with a subrequests. Process text/html documents by actually
* running the subrequest; text/xxx documents get copied verbatim,
* and any other content type is ignored. This means that a non-text
* document (such as FOOTER.gif) might get multiviewed as the result
* instead of a text document, meaning nothing will be displayed, but
* oh well.
*/
static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
{
apr_file_t *f = NULL;
request_rec *rr = NULL;
int suppress_post = 0;
int suppress_sig = 0;
/*
* If there's a readme file, send a subrequest to look for it. If it's
* found and a text file, handle it -- otherwise fall through and
* pretend there's nothing there.
*/
if ((readme_fname != NULL)
&& (rr = ap_sub_req_lookup_uri(readme_fname, r, r->output_filters))
&& (rr->status == HTTP_OK)
&& (rr->filename != NULL)
&& rr->finfo.filetype == APR_REG) {
/*
* Check for the two specific cases we allow: text/html and
* text/anything-else. The former is allowed to be processed for
* SSIs.
*/
if (rr->content_type != NULL) {
if (response_is_html(rr)) {
ap_filter_t *f;
for (f=rr->output_filters;
f->frec != ap_subreq_core_filter_handle; f = f->next);
f->next = r->output_filters;
if (ap_run_sub_req(rr) == OK) {
/* worked... */
suppress_sig = 1;
suppress_post = suppress_amble;
}
}
else if (!strncasecmp("text/", rr->content_type, 5)) {
/*
* If we can open the file, suppress the signature.
*/
if (apr_file_open(&f, rr->filename, APR_READ,
APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
do_emit_plain(r, f);
apr_file_close(f);
suppress_sig = 1;
}
}
}
}
if (!suppress_sig) {
ap_rputs(ap_psignature("", r), r);
}
if (!suppress_post) {
ap_rputs("</body></html>\n", r);
}
if (rr != NULL) {
ap_destroy_sub_req(rr);
}
}
static char *find_title(request_rec *r)
{
char titlebuf[MAX_STRING_LEN], *find = "<title>";
apr_file_t *thefile = NULL;
int x, y, p;
apr_size_t n;
if (r->status != HTTP_OK) {
return NULL;
}
if ((r->content_type != NULL)
&& (response_is_html(r)
|| !strcmp(r->content_type, INCLUDES_MAGIC_TYPE))
&& !r->content_encoding) {
if (apr_file_open(&thefile, r->filename, APR_READ,
APR_OS_DEFAULT, r->pool) != APR_SUCCESS) {
return NULL;
}
n = sizeof(char) * (MAX_STRING_LEN - 1);
apr_file_read(thefile, titlebuf, &n);
if (n == 0) {
apr_file_close(thefile);
return NULL;
}
titlebuf[n] = '\0';
for (x = 0, p = 0; titlebuf[x]; x++) {
if (apr_tolower(titlebuf[x]) == find[p]) {
if (!find[++p]) {
if ((p = ap_ind(&titlebuf[++x], '<')) != -1) {
titlebuf[x + p] = '\0';
}
/* Scan for line breaks for Tanmoy's secretary */
for (y = x; titlebuf[y]; y++) {
if ((titlebuf[y] == CR) || (titlebuf[y] == LF)) {
if (y == x) {
x++;
}
else {
titlebuf[y] = ' ';
}
}
}
apr_file_close(thefile);
return apr_pstrdup(r->pool, &titlebuf[x]);
}
}
else {
p = 0;
}
}
apr_file_close(thefile);
}
return NULL;
}
static struct ent *make_parent_entry(apr_int32_t autoindex_opts,
autoindex_config_rec *d,
request_rec *r, char keyid,
char direction)
{
struct ent *p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent));
char *testpath;
/*
* p->name is now the true parent URI.
* testpath is a crafted lie, so that the syntax '/some/..'
* (or simply '..')be used to describe 'up' from '/some/'
* when processeing IndexIgnore, and Icon|Alt|Desc configs.
*/
/* The output has always been to the parent. Don't make ourself
* our own parent (worthless cyclical reference).
*/
if (!(p->name = ap_make_full_path(r->pool, r->uri, "../"))) {
return (NULL);
}
ap_getparents(p->name);
if (!*p->name) {
return (NULL);
}
/* IndexIgnore has always compared "/thispath/.." */
testpath = ap_make_full_path(r->pool, r->filename, "..");
if (ignore_entry(d, testpath)) {
return (NULL);
}
p->size = -1;
p->lm = -1;
p->key = apr_toupper(keyid);
p->ascending = (apr_toupper(direction) == D_ASCENDING);
p->version_sort = autoindex_opts & VERSION_SORT;
if (autoindex_opts & FANCY_INDEXING) {
if (!(p->icon = find_default_icon(d, testpath))) {
p->icon = find_default_icon(d, "^^DIRECTORY^^");
}
if (!(p->alt = find_default_alt(d, testpath))) {
if (!(p->alt = find_default_alt(d, "^^DIRECTORY^^"))) {
/* Special alt text for parent dir to distinguish it from other directories
this is essential when trying to style this dir entry via AddAltClass */
p->alt = "PARENTDIR";
}
}
p->desc = find_desc(d, testpath);
}
return p;
}
static struct ent *make_autoindex_entry(const apr_finfo_t *dirent,
int autoindex_opts,
autoindex_config_rec *d,
request_rec *r, char keyid,
char direction,
const char *pattern)
{
request_rec *rr;
struct ent *p;
int show_forbidden = 0;
/* Dot is ignored, Parent is handled by make_parent_entry() */
if ((dirent->name[0] == '.') && (!dirent->name[1]
|| ((dirent->name[1] == '.') && !dirent->name[2])))
return (NULL);
/*
* On some platforms, the match must be case-blind. This is really
* a factor of the filesystem involved, but we can't detect that
* reliably - so we have to granularise at the OS level.
*/
if (pattern && (apr_fnmatch(pattern, dirent->name,
APR_FNM_NOESCAPE | APR_FNM_PERIOD
#ifdef CASE_BLIND_FILESYSTEM
| APR_FNM_CASE_BLIND
#endif
)
!= APR_SUCCESS)) {
return (NULL);
}
if (ignore_entry(d, ap_make_full_path(r->pool,
r->filename, dirent->name))) {
return (NULL);
}
if (!(rr = ap_sub_req_lookup_dirent(dirent, r, AP_SUBREQ_NO_ARGS, NULL))) {
return (NULL);
}
if((autoindex_opts & SHOW_FORBIDDEN)
&& (rr->status == HTTP_UNAUTHORIZED || rr->status == HTTP_FORBIDDEN)) {
show_forbidden = 1;
}
if ((rr->finfo.filetype != APR_DIR && rr->finfo.filetype != APR_REG)
|| !(rr->status == OK || ap_is_HTTP_SUCCESS(rr->status)
|| ap_is_HTTP_REDIRECT(rr->status)
|| show_forbidden == 1)) {
ap_destroy_sub_req(rr);
return (NULL);
}
p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent));
if (dirent->filetype == APR_DIR) {
p->name = apr_pstrcat(r->pool, dirent->name, "/", NULL);
}
else {
p->name = apr_pstrdup(r->pool, dirent->name);
}
p->size = -1;
p->icon = NULL;
p->alt = NULL;
p->desc = NULL;
p->lm = -1;
p->isdir = 0;
p->key = apr_toupper(keyid);
p->ascending = (apr_toupper(direction) == D_ASCENDING);
p->version_sort = !!(autoindex_opts & VERSION_SORT);
p->ignore_case = !!(autoindex_opts & IGNORE_CASE);
if (autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING)) {
p->lm = rr->finfo.mtime;
if (dirent->filetype == APR_DIR) {
if (autoindex_opts & FOLDERS_FIRST) {
p->isdir = 1;
}
rr->filename = ap_make_dirstr_parent (rr->pool, rr->filename);
/* omit the trailing slash (1.3 compat) */
rr->filename[strlen(rr->filename) - 1] = '\0';
if (!(p->icon = find_icon(d, rr, 1))) {
p->icon = find_default_icon(d, "^^DIRECTORY^^");
}
if (!(p->alt = find_alt(d, rr, 1))) {
if (!(p->alt = find_default_alt(d, "^^DIRECTORY^^"))) {
p->alt = "DIR";
}
}
}
else {
p->icon = find_icon(d, rr, 0);
p->alt = find_alt(d, rr, 0);
p->size = rr->finfo.size;
}
p->desc = find_desc(d, rr->filename);
if ((!p->desc) && (autoindex_opts & SCAN_HTML_TITLES)) {
p->desc = apr_pstrdup(r->pool, find_title(rr));
}
}
ap_destroy_sub_req(rr);
/*
* We don't need to take any special action for the file size key.
* If we did, it would go here.
*/
if (keyid == K_LAST_MOD) {
if (p->lm < 0) {
p->lm = 0;
}
}
return (p);
}
static char *terminate_description(autoindex_config_rec *d, char *desc,
apr_int32_t autoindex_opts, int desc_width)
{
int maxsize = desc_width;
register int x;
/*
* If there's no DescriptionWidth in effect, default to the old
* behaviour of adjusting the description size depending upon
* what else is being displayed. Otherwise, stick with the
* setting.
*/
if (d->desc_adjust == K_UNSET) {
if (autoindex_opts & SUPPRESS_ICON) {
maxsize += 6;
}
if (autoindex_opts & SUPPRESS_LAST_MOD) {
maxsize += 19;
}
if (autoindex_opts & SUPPRESS_SIZE) {
maxsize += 7;
}
}
for (x = 0; desc[x] && ((maxsize > 0) || (desc[x] == '<')); x++) {
if (desc[x] == '<') {
while (desc[x] != '>') {
if (!desc[x]) {
maxsize = 0;
break;
}
++x;
}
}
else if (desc[x] == '&') {
/* entities like &auml; count as one character */
--maxsize;
for ( ; desc[x] != ';'; ++x) {
if (desc[x] == '\0') {
maxsize = 0;
break;
}
}
}
else {
--maxsize;
}
}
if (!maxsize && desc[x] != '\0') {
desc[x - 1] = '>'; /* Grump. */
desc[x] = '\0'; /* Double Grump! */
}
return desc;
}
/*
* Emit the anchor for the specified field. If a field is the key for the
* current request, the link changes its meaning to reverse the order when
* selected again. Non-active fields always start in ascending order.
*/
static void emit_link(request_rec *r, const char *anchor, char column,
char curkey, char curdirection,
const char *colargs, int nosort)
{
if (!nosort) {
char qvalue[9];
qvalue[0] = '?';
qvalue[1] = 'C';
qvalue[2] = '=';
qvalue[3] = column;
qvalue[4] = ';';
qvalue[5] = 'O';
qvalue[6] = '=';
/* reverse? */
qvalue[7] = ((curkey == column) && (curdirection == D_ASCENDING))
? D_DESCENDING : D_ASCENDING;
qvalue[8] = '\0';
ap_rvputs(r, "<a href=\"", qvalue, colargs ? colargs : "",
"\">", anchor, "</a>", NULL);
}
else {
ap_rputs(anchor, r);
}
}
static void output_directories(struct ent **ar, int n,
autoindex_config_rec *d, request_rec *r,
apr_int32_t autoindex_opts, char keyid,
char direction, const char *colargs)
{
int x;
apr_size_t rv;
char *tp;
int static_columns = !!(autoindex_opts & SUPPRESS_COLSORT);
apr_pool_t *scratch;
int name_width;
int desc_width;
char *name_scratch;
char *pad_scratch;
char *breakrow = "";
apr_pool_create(&scratch, r->pool);
name_width = d->name_width;
desc_width = d->desc_width;
if ((autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING))
== FANCY_INDEXING) {
if (d->name_adjust == K_ADJUST) {
for (x = 0; x < n; x++) {
int t = strlen(ar[x]->name);
if (t > name_width) {
name_width = t;
}
}
}
if (d->desc_adjust == K_ADJUST) {
for (x = 0; x < n; x++) {
if (ar[x]->desc != NULL) {
int t = strlen(ar[x]->desc);
if (t > desc_width) {
desc_width = t;
}
}
}
}
}
name_scratch = apr_palloc(r->pool, name_width + 1);
pad_scratch = apr_palloc(r->pool, name_width + 1);
memset(pad_scratch, ' ', name_width);
pad_scratch[name_width] = '\0';
if (autoindex_opts & TABLE_INDEXING) {
int cols = 1;
if (d->style_sheet != NULL) {
/* Emit table with style id */
ap_rputs(" <table id=\"indexlist\">\n <tr class=\"indexhead\">", r);
} else {
ap_rputs(" <table>\n <tr>", r);
}
if (!(autoindex_opts & SUPPRESS_ICON)) {
ap_rvputs(r, "<th", (d->style_sheet != NULL) ? " class=\"indexcolicon\">" : " valign=\"top\">", NULL);
if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
ap_rvputs(r, "<img src=\"", ap_escape_html(scratch, tp),
"\" alt=\"[ICO]\"", NULL);
if (d->icon_width) {
ap_rprintf(r, " width=\"%d\"", d->icon_width);
}
if (d->icon_height) {
ap_rprintf(r, " height=\"%d\"", d->icon_height);
}
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs("></th>", r);
}
else {
ap_rputs("&nbsp;</th>", r);
}
++cols;
}
ap_rvputs(r, "<th", (d->style_sheet != NULL) ? " class=\"indexcolname\">" : ">", NULL);
emit_link(r, "Name", K_NAME, keyid, direction,
colargs, static_columns);
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
ap_rvputs(r, "</th><th", (d->style_sheet != NULL) ? " class=\"indexcollastmod\">" : ">", NULL);
emit_link(r, "Last modified", K_LAST_MOD, keyid, direction,
colargs, static_columns);
++cols;
}
if (!(autoindex_opts & SUPPRESS_SIZE)) {
ap_rvputs(r, "</th><th", (d->style_sheet != NULL) ? " class=\"indexcolsize\">" : ">", NULL);
emit_link(r, "Size", K_SIZE, keyid, direction,
colargs, static_columns);
++cols;
}
if (!(autoindex_opts & SUPPRESS_DESC)) {
ap_rvputs(r, "</th><th", (d->style_sheet != NULL) ? " class=\"indexcoldesc\">" : ">", NULL);
emit_link(r, "Description", K_DESC, keyid, direction,
colargs, static_columns);
++cols;
}
if (!(autoindex_opts & SUPPRESS_RULES)) {
breakrow = apr_psprintf(r->pool,
" <tr%s><th colspan=\"%d\">"
"<hr%s></th></tr>\n",
(d->style_sheet != NULL) ? " class=\"indexbreakrow\"" : "",
cols,
(autoindex_opts & EMIT_XHTML) ? " /" : "");
}
ap_rvputs(r, "</th></tr>\n", breakrow, NULL);
}
else if (autoindex_opts & FANCY_INDEXING) {
ap_rputs("<pre>", r);
if (!(autoindex_opts & SUPPRESS_ICON)) {
if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
ap_rvputs(r, "<img src=\"", ap_escape_html(scratch, tp),
"\" alt=\"Icon \"", NULL);
if (d->icon_width) {
ap_rprintf(r, " width=\"%d\"", d->icon_width);
}
if (d->icon_height) {
ap_rprintf(r, " height=\"%d\"", d->icon_height);
}
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs("> ", r);
}
else {
ap_rputs(" ", r);
}
}
emit_link(r, "Name", K_NAME, keyid, direction,
colargs, static_columns);
ap_rputs(pad_scratch + 4, r);
/*
* Emit the guaranteed-at-least-one-space-between-columns byte.
*/
ap_rputs(" ", r);
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
emit_link(r, "Last modified", K_LAST_MOD, keyid, direction,
colargs, static_columns);
ap_rputs(" ", r);
}
if (!(autoindex_opts & SUPPRESS_SIZE)) {
emit_link(r, "Size", K_SIZE, keyid, direction,
colargs, static_columns);
ap_rputs(" ", r);
}
if (!(autoindex_opts & SUPPRESS_DESC)) {
emit_link(r, "Description", K_DESC, keyid, direction,
colargs, static_columns);
}
if (!(autoindex_opts & SUPPRESS_RULES)) {
ap_rputs("<hr", r);
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs(">", r);
}
else {
ap_rputc('\n', r);
}
}
else {
ap_rputs("<ul>", r);
}
for (x = 0; x < n; x++) {
char *anchor, *t, *t2;
int nwidth;
apr_pool_clear(scratch);
t = ar[x]->name;
anchor = ap_escape_html(scratch, ap_os_escape_path(scratch, t, 0));
if (!x && t[0] == '/') {
t2 = "Parent Directory";
}
else {
t2 = t;
}
if (autoindex_opts & TABLE_INDEXING) {
/* Even/Odd rows for IndexStyleSheet */
if (d->style_sheet != NULL) {
if (ar[x]->alt && (autoindex_opts & ADDALTCLASS)) {
/* Include alt text in class name, distinguish between odd and even rows */
char *altclass = apr_pstrdup(scratch, ar[x]->alt);
ap_str_tolower(altclass);
ap_rvputs(r, " <tr class=\"", ( x & 0x1) ? "odd-" : "even-", altclass, "\">", NULL);
} else {
/* Distinguish between odd and even rows */
ap_rvputs(r, " <tr class=\"", ( x & 0x1) ? "odd" : "even", "\">", NULL);
}
} else {
ap_rputs("<tr>", r);
}
if (!(autoindex_opts & SUPPRESS_ICON)) {
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcolicon\">" : " valign=\"top\">", NULL);
if (autoindex_opts & ICONS_ARE_LINKS) {
ap_rvputs(r, "<a href=\"", anchor, "\">", NULL);
}
if ((ar[x]->icon) || d->default_icon) {
ap_rvputs(r, "<img src=\"",
ap_escape_html(scratch,
ar[x]->icon ? ar[x]->icon
: d->default_icon),
"\" alt=\"[", (ar[x]->alt ? ar[x]->alt : " "),
"]\"", NULL);
if (d->icon_width) {
ap_rprintf(r, " width=\"%d\"", d->icon_width);
}
if (d->icon_height) {
ap_rprintf(r, " height=\"%d\"", d->icon_height);
}
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs(">", r);
}
else {
ap_rputs("&nbsp;", r);
}
if (autoindex_opts & ICONS_ARE_LINKS) {
ap_rputs("</a></td>", r);
}
else {
ap_rputs("</td>", r);
}
}
if (d->name_adjust == K_ADJUST) {
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcolname\">" : ">", "<a href=\"", anchor, "\">",
ap_escape_html(scratch, t2), "</a>", NULL);
}
else {
nwidth = strlen(t2);
if (nwidth > name_width) {
memcpy(name_scratch, t2, name_width - 3);
name_scratch[name_width - 3] = '.';
name_scratch[name_width - 2] = '.';
name_scratch[name_width - 1] = '>';
name_scratch[name_width] = 0;
t2 = name_scratch;
nwidth = name_width;
}
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcolname\">" : ">", "<a href=\"", anchor, "\">",
ap_escape_html(scratch, t2),
"</a>", pad_scratch + nwidth, NULL);
}
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
if (ar[x]->lm != -1) {
char time_str[MAX_STRING_LEN];
apr_time_exp_t ts;
apr_time_exp_lt(&ts, ar[x]->lm);
apr_strftime(time_str, &rv, MAX_STRING_LEN,
"%Y-%m-%d %H:%M ",
&ts);
ap_rvputs(r, "</td><td", (d->style_sheet != NULL) ? " class=\"indexcollastmod\">" : " align=\"right\">",time_str, NULL);
}
else {
ap_rvputs(r, "</td><td", (d->style_sheet != NULL) ? " class=\"indexcollastmod\">&nbsp;" : ">&nbsp;", NULL);
}
}
if (!(autoindex_opts & SUPPRESS_SIZE)) {
char buf[5];
ap_rvputs(r, "</td><td", (d->style_sheet != NULL) ? " class=\"indexcolsize\">" : " align=\"right\">",
apr_strfsize(ar[x]->size, buf), NULL);
}
if (!(autoindex_opts & SUPPRESS_DESC)) {
if (ar[x]->desc) {
if (d->desc_adjust == K_ADJUST) {
ap_rvputs(r, "</td><td", (d->style_sheet != NULL) ? " class=\"indexcoldesc\">" : ">", ar[x]->desc, NULL);
}
else {
ap_rvputs(r, "</td><td", (d->style_sheet != NULL) ? " class=\"indexcoldesc\">" : ">",
terminate_description(d, ar[x]->desc,
autoindex_opts,
desc_width), NULL);
}
}
else {
ap_rputs("</td><td>&nbsp;", r);
}
}
ap_rputs("</td></tr>\n", r);
}
else if (autoindex_opts & FANCY_INDEXING) {
if (!(autoindex_opts & SUPPRESS_ICON)) {
if (autoindex_opts & ICONS_ARE_LINKS) {
ap_rvputs(r, "<a href=\"", anchor, "\">", NULL);
}
if ((ar[x]->icon) || d->default_icon) {
ap_rvputs(r, "<img src=\"",
ap_escape_html(scratch,
ar[x]->icon ? ar[x]->icon
: d->default_icon),
"\" alt=\"[", (ar[x]->alt ? ar[x]->alt : " "),
"]\"", NULL);
if (d->icon_width) {
ap_rprintf(r, " width=\"%d\"", d->icon_width);
}
if (d->icon_height) {
ap_rprintf(r, " height=\"%d\"", d->icon_height);
}
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs(">", r);
}
else {
ap_rputs(" ", r);
}
if (autoindex_opts & ICONS_ARE_LINKS) {
ap_rputs("</a> ", r);
}
else {
ap_rputc(' ', r);
}
}
nwidth = strlen(t2);
if (nwidth > name_width) {
memcpy(name_scratch, t2, name_width - 3);
name_scratch[name_width - 3] = '.';
name_scratch[name_width - 2] = '.';
name_scratch[name_width - 1] = '>';
name_scratch[name_width] = 0;
t2 = name_scratch;
nwidth = name_width;
}
ap_rvputs(r, "<a href=\"", anchor, "\">",
ap_escape_html(scratch, t2),
"</a>", pad_scratch + nwidth, NULL);
/*
* The blank before the storm.. er, before the next field.
*/
ap_rputs(" ", r);
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
if (ar[x]->lm != -1) {
char time_str[32];
apr_time_exp_t ts;
apr_time_exp_lt(&ts, ar[x]->lm);
apr_strftime(time_str, &rv, sizeof(time_str),
"%Y-%m-%d %H:%M ", &ts);
ap_rputs(time_str, r);
}
else {
/*Length="1975-04-07 01:23 " (see 4 lines above) */
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, "\"> ",
ap_escape_html(scratch, 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", r);
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs("></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;
}
/* names may identical when treated case-insensitively,
* so always fall back on strcmp() flavors to put entries
* in deterministic order. This means that 'ABC' and 'abc'
* will always appear in the same order, rather than
* variably between 'ABC abc' and 'abc ABC' order.
*/
if (c1->version_sort) {
if (c1->ignore_case) {
result = apr_strnatcasecmp (c1->name, c2->name);
}
if (!result) {
result = apr_strnatcmp(c1->name, c2->name);
}
}
/* The names may be identical in respects other other than
* filename case when strnatcmp is used above, so fall back
* to strcmp on conflicts so that fn1.01.zzz and fn1.1.zzz
* are also sorted in a deterministic order.
*/
if (!result && c1->ignore_case) {
result = strcasecmp (c1->name, c2->name);
}
if (!result) {
result = strcmp (c1->name, c2->name);
}
return result;
}
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;
char *ctype = "text/html";
char *charset;
if ((status = apr_dir_open(&thedir, name, r->pool)) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(01275)
"Can't open directory for index: %s", r->filename);
return HTTP_FORBIDDEN;
}
if (autoindex_conf->ctype) {
ctype = autoindex_conf->ctype;
}
if (autoindex_conf->charset) {
charset = autoindex_conf->charset;
}
else {
#if APR_HAS_UNICODE_FS
charset = "UTF-8";
#else
charset = "ISO-8859-1";
#endif
}
if (*charset) {
ap_set_content_type(r, apr_pstrcat(r->pool, ctype, ";charset=",
charset, NULL));
}
else {
ap_set_content_type(r, ctype);
}
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 = "", *epattern = "";
fval[0] = '\0'; vval[0] = '\0';
qstring = r->args;
while (qstring && *qstring) {
/* C= First Sort key Column (N, M, S, D) */
if ( qstring[0] == 'C' && qstring[1] == '='
&& qstring[2] && strchr(K_VALID, qstring[2])
&& ( qstring[3] == '&' || qstring[3] == ';'
|| !qstring[3])) {
keyid = qstring[2];
qstring += qstring[3] ? 4 : 3;
}
/* O= Sort order (A, D) */
else if ( qstring[0] == 'O' && qstring[1] == '='
&& ( (qstring[2] == D_ASCENDING)
|| (qstring[2] == D_DESCENDING))
&& ( qstring[3] == '&' || qstring[3] == ';'
|| !qstring[3])) {
direction = qstring[2];
qstring += qstring[3] ? 4 : 3;
}
/* F= Output Format (0 plain, 1 fancy (pre), 2 table) */
else if ( qstring[0] == 'F' && qstring[1] == '='
&& qstring[2] && strchr("012", qstring[2])
&& ( qstring[3] == '&' || 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;
}
/* V= Version sort (0, 1) */
else if ( qstring[0] == 'V' && qstring[1] == '='
&& (qstring[2] == '0' || qstring[2] == '1')
&& ( qstring[3] == '&' || qstring[3] == ';'
|| !qstring[3])) {
if (qstring[2] == '0') {
autoindex_opts &= ~VERSION_SORT;
}
else if (qstring[2] == '1') {
autoindex_opts |= VERSION_SORT;
}
strcpy(vval, ";V= ");
vval[3] = qstring[2];
qstring += qstring[3] ? 4 : 3;
}
/* P= wildcard pattern (*.foo) */
else if (qstring[0] == 'P' && qstring[1] == '=') {
const char *eos = qstring += 2; /* for efficiency */
while (*eos && *eos != '&' && *eos != ';') {
++eos;
}
if (eos == qstring) {
pstring = NULL;
}
else {
pstring = apr_pstrndup(r->pool, qstring, eos - qstring);
if (ap_unescape_url(pstring) != OK) {
/* ignore the pattern, if it's bad. */
pstring = NULL;
}
else {
ppre = ";P=";
/* be correct */
epattern = ap_escape_uri(r->pool, pstring);
}
}
if (*eos && *++eos) {
qstring = eos;
}
else {
qstring = NULL;
}
}
/* Syntax error? Ignore the remainder! */
else {
qstring = NULL;
}
}
colargs = apr_pstrcat(r->pool, fval, vval, ppre, epattern, 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, autoindex_conf->header,
autoindex_opts & SUPPRESS_PREAMBLE,
autoindex_opts & EMIT_XHTML, 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);
do {
status = apr_dir_read(&dirent, APR_FINFO_MIN | APR_FINFO_NAME, thedir);
if (APR_STATUS_IS_INCOMPLETE(status)) {
continue; /* ignore un-stat()able files */
}
else if (status != APR_SUCCESS) {
break;
}
/* 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++;
}
} while (1);
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, autoindex_conf->readme,
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) {
int errstatus;
if ((errstatus = ap_discard_request_body(r)) != OK) {
return errstatus;
}
/* 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 {
const char *index_names = apr_table_get(r->notes, "dir-index-names");
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01276)
"Cannot serve directory %s: No matching DirectoryIndex (%s) found, and "
"server-generated directory index forbidden by "
"Options directive",
r->filename,
index_names ? index_names : "none");
return HTTP_FORBIDDEN;
}
}
static void register_hooks(apr_pool_t *p)
{
ap_hook_handler(handle_autoindex,NULL,NULL,APR_HOOK_MIDDLE);
}
AP_DECLARE_MODULE(autoindex) =
{
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 */
};