00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00021 #ifndef APR_BUCKETS_H
00022 #define APR_BUCKETS_H
00023
00024 #if defined(APR_BUCKET_DEBUG) && !defined(APR_RING_DEBUG)
00025 #define APR_RING_DEBUG
00026 #endif
00027
00028 #include "apu.h"
00029 #include "apr_network_io.h"
00030 #include "apr_file_io.h"
00031 #include "apr_general.h"
00032 #include "apr_mmap.h"
00033 #include "apr_errno.h"
00034 #include "apr_ring.h"
00035 #include "apr.h"
00036 #if APR_HAVE_SYS_UIO_H
00037 #include <sys/uio.h>
00038 #endif
00039 #if APR_HAVE_STDARG_H
00040 #include <stdarg.h>
00041 #endif
00042
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046
00054 #define APR_BUCKET_BUFF_SIZE 8000
00055
00057 typedef enum {
00058 APR_BLOCK_READ,
00059 APR_NONBLOCK_READ
00060 } apr_read_type_e;
00061
00114
00115
00116
00117
00119 typedef struct apr_bucket_brigade apr_bucket_brigade;
00121 typedef struct apr_bucket apr_bucket;
00123 typedef struct apr_bucket_alloc_t apr_bucket_alloc_t;
00124
00126 typedef struct apr_bucket_type_t apr_bucket_type_t;
00127
00131 struct apr_bucket_type_t {
00135 const char *name;
00140 int num_func;
00151 enum {
00153 APR_BUCKET_DATA = 0,
00155 APR_BUCKET_METADATA = 1
00156 } is_metadata;
00164 void (*destroy)(void *data);
00165
00176 apr_status_t (*read)(apr_bucket *b, const char **str, apr_size_t *len,
00177 apr_read_type_e block);
00178
00192 apr_status_t (*setaside)(apr_bucket *e, apr_pool_t *pool);
00193
00203 apr_status_t (*split)(apr_bucket *e, apr_size_t point);
00204
00211 apr_status_t (*copy)(apr_bucket *e, apr_bucket **c);
00212
00213 };
00214
00224 struct apr_bucket {
00226 APR_RING_ENTRY(apr_bucket) link;
00228 const apr_bucket_type_t *type;
00234 apr_size_t length;
00242 apr_off_t start;
00244 void *data;
00252 void (*free)(void *e);
00254 apr_bucket_alloc_t *list;
00255 };
00256
00258 struct apr_bucket_brigade {
00264 apr_pool_t *p;
00266
00267
00268
00269
00270
00271
00272
00273 APR_RING_HEAD(apr_bucket_list, apr_bucket) list;
00275 apr_bucket_alloc_t *bucket_alloc;
00276 };
00277
00278
00282 typedef apr_status_t (*apr_brigade_flush)(apr_bucket_brigade *bb, void *ctx);
00283
00284
00285
00286
00287
00288
00289 #ifdef APR_BUCKET_DEBUG
00290
00291 #define APR_BRIGADE_CHECK_CONSISTENCY(b) \
00292 APR_RING_CHECK_CONSISTENCY(&(b)->list, apr_bucket, link)
00293
00294 #define APR_BUCKET_CHECK_CONSISTENCY(e) \
00295 APR_RING_CHECK_ELEM_CONSISTENCY((e), apr_bucket, link)
00296
00297 #else
00298
00304 #define APR_BRIGADE_CHECK_CONSISTENCY(b)
00305
00311 #define APR_BUCKET_CHECK_CONSISTENCY(e)
00312 #endif
00313
00314
00331 #define APR_BRIGADE_SENTINEL(b) APR_RING_SENTINEL(&(b)->list, apr_bucket, link)
00332
00338 #define APR_BRIGADE_EMPTY(b) APR_RING_EMPTY(&(b)->list, apr_bucket, link)
00339
00345 #define APR_BRIGADE_FIRST(b) APR_RING_FIRST(&(b)->list)
00346
00351 #define APR_BRIGADE_LAST(b) APR_RING_LAST(&(b)->list)
00352
00394 #define APR_BRIGADE_FOREACH(e, b) \
00395 APR_RING_FOREACH((e), &(b)->list, apr_bucket, link)
00396
00402 #define APR_BRIGADE_INSERT_HEAD(b, e) do { \
00403 apr_bucket *ap__b = (e); \
00404 APR_RING_INSERT_HEAD(&(b)->list, ap__b, apr_bucket, link); \
00405 APR_BRIGADE_CHECK_CONSISTENCY((b)); \
00406 } while (0)
00407
00413 #define APR_BRIGADE_INSERT_TAIL(b, e) do { \
00414 apr_bucket *ap__b = (e); \
00415 APR_RING_INSERT_TAIL(&(b)->list, ap__b, apr_bucket, link); \
00416 APR_BRIGADE_CHECK_CONSISTENCY((b)); \
00417 } while (0)
00418
00424 #define APR_BRIGADE_CONCAT(a, b) do { \
00425 APR_RING_CONCAT(&(a)->list, &(b)->list, apr_bucket, link); \
00426 APR_BRIGADE_CHECK_CONSISTENCY((a)); \
00427 } while (0)
00428
00434 #define APR_BRIGADE_PREPEND(a, b) do { \
00435 APR_RING_PREPEND(&(a)->list, &(b)->list, apr_bucket, link); \
00436 APR_BRIGADE_CHECK_CONSISTENCY((a)); \
00437 } while (0)
00438
00444 #define APR_BUCKET_INSERT_BEFORE(a, b) do { \
00445 apr_bucket *ap__a = (a), *ap__b = (b); \
00446 APR_RING_INSERT_BEFORE(ap__a, ap__b, link); \
00447 APR_BUCKET_CHECK_CONSISTENCY(ap__a); \
00448 } while (0)
00449
00455 #define APR_BUCKET_INSERT_AFTER(a, b) do { \
00456 apr_bucket *ap__a = (a), *ap__b = (b); \
00457 APR_RING_INSERT_AFTER(ap__a, ap__b, link); \
00458 APR_BUCKET_CHECK_CONSISTENCY(ap__a); \
00459 } while (0)
00460
00466 #define APR_BUCKET_NEXT(e) APR_RING_NEXT((e), link)
00467
00472 #define APR_BUCKET_PREV(e) APR_RING_PREV((e), link)
00473
00478 #define APR_BUCKET_REMOVE(e) APR_RING_REMOVE((e), link)
00479
00484 #define APR_BUCKET_INIT(e) APR_RING_ELEM_INIT((e), link)
00485
00492 #define APR_BUCKET_IS_METADATA(e) ((e)->type->is_metadata)
00493
00499 #define APR_BUCKET_IS_FLUSH(e) ((e)->type == &apr_bucket_type_flush)
00500
00505 #define APR_BUCKET_IS_EOS(e) ((e)->type == &apr_bucket_type_eos)
00506
00511 #define APR_BUCKET_IS_FILE(e) ((e)->type == &apr_bucket_type_file)
00512
00517 #define APR_BUCKET_IS_PIPE(e) ((e)->type == &apr_bucket_type_pipe)
00518
00523 #define APR_BUCKET_IS_SOCKET(e) ((e)->type == &apr_bucket_type_socket)
00524
00529 #define APR_BUCKET_IS_HEAP(e) ((e)->type == &apr_bucket_type_heap)
00530
00535 #define APR_BUCKET_IS_TRANSIENT(e) ((e)->type == &apr_bucket_type_transient)
00536
00541 #define APR_BUCKET_IS_IMMORTAL(e) ((e)->type == &apr_bucket_type_immortal)
00542 #if APR_HAS_MMAP
00543
00548 #define APR_BUCKET_IS_MMAP(e) ((e)->type == &apr_bucket_type_mmap)
00549 #endif
00550
00555 #define APR_BUCKET_IS_POOL(e) ((e)->type == &apr_bucket_type_pool)
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00568 typedef struct apr_bucket_refcount apr_bucket_refcount;
00575 struct apr_bucket_refcount {
00577 int refcount;
00578 };
00579
00580
00581
00583 typedef struct apr_bucket_heap apr_bucket_heap;
00587 struct apr_bucket_heap {
00589 apr_bucket_refcount refcount;
00593 char *base;
00595 apr_size_t alloc_len;
00597 void (*free_func)(void *data);
00598 };
00599
00601 typedef struct apr_bucket_pool apr_bucket_pool;
00605 struct apr_bucket_pool {
00617 apr_bucket_heap heap;
00623 const char *base;
00630 apr_pool_t *pool;
00634 apr_bucket_alloc_t *list;
00635 };
00636
00637 #if APR_HAS_MMAP
00638
00639 typedef struct apr_bucket_mmap apr_bucket_mmap;
00643 struct apr_bucket_mmap {
00645 apr_bucket_refcount refcount;
00647 apr_mmap_t *mmap;
00648 };
00649 #endif
00650
00652 typedef struct apr_bucket_file apr_bucket_file;
00656 struct apr_bucket_file {
00658 apr_bucket_refcount refcount;
00660 apr_file_t *fd;
00663 apr_pool_t *readpool;
00664 #if APR_HAS_MMAP
00665
00667 int can_mmap;
00668 #endif
00669 };
00670
00672 typedef union apr_bucket_structs apr_bucket_structs;
00677 union apr_bucket_structs {
00678 apr_bucket b;
00679 apr_bucket_heap heap;
00680 apr_bucket_pool pool;
00681 #if APR_HAS_MMAP
00682 apr_bucket_mmap mmap;
00683 #endif
00684 apr_bucket_file file;
00685 };
00686
00692 #define APR_BUCKET_ALLOC_SIZE APR_ALIGN_DEFAULT(2*sizeof(apr_bucket_structs))
00693
00694
00702 APU_DECLARE(apr_bucket_brigade *) apr_brigade_create(apr_pool_t *p,
00703 apr_bucket_alloc_t *list);
00704
00710 APU_DECLARE(apr_status_t) apr_brigade_destroy(apr_bucket_brigade *b);
00711
00723 APU_DECLARE(apr_status_t) apr_brigade_cleanup(void *data);
00724
00734 APU_DECLARE(apr_bucket_brigade *) apr_brigade_split(apr_bucket_brigade *b,
00735 apr_bucket *e);
00736
00745 APU_DECLARE(apr_status_t) apr_brigade_partition(apr_bucket_brigade *b,
00746 apr_off_t point,
00747 apr_bucket **after_point);
00748
00749 #if APR_NOT_DONE_YET
00750
00756 APU_DECLARE(void) apr_brigade_consume(apr_bucket_brigade *b,
00757 apr_off_t nbytes);
00758 #endif
00759
00767 APU_DECLARE(apr_status_t) apr_brigade_length(apr_bucket_brigade *bb,
00768 int read_all,
00769 apr_off_t *length);
00770
00778 APU_DECLARE(apr_status_t) apr_brigade_flatten(apr_bucket_brigade *bb,
00779 char *c,
00780 apr_size_t *len);
00781
00789 APU_DECLARE(apr_status_t) apr_brigade_pflatten(apr_bucket_brigade *bb,
00790 char **c,
00791 apr_size_t *len,
00792 apr_pool_t *pool);
00793
00802 APU_DECLARE(apr_status_t) apr_brigade_split_line(apr_bucket_brigade *bbOut,
00803 apr_bucket_brigade *bbIn,
00804 apr_read_type_e block,
00805 apr_off_t maxbytes);
00806
00816 APU_DECLARE(apr_status_t) apr_brigade_to_iovec(apr_bucket_brigade *b,
00817 struct iovec *vec, int *nvec);
00818
00827 APU_DECLARE(apr_status_t) apr_brigade_vputstrs(apr_bucket_brigade *b,
00828 apr_brigade_flush flush,
00829 void *ctx,
00830 va_list va);
00831
00841 APU_DECLARE(apr_status_t) apr_brigade_write(apr_bucket_brigade *b,
00842 apr_brigade_flush flush, void *ctx,
00843 const char *str, apr_size_t nbyte);
00844
00854 APU_DECLARE(apr_status_t) apr_brigade_writev(apr_bucket_brigade *b,
00855 apr_brigade_flush flush,
00856 void *ctx,
00857 const struct iovec *vec,
00858 apr_size_t nvec);
00859
00868 APU_DECLARE(apr_status_t) apr_brigade_puts(apr_bucket_brigade *bb,
00869 apr_brigade_flush flush, void *ctx,
00870 const char *str);
00871
00880 APU_DECLARE(apr_status_t) apr_brigade_putc(apr_bucket_brigade *b,
00881 apr_brigade_flush flush, void *ctx,
00882 const char c);
00883
00892 APU_DECLARE_NONSTD(apr_status_t) apr_brigade_putstrs(apr_bucket_brigade *b,
00893 apr_brigade_flush flush,
00894 void *ctx, ...);
00895
00906 APU_DECLARE_NONSTD(apr_status_t) apr_brigade_printf(apr_bucket_brigade *b,
00907 apr_brigade_flush flush,
00908 void *ctx,
00909 const char *fmt, ...)
00910 __attribute__((format(printf,4,5)));
00911
00922 APU_DECLARE(apr_status_t) apr_brigade_vprintf(apr_bucket_brigade *b,
00923 apr_brigade_flush flush,
00924 void *ctx,
00925 const char *fmt, va_list va);
00926
00927
00941 APU_DECLARE_NONSTD(apr_bucket_alloc_t *) apr_bucket_alloc_create(apr_pool_t *p);
00942
00951 APU_DECLARE_NONSTD(apr_bucket_alloc_t *) apr_bucket_alloc_create_ex(apr_allocator_t *allocator);
00952
00957 APU_DECLARE_NONSTD(void) apr_bucket_alloc_destroy(apr_bucket_alloc_t *list);
00958
00964 APU_DECLARE_NONSTD(void *) apr_bucket_alloc(apr_size_t size, apr_bucket_alloc_t *list);
00965
00970 APU_DECLARE_NONSTD(void) apr_bucket_free(void *block);
00971
00972
00973
00980 #define apr_bucket_destroy(e) do { \
00981 (e)->type->destroy((e)->data); \
00982 (e)->free(e); \
00983 } while (0)
00984
00996 #define apr_bucket_delete(e) do { \
00997 APR_BUCKET_REMOVE(e); \
00998 apr_bucket_destroy(e); \
00999 } while (0)
01000
01008 #define apr_bucket_read(e,str,len,block) (e)->type->read(e, str, len, block)
01009
01016 #define apr_bucket_setaside(e,p) (e)->type->setaside(e,p)
01017
01023 #define apr_bucket_split(e,point) (e)->type->split(e, point)
01024
01030 #define apr_bucket_copy(e,c) (e)->type->copy(e, c)
01031
01032
01033
01043 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_setaside_noop(apr_bucket *data,
01044 apr_pool_t *pool);
01045
01053 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_setaside_notimpl(apr_bucket *data,
01054 apr_pool_t *pool);
01055
01063 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_split_notimpl(apr_bucket *data,
01064 apr_size_t point);
01065
01073 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_copy_notimpl(apr_bucket *e,
01074 apr_bucket **c);
01075
01085 APU_DECLARE_NONSTD(void) apr_bucket_destroy_noop(void *data);
01086
01093
01094
01095
01096
01097
01102 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_flush;
01108 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_eos;
01112 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_file;
01117 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_heap;
01118 #if APR_HAS_MMAP
01119
01122 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_mmap;
01123 #endif
01124
01129 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_pool;
01133 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_pipe;
01139 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_immortal;
01145 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_transient;
01149 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_socket;
01150
01151
01152
01153
01165 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_simple_split(apr_bucket *b,
01166 apr_size_t point);
01167
01178 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_simple_copy(apr_bucket *a,
01179 apr_bucket **b);
01180
01181
01182
01183
01198 APU_DECLARE(apr_bucket *) apr_bucket_shared_make(apr_bucket *b, void *data,
01199 apr_off_t start,
01200 apr_size_t length);
01201
01210 APU_DECLARE(int) apr_bucket_shared_destroy(void *data);
01211
01223 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_split(apr_bucket *b,
01224 apr_size_t point);
01225
01235 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_copy(apr_bucket *a,
01236 apr_bucket **b);
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01257 APU_DECLARE(apr_bucket *) apr_bucket_eos_create(apr_bucket_alloc_t *list);
01258
01266 APU_DECLARE(apr_bucket *) apr_bucket_eos_make(apr_bucket *b);
01267
01275 APU_DECLARE(apr_bucket *) apr_bucket_flush_create(apr_bucket_alloc_t *list);
01276
01284 APU_DECLARE(apr_bucket *) apr_bucket_flush_make(apr_bucket *b);
01285
01293 APU_DECLARE(apr_bucket *) apr_bucket_immortal_create(const char *buf,
01294 apr_size_t nbyte,
01295 apr_bucket_alloc_t *list);
01296
01304 APU_DECLARE(apr_bucket *) apr_bucket_immortal_make(apr_bucket *b,
01305 const char *buf,
01306 apr_size_t nbyte);
01307
01315 APU_DECLARE(apr_bucket *) apr_bucket_transient_create(const char *buf,
01316 apr_size_t nbyte,
01317 apr_bucket_alloc_t *list);
01318
01326 APU_DECLARE(apr_bucket *) apr_bucket_transient_make(apr_bucket *b,
01327 const char *buf,
01328 apr_size_t nbyte);
01329
01344 APU_DECLARE(apr_bucket *) apr_bucket_heap_create(const char *buf,
01345 apr_size_t nbyte,
01346 void (*free_func)(void *data),
01347 apr_bucket_alloc_t *list);
01357 APU_DECLARE(apr_bucket *) apr_bucket_heap_make(apr_bucket *b, const char *buf,
01358 apr_size_t nbyte,
01359 void (*free_func)(void *data));
01360
01370 APU_DECLARE(apr_bucket *) apr_bucket_pool_create(const char *buf,
01371 apr_size_t length,
01372 apr_pool_t *pool,
01373 apr_bucket_alloc_t *list);
01374
01383 APU_DECLARE(apr_bucket *) apr_bucket_pool_make(apr_bucket *b, const char *buf,
01384 apr_size_t length,
01385 apr_pool_t *pool);
01386
01387 #if APR_HAS_MMAP
01388
01397 APU_DECLARE(apr_bucket *) apr_bucket_mmap_create(apr_mmap_t *mm,
01398 apr_off_t start,
01399 apr_size_t length,
01400 apr_bucket_alloc_t *list);
01401
01411 APU_DECLARE(apr_bucket *) apr_bucket_mmap_make(apr_bucket *b, apr_mmap_t *mm,
01412 apr_off_t start,
01413 apr_size_t length);
01414 #endif
01415
01422 APU_DECLARE(apr_bucket *) apr_bucket_socket_create(apr_socket_t *thissock,
01423 apr_bucket_alloc_t *list);
01430 APU_DECLARE(apr_bucket *) apr_bucket_socket_make(apr_bucket *b,
01431 apr_socket_t *thissock);
01432
01439 APU_DECLARE(apr_bucket *) apr_bucket_pipe_create(apr_file_t *thispipe,
01440 apr_bucket_alloc_t *list);
01441
01448 APU_DECLARE(apr_bucket *) apr_bucket_pipe_make(apr_bucket *b,
01449 apr_file_t *thispipe);
01450
01461 APU_DECLARE(apr_bucket *) apr_bucket_file_create(apr_file_t *fd,
01462 apr_off_t offset,
01463 apr_size_t len,
01464 apr_pool_t *p,
01465 apr_bucket_alloc_t *list);
01466
01477 APU_DECLARE(apr_bucket *) apr_bucket_file_make(apr_bucket *b, apr_file_t *fd,
01478 apr_off_t offset,
01479 apr_size_t len, apr_pool_t *p);
01480
01487 APU_DECLARE(apr_status_t) apr_bucket_file_enable_mmap(apr_bucket *b,
01488 int enabled);
01489
01491 #ifdef __cplusplus
01492 }
01493 #endif
01494
01495 #endif