]> granicus.if.org Git - apache/blob - include/http_request.h
gcc compatibility
[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 *r);
317
318 /* For post-processing after a handler has finished with a request. 
319  * (Commonly used after it was suspended)
320  */
321 AP_DECLARE(void) ap_process_request_after_handler(request_rec *r);
322
323 /**
324  * Process a top-level request from a client, allowing some or all of
325  * the response to remain buffered in the core output filter for later,
326  * asynchronous write completion
327  * @param r The current request
328  */
329 void ap_process_async_request(request_rec *r);
330
331 /**
332  * Kill the current request
333  * @param type Why the request is dieing
334  * @param r The current request
335  */
336 AP_DECLARE(void) ap_die(int type, request_rec *r);
337
338 /* Hooks */
339
340 /**
341  * Gives modules a chance to create their request_config entry when the
342  * request is created.
343  * @param r The current request
344  * @ingroup hooks
345  */
346 AP_DECLARE_HOOK(int,create_request,(request_rec *r))
347
348 /**
349  * This hook allow modules an opportunity to translate the URI into an
350  * actual filename.  If no modules do anything special, the server's default
351  * rules will be followed.
352  * @param r The current request
353  * @return OK, DECLINED, or HTTP_...
354  * @ingroup hooks
355  */
356 AP_DECLARE_HOOK(int,translate_name,(request_rec *r))
357
358 /**
359  * This hook allow modules to set the per_dir_config based on their own
360  * context (such as "<Proxy>" sections) and responds to contextless requests 
361  * such as TRACE that need no security or filesystem mapping.
362  * based on the filesystem.
363  * @param r The current request
364  * @return DONE (or HTTP_) if this contextless request was just fulfilled 
365  * (such as TRACE), OK if this is not a file, and DECLINED if this is a file.
366  * The core map_to_storage (HOOK_RUN_REALLY_LAST) will directory_walk
367  * and file_walk the r->filename.
368  * 
369  * @ingroup hooks
370  */
371 AP_DECLARE_HOOK(int,map_to_storage,(request_rec *r))
372
373 /**
374  * This hook is used to analyze the request headers, authenticate the user,
375  * and set the user information in the request record (r->user and
376  * r->ap_auth_type). This hook is only run when Apache determines that
377  * authentication/authorization is required for this resource (as determined
378  * by the 'Require' directive). It runs after the access_checker hook, and
379  * before the auth_checker hook. This hook should be registered with
380  * ap_hook_check_authn().
381  *
382  * @param r The current request
383  * @return OK, DECLINED, or HTTP_...
384  * @ingroup hooks
385  * @see ap_hook_check_authn
386  */
387 AP_DECLARE_HOOK(int,check_user_id,(request_rec *r))
388
389 /**
390  * Allows modules to perform module-specific fixing of header fields.  This
391  * is invoked just before any content-handler
392  * @param r The current request
393  * @return OK, DECLINED, or HTTP_...
394  * @ingroup hooks
395  */
396 AP_DECLARE_HOOK(int,fixups,(request_rec *r))
397  
398 /**
399  * This routine is called to determine and/or set the various document type
400  * information bits, like Content-type (via r->content_type), language, et
401  * cetera.
402  * @param r the current request
403  * @return OK, DECLINED, or HTTP_...
404  * @ingroup hooks
405  */
406 AP_DECLARE_HOOK(int,type_checker,(request_rec *r))
407
408 /**
409  * This hook is used to apply additional access control to this resource.
410  * It runs *before* a user is authenticated, so this hook is really to
411  * apply additional restrictions independent of a user. It also runs
412  * independent of 'Require' directive usage. This hook should be registered
413  * with ap_hook_check_access().
414  *
415  * @param r the current request
416  * @return OK, DECLINED, or HTTP_...
417  * @ingroup hooks
418  * @see ap_hook_check_access
419  */
420 AP_DECLARE_HOOK(int,access_checker,(request_rec *r))
421
422 /**
423  * This hook is used to apply additional access control and/or bypass
424  * authentication for this resource. It runs *before* a user is authenticated,
425  * but after the auth_checker hook.
426  * This hook should be registered with ap_hook_check_access_ex().
427  *
428  * @param r the current request
429  * @return OK (allow acces), DECLINED (let later modules decide),
430  *         or HTTP_... (deny access)
431  * @ingroup hooks
432  * @see ap_hook_check_access_ex
433  */
434 AP_DECLARE_HOOK(int,access_checker_ex,(request_rec *r))
435
436 /**
437  * This hook is used to check to see if the resource being requested
438  * is available for the authenticated user (r->user and r->ap_auth_type).
439  * It runs after the access_checker and check_user_id hooks. Note that
440  * it will *only* be called if Apache determines that access control has
441  * been applied to this resource (through a 'Require' directive). This
442  * hook should be registered with ap_hook_check_authz().
443  *
444  * @param r the current request
445  * @return OK, DECLINED, or HTTP_...
446  * @ingroup hooks
447  * @see ap_hook_check_authz
448  */
449 AP_DECLARE_HOOK(int,auth_checker,(request_rec *r))
450
451 /**
452  * Register a hook function that will apply additional access control to
453  * the current request.
454  * @param pf An access_checker hook function
455  * @param aszPre A NULL-terminated array of strings that name modules whose
456  *               hooks should precede this one
457  * @param aszSucc A NULL-terminated array of strings that name modules whose
458  *                hooks should succeed this one
459  * @param nOrder An integer determining order before honouring aszPre and
460  *               aszSucc (for example, HOOK_MIDDLE)
461  * @param type Internal request processing mode, either
462  *             AP_AUTH_INTERNAL_PER_URI or AP_AUTH_INTERNAL_PER_CONF
463  */
464 AP_DECLARE(void) ap_hook_check_access(ap_HOOK_access_checker_t *pf,
465                                       const char * const *aszPre,
466                                       const char * const *aszSucc,
467                                       int nOrder, int type);
468
469 /**
470  * Register a hook function that will apply additional access control 
471  * and/or bypass authentication for the current request.
472  * @param pf An access_checker_ex hook function
473  * @param aszPre A NULL-terminated array of strings that name modules whose
474  *               hooks should precede this one
475  * @param aszSucc A NULL-terminated array of strings that name modules whose
476  *                hooks should succeed this one
477  * @param nOrder An integer determining order before honouring aszPre and
478  *               aszSucc (for example, HOOK_MIDDLE)
479  * @param type Internal request processing mode, either
480  *             AP_AUTH_INTERNAL_PER_URI or AP_AUTH_INTERNAL_PER_CONF
481  */
482 AP_DECLARE(void) ap_hook_check_access_ex(ap_HOOK_access_checker_ex_t *pf,
483                                          const char * const *aszPre,
484                                          const char * const *aszSucc,
485                                          int nOrder, int type);
486
487
488 /**
489  * Register a hook function that will analyze the request headers,
490  * authenticate the user, and set the user information in the request record.
491  * @param pf A check_user_id hook function
492  * @param aszPre A NULL-terminated array of strings that name modules whose
493  *               hooks should precede this one
494  * @param aszSucc A NULL-terminated array of strings that name modules whose
495  *                hooks should succeed this one
496  * @param nOrder An integer determining order before honouring aszPre and
497  *               aszSucc (for example, HOOK_MIDDLE)
498  * @param type Internal request processing mode, either
499  *             AP_AUTH_INTERNAL_PER_URI or AP_AUTH_INTERNAL_PER_CONF
500  */
501 AP_DECLARE(void) ap_hook_check_authn(ap_HOOK_check_user_id_t *pf,
502                                      const char * const *aszPre,
503                                      const char * const *aszSucc,
504                                      int nOrder, int type);
505
506 /**
507  * Register a hook function that determine if the resource being requested
508  * is available for the currently authenticated user.
509  * @param pf An auth_checker hook function
510  * @param aszPre A NULL-terminated array of strings that name modules whose
511  *               hooks should precede this one
512  * @param aszSucc A NULL-terminated array of strings that name modules whose
513  *                hooks should succeed this one
514  * @param nOrder An integer determining order before honouring aszPre and
515  *               aszSucc (for example, HOOK_MIDDLE)
516  * @param type Internal request processing mode, either
517  *             AP_AUTH_INTERNAL_PER_URI or AP_AUTH_INTERNAL_PER_CONF
518  */
519 AP_DECLARE(void) ap_hook_check_authz(ap_HOOK_auth_checker_t *pf,
520                                      const char * const *aszPre,
521                                      const char * const *aszSucc,
522                                      int nOrder, int type);
523
524 /**
525  * This hook allows modules to insert filters for the current request
526  * @param r the current request
527  * @ingroup hooks
528  */
529 AP_DECLARE_HOOK(void,insert_filter,(request_rec *r))
530
531 AP_DECLARE(int) ap_location_walk(request_rec *r);
532 AP_DECLARE(int) ap_directory_walk(request_rec *r);
533 AP_DECLARE(int) ap_file_walk(request_rec *r);
534 AP_DECLARE(int) ap_if_walk(request_rec *r);
535
536 /** End Of REQUEST (EOR) bucket */
537 AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_eor;
538
539 /**
540  * Determine if a bucket is an End Of REQUEST (EOR) bucket
541  * @param e The bucket to inspect
542  * @return true or false
543  */
544 #define AP_BUCKET_IS_EOR(e)         (e->type == &ap_bucket_type_eor)
545
546 /**
547  * Make the bucket passed in an End Of REQUEST (EOR) bucket
548  * @param b The bucket to make into an EOR bucket
549  * @param r The request to destroy when this bucket is destroyed
550  * @return The new bucket, or NULL if allocation failed
551  */
552 AP_DECLARE(apr_bucket *) ap_bucket_eor_make(apr_bucket *b, request_rec *r);
553
554 /**
555  * Create a bucket referring to an End Of REQUEST (EOR). This bucket
556  * holds a pointer to the request_rec, so that the request can be
557  * destroyed right after all of the output has been sent to the client.
558  *
559  * @param list The freelist from which this bucket should be allocated
560  * @param r The request to destroy when this bucket is destroyed
561  * @return The new bucket, or NULL if allocation failed
562  */
563 AP_DECLARE(apr_bucket *) ap_bucket_eor_create(apr_bucket_alloc_t *list,
564                                               request_rec *r);
565
566 #ifdef __cplusplus
567 }
568 #endif
569
570 #endif  /* !APACHE_HTTP_REQUEST_H */
571 /** @} */