protocol.c revision 82e6711dc508d2822d9397f07136ba4ddd8764e1
7a8401ce858002b67e8f4198fde45a1562696ccbChristian Maeder/* Licensed to the Apache Software Foundation (ASF) under one or more
2b4130336e941b7d01c78a6da55449a4c6eca609Till Mossakowski * contributor license agreements. See the NOTICE file distributed with
53d399c20374a99bd95db1f9b5b93980cbf6a984Christian Maeder * this work for additional information regarding copyright ownership.
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian Maeder * The ASF licenses this file to You under the Apache License, Version 2.0
2b4130336e941b7d01c78a6da55449a4c6eca609Till Mossakowski * (the "License"); you may not use this file except in compliance with
b4fbc96e05117839ca409f5f20f97b3ac872d1edTill Mossakowski * the License. You may obtain a copy of the License at
2b4130336e941b7d01c78a6da55449a4c6eca609Till Mossakowski * http://www.apache.org/licenses/LICENSE-2.0
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder * Unless required by applicable law or agreed to in writing, software
59d823de481014f68b8b024474bffac150b56e1eWiebke Herding * distributed under the License is distributed on an "AS IS" BASIS,
cc6df32dd55910aac7de12b30cc5049d96b8f770Wiebke Herding * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
e4e1509ff358e739fddf1483ad39467e0e1becc2Christian Maeder * See the License for the specific language governing permissions and
53d399c20374a99bd95db1f9b5b93980cbf6a984Christian Maeder * limitations under the License.
e4e1509ff358e739fddf1483ad39467e0e1becc2Christian Maeder * http_protocol.c --- routines which directly communicate with the client.
53d399c20374a99bd95db1f9b5b93980cbf6a984Christian Maeder * Code originally by Rob McCool; much redone by Robert S. Thau
e4e1509ff358e739fddf1483ad39467e0e1becc2Christian Maeder * and the Apache Software Foundation.
856bdbffc895793cc5739dbb862323944cb76fdbChristian Maeder#include "http_log.h" /* For errors detected in basic auth common
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder * support code... */
53d399c20374a99bd95db1f9b5b93980cbf6a984Christian MaederAP_DECLARE_DATA ap_filter_rec_t *ap_old_write_func = NULL;
414ffa281d82f05a2d742c702f8e06b0cb05b229Christian Maeder/* Patterns to match in ap_make_content_type() */
5bc645bae86e7cc7714ab73934b77bb98ecbd078Christian Maederstatic const char *needcset[] = {
310532f8a7a1a1f1b6c25c67b7c340abc0889335Christian Maederstatic const apr_strmatch_pattern **needcset_patterns;
53d399c20374a99bd95db1f9b5b93980cbf6a984Christian Maederstatic const apr_strmatch_pattern *charset_pattern;
310532f8a7a1a1f1b6c25c67b7c340abc0889335Christian MaederAP_DECLARE(void) ap_setup_make_content_type(apr_pool_t *pool)
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski for (i = 0; needcset[i]; i++) {
310532f8a7a1a1f1b6c25c67b7c340abc0889335Christian Maeder needcset_patterns = (const apr_strmatch_pattern **)
e953bea49e7f0e1a43bccf2a66c5e2a2b50848e0Christian Maeder apr_palloc(pool, (i + 1) * sizeof(apr_strmatch_pattern *));
310532f8a7a1a1f1b6c25c67b7c340abc0889335Christian Maeder for (i = 0; needcset[i]; i++) {
e953bea49e7f0e1a43bccf2a66c5e2a2b50848e0Christian Maeder needcset_patterns[i] = apr_strmatch_precompile(pool, needcset[i], 0);
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski charset_pattern = apr_strmatch_precompile(pool, "charset=", 0);
53d399c20374a99bd95db1f9b5b93980cbf6a984Christian Maeder * Builds the content-type that should be sent to the client from the
&core_module);
return NULL;
return type;
return type;
return type;
apr_bucket *e;
if (last_char)
APR_BLOCK_READ, 0);
return rv;
return APR_EGENERAL;
e = APR_BUCKET_NEXT(e))
const char *str;
if (APR_BUCKET_IS_EOS(e)) {
return rv;
if (len == 0) {
if (bytes_handled > 0) {
return APR_ENOSPC;
if (do_alloc) {
char *new_buffer;
*s = new_buffer;
last_char--;
const char *str;
return rv;
if (APR_BUCKET_IS_EOS(e)) {
return rv;
c = *str;
if (bytes_handled >= n) {
*read = n;
return APR_ENOSPC;
char *tmp;
if (do_alloc) {
return rv;
char *new_buffer;
*s = new_buffer;
return APR_SUCCESS;
return rv;
char *tmp_s = s;
return (int)len;
++uri ;
* This will prevent "http://www.wherever.com/..\..\/" from
const char *ll;
const char *uri;
const char *pro;
int num_blank_lines = 0;
if (max_blank_lines <= 0) {
r->method);
if (ll[0]) {
r->assbackwards = 0;
char *field;
char *value;
int fields_read = 0;
char *tmp_field;
int folded = 0;
char *fold_buf;
alloc_len = 0;
if (len == 0) {
if (!folded) {
request_rec *r;
apr_pool_t *p;
const char *expect;
int access_status;
r->pool = p;
r->read_length = 0;
ap_send_error_response(r, 0);
goto traceout;
goto traceout;
r = NULL;
goto traceout;
if (!r->assbackwards) {
ap_send_error_response(r, 0);
goto traceout;
if (r->header_only) {
r->uri);
r->header_only = 0;
ap_send_error_response(r, 0);
goto traceout;
ap_send_error_response(r, 0);
goto traceout;
r = NULL;
goto traceout;
ap_send_error_response(r, 0);
goto traceout;
AP_READ_REQUEST_SUCCESS((uintptr_t)r, (char *)r->method, (char *)r->uri, (char *)r->server->defn_name, r->status);
const request_rec *r)
const request_rec *r)
apr_bucket *b;
(void) ap_discard_request_body(r);
if (!r->eos_sent) {
if (type) {
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 {
ap_filter_t *f,
request_rec *r = f->r;
apr_bucket *e;
int eos = 0;
if (!ctx) {
e = APR_BRIGADE_FIRST(b);
while (e != APR_BRIGADE_SENTINEL(b)) {
if (APR_BUCKET_IS_EOS(e)) {
const char *ignored;
if (e != APR_BRIGADE_FIRST(b)) {
return rv;
e = APR_BRIGADE_FIRST(b);
return rv;
e = APR_BUCKET_NEXT(e);
return rv;
#if APR_HAS_MMAP
apr_bucket *b;
ap_filter_t *f;
if (f == NULL) {
f = r->output_filters;
ap_filter_t *f;
if (len == 0)
return APR_SUCCESS;
f = insert_old_write_filter(r);
if (f != r->output_filters) {
return rv;
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;
ap_filter_t *f;
f = insert_old_write_filter(r);
if (!r->assbackwards) {
typedef struct hdr_ptr {
ap_filter_t *f;
} hdr_ptr;
hdr_ptr x;
if (send_headers) {
(const request_rec *r), (r), 0)