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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "apr_buckets.h"
19 APU_DECLARE_NONSTD(apr_status_t
) apr_bucket_simple_copy(apr_bucket
*a
,
22 *b
= apr_bucket_alloc(sizeof(**b
), a
->list
); /* XXX: check for failure? */
28 APU_DECLARE_NONSTD(apr_status_t
) apr_bucket_simple_split(apr_bucket
*a
,
33 if (point
> a
->length
) {
37 apr_bucket_simple_copy(a
, &b
);
43 APR_BUCKET_INSERT_AFTER(a
, b
);
48 static apr_status_t
simple_bucket_read(apr_bucket
*b
, const char **str
,
49 apr_size_t
*len
, apr_read_type_e block
)
51 *str
= (char *)b
->data
+ b
->start
;
56 APU_DECLARE(apr_bucket
*) apr_bucket_immortal_make(apr_bucket
*b
,
60 b
->data
= (char *)buf
;
63 b
->type
= &apr_bucket_type_immortal
;
68 APU_DECLARE(apr_bucket
*) apr_bucket_immortal_create(const char *buf
,
70 apr_bucket_alloc_t
*list
)
72 apr_bucket
*b
= apr_bucket_alloc(sizeof(*b
), list
);
75 b
->free
= apr_bucket_free
;
77 return apr_bucket_immortal_make(b
, buf
, length
);
81 * XXX: This function could do with some tweaking to reduce memory
82 * usage in various cases, e.g. share buffers in the heap between all
83 * the buckets that are set aside, or even spool set-aside data to
84 * disk if it gets too voluminous (but if it does then that's probably
85 * a bug elsewhere). There should probably be a apr_brigade_setaside()
86 * function that co-ordinates the action of all the bucket setaside
87 * functions to improve memory efficiency.
89 static apr_status_t
transient_bucket_setaside(apr_bucket
*b
, apr_pool_t
*pool
)
91 b
= apr_bucket_heap_make(b
, (char *)b
->data
+ b
->start
, b
->length
, NULL
);
98 APU_DECLARE(apr_bucket
*) apr_bucket_transient_make(apr_bucket
*b
,
102 b
->data
= (char *)buf
;
105 b
->type
= &apr_bucket_type_transient
;
109 APU_DECLARE(apr_bucket
*) apr_bucket_transient_create(const char *buf
,
111 apr_bucket_alloc_t
*list
)
113 apr_bucket
*b
= apr_bucket_alloc(sizeof(*b
), list
);
116 b
->free
= apr_bucket_free
;
118 return apr_bucket_transient_make(b
, buf
, length
);
121 const apr_bucket_type_t apr_bucket_type_immortal
= {
122 "IMMORTAL", 5, APR_BUCKET_DATA
,
123 apr_bucket_destroy_noop
,
125 apr_bucket_setaside_noop
,
126 apr_bucket_simple_split
,
127 apr_bucket_simple_copy
130 APU_DECLARE_DATA
const apr_bucket_type_t apr_bucket_type_transient
= {
131 "TRANSIENT", 5, APR_BUCKET_DATA
,
132 apr_bucket_destroy_noop
,
134 transient_bucket_setaside
,
135 apr_bucket_simple_split
,
136 apr_bucket_simple_copy