00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00020 #ifndef APR_BUCKETS_H
00021 #define APR_BUCKETS_H
00022
00023 #if defined(APR_BUCKET_DEBUG) && !defined(APR_RING_DEBUG)
00024 #define APR_RING_DEBUG
00025 #endif
00026
00027 #include "apu.h"
00028 #include "apr_network_io.h"
00029 #include "apr_file_io.h"
00030 #include "apr_general.h"
00031 #include "apr_mmap.h"
00032 #include "apr_errno.h"
00033 #include "apr_ring.h"
00034 #include "apr.h"
00035 #if APR_HAVE_SYS_UIO_H
00036 #include <sys/uio.h>
00037 #endif
00038 #if APR_HAVE_STDARG_H
00039 #include <stdarg.h>
00040 #endif
00041
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045
00053 #define APR_BUCKET_BUFF_SIZE 8000
00054
00056 typedef enum {
00057 APR_BLOCK_READ,
00058 APR_NONBLOCK_READ
00059 } apr_read_type_e;
00060
00113
00114
00115
00116
00118 typedef struct apr_bucket_brigade apr_bucket_brigade;
00120 typedef struct apr_bucket apr_bucket;
00122 typedef struct apr_bucket_alloc_t apr_bucket_alloc_t;
00123
00125 typedef struct apr_bucket_type_t apr_bucket_type_t;
00126
00130 struct apr_bucket_type_t {
00134 const char *name;
00139 int num_func;
00150 enum {
00152 APR_BUCKET_DATA = 0,
00154 APR_BUCKET_METADATA = 1
00155 } is_metadata;
00163 void (*destroy)(void *data);
00164
00175 apr_status_t (*read)(apr_bucket *b, const char **str, apr_size_t *len,
00176 apr_read_type_e block);
00177
00191 apr_status_t (*setaside)(apr_bucket *e, apr_pool_t *pool);
00192
00202 apr_status_t (*split)(apr_bucket *e, apr_size_t point);
00203
00210 apr_status_t (*copy)(apr_bucket *e, apr_bucket **c);
00211
00212 };
00213
00223 struct apr_bucket {
00225 APR_RING_ENTRY(apr_bucket) link;
00227 const apr_bucket_type_t *type;
00233 apr_size_t length;
00241 apr_off_t start;
00243 void *data;
00251 void (*free)(void *e);
00253 apr_bucket_alloc_t *list;
00254 };
00255
00257 struct apr_bucket_brigade {
00263 apr_pool_t *p;
00265
00266
00267
00268
00269
00270
00271
00272 APR_RING_HEAD(apr_bucket_list, apr_bucket) list;
00274 apr_bucket_alloc_t *bucket_alloc;
00275 };
00276
00277
00281 typedef apr_status_t (*apr_brigade_flush)(apr_bucket_brigade *bb, void *ctx);
00282
00283
00284
00285
00286
00287
00288 #ifdef APR_BUCKET_DEBUG
00289
00290 #define APR_BRIGADE_CHECK_CONSISTENCY(b) \
00291 APR_RING_CHECK_CONSISTENCY(&(b)->list, apr_bucket, link)
00292
00293 #define APR_BUCKET_CHECK_CONSISTENCY(e) \
00294 APR_RING_CHECK_ELEM_CONSISTENCY((e), apr_bucket, link)
00295
00296 #else
00303 #define APR_BRIGADE_CHECK_CONSISTENCY(b)
00310 #define APR_BUCKET_CHECK_CONSISTENCY(e)
00311 #endif
00312
00313
00330 #define APR_BRIGADE_SENTINEL(b) APR_RING_SENTINEL(&(b)->list, apr_bucket, link)
00331
00337 #define APR_BRIGADE_EMPTY(b) APR_RING_EMPTY(&(b)->list, apr_bucket, link)
00338
00344 #define APR_BRIGADE_FIRST(b) APR_RING_FIRST(&(b)->list)
00350 #define APR_BRIGADE_LAST(b) APR_RING_LAST(&(b)->list)
00351
00357 #define APR_BRIGADE_INSERT_HEAD(b, e) do { \
00358 apr_bucket *ap__b = (e); \
00359 APR_RING_INSERT_HEAD(&(b)->list, ap__b, apr_bucket, link); \
00360 APR_BRIGADE_CHECK_CONSISTENCY((b)); \
00361 } while (0)
00362
00368 #define APR_BRIGADE_INSERT_TAIL(b, e) do { \
00369 apr_bucket *ap__b = (e); \
00370 APR_RING_INSERT_TAIL(&(b)->list, ap__b, apr_bucket, link); \
00371 APR_BRIGADE_CHECK_CONSISTENCY((b)); \
00372 } while (0)
00373
00379 #define APR_BRIGADE_CONCAT(a, b) do { \
00380 APR_RING_CONCAT(&(a)->list, &(b)->list, apr_bucket, link); \
00381 APR_BRIGADE_CHECK_CONSISTENCY((a)); \
00382 } while (0)
00383
00389 #define APR_BRIGADE_PREPEND(a, b) do { \
00390 APR_RING_PREPEND(&(a)->list, &(b)->list, apr_bucket, link); \
00391 APR_BRIGADE_CHECK_CONSISTENCY((a)); \
00392 } while (0)
00393
00399 #define APR_BUCKET_INSERT_BEFORE(a, b) do { \
00400 apr_bucket *ap__a = (a), *ap__b = (b); \
00401 APR_RING_INSERT_BEFORE(ap__a, ap__b, link); \
00402 APR_BUCKET_CHECK_CONSISTENCY(ap__a); \
00403 } while (0)
00404
00410 #define APR_BUCKET_INSERT_AFTER(a, b) do { \
00411 apr_bucket *ap__a = (a), *ap__b = (b); \
00412 APR_RING_INSERT_AFTER(ap__a, ap__b, link); \
00413 APR_BUCKET_CHECK_CONSISTENCY(ap__a); \
00414 } while (0)
00415
00421 #define APR_BUCKET_NEXT(e) APR_RING_NEXT((e), link)
00422
00427 #define APR_BUCKET_PREV(e) APR_RING_PREV((e), link)
00428
00433 #define APR_BUCKET_REMOVE(e) APR_RING_REMOVE((e), link)
00434
00439 #define APR_BUCKET_INIT(e) APR_RING_ELEM_INIT((e), link)
00440
00447 #define APR_BUCKET_IS_METADATA(e) ((e)->type->is_metadata)
00448
00454 #define APR_BUCKET_IS_FLUSH(e) ((e)->type == &apr_bucket_type_flush)
00455
00460 #define APR_BUCKET_IS_EOS(e) ((e)->type == &apr_bucket_type_eos)
00461
00466 #define APR_BUCKET_IS_FILE(e) ((e)->type == &apr_bucket_type_file)
00467
00472 #define APR_BUCKET_IS_PIPE(e) ((e)->type == &apr_bucket_type_pipe)
00473
00478 #define APR_BUCKET_IS_SOCKET(e) ((e)->type == &apr_bucket_type_socket)
00479
00484 #define APR_BUCKET_IS_HEAP(e) ((e)->type == &apr_bucket_type_heap)
00485
00490 #define APR_BUCKET_IS_TRANSIENT(e) ((e)->type == &apr_bucket_type_transient)
00491
00496 #define APR_BUCKET_IS_IMMORTAL(e) ((e)->type == &apr_bucket_type_immortal)
00497 #if APR_HAS_MMAP
00498
00503 #define APR_BUCKET_IS_MMAP(e) ((e)->type == &apr_bucket_type_mmap)
00504 #endif
00505
00510 #define APR_BUCKET_IS_POOL(e) ((e)->type == &apr_bucket_type_pool)
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00523 typedef struct apr_bucket_refcount apr_bucket_refcount;
00530 struct apr_bucket_refcount {
00532 int refcount;
00533 };
00534
00535
00536
00538 typedef struct apr_bucket_heap apr_bucket_heap;
00542 struct apr_bucket_heap {
00544 apr_bucket_refcount refcount;
00548 char *base;
00550 apr_size_t alloc_len;
00552 void (*free_func)(void *data);
00553 };
00554
00556 typedef struct apr_bucket_pool apr_bucket_pool;
00560 struct apr_bucket_pool {
00572 apr_bucket_heap heap;
00578 const char *base;
00585 apr_pool_t *pool;
00589 apr_bucket_alloc_t *list;
00590 };
00591
00592 #if APR_HAS_MMAP
00593
00594 typedef struct apr_bucket_mmap apr_bucket_mmap;
00598 struct apr_bucket_mmap {
00600 apr_bucket_refcount refcount;
00602 apr_mmap_t *mmap;
00603 };
00604 #endif
00605
00607 typedef struct apr_bucket_file apr_bucket_file;
00611 struct apr_bucket_file {
00613 apr_bucket_refcount refcount;
00615 apr_file_t *fd;
00618 apr_pool_t *readpool;
00619 #if APR_HAS_MMAP
00620
00622 int can_mmap;
00623 #endif
00624 };
00625
00627 typedef union apr_bucket_structs apr_bucket_structs;
00632 union apr_bucket_structs {
00633 apr_bucket b;
00634 apr_bucket_heap heap;
00635 apr_bucket_pool pool;
00636 #if APR_HAS_MMAP
00637 apr_bucket_mmap mmap;
00638 #endif
00639 apr_bucket_file file;
00640 };
00641
00647 #define APR_BUCKET_ALLOC_SIZE APR_ALIGN_DEFAULT(2*sizeof(apr_bucket_structs))
00648
00649
00657 APU_DECLARE(apr_bucket_brigade *) apr_brigade_create(apr_pool_t *p,
00658 apr_bucket_alloc_t *list);
00659
00665 APU_DECLARE(apr_status_t) apr_brigade_destroy(apr_bucket_brigade *b);
00666
00678 APU_DECLARE(apr_status_t) apr_brigade_cleanup(void *data);
00679
00689 APU_DECLARE(apr_bucket_brigade *) apr_brigade_split(apr_bucket_brigade *b,
00690 apr_bucket *e);
00691
00700 APU_DECLARE(apr_status_t) apr_brigade_partition(apr_bucket_brigade *b,
00701 apr_off_t point,
00702 apr_bucket **after_point);
00703
00711 APU_DECLARE(apr_status_t) apr_brigade_length(apr_bucket_brigade *bb,
00712 int read_all,
00713 apr_off_t *length);
00714
00722 APU_DECLARE(apr_status_t) apr_brigade_flatten(apr_bucket_brigade *bb,
00723 char *c,
00724 apr_size_t *len);
00725
00733 APU_DECLARE(apr_status_t) apr_brigade_pflatten(apr_bucket_brigade *bb,
00734 char **c,
00735 apr_size_t *len,
00736 apr_pool_t *pool);
00737
00746 APU_DECLARE(apr_status_t) apr_brigade_split_line(apr_bucket_brigade *bbOut,
00747 apr_bucket_brigade *bbIn,
00748 apr_read_type_e block,
00749 apr_off_t maxbytes);
00750
00760 APU_DECLARE(apr_status_t) apr_brigade_to_iovec(apr_bucket_brigade *b,
00761 struct iovec *vec, int *nvec);
00762
00771 APU_DECLARE(apr_status_t) apr_brigade_vputstrs(apr_bucket_brigade *b,
00772 apr_brigade_flush flush,
00773 void *ctx,
00774 va_list va);
00775
00785 APU_DECLARE(apr_status_t) apr_brigade_write(apr_bucket_brigade *b,
00786 apr_brigade_flush flush, void *ctx,
00787 const char *str, apr_size_t nbyte);
00788
00798 APU_DECLARE(apr_status_t) apr_brigade_writev(apr_bucket_brigade *b,
00799 apr_brigade_flush flush,
00800 void *ctx,
00801 const struct iovec *vec,
00802 apr_size_t nvec);
00803
00812 APU_DECLARE(apr_status_t) apr_brigade_puts(apr_bucket_brigade *bb,
00813 apr_brigade_flush flush, void *ctx,
00814 const char *str);
00815
00824 APU_DECLARE(apr_status_t) apr_brigade_putc(apr_bucket_brigade *b,
00825 apr_brigade_flush flush, void *ctx,
00826 const char c);
00827
00836 APU_DECLARE_NONSTD(apr_status_t) apr_brigade_putstrs(apr_bucket_brigade *b,
00837 apr_brigade_flush flush,
00838 void *ctx, ...);
00839
00850 APU_DECLARE_NONSTD(apr_status_t) apr_brigade_printf(apr_bucket_brigade *b,
00851 apr_brigade_flush flush,
00852 void *ctx,
00853 const char *fmt, ...)
00854 __attribute__((format(printf,4,5)));
00855
00866 APU_DECLARE(apr_status_t) apr_brigade_vprintf(apr_bucket_brigade *b,
00867 apr_brigade_flush flush,
00868 void *ctx,
00869 const char *fmt, va_list va);
00870
00883 APU_DECLARE(apr_bucket *) apr_brigade_insert_file(apr_bucket_brigade *bb,
00884 apr_file_t *f,
00885 apr_off_t start,
00886 apr_off_t len,
00887 apr_pool_t *p);
00888
00889
00890
00891
00905 APU_DECLARE_NONSTD(apr_bucket_alloc_t *) apr_bucket_alloc_create(apr_pool_t *p);
00906
00915 APU_DECLARE_NONSTD(apr_bucket_alloc_t *) apr_bucket_alloc_create_ex(apr_allocator_t *allocator);
00916
00921 APU_DECLARE_NONSTD(void) apr_bucket_alloc_destroy(apr_bucket_alloc_t *list);
00922
00928 APU_DECLARE_NONSTD(void *) apr_bucket_alloc(apr_size_t size, apr_bucket_alloc_t *list);
00929
00934 APU_DECLARE_NONSTD(void) apr_bucket_free(void *block);
00935
00936
00937
00944 #define apr_bucket_destroy(e) do { \
00945 (e)->type->destroy((e)->data); \
00946 (e)->free(e); \
00947 } while (0)
00948
00960 #define apr_bucket_delete(e) do { \
00961 APR_BUCKET_REMOVE(e); \
00962 apr_bucket_destroy(e); \
00963 } while (0)
00964
00972 #define apr_bucket_read(e,str,len,block) (e)->type->read(e, str, len, block)
00973
00980 #define apr_bucket_setaside(e,p) (e)->type->setaside(e,p)
00981
00987 #define apr_bucket_split(e,point) (e)->type->split(e, point)
00988
00994 #define apr_bucket_copy(e,c) (e)->type->copy(e, c)
00995
00996
00997
01007 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_setaside_noop(apr_bucket *data,
01008 apr_pool_t *pool);
01009
01017 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_setaside_notimpl(apr_bucket *data,
01018 apr_pool_t *pool);
01019
01027 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_split_notimpl(apr_bucket *data,
01028 apr_size_t point);
01029
01037 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_copy_notimpl(apr_bucket *e,
01038 apr_bucket **c);
01039
01049 APU_DECLARE_NONSTD(void) apr_bucket_destroy_noop(void *data);
01050
01057
01058
01059
01060
01061
01066 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_flush;
01072 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_eos;
01076 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_file;
01081 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_heap;
01082 #if APR_HAS_MMAP
01086 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_mmap;
01087 #endif
01093 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_pool;
01097 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_pipe;
01103 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_immortal;
01109 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_transient;
01113 APU_DECLARE_DATA extern const apr_bucket_type_t apr_bucket_type_socket;
01114
01115
01116
01117
01129 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_simple_split(apr_bucket *b,
01130 apr_size_t point);
01131
01142 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_simple_copy(apr_bucket *a,
01143 apr_bucket **b);
01144
01145
01146
01147
01162 APU_DECLARE(apr_bucket *) apr_bucket_shared_make(apr_bucket *b, void *data,
01163 apr_off_t start,
01164 apr_size_t length);
01165
01174 APU_DECLARE(int) apr_bucket_shared_destroy(void *data);
01175
01187 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_split(apr_bucket *b,
01188 apr_size_t point);
01189
01199 APU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_copy(apr_bucket *a,
01200 apr_bucket **b);
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01221 APU_DECLARE(apr_bucket *) apr_bucket_eos_create(apr_bucket_alloc_t *list);
01222
01230 APU_DECLARE(apr_bucket *) apr_bucket_eos_make(apr_bucket *b);
01231
01239 APU_DECLARE(apr_bucket *) apr_bucket_flush_create(apr_bucket_alloc_t *list);
01240
01248 APU_DECLARE(apr_bucket *) apr_bucket_flush_make(apr_bucket *b);
01249
01257 APU_DECLARE(apr_bucket *) apr_bucket_immortal_create(const char *buf,
01258 apr_size_t nbyte,
01259 apr_bucket_alloc_t *list);
01260
01268 APU_DECLARE(apr_bucket *) apr_bucket_immortal_make(apr_bucket *b,
01269 const char *buf,
01270 apr_size_t nbyte);
01271
01279 APU_DECLARE(apr_bucket *) apr_bucket_transient_create(const char *buf,
01280 apr_size_t nbyte,
01281 apr_bucket_alloc_t *list);
01282
01290 APU_DECLARE(apr_bucket *) apr_bucket_transient_make(apr_bucket *b,
01291 const char *buf,
01292 apr_size_t nbyte);
01293
01308 APU_DECLARE(apr_bucket *) apr_bucket_heap_create(const char *buf,
01309 apr_size_t nbyte,
01310 void (*free_func)(void *data),
01311 apr_bucket_alloc_t *list);
01321 APU_DECLARE(apr_bucket *) apr_bucket_heap_make(apr_bucket *b, const char *buf,
01322 apr_size_t nbyte,
01323 void (*free_func)(void *data));
01324
01334 APU_DECLARE(apr_bucket *) apr_bucket_pool_create(const char *buf,
01335 apr_size_t length,
01336 apr_pool_t *pool,
01337 apr_bucket_alloc_t *list);
01338
01347 APU_DECLARE(apr_bucket *) apr_bucket_pool_make(apr_bucket *b, const char *buf,
01348 apr_size_t length,
01349 apr_pool_t *pool);
01350
01351 #if APR_HAS_MMAP
01361 APU_DECLARE(apr_bucket *) apr_bucket_mmap_create(apr_mmap_t *mm,
01362 apr_off_t start,
01363 apr_size_t length,
01364 apr_bucket_alloc_t *list);
01365
01375 APU_DECLARE(apr_bucket *) apr_bucket_mmap_make(apr_bucket *b, apr_mmap_t *mm,
01376 apr_off_t start,
01377 apr_size_t length);
01378 #endif
01379
01386 APU_DECLARE(apr_bucket *) apr_bucket_socket_create(apr_socket_t *thissock,
01387 apr_bucket_alloc_t *list);
01394 APU_DECLARE(apr_bucket *) apr_bucket_socket_make(apr_bucket *b,
01395 apr_socket_t *thissock);
01396
01403 APU_DECLARE(apr_bucket *) apr_bucket_pipe_create(apr_file_t *thispipe,
01404 apr_bucket_alloc_t *list);
01405
01412 APU_DECLARE(apr_bucket *) apr_bucket_pipe_make(apr_bucket *b,
01413 apr_file_t *thispipe);
01414
01425 APU_DECLARE(apr_bucket *) apr_bucket_file_create(apr_file_t *fd,
01426 apr_off_t offset,
01427 apr_size_t len,
01428 apr_pool_t *p,
01429 apr_bucket_alloc_t *list);
01430
01441 APU_DECLARE(apr_bucket *) apr_bucket_file_make(apr_bucket *b, apr_file_t *fd,
01442 apr_off_t offset,
01443 apr_size_t len, apr_pool_t *p);
01444
01451 APU_DECLARE(apr_status_t) apr_bucket_file_enable_mmap(apr_bucket *b,
01452 int enabled);
01453
01455 #ifdef __cplusplus
01456 }
01457 #endif
01458
01459 #endif