mod_mime.c revision 8d89aea1726567c698b5c24e82b4a951f498e588
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg/* ====================================================================
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * The Apache Software License, Version 1.1
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg *
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * reserved.
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg *
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * Redistribution and use in source and binary forms, with or without
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * modification, are permitted provided that the following conditions
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * are met:
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg *
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * 1. Redistributions of source code must retain the above copyright
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * notice, this list of conditions and the following disclaimer.
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg *
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * 2. Redistributions in binary form must reproduce the above copyright
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * notice, this list of conditions and the following disclaimer in
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * the documentation and/or other materials provided with the
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * distribution.
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg *
7190e58eec40192c9719d2f2593471eda14e7e7cfuankg * 3. The end-user documentation included with the redistribution,
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * if any, must include the following acknowledgment:
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * "This product includes software developed by the
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * Apache Software Foundation (http://www.apache.org/)."
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * Alternately, this acknowledgment may appear in the software itself,
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * if and wherever such third-party acknowledgments normally appear.
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg *
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * 4. The names "Apache" and "Apache Software Foundation" must
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * not be used to endorse or promote products derived from this
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * software without prior written permission. For written
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * permission, please contact apache@apache.org.
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg *
95ca7cc2aa11b41497ffab3a1003bc09d24b6bc1fuankg * 5. Products derived from this software may not be called "Apache",
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * nor may "Apache" appear in their name, without prior written
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * permission of the Apache Software Foundation.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes *
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * SUCH DAMAGE.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * ====================================================================
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes *
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * This software consists of voluntary contributions made by many
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * individuals on behalf of the Apache Software Foundation. For more
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * information on the Apache Software Foundation, please see
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * <http://www.apache.org/>.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes *
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * Portions of this software are based upon public domain software
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * originally written at the National Center for Supercomputing Applications,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * University of Illinois, Urbana-Champaign.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes/*
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * http_mime.c: Sends/gets MIME headers for requests
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes *
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholes * Rob McCool
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholes *
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes */
b387b9d37fc71c534f4718777454a8f5a1169017fuankg
b387b9d37fc71c534f4718777454a8f5a1169017fuankg#include "apr.h"
b387b9d37fc71c534f4718777454a8f5a1169017fuankg#include "apr_strings.h"
b387b9d37fc71c534f4718777454a8f5a1169017fuankg#include "apr_lib.h"
b387b9d37fc71c534f4718777454a8f5a1169017fuankg#include "apr_hash.h"
b387b9d37fc71c534f4718777454a8f5a1169017fuankg
b387b9d37fc71c534f4718777454a8f5a1169017fuankg#define APR_WANT_STRFUNC
b387b9d37fc71c534f4718777454a8f5a1169017fuankg#include "apr_want.h"
b387b9d37fc71c534f4718777454a8f5a1169017fuankg
a400161a259d6d9fd47a47fd9a4bb413fd85e3bcsf#include "ap_config.h"
cfb941e9ad5276eef7bc8f3eedcd270f30cfec35fuankg#include "httpd.h"
bfd312b5e6b4bf7113ef8f655b044f93f5c18f28fuankg#include "http_config.h"
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes#include "http_log.h"
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes#include "http_request.h"
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes/* XXXX - fix me / EBCDIC
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * there was a cludge here which would use its
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * own version apr_isascii(). Indicating that
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg * on some platforms that might be needed.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes *
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * #define OS_ASC(c) (c) -- for mere mortals
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * or
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * #define OS_ASC(c) (ebcdic2ascii[c]) -- for dino's
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes *
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * #define apr_isascii(c) ((OS_ASC(c) & 0x80) == 0)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes/* XXXXX - fix me - See note with NOT_PROXY
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholestypedef struct attrib_info {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes char *name;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes int offset;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes} attrib_info;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes/* Information to which an extension can be mapped
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholestypedef struct extension_info {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes char *forced_type; /* Additional AddTyped stuff */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes char *encoding_type; /* Added with AddEncoding... */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes char *language_type; /* Added with AddLanguage... */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes char *handler; /* Added with AddHandler... */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes char *charset_type; /* Added with AddCharset... */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes char *input_filters; /* Added with AddInputFilter... */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes char *output_filters; /* Added with AddOutputFilter... */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes} extension_info;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes#define MULTIMATCH_UNSET 0
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg#define MULTIMATCH_ANY 1
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes#define MULTIMATCH_NEGOTIATED 2
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes#define MULTIMATCH_HANDLERS 4
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes#define MULTIMATCH_FILTERS 8
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholestypedef struct {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes apr_hash_t *extension_mappings; /* Map from extension name to
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * extension_info structure */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes apr_array_header_t *remove_mappings; /* A simple list, walked once */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes char *default_language; /* Language if no AddLanguage ext found */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes int multimatch; /* Extensions to include in multiview matching
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg * for filenames, e.g. Filters and Handlers
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes} mime_dir_config;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholestypedef struct param_s {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes char *attr;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes char *val;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes struct param_s *next;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes} param;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholestypedef struct {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes char *type;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes char *subtype;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes param *param;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes} content_type;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic char tspecial[] = {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes '(', ')', '<', '>', '@', ',', ';', ':',
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes '\\', '"', '/', '[', ']', '?', '=',
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes '\0'
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes};
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
ce22ce4743d79a889dca64df4459c598e2c188c7fuankgmodule AP_MODULE_DECLARE_DATA mime_module;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic void *create_mime_dir_config(apr_pool_t *p, char *dummy)
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg{
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes mime_dir_config *new =
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes (mime_dir_config *) apr_palloc(p, sizeof(mime_dir_config));
6c080a25f5991f40225209541c989d7e76c4a39dbnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new->extension_mappings = NULL;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new->remove_mappings = NULL;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new->default_language = NULL;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
b387b9d37fc71c534f4718777454a8f5a1169017fuankg new->multimatch = MULTIMATCH_UNSET;
41022996c916eb4ab2ec3204eb491b64779eb100bnicholes
41022996c916eb4ab2ec3204eb491b64779eb100bnicholes return new;
41022996c916eb4ab2ec3204eb491b64779eb100bnicholes}
41022996c916eb4ab2ec3204eb491b64779eb100bnicholes/*
41022996c916eb4ab2ec3204eb491b64779eb100bnicholes * Overlay one hash table of extension_mappings onto another
036436f4f4cdcd76186c0058891216545967043bbnicholes */
41022996c916eb4ab2ec3204eb491b64779eb100bnicholesstatic void *overlay_extension_mappings(apr_pool_t *p,
41022996c916eb4ab2ec3204eb491b64779eb100bnicholes const void *key,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes apr_ssize_t klen,
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg const void *overlay_val,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const void *base_val,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const void *data)
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg{
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes extension_info *new_info = apr_palloc(p, sizeof(extension_info));
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const extension_info *overlay_info = (const extension_info *)overlay_val;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const extension_info *base_info = (const extension_info *)base_val;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes memcpy(new_info, base_info, sizeof(extension_info));
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg if (overlay_info->forced_type) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new_info->forced_type = overlay_info->forced_type;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes }
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (overlay_info->encoding_type) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new_info->encoding_type = overlay_info->encoding_type;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes }
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (overlay_info->language_type) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new_info->language_type = overlay_info->language_type;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes }
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (overlay_info->handler) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new_info->handler = overlay_info->handler;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes }
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (overlay_info->charset_type) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new_info->charset_type = overlay_info->charset_type;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes }
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (overlay_info->input_filters) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new_info->input_filters = overlay_info->input_filters;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes }
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (overlay_info->output_filters) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new_info->output_filters = overlay_info->output_filters;
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg }
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes return new_info;
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg}
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes/* Member is the offset within an extension_info of the pointer to reset
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes */
ce22ce4743d79a889dca64df4459c598e2c188c7fuankgstatic void remove_items(apr_pool_t *p, apr_array_header_t *remove,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes apr_hash_t *mappings)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes{
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes attrib_info *suffix = (attrib_info *) remove->elts;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes int i;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes for (i = 0; i < remove->nelts; i++) {
b387b9d37fc71c534f4718777454a8f5a1169017fuankg extension_info *exinfo =
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes (extension_info*)apr_hash_get(mappings,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes suffix[i].name,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes APR_HASH_KEY_STRING);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (exinfo && *(const char**)((char *)exinfo + suffix[i].offset)) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes extension_info *copyinfo = exinfo;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes exinfo = (extension_info*)apr_palloc(p, sizeof(*exinfo));
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg apr_hash_set(mappings, suffix[i].name,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes APR_HASH_KEY_STRING, exinfo);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes memcpy(exinfo, copyinfo, sizeof(*exinfo));
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes *(const char**)((char *)exinfo + suffix[i].offset) = NULL;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes }
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes }
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes}
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic void *merge_mime_dir_configs(apr_pool_t *p, void *basev, void *addv)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes{
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes mime_dir_config *base = (mime_dir_config *) basev;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes mime_dir_config *add = (mime_dir_config *) addv;
56ab8639aed4d3b2f031d9c1160c5f40af01bdebjerenkrantz mime_dir_config *new = apr_palloc(p, sizeof(mime_dir_config));
286fed73f9d1474652034465d4048247c6e7341fbnicholes
be88e49281c5becee364ab9c6a0576f9b9844e0fbnicholes if (base->extension_mappings && add->extension_mappings) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new->extension_mappings = apr_hash_merge(p, add->extension_mappings,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes base->extension_mappings,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes overlay_extension_mappings,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes NULL);
56ab8639aed4d3b2f031d9c1160c5f40af01bdebjerenkrantz }
56ab8639aed4d3b2f031d9c1160c5f40af01bdebjerenkrantz else {
56ab8639aed4d3b2f031d9c1160c5f40af01bdebjerenkrantz if (base->extension_mappings == NULL) {
56ab8639aed4d3b2f031d9c1160c5f40af01bdebjerenkrantz new->extension_mappings = add->extension_mappings;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes }
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes else {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new->extension_mappings = base->extension_mappings;
f7d723f1ad88ed006c6caf4c2c6604b7c59dd172bnicholes }
f7d723f1ad88ed006c6caf4c2c6604b7c59dd172bnicholes /* We may not be merging the tables, but if we potentially will change
4f935de4900dc064a1e145be5e48f6af77ac24fcbnicholes * an exinfo member, then we are about to trounce it anyways.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * We must have a copy for safety.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (new->extension_mappings && add->remove_mappings) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new->extension_mappings =
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes apr_hash_copy(p, new->extension_mappings);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes }
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes }
e961abd49ab1b184b356f63591d37083a5651451bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (new->extension_mappings) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (add->remove_mappings)
5f2aaa2483c4526d7930df4a0e5844c1b7b6c9c0fuankg remove_items(p, add->remove_mappings, new->extension_mappings);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes }
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new->remove_mappings = NULL;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new->default_language = add->default_language ?
440cda576ca9ff6476e4a04bdb253c5023da15eejerenkrantz add->default_language : base->default_language;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes new->multimatch = (add->multimatch != MULTIMATCH_UNSET) ?
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes add->multimatch : base->multimatch;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes return new;
4a59e9d628fb857a45d516ad1cdc2a3499427e97fuankg}
6f2fa094a76c27135a9825ca9492f9db0a1a3bc9bnicholes
a400161a259d6d9fd47a47fd9a4bb413fd85e3bcsfstatic const char *add_extension_info(cmd_parms *cmd, void *m_,
a400161a259d6d9fd47a47fd9a4bb413fd85e3bcsf const char *value_, const char* ext)
a400161a259d6d9fd47a47fd9a4bb413fd85e3bcsf{
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes mime_dir_config *m=m_;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes extension_info *exinfo;
91f672664302529bb620e3265cccd861661d258cbnicholes int offset = (int) (long) cmd->info;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes char *key = apr_pstrdup(cmd->temp_pool, ext);
3163ad7b2076b0f6961dc1a1ddaa06b240eecb7cjorton char *value = apr_pstrdup(cmd->pool, value_);
62c14b2cab42c51bee08809b7f22e34edb48fb56fuankg ap_str_tolower(value);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes#ifdef CASE_BLIND_FILESYSTEM
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ap_str_tolower(key);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes#endif
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (*key == '.')
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ++key;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (!m->extension_mappings) {
9558e9fdb620dd6f42ca93beac6c3ab734086706bnicholes m->extension_mappings = apr_hash_make(cmd->pool);
9558e9fdb620dd6f42ca93beac6c3ab734086706bnicholes exinfo = NULL;
9558e9fdb620dd6f42ca93beac6c3ab734086706bnicholes }
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg else
9558e9fdb620dd6f42ca93beac6c3ab734086706bnicholes exinfo = (extension_info*)apr_hash_get(m->extension_mappings, key,
9558e9fdb620dd6f42ca93beac6c3ab734086706bnicholes APR_HASH_KEY_STRING);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (!exinfo) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes exinfo = apr_pcalloc(cmd->pool, sizeof(extension_info));
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes key = apr_pstrdup(cmd->pool, key);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes apr_hash_set(m->extension_mappings, key,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes APR_HASH_KEY_STRING, exinfo);
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg }
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg *(const char**)((char *)exinfo + offset) = value;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes return NULL;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes}
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes/*
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * Note handler names are un-added with each per_dir_config merge.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * This keeps the association from being inherited, but not
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * from being re-added at a subordinate level.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic const char *remove_extension_info(cmd_parms *cmd, void *m_,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const char *ext)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes{
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes mime_dir_config *m = (mime_dir_config *) m_;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes attrib_info *suffix;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (*ext == '.')
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ++ext;
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg if (!m->remove_mappings) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes m->remove_mappings = apr_array_make(cmd->pool, 4, sizeof(*suffix));
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes }
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes suffix = (attrib_info *) apr_array_push(m->remove_mappings);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes suffix->name = apr_pstrdup(cmd->pool, ext);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes#ifdef CASE_BLIND_FILESYSTEM
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ap_str_tolower(suffix->name);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes#endif
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes suffix->offset = (int) (long) cmd->info;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes return NULL;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes}
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes/* The sole bit of server configuration that the MIME module has is
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * the name of its config file, so...
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic const char *set_types_config(cmd_parms *cmd, void *dummy,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const char *arg)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes{
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ap_set_module_config(cmd->server->module_config, &mime_module,
9558e9fdb620dd6f42ca93beac6c3ab734086706bnicholes (void *)arg);
e76fdcdfb8994ad70776526f50fa013b3e9a6033bnicholes return NULL;
9558e9fdb620dd6f42ca93beac6c3ab734086706bnicholes}
9558e9fdb620dd6f42ca93beac6c3ab734086706bnicholes
ce22ce4743d79a889dca64df4459c598e2c188c7fuankgstatic const char *multiviews_match(cmd_parms *cmd, void *m_,
9558e9fdb620dd6f42ca93beac6c3ab734086706bnicholes const char *include)
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg{
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg mime_dir_config *m = (mime_dir_config *) m_;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (strcasecmp(include, "Any") == 0) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (m->multimatch && (m->multimatch & ~MULTIMATCH_ANY))
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes return "Any is incompatible with NegotiatedOnly, "
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "Filters and Handlers";
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg m->multimatch |= MULTIMATCH_ANY;
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg }
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes else if (strcasecmp(include, "NegotiatedOnly") == 0) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (m->multimatch && (m->multimatch & ~MULTIMATCH_NEGOTIATED))
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes return "Any is incompatible with NegotiatedOnly, "
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg "Filters and Handlers";
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg m->multimatch |= MULTIMATCH_NEGOTIATED;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes }
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg else if (strcasecmp(include, "Filters") == 0) {
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg if (m->multimatch && (m->multimatch & (MULTIMATCH_NEGOTIATED
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes | MULTIMATCH_ANY)))
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg return "Filters is incompatible with Any and NegotiatedOnly";
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg m->multimatch |= MULTIMATCH_FILTERS;
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg }
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg else if (strcasecmp(include, "Handlers") == 0) {
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg if (m->multimatch && (m->multimatch & (MULTIMATCH_NEGOTIATED
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg | MULTIMATCH_ANY)))
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg return "Handlers is incompatible with Any and NegotiatedOnly";
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg m->multimatch |= MULTIMATCH_HANDLERS;
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg }
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg else
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg return "Unrecognized option";
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg return NULL;
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg}
8492a2583e10c69f40de92f9d5da884b64d9f379fuankg
8492a2583e10c69f40de92f9d5da884b64d9f379fuankgstatic const command_rec mime_cmds[] =
d598e371878cc5aa4c3a2b77c814d9b55dbdb943fuankg{
d598e371878cc5aa4c3a2b77c814d9b55dbdb943fuankgAP_INIT_ITERATE2("AddCharset", add_extension_info,
d598e371878cc5aa4c3a2b77c814d9b55dbdb943fuankg (void *)APR_XtOffsetOf(extension_info, charset_type), OR_FILEINFO,
d598e371878cc5aa4c3a2b77c814d9b55dbdb943fuankg "a charset (e.g., iso-2022-jp), followed by one or more file extensions"),
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesAP_INIT_ITERATE2("AddEncoding", add_extension_info,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes (void *)APR_XtOffsetOf(extension_info, encoding_type), OR_FILEINFO,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "an encoding (e.g., gzip), followed by one or more file extensions"),
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesAP_INIT_ITERATE2("AddHandler", add_extension_info,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes (void *)APR_XtOffsetOf(extension_info, handler), OR_FILEINFO,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "a handler name followed by one or more file extensions"),
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesAP_INIT_ITERATE2("AddInputFilter", add_extension_info,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes (void *)APR_XtOffsetOf(extension_info, input_filters), OR_FILEINFO,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "input filter name (or ; delimited names) followed by one or more file extensions"),
ce22ce4743d79a889dca64df4459c598e2c188c7fuankgAP_INIT_ITERATE2("AddLanguage", add_extension_info,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes (void *)APR_XtOffsetOf(extension_info, language_type), OR_FILEINFO,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "a language (e.g., fr), followed by one or more file extensions"),
25b3aa26ee94824bb1e9ff2631aa1588b37e5f72fuankgAP_INIT_ITERATE2("AddOutputFilter", add_extension_info,
8209b79780530f392dee6e459468d5e9eb0a4299fuankg (void *)APR_XtOffsetOf(extension_info, output_filters), OR_FILEINFO,
8209b79780530f392dee6e459468d5e9eb0a4299fuankg "output filter name (or ; delimited names) followed by one or more file extensions"),
8209b79780530f392dee6e459468d5e9eb0a4299fuankgAP_INIT_ITERATE2("AddType", add_extension_info,
8209b79780530f392dee6e459468d5e9eb0a4299fuankg (void *)APR_XtOffsetOf(extension_info, forced_type), OR_FILEINFO,
8209b79780530f392dee6e459468d5e9eb0a4299fuankg "a mime type followed by one or more file extensions"),
8209b79780530f392dee6e459468d5e9eb0a4299fuankgAP_INIT_TAKE1("DefaultLanguage", ap_set_string_slot,
8209b79780530f392dee6e459468d5e9eb0a4299fuankg (void*)APR_XtOffsetOf(mime_dir_config, default_language), OR_FILEINFO,
8209b79780530f392dee6e459468d5e9eb0a4299fuankg "language to use for documents with no other language file extension"),
8209b79780530f392dee6e459468d5e9eb0a4299fuankgAP_INIT_ITERATE("MultiviewsMatch", multiviews_match, NULL, OR_FILEINFO,
8209b79780530f392dee6e459468d5e9eb0a4299fuankg "NegotiatedOnly (default), Handlers and/or Filters, or Any"),
8209b79780530f392dee6e459468d5e9eb0a4299fuankgAP_INIT_ITERATE("RemoveCharset", remove_extension_info,
8209b79780530f392dee6e459468d5e9eb0a4299fuankg (void *)APR_XtOffsetOf(extension_info, charset_type), OR_FILEINFO,
8209b79780530f392dee6e459468d5e9eb0a4299fuankg "one or more file extensions"),
8209b79780530f392dee6e459468d5e9eb0a4299fuankgAP_INIT_ITERATE("RemoveEncoding", remove_extension_info,
8209b79780530f392dee6e459468d5e9eb0a4299fuankg (void *)APR_XtOffsetOf(extension_info, encoding_type), OR_FILEINFO,
4883fd339815130dbe680e816ef00256e10b844ffuankg "one or more file extensions"),
f2f3f241c00a7a4bd597e57a19023940e072918abnicholesAP_INIT_ITERATE("RemoveHandler", remove_extension_info,
755d7c84cbdd7bad94beede1d6b5a6526d3a1ccdfuankg (void *)APR_XtOffsetOf(extension_info, handler), OR_FILEINFO,
755d7c84cbdd7bad94beede1d6b5a6526d3a1ccdfuankg "one or more file extensions"),
755d7c84cbdd7bad94beede1d6b5a6526d3a1ccdfuankgAP_INIT_ITERATE("RemoveInputFilter", remove_extension_info,
755d7c84cbdd7bad94beede1d6b5a6526d3a1ccdfuankg (void *)APR_XtOffsetOf(extension_info, input_filters), OR_FILEINFO,
755d7c84cbdd7bad94beede1d6b5a6526d3a1ccdfuankg "one or more file extensions"),
755d7c84cbdd7bad94beede1d6b5a6526d3a1ccdfuankgAP_INIT_ITERATE("RemoveLanguage", remove_extension_info,
755d7c84cbdd7bad94beede1d6b5a6526d3a1ccdfuankg (void *)APR_XtOffsetOf(extension_info, language_type), OR_FILEINFO,
755d7c84cbdd7bad94beede1d6b5a6526d3a1ccdfuankg "one or more file extensions"),
755d7c84cbdd7bad94beede1d6b5a6526d3a1ccdfuankgAP_INIT_ITERATE("RemoveOutputFilter", remove_extension_info,
4883fd339815130dbe680e816ef00256e10b844ffuankg (void *)APR_XtOffsetOf(extension_info, output_filters), OR_FILEINFO,
4883fd339815130dbe680e816ef00256e10b844ffuankg "one or more file extensions"),
8209b79780530f392dee6e459468d5e9eb0a4299fuankgAP_INIT_ITERATE("RemoveType", remove_extension_info,
8209b79780530f392dee6e459468d5e9eb0a4299fuankg (void *)APR_XtOffsetOf(extension_info, forced_type), OR_FILEINFO,
8209b79780530f392dee6e459468d5e9eb0a4299fuankg "one or more file extensions"),
8209b79780530f392dee6e459468d5e9eb0a4299fuankgAP_INIT_TAKE1("TypesConfig", set_types_config, NULL, RSRC_CONF,
8209b79780530f392dee6e459468d5e9eb0a4299fuankg "the MIME types config file"),
0f7cc4b1d3c42262bcdced99f682778963e83ea7bnicholes {NULL}
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes};
8209b79780530f392dee6e459468d5e9eb0a4299fuankg
8209b79780530f392dee6e459468d5e9eb0a4299fuankgstatic apr_hash_t *mime_type_extensions;
8209b79780530f392dee6e459468d5e9eb0a4299fuankg
8209b79780530f392dee6e459468d5e9eb0a4299fuankgstatic void mime_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
8209b79780530f392dee6e459468d5e9eb0a4299fuankg{
8209b79780530f392dee6e459468d5e9eb0a4299fuankg ap_configfile_t *f;
8209b79780530f392dee6e459468d5e9eb0a4299fuankg char l[MAX_STRING_LEN];
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg const char *types_confname = ap_get_module_config(s->module_config, &mime_module);
273e1eccdc9e5b94f1e3e13e3ffca7360b6f461fbnicholes apr_status_t status;
b387b9d37fc71c534f4718777454a8f5a1169017fuankg
b387b9d37fc71c534f4718777454a8f5a1169017fuankg if (!types_confname)
b387b9d37fc71c534f4718777454a8f5a1169017fuankg types_confname = AP_TYPES_CONFIG_FILE;
273e1eccdc9e5b94f1e3e13e3ffca7360b6f461fbnicholes
2711ba83bd97ebdc2c9276f31a5364ea106078f4fuankg types_confname = ap_server_root_relative(p, types_confname);
273e1eccdc9e5b94f1e3e13e3ffca7360b6f461fbnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if ((status = ap_pcfg_openfile(&f, ptemp, types_confname)) != APR_SUCCESS) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ap_log_error(APLOG_MARK, APLOG_ERR, status, s,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "could not open mime types config file %s.", types_confname);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes exit(1);
8410c53aaf5e0372a19d5f4d2bc696b9c609ce3cbnicholes }
8410c53aaf5e0372a19d5f4d2bc696b9c609ce3cbnicholes
bfd312b5e6b4bf7113ef8f655b044f93f5c18f28fuankg mime_type_extensions = apr_hash_make(p);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes while (!(ap_cfg_getline(l, MAX_STRING_LEN, f))) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const char *ll = l, *ct;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (l[0] == '#')
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes continue;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ct = ap_getword_conf(p, &ll);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes
25b3aa26ee94824bb1e9ff2631aa1588b37e5f72fuankg while (ll[0]) {
25b3aa26ee94824bb1e9ff2631aa1588b37e5f72fuankg char *ext = ap_getword_conf(p, &ll);
ce22ce4743d79a889dca64df4459c598e2c188c7fuankg ap_str_tolower(ext); /* ??? */
apr_hash_set(mime_type_extensions, ext, APR_HASH_KEY_STRING, ct);
}
}
ap_cfg_closefile(f);
}
static char *zap_sp(char *s)
{
char *tp;
if (s == NULL) {
return (NULL);
}
if (*s == '\0') {
return (s);
}
/* delete prefixed white space */
for (; *s == ' ' || *s == '\t' || *s == '\n'; s++);
/* delete postfixed white space */
for (tp = s; *tp != '\0'; tp++);
for (tp--; tp != s && (*tp == ' ' || *tp == '\t' || *tp == '\n'); tp--) {
*tp = '\0';
}
return (s);
}
static int is_token(char c)
{
int res;
res = (apr_isascii(c) && apr_isgraph(c)
&& (strchr(tspecial, c) == NULL)) ? 1 : -1;
return res;
}
static int is_qtext(char c)
{
int res;
res = (apr_isascii(c) && (c != '"') && (c != '\\') && (c != '\n'))
? 1 : -1;
return res;
}
static int is_quoted_pair(char *s)
{
int res = -1;
int c;
if (((s + 1) != NULL) && (*s == '\\')) {
c = (int) *(s + 1);
if (apr_isascii(c)) {
res = 1;
}
}
return (res);
}
static content_type *analyze_ct(request_rec *r, char *s)
{
char *tp, *mp, *cp;
char *attribute, *value;
int quoted = 0;
server_rec * ss = r->server;
apr_pool_t * p = r->pool;
content_type *ctp;
param *pp, *npp;
/* initialize ctp */
ctp = (content_type *) apr_palloc(p, sizeof(content_type));
ctp->type = NULL;
ctp->subtype = NULL;
ctp->param = NULL;
tp = apr_pstrdup(p, s);
mp = tp;
cp = mp;
/* getting a type */
if (!(cp = strchr(mp, '/'))) {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss,
"mod_mime: analyze_ct: cannot get media type from '%s'",
(const char *) mp);
return (NULL);
}
ctp->type = apr_pstrndup(p, mp, cp - mp);
ctp->type = zap_sp(ctp->type);
if (ctp->type == NULL || *(ctp->type) == '\0' ||
strchr(ctp->type, ';') || strchr(ctp->type, ' ') ||
strchr(ctp->type, '\t')) {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss,
"Cannot get media subtype.");
return (NULL);
}
/* getting a subtype */
cp++;
mp = cp;
for (; *cp != ';' && *cp != '\0'; cp++)
continue;
ctp->subtype = apr_pstrndup(p, mp, cp - mp);
ctp->subtype = zap_sp(ctp->subtype);
if ((ctp->subtype == NULL) || (*(ctp->subtype) == '\0') ||
strchr(ctp->subtype, ' ') || strchr(ctp->subtype, '\t')) {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss,
"Cannot get media subtype.");
return (NULL);
}
cp = zap_sp(cp);
if (cp == NULL || *cp == '\0') {
return (ctp);
}
/* getting parameters */
cp++;
cp = zap_sp(cp);
if (cp == NULL || *cp == '\0') {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss,
"Cannot get media parameter.");
return (NULL);
}
mp = cp;
attribute = NULL;
value = NULL;
while (cp != NULL && *cp != '\0') {
if (attribute == NULL) {
if (is_token(*cp) > 0) {
cp++;
continue;
}
else if (*cp == ' ' || *cp == '\t' || *cp == '\n') {
cp++;
continue;
}
else if (*cp == '=') {
attribute = apr_pstrndup(p, mp, cp - mp);
attribute = zap_sp(attribute);
if (attribute == NULL || *attribute == '\0') {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss,
"Cannot get media parameter.");
return (NULL);
}
cp++;
cp = zap_sp(cp);
if (cp == NULL || *cp == '\0') {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss,
"Cannot get media parameter.");
return (NULL);
}
mp = cp;
continue;
}
else {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss,
"Cannot get media parameter.");
return (NULL);
}
}
else {
if (mp == cp) {
if (*cp == '"') {
quoted = 1;
cp++;
}
else {
quoted = 0;
}
}
if (quoted > 0) {
while (quoted && *cp != '\0') {
if (is_qtext(*cp) > 0) {
cp++;
}
else if (is_quoted_pair(cp) > 0) {
cp += 2;
}
else if (*cp == '"') {
cp++;
while (*cp == ' ' || *cp == '\t' || *cp == '\n') {
cp++;
}
if (*cp != ';' && *cp != '\0') {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss,
"Cannot get media parameter.");
return(NULL);
}
quoted = 0;
}
else {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss,
"Cannot get media parameter.");
return (NULL);
}
}
}
else {
while (1) {
if (is_token(*cp) > 0) {
cp++;
}
else if (*cp == '\0' || *cp == ';') {
break;
}
else {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss,
"Cannot get media parameter.");
return (NULL);
}
}
}
value = apr_pstrndup(p, mp, cp - mp);
value = zap_sp(value);
if (value == NULL || *value == '\0') {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ss,
"Cannot get media parameter.");
return (NULL);
}
pp = apr_palloc(p, sizeof(param));
pp->attr = attribute;
pp->val = value;
pp->next = NULL;
if (ctp->param == NULL) {
ctp->param = pp;
}
else {
npp = ctp->param;
while (npp->next) {
npp = npp->next;
}
npp->next = pp;
}
quoted = 0;
attribute = NULL;
value = NULL;
if (*cp == '\0') {
break;
}
cp++;
mp = cp;
}
}
return (ctp);
}
/*
* find_ct is the hook routine for determining content-type and other
* MIME-related metadata. It assumes that r->filename has already been
* set and stat has been called for r->finfo. It also assumes that the
* non-path base file name is not the empty string unless it is a dir.
*/
static int find_ct(request_rec *r)
{
mime_dir_config *conf;
apr_array_header_t *exception_list;
char *ext;
const char *fn, *type, *charset = NULL;
int found_metadata = 0;
if (r->finfo.filetype == APR_DIR) {
r->content_type = DIR_MAGIC_TYPE;
return OK;
}
conf = (mime_dir_config *) ap_get_module_config(r->per_dir_config,
&mime_module);
exception_list = apr_array_make(r->pool, 2, sizeof(char *));
/* Always drop the path leading up to the file name.
*/
if ((fn = strrchr(r->filename, '/')) == NULL)
fn = r->filename;
else
++fn;
/* The exception list keeps track of those filename components that
* are not associated with extensions indicating metadata.
* The base name is always the first exception (i.e., "txt.html" has
* a basename of "txt" even though it might look like an extension).
*/
ext = ap_getword(r->pool, &fn, '.');
*((const char **) apr_array_push(exception_list)) = ext;
/* Parse filename extensions which can be in any order
*/
while (*fn && (ext = ap_getword(r->pool, &fn, '.'))) {
const extension_info *exinfo = NULL;
int found;
if (*ext == '\0') /* ignore empty extensions "bad..html" */
continue;
found = 0;
#ifdef CASE_BLIND_FILESYSTEM
/* We have a basic problem that folks on case-crippled systems
* expect anything and everything to succeed
*/
ap_str_tolower(ext);
#endif
if (conf->extension_mappings != NULL) {
exinfo = (extension_info*)apr_hash_get(conf->extension_mappings,
ext, APR_HASH_KEY_STRING);
}
if (exinfo == NULL || !exinfo->forced_type) {
if ((type = apr_hash_get(mime_type_extensions, ext,
APR_HASH_KEY_STRING)) != NULL) {
r->content_type = type;
found = 1;
}
}
if (exinfo != NULL) {
if (exinfo->forced_type) {
r->content_type = exinfo->forced_type;
found = 1;
}
if (exinfo->charset_type) {
charset = exinfo->charset_type;
found = 1;
}
if (exinfo->language_type) {
if (!r->content_languages)
r->content_languages = apr_array_make(r->pool, 2,
sizeof(char *));
*((const char **) apr_array_push(r->content_languages))
= exinfo->language_type;
found = 1;
}
if (exinfo->encoding_type) {
if (!r->content_encoding)
r->content_encoding = exinfo->encoding_type;
else {
/* XXX should eliminate duplicate entities */
r->content_encoding = apr_pstrcat(r->pool,
r->content_encoding,
", ",
exinfo->encoding_type,
NULL);
}
found = 1;
}
/* The following extensions are not 'Found'. That is, they don't
* make any contribution to metadata negotation, so they must have
* been explicitly requested by name.
*/
if (exinfo->handler && r->proxyreq == PROXYREQ_NONE) {
r->handler = exinfo->handler;
if (conf->multimatch & MULTIMATCH_HANDLERS)
found = 1;
}
/* XXX Two significant problems; 1, we don't check to see if we are
* setting redundant filters. 2, we insert these in the types config
* hook, which may be too early (dunno.)
*/
if (exinfo->input_filters && r->proxyreq == PROXYREQ_NONE) {
const char *filter, *filters = exinfo->input_filters;
while (*filters
&& (filter = ap_getword(r->pool, &filters, ';'))) {
ap_add_input_filter(filter, NULL, r, r->connection);
}
if (conf->multimatch & MULTIMATCH_FILTERS)
found = 1;
}
if (exinfo->output_filters && r->proxyreq == PROXYREQ_NONE) {
const char *filter, *filters = exinfo->output_filters;
while (*filters
&& (filter = ap_getword(r->pool, &filters, ';'))) {
ap_add_output_filter(filter, NULL, r, r->connection);
}
if (conf->multimatch & MULTIMATCH_FILTERS)
found = 1;
}
}
if (found || (conf->multimatch & MULTIMATCH_ANY))
found_metadata = 1;
else
*((const char **) apr_array_push(exception_list)) = ext;
}
/*
* Need to set a notes entry on r for unrecognized elements.
* Somebody better claim them! If we did absolutely nothing,
* skip the notes to alert mod_negotiation we are clueless.
*/
if (found_metadata) {
apr_table_setn(r->notes, "ap-mime-exceptions-list",
(void *)exception_list);
}
if (r->content_type) {
content_type *ctp;
char *ct;
int override = 0;
ct = (char *) apr_palloc(r->pool,
sizeof(char) * (strlen(r->content_type) + 1));
strcpy(ct, r->content_type);
if ((ctp = analyze_ct(r, ct))) {
param *pp = ctp->param;
r->content_type = apr_pstrcat(r->pool, ctp->type, "/",
ctp->subtype, NULL);
while (pp != NULL) {
if (charset && !strcmp(pp->attr, "charset")) {
if (!override) {
r->content_type = apr_pstrcat(r->pool, r->content_type,
"; charset=", charset,
NULL);
override = 1;
}
}
else {
r->content_type = apr_pstrcat(r->pool, r->content_type,
"; ", pp->attr,
"=", pp->val,
NULL);
}
pp = pp->next;
}
if (charset && !override) {
r->content_type = apr_pstrcat(r->pool, r->content_type,
"; charset=", charset,
NULL);
}
}
}
/* Set default language, if none was specified by the extensions
* and we have a DefaultLanguage setting in force
*/
if (!r->content_languages && conf->default_language) {
const char **new;
if (!r->content_languages)
r->content_languages = apr_array_make(r->pool, 2, sizeof(char *));
new = (const char **) apr_array_push(r->content_languages);
*new = conf->default_language;
}
if (!r->content_type)
return DECLINED;
return OK;
}
static void register_hooks(apr_pool_t *p)
{
ap_hook_post_config(mime_post_config,NULL,NULL,APR_HOOK_MIDDLE);
ap_hook_type_checker(find_ct,NULL,NULL,APR_HOOK_MIDDLE);
/*
* this hook seems redundant ... is there any reason a type checker isn't
* allowed to do this already? I'd think that fixups in general would be
* the last opportunity to get the filters right.
* ap_hook_insert_filter(mime_insert_filters,NULL,NULL,APR_HOOK_MIDDLE);
*/
}
module AP_MODULE_DECLARE_DATA mime_module = {
STANDARD20_MODULE_STUFF,
create_mime_dir_config, /* create per-directory config structure */
merge_mime_dir_configs, /* merge per-directory config structures */
NULL, /* create per-server config structure */
NULL, /* merge per-server config structures */
mime_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};