mod_autoindex.c revision 5df5e943f377522b19786f126097da3a7288e2f0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * contributor license agreements. See the NOTICE file distributed with
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * this work for additional information regarding copyright ownership.
b99dbaab171d91e1b664397cc40e039d0c087c65fielding * The ASF licenses this file to You under the Apache License, Version 2.0
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * (the "License"); you may not use this file except in compliance with
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the License. You may obtain a copy of the License at
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * 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 * mod_autoindex.c: Handles the on-the-fly html index generation
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * Rob McCool
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * Adapted to Apache by rst.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Version sort added by Martin Pool <mbp@humbug.org.au>.
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding/****************************************************************
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * Handling configuration directives...
7fae9cc4639013f3c04c085547256c68814aee8ftrawick * Define keys for sorting.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_NAME 'N' /* Sort by file name (default) */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_SIZE 'S' /* Size (absolute, not as displayed) */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_VALID "NMSD" /* String containing _all_ valid K_ opts */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define D_VALID "AD" /* String containing _all_ valid D_ opts */
785be1b6298010956622771c870ab3cd8ca57a2faaron * These are the dimensions of the default icons supplied with Apache.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Other default dimensions.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct ai_desc_t {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic APR_INLINE int response_is_html(request_rec *r)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *ctype = ap_field_noparam(r->pool, r->content_type);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * This routine puts the standard HTML header at the top of the index page.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * We include the DOCTYPE because we may be using features therefrom (i.e.,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void emit_preamble(request_rec *r, int xhtml, const char *title)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick "<html>\n <head>\n"
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick ap_rvputs(r, " <link rel=\"stylesheet\" href=\"", d->style_sheet,
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick "\" type=\"text/css\"", xhtml ? " />\n" : ">\n", NULL);
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregamesstatic void push_item(apr_array_header_t *arr, char *type, const char *to,
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames struct item *p = (struct item *) apr_array_push(arr);
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick p->apply_path = apr_pstrcat(arr->pool, path, "*", NULL);
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick p->apply_to = apr_pstrcat(arr->pool, "*", to, NULL);
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick else if (to) {
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawickstatic const char *add_alt(cmd_parms *cmd, void *d, const char *alt,
066877f1a045103acfdd376d48cdd473c33f409bdougm const char *to)
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick push_item(((autoindex_config_rec *) d)->alt_list, cmd->info, to,
d17890657bc529b3f9db20e5546511182b829565dreidstatic const char *add_icon(cmd_parms *cmd, void *d, const char *icon,
d17890657bc529b3f9db20e5546511182b829565dreid const char *to)
785be1b6298010956622771c870ab3cd8ca57a2faaron return "missing closing paren";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding push_item(((autoindex_config_rec *) d)->icon_list, cmd->info, to,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Add description text for a filename pattern. If the pattern has
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * wildcards already (or we need to add them), add leading and
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * trailing wildcards to it to ensure substring processing. If the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * pattern contains a '/' anywhere, force wildcard matching mode,
785be1b6298010956622771c870ab3cd8ca57a2faaron * add a slash to the prefix so that "bar/bletch" won't be matched
785be1b6298010956622771c870ab3cd8ca57a2faaron * by "foobar/bletch", and make a note that there's a delimiter;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the matching routine simplifies to just the actual filename
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * whenever it can. This allows definitions in parent directories
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * to be made for files in subordinate ones using relative paths.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Absent a strcasestr() function, we have to force wildcards on
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * systems for which "AAA" and "aaa" mean the same file.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const char *add_desc(cmd_parms *cmd, void *d, const char *desc,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *to)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding autoindex_config_rec *dcfg = (autoindex_config_rec *) d;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding desc_entry = (ai_desc_t *) apr_array_push(dcfg->desc_list);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding desc_entry->full_path = (ap_strchr_c(to, '/') == NULL) ? 0 : 1;
785be1b6298010956622771c870ab3cd8ca57a2faaron desc_entry->pattern = apr_pstrcat(dcfg->desc_list->pool,
785be1b6298010956622771c870ab3cd8ca57a2faaron desc_entry->pattern = apr_pstrdup(dcfg->desc_list->pool, to);
785be1b6298010956622771c870ab3cd8ca57a2faaron desc_entry->description = apr_pstrdup(dcfg->desc_list->pool, desc);
785be1b6298010956622771c870ab3cd8ca57a2faaronstatic const char *add_ignore(cmd_parms *cmd, void *d, const char *ext)
785be1b6298010956622771c870ab3cd8ca57a2faaron push_item(((autoindex_config_rec *) d)->ign_list, 0, ext, cmd->path, NULL);
785be1b6298010956622771c870ab3cd8ca57a2faaronstatic const char *add_opts(cmd_parms *cmd, void *d, int argc, char *const argv[])
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm autoindex_config_rec *d_cfg = (autoindex_config_rec *) d;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < argc; i++) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strcasecmp(w, "SuppressColumnSorting")) {
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick return "Cannot combine '+' or '-' with 'None' keyword";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Cannot combine '-' with IconWidth=n";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Cannot combine '-' with IconHeight=n";
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick return "NameWidth with no value may only appear as "
785be1b6298010956622771c870ab3cd8ca57a2faaron "'-NameWidth'";
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return "Cannot combine '-' with NameWidth=n";
785be1b6298010956622771c870ab3cd8ca57a2faaron return "NameWidth value must be greater than 5";
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return "DescriptionWidth with no value may only appear as "
785be1b6298010956622771c870ab3cd8ca57a2faaron "'-DescriptionWidth'";
785be1b6298010956622771c870ab3cd8ca57a2faaron return "Cannot combine '-' with DescriptionWidth=n";
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return "DescriptionWidth value must be greater than 12";
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return "Invalid directory indexing option";
785be1b6298010956622771c870ab3cd8ca57a2faaron return "Cannot combine other IndexOptions keywords with 'None'";
785be1b6298010956622771c870ab3cd8ca57a2faaronstatic const char *set_default_order(cmd_parms *cmd, void *m,
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf autoindex_config_rec *d_cfg = (autoindex_config_rec *) m;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return "First keyword must be 'Ascending' or 'Descending'";
785be1b6298010956622771c870ab3cd8ca57a2faaron return "Second keyword must be 'Name', 'Date', 'Size', or "
785be1b6298010956622771c870ab3cd8ca57a2faaron "'Description'";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE2("AddIcon", add_icon, BY_PATH, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "an icon URL followed by one or more filenames"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE2("AddIconByType", add_icon, BY_TYPE, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "an icon URL followed by one or more MIME types"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE2("AddIconByEncoding", add_icon, BY_ENCODING, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "an icon URL followed by one or more content encodings"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE2("AddAlt", add_alt, BY_PATH, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "alternate descriptive text followed by one or more "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "filenames"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE2("AddAltByType", add_alt, BY_TYPE, DIR_CMD_PERMS,
785be1b6298010956622771c870ab3cd8ca57a2faaron "alternate descriptive text followed by one or more MIME "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE2("AddAltByEncoding", add_alt, BY_ENCODING, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "alternate descriptive text followed by one or more "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "content encodings"),
785be1b6298010956622771c870ab3cd8ca57a2faaron AP_INIT_TAKE_ARGV("IndexOptions", add_opts, NULL, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "one or more index options [+|-][]"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_TAKE2("IndexOrderDefault", set_default_order, NULL, DIR_CMD_PERMS,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm "{Ascending,Descending} {Name,Size,Description,Date}"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_ITERATE("IndexIgnore", add_ignore, NULL, DIR_CMD_PERMS,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "one or more file extensions"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (void *)APR_OFFSETOF(autoindex_config_rec, ign_noinherit),
785be1b6298010956622771c870ab3cd8ca57a2faaron "Reset the inherited list of IndexIgnore filenames"),
785be1b6298010956622771c870ab3cd8ca57a2faaron AP_INIT_ITERATE2("AddDescription", add_desc, BY_PATH, DIR_CMD_PERMS,
785be1b6298010956622771c870ab3cd8ca57a2faaron "Descriptive text followed by one or more filenames"),
785be1b6298010956622771c870ab3cd8ca57a2faaron AP_INIT_RAW_ARGS("FancyIndexing", ap_set_deprecated, NULL, OR_ALL,
785be1b6298010956622771c870ab3cd8ca57a2faaron "The FancyIndexing directive is no longer supported. "
785be1b6298010956622771c870ab3cd8ca57a2faaron "Use IndexOptions FancyIndexing."),
785be1b6298010956622771c870ab3cd8ca57a2faaron (void *)APR_OFFSETOF(autoindex_config_rec, default_icon),
785be1b6298010956622771c870ab3cd8ca57a2faaron (void *)APR_OFFSETOF(autoindex_config_rec, style_sheet),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_TAKE1("IndexHeadInsert", ap_set_string_slot,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm (void *)APR_OFFSETOF(autoindex_config_rec, head_insert),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DIR_CMD_PERMS, "String to insert in HTML HEAD section"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void *create_autoindex_config(apr_pool_t *p, char *dummy)
785be1b6298010956622771c870ab3cd8ca57a2faaron (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
785be1b6298010956622771c870ab3cd8ca57a2faaron new->icon_list = apr_array_make(p, 4, sizeof(struct item));
785be1b6298010956622771c870ab3cd8ca57a2faaron new->alt_list = apr_array_make(p, 4, sizeof(struct item));
785be1b6298010956622771c870ab3cd8ca57a2faaron new->desc_list = apr_array_make(p, 4, sizeof(ai_desc_t));
785be1b6298010956622771c870ab3cd8ca57a2faaron new->ign_list = apr_array_make(p, 4, sizeof(struct item));
785be1b6298010956622771c870ab3cd8ca57a2faaron return (void *) new;
785be1b6298010956622771c870ab3cd8ca57a2faaronstatic void *merge_autoindex_configs(apr_pool_t *p, void *basev, void *addv)
785be1b6298010956622771c870ab3cd8ca57a2faaron autoindex_config_rec *base = (autoindex_config_rec *) basev;
785be1b6298010956622771c870ab3cd8ca57a2faaron autoindex_config_rec *add = (autoindex_config_rec *) addv;
785be1b6298010956622771c870ab3cd8ca57a2faaron new = (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
785be1b6298010956622771c870ab3cd8ca57a2faaron new->default_icon = add->default_icon ? add->default_icon
785be1b6298010956622771c870ab3cd8ca57a2faaron new->style_sheet = add->style_sheet ? add->style_sheet
785be1b6298010956622771c870ab3cd8ca57a2faaron new->head_insert = add->head_insert ? add->head_insert
785be1b6298010956622771c870ab3cd8ca57a2faaron new->icon_height = add->icon_height ? add->icon_height : base->icon_height;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->icon_width = add->icon_width ? add->icon_width : base->icon_width;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->charset = add->charset ? add->charset : base->charset;
785be1b6298010956622771c870ab3cd8ca57a2faaron new->alt_list = apr_array_append(p, add->alt_list, base->alt_list);
785be1b6298010956622771c870ab3cd8ca57a2faaron new->desc_list = apr_array_append(p, add->desc_list, base->desc_list);
785be1b6298010956622771c870ab3cd8ca57a2faaron new->icon_list = apr_array_append(p, add->icon_list, base->icon_list);
785be1b6298010956622771c870ab3cd8ca57a2faaron new->ign_list = add->ign_noinherit ? add->ign_list : apr_array_append(p, add->ign_list, base->ign_list);
785be1b6298010956622771c870ab3cd8ca57a2faaron * If the current directory explicitly says 'no options' then we also
785be1b6298010956622771c870ab3cd8ca57a2faaron * clear any incremental mods from being inheritable further down.
785be1b6298010956622771c870ab3cd8ca57a2faaron * If there were any nonincremental options selected for
785be1b6298010956622771c870ab3cd8ca57a2faaron * this directory, they dominate and we don't inherit *anything.*
785be1b6298010956622771c870ab3cd8ca57a2faaron * Contrariwise, we *do* inherit if the only settings here are
785be1b6298010956622771c870ab3cd8ca57a2faaron * incremental ones.
785be1b6298010956622771c870ab3cd8ca57a2faaron * We may have incremental settings, so make sure we don't
785be1b6298010956622771c870ab3cd8ca57a2faaron * inadvertently inherit an IndexOptions None from above.
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick * There are local nonincremental settings, which clear
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick * all inheritance from above. They *are* the new base settings.
785be1b6298010956622771c870ab3cd8ca57a2faaron * We're guaranteed that there'll be no overlap between
785be1b6298010956622771c870ab3cd8ca57a2faaron * the add-options and the remove-options.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Inherit the NameWidth settings if there aren't any specific to
785be1b6298010956622771c870ab3cd8ca57a2faaron * the new location; otherwise we'll end up using the defaults set in the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * config-rec creation routine.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Likewise for DescriptionWidth.
91583d2e9c0550f539ea6f4dedf051979ad1ad88fanf new->default_keyid = add->default_keyid ? add->default_keyid
91583d2e9c0550f539ea6f4dedf051979ad1ad88fanf new->default_direction = add->default_direction ? add->default_direction
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/****************************************************************
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Looking things up in config entries...
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick/* Structure used to hold entries when we're actually building an index */
644be6f54749d2d9950d2c4d2ac448f7af016d26martinstatic char *find_item(const char *content_type, const char *content_encoding,
0db1b9810f06c0e3c537e0e0dfbc30160c308526trawick /* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick if ((path[0] == '^') || (!ap_strcmp_match(path, p->apply_path))) {
3c48210f662a2ab8ed90708989e04c09aae33cb2trawick if (!*(p->apply_to)) {
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (!path_only) {
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf return p->data;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic char *find_item_by_request(request_rec *r, apr_array_header_t *list, int path_only)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return find_item(ap_field_noparam(r->pool, r->content_type),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r->content_encoding, r->filename, list, path_only);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define find_icon(d,p,t) find_item_by_request(p,d->icon_list,t)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define find_alt(d,p,t) find_item_by_request(p,d->alt_list,t)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define find_default_icon(d,n) find_item(NULL, NULL, n, d->icon_list, 1)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define find_default_alt(d,n) find_item(NULL, NULL, n, d->alt_list, 1)
785be1b6298010956622771c870ab3cd8ca57a2faaron * Look through the list of pattern/description pairs and return the first one
785be1b6298010956622771c870ab3cd8ca57a2faaron * if any) that matches the filename in the request. If multiple patterns
785be1b6298010956622771c870ab3cd8ca57a2faaron * match, only the first one is used; since the order in the array is the
785be1b6298010956622771c870ab3cd8ca57a2faaron * same as the order in which directives were processed, earlier matching
785be1b6298010956622771c870ab3cd8ca57a2faaron * directives will dominate.
785be1b6298010956622771c870ab3cd8ca57a2faaronstatic char *find_desc(autoindex_config_rec *dcfg, const char *filename_full)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ai_desc_t *list = (ai_desc_t *) dcfg->desc_list->elts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *filename;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If the filename includes a path, extract just the name itself
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * for the simple matches.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((filename_only = ap_strrchr_c(filename_full, '/')) == NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Only use the full-path filename if the pattern contains '/'s.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding filename = (tuple->full_path) ? filename_full : filename_only;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Make the comparison using the cheapest method; only do
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * wildcard checking if we must.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding found = (apr_fnmatch(tuple->pattern, filename, MATCH_FLAGS) == 0);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding found = (ap_strstr_c(filename, tuple->pattern) != NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int ignore_entry(autoindex_config_rec *d, char *path)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#else /* !CASE_BLIND_FILESYSTEM */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * On some platforms, the match must be case-blind. This is really
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * a factor of the filesystem involved, but we can't detect that
e6cc28a5eb3371ba0c38e941855e71ff0054f50erbb * reliably - so we have to granularise at the OS level.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif /* !CASE_BLIND_FILESYSTEM */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*****************************************************************
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Actually generating output
785be1b6298010956622771c870ab3cd8ca57a2faaron * Elements of the emitted document:
785be1b6298010956622771c870ab3cd8ca57a2faaron * Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
785be1b6298010956622771c870ab3cd8ca57a2faaron * succeeds for the (content_type == text/html) header file.
785be1b6298010956622771c870ab3cd8ca57a2faaron * Header file
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Emitted if found (and able).
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * H1 tag line
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Emitted if a header file is NOT emitted.
785be1b6298010956622771c870ab3cd8ca57a2faaron * Directory stuff
785be1b6298010956622771c870ab3cd8ca57a2faaron * Always emitted.
785be1b6298010956622771c870ab3cd8ca57a2faaron * Emitted if FANCY_INDEXING is set.
785be1b6298010956622771c870ab3cd8ca57a2faaron * Readme file
785be1b6298010956622771c870ab3cd8ca57a2faaron * Emitted if found (and able).
785be1b6298010956622771c870ab3cd8ca57a2faaron * ServerSig
785be1b6298010956622771c870ab3cd8ca57a2faaron * Emitted if ServerSignature is not Off AND a readme file
785be1b6298010956622771c870ab3cd8ca57a2faaron * is NOT emitted.
785be1b6298010956622771c870ab3cd8ca57a2faaron * Postamble
785be1b6298010956622771c870ab3cd8ca57a2faaron * Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
785be1b6298010956622771c870ab3cd8ca57a2faaron * succeeds for the (content_type == text/html) readme file.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * emit a plain text file
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void do_emit_plain(request_rec *r, apr_file_t *f)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding while (!apr_file_eof(f)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding n = sizeof(char) * AP_IOBUFSIZE;
e6cc28a5eb3371ba0c38e941855e71ff0054f50erbb /* ###: better error here? */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding while (c < n) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = c; i < n; i++) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (buf[i] == '<' || buf[i] == '>' || buf[i] == '&') {
785be1b6298010956622771c870ab3cd8ca57a2faaron * Handle the preamble through the H1 tag line, inclusive. Locate
785be1b6298010956622771c870ab3cd8ca57a2faaron * the file with a subrequests. Process text/html documents by actually
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * running the subrequest; text/xxx documents get copied verbatim,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * and any other content type is ignored. This means that a non-text
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * document (such as HEADER.gif) might get multiviewed as the result
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * instead of a text document, meaning nothing will be displayed, but
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void emit_head(request_rec *r, char *header_fname, int suppress_amble,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *r_accept;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If there's a header file, send a subrequest to look for it. If it's
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * found and html do the subrequest, otherwise handle it
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r_accept_enc = apr_table_get(hdrs, "Accept-Encoding");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_table_setn(hdrs, "Accept", "text/html, text/plain");
382fa07a63096c4a1aabfed36433ea5ac9c40ad0trawick header_fname = apr_pstrcat(r->pool, header_fname, "?", r->args, NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && (rr = ap_sub_req_lookup_uri(header_fname, r, r->output_filters))
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Check for the two specific cases we allow: text/html and
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * text/anything-else. The former is allowed to be processed for
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Hope everything will work... */
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf /* This is a hack, but I can't find any better way to do this.
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf * The problem is that we have already created the sub-request,
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf * but we just inserted the OLD_WRITE filter, and the
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf * sub-request needs to pass its data through the OLD_WRITE
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * filter, or things go horribly wrong (missing data, data in
emit_amble = 0;
do_emit_plain(r, f);
apr_file_close(f);
emit_H1 = 0;
if (r_accept) {
if (r_accept_enc) {
if (emit_amble) {
if (emit_H1) {
int suppress_post = 0;
int suppress_sig = 0;
* text/anything-else. The former is allowed to be processed for
ap_filter_t *f;
do_emit_plain(r, f);
apr_file_close(f);
if (!suppress_sig) {
if (!suppress_post) {
apr_size_t n;
return NULL;
&& (response_is_html(r)
&& !r->content_encoding) {
return NULL;
return NULL;
for (x = 0, p = 0; titlebuf[x]; x++) {
if (!find[++p]) {
for (y = x; titlebuf[y]; y++) {
return NULL;
char direction)
char *testpath;
return (NULL);
if (!*p->name) {
return (NULL);
return (NULL);
int autoindex_opts,
char direction,
const char *pattern)
struct ent *p;
int show_forbidden = 0;
return (NULL);
#ifdef CASE_BLIND_FILESYSTEM
!= APR_SUCCESS)) {
return (NULL);
return (NULL);
return (NULL);
return (NULL);
p->isdir = 0;
if (p->lm < 0) {
p->lm = 0;
if (!desc[x]) {
maxsize = 0;
--maxsize;
maxsize = 0;
--maxsize;
return desc;
if (!nosort) {
char *tp;
int name_width;
int desc_width;
char *name_scratch;
char *pad_scratch;
== FANCY_INDEXING) {
if (t > name_width) {
name_width = t;
if (t > desc_width) {
desc_width = t;
ap_rvputs(r, "<th", (d->style_sheet != NULL) ? " class=\"indexcolicon\">" : " valign=\"top\">", NULL);
if (d->icon_width) {
if (d->icon_height) {
++cols;
++cols;
++cols;
++cols;
cols,
if (d->icon_width) {
if (d->icon_height) {
int nwidth;
t2 = t;
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcolicon\">" : " valign=\"top\">", NULL);
: d->default_icon),
if (d->icon_width) {
if (d->icon_height) {
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcolname\">" : ">", "<a href=\"", anchor, "\">",
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcolname\">" : ">", "<a href=\"", anchor, "\">",
&ts);
ap_rvputs(r, "</td><td", (d->style_sheet != NULL) ? " class=\"indexcollastmod\">" : " align=\"right\">",time_str, NULL);
ap_rvputs(r, "</td><td", (d->style_sheet != NULL) ? " class=\"indexcollastmod\"> " : "> ", NULL);
ap_rvputs(r, "</td><td", (d->style_sheet != NULL) ? " class=\"indexcolsize\">" : " align=\"right\">",
ap_rvputs(r, "</td><td", (d->style_sheet != NULL) ? " class=\"indexcoldesc\">" : ">", ar[x]->desc, NULL);
: d->default_icon),
if (d->icon_width) {
if (d->icon_height) {
desc_width), r);
int result = 0;
case K_LAST_MOD:
case K_SIZE:
case K_DESC:
if (result) {
return result;
if (!result) {
if (!result) {
return result;
char *title_endp;
int num_ent = 0, x;
const char *qstring;
char keyid;
char direction;
char *colargs;
char *fullpath;
char *charset;
return HTTP_FORBIDDEN;
if (*charset) {
ap_set_etag(r);
if (r->header_only) {
& ~TABLE_INDEXING;
++eos;
if (p != NULL) {
head = p;
num_ent++;
const char *savename;
if (p != NULL) {
head = p;
num_ent++;
if (num_ent > 0) {
p = head;
ar[x++] = p;
p = p->next;
(int (*)(const void *, const void *)) dsortf);
int allow_opts;
return DECLINED;
return DECLINED;
int errstatus;
return errstatus;
return index_directory(r, d);
r->filename,
return HTTP_FORBIDDEN;