1{ Copyright 1999-2005 The Apache Software Foundation or its licensors, as 2 * applicable. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * 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{#include "apr_hooks.h" 18#include "util_filter.h"} 19 20const 21 AP_SUBREQ_NO_ARGS = 0; 22 AP_SUBREQ_MERGE_ARGS = 1; 23 24{ 25 * @file http_request.h 26 * @brief Apache Request library 27 } 28 29{ http_request.c is the code which handles the main line of request 30 * processing, once a request has been read in (finding the right per- 31 * directory configuration, building it if necessary, and calling all 32 * the module dispatch functions in the right order). 33 * 34 * The pieces here which are public to the modules, allow them to learn 35 * how the server would handle some other file or URI, or perhaps even 36 * direct the server to serve that other file instead of the one the 37 * client requested directly. 38 * 39 * There are two ways to do that. The first is the sub_request mechanism, 40 * which handles looking up files and URIs as adjuncts to some other 41 * request (e.g., directory entries for multiviews and directory listings); 42 * the lookup functions stop short of actually running the request, but 43 * (e.g., for includes), a module may call for the request to be run 44 * by calling run_sub_req. The space allocated to create sub_reqs can be 45 * reclaimed by calling destroy_sub_req --- be sure to copy anything you care 46 * about which was allocated in its apr_pool_t elsewhere before doing this. 47 } 48 49{ 50 * An internal handler used by the ap_process_request, all subrequest mechanisms 51 * and the redirect mechanism. 52 * @param r The request, subrequest or internal redirect to pre-process 53 * @return The return code for the request 54 } 55function ap_process_request_internal(r: Prequest_rec): Integer; 56 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 57 external LibHTTPD name LibNamePrefix + 'ap_process_request_internal' + LibSuff4; 58 59{ 60 * Create a subrequest from the given URI. This subrequest can be 61 * inspected to find information about the requested URI 62 * @param new_uri The URI to lookup 63 * @param r The current request 64 * @param next_filter The first filter the sub_request should use. If this is 65 * NULL, it defaults to the first filter for the main request 66 * @return The new request record 67 * @deffunc request_rec * ap_sub_req_lookup_uri(const char *new_uri, const request_rec *r) 68 } 69function ap_sub_req_lookup_uri(const new_uri: PChar; 70 const r: Prequest_rec; next_filter: Pap_filter_t): Prequest_rec; 71 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 72 external LibHTTPD name LibNamePrefix + 'ap_sub_req_lookup_uri' + LibSuff12; 73 74{ 75 * Create a subrequest for the given file. This subrequest can be 76 * inspected to find information about the requested file 77 * @param new_file The file to lookup 78 * @param r The current request 79 * @param next_filter The first filter the sub_request should use. If this is 80 * NULL, it defaults to the first filter for the main request 81 * @return The new request record 82 * @deffunc request_rec * ap_sub_req_lookup_file(const char *new_file, const request_rec *r) 83 } 84function ap_sub_req_lookup_file(const new_file: PChar; 85 const r: Prequest_rec; next_filter: Pap_filter_t): Prequest_rec; 86 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 87 external LibHTTPD name LibNamePrefix + 'ap_sub_req_lookup_file' + LibSuff12; 88 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 } 108function ap_sub_req_lookup_dirent(const finfo: Papr_finfo_t; 109 const r: Prequest_rec; subtype: Integer; next_filter: Pap_filter_t): Prequest_rec; 110 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 111 external LibHTTPD name LibNamePrefix + 'ap_sub_req_lookup_dirent' + LibSuff16; 112 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 } 124function ap_sub_req_method_uri(const method, new_uri: PChar; 125 const r: Prequest_rec; next_filter: Pap_filter_t): Prequest_rec; 126 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 127 external LibHTTPD name LibNamePrefix + 'ap_sub_req_method_uri' + LibSuff16; 128 129{ 130 * An output filter to strip EOS buckets from sub-requests. This always 131 * has to be inserted at the end of a sub-requests filter stack. 132 * @param f The current filter 133 * @param bb The brigade to filter 134 * @deffunc apr_status_t ap_sub_req_output_filter(ap_filter_t *f, apr_bucket_brigade *bb) 135 } 136function ap_sub_req_output_filter(f: Pap_filter_t; 137 bb: Papr_bucket_brigade): apr_status_t; 138 cdecl; external LibHTTPD name 'ap_sub_req_output_filter'; 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 * @deffunc int ap_run_sub_req(request_rec *r) 145 } 146function ap_run_sub_req(r: Prequest_rec): Prequest_rec; 147 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 148 external LibHTTPD name LibNamePrefix + 'ap_run_sub_req' + LibSuff4; 149 150{ 151 * Free the memory associated with a subrequest 152 * @param r The subrequest to finish 153 * @deffunc void ap_destroy_sub_req(request_rec *r) 154 } 155procedure ap_destroy_sub_req(r: Prequest_rec); 156 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 157 external LibHTTPD name LibNamePrefix + 'ap_destroy_sub_req' + LibSuff4; 158 159{ 160 * Then there's the case that you want some other request to be served 161 * as the top-level request INSTEAD of what the client requested directly. 162 * If so, call this from a handler, and then immediately return OK. 163 } 164 165{ 166 * Redirect the current request to some other uri 167 * @param new_uri The URI to replace the current request with 168 * @param r The current request 169 * @deffunc void ap_internal_redirect(const char *new_uri, request_rec *r) 170 } 171procedure ap_internal_redirect(const new_uri: PChar; r: Prequest_rec); 172 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 173 external LibHTTPD name LibNamePrefix + 'ap_internal_redirect' + LibSuff8; 174 175{ 176 * This function is designed for things like actions or CGI scripts, when 177 * using AddHandler, and you want to preserve the content type across 178 * an internal redirect. 179 * @param new_uri The URI to replace the current request with. 180 * @param r The current request 181 * @deffunc void ap_internal_redirect_handler(const char *new_uri, request_rec *r) 182 } 183procedure ap_internal_redirect_handler(const new_uri: PChar; r: Prequest_rec); 184 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 185 external LibHTTPD name LibNamePrefix + 'ap_internal_redirect_handler' + LibSuff8; 186 187{ 188 * Redirect the current request to a sub_req, merging the pools 189 * @param sub_req A subrequest created from this request 190 * @param r The current request 191 * @deffunc void ap_internal_fast_redirect(request_rec *sub_req, request_rec *r) 192 * @tip the sub_req's pool will be merged into r's pool, be very careful 193 * not to destroy this subrequest, it will be destroyed with the main request! 194 } 195procedure ap_internal_fast_redirect(sub_req, r: Prequest_rec); 196 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 197 external LibHTTPD name LibNamePrefix + 'ap_internal_fast_redirect' + LibSuff8; 198 199{ 200 * Can be used within any handler to determine if any authentication 201 * is required for the current request 202 * @param r The current request 203 * @return 1 if authentication is required, 0 otherwise 204 * @deffunc int ap_some_auth_required(request_rec *r) 205 } 206function ap_some_auth_required(r: Prequest_rec): Integer; 207 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 208 external LibHTTPD name LibNamePrefix + 'ap_some_auth_required' + LibSuff4; 209 210{ 211 * Determine if the current request is the main request or a subrequest 212 * @param r The current request 213 * @return 1 if this is the main request, 0 otherwise 214 * @deffunc int ap_is_initial_req(request_rec *r) 215 } 216function ap_is_initial_req(r: Prequest_rec): Integer; 217 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 218 external LibHTTPD name LibNamePrefix + 'ap_is_initial_req' + LibSuff4; 219 220{ 221 * Function to set the r->mtime field to the specified value if it's later 222 * than what's already there. 223 * @param r The current request 224 * @param dependency_time Time to set the mtime to 225 * @deffunc void ap_update_mtime(request_rec *r, apr_time_t dependency_mtime) 226 } 227procedure ap_update_mtime(r: Prequest_rec; dependency_mtime: apr_time_t); 228 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 229 external LibHTTPD name LibNamePrefix + 'ap_update_mtime' + LibSuff12; 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 NULL-terminated list of strings, each identifying a 243 * method name to add. 244 * @return None. 245 * @deffunc void ap_allow_methods(request_rec *r, int reset, ...) 246 } 247procedure ap_allow_methods(r: Prequest_rec; reset: Integer; others: array of const); 248 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 249 external LibHTTPD name 'ap_allow_methods'; 250 251//AP_DECLARE(void) (request_rec *r, int reset, ...); 252 253{ 254 * Add one or more methods to the list permitted to access the resource. 255 * Usually executed by the content handler before the response header is 256 * sent, but sometimes invoked at an earlier phase if a module knows it 257 * can set the list authoritatively. Note that the methods are ADDED 258 * to any already permitted unless the reset flag is non-zero. The 259 * list is used to generate the Allow response header field when it 260 * is needed. 261 * @param r The pointer to the request identifying the resource. 262 * @param reset Boolean flag indicating whether this list should 263 * completely replace any current settings. 264 * @param ... A list of method identifiers, from the "M_" series 265 * defined in httpd.h, terminated with a value of -1 266 * (e.g., "M_GET, M_POST, M_OPTIONS, -1") 267 * @return None. 268 * @deffunc void ap_allow_standard_methods(request_rec *r, int reset, ...) 269 } 270procedure ap_allow_standard_methods(r: Prequest_rec; reset: Integer; others: array of const); 271 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 272 external LibHTTPD name 'ap_allow_standard_methods'; 273 274//AP_DECLARE(void) (request_rec *r, int reset, ...); 275 276const 277 MERGE_ALLOW = 0; 278 REPLACE_ALLOW = 1; 279 280//#ifdef CORE_PRIVATE 281{ Function called by main.c to handle first-level request } 282//void ap_process_request(request_rec *); 283{ 284 * Kill the current request 285 * @param type Why the request is dieing 286 * @param r The current request 287 * @deffunc void ap_die(int type, request_rec *r) 288 } 289procedure ap_die(type_: Integer; r: Prequest_rec); 290 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 291 external LibHTTPD name LibNamePrefix + 'ap_die' + LibSuff8; 292 293//#endif COREPRIVATE 294 295{ Hooks } 296 297{ 298 * Gives modules a chance to create their request_config entry when the 299 * request is created. 300 * @param r The current request 301 * @ingroup hooks 302 } 303type 304 ap_HOOK_create_request_t = function (r: Prequest_rec): Integer; cdecl; 305 306procedure ap_hook_create_request(pf: ap_HOOK_create_request_t; const aszPre: PPChar; 307 const aszSucc: PPChar; nOrder: Integer); 308 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 309 external LibHTTPD name LibNamePrefix + 'ap_hook_create_request' + LibSuff16; 310 311{ 312 * This hook allow modules an opportunity to translate the URI into an 313 * actual filename. If no modules do anything special, the server's default 314 * rules will be followed. 315 * @param r The current request 316 * @return OK, DECLINED, or HTTP_... 317 * @ingroup hooks 318 } 319type 320 ap_HOOK_translate_name_t = function (r: Prequest_rec): Integer; cdecl; 321 322procedure ap_hook_translate_name(pf: ap_HOOK_translate_name_t; const aszPre: PPChar; 323 const aszSucc: PPChar; nOrder: Integer); 324 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 325 external LibHTTPD name LibNamePrefix + 'ap_hook_translate_name' + LibSuff16; 326 327{ 328 * This hook allow modules to set the per_dir_config based on their own 329 * context (such as <Proxy > sections) and responds to contextless requests 330 * such as TRACE that need no security or filesystem mapping. 331 * based on the filesystem. 332 * @param r The current request 333 * @return DONE (or HTTP_) if this contextless request was just fulfilled 334 * (such as TRACE), OK if this is not a file, and DECLINED if this is a file. 335 * The core map_to_storage (HOOK_RUN_REALLY_LAST) will directory_walk 336 * and file_walk the r->filename. 337 * 338 * @ingroup hooks 339 } 340type 341 ap_HOOK_map_to_storage_t = function (r: Prequest_rec): Integer; cdecl; 342 343procedure ap_hook_map_to_storage(pf: ap_HOOK_map_to_storage_t; const aszPre: PPChar; 344 const aszSucc: PPChar; nOrder: Integer); 345 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 346 external LibHTTPD name LibNamePrefix + 'ap_hook_map_to_storage' + LibSuff16; 347 348{ 349 * This hook is used to analyze the request headers, authenticate the user, 350 * and set the user information in the request record (r->user and 351 * r->ap_auth_type). This hook is only run when Apache determines that 352 * authentication/authorization is required for this resource (as determined 353 * by the 'Require' directive). It runs after the access_checker hook, and 354 * before the auth_checker hook. 355 * 356 * @param r The current request 357 * @return OK, DECLINED, or HTTP_... 358 * @ingroup hooks 359 } 360type 361 ap_HOOK_check_user_id_t = function (r: Prequest_rec): Integer; cdecl; 362 363procedure ap_hook_check_user_id(pf: ap_HOOK_check_user_id_t; const aszPre: PPChar; 364 const aszSucc: PPChar; nOrder: Integer); 365 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 366 external LibHTTPD name LibNamePrefix + 'ap_hook_check_user_id' + LibSuff16; 367 368{ 369 * Allows modules to perform module-specific fixing of header fields. This 370 * is invoked just before any content-handler 371 * @param r The current request 372 * @return OK, DECLINED, or HTTP_... 373 * @ingroup hooks 374 } 375type 376 ap_HOOK_fixups_t = function (r: Prequest_rec): Integer; cdecl; 377 378procedure ap_hook_fixups(pf: ap_HOOK_fixups_t; const aszPre: PPChar; 379 const aszSucc: PPChar; nOrder: Integer); 380 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 381 external LibHTTPD name LibNamePrefix + 'ap_hook_fixups' + LibSuff16; 382 383{ 384 * This routine is called to determine and/or set the various document type 385 * information bits, like Content-type (via r->content_type), language, et 386 * cetera. 387 * @param r the current request 388 * @return OK, DECLINED, or HTTP_... 389 * @ingroup hooks 390 } 391type 392 ap_HOOK_type_checker_t = function (r: Prequest_rec): Integer; cdecl; 393 394procedure ap_hook_type_checker(pf: ap_HOOK_type_checker_t; const aszPre: PPChar; 395 const aszSucc: PPChar; nOrder: Integer); 396 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 397 external LibHTTPD name LibNamePrefix + 'ap_hook_type_checker' + LibSuff16; 398 399{ 400 * This hook is used to apply additional access control to this resource. 401 * It runs *before* a user is authenticated, so this hook is really to 402 * apply additional restrictions independent of a user. It also runs 403 * independent of 'Require' directive usage. 404 * 405 * @param r the current request 406 * @return OK, DECLINED, or HTTP_... 407 * @ingroup hooks 408 } 409type 410 ap_HOOK_access_checker_t = function (r: Prequest_rec): Integer; cdecl; 411 412procedure ap_hook_access_checker(pf: ap_HOOK_access_checker_t; const aszPre: PPChar; 413 const aszSucc: PPChar; nOrder: Integer); 414 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 415 external LibHTTPD name LibNamePrefix + 'ap_hook_access_checker' + LibSuff16; 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). 423 * 424 * @param r the current request 425 * @return OK, DECLINED, or HTTP_... 426 * @ingroup hooks 427 } 428type 429 ap_HOOK_auth_checker_t = function (r: Prequest_rec): Integer; cdecl; 430 431procedure ap_hook_auth_checker(pf: ap_HOOK_auth_checker_t; const aszPre: PPChar; 432 const aszSucc: PPChar; nOrder: Integer); 433 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 434 external LibHTTPD name LibNamePrefix + 'ap_hook_auth_checker' + LibSuff16; 435 436{ 437 * This hook allows modules to insert filters for the current request 438 * @param r the current request 439 * @ingroup hooks 440 } 441type 442 ap_HOOK_insert_filter_t = procedure (r: Prequest_rec); cdecl; 443 444procedure ap_hook_insert_filter(pf: ap_HOOK_insert_filter_t; const aszPre: PPChar; 445 const aszSucc: PPChar; nOrder: Integer); 446 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 447 external LibHTTPD name LibNamePrefix + 'ap_hook_insert_filter' + LibSuff16; 448 449function ap_location_walk(r: Prequest_rec): Integer; 450 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 451 external LibHTTPD name LibNamePrefix + 'ap_location_walk' + LibSuff4; 452 453function ap_directory_walk(r: Prequest_rec): Integer; 454 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 455 external LibHTTPD name LibNamePrefix + 'ap_directory_walk' + LibSuff4; 456 457function ap_file_walk(r: Prequest_rec): Integer; 458 {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} 459 external LibHTTPD name LibNamePrefix + 'ap_file_walk' + LibSuff4; 460 461