core.c revision e36ef0d081aa59867688bcbb3da65952ec16fae3
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/* ====================================================================
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * The Apache Software License, Version 1.1
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Redistribution and use in source and binary forms, with or without
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * modification, are permitted provided that the following conditions
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * 1. Redistributions of source code must retain the above copyright
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * notice, this list of conditions and the following disclaimer.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * 2. Redistributions in binary form must reproduce the above copyright
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * notice, this list of conditions and the following disclaimer in
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * the documentation and/or other materials provided with the
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * distribution.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * 3. The end-user documentation included with the redistribution,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * if any, must include the following acknowledgment:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * "This product includes software developed by the
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Apache Software Foundation (http://www.apache.org/)."
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Alternately, this acknowledgment may appear in the software itself,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * if and wherever such third-party acknowledgments normally appear.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * 4. The names "Apache" and "Apache Software Foundation" must
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * not be used to endorse or promote products derived from this
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * software without prior written permission. For written
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * permission, please contact apache@apache.org.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * 5. Products derived from this software may not be called "Apache",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * nor may "Apache" appear in their name, without prior written
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * permission of the Apache Software Foundation.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * SUCH DAMAGE.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * ====================================================================
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * This software consists of voluntary contributions made by many
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * individuals on behalf of the Apache Software Foundation. For more
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * information on the Apache Software Foundation, please see
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Portions of this software are based upon public domain software
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * originally written at the National Center for Supercomputing Applications,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * University of Illinois, Urbana-Champaign.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include "apr_thread_proc.h" /* for RLIMIT stuff */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include "http_protocol.h" /* For index_of_response(). Grump. */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include "http_main.h" /* For the default_handler below... */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/* LimitXMLRequestBody handling */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#define AP_DEFAULT_LIMIT_XML_BODY ((size_t)1000000)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. MaskeyAP_IMPLEMENT_HOOK_RUN_ALL(int, get_mgmt_items,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (apr_pool_t *p, const char *val, apr_hash_t *ht),
* This file could almost be mod_core.c, except for the stuff which affects
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
return (void *)conf;
* RESPONSE_CODES);
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;
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) {
#if APR_HAVE_IPV6
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 =
if (r->hostname) {
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;
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;
const char *server;
int port;
return err;
if (portstr) {
portstr++;
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;
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)
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
#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;
: r->filename);
return HTTP_NOT_FOUND;
return HTTP_METHOD_NOT_ALLOWED;
return HTTP_FORBIDDEN;
ap_set_etag(r);
return errstatus;
if (bld_content_md5) {
apr_bucket_copy(e, &e);
e = apr_bucket_eos_create();
typedef struct core_filter_ctx {
} core_ctx_t;
static int core_input_filter(ap_filter_t *f, apr_bucket_brigade *b, ap_input_mode_t mode, apr_off_t *readbytes)
apr_bucket *e;
const char *str;
if (!ctx)
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;
if (*readbytes) {
apr_bucket *e;
return APR_SUCCESS;
const char *pos;
return rv;
APR_BRIGADE_INSERT_TAIL(b, e);
return APR_SUCCESS;
APR_BRIGADE_INSERT_TAIL(b, e);
return APR_SUCCESS;
typedef struct CORE_OUTPUT_FILTER_CTX {
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) {
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;
&core_module);
if (filters) {
if (filters) {
if (r->main) {
return OK;