http_request.inc 19 KB

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