http_protocol.inc 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. { Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. }
  16. {#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. {
  265. * Copy a method list
  266. *
  267. * @param dest List to copy to
  268. * @param src List to copy from
  269. }
  270. procedure ap_copy_method_list(dest, src: Pap_method_list_t);
  271. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  272. external LibHTTPD name LibNamePrefix + 'ap_copy_method_list' + LibSuff8;
  273. {
  274. * Search for an HTTP method name in an ap_method_list_t structure, and
  275. * return true if found.
  276. *
  277. * @param method String containing the name of the method to check.
  278. * @param l Pointer to a method list, such as cmd->methods_limited.
  279. * @return 1 if method is in the list, otherwise 0
  280. * @deffunc int ap_method_in_list(const char *method, ap_method_list_t *l)
  281. }
  282. function ap_method_in_list(l: Pap_method_list_t; const method: PChar): Integer;
  283. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  284. external LibHTTPD name LibNamePrefix + 'ap_method_in_list' + LibSuff8;
  285. {
  286. * Add an HTTP method name to an ap_method_list_t structure if it isn't
  287. * already listed.
  288. *
  289. * @param method String containing the name of the method to check.
  290. * @param l Pointer to a method list, such as cmd->methods_limited.
  291. * @return None.
  292. * @deffunc void ap_method_in_list(ap_method_list_t *l, const char *method)
  293. }
  294. procedure ap_method_list_add(l: Pap_method_list_t; const method: PChar);
  295. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  296. external LibHTTPD name LibNamePrefix + 'ap_method_list_add' + LibSuff8;
  297. {
  298. * Remove an HTTP method name from an ap_method_list_t structure.
  299. *
  300. * @param l Pointer to a method list, such as cmd->methods_limited.
  301. * @param method String containing the name of the method to remove.
  302. * @return None.
  303. * @deffunc void ap_method_list_remove(ap_method_list_t *l, const char *method)
  304. }
  305. procedure ap_method_list_remove(l: Pap_method_list_t; const method: PChar);
  306. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  307. external LibHTTPD name LibNamePrefix + 'ap_method_list_remove' + LibSuff8;
  308. {
  309. * Reset a method list to be completely empty.
  310. *
  311. * @param l Pointer to a method list, such as cmd->methods_limited.
  312. * @return None.
  313. * @deffunc void ap_clear_method_list(ap_method_list_t *l)
  314. }
  315. procedure ap_clear_method_list(l: Pap_method_list_t);
  316. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  317. external LibHTTPD name LibNamePrefix + 'ap_clear_method_list' + LibSuff4;
  318. {
  319. * Set the content type for this request (r->content_type).
  320. * @param r The current request
  321. * @param ct The new content type
  322. * @deffunc void ap_set_content_type(request_rec *r, const char* ct)
  323. * @warning This function must be called to set r->content_type in order
  324. * for the AddOutputFilterByType directive to work correctly.
  325. }
  326. procedure ap_set_content_type(r: Prequest_rec; const ct: PChar);
  327. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  328. external LibHTTPD name LibNamePrefix + 'ap_set_content_type' + LibSuff8;
  329. { Hmmm... could macrofy these for now, and maybe forever, though the
  330. * definitions of the macros would get a whole lot hairier.
  331. }
  332. {
  333. * Output one character for this request
  334. * @param c the character to output
  335. * @param r the current request
  336. * @return The number of bytes sent
  337. * @deffunc int ap_rputc(int c, request_rec *r)
  338. }
  339. function ap_rputc(c: Integer; r: Prequest_rec): Integer;
  340. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  341. external LibHTTPD name LibNamePrefix + 'ap_rputc' + LibSuff8;
  342. {
  343. * Output a string for the current request
  344. * @param str The string to output
  345. * @param r The current request
  346. * @return The number of bytes sent
  347. * @deffunc int ap_rputs(const char *str, request_rec *r)
  348. }
  349. function ap_rputs(const str: PChar; r: Prequest_rec): Integer;
  350. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  351. external LibHTTPD name LibNamePrefix + 'ap_rputs' + LibSuff8;
  352. {
  353. * Write a buffer for the current request
  354. * @param buf The buffer to write
  355. * @param nbyte The number of bytes to send from the buffer
  356. * @param r The current request
  357. * @return The number of bytes sent
  358. * @deffunc int ap_rwrite(const void *buf, int nbyte, request_rec *r)
  359. }
  360. function ap_rwrite(const buf: Pointer; nbyte: Integer; r: Prequest_rec): Integer;
  361. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  362. external LibHTTPD name LibNamePrefix + 'ap_rwrite' + LibSuff12;
  363. {
  364. * Write an unspecified number of strings to the request
  365. * @param r The current request
  366. * @param ... The strings to write
  367. * @return The number of bytes sent
  368. * @deffunc int ap_rvputs(request_rec *r, ...)
  369. }
  370. function ap_rvputs(r: Prequest_rec; others: array of const): Integer;
  371. cdecl; external LibHTTPD name 'ap_rvputs';
  372. //AP_DECLARE_NONSTD(int) ap_rvputs(request_rec *r,...);
  373. {
  374. * Output data to the client in a printf format
  375. * @param r The current request
  376. * @param fmt The format string
  377. * @param vlist The arguments to use to fill out the format string
  378. * @return The number of bytes sent
  379. * @deffunc int ap_vrprintf(request_rec *r, const char *fmt, va_list vlist)
  380. }
  381. function ap_vrprintf(r: Prequest_rec; const fmt: PChar; vlist: va_list): Integer;
  382. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  383. external LibHTTPD name LibNamePrefix + 'ap_vrprintf' + LibSuff12;
  384. {
  385. * Output data to the client in a printf format
  386. * @param r The current request
  387. * @param fmt The format string
  388. * @param ... The arguments to use to fill out the format string
  389. * @return The number of bytes sent
  390. * @deffunc int ap_rprintf(request_rec *r, const char *fmt, ...)
  391. }
  392. function ap_rprintf(r: Prequest_rec; const fmt: PChar; others: array of const): Integer;
  393. cdecl; external LibHTTPD name 'ap_rprintf';
  394. //AP_DECLARE_NONSTD(int) ap_rprintf(request_rec *r, const char *fmt,...)
  395. // __attribute__((format(printf,2,3)));
  396. {
  397. * Flush all of the data for the current request to the client
  398. * @param r The current request
  399. * @return The number of bytes sent
  400. * @deffunc int ap_rflush(request_rec *r)
  401. }
  402. function ap_rflush(r: Prequest_rec): Integer;
  403. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  404. external LibHTTPD name LibNamePrefix + 'ap_rflush' + LibSuff4;
  405. {
  406. * Index used in custom_responses array for a specific error code
  407. * (only use outside protocol.c is in getting them configured).
  408. * @param status HTTP status code
  409. * @return The index of the response
  410. * @deffunc int ap_index_of_response(int status)
  411. }
  412. function ap_index_of_response(status: Integer): Integer;
  413. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  414. external LibHTTPD name LibNamePrefix + 'ap_index_of_response' + LibSuff4;
  415. {
  416. * Return the Status-Line for a given status code (excluding the
  417. * HTTP-Version field). If an invalid or unknown status code is
  418. * passed, "500 Internal Server Error" will be returned.
  419. * @param status The HTTP status code
  420. * @return The Status-Line
  421. * @deffunc const char *ap_get_status_line(int status)
  422. }
  423. function ap_get_status_line(status: Integer): PChar;
  424. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  425. external LibHTTPD name LibNamePrefix + 'ap_get_status_line' + LibSuff4;
  426. { Reading a block of data from the client connection (e.g., POST arg) }
  427. {
  428. * Setup the client to allow Apache to read the request body.
  429. * @param r The current request
  430. * @param read_policy How the server should interpret a chunked
  431. * transfer-encoding. One of: <pre>
  432. * REQUEST_NO_BODY Send 413 error if message has any body
  433. * REQUEST_CHUNKED_ERROR Send 411 error if body without Content-Length
  434. * REQUEST_CHUNKED_DECHUNK If chunked, remove the chunks for me.
  435. * </pre>
  436. * @return either OK or an error code
  437. * @deffunc int ap_setup_client_block(request_rec *r, int read_policy)
  438. }
  439. function ap_setup_client_block(r: Prequest_rec; read_policy: Integer): Integer;
  440. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  441. external LibHTTPD name LibNamePrefix + 'ap_setup_client_block' + LibSuff8;
  442. {
  443. * Determine if the client has sent any data. This also sends a
  444. * 100 Continue response to HTTP/1.1 clients, so modules should not be called
  445. * until the module is ready to read content.
  446. * @warning Never call this function more than once.
  447. * @param r The current request
  448. * @return 0 if there is no message to read, 1 otherwise
  449. * @deffunc int ap_should_client_block(request_rec *r)
  450. }
  451. function ap_should_client_block(r: Prequest_rec): Integer;
  452. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  453. external LibHTTPD name LibNamePrefix + 'ap_should_client_block' + LibSuff4;
  454. {
  455. * Call this in a loop. It will put data into a buffer and return the length
  456. * of the input block
  457. * @param r The current request
  458. * @param buffer The buffer in which to store the data
  459. * @param bufsiz The size of the buffer
  460. * @return Number of bytes inserted into the buffer. When done reading, 0
  461. * if EOF, or -1 if there was an error
  462. * @deffunc long ap_get_client_block(request_rec *r, char *buffer, apr_size_t bufsiz)
  463. }
  464. function ap_get_client_block(r: Prequest_rec; buffer: PChar; bufsiz: apr_size_t): cLong;
  465. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  466. external LibHTTPD name LibNamePrefix + 'ap_get_client_block' + LibSuff12;
  467. {
  468. * In HTTP/1.1, any method can have a body. However, most GET handlers
  469. * wouldn't know what to do with a request body if they received one.
  470. * This helper routine tests for and reads any message body in the request,
  471. * simply discarding whatever it receives. We need to do this because
  472. * failing to read the request body would cause it to be interpreted
  473. * as the next request on a persistent connection.
  474. * @param r The current request
  475. * @return error status if request is malformed, OK otherwise
  476. * @deffunc int ap_discard_request_body(request_rec *r)
  477. }
  478. function ap_discard_request_body(r: Prequest_rec): Integer;
  479. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  480. external LibHTTPD name LibNamePrefix + 'ap_discard_request_body' + LibSuff4;
  481. {
  482. * Setup the output headers so that the client knows how to authenticate
  483. * itself the next time, if an authentication request failed. This function
  484. * works for both basic and digest authentication
  485. * @param r The current request
  486. * @deffunc void ap_note_auth_failure(request_rec *r)
  487. }
  488. procedure ap_note_auth_failure(r: Prequest_rec);
  489. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  490. external LibHTTPD name LibNamePrefix + 'ap_note_auth_failure' + LibSuff4;
  491. {
  492. * Setup the output headers so that the client knows how to authenticate
  493. * itself the next time, if an authentication request failed. This function
  494. * works only for basic authentication
  495. * @param r The current request
  496. * @deffunc void ap_note_basic_auth_failure(request_rec *r)
  497. }
  498. procedure ap_note_basic_auth_failure(r: Prequest_rec);
  499. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  500. external LibHTTPD name LibNamePrefix + 'ap_note_basic_auth_failure' + LibSuff4;
  501. {
  502. * Setup the output headers so that the client knows how to authenticate
  503. * itself the next time, if an authentication request failed. This function
  504. * works only for digest authentication
  505. * @param r The current request
  506. * @deffunc void ap_note_digest_auth_failure(request_rec *r)
  507. }
  508. procedure ap_note_digest_auth_failure(r: Prequest_rec);
  509. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  510. external LibHTTPD name LibNamePrefix + 'ap_note_digest_auth_failure' + LibSuff4;
  511. {
  512. * Get the password from the request headers
  513. * @param r The current request
  514. * @param pw The password as set in the headers
  515. * @return 0 (OK) if it set the 'pw' argument (and assured
  516. * a correct value in r->user); otherwise it returns
  517. * an error code, either HTTP_INTERNAL_SERVER_ERROR if things are
  518. * really confused, HTTP_UNAUTHORIZED if no authentication at all
  519. * seemed to be in use, or DECLINED if there was authentication but
  520. * it wasn't Basic (in which case, the caller should presumably
  521. * decline as well).
  522. * @deffunc int ap_get_basic_auth_pw(request_rec *r, const char **pw)
  523. }
  524. function ap_get_basic_auth_pw(r: Prequest_rec; pw: PPChar): Integer;
  525. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  526. external LibHTTPD name LibNamePrefix + 'ap_get_basic_auth_pw' + LibSuff8;
  527. {
  528. * parse_uri: break apart the uri
  529. * @warning Side Effects: <pre>
  530. * - sets r->args to rest after '?' (or NULL if no '?')
  531. * - sets r->uri to request uri (without r->args part)
  532. * - sets r->hostname (if not set already) from request (scheme://host:port)
  533. * </pre>
  534. * @param r The current request
  535. * @param uri The uri to break apart
  536. * @deffunc void ap_parse_uri(request_rec *r, const char *uri)
  537. }
  538. procedure ap_parse_uri(r: Prequest_rec; const uri: PChar);
  539. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  540. external LibHTTPD name LibNamePrefix + 'ap_parse_uri' + LibSuff8;
  541. {
  542. * Get the next line of input for the request
  543. * @param s The buffer into which to read the line
  544. * @param n The size of the buffer
  545. * @param r The request
  546. * @param fold Whether to merge continuation lines
  547. * @return The length of the line, if successful
  548. * n, if the line is too big to fit in the buffer
  549. * -1 for miscellaneous errors
  550. * @deffunc int ap_method_number_of(const char *method)
  551. }
  552. function ap_getline(s: PChar; n: Integer; r: Prequest_rec; fold: Integer): Integer;
  553. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  554. external LibHTTPD name LibNamePrefix + 'ap_getline' + LibSuff16;
  555. {
  556. * Get the next line of input for the request
  557. *
  558. * Note: on ASCII boxes, ap_rgetline is a macro which simply calls
  559. * ap_rgetline_core to get the line of input.
  560. *
  561. * on EBCDIC boxes, ap_rgetline is a wrapper function which
  562. * translates ASCII protocol lines to the local EBCDIC code page
  563. * after getting the line of input.
  564. *
  565. * @param s Pointer to the pointer to the buffer into which the line
  566. * should be read; if *s==NULL, a buffer of the necessary size
  567. * to hold the data will be allocated from the request pool
  568. * @param n The size of the buffer
  569. * @param read The length of the line.
  570. * @param r The request
  571. * @param fold Whether to merge continuation lines
  572. * @param bb Working brigade to use when reading buckets
  573. * @return APR_SUCCESS, if successful
  574. * APR_ENOSPC, if the line is too big to fit in the buffer
  575. * Other errors where appropriate
  576. }
  577. {#if APR_CHARSET_EBCDIC
  578. AP_DECLARE(apr_status_t) ap_rgetline(char **s, apr_size_t n,
  579. apr_size_t *read,
  580. request_rec *r, int fold,
  581. apr_bucket_brigade *bb);
  582. #else }{ ASCII box }
  583. {#define ap_rgetline(s, n, read, r, fold, bb) \
  584. ap_rgetline_core((s), (n), (read), (r), (fold), (bb))
  585. #endif}
  586. {AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
  587. apr_size_t *read,
  588. request_rec *r, int fold,
  589. apr_bucket_brigade *bb);}
  590. {
  591. * Get the method number associated with the given string, assumed to
  592. * contain an HTTP method. Returns M_INVALID if not recognized.
  593. * @param method A string containing a valid HTTP method
  594. * @return The method number
  595. }
  596. function ap_method_number_of(const method: PChar): Integer;
  597. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  598. external LibHTTPD name LibNamePrefix + 'ap_method_number_of' + LibSuff4;
  599. {
  600. * Get the method name associated with the given internal method
  601. * number. Returns NULL if not recognized.
  602. * @param p A pool to use for temporary allocations.
  603. * @param methnum An integer value corresponding to an internal method number
  604. * @return The name corresponding to the method number
  605. }
  606. function ap_method_name_of(p: Papr_pool_t; methnum: Integer): PChar;
  607. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  608. external LibHTTPD name LibNamePrefix + 'ap_method_name_of' + LibSuff8;
  609. { Hooks }
  610. {
  611. * post_read_request --- run right after read_request or internal_redirect,
  612. * and not run during any subrequests.
  613. }
  614. {
  615. * This hook allows modules to affect the request immediately after the request
  616. * has been read, and before any other phases have been processes. This allows
  617. * modules to make decisions based upon the input header fields
  618. * @param r The current request
  619. * @return OK or DECLINED
  620. * @deffunc ap_run_post_read_request(request_rec *r)
  621. }
  622. type
  623. ap_HOOK_post_read_request_t = function(r: Prequest_rec): Integer; cdecl;
  624. procedure ap_hook_post_read_request(pf: ap_HOOK_post_read_request_t;
  625. const aszPre: PPChar; const aszSucc: PPChar; nOrder: Integer);
  626. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  627. external LibHTTPD name LibNamePrefix + 'ap_hook_post_read_request' + LibSuff16;
  628. {
  629. * This hook allows modules to perform any module-specific logging activities
  630. * over and above the normal server things.
  631. * @param r The current request
  632. * @return OK, DECLINED, or HTTP_...
  633. * @deffunc int ap_run_log_transaction(request_rec *r)
  634. }
  635. type
  636. ap_HOOK_log_transaction_t = function(r: Prequest_rec): Integer; cdecl;
  637. procedure ap_hook_log_transaction(pf: ap_HOOK_log_transaction_t;
  638. const aszPre: PPChar; const aszSucc: PPChar; nOrder: Integer);
  639. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  640. external LibHTTPD name LibNamePrefix + 'ap_hook_log_transaction' + LibSuff16;
  641. {
  642. * This hook allows modules to retrieve the http scheme for a request. This
  643. * allows Apache modules to easily extend the scheme that Apache understands
  644. * @param r The current request
  645. * @return The http method from the request
  646. }
  647. type
  648. ap_HOOK_http_method_t = function(const r: Prequest_rec): PChar; cdecl;
  649. procedure ap_hook_http_scheme(pf: ap_HOOK_http_method_t;
  650. const aszPre: PPChar; const aszSucc: PPChar; nOrder: Integer);
  651. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  652. external LibHTTPD name LibNamePrefix + 'ap_hook_http_scheme' + LibSuff16;
  653. {
  654. * Return the default port from the current request
  655. * @param r The current request
  656. * @return The current port
  657. * @deffunc apr_port_t ap_run_default_port(const request_rec *r)
  658. }
  659. type
  660. ap_HOOK_default_port_t = function(const r: Prequest_rec): apr_port_t; cdecl;
  661. procedure ap_hook_default_port(pf: ap_HOOK_default_port_t;
  662. const aszPre: PPChar; const aszSucc: PPChar; nOrder: Integer);
  663. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  664. external LibHTTPD name LibNamePrefix + 'ap_hook_default_port' + LibSuff16;
  665. {
  666. * A bucket referring to an HTTP error
  667. * This bucket can be passed down the filter stack to indicate that an
  668. * HTTP error occurred while running a filter. In order for this bucket
  669. * to be used successfully, it MUST be sent as the first bucket in the
  670. * first brigade to be sent from a given filter.
  671. }
  672. type
  673. ap_bucket_error = record
  674. { Number of buckets using this memory }
  675. refcount: apr_bucket_refcount;
  676. { The error code }
  677. status: Integer;
  678. { The error string }
  679. data: PChar;
  680. end;
  681. Pap_bucket_error = ^ap_bucket_error;
  682. //AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_error;
  683. {
  684. * Determine if a bucket is an error bucket
  685. * @param e The bucket to inspect
  686. * @return true or false
  687. }
  688. //#define AP_BUCKET_IS_ERROR(e) (e->type == &ap_bucket_type_error)
  689. {
  690. * Make the bucket passed in an error bucket
  691. * @param b The bucket to make into an error bucket
  692. * @param error The HTTP error code to put in the bucket.
  693. * @param buf An optional error string to put in the bucket.
  694. * @param p A pool to allocate out of.
  695. * @return The new bucket, or NULL if allocation failed
  696. * @deffunc apr_bucket *ap_bucket_error_make(apr_bucket *b, int error, const char *buf, apr_pool_t *p)
  697. }
  698. function ap_bucket_error_make(b: Papr_bucket; error: Integer;
  699. const buf: PChar; p: Papr_pool_t): Papr_bucket;
  700. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  701. external LibHTTPD name LibNamePrefix + 'ap_bucket_error_make' + LibSuff16;
  702. {
  703. * Create a bucket referring to an HTTP error.
  704. * @param error The HTTP error code to put in the bucket.
  705. * @param buf An optional error string to put in the bucket.
  706. * @param p A pool to allocate the error string out of.
  707. * @param list The bucket allocator from which to allocate the bucket
  708. * @return The new bucket, or NULL if allocation failed
  709. * @deffunc apr_bucket *ap_bucket_error_create(int error, const char *buf, apr_pool_t *p, apr_bucket_alloc_t *list)
  710. }
  711. function ap_bucket_error_create(error: Integer; const buf: PChar;
  712. p: Papr_pool_t; list: Papr_bucket_alloc_t): Papr_bucket;
  713. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  714. external LibHTTPD name LibNamePrefix + 'ap_bucket_error_create' + LibSuff16;
  715. function ap_byterange_filter(f: Pap_filter_t; b: Papr_bucket_brigade): apr_status_t;
  716. cdecl; external LibHTTPD name 'ap_byterange_filter';
  717. function ap_http_header_filter(f: Pap_filter_t; b: Papr_bucket_brigade): apr_status_t;
  718. cdecl; external LibHTTPD name 'ap_http_header_filter';
  719. function ap_content_length_filter(f: Pap_filter_t; b: Papr_bucket_brigade): apr_status_t;
  720. cdecl; external LibHTTPD name 'ap_content_length_filter';
  721. function ap_old_write_filter(f: Pap_filter_t; b: Papr_bucket_brigade): apr_status_t;
  722. cdecl; external LibHTTPD name 'ap_old_write_filter';
  723. {
  724. * Sett up the protocol fields for subsidiary requests
  725. * @param rnew New Sub Request
  726. * @param r current request
  727. }
  728. procedure ap_set_sub_req_protocol(rnew: Prequest_rec; const r: Prequest_rec);
  729. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  730. external LibHTTPD name LibNamePrefix + 'ap_set_sub_req_protocol' + LibSuff8;
  731. {
  732. * A wrapup function to keep the internal accounting straight.
  733. * Indicates that there is no more content coming.
  734. * @param sub_r Subrequest that is now compete
  735. }
  736. procedure ap_finalize_sub_req_protocol(sub_r: Prequest_rec);
  737. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  738. external LibHTTPD name LibNamePrefix + 'ap_finalize_sub_req_protocol' + LibSuff4;
  739. {**
  740. * Send an interim (HTTP 1xx) response immediately.
  741. * @param r The request
  742. * @param send_headers Whether to send&clear headers in r->headers_out
  743. *}//added in Apache 2.2.7
  744. procedure ap_send_interim_response(r: Prequest_rec; send_headers: Integer);
  745. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  746. external LibHTTPD name LibNamePrefix + 'ap_send_interim_response' + LibSuff8;