protocol.c revision 7727f4c9a1ac856edd057f21c4b8dbf63c6c9eef
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova/* ====================================================================
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * The Apache Software License, Version 1.1
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * Redistribution and use in source and binary forms, with or without
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * modification, are permitted provided that the following conditions
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * 1. Redistributions of source code must retain the above copyright
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * notice, this list of conditions and the following disclaimer.
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * 2. Redistributions in binary form must reproduce the above copyright
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * notice, this list of conditions and the following disclaimer in
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * the documentation and/or other materials provided with the
9f85afecbd79b3df5a0bb17bd28cd0b288dc3213Kristina Sojakova * distribution.
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * 3. The end-user documentation included with the redistribution,
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * if any, must include the following acknowledgment:
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * "This product includes software developed by the
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * Apache Software Foundation (http://www.apache.org/)."
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * Alternately, this acknowledgment may appear in the software itself,
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * if and wherever such third-party acknowledgments normally appear.
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * 4. The names "Apache" and "Apache Software Foundation" must
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * not be used to endorse or promote products derived from this
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * software without prior written permission. For written
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * permission, please contact apache@apache.org.
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * 5. Products derived from this software may not be called "Apache",
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * nor may "Apache" appear in their name, without prior written
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * permission of the Apache Software Foundation.
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * SUCH DAMAGE.
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * ====================================================================
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * This software consists of voluntary contributions made by many
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * individuals on behalf of the Apache Software Foundation. For more
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * information on the Apache Software Foundation, please see
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * Portions of this software are based upon public domain software
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * originally written at the National Center for Supercomputing Applications,
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * University of Illinois, Urbana-Champaign.
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * http_protocol.c --- routines which directly communicate with the client.
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * Code originally by Rob McCool; much redone by Robert S. Thau
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova * and the Apache Software Foundation.
#include "apr_strings.h"
#include "apr_buckets.h"
#include "apr_lib.h"
#include "apr_signal.h"
#define APR_WANT_STRFUNC
#define APR_WANT_MEMFUNC
#include "apr_want.h"
#define CORE_PRIVATE
#include "util_filter.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_main.h"
#include "http_request.h"
#include "http_vhost.h"
#include "util_charset.h"
#include "util_ebcdic.h"
#include <stdarg.h>
#include <unistd.h>
static const char *needcset[] = {
NULL };
const char **pcset;
&core_module);
if (!type) {
return type;
return type;
int fold)
apr_bucket *e;
return rv;
if (APR_BRIGADE_EMPTY(b)) {
return APR_EGENERAL;
APR_BRIGADE_FOREACH(e, b) {
const char *str;
if (APR_BUCKET_IS_EOS(e)) {
return rv;
return APR_ENOSPC;
if (do_alloc) {
char *new_buffer;
*s = new_buffer;
if (bytes_handled == 0) {
*read = 0;
return APR_SUCCESS;
if (bytes_handled < n) {
char *tmp;
if (do_alloc) {
return rv;
char *new_buffer;
*s = new_buffer;
return APR_ENOSPC;
--pos;
--pos;
const char *str;
return rv;
e = APR_BRIGADE_FIRST(b);
if (APR_BUCKET_IS_EOS(e)) {
return APR_SUCCESS;
return rv;
if (bytes_handled < n) {
char *tmp;
if (do_alloc) {
return rv;
char *new_buffer;
*s = new_buffer;
return APR_SUCCESS;
return APR_ENOSPC;
return APR_SUCCESS;
char *tmp_s = s;
return (int)len;
* This will prevent "http://www.wherever.com/..\..\/" from
const char *ll;
const char *uri;
const char *pro;
&len, r, 0);
} while (len <= 0);
if (ll[0]) {
r->assbackwards = 0;
char* field;
char *value;
int fields_read = 0;
if (len == 0) {
++value;
request_rec *r;
apr_pool_t *p;
const char *expect;
int access_status;
r->pool = p;
r->read_length = 0;
if (!read_request_line(r)) {
ap_send_error_response(r, 0);
return NULL;
if (!r->assbackwards) {
get_mime_headers(r);
ap_send_error_response(r, 0);
if (r->header_only) {
r->uri);
r->header_only = 0;
ap_send_error_response(r, 0);
ap_send_error_response(r, 0);
ap_send_error_response(r, 0);
(void) ap_discard_request_body(r);
return NULL;
apr_bucket *b;
b = apr_bucket_eos_create();
while (r->next) {
r = r->next;
if (!r->eos_sent) {
if (type) {
NULL));
return DECLINED;
if (!ap_auth_name(r)) {
return HTTP_INTERNAL_SERVER_ERROR;
if (!auth_line) {
return HTTP_UNAUTHORIZED;
return HTTP_UNAUTHORIZED;
auth_line++;
*pw = t;
return OK;
struct content_length_ctx {
int compute_len;
request_rec *r = f->r;
apr_bucket *e;
more = b;
while (more) {
b = more;
flush = 0;
APR_BRIGADE_FOREACH(e, b) {
const char *ignored;
len = 0;
if (APR_BUCKET_IS_EOS(e)) {
else if (APR_BUCKET_IS_FLUSH(e)) {
if (partial_send_okay) {
split = b;
if (partial_send_okay) {
split = b;
if (partial_send_okay) {
split = b;
return rv;
if (split) {
if (flush) {
return rv;
if (!eos) {
apr_bucket *b;
return rv;
#if APR_HAS_MMAP
apr_bucket *b;
ap_filter_t *f;
if (len == 0)
return APR_SUCCESS;
if (f == NULL) {
f = r->output_filters;
if (f != r->output_filters) {
char c2 = (char)c;
return len;
return nbyte;
struct ap_vrprintf_data {
request_rec *r;
char *buff;
* vformatter needs to write into buff and buff.curpos > buff.endpos */
return APR_SUCCESS;
vd.r = r;
written += n;
return written;
if (s == NULL)
return written;
apr_bucket *b;
b = apr_bucket_flush_create();
if (!r->assbackwards) {
(const request_rec *r),(r),0)