mod_autoindex.c revision 2e1aa1e99dea843ed25edc8f680ec22c2833d721
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * mod_autoindex.c: Handles the on-the-fly html index generation
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Rob McCool
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Adapted to Apache by rst.
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * Version sort added by Martin Pool <mbp@humbug.org.au>.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/****************************************************************
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * Handling configuration directives...
8a3228198adb03e6996f7738c361a612777ecab6aaron * Define keys for sorting.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_NAME 'N' /* Sort by file name (default) */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define K_SIZE 'S' /* Size (absolute, not as displayed) */
8a3228198adb03e6996f7738c361a612777ecab6aaron#define K_VALID "NMSD" /* String containing _all_ valid K_ opts */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define D_VALID "AD" /* String containing _all_ valid D_ opts */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * These are the dimensions of the default icons supplied with Apache.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Other default dimensions.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct ai_desc_t {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickstatic APR_INLINE int response_is_html(request_rec *r)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick char *ctype = ap_field_noparam(r->pool, r->content_type);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick * This routine puts the standard HTML header at the top of the index page.
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick * We include the DOCTYPE because we may be using features therefrom (i.e.,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickstatic void emit_preamble(request_rec *r, int xhtml, const char *title)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick "<html>\n <head>\n"
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick ap_rvputs(r, " <link rel=\"stylesheet\" href=\"", d->style_sheet,
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick "\" type=\"text/css\"", xhtml ? " />\n" : ">\n", NULL);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowestatic void push_item(apr_array_header_t *arr, char *type, const char *to,
649c9dd342a580016d29c2866de88a4609eb6457wrowe p->apply_path = apr_pstrcat(arr->pool, path, "*", NULL);
649c9dd342a580016d29c2866de88a4609eb6457wrowe else if (to) {
649c9dd342a580016d29c2866de88a4609eb6457wrowestatic const char *add_alt(cmd_parms *cmd, void *d, const char *alt,
649c9dd342a580016d29c2866de88a4609eb6457wrowe const char *to)
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe push_item(((autoindex_config_rec *) d)->alt_list, cmd->info, to,
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowestatic const char *add_icon(cmd_parms *cmd, void *d, const char *icon,
76185d819b745e953dd2cd636fbdd515c333e4a4trawick const char *to)
399cf0e5e061b49593817421b94305889fa6bc1fjorton return "missing closing paren";
d406be0d6a4f9e61bbdfa6c8cde2e09338dd650atrawick push_item(((autoindex_config_rec *) d)->icon_list, cmd->info, to,
ff0436077dc959b17a6f87825e4a106d211224c1wrowe * Add description text for a filename pattern. If the pattern has
ff0436077dc959b17a6f87825e4a106d211224c1wrowe * wildcards already (or we need to add them), add leading and
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb * trailing wildcards to it to ensure substring processing. If the
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb * pattern contains a '/' anywhere, force wildcard matching mode,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * add a slash to the prefix so that "bar/bletch" won't be matched
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * by "foobar/bletch", and make a note that there's a delimiter;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * the matching routine simplifies to just the actual filename
8a3228198adb03e6996f7738c361a612777ecab6aaron * whenever it can. This allows definitions in parent directories
ff0436077dc959b17a6f87825e4a106d211224c1wrowe * to be made for files in subordinate ones using relative paths.
ff0436077dc959b17a6f87825e4a106d211224c1wrowe * Absent a strcasestr() function, we have to force wildcards on
ff0436077dc959b17a6f87825e4a106d211224c1wrowe * systems for which "AAA" and "aaa" mean the same file.
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickstatic const char *add_desc(cmd_parms *cmd, void *d, const char *desc,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick const char *to)
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb autoindex_config_rec *dcfg = (autoindex_config_rec *) d;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding desc_entry = (ai_desc_t *) apr_array_push(dcfg->desc_list);
399cf0e5e061b49593817421b94305889fa6bc1fjorton desc_entry->full_path = (ap_strchr_c(to, '/') == NULL) ? 0 : 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding desc_entry->pattern = apr_pstrcat(dcfg->desc_list->pool,
399cf0e5e061b49593817421b94305889fa6bc1fjorton desc_entry->pattern = apr_pstrdup(dcfg->desc_list->pool, to);
399cf0e5e061b49593817421b94305889fa6bc1fjorton desc_entry->description = apr_pstrdup(dcfg->desc_list->pool, desc);
2261031aa94be82d7e6b1b8c367afc1b282317f5ianhstatic const char *add_ignore(cmd_parms *cmd, void *d, const char *ext)
85c435ceda98eab940615e4466d9c5955252e745wrowe push_item(((autoindex_config_rec *) d)->ign_list, 0, ext, cmd->path, NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const char *add_opts(cmd_parms *cmd, void *d, int argc, char *const argv[])
8a3228198adb03e6996f7738c361a612777ecab6aaron autoindex_config_rec *d_cfg = (autoindex_config_rec *) d;
8a3228198adb03e6996f7738c361a612777ecab6aaron for (i = 0; i < argc; i++) {
066877f1a045103acfdd376d48cdd473c33f409bdougm return "Cannot combine '+' or '-' with 'None' keyword";
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe return "Cannot combine '-' with IconWidth=n";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Cannot combine '-' with IconHeight=n";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "NameWidth with no value may only appear as "
8a3228198adb03e6996f7738c361a612777ecab6aaron "'-NameWidth'";
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh return "Cannot combine '-' with NameWidth=n";
8a3228198adb03e6996f7738c361a612777ecab6aaron return "NameWidth value must be greater than 5";
3d96ee83babeec32482c9082c9426340cee8c44dwrowe return "DescriptionWidth with no value may only appear as "
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm "'-DescriptionWidth'";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Cannot combine '-' with DescriptionWidth=n";
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd return "DescriptionWidth value must be greater than 12";
8a3228198adb03e6996f7738c361a612777ecab6aaron return "Invalid directory indexing option";
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh return "Cannot combine other IndexOptions keywords with 'None'";
8a3228198adb03e6996f7738c361a612777ecab6aaronstatic const char *set_default_order(cmd_parms *cmd, void *m,
8a3228198adb03e6996f7738c361a612777ecab6aaron autoindex_config_rec *d_cfg = (autoindex_config_rec *) m;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "First keyword must be 'Ascending' or 'Descending'";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Second keyword must be 'Name', 'Date', 'Size', or "
8a3228198adb03e6996f7738c361a612777ecab6aaron "'Description'";
0ef41d8e4b94d343e5b093c4dbd6ee61c1279401trawick AP_INIT_ITERATE2("AddIcon", add_icon, BY_PATH, DIR_CMD_PERMS,
8a3228198adb03e6996f7738c361a612777ecab6aaron "an icon URL followed by one or more filenames"),
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_ITERATE2("AddIconByType", add_icon, BY_TYPE, DIR_CMD_PERMS,
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard "an icon URL followed by one or more MIME types"),
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard AP_INIT_ITERATE2("AddIconByEncoding", add_icon, BY_ENCODING, DIR_CMD_PERMS,
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard "an icon URL followed by one or more content encodings"),
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard AP_INIT_ITERATE2("AddAlt", add_alt, BY_PATH, DIR_CMD_PERMS,
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard "alternate descriptive text followed by one or more "
8a3228198adb03e6996f7738c361a612777ecab6aaron "filenames"),
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_ITERATE2("AddAltByType", add_alt, BY_TYPE, DIR_CMD_PERMS,
8a3228198adb03e6996f7738c361a612777ecab6aaron "alternate descriptive text followed by one or more MIME "
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_ITERATE2("AddAltByEncoding", add_alt, BY_ENCODING, DIR_CMD_PERMS,
8a3228198adb03e6996f7738c361a612777ecab6aaron "alternate descriptive text followed by one or more "
8a3228198adb03e6996f7738c361a612777ecab6aaron "content encodings"),
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_TAKE_ARGV("IndexOptions", add_opts, NULL, DIR_CMD_PERMS,
8a3228198adb03e6996f7738c361a612777ecab6aaron "one or more index options [+|-][]"),
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_TAKE2("IndexOrderDefault", set_default_order, NULL, DIR_CMD_PERMS,
8a3228198adb03e6996f7738c361a612777ecab6aaron "{Ascending,Descending} {Name,Size,Description,Date}"),
8a3228198adb03e6996f7738c361a612777ecab6aaron AP_INIT_ITERATE("IndexIgnore", add_ignore, NULL, DIR_CMD_PERMS,
8a3228198adb03e6996f7738c361a612777ecab6aaron "one or more file extensions"),
8a3228198adb03e6996f7738c361a612777ecab6aaron (void *)APR_OFFSETOF(autoindex_config_rec, ign_noinherit),
50e421c0e069853bb724f3d816cef543e447c844jorton "Reset the inherited list of IndexIgnore filenames"),
50e421c0e069853bb724f3d816cef543e447c844jorton AP_INIT_ITERATE2("AddDescription", add_desc, BY_PATH, DIR_CMD_PERMS,
50e421c0e069853bb724f3d816cef543e447c844jorton "Descriptive text followed by one or more filenames"),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AP_INIT_RAW_ARGS("FancyIndexing", ap_set_deprecated, NULL, OR_ALL,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "The FancyIndexing directive is no longer supported. "
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh "Use IndexOptions FancyIndexing."),
8a3228198adb03e6996f7738c361a612777ecab6aaron (void *)APR_OFFSETOF(autoindex_config_rec, default_icon),
8a3228198adb03e6996f7738c361a612777ecab6aaron (void *)APR_OFFSETOF(autoindex_config_rec, style_sheet),
e34223f72e630187c4d8ac7c22da5096c833eb20trawick (void *)APR_OFFSETOF(autoindex_config_rec, head_insert),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DIR_CMD_PERMS, "String to insert in HTML HEAD section"),
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowestatic void *create_autoindex_config(apr_pool_t *p, char *dummy)
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->icon_list = apr_array_make(p, 4, sizeof(struct item));
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->alt_list = apr_array_make(p, 4, sizeof(struct item));
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->desc_list = apr_array_make(p, 4, sizeof(ai_desc_t));
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe new->ign_list = apr_array_make(p, 4, sizeof(struct item));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (void *) new;
9fe315e66ef597a158db81bcbd230d7a5d65785dndstatic void *merge_autoindex_configs(apr_pool_t *p, void *basev, void *addv)
82acfa3f57607ae78326104c420a317260554a47nd autoindex_config_rec *base = (autoindex_config_rec *) basev;
82acfa3f57607ae78326104c420a317260554a47nd autoindex_config_rec *add = (autoindex_config_rec *) addv;
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd new = (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd new->default_icon = add->default_icon ? add->default_icon
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd new->icon_height = add->icon_height ? add->icon_height : base->icon_height;
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd new->icon_width = add->icon_width ? add->icon_width : base->icon_width;
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd new->charset = add->charset ? add->charset : base->charset;
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb new->alt_list = apr_array_append(p, add->alt_list, base->alt_list);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->desc_list = apr_array_append(p, add->desc_list, base->desc_list);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->icon_list = apr_array_append(p, add->icon_list, base->icon_list);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm new->ign_list = add->ign_noinherit ? add->ign_list : apr_array_append(p, add->ign_list, base->ign_list);
8a3228198adb03e6996f7738c361a612777ecab6aaron * If the current directory explicitly says 'no options' then we also
a1de70bda57b72d8cc6b47ea744e0973ed424f56wrowe * clear any incremental mods from being inheritable further down.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If there were any nonincremental options selected for
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * this directory, they dominate and we don't inherit *anything.*
3c09db9ce04e444548e386a4b822e76ea0dabbebrbb * Contrariwise, we *do* inherit if the only settings here are
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * incremental ones.
e34223f72e630187c4d8ac7c22da5096c833eb20trawick * We may have incremental settings, so make sure we don't
3597d6b10c88c252f156fe8061b659a38dea38c2rbb * inadvertently inherit an IndexOptions None from above.
3597d6b10c88c252f156fe8061b659a38dea38c2rbb * There are local nonincremental settings, which clear
3597d6b10c88c252f156fe8061b659a38dea38c2rbb * all inheritance from above. They *are* the new base settings.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * We're guaranteed that there'll be no overlap between
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the add-options and the remove-options.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Inherit the NameWidth settings if there aren't any specific to
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the new location; otherwise we'll end up using the defaults set in the
e34223f72e630187c4d8ac7c22da5096c833eb20trawick * config-rec creation routine.
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard * Likewise for DescriptionWidth.
e34223f72e630187c4d8ac7c22da5096c833eb20trawick new->default_keyid = add->default_keyid ? add->default_keyid
e34223f72e630187c4d8ac7c22da5096c833eb20trawick new->default_direction = add->default_direction ? add->default_direction
e34223f72e630187c4d8ac7c22da5096c833eb20trawick/****************************************************************
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Looking things up in config entries...
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* Structure used to hold entries when we're actually building an index */
32c4bc04f89b16521718145dc731f750144d7b38wrowestatic char *find_item(const char *content_type, const char *content_encoding,
8a3228198adb03e6996f7738c361a612777ecab6aaron /* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */
8a3228198adb03e6996f7738c361a612777ecab6aaron if ((path[0] == '^') || (!ap_strcmp_match(path, p->apply_path))) {
8a3228198adb03e6996f7738c361a612777ecab6aaron if (!*(p->apply_to)) {
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawickstatic char *find_item_by_request(request_rec *r, apr_array_header_t *list, int path_only)
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick return find_item(ap_field_noparam(r->pool, r->content_type),
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick#define find_icon(d,p,t) find_item_by_request(p,d->icon_list,t)
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick#define find_alt(d,p,t) find_item_by_request(p,d->alt_list,t)
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick#define find_default_icon(d,n) find_item(NULL, NULL, n, d->icon_list, 1)
e8f95a682820a599fe41b22977010636be5c2717jim#define find_default_alt(d,n) find_item(NULL, NULL, n, d->alt_list, 1)
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick * Look through the list of pattern/description pairs and return the first one
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick * if any) that matches the filename in the request. If multiple patterns
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick * match, only the first one is used; since the order in the array is the
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick * same as the order in which directives were processed, earlier matching
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick * directives will dominate.
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawickstatic char *find_desc(autoindex_config_rec *dcfg, const char *filename_full)
f2b43354f9ac8496ab7003ae01211af739efba1atrawick ai_desc_t *list = (ai_desc_t *) dcfg->desc_list->elts;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick const char *filename;
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz * If the filename includes a path, extract just the name itself
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz * for the simple matches.
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick if ((filename_only = ap_strrchr_c(filename_full, '/')) == NULL) {
8a3228198adb03e6996f7738c361a612777ecab6aaron * Only use the full-path filename if the pattern contains '/'s.
8f0d7adca1c0719b3b1863fb2b9d333d7822567awrowe 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);
7646be5b9ab5b098bc81d3a08a47e1931dc87597rbb found = (ap_strstr_c(filename, tuple->pattern) != NULL);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic int ignore_entry(autoindex_config_rec *d, char *path)
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton#else /* !CASE_BLIND_FILESYSTEM */
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton * On some platforms, the match must be case-blind. This is really
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton * a factor of the filesystem involved, but we can't detect that
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton * reliably - so we have to granularise at the OS level.
76185d819b745e953dd2cd636fbdd515c333e4a4trawick#endif /* !CASE_BLIND_FILESYSTEM */
76185d819b745e953dd2cd636fbdd515c333e4a4trawick/*****************************************************************
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * Actually generating output
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Elements of the emitted document:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * succeeds for the (content_type == text/html) header file.
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * Header file
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * Emitted if found (and able).
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * H1 tag line
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Emitted if a header file is NOT emitted.
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb * Directory stuff
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb * Always emitted.
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * Emitted if FANCY_INDEXING is set.
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * Readme file
8a3228198adb03e6996f7738c361a612777ecab6aaron * Emitted if found (and able).
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * ServerSig
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * Emitted if ServerSignature is not Off AND a readme file
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * is NOT emitted.
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * Postamble
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * succeeds for the (content_type == text/html) readme file.
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * emit a plain text file
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawickstatic void do_emit_plain(request_rec *r, apr_file_t *f)
8a3228198adb03e6996f7738c361a612777ecab6aaron while (!apr_file_eof(f)) {
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb n = sizeof(char) * AP_IOBUFSIZE;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh /* ###: better error here? */
8a3228198adb03e6996f7738c361a612777ecab6aaron while (c < n) {
8a3228198adb03e6996f7738c361a612777ecab6aaron for (i = c; i < n; i++) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (buf[i] == '<' || buf[i] == '>' || buf[i] == '&') {
c54189c4d2d06d8b374940b32acf20287effff07wrowe * Handle the preamble through the H1 tag line, inclusive. Locate
c54189c4d2d06d8b374940b32acf20287effff07wrowe * the file with a subrequests. Process text/html documents by actually
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * running the subrequest; text/xxx documents get copied verbatim,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * and any other content type is ignored. This means that a non-text
c54189c4d2d06d8b374940b32acf20287effff07wrowe * document (such as HEADER.gif) might get multiviewed as the result
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * instead of a text document, meaning nothing will be displayed, but
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void emit_head(request_rec *r, char *header_fname, int suppress_amble,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *r_accept;
8a3228198adb03e6996f7738c361a612777ecab6aaron * If there's a header file, send a subrequest to look for it. If it's
8a3228198adb03e6996f7738c361a612777ecab6aaron * found and html do the subrequest, otherwise handle it
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r_accept_enc = apr_table_get(hdrs, "Accept-Encoding");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_table_setn(hdrs, "Accept", "text/html, text/plain");
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm header_fname = apr_pstrcat(r->pool, header_fname, "?", r->args, NULL);
066877f1a045103acfdd376d48cdd473c33f409bdougm && (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
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh /* Hope everything will work... */
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb /* This is a hack, but I can't find any better way to do this.
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb * The problem is that we have already created the sub-request,
066877f1a045103acfdd376d48cdd473c33f409bdougm * but we just inserted the OLD_WRITE filter, and the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * sub-request needs to pass its data through the OLD_WRITE
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * filter, or things go horribly wrong (missing data, data in
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the wrong order, etc). To fix it, if you create a
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * sub-request and then insert the OLD_WRITE filter before you
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb * run the request, you need to make sure that the sub-request
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * data goes through the OLD_WRITE filter. Just steal this
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * code. The long-term solution is to remove the ap_r*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * functions.
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * If there's a problem running the subrequest, display the
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * preamble if we didn't do it before -- the header file
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * didn't get displayed.
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;