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

« back to all changes in this revision

Viewing changes to xs/APR/Bucket/APR__Bucket.h

  • Committer: Bazaar Package Importer
  • Author(s): Andres Salomon
  • Date: 2005-08-12 01:40:38 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050812014038-gjigefs55pqx4qc8
Tags: 2.0.1-3
Grr.  Really include perl.conf file; it got lost due to diff not
wanting to add an empty file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright 2001-2004 The Apache Software Foundation
 
1
/* Copyright 2001-2005 The Apache Software Foundation
2
2
 *
3
3
 * Licensed under the Apache License, Version 2.0 (the "License");
4
4
 * you may not use this file except in compliance with the License.
15
15
 
16
16
#include "modperl_bucket.h"
17
17
 
18
 
static apr_bucket *mpxs_APR__Bucket_new(pTHX_ SV *classname, SV *sv,
19
 
                                        int offset, int len)
20
 
{
21
 
    if (!len) {
22
 
        (void)SvPV(sv, len);
23
 
    }
24
 
 
25
 
    return modperl_bucket_sv_create(aTHX_ sv, offset, len);
26
 
}
27
 
 
28
 
/* this is just so C::Scan will pickup the prototype */
29
 
static MP_INLINE apr_status_t modperl_bucket_read(apr_bucket *bucket,
30
 
                                                  const char **str,
31
 
                                                  apr_size_t *len,
32
 
                                                  apr_read_type_e block)
33
 
{
34
 
    return apr_bucket_read(bucket, str, len, block);
35
 
}
36
 
 
37
 
static MP_INLINE apr_status_t mpxs_modperl_bucket_read(pTHX_
38
 
                                                       apr_bucket *bucket,
39
 
                                                       SV *buffer,
40
 
                                                       apr_read_type_e block)
41
 
{
42
 
    int rc;
 
18
#define mpxs_APR__Bucket_delete  apr_bucket_delete
 
19
#define mpxs_APR__Bucket_destroy apr_bucket_destroy
 
20
 
 
21
static apr_bucket *mpxs_APR__Bucket_new(pTHX_  SV *classname, apr_bucket_alloc_t *list,
 
22
                                        SV *sv, apr_off_t offset, apr_size_t len)
 
23
{
 
24
 
 
25
    apr_size_t full_len;
 
26
 
 
27
    if (sv == Nullsv) {
 
28
        sv = newSV(0);
 
29
        (void)SvUPGRADE(sv, SVt_PV);
 
30
    }
 
31
 
 
32
    (void)SvPV(sv, full_len);
 
33
 
 
34
    if (len) {
 
35
        if (len > full_len - offset) {
 
36
            Perl_croak(aTHX_ "APR::Bucket::new: the length argument can't be"
 
37
                       " bigger than the total buffer length minus offset");
 
38
        }
 
39
    }
 
40
    else {
 
41
        len = full_len - offset;
 
42
    }
 
43
 
 
44
    return modperl_bucket_sv_create(aTHX_ list, sv, offset, len);
 
45
}
 
46
 
 
47
static MP_INLINE
 
48
apr_size_t mpxs_APR__Bucket_read(pTHX_
 
49
                                 apr_bucket *bucket,
 
50
                                 SV *buffer,
 
51
                                 apr_read_type_e block)
 
52
{
43
53
    apr_size_t len;
44
54
    const char *str;
45
 
 
46
 
    rc = modperl_bucket_read(bucket, &str, &len, block);
47
 
 
48
 
    if ((rc != APR_SUCCESS) && (rc != APR_EOF)) {
49
 
        /* XXX: croak ? */
50
 
    }
51
 
 
52
 
    sv_setpvn(buffer, str, len);
53
 
 
54
 
    return rc;
 
55
    apr_status_t rc = apr_bucket_read(bucket, &str, &len, block);
 
56
 
 
57
    if (!(rc == APR_SUCCESS || rc == APR_EOF)) {
 
58
        modperl_croak(aTHX_ rc, "APR::Bucket::read");
 
59
    }
 
60
 
 
61
    if (len) {
 
62
        sv_setpvn(buffer, str, len);
 
63
    }
 
64
    else {
 
65
        sv_setpvn(buffer, "", 0);
 
66
    }
 
67
 
 
68
    /* must run any set magic */
 
69
    SvSETMAGIC(buffer);
 
70
 
 
71
    SvTAINTED_on(buffer);
 
72
 
 
73
    return len;
55
74
}
56
75
 
57
76
static MP_INLINE int mpxs_APR__Bucket_is_eos(apr_bucket *bucket)
81
100
    APR_BUCKET_REMOVE(bucket);
82
101
}
83
102
 
 
103
static MP_INLINE
 
104
apr_status_t mpxs_APR__Bucket_setaside(pTHX_ SV *b_sv, SV *p_sv)
 
105
{
 
106
    apr_pool_t *p = mp_xs_sv2_APR__Pool(p_sv);
 
107
    apr_bucket *b = mp_xs_sv2_APR__Bucket(b_sv);
 
108
    apr_status_t rc = apr_bucket_setaside(b, p);
 
109
 
 
110
    /* if users don't bother to check the success, do it on their
 
111
     * behalf */
 
112
    if (GIMME_V == G_VOID && rc != APR_SUCCESS) {
 
113
        modperl_croak(aTHX_ rc, "APR::Bucket::setaside");
 
114
    }
 
115
 
 
116
    /* No need to call mpxs_add_pool_magic(b_sv, p_sv); since
 
117
     * pool_bucket_cleanup is called by apr_bucket_pool_make (called
 
118
     * by modperl_bucket_sv_setaside) if the pool goes out of scope,
 
119
     * copying the data to the heap.
 
120
     */
 
121
    
 
122
    return rc;
 
123
}