mod_mime.c revision 1585c2979d749ee71edb6a1d57bc9ff6db12a426
f743002678eb67b99bbc29fee116b65d9530fec0wrowe/* ====================================================================
80833bb9a1bf25dcf19e814438a4b311d2e1f4cffuankg * The Apache Software License, Version 1.1
fe83f60b41477b14a37edcfcd1f7f5c5a1ebfe44minfrin * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
fe83f60b41477b14a37edcfcd1f7f5c5a1ebfe44minfrin * reserved.
bb2ec4bda29720d914838486ad0bbfba9ac75d5dtrawick * Redistribution and use in source and binary forms, with or without
bb2ec4bda29720d914838486ad0bbfba9ac75d5dtrawick * modification, are permitted provided that the following conditions
7f6bfe455bd605a6401d2fcc9423972a24266b16jim * 1. Redistributions of source code must retain the above copyright
7f6bfe455bd605a6401d2fcc9423972a24266b16jim * notice, this list of conditions and the following disclaimer.
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza * 2. Redistributions in binary form must reproduce the above copyright
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza * notice, this list of conditions and the following disclaimer in
3b995de5609b15115a0764e6979ba43071a2988fjim * the documentation and/or other materials provided with the
3b995de5609b15115a0764e6979ba43071a2988fjim * distribution.
ba050a6f942b9fa0e81ed73437588005c569655ccovener * 3. The end-user documentation included with the redistribution,
ba050a6f942b9fa0e81ed73437588005c569655ccovener * if any, must include the following acknowledgment:
ba050a6f942b9fa0e81ed73437588005c569655ccovener * "This product includes software developed by the
ba050a6f942b9fa0e81ed73437588005c569655ccovener * Apache Software Foundation (http://www.apache.org/)."
ba050a6f942b9fa0e81ed73437588005c569655ccovener * Alternately, this acknowledgment may appear in the software itself,
ba050a6f942b9fa0e81ed73437588005c569655ccovener * if and wherever such third-party acknowledgments normally appear.
135ddda3a989215d2bedbcf1529bfb269c3eda23niq * 4. The names "Apache" and "Apache Software Foundation" must
135ddda3a989215d2bedbcf1529bfb269c3eda23niq * not be used to endorse or promote products derived from this
135ddda3a989215d2bedbcf1529bfb269c3eda23niq * software without prior written permission. For written
166b66614fb67e1b95c200433925787457657a0ajim * permission, please contact apache@apache.org.
166b66614fb67e1b95c200433925787457657a0ajim * 5. Products derived from this software may not be called "Apache",
166b66614fb67e1b95c200433925787457657a0ajim * nor may "Apache" appear in their name, without prior written
3f414998b6d7e96a9f699621352fc61516b1a316chrisd * permission of the Apache Software Foundation.
3f414998b6d7e96a9f699621352fc61516b1a316chrisd * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
9d766f93eefb9358f9a24bb99ff424ad399b9b39minfrin * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
9d766f93eefb9358f9a24bb99ff424ad399b9b39minfrin * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
9d766f93eefb9358f9a24bb99ff424ad399b9b39minfrin * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
5725c3eb0c6c572049ba61dedd92b4e5da078081minfrin * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
5725c3eb0c6c572049ba61dedd92b4e5da078081minfrin * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
5725c3eb0c6c572049ba61dedd92b4e5da078081minfrin * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
5725c3eb0c6c572049ba61dedd92b4e5da078081minfrin * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1122585e1e00bb81e9d0f054bf5c318cec23aa7dminfrin * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1122585e1e00bb81e9d0f054bf5c318cec23aa7dminfrin * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
1122585e1e00bb81e9d0f054bf5c318cec23aa7dminfrin * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b4e664baba9a4be0457c31f84b3dcc4c31f2cb07kbrand * SUCH DAMAGE.
b4e664baba9a4be0457c31f84b3dcc4c31f2cb07kbrand * ====================================================================
b4e664baba9a4be0457c31f84b3dcc4c31f2cb07kbrand * This software consists of voluntary contributions made by many
a52dab9b245d2bc88feacc380eb94bd6abcd5dd0kbrand * individuals on behalf of the Apache Software Foundation. For more
b4e664baba9a4be0457c31f84b3dcc4c31f2cb07kbrand * information on the Apache Software Foundation, please see
001a44c352f89c9ec332ffd3e0a6927dcd19432chumbedooh * Portions of this software are based upon public domain software
001a44c352f89c9ec332ffd3e0a6927dcd19432chumbedooh * originally written at the National Center for Supercomputing Applications,
001a44c352f89c9ec332ffd3e0a6927dcd19432chumbedooh * University of Illinois, Urbana-Champaign.
33124689065ade0dfc8c54d8ebb734f9439cb89btrawick * http_mime.c: Sends/gets MIME headers for requests
33124689065ade0dfc8c54d8ebb734f9439cb89btrawick * Rob McCool
61fefed8ce5211c31b44f3a38a6e76ca055e5780trawick/* XXXX - fix me / EBCDIC
61fefed8ce5211c31b44f3a38a6e76ca055e5780trawick * there was a cludge here which would use its
61fefed8ce5211c31b44f3a38a6e76ca055e5780trawick * own version apr_isascii(). Indicating that
6001d914962deabb83a46251001612e969bdf67ajim * on some platforms that might be needed.
6001d914962deabb83a46251001612e969bdf67ajim * #define OS_ASC(c) (c) -- for mere mortals
c4e8006db0cf457c68876d7d4c30dcc451d8cba7jkaluza * #define OS_ASC(c) (ebcdic2ascii[c]) -- for dino's
652bacc79dd7f980249784cc8c4838e8f1de7e8acovener * #define apr_isascii(c) ((OS_ASC(c) & 0x80) == 0)
652bacc79dd7f980249784cc8c4838e8f1de7e8acovener/* XXXXX - fix me - See note with NOT_PROXY
f4db898517ccc6ef1a403630de56918286d3a47eminfrintypedef struct attrib_info {
067698ad30941e38ef5d7f95f1c2736c2ebc5cb9humbedooh/* Information to which an extension can be mapped
d8a6de5eec06d4136839c8f7a56a6ab5acd2d3behumbedoohtypedef struct extension_info {
6e1e45624d6f32110383bb0bd06c254c1dba8123humbedooh char *forced_type; /* Additional AddTyped stuff */
77ca16c5676da23155311e13cee61e7eaba9fa3ejailletc char *encoding_type; /* Added with AddEncoding... */
77ca16c5676da23155311e13cee61e7eaba9fa3ejailletc char *language_type; /* Added with AddLanguage... */
921d32d80d8271da08f12fc374a69cb36d1d63b3covener char *input_filters; /* Added with AddInputFilter... */
921d32d80d8271da08f12fc374a69cb36d1d63b3covener char *output_filters; /* Added with AddOutputFilter... */
faea99bb676ec50ece38da6b1879aa37546483a2covenertypedef struct {
344f755169e100ea8ce51e847a0bf30a13b46917covener apr_hash_t *extension_mappings; /* Map from extension name to
344f755169e100ea8ce51e847a0bf30a13b46917covener * extension_info structure */
50cfe8bbbaf4279375802531268e2bf0155215fetrawick apr_array_header_t *remove_mappings; /* A simple list, walked once */
50cfe8bbbaf4279375802531268e2bf0155215fetrawick char *default_language; /* Language if no AddLanguage ext found */
ffaa9771884a8664f0e6267efbe9d26b40000461trawick int multimatch; /* Extensions to include in multiview matching
ffaa9771884a8664f0e6267efbe9d26b40000461trawick * for filenames, e.g. Filters and Handlers
f87299dab99bc04b51a6b8cad51b6795db862c0atrawicktypedef struct param_s {
4d12805e6c18253040223ea637acd6b3b3c18f60jortontypedef struct {
cb666b29f81df1d11d65002250153353568021fccovenerstatic char tspecial[] = {
1f50dc34ae069adeed20b2986e5ffdefa5c410e0covenerstatic void *create_mime_dir_config(apr_pool_t *p, char *dummy)
63a5ea80bddcc84a462e40f402b4f330e0e05411covener (mime_dir_config *) apr_palloc(p, sizeof(mime_dir_config));
74e7f6c55fd67b10cb400b3f6d1dc718a303d944minfrin * Overlay one hash table of extension_mappings onto another
74e7f6c55fd67b10cb400b3f6d1dc718a303d944minfrinstatic void *overlay_extension_mappings(apr_pool_t *p,
74e7f6c55fd67b10cb400b3f6d1dc718a303d944minfrin const void *key,
a511a29faf2ff7ead3b67680154a624effb31aafminfrin const void *base_val,
a511a29faf2ff7ead3b67680154a624effb31aafminfrin const void *data)
63921358ef93fcb41bc71d9894221ba3d7fbb87bminfrin extension_info *new_info = apr_palloc(p, sizeof(extension_info));
63921358ef93fcb41bc71d9894221ba3d7fbb87bminfrin const extension_info *overlay_info = (const extension_info *)overlay_val;
63921358ef93fcb41bc71d9894221ba3d7fbb87bminfrin const extension_info *base_info = (const extension_info *)base_val;
6d601599d3d65df0410eae6e573e75b2dbfb1fb4minfrin memcpy(new_info, base_info, sizeof(extension_info));
2c487ac43b583db869e743772a7a10b278aa2bcfminfrin new_info->language_type = overlay_info->language_type;
ef82e8fa164e0a1f8b813f7deb6b7ead96018c94niq new_info->output_filters = overlay_info->output_filters;
eafcc0ebf263d0ba69855b6e10958c4c1a2361bdsf/* Member is the offset within an extension_info of the pointer to reset
eafcc0ebf263d0ba69855b6e10958c4c1a2361bdsfstatic void remove_items(apr_pool_t *p, apr_array_header_t *remove,
9811aed12bbc71783d2e544ccb5fecd193843eadsf if (exinfo && *(const char**)((char *)exinfo + suffix[i].offset)) {
1366443dc565c33e7b449ae428bbfc4c86f33935drh exinfo = (extension_info*)apr_palloc(p, sizeof(*exinfo));
bd3f5647b96d378d9c75c954e3f13582af32c643sf *(const char**)((char *)exinfo + suffix[i].offset) = NULL;
2a7beea91d46beb41f043a84eaad060047ee04aafabienstatic void *merge_mime_dir_configs(apr_pool_t *p, void *basev, void *addv)
584a85dd4047e38d3ed3a29b6662fcc9d100ae4csf mime_dir_config *new = apr_palloc(p, sizeof(mime_dir_config));
f21e9e3d0bfb7a507ecc5bc963f2159d693503d1sf if (base->extension_mappings && add->extension_mappings) {
f21e9e3d0bfb7a507ecc5bc963f2159d693503d1sf new->extension_mappings = apr_hash_merge(p, add->extension_mappings,
536d2e7cd1fdec1255b8c3bdf41fdc714c506a54trawick /* We may not be merging the tables, but if we potentially will change
536d2e7cd1fdec1255b8c3bdf41fdc714c506a54trawick * an exinfo member, then we are about to trounce it anyways.
536d2e7cd1fdec1255b8c3bdf41fdc714c506a54trawick * We must have a copy for safety.
79c5787b92ac5f0e1cc82393816c77a006399316trawick if (new->extension_mappings && add->remove_mappings) {
79c5787b92ac5f0e1cc82393816c77a006399316trawick remove_items(p, add->remove_mappings, new->extension_mappings);
e81785da447b469da66f218b3f0244aab507958djorton new->multimatch = (add->multimatch != MULTIMATCH_UNSET) ?
53e9b27aba029b18be814df40bcf6f0428771d1efuankgstatic const char *add_extension_info(cmd_parms *cmd, void *m_,
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung exinfo = (extension_info*)apr_hash_get(m->extension_mappings, key,
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung exinfo = apr_pcalloc(cmd->pool, sizeof(extension_info));
74499a117b3b2cd9666715a14f90c0e5d1a4ee8ajim * Note handler names are un-added with each per_dir_config merge.
cfa64348224b66dd1c9979b809406c4d15b1c137fielding * This keeps the association from being inherited, but not
74499a117b3b2cd9666715a14f90c0e5d1a4ee8ajim * from being re-added at a subordinate level.
74499a117b3b2cd9666715a14f90c0e5d1a4ee8ajimstatic const char *remove_extension_info(cmd_parms *cmd, void *m_,
cfa64348224b66dd1c9979b809406c4d15b1c137fielding const char *ext)
++ext;
if (!m->remove_mappings) {
return NULL;
const char *arg)
(void *)arg);
return NULL;
| MULTIMATCH_ANY)))
| MULTIMATCH_ANY)))
return NULL;
{NULL}
ap_configfile_t *f;
char l[MAX_STRING_LEN];
if (!types_confname)
if (!types_confname) {
return HTTP_INTERNAL_SERVER_ERROR;
!= APR_SUCCESS) {
return HTTP_INTERNAL_SERVER_ERROR;
while (ll[0]) {
ap_cfg_closefile(f);
return OK;
static const char *zap_sp(const char *s)
if (s == NULL) {
return (NULL);
start++;
end--;
if (len) {
static int is_token(char c)
int res;
return res;
static int is_qtext(char c)
int res;
return res;
static int is_quoted_pair(const char *s)
if (apr_isascii(c)) {
return (res);
int quoted = 0;
mp = s;
(const char *) mp);
return (NULL);
return (NULL);
return (NULL);
cp++;
return (NULL);
return (NULL);
return (ctp);
cp++;
return (NULL);
cp++;
cp++;
return (NULL);
cp++;
return (NULL);
return (NULL);
cp++;
quoted = 0;
if (quoted > 0) {
cp++;
cp++;
cp++;
return(NULL);
quoted = 0;
return (NULL);
cp++;
return (NULL);
return (NULL);
quoted = 0;
cp++;
return (ctp);
char *ext;
int found_metadata = 0;
return OK;
&mime_module);
++fn;
* The base name is always the first exception (i.e., "txt.html" has
int found;
found = 0;
if (!r->content_languages)
if (!r->content_encoding)
r->content_encoding,
NULL);
while (*filters
while (*filters
if (found_metadata) {
(void *)exception_list);
if (r->content_type) {
int override = 0;
if (!override) {
NULL));
NULL));
NULL));
const char **new;
if (!r->content_languages)
if (!r->content_type)
return DECLINED;
return OK;