Fix memory leak when maintaining resources. When extra resources are
[apr-util.git] / include / apr_buckets.h
blob81c29b27b983fa8e387b9658487469deeec0ba50
1 /* Copyright 2000-2004 The Apache Software Foundation
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 /**
16 * @file apr_buckets.h
17 * @brief APR-UTIL Buckets/Bucket Brigades
20 #ifndef APR_BUCKETS_H
21 #define APR_BUCKETS_H
23 #if defined(APR_BUCKET_DEBUG) && !defined(APR_RING_DEBUG)
24 #define APR_RING_DEBUG
25 #endif
27 #include "apu.h"
28 #include "apr_network_io.h"
29 #include "apr_file_io.h"
30 #include "apr_general.h"
31 #include "apr_mmap.h"
32 #include "apr_errno.h"
33 #include "apr_ring.h"
34 #include "apr.h"
35 #if APR_HAVE_SYS_UIO_H
36 #include <sys/uio.h> /* for struct iovec */
37 #endif
38 #if APR_HAVE_STDARG_H
39 #include <stdarg.h>
40 #endif
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
46 /**
47 * @defgroup APR_Util_Bucket_Brigades Bucket Brigades
48 * @ingroup APR_Util
49 * @{
52 /** default bucket buffer size - 8KB minus room for memory allocator headers */
53 #define APR_BUCKET_BUFF_SIZE 8000
55 /** Determines how a bucket or brigade should be read */
56 typedef enum {
57 APR_BLOCK_READ, /**< block until data becomes available */
58 APR_NONBLOCK_READ /**< return immediately if no data is available */
59 } apr_read_type_e;
61 /**
62 * The one-sentence buzzword-laden overview: Bucket brigades represent
63 * a complex data stream that can be passed through a layered IO
64 * system without unnecessary copying. A longer overview follows...
66 * A bucket brigade is a doubly linked list (ring) of buckets, so we
67 * aren't limited to inserting at the front and removing at the end.
68 * Buckets are only passed around as members of a brigade, although
69 * singleton buckets can occur for short periods of time.
71 * Buckets are data stores of various types. They can refer to data in
72 * memory, or part of a file or mmap area, or the output of a process,
73 * etc. Buckets also have some type-dependent accessor functions:
74 * read, split, copy, setaside, and destroy.
76 * read returns the address and size of the data in the bucket. If the
77 * data isn't in memory then it is read in and the bucket changes type
78 * so that it can refer to the new location of the data. If all the
79 * data doesn't fit in the bucket then a new bucket is inserted into
80 * the brigade to hold the rest of it.
82 * split divides the data in a bucket into two regions. After a split
83 * the original bucket refers to the first part of the data and a new
84 * bucket inserted into the brigade after the original bucket refers
85 * to the second part of the data. Reference counts are maintained as
86 * necessary.
88 * setaside ensures that the data in the bucket has a long enough
89 * lifetime. Sometimes it is convenient to create a bucket referring
90 * to data on the stack in the expectation that it will be consumed
91 * (output to the network) before the stack is unwound. If that
92 * expectation turns out not to be valid, the setaside function is
93 * called to move the data somewhere safer.
95 * copy makes a duplicate of the bucket structure as long as it's
96 * possible to have multiple references to a single copy of the
97 * data itself. Not all bucket types can be copied.
99 * destroy maintains the reference counts on the resources used by a
100 * bucket and frees them if necessary.
102 * Note: all of the above functions have wrapper macros (apr_bucket_read(),
103 * apr_bucket_destroy(), etc), and those macros should be used rather
104 * than using the function pointers directly.
106 * To write a bucket brigade, they are first made into an iovec, so that we
107 * don't write too little data at one time. Currently we ignore compacting the
108 * buckets into as few buckets as possible, but if we really want good
109 * performance, then we need to compact the buckets before we convert to an
110 * iovec, or possibly while we are converting to an iovec.
114 * Forward declaration of the main types.
117 /** @see apr_bucket_brigade */
118 typedef struct apr_bucket_brigade apr_bucket_brigade;
119 /** @see apr_bucket */
120 typedef struct apr_bucket apr_bucket;
121 /** @see apr_bucket_alloc_t */
122 typedef struct apr_bucket_alloc_t apr_bucket_alloc_t;
124 /** @see apr_bucket_type_t */
125 typedef struct apr_bucket_type_t apr_bucket_type_t;
128 * Basic bucket type
130 struct apr_bucket_type_t {
132 * The name of the bucket type
134 const char *name;
135 /**
136 * The number of functions this bucket understands. Can not be less than
137 * five.
139 int num_func;
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.
150 enum {
151 /** This bucket type represents actual data to send to the client. */
152 APR_BUCKET_DATA = 0,
153 /** This bucket type represents metadata. */
154 APR_BUCKET_METADATA = 1
155 } is_metadata;
157 * Free the private data and any resources used by the bucket (if they
158 * aren't shared with another bucket). This function is required to be
159 * implemented for all bucket types, though it might be a no-op on some
160 * of them (namely ones that never allocate any private data structures).
161 * @param data The private data pointer from the bucket to be destroyed
163 void (*destroy)(void *data);
166 * Read the data from the bucket. This is required to be implemented
167 * for all bucket types.
168 * @param b The bucket to read from
169 * @param str A place to store the data read. Allocation should only be
170 * done if absolutely necessary.
171 * @param len The amount of data read.
172 * @param block Should this read function block if there is more data that
173 * cannot be read immediately.
175 apr_status_t (*read)(apr_bucket *b, const char **str, apr_size_t *len,
176 apr_read_type_e block);
179 * Make it possible to set aside the data for at least as long as the
180 * given pool. Buckets containing data that could potentially die before
181 * this pool (e.g. the data resides on the stack, in a child pool of
182 * the given pool, or in a disjoint pool) must somehow copy, shift, or
183 * transform the data to have the proper lifetime.
184 * @param e The bucket to convert
185 * @remark Some bucket types contain data that will always outlive the
186 * bucket itself. For example no data (EOS and FLUSH), or the data
187 * resides in global, constant memory (IMMORTAL), or the data is on
188 * the heap (HEAP). For these buckets, apr_bucket_setaside_noop can
189 * be used.
191 apr_status_t (*setaside)(apr_bucket *e, apr_pool_t *pool);
194 * Split one bucket in two at the specified position by duplicating
195 * the bucket structure (not the data) and modifying any necessary
196 * start/end/offset information. If it's not possible to do this
197 * for the bucket type (perhaps the length of the data is indeterminate,
198 * as with pipe and socket buckets), then APR_ENOTIMPL is returned.
199 * @param e The bucket to split
200 * @param point The offset of the first byte in the new bucket
202 apr_status_t (*split)(apr_bucket *e, apr_size_t point);
205 * Copy the bucket structure (not the data), assuming that this is
206 * possible for the bucket type. If it's not, APR_ENOTIMPL is returned.
207 * @param e The bucket to copy
208 * @param c Returns a pointer to the new bucket
210 apr_status_t (*copy)(apr_bucket *e, apr_bucket **c);
215 * apr_bucket structures are allocated on the malloc() heap and
216 * their lifetime is controlled by the parent apr_bucket_brigade
217 * structure. Buckets can move from one brigade to another e.g. by
218 * calling APR_BRIGADE_CONCAT(). In general the data in a bucket has
219 * the same lifetime as the bucket and is freed when the bucket is
220 * destroyed; if the data is shared by more than one bucket (e.g.
221 * after a split) the data is freed when the last bucket goes away.
223 struct apr_bucket {
224 /** Links to the rest of the brigade */
225 APR_RING_ENTRY(apr_bucket) link;
226 /** The type of bucket. */
227 const apr_bucket_type_t *type;
228 /** The length of the data in the bucket. This could have been implemented
229 * with a function, but this is an optimization, because the most
230 * common thing to do will be to get the length. If the length is unknown,
231 * the value of this field will be (apr_size_t)(-1).
233 apr_size_t length;
234 /** The start of the data in the bucket relative to the private base
235 * pointer. The vast majority of bucket types allow a fixed block of
236 * data to be referenced by multiple buckets, each bucket pointing to
237 * a different segment of the data. That segment starts at base+start
238 * and ends at base+start+length.
239 * If the length == (apr_size_t)(-1), then start == -1.
241 apr_off_t start;
242 /** type-dependent data hangs off this pointer */
243 void *data;
245 * Pointer to function used to free the bucket. This function should
246 * always be defined and it should be consistent with the memory
247 * function used to allocate the bucket. For example, if malloc() is
248 * used to allocate the bucket, this pointer should point to free().
249 * @param e Pointer to the bucket being freed
251 void (*free)(void *e);
252 /** The freelist from which this bucket was allocated */
253 apr_bucket_alloc_t *list;
256 /** A list of buckets */
257 struct apr_bucket_brigade {
258 /** The pool to associate the brigade with. The data is not allocated out
259 * of the pool, but a cleanup is registered with this pool. If the
260 * brigade is destroyed by some mechanism other than pool destruction,
261 * the destroying function is responsible for killing the cleanup.
263 apr_pool_t *p;
264 /** The buckets in the brigade are on this list. */
266 * The apr_bucket_list structure doesn't actually need a name tag
267 * because it has no existence independent of struct apr_bucket_brigade;
268 * the ring macros are designed so that you can leave the name tag
269 * argument empty in this situation but apparently the Windows compiler
270 * doesn't like that.
272 APR_RING_HEAD(apr_bucket_list, apr_bucket) list;
273 /** The freelist from which this bucket was allocated */
274 apr_bucket_alloc_t *bucket_alloc;
279 * Function called when a brigade should be flushed
281 typedef apr_status_t (*apr_brigade_flush)(apr_bucket_brigade *bb, void *ctx);
284 * define APR_BUCKET_DEBUG if you want your brigades to be checked for
285 * validity at every possible instant. this will slow your code down
286 * substantially but is a very useful debugging tool.
288 #ifdef APR_BUCKET_DEBUG
290 #define APR_BRIGADE_CHECK_CONSISTENCY(b) \
291 APR_RING_CHECK_CONSISTENCY(&(b)->list, apr_bucket, link)
293 #define APR_BUCKET_CHECK_CONSISTENCY(e) \
294 APR_RING_CHECK_ELEM_CONSISTENCY((e), apr_bucket, link)
296 #else
298 * checks the ring pointers in a bucket brigade for consistency. an
299 * abort() will be triggered if any inconsistencies are found.
300 * note: this is a no-op unless APR_BUCKET_DEBUG is defined.
301 * @param b The brigade
303 #define APR_BRIGADE_CHECK_CONSISTENCY(b)
305 * checks the brigade a bucket is in for ring consistency. an
306 * abort() will be triggered if any inconsistencies are found.
307 * note: this is a no-op unless APR_BUCKET_DEBUG is defined.
308 * @param e The bucket
310 #define APR_BUCKET_CHECK_CONSISTENCY(e)
311 #endif
315 * Wrappers around the RING macros to reduce the verbosity of the code
316 * that handles bucket brigades.
319 * The magic pointer value that indicates the head of the brigade
320 * @remark This is used to find the beginning and end of the brigade, eg:
321 * <pre>
322 * while (e != APR_BRIGADE_SENTINEL(b)) {
323 * ...
324 * e = APR_BUCKET_NEXT(e);
326 * </pre>
327 * @param b The brigade
328 * @return The magic pointer value
330 #define APR_BRIGADE_SENTINEL(b) APR_RING_SENTINEL(&(b)->list, apr_bucket, link)
333 * Determine if the bucket brigade is empty
334 * @param b The brigade to check
335 * @return true or false
337 #define APR_BRIGADE_EMPTY(b) APR_RING_EMPTY(&(b)->list, apr_bucket, link)
340 * Return the first bucket in a brigade
341 * @param b The brigade to query
342 * @return The first bucket in the brigade
344 #define APR_BRIGADE_FIRST(b) APR_RING_FIRST(&(b)->list)
346 * Return the last bucket in a brigade
347 * @param b The brigade to query
348 * @return The last bucket in the brigade
350 #define APR_BRIGADE_LAST(b) APR_RING_LAST(&(b)->list)
353 * Insert a list of buckets at the front of a brigade
354 * @param b The brigade to add to
355 * @param e The first bucket in a list of buckets to insert
357 #define APR_BRIGADE_INSERT_HEAD(b, e) do { \
358 apr_bucket *ap__b = (e); \
359 APR_RING_INSERT_HEAD(&(b)->list, ap__b, apr_bucket, link); \
360 APR_BRIGADE_CHECK_CONSISTENCY((b)); \
361 } while (0)
364 * Insert a list of buckets at the end of a brigade
365 * @param b The brigade to add to
366 * @param e The first bucket in a list of buckets to insert
368 #define APR_BRIGADE_INSERT_TAIL(b, e) do { \
369 apr_bucket *ap__b = (e); \
370 APR_RING_INSERT_TAIL(&(b)->list, ap__b, apr_bucket, link); \
371 APR_BRIGADE_CHECK_CONSISTENCY((b)); \
372 } while (0)
375 * Concatenate brigade b onto the end of brigade a, leaving brigade b empty
376 * @param a The first brigade
377 * @param b The second brigade
379 #define APR_BRIGADE_CONCAT(a, b) do { \
380 APR_RING_CONCAT(&(a)->list, &(b)->list, apr_bucket, link); \
381 APR_BRIGADE_CHECK_CONSISTENCY((a)); \
382 } while (0)
385 * Prepend brigade b onto the beginning of brigade a, leaving brigade b empty
386 * @param a The first brigade
387 * @param b The second brigade
389 #define APR_BRIGADE_PREPEND(a, b) do { \
390 APR_RING_PREPEND(&(a)->list, &(b)->list, apr_bucket, link); \
391 APR_BRIGADE_CHECK_CONSISTENCY((a)); \
392 } while (0)
395 * Insert a list of buckets before a specified bucket
396 * @param a The bucket to insert before
397 * @param b The buckets to insert
399 #define APR_BUCKET_INSERT_BEFORE(a, b) do { \
400 apr_bucket *ap__a = (a), *ap__b = (b); \
401 APR_RING_INSERT_BEFORE(ap__a, ap__b, link); \
402 APR_BUCKET_CHECK_CONSISTENCY(ap__a); \
403 } while (0)
406 * Insert a list of buckets after a specified bucket
407 * @param a The bucket to insert after
408 * @param b The buckets to insert
410 #define APR_BUCKET_INSERT_AFTER(a, b) do { \
411 apr_bucket *ap__a = (a), *ap__b = (b); \
412 APR_RING_INSERT_AFTER(ap__a, ap__b, link); \
413 APR_BUCKET_CHECK_CONSISTENCY(ap__a); \
414 } while (0)
417 * Get the next bucket in the list
418 * @param e The current bucket
419 * @return The next bucket
421 #define APR_BUCKET_NEXT(e) APR_RING_NEXT((e), link)
423 * Get the previous bucket in the list
424 * @param e The current bucket
425 * @return The previous bucket
427 #define APR_BUCKET_PREV(e) APR_RING_PREV((e), link)
430 * Remove a bucket from its bucket brigade
431 * @param e The bucket to remove
433 #define APR_BUCKET_REMOVE(e) APR_RING_REMOVE((e), link)
436 * Initialize a new bucket's prev/next pointers
437 * @param e The bucket to initialize
439 #define APR_BUCKET_INIT(e) APR_RING_ELEM_INIT((e), link)
442 * Determine if a bucket contains metadata. An empty bucket is
443 * safe to arbitrarily remove if and only if this is false.
444 * @param e The bucket to inspect
445 * @return true or false
447 #define APR_BUCKET_IS_METADATA(e) ((e)->type->is_metadata)
450 * Determine if a bucket is a FLUSH bucket
451 * @param e The bucket to inspect
452 * @return true or false
454 #define APR_BUCKET_IS_FLUSH(e) ((e)->type == &apr_bucket_type_flush)
456 * Determine if a bucket is an EOS bucket
457 * @param e The bucket to inspect
458 * @return true or false
460 #define APR_BUCKET_IS_EOS(e) ((e)->type == &apr_bucket_type_eos)
462 * Determine if a bucket is a FILE bucket
463 * @param e The bucket to inspect
464 * @return true or false
466 #define APR_BUCKET_IS_FILE(e) ((e)->type == &apr_bucket_type_file)
468 * Determine if a bucket is a PIPE bucket
469 * @param e The bucket to inspect
470 * @return true or false
472 #define APR_BUCKET_IS_PIPE(e) ((e)->type == &apr_bucket_type_pipe)
474 * Determine if a bucket is a SOCKET bucket
475 * @param e The bucket to inspect
476 * @return true or false
478 #define APR_BUCKET_IS_SOCKET(e) ((e)->type == &apr_bucket_type_socket)
480 * Determine if a bucket is a HEAP bucket
481 * @param e The bucket to inspect
482 * @return true or false
484 #define APR_BUCKET_IS_HEAP(e) ((e)->type == &apr_bucket_type_heap)
486 * Determine if a bucket is a TRANSIENT bucket
487 * @param e The bucket to inspect
488 * @return true or false
490 #define APR_BUCKET_IS_TRANSIENT(e) ((e)->type == &apr_bucket_type_transient)
492 * Determine if a bucket is a IMMORTAL bucket
493 * @param e The bucket to inspect
494 * @return true or false
496 #define APR_BUCKET_IS_IMMORTAL(e) ((e)->type == &apr_bucket_type_immortal)
497 #if APR_HAS_MMAP
499 * Determine if a bucket is a MMAP bucket
500 * @param e The bucket to inspect
501 * @return true or false
503 #define APR_BUCKET_IS_MMAP(e) ((e)->type == &apr_bucket_type_mmap)
504 #endif
506 * Determine if a bucket is a POOL bucket
507 * @param e The bucket to inspect
508 * @return true or false
510 #define APR_BUCKET_IS_POOL(e) ((e)->type == &apr_bucket_type_pool)
513 * General-purpose reference counting for the various bucket types.
515 * Any bucket type that keeps track of the resources it uses (i.e.
516 * most of them except for IMMORTAL, TRANSIENT, and EOS) needs to
517 * attach a reference count to the resource so that it can be freed
518 * when the last bucket that uses it goes away. Resource-sharing may
519 * occur because of bucket splits or buckets that refer to globally
520 * cached data. */
522 /** @see apr_bucket_refcount */
523 typedef struct apr_bucket_refcount apr_bucket_refcount;
525 * The structure used to manage the shared resource must start with an
526 * apr_bucket_refcount which is updated by the general-purpose refcount
527 * code. A pointer to the bucket-type-dependent private data structure
528 * can be cast to a pointer to an apr_bucket_refcount and vice versa.
530 struct apr_bucket_refcount {
531 /** The number of references to this bucket */
532 int refcount;
535 /* ***** Reference-counted bucket types ***** */
537 /** @see apr_bucket_heap */
538 typedef struct apr_bucket_heap apr_bucket_heap;
540 * A bucket referring to data allocated off the heap.
542 struct apr_bucket_heap {
543 /** Number of buckets using this memory */
544 apr_bucket_refcount refcount;
545 /** The start of the data actually allocated. This should never be
546 * modified, it is only used to free the bucket.
548 char *base;
549 /** how much memory was allocated */
550 apr_size_t alloc_len;
551 /** function to use to delete the data */
552 void (*free_func)(void *data);
555 /** @see apr_bucket_pool */
556 typedef struct apr_bucket_pool apr_bucket_pool;
558 * A bucket referring to data allocated from a pool
560 struct apr_bucket_pool {
561 /** The pool bucket must be able to be easily morphed to a heap
562 * bucket if the pool gets cleaned up before all references are
563 * destroyed. This apr_bucket_heap structure is populated automatically
564 * when the pool gets cleaned up, and subsequent calls to pool_read()
565 * will result in the apr_bucket in question being morphed into a
566 * regular heap bucket. (To avoid having to do many extra refcount
567 * manipulations and b->data manipulations, the apr_bucket_pool
568 * struct actually *contains* the apr_bucket_heap struct that it
569 * will become as its first element; the two share their
570 * apr_bucket_refcount members.)
572 apr_bucket_heap heap;
573 /** The block of data actually allocated from the pool.
574 * Segments of this block are referenced by adjusting
575 * the start and length of the apr_bucket accordingly.
576 * This will be NULL after the pool gets cleaned up.
578 const char *base;
579 /** The pool the data was allocated from. When the pool
580 * is cleaned up, this gets set to NULL as an indicator
581 * to pool_read() that the data is now on the heap and
582 * so it should morph the bucket into a regular heap
583 * bucket before continuing.
585 apr_pool_t *pool;
586 /** The freelist this structure was allocated from, which is
587 * needed in the cleanup phase in order to allocate space on the heap
589 apr_bucket_alloc_t *list;
592 #if APR_HAS_MMAP
593 /** @see apr_bucket_mmap */
594 typedef struct apr_bucket_mmap apr_bucket_mmap;
596 * A bucket referring to an mmap()ed file
598 struct apr_bucket_mmap {
599 /** Number of buckets using this memory */
600 apr_bucket_refcount refcount;
601 /** The mmap this sub_bucket refers to */
602 apr_mmap_t *mmap;
604 #endif
606 /** @see apr_bucket_file */
607 typedef struct apr_bucket_file apr_bucket_file;
609 * A bucket referring to an file
611 struct apr_bucket_file {
612 /** Number of buckets using this memory */
613 apr_bucket_refcount refcount;
614 /** The file this bucket refers to */
615 apr_file_t *fd;
616 /** The pool into which any needed structures should
617 * be created while reading from this file bucket */
618 apr_pool_t *readpool;
619 #if APR_HAS_MMAP
620 /** Whether this bucket should be memory-mapped if
621 * a caller tries to read from it */
622 int can_mmap;
623 #endif /* APR_HAS_MMAP */
626 /** @see apr_bucket_structs */
627 typedef union apr_bucket_structs apr_bucket_structs;
629 * A union of all bucket structures so we know what
630 * the max size is.
632 union apr_bucket_structs {
633 apr_bucket b; /**< Bucket */
634 apr_bucket_heap heap; /**< Heap */
635 apr_bucket_pool pool; /**< Pool */
636 #if APR_HAS_MMAP
637 apr_bucket_mmap mmap; /**< MMap */
638 #endif
639 apr_bucket_file file; /**< File */
643 * The amount that apr_bucket_alloc() should allocate in the common case.
644 * Note: this is twice as big as apr_bucket_structs to allow breathing
645 * room for third-party bucket types.
647 #define APR_BUCKET_ALLOC_SIZE APR_ALIGN_DEFAULT(2*sizeof(apr_bucket_structs))
649 /* ***** Bucket Brigade Functions ***** */
651 * Create a new bucket brigade. The bucket brigade is originally empty.
652 * @param p The pool to associate with the brigade. Data is not allocated out
653 * of the pool, but a cleanup is registered.
654 * @param list The bucket allocator to use
655 * @return The empty bucket brigade
657 APU_DECLARE(apr_bucket_brigade *) apr_brigade_create(apr_pool_t *p,
658 apr_bucket_alloc_t *list);
661 * destroy an entire bucket brigade. This includes destroying all of the
662 * buckets within the bucket brigade's bucket list.
663 * @param b The bucket brigade to destroy
665 APU_DECLARE(apr_status_t) apr_brigade_destroy(apr_bucket_brigade *b);
668 * empty out an entire bucket brigade. This includes destroying all of the
669 * buckets within the bucket brigade's bucket list. This is similar to
670 * apr_brigade_destroy(), except that it does not deregister the brigade's
671 * pool cleanup function.
672 * @param data The bucket brigade to clean up
673 * @remark Generally, you should use apr_brigade_destroy(). This function
674 * can be useful in situations where you have a single brigade that
675 * you wish to reuse many times by destroying all of the buckets in
676 * the brigade and putting new buckets into it later.
678 APU_DECLARE(apr_status_t) apr_brigade_cleanup(void *data);
681 * Split a bucket brigade into two, such that the given bucket is the
682 * first in the new bucket brigade. This function is useful when a
683 * filter wants to pass only the initial part of a brigade to the next
684 * filter.
685 * @param b The brigade to split
686 * @param e The first element of the new brigade
687 * @return The new brigade
689 APU_DECLARE(apr_bucket_brigade *) apr_brigade_split(apr_bucket_brigade *b,
690 apr_bucket *e);
693 * Partition a bucket brigade at a given offset (in bytes from the start of
694 * the brigade). This is useful whenever a filter wants to use known ranges
695 * of bytes from the brigade; the ranges can even overlap.
696 * @param b The brigade to partition
697 * @param point The offset at which to partition the brigade
698 * @param after_point Returns a pointer to the first bucket after the partition
700 APU_DECLARE(apr_status_t) apr_brigade_partition(apr_bucket_brigade *b,
701 apr_off_t point,
702 apr_bucket **after_point);
705 * Return the total length of the brigade.
706 * @param bb The brigade to compute the length of
707 * @param read_all Read unknown-length buckets to force a size
708 * @param length Returns the length of the brigade, or -1 if the brigade has
709 * buckets of indeterminate length and read_all is 0.
711 APU_DECLARE(apr_status_t) apr_brigade_length(apr_bucket_brigade *bb,
712 int read_all,
713 apr_off_t *length);
716 * Take a bucket brigade and store the data in a flat char*
717 * @param bb The bucket brigade to create the char* from
718 * @param c The char* to write into
719 * @param len The maximum length of the char array. On return, it is the
720 * actual length of the char array.
722 APU_DECLARE(apr_status_t) apr_brigade_flatten(apr_bucket_brigade *bb,
723 char *c,
724 apr_size_t *len);
727 * Creates a pool-allocated string representing a flat bucket brigade
728 * @param bb The bucket brigade to create the char array from
729 * @param c On return, the allocated char array
730 * @param len On return, the length of the char array.
731 * @param pool The pool to allocate the string from.
733 APU_DECLARE(apr_status_t) apr_brigade_pflatten(apr_bucket_brigade *bb,
734 char **c,
735 apr_size_t *len,
736 apr_pool_t *pool);
739 * Split a brigade to represent one LF line.
740 * @param bbOut The bucket brigade that will have the LF line appended to.
741 * @param bbIn The input bucket brigade to search for a LF-line.
742 * @param block The blocking mode to be used to split the line.
743 * @param maxbytes The maximum bytes to read. If this many bytes are seen
744 * without a LF, the brigade will contain a partial line.
746 APU_DECLARE(apr_status_t) apr_brigade_split_line(apr_bucket_brigade *bbOut,
747 apr_bucket_brigade *bbIn,
748 apr_read_type_e block,
749 apr_off_t maxbytes);
752 * create an iovec of the elements in a bucket_brigade... return number
753 * of elements used. This is useful for writing to a file or to the
754 * network efficiently.
755 * @param b The bucket brigade to create the iovec from
756 * @param vec The iovec to create
757 * @param nvec The number of elements in the iovec. On return, it is the
758 * number of iovec elements actually filled out.
760 APU_DECLARE(apr_status_t) apr_brigade_to_iovec(apr_bucket_brigade *b,
761 struct iovec *vec, int *nvec);
764 * This function writes a list of strings into a bucket brigade.
765 * @param b The bucket brigade to add to
766 * @param flush The flush function to use if the brigade is full
767 * @param ctx The structure to pass to the flush function
768 * @param va A list of strings to add
769 * @return APR_SUCCESS or error code.
771 APU_DECLARE(apr_status_t) apr_brigade_vputstrs(apr_bucket_brigade *b,
772 apr_brigade_flush flush,
773 void *ctx,
774 va_list va);
777 * This function writes a string into a bucket brigade.
778 * @param b The bucket brigade to add to
779 * @param flush The flush function to use if the brigade is full
780 * @param ctx The structure to pass to the flush function
781 * @param str The string to add
782 * @param nbyte The number of bytes to write
783 * @return APR_SUCCESS or error code
785 APU_DECLARE(apr_status_t) apr_brigade_write(apr_bucket_brigade *b,
786 apr_brigade_flush flush, void *ctx,
787 const char *str, apr_size_t nbyte);
790 * This function writes multiple strings into a bucket brigade.
791 * @param b The bucket brigade to add to
792 * @param flush The flush function to use if the brigade is full
793 * @param ctx The structure to pass to the flush function
794 * @param vec The strings to add (address plus length for each)
795 * @param nvec The number of entries in iovec
796 * @return APR_SUCCESS or error code
798 APU_DECLARE(apr_status_t) apr_brigade_writev(apr_bucket_brigade *b,
799 apr_brigade_flush flush,
800 void *ctx,
801 const struct iovec *vec,
802 apr_size_t nvec);
805 * This function writes a string into a bucket brigade.
806 * @param bb 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 str The string to add
810 * @return APR_SUCCESS or error code
812 APU_DECLARE(apr_status_t) apr_brigade_puts(apr_bucket_brigade *bb,
813 apr_brigade_flush flush, void *ctx,
814 const char *str);
817 * This function writes a character into a bucket brigade.
818 * @param b The bucket brigade to add to
819 * @param flush The flush function to use if the brigade is full
820 * @param ctx The structure to pass to the flush function
821 * @param c The character to add
822 * @return APR_SUCCESS or error code
824 APU_DECLARE(apr_status_t) apr_brigade_putc(apr_bucket_brigade *b,
825 apr_brigade_flush flush, void *ctx,
826 const char c);
829 * This function writes an unspecified number of strings into a bucket brigade.
830 * @param b The bucket brigade to add to
831 * @param flush The flush function to use if the brigade is full
832 * @param ctx The structure to pass to the flush function
833 * @param ... The strings to add
834 * @return APR_SUCCESS or error code
836 APU_DECLARE_NONSTD(apr_status_t) apr_brigade_putstrs(apr_bucket_brigade *b,
837 apr_brigade_flush flush,
838 void *ctx, ...);
841 * Evaluate a printf and put the resulting string at the end
842 * of the bucket brigade.
843 * @param b The brigade to write to
844 * @param flush The flush function to use if the brigade is full
845 * @param ctx The structure to pass to the flush function
846 * @param fmt The format of the string to write
847 * @param ... The arguments to fill out the format
848 * @return APR_SUCCESS or error code
850 APU_DECLARE_NONSTD(apr_status_t) apr_brigade_printf(apr_bucket_brigade *b,
851 apr_brigade_flush flush,
852 void *ctx,
853 const char *fmt, ...)
854 __attribute__((format(printf,4,5)));
857 * Evaluate a printf and put the resulting string at the end
858 * of the bucket brigade.
859 * @param b The brigade to write to
860 * @param flush The flush function to use if the brigade is full
861 * @param ctx The structure to pass to the flush function
862 * @param fmt The format of the string to write
863 * @param va The arguments to fill out the format
864 * @return APR_SUCCESS or error code
866 APU_DECLARE(apr_status_t) apr_brigade_vprintf(apr_bucket_brigade *b,
867 apr_brigade_flush flush,
868 void *ctx,
869 const char *fmt, va_list va);
871 /* ***** Bucket freelist functions ***** */
873 * Create a bucket allocator.
874 * @param p This pool's underlying apr_allocator_t is used to allocate memory
875 * for the bucket allocator. When the pool is destroyed, the bucket
876 * allocator's cleanup routine will free all memory that has been
877 * allocated from it.
878 * @remark The reason the allocator gets its memory from the pool's
879 * apr_allocator_t rather than from the pool itself is because
880 * the bucket allocator will free large memory blocks back to the
881 * allocator when it's done with them, thereby preventing memory
882 * footprint growth that would occur if we allocated from the pool.
883 * @warning The allocator must never be used by more than one thread at a time.
885 APU_DECLARE_NONSTD(apr_bucket_alloc_t *) apr_bucket_alloc_create(apr_pool_t *p);
888 * Create a bucket allocator.
889 * @param allocator This apr_allocator_t is used to allocate both the bucket
890 * allocator and all memory handed out by the bucket allocator. The
891 * caller is responsible for destroying the bucket allocator and the
892 * apr_allocator_t -- no automatic cleanups will happen.
893 * @warning The allocator must never be used by more than one thread at a time.
895 APU_DECLARE_NONSTD(apr_bucket_alloc_t *) apr_bucket_alloc_create_ex(apr_allocator_t *allocator);
898 * Destroy a bucket allocator.
899 * @param list The allocator to be destroyed
901 APU_DECLARE_NONSTD(void) apr_bucket_alloc_destroy(apr_bucket_alloc_t *list);
904 * Allocate memory for use by the buckets.
905 * @param size The amount to allocate.
906 * @param list The allocator from which to allocate the memory.
908 APU_DECLARE_NONSTD(void *) apr_bucket_alloc(apr_size_t size, apr_bucket_alloc_t *list);
911 * Free memory previously allocated with apr_bucket_alloc().
912 * @param block The block of memory to be freed.
914 APU_DECLARE_NONSTD(void) apr_bucket_free(void *block);
917 /* ***** Bucket Functions ***** */
919 * Free the resources used by a bucket. If multiple buckets refer to
920 * the same resource it is freed when the last one goes away.
921 * @see apr_bucket_delete()
922 * @param e The bucket to destroy
924 #define apr_bucket_destroy(e) do { \
925 (e)->type->destroy((e)->data); \
926 (e)->free(e); \
927 } while (0)
930 * Delete a bucket by removing it from its brigade (if any) and then
931 * destroying it.
932 * @remark This mainly acts as an aid in avoiding code verbosity. It is
933 * the preferred exact equivalent to:
934 * <pre>
935 * APR_BUCKET_REMOVE(e);
936 * apr_bucket_destroy(e);
937 * </pre>
938 * @param e The bucket to delete
940 #define apr_bucket_delete(e) do { \
941 APR_BUCKET_REMOVE(e); \
942 apr_bucket_destroy(e); \
943 } while (0)
946 * read the data from the bucket
947 * @param e The bucket to read from
948 * @param str The location to store the data in
949 * @param len The amount of data read
950 * @param block Whether the read function blocks
952 #define apr_bucket_read(e,str,len,block) (e)->type->read(e, str, len, block)
955 * Setaside data so that stack data is not destroyed on returning from
956 * the function
957 * @param e The bucket to setaside
958 * @param p The pool to setaside into
960 #define apr_bucket_setaside(e,p) (e)->type->setaside(e,p)
963 * Split one bucket in two.
964 * @param e The bucket to split
965 * @param point The offset to split the bucket at
967 #define apr_bucket_split(e,point) (e)->type->split(e, point)
970 * Copy a bucket.
971 * @param e The bucket to copy
972 * @param c Returns a pointer to the new bucket
974 #define apr_bucket_copy(e,c) (e)->type->copy(e, c)
976 /* Bucket type handling */
979 * This function simply returns APR_SUCCESS to denote that the bucket does
980 * not require anything to happen for its setaside() function. This is
981 * appropriate for buckets that have "immortal" data -- the data will live
982 * at least as long as the bucket.
983 * @param data The bucket to setaside
984 * @param pool The pool defining the desired lifetime of the bucket data
985 * @return APR_SUCCESS
987 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_setaside_noop(apr_bucket *data,
988 apr_pool_t *pool);
991 * A place holder function that signifies that the setaside function was not
992 * implemented for this bucket
993 * @param data The bucket to setaside
994 * @param pool The pool defining the desired lifetime of the bucket data
995 * @return APR_ENOTIMPL
997 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_setaside_notimpl(apr_bucket *data,
998 apr_pool_t *pool);
1001 * A place holder function that signifies that the split function was not
1002 * implemented for this bucket
1003 * @param data The bucket to split
1004 * @param point The location to split the bucket
1005 * @return APR_ENOTIMPL
1007 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_split_notimpl(apr_bucket *data,
1008 apr_size_t point);
1011 * A place holder function that signifies that the copy function was not
1012 * implemented for this bucket
1013 * @param e The bucket to copy
1014 * @param c Returns a pointer to the new bucket
1015 * @return APR_ENOTIMPL
1017 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_copy_notimpl(apr_bucket *e,
1018 apr_bucket **c);
1021 * A place holder function that signifies that this bucket does not need
1022 * to do anything special to be destroyed. That's only the case for buckets
1023 * that either have no data (metadata buckets) or buckets whose data pointer
1024 * points to something that's not a bucket-type-specific structure, as with
1025 * simple buckets where data points to a string and pipe buckets where data
1026 * points directly to the apr_file_t.
1027 * @param data The bucket data to destroy
1029 APU_DECLARE_NONSTD(void) apr_bucket_destroy_noop(void *data);
1032 * There is no apr_bucket_destroy_notimpl, because destruction is required
1033 * to be implemented (it could be a noop, but only if that makes sense for
1034 * the bucket type)
1037 /* There is no apr_bucket_read_notimpl, because it is a required function
1041 /* All of the bucket types implemented by the core */
1043 * The flush bucket type. This signifies that all data should be flushed to
1044 * the next filter. The flush bucket should be sent with the other buckets.
1046 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_flush;
1048 * The EOS bucket type. This signifies that there will be no more data, ever.
1049 * All filters MUST send all data to the next filter when they receive a
1050 * bucket of this type
1052 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_eos;
1054 * The FILE bucket type. This bucket represents a file on disk
1056 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_file;
1058 * The HEAP bucket type. This bucket represents a data allocated from the
1059 * heap.
1061 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_heap;
1062 #if APR_HAS_MMAP
1064 * The MMAP bucket type. This bucket represents an MMAP'ed file
1066 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_mmap;
1067 #endif
1069 * The POOL bucket type. This bucket represents a data that was allocated
1070 * from a pool. IF this bucket is still available when the pool is cleared,
1071 * the data is copied on to the heap.
1073 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_pool;
1075 * The PIPE bucket type. This bucket represents a pipe to another program.
1077 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_pipe;
1079 * The IMMORTAL bucket type. This bucket represents a segment of data that
1080 * the creator is willing to take responsibility for. The core will do
1081 * nothing with the data in an immortal bucket
1083 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_immortal;
1085 * The TRANSIENT bucket type. This bucket represents a data allocated off
1086 * the stack. When the setaside function is called, this data is copied on
1087 * to the heap
1089 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_transient;
1091 * The SOCKET bucket type. This bucket represents a socket to another machine
1093 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_socket;
1096 /* ***** Simple buckets ***** */
1099 * Split a simple bucket into two at the given point. Most non-reference
1100 * counting buckets that allow multiple references to the same block of
1101 * data (eg transient and immortal) will use this as their split function
1102 * without any additional type-specific handling.
1103 * @param b The bucket to be split
1104 * @param point The offset of the first byte in the new bucket
1105 * @return APR_EINVAL if the point is not within the bucket;
1106 * APR_ENOMEM if allocation failed;
1107 * or APR_SUCCESS
1109 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_simple_split(apr_bucket *b,
1110 apr_size_t point);
1113 * Copy a simple bucket. Most non-reference-counting buckets that allow
1114 * multiple references to the same block of data (eg transient and immortal)
1115 * will use this as their copy function without any additional type-specific
1116 * handling.
1117 * @param a The bucket to copy
1118 * @param b Returns a pointer to the new bucket
1119 * @return APR_ENOMEM if allocation failed;
1120 * or APR_SUCCESS
1122 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_simple_copy(apr_bucket *a,
1123 apr_bucket **b);
1126 /* ***** Shared, reference-counted buckets ***** */
1129 * Initialize a bucket containing reference-counted data that may be
1130 * shared. The caller must allocate the bucket if necessary and
1131 * initialize its type-dependent fields, and allocate and initialize
1132 * its own private data structure. This function should only be called
1133 * by type-specific bucket creation functions.
1134 * @param b The bucket to initialize
1135 * @param data A pointer to the private data structure
1136 * with the reference count at the start
1137 * @param start The start of the data in the bucket
1138 * relative to the private base pointer
1139 * @param length The length of the data in the bucket
1140 * @return The new bucket, or NULL if allocation failed
1142 APU_DECLARE(apr_bucket *) apr_bucket_shared_make(apr_bucket *b, void *data,
1143 apr_off_t start,
1144 apr_size_t length);
1147 * Decrement the refcount of the data in the bucket. This function
1148 * should only be called by type-specific bucket destruction functions.
1149 * @param data The private data pointer from the bucket to be destroyed
1150 * @return TRUE or FALSE; TRUE if the reference count is now
1151 * zero, indicating that the shared resource itself can
1152 * be destroyed by the caller.
1154 APU_DECLARE(int) apr_bucket_shared_destroy(void *data);
1157 * Split a bucket into two at the given point, and adjust the refcount
1158 * to the underlying data. Most reference-counting bucket types will
1159 * be able to use this function as their split function without any
1160 * additional type-specific handling.
1161 * @param b The bucket to be split
1162 * @param point The offset of the first byte in the new bucket
1163 * @return APR_EINVAL if the point is not within the bucket;
1164 * APR_ENOMEM if allocation failed;
1165 * or APR_SUCCESS
1167 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_split(apr_bucket *b,
1168 apr_size_t point);
1171 * Copy a refcounted bucket, incrementing the reference count. Most
1172 * reference-counting bucket types will be able to use this function
1173 * as their copy function without any additional type-specific handling.
1174 * @param a The bucket to copy
1175 * @param b Returns a pointer to the new bucket
1176 * @return APR_ENOMEM if allocation failed;
1177 or APR_SUCCESS
1179 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_copy(apr_bucket *a,
1180 apr_bucket **b);
1183 /* ***** Functions to Create Buckets of varying types ***** */
1185 * Each bucket type foo has two initialization functions:
1186 * apr_bucket_foo_make which sets up some already-allocated memory as a
1187 * bucket of type foo; and apr_bucket_foo_create which allocates memory
1188 * for the bucket, calls apr_bucket_make_foo, and initializes the
1189 * bucket's list pointers. The apr_bucket_foo_make functions are used
1190 * inside the bucket code to change the type of buckets in place;
1191 * other code should call apr_bucket_foo_create. All the initialization
1192 * functions change nothing if they fail.
1196 * Create an End of Stream bucket. This indicates that there is no more data
1197 * coming from down the filter stack. All filters should flush at this point.
1198 * @param list The freelist from which this bucket should be allocated
1199 * @return The new bucket, or NULL if allocation failed
1201 APU_DECLARE(apr_bucket *) apr_bucket_eos_create(apr_bucket_alloc_t *list);
1204 * Make the bucket passed in an EOS bucket. This indicates that there is no
1205 * more data coming from down the filter stack. All filters should flush at
1206 * this point.
1207 * @param b The bucket to make into an EOS bucket
1208 * @return The new bucket, or NULL if allocation failed
1210 APU_DECLARE(apr_bucket *) apr_bucket_eos_make(apr_bucket *b);
1213 * Create a flush bucket. This indicates that filters should flush their
1214 * data. There is no guarantee that they will flush it, but this is the
1215 * best we can do.
1216 * @param list The freelist from which this bucket should be allocated
1217 * @return The new bucket, or NULL if allocation failed
1219 APU_DECLARE(apr_bucket *) apr_bucket_flush_create(apr_bucket_alloc_t *list);
1222 * Make the bucket passed in a FLUSH bucket. This indicates that filters
1223 * should flush their data. There is no guarantee that they will flush it,
1224 * but this is the best we can do.
1225 * @param b The bucket to make into a FLUSH bucket
1226 * @return The new bucket, or NULL if allocation failed
1228 APU_DECLARE(apr_bucket *) apr_bucket_flush_make(apr_bucket *b);
1231 * Create a bucket referring to long-lived data.
1232 * @param buf The data to insert into the bucket
1233 * @param nbyte The size of the data to insert.
1234 * @param list The freelist from which this bucket should be allocated
1235 * @return The new bucket, or NULL if allocation failed
1237 APU_DECLARE(apr_bucket *) apr_bucket_immortal_create(const char *buf,
1238 apr_size_t nbyte,
1239 apr_bucket_alloc_t *list);
1242 * Make the bucket passed in a bucket refer to long-lived data
1243 * @param b The bucket to make into a IMMORTAL bucket
1244 * @param buf The data to insert into the bucket
1245 * @param nbyte The size of the data to insert.
1246 * @return The new bucket, or NULL if allocation failed
1248 APU_DECLARE(apr_bucket *) apr_bucket_immortal_make(apr_bucket *b,
1249 const char *buf,
1250 apr_size_t nbyte);
1253 * Create a bucket referring to data on the stack.
1254 * @param buf The data to insert into the bucket
1255 * @param nbyte The size of the data to insert.
1256 * @param list The freelist from which this bucket should be allocated
1257 * @return The new bucket, or NULL if allocation failed
1259 APU_DECLARE(apr_bucket *) apr_bucket_transient_create(const char *buf,
1260 apr_size_t nbyte,
1261 apr_bucket_alloc_t *list);
1264 * Make the bucket passed in a bucket refer to stack data
1265 * @param b The bucket to make into a TRANSIENT bucket
1266 * @param buf The data to insert into the bucket
1267 * @param nbyte The size of the data to insert.
1268 * @return The new bucket, or NULL if allocation failed
1270 APU_DECLARE(apr_bucket *) apr_bucket_transient_make(apr_bucket *b,
1271 const char *buf,
1272 apr_size_t nbyte);
1275 * Create a bucket referring to memory on the heap. If the caller asks
1276 * for the data to be copied, this function always allocates 4K of
1277 * memory so that more data can be added to the bucket without
1278 * requiring another allocation. Therefore not all the data may be put
1279 * into the bucket. If copying is not requested then the bucket takes
1280 * over responsibility for free()ing the memory.
1281 * @param buf The buffer to insert into the bucket
1282 * @param nbyte The size of the buffer to insert.
1283 * @param free_func Function to use to free the data; NULL indicates that the
1284 * bucket should make a copy of the data
1285 * @param list The freelist from which this bucket should be allocated
1286 * @return The new bucket, or NULL if allocation failed
1288 APU_DECLARE(apr_bucket *) apr_bucket_heap_create(const char *buf,
1289 apr_size_t nbyte,
1290 void (*free_func)(void *data),
1291 apr_bucket_alloc_t *list);
1293 * Make the bucket passed in a bucket refer to heap data
1294 * @param b The bucket to make into a HEAP bucket
1295 * @param buf The buffer to insert into the bucket
1296 * @param nbyte The size of the buffer to insert.
1297 * @param free_func Function to use to free the data; NULL indicates that the
1298 * bucket should make a copy of the data
1299 * @return The new bucket, or NULL if allocation failed
1301 APU_DECLARE(apr_bucket *) apr_bucket_heap_make(apr_bucket *b, const char *buf,
1302 apr_size_t nbyte,
1303 void (*free_func)(void *data));
1306 * Create a bucket referring to memory allocated from a pool.
1308 * @param buf The buffer to insert into the bucket
1309 * @param length The number of bytes referred to by this bucket
1310 * @param pool The pool the memory was allocated from
1311 * @param list The freelist from which this bucket should be allocated
1312 * @return The new bucket, or NULL if allocation failed
1314 APU_DECLARE(apr_bucket *) apr_bucket_pool_create(const char *buf,
1315 apr_size_t length,
1316 apr_pool_t *pool,
1317 apr_bucket_alloc_t *list);
1320 * Make the bucket passed in a bucket refer to pool data
1321 * @param b The bucket to make into a pool bucket
1322 * @param buf The buffer to insert into the bucket
1323 * @param length The number of bytes referred to by this bucket
1324 * @param pool The pool the memory was allocated from
1325 * @return The new bucket, or NULL if allocation failed
1327 APU_DECLARE(apr_bucket *) apr_bucket_pool_make(apr_bucket *b, const char *buf,
1328 apr_size_t length,
1329 apr_pool_t *pool);
1331 #if APR_HAS_MMAP
1333 * Create a bucket referring to mmap()ed memory.
1334 * @param mm The mmap to insert into the bucket
1335 * @param start The offset of the first byte in the mmap
1336 * that this bucket refers to
1337 * @param length The number of bytes referred to by this bucket
1338 * @param list The freelist from which this bucket should be allocated
1339 * @return The new bucket, or NULL if allocation failed
1341 APU_DECLARE(apr_bucket *) apr_bucket_mmap_create(apr_mmap_t *mm,
1342 apr_off_t start,
1343 apr_size_t length,
1344 apr_bucket_alloc_t *list);
1347 * Make the bucket passed in a bucket refer to an MMAP'ed file
1348 * @param b The bucket to make into a MMAP bucket
1349 * @param mm The mmap to insert into the bucket
1350 * @param start The offset of the first byte in the mmap
1351 * that this bucket refers to
1352 * @param length The number of bytes referred to by this bucket
1353 * @return The new bucket, or NULL if allocation failed
1355 APU_DECLARE(apr_bucket *) apr_bucket_mmap_make(apr_bucket *b, apr_mmap_t *mm,
1356 apr_off_t start,
1357 apr_size_t length);
1358 #endif
1361 * Create a bucket referring to a socket.
1362 * @param thissock The socket to put in the bucket
1363 * @param list The freelist from which this bucket should be allocated
1364 * @return The new bucket, or NULL if allocation failed
1366 APU_DECLARE(apr_bucket *) apr_bucket_socket_create(apr_socket_t *thissock,
1367 apr_bucket_alloc_t *list);
1369 * Make the bucket passed in a bucket refer to a socket
1370 * @param b The bucket to make into a SOCKET bucket
1371 * @param thissock The socket to put in the bucket
1372 * @return The new bucket, or NULL if allocation failed
1374 APU_DECLARE(apr_bucket *) apr_bucket_socket_make(apr_bucket *b,
1375 apr_socket_t *thissock);
1378 * Create a bucket referring to a pipe.
1379 * @param thispipe The pipe to put in the bucket
1380 * @param list The freelist from which this bucket should be allocated
1381 * @return The new bucket, or NULL if allocation failed
1383 APU_DECLARE(apr_bucket *) apr_bucket_pipe_create(apr_file_t *thispipe,
1384 apr_bucket_alloc_t *list);
1387 * Make the bucket passed in a bucket refer to a pipe
1388 * @param b The bucket to make into a PIPE bucket
1389 * @param thispipe The pipe to put in the bucket
1390 * @return The new bucket, or NULL if allocation failed
1392 APU_DECLARE(apr_bucket *) apr_bucket_pipe_make(apr_bucket *b,
1393 apr_file_t *thispipe);
1396 * Create a bucket referring to a file.
1397 * @param fd The file to put in the bucket
1398 * @param offset The offset where the data of interest begins in the file
1399 * @param len The amount of data in the file we are interested in
1400 * @param p The pool into which any needed structures should be created
1401 * while reading from this file bucket
1402 * @param list The freelist from which this bucket should be allocated
1403 * @return The new bucket, or NULL if allocation failed
1405 APU_DECLARE(apr_bucket *) apr_bucket_file_create(apr_file_t *fd,
1406 apr_off_t offset,
1407 apr_size_t len,
1408 apr_pool_t *p,
1409 apr_bucket_alloc_t *list);
1412 * Make the bucket passed in a bucket refer to a file
1413 * @param b The bucket to make into a FILE bucket
1414 * @param fd The file to put in the bucket
1415 * @param offset The offset where the data of interest begins in the file
1416 * @param len The amount of data in the file we are interested in
1417 * @param p The pool into which any needed structures should be created
1418 * while reading from this file bucket
1419 * @return The new bucket, or NULL if allocation failed
1421 APU_DECLARE(apr_bucket *) apr_bucket_file_make(apr_bucket *b, apr_file_t *fd,
1422 apr_off_t offset,
1423 apr_size_t len, apr_pool_t *p);
1426 * Enable or disable memory-mapping for a FILE bucket (default is enabled)
1427 * @param b The bucket
1428 * @param enabled Whether memory-mapping should be enabled
1429 * @return APR_SUCCESS normally, or an error code if the operation fails
1431 APU_DECLARE(apr_status_t) apr_bucket_file_enable_mmap(apr_bucket *b,
1432 int enabled);
1434 /** @} */
1435 #ifdef __cplusplus
1437 #endif
1439 #endif /* !APR_BUCKETS_H */