http_core.c revision 45c80f304f2d76e5d53ea77fda737e7037fae124
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd/* ====================================================================
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * The Apache Software License, Version 1.1
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * Copyright (c) 2000 The Apache Software Foundation. All rights
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * reserved.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * Redistribution and use in source and binary forms, with or without
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * modification, are permitted provided that the following conditions
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * are met:
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * 1. Redistributions of source code must retain the above copyright
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * notice, this list of conditions and the following disclaimer.
2e545ce2450a9953665f701bb05350f0d3f26275nd * 2. Redistributions in binary form must reproduce the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer in
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * the documentation and/or other materials provided with the
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * distribution.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * 3. The end-user documentation included with the redistribution,
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * if any, must include the following acknowledgment:
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * "This product includes software developed by the
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * Apache Software Foundation (http://www.apache.org/)."
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * Alternately, this acknowledgment may appear in the software itself,
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * if and wherever such third-party acknowledgments normally appear.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * 4. The names "Apache" and "Apache Software Foundation" must
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * not be used to endorse or promote products derived from this
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * software without prior written permission. For written
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * permission, please contact apache@apache.org.
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * 5. Products derived from this software may not be called "Apache",
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * nor may "Apache" appear in their name, without prior written
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * permission of the Apache Software Foundation.
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * SUCH DAMAGE.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * ====================================================================
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * This software consists of voluntary contributions made by many
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * individuals on behalf of the Apache Software Foundation. For more
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * information on the Apache Software Foundation, please see
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * Portions of this software are based upon public domain software
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * originally written at the National Center for Supercomputing Applications,
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * University of Illinois, Urbana-Champaign.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd#include "http_protocol.h" /* For index_of_response(). Grump. */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd#include "http_main.h" /* For the default_handler below... */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd/* Allow Apache to use ap_mmap */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd/* mmap support for static files based on ideas from John Heidemann's
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * patch against 1.0.5. See
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * <http://www.isi.edu/~johnh/SOFTWARE/APACHE/index.html>.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd/* Files have to be at least this big before they're mmap()d. This is to deal
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * with systems where the expense of doing an mmap() and an munmap() outweighs
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * the benefit for small files. It shouldn't be set lower than 1.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd #endif /* SUNOS4 */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd#endif /* MMAP_THRESHOLD */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd#endif /* USE_MMAP_FILES */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd/* Server core module... This module provides support for really basic
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * server operations, including options and commands which control the
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * operation of other modules. Consider this the bureaucracy module.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * The core module also defines handlers, etc., do handle just enough
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * to allow a server with the core module ONLY to actually serve documents
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * (though it slaps DefaultType on all of 'em); this was useful in testing,
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * but may not be worth preserving.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * This file could almost be mod_core.c, except for the stuff which affects
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * the http_conf_globals.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndstatic void *create_core_dir_config(ap_pool_t *a, char *dir)
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd conf = (core_dir_config *)ap_pcalloc(a, sizeof(core_dir_config));
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd conf->d_is_fnmatch = conf->d ? (ap_is_fnmatch(conf->d) != 0) : 0;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd conf->d_components = conf->d ? ap_count_dirs(conf->d) : 0;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd conf->do_rfc1413 = DEFAULT_RFC1413 | 2; /* set bit 1 to indicate default */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd conf->script_interpreter_source = INTERPRETER_SOURCE_UNSET;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd conf->add_default_charset_name = DEFAULT_ADD_DEFAULT_CHARSET_NAME;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd return (void *)conf;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndstatic void *merge_core_dir_configs(ap_pool_t *a, void *basev, void *newv)
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd conf = (core_dir_config *)ap_palloc(a, sizeof(core_dir_config));
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd memcpy((char *)conf, (const char *)base, sizeof(core_dir_config));
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd memcpy(conf->response_code_strings, base->response_code_strings,
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd /* there was no explicit setting of new->opts, so we merge
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * preserve the invariant (opts_add & opts_remove) == 0
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar conf->opts_add = (conf->opts_add & ~new->opts_remove) | new->opts_add;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar conf->opts_remove = (conf->opts_remove & ~new->opts_add)
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar conf->opts = (conf->opts & ~conf->opts_remove) | conf->opts_add;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar if ((base->opts & OPT_INCNOEXEC) && (new->opts & OPT_INCLUDES)) {
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar conf->opts = (conf->opts & ~OPT_INCNOEXEC) | OPT_INCLUDES;
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar /* otherwise we just copy, because an explicit opts setting
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * overrides all earlier +/- modifiers
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar sizeof(*conf->response_code_strings) * RESPONSE_CODES);
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar memcpy(conf->response_code_strings, new->response_code_strings,
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar sizeof(*conf->response_code_strings) * RESPONSE_CODES);
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar for (i = 0; i < RESPONSE_CODES; ++i) {
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar if (new->use_canonical_name != USE_CANONICAL_NAME_UNSET) {
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar if (new->script_interpreter_source != INTERPRETER_SOURCE_UNSET) {
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar conf->script_interpreter_source = new->script_interpreter_source;
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung if (new->add_default_charset != ADD_DEFAULT_CHARSET_UNSET) {
727872d18412fc021f03969b8641810d8896820bhumbedooh conf->add_default_charset = new->add_default_charset;
0d0ba3a410038e179b695446bb149cce6264e0abnd conf->add_default_charset_name = new->add_default_charset_name;
0d0ba3a410038e179b695446bb149cce6264e0abnd return (void*)conf;
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedoohstatic void *create_core_server_config(ap_pool_t *a, server_rec *s)
0d0ba3a410038e179b695446bb149cce6264e0abnd conf = (core_server_config *)ap_pcalloc(a, sizeof(core_server_config));
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen conf->access_name = is_virtual ? NULL : DEFAULT_ACCESS_FNAME;
0d0ba3a410038e179b695446bb149cce6264e0abnd conf->ap_document_root = is_virtual ? NULL : DOCUMENT_LOCATION;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd return (void *)conf;
return conf;
&core_module);
&core_module);
#ifdef HAVE_DRIVE_LETTERS
struct reorder_sort_rec {
void *elt;
int orig_index;
int nelts;
void **elts;
for (i = 0; i < nelts; ++i) {
for (i = 0; i < nelts; ++i) {
&core_module);
&core_module);
&core_module);
&core_module);
&core_module);
&core_module);
&core_module);
&core_module);
return NULL;
if (hptr) {
char **haddr;
int type)
int hostname_lookups;
if (dir_config) {
return NULL;
return NULL;
&core_module);
return NULL;
core_dir_config *d;
&core_module);
AF_INET);
unsigned port;
core_dir_config *d =
: port;
return port;
request_rec *r)
core_dir_config *d =
return d->limit_req_body;
#ifdef WIN32
int size;
int result;
char *keyName;
char *buffer;
if (!ext)
return NULL;
&hkeyOpen);
return NULL;
size = 0;
return NULL;
&hkeyOpen);
return NULL;
size = 0;
return NULL;
return buffer;
char** interpreter )
core_dir_config *d;
&core_module);
if (!exename) {
if (!exename) {
exename++;
return eFileTypeEXE32;
if (*interpreter)
return eFileTypeSCRIPT;
return eFileTypeUNKNOWN;
return eFileTypeUNKNOWN;
return fileType;
* Commands... this module handles almost all of the NCSA httpd.conf
* commands, but most of the old srm.conf is in the the modules.
const char *what)
return dirp;
return NULL;
unsigned forbidden)
return NULL;
return err;
return NULL;
#ifdef GPROF
return err;
return NULL;
return err;
return NULL;
return err;
arg);
return NULL;
int idx;
return err;
* http_protocol.c relies on to distinguish between
return NULL;
return err;
return NULL;
char action;
action = *(w++);
else if (first) {
first = 0;
return NULL;
return NULL;
require_line *r;
if (!c->ap_requires) {
return NULL;
const char *arg)
int limited = 0;
const char *errmsg;
return err;
while (limited_methods[0]) {
return errmsg;
#ifdef WIN32
#define USE_ICASE 0
const char *errmsg;
return err;
&core_module);
return errmsg;
conf->r = r;
return NULL;
const char *errmsg;
return err;
&core_module);
return errmsg;
conf->r = r;
return NULL;
const char *arg)
const char *errmsg;
return err;
if (!old_path) {
&core_module);
return errmsg;
conf->r = r;
return NULL;
if (not) {
arg++;
return NULL;
char **defines;
char *endp;
int not = 0;
arg++;
return NULL;
/* httpd.conf commands... beginning with the <VirtualHost> business */
const char *errmsg;
return err;
if (errmsg) {
return errmsg;
s->lookup_defaults);
return errmsg;
const char *arg)
while (*arg) {
return NULL;
return err;
return NULL;
return err;
return NULL;
char *arg)
return err;
return NULL;
int port;
return err;
return NULL;
char *arg)
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
char *arg)
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
char *arg)
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
char *arg)
return err;
return NULL;
return NULL;
char *str;
return err;
return NULL;
&core_module);
return NULL;
return err;
return err;
return NULL;
int lim;
return err;
if (lim < 0) {
return NULL;
char *arg)
int lim;
return err;
if (lim < 0) {
NULL);
return NULL;
int lim;
return err;
if (lim < 0) {
NULL);
return NULL;
char *arg)
return err;
* Instead we have an idiotic define in httpd.h that prevents
return NULL;
#ifdef WIN32
char *arg)
return NULL;
#ifdef GPROF
TAKE1, "The name of the default charset to add to any Content-Type without one or 'Off' to disable" },
NULL },
#ifdef _OSD_POSIX
#ifdef WIN32
{ NULL }
if (r->proxyreq) {
return HTTP_FORBIDDEN;
return BAD_REQUEST;
NULL);
NULL);
return OK;
core_dir_config *d =
#ifdef USE_MMAP_FILES
#ifdef CHARSET_EBCDIC
return errstatus;
return NOT_IMPLEMENTED;
return ap_send_http_options(r);
return METHOD_NOT_ALLOWED;
: r->filename);
return HTTP_NOT_FOUND;
return METHOD_NOT_ALLOWED;
return FORBIDDEN;
ap_set_etag(r);
return errstatus;
#ifdef CHARSET_EBCDIC
#ifdef USE_MMAP_FILES
#ifdef CHARSET_EBCDIC
xlate_to_net));
if (!r->header_only) {
if (!rangestatus) {
long length;
return HTTP_INTERNAL_SERVER_ERROR;
#ifdef USE_MMAP_FILES
char *addr;
#ifdef CHARSET_EBCDIC
if (xlate_to_net) {
if (!r->header_only) {
if (!rangestatus) {
long length;
return OK;
{ return DEFAULT_HTTP_PORT; }
static void register_hooks(void)