]> granicus.if.org Git - apache/blob - include/http_request.h
Added a new LDAPConnectionTimeout directive to util_ldap so that the socket connectio...
[apache] / include / http_request.h
1 /* Copyright 1999-2004 The Apache Software Foundation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef APACHE_HTTP_REQUEST_H
17 #define APACHE_HTTP_REQUEST_H
18
19 #include "apr_hooks.h"
20 #include "util_filter.h"
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #define AP_SUBREQ_NO_ARGS 0
27 #define AP_SUBREQ_MERGE_ARGS 1
28
29 /**
30  * @file http_request.h
31  * @brief Apache Request library
32  */
33
34 /* http_request.c is the code which handles the main line of request
35  * processing, once a request has been read in (finding the right per-
36  * directory configuration, building it if necessary, and calling all
37  * the module dispatch functions in the right order).
38  *
39  * The pieces here which are public to the modules, allow them to learn
40  * how the server would handle some other file or URI, or perhaps even
41  * direct the server to serve that other file instead of the one the
42  * client requested directly.
43  *
44  * There are two ways to do that.  The first is the sub_request mechanism,
45  * which handles looking up files and URIs as adjuncts to some other
46  * request (e.g., directory entries for multiviews and directory listings);
47  * the lookup functions stop short of actually running the request, but
48  * (e.g., for includes), a module may call for the request to be run
49  * by calling run_sub_req.  The space allocated to create sub_reqs can be
50  * reclaimed by calling destroy_sub_req --- be sure to copy anything you care
51  * about which was allocated in its apr_pool_t elsewhere before doing this.
52  */
53
54 /**
55  * An internal handler used by the ap_process_request, all subrequest mechanisms
56  * and the redirect mechanism.
57  * @param r The request, subrequest or internal redirect to pre-process
58  * @return The return code for the request
59  */
60 AP_DECLARE(int) ap_process_request_internal(request_rec *r);
61
62 /**
63  * Create a subrequest from the given URI.  This subrequest can be
64  * inspected to find information about the requested URI
65  * @param new_uri The URI to lookup
66  * @param r The current request
67  * @param next_filter The first filter the sub_request should use.  If this is
68  *                    NULL, it defaults to the first filter for the main request
69  * @return The new request record
70  * @deffunc request_rec * ap_sub_req_lookup_uri(const char *new_uri, const request_rec *r)
71  */
72 AP_DECLARE(request_rec *) ap_sub_req_lookup_uri(const char *new_uri,
73                                                 const request_rec *r,
74                                                 ap_filter_t *next_filter);
75
76 /**
77  * Create a subrequest for the given file.  This subrequest can be
78  * inspected to find information about the requested file
79  * @param new_file The file to lookup
80  * @param r The current request
81  * @param next_filter The first filter the sub_request should use.  If this is
82  *                    NULL, it defaults to the first filter for the main request
83  * @return The new request record
84  * @deffunc request_rec * ap_sub_req_lookup_file(const char *new_file, const request_rec *r)
85  */
86 AP_DECLARE(request_rec *) ap_sub_req_lookup_file(const char *new_file,
87                                               const request_rec *r,
88                                               ap_filter_t *next_filter);
89 /**
90  * Create a subrequest for the given apr_dir_read result.  This subrequest 
91  * can be inspected to find information about the requested file
92  * @param finfo The apr_dir_read result to lookup
93  * @param r The current request
94  * @param subtype What type of subrequest to perform, one of;
95  * <PRE>
96  *      AP_SUBREQ_NO_ARGS     ignore r->args and r->path_info
97  *      AP_SUBREQ_MERGE_ARGS  merge r->args and r->path_info
98  * </PRE>
99  * @param next_filter The first filter the sub_request should use.  If this is
100  *                    NULL, it defaults to the first filter for the main request
101  * @return The new request record
102  * @deffunc request_rec * ap_sub_req_lookup_dirent(apr_finfo_t *finfo, int subtype, const request_rec *r)
103  * @tip The apr_dir_read flags value APR_FINFO_MIN|APR_FINFO_NAME flag is the 
104  * minimum recommended query if the results will be passed to apr_dir_read.
105  * The file info passed must include the name, and must have the same relative
106  * directory as the current request.
107  */
108 AP_DECLARE(request_rec *) ap_sub_req_lookup_dirent(const apr_finfo_t *finfo,
109                                                    const request_rec *r,
110                                                    int subtype,
111                                                    ap_filter_t *next_filter);
112 /**
113  * Create a subrequest for the given URI using a specific method.  This
114  * subrequest can be inspected to find information about the requested URI
115  * @param method The method to use in the new subrequest
116  * @param new_uri The URI to lookup
117  * @param r The current request
118  * @param next_filter The first filter the sub_request should use.  If this is
119  *                    NULL, it defaults to the first filter for the main request
120  * @return The new request record
121  * @deffunc request_rec * ap_sub_req_method_uri(const char *method, const char *new_uri, const request_rec *r)
122  */
123 AP_DECLARE(request_rec *) ap_sub_req_method_uri(const char *method,
124                                                 const char *new_uri,
125                                                 const request_rec *r,
126                                                 ap_filter_t *next_filter);
127 /**
128  * An output filter to strip EOS buckets from sub-requests.  This always
129  * has to be inserted at the end of a sub-requests filter stack.
130  * @param f The current filter
131  * @param bb The brigade to filter
132  * @deffunc apr_status_t ap_sub_req_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
133  */
134 AP_CORE_DECLARE_NONSTD(apr_status_t) ap_sub_req_output_filter(ap_filter_t *f,
135                                                         apr_bucket_brigade *bb);
136
137 /**
138  * Run the handler for the subrequest
139  * @param r The subrequest to run
140  * @return The return code for the subrequest
141  * @deffunc int ap_run_sub_req(request_rec *r)
142  */
143 AP_DECLARE(int) ap_run_sub_req(request_rec *r);
144
145 /**
146  * Free the memory associated with a subrequest
147  * @param r The subrequest to finish
148  * @deffunc void ap_destroy_sub_req(request_rec *r)
149  */
150 AP_DECLARE(void) ap_destroy_sub_req(request_rec *r);
151
152 /*
153  * Then there's the case that you want some other request to be served
154  * as the top-level request INSTEAD of what the client requested directly.
155  * If so, call this from a handler, and then immediately return OK.
156  */
157
158 /**
159  * Redirect the current request to some other uri
160  * @param new_uri The URI to replace the current request with
161  * @param r The current request
162  * @deffunc void ap_internal_redirect(const char *new_uri, request_rec *r)
163  */
164 AP_DECLARE(void) ap_internal_redirect(const char *new_uri, request_rec *r);
165
166 /**
167  * This function is designed for things like actions or CGI scripts, when
168  * using AddHandler, and you want to preserve the content type across
169  * an internal redirect.
170  * @param new_uri The URI to replace the current request with.
171  * @param r The current request
172  * @deffunc void ap_internal_redirect_handler(const char *new_uri, request_rec *r)
173  */
174 AP_DECLARE(void) ap_internal_redirect_handler(const char *new_uri, request_rec *r);
175
176 /**
177  * Redirect the current request to a sub_req, merging the pools
178  * @param sub_req A subrequest created from this request
179  * @param r The current request
180  * @deffunc void ap_internal_fast_redirect(request_rec *sub_req, request_rec *r)
181  * @tip the sub_req's pool will be merged into r's pool, be very careful
182  * not to destroy this subrequest, it will be destroyed with the main request!
183  */
184 AP_DECLARE(void) ap_internal_fast_redirect(request_rec *sub_req, request_rec *r);
185
186 /**
187  * Can be used within any handler to determine if any authentication
188  * is required for the current request
189  * @param r The current request
190  * @return 1 if authentication is required, 0 otherwise
191  * @deffunc int ap_some_auth_required(request_rec *r)
192  */
193 AP_DECLARE(int) ap_some_auth_required(request_rec *r);
194  
195 /**
196  * Determine if the current request is the main request or a subrequest
197  * @param r The current request
198  * @return 1 if this is the main request, 0 otherwise
199  * @deffunc int ap_is_initial_req(request_rec *r)
200  */
201 AP_DECLARE(int) ap_is_initial_req(request_rec *r);
202
203 /**
204  * Function to set the r->mtime field to the specified value if it's later
205  * than what's already there.
206  * @param r The current request
207  * @param dependency_time Time to set the mtime to
208  * @deffunc void ap_update_mtime(request_rec *r, apr_time_t dependency_mtime)
209  */
210 AP_DECLARE(void) ap_update_mtime(request_rec *r, apr_time_t dependency_mtime);
211
212 /**
213  * Add one or more methods to the list permitted to access the resource.
214  * Usually executed by the content handler before the response header is
215  * sent, but sometimes invoked at an earlier phase if a module knows it
216  * can set the list authoritatively.  Note that the methods are ADDED
217  * to any already permitted unless the reset flag is non-zero.  The
218  * list is used to generate the Allow response header field when it
219  * is needed.
220  * @param   r     The pointer to the request identifying the resource.
221  * @param   reset Boolean flag indicating whether this list should
222  *                completely replace any current settings.
223  * @param   ...   A NULL-terminated list of strings, each identifying a
224  *                method name to add.
225  * @return  None.
226  * @deffunc void ap_allow_methods(request_rec *r, int reset, ...)
227  */
228 AP_DECLARE(void) ap_allow_methods(request_rec *r, int reset, ...);
229
230 /**
231  * Add one or more methods to the list permitted to access the resource.
232  * Usually executed by the content handler before the response header is
233  * sent, but sometimes invoked at an earlier phase if a module knows it
234  * can set the list authoritatively.  Note that the methods are ADDED
235  * to any already permitted unless the reset flag is non-zero.  The
236  * list is used to generate the Allow response header field when it
237  * is needed.
238  * @param   r     The pointer to the request identifying the resource.
239  * @param   reset Boolean flag indicating whether this list should
240  *                completely replace any current settings.
241  * @param   ...   A list of method identifiers, from the "M_" series
242  *                defined in httpd.h, terminated with a value of -1
243  *                (e.g., "M_GET, M_POST, M_OPTIONS, -1")
244  * @return  None.
245  * @deffunc void ap_allow_standard_methods(request_rec *r, int reset, ...)
246  */
247 AP_DECLARE(void) ap_allow_standard_methods(request_rec *r, int reset, ...);
248
249 #define MERGE_ALLOW 0
250 #define REPLACE_ALLOW 1
251
252 #ifdef CORE_PRIVATE
253 /* Function called by main.c to handle first-level request */
254 void ap_process_request(request_rec *);
255 /**
256  * Kill the current request
257  * @param type Why the request is dieing
258  * @param r The current request
259  * @deffunc void ap_die(int type, request_rec *r)
260  */
261 AP_DECLARE(void) ap_die(int type, request_rec *r);
262 #endif
263
264 /* Hooks */
265
266 /**
267  * Gives modules a chance to create their request_config entry when the
268  * request is created.
269  * @param r The current request
270  * @ingroup hooks
271  */
272 AP_DECLARE_HOOK(int,create_request,(request_rec *r))
273
274 /**
275  * This hook allow modules an opportunity to translate the URI into an
276  * actual filename.  If no modules do anything special, the server's default
277  * rules will be followed.
278  * @param r The current request
279  * @return OK, DECLINED, or HTTP_...
280  * @ingroup hooks
281  */
282 AP_DECLARE_HOOK(int,translate_name,(request_rec *r))
283
284 /**
285  * This hook allow modules to set the per_dir_config based on their own
286  * context (such as <Proxy > sections) and responds to contextless requests 
287  * such as TRACE that need no security or filesystem mapping.
288  * based on the filesystem.
289  * @param r The current request
290  * @return DONE (or HTTP_) if this contextless request was just fulfilled 
291  * (such as TRACE), OK if this is not a file, and DECLINED if this is a file.
292  * The core map_to_storage (HOOK_RUN_REALLY_LAST) will directory_walk
293  * and file_walk the r->filename.
294  * 
295  * @ingroup hooks
296  */
297 AP_DECLARE_HOOK(int,map_to_storage,(request_rec *r))
298
299 /**
300  * This hook is used to analyze the request headers, authenticate the user,
301  * and set the user information in the request record (r->user and
302  * r->ap_auth_type). This hook is only run when Apache determines that
303  * authentication/authorization is required for this resource (as determined
304  * by the 'Require' directive). It runs after the access_checker hook, and
305  * before the auth_checker hook.
306  *
307  * @param r The current request
308  * @return OK, DECLINED, or HTTP_...
309  * @ingroup hooks
310  */
311 AP_DECLARE_HOOK(int,check_user_id,(request_rec *r))
312
313 /**
314  * Allows modules to perform module-specific fixing of header fields.  This
315  * is invoked just before any content-handler
316  * @param r The current request
317  * @return OK, DECLINED, or HTTP_...
318  * @ingroup hooks
319  */
320 AP_DECLARE_HOOK(int,fixups,(request_rec *r))
321  
322 /**
323  * This routine is called to determine and/or set the various document type
324  * information bits, like Content-type (via r->content_type), language, et
325  * cetera.
326  * @param r the current request
327  * @return OK, DECLINED, or HTTP_...
328  * @ingroup hooks
329  */
330 AP_DECLARE_HOOK(int,type_checker,(request_rec *r))
331
332 /**
333  * This hook is used to apply additional access control to this resource.
334  * It runs *before* a user is authenticated, so this hook is really to
335  * apply additional restrictions independent of a user. It also runs
336  * independent of 'Require' directive usage.
337  *
338  * @param r the current request
339  * @return OK, DECLINED, or HTTP_...
340  * @ingroup hooks
341  */
342 AP_DECLARE_HOOK(int,access_checker,(request_rec *r))
343
344 /**
345  * This hook is used to check to see if the resource being requested
346  * is available for the authenticated user (r->user and r->ap_auth_type).
347  * It runs after the access_checker and check_user_id hooks. Note that
348  * it will *only* be called if Apache determines that access control has
349  * been applied to this resource (through a 'Require' directive).
350  *
351  * @param r the current request
352  * @return OK, DECLINED, or HTTP_...
353  * @ingroup hooks
354  */
355 AP_DECLARE_HOOK(int,auth_checker,(request_rec *r))
356
357 /**
358  * This hook allows modules to insert filters for the current request
359  * @param r the current request
360  * @ingroup hooks
361  */
362 AP_DECLARE_HOOK(void,insert_filter,(request_rec *r))
363
364 AP_DECLARE(int) ap_location_walk(request_rec *r);
365 AP_DECLARE(int) ap_directory_walk(request_rec *r);
366 AP_DECLARE(int) ap_file_walk(request_rec *r);
367
368 #ifdef __cplusplus
369 }
370 #endif
371
372 #endif  /* !APACHE_HTTP_REQUEST_H */