core.c revision 24efed0910118b762a4eb84830875d4714b8d315
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova/* ====================================================================
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * The Apache Software License, Version 1.1
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * Redistribution and use in source and binary forms, with or without
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * modification, are permitted provided that the following conditions
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * 1. Redistributions of source code must retain the above copyright
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * notice, this list of conditions and the following disclaimer.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * 2. Redistributions in binary form must reproduce the above copyright
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * notice, this list of conditions and the following disclaimer in
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * the documentation and/or other materials provided with the
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * distribution.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * 3. The end-user documentation included with the redistribution,
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * if any, must include the following acknowledgment:
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * "This product includes software developed by the
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * Apache Software Foundation (http://www.apache.org/)."
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * Alternately, this acknowledgment may appear in the software itself,
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * if and wherever such third-party acknowledgments normally appear.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * 4. The names "Apache" and "Apache Software Foundation" must
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * not be used to endorse or promote products derived from this
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * software without prior written permission. For written
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * permission, please contact apache@apache.org.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * 5. Products derived from this software may not be called "Apache",
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * nor may "Apache" appear in their name, without prior written
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * permission of the Apache Software Foundation.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * SUCH DAMAGE.
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * ====================================================================
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * This software consists of voluntary contributions made by many
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * individuals on behalf of the Apache Software Foundation. For more
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * information on the Apache Software Foundation, please see
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * Portions of this software are based upon public domain software
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * originally written at the National Center for Supercomputing Applications,
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * University of Illinois, Urbana-Champaign.
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova#include "apr_thread_proc.h" /* for RLIMIT stuff */
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova#include "http_protocol.h" /* For index_of_response(). Grump. */
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova#include "http_main.h" /* For the default_handler below... */
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova/* LimitXMLRequestBody handling */
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova#define AP_DEFAULT_LIMIT_XML_BODY ((size_t)1000000)
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina SojakovaAP_IMPLEMENT_HOOK_RUN_ALL(int, get_mgmt_items,
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova (apr_pool_t *p, const char *val, apr_hash_t *ht),
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova/* Server core module... This module provides support for really basic
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * server operations, including options and commands which control the
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * operation of other modules. Consider this the bureaucracy module.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * The core module also defines handlers, etc., do handle just enough
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * to allow a server with the core module ONLY to actually serve documents
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * (though it slaps DefaultType on all of 'em); this was useful in testing,
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * but may not be worth preserving.
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * This file could almost be mod_core.c, except for the stuff which affects
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * the http_conf_globals.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova/* Handles for core filters */
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina SojakovaAP_DECLARE_DATA ap_filter_rec_t *ap_subreq_core_filter_handle;
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina SojakovaAP_DECLARE_DATA ap_filter_rec_t *ap_core_output_filter_handle;
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina SojakovaAP_DECLARE_DATA ap_filter_rec_t *ap_content_length_filter_handle;
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina SojakovaAP_DECLARE_DATA ap_filter_rec_t *ap_net_time_filter_handle;
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina SojakovaAP_DECLARE_DATA ap_filter_rec_t *ap_core_input_filter_handle;
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakovastatic void *create_core_dir_config(apr_pool_t *a, char *dir)
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova conf = (core_dir_config *)apr_pcalloc(a, sizeof(core_dir_config));
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova /* conf->r and conf->d[_*] are initialized by dirsection() or left NULL */
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova conf->opts = dir ? OPT_UNSET : OPT_UNSET|OPT_ALL;
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova conf->opts_add = conf->opts_remove = OPT_NONE;
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova conf->override = dir ? OR_UNSET : OR_UNSET|OR_ALL;
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
return (void *)conf;
const void *key,
const void *overlay_val,
const void *base_val,
const void *data)
while (overlay_info) {
while (base_info) {
ap_filter_rec_t *f;
int found = 0;
f = cur;
f = f->next;
if (!found) {
cur = f;
return cur;
for (i = 0; i < RESPONSE_CODES; ++i) {
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
NULL);
return (void*)conf;
#ifdef GPROF
return (void *)conf;
return conf;
&core_module);
&core_module);
struct reorder_sort_rec {
int orig_index;
int nelts;
if (!nelts) {
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;
while (sa) {
int hostname_lookups;
*str_is_ip = 0;
if (dir_config) {
== APR_SUCCESS) {
return NULL;
return NULL;
&core_module);
return NULL;
core_dir_config *d;
&core_module);
core_dir_config *d =
ap_default_port(r);
ap_default_port(r);
return port;
request_rec *r)
core_dir_config *d =
return d->limit_req_body;
* 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 NULL;
const char *arg)
return err;
return NULL;
#ifdef GPROF
return err;
return NULL;
return err;
return NULL;
const char *arg)
return err;
arg);
return NULL;
const char *string)
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;
const char *args_p)
char action;
char *token;
const char *args;
int valid;
int first;
int explicit;
explicit = 0;
token++;
if (first) {
first = 0;
valid = 0;
valid = 0;
if (! valid) {
NULL);
if (explicit) {
return NULL;
const char *arg)
return err;
return NULL;
return NULL;
require_line *r;
if (!c->ap_requires) {
return NULL;
void *dummy,
const char *arg)
const char *errmsg;
return err;
while (limited_methods[0]) {
int methnum;
return errmsg;
#ifdef WIN32
#define USE_ICASE 0
const char *errmsg;
return err;
if (!arg) {
char *newpath;
return errmsg;
conf->r = r;
return NULL;
const char *errmsg;
return err;
return errmsg;
conf->r = r;
return NULL;
const char *errmsg;
return err;
if (!old_path) {
char *newpath;
return errmsg;
conf->r = r;
return NULL;
if (not) {
arg++;
const char *retval;
return retval;
char **defines;
const char *endp;
int not = 0;
arg++;
const char *retval;
return retval;
/* httpd.conf commands... beginning with the <VirtualHost> business */
const char *arg)
const char *errmsg;
return err;
if (errmsg) {
return errmsg;
s->lookup_defaults);
return errmsg;
const char *arg)
while (*arg) {
return NULL;
const char *arg)
return err;
return NULL;
const char *portstr;
int port;
return err;
if (portstr) {
portstr++;
port = 0;
return NULL;
const char *arg)
return err;
return NULL;
const char *arg)
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
const char *arg)
return err;
return NULL;
const char *arg)
return err;
return NULL;
return err;
return NULL;
return NULL;
const char *arg)
return err;
return NULL;
const char *name)
if (!conffile) {
return NULL;
char *str;
return err;
return NULL;
&core_module);
const char *word1)
return NULL;
return err;
static int version_locked = 0;
enum server_token_type {
version_locked = 0;
return APR_SUCCESS;
if (! version_locked) {
const char *arg)
return err;
return NULL;
const char *arg)
int lim;
return err;
if (lim < 0) {
return NULL;
const char *arg)
int lim;
return err;
if (lim < 0) {
NULL);
return NULL;
const char *arg)
int lim;
return err;
if (lim < 0) {
NULL);
return NULL;
const char *arg)
char *errp;
return err;
* Instead we have an idiotic define in httpd.h that prevents
return NULL;
const char *arg)
return err;
return NULL;
return AP_DEFAULT_LIMIT_XML_BODY;
#if !defined (RLIMIT_CPU) || !(defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)) || !defined (RLIMIT_NPROC)
return NULL;
#ifdef RLIMIT_CPU
return NULL;
#if defined(RLIMIT_AS)
return NULL;
#ifdef RLIMIT_NPROC
return NULL;
if (old) {
return NULL;
&core_module);
while (ct_filter) {
*nbytes = 0;
bytes_written += n;
return rv;
*nbytes += n;
if (n < cnt) {
return APR_SUCCESS;
#if APR_HAS_SENDFILE
#ifdef AP_DEBUG
flags);
tmplen = 0;
file_bytes_left = 0;
file_offset = 0;
tmplen = 0;
apr_int32_t i;
*nbytes = 0;
sendlen = 0;
return rv;
#ifdef GPROF
"Set to on or off for PATH_INFO to be accepted by handlers, or default for the per-handler preference"),
#ifdef _OSD_POSIX
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
* #defined them in mpm.h.
#ifdef AP_MPM_WANT_SET_PIDFILE
#ifdef AP_MPM_WANT_SET_SCOREBOARD
#ifdef AP_MPM_WANT_SET_LOCKFILE
#ifdef AP_MPM_WANT_SET_MAX_REQUESTS
#ifdef AP_MPM_WANT_SET_COREDUMPDIR
#ifdef AP_MPM_WANT_SET_MAX_MEM_FREE
{ NULL }
if (r->proxyreq) {
return HTTP_FORBIDDEN;
return HTTP_BAD_REQUEST;
!= APR_SUCCESS) {
return HTTP_FORBIDDEN;
!= APR_SUCCESS) {
return HTTP_FORBIDDEN;
return OK;
int access_status;
return access_status;
return access_status;
return OK;
&core_module);
return OK;
apr_bucket *e;
core_dir_config *d;
int errstatus;
int bld_content_md5;
&core_module);
return errstatus;
return HTTP_NOT_FOUND;
return HTTP_NOT_FOUND;
return HTTP_NOT_FOUND;
return HTTP_FORBIDDEN;
ap_set_etag(r);
return errstatus;
if (bld_content_md5) {
c->bucket_alloc);
#if APR_HAS_MMAP
(void)apr_bucket_file_enable_mmap(e, 0);
return HTTP_NOT_IMPLEMENTED;
return ap_send_http_options(r);
return HTTP_METHOD_NOT_ALLOWED;
if (!f->ctx) {
if (*first_line) {
(int)(keptalive
*first_line = 0;
if (keptalive) {
#define BRIGADE_NORMALIZE(b) \
apr_bucket *d; \
d = APR_BUCKET_NEXT(e); \
apr_bucket_delete(e); \
e = APR_BUCKET_NEXT(e); \
apr_bucket *e;
const char *str;
return APR_SUCCESS;
if (!ctx)
return APR_EOF;
return APR_EOF;
apr_bucket *e;
return APR_EOF;
return rv;
c = str;
if (*c == APR_ASCII_LF)
return APR_SUCCESS;
apr_bucket *e;
APR_BRIGADE_INSERT_TAIL(b, e);
return APR_SUCCESS;
apr_bucket *e;
return APR_SUCCESS;
return rv;
APR_BRIGADE_INSERT_TAIL(b, e);
return APR_SUCCESS;
return rv;
return rv;
return APR_SUCCESS;
return rv;
conn_rec *c = f->c;
if (ctx->b) {
b = ctx->b;
while (b && !APR_BRIGADE_EMPTY(b)) {
apr_bucket *e;
APR_BRIGADE_FOREACH(e, b) {
last_e = e;
if (APR_BUCKET_IS_EOS(e)) {
if (APR_BUCKET_IS_FLUSH(e)) {
else if (APR_BUCKET_IS_FILE(e)
if (fd) {
const char *str;
apr_size_t n;
if (!fd) {
if (last_merged_bucket) {
temp_brig = b;
b = bb;
f->c->bucket_alloc);
while (temp != e) {
apr_bucket *d;
d = temp;
nvec = 0;
nbytes = 0;
nvec++;
nvec++;
e = temp;
last_e = e;
nvec++;
nbytes += n;
const char *str;
apr_size_t n;
return HTTP_INTERNAL_SERVER_ERROR;
return APR_SUCCESS;
if (fd) {
#if APR_HAS_SENDFILE
if (nvec) {
if (nvec_trailers) {
#if APR_HAS_SENDFILE
if (more)
return APR_SUCCESS;
b = more;
return APR_SUCCESS;
return OK;
return OK;
&core_module);
if (filters) {
if (filters) {
return APR_SUCCESS;
return num_request_notes++;
return NULL;
if (!req_cfg) {
return NULL;
sizeof(void *) * num_request_notes);
if (r->main) {
if (!r->prev) {
return OK;
!= APR_SUCCESS) {
return NULL;
!= APR_SUCCESS) {
return NULL;
net->c = c;
return DONE;