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