mod_mime.c revision 46de853ccb7478106900ae44a039cde3af036963
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. 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. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``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 SOFTWARE FOUNDATION 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 Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
/*
* http_mime.c: Sends/gets MIME headers for requests
*
* Rob McCool
*
*/
#include "apr.h"
#include "apr_strings.h"
#include "apr_lib.h"
#include "apr_hash.h"
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "http_request.h"
/* XXXX - fix me / EBCDIC
* there was a cludge here which would use its
* own version apr_isascii(). Indicating that
* on some platforms that might be needed.
*
* #define OS_ASC(c) (c) -- for mere mortals
* or
* #define OS_ASC(c) (ebcdic2ascii[c]) -- for dino's
*
* #define apr_isascii(c) ((OS_ASC(c) & 0x80) == 0)
*/
/* XXXXX - fix me - See note with NOT_PROXY
*/
typedef struct attrib_info {
char *name;
} attrib_info;
/* Information to which an extension can be mapped
*/
typedef struct extension_info {
char *forced_type; /* Additional AddTyped stuff */
char *encoding_type; /* Added with AddEncoding... */
char *language_type; /* Added with AddLanguage... */
char *handler; /* Added with AddHandler... */
char *charset_type; /* Added with AddCharset... */
int copy; /* To avoid dupping in the merge */
typedef struct {
* extension_info structure */
int copy_mappings; /* To avoid dupping in the merge */
char *type; /* Type forced with ForceType */
char *handler; /* Handler forced with SetHandler */
char *default_language; /* Language if no AddLanguage ext found */
/* Due to the FUD about JS and charsets
typedef struct param_s {
char *attr;
char *val;
} param;
typedef struct {
char *type;
char *subtype;
} content_type;
static char tspecial[] = {
'(', ')', '<', '>', '@', ',', ';', ':',
'\\', '"', '/', '[', ']', '?', '=',
'\0'
};
{
new->copy_mappings = 0;
return new;
}
/*
* Overlay one hash table of extension_mappings onto another
*/
static void overlay_extension_mappings(apr_pool_t *p,
{
char *key;
if (base_info) {
}
if (overlay_info->forced_type) {
}
if (overlay_info->encoding_type) {
}
if (overlay_info->language_type) {
}
if (overlay_info->handler) {
}
if (overlay_info->charset_type) {
}
}
else {
}
}
}
{
int i;
if (base->copy_mappings)
else {
}
}
else {
}
}
|| add->types_remove
|| add->encodings_remove)) {
/* ### as slow as can be... just use an apr_hash_dup! */
}
}
if (add->handlers_remove) {
if (exinfo) {
}
}
}
}
if (add->types_remove) {
if (exinfo) {
}
}
}
}
if (add->encodings_remove) {
if (exinfo) {
}
}
}
}
return new;
}
const char* ext)
{
mime_dir_config *m=m_;
#ifdef CASE_BLIND_FILESYSTEM
#endif
if (*key == '.')
++key;
if (!exinfo) {
/* pcalloc sets ->copy to false */
}
return exinfo;
}
const char *ext)
{
return NULL;
}
const char *ext)
{
return NULL;
}
const char *ext)
{
return NULL;
}
const char *ext)
{
return NULL;
}
const char *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.
*/
const char* ext)
{
if (*ext == '.')
++ext;
}
#ifdef CASE_BLIND_FILESYSTEM
#endif
}
{
return NULL;
}
/*
* Just like the previous function, except that it records encoding
* associations to be undone.
*/
{
return NULL;
}
/*
* Similar to the previous functions, except that it deals with filename
*/
{
return NULL;
}
/* The sole bit of server configuration that the MIME module has is
* the name of its config file, so...
*/
const char *arg)
{
(void *)arg);
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 charset (e.g., iso-2022-jp), 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"),
"a media type"),
"one or more file extensions"),
"one or more file extensions"),
"one or more file extensions"),
"a handler name"),
"the MIME types config file"),
"language to use for documents with no other language file extension"),
{NULL}
};
static apr_hash_t *mime_type_extensions;
{
ap_configfile_t *f;
char l[MAX_STRING_LEN];
if (!types_confname)
"could not open mime types config file %s.", types_confname);
exit(1);
}
while (!(ap_cfg_getline(l, MAX_STRING_LEN, f))) {
if (l[0] == '#')
continue;
while (ll[0]) {
}
}
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 */
*tp = '\0';
}
return (s);
}
static int is_token(char c)
{
int res;
return res;
}
static int is_qtext(char c)
{
int res;
? 1 : -1;
return res;
}
static int is_quoted_pair(char *s)
{
int res = -1;
int c;
c = (int) *(s + 1);
if (apr_isascii(c)) {
res = 1;
}
}
return (res);
}
{
int quoted = 0;
apr_pool_t * p = r->pool;
/* initialize ctp */
tp = apr_pstrdup(p, s);
/* getting a type */
"mod_mime: analyze_ct: cannot get media type from '%s'",
(const char *) mp);
return (NULL);
}
"Cannot get media subtype.");
return (NULL);
}
/* getting a subtype */
cp++;
continue;
"Cannot get media subtype.");
return (NULL);
}
return (ctp);
}
/* getting parameters */
cp++;
"Cannot get media parameter.");
return (NULL);
}
cp++;
continue;
}
cp++;
continue;
}
else if (*cp == '=') {
"Cannot get media parameter.");
return (NULL);
}
cp++;
"Cannot get media parameter.");
return (NULL);
}
continue;
}
else {
"Cannot get media parameter.");
return (NULL);
}
}
else {
if (*cp == '"') {
quoted = 1;
cp++;
}
else {
quoted = 0;
}
}
if (quoted > 0) {
cp++;
}
else if (is_quoted_pair(cp) > 0) {
cp += 2;
}
else if (*cp == '"') {
cp++;
cp++;
}
"Cannot get media parameter.");
return(NULL);
}
quoted = 0;
}
else {
"Cannot get media parameter.");
return (NULL);
}
}
}
else {
while (1) {
cp++;
}
break;
}
else {
"Cannot get media parameter.");
return (NULL);
}
}
}
"Cannot get media parameter.");
return (NULL);
}
}
else {
}
}
quoted = 0;
if (*cp == '\0') {
break;
}
cp++;
}
}
return (ctp);
}
static int find_ct(request_rec *r)
{
char *ext;
const char *type;
int found_any = 0;
r->content_type = DIR_MAGIC_TYPE;
return OK;
}
/* Always drop the leading element
*/
else
++fn;
/* always add a note that we have parsed exceptions,
* the base name is the first exception.
*/
/* Parse filename extensions which can be in any order
*/
int found = 0;
#ifdef CASE_BLIND_FILESYSTEM
/* We have a basic problem that folks on case-crippled systems
* expect anything and everything to succeed
*/
#endif
/* Check for Content-Type */
APR_HASH_KEY_STRING))) {
r->content_type = type;
found = 1;
}
/* Add charset to Content-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
/* XXX should eliminate duplicate entities */
found = 1;
}
/* Check for a special handler, but not for proxy request */
&& (PROXYREQ_NONE == r->proxyreq)) {
found = 1;
}
/* Not good... nobody claims it.
*/
if (found)
found_any = 1;
else
}
/*
* 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_any) {
(void *)exception_list);
}
if (r->content_type) {
char *ct;
int override = 0;
if (!override) {
"; charset=", charset,
NULL);
override = 1;
}
}
else {
NULL);
}
}
"; charset=", charset,
NULL);
}
}
}
/* 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(apr_pool_t *p)
{
}
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 */
};