mod_mime.c revision e95f5a6ebefb83d0e8a82cbc4db7d354957a817d
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 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
*
*/
#define MIME_PRIVATE
#include "apr_strings.h"
#include "apr_lib.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "http_request.h"
#ifdef HAVE_STRING_H
#include <string.h>
#endif
/* 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;
typedef struct {
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'
};
{
return new;
}
{
int i;
base->forced_types);
base->filter_names);
}
}
}
return new;
}
const char *ext)
{
mime_dir_config *m=m_;
if (*ext == '.')
++ext;
return NULL;
}
const char *ext)
{
mime_dir_config *m=m_;
if (*ext == '.')
++ext;
return NULL;
}
const char *ext)
{
mime_dir_config *m=m_;
if (*ext == '.') {
++ext;
}
return NULL;
}
const char *ext)
{
mime_dir_config *m=m_;
if (*ext == '.') {
++ext;
}
return NULL;
}
const char *ext)
{
mime_dir_config *m=m_;
if (*ext == '.')
++ext;
return NULL;
}
const char *filt)
{
mime_dir_config *m=m_;
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;
}
/*
* Just like the previous function, except that it records encoding
* associations to be undone.
*/
{
if (*ext == '.') {
++ext;
}
return NULL;
}
/*
* Similar to the previous functions, except that it deals with filename
*/
{
if (*ext == '.') {
++ext;
}
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 mime type followed by one or more filters"),
"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}
};
/* Hash apr_table_t --- only one of these per daemon; virtual hosts can
* get private versions through AddType...
*/
#define MIME_HASHSIZE (32)
{
configfile_t *f;
char l[MAX_STRING_LEN];
int x;
if (!types_confname)
"could not open mime types config 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 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++;
"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 *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;
}
/* 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
found = 1;
}
/* Check for a special handler, but not for proxy request */
#if 0
/* XXX fix me when the proxy code is updated */
#endif
) {
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;
}
}
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;
}
{
request_rec *r = input;
return 1;
}
static void mime_insert_filter(request_rec *r)
{
}
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 apr_table_t */
register_hooks /* register hooks */
};