mod_autoindex.c revision 5df5e943f377522b19786f126097da3a7288e2f0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * contributor license agreements. See the NOTICE file distributed with
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * this work for additional information regarding copyright ownership.
b99dbaab171d91e1b664397cc40e039d0c087c65fielding * The ASF licenses this file to You under the Apache License, Version 2.0
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * (the "License"); you may not use this file except in compliance with
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the License. You may obtain a copy of the License at
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * http://www.apache.org/licenses/LICENSE-2.0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Unless required by applicable law or agreed to in writing, software
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * distributed under the License is distributed on an "AS IS" BASIS,
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * See the License for the specific language governing permissions and
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * limitations under the License.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * mod_autoindex.c: Handles the on-the-fly html index generation
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding *
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * Rob McCool
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * 3/23/93
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding *
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * Adapted to Apache by rst.
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Version sort added by Martin Pool <mbp@humbug.org.au>.
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding */
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "apr_strings.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "apr_fnmatch.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "apr_strings.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "apr_lib.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
64185f9824e42f21ca7b9ae6c004484215c031a7rbb#define APR_WANT_STRFUNC
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "apr_want.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "ap_config.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "httpd.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "http_config.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_core.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "http_request.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "http_protocol.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "http_log.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "http_main.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "util_script.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "mod_core.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingmodule AP_MODULE_DECLARE_DATA autoindex_module;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding/****************************************************************
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding *
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * Handling configuration directives...
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#define NO_OPTIONS (1 << 0) /* Indexing options */
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#define ICONS_ARE_LINKS (1 << 1)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SCAN_HTML_TITLES (1 << 2)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_ICON (1 << 3)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_LAST_MOD (1 << 4)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_SIZE (1 << 5)
785be1b6298010956622771c870ab3cd8ca57a2faaron#define SUPPRESS_DESC (1 << 6)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_PREAMBLE (1 << 7)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_COLSORT (1 << 8)
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#define SUPPRESS_RULES (1 << 9)
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#define FOLDERS_FIRST (1 << 10)
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#define VERSION_SORT (1 << 11)
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#define TRACK_MODIFIED (1 << 12)
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#define FANCY_INDEXING (1 << 13)
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#define TABLE_INDEXING (1 << 14)
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#define IGNORE_CLIENT (1 << 15)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define IGNORE_CASE (1 << 16)
2d71630471d1c23f0137309e3c3957c633ecbfd6rbb#define EMIT_XHTML (1 << 17)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SHOW_FORBIDDEN (1 << 18)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define ADDALTCLASS (1 << 19)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define OPTION_UNSET (1 << 20)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_NOADJUST 0
51af95bb51b5084e883bad250b2afa2838e9ceebfielding#define K_ADJUST 1
d4f1d9c1ff112a8ab9bee31f196973761329b236rbb#define K_UNSET 2
7fae9cc4639013f3c04c085547256c68814aee8ftrawick
7fae9cc4639013f3c04c085547256c68814aee8ftrawick/*
7fae9cc4639013f3c04c085547256c68814aee8ftrawick * Define keys for sorting.
7fae9cc4639013f3c04c085547256c68814aee8ftrawick */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_NAME 'N' /* Sort by file name (default) */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_LAST_MOD 'M' /* Last modification date */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_SIZE 'S' /* Size (absolute, not as displayed) */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_DESC 'D' /* Description */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_VALID "NMSD" /* String containing _all_ valid K_ opts */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define D_ASCENDING 'A'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define D_DESCENDING 'D'
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define D_VALID "AD" /* String containing _all_ valid D_ opts */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
785be1b6298010956622771c870ab3cd8ca57a2faaron * These are the dimensions of the default icons supplied with Apache.
785be1b6298010956622771c870ab3cd8ca57a2faaron */
785be1b6298010956622771c870ab3cd8ca57a2faaron#define DEFAULT_ICON_WIDTH 20
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define DEFAULT_ICON_HEIGHT 22
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Other default dimensions.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define DEFAULT_NAME_WIDTH 23
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define DEFAULT_DESC_WIDTH 23
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
785be1b6298010956622771c870ab3cd8ca57a2faaronstruct item {
785be1b6298010956622771c870ab3cd8ca57a2faaron char *type;
785be1b6298010956622771c870ab3cd8ca57a2faaron char *apply_to;
785be1b6298010956622771c870ab3cd8ca57a2faaron char *apply_path;
785be1b6298010956622771c870ab3cd8ca57a2faaron char *data;
785be1b6298010956622771c870ab3cd8ca57a2faaron};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct ai_desc_t {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm char *pattern;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *description;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int full_path;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int wildcards;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding} ai_desc_t;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct autoindex_config_struct {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *default_icon;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *style_sheet;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *head_insert;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *header;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *readme;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_int32_t opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_int32_t incremented_opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_int32_t decremented_opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int name_width;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int name_adjust;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int desc_width;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int desc_adjust;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int icon_width;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int icon_height;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char default_keyid;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char default_direction;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_array_header_t *icon_list;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_array_header_t *alt_list;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_array_header_t *desc_list;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_array_header_t *ign_list;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int ign_noinherit;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *ctype;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *charset;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding} autoindex_config_rec;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic char c_by_encoding, c_by_type, c_by_path;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define BY_ENCODING &c_by_encoding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define BY_TYPE &c_by_type
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define BY_PATH &c_by_path
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic APR_INLINE int response_is_html(request_rec *r)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *ctype = ap_field_noparam(r->pool, r->content_type);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_str_tolower(ctype);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return !strcmp(ctype, "text/html")
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding || !strcmp(ctype, "application/xhtml+xml");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * This routine puts the standard HTML header at the top of the index page.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * We include the DOCTYPE because we may be using features therefrom (i.e.,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void emit_preamble(request_rec *r, int xhtml, const char *title)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding autoindex_config_rec *d;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding &autoindex_module);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (xhtml) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, DOCTYPE_XHTML_1_0T,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding " <head>\n <title>Index of ", title,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "</title>\n", NULL);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm } else {
785be1b6298010956622771c870ab3cd8ca57a2faaron ap_rvputs(r, DOCTYPE_HTML_3_2,
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick "<html>\n <head>\n"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding " <title>Index of ", title,
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick "</title>\n", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick if (d->style_sheet != NULL) {
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick ap_rvputs(r, " <link rel=\"stylesheet\" href=\"", d->style_sheet,
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick "\" type=\"text/css\"", xhtml ? " />\n" : ">\n", NULL);
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (d->head_insert != NULL) {
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick ap_rputs(d->head_insert, r);
785be1b6298010956622771c870ab3cd8ca57a2faaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs(" </head>\n <body>\n", r);
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick}
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregamesstatic void push_item(apr_array_header_t *arr, char *type, const char *to,
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames const char *path, const char *data)
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames{
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames struct item *p = (struct item *) apr_array_push(arr);
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames if (!to) {
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames to = "";
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames }
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames if (!path) {
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames path = "";
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick }
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick p->type = type;
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick p->data = apr_pstrdup(arr->pool, data);
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick p->apply_path = apr_pstrcat(arr->pool, path, "*", NULL);
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick if ((type == BY_PATH) && (!ap_is_matchexp(to))) {
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick p->apply_to = apr_pstrcat(arr->pool, "*", to, NULL);
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick }
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick else if (to) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p->apply_to = apr_pstrdup(arr->pool, to);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
eae32ab3fb398ca408bc2d45b22adf1b67a75471rbb else {
066877f1a045103acfdd376d48cdd473c33f409bdougm p->apply_to = NULL;
eae32ab3fb398ca408bc2d45b22adf1b67a75471rbb }
785be1b6298010956622771c870ab3cd8ca57a2faaron}
785be1b6298010956622771c870ab3cd8ca57a2faaron
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawickstatic const char *add_alt(cmd_parms *cmd, void *d, const char *alt,
066877f1a045103acfdd376d48cdd473c33f409bdougm const char *to)
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick{
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick if (cmd->info == BY_PATH) {
785be1b6298010956622771c870ab3cd8ca57a2faaron if (!strcmp(to, "**DIRECTORY**")) {
785be1b6298010956622771c870ab3cd8ca57a2faaron to = "^^DIRECTORY^^";
066877f1a045103acfdd376d48cdd473c33f409bdougm }
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick }
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick if (cmd->info == BY_ENCODING) {
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick char *tmp = apr_pstrdup(cmd->pool, to);
74b39333600dee3260355ad3a06e36ef6c61c8f1dreid ap_str_tolower(tmp);
74b39333600dee3260355ad3a06e36ef6c61c8f1dreid to = tmp;
74b39333600dee3260355ad3a06e36ef6c61c8f1dreid }
74b39333600dee3260355ad3a06e36ef6c61c8f1dreid
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick push_item(((autoindex_config_rec *) d)->alt_list, cmd->info, to,
066877f1a045103acfdd376d48cdd473c33f409bdougm cmd->path, alt);
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick return NULL;
d17890657bc529b3f9db20e5546511182b829565dreid}
d17890657bc529b3f9db20e5546511182b829565dreid
d17890657bc529b3f9db20e5546511182b829565dreidstatic const char *add_icon(cmd_parms *cmd, void *d, const char *icon,
d17890657bc529b3f9db20e5546511182b829565dreid const char *to)
d17890657bc529b3f9db20e5546511182b829565dreid{
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick char *iconbak = apr_pstrdup(cmd->pool, icon);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (icon[0] == '(') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *alt;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *cl = strchr(iconbak, ')');
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
785be1b6298010956622771c870ab3cd8ca57a2faaron if (cl == NULL) {
785be1b6298010956622771c870ab3cd8ca57a2faaron return "missing closing paren";
785be1b6298010956622771c870ab3cd8ca57a2faaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding alt = ap_getword_nc(cmd->pool, &iconbak, ',');
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *cl = '\0'; /* Lose closing paren */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding add_alt(cmd, d, &alt[1], to);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (cmd->info == BY_PATH) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!strcmp(to, "**DIRECTORY**")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding to = "^^DIRECTORY^^";
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron if (cmd->info == BY_ENCODING) {
785be1b6298010956622771c870ab3cd8ca57a2faaron char *tmp = apr_pstrdup(cmd->pool, to);
785be1b6298010956622771c870ab3cd8ca57a2faaron ap_str_tolower(tmp);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding to = tmp;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding push_item(((autoindex_config_rec *) d)->icon_list, cmd->info, to,
785be1b6298010956622771c870ab3cd8ca57a2faaron cmd->path, iconbak);
785be1b6298010956622771c870ab3cd8ca57a2faaron return NULL;
785be1b6298010956622771c870ab3cd8ca57a2faaron}
785be1b6298010956622771c870ab3cd8ca57a2faaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Add description text for a filename pattern. If the pattern has
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * wildcards already (or we need to add them), add leading and
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * trailing wildcards to it to ensure substring processing. If the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * pattern contains a '/' anywhere, force wildcard matching mode,
785be1b6298010956622771c870ab3cd8ca57a2faaron * add a slash to the prefix so that "bar/bletch" won't be matched
785be1b6298010956622771c870ab3cd8ca57a2faaron * by "foobar/bletch", and make a note that there's a delimiter;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the matching routine simplifies to just the actual filename
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * whenever it can. This allows definitions in parent directories
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * to be made for files in subordinate ones using relative paths.
785be1b6298010956622771c870ab3cd8ca57a2faaron */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Absent a strcasestr() function, we have to force wildcards on
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * systems for which "AAA" and "aaa" mean the same file.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef CASE_BLIND_FILESYSTEM
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define WILDCARDS_REQUIRED 1
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#else
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define WILDCARDS_REQUIRED 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const char *add_desc(cmd_parms *cmd, void *d, const char *desc,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *to)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding autoindex_config_rec *dcfg = (autoindex_config_rec *) d;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ai_desc_t *desc_entry;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *prefix = "";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding desc_entry = (ai_desc_t *) apr_array_push(dcfg->desc_list);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding desc_entry->full_path = (ap_strchr_c(to, '/') == NULL) ? 0 : 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding desc_entry->wildcards = (WILDCARDS_REQUIRED
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding || desc_entry->full_path
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding || apr_fnmatch_test(to));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (desc_entry->wildcards) {
785be1b6298010956622771c870ab3cd8ca57a2faaron prefix = desc_entry->full_path ? "*/" : "*";
785be1b6298010956622771c870ab3cd8ca57a2faaron desc_entry->pattern = apr_pstrcat(dcfg->desc_list->pool,
785be1b6298010956622771c870ab3cd8ca57a2faaron prefix, to, "*", NULL);
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron else {
785be1b6298010956622771c870ab3cd8ca57a2faaron desc_entry->pattern = apr_pstrdup(dcfg->desc_list->pool, to);
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron desc_entry->description = apr_pstrdup(dcfg->desc_list->pool, desc);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
785be1b6298010956622771c870ab3cd8ca57a2faaronstatic const char *add_ignore(cmd_parms *cmd, void *d, const char *ext)
785be1b6298010956622771c870ab3cd8ca57a2faaron{
785be1b6298010956622771c870ab3cd8ca57a2faaron push_item(((autoindex_config_rec *) d)->ign_list, 0, ext, cmd->path, NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaronstatic const char *add_opts(cmd_parms *cmd, void *d, int argc, char *const argv[])
785be1b6298010956622771c870ab3cd8ca57a2faaron{
785be1b6298010956622771c870ab3cd8ca57a2faaron int i;
785be1b6298010956622771c870ab3cd8ca57a2faaron char *w;
785be1b6298010956622771c870ab3cd8ca57a2faaron apr_int32_t opts;
785be1b6298010956622771c870ab3cd8ca57a2faaron apr_int32_t opts_add;
785be1b6298010956622771c870ab3cd8ca57a2faaron apr_int32_t opts_remove;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char action;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm autoindex_config_rec *d_cfg = (autoindex_config_rec *) d;
785be1b6298010956622771c870ab3cd8ca57a2faaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding opts = d_cfg->opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding opts_add = d_cfg->incremented_opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding opts_remove = d_cfg->decremented_opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < argc; i++) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int option = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding w = argv[i];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((*w == '+') || (*w == '-')) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding action = *(w++);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding action = '\0';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!strcasecmp(w, "FancyIndexing")) {
a7ed9c525f9460187f327cea953bf90ecf1bdc51gstein option = FANCY_INDEXING;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "FoldersFirst")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = FOLDERS_FIRST;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "HTMLTable")) {
a7ed9c525f9460187f327cea953bf90ecf1bdc51gstein option = TABLE_INDEXING;
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick }
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick else if (!strcasecmp(w, "IconsAreLinks")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = ICONS_ARE_LINKS;
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick }
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick else if (!strcasecmp(w, "IgnoreCase")) {
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick option = IGNORE_CASE;
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick }
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick else if (!strcasecmp(w, "IgnoreClient")) {
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick option = IGNORE_CLIENT;
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "ScanHTMLTitles")) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm option = SCAN_HTML_TITLES;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "SuppressColumnSorting")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SUPPRESS_COLSORT;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm else if (!strcasecmp(w, "SuppressDescription")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SUPPRESS_DESC;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "SuppressHTMLPreamble")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SUPPRESS_PREAMBLE;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "SuppressIcon")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SUPPRESS_ICON;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (!strcasecmp(w, "SuppressLastModified")) {
785be1b6298010956622771c870ab3cd8ca57a2faaron option = SUPPRESS_LAST_MOD;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "SuppressSize")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SUPPRESS_SIZE;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "SuppressRules")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SUPPRESS_RULES;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "TrackModified")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = TRACK_MODIFIED;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "VersionSort")) {
a7ed9c525f9460187f327cea953bf90ecf1bdc51gstein option = VERSION_SORT;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "XHTML")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = EMIT_XHTML;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm else if (!strcasecmp(w, "ShowForbidden")) {
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick option = SHOW_FORBIDDEN;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (!strcasecmp(w, "AddAltClass")) {
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick option = ADDALTCLASS;
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick }
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick else if (!strcasecmp(w, "None")) {
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick if (action != '\0') {
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick return "Cannot combine '+' or '-' with 'None' keyword";
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick }
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick opts = NO_OPTIONS;
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick opts_add = 0;
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick opts_remove = 0;
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick }
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick else if (!strcasecmp(w, "IconWidth")) {
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick if (action != '-') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->icon_width = DEFAULT_ICON_WIDTH;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->icon_width = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
8f8ec0957334f50b7ac11359f90490ee467258eedreid }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strncasecmp(w, "IconWidth=", 10)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action == '-') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Cannot combine '-' with IconWidth=n";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->icon_width = atoi(&w[10]);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "IconHeight")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action != '-') {
785be1b6298010956622771c870ab3cd8ca57a2faaron d_cfg->icon_height = DEFAULT_ICON_HEIGHT;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->icon_height = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf else if (!strncasecmp(w, "IconHeight=", 11)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action == '-') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Cannot combine '-' with IconHeight=n";
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->icon_height = atoi(&w[11]);
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "NameWidth")) {
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick if (action != '-') {
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick return "NameWidth with no value may only appear as "
785be1b6298010956622771c870ab3cd8ca57a2faaron "'-NameWidth'";
785be1b6298010956622771c870ab3cd8ca57a2faaron }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf d_cfg->name_width = DEFAULT_NAME_WIDTH;
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick d_cfg->name_adjust = K_NOADJUST;
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick }
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (!strncasecmp(w, "NameWidth=", 10)) {
785be1b6298010956622771c870ab3cd8ca57a2faaron if (action == '-') {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return "Cannot combine '-' with NameWidth=n";
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf }
785be1b6298010956622771c870ab3cd8ca57a2faaron if (w[10] == '*') {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf d_cfg->name_adjust = K_ADJUST;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf }
785be1b6298010956622771c870ab3cd8ca57a2faaron else {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf int width = atoi(&w[10]);
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf
785be1b6298010956622771c870ab3cd8ca57a2faaron if (width && (width < 5)) {
785be1b6298010956622771c870ab3cd8ca57a2faaron return "NameWidth value must be greater than 5";
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron d_cfg->name_width = width;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf d_cfg->name_adjust = K_NOADJUST;
066877f1a045103acfdd376d48cdd473c33f409bdougm }
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (!strcasecmp(w, "DescriptionWidth")) {
785be1b6298010956622771c870ab3cd8ca57a2faaron if (action != '-') {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return "DescriptionWidth with no value may only appear as "
785be1b6298010956622771c870ab3cd8ca57a2faaron "'-DescriptionWidth'";
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron d_cfg->desc_width = DEFAULT_DESC_WIDTH;
785be1b6298010956622771c870ab3cd8ca57a2faaron d_cfg->desc_adjust = K_NOADJUST;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (!strncasecmp(w, "DescriptionWidth=", 17)) {
785be1b6298010956622771c870ab3cd8ca57a2faaron if (action == '-') {
785be1b6298010956622771c870ab3cd8ca57a2faaron return "Cannot combine '-' with DescriptionWidth=n";
785be1b6298010956622771c870ab3cd8ca57a2faaron }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf if (w[17] == '*') {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf d_cfg->desc_adjust = K_ADJUST;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf else {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf int width = atoi(&w[17]);
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf if (width && (width < 12)) {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return "DescriptionWidth value must be greater than 12";
066877f1a045103acfdd376d48cdd473c33f409bdougm }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->desc_width = width;
785be1b6298010956622771c870ab3cd8ca57a2faaron d_cfg->desc_adjust = K_NOADJUST;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strncasecmp(w, "Type=", 5)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->ctype = apr_pstrdup(cmd->pool, &w[5]);
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (!strncasecmp(w, "Charset=", 8)) {
785be1b6298010956622771c870ab3cd8ca57a2faaron d_cfg->charset = apr_pstrdup(cmd->pool, &w[8]);
785be1b6298010956622771c870ab3cd8ca57a2faaron }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf else {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return "Invalid directory indexing option";
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf if (action == '\0') {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf opts |= option;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf opts_add = 0;
785be1b6298010956622771c870ab3cd8ca57a2faaron opts_remove = 0;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (action == '+') {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf opts_add |= option;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf opts_remove &= ~option;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf else {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf opts_remove |= option;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf opts_add &= ~option;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron if ((opts & NO_OPTIONS) && (opts & ~NO_OPTIONS)) {
785be1b6298010956622771c870ab3cd8ca57a2faaron return "Cannot combine other IndexOptions keywords with 'None'";
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron d_cfg->incremented_opts = opts_add;
785be1b6298010956622771c870ab3cd8ca57a2faaron d_cfg->decremented_opts = opts_remove;
785be1b6298010956622771c870ab3cd8ca57a2faaron d_cfg->opts = opts;
785be1b6298010956622771c870ab3cd8ca57a2faaron return NULL;
785be1b6298010956622771c870ab3cd8ca57a2faaron}
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaronstatic const char *set_default_order(cmd_parms *cmd, void *m,
785be1b6298010956622771c870ab3cd8ca57a2faaron const char *direction, const char *key)
785be1b6298010956622771c870ab3cd8ca57a2faaron{
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf autoindex_config_rec *d_cfg = (autoindex_config_rec *) m;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf
785be1b6298010956622771c870ab3cd8ca57a2faaron if (!strcasecmp(direction, "Ascending")) {
785be1b6298010956622771c870ab3cd8ca57a2faaron d_cfg->default_direction = D_ASCENDING;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf else if (!strcasecmp(direction, "Descending")) {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf d_cfg->default_direction = D_DESCENDING;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf else {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return "First keyword must be 'Ascending' or 'Descending'";
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron if (!strcasecmp(key, "Name")) {
785be1b6298010956622771c870ab3cd8ca57a2faaron d_cfg->default_keyid = K_NAME;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (!strcasecmp(key, "Date")) {
785be1b6298010956622771c870ab3cd8ca57a2faaron d_cfg->default_keyid = K_LAST_MOD;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (!strcasecmp(key, "Size")) {
785be1b6298010956622771c870ab3cd8ca57a2faaron d_cfg->default_keyid = K_SIZE;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (!strcasecmp(key, "Description")) {
785be1b6298010956622771c870ab3cd8ca57a2faaron d_cfg->default_keyid = K_DESC;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron else {
785be1b6298010956622771c870ab3cd8ca57a2faaron return "Second keyword must be 'Name', 'Date', 'Size', or "
785be1b6298010956622771c870ab3cd8ca57a2faaron "'Description'";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
ebc18d48bea83ee5ed7a1b4e30007e5192539829wrowe
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define DIR_CMD_PERMS OR_INDEXES
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const command_rec autoindex_cmds[] =
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE2("AddIcon", add_icon, BY_PATH, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "an icon URL followed by one or more filenames"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE2("AddIconByType", add_icon, BY_TYPE, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "an icon URL followed by one or more MIME types"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE2("AddIconByEncoding", add_icon, BY_ENCODING, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "an icon URL followed by one or more content encodings"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE2("AddAlt", add_alt, BY_PATH, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "alternate descriptive text followed by one or more "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "filenames"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE2("AddAltByType", add_alt, BY_TYPE, DIR_CMD_PERMS,
785be1b6298010956622771c870ab3cd8ca57a2faaron "alternate descriptive text followed by one or more MIME "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "types"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE2("AddAltByEncoding", add_alt, BY_ENCODING, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "alternate descriptive text followed by one or more "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "content encodings"),
785be1b6298010956622771c870ab3cd8ca57a2faaron AP_INIT_TAKE_ARGV("IndexOptions", add_opts, NULL, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "one or more index options [+|-][]"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_TAKE2("IndexOrderDefault", set_default_order, NULL, DIR_CMD_PERMS,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm "{Ascending,Descending} {Name,Size,Description,Date}"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE("IndexIgnore", add_ignore, NULL, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "one or more file extensions"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_FLAG("IndexIgnoreReset", ap_set_flag_slot,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (void *)APR_OFFSETOF(autoindex_config_rec, ign_noinherit),
785be1b6298010956622771c870ab3cd8ca57a2faaron DIR_CMD_PERMS,
785be1b6298010956622771c870ab3cd8ca57a2faaron "Reset the inherited list of IndexIgnore filenames"),
785be1b6298010956622771c870ab3cd8ca57a2faaron AP_INIT_ITERATE2("AddDescription", add_desc, BY_PATH, DIR_CMD_PERMS,
785be1b6298010956622771c870ab3cd8ca57a2faaron "Descriptive text followed by one or more filenames"),
785be1b6298010956622771c870ab3cd8ca57a2faaron AP_INIT_TAKE1("HeaderName", ap_set_string_slot,
785be1b6298010956622771c870ab3cd8ca57a2faaron (void *)APR_OFFSETOF(autoindex_config_rec, header),
785be1b6298010956622771c870ab3cd8ca57a2faaron DIR_CMD_PERMS, "a filename"),
785be1b6298010956622771c870ab3cd8ca57a2faaron AP_INIT_TAKE1("ReadmeName", ap_set_string_slot,
785be1b6298010956622771c870ab3cd8ca57a2faaron (void *)APR_OFFSETOF(autoindex_config_rec, readme),
785be1b6298010956622771c870ab3cd8ca57a2faaron DIR_CMD_PERMS, "a filename"),
785be1b6298010956622771c870ab3cd8ca57a2faaron AP_INIT_RAW_ARGS("FancyIndexing", ap_set_deprecated, NULL, OR_ALL,
785be1b6298010956622771c870ab3cd8ca57a2faaron "The FancyIndexing directive is no longer supported. "
785be1b6298010956622771c870ab3cd8ca57a2faaron "Use IndexOptions FancyIndexing."),
785be1b6298010956622771c870ab3cd8ca57a2faaron AP_INIT_TAKE1("DefaultIcon", ap_set_string_slot,
785be1b6298010956622771c870ab3cd8ca57a2faaron (void *)APR_OFFSETOF(autoindex_config_rec, default_icon),
785be1b6298010956622771c870ab3cd8ca57a2faaron DIR_CMD_PERMS, "an icon URL"),
785be1b6298010956622771c870ab3cd8ca57a2faaron AP_INIT_TAKE1("IndexStyleSheet", ap_set_string_slot,
785be1b6298010956622771c870ab3cd8ca57a2faaron (void *)APR_OFFSETOF(autoindex_config_rec, style_sheet),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DIR_CMD_PERMS, "URL to style sheet"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_TAKE1("IndexHeadInsert", ap_set_string_slot,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm (void *)APR_OFFSETOF(autoindex_config_rec, head_insert),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DIR_CMD_PERMS, "String to insert in HTML HEAD section"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {NULL}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void *create_autoindex_config(apr_pool_t *p, char *dummy)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
785be1b6298010956622771c870ab3cd8ca57a2faaron autoindex_config_rec *new =
785be1b6298010956622771c870ab3cd8ca57a2faaron (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
785be1b6298010956622771c870ab3cd8ca57a2faaron
900127764fb985c340ee4979cac97146a330c694trawick new->icon_width = 0;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->icon_height = 0;
900127764fb985c340ee4979cac97146a330c694trawick new->name_width = DEFAULT_NAME_WIDTH;
900127764fb985c340ee4979cac97146a330c694trawick new->name_adjust = K_UNSET;
900127764fb985c340ee4979cac97146a330c694trawick new->desc_width = DEFAULT_DESC_WIDTH;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->desc_adjust = K_UNSET;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->icon_list = apr_array_make(p, 4, sizeof(struct item));
785be1b6298010956622771c870ab3cd8ca57a2faaron new->alt_list = apr_array_make(p, 4, sizeof(struct item));
785be1b6298010956622771c870ab3cd8ca57a2faaron new->desc_list = apr_array_make(p, 4, sizeof(ai_desc_t));
785be1b6298010956622771c870ab3cd8ca57a2faaron new->ign_list = apr_array_make(p, 4, sizeof(struct item));
785be1b6298010956622771c870ab3cd8ca57a2faaron new->opts = OPTION_UNSET;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->incremented_opts = 0;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->decremented_opts = 0;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->default_keyid = '\0';
785be1b6298010956622771c870ab3cd8ca57a2faaron new->default_direction = '\0';
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron return (void *) new;
785be1b6298010956622771c870ab3cd8ca57a2faaron}
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaronstatic void *merge_autoindex_configs(apr_pool_t *p, void *basev, void *addv)
785be1b6298010956622771c870ab3cd8ca57a2faaron{
785be1b6298010956622771c870ab3cd8ca57a2faaron autoindex_config_rec *new;
785be1b6298010956622771c870ab3cd8ca57a2faaron autoindex_config_rec *base = (autoindex_config_rec *) basev;
785be1b6298010956622771c870ab3cd8ca57a2faaron autoindex_config_rec *add = (autoindex_config_rec *) addv;
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron new = (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
785be1b6298010956622771c870ab3cd8ca57a2faaron new->default_icon = add->default_icon ? add->default_icon
785be1b6298010956622771c870ab3cd8ca57a2faaron : base->default_icon;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->style_sheet = add->style_sheet ? add->style_sheet
785be1b6298010956622771c870ab3cd8ca57a2faaron : base->style_sheet;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->head_insert = add->head_insert ? add->head_insert
785be1b6298010956622771c870ab3cd8ca57a2faaron : base->head_insert;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->header = add->header ? add->header
785be1b6298010956622771c870ab3cd8ca57a2faaron : base->header;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->readme = add->readme ? add->readme
785be1b6298010956622771c870ab3cd8ca57a2faaron : base->readme;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->icon_height = add->icon_height ? add->icon_height : base->icon_height;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->icon_width = add->icon_width ? add->icon_width : base->icon_width;
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron new->ctype = add->ctype ? add->ctype : base->ctype;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->charset = add->charset ? add->charset : base->charset;
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron new->alt_list = apr_array_append(p, add->alt_list, base->alt_list);
785be1b6298010956622771c870ab3cd8ca57a2faaron new->desc_list = apr_array_append(p, add->desc_list, base->desc_list);
785be1b6298010956622771c870ab3cd8ca57a2faaron new->icon_list = apr_array_append(p, add->icon_list, base->icon_list);
785be1b6298010956622771c870ab3cd8ca57a2faaron new->ign_list = add->ign_noinherit ? add->ign_list : apr_array_append(p, add->ign_list, base->ign_list);
785be1b6298010956622771c870ab3cd8ca57a2faaron if (add->opts == NO_OPTIONS) {
785be1b6298010956622771c870ab3cd8ca57a2faaron /*
785be1b6298010956622771c870ab3cd8ca57a2faaron * If the current directory explicitly says 'no options' then we also
785be1b6298010956622771c870ab3cd8ca57a2faaron * clear any incremental mods from being inheritable further down.
785be1b6298010956622771c870ab3cd8ca57a2faaron */
785be1b6298010956622771c870ab3cd8ca57a2faaron new->opts = NO_OPTIONS;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->incremented_opts = 0;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->decremented_opts = 0;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron else {
785be1b6298010956622771c870ab3cd8ca57a2faaron /*
785be1b6298010956622771c870ab3cd8ca57a2faaron * If there were any nonincremental options selected for
785be1b6298010956622771c870ab3cd8ca57a2faaron * this directory, they dominate and we don't inherit *anything.*
785be1b6298010956622771c870ab3cd8ca57a2faaron * Contrariwise, we *do* inherit if the only settings here are
785be1b6298010956622771c870ab3cd8ca57a2faaron * incremental ones.
785be1b6298010956622771c870ab3cd8ca57a2faaron */
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick if (add->opts == OPTION_UNSET) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->incremented_opts = (base->incremented_opts
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick | add->incremented_opts)
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick & ~add->decremented_opts;
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick new->decremented_opts = (base->decremented_opts
785be1b6298010956622771c870ab3cd8ca57a2faaron | add->decremented_opts);
785be1b6298010956622771c870ab3cd8ca57a2faaron /*
785be1b6298010956622771c870ab3cd8ca57a2faaron * We may have incremental settings, so make sure we don't
785be1b6298010956622771c870ab3cd8ca57a2faaron * inadvertently inherit an IndexOptions None from above.
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick */
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick new->opts = (base->opts & ~NO_OPTIONS);
066877f1a045103acfdd376d48cdd473c33f409bdougm }
785be1b6298010956622771c870ab3cd8ca57a2faaron else {
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick /*
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick * There are local nonincremental settings, which clear
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick * all inheritance from above. They *are* the new base settings.
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick */
785be1b6298010956622771c870ab3cd8ca57a2faaron new->opts = add->opts;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron /*
785be1b6298010956622771c870ab3cd8ca57a2faaron * We're guaranteed that there'll be no overlap between
785be1b6298010956622771c870ab3cd8ca57a2faaron * the add-options and the remove-options.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->opts |= new->incremented_opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->opts &= ~new->decremented_opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Inherit the NameWidth settings if there aren't any specific to
785be1b6298010956622771c870ab3cd8ca57a2faaron * the new location; otherwise we'll end up using the defaults set in the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * config-rec creation routine.
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (add->name_adjust == K_UNSET) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->name_width = base->name_width;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->name_adjust = base->name_adjust;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
bbbf8f0e622ad5a37ccf70f35660fc755575278arbb else {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm new->name_width = add->name_width;
066877f1a045103acfdd376d48cdd473c33f409bdougm new->name_adjust = add->name_adjust;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Likewise for DescriptionWidth.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (add->desc_adjust == K_UNSET) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->desc_width = base->desc_width;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->desc_adjust = base->desc_adjust;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf else {
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf new->desc_width = add->desc_width;
91583d2e9c0550f539ea6f4dedf051979ad1ad88fanf new->desc_adjust = add->desc_adjust;
91583d2e9c0550f539ea6f4dedf051979ad1ad88fanf }
91583d2e9c0550f539ea6f4dedf051979ad1ad88fanf
91583d2e9c0550f539ea6f4dedf051979ad1ad88fanf new->default_keyid = add->default_keyid ? add->default_keyid
91583d2e9c0550f539ea6f4dedf051979ad1ad88fanf : base->default_keyid;
91583d2e9c0550f539ea6f4dedf051979ad1ad88fanf new->default_direction = add->default_direction ? add->default_direction
91583d2e9c0550f539ea6f4dedf051979ad1ad88fanf : base->default_direction;
91583d2e9c0550f539ea6f4dedf051979ad1ad88fanf return new;
91583d2e9c0550f539ea6f4dedf051979ad1ad88fanf}
91583d2e9c0550f539ea6f4dedf051979ad1ad88fanf
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/****************************************************************
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Looking things up in config entries...
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick */
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick/* Structure used to hold entries when we're actually building an index */
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanfstruct ent {
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick char *name;
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick char *icon;
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick char *alt;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *desc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_off_t size;
0db1b9810f06c0e3c537e0e0dfbc30160c308526trawick apr_time_t lm;
0db1b9810f06c0e3c537e0e0dfbc30160c308526trawick struct ent *next;
0db1b9810f06c0e3c537e0e0dfbc30160c308526trawick int ascending, ignore_case, version_sort;
0db1b9810f06c0e3c537e0e0dfbc30160c308526trawick char key;
0db1b9810f06c0e3c537e0e0dfbc30160c308526trawick int isdir;
0db1b9810f06c0e3c537e0e0dfbc30160c308526trawick};
0db1b9810f06c0e3c537e0e0dfbc30160c308526trawick
644be6f54749d2d9950d2c4d2ac448f7af016d26martinstatic char *find_item(const char *content_type, const char *content_encoding,
644be6f54749d2d9950d2c4d2ac448f7af016d26martin char *path, apr_array_header_t *list, int path_only)
644be6f54749d2d9950d2c4d2ac448f7af016d26martin{
644be6f54749d2d9950d2c4d2ac448f7af016d26martin struct item *items = (struct item *) list->elts;
644be6f54749d2d9950d2c4d2ac448f7af016d26martin int i;
644be6f54749d2d9950d2c4d2ac448f7af016d26martin
644be6f54749d2d9950d2c4d2ac448f7af016d26martin for (i = 0; i < list->nelts; ++i) {
644be6f54749d2d9950d2c4d2ac448f7af016d26martin struct item *p = &items[i];
644be6f54749d2d9950d2c4d2ac448f7af016d26martin
0db1b9810f06c0e3c537e0e0dfbc30160c308526trawick /* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick if ((path[0] == '^') || (!ap_strcmp_match(path, p->apply_path))) {
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick if (!*(p->apply_to)) {
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick return p->data;
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick }
71715c646d5231de578431f8961e711764b899d3fanf else if (p->type == BY_PATH || path[0] == '^') {
785be1b6298010956622771c870ab3cd8ca57a2faaron if (!ap_strcmp_match(path, p->apply_to)) {
785be1b6298010956622771c870ab3cd8ca57a2faaron return p->data;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (!path_only) {
785be1b6298010956622771c870ab3cd8ca57a2faaron if (!content_encoding) {
785be1b6298010956622771c870ab3cd8ca57a2faaron if (p->type == BY_TYPE) {
785be1b6298010956622771c870ab3cd8ca57a2faaron if (content_type
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick && !ap_strcasecmp_match(content_type,
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick p->apply_to)) {
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick return p->data;
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick }
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick }
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf if (p->type == BY_ENCODING) {
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf if (!ap_strcasecmp_match(content_encoding,
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf p->apply_to)) {
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf return p->data;
5e4791fd54c10fdd77ca81bee8ac8398f16d6d6astoddard }
785be1b6298010956622771c870ab3cd8ca57a2faaron }
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic char *find_item_by_request(request_rec *r, apr_array_header_t *list, int path_only)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return find_item(ap_field_noparam(r->pool, r->content_type),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r->content_encoding, r->filename, list, path_only);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
785be1b6298010956622771c870ab3cd8ca57a2faaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define find_icon(d,p,t) find_item_by_request(p,d->icon_list,t)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define find_alt(d,p,t) find_item_by_request(p,d->alt_list,t)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define find_default_icon(d,n) find_item(NULL, NULL, n, d->icon_list, 1)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define find_default_alt(d,n) find_item(NULL, NULL, n, d->alt_list, 1)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
785be1b6298010956622771c870ab3cd8ca57a2faaron/*
785be1b6298010956622771c870ab3cd8ca57a2faaron * Look through the list of pattern/description pairs and return the first one
785be1b6298010956622771c870ab3cd8ca57a2faaron * if any) that matches the filename in the request. If multiple patterns
785be1b6298010956622771c870ab3cd8ca57a2faaron * match, only the first one is used; since the order in the array is the
785be1b6298010956622771c870ab3cd8ca57a2faaron * same as the order in which directives were processed, earlier matching
785be1b6298010956622771c870ab3cd8ca57a2faaron * directives will dominate.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef CASE_BLIND_FILESYSTEM
785be1b6298010956622771c870ab3cd8ca57a2faaron#define MATCH_FLAGS APR_FNM_CASE_BLIND
785be1b6298010956622771c870ab3cd8ca57a2faaron#else
785be1b6298010956622771c870ab3cd8ca57a2faaron#define MATCH_FLAGS 0
785be1b6298010956622771c870ab3cd8ca57a2faaron#endif
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaronstatic char *find_desc(autoindex_config_rec *dcfg, const char *filename_full)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int i;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ai_desc_t *list = (ai_desc_t *) dcfg->desc_list->elts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *filename_only;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *filename;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If the filename includes a path, extract just the name itself
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * for the simple matches.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((filename_only = ap_strrchr_c(filename_full, '/')) == NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding filename_only = filename_full;
3d96ee83babeec32482c9082c9426340cee8c44dwrowe }
785be1b6298010956622771c870ab3cd8ca57a2faaron else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding filename_only++;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < dcfg->desc_list->nelts; ++i) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ai_desc_t *tuple = &list[i];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int found;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Only use the full-path filename if the pattern contains '/'s.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding filename = (tuple->full_path) ? filename_full : filename_only;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
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 {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding found = (ap_strstr_c(filename, tuple->pattern) != NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (found) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return tuple->description;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron return NULL;
785be1b6298010956622771c870ab3cd8ca57a2faaron}
785be1b6298010956622771c870ab3cd8ca57a2faaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int ignore_entry(autoindex_config_rec *d, char *path)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_array_header_t *list = d->ign_list;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding struct item *items = (struct item *) list->elts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *tt;
785be1b6298010956622771c870ab3cd8ca57a2faaron int i;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((tt = strrchr(path, '/')) == NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding tt = path;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding tt++;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < list->nelts; ++i) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding struct item *p = &items[i];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *ap;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((ap = strrchr(p->apply_to, '/')) == NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap = p->apply_to;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap++;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifndef CASE_BLIND_FILESYSTEM
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!ap_strcmp_match(path, p->apply_path)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && !ap_strcmp_match(tt, ap)) {
dad234382d8424e1c5a30af2838e172aec9d6d1bdreid return 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#else /* !CASE_BLIND_FILESYSTEM */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * On some platforms, the match must be case-blind. This is really
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * a factor of the filesystem involved, but we can't detect that
e6cc28a5eb3371ba0c38e941855e71ff0054f50erbb * reliably - so we have to granularise at the OS level.
e6cc28a5eb3371ba0c38e941855e71ff0054f50erbb */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!ap_strcasecmp_match(path, p->apply_path)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && !ap_strcasecmp_match(tt, ap)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif /* !CASE_BLIND_FILESYSTEM */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*****************************************************************
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Actually generating output
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron/*
785be1b6298010956622771c870ab3cd8ca57a2faaron * Elements of the emitted document:
785be1b6298010956622771c870ab3cd8ca57a2faaron * Preamble
785be1b6298010956622771c870ab3cd8ca57a2faaron * Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
785be1b6298010956622771c870ab3cd8ca57a2faaron * succeeds for the (content_type == text/html) header file.
785be1b6298010956622771c870ab3cd8ca57a2faaron * Header file
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Emitted if found (and able).
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * H1 tag line
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Emitted if a header file is NOT emitted.
785be1b6298010956622771c870ab3cd8ca57a2faaron * Directory stuff
785be1b6298010956622771c870ab3cd8ca57a2faaron * Always emitted.
785be1b6298010956622771c870ab3cd8ca57a2faaron * HR
785be1b6298010956622771c870ab3cd8ca57a2faaron * Emitted if FANCY_INDEXING is set.
785be1b6298010956622771c870ab3cd8ca57a2faaron * Readme file
785be1b6298010956622771c870ab3cd8ca57a2faaron * Emitted if found (and able).
785be1b6298010956622771c870ab3cd8ca57a2faaron * ServerSig
785be1b6298010956622771c870ab3cd8ca57a2faaron * Emitted if ServerSignature is not Off AND a readme file
785be1b6298010956622771c870ab3cd8ca57a2faaron * is NOT emitted.
785be1b6298010956622771c870ab3cd8ca57a2faaron * Postamble
785be1b6298010956622771c870ab3cd8ca57a2faaron * Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
785be1b6298010956622771c870ab3cd8ca57a2faaron * succeeds for the (content_type == text/html) readme file.
785be1b6298010956622771c870ab3cd8ca57a2faaron */
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * emit a plain text file
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void do_emit_plain(request_rec *r, apr_file_t *f)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char buf[AP_IOBUFSIZE + 1];
51af95bb51b5084e883bad250b2afa2838e9ceebfielding int ch;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_size_t i, c, n;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_status_t rv;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs("<pre>\n", r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding while (!apr_file_eof(f)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding do {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding n = sizeof(char) * AP_IOBUFSIZE;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding rv = apr_file_read(f, buf, &n);
dad234382d8424e1c5a30af2838e172aec9d6d1bdreid } while (APR_STATUS_IS_EINTR(rv));
382fa07a63096c4a1aabfed36433ea5ac9c40ad0trawick if (n == 0 || rv != APR_SUCCESS) {
e6cc28a5eb3371ba0c38e941855e71ff0054f50erbb /* ###: better error here? */
e6cc28a5eb3371ba0c38e941855e71ff0054f50erbb break;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding buf[n] = '\0';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding c = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding while (c < n) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = c; i < n; i++) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (buf[i] == '<' || buf[i] == '>' || buf[i] == '&') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding break;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ch = buf[i];
785be1b6298010956622771c870ab3cd8ca57a2faaron buf[i] = '\0';
785be1b6298010956622771c870ab3cd8ca57a2faaron ap_rputs(&buf[c], r);
785be1b6298010956622771c870ab3cd8ca57a2faaron if (ch == '<') {
785be1b6298010956622771c870ab3cd8ca57a2faaron ap_rputs("&lt;", r);
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (ch == '>') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs("&gt;", r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (ch == '&') {
785be1b6298010956622771c870ab3cd8ca57a2faaron ap_rputs("&amp;", r);
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron c = i + 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rputs("</pre>\n", r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
51af95bb51b5084e883bad250b2afa2838e9ceebfielding/*
785be1b6298010956622771c870ab3cd8ca57a2faaron * Handle the preamble through the H1 tag line, inclusive. Locate
785be1b6298010956622771c870ab3cd8ca57a2faaron * 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
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * document (such as HEADER.gif) might get multiviewed as the result
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * 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)
785be1b6298010956622771c870ab3cd8ca57a2faaron{
785be1b6298010956622771c870ab3cd8ca57a2faaron autoindex_config_rec *d;
785be1b6298010956622771c870ab3cd8ca57a2faaron apr_table_t *hdrs = r->headers_in;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_file_t *f = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding request_rec *rr = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int emit_amble = 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int emit_H1 = 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *r_accept;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *r_accept_enc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If there's a header file, send a subrequest to look for it. If it's
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * found and html do the subrequest, otherwise handle it
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding 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
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
8f8ec0957334f50b7ac11359f90490ee467258eedreid if ((header_fname != NULL) && r->args) {
382fa07a63096c4a1aabfed36433ea5ac9c40ad0trawick header_fname = apr_pstrcat(r->pool, header_fname, "?", r->args, NULL);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick
e6cc28a5eb3371ba0c38e941855e71ff0054f50erbb if ((header_fname != NULL)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && (rr = ap_sub_req_lookup_uri(header_fname, r, r->output_filters))
785be1b6298010956622771c870ab3cd8ca57a2faaron && (rr->status == HTTP_OK)
785be1b6298010956622771c870ab3cd8ca57a2faaron && (rr->filename != NULL)
785be1b6298010956622771c870ab3cd8ca57a2faaron && (rr->finfo.filetype == APR_REG)) {
785be1b6298010956622771c870ab3cd8ca57a2faaron /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Check for the two specific cases we allow: text/html and
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * text/anything-else. The former is allowed to be processed for
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf * SSIs.
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (rr->content_type != NULL) {
066877f1a045103acfdd376d48cdd473c33f409bdougm if (response_is_html(rr)) {
e6cc28a5eb3371ba0c38e941855e71ff0054f50erbb ap_filter_t *f;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Hope everything will work... */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding emit_amble = 0;
785be1b6298010956622771c870ab3cd8ca57a2faaron emit_H1 = 0;
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron if (! suppress_amble) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding emit_preamble(r, emit_xhtml, title);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf /* This is a hack, but I can't find any better way to do this.
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf * The problem is that we have already created the sub-request,
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf * but we just inserted the OLD_WRITE filter, and the
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf * sub-request needs to pass its data through the OLD_WRITE
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * filter, or things go horribly wrong (missing data, data in
* the wrong order, etc). To fix it, if you create a
* sub-request and then insert the OLD_WRITE filter before you
* run the request, you need to make sure that the sub-request
* data goes through the OLD_WRITE filter. Just steal this
* code. The long-term solution is to remove the ap_r*
* functions.
*/
for (f=rr->output_filters;
f->frec != ap_subreq_core_filter_handle; f = f->next);
f->next = r->output_filters;
/*
* If there's a problem running the subrequest, display the
* preamble if we didn't do it before -- the header file
* didn't get displayed.
*/
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;
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[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_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 */
};