<commit_before>static MP_INLINE SV *mpxs_ap_requires(pTHX_ request_rec *r)
{
    AV *av;
    HV *hv;
    register int x;
    const apr_array_header_t *reqs_arr = ap_requires(r);
    require_line *reqs;

    if (!reqs_arr) {
        return &PL_sv_undef;
    }

    reqs = (require_line *)reqs_arr->elts;
    av = newAV();

    for (x=0; x < reqs_arr->nelts; x++) {
        /* XXX should we do this or let PerlAuthzHandler? */
        if (! (reqs[x].method_mask & (1 << r->method_number))) {
            continue;
        }

        hv = newHV();

        hv_store(hv, "method_mask", 11, 
                 newSViv((IV)reqs[x].method_mask), 0);

        hv_store(hv, "requirement", 11, 
                 newSVpv(reqs[x].requirement,0), 0);

        av_push(av, newRV_noinc((SV*)hv));
    }

    return newRV_noinc((SV*)av); 
}

static MP_INLINE
void mpxs_ap_allow_methods(pTHX_ I32 items, SV **MARK, SV **SP)
{
    request_rec *r;
    SV *reset;

    mpxs_usage_va_2(r, reset, "$r->allow_methods(reset, ...)");

    if (SvIV(reset)) {
        ap_clear_method_list(r->allowed_methods);
    }

    while (MARK <= SP) {
        STRLEN n_a;
        char *method = SvPV(*MARK, n_a);
        ap_method_list_add(r->allowed_methods, method);
        MARK++;
    }
}

static MP_INLINE void mpxs_insert_auth_cfg(pTHX_ request_rec *r,
                                           char *directive,
                                           char *val)
{
    const char *errmsg;
    AV *config = newAV();

    av_push(config, newSVpvf("%s %s", directive, val));

    errmsg =
        modperl_config_insert_request(aTHX_ r,
                                      newRV_noinc((SV*)config),
                                      r->filename, OR_AUTHCFG);

    if (errmsg) {
        Perl_warn(aTHX_ "Can't change %s to '%s'\n", directive, val);
    }

    SvREFCNT_dec((SV*)config);
}

static MP_INLINE
const char *mpxs_Apache__RequestRec_auth_type(pTHX_ request_rec *r,
                                              char *type)
{
    if (type) {
        mpxs_insert_auth_cfg(aTHX_ r, "AuthType", type);
    }

    return ap_auth_type(r);
}

static MP_INLINE
const char *mpxs_Apache__RequestRec_auth_name(pTHX_ request_rec *r,
                                              char *name)
{
    if (name) {
        mpxs_insert_auth_cfg(aTHX_ r, "AuthName", name);
    }

    return ap_auth_name(r);
}

static XS(MPXS_ap_get_basic_auth_pw)
{
    dXSARGS;
    request_rec *r;
    const char *sent_pw = NULL;
    int rc;

    mpxs_usage_items_1("r");

    mpxs_PPCODE({
        r = mp_xs_sv2_r(ST(0));

        /* Default auth-type to Basic */
        if (!ap_auth_type(r)) {
            mpxs_Apache__RequestRec_auth_type(aTHX_ r, "Basic");
        }

        rc = ap_get_basic_auth_pw(r, &sent_pw);

        EXTEND(SP, 2);
        PUSHs_mortal_iv(rc);
        if (rc == OK) {
            PUSHs_mortal_pv(sent_pw);
        }
        else {
            PUSHs(&PL_sv_undef);
        }
    });
}
<commit_msg>PR: Obtained from: Submitted by:	<NAME> <<EMAIL>> Reviewed by:	dougm s/newSVpvf/Perl_newSVpvf/ in mpxs_insert_auth_cfg<commit_after>static MP_INLINE SV *mpxs_ap_requires(pTHX_ request_rec *r)
{
    AV *av;
    HV *hv;
    register int x;
    const apr_array_header_t *reqs_arr = ap_requires(r);
    require_line *reqs;

    if (!reqs_arr) {
        return &PL_sv_undef;
    }

    reqs = (require_line *)reqs_arr->elts;
    av = newAV();

    for (x=0; x < reqs_arr->nelts; x++) {
        /* XXX should we do this or let PerlAuthzHandler? */
        if (! (reqs[x].method_mask & (1 << r->method_number))) {
            continue;
        }

        hv = newHV();

        hv_store(hv, "method_mask", 11, 
                 newSViv((IV)reqs[x].method_mask), 0);

        hv_store(hv, "requirement", 11, 
                 newSVpv(reqs[x].requirement,0), 0);

        av_push(av, newRV_noinc((SV*)hv));
    }

    return newRV_noinc((SV*)av); 
}

static MP_INLINE
void mpxs_ap_allow_methods(pTHX_ I32 items, SV **MARK, SV **SP)
{
    request_rec *r;
    SV *reset;

    mpxs_usage_va_2(r, reset, "$r->allow_methods(reset, ...)");

    if (SvIV(reset)) {
        ap_clear_method_list(r->allowed_methods);
    }

    while (MARK <= SP) {
        STRLEN n_a;
        char *method = SvPV(*MARK, n_a);
        ap_method_list_add(r->allowed_methods, method);
        MARK++;
    }
}

static MP_INLINE void mpxs_insert_auth_cfg(pTHX_ request_rec *r,
                                           char *directive,
                                           char *val)
{
    const char *errmsg;
    AV *config = newAV();

    av_push(config, Perl_newSVpvf(aTHX_ "%s %s", directive, val));

    errmsg =
        modperl_config_insert_request(aTHX_ r,
                                      newRV_noinc((SV*)config),
                                      r->filename, OR_AUTHCFG);

    if (errmsg) {
        Perl_warn(aTHX_ "Can't change %s to '%s'\n", directive, val);
    }

    SvREFCNT_dec((SV*)config);
}

static MP_INLINE
const char *mpxs_Apache__RequestRec_auth_type(pTHX_ request_rec *r,
                                              char *type)
{
    if (type) {
        mpxs_insert_auth_cfg(aTHX_ r, "AuthType", type);
    }

    return ap_auth_type(r);
}

static MP_INLINE
const char *mpxs_Apache__RequestRec_auth_name(pTHX_ request_rec *r,
                                              char *name)
{
    if (name) {
        mpxs_insert_auth_cfg(aTHX_ r, "AuthName", name);
    }

    return ap_auth_name(r);
}

static XS(MPXS_ap_get_basic_auth_pw)
{
    dXSARGS;
    request_rec *r;
    const char *sent_pw = NULL;
    int rc;

    mpxs_usage_items_1("r");

    mpxs_PPCODE({
        r = mp_xs_sv2_r(ST(0));

        /* Default auth-type to Basic */
        if (!ap_auth_type(r)) {
            mpxs_Apache__RequestRec_auth_type(aTHX_ r, "Basic");
        }

        rc = ap_get_basic_auth_pw(r, &sent_pw);

        EXTEND(SP, 2);
        PUSHs_mortal_iv(rc);
        if (rc == OK) {
            PUSHs_mortal_pv(sent_pw);
        }
        else {
            PUSHs(&PL_sv_undef);
        }
    });
}

{'fraction_non_alphanumeric': 0.12413452027695351, 'fraction_numerical': 0.005275304978569074, 'mean_word_length': 1.9408628211342704, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4420360', 'n_tokens_mistral': 2309, 'n_tokens_neox': 2193, 'n_words': 417}