apr_buckets.inc 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  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. * Iterate through a bucket brigade
  339. * @param e The current bucket
  340. * @param b The brigade to iterate over
  341. * @remark This is the same as either:
  342. * <pre>
  343. * e = APR_BRIGADE_FIRST(b);
  344. * while (e != APR_BRIGADE_SENTINEL(b)) (
  345. * ...
  346. * e = APR_BUCKET_NEXT(e);
  347. * )
  348. * OR
  349. * for (e = APR_BRIGADE_FIRST(b);
  350. * e != APR_BRIGADE_SENTINEL(b);
  351. * e = APR_BUCKET_NEXT(e)) (
  352. * ...
  353. * )
  354. * </pre>
  355. * @warning Be aware that you cannot change the value of e within
  356. * the foreach loop, nor can you destroy the bucket it points to.
  357. * Modifying the prev and next pointers of the bucket is dangerous
  358. * but can be done if you're careful. If you change e's value or
  359. * destroy the bucket it points to, then APR_BRIGADE_FOREACH
  360. * will have no way to find out what bucket to use for its next
  361. * iteration. The reason for this can be seen by looking closely
  362. * at the equivalent loops given in the tip above. So, for example,
  363. * if you are writing a loop that empties out a brigade one bucket
  364. * at a time, APR_BRIGADE_FOREACH just won't work for you. Do it
  365. * by hand, like so:
  366. * <pre>
  367. * while (!APR_BRIGADE_EMPTY(b)) (
  368. * e = APR_BRIGADE_FIRST(b);
  369. * ...
  370. * apr_bucket_delete(e);
  371. * )
  372. * </pre>
  373. * @deprecated This macro causes more headaches than it's worth. Use
  374. * one of the alternatives documented here instead; the clarity gained
  375. * in what's really going on is well worth the extra line or two of code.
  376. * This macro will be removed at some point in the future.
  377. }
  378. //#define APR_BRIGADE_FOREACH(e, b) \
  379. // APR_RING_FOREACH((e), &(b)->list, apr_bucket, link)
  380. {
  381. * Insert a list of buckets at the front of a brigade
  382. * @param b The brigade to add to
  383. * @param e The first bucket in a list of buckets to insert
  384. }
  385. {#define APR_BRIGADE_INSERT_HEAD(b, e) do ( \
  386. apr_bucket *ap__b = (e); \
  387. APR_RING_INSERT_HEAD(&(b)->list, ap__b, apr_bucket, link); \
  388. APR_BRIGADE_CHECK_CONSISTENCY((b)); \
  389. ) while (0)}
  390. {
  391. * Insert a list of buckets at the end of a brigade
  392. * @param b The brigade to add to
  393. * @param e The first bucket in a list of buckets to insert
  394. }
  395. {#define APR_BRIGADE_INSERT_TAIL(b, e) do begin \
  396. apr_bucket *ap__b = (e); \
  397. APR_RING_INSERT_TAIL(&(b)->list, ap__b, apr_bucket, link); \
  398. APR_BRIGADE_CHECK_CONSISTENCY((b)); \
  399. end while (0)}
  400. {
  401. * Concatenate brigade b onto the end of brigade a, leaving brigade b empty
  402. * @param a The first brigade
  403. * @param b The second brigade
  404. }
  405. {#define APR_BRIGADE_CONCAT(a, b) do begin
  406. APR_RING_CONCAT(&(a)->list, &(b)->list, apr_bucket, link); \
  407. APR_BRIGADE_CHECK_CONSISTENCY((a)); \
  408. end while (0);}
  409. {
  410. * Prepend brigade b onto the beginning of brigade a, leaving brigade b empty
  411. * @param a The first brigade
  412. * @param b The second brigade
  413. }
  414. {#define APR_BRIGADE_PREPEND(a, b) do begin
  415. APR_RING_PREPEND(&(a)->list, &(b)->list, apr_bucket, link); \
  416. APR_BRIGADE_CHECK_CONSISTENCY((a)); \
  417. end while (0)}
  418. {
  419. * Insert a list of buckets before a specified bucket
  420. * @param a The bucket to insert before
  421. * @param b The buckets to insert
  422. }
  423. {#define APR_BUCKET_INSERT_BEFORE(a, b) do begin
  424. apr_bucket *ap__a = (a), *ap__b = (b); \
  425. APR_RING_INSERT_BEFORE(ap__a, ap__b, link); \
  426. APR_BUCKET_CHECK_CONSISTENCY(ap__a); \
  427. end while (0)}
  428. {
  429. * Insert a list of buckets after a specified bucket
  430. * @param a The bucket to insert after
  431. * @param b The buckets to insert
  432. }
  433. {#define APR_BUCKET_INSERT_AFTER(a, b) do begin
  434. apr_bucket *ap__a = (a), *ap__b = (b); \
  435. APR_RING_INSERT_AFTER(ap__a, ap__b, link); \
  436. APR_BUCKET_CHECK_CONSISTENCY(ap__a); \
  437. end while (0)}
  438. {
  439. * Get the next bucket in the list
  440. * @param e The current bucket
  441. * @return The next bucket
  442. }
  443. //#define APR_BUCKET_NEXT(e) APR_RING_NEXT((e), link)
  444. {
  445. * Get the previous bucket in the list
  446. * @param e The current bucket
  447. * @return The previous bucket
  448. }
  449. //#define APR_BUCKET_PREV(e) APR_RING_PREV((e), link)
  450. {
  451. * Remove a bucket from its bucket brigade
  452. * @param e The bucket to remove
  453. }
  454. //#define APR_BUCKET_REMOVE(e) APR_RING_REMOVE((e), link)
  455. {
  456. * Initialize a new bucket's prev/next pointers
  457. * @param e The bucket to initialize
  458. }
  459. //#define APR_BUCKET_INIT(e) APR_RING_ELEM_INIT((e), link)
  460. {
  461. * Determine if a bucket contains metadata. An empty bucket is
  462. * safe to arbitrarily remove if and only if this is false.
  463. * @param e The bucket to inspect
  464. * @return true or false
  465. }
  466. //#define APR_BUCKET_IS_METADATA(e) ((e)->type->is_metadata)
  467. {
  468. * Determine if a bucket is a FLUSH bucket
  469. * @param e The bucket to inspect
  470. * @return true or false
  471. }
  472. //#define APR_BUCKET_IS_FLUSH(e) ((e)->type == &apr_bucket_type_flush)
  473. {
  474. * Determine if a bucket is an EOS bucket
  475. * @param e The bucket to inspect
  476. * @return true or false
  477. }
  478. //#define APR_BUCKET_IS_EOS(e) ((e)->type == &apr_bucket_type_eos)
  479. {
  480. * Determine if a bucket is a FILE bucket
  481. * @param e The bucket to inspect
  482. * @return true or false
  483. }
  484. //#define APR_BUCKET_IS_FILE(e) ((e)->type == &apr_bucket_type_file)
  485. {
  486. * Determine if a bucket is a PIPE bucket
  487. * @param e The bucket to inspect
  488. * @return true or false
  489. }
  490. //#define APR_BUCKET_IS_PIPE(e) ((e)->type == &apr_bucket_type_pipe)
  491. {
  492. * Determine if a bucket is a SOCKET bucket
  493. * @param e The bucket to inspect
  494. * @return true or false
  495. }
  496. //#define APR_BUCKET_IS_SOCKET(e) ((e)->type == &apr_bucket_type_socket)
  497. {
  498. * Determine if a bucket is a HEAP bucket
  499. * @param e The bucket to inspect
  500. * @return true or false
  501. }
  502. //#define APR_BUCKET_IS_HEAP(e) ((e)->type == &apr_bucket_type_heap)
  503. {
  504. * Determine if a bucket is a TRANSIENT bucket
  505. * @param e The bucket to inspect
  506. * @return true or false
  507. }
  508. //#define APR_BUCKET_IS_TRANSIENT(e) ((e)->type == &apr_bucket_type_transient)
  509. {
  510. * Determine if a bucket is a IMMORTAL bucket
  511. * @param e The bucket to inspect
  512. * @return true or false
  513. }
  514. //#define APR_BUCKET_IS_IMMORTAL(e) ((e)->type == &apr_bucket_type_immortal)
  515. //#if APR_HAS_MMAP
  516. {
  517. * Determine if a bucket is a MMAP bucket
  518. * @param e The bucket to inspect
  519. * @return true or false
  520. }
  521. //#define APR_BUCKET_IS_MMAP(e) ((e)->type == &apr_bucket_type_mmap)
  522. //#endif
  523. {
  524. * Determine if a bucket is a POOL bucket
  525. * @param e The bucket to inspect
  526. * @return true or false
  527. }
  528. //#define APR_BUCKET_IS_POOL(e) ((e)->type == &apr_bucket_type_pool)
  529. {
  530. * General-purpose reference counting for the various bucket types.
  531. *
  532. * Any bucket type that keeps track of the resources it uses (i.e.
  533. * most of them except for IMMORTAL, TRANSIENT, and EOS) needs to
  534. * attach a reference count to the resource so that it can be freed
  535. * when the last bucket that uses it goes away. Resource-sharing may
  536. * occur because of bucket splits or buckets that refer to globally
  537. * cached data. }
  538. { @see apr_bucket_refcount }
  539. Papr_bucket_refcount = ^apr_bucket_refcount;
  540. {
  541. * The structure used to manage the shared resource must start with an
  542. * apr_bucket_refcount which is updated by the general-purpose refcount
  543. * code. A pointer to the bucket-type-dependent private data structure
  544. * can be cast to a pointer to an apr_bucket_refcount and vice versa.
  545. }
  546. apr_bucket_refcount = record
  547. { The number of references to this bucket }
  548. refcount: Integer;
  549. end;
  550. { ***** Reference-counted bucket types ***** }
  551. { @see apr_bucket_heap }
  552. Papr_bucket_heap = ^apr_bucket_heap;
  553. {
  554. * A bucket referring to data allocated off the heap.
  555. }
  556. free_func_t = procedure (data: Pointer);
  557. apr_bucket_heap = record
  558. { Number of buckets using this memory }
  559. refcount: apr_bucket_refcount;
  560. { The start of the data actually allocated. This should never be
  561. * modified, it is only used to free the bucket.
  562. }
  563. base: PChar;
  564. { how much memory was allocated }
  565. alloc_len: apr_size_t;
  566. { function to use to delete the data }
  567. free_func: free_func_t;
  568. end;
  569. { @see apr_bucket_pool }
  570. Papr_bucket_pool = ^apr_bucket_pool;
  571. {
  572. * A bucket referring to data allocated from a pool
  573. }
  574. apr_bucket_pool = record
  575. { The pool bucket must be able to be easily morphed to a heap
  576. * bucket if the pool gets cleaned up before all references are
  577. * destroyed. This apr_bucket_heap structure is populated automatically
  578. * when the pool gets cleaned up, and subsequent calls to pool_read()
  579. * will result in the apr_bucket in question being morphed into a
  580. * regular heap bucket. (To avoid having to do many extra refcount
  581. * manipulations and b->data manipulations, the apr_bucket_pool
  582. * struct actually *contains* the apr_bucket_heap struct that it
  583. * will become as its first element; the two share their
  584. * apr_bucket_refcount members.)
  585. }
  586. heap: apr_bucket_heap;
  587. { The block of data actually allocated from the pool.
  588. * Segments of this block are referenced by adjusting
  589. * the start and length of the apr_bucket accordingly.
  590. * This will be NULL after the pool gets cleaned up.
  591. }
  592. base: PChar;
  593. { The pool the data was allocated from. When the pool
  594. * is cleaned up, this gets set to NULL as an indicator
  595. * to pool_read() that the data is now on the heap and
  596. * so it should morph the bucket into a regular heap
  597. * bucket before continuing.
  598. }
  599. pool: Papr_pool_t;
  600. { The freelist this structure was allocated from, which is
  601. * needed in the cleanup phase in order to allocate space on the heap
  602. }
  603. list: Papr_bucket_alloc_t;
  604. end;
  605. {$ifdef APR_HAS_MMAP}
  606. { @see apr_bucket_mmap }
  607. Papr_bucket_mmap = ^apr_bucket_mmap;
  608. {
  609. * A bucket referring to an mmap()ed file
  610. }
  611. apr_bucket_mmap = record
  612. { Number of buckets using this memory }
  613. refcount: apr_bucket_refcount;
  614. { The mmap this sub_bucket refers to }
  615. mmap: Papr_mmap_t;
  616. end;
  617. {$endif}
  618. { @see apr_bucket_file }
  619. Papr_bucket_file = ^apr_bucket_file;
  620. {
  621. * A bucket referring to an file
  622. }
  623. apr_bucket_file = record
  624. { Number of buckets using this memory }
  625. refcount: apr_bucket_refcount;
  626. { The file this bucket refers to }
  627. fd: Papr_file_t;
  628. { The pool into which any needed structures should
  629. * be created while reading from this file bucket }
  630. readpool: Papr_pool_t;
  631. {$ifdef APR_HAS_MMAP}
  632. { Whether this bucket should be memory-mapped if
  633. * a caller tries to read from it }
  634. can_mmap: Integer;
  635. {$endif} { APR_HAS_MMAP }
  636. end;
  637. { @see apr_bucket_structs }
  638. Papr_bucket_structs = ^apr_bucket_structs;
  639. {
  640. * A union of all bucket structures so we know what
  641. * the max size is.
  642. }
  643. apr_bucket_structs = record
  644. case Integer of
  645. 0: (b: apr_bucket); {< Bucket }
  646. 1: (heap: apr_bucket_heap); {< Heap }
  647. 2: (pool: apr_bucket_pool); {< Pool }
  648. {$ifdef APR_HAS_MMAP}
  649. 3: (mmap: apr_bucket_mmap); {< MMap }
  650. {$endif}
  651. 4: (file_: apr_bucket_file); {< File }
  652. end;
  653. {
  654. * The amount that apr_bucket_alloc() should allocate in the common case.
  655. * Note: this is twice as big as apr_bucket_structs to allow breathing
  656. * room for third-party bucket types.
  657. }
  658. //#define APR_BUCKET_ALLOC_SIZE APR_ALIGN_DEFAULT(2*sizeof(apr_bucket_structs))
  659. { ***** Bucket Brigade Functions ***** }
  660. {
  661. * Create a new bucket brigade. The bucket brigade is originally empty.
  662. * @param p The pool to associate with the brigade. Data is not allocated out
  663. * of the pool, but a cleanup is registered.
  664. * @param list The bucket allocator to use
  665. * @return The empty bucket brigade
  666. }
  667. //APU_DECLARE(apr_bucket_brigade *) apr_brigade_create(apr_pool_t *p,
  668. // apr_bucket_alloc_t *list);
  669. {
  670. * destroy an entire bucket brigade. This includes destroying all of the
  671. * buckets within the bucket brigade's bucket list.
  672. * @param b The bucket brigade to destroy
  673. }
  674. //APU_DECLARE(apr_status_t) apr_brigade_destroy(apr_bucket_brigade *b);
  675. {
  676. * empty out an entire bucket brigade. This includes destroying all of the
  677. * buckets within the bucket brigade's bucket list. This is similar to
  678. * apr_brigade_destroy(), except that it does not deregister the brigade's
  679. * pool cleanup function.
  680. * @param data The bucket brigade to clean up
  681. * @remark Generally, you should use apr_brigade_destroy(). This function
  682. * can be useful in situations where you have a single brigade that
  683. * you wish to reuse many times by destroying all of the buckets in
  684. * the brigade and putting new buckets into it later.
  685. }
  686. //APU_DECLARE(apr_status_t) apr_brigade_cleanup(void *data);
  687. {
  688. * Split a bucket brigade into two, such that the given bucket is the
  689. * first in the new bucket brigade. This function is useful when a
  690. * filter wants to pass only the initial part of a brigade to the next
  691. * filter.
  692. * @param b The brigade to split
  693. * @param e The first element of the new brigade
  694. * @return The new brigade
  695. }
  696. //APU_DECLARE(apr_bucket_brigade *) apr_brigade_split(apr_bucket_brigade *b,
  697. // apr_bucket *e);
  698. {
  699. * Partition a bucket brigade at a given offset (in bytes from the start of
  700. * the brigade). This is useful whenever a filter wants to use known ranges
  701. * of bytes from the brigade; the ranges can even overlap.
  702. * @param b The brigade to partition
  703. * @param point The offset at which to partition the brigade
  704. * @param after_point Returns a pointer to the first bucket after the partition
  705. }
  706. //APU_DECLARE(apr_status_t) apr_brigade_partition(apr_bucket_brigade *b,
  707. // apr_off_t point,
  708. // apr_bucket **after_point);
  709. //#if APR_NOT_DONE_YET
  710. {
  711. * consume nbytes from beginning of b -- call apr_bucket_destroy as
  712. * appropriate, and/or modify start on last element
  713. * @param b The brigade to consume data from
  714. * @param nbytes The number of bytes to consume
  715. }
  716. //APU_DECLARE(void) apr_brigade_consume(apr_bucket_brigade *b,
  717. // apr_off_t nbytes);
  718. //#endif
  719. {
  720. * Return the total length of the brigade.
  721. * @param bb The brigade to compute the length of
  722. * @param read_all Read unknown-length buckets to force a size
  723. * @param length Returns the length of the brigade, or -1 if the brigade has
  724. * buckets of indeterminate length and read_all is 0.
  725. }
  726. {APU_DECLARE(apr_status_t) apr_brigade_length(apr_bucket_brigade *bb,
  727. int read_all,
  728. apr_off_t *length);
  729. }
  730. {
  731. * Take a bucket brigade and store the data in a flat char*
  732. * @param bb The bucket brigade to create the char* from
  733. * @param c The char* to write into
  734. * @param len The maximum length of the char array. On return, it is the
  735. * actual length of the char array.
  736. }
  737. {APU_DECLARE(apr_status_t) apr_brigade_flatten(apr_bucket_brigade *bb,
  738. char *c,
  739. apr_size_t *len);
  740. }
  741. {
  742. * Creates a pool-allocated string representing a flat bucket brigade
  743. * @param bb The bucket brigade to create the char array from
  744. * @param c On return, the allocated char array
  745. * @param len On return, the length of the char array.
  746. * @param pool The pool to allocate the string from.
  747. }
  748. {APU_DECLARE(apr_status_t) apr_brigade_pflatten(apr_bucket_brigade *bb,
  749. char **c,
  750. apr_size_t *len,
  751. apr_pool_t *pool);
  752. }
  753. {
  754. * Split a brigade to represent one LF line.
  755. * @param bbOut The bucket brigade that will have the LF line appended to.
  756. * @param bbIn The input bucket brigade to search for a LF-line.
  757. * @param block The blocking mode to be used to split the line.
  758. * @param maxbytes The maximum bytes to read. If this many bytes are seen
  759. * without a LF, the brigade will contain a partial line.
  760. }
  761. {APU_DECLARE(apr_status_t) apr_brigade_split_line(apr_bucket_brigade *bbOut,
  762. apr_bucket_brigade *bbIn,
  763. apr_read_type_e block,
  764. apr_off_t maxbytes);
  765. }
  766. {
  767. * create an iovec of the elements in a bucket_brigade... return number
  768. * of elements used. This is useful for writing to a file or to the
  769. * network efficiently.
  770. * @param b The bucket brigade to create the iovec from
  771. * @param vec The iovec to create
  772. * @param nvec The number of elements in the iovec. On return, it is the
  773. * number of iovec elements actually filled out.
  774. }
  775. {APU_DECLARE(apr_status_t) apr_brigade_to_iovec(apr_bucket_brigade *b,
  776. struct iovec *vec, int *nvec);
  777. }
  778. {
  779. * This function writes a list of strings into a bucket brigade.
  780. * @param b The bucket brigade to add to
  781. * @param flush The flush function to use if the brigade is full
  782. * @param ctx The structure to pass to the flush function
  783. * @param va A list of strings to add
  784. * @return APR_SUCCESS or error code.
  785. }
  786. {APU_DECLARE(apr_status_t) apr_brigade_vputstrs(apr_bucket_brigade *b,
  787. apr_brigade_flush flush,
  788. void *ctx,
  789. va_list va);
  790. }
  791. {
  792. * This function writes a string into a bucket brigade.
  793. * @param b The bucket brigade to add to
  794. * @param flush The flush function to use if the brigade is full
  795. * @param ctx The structure to pass to the flush function
  796. * @param str The string to add
  797. * @param nbyte The number of bytes to write
  798. * @return APR_SUCCESS or error code
  799. }
  800. {APU_DECLARE(apr_status_t) apr_brigade_write(apr_bucket_brigade *b,
  801. apr_brigade_flush flush, void *ctx,
  802. const char *str, apr_size_t nbyte);
  803. }
  804. {
  805. * This function writes multiple strings into a bucket brigade.
  806. * @param b The bucket brigade to add to
  807. * @param flush The flush function to use if the brigade is full
  808. * @param ctx The structure to pass to the flush function
  809. * @param vec The strings to add (address plus length for each)
  810. * @param nvec The number of entries in iovec
  811. * @return APR_SUCCESS or error code
  812. }
  813. {APU_DECLARE(apr_status_t) apr_brigade_writev(apr_bucket_brigade *b,
  814. apr_brigade_flush flush,
  815. void *ctx,
  816. const struct iovec *vec,
  817. apr_size_t nvec);
  818. }
  819. {
  820. * This function writes a string into a bucket brigade.
  821. * @param bb The bucket brigade to add to
  822. * @param flush The flush function to use if the brigade is full
  823. * @param ctx The structure to pass to the flush function
  824. * @param str The string to add
  825. * @return APR_SUCCESS or error code
  826. }
  827. {APU_DECLARE(apr_status_t) apr_brigade_puts(apr_bucket_brigade *bb,
  828. apr_brigade_flush flush, void *ctx,
  829. const char *str);
  830. }
  831. {
  832. * This function writes a character into a bucket brigade.
  833. * @param b The bucket brigade to add to
  834. * @param flush The flush function to use if the brigade is full
  835. * @param ctx The structure to pass to the flush function
  836. * @param c The character to add
  837. * @return APR_SUCCESS or error code
  838. }
  839. {APU_DECLARE(apr_status_t) apr_brigade_putc(apr_bucket_brigade *b,
  840. apr_brigade_flush flush, void *ctx,
  841. const char c);
  842. }
  843. {
  844. * This function writes an unspecified number of strings into a bucket brigade.
  845. * @param b The bucket brigade to add to
  846. * @param flush The flush function to use if the brigade is full
  847. * @param ctx The structure to pass to the flush function
  848. * @param ... The strings to add
  849. * @return APR_SUCCESS or error code
  850. }
  851. {APU_DECLARE_NONSTD(apr_status_t) apr_brigade_putstrs(apr_bucket_brigade *b,
  852. apr_brigade_flush flush,
  853. void *ctx, ...);
  854. }
  855. {
  856. * Evaluate a printf and put the resulting string at the end
  857. * of the bucket brigade.
  858. * @param b The brigade to write to
  859. * @param flush The flush function to use if the brigade is full
  860. * @param ctx The structure to pass to the flush function
  861. * @param fmt The format of the string to write
  862. * @param ... The arguments to fill out the format
  863. * @return APR_SUCCESS or error code
  864. }
  865. {APU_DECLARE_NONSTD(apr_status_t) apr_brigade_printf(apr_bucket_brigade *b,
  866. apr_brigade_flush flush,
  867. void *ctx,
  868. const char *fmt, ...)
  869. __attribute__((format(printf,4,5)));
  870. }
  871. {
  872. * Evaluate a printf and put the resulting string at the end
  873. * of the bucket brigade.
  874. * @param b The brigade to write to
  875. * @param flush The flush function to use if the brigade is full
  876. * @param ctx The structure to pass to the flush function
  877. * @param fmt The format of the string to write
  878. * @param va The arguments to fill out the format
  879. * @return APR_SUCCESS or error code
  880. }
  881. {APU_DECLARE(apr_status_t) apr_brigade_vprintf(apr_bucket_brigade *b,
  882. apr_brigade_flush flush,
  883. void *ctx,
  884. const char *fmt, va_list va);
  885. }
  886. { ***** Bucket freelist functions ***** }
  887. {
  888. * Create a bucket allocator.
  889. * @param p This pool's underlying apr_allocator_t is used to allocate memory
  890. * for the bucket allocator. When the pool is destroyed, the bucket
  891. * allocator's cleanup routine will free all memory that has been
  892. * allocated from it.
  893. * @remark The reason the allocator gets its memory from the pool's
  894. * apr_allocator_t rather than from the pool itself is because
  895. * the bucket allocator will free large memory blocks back to the
  896. * allocator when it's done with them, thereby preventing memory
  897. * footprint growth that would occur if we allocated from the pool.
  898. * @warning The allocator must never be used by more than one thread at a time.
  899. }
  900. //APU_DECLARE_NONSTD(apr_bucket_alloc_t *) apr_bucket_alloc_create(apr_pool_t *p);
  901. {
  902. * Create a bucket allocator.
  903. * @param allocator This apr_allocator_t is used to allocate both the bucket
  904. * allocator and all memory handed out by the bucket allocator. The
  905. * caller is responsible for destroying the bucket allocator and the
  906. * apr_allocator_t -- no automatic cleanups will happen.
  907. * @warning The allocator must never be used by more than one thread at a time.
  908. }
  909. //APU_DECLARE_NONSTD(apr_bucket_alloc_t *) apr_bucket_alloc_create_ex(apr_allocator_t *allocator);
  910. {
  911. * Destroy a bucket allocator.
  912. * @param list The allocator to be destroyed
  913. }
  914. //APU_DECLARE_NONSTD(void) apr_bucket_alloc_destroy(apr_bucket_alloc_t *list);
  915. {
  916. * Allocate memory for use by the buckets.
  917. * @param size The amount to allocate.
  918. * @param list The allocator from which to allocate the memory.
  919. }
  920. //APU_DECLARE_NONSTD(void *) apr_bucket_alloc(apr_size_t size, apr_bucket_alloc_t *list);
  921. {
  922. * Free memory previously allocated with apr_bucket_alloc().
  923. * @param block The block of memory to be freed.
  924. }
  925. //APU_DECLARE_NONSTD(void) apr_bucket_free(void *block);
  926. { ***** Bucket Functions ***** }
  927. {
  928. * Free the resources used by a bucket. If multiple buckets refer to
  929. * the same resource it is freed when the last one goes away.
  930. * @see apr_bucket_delete()
  931. * @param e The bucket to destroy
  932. }
  933. {#define apr_bucket_destroy(e) do begin
  934. (e)->type->destroy((e)->data); \
  935. (e)->free(e); \
  936. end while (0)}
  937. {
  938. * Delete a bucket by removing it from its brigade (if any) and then
  939. * destroying it.
  940. * @remark This mainly acts as an aid in avoiding code verbosity. It is
  941. * the preferred exact equivalent to:
  942. * <pre>
  943. * APR_BUCKET_REMOVE(e);
  944. * apr_bucket_destroy(e);
  945. * </pre>
  946. * @param e The bucket to delete
  947. }
  948. {#define apr_bucket_delete(e) do begin
  949. APR_BUCKET_REMOVE(e); \
  950. apr_bucket_destroy(e); \
  951. end while (0)}
  952. {
  953. * read the data from the bucket
  954. * @param e The bucket to read from
  955. * @param str The location to store the data in
  956. * @param len The amount of data read
  957. * @param block Whether the read function blocks
  958. }
  959. //#define apr_bucket_read(e,str,len,block) (e)->type->read(e, str, len, block)
  960. {
  961. * Setaside data so that stack data is not destroyed on returning from
  962. * the function
  963. * @param e The bucket to setaside
  964. * @param p The pool to setaside into
  965. }
  966. //#define apr_bucket_setaside(e,p) (e)->type->setaside(e,p)
  967. {
  968. * Split one bucket in two.
  969. * @param e The bucket to split
  970. * @param point The offset to split the bucket at
  971. }
  972. //#define apr_bucket_split(e,point) (e)->type->split(e, point)
  973. {
  974. * Copy a bucket.
  975. * @param e The bucket to copy
  976. * @param c Returns a pointer to the new bucket
  977. }
  978. //#define apr_bucket_copy(e,c) (e)->type->copy(e, c)
  979. { Bucket type handling }
  980. {
  981. * This function simply returns APR_SUCCESS to denote that the bucket does
  982. * not require anything to happen for its setaside() function. This is
  983. * appropriate for buckets that have "immortal" data -- the data will live
  984. * at least as long as the bucket.
  985. * @param data The bucket to setaside
  986. * @param pool The pool defining the desired lifetime of the bucket data
  987. * @return APR_SUCCESS
  988. }
  989. {APU_DECLARE_NONSTD(apr_status_t) apr_bucket_setaside_noop(apr_bucket *data,
  990. apr_pool_t *pool);
  991. }
  992. {
  993. * A place holder function that signifies that the setaside function was not
  994. * implemented for this bucket
  995. * @param data The bucket to setaside
  996. * @param pool The pool defining the desired lifetime of the bucket data
  997. * @return APR_ENOTIMPL
  998. }
  999. {APU_DECLARE_NONSTD(apr_status_t) apr_bucket_setaside_notimpl(apr_bucket *data,
  1000. apr_pool_t *pool);
  1001. }
  1002. {
  1003. * A place holder function that signifies that the split function was not
  1004. * implemented for this bucket
  1005. * @param data The bucket to split
  1006. * @param point The location to split the bucket
  1007. * @return APR_ENOTIMPL
  1008. }
  1009. {APU_DECLARE_NONSTD(apr_status_t) apr_bucket_split_notimpl(apr_bucket *data,
  1010. apr_size_t point);
  1011. }
  1012. {
  1013. * A place holder function that signifies that the copy function was not
  1014. * implemented for this bucket
  1015. * @param e The bucket to copy
  1016. * @param c Returns a pointer to the new bucket
  1017. * @return APR_ENOTIMPL
  1018. }
  1019. {APU_DECLARE_NONSTD(apr_status_t) apr_bucket_copy_notimpl(apr_bucket *e,
  1020. apr_bucket **c);
  1021. }
  1022. {
  1023. * A place holder function that signifies that this bucket does not need
  1024. * to do anything special to be destroyed. That's only the case for buckets
  1025. * that either have no data (metadata buckets) or buckets whose data pointer
  1026. * points to something that's not a bucket-type-specific structure, as with
  1027. * simple buckets where data points to a string and pipe buckets where data
  1028. * points directly to the apr_file_t.
  1029. * @param data The bucket data to destroy
  1030. }
  1031. //APU_DECLARE_NONSTD(void) apr_bucket_destroy_noop(void *data);
  1032. {
  1033. * There is no apr_bucket_destroy_notimpl, because destruction is required
  1034. * to be implemented (it could be a noop, but only if that makes sense for
  1035. * the bucket type)
  1036. }
  1037. { There is no apr_bucket_read_notimpl, because it is a required function
  1038. }
  1039. { All of the bucket types implemented by the core }
  1040. {
  1041. * The flush bucket type. This signifies that all data should be flushed to
  1042. * the next filter. The flush bucket should be sent with the other buckets.
  1043. }
  1044. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_flush;
  1045. {
  1046. * The EOS bucket type. This signifies that there will be no more data, ever.
  1047. * All filters MUST send all data to the next filter when they receive a
  1048. * bucket of this type
  1049. }
  1050. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_eos;
  1051. {
  1052. * The FILE bucket type. This bucket represents a file on disk
  1053. }
  1054. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_file;
  1055. {
  1056. * The HEAP bucket type. This bucket represents a data allocated from the
  1057. * heap.
  1058. }
  1059. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_heap;
  1060. //#if APR_HAS_MMAP
  1061. {
  1062. * The MMAP bucket type. This bucket represents an MMAP'ed file
  1063. }
  1064. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_mmap;
  1065. //#endif
  1066. {
  1067. * The POOL bucket type. This bucket represents a data that was allocated
  1068. * from a pool. IF this bucket is still available when the pool is cleared,
  1069. * the data is copied on to the heap.
  1070. }
  1071. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_pool;
  1072. {
  1073. * The PIPE bucket type. This bucket represents a pipe to another program.
  1074. }
  1075. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_pipe;
  1076. {
  1077. * The IMMORTAL bucket type. This bucket represents a segment of data that
  1078. * the creator is willing to take responsibility for. The core will do
  1079. * nothing with the data in an immortal bucket
  1080. }
  1081. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_immortal;
  1082. {
  1083. * The TRANSIENT bucket type. This bucket represents a data allocated off
  1084. * the stack. When the setaside function is called, this data is copied on
  1085. * to the heap
  1086. }
  1087. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_transient;
  1088. {
  1089. * The SOCKET bucket type. This bucket represents a socket to another machine
  1090. }
  1091. //APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_socket;
  1092. { ***** Simple buckets ***** }
  1093. {
  1094. * Split a simple bucket into two at the given point. Most non-reference
  1095. * counting buckets that allow multiple references to the same block of
  1096. * data (eg transient and immortal) will use this as their split function
  1097. * without any additional type-specific handling.
  1098. * @param b The bucket to be split
  1099. * @param point The offset of the first byte in the new bucket
  1100. * @return APR_EINVAL if the point is not within the bucket;
  1101. * APR_ENOMEM if allocation failed;
  1102. * or APR_SUCCESS
  1103. }
  1104. //APU_DECLARE_NONSTD(apr_status_t) apr_bucket_simple_split(apr_bucket *b,
  1105. // apr_size_t point);
  1106. {
  1107. * Copy a simple bucket. Most non-reference-counting buckets that allow
  1108. * multiple references to the same block of data (eg transient and immortal)
  1109. * will use this as their copy function without any additional type-specific
  1110. * handling.
  1111. * @param a The bucket to copy
  1112. * @param b Returns a pointer to the new bucket
  1113. * @return APR_ENOMEM if allocation failed;
  1114. * or APR_SUCCESS
  1115. }
  1116. {APU_DECLARE_NONSTD(apr_status_t) apr_bucket_simple_copy(apr_bucket *a,
  1117. apr_bucket **b);
  1118. }
  1119. { ***** Shared, reference-counted buckets ***** }
  1120. {
  1121. * Initialize a bucket containing reference-counted data that may be
  1122. * shared. The caller must allocate the bucket if necessary and
  1123. * initialize its type-dependent fields, and allocate and initialize
  1124. * its own private data structure. This function should only be called
  1125. * by type-specific bucket creation functions.
  1126. * @param b The bucket to initialize
  1127. * @param data A pointer to the private data structure
  1128. * with the reference count at the start
  1129. * @param start The start of the data in the bucket
  1130. * relative to the private base pointer
  1131. * @param length The length of the data in the bucket
  1132. * @return The new bucket, or NULL if allocation failed
  1133. }
  1134. {APU_DECLARE(apr_bucket *) apr_bucket_shared_make(apr_bucket *b, void *data,
  1135. apr_off_t start,
  1136. apr_size_t length);
  1137. }
  1138. {
  1139. * Decrement the refcount of the data in the bucket. This function
  1140. * should only be called by type-specific bucket destruction functions.
  1141. * @param data The private data pointer from the bucket to be destroyed
  1142. * @return TRUE or FALSE; TRUE if the reference count is now
  1143. * zero, indicating that the shared resource itself can
  1144. * be destroyed by the caller.
  1145. }
  1146. //APU_DECLARE(int) apr_bucket_shared_destroy(void *data);
  1147. {
  1148. * Split a bucket into two at the given point, and adjust the refcount
  1149. * to the underlying data. Most reference-counting bucket types will
  1150. * be able to use this function as their split function without any
  1151. * additional type-specific handling.
  1152. * @param b The bucket to be split
  1153. * @param point The offset of the first byte in the new bucket
  1154. * @return APR_EINVAL if the point is not within the bucket;
  1155. * APR_ENOMEM if allocation failed;
  1156. * or APR_SUCCESS
  1157. }
  1158. //APU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_split(apr_bucket *b,
  1159. // apr_size_t point);
  1160. {
  1161. * Copy a refcounted bucket, incrementing the reference count. Most
  1162. * reference-counting bucket types will be able to use this function
  1163. * as their copy function without any additional type-specific handling.
  1164. * @param a The bucket to copy
  1165. * @param b Returns a pointer to the new bucket
  1166. * @return APR_ENOMEM if allocation failed;
  1167. or APR_SUCCESS
  1168. }
  1169. //APU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_copy(apr_bucket *a,
  1170. // apr_bucket **b);
  1171. { ***** Functions to Create Buckets of varying types ***** }
  1172. {
  1173. * Each bucket type foo has two initialization functions:
  1174. * apr_bucket_foo_make which sets up some already-allocated memory as a
  1175. * bucket of type foo; and apr_bucket_foo_create which allocates memory
  1176. * for the bucket, calls apr_bucket_make_foo, and initializes the
  1177. * bucket's list pointers. The apr_bucket_foo_make functions are used
  1178. * inside the bucket code to change the type of buckets in place;
  1179. * other code should call apr_bucket_foo_create. All the initialization
  1180. * functions change nothing if they fail.
  1181. }
  1182. {
  1183. * Create an End of Stream bucket. This indicates that there is no more data
  1184. * coming from down the filter stack. All filters should flush at this point.
  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_eos_create(apr_bucket_alloc_t *list);
  1189. {
  1190. * Make the bucket passed in an EOS bucket. This indicates that there is no
  1191. * more data coming from down the filter stack. All filters should flush at
  1192. * this point.
  1193. * @param b The bucket to make into an EOS bucket
  1194. * @return The new bucket, or NULL if allocation failed
  1195. }
  1196. //APU_DECLARE(apr_bucket *) apr_bucket_eos_make(apr_bucket *b);
  1197. {
  1198. * Create a flush bucket. This indicates that filters should flush their
  1199. * data. There is no guarantee that they will flush it, but this is the
  1200. * best we can do.
  1201. * @param list The freelist from which this bucket should be allocated
  1202. * @return The new bucket, or NULL if allocation failed
  1203. }
  1204. //APU_DECLARE(apr_bucket *) apr_bucket_flush_create(apr_bucket_alloc_t *list);
  1205. {
  1206. * Make the bucket passed in a FLUSH bucket. This indicates that filters
  1207. * should flush their data. There is no guarantee that they will flush it,
  1208. * but this is the best we can do.
  1209. * @param b The bucket to make into a FLUSH bucket
  1210. * @return The new bucket, or NULL if allocation failed
  1211. }
  1212. //APU_DECLARE(apr_bucket *) apr_bucket_flush_make(apr_bucket *b);
  1213. {
  1214. * Create a bucket referring to long-lived data.
  1215. * @param buf The data to insert into the bucket
  1216. * @param nbyte The size of the data to insert.
  1217. * @param list The freelist from which this bucket should be allocated
  1218. * @return The new bucket, or NULL if allocation failed
  1219. }
  1220. {APU_DECLARE(apr_bucket *) apr_bucket_immortal_create(const char *buf,
  1221. apr_size_t nbyte,
  1222. apr_bucket_alloc_t *list);
  1223. }
  1224. {
  1225. * Make the bucket passed in a bucket refer to long-lived data
  1226. * @param b The bucket to make into a IMMORTAL bucket
  1227. * @param buf The data to insert into the bucket
  1228. * @param nbyte The size of the data to insert.
  1229. * @return The new bucket, or NULL if allocation failed
  1230. }
  1231. {APU_DECLARE(apr_bucket *) apr_bucket_immortal_make(apr_bucket *b,
  1232. const char *buf,
  1233. apr_size_t nbyte);
  1234. }
  1235. {
  1236. * Create a bucket referring to data on the stack.
  1237. * @param buf The data to insert into the bucket
  1238. * @param nbyte The size of the data to insert.
  1239. * @param list The freelist from which this bucket should be allocated
  1240. * @return The new bucket, or NULL if allocation failed
  1241. }
  1242. {APU_DECLARE(apr_bucket *) apr_bucket_transient_create(const char *buf,
  1243. apr_size_t nbyte,
  1244. apr_bucket_alloc_t *list);
  1245. }
  1246. {
  1247. * Make the bucket passed in a bucket refer to stack data
  1248. * @param b The bucket to make into a TRANSIENT bucket
  1249. * @param buf The data to insert into the bucket
  1250. * @param nbyte The size of the data to insert.
  1251. * @return The new bucket, or NULL if allocation failed
  1252. }
  1253. {APU_DECLARE(apr_bucket *) apr_bucket_transient_make(apr_bucket *b,
  1254. const char *buf,
  1255. apr_size_t nbyte);
  1256. }
  1257. {
  1258. * Create a bucket referring to memory on the heap. If the caller asks
  1259. * for the data to be copied, this function always allocates 4K of
  1260. * memory so that more data can be added to the bucket without
  1261. * requiring another allocation. Therefore not all the data may be put
  1262. * into the bucket. If copying is not requested then the bucket takes
  1263. * over responsibility for free()ing the memory.
  1264. * @param buf The buffer to insert into the bucket
  1265. * @param nbyte The size of the buffer to insert.
  1266. * @param free_func Function to use to free the data; NULL indicates that the
  1267. * bucket should make a copy of the data
  1268. * @param list The freelist from which this bucket should be allocated
  1269. * @return The new bucket, or NULL if allocation failed
  1270. }
  1271. {APU_DECLARE(apr_bucket *) apr_bucket_heap_create(const char *buf,
  1272. apr_size_t nbyte,
  1273. void ( *free_func)(void *data),
  1274. apr_bucket_alloc_t *list);}
  1275. {
  1276. * Make the bucket passed in a bucket refer to heap data
  1277. * @param b The bucket to make into a HEAP bucket
  1278. * @param buf The buffer to insert into the bucket
  1279. * @param nbyte The size of the buffer to insert.
  1280. * @param free_func Function to use to free the data; NULL indicates that the
  1281. * bucket should make a copy of the data
  1282. * @return The new bucket, or NULL if allocation failed
  1283. }
  1284. {APU_DECLARE(apr_bucket *) apr_bucket_heap_make(apr_bucket *b, const char *buf,
  1285. apr_size_t nbyte,
  1286. void ( *free_func)(void *data));}
  1287. {
  1288. * Create a bucket referring to memory allocated from a pool.
  1289. *
  1290. * @param buf The buffer to insert into the bucket
  1291. * @param length The number of bytes referred to by this bucket
  1292. * @param pool The pool the memory was allocated from
  1293. * @param list The freelist from which this bucket should be allocated
  1294. * @return The new bucket, or NULL if allocation failed
  1295. }
  1296. {APU_DECLARE(apr_bucket *) apr_bucket_pool_create(const char *buf,
  1297. apr_size_t length,
  1298. apr_pool_t *pool,
  1299. apr_bucket_alloc_t *list);}
  1300. {
  1301. * Make the bucket passed in a bucket refer to pool data
  1302. * @param b The bucket to make into a pool bucket
  1303. * @param buf The buffer to insert into the bucket
  1304. * @param length The number of bytes referred to by this bucket
  1305. * @param pool The pool the memory was allocated from
  1306. * @return The new bucket, or NULL if allocation failed
  1307. }
  1308. {APU_DECLARE(apr_bucket *) apr_bucket_pool_make(apr_bucket *b, const char *buf,
  1309. apr_size_t length,
  1310. apr_pool_t *pool);}
  1311. //#if APR_HAS_MMAP
  1312. {
  1313. * Create a bucket referring to mmap()ed memory.
  1314. * @param mm The mmap to insert into the bucket
  1315. * @param start The offset of the first byte in the mmap
  1316. * that this bucket refers to
  1317. * @param length The number of bytes referred to by this bucket
  1318. * @param list The freelist from which this bucket should be allocated
  1319. * @return The new bucket, or NULL if allocation failed
  1320. }
  1321. {APU_DECLARE(apr_bucket *) apr_bucket_mmap_create(apr_mmap_t *mm,
  1322. apr_off_t start,
  1323. apr_size_t length,
  1324. apr_bucket_alloc_t *list);
  1325. }
  1326. {
  1327. * Make the bucket passed in a bucket refer to an MMAP'ed file
  1328. * @param b The bucket to make into a MMAP bucket
  1329. * @param mm The mmap to insert into the bucket
  1330. * @param start The offset of the first byte in the mmap
  1331. * that this bucket refers to
  1332. * @param length The number of bytes referred to by this bucket
  1333. * @return The new bucket, or NULL if allocation failed
  1334. }
  1335. {APU_DECLARE(apr_bucket *) apr_bucket_mmap_make(apr_bucket *b, apr_mmap_t *mm,
  1336. apr_off_t start,
  1337. apr_size_t length);
  1338. #endif}
  1339. {
  1340. * Create a bucket referring to a socket.
  1341. * @param thissock The socket to put in the bucket
  1342. * @param list The freelist from which this bucket should be allocated
  1343. * @return The new bucket, or NULL if allocation failed
  1344. }
  1345. {APU_DECLARE(apr_bucket *) apr_bucket_socket_create(apr_socket_t *thissock,
  1346. apr_bucket_alloc_t *list);}
  1347. {
  1348. * Make the bucket passed in a bucket refer to a socket
  1349. * @param b The bucket to make into a SOCKET bucket
  1350. * @param thissock The socket to put in the bucket
  1351. * @return The new bucket, or NULL if allocation failed
  1352. }
  1353. {APU_DECLARE(apr_bucket *) apr_bucket_socket_make(apr_bucket *b,
  1354. apr_socket_t *thissock);}
  1355. {
  1356. * Create a bucket referring to a pipe.
  1357. * @param thispipe The pipe to put in the bucket
  1358. * @param list The freelist from which this bucket should be allocated
  1359. * @return The new bucket, or NULL if allocation failed
  1360. }
  1361. {APU_DECLARE(apr_bucket *) apr_bucket_pipe_create(apr_file_t *thispipe,
  1362. apr_bucket_alloc_t *list);}
  1363. {
  1364. * Make the bucket passed in a bucket refer to a pipe
  1365. * @param b The bucket to make into a PIPE bucket
  1366. * @param thispipe The pipe to put in the bucket
  1367. * @return The new bucket, or NULL if allocation failed
  1368. }
  1369. {APU_DECLARE(apr_bucket *) apr_bucket_pipe_make(apr_bucket *b,
  1370. apr_file_t *thispipe);}
  1371. {
  1372. * Create a bucket referring to a file.
  1373. * @param fd The file to put in the bucket
  1374. * @param offset The offset where the data of interest begins in the file
  1375. * @param len The amount of data in the file we are interested in
  1376. * @param p The pool into which any needed structures should be created
  1377. * while reading from this file bucket
  1378. * @param list The freelist from which this bucket should be allocated
  1379. * @return The new bucket, or NULL if allocation failed
  1380. }
  1381. {APU_DECLARE(apr_bucket *) apr_bucket_file_create(apr_file_t *fd,
  1382. apr_off_t offset,
  1383. apr_size_t len,
  1384. apr_pool_t *p,
  1385. apr_bucket_alloc_t *list);
  1386. }
  1387. {
  1388. * Make the bucket passed in a bucket refer to a file
  1389. * @param b The bucket to make into a FILE bucket
  1390. * @param fd The file to put in the bucket
  1391. * @param offset The offset where the data of interest begins in the file
  1392. * @param len The amount of data in the file we are interested in
  1393. * @param p The pool into which any needed structures should be created
  1394. * while reading from this file bucket
  1395. * @return The new bucket, or NULL if allocation failed
  1396. }
  1397. {APU_DECLARE(apr_bucket *) apr_bucket_file_make(apr_bucket *b, apr_file_t *fd,
  1398. apr_off_t offset,
  1399. apr_size_t len, apr_pool_t *p);
  1400. }
  1401. {
  1402. * Enable or disable memory-mapping for a FILE bucket (default is enabled)
  1403. * @param b The bucket
  1404. * @param enabled Whether memory-mapping should be enabled
  1405. * @return APR_SUCCESS normally, or an error code if the operation fails
  1406. }
  1407. {APU_DECLARE(apr_status_t) apr_bucket_file_enable_mmap(apr_bucket *b,
  1408. int enabled);}