]> granicus.if.org Git - apache/blob - include/http_request.h
* include/http_request.h: Fix warning with gcc -Wall.
[apache] / 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 /**
18  * @file http_request.h
19  * @brief Apache Request library
20  *
21  * @defgroup APACHE_CORE_REQ Apache Request Processing
22  * @ingroup  APACHE_CORE
23  * @{
24  */
25
26 /*
27  * request.c is the code which handles the main line of request
28  * processing, once a request has been read in (finding the right per-
29  * directory configuration, building it if necessary, and calling all
30  * the module dispatch functions in the right order).
31  *
32  * The pieces here which are public to the modules, allow them to learn
33  * how the server would handle some other file or URI, or perhaps even
34  * direct the server to serve that other file instead of the one the
35  * client requested directly.
36  *
37  * There are two ways to do that.  The first is the sub_request mechanism,
38  * which handles looking up files and URIs as adjuncts to some other
39  * request (e.g., directory entries for multiviews and directory listings);
40  * the lookup functions stop short of actually running the request, but
41  * (e.g., for includes), a module may call for the request to be run
42  * by calling run_sub_req.  The space allocated to create sub_reqs can be
43  * reclaimed by calling destroy_sub_req --- be sure to copy anything you care
44  * about which was allocated in its apr_pool_t elsewhere before doing this.
45  */
46
47 #ifndef APACHE_HTTP_REQUEST_H
48 #define APACHE_HTTP_REQUEST_H
49
50 #include "apr_hooks.h"
51 #include "apr_optional.h"
52 #include "util_filter.h"
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58 #define AP_SUBREQ_NO_ARGS 0
59 #define AP_SUBREQ_MERGE_ARGS 1
60
61 /**
62  * An internal handler used by the ap_process_request, all subrequest mechanisms
63  * and the redirect mechanism.
64  * @param r The request, subrequest or internal redirect to pre-process
65  * @return The return code for the request
66  */
67 AP_DECLARE(int) ap_process_request_internal(request_rec *r);
68
69 /**
70  * Create a subrequest from the given URI.  This subrequest can be
71  * inspected to find information about the requested URI
72  * @param new_uri The URI to lookup
73  * @param r The current request
74  * @param next_filter The first filter the sub_request should use.  If this is
75  *                    NULL, it defaults to the first filter for the main request
76  * @return The new request record
77  */
78 AP_DECLARE(request_rec *) ap_sub_req_lookup_uri(const char *new_uri,
79                                                 const request_rec *r,
80                                                 ap_filter_t *next_filter);
81
82 /**
83  * Create a subrequest for the given file.  This subrequest can be
84  * inspected to find information about the requested file
85  * @param new_file The file to lookup
86  * @param r The current request
87  * @param next_filter The first filter the sub_request should use.  If this is
88  *                    NULL, it defaults to the first filter for the main request
89  * @return The new request record
90  */
91 AP_DECLARE(request_rec *) ap_sub_req_lookup_file(const char *new_file,
92                                               const request_rec *r,
93                                               ap_filter_t *next_filter);
94 /**
95  * Create a subrequest for the given apr_dir_read result.  This subrequest 
96  * can be inspected to find information about the requested file
97  * @param finfo The apr_dir_read result to lookup
98  * @param r The current request
99  * @param subtype What type of subrequest to perform, one of;
100  * <PRE>
101  *      AP_SUBREQ_NO_ARGS     ignore r->args and r->path_info
102  *      AP_SUBREQ_MERGE_ARGS  merge r->args and r->path_info
103  * </PRE>
104  * @param next_filter The first filter the sub_request should use.  If this is
105  *                    NULL, it defaults to the first filter for the main request
106  * @return The new request record
107  * @note The apr_dir_read flags value APR_FINFO_MIN|APR_FINFO_NAME flag is the 
108  * minimum recommended query if the results will be passed to apr_dir_read.
109  * The file info passed must include the name, and must have the same relative
110  * directory as the current request.
111  */
112 AP_DECLARE(request_rec *) ap_sub_req_lookup_dirent(const apr_finfo_t *finfo,
113                                                    const request_rec *r,
114                                                    int subtype,
115                                                    ap_filter_t *next_filter);
116 /**
117  * Create a subrequest for the given URI using a specific method.  This
118  * subrequest can be inspected to find information about the requested URI
119  * @param method The method to use in the new subrequest
120  * @param new_uri The URI to lookup
121  * @param r The current request
122  * @param next_filter The first filter the sub_request should use.  If this is
123  *                    NULL, it defaults to the first filter for the main request
124  * @return The new request record
125  */
126 AP_DECLARE(request_rec *) ap_sub_req_method_uri(const char *method,
127                                                 const char *new_uri,
128                                                 const request_rec *r,
129                                                 ap_filter_t *next_filter);
130 /**
131  * An output filter to strip EOS buckets from sub-requests.  This always
132  * has to be inserted at the end of a sub-requests filter stack.
133  * @param f The current filter
134  * @param bb The brigade to filter
135  * @return status code
136  */
137 AP_CORE_DECLARE_NONSTD(apr_status_t) ap_sub_req_output_filter(ap_filter_t *f,
138                                                         apr_bucket_brigade *bb);
139
140 /**
141  * Run the handler for the subrequest
142  * @param r The subrequest to run
143  * @return The return code for the subrequest
144  */
145 AP_DECLARE(int) ap_run_sub_req(request_rec *r);
146
147 /**
148  * Free the memory associated with a subrequest
149  * @param r The subrequest to finish
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  */
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  */
173 AP_DECLARE(void) ap_internal_redirect_handler(const char *new_uri, request_rec *r);
174
175 /**
176  * Redirect the current request to a sub_req, merging the pools
177  * @param sub_req A subrequest created from this request
178  * @param r The current request
179  * @note the sub_req's pool will be merged into r's pool, be very careful
180  * not to destroy this subrequest, it will be destroyed with the main request!
181  */
182 AP_DECLARE(void) ap_internal_fast_redirect(request_rec *sub_req, request_rec *r);
183
184 /**
185  * Can be used within any handler to determine if any authentication
186  * is required for the current request
187  * @param r The current request
188  * @return 1 if authentication is required, 0 otherwise
189  */
190 AP_DECLARE(int) ap_some_auth_required(request_rec *r);
191
192 /**
193  * @defgroup APACHE_CORE_REQ_AUTH Access Control for Sub-Requests and
194  *                                Internal Redirects
195  * @ingroup  APACHE_CORE_REQ
196  * @{
197  */
198
199 #define AP_AUTH_INTERNAL_PER_URI  0  /**< Run access control hooks on all
200                                           internal requests with URIs
201                                           distinct from that of initial
202                                           request */
203 #define AP_AUTH_INTERNAL_PER_CONF 1  /**< Run access control hooks only on
204                                           internal requests with
205                                           configurations distinct from
206                                           that of initial request */
207 #define AP_AUTH_INTERNAL_MASK     0x000F  /**< mask to extract internal request
208                                                processing mode */
209
210 /**
211  * Clear flag which determines when access control hooks will be run for
212  * internal requests.
213  */
214 AP_DECLARE(void) ap_clear_auth_internal(void);
215
216 /**
217  * Determine whether access control hooks will be run for all internal
218  * requests with URIs distinct from that of the initial request, or only
219  * those for which different configurations apply than those which applied
220  * to the initial request.  To accomodate legacy external modules which
221  * may expect access control hooks to be run for all internal requests
222  * with distinct URIs, this is the default behaviour unless all access
223  * control hooks and authentication and authorization providers are
224  * registered with AP_AUTH_INTERNAL_PER_CONF.
225  * @param ptemp Pool used for temporary allocations
226  */
227 AP_DECLARE(void) ap_setup_auth_internal(apr_pool_t *ptemp);
228
229 /**
230  * Register an authentication or authorization provider with the global
231  * provider pool.
232  * @param pool The pool to create any storage from
233  * @param provider_group The group to store the provider in
234  * @param provider_name The name for this provider
235  * @param provider_version The version for this provider
236  * @param provider Opaque structure for this provider
237  * @param type Internal request processing mode, either
238  *             AP_AUTH_INTERNAL_PER_URI or AP_AUTH_INTERNAL_PER_CONF
239  * @return APR_SUCCESS if all went well
240  */
241 AP_DECLARE(apr_status_t) ap_register_auth_provider(apr_pool_t *pool,
242                                                    const char *provider_group,
243                                                    const char *provider_name,
244                                                    const char *provider_version,
245                                                    const void *provider,
246                                                    int type);
247
248 /** @} */
249
250 /* Optional functions coming from mod_authn_core and mod_authz_core
251  * that list all registered authn/z providers.
252  */
253 APR_DECLARE_OPTIONAL_FN(apr_array_header_t *, authn_ap_list_provider_names,
254                         (apr_pool_t *ptemp));
255 APR_DECLARE_OPTIONAL_FN(apr_array_header_t *, authz_ap_list_provider_names,
256                         (apr_pool_t *ptemp));
257
258 /**
259  * Determine if the current request is the main request or a subrequest
260  * @param r The current request
261  * @return 1 if this is the main request, 0 otherwise
262  */
263 AP_DECLARE(int) ap_is_initial_req(request_rec *r);
264
265 /**
266  * Function to set the r->mtime field to the specified value if it's later
267  * than what's already there.
268  * @param r The current request
269  * @param dependency_mtime Time to set the mtime to
270  */
271 AP_DECLARE(void) ap_update_mtime(request_rec *r, apr_time_t dependency_mtime);
272
273 /**
274  * Add one or more methods to the list permitted to access the resource.
275  * Usually executed by the content handler before the response header is
276  * sent, but sometimes invoked at an earlier phase if a module knows it
277  * can set the list authoritatively.  Note that the methods are ADDED
278  * to any already permitted unless the reset flag is non-zero.  The
279  * list is used to generate the Allow response header field when it
280  * is needed.
281  * @param   r     The pointer to the request identifying the resource.
282  * @param   reset Boolean flag indicating whether this list should
283  *                completely replace any current settings.
284  * @param   ...   A NULL-terminated list of strings, each identifying a
285  *                method name to add.
286  * @return  None.
287  */
288 AP_DECLARE(void) ap_allow_methods(request_rec *r, int reset, ...);
289
290 /**
291  * Add one or more methods to the list permitted to access the resource.
292  * Usually executed by the content handler before the response header is
293  * sent, but sometimes invoked at an earlier phase if a module knows it
294  * can set the list authoritatively.  Note that the methods are ADDED
295  * to any already permitted unless the reset flag is non-zero.  The
296  * list is used to generate the Allow response header field when it
297  * is needed.
298  * @param   r     The pointer to the request identifying the resource.
299  * @param   reset Boolean flag indicating whether this list should
300  *                completely replace any current settings.
301  * @param   ...   A list of method identifiers, from the "M_" series
302  *                defined in httpd.h, terminated with a value of -1
303  *                (e.g., "M_GET, M_POST, M_OPTIONS, -1")
304  * @return  None.
305  */
306 AP_DECLARE(void) ap_allow_standard_methods(request_rec *r, int reset, ...);
307
308 #define MERGE_ALLOW 0
309 #define REPLACE_ALLOW 1
310
311 /**
312  * Process a top-level request from a client, and synchronously write
313  * the response to the client
314  * @param r The current request
315  */
316 void ap_process_request(request_rec *);
317
318 /**
319  * Process a top-level request from a client, allowing some or all of
320  * the response to remain buffered in the core output filter for later,
321  * asynchronous write completion
322  * @param r The current request
323  */
324 void ap_process_async_request(request_rec *);
325
326 /**
327  * Kill the current request
328  * @param type Why the request is dieing
329  * @param r The current request
330  */
331 AP_DECLARE(void) ap_die(int type, request_rec *r);
332
333 /* Hooks */
334
335 /**
336  * Gives modules a chance to create their request_config entry when the
337  * request is created.
338  * @param r The current request
339  * @ingroup hooks
340  */
341 AP_DECLARE_HOOK(int,create_request,(request_rec *r))
342
343 /**
344  * This hook allow modules an opportunity to translate the URI into an
345  * actual filename.  If no modules do anything special, the server's default
346  * rules will be followed.
347  * @param r The current request
348  * @return OK, DECLINED, or HTTP_...
349  * @ingroup hooks
350  */
351 AP_DECLARE_HOOK(int,translate_name,(request_rec *r))
352
353 /**
354  * This hook allow modules to set the per_dir_config based on their own
355  * context (such as "<Proxy>" sections) and responds to contextless requests 
356  * such as TRACE that need no security or filesystem mapping.
357  * based on the filesystem.
358  * @param r The current request
359  * @return DONE (or HTTP_) if this contextless request was just fulfilled 
360  * (such as TRACE), OK if this is not a file, and DECLINED if this is a file.
361  * The core map_to_storage (HOOK_RUN_REALLY_LAST) will directory_walk
362  * and file_walk the r->filename.
363  * 
364  * @ingroup hooks
365  */
366 AP_DECLARE_HOOK(int,map_to_storage,(request_rec *r))
367
368 /**
369  * This hook is used to analyze the request headers, authenticate the user,
370  * and set the user information in the request record (r->user and
371  * r->ap_auth_type). This hook is only run when Apache determines that
372  * authentication/authorization is required for this resource (as determined
373  * by the 'Require' directive). It runs after the access_checker hook, and
374  * before the auth_checker hook. This hook should be registered with
375  * ap_hook_check_authn().
376  *
377  * @param r The current request
378  * @return OK, DECLINED, or HTTP_...
379  * @ingroup hooks
380  * @see ap_hook_check_authn
381  */
382 AP_DECLARE_HOOK(int,check_user_id,(request_rec *r))
383
384 /**
385  * Allows modules to perform module-specific fixing of header fields.  This
386  * is invoked just before any content-handler
387  * @param r The current request
388  * @return OK, DECLINED, or HTTP_...
389  * @ingroup hooks
390  */
391 AP_DECLARE_HOOK(int,fixups,(request_rec *r))
392  
393 /**
394  * This routine is called to determine and/or set the various document type
395  * information bits, like Content-type (via r->content_type), language, et
396  * cetera.
397  * @param r the current request
398  * @return OK, DECLINED, or HTTP_...
399  * @ingroup hooks
400  */
401 AP_DECLARE_HOOK(int,type_checker,(request_rec *r))
402
403 /**
404  * This hook is used to apply additional access control to this resource.
405  * It runs *before* a user is authenticated, so this hook is really to
406  * apply additional restrictions independent of a user. It also runs
407  * independent of 'Require' directive usage. This hook should be registered
408  * with ap_hook_check_access().
409  *
410  * @param r the current request
411  * @return OK, DECLINED, or HTTP_...
412  * @ingroup hooks
413  * @see ap_hook_check_access
414  */
415 AP_DECLARE_HOOK(int,access_checker,(request_rec *r))
416
417 /**
418  * This hook is used to check to see if the resource being requested
419  * is available for the authenticated user (r->user and r->ap_auth_type).
420  * It runs after the access_checker and check_user_id hooks. Note that
421  * it will *only* be called if Apache determines that access control has
422  * been applied to this resource (through a 'Require' directive). This
423  * hook should be registered with ap_hook_check_authz().
424  *
425  * @param r the current request
426  * @return OK, DECLINED, or HTTP_...
427  * @ingroup hooks
428  * @see ap_hook_check_authz
429  */
430 AP_DECLARE_HOOK(int,auth_checker,(request_rec *r))
431
432 /**
433  * Register a hook function that will apply additional access control to
434  * the current request.
435  * @param pf An access_checker hook function
436  * @param aszPre A NULL-terminated array of strings that name modules whose
437  *               hooks should precede this one
438  * @param aszSucc A NULL-terminated array of strings that name modules whose
439  *                hooks should succeed this one
440  * @param nOrder An integer determining order before honouring aszPre and
441  *               aszSucc (for example, HOOK_MIDDLE)
442  * @param type Internal request processing mode, either
443  *             AP_AUTH_INTERNAL_PER_URI or AP_AUTH_INTERNAL_PER_CONF
444  */
445 AP_DECLARE(void) ap_hook_check_access(ap_HOOK_access_checker_t *pf,
446                                       const char * const *aszPre,
447                                       const char * const *aszSucc,
448                                       int nOrder, int type);
449
450 /**
451  * Register a hook function that will analyze the request headers,
452  * authenticate the user, and set the user information in the request record.
453  * @param pf A check_user_id hook function
454  * @param aszPre A NULL-terminated array of strings that name modules whose
455  *               hooks should precede this one
456  * @param aszSucc A NULL-terminated array of strings that name modules whose
457  *                hooks should succeed this one
458  * @param nOrder An integer determining order before honouring aszPre and
459  *               aszSucc (for example, HOOK_MIDDLE)
460  * @param type Internal request processing mode, either
461  *             AP_AUTH_INTERNAL_PER_URI or AP_AUTH_INTERNAL_PER_CONF
462  */
463 AP_DECLARE(void) ap_hook_check_authn(ap_HOOK_check_user_id_t *pf,
464                                      const char * const *aszPre,
465                                      const char * const *aszSucc,
466                                      int nOrder, int type);
467
468 /**
469  * Register a hook function that determine if the resource being requested
470  * is available for the currently authenticated user.
471  * @param pf An auth_checker hook function
472  * @param aszPre A NULL-terminated array of strings that name modules whose
473  *               hooks should precede this one
474  * @param aszSucc A NULL-terminated array of strings that name modules whose
475  *                hooks should succeed this one
476  * @param nOrder An integer determining order before honouring aszPre and
477  *               aszSucc (for example, HOOK_MIDDLE)
478  * @param type Internal request processing mode, either
479  *             AP_AUTH_INTERNAL_PER_URI or AP_AUTH_INTERNAL_PER_CONF
480  */
481 AP_DECLARE(void) ap_hook_check_authz(ap_HOOK_auth_checker_t *pf,
482                                      const char * const *aszPre,
483                                      const char * const *aszSucc,
484                                      int nOrder, int type);
485
486 /**
487  * This hook allows modules to insert filters for the current request
488  * @param r the current request
489  * @ingroup hooks
490  */
491 AP_DECLARE_HOOK(void,insert_filter,(request_rec *r))
492
493 AP_DECLARE(int) ap_location_walk(request_rec *r);
494 AP_DECLARE(int) ap_directory_walk(request_rec *r);
495 AP_DECLARE(int) ap_file_walk(request_rec *r);
496
497 /** End Of REQUEST (EOR) bucket */
498 AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_eor;
499
500 /**
501  * Determine if a bucket is an End Of REQUEST (EOR) bucket
502  * @param e The bucket to inspect
503  * @return true or false
504  */
505 #define AP_BUCKET_IS_EOR(e)         (e->type == &ap_bucket_type_eor)
506
507 /**
508  * Make the bucket passed in an End Of REQUEST (EOR) bucket
509  * @param b The bucket to make into an EOR bucket
510  * @param r The request to destroy when this bucket is destroyed
511  * @return The new bucket, or NULL if allocation failed
512  */
513 AP_DECLARE(apr_bucket *) ap_bucket_eor_make(apr_bucket *b, request_rec *r);
514
515 /**
516  * Create a bucket referring to an End Of REQUEST (EOR). This bucket
517  * holds a pointer to the request_rec, so that the request can be
518  * destroyed right after all of the output has been sent to the client.
519  *
520  * @param list The freelist from which this bucket should be allocated
521  * @param r The request to destroy when this bucket is destroyed
522  * @return The new bucket, or NULL if allocation failed
523  */
524 AP_DECLARE(apr_bucket *) ap_bucket_eor_create(apr_bucket_alloc_t *list,
525                                               request_rec *r);
526
527 #ifdef __cplusplus
528 }
529 #endif
530
531 #endif  /* !APACHE_HTTP_REQUEST_H */
532 /** @} */