mod_autoindex.c revision 73ea536090d61caf6b149bf9d7abb3c0d95b69f1
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.
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * 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)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_DESC (1 << 6)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_PREAMBLE (1 << 7)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_COLSORT (1 << 8)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SUPPRESS_RULES (1 << 9)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define FOLDERS_FIRST (1 << 10)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define VERSION_SORT (1 << 11)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define TRACK_MODIFIED (1 << 12)
90211b595b36b22a529f9f68238f77fed273e08erbb#define FANCY_INDEXING (1 << 13)
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb#define TABLE_INDEXING (1 << 14)
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb#define IGNORE_CLIENT (1 << 15)
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb#define IGNORE_CASE (1 << 16)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define EMIT_XHTML (1 << 17)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define SHOW_FORBIDDEN (1 << 18)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define ADDALTCLASS (1 << 19)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_NOADJUST 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_ADJUST 1
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_UNSET 2
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Define keys for sorting.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
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/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * These are the dimensions of the default icons supplied with Apache.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#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
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstruct item {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *type;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *apply_to;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *apply_path;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *data;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct ai_desc_t {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding 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
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/*
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb * This routine puts the standard HTML header at the top of the index page.
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb * 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;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb &autoindex_module);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (xhtml) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, DOCTYPE_XHTML_1_0T,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding " <head>\n <title>Index of ", title,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "</title>\n", NULL);
07fcce220d1d0801bd38de5a85af72668c9761e0trawick } else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, DOCTYPE_HTML_3_2,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb "<html>\n <head>\n"
ec727afb817df0e5202135278c0d2902923cc980stoddard " <title>Index of ", title,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb "</title>\n", NULL);
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb }
ec727afb817df0e5202135278c0d2902923cc980stoddard
ec727afb817df0e5202135278c0d2902923cc980stoddard if (d->style_sheet != NULL) {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb ap_rvputs(r, " <link rel=\"stylesheet\" href=\"", d->style_sheet,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb "\" type=\"text/css\"", xhtml ? " />\n" : ">\n", NULL);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (d->head_insert != NULL) {
f285a4a0695a101af2c2af5257fd660f7fd8affdrbb ap_rputs(d->head_insert, r);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb ap_rvputs(r, " </head>\n <body>\n", NULL);
99b130dd1f797c0acf3ffa960b3c9acefd29f0fcrbb}
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbbstatic void push_item(apr_array_header_t *arr, char *type, const char *to,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb const char *path, const char *data)
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb{
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb struct item *p = (struct item *) apr_array_push(arr);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (!to) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding to = "";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb if (!path) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding path = "";
061c3874622b67beff724876b9bd1b1f291f2eaafielding }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p->type = type;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p->data = data ? apr_pstrdup(arr->pool, data) : NULL;
9ede6357edc9aff1fb2f7edebefab473673298aarbb p->apply_path = apr_pstrcat(arr->pool, path, "*", NULL);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if ((type == BY_PATH) && (!ap_is_matchexp(to))) {
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb p->apply_to = apr_pstrcat(arr->pool, "*", to, NULL);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (to) {
2b484455736f4c30447aa852764f53282cbeb5ddrbb p->apply_to = apr_pstrdup(arr->pool, to);
2b484455736f4c30447aa852764f53282cbeb5ddrbb }
2b484455736f4c30447aa852764f53282cbeb5ddrbb else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p->apply_to = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const char *add_alt(cmd_parms *cmd, void *d, const char *alt,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *to)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (cmd->info == BY_PATH) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!strcmp(to, "**DIRECTORY**")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding to = "^^DIRECTORY^^";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (cmd->info == BY_ENCODING) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *tmp = apr_pstrdup(cmd->pool, to);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_str_tolower(tmp);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding to = tmp;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding push_item(((autoindex_config_rec *) d)->alt_list, cmd->info, to,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding cmd->path, alt);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const char *add_icon(cmd_parms *cmd, void *d, const char *icon,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *to)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *iconbak = apr_pstrdup(cmd->pool, icon);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
061c3874622b67beff724876b9bd1b1f291f2eaafielding if (icon[0] == '(') {
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj char *alt;
95ed69df3d43a7d2758720bad8950f07587bdeb9bjh char *cl = strchr(iconbak, ')');
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2b484455736f4c30447aa852764f53282cbeb5ddrbb if (cl == NULL) {
2b484455736f4c30447aa852764f53282cbeb5ddrbb return "missing closing paren";
2b484455736f4c30447aa852764f53282cbeb5ddrbb }
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) {
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb if (!strcmp(to, "**DIRECTORY**")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding to = "^^DIRECTORY^^";
4e1e8abb2a6e588366a4680b039b460fc5fe1ccdstoddard }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (cmd->info == BY_ENCODING) {
40303323ae9960bd38a0f03d2c10e897a7badd88rbb char *tmp = apr_pstrdup(cmd->pool, to);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_str_tolower(tmp);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding to = tmp;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding push_item(((autoindex_config_rec *) d)->icon_list, cmd->info, to,
c57161db43fe4cf5a62758d7d0834675e59cad0astoddard cmd->path, iconbak);
5914b312b3377f0275f95487bc9557d7c93e0678stoddard return NULL;
40303323ae9960bd38a0f03d2c10e897a7badd88rbb}
02ecbdc58dc450237cba13a3982bf0b3743d539crbb
4e1e8abb2a6e588366a4680b039b460fc5fe1ccdstoddard/*
ec727afb817df0e5202135278c0d2902923cc980stoddard * Add description text for a filename pattern. If the pattern has
ec727afb817df0e5202135278c0d2902923cc980stoddard * wildcards already (or we need to add them), add leading and
ec727afb817df0e5202135278c0d2902923cc980stoddard * trailing wildcards to it to ensure substring processing. If the
ec727afb817df0e5202135278c0d2902923cc980stoddard * pattern contains a '/' anywhere, force wildcard matching mode,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * add a slash to the prefix so that "bar/bletch" won't be matched
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * 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.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
0942697a9b5de44865676345a3828741c827efe6rbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Absent a strcasestr() function, we have to force wildcards on
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * systems for which "AAA" and "aaa" mean the same file.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb#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
9ede6357edc9aff1fb2f7edebefab473673298aarbb || desc_entry->full_path
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb || apr_fnmatch_test(to));
40303323ae9960bd38a0f03d2c10e897a7badd88rbb if (desc_entry->wildcards) {
4e1e8abb2a6e588366a4680b039b460fc5fe1ccdstoddard prefix = desc_entry->full_path ? "*/" : "*";
02ecbdc58dc450237cba13a3982bf0b3743d539crbb desc_entry->pattern = apr_pstrcat(dcfg->desc_list->pool,
40303323ae9960bd38a0f03d2c10e897a7badd88rbb prefix, to, "*", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
0942697a9b5de44865676345a3828741c827efe6rbb desc_entry->pattern = apr_pstrdup(dcfg->desc_list->pool, to);
0942697a9b5de44865676345a3828741c827efe6rbb }
3597d6b10c88c252f156fe8061b659a38dea38c2rbb desc_entry->description = apr_pstrdup(dcfg->desc_list->pool, desc);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const char *add_ignore(cmd_parms *cmd, void *d, const char *ext)
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding push_item(((autoindex_config_rec *) d)->ign_list, 0, ext, cmd->path, NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const char *add_opts(cmd_parms *cmd, void *d, int argc, char *const argv[])
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int i;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *w;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_int32_t opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_int32_t opts_add;
40303323ae9960bd38a0f03d2c10e897a7badd88rbb apr_int32_t opts_remove;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char action;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding autoindex_config_rec *d_cfg = (autoindex_config_rec *) d;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding opts = d_cfg->opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding opts_add = d_cfg->incremented_opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding opts_remove = d_cfg->decremented_opts;
2b484455736f4c30447aa852764f53282cbeb5ddrbb
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")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = FANCY_INDEXING;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "FoldersFirst")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = FOLDERS_FIRST;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "HTMLTable")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = TABLE_INDEXING;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "IconsAreLinks")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = ICONS_ARE_LINKS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "IgnoreCase")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = IGNORE_CASE;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "IgnoreClient")) {
2b484455736f4c30447aa852764f53282cbeb5ddrbb option = IGNORE_CLIENT;
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet }
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet else if (!strcasecmp(w, "ScanHTMLTitles")) {
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet option = SCAN_HTML_TITLES;
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet }
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet else if (!strcasecmp(w, "SuppressColumnSorting")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SUPPRESS_COLSORT;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "SuppressDescription")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SUPPRESS_DESC;
2b484455736f4c30447aa852764f53282cbeb5ddrbb }
2b484455736f4c30447aa852764f53282cbeb5ddrbb else if (!strcasecmp(w, "SuppressHTMLPreamble")) {
2b484455736f4c30447aa852764f53282cbeb5ddrbb option = SUPPRESS_PREAMBLE;
2b484455736f4c30447aa852764f53282cbeb5ddrbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "SuppressIcon")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SUPPRESS_ICON;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "SuppressLastModified")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SUPPRESS_LAST_MOD;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "SuppressSize")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SUPPRESS_SIZE;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
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")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = VERSION_SORT;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "XHTML")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = EMIT_XHTML;
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "ShowForbidden")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = SHOW_FORBIDDEN;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
fd47393e4c08a1515601cb1f1e8deddf4163e858martin else if (!strcasecmp(w, "AddAltClass")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding option = ADDALTCLASS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "None")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action != '\0') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Cannot combine '+' or '-' with 'None' keyword";
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding opts = NO_OPTIONS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding opts_add = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding opts_remove = 0;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb }
3597d6b10c88c252f156fe8061b659a38dea38c2rbb else if (!strcasecmp(w, "IconWidth")) {
3597d6b10c88c252f156fe8061b659a38dea38c2rbb if (action != '-') {
3597d6b10c88c252f156fe8061b659a38dea38c2rbb d_cfg->icon_width = DEFAULT_ICON_WIDTH;
3597d6b10c88c252f156fe8061b659a38dea38c2rbb }
3597d6b10c88c252f156fe8061b659a38dea38c2rbb else {
3597d6b10c88c252f156fe8061b659a38dea38c2rbb d_cfg->icon_width = 0;
3597d6b10c88c252f156fe8061b659a38dea38c2rbb }
3597d6b10c88c252f156fe8061b659a38dea38c2rbb }
3597d6b10c88c252f156fe8061b659a38dea38c2rbb else if (!strncasecmp(w, "IconWidth=", 10)) {
3597d6b10c88c252f156fe8061b659a38dea38c2rbb if (action == '-') {
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj return "Cannot combine '-' with IconWidth=n";
3597d6b10c88c252f156fe8061b659a38dea38c2rbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->icon_width = atoi(&w[10]);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj else if (!strcasecmp(w, "IconHeight")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action != '-') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->icon_height = DEFAULT_ICON_HEIGHT;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj else {
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj d_cfg->icon_height = 0;
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj }
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj }
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj else if (!strncasecmp(w, "IconHeight=", 11)) {
70a2c0407879c11b29adc782d1665a0131f30b3frbb if (action == '-') {
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb return "Cannot combine '-' with IconHeight=n";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->icon_height = atoi(&w[11]);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "NameWidth")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action != '-') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "NameWidth with no value may only appear as "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "'-NameWidth'";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->name_width = DEFAULT_NAME_WIDTH;
0942697a9b5de44865676345a3828741c827efe6rbb d_cfg->name_adjust = K_NOADJUST;
0942697a9b5de44865676345a3828741c827efe6rbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strncasecmp(w, "NameWidth=", 10)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action == '-') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Cannot combine '-' with NameWidth=n";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
3597d6b10c88c252f156fe8061b659a38dea38c2rbb if (w[10] == '*') {
3597d6b10c88c252f156fe8061b659a38dea38c2rbb d_cfg->name_adjust = K_ADJUST;
3597d6b10c88c252f156fe8061b659a38dea38c2rbb }
3597d6b10c88c252f156fe8061b659a38dea38c2rbb else {
3597d6b10c88c252f156fe8061b659a38dea38c2rbb int width = atoi(&w[10]);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb
3597d6b10c88c252f156fe8061b659a38dea38c2rbb if (width && (width < 5)) {
3597d6b10c88c252f156fe8061b659a38dea38c2rbb return "NameWidth value must be greater than 5";
3597d6b10c88c252f156fe8061b659a38dea38c2rbb }
3597d6b10c88c252f156fe8061b659a38dea38c2rbb d_cfg->name_width = width;
3597d6b10c88c252f156fe8061b659a38dea38c2rbb d_cfg->name_adjust = K_NOADJUST;
3597d6b10c88c252f156fe8061b659a38dea38c2rbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "DescriptionWidth")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action != '-') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "DescriptionWidth with no value may only appear as "
0942697a9b5de44865676345a3828741c827efe6rbb "'-DescriptionWidth'";
0942697a9b5de44865676345a3828741c827efe6rbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->desc_width = DEFAULT_DESC_WIDTH;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->desc_adjust = K_NOADJUST;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strncasecmp(w, "DescriptionWidth=", 17)) {
3597d6b10c88c252f156fe8061b659a38dea38c2rbb if (action == '-') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Cannot combine '-' with DescriptionWidth=n";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (w[17] == '*') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->desc_adjust = K_ADJUST;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int width = atoi(&w[17]);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (width && (width < 12)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "DescriptionWidth value must be greater than 12";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->desc_width = width;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->desc_adjust = K_NOADJUST;
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim }
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strncasecmp(w, "Type=", 5)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->ctype = apr_pstrdup(cmd->pool, &w[5]);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strncasecmp(w, "Charset=", 8)) {
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb d_cfg->charset = apr_pstrdup(cmd->pool, &w[8]);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
9ede6357edc9aff1fb2f7edebefab473673298aarbb else {
d96aa158770d3f83cb59cf0f2f7402e175f7dfccrbb return "Invalid directory indexing option";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (action == '\0') {
a8577c2083e1fe27d78bf198668eb8bc2687d060martin opts |= option;
a8577c2083e1fe27d78bf198668eb8bc2687d060martin opts_add = 0;
a8577c2083e1fe27d78bf198668eb8bc2687d060martin opts_remove = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (action == '+') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding opts_add |= option;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding opts_remove &= ~option;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
d96aa158770d3f83cb59cf0f2f7402e175f7dfccrbb opts_remove |= option;
061c3874622b67beff724876b9bd1b1f291f2eaafielding opts_add &= ~option;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((opts & NO_OPTIONS) && (opts & ~NO_OPTIONS)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Cannot combine other IndexOptions keywords with 'None'";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->incremented_opts = opts_add;
0942697a9b5de44865676345a3828741c827efe6rbb d_cfg->decremented_opts = opts_remove;
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb d_cfg->opts = opts;
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb return NULL;
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb}
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const char *set_default_order(cmd_parms *cmd, void *m,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *direction, const char *key)
a8577c2083e1fe27d78bf198668eb8bc2687d060martin{
a8577c2083e1fe27d78bf198668eb8bc2687d060martin autoindex_config_rec *d_cfg = (autoindex_config_rec *) m;
a8577c2083e1fe27d78bf198668eb8bc2687d060martin
a8577c2083e1fe27d78bf198668eb8bc2687d060martin if (!strcasecmp(direction, "Ascending")) {
a5b7afe9f897d699f46d0b668b4c87936b4628f7manoj d_cfg->default_direction = D_ASCENDING;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2b484455736f4c30447aa852764f53282cbeb5ddrbb else if (!strcasecmp(direction, "Descending")) {
2b484455736f4c30447aa852764f53282cbeb5ddrbb d_cfg->default_direction = D_DESCENDING;
2b484455736f4c30447aa852764f53282cbeb5ddrbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "First keyword must be 'Ascending' or 'Descending'";
a8577c2083e1fe27d78bf198668eb8bc2687d060martin }
a8577c2083e1fe27d78bf198668eb8bc2687d060martin
a8577c2083e1fe27d78bf198668eb8bc2687d060martin if (!strcasecmp(key, "Name")) {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb d_cfg->default_keyid = K_NAME;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(key, "Date")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->default_keyid = K_LAST_MOD;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(key, "Size")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->default_keyid = K_SIZE;
0942697a9b5de44865676345a3828741c827efe6rbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(key, "Description")) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d_cfg->default_keyid = K_DESC;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Second keyword must be 'Name', 'Date', 'Size', or "
0942697a9b5de44865676345a3828741c827efe6rbb "'Description'";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define DIR_CMD_PERMS OR_INDEXES
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
3597d6b10c88c252f156fe8061b659a38dea38c2rbbstatic 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"),
0942697a9b5de44865676345a3828741c827efe6rbb 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,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "alternate descriptive text followed by one or more MIME "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "types"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE2("AddAltByEncoding", add_alt, BY_ENCODING, DIR_CMD_PERMS,
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet "alternate descriptive text followed by one or more "
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet "content encodings"),
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet AP_INIT_TAKE_ARGV("IndexOptions", add_opts, NULL, DIR_CMD_PERMS,
2b484455736f4c30447aa852764f53282cbeb5ddrbb "one or more index options [+|-][]"),
2b484455736f4c30447aa852764f53282cbeb5ddrbb AP_INIT_TAKE2("IndexOrderDefault", set_default_order, NULL, DIR_CMD_PERMS,
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet "{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_ITERATE2("AddDescription", add_desc, BY_PATH, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "Descriptive text followed by one or more filenames"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_TAKE1("HeaderName", ap_set_string_slot,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (void *)APR_OFFSETOF(autoindex_config_rec, header),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DIR_CMD_PERMS, "a filename"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_TAKE1("ReadmeName", ap_set_string_slot,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (void *)APR_OFFSETOF(autoindex_config_rec, readme),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DIR_CMD_PERMS, "a filename"),
aa811cad2eb3fc01d17a5c8eba274b915ab8cd20manoj AP_INIT_RAW_ARGS("FancyIndexing", ap_set_deprecated, NULL, OR_ALL,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "The FancyIndexing directive is no longer supported. "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "Use IndexOptions FancyIndexing."),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_TAKE1("DefaultIcon", ap_set_string_slot,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (void *)APR_OFFSETOF(autoindex_config_rec, default_icon),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DIR_CMD_PERMS, "an icon URL"),
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb AP_INIT_TAKE1("IndexStyleSheet", ap_set_string_slot,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb (void *)APR_OFFSETOF(autoindex_config_rec, style_sheet),
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb DIR_CMD_PERMS, "URL to style sheet"),
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb AP_INIT_TAKE1("IndexHeadInsert", ap_set_string_slot,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb (void *)APR_OFFSETOF(autoindex_config_rec, head_insert),
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb DIR_CMD_PERMS, "String to insert in HTML HEAD section"),
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb {NULL}
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb};
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbbstatic void *create_autoindex_config(apr_pool_t *p, char *dummy)
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb{
07fcce220d1d0801bd38de5a85af72668c9761e0trawick autoindex_config_rec *new =
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
2a7d0035b5594ddc0907a9cc545e14ae5140c541manoj
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb new->icon_width = 0;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb new->icon_height = 0;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb new->name_width = DEFAULT_NAME_WIDTH;
2b484455736f4c30447aa852764f53282cbeb5ddrbb new->name_adjust = K_UNSET;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb new->desc_width = DEFAULT_DESC_WIDTH;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb new->desc_adjust = K_UNSET;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb new->icon_list = apr_array_make(p, 4, sizeof(struct item));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->alt_list = apr_array_make(p, 4, sizeof(struct item));
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb new->desc_list = apr_array_make(p, 4, sizeof(ai_desc_t));
f285a4a0695a101af2c2af5257fd660f7fd8affdrbb new->ign_list = apr_array_make(p, 4, sizeof(struct item));
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb new->opts = 0;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb new->incremented_opts = 0;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb new->decremented_opts = 0;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb new->default_keyid = '\0';
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb new->default_direction = '\0';
2a7d0035b5594ddc0907a9cc545e14ae5140c541manoj
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb return (void *) new;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbbstatic void *merge_autoindex_configs(apr_pool_t *p, void *basev, void *addv)
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb{
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb autoindex_config_rec *new;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding autoindex_config_rec *base = (autoindex_config_rec *) basev;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding autoindex_config_rec *add = (autoindex_config_rec *) addv;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new = (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->default_icon = add->default_icon ? add->default_icon
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding : base->default_icon;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->style_sheet = add->style_sheet ? add->style_sheet
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding : base->style_sheet;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->head_insert = add->head_insert ? add->head_insert
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding : base->head_insert;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->header = add->header ? add->header
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb : base->header;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->readme = add->readme ? add->readme
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding : base->readme;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->icon_height = add->icon_height ? add->icon_height : base->icon_height;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->icon_width = add->icon_width ? add->icon_width : base->icon_width;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb new->ctype = add->ctype ? add->ctype : base->ctype;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->charset = add->charset ? add->charset : base->charset;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2b484455736f4c30447aa852764f53282cbeb5ddrbb new->alt_list = apr_array_append(p, add->alt_list, base->alt_list);
2b484455736f4c30447aa852764f53282cbeb5ddrbb new->ign_list = apr_array_append(p, add->ign_list, base->ign_list);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->desc_list = apr_array_append(p, add->desc_list, base->desc_list);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->icon_list = apr_array_append(p, add->icon_list, base->icon_list);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (add->opts & NO_OPTIONS) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If the current directory says 'no options' then we also
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb * clear any incremental mods from being inheritable further down.
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->opts = NO_OPTIONS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->incremented_opts = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->decremented_opts = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb /*
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb * If there were any nonincremental options selected for
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * this directory, they dominate and we don't inherit *anything.*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Contrariwise, we *do* inherit if the only settings here are
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * incremental ones.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (add->opts == 0) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->incremented_opts = (base->incremented_opts
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding | add->incremented_opts)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding & ~add->decremented_opts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->decremented_opts = (base->decremented_opts
2a7d0035b5594ddc0907a9cc545e14ae5140c541manoj | add->decremented_opts);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * We may have incremental settings, so make sure we don't
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * inadvertently inherit an IndexOptions None from above.
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb */
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb new->opts = (base->opts & ~NO_OPTIONS);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb /*
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb * There are local nonincremental settings, which clear
2a7d0035b5594ddc0907a9cc545e14ae5140c541manoj * all inheritance from above. They *are* the new base settings.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->opts = add->opts;;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2a7d0035b5594ddc0907a9cc545e14ae5140c541manoj /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * We're guaranteed that there'll be no overlap between
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the add-options and the remove-options.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb new->opts |= new->incremented_opts;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb new->opts &= ~new->decremented_opts;
2a7d0035b5594ddc0907a9cc545e14ae5140c541manoj }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Inherit the NameWidth settings if there aren't any specific to
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb * the new location; otherwise we'll end up using the defaults set in the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * config-rec creation routine.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (add->name_adjust == K_UNSET) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->name_width = base->name_width;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->name_adjust = base->name_adjust;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb else {
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb new->name_width = add->name_width;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->name_adjust = add->name_adjust;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Likewise for DescriptionWidth.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (add->desc_adjust == K_UNSET) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->desc_width = base->desc_width;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb new->desc_adjust = base->desc_adjust;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->desc_width = add->desc_width;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->desc_adjust = add->desc_adjust;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->default_keyid = add->default_keyid ? add->default_keyid
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb : base->default_keyid;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb new->default_direction = add->default_direction ? add->default_direction
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb : base->default_direction;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return new;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb}
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb/****************************************************************
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Looking things up in config entries...
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* Structure used to hold entries when we're actually building an index */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
9ede6357edc9aff1fb2f7edebefab473673298aarbbstruct ent {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb char *name;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *icon;
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb char *alt;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb char *desc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_off_t size;
2b484455736f4c30447aa852764f53282cbeb5ddrbb apr_time_t lm;
2b484455736f4c30447aa852764f53282cbeb5ddrbb struct ent *next;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int ascending, ignore_case, version_sort;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char key;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb int isdir;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbbstatic char *find_item(const char *content_type, const char *content_encoding,
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb char *path, apr_array_header_t *list, int path_only)
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding struct item *items = (struct item *) list->elts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int i;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < list->nelts; ++i) {
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb struct item *p = &items[i];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((path[0] == '^') || (!ap_strcmp_match(path, p->apply_path))) {
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb if (!*(p->apply_to)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return p->data;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb }
else if (p->type == BY_PATH || path[0] == '^') {
if (!ap_strcmp_match(path, p->apply_to)) {
return p->data;
}
}
else if (!path_only) {
if (!content_encoding) {
if (p->type == BY_TYPE) {
if (content_type
&& !ap_strcasecmp_match(content_type,
p->apply_to)) {
return p->data;
}
}
}
else {
if (p->type == BY_ENCODING) {
if (!ap_strcasecmp_match(content_encoding,
p->apply_to)) {
return p->data;
}
}
}
}
}
}
return NULL;
}
static char *find_item_by_request(request_rec *r, apr_array_header_t *list, int path_only)
{
return find_item(ap_field_noparam(r->pool, r->content_type),
r->content_encoding, r->filename, list, path_only);
}
#define find_icon(d,p,t) find_item_by_request(p,d->icon_list,t)
#define find_alt(d,p,t) find_item_by_request(p,d->alt_list,t)
#define find_default_icon(d,n) find_item(NULL, NULL, n, d->icon_list, 1)
#define find_default_alt(d,n) find_item(NULL, NULL, n, d->alt_list, 1)
/*
* Look through the list of pattern/description pairs and return the first one
* if any) that matches the filename in the request. If multiple patterns
* match, only the first one is used; since the order in the array is the
* same as the order in which directives were processed, earlier matching
* directives will dominate.
*/
#ifdef CASE_BLIND_FILESYSTEM
#define MATCH_FLAGS APR_FNM_CASE_BLIND
#else
#define MATCH_FLAGS 0
#endif
static char *find_desc(autoindex_config_rec *dcfg, const char *filename_full)
{
int i;
ai_desc_t *list = (ai_desc_t *) dcfg->desc_list->elts;
const char *filename_only;
const char *filename;
/*
* If the filename includes a path, extract just the name itself
* for the simple matches.
*/
if ((filename_only = ap_strrchr_c(filename_full, '/')) == NULL) {
filename_only = filename_full;
}
else {
filename_only++;
}
for (i = 0; i < dcfg->desc_list->nelts; ++i) {
ai_desc_t *tuple = &list[i];
int found;
/*
* Only use the full-path filename if the pattern contains '/'s.
*/
filename = (tuple->full_path) ? filename_full : filename_only;
/*
* Make the comparison using the cheapest method; only do
* wildcard checking if we must.
*/
if (tuple->wildcards) {
found = (apr_fnmatch(tuple->pattern, filename, MATCH_FLAGS) == 0);
}
else {
found = (ap_strstr_c(filename, tuple->pattern) != NULL);
}
if (found) {
return tuple->description;
}
}
return NULL;
}
static int ignore_entry(autoindex_config_rec *d, char *path)
{
apr_array_header_t *list = d->ign_list;
struct item *items = (struct item *) list->elts;
char *tt;
int i;
if ((tt = strrchr(path, '/')) == NULL) {
tt = path;
}
else {
tt++;
}
for (i = 0; i < list->nelts; ++i) {
struct item *p = &items[i];
char *ap;
if ((ap = strrchr(p->apply_to, '/')) == NULL) {
ap = p->apply_to;
}
else {
ap++;
}
#ifndef CASE_BLIND_FILESYSTEM
if (!ap_strcmp_match(path, p->apply_path)
&& !ap_strcmp_match(tt, ap)) {
return 1;
}
#else /* !CASE_BLIND_FILESYSTEM */
/*
* 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 (!ap_strcasecmp_match(path, p->apply_path)
&& !ap_strcasecmp_match(tt, ap)) {
return 1;
}
#endif /* !CASE_BLIND_FILESYSTEM */
}
return 0;
}
/*****************************************************************
*
* Actually generating output
*/
/*
* Elements of the emitted document:
* Preamble
* Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
* succeeds for the (content_type == text/html) header file.
* Header file
* Emitted if found (and able).
* H1 tag line
* Emitted if a header file is NOT emitted.
* Directory stuff
* Always emitted.
* HR
* Emitted if FANCY_INDEXING is set.
* Readme file
* Emitted if found (and able).
* ServerSig
* Emitted if ServerSignature is not Off AND a readme file
* is NOT emitted.
* Postamble
* Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
* succeeds for the (content_type == text/html) readme file.
*/
/*
* emit a plain text file
*/
static void do_emit_plain(request_rec *r, apr_file_t *f)
{
char buf[AP_IOBUFSIZE + 1];
int ch;
apr_size_t i, c, n;
apr_status_t rv;
ap_rputs("<pre>\n", r);
while (!apr_file_eof(f)) {
do {
n = sizeof(char) * AP_IOBUFSIZE;
rv = apr_file_read(f, buf, &n);
} while (APR_STATUS_IS_EINTR(rv));
if (n == 0 || rv != APR_SUCCESS) {
/* ###: better error here? */
break;
}
buf[n] = '\0';
c = 0;
while (c < n) {
for (i = c; i < n; i++) {
if (buf[i] == '<' || buf[i] == '>' || buf[i] == '&') {
break;
}
}
ch = buf[i];
buf[i] = '\0';
ap_rputs(&buf[c], r);
if (ch == '<') {
ap_rputs("&lt;", r);
}
else if (ch == '>') {
ap_rputs("&gt;", r);
}
else if (ch == '&') {
ap_rputs("&amp;", r);
}
c = i + 1;
}
}
ap_rputs("</pre>\n", r);
}
/*
* Handle the preamble through the H1 tag line, 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 HEADER.gif) might get multiviewed as the result
* instead of a text document, meaning nothing will be displayed, but
* oh well.
*/
static void emit_head(request_rec *r, char *header_fname, int suppress_amble,
int emit_xhtml, char *title)
{
apr_table_t *hdrs = r->headers_in;
apr_file_t *f = NULL;
request_rec *rr = NULL;
int emit_amble = 1;
int emit_H1 = 1;
const char *r_accept;
const char *r_accept_enc;
/*
* If there's a header file, send a subrequest to look for it. If it's
* found and html do the subrequest, otherwise handle it
*/
r_accept = apr_table_get(hdrs, "Accept");
r_accept_enc = apr_table_get(hdrs, "Accept-Encoding");
apr_table_setn(hdrs, "Accept", "text/html, text/plain");
apr_table_unset(hdrs, "Accept-Encoding");
if ((header_fname != NULL) && r->args) {
header_fname = apr_pstrcat(r->pool, header_fname, "?", r->args, NULL);
}
if ((header_fname != NULL)
&& (rr = ap_sub_req_lookup_uri(header_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;
/* Hope everything will work... */
emit_amble = 0;
emit_H1 = 0;
if (! suppress_amble) {
emit_preamble(r, emit_xhtml, title);
}
/* This is a hack, but I can't find any better way to do this.
* The problem is that we have already created the sub-request,
* but we just inserted the OLD_WRITE filter, and the
* sub-request needs to pass its data through the OLD_WRITE
* 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);
}
autoindex_config_rec *d;
d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config, &autoindex_module);
if (emit_H1) {
if (d->style_sheet != NULL) {
/* Insert style id if stylesheet used */
ap_rvputs(r, " <h1 id=\"indextitle\">Index of ", title, "</h1>\n", NULL);
} else {
ap_rvputs(r, "<h1>Index of ", title, "</h1>\n", NULL);
}
}
if (rr != NULL) {
ap_destroy_sub_req(rr);
}
}
/*
* Handle the Readme file through the postamble, inclusive. Locate
* the file with a subrequests. Process text/html documents by actually
* running the subrequest; text/xxx documents get copied verbatim,
* and any other content type is ignored. This means that a non-text
* document (such as FOOTER.gif) might get multiviewed as the result
* instead of a text document, meaning nothing will be displayed, but
* oh well.
*/
static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
{
apr_file_t *f = NULL;
request_rec *rr = NULL;
int suppress_post = 0;
int suppress_sig = 0;
/*
* If there's a readme file, send a subrequest to look for it. If it's
* found and a text file, handle it -- otherwise fall through and
* pretend there's nothing there.
*/
if ((readme_fname != NULL)
&& (rr = ap_sub_req_lookup_uri(readme_fname, r, r->output_filters))
&& (rr->status == HTTP_OK)
&& (rr->filename != NULL)
&& rr->finfo.filetype == APR_REG) {
/*
* Check for the two specific cases we allow: text/html and
* text/anything-else. The former is allowed to be processed for
* SSIs.
*/
if (rr->content_type != NULL) {
if (response_is_html(rr)) {
ap_filter_t *f;
for (f=rr->output_filters;
f->frec != ap_subreq_core_filter_handle; f = f->next);
f->next = r->output_filters;
if (ap_run_sub_req(rr) == OK) {
/* worked... */
suppress_sig = 1;
suppress_post = suppress_amble;
}
}
else if (!strncasecmp("text/", rr->content_type, 5)) {
/*
* If we can open the file, suppress the signature.
*/
if (apr_file_open(&f, rr->filename, APR_READ,
APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
do_emit_plain(r, f);
apr_file_close(f);
suppress_sig = 1;
}
}
}
}
if (!suppress_sig) {
ap_rputs(ap_psignature("", r), r);
}
if (!suppress_post) {
ap_rputs("</body></html>\n", r);
}
if (rr != NULL) {
ap_destroy_sub_req(rr);
}
}
static char *find_title(request_rec *r)
{
char titlebuf[MAX_STRING_LEN], *find = "<title>";
apr_file_t *thefile = NULL;
int x, y, p;
apr_size_t n;
if (r->status != HTTP_OK) {
return NULL;
}
if ((r->content_type != NULL)
&& (response_is_html(r)
|| !strcmp(r->content_type, INCLUDES_MAGIC_TYPE))
&& !r->content_encoding) {
if (apr_file_open(&thefile, r->filename, APR_READ,
APR_OS_DEFAULT, r->pool) != APR_SUCCESS) {
return NULL;
}
n = sizeof(char) * (MAX_STRING_LEN - 1);
apr_file_read(thefile, titlebuf, &n);
if (n <= 0) {
apr_file_close(thefile);
return NULL;
}
titlebuf[n] = '\0';
for (x = 0, p = 0; titlebuf[x]; x++) {
if (apr_tolower(titlebuf[x]) == find[p]) {
if (!find[++p]) {
if ((p = ap_ind(&titlebuf[++x], '<')) != -1) {
titlebuf[x + p] = '\0';
}
/* Scan for line breaks for Tanmoy's secretary */
for (y = x; titlebuf[y]; y++) {
if ((titlebuf[y] == CR) || (titlebuf[y] == LF)) {
if (y == x) {
x++;
}
else {
titlebuf[y] = ' ';
}
}
}
apr_file_close(thefile);
return apr_pstrdup(r->pool, &titlebuf[x]);
}
}
else {
p = 0;
}
}
apr_file_close(thefile);
}
return NULL;
}
static struct ent *make_parent_entry(apr_int32_t autoindex_opts,
autoindex_config_rec *d,
request_rec *r, char keyid,
char direction)
{
struct ent *p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent));
char *testpath;
/*
* p->name is now the true parent URI.
* testpath is a crafted lie, so that the syntax '/some/..'
* (or simply '..')be used to describe 'up' from '/some/'
* when processeing IndexIgnore, and Icon|Alt|Desc configs.
*/
/* The output has always been to the parent. Don't make ourself
* our own parent (worthless cyclical reference).
*/
if (!(p->name = ap_make_full_path(r->pool, r->uri, "../"))) {
return (NULL);
}
ap_getparents(p->name);
if (!*p->name) {
return (NULL);
}
/* IndexIgnore has always compared "/thispath/.." */
testpath = ap_make_full_path(r->pool, r->filename, "..");
if (ignore_entry(d, testpath)) {
return (NULL);
}
p->size = -1;
p->lm = -1;
p->key = apr_toupper(keyid);
p->ascending = (apr_toupper(direction) == D_ASCENDING);
p->version_sort = autoindex_opts & VERSION_SORT;
if (autoindex_opts & FANCY_INDEXING) {
if (!(p->icon = find_default_icon(d, testpath))) {
p->icon = find_default_icon(d, "^^DIRECTORY^^");
}
if (!(p->alt = find_default_alt(d, testpath))) {
if (!(p->alt = find_default_alt(d, "^^DIRECTORY^^"))) {
/* Special alt text for parent dir to distinguish it from other directories
this is essential when trying to style this dir entry via AddAltClass */
p->alt = "PARENTDIR";
}
}
p->desc = find_desc(d, testpath);
}
return p;
}
static struct ent *make_autoindex_entry(const apr_finfo_t *dirent,
int autoindex_opts,
autoindex_config_rec *d,
request_rec *r, char keyid,
char direction,
const char *pattern)
{
request_rec *rr;
struct ent *p;
int show_forbidden = 0;
/* Dot is ignored, Parent is handled by make_parent_entry() */
if ((dirent->name[0] == '.') && (!dirent->name[1]
|| ((dirent->name[1] == '.') && !dirent->name[2])))
return (NULL);
/*
* On some platforms, the match must be case-blind. This is really
* a factor of the filesystem involved, but we can't detect that
* reliably - so we have to granularise at the OS level.
*/
if (pattern && (apr_fnmatch(pattern, dirent->name,
APR_FNM_NOESCAPE | APR_FNM_PERIOD
#ifdef CASE_BLIND_FILESYSTEM
| APR_FNM_CASE_BLIND
#endif
)
!= APR_SUCCESS)) {
return (NULL);
}
if (ignore_entry(d, ap_make_full_path(r->pool,
r->filename, dirent->name))) {
return (NULL);
}
if (!(rr = ap_sub_req_lookup_dirent(dirent, r, AP_SUBREQ_NO_ARGS, NULL))) {
return (NULL);
}
if((autoindex_opts & SHOW_FORBIDDEN)
&& (rr->status == HTTP_UNAUTHORIZED || rr->status == HTTP_FORBIDDEN)) {
show_forbidden = 1;
}
if ((rr->finfo.filetype != APR_DIR && rr->finfo.filetype != APR_REG)
|| !(rr->status == OK || ap_is_HTTP_SUCCESS(rr->status)
|| ap_is_HTTP_REDIRECT(rr->status)
|| show_forbidden == 1)) {
ap_destroy_sub_req(rr);
return (NULL);
}
p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent));
if (dirent->filetype == APR_DIR) {
p->name = apr_pstrcat(r->pool, dirent->name, "/", NULL);
}
else {
p->name = apr_pstrdup(r->pool, dirent->name);
}
p->size = -1;
p->icon = NULL;
p->alt = NULL;
p->desc = NULL;
p->lm = -1;
p->isdir = 0;
p->key = apr_toupper(keyid);
p->ascending = (apr_toupper(direction) == D_ASCENDING);
p->version_sort = !!(autoindex_opts & VERSION_SORT);
p->ignore_case = !!(autoindex_opts & IGNORE_CASE);
if (autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING)) {
p->lm = rr->finfo.mtime;
if (dirent->filetype == APR_DIR) {
if (autoindex_opts & FOLDERS_FIRST) {
p->isdir = 1;
}
rr->filename = ap_make_dirstr_parent (rr->pool, rr->filename);
/* omit the trailing slash (1.3 compat) */
rr->filename[strlen(rr->filename) - 1] = '\0';
if (!(p->icon = find_icon(d, rr, 1))) {
p->icon = find_default_icon(d, "^^DIRECTORY^^");
}
if (!(p->alt = find_alt(d, rr, 1))) {
if (!(p->alt = find_default_alt(d, "^^DIRECTORY^^"))) {
p->alt = "DIR";
}
}
}
else {
p->icon = find_icon(d, rr, 0);
p->alt = find_alt(d, rr, 0);
p->size = rr->finfo.size;
}
p->desc = find_desc(d, rr->filename);
if ((!p->desc) && (autoindex_opts & SCAN_HTML_TITLES)) {
p->desc = apr_pstrdup(r->pool, find_title(rr));
}
}
ap_destroy_sub_req(rr);
/*
* We don't need to take any special action for the file size key.
* If we did, it would go here.
*/
if (keyid == K_LAST_MOD) {
if (p->lm < 0) {
p->lm = 0;
}
}
return (p);
}
static char *terminate_description(autoindex_config_rec *d, char *desc,
apr_int32_t autoindex_opts, int desc_width)
{
int maxsize = desc_width;
register int x;
/*
* If there's no DescriptionWidth in effect, default to the old
* behaviour of adjusting the description size depending upon
* what else is being displayed. Otherwise, stick with the
* setting.
*/
if (d->desc_adjust == K_UNSET) {
if (autoindex_opts & SUPPRESS_ICON) {
maxsize += 6;
}
if (autoindex_opts & SUPPRESS_LAST_MOD) {
maxsize += 19;
}
if (autoindex_opts & SUPPRESS_SIZE) {
maxsize += 7;
}
}
for (x = 0; desc[x] && ((maxsize > 0) || (desc[x] == '<')); x++) {
if (desc[x] == '<') {
while (desc[x] != '>') {
if (!desc[x]) {
maxsize = 0;
break;
}
++x;
}
}
else if (desc[x] == '&') {
/* entities like &auml; count as one character */
--maxsize;
for ( ; desc[x] != ';'; ++x) {
if (desc[x] == '\0') {
maxsize = 0;
break;
}
}
}
else {
--maxsize;
}
}
if (!maxsize && desc[x] != '\0') {
desc[x - 1] = '>'; /* Grump. */
desc[x] = '\0'; /* Double Grump! */
}
return desc;
}
/*
* Emit the anchor for the specified field. If a field is the key for the
* current request, the link changes its meaning to reverse the order when
* selected again. Non-active fields always start in ascending order.
*/
static void emit_link(request_rec *r, const char *anchor, char column,
char curkey, char curdirection,
const char *colargs, int nosort)
{
if (!nosort) {
char qvalue[9];
qvalue[0] = '?';
qvalue[1] = 'C';
qvalue[2] = '=';
qvalue[3] = column;
qvalue[4] = ';';
qvalue[5] = 'O';
qvalue[6] = '=';
/* reverse? */
qvalue[7] = ((curkey == column) && (curdirection == D_ASCENDING))
? D_DESCENDING : D_ASCENDING;
qvalue[8] = '\0';
ap_rvputs(r, "<a href=\"", qvalue, colargs ? colargs : "",
"\">", anchor, "</a>", NULL);
}
else {
ap_rputs(anchor, r);
}
}
static void output_directories(struct ent **ar, int n,
autoindex_config_rec *d, request_rec *r,
apr_int32_t autoindex_opts, char keyid,
char direction, const char *colargs)
{
int x;
apr_size_t rv;
char *name = r->uri;
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);
if (name[0] == '\0') {
name = "/";
}
name_width = d->name_width;
desc_width = d->desc_width;
if ((autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING))
== FANCY_INDEXING) {
if (d->name_adjust == K_ADJUST) {
for (x = 0; x < n; x++) {
int t = strlen(ar[x]->name);
if (t > name_width) {
name_width = t;
}
}
}
if (d->desc_adjust == K_ADJUST) {
for (x = 0; x < n; x++) {
if (ar[x]->desc != NULL) {
int t = strlen(ar[x]->desc);
if (t > desc_width) {
desc_width = t;
}
}
}
}
}
name_scratch = apr_palloc(r->pool, name_width + 1);
pad_scratch = apr_palloc(r->pool, name_width + 1);
memset(pad_scratch, ' ', name_width);
pad_scratch[name_width] = '\0';
if (autoindex_opts & TABLE_INDEXING) {
int cols = 1;
if (d->style_sheet != NULL) {
/* Emit table with style id */
ap_rputs(" <table id=\"indexlist\">\n <tr class=\"indexhead\">", r);
} else {
ap_rputs(" <table>\n <tr>", r);
}
if (!(autoindex_opts & SUPPRESS_ICON)) {
ap_rvputs(r, "<th", (d->style_sheet != NULL) ? " class=\"indexcolicon\">" : " valign=\"top\">", NULL);
if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
ap_rvputs(r, "<img src=\"", ap_escape_html(scratch, tp),
"\" alt=\"[ICO]\"", NULL);
if (d->icon_width) {
ap_rprintf(r, " width=\"%d\"", d->icon_width);
}
if (d->icon_height) {
ap_rprintf(r, " height=\"%d\"", d->icon_height);
}
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs("></th>", r);
}
else {
ap_rputs("&nbsp;</th>", r);
}
++cols;
}
ap_rvputs(r, "<th", (d->style_sheet != NULL) ? " class=\"indexcolname\">" : ">", NULL);
emit_link(r, "Name", K_NAME, keyid, direction,
colargs, static_columns);
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
ap_rvputs(r, "</th><th", (d->style_sheet != NULL) ? " class=\"indexcollastmod\">" : ">", NULL);
emit_link(r, "Last modified", K_LAST_MOD, keyid, direction,
colargs, static_columns);
++cols;
}
if (!(autoindex_opts & SUPPRESS_SIZE)) {
ap_rvputs(r, "</th><th", (d->style_sheet != NULL) ? " class=\"indexcolsize\">" : ">", NULL);
emit_link(r, "Size", K_SIZE, keyid, direction,
colargs, static_columns);
++cols;
}
if (!(autoindex_opts & SUPPRESS_DESC)) {
ap_rvputs(r, "</th><th", (d->style_sheet != NULL) ? " class=\"indexcoldesc\">" : ">", NULL);
emit_link(r, "Description", K_DESC, keyid, direction,
colargs, static_columns);
++cols;
}
if (!(autoindex_opts & SUPPRESS_RULES)) {
breakrow = apr_psprintf(r->pool,
" <tr%s><th colspan=\"%d\">"
"<hr%s></th></tr>\n",
(d->style_sheet != NULL) ? " class=\"indexbreakrow\"" : "",
cols,
(autoindex_opts & EMIT_XHTML) ? " /" : "");
}
ap_rvputs(r, "</th></tr>\n", breakrow, NULL);
}
else if (autoindex_opts & FANCY_INDEXING) {
ap_rputs("<pre>", r);
if (!(autoindex_opts & SUPPRESS_ICON)) {
if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
ap_rvputs(r, "<img src=\"", ap_escape_html(scratch, tp),
"\" alt=\"Icon \"", NULL);
if (d->icon_width) {
ap_rprintf(r, " width=\"%d\"", d->icon_width);
}
if (d->icon_height) {
ap_rprintf(r, " height=\"%d\"", d->icon_height);
}
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs("> ", r);
}
else {
ap_rputs(" ", r);
}
}
emit_link(r, "Name", K_NAME, keyid, direction,
colargs, static_columns);
ap_rputs(pad_scratch + 4, r);
/*
* Emit the guaranteed-at-least-one-space-between-columns byte.
*/
ap_rputs(" ", r);
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
emit_link(r, "Last modified", K_LAST_MOD, keyid, direction,
colargs, static_columns);
ap_rputs(" ", r);
}
if (!(autoindex_opts & SUPPRESS_SIZE)) {
emit_link(r, "Size", K_SIZE, keyid, direction,
colargs, static_columns);
ap_rputs(" ", r);
}
if (!(autoindex_opts & SUPPRESS_DESC)) {
emit_link(r, "Description", K_DESC, keyid, direction,
colargs, static_columns);
}
if (!(autoindex_opts & SUPPRESS_RULES)) {
ap_rputs("<hr", r);
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs(">", r);
}
else {
ap_rputc('\n', r);
}
}
else {
ap_rputs("<ul>", r);
}
for (x = 0; x < n; x++) {
char *anchor, *t, *t2;
int nwidth;
apr_pool_clear(scratch);
t = ar[x]->name;
anchor = ap_escape_html(scratch, ap_os_escape_path(scratch, t, 0));
if (!x && t[0] == '/') {
t2 = "Parent Directory";
}
else {
t2 = t;
}
if (autoindex_opts & TABLE_INDEXING) {
/* Even/Odd rows for IndexStyleSheet */
if (d->style_sheet != NULL) {
if (ar[x]->alt && (autoindex_opts & ADDALTCLASS)) {
/* Include alt text in class name, distinguish between odd and even rows */
char *altclass = apr_pstrdup(scratch, ar[x]->alt);
ap_str_tolower(altclass);
ap_rvputs(r, " <tr class=\"", ( x & 0x1) ? "odd-" : "even-", altclass, "\">", NULL);
} else {
/* Distinguish between odd and even rows */
ap_rvputs(r, " <tr class=\"", ( x & 0x1) ? "odd" : "even", "\">", NULL);
}
} else {
ap_rputs("<tr>", r);
}
if (!(autoindex_opts & SUPPRESS_ICON)) {
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcolicon\">" : " valign=\"top\">", NULL);
if (autoindex_opts & ICONS_ARE_LINKS) {
ap_rvputs(r, "<a href=\"", anchor, "\">", NULL);
}
if ((ar[x]->icon) || d->default_icon) {
ap_rvputs(r, "<img src=\"",
ap_escape_html(scratch,
ar[x]->icon ? ar[x]->icon
: d->default_icon),
"\" alt=\"[", (ar[x]->alt ? ar[x]->alt : " "),
"]\"", NULL);
if (d->icon_width) {
ap_rprintf(r, " width=\"%d\"", d->icon_width);
}
if (d->icon_height) {
ap_rprintf(r, " height=\"%d\"", d->icon_height);
}
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs(">", r);
}
else {
ap_rputs("&nbsp;", r);
}
if (autoindex_opts & ICONS_ARE_LINKS) {
ap_rputs("</a></td>", r);
}
else {
ap_rputs("</td>", r);
}
}
if (d->name_adjust == K_ADJUST) {
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcolname\">" : ">", "<a href=\"", anchor, "\">",
ap_escape_html(scratch, t2), "</a>", NULL);
}
else {
nwidth = strlen(t2);
if (nwidth > name_width) {
memcpy(name_scratch, t2, name_width - 3);
name_scratch[name_width - 3] = '.';
name_scratch[name_width - 2] = '.';
name_scratch[name_width - 1] = '>';
name_scratch[name_width] = 0;
t2 = name_scratch;
nwidth = name_width;
}
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcolname\">" : ">", "<a href=\"", anchor, "\">",
ap_escape_html(scratch, t2),
"</a>", pad_scratch + nwidth, NULL);
}
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
if (ar[x]->lm != -1) {
char time_str[MAX_STRING_LEN];
apr_time_exp_t ts;
apr_time_exp_lt(&ts, ar[x]->lm);
apr_strftime(time_str, &rv, MAX_STRING_LEN,
"%Y-%m-%d %H:%M ",
&ts);
ap_rvputs(r, "</td><td", (d->style_sheet != NULL) ? " class=\"indexcollastmod\">" : " align=\"right\">",time_str, NULL);
}
else {
ap_rvputs(r, "</td><td", (d->style_sheet != NULL) ? " class=\"indexcollastmod\">&nbsp;" : ">&nbsp;", NULL);
}
}
if (!(autoindex_opts & SUPPRESS_SIZE)) {
char buf[5];
ap_rvputs(r, "</td><td", (d->style_sheet != NULL) ? " class=\"indexcolsize\">" : " align=\"right\">",
apr_strfsize(ar[x]->size, buf), NULL);
}
if (!(autoindex_opts & SUPPRESS_DESC)) {
if (ar[x]->desc) {
if (d->desc_adjust == K_ADJUST) {
ap_rvputs(r, "</td><td", (d->style_sheet != NULL) ? " class=\"indexcoldesc\">" : ">", ar[x]->desc, NULL);
}
else {
ap_rvputs(r, "</td><td", (d->style_sheet != NULL) ? " class=\"indexcoldesc\">" : ">",
terminate_description(d, ar[x]->desc,
autoindex_opts,
desc_width), NULL);
}
}
else {
ap_rputs("</td><td>&nbsp;", r);
}
}
ap_rputs("</td></tr>\n", r);
}
else if (autoindex_opts & FANCY_INDEXING) {
if (!(autoindex_opts & SUPPRESS_ICON)) {
if (autoindex_opts & ICONS_ARE_LINKS) {
ap_rvputs(r, "<a href=\"", anchor, "\">", NULL);
}
if ((ar[x]->icon) || d->default_icon) {
ap_rvputs(r, "<img src=\"",
ap_escape_html(scratch,
ar[x]->icon ? ar[x]->icon
: d->default_icon),
"\" alt=\"[", (ar[x]->alt ? ar[x]->alt : " "),
"]\"", NULL);
if (d->icon_width) {
ap_rprintf(r, " width=\"%d\"", d->icon_width);
}
if (d->icon_height) {
ap_rprintf(r, " height=\"%d\"", d->icon_height);
}
if (autoindex_opts & EMIT_XHTML) {
ap_rputs(" /", r);
}
ap_rputs(">", r);
}
else {
ap_rputs(" ", r);
}
if (autoindex_opts & ICONS_ARE_LINKS) {
ap_rputs("</a> ", r);
}
else {
ap_rputc(' ', r);
}
}
nwidth = strlen(t2);
if (nwidth > name_width) {
memcpy(name_scratch, t2, name_width - 3);
name_scratch[name_width - 3] = '.';
name_scratch[name_width - 2] = '.';
name_scratch[name_width - 1] = '>';
name_scratch[name_width] = 0;
t2 = name_scratch;
nwidth = name_width;
}
ap_rvputs(r, "<a href=\"", anchor, "\">",
ap_escape_html(scratch, t2),
"</a>", pad_scratch + nwidth, NULL);
/*
* The blank before the storm.. er, before the next field.
*/
ap_rputs(" ", r);
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
if (ar[x]->lm != -1) {
char time_str[MAX_STRING_LEN];
apr_time_exp_t ts;
apr_time_exp_lt(&ts, ar[x]->lm);
apr_strftime(time_str, &rv, MAX_STRING_LEN,
"%Y-%m-%d %H:%M ", &ts);
ap_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,
"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 {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"Directory index forbidden by "
"Options directive: %s", r->filename);
return HTTP_FORBIDDEN;
}
}
static void register_hooks(apr_pool_t *p)
{
ap_hook_handler(handle_autoindex,NULL,NULL,APR_HOOK_MIDDLE);
}
module AP_MODULE_DECLARE_DATA autoindex_module =
{
STANDARD20_MODULE_STUFF,
create_autoindex_config, /* dir config creater */
merge_autoindex_configs, /* dir merger --- default is to override */
NULL, /* server config */
NULL, /* merge server config */
autoindex_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};