~ubuntu-branches/ubuntu/edgy/libapache2-mod-perl2/edgy

« back to all changes in this revision

Viewing changes to xs/APR/Brigade/APR__Brigade.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2004-08-19 06:23:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040819062348-jxl4koqbtvgm8v2t
Tags: 1.99.14-4
Remove the LFS CFLAGS, and build-dep against apache2-*-dev (>= 2.0.50-10)
as we're backing out of the apache2/apr ABI transition.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2001-2004 The Apache Software Foundation
 
2
 *
 
3
 * Licensed under the Apache License, Version 2.0 (the "License");
 
4
 * you may not use this file except in compliance with the License.
 
5
 * You may obtain a copy of the License at
 
6
 *
 
7
 *     http://www.apache.org/licenses/LICENSE-2.0
 
8
 *
 
9
 * Unless required by applicable law or agreed to in writing, software
 
10
 * distributed under the License is distributed on an "AS IS" BASIS,
 
11
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
12
 * See the License for the specific language governing permissions and
 
13
 * limitations under the License.
 
14
 */
 
15
 
1
16
static MP_INLINE
2
17
apr_bucket_brigade *mpxs_apr_brigade_create(pTHX_ SV *CLASS,
3
18
                                            apr_pool_t *p,
67
82
    return APR_BRIGADE_EMPTY(brigade);
68
83
}
69
84
 
 
85
static MP_INLINE
 
86
apr_pool_t *mpxs_APR__Brigade_pool(apr_bucket_brigade *brigade)
 
87
{
 
88
    /* eesh, it's r->pool, and c->pool, but bb->p 
 
89
     * let's make Perl consistent, otherwise this could be autogenerated
 
90
     */
 
91
 
 
92
    return brigade->p;
 
93
}
 
94
 
 
95
static MP_INLINE
 
96
SV *mpxs_APR__Brigade_length(pTHX_ apr_bucket_brigade *bb,
 
97
                             int read_all)
 
98
{
 
99
    apr_off_t length;
 
100
 
 
101
    apr_status_t rv = apr_brigade_length(bb, read_all, &length);
 
102
 
 
103
    /* XXX - we're deviating from the API here a bit in order to
 
104
     * make it more perlish - returning the length instead of
 
105
     * the return code.  maybe that's not such a good idea, though...
 
106
     */
 
107
    if (rv == APR_SUCCESS) {
 
108
        return newSViv((int)length);
 
109
    }
 
110
 
 
111
    return &PL_sv_undef;
 
112
}
 
113
 
 
114
#define mp_xs_sv2_bb mp_xs_sv2_APR__Brigade
 
115
 
 
116
static MP_INLINE
 
117
SV *mpxs_APR__Brigade_flatten(pTHX_ I32 items,
 
118
                              SV **MARK, SV **SP)
 
119
{
 
120
 
 
121
    apr_bucket_brigade *bb;
 
122
    apr_size_t length;
 
123
    apr_status_t status;
 
124
    SV *data;
 
125
 
 
126
    mpxs_usage_va_1(bb, "$bb->flatten([$length])");
 
127
 
 
128
    if (items > 1) {
 
129
        /* APR::Brigade->flatten($length); */
 
130
        length = SvIV(*MARK);
 
131
    }
 
132
    else {
 
133
        /* APR::Brigade->flatten(); */
 
134
        /* can't use pflatten, because we can't realloc() memory
 
135
         * allocated by pflatten. and we need to append '\0' to it in
 
136
         * SvPVX.  so we copy pflatten's guts here.
 
137
         */
 
138
        apr_off_t actual;
 
139
        apr_brigade_length(bb, 1, &actual);
 
140
        length = (apr_size_t)actual;
 
141
    }
 
142
 
 
143
    data = newSV(0);
 
144
    mpxs_sv_grow(data, length);
 
145
 
 
146
    status = apr_brigade_flatten(bb, SvPVX(data), &length);
 
147
    if (status != APR_SUCCESS) {
 
148
        /* XXX croak?
 
149
         * note that reading from an empty brigade will return
 
150
         * an empty string, not undef, so there is a difference
 
151
         */
 
152
        return &PL_sv_undef;
 
153
    }
 
154
 
 
155
    mpxs_sv_cur_set(data, length);
 
156
    SvTAINTED_on(data);
 
157
 
 
158
    return data;
 
159
}