Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Apache/modules/generators/   (Apache Software Stiftung Version 2.4.65©)  Datei vom 27.8.2024 mit Größe 77 kB image not shown  

Quelle  mod_autoindex.c   Sprache: C

 
/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


/*
 * mod_autoindex.c: Handles the on-the-fly html index generation
 *
 * Rob McCool
 * 3/23/93
 *
 * Adapted to Apache by rst.
 *
 * Version sort added by Martin Pool <mbp@humbug.org.au>.
 */


#include "apr_strings.h"
#include "apr_fnmatch.h"
#include "apr_strings.h"
#include "apr_lib.h"

#define APR_WANT_STRFUNC
#include "apr_want.h"

#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_request.h"
#include "http_protocol.h"
#include "http_log.h"
#include "http_main.h"
#include "util_script.h"

#include "mod_core.h"

module AP_MODULE_DECLARE_DATA autoindex_module;

/****************************************************************
 *
 * Handling configuration directives...
 */


#define NO_OPTIONS          (1 <<  0)  /* Indexing options */
#define ICONS_ARE_LINKS     (1 <<  1)
#define SCAN_HTML_TITLES    (1 <<  2)
#define SUPPRESS_ICON       (1 <<  3)
#define SUPPRESS_LAST_MOD   (1 <<  4)
#define SUPPRESS_SIZE       (1 <<  5)
#define SUPPRESS_DESC       (1 <<  6)
#define SUPPRESS_PREAMBLE   (1 <<  7)
#define SUPPRESS_COLSORT    (1 <<  8)
#define SUPPRESS_RULES      (1 <<  9)
#define FOLDERS_FIRST       (1 << 10)
#define VERSION_SORT        (1 << 11)
#define TRACK_MODIFIED      (1 << 12)
#define FANCY_INDEXING      (1 << 13)
#define TABLE_INDEXING      (1 << 14)
#define IGNORE_CLIENT       (1 << 15)
#define IGNORE_CASE         (1 << 16)
#define EMIT_XHTML          (1 << 17)
#define SHOW_FORBIDDEN      (1 << 18)
#define ADDALTCLASS         (1 << 19)
#define OPTION_UNSET        (1 << 20)

#define K_NOADJUST 0
#define K_ADJUST 1
#define K_UNSET 2

/*
 * Define keys for sorting.
 */

#define K_NAME 'N'              /* Sort by file name (default) */
#define K_LAST_MOD 'M'          /* Last modification date */
#define K_SIZE 'S'              /* Size (absolute, not as displayed) */
#define K_DESC 'D'              /* Description */
#define K_VALID "NMSD"          /* String containing _all_ valid K_ opts */

#define D_ASCENDING 'A'
#define D_DESCENDING 'D'
#define D_VALID "AD"            /* String containing _all_ valid D_ opts */

/*
 * These are the dimensions of the default icons supplied with Apache.
 */

#define DEFAULT_ICON_WIDTH 20
#define DEFAULT_ICON_HEIGHT 22

/*
 * Other default dimensions.
 */

#define DEFAULT_NAME_WIDTH 23
#define DEFAULT_DESC_WIDTH 23

struct item {
    char *type;
    char *apply_to;
    char *apply_path;
    char *data;
};

typedef struct ai_desc_t {
    char *pattern;
    char *description;
    int full_path;
    int wildcards;
} ai_desc_t;

typedef struct autoindex_config_struct {

    char *default_icon;
    char *style_sheet;
    char *head_insert;
    char *header;
    char *readme;
    apr_int32_t opts;
    apr_int32_t incremented_opts;
    apr_int32_t decremented_opts;
    int name_width;
    int name_adjust;
    int desc_width;
    int desc_adjust;
    int icon_width;
    int icon_height;
    char default_keyid;
    char default_direction;

    apr_array_header_t *icon_list;
    apr_array_header_t *alt_list;
    apr_array_header_t *desc_list;
    apr_array_header_t *ign_list;
    int ign_noinherit;

    char *ctype;
    char *charset;
    char *datetime_format;
} autoindex_config_rec;

static char c_by_encoding, c_by_type, c_by_path;

#define BY_ENCODING &c_by_encoding
#define BY_TYPE &c_by_type
#define BY_PATH &c_by_path

static APR_INLINE int response_is_html(request_rec *r)
{
    char *ctype = ap_field_noparam(r->pool, r->content_type);

    return !ap_cstr_casecmp(ctype, "text/html")
        || !ap_cstr_casecmp(ctype, "application/xhtml+xml");
}

/*
 * This routine puts the standard HTML header at the top of the index page.
 * We include the DOCTYPE because we may be using features therefrom (i.e.,
 * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
 */

static void emit_preamble(request_rec *r, int xhtml, const char *title)
{
    autoindex_config_rec *d;

    d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config,
                                                      &autoindex_module);

    if (xhtml) {
        ap_rvputs(r, DOCTYPE_XHTML_1_0T,
                  "http://www.w3.org/1999/xhtml\">\n"
                  " \n Index of "</span>, title,<br>                   <span style='color:blue'>"\n", NULL);
    } else {
        ap_rvputs(r, DOCTYPE_HTML_3_2,
                  "\n \n"
                  " Index of "</span>, title,<br>                   <span style='color:blue'>"\n", NULL);
    }

    if (d->style_sheet != NULL) {
        ap_rvputs(r, " stylesheet\" href=\"", d->style_sheet,
                "\" type=\"text/css\"", xhtml ? " />\n" : ">\n", NULL);
    }
    if (d->head_insert != NULL) {
        ap_rputs(d->head_insert, r);
    }
    ap_rputs(" \n \n", r);
}

static void push_item(apr_array_header_t *arr, char *type, const char *to,
                      const char *path, const char *data)
{
    struct item *p = (struct item *) apr_array_push(arr);

    if (!to) {
        to = "";
    }
    if (!path) {
        path = "";
    }

    p->type = type;
    p->data = apr_pstrdup(arr->pool, data);
    p->apply_path = apr_pstrcat(arr->pool, path, "*", NULL);

    if ((type == BY_PATH) && (!ap_is_matchexp(to))) {
        p->apply_to = apr_pstrcat(arr->pool, "*", to, NULL);
    }
    else {
        p->apply_to = apr_pstrdup(arr->pool, to);
    }
}

static const char *add_alt(cmd_parms *cmd, void *d, const char *alt,
                           const char *to)
{
    if (cmd->info == BY_PATH) {
        if (!strcmp(to, "**DIRECTORY**")) {
            to = "^^DIRECTORY^^";
        }
    }
    if (cmd->info == BY_ENCODING) {
        char *tmp = apr_pstrdup(cmd->temp_pool, to);
        ap_str_tolower(tmp);
        to = tmp;
    }

    push_item(((autoindex_config_rec *) d)->alt_list, cmd->info, to,
              cmd->path, alt);
    return NULL;
}

static const char *add_icon(cmd_parms *cmd, void *d, const char *icon,
                            const char *to)
{
    char *iconbak = apr_pstrdup(cmd->temp_pool, icon);

    if (icon[0] == '(') {
        char *alt;
        char *cl = strchr(iconbak, ')');

        if (cl == NULL) {
            return "missing closing paren";
        }
        alt = ap_getword_nc(cmd->temp_pool, &iconbak, ',');
        *cl = '\0';                             /* Lose closing paren */
        add_alt(cmd, d, &alt[1], to);
    }
    if (cmd->info == BY_PATH) {
        if (!strcmp(to, "**DIRECTORY**")) {
            to = "^^DIRECTORY^^";
        }
    }
    if (cmd->info == BY_ENCODING) {
        char *tmp = apr_pstrdup(cmd->temp_pool, to);
        ap_str_tolower(tmp);
        to = tmp;
    }

    push_item(((autoindex_config_rec *) d)->icon_list, cmd->info, to,
              cmd->path, iconbak);
    return NULL;
}

/*
 * Add description text for a filename pattern.  If the pattern has
 * wildcards already (or we need to add them), add leading and
 * trailing wildcards to it to ensure substring processing.  If the
 * pattern contains a '/' anywhere, force wildcard matching mode,
 * add a slash to the prefix so that "bar/bletch" won't be matched
 * by "foobar/bletch", and make a note that there's a delimiter;
 * the matching routine simplifies to just the actual filename
 * whenever it can.  This allows definitions in parent directories
 * to be made for files in subordinate ones using relative paths.
 */


/*
 * Absent a strcasestr() function, we have to force wildcards on
 * systems for which "AAA" and "aaa" mean the same file.
 */

#ifdef CASE_BLIND_FILESYSTEM
#define WILDCARDS_REQUIRED 1
#else
#define WILDCARDS_REQUIRED 0
#endif

static const char *add_desc(cmd_parms *cmd, void *d, const char *desc,
                            const char *to)
{
    autoindex_config_rec *dcfg = (autoindex_config_rec *) d;
    ai_desc_t *desc_entry;
    char *prefix = "";

    desc_entry = (ai_desc_t *) apr_array_push(dcfg->desc_list);
    desc_entry->full_path = (ap_strchr_c(to, '/') == NULL) ? 0 : 1;
    desc_entry->wildcards = (WILDCARDS_REQUIRED
                             || desc_entry->full_path
                             || apr_fnmatch_test(to));
    if (desc_entry->wildcards) {
        prefix = desc_entry->full_path ? "*/" : "*";
        desc_entry->pattern = apr_pstrcat(dcfg->desc_list->pool,
                                          prefix, to, "*", NULL);
    }
    else {
        desc_entry->pattern = apr_pstrdup(dcfg->desc_list->pool, to);
    }
    desc_entry->description = apr_pstrdup(dcfg->desc_list->pool, desc);
    return NULL;
}

static const char *add_ignore(cmd_parms *cmd, void *d, const char *ext)
{
    push_item(((autoindex_config_rec *) d)->ign_list, 0, ext, cmd->path, NULL);
    return NULL;
}

static const char *add_opts(cmd_parms *cmd, void *d, int argc, char *const argv[])
{
    int i;
    char *w;
    apr_int32_t opts;
    apr_int32_t opts_add;
    apr_int32_t opts_remove;
    char action;
    autoindex_config_rec *d_cfg = (autoindex_config_rec *) d;

    opts = d_cfg->opts;
    opts_add = d_cfg->incremented_opts;
    opts_remove = d_cfg->decremented_opts;

    for (i = 0; i < argc; i++) {
        int option = 0;
        w = argv[i];

        if ((*w == '+') || (*w == '-')) {
            action = *(w++);
        }
        else {
            action = '\0';
        }
        if (!strcasecmp(w, "FancyIndexing")) {
            option = FANCY_INDEXING;
        }
        else if (!strcasecmp(w, "FoldersFirst")) {
            option = FOLDERS_FIRST;
        }
        else if (!strcasecmp(w, "HTMLTable")) {
            option = TABLE_INDEXING;
        }
        else if (!strcasecmp(w, "IconsAreLinks")) {
            option = ICONS_ARE_LINKS;
        }
        else if (!strcasecmp(w, "IgnoreCase")) {
            option = IGNORE_CASE;
        }
        else if (!strcasecmp(w, "IgnoreClient")) {
            option = IGNORE_CLIENT;
        }
        else if (!strcasecmp(w, "ScanHTMLTitles")) {
            option = SCAN_HTML_TITLES;
        }
        else if (!strcasecmp(w, "SuppressColumnSorting")) {
            option = SUPPRESS_COLSORT;
        }
        else if (!strcasecmp(w, "SuppressDescription")) {
            option = SUPPRESS_DESC;
        }
        else if (!strcasecmp(w, "SuppressHTMLPreamble")) {
            option = SUPPRESS_PREAMBLE;
        }
        else if (!strcasecmp(w, "SuppressIcon")) {
            option = SUPPRESS_ICON;
        }
        else if (!strcasecmp(w, "SuppressLastModified")) {
            option = SUPPRESS_LAST_MOD;
        }
        else if (!strcasecmp(w, "SuppressSize")) {
            option = SUPPRESS_SIZE;
        }
        else if (!strcasecmp(w, "SuppressRules")) {
            option = SUPPRESS_RULES;
        }
        else if (!strcasecmp(w, "TrackModified")) {
            option = TRACK_MODIFIED;
        }
        else if (!strcasecmp(w, "VersionSort")) {
            option = VERSION_SORT;
        }
        else if (!strcasecmp(w, "XHTML")) {
            option = EMIT_XHTML;
        }
        else if (!strcasecmp(w, "ShowForbidden")) {
            option = SHOW_FORBIDDEN;
        }
        else if (!strcasecmp(w, "AddAltClass")) {
            option = ADDALTCLASS;
        }
        else if (!strcasecmp(w, "None")) {
            if (action != '\0') {
                return "Cannot combine '+' or '-' with 'None' keyword";
            }
            opts = NO_OPTIONS;
            opts_add = 0;
            opts_remove = 0;
        }
        else if (!strcasecmp(w, "IconWidth")) {
            if (action != '-') {
                d_cfg->icon_width = DEFAULT_ICON_WIDTH;
            }
            else {
                d_cfg->icon_width = 0;
            }
        }
        else if (!strncasecmp(w, "IconWidth=", 10)) {
            if (action == '-') {
                return "Cannot combine '-' with IconWidth=n";
            }
            d_cfg->icon_width = atoi(&w[10]);
        }
        else if (!strcasecmp(w, "IconHeight")) {
            if (action != '-') {
                d_cfg->icon_height = DEFAULT_ICON_HEIGHT;
            }
            else {
                d_cfg->icon_height = 0;
            }
        }
        else if (!strncasecmp(w, "IconHeight=", 11)) {
            if (action == '-') {
                return "Cannot combine '-' with IconHeight=n";
            }
            d_cfg->icon_height = atoi(&w[11]);
        }
        else if (!strcasecmp(w, "NameWidth")) {
            if (action != '-') {
                return "NameWidth with no value may only appear as "
                       "'-NameWidth'";
            }
            d_cfg->name_width = DEFAULT_NAME_WIDTH;
            d_cfg->name_adjust = K_NOADJUST;
        }
        else if (!strncasecmp(w, "NameWidth=", 10)) {
            if (action == '-') {
                return "Cannot combine '-' with NameWidth=n";
            }
            if (w[10] == '*') {
                d_cfg->name_adjust = K_ADJUST;
            }
            else {
                int width = atoi(&w[10]);

                if (width && (width < 5)) {
                    return "NameWidth value must be greater than 5";
                }
                d_cfg->name_width = width;
                d_cfg->name_adjust = K_NOADJUST;
            }
        }
        else if (!strcasecmp(w, "DescriptionWidth")) {
            if (action != '-') {
                return "DescriptionWidth with no value may only appear as "
                       "'-DescriptionWidth'";
            }
            d_cfg->desc_width = DEFAULT_DESC_WIDTH;
            d_cfg->desc_adjust = K_NOADJUST;
        }
        else if (!strncasecmp(w, "DescriptionWidth=", 17)) {
            if (action == '-') {
                return "Cannot combine '-' with DescriptionWidth=n";
            }
            if (w[17] == '*') {
                d_cfg->desc_adjust = K_ADJUST;
            }
            else {
                int width = atoi(&w[17]);

                if (width && (width < 12)) {
                    return "DescriptionWidth value must be greater than 12";
                }
                d_cfg->desc_width = width;
                d_cfg->desc_adjust = K_NOADJUST;
            }
        }
        else if (!strncasecmp(w, "Type=", 5)) {
            d_cfg->ctype = apr_pstrdup(cmd->pool, &w[5]);
        }
        else if (!strncasecmp(w, "Charset=", 8)) {
            d_cfg->charset = apr_pstrdup(cmd->pool, &w[8]);
        }
        else if (!strcasecmp(w, "UseOldDateFormat")) {
            d_cfg->datetime_format = "%d-%b-%Y %H:%M";
        }
        else {
            return "Invalid directory indexing option";
        }
        if (action == '\0') {
            opts |= option;
            opts_add = 0;
            opts_remove = 0;
        }
        else if (action == '+') {
            opts_add |= option;
            opts_remove &= ~option;
        }
        else {
            opts_remove |= option;
            opts_add &= ~option;
        }
    }
    if ((opts & NO_OPTIONS) && (opts & ~NO_OPTIONS)) {
        return "Cannot combine other IndexOptions keywords with 'None'";
    }
    d_cfg->incremented_opts = opts_add;
    d_cfg->decremented_opts = opts_remove;
    d_cfg->opts = opts;
    return NULL;
}

static const char *set_default_order(cmd_parms *cmd, void *m,
                                     const char *direction, const char *key)
{
    autoindex_config_rec *d_cfg = (autoindex_config_rec *) m;

    if (!strcasecmp(direction, "Ascending")) {
        d_cfg->default_direction = D_ASCENDING;
    }
    else if (!strcasecmp(direction, "Descending")) {
        d_cfg->default_direction = D_DESCENDING;
    }
    else {
        return "First keyword must be 'Ascending' or 'Descending'";
    }

    if (!strcasecmp(key, "Name")) {
        d_cfg->default_keyid = K_NAME;
    }
    else if (!strcasecmp(key, "Date")) {
        d_cfg->default_keyid = K_LAST_MOD;
    }
    else if (!strcasecmp(key, "Size")) {
        d_cfg->default_keyid = K_SIZE;
    }
    else if (!strcasecmp(key, "Description")) {
        d_cfg->default_keyid = K_DESC;
    }
    else {
        return "Second keyword must be 'Name', 'Date', 'Size', or "
               "'Description'";
    }

    return NULL;
}

#define DIR_CMD_PERMS OR_INDEXES

static const command_rec autoindex_cmds[] =
{
    AP_INIT_ITERATE2("AddIcon", add_icon, BY_PATH, DIR_CMD_PERMS,
                     "an icon URL followed by one or more filenames"),
    AP_INIT_ITERATE2("AddIconByType", add_icon, BY_TYPE, DIR_CMD_PERMS,
                     "an icon URL followed by one or more MIME types"),
    AP_INIT_ITERATE2("AddIconByEncoding", add_icon, BY_ENCODING, DIR_CMD_PERMS,
                     "an icon URL followed by one or more content encodings"),
    AP_INIT_ITERATE2("AddAlt", add_alt, BY_PATH, DIR_CMD_PERMS,
                     "alternate descriptive text followed by one or more "
                     "filenames"),
    AP_INIT_ITERATE2("AddAltByType", add_alt, BY_TYPE, DIR_CMD_PERMS,
                     "alternate descriptive text followed by one or more MIME "
                     "types"),
    AP_INIT_ITERATE2("AddAltByEncoding", add_alt, BY_ENCODING, DIR_CMD_PERMS,
                     "alternate descriptive text followed by one or more "
                     "content encodings"),
    AP_INIT_TAKE_ARGV("IndexOptions", add_opts, NULL, DIR_CMD_PERMS,
                      "one or more index options [+|-][]"),
    AP_INIT_TAKE2("IndexOrderDefault", set_default_order, NULL, DIR_CMD_PERMS,
                  "{Ascending,Descending} {Name,Size,Description,Date}"),
    AP_INIT_ITERATE("IndexIgnore", add_ignore, NULL, DIR_CMD_PERMS,
                    "one or more file extensions"),
    AP_INIT_FLAG("IndexIgnoreReset", ap_set_flag_slot,
                 (void *)APR_OFFSETOF(autoindex_config_rec, ign_noinherit),
                 DIR_CMD_PERMS,
                 "Reset the inherited list of IndexIgnore filenames"),
    AP_INIT_ITERATE2("AddDescription", add_desc, BY_PATH, DIR_CMD_PERMS,
                     "Descriptive text followed by one or more filenames"),
    AP_INIT_TAKE1("HeaderName", ap_set_string_slot,
                  (void *)APR_OFFSETOF(autoindex_config_rec, header),
                  DIR_CMD_PERMS, "a filename"),
    AP_INIT_TAKE1("ReadmeName", ap_set_string_slot,
                  (void *)APR_OFFSETOF(autoindex_config_rec, readme),
                  DIR_CMD_PERMS, "a filename"),
    AP_INIT_RAW_ARGS("FancyIndexing", ap_set_deprecated, NULL, OR_ALL,
                     "The FancyIndexing directive is no longer supported. "
                     "Use IndexOptions FancyIndexing."),
    AP_INIT_TAKE1("DefaultIcon", ap_set_string_slot,
                  (void *)APR_OFFSETOF(autoindex_config_rec, default_icon),
                  DIR_CMD_PERMS, "an icon URL"),
    AP_INIT_TAKE1("IndexStyleSheet", ap_set_string_slot,
                  (void *)APR_OFFSETOF(autoindex_config_rec, style_sheet),
                  DIR_CMD_PERMS, "URL to style sheet"),
    AP_INIT_TAKE1("IndexHeadInsert", ap_set_string_slot,
                  (void *)APR_OFFSETOF(autoindex_config_rec, head_insert),
                  DIR_CMD_PERMS, "String to insert in HTML HEAD section"),
    {NULL}
};

static void *create_autoindex_config(apr_pool_t *p, char *dummy)
{
    autoindex_config_rec *new =
    (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));

    new->icon_width = 0;
    new->icon_height = 0;
    new->name_width = DEFAULT_NAME_WIDTH;
    new->name_adjust = K_UNSET;
    new->desc_width = DEFAULT_DESC_WIDTH;
    new->desc_adjust = K_UNSET;
    new->icon_list = apr_array_make(p, 4, sizeof(struct item));
    new->alt_list = apr_array_make(p, 4, sizeof(struct item));
    new->desc_list = apr_array_make(p, 4, sizeof(ai_desc_t));
    new->ign_list = apr_array_make(p, 4, sizeof(struct item));
    new->opts = OPTION_UNSET;
    new->incremented_opts = 0;
    new->decremented_opts = 0;
    new->default_keyid = '\0';
    new->default_direction = '\0';

    return (void *) new;
}

static void *merge_autoindex_configs(apr_pool_t *p, void *basev, void *addv)
{
    autoindex_config_rec *new;
    autoindex_config_rec *base = (autoindex_config_rec *) basev;
    autoindex_config_rec *add = (autoindex_config_rec *) addv;

    new = (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
    new->default_icon = add->default_icon ? add->default_icon
                                          : base->default_icon;
    new->style_sheet = add->style_sheet ? add->style_sheet
                                          : base->style_sheet;
    new->head_insert = add->head_insert ? add->head_insert
                                          : base->head_insert;
    new->header = add->header ? add->header
                                : base->header;
    new->readme = add->readme ? add->readme
                                : base->readme;
    new->icon_height = add->icon_height ? add->icon_height : base->icon_height;
    new->icon_width = add->icon_width ? add->icon_width : base->icon_width;

    new->ctype = add->ctype ? add->ctype : base->ctype;
    new->charset = add->charset ? add->charset : base->charset;
    new->datetime_format = add->datetime_format ? add->datetime_format : base->datetime_format;

    new->alt_list = apr_array_append(p, add->alt_list, base->alt_list);
    new->desc_list = apr_array_append(p, add->desc_list, base->desc_list);
    new->icon_list = apr_array_append(p, add->icon_list, base->icon_list);
    new->ign_list = add->ign_noinherit ? add->ign_list : apr_array_append(p, add->ign_list, base->ign_list);
    if (add->opts == NO_OPTIONS) {
        /*
         * If the current directory explicitly says 'no options' then we also
         * clear any incremental mods from being inheritable further down.
         */

        new->opts = NO_OPTIONS;
        new->incremented_opts = 0;
        new->decremented_opts = 0;
    }
    else {
        /*
         * If there were any nonincremental options selected for
         * this directory, they dominate and we don't inherit *anything.*
         * Contrariwise, we *do* inherit if the only settings here are
         * incremental ones.
         */

        if (add->opts == OPTION_UNSET) {
            new->incremented_opts = (base->incremented_opts
                                     | add->incremented_opts)
                                    & ~add->decremented_opts;
            new->decremented_opts = (base->decremented_opts
                                     | add->decremented_opts);
            /*
             * We may have incremental settings, so make sure we don't
             * inadvertently inherit an IndexOptions None from above.
             */

            new->opts = (base->opts & ~NO_OPTIONS);
        }
        else {
            /*
             * There are local nonincremental settings, which clear
             * all inheritance from above.  They *are* the new base settings.
             */

            new->opts = add->opts;
        }
        /*
         * We're guaranteed that there'll be no overlap between
         * the add-options and the remove-options.
         */

        new->opts |= new->incremented_opts;
        new->opts &= ~new->decremented_opts;
    }
    /*
     * Inherit the NameWidth settings if there aren't any specific to
     * the new location; otherwise we'll end up using the defaults set in the
     * config-rec creation routine.
     */

    if (add->name_adjust == K_UNSET) {
        new->name_width = base->name_width;
        new->name_adjust = base->name_adjust;
    }
    else {
        new->name_width = add->name_width;
        new->name_adjust = add->name_adjust;
    }

    /*
     * Likewise for DescriptionWidth.
     */

    if (add->desc_adjust == K_UNSET) {
        new->desc_width = base->desc_width;
        new->desc_adjust = base->desc_adjust;
    }
    else {
        new->desc_width = add->desc_width;
        new->desc_adjust = add->desc_adjust;
    }

    new->default_keyid = add->default_keyid ? add->default_keyid
                                            : base->default_keyid;
    new->default_direction = add->default_direction ? add->default_direction
                                                    : base->default_direction;
    return new;
}

/****************************************************************
 *
 * Looking things up in config entries...
 */


/* Structure used to hold entries when we're actually building an index */

struct ent {
    char *name;
    char *icon;
    char *alt;
    char *desc;
    apr_off_t size;
    apr_time_t lm;
    struct ent *next;
    int ascending, ignore_case, version_sort;
    char key;
    int isdir;
};

static char *find_item(const char *content_type, const char *content_encoding,
                       char *path, apr_array_header_t *list, int path_only)
{
    struct item *items = (struct item *) list->elts;
    int i;

    for (i = 0; i < list->nelts; ++i) {
        struct item *p = &items[i];

        /* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */
        if ((path[0] == '^') || (!ap_strcmp_match(path, p->apply_path))) {
            if (!*(p->apply_to)) {
                return p->data;
            }
            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("
\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("<", r);
            }
            else if (ch == '>') {
                ap_rputs(">", r);
            }
            else if (ch == '&') {
                ap_rputs("&", r);
            }
            c = i + 1;
        }
    }
    ap_rputs("
\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)
{
    autoindex_config_rec *d;
    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 (!ap_cstr_casecmpn("text/", rr->content_type, 5)) {
                /*
                 * If we can open the file, prefix it with the preamble
                 * regardless; since we'll be sending a <pre> block around
                 * the file's contents, any HTML header it had won't end up
                 * where it belongs.
                 */

                if (apr_file_open(&f, rr->filename, APR_READ,
                                  APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
                    emit_preamble(r, emit_xhtml, title);
                    emit_amble = 0;
                    do_emit_plain(r, f);
                    apr_file_close(f);
                    emit_H1 = 0;
                }
            }
        }
    }

    if (r_accept) {
        apr_table_setn(hdrs, "Accept", r_accept);
    }
    else {
        apr_table_unset(hdrs, "Accept");
    }

    if (r_accept_enc) {
        apr_table_setn(hdrs, "Accept-Encoding", r_accept_enc);
    }

    if (emit_amble) {
        emit_preamble(r, emit_xhtml, title);
    }

    d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config, &autoindex_module);

    if (emit_H1) {
        if (d->style_sheet != NULL) {
            /* Insert style id if stylesheet used */
            ap_rvputs(r, "

indextitle\">Index of ", title, "

\n"
, NULL);
        } else {
            ap_rvputs(r, "

Index of ", title, "

\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 (!ap_cstr_casecmpn("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("\n", r);
    }
    if (rr != NULL) {
        ap_destroy_sub_req(rr);
    }
}


static char *find_title(request_rec *r)
{
    char titlebuf[MAX_STRING_LEN], *find = ""</span>;<br>     apr_file_t *thefile = NULL;<br>     <span style='color:red'>int</span> x, y, p;<br>     apr_size_t n;<br> <br>     <span style='color:red'>if</span> (r->status != HTTP_OK) {<br>         <span style='color:red'>return</span> NULL;<br>     }<br>     <span style='color:red'>if</span> ((r->content_type != NULL)<br>         && (response_is_html(r)<br>             || !strcmp(r->content_type, INCLUDES_MAGIC_TYPE))<br>         && !r->content_encoding) {<br>         <span style='color:red'>if</span> (apr_file_open(&thefile, r->filename, APR_READ,<br>                           APR_OS_DEFAULT, r->pool) != APR_SUCCESS) {<br>             <span style='color:red'>return</span> NULL;<br>         }<br>         n = <span style='color:red'>sizeof</span>(<span style='color:red'>char</span>) * (MAX_STRING_LEN - 1);<br>         apr_file_read(thefile, titlebuf, &n);<br>         <span style='color:red'>if</span> (n == 0) {<br>             apr_file_close(thefile);<br>             <span style='color:red'>return</span> NULL;<br>         }<br>         titlebuf[n] = <span style='color:blue'>'\0'</span>;<br>         <span style='color:red'>for</span> (x = 0, p = 0; titlebuf[x]; x++) {<br>             <span style='color:red'>if</span> (apr_tolower(titlebuf[x]) == find[p]) {<br>                 <span style='color:red'>if</span> (!find[++p]) {<br>                     <span style='color:red'>if</span> ((p = ap_ind(&titlebuf[++x], <span style='color:blue'>'<'</span>)) != -1) {<br>                         titlebuf[x + p] = <span style='color:blue'>'\0'</span>;<br>                     }<br>                     <span style='color:green'>/* Scan for line breaks for Tanmoy's secretary */</span><br>                     <span style='color:red'>for</span> (y = x; titlebuf[y]; y++) {<br>                         <span style='color:red'>if</span> ((titlebuf[y] == CR) || (titlebuf[y] == LF)) {<br>                             <span style='color:red'>if</span> (y == x) {<br>                                 x++;<br>                             }<br>                             <span style='color:red'>else</span> {<br>                                 titlebuf[y] = <span style='color:blue'>' '</span>;<br>                             }<br>                         }<br>                     }<br>                     apr_file_close(thefile);<br>                     <span style='color:red'>return</span> apr_pstrdup(r->pool, &titlebuf[x]);<br>                 }<br>             }<br>             <span style='color:red'>else</span> {<br>                 p = 0;<br>             }<br>         }<br>         apr_file_close(thefile);<br>     }<br>     <span style='color:red'>return</span> NULL;<br> }<br> <br> <span style='color:red'>static</span> <span style='color:red'>struct</span> ent *make_parent_entry(apr_int32_t autoindex_opts,<br>                                      autoindex_config_rec *d,<br>                                      request_rec *r, <span style='color:red'>char</span> keyid,<br>                                      <span style='color:red'>char</span> direction)<br> {<br>     <span style='color:red'>struct</span> ent *p = (<span style='color:red'>struct</span> ent *) apr_pcalloc(r->pool, <span style='color:red'>sizeof</span>(<span style='color:red'>struct</span> ent));<br>     <span style='color:red'>char</span> *testpath;<br>     <span style='color:green'>/*<br> <span style='color:green'>     * p->name is now the true parent URI.</span><br> <span style='color:green'>     * testpath is a crafted lie, so that the syntax '/some/..'</span><br> <span style='color:green'>     * (or simply '..')be used to describe 'up' from '/some/'</span><br> <span style='color:green'>     * when processeing IndexIgnore, and Icon|Alt|Desc configs.</span><br>      */</span><br> <br>     <span style='color:green'>/* The output has always been to the parent.  Don't make ourself<br> <span style='color:green'>     * our own parent (worthless cyclical reference).</span><br>      */</span><br>     <span style='color:red'>if</span> (!(p->name = ap_make_full_path(r->pool, r->uri, <span style='color:blue'>"../"</span>))) {<br>         <span style='color:red'>return</span> (NULL);<br>     }<br>     <span style='color:red'>if</span> (!ap_normalize_path(p->name, AP_NORMALIZE_ALLOW_RELATIVE |<br>                                     AP_NORMALIZE_NOT_ABOVE_ROOT)<br>             || p->name[0] == <span style='color:blue'>'\0'</span>) {<br>         <span style='color:red'>return</span> (NULL);<br>     }<br> <br>     <span style='color:green'>/* IndexIgnore has always compared "/thispath/.." */</span><br>     testpath = ap_make_full_path(r->pool, r->filename, <span style='color:blue'>".."</span>);<br>     <span style='color:red'>if</span> (ignore_entry(d, testpath)) {<br>         <span style='color:red'>return</span> (NULL);<br>     }<br> <br>     p->size = -1;<br>     p->lm = -1;<br>     p->key = apr_toupper(keyid);<br>     p->ascending = (apr_toupper(direction) == D_ASCENDING);<br>     p->version_sort = autoindex_opts & VERSION_SORT;<br>     <span style='color:red'>if</span> (autoindex_opts & FANCY_INDEXING) {<br>         <span style='color:red'>if</span> (!(p->icon = find_default_icon(d, testpath))) {<br>             p->icon = find_default_icon(d, <span style='color:blue'>"^^DIRECTORY^^"</span>);<br>         }<br>         <span style='color:red'>if</span> (!(p->alt = find_default_alt(d, testpath))) {<br>             <span style='color:red'>if</span> (!(p->alt = find_default_alt(d, <span style='color:blue'>"^^DIRECTORY^^"</span>))) {<br>                 <span style='color:green'>/* Special alt text for parent dir to distinguish it from other directories<br>                    this is essential when trying to style this dir entry via AddAltClass */</span><br>                 p->alt = <span style='color:blue'>"PARENTDIR"</span>;<br>             }<br>         }<br>         p->desc = find_desc(d, testpath);<br>     }<br>     <span style='color:red'>return</span> p;<br> }<br> <br> <span style='color:red'>static</span> <span style='color:red'>struct</span> ent *make_autoindex_entry(<span style='color:red'>const</span> apr_finfo_t *dirent,<br>                                         <span style='color:red'>int</span> autoindex_opts,<br>                                         autoindex_config_rec *d,<br>                                         request_rec *r, <span style='color:red'>char</span> keyid,<br>                                         <span style='color:red'>char</span> direction,<br>                                         <span style='color:red'>const</span> <span style='color:red'>char</span> *pattern)<br> {<br>     request_rec *rr;<br>     <span style='color:red'>struct</span> ent *p;<br>     <span style='color:red'>int</span> show_forbidden = 0;<br> <br>     <span style='color:green'>/* Dot is ignored, Parent is handled by make_parent_entry() */</span><br>     <span style='color:red'>if</span> ((dirent->name[0] == <span style='color:blue'>'.'</span>) && (!dirent->name[1]<br>         || ((dirent->name[1] == <span style='color:blue'>'.'</span>) && !dirent->name[2])))<br>         <span style='color:red'>return</span> (NULL);<br> <br>     <span style='color:green'>/*<br> <span style='color:green'>     * On some platforms, the match must be case-blind.  This is really</span><br> <span style='color:green'>     * a factor of the filesystem involved, but we can't detect that</span><br> <span style='color:green'>     * reliably - so we have to granularise at the OS level.</span><br>      */</span><br>     <span style='color:red'>if</span> (pattern && (apr_fnmatch(pattern, dirent->name,<br>                                 APR_FNM_NOESCAPE | APR_FNM_PERIOD<br> <span style='color:turquoise'>#ifdef</span> CASE_BLIND_FILESYSTEM<br>                                 | APR_FNM_CASE_BLIND<br> <span style='color:turquoise'>#endif</span><br>                                 )<br>                     != APR_SUCCESS)) {<br>         <span style='color:red'>return</span> (NULL);<br>     }<br> <br>     <span style='color:red'>if</span> (ignore_entry(d, ap_make_full_path(r->pool,<br>                                           r->filename, dirent->name))) {<br>         <span style='color:red'>return</span> (NULL);<br>     }<br> <br>     <span style='color:red'>if</span> (!(rr = ap_sub_req_lookup_dirent(dirent, r, AP_SUBREQ_NO_ARGS, NULL))) {<br>         <span style='color:red'>return</span> (NULL);<br>     }<br> <br>     <span style='color:red'>if</span> ((autoindex_opts & SHOW_FORBIDDEN)<br>         && (rr->status == HTTP_UNAUTHORIZED || rr->status == HTTP_FORBIDDEN)) {<br>         show_forbidden = 1;<br>     }<br> <br>     <span style='color:red'>if</span> ((rr->finfo.filetype != APR_DIR && rr->finfo.filetype != APR_REG)<br>         || !(rr->status == OK || ap_is_HTTP_SUCCESS(rr->status)<br>                               || ap_is_HTTP_REDIRECT(rr->status)<br>                               || show_forbidden == 1)) {<br>         ap_destroy_sub_req(rr);<br>         <span style='color:red'>return</span> (NULL);<br>     }<br> <br>     p = (<span style='color:red'>struct</span> ent *) apr_pcalloc(r->pool, <span style='color:red'>sizeof</span>(<span style='color:red'>struct</span> ent));<br>     <span style='color:red'>if</span> (dirent->filetype == APR_DIR) {<br>         p->name = apr_pstrcat(r->pool, dirent->name, <span style='color:blue'>"/"</span>, NULL);<br>     }<br>     <span style='color:red'>else</span> {<br>         p->name = apr_pstrdup(r->pool, dirent->name);<br>     }<br>     p->size = -1;<br>     p->icon = NULL;<br>     p->alt = NULL;<br>     p->desc = NULL;<br>     p->lm = -1;<br>     p->isdir = 0;<br>     p->key = apr_toupper(keyid);<br>     p->ascending = (apr_toupper(direction) == D_ASCENDING);<br>     p->version_sort = !!(autoindex_opts & VERSION_SORT);<br>     p->ignore_case = !!(autoindex_opts & IGNORE_CASE);<br> <br>     <span style='color:red'>if</span> (autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING)) {<br>         p->lm = rr->finfo.mtime;<br>         <span style='color:red'>if</span> (dirent->filetype == APR_DIR) {<br>             <span style='color:red'>if</span> (autoindex_opts & FOLDERS_FIRST) {<br>                 p->isdir = 1;<br>             }<br>             rr->filename = ap_make_dirstr_parent (rr->pool, rr->filename);<br> <br>             <span style='color:green'>/* omit the trailing slash (1.3 compat) */</span><br>             rr->filename[strlen(rr->filename) - 1] = <span style='color:blue'>'\0'</span>;<br> <br>             <span style='color:red'>if</span> (!(p->icon = find_icon(d, rr, 1))) {<br>                 p->icon = find_default_icon(d, <span style='color:blue'>"^^DIRECTORY^^"</span>);<br>             }<br>             <span style='color:red'>if</span> (!(p->alt = find_alt(d, rr, 1))) {<br>                 <span style='color:red'>if</span> (!(p->alt = find_default_alt(d, <span style='color:blue'>"^^DIRECTORY^^"</span>))) {<br>                     p->alt = <span style='color:blue'>"DIR"</span>;<br>                 }<br>             }<br>         }<br>         <span style='color:red'>else</span> {<br>             p->icon = find_icon(d, rr, 0);<br>             p->alt = find_alt(d, rr, 0);<br>             p->size = rr->finfo.size;<br>         }<br> <br>         p->desc = find_desc(d, rr->filename);<br> <br>         <span style='color:red'>if</span> ((!p->desc) && (autoindex_opts & SCAN_HTML_TITLES)) {<br>             p->desc = apr_pstrdup(r->pool, find_title(rr));<br>         }<br>     }<br>     ap_destroy_sub_req(rr);<br>     <span style='color:green'>/*<br> <span style='color:green'>     * We don't need to take any special action for the file size key.</span><br> <span style='color:green'>     * If we did, it would go here.</span><br>      */</span><br>     <span style='color:red'>if</span> (keyid == K_LAST_MOD) {<br>         <span style='color:red'>if</span> (p->lm < 0) {<br>             p->lm = 0;<br>         }<br>     }<br>     <span style='color:red'>return</span> (p);<br> }<br> <br> <span style='color:red'>static</span> <span style='color:red'>char</span> *terminate_description(autoindex_config_rec *d, <span style='color:red'>char</span> *desc,<br>                                    apr_int32_t autoindex_opts, <span style='color:red'>int</span> desc_width)<br> {<br>     <span style='color:red'>int</span> maxsize = desc_width;<br>     <span style='color:red'>int</span> x;<br> <br>     <span style='color:green'>/*<br> <span style='color:green'>     * If there's no DescriptionWidth in effect, default to the old</span><br> <span style='color:green'>     * behaviour of adjusting the description size depending upon</span><br> <span style='color:green'>     * what else is being displayed.  Otherwise, stick with the</span><br> <span style='color:green'>     * setting.</span><br>      */</span><br>     <span style='color:red'>if</span> (d->desc_adjust == K_UNSET) {<br>         <span style='color:red'>if</span> (autoindex_opts & SUPPRESS_ICON) {<br>             maxsize += 6;<br>         }<br>         <span style='color:red'>if</span> (autoindex_opts & SUPPRESS_LAST_MOD) {<br>             maxsize += 19;<br>         }<br>         <span style='color:red'>if</span> (autoindex_opts & SUPPRESS_SIZE) {<br>             maxsize += 7;<br>         }<br>     }<br>     <span style='color:red'>for</span> (x = 0; desc[x] && ((maxsize > 0) || (desc[x] == <span style='color:blue'>'<'</span>)); x++) {<br>         <span style='color:red'>if</span> (desc[x] == <span style='color:blue'>'<'</span>) {<br>             <span style='color:red'>while</span> (desc[x] != <span style='color:blue'>'>'</span>) {<br>                 <span style='color:red'>if</span> (!desc[x]) {<br>                     maxsize = 0;<br>                     <span style='color:red'>break</span>;<br>                 }<br>                 ++x;<br>             }<br>         }<br>         <span style='color:red'>else</span> <span style='color:red'>if</span> (desc[x] == <span style='color:blue'>'&'</span>) {<br>             <span style='color:green'>/* entities like ä count as one character */</span><br>             --maxsize;<br>             <span style='color:red'>for</span> ( ; desc[x] != <span style='color:blue'>';'</span>; ++x) {<br>                 <span style='color:red'>if</span> (desc[x] == <span style='color:blue'>'\0'</span>) {<br>                      maxsize = 0;<br>                      <span style='color:red'>break</span>;<br>                 }<br>             }<br>         }<br>         <span style='color:red'>else</span> {<br>             --maxsize;<br>         }<br>     }<br>     <span style='color:red'>if</span> (!maxsize && desc[x] != <span style='color:blue'>'\0'</span>) {<br>         desc[x - 1] = <span style='color:blue'>'>'</span>;      <span style='color:green'>/* Grump. */</span><br>         desc[x] = <span style='color:blue'>'\0'</span>;         <span style='color:green'>/* Double Grump! */</span><br>     }<br>     <span style='color:red'>return</span> desc;<br> }<br> <br> <span style='color:green'>/*<br> <span style='color:green'> * Emit the anchor for the specified field.  If a field is the key for the</span><br> <span style='color:green'> * current request, the link changes its meaning to reverse the order when</span><br> <span style='color:green'> * selected again.  Non-active fields always start in ascending order.</span><br>  */</span><br> <span style='color:red'>static</span> <span style='color:red'>void</span> emit_link(request_rec *r, <span style='color:red'>const</span> <span style='color:red'>char</span> *anchor, <span style='color:red'>char</span> column,<br>                       <span style='color:red'>char</span> curkey, <span style='color:red'>char</span> curdirection,<br>                       <span style='color:red'>const</span> <span style='color:red'>char</span> *colargs, <span style='color:red'>int</span> nosort)<br> {<br>     <span style='color:red'>if</span> (!nosort) {<br>         <span style='color:red'>char</span> qvalue[9];<br> <br>         qvalue[0] = <span style='color:blue'>'?'</span>;<br>         qvalue[1] = <span style='color:blue'>'C'</span>;<br>         qvalue[2] = <span style='color:blue'>'='</span>;<br>         qvalue[3] = column;<br>         qvalue[4] = <span style='color:blue'>';'</span>;<br>         qvalue[5] = <span style='color:blue'>'O'</span>;<br>         qvalue[6] = <span style='color:blue'>'='</span>;<br>                     <span style='color:green'>/* reverse? */</span><br>         qvalue[7] = ((curkey == column) && (curdirection == D_ASCENDING))<br>                       ? D_DESCENDING : D_ASCENDING;<br>         qvalue[8] = <span style='color:blue'>'\0'</span>;<br>         ap_rvputs(r, <span style='color:blue'>"<a href=\"</span><span style='color:blue'>", qvalue, colargs ? colargs : "</span><span style='color:blue'>",</span><br>                      <span style='color:blue'>"\"</span>><span style='color:blue'>", anchor, "</span></a><span style='color:blue'>", NULL);</span><br>     }<br>     <span style='color:red'>else</span> {<br>         ap_rputs(anchor, r);<br>     }<br> }<br> <br> <span style='color:red'>static</span> <span style='color:red'>void</span> output_directories(<span style='color:red'>struct</span> ent **ar, <span style='color:red'>int</span> n,<br>                                autoindex_config_rec *d, request_rec *r,<br>                                apr_int32_t autoindex_opts, <span style='color:red'>char</span> keyid,<br>                                <span style='color:red'>char</span> direction, <span style='color:red'>const</span> <span style='color:red'>char</span> *colargs)<br> {<br>     <span style='color:red'>int</span> x;<br>     apr_size_t rv;<br>     <span style='color:red'>char</span> *tp;<br>     <span style='color:red'>int</span> static_columns = !!(autoindex_opts & SUPPRESS_COLSORT);<br>     apr_pool_t *scratch;<br>     <span style='color:red'>int</span> name_width;<br>     <span style='color:red'>int</span> desc_width;<br>     <span style='color:red'>char</span> *datetime_format;<br>     <span style='color:red'>char</span> *name_scratch;<br>     <span style='color:red'>char</span> *pad_scratch;<br>     <span style='color:red'>char</span> *breakrow = <span style='color:blue'>""</span>;<br> <br>     apr_pool_create(&scratch, r->pool);<br>     apr_pool_tag(scratch, <span style='color:blue'>"autoindex_scratch"</span>);<br> <br>     name_width = d->name_width;<br>     desc_width = d->desc_width;<br>     datetime_format = d->datetime_format ? d->datetime_format : <span style='color:blue'>"%Y-%m-%d %H:%M"</span>;<br> <br>     <span style='color:red'>if</span> ((autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING))<br>                         == FANCY_INDEXING) {<br>         <span style='color:red'>if</span> (d->name_adjust == K_ADJUST) {<br>             <span style='color:red'>for</span> (x = 0; x < n; x++) {<br>                 <span style='color:red'>int</span> t = strlen(ar[x]->name);<br>                 <span style='color:red'>if</span> (t > name_width) {<br>                     name_width = t;<br>                 }<br>             }<br>         }<br> <br>         <span style='color:red'>if</span> (d->desc_adjust == K_ADJUST) {<br>             <span style='color:red'>for</span> (x = 0; x < n; x++) {<br>                 <span style='color:red'>if</span> (ar[x]->desc != NULL) {<br>                     <span style='color:red'>int</span> t = strlen(ar[x]->desc);<br>                     <span style='color:red'>if</span> (t > desc_width) {<br>                         desc_width = t;<br>                     }<br>                 }<br>             }<br>         }<br>     }<br>     name_scratch = apr_palloc(r->pool, name_width + 1);<br>     pad_scratch = apr_palloc(r->pool, name_width + 1);<br>     memset(pad_scratch, <span style='color:blue'>' '</span>, name_width);<br>     pad_scratch[name_width] = <span style='color:blue'>'\0'</span>;<br> <br>     <span style='color:red'>if</span> (autoindex_opts & TABLE_INDEXING) {<br>         <span style='color:red'>int</span> cols = 1;<br>         <span style='color:red'>if</span> (d->style_sheet != NULL) {<br>             <span style='color:green'>/* Emit table with style id */</span><br>             ap_rputs(<span style='color:blue'>" <table id=\"</span>indexlist\<span style='color:blue'>">\n <tr class=\"</span>indexhead\<span style='color:blue'>">"</span>, r);<br>         } <span style='color:red'>else</span> {<br>             ap_rputs(<span style='color:blue'>" <table>\n <tr>"</span>, r);<br>         }<br>         <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_ICON)) {<br>             ap_rvputs(r, <span style='color:blue'>"<th"</span>, (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexcolicon\<span style='color:blue'>">"</span> : <span style='color:blue'>" valign=\"</span>top\<span style='color:blue'>"><wbr>"</span>, NULL);<br>             <span style='color:red'>if</span> ((tp = find_default_icon(d, <span style='color:blue'>"^^BLANKICON^^"</span>))) {<br>                 ap_rvputs(r, <span style='color:blue'>"<img src=\"</span><span style='color:blue'>", ap_escape_html(scratch, tp),</span><br>                              <span style='color:blue'>"\"</span> alt=\<span style='color:blue'>"[ICO]\"</span><span style='color:blue'>", NULL);</span><br>                 <span style='color:red'>if</span> (d->icon_width) {<br>                     ap_rprintf(r, <span style='color:blue'>" width=\"</span>%d\<span style='color:blue'>""</span>, d->icon_width);<br>                 }<br>                 <span style='color:red'>if</span> (d->icon_height) {<br>                     ap_rprintf(r, <span style='color:blue'>" height=\"</span>%d\<span style='color:blue'>""</span>, d->icon_height);<br>                 }<br> <br>                 <span style='color:red'>if</span> (autoindex_opts & EMIT_XHTML) {<br>                     ap_rputs(<span style='color:blue'>" /"</span>, r);<br>                 }<br>                 ap_rputs(<span style='color:blue'>"></th>"</span>, r);<br>             }<br>             <span style='color:red'>else</span> {<br>                 ap_rputs(<span style='color:blue'>" </th>"</span>, r);<br>             }<br> <br>             ++cols;<br>         }<br>         ap_rvputs(r, <span style='color:blue'>"<th"</span>, (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexcolname\<span style='color:blue'>">"</span> : <span style='color:blue'>">"</span>, NULL);<br>         emit_link(r, <span style='color:blue'>"Name"</span>, K_NAME, keyid, direction,<br>                   colargs, static_columns);<br>         <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_LAST_MOD)) {<br>             ap_rvputs(r, <span style='color:blue'>"</th><th"</span>, (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexcollastmod\<span style='color:blue'>">"</span> : <span style='color:blue'>">"</span>, NULL);<br>             emit_link(r, <span style='color:blue'>"Last modified"</span>, K_LAST_MOD, keyid, direction,<br>                       colargs, static_columns);<br>             ++cols;<br>         }<br>         <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_SIZE)) {<br>             ap_rvputs(r, <span style='color:blue'>"</th><th"</span>, (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexcolsize\<span style='color:blue'>">"</span> : <span style='color:blue'>">"</span>, NULL);<br>             emit_link(r, <span style='color:blue'>"Size"</span>, K_SIZE, keyid, direction,<br>                       colargs, static_columns);<br>             ++cols;<br>         }<br>         <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_DESC)) {<br>             ap_rvputs(r, <span style='color:blue'>"</th><th"</span>, (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexcoldesc\<span style='color:blue'>">"</span> : <span style='color:blue'>">"</span>, NULL);<br>             emit_link(r, <span style='color:blue'>"Description"</span>, K_DESC, keyid, direction,<br>                       colargs, static_columns);<br>             ++cols;<br>         }<br>         <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_RULES)) {<br>             breakrow = apr_psprintf(r->pool,<br>                                     <span style='color:blue'>" <tr%s><th colspan=\"</span>%d\<span style='color:blue'>">"</span><br>                                     <span style='color:blue'>"<hr%s></th></tr>\n"</span>,<br>                                     (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexbreakrow\<span style='color:blue'>""</span> : <span style='color:blue'>""</span>,<br>                                     cols,<br>                                     (autoindex_opts & EMIT_XHTML) ? <span style='color:blue'>" /"</span> : <span style='color:blue'>""</span>);<br>         }<br>         ap_rvputs(r, <span style='color:blue'>"</th></tr>\n"</span>, breakrow, NULL);<br>     }<br>     <span style='color:red'>else</span> <span style='color:red'>if</span> (autoindex_opts & FANCY_INDEXING) {<br>         ap_rputs(<span style='color:blue'>"<pre>"</span>, r);<br>         <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_ICON)) {<br>             <span style='color:red'>if</span> ((tp = find_default_icon(d, <span style='color:blue'>"^^BLANKICON^^"</span>))) {<br>                 ap_rvputs(r, <span style='color:blue'>"<img src=\"</span><span style='color:blue'>", ap_escape_html(scratch, tp),</span><br>                              <span style='color:blue'>"\"</span> alt=\<span style='color:blue'>"Icon \"</span><span style='color:blue'>", NULL);</span><br>                 <span style='color:red'>if</span> (d->icon_width) {<br>                     ap_rprintf(r, <span style='color:blue'>" width=\"</span>%d\<span style='color:blue'>""</span>, d->icon_width);<br>                 }<br>                 <span style='color:red'>if</span> (d->icon_height) {<br>                     ap_rprintf(r, <span style='color:blue'>" height=\"</span>%d\<span style='color:blue'>""</span>, d->icon_height);<br>                 }<br> <br>                 <span style='color:red'>if</span> (autoindex_opts & EMIT_XHTML) {<br>                     ap_rputs(<span style='color:blue'>" /"</span>, r);<br>                 }<br>                 ap_rputs(<span style='color:blue'>"> "</span>, r);<br>             }<br>             <span style='color:red'>else</span> {<br>                 ap_rputs(<span style='color:blue'>" "</span>, r);<br>             }<br>         }<br>         emit_link(r, <span style='color:blue'>"Name"</span>, K_NAME, keyid, direction,<br>                   colargs, static_columns);<br>         ap_rputs(pad_scratch + 4, r);<br>         <span style='color:green'>/*<br> <span style='color:green'>         * Emit the guaranteed-at-least-one-space-between-columns byte.</span><br>          */</span><br>         ap_rputs(<span style='color:blue'>" "</span>, r);<br>         <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_LAST_MOD)) {<br>             emit_link(r, <span style='color:blue'>"Last modified"</span>, K_LAST_MOD, keyid, direction,<br>                       colargs, static_columns);<br>             ap_rputs(<span style='color:blue'>" "</span>, r);<br>         }<br>         <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_SIZE)) {<br>             emit_link(r, <span style='color:blue'>"Size"</span>, K_SIZE, keyid, direction,<br>                       colargs, static_columns);<br>             ap_rputs(<span style='color:blue'>" "</span>, r);<br>         }<br>         <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_DESC)) {<br>             emit_link(r, <span style='color:blue'>"Description"</span>, K_DESC, keyid, direction,<br>                       colargs, static_columns);<br>         }<br>         <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_RULES)) {<br>             ap_rputs(<span style='color:blue'>"<hr"</span>, r);<br>             <span style='color:red'>if</span> (autoindex_opts & EMIT_XHTML) {<br>                 ap_rputs(<span style='color:blue'>" /"</span>, r);<br>             }<br>             ap_rputs(<span style='color:blue'>">"</span>, r);<br>         }<br>         <span style='color:red'>else</span> {<br>             ap_rputc(<span style='color:blue'>'\n'</span>, r);<br>         }<br>     }<br>     <span style='color:red'>else</span> {<br>         ap_rputs(<span style='color:blue'>"<ul>"</span>, r);<br>     }<br> <br>     <span style='color:red'>for</span> (x = 0; x < n; x++) {<br>         <span style='color:red'>char</span> *anchor, *t, *t2;<br>         <span style='color:red'>int</span> nwidth;<br> <br>         apr_pool_clear(scratch);<br> <br>         t = ar[x]->name;<br>         anchor = ap_escape_html(scratch, ap_os_escape_path(scratch, t, 0));<br> <br>         <span style='color:red'>if</span> (!x && t[0] == <span style='color:blue'>'/'</span>) {<br>             t2 = <span style='color:blue'>"Parent Directory"</span>;<br>         }<br>         <span style='color:red'>else</span> {<br>             t2 = t;<br>         }<br> <br>         <span style='color:red'>if</span> (autoindex_opts & TABLE_INDEXING) {<br>             <span style='color:green'>/* Even/Odd rows for IndexStyleSheet */</span><br>             <span style='color:red'>if</span> (d->style_sheet != NULL) {<br>                 <span style='color:red'>if</span> (ar[x]->alt && (autoindex_opts & ADDALTCLASS)) {<br>                     <span style='color:green'>/* Include alt text in class name, distinguish between odd and even rows */</span><br>                     <span style='color:red'>char</span> *altclass = apr_pstrdup(scratch, ar[x]->alt);<br>                     ap_str_tolower(altclass);<br>                     ap_rvputs(r, <span style='color:blue'>" <tr class=\"</span><span style='color:blue'>", ( x & 0x1) ? "</span>odd-<span style='color:blue'>" : "</span>even-<span style='color:blue'>", altclass, "</span>\<span style='color:blue'>">"</span>, NULL);<br>                 } <span style='color:red'>else</span> {<br>                     <span style='color:green'>/* Distinguish between odd and even rows */</span><br>                     ap_rvputs(r, <span style='color:blue'>" <tr class=\"</span><span style='color:blue'>", ( x & 0x1) ? "</span>odd<span style='color:blue'>" : "</span>even<span style='color:blue'>", "</span>\<span style='color:blue'>">"</span>, NULL);<br>                 }<br>             } <span style='color:red'>else</span> {<br>                 ap_rputs(<span style='color:blue'>"<tr>"</span>, r);<br>             }<br> <br>             <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_ICON)) {<br>                 ap_rvputs(r, <span style='color:blue'>"<td"</span>, (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexcolicon\<span style='color:blue'>">"</span> : <span style='color:blue'>" valign=\"</span>top\<span style='color:blue'>"><wbr>"</span>, NULL);<br>                 <span style='color:red'>if</span> (autoindex_opts & ICONS_ARE_LINKS) {<br>                     ap_rvputs(r, <span style='color:blue'>"<a href=\"</span><span style='color:blue'>", anchor, "</span>\<span style='color:blue'>">"</span>, NULL);<br>                 }<br>                 <span style='color:red'>if</span> ((ar[x]->icon) || d->default_icon) {<br>                     ap_rvputs(r, <span style='color:blue'>"<img src=\"</span><span style='color:blue'>",</span><br>                               ap_escape_html(scratch,<br>                                              ar[x]->icon ? ar[x]->icon<br>                                                          : d->default_icon),<br>                               <span style='color:blue'>"\"</span> alt=\<span style='color:blue'>"["</span>, (ar[x]->alt ? ar[x]->alt : <span style='color:blue'>" "</span>),<br>                               <span style='color:blue'>"]\"</span><span style='color:blue'>", NULL);</span><br>                     <span style='color:red'>if</span> (d->icon_width) {<br>                         ap_rprintf(r, <span style='color:blue'>" width=\"</span>%d\<span style='color:blue'>""</span>, d->icon_width);<br>                     }<br>                     <span style='color:red'>if</span> (d->icon_height) {<br>                         ap_rprintf(r, <span style='color:blue'>" height=\"</span>%d\<span style='color:blue'>""</span>, d->icon_height);<br>                     }<br> <br>                     <span style='color:red'>if</span> (autoindex_opts & EMIT_XHTML) {<br>                         ap_rputs(<span style='color:blue'>" /"</span>, r);<br>                     }<br>                     ap_rputs(<span style='color:blue'>">"</span>, r);<br>                 }<br>                 <span style='color:red'>else</span> {<br>                     ap_rputs(<span style='color:blue'>" "</span>, r);<br>                 }<br>                 <span style='color:red'>if</span> (autoindex_opts & ICONS_ARE_LINKS) {<br>                     ap_rputs(<span style='color:blue'>"</a></td>"</span>, r);<br>                 }<br>                 <span style='color:red'>else</span> {<br>                     ap_rputs(<span style='color:blue'>"</td>"</span>, r);<br>                 }<br>             }<br>             <span style='color:red'>if</span> (d->name_adjust == K_ADJUST) {<br>                 ap_rvputs(r, <span style='color:blue'>"<td"</span>, (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexcolname\<span style='color:blue'>">"</span> : <span style='color:blue'>">"</span>, <span style='color:blue'>"<a href=\"</span><span style='color:blue'>", anchor, "</span><wbr>\<span style='color:blue'>">"</span>,<br>                           ap_escape_html(scratch, t2), <span style='color:blue'>"</a>"</span>, NULL);<br>             }<br>             <span style='color:red'>else</span> {<br>                 nwidth = strlen(t2);<br>                 <span style='color:red'>if</span> (nwidth > name_width) {<br>                   memcpy(name_scratch, t2, name_width - 3);<br>                   name_scratch[name_width - 3] = <span style='color:blue'>'.'</span>;<br>                   name_scratch[name_width - 2] = <span style='color:blue'>'.'</span>;<br>                   name_scratch[name_width - 1] = <span style='color:blue'>'>'</span>;<br>                   name_scratch[name_width] = 0;<br>                   t2 = name_scratch;<br>                   nwidth = name_width;<br>                 }<br>                 ap_rvputs(r, <span style='color:blue'>"<td"</span>, (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexcolname\<span style='color:blue'>">"</span> : <span style='color:blue'>">"</span>, <span style='color:blue'>"<a href=\"</span><span style='color:blue'>", anchor, "</span><wbr>\<span style='color:blue'>">"</span>,<br>                           ap_escape_html(scratch, t2),<br>                           <span style='color:blue'>"</a>"</span>, pad_scratch + nwidth, NULL);<br>             }<br>             <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_LAST_MOD)) {<br>                 <span style='color:red'>if</span> (ar[x]->lm != -1) {<br>                     <span style='color:red'>char</span> time_str[32];<br>                     apr_time_exp_t ts;<br>                     apr_time_exp_lt(&ts, ar[x]->lm);<br>                     apr_strftime(time_str, &rv, <span style='color:red'>sizeof</span>(time_str),<br>                                  datetime_format,<br>                                  &ts);<br>                     ap_rvputs(r, <span style='color:blue'>"</td><td"</span>, (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexcollastmod\<span style='color:blue'>">"</span> : <span style='color:blue'>" align=\"</span>righ<wbr>t\<span style='color:blue'>">"</span>, time_str, <span style='color:blue'>" "</span>, NULL);<br>                 }<br>                 <span style='color:red'>else</span> {<br>                     ap_rvputs(r, <span style='color:blue'>"</td><td"</span>, (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexcollastmod\<span style='color:blue'>"> "</span> : <span style='color:blue'>"> "</span>, NULL);<br>                 }<br>             }<br>             <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_SIZE)) {<br>                 <span style='color:red'>char</span> buf[5];<br>                 ap_rvputs(r, <span style='color:blue'>"</td><td"</span>, (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexcolsize\<span style='color:blue'>">"</span> : <span style='color:blue'>" align=\"</span>right\<span style='color:blue'>"<wbr>>"</span>,<br>                           apr_strfsize(ar[x]->size, buf), NULL);<br>             }<br>             <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_DESC)) {<br>                 <span style='color:red'>if</span> (ar[x]->desc) {<br>                     <span style='color:red'>if</span> (d->desc_adjust == K_ADJUST) {<br>                         ap_rvputs(r, <span style='color:blue'>"</td><td"</span>, (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexcoldesc\<span style='color:blue'>">"</span> : <span style='color:blue'>">"</span>, ar[x]->desc, NU<wbr>LL);<br>                     }<br>                     <span style='color:red'>else</span> {<br>                         ap_rvputs(r, <span style='color:blue'>"</td><td"</span>, (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexcoldesc\<span style='color:blue'>">"</span> : <span style='color:blue'>">"</span>,<br>                                   terminate_description(d, ar[x]->desc,<br>                                                         autoindex_opts,<br>                                                         desc_width), NULL);<br>                     }<br>                 }<br>                 <span style='color:red'>else</span> {<br>                     ap_rvputs(r, <span style='color:blue'>"</td><td"</span>, (d->style_sheet != NULL) ? <span style='color:blue'>" class=\"</span>indexcoldesc\<span style='color:blue'>">"</span> : <span style='color:blue'>">"</span>, <span style='color:blue'>" "</span>, NULL);<br>                 }<br>             }<br>             ap_rputs(<span style='color:blue'>"</td></tr>\n"</span>, r);<br>         }<br>         <span style='color:red'>else</span> <span style='color:red'>if</span> (autoindex_opts & FANCY_INDEXING) {<br>             <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_ICON)) {<br>                 <span style='color:red'>if</span> (autoindex_opts & ICONS_ARE_LINKS) {<br>                     ap_rvputs(r, <span style='color:blue'>"<a href=\"</span><span style='color:blue'>", anchor, "</span>\<span style='color:blue'>">"</span>, NULL);<br>                 }<br>                 <span style='color:red'>if</span> ((ar[x]->icon) || d->default_icon) {<br>                     ap_rvputs(r, <span style='color:blue'>"<img src=\"</span><span style='color:blue'>",</span><br>                               ap_escape_html(scratch,<br>                                              ar[x]->icon ? ar[x]->icon<br>                                                          : d->default_icon),<br>                               <span style='color:blue'>"\"</span> alt=\<span style='color:blue'>"["</span>, (ar[x]->alt ? ar[x]->alt : <span style='color:blue'>" "</span>),<br>                               <span style='color:blue'>"]\"</span><span style='color:blue'>", NULL);</span><br>                     <span style='color:red'>if</span> (d->icon_width) {<br>                         ap_rprintf(r, <span style='color:blue'>" width=\"</span>%d\<span style='color:blue'>""</span>, d->icon_width);<br>                     }<br>                     <span style='color:red'>if</span> (d->icon_height) {<br>                         ap_rprintf(r, <span style='color:blue'>" height=\"</span>%d\<span style='color:blue'>""</span>, d->icon_height);<br>                     }<br> <br>                     <span style='color:red'>if</span> (autoindex_opts & EMIT_XHTML) {<br>                         ap_rputs(<span style='color:blue'>" /"</span>, r);<br>                     }<br>                     ap_rputs(<span style='color:blue'>">"</span>, r);<br>                 }<br>                 <span style='color:red'>else</span> {<br>                     ap_rputs(<span style='color:blue'>" "</span>, r);<br>                 }<br>                 <span style='color:red'>if</span> (autoindex_opts & ICONS_ARE_LINKS) {<br>                     ap_rputs(<span style='color:blue'>"</a> "</span>, r);<br>                 }<br>                 <span style='color:red'>else</span> {<br>                     ap_rputc(<span style='color:blue'>' '</span>, r);<br>                 }<br>             }<br>             nwidth = strlen(t2);<br>             <span style='color:red'>if</span> (nwidth > name_width) {<br>                 memcpy(name_scratch, t2, name_width - 3);<br>                 name_scratch[name_width - 3] = <span style='color:blue'>'.'</span>;<br>                 name_scratch[name_width - 2] = <span style='color:blue'>'.'</span>;<br>                 name_scratch[name_width - 1] = <span style='color:blue'>'>'</span>;<br>                 name_scratch[name_width] = 0;<br>                 t2 = name_scratch;<br>                 nwidth = name_width;<br>             }<br>             ap_rvputs(r, <span style='color:blue'>"<a href=\"</span><span style='color:blue'>", anchor, "</span>\<span style='color:blue'>">"</span>,<br>                       ap_escape_html(scratch, t2),<br>                       <span style='color:blue'>"</a>"</span>, pad_scratch + nwidth, NULL);<br>             <span style='color:green'>/*<br> <span style='color:green'>             * The blank before the storm.. er, before the next field.</span><br>              */</span><br>             ap_rputs(<span style='color:blue'>" "</span>, r);<br>             <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_LAST_MOD)) {<br>                 <span style='color:red'>if</span> (ar[x]->lm != -1) {<br>                     <span style='color:red'>char</span> time_str[32];<br>                     apr_time_exp_t ts;<br>                     apr_time_exp_lt(&ts, ar[x]->lm);<br>                     apr_strftime(time_str, &rv, <span style='color:red'>sizeof</span>(time_str),<br>                                 datetime_format,<br>                                 &ts);<br>                     ap_rvputs(r, time_str, <span style='color:blue'>" "</span>, NULL);<br>                 }<br>                 <span style='color:red'>else</span> {<br>                    <span style='color:green'>/* Length="1975-04-07 01:23  "  (default in 2.4 and later) or<br> <span style='color:green'>                    * Length="07-Apr-1975 01:24  ". (2.2 and UseOldDateFormat) </span><br> <span style='color:green'>                    * See 'datetime_format' above.</span><br>                     */</span><br>                     ap_rputs(<span style='color:blue'>" "</span>, r);<br>                 }<br>             }<br>             <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_SIZE)) {<br>                 <span style='color:red'>char</span> buf[5];<br>                 ap_rputs(apr_strfsize(ar[x]->size, buf), r);<br>                 ap_rputs(<span style='color:blue'>" "</span>, r);<br>             }<br>             <span style='color:red'>if</span> (!(autoindex_opts & SUPPRESS_DESC)) {<br>                 <span style='color:red'>if</span> (ar[x]->desc) {<br>                     ap_rputs(terminate_description(d, ar[x]->desc,<br>                                                    autoindex_opts,<br>                                                    desc_width), r);<br>                 }<br>             }<br>             ap_rputc(<span style='color:blue'>'\n'</span>, r);<br>         }<br>         <span style='color:red'>else</span> {<br>             ap_rvputs(r, <span style='color:blue'>"<li><a href=\"</span><span style='color:blue'>", anchor, "</span>\<span style='color:blue'>"> "</span>,<br>                       ap_escape_html(scratch, t2),<br>                       <span style='color:blue'>"</a></li>\n"</span>, NULL);<br>         }<br>     }<br>     <span style='color:red'>if</span> (autoindex_opts & TABLE_INDEXING) {<br>         ap_rvputs(r, breakrow, <span style='color:blue'>"</table>\n"</span>, NULL);<br>     }<br>     <span style='color:red'>else</span> <span style='color:red'>if</span> (autoindex_opts & FANCY_INDEXING) {<br> --> --------------------<br> <br> --> maximum size reached<br> <br> --> --------------------<br> <p align=center><label for='file'>quality</label><progress id='qual' value=95 max=100>95% </progress></p> </span><br> <h3><b>¤</b> Dauer der Verarbeitung: 0.38 Sekunden  (vorverarbeitet)  <b>¤</b></h3> <p height="2" colspan="2" align="center"><span style="font-size: 3px;">*© Formatika GbR, Deutschland</span></p> </div> </td> <td valign="top" align="center" class="greenscreensmall"> <br><br><br> <br> <table width="20%"> <tr><td align="center"> <a href="print.jsp?content=directory"> <br>Wurzel<br> <img border="0" src="/Images/penguin.jpg" height=36 alt="" title="Wurzel"> </a> </td> </tr> <tr><td align="center"> <a href="print.jsp?content=search" title="Suchen"> <br>Suchen<br> <img src="/Images/find.png" height="48" alt="" border="0"> </a> </td> </tr> <tr><td align="left"><a href="print.jsp?content=directory&detail=products/Sources/formale%20Sprachen/PVS/" title="Projekt "><br>Beweissystem der NASA</a></td></tr> <tr><td align="left"><a href="print.jsp?content=directory&detail=products/Sources/formale%20Sprachen/Isabelle/" title="Projekt "><br>Beweissystem Isabelle</a></td></tr> <tr><td align="left"><a href="print.jsp?content=directory&detail=products/Sources/formale%20Sprachen/Cobol/Test-Suite/" title="Projekt "><br>NIST Cobol Testsuite</a></td></tr> <tr><td align="left"><a href="print.jsp?content=directory&detail=products/Sources/formale%20Sprachen/Fortran/f90gl-1.2.15/" title="Projekt "><br>Cephes Mathematical Library</a></td></tr> <tr><td align="left"><a href="print.jsp?content=directory&detail=products/Sources/formale%20Sprachen/VDM/" title="Projekt "><br>Wiener Entwicklungsmethode</a></td></tr> <tr><td align="center"> <br> <h2>Haftungshinweis</h2> <div align="justify" class="featuresmall">Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.</div> <br> <h2>Bemerkung:</h2> <div align="justify" class="featuresmall"> Die farbliche Syntaxdarstellung ist noch experimentell.</div> <br> </td> </tr> </table> <br><br> <div> <br> <script src="https://www.formatika.de/base/formcheck.js"></script> <script> function checkform(form) { var res = true; res = res && isnotempty(form.file); res = res && isurl(form.file); return res; } </script> </div><br> <br> </td> </tr> </table> </div> <div class="printelement"> <script> warningpreview(); </script> </div> <p align=right class=hidden>2026-03-28</p> </td></tr> </table> </body> </html>