core.c revision 91a9b0a5d1aa9614c3d3361a66ebf570b5d0319c
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe/* ====================================================================
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * The Apache Software License, Version 1.1
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * Redistribution and use in source and binary forms, with or without
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * modification, are permitted provided that the following conditions
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * 1. Redistributions of source code must retain the above copyright
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * notice, this list of conditions and the following disclaimer.
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * 2. Redistributions in binary form must reproduce the above copyright
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * notice, this list of conditions and the following disclaimer in
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * the documentation and/or other materials provided with the
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * distribution.
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * 3. The end-user documentation included with the redistribution,
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe * if any, must include the following acknowledgment:
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe * "This product includes software developed by the
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe * Apache Software Foundation (http://www.apache.org/)."
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * Alternately, this acknowledgment may appear in the software itself,
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * if and wherever such third-party acknowledgments normally appear.
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * 4. The names "Apache" and "Apache Software Foundation" must
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * not be used to endorse or promote products derived from this
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * software without prior written permission. For written
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * permission, please contact apache@apache.org.
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * 5. Products derived from this software may not be called "Apache",
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * nor may "Apache" appear in their name, without prior written
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * permission of the Apache Software Foundation.
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * SUCH DAMAGE.
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * ====================================================================
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * This software consists of voluntary contributions made by many
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * individuals on behalf of the Apache Software Foundation. For more
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * information on the Apache Software Foundation, please see
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * Portions of this software are based upon public domain software
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * originally written at the National Center for Supercomputing Applications,
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe * University of Illinois, Urbana-Champaign.
#include "apr_hooks.h"
#define APR_WANT_IOVEC
#define APR_WANT_STRFUNC
#define APR_WANT_MEMFUNC
#include "apr_want.h"
#define CORE_PRIVATE
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_request.h"
#include "http_vhost.h"
#include "http_log.h"
#include "rfc1413.h"
#include "util_md5.h"
#include "http_connection.h"
#include "apr_buckets.h"
#include "util_filter.h"
#include "util_ebcdic.h"
#include "mpm.h"
#include "mpm_common.h"
#include "scoreboard.h"
#include "mod_core.h"
#include "mod_proxy.h"
#include "ap_listen.h"
* This file could almost be mod_core.c, except for the stuff which affects
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
return (void *)conf;
for (i = 0; i < RESPONSE_CODES; ++i) {
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
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) {
return NULL;
return NULL;
&core_module);
return NULL;
core_dir_config *d;
&core_module);
core_dir_config *d =
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;
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;
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;
return NULL;
require_line *r;
if (!c->ap_requires) {
return NULL;
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)
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;
*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
{ 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;
return DECLINED;
&core_module);
return errstatus;
return HTTP_NOT_IMPLEMENTED;
return ap_send_http_options(r);
return HTTP_METHOD_NOT_ALLOWED;
return HTTP_NOT_FOUND;
return HTTP_NOT_FOUND;
return HTTP_FORBIDDEN;
ap_set_etag(r);
return errstatus;
if (bld_content_md5) {
apr_bucket_copy(e, &e);
e = apr_bucket_eos_create();
if (!f->ctx) {
if (*first_line) {
(int)(keptalive
*first_line = 0;
if (keptalive) {
apr_bucket *e;
const char *str;
return APR_SUCCESS;
if (!ctx)
return APR_EOF;
apr_bucket *e;
return APR_EOF;
return rv;
c = str;
if (*c == APR_ASCII_LF)
return APR_SUCCESS;
apr_bucket *e;
e = apr_bucket_eos_create();
APR_BRIGADE_INSERT_TAIL(b, e);
return APR_SUCCESS;
apr_bucket *e;
return APR_SUCCESS;
return rv;
return rv;
return APR_SUCCESS;
return rv;
conn_rec *c = f->c;
if (ctx->b) {
b = ctx->b;
apr_bucket *e;
APR_BRIGADE_FOREACH(e, b) {
last_e = 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;
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 rv;
return APR_SUCCESS;
if (fd) {
#if APR_HAS_SENDFILE
if (nvec) {
if (nvec_trailers) {
#if APR_HAS_SENDFILE
if (!c->keepalive) {
if (more)
return rv;
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) {
return OK;
!= APR_SUCCESS) {
return NULL;
!= APR_SUCCESS) {
return NULL;
return net->c;