http_protocol.h revision fd0edaa8e3d4dd67d0604ccef2e96b071db96643
2d2eda71267231c2526be701fe655db125852c1ffielding/* ====================================================================
2d2eda71267231c2526be701fe655db125852c1ffielding * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * Redistribution and use in source and binary forms, with or without
2d2eda71267231c2526be701fe655db125852c1ffielding * modification, are permitted provided that the following conditions
2d2eda71267231c2526be701fe655db125852c1ffielding * are met:
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * 1. Redistributions of source code must retain the above copyright
2d2eda71267231c2526be701fe655db125852c1ffielding * notice, this list of conditions and the following disclaimer.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * 2. Redistributions in binary form must reproduce the above copyright
2d2eda71267231c2526be701fe655db125852c1ffielding * notice, this list of conditions and the following disclaimer in
2d2eda71267231c2526be701fe655db125852c1ffielding * the documentation and/or other materials provided with the
2d2eda71267231c2526be701fe655db125852c1ffielding * distribution.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * 3. All advertising materials mentioning features or use of this
2d2eda71267231c2526be701fe655db125852c1ffielding * software must display the following acknowledgment:
2d2eda71267231c2526be701fe655db125852c1ffielding * "This product includes software developed by the Apache Group
2d2eda71267231c2526be701fe655db125852c1ffielding * for use in the Apache HTTP server project (http://www.apache.org/)."
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * 4. The names "Apache Server" and "Apache Group" must not be used to
2d2eda71267231c2526be701fe655db125852c1ffielding * endorse or promote products derived from this software without
2d2eda71267231c2526be701fe655db125852c1ffielding * prior written permission. For written permission, please contact
2d2eda71267231c2526be701fe655db125852c1ffielding * apache@apache.org.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * 5. Products derived from this software may not be called "Apache"
2d2eda71267231c2526be701fe655db125852c1ffielding * nor may "Apache" appear in their names without prior written
2d2eda71267231c2526be701fe655db125852c1ffielding * permission of the Apache Group.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * 6. Redistributions of any form whatsoever must retain the following
2d2eda71267231c2526be701fe655db125852c1ffielding * acknowledgment:
2d2eda71267231c2526be701fe655db125852c1ffielding * "This product includes software developed by the Apache Group
2d2eda71267231c2526be701fe655db125852c1ffielding * for use in the Apache HTTP server project (http://www.apache.org/)."
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
2d2eda71267231c2526be701fe655db125852c1ffielding * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2d2eda71267231c2526be701fe655db125852c1ffielding * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2d2eda71267231c2526be701fe655db125852c1ffielding * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
2d2eda71267231c2526be701fe655db125852c1ffielding * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2d2eda71267231c2526be701fe655db125852c1ffielding * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2d2eda71267231c2526be701fe655db125852c1ffielding * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2d2eda71267231c2526be701fe655db125852c1ffielding * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2d2eda71267231c2526be701fe655db125852c1ffielding * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2d2eda71267231c2526be701fe655db125852c1ffielding * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2d2eda71267231c2526be701fe655db125852c1ffielding * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2d2eda71267231c2526be701fe655db125852c1ffielding * OF THE POSSIBILITY OF SUCH DAMAGE.
2d2eda71267231c2526be701fe655db125852c1ffielding * ====================================================================
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * This software consists of voluntary contributions made by many
2d2eda71267231c2526be701fe655db125852c1ffielding * individuals on behalf of the Apache Group and was originally based
2d2eda71267231c2526be701fe655db125852c1ffielding * on public domain software written at the National Center for
2d2eda71267231c2526be701fe655db125852c1ffielding * Supercomputing Applications, University of Illinois, Urbana-Champaign.
2d2eda71267231c2526be701fe655db125852c1ffielding * For more information on the Apache Group and the Apache HTTP server
2d2eda71267231c2526be701fe655db125852c1ffielding * project, please see <http://www.apache.org/>.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding#ifndef APACHE_HTTP_PROTOCOL_H
2d2eda71267231c2526be701fe655db125852c1ffielding#define APACHE_HTTP_PROTOCOL_H
2d2eda71267231c2526be701fe655db125852c1ffielding
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding#include "ap_hooks.h"
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding
2d2eda71267231c2526be701fe655db125852c1ffielding#ifdef __cplusplus
2d2eda71267231c2526be701fe655db125852c1ffieldingextern "C" {
2d2eda71267231c2526be701fe655db125852c1ffielding#endif
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/*
2d2eda71267231c2526be701fe655db125852c1ffielding * Prototypes for routines which either talk directly back to the user,
2d2eda71267231c2526be701fe655db125852c1ffielding * or control the ones that eventually do.
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* Read a request and fill in the fields. */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingrequest_rec *ap_read_request(conn_rec *c);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* Send a single HTTP header field */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT_NONSTD(int) ap_send_header_field(request_rec *r, const char *fieldname,
2d2eda71267231c2526be701fe655db125852c1ffielding const char *fieldval);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* Send the minimal part of an HTTP response header... but modules should be
2d2eda71267231c2526be701fe655db125852c1ffielding * very careful about using this, and should prefer ap_send_http_header().
2d2eda71267231c2526be701fe655db125852c1ffielding * Much of the HTTP/1.1 implementation correctness depends on code in
2d2eda71267231c2526be701fe655db125852c1ffielding * ap_send_http_header().
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(void) ap_basic_http_header(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* Send the Status-Line and header fields for HTTP response */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(void) ap_send_http_header(request_rec *l);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* Send the response to special method requests */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_send_http_trace(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffieldingint ap_send_http_options(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* Finish up stuff after a request */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(void) ap_finalize_request_protocol(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* Send error back to client... last arg indicates error status in case
2d2eda71267231c2526be701fe655db125852c1ffielding * we get an error in the process of trying to deal with an ErrorDocument
2d2eda71267231c2526be701fe655db125852c1ffielding * to handle some other error. In that case, we print the default report
2d2eda71267231c2526be701fe655db125852c1ffielding * for the first thing that went wrong, and more briefly report on the
2d2eda71267231c2526be701fe655db125852c1ffielding * problem with the ErrorDocument.
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingvoid ap_send_error_response(request_rec *r, int recursive_error);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* Set last modified header line from the lastmod date of the associated file.
2d2eda71267231c2526be701fe655db125852c1ffielding * Also, set content length.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * May return an error status, typically USE_LOCAL_COPY (that when the
2d2eda71267231c2526be701fe655db125852c1ffielding * permit_cache argument is set to one).
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_set_content_length(request_rec *r, long length);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_set_keepalive(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(time_t) ap_rationalize_mtime(request_rec *r, time_t mtime);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(char *) ap_make_etag(request_rec *r, int force_weak);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(void) ap_set_etag(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(void) ap_set_last_modified(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_meets_conditions(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* Other ways to send stuff at the client. All of these keep track
2d2eda71267231c2526be701fe655db125852c1ffielding * of bytes_sent automatically. This indirection is intended to make
2d2eda71267231c2526be701fe655db125852c1ffielding * it a little more painless to slide things like HTTP-NG packetization
2d2eda71267231c2526be701fe655db125852c1ffielding * underneath the main body of the code later. In the meantime, it lets
2d2eda71267231c2526be701fe655db125852c1ffielding * us centralize a bit of accounting (bytes_sent).
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * These also return the number of bytes written by the call.
2d2eda71267231c2526be701fe655db125852c1ffielding * They should only be called with a timeout registered, for obvious reaasons.
2d2eda71267231c2526be701fe655db125852c1ffielding * (Ditto the send_header stuff).
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffielding
f9c4356e783d254720e6f312a044caf6db68639bfieldingAPI_EXPORT(long) ap_send_fd(APRFile fd, request_rec *r);
f9c4356e783d254720e6f312a044caf6db68639bfieldingAPI_EXPORT(long) ap_send_fd_length(APRFile fd, request_rec *r, long length);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(long) ap_send_fb(BUFF *f, request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(long) ap_send_fb_length(BUFF *f, request_rec *r, long length);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(size_t) ap_send_mmap(void *mm, request_rec *r, size_t offset,
2d2eda71267231c2526be701fe655db125852c1ffielding size_t length);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* Hmmm... could macrofy these for now, and maybe forever, though the
2d2eda71267231c2526be701fe655db125852c1ffielding * definitions of the macros would get a whole lot hairier.
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_rputc(int c, request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_rputs(const char *str, request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_rwrite(const void *buf, int nbyte, request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT_NONSTD(int) ap_rvputs(request_rec *r,...);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_vrprintf(request_rec *r, const char *fmt, va_list vlist);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT_NONSTD(int) ap_rprintf(request_rec *r, const char *fmt,...)
2d2eda71267231c2526be701fe655db125852c1ffielding __attribute__((format(printf,2,3)));
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_rflush(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/*
2d2eda71267231c2526be701fe655db125852c1ffielding * Index used in custom_responses array for a specific error code
2d2eda71267231c2526be701fe655db125852c1ffielding * (only use outside protocol.c is in getting them configured).
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_index_of_response(int status);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* Reading a block of data from the client connection (e.g., POST arg) */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_setup_client_block(request_rec *r, int read_policy);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_should_client_block(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(long) ap_get_client_block(request_rec *r, char *buffer, int bufsiz);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_discard_request_body(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* Sending a byterange */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_set_byterange(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_each_byterange(request_rec *r, long *offset, long *length);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* Support for the Basic authentication protocol. Note that there's
2d2eda71267231c2526be701fe655db125852c1ffielding * nothing that prevents these from being in mod_auth.c, except that other
2d2eda71267231c2526be701fe655db125852c1ffielding * modules which wanted to provide their own variants on finding users and
2d2eda71267231c2526be701fe655db125852c1ffielding * passwords for Basic auth (a fairly common request) would then require
2d2eda71267231c2526be701fe655db125852c1ffielding * mod_auth to be loaded or they wouldn't work.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * get_basic_auth_pw returns 0 (OK) if it set the 'pw' argument (and assured
2d2eda71267231c2526be701fe655db125852c1ffielding * a correct value in r->connection->user); otherwise it returns an error
2d2eda71267231c2526be701fe655db125852c1ffielding * code, either SERVER_ERROR if things are really confused, AUTH_REQUIRED
2d2eda71267231c2526be701fe655db125852c1ffielding * if no authentication at all seemed to be in use, or DECLINED if there
2d2eda71267231c2526be701fe655db125852c1ffielding * was authentication but it wasn't Basic (in which case, the caller should
2d2eda71267231c2526be701fe655db125852c1ffielding * presumably decline as well).
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * note_basic_auth_failure arranges for the right stuff to be scribbled on
2d2eda71267231c2526be701fe655db125852c1ffielding * the HTTP return so that the client knows how to authenticate itself the
2d2eda71267231c2526be701fe655db125852c1ffielding * next time. As does note_digest_auth_failure for Digest auth.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * note_auth_failure does the same thing, but will call the correct one
2d2eda71267231c2526be701fe655db125852c1ffielding * based on the authentication type in use.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(void) ap_note_auth_failure(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(void) ap_note_basic_auth_failure(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(void) ap_note_digest_auth_failure(request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_get_basic_auth_pw(request_rec *r, const char **pw);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/*
2d2eda71267231c2526be701fe655db125852c1ffielding * Setting up the protocol fields for subsidiary requests...
2d2eda71267231c2526be701fe655db125852c1ffielding * Also, a wrapup function to keep the internal accounting straight.
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingvoid ap_set_sub_req_protocol(request_rec *rnew, const request_rec *r);
2d2eda71267231c2526be701fe655db125852c1ffieldingvoid ap_finalize_sub_req_protocol(request_rec *sub_r);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* This is also useful for putting sub_reqs and internal_redirects together */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingCORE_EXPORT(void) ap_parse_uri(request_rec *r, const char *uri);
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/* Get the method number associated with the given string, assumed to
2d2eda71267231c2526be701fe655db125852c1ffielding * contain an HTTP method. Returns M_INVALID if not recognized.
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffieldingAPI_EXPORT(int) ap_method_number_of(const char *method);
2d2eda71267231c2526be701fe655db125852c1ffielding
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding /* Hooks */
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding /*
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding * post_read_request --- run right after read_request or internal_redirect,
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding * and not run during any subrequests.
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding */
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fieldingDECLARE_HOOK(int,post_read_request,(request_rec *))
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fieldingDECLARE_HOOK(int,log_transaction,(request_rec *))
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fieldingDECLARE_HOOK(const char *,http_method,(const request_rec *))
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fieldingDECLARE_HOOK(unsigned short,default_port,(const request_rec *))
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding
2d2eda71267231c2526be701fe655db125852c1ffielding#ifdef __cplusplus
2d2eda71267231c2526be701fe655db125852c1ffielding}
2d2eda71267231c2526be701fe655db125852c1ffielding#endif
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding#endif /* !APACHE_HTTP_PROTOCOL_H */