mod_perl

 view release on metacpan or  search on metacpan

xs/Apache2/Log/Apache2__Log.h  view on Meta::CPAN

/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

static void mpxs_Apache2__Log_BOOT(pTHX)
{
    av_push(get_av("Apache2::Log::Request::ISA", TRUE),
            newSVpv("Apache2::Log", 12));
    av_push(get_av("Apache2::Log::Server::ISA", TRUE),
            newSVpv("Apache2::Log", 12));
}

#define croak_inval_obj()                                       \
    Perl_croak(aTHX_ "Argument is not an Apache2::RequestRec "   \
               "or Apache2::ServerRec object")

static void mpxs_ap_log_error(pTHX_ int level, SV *sv, SV *msg)
{
    char *file = NULL;
    int line = 0;
    char *str;
    SV *svstr = (SV *)NULL;
    STRLEN n_a;
    int lmask = level & APLOG_LEVELMASK;
    server_rec *s;
    request_rec *r = NULL;

    if (SvROK(sv) && sv_isa(sv, "Apache2::Log::Request")) {
        r = INT2PTR(request_rec *, SvObjIV(sv));
        s = r->server;
    }
    else if (SvROK(sv) && sv_isa(sv, "Apache2::Log::Server")) {
        s = INT2PTR(server_rec *, SvObjIV(sv));
    }
    else {
        s = modperl_global_get_server_rec();
    }

    if ((lmask >= APLOG_DEBUG) && (mp_loglevel(s) >= APLOG_DEBUG)) {
        COP *cop = PL_curcop;
        file = CopFILE(cop); /* (caller)[1] */
        line = CopLINE(cop); /* (caller)[2] */
    }

    if ((mp_loglevel(s) >= lmask) &&
        SvROK(msg) && (SvTYPE(SvRV(msg)) == SVt_PVCV)) {
        dSP;
        ENTER;SAVETMPS;
        PUSHMARK(sp);
        (void)call_sv(msg, G_SCALAR);
        SPAGAIN;
        svstr = POPs;
        (void)SvREFCNT_inc(svstr);
        PUTBACK;
        FREETMPS;LEAVE;
        str = SvPV(svstr,n_a);
    }
    else {
        str = SvPV(msg,n_a);
    }

    if (r) {
        ap_log_rerror(file, line, mp_module_index_ level, 0, r,
		      "%s", str);
    }
    else {
        ap_log_error(file, line, mp_module_index_ level, 0, s,
		     "%s", str);
    }

    if (svstr) {
        SvREFCNT_dec(svstr);
    }
}

#define MP_LOG_REQUEST 1
#define MP_LOG_SERVER  2

static SV *mpxs_Apache2__Log_log(pTHX_ SV *sv, int logtype)
{
    SV *svretval;
    void *retval;
    char *pclass;

    switch (logtype) {
      case MP_LOG_REQUEST:
        pclass = "Apache2::Log::Request";
        retval = (void *)modperl_sv2request_rec(aTHX_ sv);
        break;
      case MP_LOG_SERVER:
        pclass = "Apache2::Log::Server";
        retval = (void *)modperl_sv2server_rec(aTHX_ sv);
        break;
      default:
        croak_inval_obj();
    };

    svretval = newSV(0);
    sv_setref_pv(svretval, pclass, (void*)retval);

    return svretval;
}



( run in 4.612 seconds using v1.01-cache-2.11-cpan-5e09290becf )