mod_mime.c revision 0942697a9b5de44865676345a3828741c827efe6
/* ====================================================================
* Copyright (c) 1995-1999 The Apache Group. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* 4. The names "Apache Server" and "Apache Group" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Group and was originally based
* on public domain software written at the National Center for
* Supercomputing Applications, University of Illinois, Urbana-Champaign.
* For more information on the Apache Group and the Apache HTTP server
* project, please see <http://www.apache.org/>.
*
*/
/*
* http_mime.c: Sends/gets MIME headers for requests
*
* Rob McCool
*
*/
#define MIME_PRIVATE
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "http_request.h"
typedef struct handlers_info {
char *name;
typedef struct {
char *type; /* Type forced with ForceType */
char *handler; /* Handler forced with SetHandler */
char *default_language; /* Language if no AddLanguage ext found */
{
return new;
}
{
int i;
}
base->forced_types);
return new;
}
char *ext)
{
if (*ext == '.')
++ext;
return NULL;
}
char *ext)
{
if (*ext == '.')
++ext;
return NULL;
}
char *ext)
{
if (*ext == '.')
++ext;
return NULL;
}
char *ext)
{
if (*ext == '.')
++ext;
return NULL;
}
/*
* Note handler names that should be un-added for this location. This
* will keep the association from being inherited, as well, but not
* from being re-added at a subordinate level.
*/
{
if (*ext == '.') {
++ext;
}
return NULL;
}
/* The sole bit of server configuration that the MIME module has is
* the name of its config file, so...
*/
{
return NULL;
}
static const command_rec mime_cmds[] =
{
"a mime type followed by one or more file extensions"},
"an encoding (e.g., gzip), followed by one or more file extensions"},
"a language (e.g., fr), followed by one or more file extensions"},
"a handler name followed by one or more file extensions"},
{"ForceType", ap_set_string_slot_lower,
"a media type"},
"one or more file extensions"},
{"SetHandler", ap_set_string_slot_lower,
"a handler name"},
"the MIME types config file"},
{"DefaultLanguage", ap_set_string_slot,
"language to use for documents with no other language file extension" },
{NULL}
};
/* Hash ap_table_t --- only one of these per daemon; virtual hosts can
* get private versions through AddType...
*/
#define MIME_HASHSIZE (32)
static void mime_post_config(ap_context_t *p, ap_context_t *plog, ap_context_t *ptemp, server_rec *s)
{
configfile_t *f;
char l[MAX_STRING_LEN];
int x;
if (!types_confname)
if (!(f = ap_pcfg_openfile(p, types_confname))) {
"could not open mime types log file %s.", types_confname);
exit(1);
}
for (x = 0; x < MIME_HASHSIZE; x++)
while (!(ap_cfg_getline(l, MAX_STRING_LEN, f))) {
if (l[0] == '#')
continue;
while (ll[0]) {
}
}
ap_cfg_closefile(f);
}
static int find_ct(request_rec *r)
{
char *ext;
const char *orighandler = r->handler;
const char *type;
r->content_type = DIR_MAGIC_TYPE;
return OK;
}
/* TM -- FIXME
* if r->filename does not contain a '/', the following passes a null
* pointer to getword, causing a SEGV ..
*/
/* Parse filename extensions, which can be in any order */
int found = 0;
/* Check for Content-Type */
r->content_type = type;
found = 1;
}
/* Check for Content-Language */
const char **new;
if (!r->content_languages)
found = 1;
}
/* Check for Content-Encoding */
if (!r->content_encoding)
r->content_encoding = type;
else
found = 1;
}
/* Check for a special handler, but not for proxy request */
found = 1;
}
/* This is to deal with cases such as foo.gif.bak, which we want
* to not have a type. So if we find an unknown extension, we
*/
if (!found) {
r->content_type = NULL;
r->content_language = NULL;
r->content_languages = NULL;
r->content_encoding = NULL;
r->handler = orighandler;
}
}
/* Set default language, if none was specified by the extensions
* and we have a DefaultLanguage setting in force
*/
const char **new;
if (!r->content_languages)
}
/* Check for overrides with ForceType/SetHandler */
if (!r->content_type)
return DECLINED;
return OK;
}
static void register_hooks(void)
{
}
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 ap_table_t */
NULL, /* handlers */
register_hooks /* register hooks */
};