1276630Skib/* Licensed to the Apache Software Foundation (ASF) under one or more
2276630Skib * contributor license agreements.  See the NOTICE file distributed with
3276630Skib * this work for additional information regarding copyright ownership.
4276630Skib * The ASF licenses this file to You under the Apache License, Version 2.0
5276630Skib * (the "License"); you may not use this file except in compliance with
6276630Skib * the License.  You may obtain a copy of the License at
7276630Skib *
8276630Skib *     http://www.apache.org/licenses/LICENSE-2.0
9276630Skib *
10276630Skib * Unless required by applicable law or agreed to in writing, software
11276630Skib * distributed under the License is distributed on an "AS IS" BASIS,
12276630Skib * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13276630Skib * See the License for the specific language governing permissions and
14276630Skib * limitations under the License.
15276630Skib */
16276630Skib
17276630Skib#include "apr_buckets.h"
18276630Skib
19276630SkibAPU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_split(apr_bucket *a,
20276630Skib                                                         apr_size_t point)
21276630Skib{
22276630Skib    apr_bucket_refcount *r = a->data;
23276630Skib    apr_status_t rv;
24276630Skib
25276630Skib    if ((rv = apr_bucket_simple_split(a, point)) != APR_SUCCESS) {
26276630Skib        return rv;
27276630Skib    }
28276630Skib    r->refcount++;
29276630Skib
30276630Skib    return APR_SUCCESS;
31276630Skib}
32276630Skib
33276630SkibAPU_DECLARE_NONSTD(apr_status_t) apr_bucket_shared_copy(apr_bucket *a,
34276630Skib                                                        apr_bucket **b)
35276630Skib{
36276630Skib    apr_bucket_refcount *r = a->data;
37276630Skib
38276630Skib    apr_bucket_simple_copy(a, b);
39276630Skib    r->refcount++;
40276630Skib
41276630Skib    return APR_SUCCESS;
42276630Skib}
43276630Skib
44276630SkibAPU_DECLARE(int) apr_bucket_shared_destroy(void *data)
45276630Skib{
46276630Skib    apr_bucket_refcount *r = data;
47276630Skib    r->refcount--;
48276630Skib    return (r->refcount == 0);
49276630Skib}
50276630Skib
51APU_DECLARE(apr_bucket *) apr_bucket_shared_make(apr_bucket *b, void *data,
52                                                 apr_off_t start,
53                                                 apr_size_t length)
54{
55    apr_bucket_refcount *r = data;
56
57    b->data   = r;
58    b->start  = start;
59    b->length = length;
60    /* caller initializes the type field */
61    r->refcount = 1;
62
63    return b;
64}
65