Apache HTTPD
apr_buckets.h
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. 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 */
21#ifndef APR_BUCKETS_H
22#define APR_BUCKETS_H
23
24#if defined(APR_BUCKET_DEBUG) && !defined(APR_RING_DEBUG)
25#define APR_RING_DEBUG
26#endif
27
28#include "apu.h"
29#include "apr_network_io.h"
30#include "apr_file_io.h"
31#include "apr_general.h"
32#include "apr_mmap.h"
33#include "apr_errno.h"
34#include "apr_ring.h"
35#include "apr.h"
36#if APR_HAVE_SYS_UIO_H
37#include <sys/uio.h> /* for struct iovec */
38#endif
39#if APR_HAVE_STDARG_H
40#include <stdarg.h>
41#endif
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
54#define APR_BUCKET_BUFF_SIZE 8000
55
61
114/*
115 * Forward declaration of the main types.
116 */
117
121typedef struct apr_bucket apr_bucket;
124
127
214
256
266 /*
267 * The apr_bucket_list structure doesn't actually need a name tag
268 * because it has no existence independent of struct apr_bucket_brigade;
269 * the ring macros are designed so that you can leave the name tag
270 * argument empty in this situation but apparently the Windows compiler
271 * doesn't like that.
272 */
276};
277
278
283
284/*
285 * define APR_BUCKET_DEBUG if you want your brigades to be checked for
286 * validity at every possible instant. this will slow your code down
287 * substantially but is a very useful debugging tool.
288 */
289#ifdef APR_BUCKET_DEBUG
290
291#define APR_BRIGADE_CHECK_CONSISTENCY(b) \
292 APR_RING_CHECK_CONSISTENCY(&(b)->list, apr_bucket, link)
293
294#define APR_BUCKET_CHECK_CONSISTENCY(e) \
295 APR_RING_CHECK_ELEM_CONSISTENCY((e), apr_bucket, link)
296
297#else
304#define APR_BRIGADE_CHECK_CONSISTENCY(b)
311#define APR_BUCKET_CHECK_CONSISTENCY(e)
312#endif
313
314
331#define APR_BRIGADE_SENTINEL(b) APR_RING_SENTINEL(&(b)->list, apr_bucket, link)
332
338#define APR_BRIGADE_EMPTY(b) APR_RING_EMPTY(&(b)->list, apr_bucket, link)
339
345#define APR_BRIGADE_FIRST(b) APR_RING_FIRST(&(b)->list)
351#define APR_BRIGADE_LAST(b) APR_RING_LAST(&(b)->list)
352
358#define APR_BRIGADE_INSERT_HEAD(b, e) do { \
359 apr_bucket *ap__b = (e); \
360 APR_RING_INSERT_HEAD(&(b)->list, ap__b, apr_bucket, link); \
361 APR_BRIGADE_CHECK_CONSISTENCY((b)); \
362 } while (0)
363
369#define APR_BRIGADE_INSERT_TAIL(b, e) do { \
370 apr_bucket *ap__b = (e); \
371 APR_RING_INSERT_TAIL(&(b)->list, ap__b, apr_bucket, link); \
372 APR_BRIGADE_CHECK_CONSISTENCY((b)); \
373 } while (0)
374
380#define APR_BRIGADE_CONCAT(a, b) do { \
381 APR_RING_CONCAT(&(a)->list, &(b)->list, apr_bucket, link); \
382 APR_BRIGADE_CHECK_CONSISTENCY((a)); \
383 } while (0)
384
390#define APR_BRIGADE_PREPEND(a, b) do { \
391 APR_RING_PREPEND(&(a)->list, &(b)->list, apr_bucket, link); \
392 APR_BRIGADE_CHECK_CONSISTENCY((a)); \
393 } while (0)
394
400#define APR_BUCKET_INSERT_BEFORE(a, b) do { \
401 apr_bucket *ap__a = (a), *ap__b = (b); \
402 APR_RING_INSERT_BEFORE(ap__a, ap__b, link); \
403 APR_BUCKET_CHECK_CONSISTENCY(ap__a); \
404 } while (0)
405
411#define APR_BUCKET_INSERT_AFTER(a, b) do { \
412 apr_bucket *ap__a = (a), *ap__b = (b); \
413 APR_RING_INSERT_AFTER(ap__a, ap__b, link); \
414 APR_BUCKET_CHECK_CONSISTENCY(ap__a); \
415 } while (0)
416
422#define APR_BUCKET_NEXT(e) APR_RING_NEXT((e), link)
428#define APR_BUCKET_PREV(e) APR_RING_PREV((e), link)
429
434#define APR_BUCKET_REMOVE(e) APR_RING_REMOVE((e), link)
435
440#define APR_BUCKET_INIT(e) APR_RING_ELEM_INIT((e), link)
441
448#define APR_BUCKET_IS_METADATA(e) ((e)->type->is_metadata)
449
455#define APR_BUCKET_IS_FLUSH(e) ((e)->type == &apr_bucket_type_flush)
461#define APR_BUCKET_IS_EOS(e) ((e)->type == &apr_bucket_type_eos)
467#define APR_BUCKET_IS_FILE(e) ((e)->type == &apr_bucket_type_file)
473#define APR_BUCKET_IS_PIPE(e) ((e)->type == &apr_bucket_type_pipe)
479#define APR_BUCKET_IS_SOCKET(e) ((e)->type == &apr_bucket_type_socket)
485#define APR_BUCKET_IS_HEAP(e) ((e)->type == &apr_bucket_type_heap)
491#define APR_BUCKET_IS_TRANSIENT(e) ((e)->type == &apr_bucket_type_transient)
497#define APR_BUCKET_IS_IMMORTAL(e) ((e)->type == &apr_bucket_type_immortal)
498#if APR_HAS_MMAP
504#define APR_BUCKET_IS_MMAP(e) ((e)->type == &apr_bucket_type_mmap)
505#endif
511#define APR_BUCKET_IS_POOL(e) ((e)->type == &apr_bucket_type_pool)
512
513/*
514 * General-purpose reference counting for the various bucket types.
515 *
516 * Any bucket type that keeps track of the resources it uses (i.e.
517 * most of them except for IMMORTAL, TRANSIENT, and EOS) needs to
518 * attach a reference count to the resource so that it can be freed
519 * when the last bucket that uses it goes away. Resource-sharing may
520 * occur because of bucket splits or buckets that refer to globally
521 * cached data. */
522
535
536/* ***** Reference-counted bucket types ***** */
537
555
592
593#if APR_HAS_MMAP
595typedef struct apr_bucket_mmap apr_bucket_mmap;
599struct apr_bucket_mmap {
601 apr_bucket_refcount refcount;
604};
605#endif
606
620#if APR_HAS_MMAP
623 int can_mmap;
624#endif /* APR_HAS_MMAP */
627};
628
644
650#define APR_BUCKET_ALLOC_SIZE APR_ALIGN_DEFAULT(2*sizeof(apr_bucket_structs))
651
652/* ***** Bucket Brigade Functions ***** */
662
669
682
701
714 apr_bucket *e);
715
731
743
752 char *c,
754
763 char **c,
766
779
790 struct iovec *vec, int *nvec);
791
802 void *ctx,
804
830 const char *str, apr_size_t nbyte);
831
843 void *ctx,
844 const struct iovec *vec,
846
857 const char *str);
858
869 const char c);
870
881 void *ctx, ...);
882
895 void *ctx,
896 const char *fmt, ...)
898
911 void *ctx,
912 const char *fmt, va_list va);
913
931
932
933
934/* ***** Bucket freelist functions ***** */
949
959
965
977
984
990
991
992/* ***** Bucket Functions ***** */
999#define apr_bucket_destroy(e) do { \
1000 apr_bucket *apr__d = (e); \
1001 apr__d->type->destroy(apr__d->data); \
1002 apr__d->free(apr__d); \
1003 } while (0)
1004
1016#define apr_bucket_delete(e) do { \
1017 apr_bucket *apr__b = (e); \
1018 APR_BUCKET_REMOVE(apr__b); \
1019 apr_bucket_destroy(apr__b); \
1020 } while (0)
1021
1089#define apr_bucket_read(e,str,len,block) (e)->type->read(e, str, len, block)
1090
1097#define apr_bucket_setaside(e,p) (e)->type->setaside(e,p)
1098
1109#define apr_bucket_split(e,point) (e)->type->split(e, point)
1110
1116#define apr_bucket_copy(e,c) (e)->type->copy(e, c)
1117
1118/* Bucket type handling */
1119
1130 apr_pool_t *pool);
1131
1140 apr_pool_t *pool);
1141
1151
1160 apr_bucket **c);
1161
1172
1179/* There is no apr_bucket_read_notimpl, because it is a required function
1180 */
1181
1182
1183/* All of the bucket types implemented by the core */
1204#if APR_HAS_MMAP
1209#endif
1236
1237
1238/* ***** Simple buckets ***** */
1239
1253
1266
1267
1268/* ***** Shared, reference-counted buckets ***** */
1269
1287
1297
1311
1322 apr_bucket **b);
1323
1324
1325/* ***** Functions to Create Buckets of varying types ***** */
1326/*
1327 * Each bucket type foo has two initialization functions:
1328 * apr_bucket_foo_make which sets up some already-allocated memory as a
1329 * bucket of type foo; and apr_bucket_foo_create which allocates memory
1330 * for the bucket, calls apr_bucket_make_foo, and initializes the
1331 * bucket's list pointers. The apr_bucket_foo_make functions are used
1332 * inside the bucket code to change the type of buckets in place;
1333 * other code should call apr_bucket_foo_create. All the initialization
1334 * functions change nothing if they fail.
1335 */
1336
1344
1353
1362
1371
1382
1391 const char *buf,
1393
1404
1413 const char *buf,
1415
1432 void (*free_func)(void *data),
1445 void (*free_func)(void *data));
1446
1460
1471 apr_pool_t *pool);
1472
1473#if APR_HAS_MMAP
1487
1500#endif
1501
1518
1527
1536
1555 apr_size_t len,
1556 apr_pool_t *p,
1558
1572
1581
1594
1596#ifdef __cplusplus
1597}
1598#endif
1599
1600#endif /* !APR_BUCKETS_H */
APR Error Codes.
APR File I/O Handling.
APR Miscellaneous library routines.
APR MMAP routines.
APR Network library.
APR Rings.
APU_DECLARE(void)
Computes SipHash-2-4, producing a 64bit (APR_SIPHASH_DSIZE) hash from a message and a 128bit (APR_SIP...
Definition apr_sha1.c:206
APU_DECLARE_DATA const apr_bucket_type_t apr_bucket_type_pipe
struct iovec * vec
int enabled
APU_DECLARE_DATA const apr_bucket_type_t apr_bucket_type_transient
apr_file_t * f
apr_bucket_brigade apr_read_type_e apr_off_t maxbytes
apr_brigade_flush flush
apr_off_t offset
APU_DECLARE_DATA const apr_bucket_type_t apr_bucket_type_socket
const char * buf
apr_brigade_flush void const char apr_size_t nbyte
APU_DECLARE_DATA const apr_bucket_type_t apr_bucket_type_eos
char apr_size_t * len
APU_DECLARE_DATA const apr_bucket_type_t apr_bucket_type_flush
apr_size_t size
apr_socket_t * thissock
apr_file_t apr_off_t apr_off_t apr_pool_t * p
apr_file_t apr_off_t start
void * data
apr_read_type_e
Definition apr_buckets.h:57
apr_bucket * e
apr_bucket ** b
int read_all
apr_brigade_flush void * ctx
apr_off_t point
APU_DECLARE_DATA const apr_bucket_type_t apr_bucket_type_pool
APU_DECLARE_NONSTD(void) apr_bucket_alloc_destroy(apr_bucket_alloc_t *list)
Definition apr_buckets.c:43
apr_size_t void(* free_func)(void *data)
apr_brigade_flush void const char * str
char * c
apr_brigade_flush void apr_brigade_flush void const char * fmt
APU_DECLARE_DATA const apr_bucket_type_t apr_bucket_type_file
apr_bucket apr_bucket_brigade * a
char apr_size_t apr_pool_t * pool
APU_DECLARE_DATA const apr_bucket_type_t apr_bucket_type_immortal
apr_file_t * thispipe
apr_off_t apr_bucket ** after_point
apr_bucket_brigade apr_read_type_e block
apr_file_t * fd
APU_DECLARE_DATA const apr_bucket_type_t apr_bucket_type_heap
int apr_off_t * length
apr_bucket_alloc_t * list
apr_bucket_brigade * bbIn
apr_status_t(* apr_brigade_flush)(apr_bucket_brigade *bb, void *ctx)
apr_brigade_flush void va_list va
struct iovec int * nvec
@ APR_BLOCK_READ
Definition apr_buckets.h:58
@ APR_NONBLOCK_READ
Definition apr_buckets.h:59
apr_size_t size
int apr_status_t
Definition apr_errno.h:44
const char * format
apr_abortfunc_t apr_allocator_t * allocator
Definition apr_pools.h:208
const char apr_status_t(*) apr_pool_t *poo __attribute__)((nonnull(2, 4)))
Definition apr_pools.h:567
#define APR_RING_ENTRY(elem)
Definition apr_ring.h:70
#define APR_RING_HEAD(head, elem)
Definition apr_ring.h:91
apr_bucket_alloc_t * bucket_alloc
struct apr_bucket_brigade::apr_bucket_list list
apr_pool_t * readpool
apr_size_t read_size
apr_file_t * fd
apr_bucket_refcount refcount
apr_bucket_refcount refcount
void(* free_func)(void *data)
apr_size_t alloc_len
apr_bucket_heap heap
apr_bucket_alloc_t * list
const char * base
apr_pool_t * pool
apr_status_t(* split)(apr_bucket *e, apr_size_t point)
apr_status_t(* copy)(apr_bucket *e, apr_bucket **c)
apr_status_t(* read)(apr_bucket *b, const char **str, apr_size_t *len, apr_read_type_e block)
enum apr_bucket_type_t::@65 is_metadata
const char * name
apr_status_t(* setaside)(apr_bucket *e, apr_pool_t *pool)
void(* destroy)(void *data)
apr_size_t length
void(* free)(void *e)
apr_off_t start
apr_bucket_alloc_t * list
void * data
const apr_bucket_type_t * type
struct apr_bucket::@66 link
apr_bucket_heap heap
apr_bucket_file file
apr_bucket_pool pool