-: 0:Source:modperl_bucket.c -: 0:Object:modperl_bucket.bb -: 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: -: 16:#include "mod_perl.h" -: 17: -: 18:/* -: 19: * modperl_bucket_sv code derived from mod_snake's ModSnakePyBucket -: 20: * by Jon Travis -: 21: */ -: 22: -: 23:typedef struct { -: 24: apr_bucket_refcount refcount; -: 25: SV *sv; -: 26: PerlInterpreter *perl; -: 27:} modperl_bucket_sv_t; -: 28: -: 29:static apr_status_t -: 30:modperl_bucket_sv_read(apr_bucket *bucket, const char **str, -: 31: apr_size_t *len, apr_read_type_e block) 422: 32:{ 422: 33: modperl_bucket_sv_t *svbucket = 422: 34: (modperl_bucket_sv_t *)bucket->data; 422: 35: dTHXa(svbucket->perl); 422: 36: STRLEN n_a; 422: 37: char *pv = SvPV(svbucket->sv, n_a); -: 38: 422: 39: *str = pv + bucket->start; 422: 40: *len = bucket->length; -: 41: 422: 42: return APR_SUCCESS; -: 43:} -: 44: -: 45:static void modperl_bucket_sv_destroy(void *data) 75: 46:{ 75: 47: modperl_bucket_sv_t *svbucket = 75: 48: (modperl_bucket_sv_t *)data; 75: 49: dTHXa(svbucket->perl); -: 50: 75: 51: if (!apr_bucket_shared_destroy(svbucket)) { #####: 52: MP_TRACE_f(MP_FUNC, "bucket refcnt=%d\n", -: 53: ((apr_bucket_refcount *)svbucket)->refcount); #####: 54: return; -: 55: } -: 56: 75: 57: MP_TRACE_f(MP_FUNC, "sv=0x%lx, refcnt=%d\n", -: 58: (unsigned long)svbucket->sv, SvREFCNT(svbucket->sv)); -: 59: 75: 60: SvREFCNT_dec(svbucket->sv); -: 61: 75: 62: free(svbucket); -: 63:} -: 64: -: 65:static const apr_bucket_type_t modperl_bucket_sv_type = { -: 66: "mod_perl SV bucket", 4, -: 67:#if MODULE_MAGIC_NUMBER >= 20020602 -: 68: APR_BUCKET_DATA, -: 69:#endif -: 70: modperl_bucket_sv_destroy, -: 71: modperl_bucket_sv_read, -: 72: apr_bucket_setaside_notimpl, -: 73: apr_bucket_shared_split, -: 74: apr_bucket_shared_copy, -: 75:}; -: 76: -: 77:static apr_bucket *modperl_bucket_sv_make(pTHX_ -: 78: apr_bucket *bucket, -: 79: SV *sv, -: 80: int offset, int len) 81: 81:{ 81: 82: modperl_bucket_sv_t *svbucket; -: 83: 81: 84: svbucket = (modperl_bucket_sv_t *)malloc(sizeof(*svbucket)); -: 85: 81: 86: bucket = apr_bucket_shared_make(bucket, svbucket, offset, offset+len); -: 87: -: 88: /* XXX: need to deal with PerlInterpScope */ -: 89:#ifdef USE_ITHREADS 81: 90: svbucket->perl = aTHX; -: 91:#endif 81: 92: svbucket->sv = sv; -: 93: 81: 94: if (!bucket) { #####: 95: free(svbucket); #####: 96: return NULL; -: 97: } -: 98: 81: 99: (void)SvREFCNT_inc(svbucket->sv); -: 100: 81: 101: MP_TRACE_f(MP_FUNC, "sv=0x%lx, refcnt=%d\n", -: 102: (unsigned long)sv, SvREFCNT(sv)); -: 103: 81: 104: bucket->type = &modperl_bucket_sv_type; 81: 105: bucket->free = free; -: 106: 81: 107: return bucket; -: 108:} -: 109: -: 110:apr_bucket *modperl_bucket_sv_create(pTHX_ SV *sv, int offset, int len) 81: 111:{ 81: 112: apr_bucket *bucket; -: 113: 81: 114: bucket = (apr_bucket *)malloc(sizeof(*bucket)); 81: 115: APR_BUCKET_INIT(bucket); -: 116: 81: 117: return modperl_bucket_sv_make(aTHX_ bucket, sv, offset, len); -: 118:}