http_protocol.inc 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  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 "httpd.h"
  17. #include "apr_hooks.h"
  18. #include "apr_portable.h"
  19. #include "apr_mmap.h"
  20. #include "apr_buckets.h"
  21. #include "util_filter.h"}
  22. {
  23. * @package HTTP protocol handling
  24. }
  25. {
  26. * This hook allows modules to insert filters for the current error response
  27. * @param r the current request
  28. * @ingroup hooks
  29. }
  30. type
  31. ap_HOOK_insert_error_filter_t = procedure(r: Prequest_rec); cdecl;
  32. procedure ap_hook_insert_error_filter(pf: ap_HOOK_insert_error_filter_t; const aszPre: PPChar;
  33. const aszSucc: PPChar; nOrder: Integer);
  34. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  35. external LibHTTPD name LibNamePrefix + 'ap_hook_insert_error_filter' + LibSuff16;
  36. { This is an optimization. We keep a record of the filter_rec that
  37. * stores the old_write filter, so that we can avoid strcmp's later.
  38. }
  39. //AP_DECLARE_DATA extern ap_filter_rec_t *ap_old_write_func;
  40. {
  41. * Prototypes for routines which either talk directly back to the user,
  42. * or control the ones that eventually do.
  43. }
  44. {
  45. * Read a request and fill in the fields.
  46. * @param c The current connection
  47. * @return The new request_rec
  48. }
  49. //request_rec *ap_read_request(conn_rec *c);
  50. {
  51. * Read the mime-encoded headers.
  52. * @param r The current request
  53. }
  54. procedure ap_get_mime_headers(r: Prequest_rec);
  55. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  56. external LibHTTPD name LibNamePrefix + 'ap_get_mime_headers' + LibSuff4;
  57. {
  58. * Optimized version of ap_get_mime_headers() that requires a
  59. * temporary brigade to work with
  60. * @param r The current request
  61. * @param bb temp brigade
  62. }
  63. procedure ap_get_mime_headers_core(r: Prequest_rec; bb: Papr_bucket_brigade);
  64. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  65. external LibHTTPD name LibNamePrefix + 'ap_get_mime_headers_core' + LibSuff8;
  66. { Finish up stuff after a request }
  67. {
  68. * Called at completion of sending the response. It sends the terminating
  69. * protocol information.
  70. * @param r The current request
  71. * @deffunc void ap_finalize_request_protocol(request_rec *r)
  72. }
  73. procedure ap_finalize_request_protocol(r: Prequest_rec);
  74. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  75. external LibHTTPD name LibNamePrefix + 'ap_finalize_request_protocol' + LibSuff4;
  76. {
  77. * Send error back to client.
  78. * @param r The current request
  79. * @param recursive_error last arg indicates error status in case we get
  80. * an error in the process of trying to deal with an ErrorDocument
  81. * to handle some other error. In that case, we print the default
  82. * report for the first thing that went wrong, and more briefly report
  83. * on the problem with the ErrorDocument.
  84. * @deffunc void ap_send_error_response(request_rec *r, int recursive_error)
  85. }
  86. procedure ap_send_error_response(r: Prequest_rec; recursive_error: Integer);
  87. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  88. external LibHTTPD name LibNamePrefix + 'ap_send_error_response' + LibSuff8;
  89. { Set last modified header line from the lastmod date of the associated file.
  90. * Also, set content length.
  91. *
  92. * May return an error status, typically HTTP_NOT_MODIFIED (that when the
  93. * permit_cache argument is set to one).
  94. }
  95. {
  96. * Set the content length for this request
  97. * @param r The current request
  98. * @param length The new content length
  99. * @deffunc void ap_set_content_length(request_rec *r, apr_off_t length)
  100. }
  101. procedure ap_set_content_length(r: Prequest_rec; length: apr_off_t);
  102. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  103. external LibHTTPD name LibNamePrefix + 'ap_set_content_length' + LibSuff12;
  104. {
  105. * Set the keepalive status for this request
  106. * @param r The current request
  107. * @return 1 if keepalive can be set, 0 otherwise
  108. * @deffunc int ap_set_keepalive(request_rec *r)
  109. }
  110. function ap_set_keepalive(r: Prequest_rec): Integer;
  111. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  112. external LibHTTPD name LibNamePrefix + 'ap_set_keepalive' + LibSuff4;
  113. {
  114. * Return the latest rational time from a request/mtime pair. Mtime is
  115. * returned unless it's in the future, in which case we return the current time.
  116. * @param r The current request
  117. * @param mtime The last modified time
  118. * @return the latest rational time.
  119. * @deffunc apr_time_t ap_rationalize_mtime(request_rec *r, apr_time_t mtime)
  120. }
  121. function ap_rationalize_mtime(r: Prequest_rec; mtime: apr_time_t): apr_time_t;
  122. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  123. external LibHTTPD name LibNamePrefix + 'ap_rationalize_mtime' + LibSuff12;
  124. {
  125. * Build the content-type that should be sent to the client from the
  126. * content-type specified. The following rules are followed:
  127. * - if type is NULL, type is set to ap_default_type(r)
  128. * - if charset adding is disabled, stop processing and return type.
  129. * - then, if there are no parameters on type, add the default charset
  130. * - return type
  131. * @param r The current request
  132. * @return The content-type
  133. * @deffunc const char *ap_make_content_type(request_rec *r, const char *type);
  134. }
  135. function ap_make_content_type(r: Prequest_rec; type_: PChar): PChar;
  136. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  137. external LibHTTPD name LibNamePrefix + 'ap_make_content_type' + LibSuff8;
  138. //#ifdef CORE_PRIVATE
  139. {
  140. * Precompile metadata structures used by ap_make_content_type()
  141. * @param r The pool to use for allocations
  142. * @deffunc void ap_setup_make_content_type(apr_pool_t *pool)
  143. }
  144. procedure ap_setup_make_content_type(pool: Papr_pool_t);
  145. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  146. external LibHTTPD name LibNamePrefix + 'ap_setup_make_content_type' + LibSuff4;
  147. //#endif { CORE_PRIVATE }
  148. {
  149. * Construct an entity tag from the resource information. If it's a real
  150. * file, build in some of the file characteristics.
  151. * @param r The current request
  152. * @param force_weak Force the entity tag to be weak - it could be modified
  153. * again in as short an interval.
  154. * @return The entity tag
  155. * @deffunc char *ap_make_etag(request_rec *r, int force_weak)
  156. }
  157. function ap_make_etag(r: Prequest_rec; force_weak: Integer): PChar;
  158. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  159. external LibHTTPD name LibNamePrefix + 'ap_make_etag' + LibSuff8;
  160. {
  161. * Set the E-tag outgoing header
  162. * @param The current request
  163. * @deffunc void ap_set_etag(request_rec *r)
  164. }
  165. procedure ap_set_etag(r: Prequest_rec);
  166. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  167. external LibHTTPD name LibNamePrefix + 'ap_set_etag' + LibSuff4;
  168. {
  169. * Set the last modified time for the file being sent
  170. * @param r The current request
  171. * @deffunc void ap_set_last_modified(request_rec *r)
  172. }
  173. procedure ap_set_last_modified(r: Prequest_rec);
  174. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  175. external LibHTTPD name LibNamePrefix + 'ap_set_last_modified' + LibSuff4;
  176. {
  177. * Implements condition GET rules for HTTP/1.1 specification. This function
  178. * inspects the client headers and determines if the response fulfills
  179. * the requirements specified.
  180. * @param r The current request
  181. * @return OK if the response fulfills the condition GET rules, some
  182. * other status code otherwise
  183. * @deffunc int ap_meets_conditions(request_rec *r)
  184. }
  185. function ap_meets_conditions(r: Prequest_rec): Integer;
  186. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  187. external LibHTTPD name LibNamePrefix + 'ap_meets_conditions' + LibSuff4;
  188. { Other ways to send stuff at the client. All of these keep track
  189. * of bytes_sent automatically. This indirection is intended to make
  190. * it a little more painless to slide things like HTTP-NG packetization
  191. * underneath the main body of the code later. In the meantime, it lets
  192. * us centralize a bit of accounting (bytes_sent).
  193. *
  194. * These also return the number of bytes written by the call.
  195. * They should only be called with a timeout registered, for obvious reaasons.
  196. * (Ditto the send_header stuff).
  197. }
  198. {
  199. * Send an entire file to the client, using sendfile if supported by the
  200. * current platform
  201. * @param fd The file to send.
  202. * @param r The current request
  203. * @param offset Offset into the file to start sending.
  204. * @param length Amount of data to send
  205. * @param nbytes Amount of data actually sent
  206. * @deffunc apr_status_t ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t offset, apr_size_t length, apr_size_t *nbytes);
  207. }
  208. function ap_send_fd(fd: Papr_file_t; r: Prequest_rec; offset: apr_off_t;
  209. length: apr_size_t; nbytes: Papr_size_t): apr_status_t;
  210. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  211. external LibHTTPD name LibNamePrefix + 'ap_send_fd' + LibSuff24;
  212. {$ifdef APR_HAS_MMAP}
  213. {
  214. * Send an MMAP'ed file to the client
  215. * @param mm The MMAP'ed file to send
  216. * @param r The current request
  217. * @param offset The offset into the MMAP to start sending
  218. * @param length The amount of data to send
  219. * @return The number of bytes sent
  220. * @deffunc size_t ap_send_mmap(apr_mmap_t *mm, request_rec *r, size_t offset, size_t length)
  221. }
  222. function ap_send_mmap(mm: Papr_mmap_t; r: Prequest_rec; offset, length: size_t): size_t;
  223. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  224. external LibHTTPD name LibNamePrefix + 'ap_send_mmap' + LibSuff20;
  225. {$endif}
  226. {
  227. * Register a new request method, and return the offset that will be
  228. * associated with that method.
  229. *
  230. * @param p The pool to create registered method numbers from.
  231. * @param methname The name of the new method to register.
  232. * @return Ab int value representing an offset into a bitmask.
  233. }
  234. function ap_method_register(p: Papr_pool_t; methname: PChar): Integer;
  235. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  236. external LibHTTPD name LibNamePrefix + 'ap_method_register' + LibSuff8;
  237. {
  238. * Initialize the method_registry and allocate memory for it.
  239. *
  240. * @param p Pool to allocate memory for the registry from.
  241. }
  242. procedure ap_method_registry_init(p: Papr_pool_t);
  243. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  244. external LibHTTPD name LibNamePrefix + 'ap_method_registry_init' + LibSuff4;
  245. {
  246. * This is a convenience macro to ease with checking a mask
  247. * against a method name.
  248. }
  249. {#define AP_METHOD_CHECK_ALLOWED(mask, methname) \
  250. ((mask) & (AP_METHOD_BIT << ap_method_number_of((methname))))}
  251. {
  252. * Create a new method list with the specified number of preallocated
  253. * slots for extension methods.
  254. *
  255. * @param p Pointer to a pool in which the structure should be
  256. * allocated.
  257. * @param nelts Number of preallocated extension slots
  258. * @return Pointer to the newly created structure.
  259. * @deffunc ap_method_list_t ap_make_method_list(apr_pool_t *p, int nelts)
  260. }
  261. function ap_make_method_list(p: Papr_pool_t; nelts: Integer): Pap_method_list_t;
  262. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  263. external LibHTTPD name LibNamePrefix + 'ap_make_method_list' + LibSuff8;
  264. procedure ap_copy_method_list(dest, src: Pap_method_list_t);
  265. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  266. external LibHTTPD name LibNamePrefix + 'ap_copy_method_list' + LibSuff8;
  267. type
  268. comp_t = procedure (urec: Pointer; const mname: PChar; mnum: Integer);
  269. procedure ap_method_list_do(
  270. comp: comp_t; rec: Pointer; ml: Pap_method_list_t; others: array of const);
  271. cdecl; external LibHTTPD name 'ap_method_list_do';
  272. type
  273. ap_method_list_vdo_t = function (urec: Pointer; const mname: PChar;
  274. mnum: Integer): Integer; cdecl;
  275. procedure ap_method_list_vdo(comp: ap_method_list_vdo_t;
  276. rec: Pointer; const ml: Pap_method_list_t; cp: va_list);
  277. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  278. external LibHTTPD name LibNamePrefix + 'ap_method_list_vdo' + LibSuff16;
  279. {
  280. * Search for an HTTP method name in an ap_method_list_t structure, and
  281. * return true if found.
  282. *
  283. * @param method String containing the name of the method to check.
  284. * @param l Pointer to a method list, such as cmd->methods_limited.
  285. * @return 1 if method is in the list, otherwise 0
  286. * @deffunc int ap_method_in_list(const char *method, ap_method_list_t *l)
  287. }
  288. function ap_method_in_list(l: Pap_method_list_t; const method: PChar): Integer;
  289. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  290. external LibHTTPD name LibNamePrefix + 'ap_method_in_list' + LibSuff8;
  291. {
  292. * Add an HTTP method name to an ap_method_list_t structure if it isn't
  293. * already listed.
  294. *
  295. * @param method String containing the name of the method to check.
  296. * @param l Pointer to a method list, such as cmd->methods_limited.
  297. * @return None.
  298. * @deffunc void ap_method_in_list(ap_method_list_t *l, const char *method)
  299. }
  300. procedure ap_method_list_add(l: Pap_method_list_t; const method: PChar);
  301. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  302. external LibHTTPD name LibNamePrefix + 'ap_method_list_add' + LibSuff8;
  303. {
  304. * Remove an HTTP method name from an ap_method_list_t structure.
  305. *
  306. * @param l Pointer to a method list, such as cmd->methods_limited.
  307. * @param method String containing the name of the method to remove.
  308. * @return None.
  309. * @deffunc void ap_method_list_remove(ap_method_list_t *l, const char *method)
  310. }
  311. procedure ap_method_list_remove(l: Pap_method_list_t; const method: PChar);
  312. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  313. external LibHTTPD name LibNamePrefix + 'ap_method_list_remove' + LibSuff8;
  314. {
  315. * Reset a method list to be completely empty.
  316. *
  317. * @param l Pointer to a method list, such as cmd->methods_limited.
  318. * @return None.
  319. * @deffunc void ap_clear_method_list(ap_method_list_t *l)
  320. }
  321. procedure ap_clear_method_list(l: Pap_method_list_t);
  322. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  323. external LibHTTPD name LibNamePrefix + 'ap_clear_method_list' + LibSuff4;
  324. {
  325. * Set the content type for this request (r->content_type).
  326. * @param r The current request
  327. * @param ct The new content type
  328. * @deffunc void ap_set_content_type(request_rec *r, const char* ct)
  329. * @warning This function must be called to set r->content_type in order
  330. * for the AddOutputFilterByType directive to work correctly.
  331. }
  332. procedure ap_set_content_type(r: Prequest_rec; const ct: PChar);
  333. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  334. external LibHTTPD name LibNamePrefix + 'ap_set_content_type' + LibSuff8;
  335. { Hmmm... could macrofy these for now, and maybe forever, though the
  336. * definitions of the macros would get a whole lot hairier.
  337. }
  338. {
  339. * Output one character for this request
  340. * @param c the character to output
  341. * @param r the current request
  342. * @return The number of bytes sent
  343. * @deffunc int ap_rputc(int c, request_rec *r)
  344. }
  345. function ap_rputc(c: Integer; r: Prequest_rec): Integer;
  346. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  347. external LibHTTPD name LibNamePrefix + 'ap_rputc' + LibSuff8;
  348. {
  349. * Output a string for the current request
  350. * @param str The string to output
  351. * @param r The current request
  352. * @return The number of bytes sent
  353. * @deffunc int ap_rputs(const char *str, request_rec *r)
  354. }
  355. function ap_rputs(const str: PChar; r: Prequest_rec): Integer;
  356. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  357. external LibHTTPD name LibNamePrefix + 'ap_rputs' + LibSuff8;
  358. {
  359. * Write a buffer for the current request
  360. * @param buf The buffer to write
  361. * @param nbyte The number of bytes to send from the buffer
  362. * @param r The current request
  363. * @return The number of bytes sent
  364. * @deffunc int ap_rwrite(const void *buf, int nbyte, request_rec *r)
  365. }
  366. function ap_rwrite(const buf: Pointer; nbyte: Integer; r: Prequest_rec): Integer;
  367. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  368. external LibHTTPD name LibNamePrefix + 'ap_rwrite' + LibSuff12;
  369. {
  370. * Write an unspecified number of strings to the request
  371. * @param r The current request
  372. * @param ... The strings to write
  373. * @return The number of bytes sent
  374. * @deffunc int ap_rvputs(request_rec *r, ...)
  375. }
  376. function ap_rvputs(r: Prequest_rec; others: array of const): Integer;
  377. cdecl; external LibHTTPD name 'ap_rvputs';
  378. //AP_DECLARE_NONSTD(int) ap_rvputs(request_rec *r,...);
  379. {
  380. * Output data to the client in a printf format
  381. * @param r The current request
  382. * @param fmt The format string
  383. * @param vlist The arguments to use to fill out the format string
  384. * @return The number of bytes sent
  385. * @deffunc int ap_vrprintf(request_rec *r, const char *fmt, va_list vlist)
  386. }
  387. function ap_vrprintf(r: Prequest_rec; const fmt: PChar; vlist: va_list): Integer;
  388. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  389. external LibHTTPD name LibNamePrefix + 'ap_vrprintf' + LibSuff12;
  390. {
  391. * Output data to the client in a printf format
  392. * @param r The current request
  393. * @param fmt The format string
  394. * @param ... The arguments to use to fill out the format string
  395. * @return The number of bytes sent
  396. * @deffunc int ap_rprintf(request_rec *r, const char *fmt, ...)
  397. }
  398. function ap_rprintf(r: Prequest_rec; const fmt: PChar; others: array of const): Integer;
  399. cdecl; external LibHTTPD name 'ap_rprintf';
  400. //AP_DECLARE_NONSTD(int) ap_rprintf(request_rec *r, const char *fmt,...)
  401. // __attribute__((format(printf,2,3)));
  402. {
  403. * Flush all of the data for the current request to the client
  404. * @param r The current request
  405. * @return The number of bytes sent
  406. * @deffunc int ap_rflush(request_rec *r)
  407. }
  408. function ap_rflush(r: Prequest_rec): Integer;
  409. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  410. external LibHTTPD name LibNamePrefix + 'ap_rflush' + LibSuff4;
  411. {
  412. * Index used in custom_responses array for a specific error code
  413. * (only use outside protocol.c is in getting them configured).
  414. * @param status HTTP status code
  415. * @return The index of the response
  416. * @deffunc int ap_index_of_response(int status)
  417. }
  418. function ap_index_of_response(status: Integer): Integer;
  419. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  420. external LibHTTPD name LibNamePrefix + 'ap_index_of_response' + LibSuff4;
  421. {
  422. * Return the Status-Line for a given status code (excluding the
  423. * HTTP-Version field). If an invalid or unknown status code is
  424. * passed, "500 Internal Server Error" will be returned.
  425. * @param status The HTTP status code
  426. * @return The Status-Line
  427. * @deffunc const char *ap_get_status_line(int status)
  428. }
  429. function ap_get_status_line(status: Integer): PChar;
  430. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  431. external LibHTTPD name LibNamePrefix + 'ap_get_status_line' + LibSuff4;
  432. { Reading a block of data from the client connection (e.g., POST arg) }
  433. {
  434. * Setup the client to allow Apache to read the request body.
  435. * @param r The current request
  436. * @param read_policy How the server should interpret a chunked
  437. * transfer-encoding. One of: <pre>
  438. * REQUEST_NO_BODY Send 413 error if message has any body
  439. * REQUEST_CHUNKED_ERROR Send 411 error if body without Content-Length
  440. * REQUEST_CHUNKED_DECHUNK If chunked, remove the chunks for me.
  441. * </pre>
  442. * @return either OK or an error code
  443. * @deffunc int ap_setup_client_block(request_rec *r, int read_policy)
  444. }
  445. function ap_setup_client_block(r: Prequest_rec; read_policy: Integer): Integer;
  446. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  447. external LibHTTPD name LibNamePrefix + 'ap_setup_client_block' + LibSuff8;
  448. {
  449. * Determine if the client has sent any data. This also sends a
  450. * 100 Continue response to HTTP/1.1 clients, so modules should not be called
  451. * until the module is ready to read content.
  452. * @warning Never call this function more than once.
  453. * @param r The current request
  454. * @return 0 if there is no message to read, 1 otherwise
  455. * @deffunc int ap_should_client_block(request_rec *r)
  456. }
  457. function ap_should_client_block(r: Prequest_rec): Integer;
  458. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  459. external LibHTTPD name LibNamePrefix + 'ap_should_client_block' + LibSuff4;
  460. {
  461. * Call this in a loop. It will put data into a buffer and return the length
  462. * of the input block
  463. * @param r The current request
  464. * @param buffer The buffer in which to store the data
  465. * @param bufsiz The size of the buffer
  466. * @return Number of bytes inserted into the buffer. When done reading, 0
  467. * if EOF, or -1 if there was an error
  468. * @deffunc long ap_get_client_block(request_rec *r, char *buffer, apr_size_t bufsiz)
  469. }
  470. function ap_get_client_block(r: Prequest_rec; buffer: PChar; bufsiz: apr_size_t): cLong;
  471. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  472. external LibHTTPD name LibNamePrefix + 'ap_get_client_block' + LibSuff12;
  473. {
  474. * In HTTP/1.1, any method can have a body. However, most GET handlers
  475. * wouldn't know what to do with a request body if they received one.
  476. * This helper routine tests for and reads any message body in the request,
  477. * simply discarding whatever it receives. We need to do this because
  478. * failing to read the request body would cause it to be interpreted
  479. * as the next request on a persistent connection.
  480. * @param r The current request
  481. * @return error status if request is malformed, OK otherwise
  482. * @deffunc int ap_discard_request_body(request_rec *r)
  483. }
  484. function ap_discard_request_body(r: Prequest_rec): Integer;
  485. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  486. external LibHTTPD name LibNamePrefix + 'ap_discard_request_body' + LibSuff4;
  487. {
  488. * Setup the output headers so that the client knows how to authenticate
  489. * itself the next time, if an authentication request failed. This function
  490. * works for both basic and digest authentication
  491. * @param r The current request
  492. * @deffunc void ap_note_auth_failure(request_rec *r)
  493. }
  494. procedure ap_note_auth_failure(r: Prequest_rec);
  495. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  496. external LibHTTPD name LibNamePrefix + 'ap_note_auth_failure' + LibSuff4;
  497. {
  498. * Setup the output headers so that the client knows how to authenticate
  499. * itself the next time, if an authentication request failed. This function
  500. * works only for basic authentication
  501. * @param r The current request
  502. * @deffunc void ap_note_basic_auth_failure(request_rec *r)
  503. }
  504. procedure ap_note_basic_auth_failure(r: Prequest_rec);
  505. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  506. external LibHTTPD name LibNamePrefix + 'ap_note_basic_auth_failure' + LibSuff4;
  507. {
  508. * Setup the output headers so that the client knows how to authenticate
  509. * itself the next time, if an authentication request failed. This function
  510. * works only for digest authentication
  511. * @param r The current request
  512. * @deffunc void ap_note_digest_auth_failure(request_rec *r)
  513. }
  514. procedure ap_note_digest_auth_failure(r: Prequest_rec);
  515. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  516. external LibHTTPD name LibNamePrefix + 'ap_note_digest_auth_failure' + LibSuff4;
  517. {
  518. * Get the password from the request headers
  519. * @param r The current request
  520. * @param pw The password as set in the headers
  521. * @return 0 (OK) if it set the 'pw' argument (and assured
  522. * a correct value in r->user); otherwise it returns
  523. * an error code, either HTTP_INTERNAL_SERVER_ERROR if things are
  524. * really confused, HTTP_UNAUTHORIZED if no authentication at all
  525. * seemed to be in use, or DECLINED if there was authentication but
  526. * it wasn't Basic (in which case, the caller should presumably
  527. * decline as well).
  528. * @deffunc int ap_get_basic_auth_pw(request_rec *r, const char **pw)
  529. }
  530. function ap_get_basic_auth_pw(r: Prequest_rec; pw: PPChar): Integer;
  531. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  532. external LibHTTPD name LibNamePrefix + 'ap_get_basic_auth_pw' + LibSuff8;
  533. {
  534. * parse_uri: break apart the uri
  535. * @warning Side Effects: <pre>
  536. * - sets r->args to rest after '?' (or NULL if no '?')
  537. * - sets r->uri to request uri (without r->args part)
  538. * - sets r->hostname (if not set already) from request (scheme://host:port)
  539. * </pre>
  540. * @param r The current request
  541. * @param uri The uri to break apart
  542. * @deffunc void ap_parse_uri(request_rec *r, const char *uri)
  543. }
  544. procedure ap_parse_uri(r: Prequest_rec; const uri: PChar);
  545. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  546. external LibHTTPD name LibNamePrefix + 'ap_parse_uri' + LibSuff8;
  547. {
  548. * Get the next line of input for the request
  549. * @param s The buffer into which to read the line
  550. * @param n The size of the buffer
  551. * @param r The request
  552. * @param fold Whether to merge continuation lines
  553. * @return The length of the line, if successful
  554. * n, if the line is too big to fit in the buffer
  555. * -1 for miscellaneous errors
  556. * @deffunc int ap_method_number_of(const char *method)
  557. }
  558. function ap_getline(s: PChar; n: Integer; r: Prequest_rec; fold: Integer): Integer;
  559. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  560. external LibHTTPD name LibNamePrefix + 'ap_getline' + LibSuff16;
  561. {
  562. * Get the next line of input for the request
  563. *
  564. * Note: on ASCII boxes, ap_rgetline is a macro which simply calls
  565. * ap_rgetline_core to get the line of input.
  566. *
  567. * on EBCDIC boxes, ap_rgetline is a wrapper function which
  568. * translates ASCII protocol lines to the local EBCDIC code page
  569. * after getting the line of input.
  570. *
  571. * @param s Pointer to the pointer to the buffer into which the line
  572. * should be read; if *s==NULL, a buffer of the necessary size
  573. * to hold the data will be allocated from the request pool
  574. * @param n The size of the buffer
  575. * @param read The length of the line.
  576. * @param r The request
  577. * @param fold Whether to merge continuation lines
  578. * @param bb Working brigade to use when reading buckets
  579. * @return APR_SUCCESS, if successful
  580. * APR_ENOSPC, if the line is too big to fit in the buffer
  581. * Other errors where appropriate
  582. }
  583. {#if APR_CHARSET_EBCDIC
  584. AP_DECLARE(apr_status_t) ap_rgetline(char **s, apr_size_t n,
  585. apr_size_t *read,
  586. request_rec *r, int fold,
  587. apr_bucket_brigade *bb);
  588. #else }{ ASCII box }
  589. {#define ap_rgetline(s, n, read, r, fold, bb) \
  590. ap_rgetline_core((s), (n), (read), (r), (fold), (bb))
  591. #endif}
  592. {AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
  593. apr_size_t *read,
  594. request_rec *r, int fold,
  595. apr_bucket_brigade *bb);}
  596. {
  597. * Get the method number associated with the given string, assumed to
  598. * contain an HTTP method. Returns M_INVALID if not recognized.
  599. * @param method A string containing a valid HTTP method
  600. * @return The method number
  601. }
  602. function ap_method_number_of(const method: PChar): Integer;
  603. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  604. external LibHTTPD name LibNamePrefix + 'ap_method_number_of' + LibSuff4;
  605. {
  606. * Get the method name associated with the given internal method
  607. * number. Returns NULL if not recognized.
  608. * @param p A pool to use for temporary allocations.
  609. * @param methnum An integer value corresponding to an internal method number
  610. * @return The name corresponding to the method number
  611. }
  612. function ap_method_name_of(p: Papr_pool_t; methnum: Integer): PChar;
  613. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  614. external LibHTTPD name LibNamePrefix + 'ap_method_name_of' + LibSuff8;
  615. { Hooks }
  616. {
  617. * post_read_request --- run right after read_request or internal_redirect,
  618. * and not run during any subrequests.
  619. }
  620. {
  621. * This hook allows modules to affect the request immediately after the request
  622. * has been read, and before any other phases have been processes. This allows
  623. * modules to make decisions based upon the input header fields
  624. * @param r The current request
  625. * @return OK or DECLINED
  626. * @deffunc ap_run_post_read_request(request_rec *r)
  627. }
  628. type
  629. ap_HOOK_post_read_request_t = function(r: Prequest_rec): Integer; cdecl;
  630. procedure ap_hook_post_read_request(pf: ap_HOOK_post_read_request_t;
  631. const aszPre: PPChar; const aszSucc: PPChar; nOrder: Integer);
  632. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  633. external LibHTTPD name LibNamePrefix + 'ap_hook_post_read_request' + LibSuff16;
  634. {
  635. * This hook allows modules to perform any module-specific logging activities
  636. * over and above the normal server things.
  637. * @param r The current request
  638. * @return OK, DECLINED, or HTTP_...
  639. * @deffunc int ap_run_log_transaction(request_rec *r)
  640. }
  641. type
  642. ap_HOOK_log_transaction_t = function(r: Prequest_rec): Integer; cdecl;
  643. procedure ap_hook_log_transaction(pf: ap_HOOK_log_transaction_t;
  644. const aszPre: PPChar; const aszSucc: PPChar; nOrder: Integer);
  645. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  646. external LibHTTPD name LibNamePrefix + 'ap_hook_log_transaction' + LibSuff16;
  647. {
  648. * This hook allows modules to retrieve the http method from a request. This
  649. * allows Apache modules to easily extend the methods that Apache understands
  650. * @param r The current request
  651. * @return The http method from the request
  652. * @deffunc const char *ap_run_http_method(const request_rec *r)
  653. }
  654. type
  655. ap_HOOK_http_method_t = function(const r: Prequest_rec): PChar; cdecl;
  656. procedure ap_hook_http_method(pf: ap_HOOK_http_method_t;
  657. const aszPre: PPChar; const aszSucc: PPChar; nOrder: Integer);
  658. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  659. external LibHTTPD name LibNamePrefix + 'ap_hook_http_method' + LibSuff16;
  660. {
  661. * Return the default port from the current request
  662. * @param r The current request
  663. * @return The current port
  664. * @deffunc apr_port_t ap_run_default_port(const request_rec *r)
  665. }
  666. type
  667. ap_HOOK_default_port_t = function(const r: Prequest_rec): apr_port_t; cdecl;
  668. procedure ap_hook_default_port(pf: ap_HOOK_default_port_t;
  669. const aszPre: PPChar; const aszSucc: PPChar; nOrder: Integer);
  670. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  671. external LibHTTPD name LibNamePrefix + 'ap_hook_default_port' + LibSuff16;
  672. {
  673. * A bucket referring to an HTTP error
  674. * This bucket can be passed down the filter stack to indicate that an
  675. * HTTP error occurred while running a filter. In order for this bucket
  676. * to be used successfully, it MUST be sent as the first bucket in the
  677. * first brigade to be sent from a given filter.
  678. }
  679. type
  680. ap_bucket_error = record
  681. { Number of buckets using this memory }
  682. refcount: apr_bucket_refcount;
  683. { The error code }
  684. status: Integer;
  685. { The error string }
  686. data: PChar;
  687. end;
  688. Pap_bucket_error = ^ap_bucket_error;
  689. //AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_error;
  690. {
  691. * Determine if a bucket is an error bucket
  692. * @param e The bucket to inspect
  693. * @return true or false
  694. }
  695. //#define AP_BUCKET_IS_ERROR(e) (e->type == &ap_bucket_type_error)
  696. {
  697. * Make the bucket passed in an error bucket
  698. * @param b The bucket to make into an error bucket
  699. * @param error The HTTP error code to put in the bucket.
  700. * @param buf An optional error string to put in the bucket.
  701. * @param p A pool to allocate out of.
  702. * @return The new bucket, or NULL if allocation failed
  703. * @deffunc apr_bucket *ap_bucket_error_make(apr_bucket *b, int error, const char *buf, apr_pool_t *p)
  704. }
  705. function ap_bucket_error_make(b: Papr_bucket; error: Integer;
  706. const buf: PChar; p: Papr_pool_t): Papr_bucket;
  707. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  708. external LibHTTPD name LibNamePrefix + 'ap_bucket_error_make' + LibSuff16;
  709. {
  710. * Create a bucket referring to an HTTP error.
  711. * @param error The HTTP error code to put in the bucket.
  712. * @param buf An optional error string to put in the bucket.
  713. * @param p A pool to allocate the error string out of.
  714. * @param list The bucket allocator from which to allocate the bucket
  715. * @return The new bucket, or NULL if allocation failed
  716. * @deffunc apr_bucket *ap_bucket_error_create(int error, const char *buf, apr_pool_t *p, apr_bucket_alloc_t *list)
  717. }
  718. function ap_bucket_error_create(error: Integer; const buf: PChar;
  719. p: Papr_pool_t; list: Papr_bucket_alloc_t): Papr_bucket;
  720. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  721. external LibHTTPD name LibNamePrefix + 'ap_bucket_error_create' + LibSuff16;
  722. function ap_byterange_filter(f: Pap_filter_t; b: Papr_bucket_brigade): apr_status_t;
  723. cdecl; external LibHTTPD name 'ap_byterange_filter';
  724. function ap_http_header_filter(f: Pap_filter_t; b: Papr_bucket_brigade): apr_status_t;
  725. cdecl; external LibHTTPD name 'ap_http_header_filter';
  726. function ap_content_length_filter(f: Pap_filter_t; b: Papr_bucket_brigade): apr_status_t;
  727. cdecl; external LibHTTPD name 'ap_content_length_filter';
  728. function ap_old_write_filter(f: Pap_filter_t; b: Papr_bucket_brigade): apr_status_t;
  729. cdecl; external LibHTTPD name 'ap_old_write_filter';
  730. {
  731. * Setting up the protocol fields for subsidiary requests...
  732. * Also, a wrapup function to keep the internal accounting straight.
  733. }
  734. procedure ap_set_sub_req_protocol(rnew: Prequest_rec; const r: Prequest_rec);
  735. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  736. external LibHTTPD name LibNamePrefix + 'ap_set_sub_req_protocol' + LibSuff8;
  737. procedure ap_finalize_sub_req_protocol(sub_r: Prequest_rec);
  738. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  739. external LibHTTPD name LibNamePrefix + 'ap_finalize_sub_req_protocol' + LibSuff4;