1 /* ====================================================================
2 * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the Apache Group
19 * for use in the Apache HTTP server project (http://www.apache.org/)."
21 * 4. The names "Apache Server" and "Apache Group" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
26 * 5. Products derived from this software may not be called "Apache"
27 * nor may "Apache" appear in their names without prior written
28 * permission of the Apache Group.
30 * 6. Redistributions of any form whatsoever must retain the following
32 * "This product includes software developed by the Apache Group
33 * for use in the Apache HTTP server project (http://www.apache.org/)."
35 * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Group and was originally based
51 * on public domain software written at the National Center for
52 * Supercomputing Applications, University of Illinois, Urbana-Champaign.
53 * For more information on the Apache Group and the Apache HTTP server
54 * project, please see <http://www.apache.org/>.
58 #ifndef APACHE_HTTP_PROTOCOL_H
59 #define APACHE_HTTP_PROTOCOL_H
62 #include "apr_portable.h"
70 * Prototypes for routines which either talk directly back to the user,
71 * or control the ones that eventually do.
74 /* Read a request and fill in the fields. */
76 request_rec *ap_read_request(conn_rec *c);
78 /* Send a single HTTP header field */
80 API_EXPORT_NONSTD(int) ap_send_header_field(request_rec *r, const char *fieldname,
81 const char *fieldval);
83 /* Send the minimal part of an HTTP response header... but modules should be
84 * very careful about using this, and should prefer ap_send_http_header().
85 * Much of the HTTP/1.1 implementation correctness depends on code in
86 * ap_send_http_header().
88 API_EXPORT(void) ap_basic_http_header(request_rec *r);
90 /* Send the Status-Line and header fields for HTTP response */
92 API_EXPORT(void) ap_send_http_header(request_rec *l);
94 /* Send the response to special method requests */
96 API_EXPORT(int) ap_send_http_trace(request_rec *r);
97 int ap_send_http_options(request_rec *r);
99 /* Finish up stuff after a request */
101 API_EXPORT(void) ap_finalize_request_protocol(request_rec *r);
103 /* Send error back to client... last arg indicates error status in case
104 * we get an error in the process of trying to deal with an ErrorDocument
105 * to handle some other error. In that case, we print the default report
106 * for the first thing that went wrong, and more briefly report on the
107 * problem with the ErrorDocument.
110 API_EXPORT(void) ap_send_error_response(request_rec *r, int recursive_error);
112 /* Set last modified header line from the lastmod date of the associated file.
113 * Also, set content length.
115 * May return an error status, typically USE_LOCAL_COPY (that when the
116 * permit_cache argument is set to one).
119 API_EXPORT(int) ap_set_content_length(request_rec *r, long length);
120 API_EXPORT(int) ap_set_keepalive(request_rec *r);
121 API_EXPORT(ap_time_t *) ap_rationalize_mtime(request_rec *r, ap_time_t *mtime);
122 API_EXPORT(char *) ap_make_etag(request_rec *r, int force_weak);
123 API_EXPORT(void) ap_set_etag(request_rec *r);
124 API_EXPORT(void) ap_set_last_modified(request_rec *r);
125 API_EXPORT(int) ap_meets_conditions(request_rec *r);
127 /* Other ways to send stuff at the client. All of these keep track
128 * of bytes_sent automatically. This indirection is intended to make
129 * it a little more painless to slide things like HTTP-NG packetization
130 * underneath the main body of the code later. In the meantime, it lets
131 * us centralize a bit of accounting (bytes_sent).
133 * These also return the number of bytes written by the call.
134 * They should only be called with a timeout registered, for obvious reaasons.
135 * (Ditto the send_header stuff).
138 API_EXPORT(long) ap_send_fd(ap_file_t *fd, request_rec *r);
139 API_EXPORT(long) ap_send_fd_length(ap_file_t *fd, request_rec *r, long length);
141 API_EXPORT(long) ap_send_fb(BUFF *f, request_rec *r);
142 API_EXPORT(long) ap_send_fb_length(BUFF *f, request_rec *r, long length);
144 API_EXPORT(size_t) ap_send_mmap(ap_mmap_t *mm, request_rec *r, size_t offset,
147 /* Hmmm... could macrofy these for now, and maybe forever, though the
148 * definitions of the macros would get a whole lot hairier.
151 API_EXPORT(int) ap_rputc(int c, request_rec *r);
152 API_EXPORT(int) ap_rputs(const char *str, request_rec *r);
153 API_EXPORT(int) ap_rwrite(const void *buf, int nbyte, request_rec *r);
154 API_EXPORT_NONSTD(int) ap_rvputs(request_rec *r,...);
155 API_EXPORT(int) ap_vrprintf(request_rec *r, const char *fmt, va_list vlist);
156 API_EXPORT_NONSTD(int) ap_rprintf(request_rec *r, const char *fmt,...)
157 __attribute__((format(printf,2,3)));
158 API_EXPORT(int) ap_rflush(request_rec *r);
161 * Index used in custom_responses array for a specific error code
162 * (only use outside protocol.c is in getting them configured).
165 API_EXPORT(int) ap_index_of_response(int status);
167 /* Reading a block of data from the client connection (e.g., POST arg) */
169 API_EXPORT(int) ap_setup_client_block(request_rec *r, int read_policy);
170 API_EXPORT(int) ap_should_client_block(request_rec *r);
171 API_EXPORT(long) ap_get_client_block(request_rec *r, char *buffer, int bufsiz);
172 API_EXPORT(int) ap_discard_request_body(request_rec *r);
174 /* Sending a byterange */
176 API_EXPORT(int) ap_set_byterange(request_rec *r);
177 API_EXPORT(int) ap_each_byterange(request_rec *r, ap_off_t *offset,
180 /* Support for the Basic authentication protocol. Note that there's
181 * nothing that prevents these from being in mod_auth.c, except that other
182 * modules which wanted to provide their own variants on finding users and
183 * passwords for Basic auth (a fairly common request) would then require
184 * mod_auth to be loaded or they wouldn't work.
186 * get_basic_auth_pw returns 0 (OK) if it set the 'pw' argument (and assured
187 * a correct value in r->connection->user); otherwise it returns an error
188 * code, either SERVER_ERROR if things are really confused, AUTH_REQUIRED
189 * if no authentication at all seemed to be in use, or DECLINED if there
190 * was authentication but it wasn't Basic (in which case, the caller should
191 * presumably decline as well).
193 * note_basic_auth_failure arranges for the right stuff to be scribbled on
194 * the HTTP return so that the client knows how to authenticate itself the
195 * next time. As does note_digest_auth_failure for Digest auth.
197 * note_auth_failure does the same thing, but will call the correct one
198 * based on the authentication type in use.
202 API_EXPORT(void) ap_note_auth_failure(request_rec *r);
203 API_EXPORT(void) ap_note_basic_auth_failure(request_rec *r);
204 API_EXPORT(void) ap_note_digest_auth_failure(request_rec *r);
205 API_EXPORT(int) ap_get_basic_auth_pw(request_rec *r, const char **pw);
208 * Setting up the protocol fields for subsidiary requests...
209 * Also, a wrapup function to keep the internal accounting straight.
212 void ap_set_sub_req_protocol(request_rec *rnew, const request_rec *r);
213 void ap_finalize_sub_req_protocol(request_rec *sub_r);
215 /* This is also useful for putting sub_reqs and internal_redirects together */
217 CORE_EXPORT(void) ap_parse_uri(request_rec *r, const char *uri);
219 /* Get the method number associated with the given string, assumed to
220 * contain an HTTP method. Returns M_INVALID if not recognized.
222 API_EXPORT(int) ap_method_number_of(const char *method);
226 * post_read_request --- run right after read_request or internal_redirect,
227 * and not run during any subrequests.
229 DECLARE_HOOK(int,post_read_request,(request_rec *))
230 DECLARE_HOOK(int,log_transaction,(request_rec *))
231 DECLARE_HOOK(const char *,http_method,(const request_rec *))
232 DECLARE_HOOK(unsigned short,default_port,(const request_rec *))
238 #endif /* !APACHE_HTTP_PROTOCOL_H */