apr_buckets.inc 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483
  1. { Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. }
  16. {
  17. * @file apr_buckets.h
  18. * @brief APR-UTIL Buckets/Bucket Brigades
  19. }
  20. {#if defined(APR_BUCKET_DEBUG) && !defined(APR_RING_DEBUG)
  21. #define APR_RING_DEBUG
  22. #endif
  23. #include "apu.h"
  24. #include "apr_network_io.h"
  25. #include "apr_file_io.h"
  26. #include "apr_general.h"
  27. #include "apr_mmap.h"
  28. #include "apr_errno.h"
  29. #include "apr_ring.h"
  30. #include "apr.h"
  31. #if APR_HAVE_SYS_UIO_H
  32. #include <sys/uio.h> for struct iovec
  33. #endif
  34. #if APR_HAVE_STDARG_H
  35. #include <stdarg.h>
  36. #endif}
  37. {
  38. * @defgroup APR_Util_Bucket_Brigades Bucket Brigades
  39. * @ingroup APR_Util
  40. }
  41. { default bucket buffer size - 8KB minus room for memory allocator headers }
  42. const
  43. APR_BUCKET_BUFF_SIZE = 8000;
  44. { Determines how a bucket or brigade should be read }
  45. type
  46. apr_read_type_e = (
  47. APR_BLOCK_READ, {< block until data becomes available }
  48. APR_NONBLOCK_READ {< return immediately if no data is available }
  49. );
  50. {
  51. * The one-sentence buzzword-laden overview: Bucket brigades represent
  52. * a complex data stream that can be passed through a layered IO
  53. * system without unnecessary copying. A longer overview follows...
  54. *
  55. * A bucket brigade is a doubly linked list (ring) of buckets, so we
  56. * aren't limited to inserting at the front and removing at the end.
  57. * Buckets are only passed around as members of a brigade, although
  58. * singleton buckets can occur for short periods of time.
  59. *
  60. * Buckets are data stores of various types. They can refer to data in
  61. * memory, or part of a file or mmap area, or the output of a process,
  62. * etc. Buckets also have some type-dependent accessor functions:
  63. * read, split, copy, setaside, and destroy.
  64. *
  65. * read returns the address and size of the data in the bucket. If the
  66. * data isn't in memory then it is read in and the bucket changes type
  67. * so that it can refer to the new location of the data. If all the
  68. * data doesn't fit in the bucket then a new bucket is inserted into
  69. * the brigade to hold the rest of it.
  70. *
  71. * split divides the data in a bucket into two regions. After a split
  72. * the original bucket refers to the first part of the data and a new
  73. * bucket inserted into the brigade after the original bucket refers
  74. * to the second part of the data. Reference counts are maintained as
  75. * necessary.
  76. *
  77. * setaside ensures that the data in the bucket has a long enough
  78. * lifetime. Sometimes it is convenient to create a bucket referring
  79. * to data on the stack in the expectation that it will be consumed
  80. * (output to the network) before the stack is unwound. If that
  81. * expectation turns out not to be valid, the setaside function is
  82. * called to move the data somewhere safer.
  83. *
  84. * copy makes a duplicate of the bucket structure as long as it's
  85. * possible to have multiple references to a single copy of the
  86. * data itself. Not all bucket types can be copied.
  87. *
  88. * destroy maintains the reference counts on the resources used by a
  89. * bucket and frees them if necessary.
  90. *
  91. * Note: all of the above functions have wrapper macros (apr_bucket_read(),
  92. * apr_bucket_destroy(), etc), and those macros should be used rather
  93. * than using the function pointers directly.
  94. *
  95. * To write a bucket brigade, they are first made into an iovec, so that we
  96. * don't write too little data at one time. Currently we ignore compacting the
  97. * buckets into as few buckets as possible, but if we really want good
  98. * performance, then we need to compact the buckets before we convert to an
  99. * iovec, or possibly while we are converting to an iovec.
  100. }
  101. {
  102. * Forward declaration of the main types.
  103. }
  104. { @see apr_bucket_brigade }
  105. Papr_bucket_brigade = ^apr_bucket_brigade;
  106. PPapr_bucket_brigade = ^Papr_bucket_brigade;
  107. { @see apr_bucket }
  108. Papr_bucket = ^apr_bucket;
  109. PPapr_bucket = ^Papr_bucket;
  110. { @see apr_bucket_alloc_t }
  111. apr_bucket_alloc_t = record end;
  112. Papr_bucket_alloc_t = ^apr_bucket_alloc_t;
  113. { @see apr_bucket_type_t }
  114. Papr_bucket_type_t = ^apr_bucket_type_t;
  115. is_metadata = (
  116. { This bucket type represents actual data to send to the client. }
  117. APR_BUCKET_DATA = 0,
  118. { This bucket type represents metadata. }
  119. APR_BUCKET_METADATA = 1
  120. );
  121. destroy_t = procedure (data: Pointer);
  122. read_t = function (b: Papr_bucket; const str: PPChar; len: Papr_size_t;
  123. block: apr_read_type_e): apr_status_t;
  124. setaside_t = function (e: Papr_bucket; pool: Papr_pool_t): apr_status_t;
  125. split_t = function (e: Papr_bucket; point: apr_size_t): apr_status_t;
  126. copy_t = function (e: Papr_bucket; c: PPapr_bucket): apr_status_t;
  127. {
  128. * Basic bucket type
  129. }
  130. apr_bucket_type_t = record
  131. {
  132. * The name of the bucket type
  133. }
  134. name: PChar;
  135. {
  136. * The number of functions this bucket understands. Can not be less than
  137. * five.
  138. }
  139. num_func: Integer;
  140. {
  141. * Whether the bucket contains metadata (ie, information that
  142. * describes the regular contents of the brigade). The metadata
  143. * is not returned by apr_bucket_read() and is not indicated by
  144. * the ->length of the apr_bucket itself. In other words, an
  145. * empty bucket is safe to arbitrarily remove if and only if it
  146. * contains no metadata. In this sense, "data" is just raw bytes
  147. * that are the "content" of the brigade and "metadata" describes
  148. * that data but is not a proper part of it.
  149. }
  150. { Declaration moved up }
  151. {
  152. * Free the private data and any resources used by the bucket (if they
  153. * aren't shared with another bucket). This function is required to be
  154. * implemented for all bucket types, though it might be a no-op on some
  155. * of them (namely ones that never allocate any private data structures).
  156. * @param data The private data pointer from the bucket to be destroyed
  157. }
  158. destroy: destroy_t;
  159. {
  160. * Read the data from the bucket. This is required to be implemented
  161. * for all bucket types.
  162. * @param b The bucket to read from
  163. * @param str A place to store the data read. Allocation should only be
  164. * done if absolutely necessary.
  165. * @param len The amount of data read.
  166. * @param block Should this read function block if there is more data that
  167. * cannot be read immediately.
  168. }
  169. read: read_t;
  170. {
  171. * Make it possible to set aside the data for at least as long as the
  172. * given pool. Buckets containing data that could potentially die before
  173. * this pool (e.g. the data resides on the stack, in a child pool of
  174. * the given pool, or in a disjoint pool) must somehow copy, shift, or
  175. * transform the data to have the proper lifetime.
  176. * @param e The bucket to convert
  177. * @remark Some bucket types contain data that will always outlive the
  178. * bucket itself. For example no data (EOS and FLUSH), or the data
  179. * resides in global, constant memory (IMMORTAL), or the data is on
  180. * the heap (HEAP). For these buckets, apr_bucket_setaside_noop can
  181. * be used.
  182. }
  183. setaside: setaside_t;
  184. {
  185. * Split one bucket in two at the specified position by duplicating
  186. * the bucket structure (not the data) and modifying any necessary
  187. * start/end/offset information. If it's not possible to do this
  188. * for the bucket type (perhaps the length of the data is indeterminate,
  189. * as with pipe and socket buckets), then APR_ENOTIMPL is returned.
  190. * @param e The bucket to split
  191. * @param point The offset of the first byte in the new bucket
  192. }
  193. split: split_t;
  194. {
  195. * Copy the bucket structure (not the data), assuming that this is
  196. * possible for the bucket type. If it's not, APR_ENOTIMPL is returned.
  197. * @param e The bucket to copy
  198. * @param c Returns a pointer to the new bucket
  199. }
  200. copy: copy_t;
  201. end;
  202. {
  203. * apr_bucket structures are allocated on the malloc() heap and
  204. * their lifetime is controlled by the parent apr_bucket_brigade
  205. * structure. Buckets can move from one brigade to another e.g. by
  206. * calling APR_BRIGADE_CONCAT(). In general the data in a bucket has
  207. * the same lifetime as the bucket and is freed when the bucket is
  208. * destroyed; if the data is shared by more than one bucket (e.g.
  209. * after a split) the data is freed when the last bucket goes away.
  210. }
  211. free_t = procedure(e: Pointer);
  212. link_t = record
  213. next: Papr_bucket;
  214. prev: Papr_bucket;
  215. end;
  216. apr_bucket = record
  217. { Links to the rest of the brigade }
  218. link: link_t;
  219. { The type of bucket. }
  220. type_: Papr_bucket_type_t;
  221. { The length of the data in the bucket. This could have been implemented
  222. * with a function, but this is an optimization, because the most
  223. * common thing to do will be to get the length. If the length is unknown,
  224. * the value of this field will be (apr_size_t)(-1).
  225. }
  226. length: apr_size_t;
  227. { The start of the data in the bucket relative to the private base
  228. * pointer. The vast majority of bucket types allow a fixed block of
  229. * data to be referenced by multiple buckets, each bucket pointing to
  230. * a different segment of the data. That segment starts at base+start
  231. * and ends at base+start+length.
  232. * If the length == (apr_size_t)(-1), then start == -1.
  233. }
  234. start: apr_off_t;
  235. { type-dependent data hangs off this pointer }
  236. data: Pointer;
  237. {
  238. * Pointer to function used to free the bucket. This function should
  239. * always be defined and it should be consistent with the memory
  240. * function used to allocate the bucket. For example, if malloc() is
  241. * used to allocate the bucket, this pointer should point to free().
  242. * @param e Pointer to the bucket being freed
  243. }
  244. free: free_t;
  245. { The freelist from which this bucket was allocated }
  246. list: Papr_bucket_alloc_t;
  247. end;
  248. { A list of buckets }
  249. apr_bucket_list = record
  250. next: Papr_bucket;
  251. prev: Papr_bucket;
  252. end;
  253. apr_bucket_brigade = record
  254. { The pool to associate the brigade with. The data is not allocated out
  255. * of the pool, but a cleanup is registered with this pool. If the
  256. * brigade is destroyed by some mechanism other than pool destruction,
  257. * the destroying function is responsible for killing the cleanup.
  258. }
  259. p: Papr_pool_t;
  260. { The buckets in the brigade are on this list. }
  261. {
  262. * The apr_bucket_list structure doesn't actually need a name tag
  263. * because it has no existence independent of struct apr_bucket_brigade;
  264. * the ring macros are designed so that you can leave the name tag
  265. * argument empty in this situation but apparently the Windows compiler
  266. * doesn't like that.
  267. }
  268. list: apr_bucket_list;
  269. { The freelist from which this bucket was allocated }
  270. bucket_alloc: Papr_bucket_alloc_t;
  271. end;
  272. {
  273. * Function called when a brigade should be flushed
  274. }
  275. apr_brigade_flush = function (bb: Papr_bucket_brigade; ctx: Pointer): apr_status_t;
  276. {
  277. * define APR_BUCKET_DEBUG if you want your brigades to be checked for
  278. * validity at every possible instant. this will slow your code down
  279. * substantially but is a very useful debugging tool.
  280. }
  281. {#ifdef APR_BUCKET_DEBUG
  282. #define APR_BRIGADE_CHECK_CONSISTENCY(b) \
  283. APR_RING_CHECK_CONSISTENCY(&(b)->list, apr_bucket, link)
  284. #define APR_BUCKET_CHECK_CONSISTENCY(e) \
  285. APR_RING_CHECK_ELEM_CONSISTENCY((e), apr_bucket, link)
  286. #else}
  287. {
  288. * checks the ring pointers in a bucket brigade for consistency. an
  289. * abort() will be triggered if any inconsistencies are found.
  290. * note: this is a no-op unless APR_BUCKET_DEBUG is defined.
  291. * @param b The brigade
  292. }
  293. //#define APR_BRIGADE_CHECK_CONSISTENCY(b)
  294. {
  295. * checks the brigade a bucket is in for ring consistency. an
  296. * abort() will be triggered if any inconsistencies are found.
  297. * note: this is a no-op unless APR_BUCKET_DEBUG is defined.
  298. * @param e The bucket
  299. }
  300. //#define APR_BUCKET_CHECK_CONSISTENCY(e)
  301. //#endif
  302. {
  303. * Wrappers around the RING macros to reduce the verbosity of the code
  304. * that handles bucket brigades.
  305. }
  306. {
  307. * The magic pointer value that indicates the head of the brigade
  308. * @remark This is used to find the beginning and end of the brigade, eg:
  309. * <pre>
  310. * while (e != APR_BRIGADE_SENTINEL(b)) (
  311. * ...
  312. * e = APR_BUCKET_NEXT(e);
  313. * )
  314. * </pre>
  315. * @param b The brigade
  316. * @return The magic pointer value
  317. }
  318. //#define APR_BRIGADE_SENTINEL(b) APR_RING_SENTINEL(&(b)->list, apr_bucket, link)
  319. {
  320. * Determine if the bucket brigade is empty
  321. * @param b The brigade to check
  322. * @return true or false
  323. }
  324. //#define APR_BRIGADE_EMPTY(b) APR_RING_EMPTY(&(b)->list, apr_bucket, link)
  325. {
  326. * Return the first bucket in a brigade
  327. * @param b The brigade to query
  328. * @return The first bucket in the brigade
  329. }
  330. //#define APR_BRIGADE_FIRST(b) APR_RING_FIRST(&(b)->list)
  331. {
  332. * Return the last bucket in a brigade
  333. * @param b The brigade to query
  334. * @return The last bucket in the brigade
  335. }
  336. //#define APR_BRIGADE_LAST(b) APR_RING_LAST(&(b)->list)
  337. {
  338. * Insert a list of buckets at the front of a brigade
  339. * @param b The brigade to add to
  340. * @param e The first bucket in a list of buckets to insert
  341. }
  342. {#define APR_BRIGADE_INSERT_HEAD(b, e) do ( \
  343. apr_bucket *ap__b = (e); \
  344. APR_RING_INSERT_HEAD(&(b)->list, ap__b, apr_bucket, link); \
  345. APR_BRIGADE_CHECK_CONSISTENCY((b)); \
  346. ) while (0)}
  347. {
  348. * Insert a list of buckets at the end of a brigade
  349. * @param b The brigade to add to
  350. * @param e The first bucket in a list of buckets to insert
  351. }
  352. {#define APR_BRIGADE_INSERT_TAIL(b, e) do begin \
  353. apr_bucket *ap__b = (e); \
  354. APR_RING_INSERT_TAIL(&(b)->list, ap__b, apr_bucket, link); \
  355. APR_BRIGADE_CHECK_CONSISTENCY((b)); \
  356. end while (0)}
  357. {
  358. * Concatenate brigade b onto the end of brigade a, leaving brigade b empty
  359. * @param a The first brigade
  360. * @param b The second brigade
  361. }
  362. {#define APR_BRIGADE_CONCAT(a, b) do begin
  363. APR_RING_CONCAT(&(a)->list, &(b)->list, apr_bucket, link); \
  364. APR_BRIGADE_CHECK_CONSISTENCY((a)); \
  365. end while (0);}
  366. {
  367. * Prepend brigade b onto the beginning of brigade a, leaving brigade b empty
  368. * @param a The first brigade
  369. * @param b The second brigade
  370. }
  371. {#define APR_BRIGADE_PREPEND(a, b) do begin
  372. APR_RING_PREPEND(&(a)->list, &(b)->list, apr_bucket, link); \
  373. APR_BRIGADE_CHECK_CONSISTENCY((a)); \
  374. end while (0)}
  375. {
  376. * Insert a list of buckets before a specified bucket
  377. * @param a The bucket to insert before
  378. * @param b The buckets to insert
  379. }
  380. {#define APR_BUCKET_INSERT_BEFORE(a, b) do begin
  381. apr_bucket *ap__a = (a), *ap__b = (b); \
  382. APR_RING_INSERT_BEFORE(ap__a, ap__b, link); \
  383. APR_BUCKET_CHECK_CONSISTENCY(ap__a); \
  384. end while (0)}
  385. {
  386. * Insert a list of buckets after a specified bucket
  387. * @param a The bucket to insert after
  388. * @param b The buckets to insert
  389. }
  390. {#define APR_BUCKET_INSERT_AFTER(a, b) do begin
  391. apr_bucket *ap__a = (a), *ap__b = (b); \
  392. APR_RING_INSERT_AFTER(ap__a, ap__b, link); \
  393. APR_BUCKET_CHECK_CONSISTENCY(ap__a); \
  394. end while (0)}
  395. {
  396. * Get the next bucket in the list
  397. * @param e The current bucket
  398. * @return The next bucket
  399. }
  400. //#define APR_BUCKET_NEXT(e) APR_RING_NEXT((e), link)
  401. {
  402. * Get the previous bucket in the list
  403. * @param e The current bucket
  404. * @return The previous bucket
  405. }
  406. //#define APR_BUCKET_PREV(e) APR_RING_PREV((e), link)
  407. {
  408. * Remove a bucket from its bucket brigade
  409. * @param e The bucket to remove
  410. }
  411. //#define APR_BUCKET_REMOVE(e) APR_RING_REMOVE((e), link)
  412. {
  413. * Initialize a new bucket's prev/next pointers
  414. * @param e The bucket to initialize
  415. }
  416. //#define APR_BUCKET_INIT(e) APR_RING_ELEM_INIT((e), link)
  417. {
  418. * Determine if a bucket contains metadata. An empty bucket is
  419. * safe to arbitrarily remove if and only if this is false.
  420. * @param e The bucket to inspect
  421. * @return true or false
  422. }
  423. //#define APR_BUCKET_IS_METADATA(e) ((e)->type->is_metadata)
  424. {
  425. * Determine if a bucket is a FLUSH bucket
  426. * @param e The bucket to inspect
  427. * @return true or false
  428. }
  429. //#define APR_BUCKET_IS_FLUSH(e) ((e)->type == &apr_bucket_type_flush)
  430. {
  431. * Determine if a bucket is an EOS bucket
  432. * @param e The bucket to inspect
  433. * @return true or false
  434. }
  435. //#define APR_BUCKET_IS_EOS(e) ((e)->type == &apr_bucket_type_eos)
  436. {
  437. * Determine if a bucket is a FILE bucket
  438. * @param e The bucket to inspect
  439. * @return true or false
  440. }
  441. //#define APR_BUCKET_IS_FILE(e) ((e)->type == &apr_bucket_type_file)
  442. {
  443. * Determine if a bucket is a PIPE bucket
  444. * @param e The bucket to inspect
  445. * @return true or false
  446. }
  447. //#define APR_BUCKET_IS_PIPE(e) ((e)->type == &apr_bucket_type_pipe)
  448. {
  449. * Determine if a bucket is a SOCKET bucket
  450. * @param e The bucket to inspect
  451. * @return true or false
  452. }
  453. //#define APR_BUCKET_IS_SOCKET(e) ((e)->type == &apr_bucket_type_socket)
  454. {
  455. * Determine if a bucket is a HEAP bucket
  456. * @param e The bucket to inspect
  457. * @return true or false
  458. }
  459. //#define APR_BUCKET_IS_HEAP(e) ((e)->type == &apr_bucket_type_heap)
  460. {
  461. * Determine if a bucket is a TRANSIENT bucket
  462. * @param e The bucket to inspect
  463. * @return true or false
  464. }
  465. //#define APR_BUCKET_IS_TRANSIENT(e) ((e)->type == &apr_bucket_type_transient)
  466. {
  467. * Determine if a bucket is a IMMORTAL bucket
  468. * @param e The bucket to inspect
  469. * @return true or false
  470. }
  471. //#define APR_BUCKET_IS_IMMORTAL(e) ((e)->type == &apr_bucket_type_immortal)
  472. //#if APR_HAS_MMAP
  473. {
  474. * Determine if a bucket is a MMAP bucket
  475. * @param e The bucket to inspect
  476. * @return true or false
  477. }
  478. //#define APR_BUCKET_IS_MMAP(e) ((e)->type == &apr_bucket_type_mmap)
  479. //#endif
  480. {
  481. * Determine if a bucket is a POOL bucket
  482. * @param e The bucket to inspect
  483. * @return true or false
  484. }
  485. //#define APR_BUCKET_IS_POOL(e) ((e)->type == &apr_bucket_type_pool)
  486. {
  487. * General-purpose reference counting for the various bucket types.
  488. *
  489. * Any bucket type that keeps track of the resources it uses (i.e.
  490. * most of them except for IMMORTAL, TRANSIENT, and EOS) needs to
  491. * attach a reference count to the resource so that it can be freed
  492. * when the last bucket that uses it goes away. Resource-sharing may
  493. * occur because of bucket splits or buckets that refer to globally
  494. * cached data. }
  495. { @see apr_bucket_refcount }
  496. Papr_bucket_refcount = ^apr_bucket_refcount;
  497. {
  498. * The structure used to manage the shared resource must start with an
  499. * apr_bucket_refcount which is updated by the general-purpose refcount
  500. * code. A pointer to the bucket-type-dependent private data structure
  501. * can be cast to a pointer to an apr_bucket_refcount and vice versa.
  502. }
  503. apr_bucket_refcount = record
  504. { The number of references to this bucket }
  505. refcount: Integer;
  506. end;
  507. { ***** Reference-counted bucket types ***** }
  508. { @see apr_bucket_heap }
  509. Papr_bucket_heap = ^apr_bucket_heap;
  510. {
  511. * A bucket referring to data allocated off the heap.
  512. }
  513. free_func_t = procedure (data: Pointer);
  514. apr_bucket_heap = record
  515. { Number of buckets using this memory }
  516. refcount: apr_bucket_refcount;
  517. { The start of the data actually allocated. This should never be
  518. * modified, it is only used to free the bucket.
  519. }
  520. base: PChar;
  521. { how much memory was allocated }
  522. alloc_len: apr_size_t;
  523. { function to use to delete the data }
  524. free_func: free_func_t;
  525. end;
  526. { @see apr_bucket_pool }
  527. Papr_bucket_pool = ^apr_bucket_pool;
  528. {
  529. * A bucket referring to data allocated from a pool
  530. }
  531. apr_bucket_pool = record
  532. { The pool bucket must be able to be easily morphed to a heap
  533. * bucket if the pool gets cleaned up before all references are
  534. * destroyed. This apr_bucket_heap structure is populated automatically
  535. * when the pool gets cleaned up, and subsequent calls to pool_read()
  536. * will result in the apr_bucket in question being morphed into a
  537. * regular heap bucket. (To avoid having to do many extra refcount
  538. * manipulations and b->data manipulations, the apr_bucket_pool
  539. * struct actually *contains* the apr_bucket_heap struct that it
  540. * will become as its first element; the two share their
  541. * apr_bucket_refcount members.)
  542. }
  543. heap: apr_bucket_heap;
  544. { The block of data actually allocated from the pool.
  545. * Segments of this block are referenced by adjusting
  546. * the start and length of the apr_bucket accordingly.
  547. * This will be NULL after the pool gets cleaned up.
  548. }
  549. base: PChar;
  550. { The pool the data was allocated from. When the pool
  551. * is cleaned up, this gets set to NULL as an indicator
  552. * to pool_read() that the data is now on the heap and
  553. * so it should morph the bucket into a regular heap
  554. * bucket before continuing.
  555. }
  556. pool: Papr_pool_t;
  557. { The freelist this structure was allocated from, which is
  558. * needed in the cleanup phase in order to allocate space on the heap
  559. }
  560. list: Papr_bucket_alloc_t;
  561. end;
  562. {$ifdef APR_HAS_MMAP}
  563. { @see apr_bucket_mmap }
  564. Papr_bucket_mmap = ^apr_bucket_mmap;
  565. {
  566. * A bucket referring to an mmap()ed file
  567. }
  568. apr_bucket_mmap = record
  569. { Number of buckets using this memory }
  570. refcount: apr_bucket_refcount;
  571. { The mmap this sub_bucket refers to }
  572. mmap: Papr_mmap_t;
  573. end;
  574. {$endif}
  575. { @see apr_bucket_file }
  576. Papr_bucket_file = ^apr_bucket_file;
  577. {
  578. * A bucket referring to an file
  579. }
  580. apr_bucket_file = record
  581. { Number of buckets using this memory }
  582. refcount: apr_bucket_refcount;
  583. { The file this bucket refers to }
  584. fd: Papr_file_t;
  585. { The pool into which any needed structures should
  586. * be created while reading from this file bucket }
  587. readpool: Papr_pool_t;
  588. {$ifdef APR_HAS_MMAP}
  589. { Whether this bucket should be memory-mapped if
  590. * a caller tries to read from it }
  591. can_mmap: Integer;
  592. {$endif} { APR_HAS_MMAP }
  593. end;
  594. { @see apr_bucket_structs }
  595. Papr_bucket_structs = ^apr_bucket_structs;
  596. {
  597. * A union of all bucket structures so we know what
  598. * the max size is.
  599. }
  600. apr_bucket_structs = record
  601. case Integer of
  602. 0: (b: apr_bucket); {< Bucket }
  603. 1: (heap: apr_bucket_heap); {< Heap }
  604. 2: (pool: apr_bucket_pool); {< Pool }
  605. {$ifdef APR_HAS_MMAP}
  606. 3: (mmap: apr_bucket_mmap); {< MMap }
  607. {$endif}
  608. 4: (file_: apr_bucket_file); {< File }
  609. end;
  610. {
  611. * The amount that apr_bucket_alloc() should allocate in the common case.
  612. * Note: this is twice as big as apr_bucket_structs to allow breathing
  613. * room for third-party bucket types.
  614. }
  615. //#define APR_BUCKET_ALLOC_SIZE APR_ALIGN_DEFAULT(2*sizeof(apr_bucket_structs))
  616. { ***** Bucket Brigade Functions ***** }
  617. {
  618. * Create a new bucket brigade. The bucket brigade is originally empty.
  619. * @param p The pool to associate with the brigade. Data is not allocated out
  620. * of the pool, but a cleanup is registered.
  621. * @param list The bucket allocator to use
  622. * @return The empty bucket brigade
  623. }
  624. //APU_DECLARE(apr_bucket_brigade *) apr_brigade_create(apr_pool_t *p,
  625. // apr_bucket_alloc_t *list);
  626. {
  627. * destroy an entire bucket brigade. This includes destroying all of the
  628. * buckets within the bucket brigade's bucket list.
  629. * @param b The bucket brigade to destroy
  630. }
  631. //APU_DECLARE(apr_status_t) apr_brigade_destroy(apr_bucket_brigade *b);
  632. {
  633. * empty out an entire bucket brigade. This includes destroying all of the
  634. * buckets within the bucket brigade's bucket list. This is similar to
  635. * apr_brigade_destroy(), except that it does not deregister the brigade's
  636. * pool cleanup function.
  637. * @param data The bucket brigade to clean up
  638. * @remark Generally, you should use apr_brigade_destroy(). This function
  639. * can be useful in situations where you have a single brigade that
  640. * you wish to reuse many times by destroying all of the buckets in
  641. * the brigade and putting new buckets into it later.
  642. }
  643. //APU_DECLARE(apr_status_t) apr_brigade_cleanup(void *data);
  644. {
  645. * Split a bucket brigade into two, such that the given bucket is the
  646. * first in the new bucket brigade. This function is useful when a
  647. * filter wants to pass only the initial part of a brigade to the next
  648. * filter.
  649. * @param b The brigade to split
  650. * @param e The first element of the new brigade
  651. * @return The new brigade
  652. }
  653. //APU_DECLARE(apr_bucket_brigade *) apr_brigade_split(apr_bucket_brigade *b,
  654. // apr_bucket *e);
  655. {
  656. * Partition a bucket brigade at a given offset (in bytes from the start of
  657. * the brigade). This is useful whenever a filter wants to use known ranges
  658. * of bytes from the brigade; the ranges can even overlap.
  659. * @param b The brigade to partition
  660. * @param point The offset at which to partition the brigade
  661. * @param after_point Returns a pointer to the first bucket after the partition
  662. * @return APR_SUCCESS on success, APR_INCOMPLETE if the contents of the
  663. * brigade were shorter than @a point, or an error code.
  664. * @remark if APR_INCOMPLETE is returned, @a after_point will be set to
  665. * the brigade sentinel.
  666. }
  667. //APU_DECLARE(apr_status_t) apr_brigade_partition(apr_bucket_brigade *b,
  668. // apr_off_t point,
  669. // apr_bucket **after_point);
  670. {
  671. * Return the total length of the brigade.
  672. * @param bb The brigade to compute the length of
  673. * @param read_all Read unknown-length buckets to force a size
  674. * @param length Returns the length of the brigade, or -1 if the brigade has
  675. * buckets of indeterminate length and read_all is 0.
  676. }
  677. {APU_DECLARE(apr_status_t) apr_brigade_length(apr_bucket_brigade *bb,
  678. int read_all,
  679. apr_off_t *length);
  680. }
  681. {
  682. * Take a bucket brigade and store the data in a flat char*
  683. * @param bb The bucket brigade to create the char* from
  684. * @param c The char* to write into
  685. * @param len The maximum length of the char array. On return, it is the
  686. * actual length of the char array.
  687. }
  688. {APU_DECLARE(apr_status_t) apr_brigade_flatten(apr_bucket_brigade *bb,
  689. char *c,
  690. apr_size_t *len);
  691. }
  692. {
  693. * Creates a pool-allocated string representing a flat bucket brigade
  694. * @param bb The bucket brigade to create the char array from
  695. * @param c On return, the allocated char array
  696. * @param len On return, the length of the char array.
  697. * @param pool The pool to allocate the string from.
  698. }
  699. {APU_DECLARE(apr_status_t) apr_brigade_pflatten(apr_bucket_brigade *bb,
  700. char **c,
  701. apr_size_t *len,
  702. apr_pool_t *pool);
  703. }
  704. {
  705. * Split a brigade to represent one LF line.
  706. * @param bbOut The bucket brigade that will have the LF line appended to.
  707. * @param bbIn The input bucket brigade to search for a LF-line.
  708. * @param block The blocking mode to be used to split the line.
  709. * @param maxbytes The maximum bytes to read. If this many bytes are seen
  710. * without a LF, the brigade will contain a partial line.
  711. }
  712. {APU_DECLARE(apr_status_t) apr_brigade_split_line(apr_bucket_brigade *bbOut,
  713. apr_bucket_brigade *bbIn,
  714. apr_read_type_e block,
  715. apr_off_t maxbytes);
  716. }
  717. {
  718. * create an iovec of the elements in a bucket_brigade... return number
  719. * of elements used. This is useful for writing to a file or to the
  720. * network efficiently.
  721. * @param b The bucket brigade to create the iovec from
  722. * @param vec The iovec to create
  723. * @param nvec The number of elements in the iovec. On return, it is the
  724. * number of iovec elements actually filled out.
  725. }
  726. {APU_DECLARE(apr_status_t) apr_brigade_to_iovec(apr_bucket_brigade *b,
  727. struct iovec *vec, int *nvec);
  728. }
  729. {
  730. * This function writes a list of strings into a bucket brigade.
  731. * @param b The bucket brigade to add to
  732. * @param flush The flush function to use if the brigade is full
  733. * @param ctx The structure to pass to the flush function
  734. * @param va A list of strings to add
  735. * @return APR_SUCCESS or error code.
  736. }
  737. {APU_DECLARE(apr_status_t) apr_brigade_vputstrs(apr_bucket_brigade *b,
  738. apr_brigade_flush flush,
  739. void *ctx,
  740. va_list va);
  741. }
  742. {
  743. * This function writes a string into a bucket brigade.
  744. * @param b The bucket brigade to add to
  745. * @param flush The flush function to use if the brigade is full
  746. * @param ctx The structure to pass to the flush function
  747. * @param str The string to add
  748. * @param nbyte The number of bytes to write
  749. * @return APR_SUCCESS or error code
  750. }
  751. {APU_DECLARE(apr_status_t) apr_brigade_write(apr_bucket_brigade *b,
  752. apr_brigade_flush flush, void *ctx,
  753. const char *str, apr_size_t nbyte);
  754. }
  755. {
  756. * This function writes multiple strings into a bucket brigade.
  757. * @param b The bucket brigade to add to
  758. * @param flush The flush function to use if the brigade is full
  759. * @param ctx The structure to pass to the flush function
  760. * @param vec The strings to add (address plus length for each)
  761. * @param nvec The number of entries in iovec
  762. * @return APR_SUCCESS or error code
  763. }
  764. {APU_DECLARE(apr_status_t) apr_brigade_writev(apr_bucket_brigade *b,
  765. apr_brigade_flush flush,
  766. void *ctx,
  767. const struct iovec *vec,
  768. apr_size_t nvec);
  769. }
  770. {
  771. * This function writes a string into a bucket brigade.
  772. * @param bb The bucket brigade to add to
  773. * @param flush The flush function to use if the brigade is full
  774. * @param ctx The structure to pass to the flush function
  775. * @param str The string to add
  776. * @return APR_SUCCESS or error code
  777. }
  778. {APU_DECLARE(apr_status_t) apr_brigade_puts(apr_bucket_brigade *bb,
  779. apr_brigade_flush flush, void *ctx,
  780. const char *str);
  781. }
  782. {
  783. * This function writes a character into a bucket brigade.
  784. * @param b The bucket brigade to add to
  785. * @param flush The flush function to use if the brigade is full
  786. * @param ctx The structure to pass to the flush function
  787. * @param c The character to add
  788. * @return APR_SUCCESS or error code
  789. }
  790. {APU_DECLARE(apr_status_t) apr_brigade_putc(apr_bucket_brigade *b,
  791. apr_brigade_flush flush, void *ctx,
  792. const char c);
  793. }
  794. {
  795. * This function writes an unspecified number of strings into a bucket brigade.
  796. * @param b The bucket brigade to add to
  797. * @param flush The flush function to use if the brigade is full
  798. * @param ctx The structure to pass to the flush function
  799. * @param ... The strings to add
  800. * @return APR_SUCCESS or error code
  801. }
  802. {APU_DECLARE_NONSTD(apr_status_t) apr_brigade_putstrs(apr_bucket_brigade *b,
  803. apr_brigade_flush flush,
  804. void *ctx, ...);
  805. }
  806. {
  807. * Evaluate a printf and put the resulting string at the end
  808. * of the bucket brigade.
  809. * @param b The brigade to write to
  810. * @param flush The flush function to use if the brigade is full
  811. * @param ctx The structure to pass to the flush function
  812. * @param fmt The format of the string to write
  813. * @param ... The arguments to fill out the format
  814. * @return APR_SUCCESS or error code
  815. }
  816. {APU_DECLARE_NONSTD(apr_status_t) apr_brigade_printf(apr_bucket_brigade *b,
  817. apr_brigade_flush flush,
  818. void *ctx,
  819. const char *fmt, ...)
  820. __attribute__((format(printf,4,5)));
  821. }
  822. {
  823. * Evaluate a printf and put the resulting string at the end
  824. * of the bucket brigade.
  825. * @param b The brigade to write to
  826. * @param flush The flush function to use if the brigade is full
  827. * @param ctx The structure to pass to the flush function
  828. * @param fmt The format of the string to write
  829. * @param va The arguments to fill out the format
  830. * @return APR_SUCCESS or error code
  831. }
  832. {APU_DECLARE(apr_status_t) apr_brigade_vprintf(apr_bucket_brigade *b,
  833. apr_brigade_flush flush,
  834. void *ctx,
  835. const char *fmt, va_list va);
  836. }
  837. {
  838. * Utility function to insert a file (or a segment of a file) onto the
  839. * end of the brigade. The file is split into multiple buckets if it
  840. * is larger than the maximum size which can be represented by a
  841. * single bucket.
  842. * @param bb the brigade to insert into
  843. * @param f the file to insert
  844. * @param start the offset of the start of the segment
  845. * @param len the length of the segment of the file to insert
  846. * @param p pool from which file buckets are allocated
  847. * @return the last bucket inserted
  848. }
  849. {APU_DECLARE(apr_bucket *) apr_brigade_insert_file(apr_bucket_brigade *bb,
  850. apr_file_t *f,
  851. apr_off_t start,
  852. apr_off_t len,
  853. apr_pool_t *p);}
  854. { ***** Bucket freelist functions ***** }
  855. {
  856. * Create a bucket allocator.
  857. * @param p This pool's underlying apr_allocator_t is used to allocate memory
  858. * for the bucket allocator. When the pool is destroyed, the bucket
  859. * allocator's cleanup routine will free all memory that has been
  860. * allocated from it.
  861. * @remark The reason the allocator gets its memory from the pool's
  862. * apr_allocator_t rather than from the pool itself is because
  863. * the bucket allocator will free large memory blocks back to the
  864. * allocator when it's done with them, thereby preventing memory
  865. * footprint growth that would occur if we allocated from the pool.
  866. * @warning The allocator must never be used by more than one thread at a time.
  867. }
  868. //APU_DECLARE_NONSTD(apr_bucket_alloc_t *) apr_bucket_alloc_create(apr_pool_t *p);
  869. {
  870. * Create a bucket allocator.
  871. * @param allocator This apr_allocator_t is used to allocate both the bucket
  872. * allocator and all memory handed out by the bucket allocator. The
  873. * caller is responsible for destroying the bucket allocator and the
  874. * apr_allocator_t -- no automatic cleanups will happen.
  875. * @warning The allocator must never be used by more than one thread at a time.
  876. }
  877. //APU_DECLARE_NONSTD(apr_bucket_alloc_t *) apr_bucket_alloc_create_ex(apr_allocator_t *allocator);
  878. {
  879. * Destroy a bucket allocator.
  880. * @param list The allocator to be destroyed
  881. }
  882. //APU_DECLARE_NONSTD(void) apr_bucket_alloc_destroy(apr_bucket_alloc_t *list);
  883. {
  884. * Allocate memory for use by the buckets.
  885. * @param size The amount to allocate.
  886. * @param list The allocator from which to allocate the memory.
  887. }
  888. //APU_DECLARE_NONSTD(void *) apr_bucket_alloc(apr_size_t size, apr_bucket_alloc_t *list);
  889. {
  890. * Free memory previously allocated with apr_bucket_alloc().
  891. * @param block The block of memory to be freed.
  892. }
  893. //APU_DECLARE_NONSTD(void) apr_bucket_free(void *block);
  894. { ***** Bucket Functions ***** }
  895. {
  896. * Free the resources used by a bucket. If multiple buckets refer to
  897. * the same resource it is freed when the last one goes away.
  898. * @see apr_bucket_delete()
  899. * @param e The bucket to destroy
  900. }
  901. {#define apr_bucket_destroy(e) do begin
  902. (e)->type->destroy((e)->data); \
  903. (e)->free(e); \
  904. end while (0)}
  905. {
  906. * Delete a bucket by removing it from its brigade (if any) and then
  907. * destroying it.
  908. * @remark This mainly acts as an aid in avoiding code verbosity. It is
  909. * the preferred exact equivalent to:
  910. * <pre>
  911. * APR_BUCKET_REMOVE(e);
  912. * apr_bucket_destroy(e);
  913. * </pre>
  914. * @param e The bucket to delete
  915. }
  916. {#define apr_bucket_delete(e) do begin
  917. APR_BUCKET_REMOVE(e); \
  918. apr_bucket_destroy(e); \
  919. end while (0)}
  920. {
  921. * read the data from the bucket
  922. * @param e The bucket to read from
  923. * @param str The location to store the data in
  924. * @param len The amount of data read
  925. * @param block Whether the read function blocks
  926. }
  927. //#define apr_bucket_read(e,str,len,block) (e)->type->read(e, str, len, block)
  928. {
  929. * Setaside data so that stack data is not destroyed on returning from
  930. * the function
  931. * @param e The bucket to setaside
  932. * @param p The pool to setaside into
  933. }
  934. //#define apr_bucket_setaside(e,p) (e)->type->setaside(e,p)
  935. {
  936. * Split one bucket in two.
  937. * @param e The bucket to split
  938. * @param point The offset to split the bucket at
  939. }
  940. //#define apr_bucket_split(e,point) (e)->type->split(e, point)
  941. {
  942. * Copy a bucket.
  943. * @param e The bucket to copy
  944. * @param c Returns a pointer to the new bucket
  945. }
  946. //#define apr_bucket_copy(e,c) (e)->type->copy(e, c)
  947. { Bucket type handling }
  948. {
  949. * This function simply returns APR_SUCCESS to denote that the bucket does
  950. * not require anything to happen for its setaside() function. This is
  951. * appropriate for buckets that have "immortal" data -- the data will live
  952. * at least as long as the bucket.
  953. * @param data The bucket to setaside
  954. * @param pool The pool defining the desired lifetime of the bucket data
  955. * @return APR_SUCCESS
  956. }
  957. {APU_DECLARE_NONSTD(apr_status_t) apr_bucket_setaside_noop(apr_bucket *data,
  958. apr_pool_t *pool);
  959. }
  960. {
  961. * A place holder function that signifies that the setaside function was not
  962. * implemented for this bucket
  963. * @param data The bucket to setaside
  964. * @param pool The pool defining the desired lifetime of the bucket data
  965. * @return APR_ENOTIMPL
  966. }
  967. {APU_DECLARE_NONSTD(apr_status_t) apr_bucket_setaside_notimpl(apr_bucket *data,
  968. apr_pool_t *pool);
  969. }
  970. {
  971. * A place holder function that signifies that the split function was not
  972. * implemented for this bucket
  973. * @param data The bucket to split
  974. * @param point The location to split the bucket
  975. * @return APR_ENOTIMPL
  976. }
  977. {APU_DECLARE_NONSTD(apr_status_t) apr_bucket_split_notimpl(apr_bucket *data,
  978. apr_size_t point);
  979. }
  980. {
  981. * A place holder function that signifies that the copy function was not
  982. * implemented for this bucket
  983. * @param e The bucket to copy
  984. * @param c Returns a pointer to the new bucket
  985. * @return APR_ENOTIMPL
  986. }
  987. {APU_DECLARE_NONSTD(apr_status_t) apr_bucket_copy_notimpl(apr_bucket *e,
  988. apr_bucket **c);
  989. }
  990. {
  991. * A place holder function that signifies that this bucket does not need
  992. * to do anything special to be destroyed. That's only the case for buckets
  993. * that either have no data (metadata buckets) or buckets whose data pointer
  994. * points to something that's not a bucket-type-specific structure, as with
  995. * simple buckets where data points to a string and pipe buckets where data
  996. * points directly to the apr_file_t.
  997. * @param data The bucket data to destroy
  998. }
  999. //APU_DECLARE_NONSTD(void) apr_bucket_destroy_noop(void *data);
  1000. {
  1001. * There is no apr_bucket_destroy_notimpl, because destruction is required
  1002. * to be implemented (it could be a noop, but only if that makes sense for
  1003. * the bucket type)
  1004. }
  1005. { There is no apr_bucket_read_notimpl, because it is a required function
  1006. }
  1007. { All of the bucket types implemented by the core }
  1008. {
  1009. * The flush bucket type. This signifies that all data should be flushed to
  1010. * the next filter. The flush bucket should be sent with the other buckets.
  1011. }
  1012. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_flush;
  1013. {
  1014. * The EOS bucket type. This signifies that there will be no more data, ever.
  1015. * All filters MUST send all data to the next filter when they receive a
  1016. * bucket of this type
  1017. }
  1018. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_eos;
  1019. {
  1020. * The FILE bucket type. This bucket represents a file on disk
  1021. }
  1022. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_file;
  1023. {
  1024. * The HEAP bucket type. This bucket represents a data allocated from the
  1025. * heap.
  1026. }
  1027. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_heap;
  1028. //#if APR_HAS_MMAP
  1029. {
  1030. * The MMAP bucket type. This bucket represents an MMAP'ed file
  1031. }
  1032. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_mmap;
  1033. //#endif
  1034. {
  1035. * The POOL bucket type. This bucket represents a data that was allocated
  1036. * from a pool. IF this bucket is still available when the pool is cleared,
  1037. * the data is copied on to the heap.
  1038. }
  1039. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_pool;
  1040. {
  1041. * The PIPE bucket type. This bucket represents a pipe to another program.
  1042. }
  1043. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_pipe;
  1044. {
  1045. * The IMMORTAL bucket type. This bucket represents a segment of data that
  1046. * the creator is willing to take responsibility for. The core will do
  1047. * nothing with the data in an immortal bucket
  1048. }
  1049. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_immortal;
  1050. {
  1051. * The TRANSIENT bucket type. This bucket represents a data allocated off
  1052. * the stack. When the setaside function is called, this data is copied on
  1053. * to the heap
  1054. }
  1055. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_transient;
  1056. {
  1057. * The SOCKET bucket type. This bucket represents a socket to another machine
  1058. }
  1059. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_socket;
  1060. { ***** Simple buckets ***** }
  1061. {
  1062. * Split a simple bucket into two at the given point. Most non-reference
  1063. * counting buckets that allow multiple references to the same block of
  1064. * data (eg transient and immortal) will use this as their split function
  1065. * without any additional type-specific handling.
  1066. * @param b The bucket to be split
  1067. * @param point The offset of the first byte in the new bucket
  1068. * @return APR_EINVAL if the point is not within the bucket;
  1069. * APR_ENOMEM if allocation failed;
  1070. * or APR_SUCCESS
  1071. }
  1072. //APU_DECLARE_NONSTD(apr_status_t) apr_bucket_simple_split(apr_bucket *b,
  1073. // apr_size_t point);
  1074. {
  1075. * Copy a simple bucket. Most non-reference-counting buckets that allow
  1076. * multiple references to the same block of data (eg transient and immortal)
  1077. * will use this as their copy function without any additional type-specific
  1078. * handling.
  1079. * @param a The bucket to copy
  1080. * @param b Returns a pointer to the new bucket
  1081. * @return APR_ENOMEM if allocation failed;
  1082. * or APR_SUCCESS
  1083. }
  1084. {APU_DECLARE_NONSTD(apr_status_t) apr_bucket_simple_copy(apr_bucket *a,
  1085. apr_bucket **b);
  1086. }
  1087. { ***** Shared, reference-counted buckets ***** }
  1088. {
  1089. * Initialize a bucket containing reference-counted data that may be
  1090. * shared. The caller must allocate the bucket if necessary and
  1091. * initialize its type-dependent fields, and allocate and initialize
  1092. * its own private data structure. This function should only be called
  1093. * by type-specific bucket creation functions.
  1094. * @param b The bucket to initialize
  1095. * @param data A pointer to the private data structure
  1096. * with the reference count at the start
  1097. * @param start The start of the data in the bucket
  1098. * relative to the private base pointer
  1099. * @param length The length of the data in the bucket
  1100. * @return The new bucket, or NULL if allocation failed
  1101. }
  1102. {APU_DECLARE(apr_bucket *) apr_bucket_shared_make(apr_bucket *b, void *data,
  1103. apr_off_t start,
  1104. apr_size_t length);
  1105. }
  1106. {
  1107. * Decrement the refcount of the data in the bucket. This function
  1108. * should only be called by type-specific bucket destruction functions.
  1109. * @param data The private data pointer from the bucket to be destroyed
  1110. * @return TRUE or FALSE; TRUE if the reference count is now
  1111. * zero, indicating that the shared resource itself can
  1112. * be destroyed by the caller.
  1113. }
  1114. //APU_DECLARE(int) apr_bucket_shared_destroy(void *data);
  1115. {
  1116. * Split a bucket into two at the given point, and adjust the refcount
  1117. * to the underlying data. Most reference-counting bucket types will
  1118. * be able to use this function as their split function without any
  1119. * additional type-specific handling.
  1120. * @param b The bucket to be split
  1121. * @param point The offset of the first byte in the new bucket
  1122. * @return APR_EINVAL if the point is not within the bucket;
  1123. * APR_ENOMEM if allocation failed;
  1124. * or APR_SUCCESS
  1125. }
  1126. //APU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_split(apr_bucket *b,
  1127. // apr_size_t point);
  1128. {
  1129. * Copy a refcounted bucket, incrementing the reference count. Most
  1130. * reference-counting bucket types will be able to use this function
  1131. * as their copy function without any additional type-specific handling.
  1132. * @param a The bucket to copy
  1133. * @param b Returns a pointer to the new bucket
  1134. * @return APR_ENOMEM if allocation failed;
  1135. or APR_SUCCESS
  1136. }
  1137. //APU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_copy(apr_bucket *a,
  1138. // apr_bucket **b);
  1139. { ***** Functions to Create Buckets of varying types ***** }
  1140. {
  1141. * Each bucket type foo has two initialization functions:
  1142. * apr_bucket_foo_make which sets up some already-allocated memory as a
  1143. * bucket of type foo; and apr_bucket_foo_create which allocates memory
  1144. * for the bucket, calls apr_bucket_make_foo, and initializes the
  1145. * bucket's list pointers. The apr_bucket_foo_make functions are used
  1146. * inside the bucket code to change the type of buckets in place;
  1147. * other code should call apr_bucket_foo_create. All the initialization
  1148. * functions change nothing if they fail.
  1149. }
  1150. {
  1151. * Create an End of Stream bucket. This indicates that there is no more data
  1152. * coming from down the filter stack. All filters should flush at this point.
  1153. * @param list The freelist from which this bucket should be allocated
  1154. * @return The new bucket, or NULL if allocation failed
  1155. }
  1156. //APU_DECLARE(apr_bucket *) apr_bucket_eos_create(apr_bucket_alloc_t *list);
  1157. {
  1158. * Make the bucket passed in an EOS bucket. This indicates that there is no
  1159. * more data coming from down the filter stack. All filters should flush at
  1160. * this point.
  1161. * @param b The bucket to make into an EOS bucket
  1162. * @return The new bucket, or NULL if allocation failed
  1163. }
  1164. //APU_DECLARE(apr_bucket *) apr_bucket_eos_make(apr_bucket *b);
  1165. {
  1166. * Create a flush bucket. This indicates that filters should flush their
  1167. * data. There is no guarantee that they will flush it, but this is the
  1168. * best we can do.
  1169. * @param list The freelist from which this bucket should be allocated
  1170. * @return The new bucket, or NULL if allocation failed
  1171. }
  1172. //APU_DECLARE(apr_bucket *) apr_bucket_flush_create(apr_bucket_alloc_t *list);
  1173. {
  1174. * Make the bucket passed in a FLUSH bucket. This indicates that filters
  1175. * should flush their data. There is no guarantee that they will flush it,
  1176. * but this is the best we can do.
  1177. * @param b The bucket to make into a FLUSH bucket
  1178. * @return The new bucket, or NULL if allocation failed
  1179. }
  1180. //APU_DECLARE(apr_bucket *) apr_bucket_flush_make(apr_bucket *b);
  1181. {
  1182. * Create a bucket referring to long-lived data.
  1183. * @param buf The data to insert into the bucket
  1184. * @param nbyte The size of the data to insert.
  1185. * @param list The freelist from which this bucket should be allocated
  1186. * @return The new bucket, or NULL if allocation failed
  1187. }
  1188. {APU_DECLARE(apr_bucket *) apr_bucket_immortal_create(const char *buf,
  1189. apr_size_t nbyte,
  1190. apr_bucket_alloc_t *list);
  1191. }
  1192. {
  1193. * Make the bucket passed in a bucket refer to long-lived data
  1194. * @param b The bucket to make into a IMMORTAL bucket
  1195. * @param buf The data to insert into the bucket
  1196. * @param nbyte The size of the data to insert.
  1197. * @return The new bucket, or NULL if allocation failed
  1198. }
  1199. {APU_DECLARE(apr_bucket *) apr_bucket_immortal_make(apr_bucket *b,
  1200. const char *buf,
  1201. apr_size_t nbyte);
  1202. }
  1203. {
  1204. * Create a bucket referring to data on the stack.
  1205. * @param buf The data to insert into the bucket
  1206. * @param nbyte The size of the data to insert.
  1207. * @param list The freelist from which this bucket should be allocated
  1208. * @return The new bucket, or NULL if allocation failed
  1209. }
  1210. {APU_DECLARE(apr_bucket *) apr_bucket_transient_create(const char *buf,
  1211. apr_size_t nbyte,
  1212. apr_bucket_alloc_t *list);
  1213. }
  1214. {
  1215. * Make the bucket passed in a bucket refer to stack data
  1216. * @param b The bucket to make into a TRANSIENT bucket
  1217. * @param buf The data to insert into the bucket
  1218. * @param nbyte The size of the data to insert.
  1219. * @return The new bucket, or NULL if allocation failed
  1220. }
  1221. {APU_DECLARE(apr_bucket *) apr_bucket_transient_make(apr_bucket *b,
  1222. const char *buf,
  1223. apr_size_t nbyte);
  1224. }
  1225. {
  1226. * Create a bucket referring to memory on the heap. If the caller asks
  1227. * for the data to be copied, this function always allocates 4K of
  1228. * memory so that more data can be added to the bucket without
  1229. * requiring another allocation. Therefore not all the data may be put
  1230. * into the bucket. If copying is not requested then the bucket takes
  1231. * over responsibility for free()ing the memory.
  1232. * @param buf The buffer to insert into the bucket
  1233. * @param nbyte The size of the buffer to insert.
  1234. * @param free_func Function to use to free the data; NULL indicates that the
  1235. * bucket should make a copy of the data
  1236. * @param list The freelist from which this bucket should be allocated
  1237. * @return The new bucket, or NULL if allocation failed
  1238. }
  1239. {APU_DECLARE(apr_bucket *) apr_bucket_heap_create(const char *buf,
  1240. apr_size_t nbyte,
  1241. void ( *free_func)(void *data),
  1242. apr_bucket_alloc_t *list);}
  1243. {
  1244. * Make the bucket passed in a bucket refer to heap data
  1245. * @param b The bucket to make into a HEAP bucket
  1246. * @param buf The buffer to insert into the bucket
  1247. * @param nbyte The size of the buffer to insert.
  1248. * @param free_func Function to use to free the data; NULL indicates that the
  1249. * bucket should make a copy of the data
  1250. * @return The new bucket, or NULL if allocation failed
  1251. }
  1252. {APU_DECLARE(apr_bucket *) apr_bucket_heap_make(apr_bucket *b, const char *buf,
  1253. apr_size_t nbyte,
  1254. void ( *free_func)(void *data));}
  1255. {
  1256. * Create a bucket referring to memory allocated from a pool.
  1257. *
  1258. * @param buf The buffer to insert into the bucket
  1259. * @param length The number of bytes referred to by this bucket
  1260. * @param pool The pool the memory was allocated from
  1261. * @param list The freelist from which this bucket should be allocated
  1262. * @return The new bucket, or NULL if allocation failed
  1263. }
  1264. {APU_DECLARE(apr_bucket *) apr_bucket_pool_create(const char *buf,
  1265. apr_size_t length,
  1266. apr_pool_t *pool,
  1267. apr_bucket_alloc_t *list);}
  1268. {
  1269. * Make the bucket passed in a bucket refer to pool data
  1270. * @param b The bucket to make into a pool bucket
  1271. * @param buf The buffer to insert into the bucket
  1272. * @param length The number of bytes referred to by this bucket
  1273. * @param pool The pool the memory was allocated from
  1274. * @return The new bucket, or NULL if allocation failed
  1275. }
  1276. {APU_DECLARE(apr_bucket *) apr_bucket_pool_make(apr_bucket *b, const char *buf,
  1277. apr_size_t length,
  1278. apr_pool_t *pool);}
  1279. //#if APR_HAS_MMAP
  1280. {
  1281. * Create a bucket referring to mmap()ed memory.
  1282. * @param mm The mmap to insert into the bucket
  1283. * @param start The offset of the first byte in the mmap
  1284. * that this bucket refers to
  1285. * @param length The number of bytes referred to by this bucket
  1286. * @param list The freelist from which this bucket should be allocated
  1287. * @return The new bucket, or NULL if allocation failed
  1288. }
  1289. {APU_DECLARE(apr_bucket *) apr_bucket_mmap_create(apr_mmap_t *mm,
  1290. apr_off_t start,
  1291. apr_size_t length,
  1292. apr_bucket_alloc_t *list);
  1293. }
  1294. {
  1295. * Make the bucket passed in a bucket refer to an MMAP'ed file
  1296. * @param b The bucket to make into a MMAP bucket
  1297. * @param mm The mmap to insert into the bucket
  1298. * @param start The offset of the first byte in the mmap
  1299. * that this bucket refers to
  1300. * @param length The number of bytes referred to by this bucket
  1301. * @return The new bucket, or NULL if allocation failed
  1302. }
  1303. {APU_DECLARE(apr_bucket *) apr_bucket_mmap_make(apr_bucket *b, apr_mmap_t *mm,
  1304. apr_off_t start,
  1305. apr_size_t length);
  1306. #endif}
  1307. {
  1308. * Create a bucket referring to a socket.
  1309. * @param thissock The socket to put in the bucket
  1310. * @param list The freelist from which this bucket should be allocated
  1311. * @return The new bucket, or NULL if allocation failed
  1312. }
  1313. {APU_DECLARE(apr_bucket *) apr_bucket_socket_create(apr_socket_t *thissock,
  1314. apr_bucket_alloc_t *list);}
  1315. {
  1316. * Make the bucket passed in a bucket refer to a socket
  1317. * @param b The bucket to make into a SOCKET bucket
  1318. * @param thissock The socket to put in the bucket
  1319. * @return The new bucket, or NULL if allocation failed
  1320. }
  1321. {APU_DECLARE(apr_bucket *) apr_bucket_socket_make(apr_bucket *b,
  1322. apr_socket_t *thissock);}
  1323. {
  1324. * Create a bucket referring to a pipe.
  1325. * @param thispipe The pipe to put in the bucket
  1326. * @param list The freelist from which this bucket should be allocated
  1327. * @return The new bucket, or NULL if allocation failed
  1328. }
  1329. {APU_DECLARE(apr_bucket *) apr_bucket_pipe_create(apr_file_t *thispipe,
  1330. apr_bucket_alloc_t *list);}
  1331. {
  1332. * Make the bucket passed in a bucket refer to a pipe
  1333. * @param b The bucket to make into a PIPE bucket
  1334. * @param thispipe The pipe to put in the bucket
  1335. * @return The new bucket, or NULL if allocation failed
  1336. }
  1337. {APU_DECLARE(apr_bucket *) apr_bucket_pipe_make(apr_bucket *b,
  1338. apr_file_t *thispipe);}
  1339. {
  1340. * Create a bucket referring to a file.
  1341. * @param fd The file to put in the bucket
  1342. * @param offset The offset where the data of interest begins in the file
  1343. * @param len The amount of data in the file we are interested in
  1344. * @param p The pool into which any needed structures should be created
  1345. * while reading from this file bucket
  1346. * @param list The freelist from which this bucket should be allocated
  1347. * @return The new bucket, or NULL if allocation failed
  1348. }
  1349. {APU_DECLARE(apr_bucket *) apr_bucket_file_create(apr_file_t *fd,
  1350. apr_off_t offset,
  1351. apr_size_t len,
  1352. apr_pool_t *p,
  1353. apr_bucket_alloc_t *list);
  1354. }
  1355. {
  1356. * Make the bucket passed in a bucket refer to a file
  1357. * @param b The bucket to make into a FILE bucket
  1358. * @param fd The file to put in the bucket
  1359. * @param offset The offset where the data of interest begins in the file
  1360. * @param len The amount of data in the file we are interested in
  1361. * @param p The pool into which any needed structures should be created
  1362. * while reading from this file bucket
  1363. * @return The new bucket, or NULL if allocation failed
  1364. }
  1365. {APU_DECLARE(apr_bucket *) apr_bucket_file_make(apr_bucket *b, apr_file_t *fd,
  1366. apr_off_t offset,
  1367. apr_size_t len, apr_pool_t *p);
  1368. }
  1369. {
  1370. * Enable or disable memory-mapping for a FILE bucket (default is enabled)
  1371. * @param b The bucket
  1372. * @param enabled Whether memory-mapping should be enabled
  1373. * @return APR_SUCCESS normally, or an error code if the operation fails
  1374. }
  1375. {APU_DECLARE(apr_status_t) apr_bucket_file_enable_mmap(apr_bucket *b,
  1376. int enabled);}