protocol.c revision 3fde4c273ea649d1320ec9c51e7d096cd9340a94
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere/* ====================================================================
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * The Apache Software License, Version 1.1
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * reserved.
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * Redistribution and use in source and binary forms, with or without
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * modification, are permitted provided that the following conditions
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * 1. Redistributions of source code must retain the above copyright
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * notice, this list of conditions and the following disclaimer.
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * 2. Redistributions in binary form must reproduce the above copyright
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * notice, this list of conditions and the following disclaimer in
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * the documentation and/or other materials provided with the
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * distribution.
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * 3. The end-user documentation included with the redistribution,
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * if any, must include the following acknowledgment:
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * "This product includes software developed by the
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * Apache Software Foundation (http://www.apache.org/)."
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * Alternately, this acknowledgment may appear in the software itself,
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * if and wherever such third-party acknowledgments normally appear.
fac8c35bfb158112226ab43ddf84d59daca5dc30nd * 4. The names "Apache" and "Apache Software Foundation" must
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen * not be used to endorse or promote products derived from this
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen * software without prior written permission. For written
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * permission, please contact apache@apache.org.
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * 5. Products derived from this software may not be called "Apache",
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * nor may "Apache" appear in their name, without prior written
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * permission of the Apache Software Foundation.
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
fabd4bc0c499704e644a74f78cc3871436824ea0jim * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * SUCH DAMAGE.
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * ====================================================================
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * This software consists of voluntary contributions made by many
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * individuals on behalf of the Apache Software Foundation. For more
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor * information on the Apache Software Foundation, please see
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * Portions of this software are based upon public domain software
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * originally written at the National Center for Supercomputing Applications,
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * University of Illinois, Urbana-Champaign.
bed3c2e56e8f3328e780200466b9d009093db468sf * http_protocol.c --- routines which directly communicate with the client.
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * Code originally by Rob McCool; much redone by Robert S. Thau
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * and the Apache Software Foundation.
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor#include "http_log.h" /* For errors detected in basic auth common
fabd4bc0c499704e644a74f78cc3871436824ea0jim * support code... */
999942e8e84bcae9b439ab30a040b1b997b343c9gryzorAP_DECLARE_DATA ap_filter_rec_t *ap_old_write_func = NULL;
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor * Builds the content-type that should be sent to the client from the
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * content-type specified. The following rules are followed:
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor * - if type is NULL, type is set to ap_default_type(r)
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor * - if charset adding is disabled, stop processing and return type.
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor * - then, if there are no parameters on type, add the default charset
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor * - return type
999942e8e84bcae9b439ab30a040b1b997b343c9gryzorAP_DECLARE(const char *)ap_make_content_type(request_rec *r, const char *type)
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor static const char *needcset[] = {
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere const char **pcset;
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere (core_dir_config *)ap_get_module_config(r->per_dir_config,
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor if (conf->add_default_charset != ADD_DEFAULT_CHARSET_ON) {
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor /* already has parameter, do nothing */
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor /* XXX we don't check the validity */
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor /* see if it makes sense to add the charset. At present,
999942e8e84bcae9b439ab30a040b1b997b343c9gryzor * we only add it if the Content-type is one of needcset[]
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclereAP_DECLARE(void) ap_set_content_length(request_rec *r, apr_off_t clength)
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen * Return the latest rational time from a request/mtime (modification time)
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen * pair. We return the mtime unless it's in the future, in which case we
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * return the current time. We use the request time as a reference in order
9c1260efa52c82c2a58e5b5f20cd6902563d95f5rbowen * to limit the number of calls to time(). We don't check for futurosity
e3659090e9bb9934465dbb6c6212ba4c512190b0jfclere * unless the mtime is at least as new as the reference.
char *pos;
char *last_char;
const char *temp;
int retval;
int looking_ahead = 0;
apr_bucket *e;
if (APR_BRIGADE_EMPTY(b)) {
APR_BRIGADE_EMPTY(b)) {
e = APR_BRIGADE_FIRST(b);
if (APR_BUCKET_IS_EOS(e)) {
if (e->length == 0) {
if (total) {
if (do_alloc) {
char *new_buffer;
*s = new_buffer;
/* no LF yet...character mode client (telnet)...keep going
return total;
char *tmp_s = s;
* This will prevent "http://www.wherever.com/..\..\/" from
const char *ll;
const char *uri;
const char *pro;
int len;
if (ll[0]) {
r->assbackwards = 0;
char* field;
char *value;
int len;
int fields_read = 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)