Apache HTTPD
apr_buckets_pool.c
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 */
16
17#include "apr_buckets.h"
18#define APR_WANT_MEMFUNC
19#include "apr_want.h"
20
22{
24
25 /*
26 * If the pool gets cleaned up, we have to copy the data out
27 * of the pool and onto the heap. But the apr_buckets out there
28 * that point to this pool bucket need to be notified such that
29 * they can morph themselves into a regular heap bucket the next
30 * time they try to read. To avoid having to manipulate
31 * reference counts and b->data pointers, the apr_bucket_pool
32 * actually _contains_ an apr_bucket_heap as its first element,
33 * so the two share their apr_bucket_refcount member, and you
34 * can typecast a pool bucket struct to make it look like a
35 * regular old heap bucket struct.
36 */
37 p->heap.base = apr_bucket_alloc(p->heap.alloc_len, p->list);
38 memcpy(p->heap.base, p->base, p->heap.alloc_len);
39 p->base = NULL;
40 p->pool = NULL;
41
42 return APR_SUCCESS;
43}
44
47{
48 apr_bucket_pool *p = b->data;
49 const char *base = p->base;
50
51 if (p->pool == NULL) {
52 /*
53 * pool has been cleaned up... masquerade as a heap bucket from now
54 * on. subsequent bucket operations will use the heap bucket code.
55 */
56 b->type = &apr_bucket_type_heap;
57 base = p->heap.base;
58 }
59 *str = base + b->start;
60 *len = b->length;
61 return APR_SUCCESS;
62}
63
64static void pool_bucket_destroy(void *data)
65{
67
68 /* If the pool is cleaned up before the last reference goes
69 * away, the data is really now on the heap; heap_destroy() takes
70 * over. free() in heap_destroy() thinks it's freeing
71 * an apr_bucket_heap, when in reality it's freeing the whole
72 * apr_bucket_pool for us.
73 */
74 if (p->pool) {
75 /* the shared resource is still in the pool
76 * because the pool has not been cleaned up yet
77 */
81 }
82 }
83 else {
84 /* the shared resource is no longer in the pool, it's
85 * on the heap, but this reference still thinks it's a pool
86 * bucket. we should just go ahead and pass control to
87 * heap_destroy() for it since it doesn't know any better.
88 */
90 }
91}
92
94 const char *buf, apr_size_t length, apr_pool_t *pool)
95{
97
98 p = apr_bucket_alloc(sizeof(*p), b->list);
99
100 /* XXX: we lose the const qualifier here which indicates
101 * there's something screwy with the API...
102 */
103 /* XXX: why is this? buf is const, p->base is const... what's
104 * the problem? --jcw */
105 p->base = (char *) buf;
106 p->pool = pool;
107 p->list = b->list;
108
110 b->type = &apr_bucket_type_pool;
111
112 /* pre-initialize heap bucket member */
113 p->heap.alloc_len = length;
114 p->heap.base = NULL;
115 p->heap.free_func = apr_bucket_free;
116
119 return b;
120}
121
126{
127 apr_bucket *b = apr_bucket_alloc(sizeof(*b), list);
128
130 b->free = apr_bucket_free;
131 b->list = list;
133}
134
136 "POOL", 5, APR_BUCKET_DATA,
139 apr_bucket_setaside_noop, /* don't need to setaside thanks to the cleanup*/
142};
const char apr_size_t len
Definition ap_regex.h:187
APR-UTIL Buckets/Bucket Brigades.
static apr_status_t pool_bucket_read(apr_bucket *b, const char **str, apr_size_t *len, apr_read_type_e block)
static void pool_bucket_destroy(void *data)
static apr_status_t pool_bucket_cleanup(void *data)
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
APR Standard Headers Support.
ap_conf_vector_t * base
const unsigned char * buf
Definition util_md5.h:50
#define APR_BUCKET_INIT(e)
apr_read_type_e
Definition apr_buckets.h:57
APU_DECLARE_DATA const apr_bucket_type_t apr_bucket_type_pool
APU_DECLARE_DATA const apr_bucket_type_t apr_bucket_type_heap
int apr_off_t * length
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
const apr_array_header_t * list
Definition apr_cstr.h:105
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
apr_pool_t * b
Definition apr_pools.h:529
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
void(* destroy)(void *data)
#define str