]> granicus.if.org Git - apache/blob - include/http_protocol.h
finished that boring job:
[apache] / include / http_protocol.h
1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  *
19  * 3. The end-user documentation included with the redistribution,
20  *    if any, must include the following acknowledgment:
21  *       "This product includes software developed by the
22  *        Apache Software Foundation (http://www.apache.org/)."
23  *    Alternately, this acknowledgment may appear in the software itself,
24  *    if and wherever such third-party acknowledgments normally appear.
25  *
26  * 4. The names "Apache" and "Apache Software Foundation" must
27  *    not be used to endorse or promote products derived from this
28  *    software without prior written permission. For written
29  *    permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache",
32  *    nor may "Apache" appear in their name, without prior written
33  *    permission of the Apache Software Foundation.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Software Foundation.  For more
51  * information on the Apache Software Foundation, please see
52  * <http://www.apache.org/>.
53  *
54  * Portions of this software are based upon public domain software
55  * originally written at the National Center for Supercomputing Applications,
56  * University of Illinois, Urbana-Champaign.
57  */
58
59 #ifndef APACHE_HTTP_PROTOCOL_H
60 #define APACHE_HTTP_PROTOCOL_H
61
62 #include "httpd.h"
63 #include "apr_hooks.h"
64 #include "apr_portable.h"
65 #include "apr_mmap.h"
66 #include "apr_buckets.h"
67 #include "util_filter.h"
68
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72
73 /**
74  * @package HTTP protocol handling
75  */
76
77 /* This is an optimization.  We keep a record of the filter_rec that
78  * stores the old_write filter, so that we can avoid strcmp's later.
79  */
80 AP_DECLARE_DATA extern ap_filter_rec_t *ap_old_write_func;
81
82 /*
83  * Prototypes for routines which either talk directly back to the user,
84  * or control the ones that eventually do.
85  */
86
87 /**
88  * Read a request and fill in the fields.
89  * @param c The current connection
90  * @return The new request_rec
91  */ 
92 request_rec *ap_read_request(conn_rec *c);
93
94 /**
95  * Read the mime-encoded headers.
96  * @param r The current request
97  */
98 AP_DECLARE(void) ap_get_mime_headers(request_rec *r);
99
100 /**
101  * Optimized version of ap_get_mime_headers() that requires a
102  * temporary brigade to work with
103  * @param r The current request
104  * @param bb temp brigade
105  */
106 AP_DECLARE(void) ap_get_mime_headers_core(request_rec *r,
107                                           apr_bucket_brigade *bb);
108
109 /* Finish up stuff after a request */
110
111 /**
112  * Called at completion of sending the response.  It sends the terminating
113  * protocol information.
114  * @param r The current request
115  * @deffunc void ap_finalize_request_protocol(request_rec *r)
116  */
117 AP_DECLARE(void) ap_finalize_request_protocol(request_rec *r);
118
119 /**
120  * Send error back to client.
121  * @param r The current request
122  * @param recursive_error last arg indicates error status in case we get 
123  *      an error in the process of trying to deal with an ErrorDocument 
124  *      to handle some other error.  In that case, we print the default 
125  *      report for the first thing that went wrong, and more briefly report 
126  *      on the problem with the ErrorDocument.
127  * @deffunc void ap_send_error_response(request_rec *r, int recursive_error)
128  */
129 AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error);
130
131 /* Set last modified header line from the lastmod date of the associated file.
132  * Also, set content length.
133  *
134  * May return an error status, typically HTTP_NOT_MODIFIED (that when the
135  * permit_cache argument is set to one).
136  */
137
138 /**
139  * Set the content length for this request
140  * @param r The current request
141  * @param length The new content length
142  * @deffunc void ap_set_content_length(request_rec *r, apr_off_t length)
143  */
144 AP_DECLARE(void) ap_set_content_length(request_rec *r, apr_off_t length);
145
146 /**
147  * Set the keepalive status for this request
148  * @param r The current request
149  * @return 1 if keepalive can be set, 0 otherwise
150  * @deffunc int ap_set_keepalive(request_rec *r)
151  */
152 AP_DECLARE(int) ap_set_keepalive(request_rec *r);
153
154 /**
155  * Return the latest rational time from a request/mtime pair.  Mtime is 
156  * returned unless it's in the future, in which case we return the current time.
157  * @param r The current request
158  * @param mtime The last modified time
159  * @return the latest rational time.
160  * @deffunc apr_time_t ap_rationalize_mtime(request_rec *r, apr_time_t mtime)
161  */
162 AP_DECLARE(apr_time_t) ap_rationalize_mtime(request_rec *r, apr_time_t mtime);
163
164 /**
165  * Build the content-type that should be sent to the client from the
166  * content-type specified.  The following rules are followed:
167  *    - if type is NULL, type is set to ap_default_type(r)
168  *    - if charset adding is disabled, stop processing and return type.
169  *    - then, if there are no parameters on type, add the default charset
170  *    - return type
171  * @param r The current request
172  * @return The content-type
173  * @deffunc const char *ap_make_content_type(request_rec *r, const char *type);
174  */ 
175 AP_DECLARE(const char *) ap_make_content_type(request_rec *r,
176                                               const char *type);
177
178 #ifdef CORE_PRIVATE
179 /**
180  * Precompile metadata structures used by ap_make_content_type()
181  * @param r The pool to use for allocations
182  * @deffunc void ap_setup_make_content_type(apr_pool_t *pool)
183  */
184 AP_DECLARE(void) ap_setup_make_content_type(apr_pool_t *pool);
185 #endif /* CORE_PRIVATE */
186
187 /**
188  * Construct an entity tag from the resource information.  If it's a real
189  * file, build in some of the file characteristics.
190  * @param r The current request
191  * @param force_weak Force the entity tag to be weak - it could be modified
192  *                   again in as short an interval.
193  * @return The entity tag
194  * @deffunc char *ap_make_etag(request_rec *r, int force_weak)
195  */ 
196 AP_DECLARE(char *) ap_make_etag(request_rec *r, int force_weak);
197
198 /**
199  * Set the E-tag outgoing header
200  * @param The current request
201  * @deffunc void ap_set_etag(request_rec *r)
202  */
203 AP_DECLARE(void) ap_set_etag(request_rec *r);
204
205 /**
206  * Set the last modified time for the file being sent
207  * @param r The current request
208  * @deffunc void ap_set_last_modified(request_rec *r)
209  */
210 AP_DECLARE(void) ap_set_last_modified(request_rec *r);
211
212 /**
213  * Implements condition GET rules for HTTP/1.1 specification.  This function
214  * inspects the client headers and determines if the response fulfills 
215  * the requirements specified.
216  * @param r The current request
217  * @return 1 if the response fulfills the condition GET rules, 0 otherwise
218  * @deffunc int ap_meets_conditions(request_rec *r)
219  */
220 AP_DECLARE(int) ap_meets_conditions(request_rec *r);
221
222 /* Other ways to send stuff at the client.  All of these keep track
223  * of bytes_sent automatically.  This indirection is intended to make
224  * it a little more painless to slide things like HTTP-NG packetization
225  * underneath the main body of the code later.  In the meantime, it lets
226  * us centralize a bit of accounting (bytes_sent).
227  *
228  * These also return the number of bytes written by the call.
229  * They should only be called with a timeout registered, for obvious reaasons.
230  * (Ditto the send_header stuff).
231  */
232
233 /**
234  * Send an entire file to the client, using sendfile if supported by the 
235  * current platform
236  * @param fd The file to send.
237  * @param r The current request
238  * @param offset Offset into the file to start sending.
239  * @param length Amount of data to send
240  * @param nbytes Amount of data actually sent
241  * @deffunc apr_status_t ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t offset, apr_size_t length, apr_size_t *nbytes);
242  */
243 AP_DECLARE(apr_status_t) ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t offset, 
244                                    apr_size_t length, apr_size_t *nbytes);
245
246 #if APR_HAS_MMAP
247 /**
248  * Send an MMAP'ed file to the client
249  * @param mm The MMAP'ed file to send
250  * @param r The current request
251  * @param offset The offset into the MMAP to start sending
252  * @param length The amount of data to send
253  * @return The number of bytes sent
254  * @deffunc size_t ap_send_mmap(apr_mmap_t *mm, request_rec *r, size_t offset, size_t length)
255  */
256 AP_DECLARE(size_t) ap_send_mmap(apr_mmap_t *mm, request_rec *r, size_t offset,
257                              size_t length);
258 #endif
259
260
261 /**
262  * Register a new request method, and return the offset that will be
263  * associated with that method.
264  *
265  * @param p        The pool to create registered method numbers from.
266  * @param methname The name of the new method to register.
267  * @return         Ab int value representing an offset into a bitmask.
268  */
269 AP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname);
270
271 /**
272  * Initialize the method_registry and allocate memory for it.
273  *
274  * @param p Pool to allocate memory for the registry from.
275  */
276 AP_DECLARE(void) ap_method_registry_init(apr_pool_t *p);
277
278 /*
279  * This is a convenience macro to ease with checking a mask
280  * against a method name.
281  */
282 #define AP_METHOD_CHECK_ALLOWED(mask, methname) \
283     ((mask) & (AP_METHOD_BIT << ap_method_number_of((methname))))
284
285 /**
286  * Create a new method list with the specified number of preallocated
287  * slots for extension methods.
288  *
289  * @param   p       Pointer to a pool in which the structure should be
290  *                  allocated.
291  * @param   nelts   Number of preallocated extension slots
292  * @return  Pointer to the newly created structure.
293  * @deffunc ap_method_list_t ap_make_method_list(apr_pool_t *p, int nelts)
294  */
295 AP_DECLARE(ap_method_list_t *) ap_make_method_list(apr_pool_t *p, int nelts);
296 AP_DECLARE(void) ap_copy_method_list(ap_method_list_t *dest,
297                                      ap_method_list_t *src);
298 AP_DECLARE_NONSTD(void) ap_method_list_do(int (*comp) (void *urec, const char *mname,
299                                                        int mnum),
300                                           void *rec,
301                                           const ap_method_list_t *ml, ...);
302 AP_DECLARE(void) ap_method_list_vdo(int (*comp) (void *urec, const char *mname,
303                                                  int mnum),
304                                     void *rec, const ap_method_list_t *ml,
305                                     va_list vp);
306 /**
307  * Search for an HTTP method name in an ap_method_list_t structure, and
308  * return true if found.
309  *
310  * @param   method  String containing the name of the method to check.
311  * @param   l       Pointer to a method list, such as cmd->methods_limited.
312  * @return  1 if method is in the list, otherwise 0
313  * @deffunc int ap_method_in_list(const char *method, ap_method_list_t *l)
314  */
315 AP_DECLARE(int) ap_method_in_list(ap_method_list_t *l, const char *method);
316
317 /**
318  * Add an HTTP method name to an ap_method_list_t structure if it isn't
319  * already listed.
320  *
321  * @param   method  String containing the name of the method to check.
322  * @param   l       Pointer to a method list, such as cmd->methods_limited.
323  * @return  None.
324  * @deffunc void ap_method_in_list(ap_method_list_t *l, const char *method)
325  */
326 AP_DECLARE(void) ap_method_list_add(ap_method_list_t *l, const char *method);
327     
328 /**
329  * Remove an HTTP method name from an ap_method_list_t structure.
330  *
331  * @param   l       Pointer to a method list, such as cmd->methods_limited.
332  * @param   method  String containing the name of the method to remove.
333  * @return  None.
334  * @deffunc void ap_method_list_remove(ap_method_list_t *l, const char *method)
335  */
336 AP_DECLARE(void) ap_method_list_remove(ap_method_list_t *l,
337                                        const char *method);
338
339 /**
340  * Reset a method list to be completely empty.
341  *
342  * @param   l       Pointer to a method list, such as cmd->methods_limited.
343  * @return  None.
344  * @deffunc void ap_clear_method_list(ap_method_list_t *l)
345  */
346 AP_DECLARE(void) ap_clear_method_list(ap_method_list_t *l);
347     
348 /**
349  * Set the content type for this request (r->content_type). 
350  * @param r The current request
351  * @param ct The new content type
352  * @deffunc void ap_set_content_type(request_rec *r, const char* ct)
353  * @warning This function must be called to set r->content_type in order 
354  * for the AddOutputFilterByType directive to work correctly.
355  */
356 AP_DECLARE(void) ap_set_content_type(request_rec *r, const char *ct);
357
358 /* Hmmm... could macrofy these for now, and maybe forever, though the
359  * definitions of the macros would get a whole lot hairier.
360  */
361
362 /**
363  * Output one character for this request
364  * @param c the character to output
365  * @param r the current request
366  * @return The number of bytes sent
367  * @deffunc int ap_rputc(int c, request_rec *r)
368  */
369 AP_DECLARE(int) ap_rputc(int c, request_rec *r);
370
371 /**
372  * Output a string for the current request
373  * @param str The string to output
374  * @param r The current request
375  * @return The number of bytes sent
376  * @deffunc int ap_rputs(const char *str, request_rec *r)
377  */
378 AP_DECLARE(int) ap_rputs(const char *str, request_rec *r);
379
380 /**
381  * Write a buffer for the current request
382  * @param buf The buffer to write
383  * @param nbyte The number of bytes to send from the buffer
384  * @param r The current request
385  * @return The number of bytes sent
386  * @deffunc int ap_rwrite(const void *buf, int nbyte, request_rec *r)
387  */
388 AP_DECLARE(int) ap_rwrite(const void *buf, int nbyte, request_rec *r);
389
390 /**
391  * Write an unspecified number of strings to the request
392  * @param r The current request
393  * @param ... The strings to write
394  * @return The number of bytes sent
395  * @deffunc int ap_rvputs(request_rec *r, ...)
396  */
397 AP_DECLARE_NONSTD(int) ap_rvputs(request_rec *r,...);
398
399 /**
400  * Output data to the client in a printf format
401  * @param r The current request
402  * @param fmt The format string
403  * @param vlist The arguments to use to fill out the format string
404  * @return The number of bytes sent
405  * @deffunc int ap_vrprintf(request_rec *r, const char *fmt, va_list vlist)
406  */
407 AP_DECLARE(int) ap_vrprintf(request_rec *r, const char *fmt, va_list vlist);
408
409 /**
410  * Output data to the client in a printf format
411  * @param r The current request
412  * @param fmt The format string
413  * @param ... The arguments to use to fill out the format string
414  * @return The number of bytes sent
415  * @deffunc int ap_rprintf(request_rec *r, const char *fmt, ...)
416  */
417 AP_DECLARE_NONSTD(int) ap_rprintf(request_rec *r, const char *fmt,...)
418                                 __attribute__((format(printf,2,3)));
419 /**
420  * Flush all of the data for the current request to the client
421  * @param r The current request
422  * @return The number of bytes sent
423  * @deffunc int ap_rflush(request_rec *r)
424  */
425 AP_DECLARE(int) ap_rflush(request_rec *r);
426
427 /**
428  * Index used in custom_responses array for a specific error code
429  * (only use outside protocol.c is in getting them configured).
430  * @param status HTTP status code
431  * @return The index of the response
432  * @deffunc int ap_index_of_response(int status)
433  */
434 AP_DECLARE(int) ap_index_of_response(int status);
435
436 /** 
437  * Return the Status-Line for a given status code (excluding the
438  * HTTP-Version field). If an invalid or unknown status code is
439  * passed, "500 Internal Server Error" will be returned. 
440  * @param status The HTTP status code
441  * @return The Status-Line
442  * @deffunc const char *ap_get_status_line(int status)
443  */
444 AP_DECLARE(const char *) ap_get_status_line(int status);
445
446 /* Reading a block of data from the client connection (e.g., POST arg) */
447
448 /**
449  * Setup the client to allow Apache to read the request body.
450  * @param r The current request
451  * @param read_policy How the server should interpret a chunked 
452  *                    transfer-encoding.  One of: <pre>
453  *    REQUEST_NO_BODY          Send 413 error if message has any body
454  *    REQUEST_CHUNKED_ERROR    Send 411 error if body without Content-Length
455  *    REQUEST_CHUNKED_DECHUNK  If chunked, remove the chunks for me.
456  * </pre>
457  * @return either OK or an error code
458  * @deffunc int ap_setup_client_block(request_rec *r, int read_policy)
459  */
460 AP_DECLARE(int) ap_setup_client_block(request_rec *r, int read_policy);
461
462 /**
463  * Determine if the client has sent any data.  This also sends a 
464  * 100 Continue response to HTTP/1.1 clients, so modules should not be called
465  * until the module is ready to read content.
466  * @warning Never call this function more than once.
467  * @param r The current request
468  * @return 0 if there is no message to read, 1 otherwise
469  * @deffunc int ap_should_client_block(request_rec *r)
470  */
471 AP_DECLARE(int) ap_should_client_block(request_rec *r);
472
473 /**
474  * Call this in a loop.  It will put data into a buffer and return the length
475  * of the input block
476  * @param r The current request
477  * @param buffer The buffer in which to store the data
478  * @param bufsiz The size of the buffer
479  * @return Number of bytes inserted into the buffer.  When done reading, 0
480  *         if EOF, or -1 if there was an error
481  * @deffunc long ap_get_client_block(request_rec *r, char *buffer, apr_size_t bufsiz)
482  */
483 AP_DECLARE(long) ap_get_client_block(request_rec *r, char *buffer, apr_size_t bufsiz);
484
485 /**
486  * In HTTP/1.1, any method can have a body.  However, most GET handlers
487  * wouldn't know what to do with a request body if they received one.
488  * This helper routine tests for and reads any message body in the request,
489  * simply discarding whatever it receives.  We need to do this because
490  * failing to read the request body would cause it to be interpreted
491  * as the next request on a persistent connection.
492  * @param r The current request
493  * @return error status if request is malformed, OK otherwise 
494  * @deffunc int ap_discard_request_body(request_rec *r)
495  */
496 AP_DECLARE(int) ap_discard_request_body(request_rec *r);
497
498
499 /**
500  * Setup the output headers so that the client knows how to authenticate
501  * itself the next time, if an authentication request failed.  This function
502  * works for both basic and digest authentication
503  * @param r The current request
504  * @deffunc void ap_note_auth_failure(request_rec *r)
505  */ 
506 AP_DECLARE(void) ap_note_auth_failure(request_rec *r);
507
508 /**
509  * Setup the output headers so that the client knows how to authenticate
510  * itself the next time, if an authentication request failed.  This function
511  * works only for basic authentication
512  * @param r The current request
513  * @deffunc void ap_note_basic_auth_failure(request_rec *r)
514  */ 
515 AP_DECLARE(void) ap_note_basic_auth_failure(request_rec *r);
516
517 /**
518  * Setup the output headers so that the client knows how to authenticate
519  * itself the next time, if an authentication request failed.  This function
520  * works only for digest authentication
521  * @param r The current request
522  * @deffunc void ap_note_digest_auth_failure(request_rec *r)
523  */ 
524 AP_DECLARE(void) ap_note_digest_auth_failure(request_rec *r);
525
526 /**
527  * Get the password from the request headers
528  * @param r The current request
529  * @param pw The password as set in the headers
530  * @return 0 (OK) if it set the 'pw' argument (and assured
531  *         a correct value in r->connection->user); otherwise it returns 
532  *         an error code, either HTTP_INTERNAL_SERVER_ERROR if things are 
533  *         really confused, HTTP_UNAUTHORIZED if no authentication at all 
534  *         seemed to be in use, or DECLINED if there was authentication but 
535  *         it wasn't Basic (in which case, the caller should presumably 
536  *         decline as well).
537  * @deffunc int ap_get_basic_auth_pw(request_rec *r, const char **pw)
538  */
539 AP_DECLARE(int) ap_get_basic_auth_pw(request_rec *r, const char **pw);
540
541 /**
542  * parse_uri: break apart the uri
543  * @warning Side Effects: <pre>
544  *    - sets r->args to rest after '?' (or NULL if no '?')
545  *    - sets r->uri to request uri (without r->args part)
546  *    - sets r->hostname (if not set already) from request (scheme://host:port)
547  * </pre>
548  * @param r The current request
549  * @param uri The uri to break apart
550  * @deffunc void ap_parse_uri(request_rec *r, const char *uri)
551  */
552 AP_CORE_DECLARE(void) ap_parse_uri(request_rec *r, const char *uri);
553
554 /**
555  * Get the next line of input for the request
556  * @param s The buffer into which to read the line
557  * @param n The size of the buffer
558  * @param r The request
559  * @param fold Whether to merge continuation lines
560  * @return The length of the line, if successful
561  *         n, if the line is too big to fit in the buffer
562  *         -1 for miscellaneous errors
563  * @deffunc int ap_method_number_of(const char *method)
564  */
565 AP_DECLARE(int) ap_getline(char *s, int n, request_rec *r, int fold);
566
567 /**
568  * Get the next line of input for the request
569  *
570  * Note: on ASCII boxes, ap_rgetline is a macro which simply calls 
571  *       ap_rgetline_core to get the line of input.
572  * 
573  *       on EBCDIC boxes, ap_rgetline is a wrapper function which
574  *       translates ASCII protocol lines to the local EBCDIC code page
575  *       after getting the line of input.
576  *       
577  * @param s Pointer to the pointer to the buffer into which the line
578  *          should be read; if *s==NULL, a buffer of the necessary size
579  *          to hold the data will be allocated from the request pool
580  * @param n The size of the buffer
581  * @param read The length of the line.
582  * @param r The request
583  * @param fold Whether to merge continuation lines
584  * @param bb Working brigade to use when reading buckets
585  * @return APR_SUCCESS, if successful
586  *         APR_ENOSPC, if the line is too big to fit in the buffer
587  *         Other errors where appropriate
588  */
589 #if APR_CHARSET_EBCDIC
590 AP_DECLARE(apr_status_t) ap_rgetline(char **s, apr_size_t n, 
591                                      apr_size_t *read,
592                                      request_rec *r, int fold,
593                                      apr_bucket_brigade *bb);
594 #else /* ASCII box */
595 #define ap_rgetline(s, n, read, r, fold, bb) \
596         ap_rgetline_core((s), (n), (read), (r), (fold), (bb))
597 #endif
598 AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n, 
599                                           apr_size_t *read,
600                                           request_rec *r, int fold,
601                                           apr_bucket_brigade *bb);
602
603 /**
604  * Get the method number associated with the given string, assumed to
605  * contain an HTTP method.  Returns M_INVALID if not recognized.
606  * @param method A string containing a valid HTTP method
607  * @return The method number
608  */
609 AP_DECLARE(int) ap_method_number_of(const char *method);
610
611 /**
612  * Get the method name associated with the given internal method
613  * number.  Returns NULL if not recognized.
614  * @param p A pool to use for temporary allocations.
615  * @param methnum An integer value corresponding to an internal method number
616  * @return The name corresponding to the method number
617  */
618 AP_DECLARE(const char *) ap_method_name_of(apr_pool_t *p, int methnum);
619
620
621   /* Hooks */
622   /*
623    * post_read_request --- run right after read_request or internal_redirect,
624    *                  and not run during any subrequests.
625    */
626 /**
627  * This hook allows modules to affect the request immediately after the request
628  * has been read, and before any other phases have been processes.  This allows
629  * modules to make decisions based upon the input header fields
630  * @param r The current request
631  * @return OK or DECLINED
632  * @deffunc ap_run_post_read_request(request_rec *r)
633  */
634 AP_DECLARE_HOOK(int,post_read_request,(request_rec *r))
635
636 /**
637  * This hook allows modules to perform any module-specific logging activities
638  * over and above the normal server things.
639  * @param r The current request
640  * @return OK, DECLINED, or HTTP_...
641  * @deffunc int ap_run_log_transaction(request_rec *r)
642  */
643 AP_DECLARE_HOOK(int,log_transaction,(request_rec *r))
644
645 /**
646  * This hook allows modules to retrieve the http method from a request.  This
647  * allows Apache modules to easily extend the methods that Apache understands
648  * @param r The current request
649  * @return The http method from the request
650  * @deffunc const char *ap_run_http_method(const request_rec *r)
651  */
652 AP_DECLARE_HOOK(const char *,http_method,(const request_rec *r))
653
654 /**
655  * Return the default port from the current request
656  * @param r The current request
657  * @return The current port
658  * @deffunc apr_port_t ap_run_default_port(const request_rec *r)
659  */
660 AP_DECLARE_HOOK(apr_port_t,default_port,(const request_rec *r))
661
662 typedef struct ap_bucket_error ap_bucket_error;
663
664 /**
665  * A bucket referring to an HTTP error
666  * This bucket can be passed down the filter stack to indicate that an
667  * HTTP error occurred while running a filter.  In order for this bucket
668  * to be used successfully, it MUST be sent as the first bucket in the
669  * first brigade to be sent from a given filter.
670  */
671 struct ap_bucket_error {
672     /** Number of buckets using this memory */
673     apr_bucket_refcount refcount;
674     /** The error code */
675     int status;
676     /** The error string */
677     const char    *data;
678 };
679
680 AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_error;
681
682 /**
683  * Determine if a bucket is an error bucket
684  * @param e The bucket to inspect
685  * @return true or false
686  */
687 #define AP_BUCKET_IS_ERROR(e)         (e->type == &ap_bucket_type_error)
688
689 /**
690  * Make the bucket passed in an error bucket
691  * @param b The bucket to make into an error bucket
692  * @param error The HTTP error code to put in the bucket. 
693  * @param buf An optional error string to put in the bucket.
694  * @param p A pool to allocate out of.
695  * @return The new bucket, or NULL if allocation failed
696  * @deffunc apr_bucket *ap_bucket_error_make(apr_bucket *b, int error, const char *buf, apr_pool_t *p)
697  */
698 AP_DECLARE(apr_bucket *) ap_bucket_error_make(apr_bucket *b, int error,
699                 const char *buf, apr_pool_t *p);
700
701 /**
702  * Create a bucket referring to an HTTP error.
703  * @param error The HTTP error code to put in the bucket. 
704  * @param buf An optional error string to put in the bucket.
705  * @param p A pool to allocate the error string out of.
706  * @param list The bucket allocator from which to allocate the bucket
707  * @return The new bucket, or NULL if allocation failed
708  * @deffunc apr_bucket *ap_bucket_error_create(int error, const char *buf, apr_pool_t *p, apr_bucket_alloc_t *list)
709  */
710 AP_DECLARE(apr_bucket *) ap_bucket_error_create(int error, const char *buf,
711                                                 apr_pool_t *p,
712                                                 apr_bucket_alloc_t *list);
713
714 AP_DECLARE_NONSTD(apr_status_t) ap_byterange_filter(ap_filter_t *f, apr_bucket_brigade *b);
715 AP_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f, apr_bucket_brigade *b);
716 AP_DECLARE_NONSTD(apr_status_t) ap_content_length_filter(ap_filter_t *,
717                                                               apr_bucket_brigade *);
718 AP_DECLARE_NONSTD(apr_status_t) ap_old_write_filter(ap_filter_t *f, apr_bucket_brigade *b);
719
720 /*
721  * Setting up the protocol fields for subsidiary requests...
722  * Also, a wrapup function to keep the internal accounting straight.
723  */
724 void ap_set_sub_req_protocol(request_rec *rnew, const request_rec *r);
725 void ap_finalize_sub_req_protocol(request_rec *sub_r);
726                                                                                 
727 #ifdef __cplusplus
728 }
729 #endif
730
731 #endif  /* !APACHE_HTTP_PROTOCOL_H */