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

« back to all changes in this revision

Viewing changes to xs/Apache/Access/Apache__Access.h

  • Committer: Bazaar Package Importer
  • Author(s): Andres Salomon
  • Date: 2004-02-13 22:22:35 UTC
  • Revision ID: james.westby@ubuntu.com-20040213222235-x0ggyscn50jvab2v
Tags: upstream-1.99.12
ImportĀ upstreamĀ versionĀ 1.99.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
static MP_INLINE SV *mpxs_ap_requires(pTHX_ request_rec *r)
 
2
{
 
3
    AV *av;
 
4
    HV *hv;
 
5
    register int x;
 
6
    const apr_array_header_t *reqs_arr = ap_requires(r);
 
7
    require_line *reqs;
 
8
 
 
9
    if (!reqs_arr) {
 
10
        return &PL_sv_undef;
 
11
    }
 
12
 
 
13
    reqs = (require_line *)reqs_arr->elts;
 
14
    av = newAV();
 
15
 
 
16
    for (x=0; x < reqs_arr->nelts; x++) {
 
17
        /* XXX should we do this or let PerlAuthzHandler? */
 
18
        if (! (reqs[x].method_mask & (1 << r->method_number))) {
 
19
            continue;
 
20
        }
 
21
 
 
22
        hv = newHV();
 
23
 
 
24
        hv_store(hv, "method_mask", 11, 
 
25
                 newSViv((IV)reqs[x].method_mask), 0);
 
26
 
 
27
        hv_store(hv, "requirement", 11, 
 
28
                 newSVpv(reqs[x].requirement,0), 0);
 
29
 
 
30
        av_push(av, newRV_noinc((SV*)hv));
 
31
    }
 
32
 
 
33
    return newRV_noinc((SV*)av); 
 
34
}
 
35
 
 
36
static MP_INLINE
 
37
void mpxs_ap_allow_methods(pTHX_ I32 items, SV **MARK, SV **SP)
 
38
{
 
39
    request_rec *r;
 
40
    SV *reset;
 
41
 
 
42
    mpxs_usage_va_2(r, reset, "$r->allow_methods(reset, ...)");
 
43
 
 
44
    if (SvIV(reset)) {
 
45
        ap_clear_method_list(r->allowed_methods);
 
46
    }
 
47
 
 
48
    while (MARK <= SP) {
 
49
        STRLEN n_a;
 
50
        char *method = SvPV(*MARK, n_a);
 
51
        ap_method_list_add(r->allowed_methods, method);
 
52
        MARK++;
 
53
    }
 
54
}
 
55
 
 
56
static MP_INLINE void mpxs_insert_auth_cfg(pTHX_ request_rec *r,
 
57
                                           char *directive,
 
58
                                           char *val)
 
59
{
 
60
    const char *errmsg;
 
61
    AV *config = newAV();
 
62
 
 
63
    av_push(config, Perl_newSVpvf(aTHX_ "%s %s", directive, val));
 
64
 
 
65
    errmsg =
 
66
        modperl_config_insert_request(aTHX_ r,
 
67
                                      newRV_noinc((SV*)config),
 
68
                                      r->filename, OR_AUTHCFG);
 
69
 
 
70
    if (errmsg) {
 
71
        Perl_warn(aTHX_ "Can't change %s to '%s'\n", directive, val);
 
72
    }
 
73
 
 
74
    SvREFCNT_dec((SV*)config);
 
75
}
 
76
 
 
77
static MP_INLINE
 
78
const char *mpxs_Apache__RequestRec_auth_type(pTHX_ request_rec *r,
 
79
                                              char *type)
 
80
{
 
81
    if (type) {
 
82
        mpxs_insert_auth_cfg(aTHX_ r, "AuthType", type);
 
83
    }
 
84
 
 
85
    return ap_auth_type(r);
 
86
}
 
87
 
 
88
static MP_INLINE
 
89
const char *mpxs_Apache__RequestRec_auth_name(pTHX_ request_rec *r,
 
90
                                              char *name)
 
91
{
 
92
    if (name) {
 
93
        mpxs_insert_auth_cfg(aTHX_ r, "AuthName", name);
 
94
    }
 
95
 
 
96
    return ap_auth_name(r);
 
97
}
 
98
 
 
99
static XS(MPXS_ap_get_basic_auth_pw)
 
100
{
 
101
    dXSARGS;
 
102
    request_rec *r;
 
103
    const char *sent_pw = NULL;
 
104
    int rc;
 
105
 
 
106
    mpxs_usage_items_1("r");
 
107
 
 
108
    mpxs_PPCODE({
 
109
        r = mp_xs_sv2_r(ST(0));
 
110
 
 
111
        /* Default auth-type to Basic */
 
112
        if (!ap_auth_type(r)) {
 
113
            mpxs_Apache__RequestRec_auth_type(aTHX_ r, "Basic");
 
114
        }
 
115
 
 
116
        rc = ap_get_basic_auth_pw(r, &sent_pw);
 
117
 
 
118
        EXTEND(SP, 2);
 
119
        PUSHs_mortal_iv(rc);
 
120
        if (rc == OK) {
 
121
            PUSHs_mortal_pv(sent_pw);
 
122
        }
 
123
        else {
 
124
            PUSHs(&PL_sv_undef);
 
125
        }
 
126
    });
 
127
}