Synchronize local git repo with remote git repo
[httpd-crcsyncproxy.git] / include / http_request.h
blobde87d99742c4065b4b4020594eedde925690c5f0
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 /**
18 * @file http_request.h
19 * @brief Apache Request library
21 * @defgroup APACHE_CORE_REQ Apache Request Processing
22 * @ingroup APACHE_CORE
23 * @{
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).
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.
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.
47 #ifndef APACHE_HTTP_REQUEST_H
48 #define APACHE_HTTP_REQUEST_H
50 #include "apr_hooks.h"
51 #include "apr_optional.h"
52 #include "util_filter.h"
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
58 #define AP_SUBREQ_NO_ARGS 0
59 #define AP_SUBREQ_MERGE_ARGS 1
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
67 AP_DECLARE(int) ap_process_request_internal(request_rec *r);
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
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);
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
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.
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);
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
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);
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
137 AP_CORE_DECLARE_NONSTD(apr_status_t) ap_sub_req_output_filter(ap_filter_t *f,
138 apr_bucket_brigade *bb);
141 * Run the handler for the subrequest
142 * @param r The subrequest to run
143 * @return The return code for the subrequest
145 AP_DECLARE(int) ap_run_sub_req(request_rec *r);
148 * Free the memory associated with a subrequest
149 * @param r The subrequest to finish
151 AP_DECLARE(void) ap_destroy_sub_req(request_rec *r);
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.
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
164 AP_DECLARE(void) ap_internal_redirect(const char *new_uri, request_rec *r);
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
173 AP_DECLARE(void) ap_internal_redirect_handler(const char *new_uri, request_rec *r);
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!
182 AP_DECLARE(void) ap_internal_fast_redirect(request_rec *sub_req, request_rec *r);
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
190 AP_DECLARE(int) ap_some_auth_required(request_rec *r);
193 * @defgroup APACHE_CORE_REQ_AUTH Access Control for Sub-Requests and
194 * Internal Redirects
195 * @ingroup APACHE_CORE_REQ
196 * @{
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 */
211 * Clear flag which determines when access control hooks will be run for
212 * internal requests.
214 AP_DECLARE(void) ap_clear_auth_internal(void);
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
227 AP_DECLARE(void) ap_setup_auth_internal(apr_pool_t *ptemp);
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
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);
248 /** @} */
250 /* Optional functions coming from mod_authn_core and mod_authz_core
251 * that list all registered authn/z providers.
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));
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
263 AP_DECLARE(int) ap_is_initial_req(request_rec *r);
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
271 AP_DECLARE(void) ap_update_mtime(request_rec *r, apr_time_t dependency_mtime);
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.
288 AP_DECLARE(void) ap_allow_methods(request_rec *r, int reset, ...);
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.
306 AP_DECLARE(void) ap_allow_standard_methods(request_rec *r, int reset, ...);
308 #define MERGE_ALLOW 0
309 #define REPLACE_ALLOW 1
312 * Process a top-level request from a client, and synchronously write
313 * the response to the client
314 * @param r The current request
316 void ap_process_request(request_rec *);
318 /* For post-processing after a handler has finished with a request. (Commonly used after it was suspended) */
319 void ap_process_request_after_handler(request_rec *r);
322 * Process a top-level request from a client, allowing some or all of
323 * the response to remain buffered in the core output filter for later,
324 * asynchronous write completion
325 * @param r The current request
327 void ap_process_async_request(request_rec *);
330 * Kill the current request
331 * @param type Why the request is dieing
332 * @param r The current request
334 AP_DECLARE(void) ap_die(int type, request_rec *r);
336 /* Hooks */
339 * Gives modules a chance to create their request_config entry when the
340 * request is created.
341 * @param r The current request
342 * @ingroup hooks
344 AP_DECLARE_HOOK(int,create_request,(request_rec *r))
347 * This hook allow modules an opportunity to translate the URI into an
348 * actual filename. If no modules do anything special, the server's default
349 * rules will be followed.
350 * @param r The current request
351 * @return OK, DECLINED, or HTTP_...
352 * @ingroup hooks
354 AP_DECLARE_HOOK(int,translate_name,(request_rec *r))
357 * This hook allow modules to set the per_dir_config based on their own
358 * context (such as "<Proxy>" sections) and responds to contextless requests
359 * such as TRACE that need no security or filesystem mapping.
360 * based on the filesystem.
361 * @param r The current request
362 * @return DONE (or HTTP_) if this contextless request was just fulfilled
363 * (such as TRACE), OK if this is not a file, and DECLINED if this is a file.
364 * The core map_to_storage (HOOK_RUN_REALLY_LAST) will directory_walk
365 * and file_walk the r->filename.
367 * @ingroup hooks
369 AP_DECLARE_HOOK(int,map_to_storage,(request_rec *r))
372 * This hook is used to analyze the request headers, authenticate the user,
373 * and set the user information in the request record (r->user and
374 * r->ap_auth_type). This hook is only run when Apache determines that
375 * authentication/authorization is required for this resource (as determined
376 * by the 'Require' directive). It runs after the access_checker hook, and
377 * before the auth_checker hook. This hook should be registered with
378 * ap_hook_check_authn().
380 * @param r The current request
381 * @return OK, DECLINED, or HTTP_...
382 * @ingroup hooks
383 * @see ap_hook_check_authn
385 AP_DECLARE_HOOK(int,check_user_id,(request_rec *r))
388 * Allows modules to perform module-specific fixing of header fields. This
389 * is invoked just before any content-handler
390 * @param r The current request
391 * @return OK, DECLINED, or HTTP_...
392 * @ingroup hooks
394 AP_DECLARE_HOOK(int,fixups,(request_rec *r))
397 * This routine is called to determine and/or set the various document type
398 * information bits, like Content-type (via r->content_type), language, et
399 * cetera.
400 * @param r the current request
401 * @return OK, DECLINED, or HTTP_...
402 * @ingroup hooks
404 AP_DECLARE_HOOK(int,type_checker,(request_rec *r))
407 * This hook is used to apply additional access control to this resource.
408 * It runs *before* a user is authenticated, so this hook is really to
409 * apply additional restrictions independent of a user. It also runs
410 * independent of 'Require' directive usage. This hook should be registered
411 * with ap_hook_check_access().
413 * @param r the current request
414 * @return OK, DECLINED, or HTTP_...
415 * @ingroup hooks
416 * @see ap_hook_check_access
418 AP_DECLARE_HOOK(int,access_checker,(request_rec *r))
421 * This hook is used to check to see if the resource being requested
422 * is available for the authenticated user (r->user and r->ap_auth_type).
423 * It runs after the access_checker and check_user_id hooks. Note that
424 * it will *only* be called if Apache determines that access control has
425 * been applied to this resource (through a 'Require' directive). This
426 * hook should be registered with ap_hook_check_authz().
428 * @param r the current request
429 * @return OK, DECLINED, or HTTP_...
430 * @ingroup hooks
431 * @see ap_hook_check_authz
433 AP_DECLARE_HOOK(int,auth_checker,(request_rec *r))
436 * Register a hook function that will apply additional access control to
437 * the current request.
438 * @param pf An access_checker hook function
439 * @param aszPre A NULL-terminated array of strings that name modules whose
440 * hooks should precede this one
441 * @param aszSucc A NULL-terminated array of strings that name modules whose
442 * hooks should succeed this one
443 * @param nOrder An integer determining order before honouring aszPre and
444 * aszSucc (for example, HOOK_MIDDLE)
445 * @param type Internal request processing mode, either
446 * AP_AUTH_INTERNAL_PER_URI or AP_AUTH_INTERNAL_PER_CONF
448 AP_DECLARE(void) ap_hook_check_access(ap_HOOK_access_checker_t *pf,
449 const char * const *aszPre,
450 const char * const *aszSucc,
451 int nOrder, int type);
454 * Register a hook function that will analyze the request headers,
455 * authenticate the user, and set the user information in the request record.
456 * @param pf A check_user_id hook function
457 * @param aszPre A NULL-terminated array of strings that name modules whose
458 * hooks should precede this one
459 * @param aszSucc A NULL-terminated array of strings that name modules whose
460 * hooks should succeed this one
461 * @param nOrder An integer determining order before honouring aszPre and
462 * aszSucc (for example, HOOK_MIDDLE)
463 * @param type Internal request processing mode, either
464 * AP_AUTH_INTERNAL_PER_URI or AP_AUTH_INTERNAL_PER_CONF
466 AP_DECLARE(void) ap_hook_check_authn(ap_HOOK_check_user_id_t *pf,
467 const char * const *aszPre,
468 const char * const *aszSucc,
469 int nOrder, int type);
472 * Register a hook function that determine if the resource being requested
473 * is available for the currently authenticated user.
474 * @param pf An auth_checker hook function
475 * @param aszPre A NULL-terminated array of strings that name modules whose
476 * hooks should precede this one
477 * @param aszSucc A NULL-terminated array of strings that name modules whose
478 * hooks should succeed this one
479 * @param nOrder An integer determining order before honouring aszPre and
480 * aszSucc (for example, HOOK_MIDDLE)
481 * @param type Internal request processing mode, either
482 * AP_AUTH_INTERNAL_PER_URI or AP_AUTH_INTERNAL_PER_CONF
484 AP_DECLARE(void) ap_hook_check_authz(ap_HOOK_auth_checker_t *pf,
485 const char * const *aszPre,
486 const char * const *aszSucc,
487 int nOrder, int type);
490 * This hook allows modules to insert filters for the current request
491 * @param r the current request
492 * @ingroup hooks
494 AP_DECLARE_HOOK(void,insert_filter,(request_rec *r))
496 AP_DECLARE(int) ap_location_walk(request_rec *r);
497 AP_DECLARE(int) ap_directory_walk(request_rec *r);
498 AP_DECLARE(int) ap_file_walk(request_rec *r);
500 /** End Of REQUEST (EOR) bucket */
501 AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_eor;
504 * Determine if a bucket is an End Of REQUEST (EOR) bucket
505 * @param e The bucket to inspect
506 * @return true or false
508 #define AP_BUCKET_IS_EOR(e) (e->type == &ap_bucket_type_eor)
511 * Make the bucket passed in an End Of REQUEST (EOR) bucket
512 * @param b The bucket to make into an EOR bucket
513 * @param r The request to destroy when this bucket is destroyed
514 * @return The new bucket, or NULL if allocation failed
516 AP_DECLARE(apr_bucket *) ap_bucket_eor_make(apr_bucket *b, request_rec *r);
519 * Create a bucket referring to an End Of REQUEST (EOR). This bucket
520 * holds a pointer to the request_rec, so that the request can be
521 * destroyed right after all of the output has been sent to the client.
523 * @param list The freelist from which this bucket should be allocated
524 * @param r The request to destroy when this bucket is destroyed
525 * @return The new bucket, or NULL if allocation failed
527 AP_DECLARE(apr_bucket *) ap_bucket_eor_create(apr_bucket_alloc_t *list,
528 request_rec *r);
530 #ifdef __cplusplus
532 #endif
534 #endif /* !APACHE_HTTP_REQUEST_H */
535 /** @} */