"Fossies" - the Fresh Open Source Software Archive

Member "mod_perl-2.0.11/xs/APR/Bucket/APR__Bucket.h" (5 Oct 2019, 3693 Bytes) of package /linux/www/apache_httpd_modules/mod_perl-2.0.11.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "APR__Bucket.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.0.8_vs_2.0.9.

    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 "modperl_bucket.h"
   18 
   19 #define mpxs_APR__Bucket_delete  apr_bucket_delete
   20 #define mpxs_APR__Bucket_destroy apr_bucket_destroy
   21 
   22 static apr_bucket *mpxs_APR__Bucket_new(pTHX_  SV *classname, apr_bucket_alloc_t *list,
   23                                         SV *sv, apr_off_t offset, apr_size_t len)
   24 {
   25 
   26     apr_size_t full_len;
   27 
   28     if (sv == (SV *)NULL) {
   29         sv = newSV(0);
   30         (void)SvUPGRADE(sv, SVt_PV);
   31     }
   32 
   33     (void)SvPV(sv, full_len);
   34 
   35     if (len) {
   36         if (len > full_len - offset) {
   37             Perl_croak(aTHX_ "APR::Bucket::new: the length argument can't be"
   38                        " bigger than the total buffer length minus offset");
   39         }
   40     }
   41     else {
   42         len = full_len - offset;
   43     }
   44 
   45     return modperl_bucket_sv_create(aTHX_ list, sv, offset, len);
   46 }
   47 
   48 static MP_INLINE
   49 apr_size_t mpxs_APR__Bucket_read(pTHX_
   50                                  apr_bucket *bucket,
   51                                  SV *buffer,
   52                                  apr_read_type_e block)
   53 {
   54     apr_size_t len;
   55     const char *str;
   56     apr_status_t rc = apr_bucket_read(bucket, &str, &len, block);
   57 
   58     if (!(rc == APR_SUCCESS || rc == APR_EOF)) {
   59         modperl_croak(aTHX_ rc, "APR::Bucket::read");
   60     }
   61 
   62     if (len) {
   63         sv_setpvn(buffer, str, len);
   64     }
   65     else {
   66         sv_setpvn(buffer, "", 0);
   67     }
   68 
   69     /* must run any set magic */
   70     SvSETMAGIC(buffer);
   71 
   72     SvTAINTED_on(buffer);
   73 
   74     return len;
   75 }
   76 
   77 static MP_INLINE int mpxs_APR__Bucket_is_eos(apr_bucket *bucket)
   78 {
   79     return APR_BUCKET_IS_EOS(bucket);
   80 }
   81 
   82 static MP_INLINE int mpxs_APR__Bucket_is_flush(apr_bucket *bucket)
   83 {
   84     return APR_BUCKET_IS_FLUSH(bucket);
   85 }
   86 
   87 static MP_INLINE void mpxs_APR__Bucket_insert_before(apr_bucket *a,
   88                                                      apr_bucket *b)
   89 {
   90     APR_BUCKET_INSERT_BEFORE(a, b);
   91 }
   92 
   93 static MP_INLINE void mpxs_APR__Bucket_insert_after(apr_bucket *a,
   94                                                     apr_bucket *b)
   95 {
   96     APR_BUCKET_INSERT_AFTER(a, b);
   97 }
   98 
   99 static MP_INLINE void mpxs_APR__Bucket_remove(apr_bucket *bucket)
  100 {
  101     APR_BUCKET_REMOVE(bucket);
  102 }
  103 
  104 static MP_INLINE
  105 apr_status_t mpxs_APR__Bucket_setaside(pTHX_ SV *b_sv, SV *p_sv)
  106 {
  107     apr_pool_t *p = mp_xs_sv2_APR__Pool(p_sv);
  108     apr_bucket *b = mp_xs_sv2_APR__Bucket(b_sv);
  109     apr_status_t rc = apr_bucket_setaside(b, p);
  110 
  111     /* if users don't bother to check the success, do it on their
  112      * behalf */
  113     if (GIMME_V == G_VOID && rc != APR_SUCCESS) {
  114         modperl_croak(aTHX_ rc, "APR::Bucket::setaside");
  115     }
  116 
  117     /* No need to call mpxs_add_pool_magic(b_sv, p_sv); since
  118      * pool_bucket_cleanup is called by apr_bucket_pool_make (called
  119      * by modperl_bucket_sv_setaside) if the pool goes out of scope,
  120      * copying the data to the heap.
  121      */
  122 
  123     return rc;
  124 }
  125 
  126 /*
  127  * Local Variables:
  128  * c-basic-offset: 4
  129  * indent-tabs-mode: nil
  130  * End:
  131  */