mod_autoindex.c revision 2dcfdce30a4dabc6a194c367c9ef5e53d37df638
842ae4bd224140319ae7feec1872b93dfd491143fielding/* ====================================================================
842ae4bd224140319ae7feec1872b93dfd491143fielding * The Apache Software License, Version 1.1
842ae4bd224140319ae7feec1872b93dfd491143fielding * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
842ae4bd224140319ae7feec1872b93dfd491143fielding * reserved.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Redistribution and use in source and binary forms, with or without
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * modification, are permitted provided that the following conditions
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 1. Redistributions of source code must retain the above copyright
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * notice, this list of conditions and the following disclaimer.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 2. Redistributions in binary form must reproduce the above copyright
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * notice, this list of conditions and the following disclaimer in
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the documentation and/or other materials provided with the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * distribution.
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * 3. The end-user documentation included with the redistribution,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * if any, must include the following acknowledgment:
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh * "This product includes software developed by the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Apache Software Foundation (http://www.apache.org/)."
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Alternately, this acknowledgment may appear in the software itself,
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * if and wherever such third-party acknowledgments normally appear.
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * 4. The names "Apache" and "Apache Software Foundation" must
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * not be used to endorse or promote products derived from this
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * software without prior written permission. For written
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * permission, please contact apache@apache.org.
573394373c777e1624a481160f3d02f8fb09f3ffrjung * 5. Products derived from this software may not be called "Apache",
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * nor may "Apache" appear in their name, without prior written
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * permission of the Apache Software Foundation.
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
d633ae407c3c956cb2d67ff27055ff0e640967adfuankg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
d633ae407c3c956cb2d67ff27055ff0e640967adfuankg * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
d633ae407c3c956cb2d67ff27055ff0e640967adfuankg * SUCH DAMAGE.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ====================================================================
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * This software consists of voluntary contributions made by many
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * individuals on behalf of the Apache Software Foundation. For more
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * information on the Apache Software Foundation, please see
cf8fe49d9d89cfa4b62cb2b1376ca6f25b81b362trawick * Portions of this software are based upon public domain software
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * originally written at the National Center for Supercomputing Applications,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * University of Illinois, Urbana-Champaign.
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf * mod_autoindex.c: Handles the on-the-fly html index generation
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf * Rob McCool
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf * Adapted to Apache by rst.
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi * Version sort added by Martin Pool <mbp@humbug.org.au>.
8a3228198adb03e6996f7738c361a612777ecab6aaron/****************************************************************
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * 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.
8a3228198adb03e6996f7738c361a612777ecab6aarontypedef struct ai_desc_t {
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sftypedef struct autoindex_config_struct {
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton * This routine puts the standard HTML header at the top of the index page.
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton * We include the DOCTYPE because we may be using features therefrom (i.e.,
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jortonstatic void push_item(apr_array_header_t *arr, char *type, const char *to,
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton struct item *p = (struct item *) apr_array_push(arr);
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe p->apply_path = apr_pstrcat(arr->pool, path, "*", NULL);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick p->apply_to = apr_pstrcat(arr->pool, "*", to, NULL);
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe else if (to) {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickstatic const char *add_alt(cmd_parms *cmd, void *d, const char *alt,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick const char *to)
066877f1a045103acfdd376d48cdd473c33f409bdougm push_item(((autoindex_config_rec *) d)->alt_list, cmd->info, to,
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowestatic const char *add_icon(cmd_parms *cmd, void *d, const char *icon,
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe const char *to)
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe return "missing closing paren";
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim push_item(((autoindex_config_rec *) d)->icon_list, cmd->info, to,
649c9dd342a580016d29c2866de88a4609eb6457wrowe * Add description text for a filename pattern. If the pattern has
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * wildcards already (or we need to add them), add leading and
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * trailing wildcards to it to ensure substring processing. If the
649c9dd342a580016d29c2866de88a4609eb6457wrowe * pattern contains a '/' anywhere, force wildcard matching mode,
649c9dd342a580016d29c2866de88a4609eb6457wrowe * add a slash to the prefix so that "bar/bletch" won't be matched
649c9dd342a580016d29c2866de88a4609eb6457wrowe * by "foobar/bletch", and make a note that there's a delimiter;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe * the matching routine simplifies to just the actual filename
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe * whenever it can. This allows definitions in parent directories
649c9dd342a580016d29c2866de88a4609eb6457wrowe * to be made for files in subordinate ones using relative paths.
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe * Absent a strcasestr() function, we have to force wildcards on
185aa71728867671e105178b4c66fbc22b65ae26sf * systems for which "AAA" and "aaa" mean the same file.
76185d819b745e953dd2cd636fbdd515c333e4a4trawickstatic const char *add_desc(cmd_parms *cmd, void *d, const char *desc,
185aa71728867671e105178b4c66fbc22b65ae26sf const char *to)
76185d819b745e953dd2cd636fbdd515c333e4a4trawick autoindex_config_rec *dcfg = (autoindex_config_rec *) d;
399cf0e5e061b49593817421b94305889fa6bc1fjorton 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,
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick desc_entry->pattern = apr_pstrdup(dcfg->desc_list->pool, to);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm desc_entry->description = apr_pstrdup(dcfg->desc_list->pool, desc);
5a6a87d8920e385b1ed14177d74ab9786f3acddfwrowestatic const char *add_ignore(cmd_parms *cmd, void *d, const char *ext)
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe push_item(((autoindex_config_rec *) d)->ign_list, 0, ext, cmd->path, NULL);
76185d819b745e953dd2cd636fbdd515c333e4a4trawickstatic const char *add_header(cmd_parms *cmd, void *d, const char *name)
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim push_item(((autoindex_config_rec *) d)->hdr_list, 0, NULL, cmd->path,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic const char *add_readme(cmd_parms *cmd, void *d, const char *name)
8a3228198adb03e6996f7738c361a612777ecab6aaron push_item(((autoindex_config_rec *) d)->rdme_list, 0, NULL, cmd->path,
ff0436077dc959b17a6f87825e4a106d211224c1wrowestatic const char *add_opts(cmd_parms *cmd, void *d, const char *optstr)
20c85ca0d404e29972fb94c3d6236a264d1c77abstoddard autoindex_config_rec *d_cfg = (autoindex_config_rec *) d;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb while (optstr[0]) {
8a3228198adb03e6996f7738c361a612777ecab6aaron return "Cannot combine '+' or '-' with 'None' keyword";
32c4bc04f89b16521718145dc731f750144d7b38wrowe return "Cannot combine '-' with IconWidth=n";
e8f95a682820a599fe41b22977010636be5c2717jim return "Cannot combine '-' with IconHeight=n";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "NameWidth with no value may only appear as "
649c9dd342a580016d29c2866de88a4609eb6457wrowe "'-NameWidth'";
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim return "Cannot combine '-' with NameWidth=n";
649c9dd342a580016d29c2866de88a4609eb6457wrowe return "NameWidth value must be greater than 5";
85c435ceda98eab940615e4466d9c5955252e745wrowe return "DescriptionWidth with no value may only appear as "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "'-DescriptionWidth'";
649c9dd342a580016d29c2866de88a4609eb6457wrowe return "Cannot combine '-' with DescriptionWidth=n";
649c9dd342a580016d29c2866de88a4609eb6457wrowe return "DescriptionWidth value must be greater than 12";
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe return "Invalid directory indexing option";
8a3228198adb03e6996f7738c361a612777ecab6aaron return "Cannot combine other IndexOptions keywords with 'None'";
2261031aa94be82d7e6b1b8c367afc1b282317f5ianhstatic const char *set_default_order(cmd_parms *cmd, void *m,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh autoindex_config_rec *d_cfg = (autoindex_config_rec *) m;
8a3228198adb03e6996f7738c361a612777ecab6aaron return "First keyword must be 'Ascending' or 'Descending'";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return "Second keyword must be 'Name', 'Date', 'Size', or "
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "'Description'";
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_ITERATE2("AddIcon", add_icon, BY_PATH, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "an icon URL followed by one or more filenames"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_ITERATE2("AddIconByType", add_icon, BY_TYPE, DIR_CMD_PERMS,
c6c1730850cd8c7149f62efb3f5e8afa25e24f4fminfrin "an icon URL followed by one or more MIME types"),
4240daa133bbeddbc3141553879eda4fccfe93feminfrin AP_INIT_ITERATE2("AddIconByEncoding", add_icon, BY_ENCODING, DIR_CMD_PERMS,
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf "an icon URL followed by one or more content encodings"),
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin AP_INIT_ITERATE2("AddAlt", add_alt, BY_PATH, DIR_CMD_PERMS,
c41be3600a58bd39a76d1215abcdbbd8e9b1c356minfrin "alternate descriptive text followed by one or more filenames"),
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf AP_INIT_ITERATE2("AddAltByType", add_alt, BY_TYPE, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "alternate descriptive text followed by one or more MIME types"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_ITERATE2("AddAltByEncoding", add_alt, BY_ENCODING, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "alternate descriptive text followed by one or more content encodings"),
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh AP_INIT_RAW_ARGS("IndexOptions", add_opts, NULL, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "one or more index options [+|-][]"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_TAKE2("IndexOrderDefault", set_default_order, NULL, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "{Ascending,Descending} {Name,Size,Description,Date}"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_ITERATE("IndexIgnore", add_ignore, NULL, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "one or more file extensions"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_ITERATE2("AddDescription", add_desc, BY_PATH, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "Descriptive text followed by one or more filenames"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_TAKE1("HeaderName", add_header, NULL, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "a filename"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_TAKE1("ReadmeName", add_readme, NULL, DIR_CMD_PERMS,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "a filename"),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf AP_INIT_RAW_ARGS("FancyIndexing", ap_set_deprecated, NULL, OR_ALL,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf "The FancyIndexing directive is no longer supported. Use IndexOptions FancyIndexing."),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf (void *)APR_OFFSETOF(autoindex_config_rec, default_icon),
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic void *create_autoindex_config(apr_pool_t *p, char *dummy)
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf new->icon_list = apr_array_make(p, 4, sizeof(struct item));
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf new->alt_list = apr_array_make(p, 4, sizeof(struct item));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->desc_list = apr_array_make(p, 4, sizeof(ai_desc_t));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->ign_list = apr_array_make(p, 4, sizeof(struct item));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->hdr_list = apr_array_make(p, 4, sizeof(struct item));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->rdme_list = apr_array_make(p, 4, sizeof(struct item));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return (void *) new;
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic void *merge_autoindex_configs(apr_pool_t *p, void *basev, void *addv)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf autoindex_config_rec *base = (autoindex_config_rec *) basev;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf autoindex_config_rec *add = (autoindex_config_rec *) addv;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new = (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->default_icon = add->default_icon ? add->default_icon
8a3228198adb03e6996f7738c361a612777ecab6aaron new->icon_height = add->icon_height ? add->icon_height : base->icon_height;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->icon_width = add->icon_width ? add->icon_width : base->icon_width;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->alt_list = apr_array_append(p, add->alt_list, base->alt_list);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->ign_list = apr_array_append(p, add->ign_list, base->ign_list);
baf4649272f3dabd48b095a23b3180cc0105dce6rjung new->hdr_list = apr_array_append(p, add->hdr_list, base->hdr_list);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->desc_list = apr_array_append(p, add->desc_list, base->desc_list);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->icon_list = apr_array_append(p, add->icon_list, base->icon_list);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf new->rdme_list = apr_array_append(p, add->rdme_list, base->rdme_list);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If the current directory says 'no options' then we also
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * clear any incremental mods from being inheritable further down.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If there were any nonincremental options selected for
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * this directory, they dominate and we don't inherit *anything.*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Contrariwise, we *do* inherit if the only settings here are
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * incremental ones.
6c266c0dc27ed2972bfb14a8bd5428065c4b3a8bsf * We may have incremental settings, so make sure we don't
6c266c0dc27ed2972bfb14a8bd5428065c4b3a8bsf * inadvertently inherit an IndexOptions None from above.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * There are local nonincremental settings, which clear
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * all inheritance from above. They *are* the new base settings.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * We're guaranteed that there'll be no overlap between
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * the add-options and the remove-options.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Inherit the NameWidth settings if there aren't any specific to
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * the new location; otherwise we'll end up using the defaults set in the
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * config-rec creation routine.
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard * Likewise for DescriptionWidth.
8a3228198adb03e6996f7738c361a612777ecab6aaron new->default_keyid = add->default_keyid ? add->default_keyid
8a3228198adb03e6996f7738c361a612777ecab6aaron new->default_direction = add->default_direction ? add->default_direction
50e421c0e069853bb724f3d816cef543e447c844jorton/****************************************************************
50e421c0e069853bb724f3d816cef543e447c844jorton * Looking things up in config entries...
50e421c0e069853bb724f3d816cef543e447c844jorton/* Structure used to hold entries when we're actually building an index */
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic char *find_item(request_rec *r, apr_array_header_t *list, int path_only)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const char *content_type = ap_field_noparam(r->pool, r->content_type);
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf /* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf if ((path[0] == '^') || (!ap_strcmp_match(path, p->apply_path))) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!*(p->apply_to)) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return p->data;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return p->data;
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf else if (!path_only) {
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf return p->data;
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf return p->data;
4497075b5e08b0c8ee89425a1758258ae80550fcsfstatic char *find_default_item(char *bogus_name, apr_array_header_t *list)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* Bleah. I tried to clean up find_item, and it lead to this bit
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * of ugliness. Note that the fields initialized are precisely
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * those that find_item looks at...
4497075b5e08b0c8ee89425a1758258ae80550fcsf#define find_default_icon(d,n) find_default_item(n, d->icon_list)
4497075b5e08b0c8ee89425a1758258ae80550fcsf#define find_default_alt(d,n) find_default_item(n, d->alt_list)
4497075b5e08b0c8ee89425a1758258ae80550fcsf * Look through the list of pattern/description pairs and return the first one
4497075b5e08b0c8ee89425a1758258ae80550fcsf * if any) that matches the filename in the request. If multiple patterns
4497075b5e08b0c8ee89425a1758258ae80550fcsf * match, only the first one is used; since the order in the array is the
4497075b5e08b0c8ee89425a1758258ae80550fcsf * same as the order in which directives were processed, earlier matching
4497075b5e08b0c8ee89425a1758258ae80550fcsf * directives will dominate.
4497075b5e08b0c8ee89425a1758258ae80550fcsfstatic char *find_desc(autoindex_config_rec *dcfg, const char *filename_full)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const char *filename_only;
ce4dc40a4e87991087488f70d96d3447d7557294sf const char *filename;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If the filename includes a path, extract just the name itself
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * for the simple matches.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if ((filename_only = ap_strrchr_c(filename_full, '/')) == NULL) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Only use the full-path filename if the pattern contains '/'s.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf filename = (tuple->full_path) ? filename_full : filename_only;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Make the comparison using the cheapest method; only do
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * wildcard checking if we must.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf found = (apr_fnmatch(tuple->pattern, filename, MATCH_FLAGS) == 0);
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int ignore_entry(autoindex_config_rec *d, char *path)
ce4dc40a4e87991087488f70d96d3447d7557294sf#else /* !CASE_BLIND_FILESYSTEM */
ce4dc40a4e87991087488f70d96d3447d7557294sf * On some platforms, the match must be case-blind. This is really
ce4dc40a4e87991087488f70d96d3447d7557294sf * a factor of the filesystem involved, but we can't detect that
ce4dc40a4e87991087488f70d96d3447d7557294sf * reliably - so we have to granularise at the OS level.
ce4dc40a4e87991087488f70d96d3447d7557294sf#endif /* !CASE_BLIND_FILESYSTEM */
ce4dc40a4e87991087488f70d96d3447d7557294sf/*****************************************************************
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf * Actually generating output
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Elements of the emitted document:
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Preamble
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * succeeds for the (content_type == text/html) header file.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Header file
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Emitted if found (and able).
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * H1 tag line
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Emitted if a header file is NOT emitted.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Directory stuff
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Always emitted.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Emitted if FANCY_INDEXING is set.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Readme file
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Emitted if found (and able).
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * ServerSig
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Emitted if ServerSignature is not Off AND a readme file
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * is NOT emitted.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Postamble
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * succeeds for the (content_type == text/html) readme file.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * emit a plain text file
e302f38fd646764ce1a1e1c578d794aef514a9e5sf while (!apr_file_eof(f)) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf n = sizeof(char) * AP_IOBUFSIZE;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* ###: better error here? */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf while (c < n) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf for (i = c; i < n; i++) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Handle the preamble through the H1 tag line, inclusive. Locate
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * the file with a subrequests. Process text/html documents by actually
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf * running the subrequest; text/xxx documents get copied verbatim,
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf * 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
82acfa3f57607ae78326104c420a317260554a47nd * instead of a text document, meaning nothing will be displayed, but
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * oh well.
9fe315e66ef597a158db81bcbd230d7a5d65785dndstatic void emit_head(request_rec *r, char *header_fname, int suppress_amble,
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd const char *r_accept;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const char *r_accept_enc;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If there's a header file, send a subrequest to look for it. If it's
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * found and html do the subrequest, otherwise handle it
e302f38fd646764ce1a1e1c578d794aef514a9e5sf header_fname = apr_pstrcat(r->pool, header_fname, "?", r->args, NULL);
9fe315e66ef597a158db81bcbd230d7a5d65785dnd && (rr = ap_sub_req_lookup_uri(header_fname, r, r->output_filters))
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Check for the two specific cases we allow: text/html and
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * text/anything-else. The former is allowed to be processed for
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!strcasecmp(ap_field_noparam(r->pool, rr->content_type),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* Hope everything will work... */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* This is a hack, but I can't find any better way to do this.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * The problem is that we have already created the sub-request,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * but we just inserted the OLD_WRITE filter, and the
9fe315e66ef597a158db81bcbd230d7a5d65785dnd * sub-request needs to pass its data through the OLD_WRITE
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * filter, or things go horribly wrong (missing data, data in
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * the wrong order, etc). To fix it, if you create a
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * sub-request and then insert the OLD_WRITE filter before you
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * run the request, you need to make sure that the sub-request
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * data goes through the OLD_WRITE filter. Just steal this
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd * code. The long-term solution is to remove the ap_r*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * functions.
ee2c610570b9e159784e87e72d1c17f459b85768sf * If there's a problem running the subrequest, display the
b5c4b00201fdc3ed11c6cc05cf3f9a7912ac0cfbsf * preamble if we didn't do it before -- the header file
b5c4b00201fdc3ed11c6cc05cf3f9a7912ac0cfbsf * didn't get displayed.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* It didn't work */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If we can open the file, prefix it with the preamble
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * regardless; since we'll be sending a <pre> block around
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * the file's contents, any HTML header it had won't end up
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * where it belongs.
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_table_setn(hdrs, "Accept-Encoding", r_accept_enc);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Handle the Readme file through the postamble, inclusive. Locate
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * the file with a subrequests. Process text/html documents by actually
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * running the subrequest; text/xxx documents get copied verbatim,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * and any other content type is ignored. This means that a non-text
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * document (such as FOOTER.gif) might get multiviewed as the result
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * instead of a text document, meaning nothing will be displayed, but
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * oh well.
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If there's a readme file, send a subrequest to look for it. If it's
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * found and a text file, handle it -- otherwise fall through and
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * pretend there's nothing there.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf && (rr = ap_sub_req_lookup_uri(readme_fname, r, r->output_filters))
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Check for the two specific cases we allow: text/html and
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * text/anything-else. The former is allowed to be processed for
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!strcasecmp(ap_field_noparam(r->pool, rr->content_type),
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* worked... */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If we can open the file, suppress the signature.
a8eeeed944c5d1986ab92649271d29839abd1155sf int x, y, p;
a8eeeed944c5d1986ab92649271d29839abd1155sf && (!strcasecmp(ap_field_noparam(r->pool, r->content_type),
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf if (n <= 0) {
7f630e66c9c37e797e1c06bf7b259c0859538978trawick for (x = 0, p = 0; titlebuf[x]; x++) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!find[++p]) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* Scan for line breaks for Tanmoy's secretary */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf for (y = x; titlebuf[y]; y++) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (y == x) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic struct ent *make_parent_entry(apr_int32_t autoindex_opts,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf struct ent *p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent));
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * p->name is now the true parent URI.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * testpath is a crafted lie, so that the syntax '/some/..'
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * (or simply '..')be used to describe 'up' from '/some/'
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * when processeing IndexIgnore, and Icon|Alt|Desc configs.
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf /* The output has always been to the parent. Don't make ourself
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf * our own parent (worthless cyclical reference).
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!(p->name = ap_make_full_path(r->pool, r->uri, "../"))) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!*p->name) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* IndexIgnore has always compared "/thispath/.." */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf testpath = ap_make_full_path(r->pool, r->filename, "..");
e11c9fa326e7bfa48bd9be5bae7037ae76b2612dsfstatic struct ent *make_autoindex_entry(const apr_finfo_t *dirent,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const char *pattern)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf struct ent *p;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* Dot is ignored, Parent is handled by make_parent_entry() */
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf#else /* !CASE_BLIND_FILESYSTEM */
3597d6b10c88c252f156fe8061b659a38dea38c2rbb * On some platforms, the match must be case-blind. This is really
3597d6b10c88c252f156fe8061b659a38dea38c2rbb * a factor of the filesystem involved, but we can't detect that
3597d6b10c88c252f156fe8061b659a38dea38c2rbb * reliably - so we have to granularise at the OS level.
3597d6b10c88c252f156fe8061b659a38dea38c2rbb#endif /* !CASE_BLIND_FILESYSTEM */
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf if (!(rr = ap_sub_req_lookup_dirent(dirent, r, AP_SUBREQ_NO_ARGS, NULL))) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((rr->finfo.filetype != APR_DIR && rr->finfo.filetype != APR_REG)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding || !(rr->status == OK || ap_is_HTTP_SUCCESS(rr->status)
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p->name = apr_pstrcat(r->pool, dirent->name, "/", NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p->ascending = (apr_toupper(direction) == D_ASCENDING);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p->version_sort = !!(autoindex_opts & VERSION_SORT);
e34223f72e630187c4d8ac7c22da5096c833eb20trawick if (autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING)) {
e34223f72e630187c4d8ac7c22da5096c833eb20trawick if ((!p->desc) && (autoindex_opts & SCAN_HTML_TITLES)) {
bd27541a0c96caa881f17a490e23cdd220d480c8poirier * We don't need to take any special action for the file size key.
bd27541a0c96caa881f17a490e23cdd220d480c8poirier * If we did, it would go here.
bd27541a0c96caa881f17a490e23cdd220d480c8poirier if (p->lm < 0) {
bd27541a0c96caa881f17a490e23cdd220d480c8poirier return (p);
bd27541a0c96caa881f17a490e23cdd220d480c8poirierstatic char *terminate_description(autoindex_config_rec *d, char *desc,
bd27541a0c96caa881f17a490e23cdd220d480c8poirier register int x;
bd27541a0c96caa881f17a490e23cdd220d480c8poirier * If there's no DescriptionWidth in effect, default to the old
bd27541a0c96caa881f17a490e23cdd220d480c8poirier * behaviour of adjusting the description size depending upon
185aa71728867671e105178b4c66fbc22b65ae26sf * what else is being displayed. Otherwise, stick with the
20e0c71be778348516719e1e58a9f55c8e78c570trawick for (x = 0; desc[x] && ((maxsize > 0) || (desc[x] == '<')); x++) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* entities like ä count as one character */
8a3228198adb03e6996f7738c361a612777ecab6aaron * Emit the anchor for the specified field. If a field is the key for the
8a3228198adb03e6996f7738c361a612777ecab6aaron * current request, the link changes its meaning to reverse the order when
8a3228198adb03e6996f7738c361a612777ecab6aaron * selected again. Non-active fields always start in ascending order.
8a3228198adb03e6996f7738c361a612777ecab6aaronstatic void emit_link(request_rec *r, const char *anchor, char column,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding reverse = ((curkey == column) && (curdirection == D_ASCENDING));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, "<a href=\"", qvalue, colargs ? colargs : "",
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawickstatic void output_directories(struct ent **ar, int n,
1ec73fc12d4912ea9f4841c301458454589b32d9trawick int static_columns = !!(autoindex_opts & SUPPRESS_COLSORT);
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz if ((autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING))
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz for (x = 0; x < n; x++) {
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick for (x = 0; x < n; x++) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_rvputs(r, "<img src=\"", ap_escape_html(scratch, tp),
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe emit_link(r, "Last modified", K_LAST_MOD, keyid, direction,
76185d819b745e953dd2cd636fbdd515c333e4a4trawick "<tr><th colspan=\"%d\">"
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung ap_rvputs(r, "<img src=\"", ap_escape_html(scratch, tp),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Emit the guaranteed-at-least-one-space-between-columns byte.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding emit_link(r, "Last modified", K_LAST_MOD, keyid, direction,
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick for (x = 0; x < n; x++) {
ffb048955d9939c0ab6ff99c2efc412d8e7a191dwrowe anchor = ap_escape_html(scratch, ap_os_escape_path(scratch, t, 0));
8a3228198adb03e6996f7738c361a612777ecab6aaron if (!x && t[0] == '/') {
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf * The blank before the storm.. er, before the next field.
ce4dc40a4e87991087488f70d96d3447d7557294sf /*Length="22-Feb-1998 23:42 " (see 4 lines above) */
desc_width), r);
int result = 0;
case K_LAST_MOD:
case K_SIZE:
case K_DESC:
if (result) {
return result;
char *title_endp;
int num_ent = 0, x;
const char *qstring;
char keyid;
char direction;
char *colargs;
char *fullpath;
return HTTP_FORBIDDEN;
ap_set_etag(r);
if (r->header_only) {
& ~TABLE_INDEXING;
if (eos) {
if (*pstring) {
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;
return index_directory(r, d);
return HTTP_FORBIDDEN;