| 1 |
|
| /* punk_oamount.h - the `api` mount, in C. |
| 2 |
|
| * |
| 3 |
|
| * One `api` mount is an OpenAPI document compiled by Open::API and dispatched |
| 4 |
|
| * to controller methods named after its operationIds. The request half was |
| 5 |
|
| * already C (punk_dispatch.h, over Open::API's oa_abi table); this is the boot |
| 6 |
|
| * half - controller discovery, the security-requirements-to-guards compiler, |
| 7 |
|
| * the per-spec-prefix guards, and the operation table they all fold into. |
| 8 |
|
| * |
| 9 |
|
| * It is boot-time work, so the win is not speed: it is that the mount no |
| 10 |
|
| * longer straddles two languages. The generated security guards used to be |
| 11 |
|
| * Perl closures built by a Perl compiler and then called from the C |
| 12 |
|
| * dispatcher; now they are magic CVs (punk_static.h's closure pattern) |
| 13 |
|
| * carrying their alternatives, so the whole path from route to controller is |
| 14 |
|
| * C calling the checkers the application registered. |
| 15 |
|
| * |
| 16 |
|
| * Two things still cross into Perl at boot, because the ABI has no C form for |
| 17 |
|
| * them: $api->operations and $api->spec. Both are single calls per mount. |
| 18 |
|
| * |
| 19 |
|
| * Must be included after punk_context.h (pcx_call_meth), punk_dispatch.h |
| 20 |
|
| * (punk_oa, the oa_abi table) and punk_static.h (punk_closure). |
| 21 |
|
| */ |
| 22 |
|
| |
| 23 |
|
| #ifndef PUNK_OAMOUNT_H |
| 24 |
|
| #define PUNK_OAMOUNT_H |
| 25 |
|
| |
| 26 |
|
| /* The 401 body. Its Content-Length is taken from the string rather than |
| 27 |
|
| * written out beside it: the two had drifted, and a length two bytes short |
| 28 |
|
| * truncated the JSON on the wire - a parse error for every client refused. */ |
| 29 |
|
| #define POA_UNAUTHORIZED "{\"errors\":[{\"message\":\"unauthorized\"}]}" |
| 30 |
|
| |
| 31 |
217 |
| static HV *poa_hv(pTHX_ SV *self) { |
| 32 |
|
| /* |
| 33 |
|
| # uncoverable branch true |
| 34 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 35 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 36 |
217 |
▶ | if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
217 |
0 |
217 |
| if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
0 |
217 |
217 |
|
| 37 |
0 |
| croak("Punk::Mount::OpenAPI: not a mount object"); /* # uncoverable statement */ |
| 38 |
217 |
| return (HV *)SvRV(self); |
| 39 |
|
| } |
| 40 |
|
| |
| 41 |
1098 |
| static SV *poa_get(pTHX_ HV *h, const char *k) { |
| 42 |
1098 |
| SV **e = hv_fetch(h, k, (I32)strlen(k), 0); |
| 43 |
1098 |
▶ | return (e && *e) ? *e : NULL; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| return (e && *e) ? *e : NULL; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
847 |
251 |
1098 |
| return (e && *e) ? *e : NULL; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
847 |
0 |
847 |
|
| 44 |
|
| } |
| 45 |
|
| |
| 46 |
680 |
| static HV *poa_hash_of(pTHX_ SV *v) { |
| 47 |
|
| /* |
| 48 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 49 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 50 |
680 |
▶ | return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) ? (HV *)SvRV(v) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) ? (HV *)SvRV(v) : NULL; |
582 |
98 |
680 |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) ? (HV *)SvRV(v) : NULL; |
582 |
0 |
582 |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) ? (HV *)SvRV(v) : NULL; |
582 |
0 |
582 |
|
| 51 |
|
| } |
| 52 |
182 |
| static AV *poa_av_of(pTHX_ SV *v) { |
| 53 |
182 |
▶ | return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVAV) ? (AV *)SvRV(v) : NULL; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 3 branches
| Branch | True | False | Total |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVAV) ? (AV *)SvRV(v) : NULL; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
120 |
62 |
182 |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVAV) ? (AV *)SvRV(v) : NULL; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
120 |
0 |
120 |
| return (v && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVAV) ? (AV *)SvRV(v) : NULL; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
118 |
2 |
120 |
|
| 54 |
|
| } |
| 55 |
|
| |
| 56 |
|
| /* $resolve->($target, $what) - the boot-time target resolver Punk::App hands |
| 57 |
|
| * every subsystem. Returns the coderef (+1). */ |
| 58 |
52 |
| static SV *poa_resolve(pTHX_ SV *resolve, SV *target, const char *what) { |
| 59 |
52 |
| dSP; SV *r; int count; |
| 60 |
52 |
| ENTER; SAVETMPS; |
| 61 |
52 |
▶ | PUSHMARK(SP); EXTEND(SP, 2); |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHMARK(SP); EXTEND(SP, 2); |
0 |
52 |
52 |
| PUSHMARK(SP); EXTEND(SP, 2); |
0 |
52 |
52 |
|
| 62 |
52 |
| PUSHs(target); |
| 63 |
52 |
| mPUSHp(what, strlen(what)); |
| 64 |
52 |
| PUTBACK; |
| 65 |
52 |
| count = call_sv(resolve, G_SCALAR); |
| 66 |
52 |
| SPAGAIN; |
| 67 |
52 |
▶ | r = count > 0 ? SvREFCNT_inc(POPs) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| r = count > 0 ? SvREFCNT_inc(POPs) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
52 |
0 |
52 |
|
| 68 |
52 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
52 |
0 |
52 |
|
| 69 |
|
| /* |
| 70 |
|
| # uncoverable branch true |
| 71 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 72 |
52 |
▶ | if (!r) croak("Punk: %s did not resolve", what); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!r) croak("Punk: %s did not resolve", what); |
0 |
52 |
52 |
|
| 73 |
52 |
| return r; |
| 74 |
|
| } |
| 75 |
|
| |
| 76 |
|
| /* $code->(@args) in scalar context. No G_EVAL: a checker that dies should |
| 77 |
|
| * propagate to the guard chain's own eval, exactly as the Perl did. +1. */ |
| 78 |
25 |
| static SV *poa_call_args(pTHX_ SV *code, SV **argv, int n) { |
| 79 |
25 |
| dSP; SV *r; int count, i; |
| 80 |
25 |
| ENTER; SAVETMPS; |
| 81 |
25 |
▶ | PUSHMARK(SP); EXTEND(SP, n); |
Branch: 3 branches
| Branch | True | False | Total |
| PUSHMARK(SP); EXTEND(SP, n); |
0 |
25 |
25 |
| PUSHMARK(SP); EXTEND(SP, n); |
25 |
0 |
25 |
| PUSHMARK(SP); EXTEND(SP, n); |
0 |
25 |
25 |
|
| 82 |
125 |
▶ | for (i = 0; i < n; i++) PUSHs(argv[i]); |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) PUSHs(argv[i]); |
100 |
25 |
125 |
|
| 83 |
25 |
| PUTBACK; |
| 84 |
25 |
| count = call_sv(code, G_SCALAR); |
| 85 |
25 |
| SPAGAIN; |
| 86 |
25 |
▶ | r = count > 0 ? SvREFCNT_inc(POPs) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| r = count > 0 ? SvREFCNT_inc(POPs) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
25 |
0 |
25 |
|
| 87 |
25 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
25 |
0 |
25 |
|
| 88 |
25 |
| return r; |
| 89 |
|
| } |
| 90 |
|
| |
| 91 |
|
| /* ---- base64 (HTTP Basic credentials) -------------------------------------- |
| 92 |
|
| * Decode only, and standard alphabet: the url-safe spelling never appears in |
| 93 |
|
| * an Authorization header. Returns NULL when the input is not base64. */ |
| 94 |
4 |
| static SV *poa_b64_decode(pTHX_ const char *s, STRLEN len) { |
| 95 |
4 |
| SV *out = newSV(len + 1); |
| 96 |
|
| char *d; |
| 97 |
4 |
| unsigned v = 0; |
| 98 |
4 |
| int bits = 0; |
| 99 |
|
| STRLEN i; |
| 100 |
4 |
| SvPOK_on(out); |
| 101 |
4 |
| d = SvPVX(out); |
| 102 |
44 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
43 |
1 |
44 |
|
| 103 |
43 |
| char c = s[i]; |
| 104 |
|
| int x; |
| 105 |
43 |
▶ | if (c == '=') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (c == '=') { |
2 |
41 |
43 |
|
| 106 |
|
| /* padding ends the data: at most two, nothing after them, and |
| 107 |
|
| * the bits they pad must be zero - anything looser decodes two |
| 108 |
|
| * different headers to one credential */ |
| 109 |
2 |
| STRLEN pad = 0; |
| 110 |
6 |
▶ | while (i < len && s[i] == '=') { pad++; i++; } /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| while (i < len && s[i] == '=') { pad++; i++; } /* # uncoverable condition right count:2 class:ignore_covered_err */ |
4 |
2 |
6 |
| while (i < len && s[i] == '=') { pad++; i++; } /* # uncoverable condition right count:2 class:ignore_covered_err */ |
4 |
0 |
4 |
|
| 111 |
|
| /* |
| 112 |
|
| # uncoverable branch true |
| 113 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 114 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 115 |
|
| # uncoverable condition left count:3 class:ignore_covered_err |
| 116 |
|
| # uncoverable condition right count:3 class:ignore_covered_err |
| 117 |
|
| # uncoverable condition left count:4 class:ignore_covered_err */ |
| 118 |
2 |
▶ | if (i != len || pad > 2 || (bits && (v & ((1u << bits) - 1)))) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (i != len || pad > 2 || (bits && (v & ((1u << bits) - 1)))) { |
2 |
0 |
2 |
| if (i != len || pad > 2 || (bits && (v & ((1u << bits) - 1)))) { |
2 |
0 |
2 |
| if (i != len || pad > 2 || (bits && (v & ((1u << bits) - 1)))) { |
2 |
0 |
2 |
| if (i != len || pad > 2 || (bits && (v & ((1u << bits) - 1)))) { |
0 |
2 |
2 |
|
| 119 |
0 |
| SvREFCNT_dec(out); return NULL; /* # uncoverable statement */ |
| 120 |
|
| } |
| 121 |
2 |
| break; |
| 122 |
|
| } |
| 123 |
41 |
▶ | if (c >= 'A' && c <= 'Z') x = c - 'A'; |
Branch: 2 branches
| Branch | True | False | Total |
| if (c >= 'A' && c <= 'Z') x = c - 'A'; |
34 |
7 |
41 |
| if (c >= 'A' && c <= 'Z') x = c - 'A'; |
19 |
15 |
34 |
|
| 124 |
22 |
▶ | else if (c >= 'a' && c <= 'z') x = c - 'a' + 26; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| else if (c >= 'a' && c <= 'z') x = c - 'a' + 26; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
15 |
7 |
22 |
| else if (c >= 'a' && c <= 'z') x = c - 'a' + 26; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
15 |
0 |
15 |
|
| 125 |
7 |
▶ | else if (c >= '0' && c <= '9') x = c - '0' + 52; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| else if (c >= '0' && c <= '9') x = c - '0' + 52; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
6 |
1 |
7 |
| else if (c >= '0' && c <= '9') x = c - '0' + 52; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
6 |
0 |
6 |
|
| 126 |
|
| /* |
| 127 |
|
| # uncoverable branch true |
| 128 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 129 |
1 |
▶ | else if (c == '+') x = 62; |
Branch: 1 branch
| Branch | True | False | Total |
| else if (c == '+') x = 62; |
0 |
1 |
1 |
|
| 130 |
|
| /* |
| 131 |
|
| # uncoverable branch true |
| 132 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 133 |
1 |
▶ | else if (c == '/') x = 63; |
Branch: 1 branch
| Branch | True | False | Total |
| else if (c == '/') x = 63; |
0 |
1 |
1 |
|
| 134 |
1 |
| else { SvREFCNT_dec(out); return NULL; } |
| 135 |
40 |
| v = (v << 6) | (unsigned)x; |
| 136 |
40 |
| bits += 6; |
| 137 |
40 |
▶ | if (bits >= 8) { bits -= 8; *d++ = (char)((v >> bits) & 0xFF); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (bits >= 8) { bits -= 8; *d++ = (char)((v >> bits) & 0xFF); } |
29 |
11 |
40 |
|
| 138 |
|
| } |
| 139 |
3 |
| *d = '\0'; |
| 140 |
3 |
| SvCUR_set(out, (STRLEN)(d - SvPVX(out))); |
| 141 |
3 |
| return out; |
| 142 |
|
| } |
| 143 |
|
| |
| 144 |
|
| /* case-insensitive "<prefix> " at the front; returns the rest, or NULL. |
| 145 |
|
| * Mirrors /\A<prefix> (.+)\z/i - so the remainder must be non-empty and, since |
| 146 |
|
| * '.' does not match a newline, must not contain one. */ |
| 147 |
11 |
| static const char *poa_auth_param(const char *s, STRLEN len, |
| 148 |
|
| const char *word, STRLEN wlen, |
| 149 |
|
| STRLEN *out_len) { |
| 150 |
|
| STRLEN i; |
| 151 |
|
| /* |
| 152 |
|
| # uncoverable branch true |
| 153 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 154 |
11 |
▶ | if (len <= wlen + 1) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (len <= wlen + 1) return NULL; |
0 |
11 |
11 |
|
| 155 |
68 |
▶ | for (i = 0; i < wlen; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < wlen; i++) |
58 |
10 |
68 |
|
| 156 |
58 |
▶ | if (toLOWER((U8)s[i]) != toLOWER((U8)word[i])) return NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| if (toLOWER((U8)s[i]) != toLOWER((U8)word[i])) return NULL; |
10 |
48 |
58 |
| if (toLOWER((U8)s[i]) != toLOWER((U8)word[i])) return NULL; |
11 |
47 |
58 |
| if (toLOWER((U8)s[i]) != toLOWER((U8)word[i])) return NULL; |
1 |
57 |
58 |
|
| 157 |
|
| /* |
| 158 |
|
| # uncoverable branch true |
| 159 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 160 |
10 |
▶ | if (s[wlen] != ' ') return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (s[wlen] != ' ') return NULL; |
0 |
10 |
10 |
|
| 161 |
112 |
▶ | for (i = wlen + 1; i < len; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = wlen + 1; i < len; i++) |
102 |
10 |
112 |
|
| 162 |
|
| /* |
| 163 |
|
| # uncoverable branch true class:ignore_covered_err |
| 164 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 165 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 166 |
102 |
▶ | if (s[i] == '\n' || s[i] == '\r') return NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| if (s[i] == '\n' || s[i] == '\r') return NULL; |
102 |
0 |
102 |
| if (s[i] == '\n' || s[i] == '\r') return NULL; |
0 |
102 |
102 |
|
| 167 |
10 |
| *out_len = len - wlen - 1; |
| 168 |
10 |
| return s + wlen + 1; |
| 169 |
|
| } |
| 170 |
|
| |
| 171 |
|
| /* The credential a securityScheme describes, pulled off the request the way |
| 172 |
|
| * the scheme says to. Mortal, or NULL. */ |
| 173 |
35 |
| static SV *poa_credential(pTHX_ SV *c, HV *def) { |
| 174 |
35 |
| SV *type = poa_get(aTHX_ def, "type"); |
| 175 |
35 |
| SV *req = pcx_call_meth(aTHX_ c, "req", NULL, 0, 1); |
| 176 |
35 |
| SV *out = NULL; |
| 177 |
35 |
| STRLEN tl = 0; |
| 178 |
|
| /* |
| 179 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 180 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 181 |
70 |
▶ | const char *t = (type && SvOK(type)) ? SvPV_const(type, tl) : ""; |
Branch: 2 branches
| Branch | True | False | Total |
| const char *t = (type && SvOK(type)) ? SvPV_const(type, tl) : ""; |
35 |
0 |
35 |
| const char *t = (type && SvOK(type)) ? SvPV_const(type, tl) : ""; |
35 |
0 |
35 |
|
| 182 |
|
| |
| 183 |
|
| /* |
| 184 |
|
| # uncoverable branch true |
| 185 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 186 |
35 |
▶ | if (!req) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!req) return NULL; |
0 |
35 |
35 |
|
| 187 |
35 |
| sv_2mortal(req); |
| 188 |
|
| |
| 189 |
35 |
▶ | if (tl == 6 && memEQ(t, "apiKey", 6)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (tl == 6 && memEQ(t, "apiKey", 6)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
21 |
14 |
35 |
| if (tl == 6 && memEQ(t, "apiKey", 6)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
21 |
0 |
21 |
|
| 190 |
21 |
| SV *in = poa_get(aTHX_ def, "in"); |
| 191 |
21 |
| SV *name = poa_get(aTHX_ def, "name"); |
| 192 |
21 |
| STRLEN il = 0; |
| 193 |
|
| /* |
| 194 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 195 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 196 |
42 |
▶ | const char *ins = (in && SvOK(in)) ? SvPV_const(in, il) : "header"; |
Branch: 2 branches
| Branch | True | False | Total |
| const char *ins = (in && SvOK(in)) ? SvPV_const(in, il) : "header"; |
21 |
0 |
21 |
| const char *ins = (in && SvOK(in)) ? SvPV_const(in, il) : "header"; |
21 |
0 |
21 |
|
| 197 |
|
| /* |
| 198 |
|
| # uncoverable branch true |
| 199 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 200 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 201 |
21 |
▶ | if (!(in && SvOK(in))) il = 6; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(in && SvOK(in))) il = 6; |
21 |
0 |
21 |
| if (!(in && SvOK(in))) il = 6; |
0 |
21 |
21 |
|
| 202 |
|
| /* |
| 203 |
|
| # uncoverable branch true |
| 204 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 205 |
21 |
▶ | if (!name) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!name) return NULL; |
0 |
21 |
21 |
|
| 206 |
38 |
▶ | if (il == 6 && memEQ(ins, "header", 6)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (il == 6 && memEQ(ins, "header", 6)) { |
19 |
2 |
21 |
| if (il == 6 && memEQ(ins, "header", 6)) { |
17 |
2 |
19 |
|
| 207 |
17 |
| SV *argv[1]; argv[0] = name; |
| 208 |
17 |
| out = pcx_call_meth(aTHX_ req, "header", argv, 1, 1); |
| 209 |
|
| } |
| 210 |
6 |
▶ | else if (il == 5 && memEQ(ins, "query", 5)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| else if (il == 5 && memEQ(ins, "query", 5)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
2 |
2 |
4 |
| else if (il == 5 && memEQ(ins, "query", 5)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
2 |
0 |
2 |
|
| 211 |
2 |
| SV *q = pcx_call_meth(aTHX_ req, "query", NULL, 0, 1); |
| 212 |
2 |
| HV *qh = poa_hash_of(aTHX_ q); |
| 213 |
|
| /* |
| 214 |
|
| # uncoverable branch false |
| 215 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 216 |
2 |
▶ | if (qh) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (qh) { |
2 |
0 |
2 |
|
| 217 |
2 |
| HE *he = hv_fetch_ent(qh, name, 0, 0); |
| 218 |
|
| /* |
| 219 |
|
| # uncoverable branch false |
| 220 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 221 |
2 |
▶ | if (he) out = newSVsv(HeVAL(he)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (he) out = newSVsv(HeVAL(he)); |
2 |
0 |
2 |
|
| 222 |
|
| } |
| 223 |
|
| /* |
| 224 |
|
| # uncoverable branch false |
| 225 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 226 |
2 |
▶ | if (q) SvREFCNT_dec(q); |
Branch: 1 branch
| Branch | True | False | Total |
| if (q) SvREFCNT_dec(q); |
2 |
0 |
2 |
|
| 227 |
|
| } |
| 228 |
|
| /* |
| 229 |
|
| # uncoverable branch false |
| 230 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 231 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 232 |
2 |
▶ | else if (il == 6 && memEQ(ins, "cookie", 6)) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (il == 6 && memEQ(ins, "cookie", 6)) { |
2 |
0 |
2 |
| else if (il == 6 && memEQ(ins, "cookie", 6)) { |
2 |
0 |
2 |
|
| 233 |
2 |
| SV *argv[1]; argv[0] = name; |
| 234 |
2 |
| out = pcx_call_meth(aTHX_ req, "cookie", argv, 1, 1); |
| 235 |
|
| } |
| 236 |
21 |
▶ | return out ? sv_2mortal(out) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| return out ? sv_2mortal(out) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
21 |
0 |
21 |
|
| 237 |
|
| } |
| 238 |
|
| |
| 239 |
|
| { |
| 240 |
|
| SV *argv[1], *auth; |
| 241 |
|
| STRLEN al; |
| 242 |
|
| const char *as; |
| 243 |
14 |
| argv[0] = sv_2mortal(newSVpvs("authorization")); |
| 244 |
14 |
| auth = pcx_call_meth(aTHX_ req, "header", argv, 1, 1); |
| 245 |
14 |
▶ | if (!(auth && SvOK(auth))) { if (auth) SvREFCNT_dec(auth); return NULL; } /* # uncoverable condition left count:1 class:ignore_covered_err */ |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(auth && SvOK(auth))) { if (auth) SvREFCNT_dec(auth); return NULL; } /* # uncoverable condition left count:1 class:ignore_covered_err */ |
14 |
0 |
14 |
| if (!(auth && SvOK(auth))) { if (auth) SvREFCNT_dec(auth); return NULL; } /* # uncoverable condition left count:1 class:ignore_covered_err */ |
3 |
11 |
14 |
| if (!(auth && SvOK(auth))) { if (auth) SvREFCNT_dec(auth); return NULL; } /* # uncoverable condition left count:1 class:ignore_covered_err */ |
3 |
0 |
3 |
|
| 246 |
11 |
| sv_2mortal(auth); |
| 247 |
11 |
| as = SvPV_const(auth, al); |
| 248 |
|
| |
| 249 |
|
| /* |
| 250 |
|
| # uncoverable branch false |
| 251 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 252 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 253 |
11 |
▶ | if (tl == 4 && memEQ(t, "http", 4)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (tl == 4 && memEQ(t, "http", 4)) { |
11 |
0 |
11 |
| if (tl == 4 && memEQ(t, "http", 4)) { |
11 |
0 |
11 |
|
| 254 |
11 |
| SV *scheme = poa_get(aTHX_ def, "scheme"); |
| 255 |
11 |
| STRLEN sl = 0; |
| 256 |
11 |
▶ | const char *ss = (scheme && SvOK(scheme)) |
Branch: 1 branch
| Branch | True | False | Total |
| const char *ss = (scheme && SvOK(scheme)) |
11 |
0 |
11 |
|
| 257 |
22 |
▶ | ? SvPV_const(scheme, sl) : ""; |
Branch: 1 branch
| Branch | True | False | Total |
| ? SvPV_const(scheme, sl) : ""; |
11 |
0 |
11 |
|
| 258 |
11 |
▶ | if (sl == 5 && toLOWER((U8)ss[0]) == 'b' && toLOWER((U8)ss[1]) == 'a' |
Branch: 5 branches
| Branch | True | False | Total |
| if (sl == 5 && toLOWER((U8)ss[0]) == 'b' && toLOWER((U8)ss[1]) == 'a' |
5 |
6 |
11 |
| if (sl == 5 && toLOWER((U8)ss[0]) == 'b' && toLOWER((U8)ss[1]) == 'a' |
0 |
5 |
5 |
| if (sl == 5 && toLOWER((U8)ss[0]) == 'b' && toLOWER((U8)ss[1]) == 'a' |
5 |
0 |
5 |
| if (sl == 5 && toLOWER((U8)ss[0]) == 'b' && toLOWER((U8)ss[1]) == 'a' |
0 |
5 |
5 |
| if (sl == 5 && toLOWER((U8)ss[0]) == 'b' && toLOWER((U8)ss[1]) == 'a' |
5 |
0 |
5 |
|
| 259 |
5 |
▶ | && toLOWER((U8)ss[2]) == 's' && toLOWER((U8)ss[3]) == 'i' |
Branch: 4 branches
| Branch | True | False | Total |
| && toLOWER((U8)ss[2]) == 's' && toLOWER((U8)ss[3]) == 'i' |
0 |
5 |
5 |
| && toLOWER((U8)ss[2]) == 's' && toLOWER((U8)ss[3]) == 'i' |
5 |
0 |
5 |
| && toLOWER((U8)ss[2]) == 's' && toLOWER((U8)ss[3]) == 'i' |
0 |
5 |
5 |
| && toLOWER((U8)ss[2]) == 's' && toLOWER((U8)ss[3]) == 'i' |
5 |
0 |
5 |
|
| 260 |
5 |
▶ | && toLOWER((U8)ss[4]) == 'c') { |
Branch: 2 branches
| Branch | True | False | Total |
| && toLOWER((U8)ss[4]) == 'c') { |
0 |
5 |
5 |
| && toLOWER((U8)ss[4]) == 'c') { |
5 |
0 |
5 |
|
| 261 |
|
| STRLEN pl; |
| 262 |
5 |
| const char *p = poa_auth_param(as, al, "Basic", 5, &pl); |
| 263 |
5 |
▶ | if (!p) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p) return NULL; |
1 |
4 |
5 |
|
| 264 |
4 |
| out = poa_b64_decode(aTHX_ p, pl); |
| 265 |
4 |
▶ | return out ? sv_2mortal(out) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return out ? sv_2mortal(out) : NULL; |
3 |
1 |
4 |
|
| 266 |
|
| } |
| 267 |
|
| } |
| 268 |
|
| /* http bearer, oauth2 and openIdConnect all verify an issued token */ |
| 269 |
|
| { |
| 270 |
|
| STRLEN pl; |
| 271 |
6 |
| const char *p = poa_auth_param(as, al, "Bearer", 6, &pl); |
| 272 |
|
| /* |
| 273 |
|
| # uncoverable branch true |
| 274 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 275 |
6 |
▶ | if (!p) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p) return NULL; |
0 |
6 |
6 |
|
| 276 |
6 |
| return sv_2mortal(newSVpvn(p, pl)); |
| 277 |
|
| } |
| 278 |
|
| } |
| 279 |
|
| } |
| 280 |
|
| |
| 281 |
|
| /* ---- the generated per-operation security guard ---------------------------- |
| 282 |
|
| * |
| 283 |
|
| * Alternatives are OR, the schemes within one alternative are AND, and the |
| 284 |
|
| * eldest passing alternative authorizes (its results land in |
| 285 |
|
| * $c->stash->{auth}); none passing answers 401 before any body is read. |
| 286 |
|
| * |
| 287 |
|
| * Captured: [ $op_id, \@alts ] where each alt is an AV of |
| 288 |
|
| * [ $name, \%def, $checker, $scopes ]. */ |
| 289 |
|
| |
| 290 |
|
| XS_INTERNAL(punk_oa_security_cb); |
| 291 |
29 |
| XS_INTERNAL(punk_oa_security_cb) { |
| 292 |
29 |
| dXSARGS; |
| 293 |
29 |
| AV *cap = punk_clos_cap(aTHX_ cv); |
| 294 |
29 |
▶ | SV *c = items > 0 ? ST(0) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *c = items > 0 ? ST(0) : &PL_sv_undef; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
29 |
0 |
29 |
|
| 295 |
|
| SV *op_id, *alts_sv; |
| 296 |
|
| AV *alts; |
| 297 |
|
| SSize_t ai, an; |
| 298 |
|
| |
| 299 |
|
| /* |
| 300 |
|
| # uncoverable branch true class:ignore_covered_err |
| 301 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 302 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 303 |
29 |
▶ | if (!cap || items < 1) croak("Punk: a security guard lost its captures"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!cap || items < 1) croak("Punk: a security guard lost its captures"); |
29 |
0 |
29 |
| if (!cap || items < 1) croak("Punk: a security guard lost its captures"); |
0 |
29 |
29 |
|
| 304 |
29 |
| op_id = *av_fetch(cap, 0, 0); |
| 305 |
29 |
| alts_sv = *av_fetch(cap, 1, 0); |
| 306 |
29 |
| alts = (AV *)SvRV(alts_sv); |
| 307 |
29 |
| an = av_len(alts) + 1; |
| 308 |
|
| |
| 309 |
46 |
▶ | for (ai = 0; ai < an; ai++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ai = 0; ai < an; ai++) { |
32 |
14 |
46 |
|
| 310 |
32 |
| AV *alt = (AV *)SvRV(*av_fetch(alts, ai, 0)); |
| 311 |
32 |
| SSize_t pi, pn = av_len(alt) + 1; |
| 312 |
32 |
| HV *auth = newHV(); |
| 313 |
32 |
| int ok = 1; |
| 314 |
|
| |
| 315 |
50 |
▶ | for (pi = 0; pi < pn; pi++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (pi = 0; pi < pn; pi++) { |
35 |
15 |
50 |
|
| 316 |
35 |
| AV *part = (AV *)SvRV(*av_fetch(alt, pi, 0)); |
| 317 |
35 |
| SV *name = *av_fetch(part, 0, 0); |
| 318 |
35 |
| HV *def = (HV *)SvRV(*av_fetch(part, 1, 0)); |
| 319 |
35 |
| SV *checker = *av_fetch(part, 2, 0); |
| 320 |
35 |
| SV **scp = av_fetch(part, 3, 0); |
| 321 |
35 |
| SV *cred = poa_credential(aTHX_ c, def); |
| 322 |
|
| SV *got; |
| 323 |
|
| |
| 324 |
|
| /* a repeated query parameter arrives as an arrayref: that is |
| 325 |
|
| * no credential, not a string whose length is a pointer's */ |
| 326 |
|
| /* |
| 327 |
|
| # uncoverable condition left count:3 class:ignore_covered_err |
| 328 |
|
| # uncoverable condition left count:4 class:ignore_covered_err */ |
| 329 |
35 |
▶ | if (!(cred && SvOK(cred) && !SvROK(cred) && SvCUR(cred))) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (!(cred && SvOK(cred) && !SvROK(cred) && SvCUR(cred))) { |
30 |
5 |
35 |
| if (!(cred && SvOK(cred) && !SvROK(cred) && SvCUR(cred))) { |
25 |
5 |
30 |
| if (!(cred && SvOK(cred) && !SvROK(cred) && SvCUR(cred))) { |
25 |
0 |
25 |
| if (!(cred && SvOK(cred) && !SvROK(cred) && SvCUR(cred))) { |
0 |
25 |
25 |
|
| 330 |
10 |
| ok = 0; break; |
| 331 |
|
| } |
| 332 |
|
| { |
| 333 |
|
| SV *argv[4]; |
| 334 |
25 |
| argv[0] = cred; |
| 335 |
25 |
| argv[1] = c; |
| 336 |
25 |
| argv[2] = op_id; |
| 337 |
|
| /* |
| 338 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 339 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 340 |
25 |
▶ | argv[3] = (scp && *scp) ? *scp : &PL_sv_undef; |
Branch: 2 branches
| Branch | True | False | Total |
| argv[3] = (scp && *scp) ? *scp : &PL_sv_undef; |
25 |
0 |
25 |
| argv[3] = (scp && *scp) ? *scp : &PL_sv_undef; |
25 |
0 |
25 |
|
| 341 |
25 |
| got = poa_call_args(aTHX_ checker, argv, 4); |
| 342 |
|
| } |
| 343 |
25 |
▶ | if (!(got && SvTRUE(got))) { /* # uncoverable condition left count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(got && SvTRUE(got))) { /* # uncoverable condition left count:1 class:ignore_covered_err */ |
25 |
0 |
25 |
| if (!(got && SvTRUE(got))) { /* # uncoverable condition left count:1 class:ignore_covered_err */ |
7 |
18 |
25 |
|
| 344 |
|
| /* |
| 345 |
|
| # uncoverable branch false |
| 346 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 347 |
7 |
▶ | if (got) SvREFCNT_dec(got); |
Branch: 1 branch
| Branch | True | False | Total |
| if (got) SvREFCNT_dec(got); |
7 |
0 |
7 |
|
| 348 |
7 |
| ok = 0; break; |
| 349 |
|
| } |
| 350 |
18 |
| (void)hv_store_ent(auth, name, got, 0); /* takes the +1 */ |
| 351 |
|
| } |
| 352 |
|
| |
| 353 |
32 |
▶ | if (ok) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ok) { |
15 |
17 |
32 |
|
| 354 |
15 |
| SV *stash = pcx_call_meth(aTHX_ c, "stash", NULL, 0, 1); |
| 355 |
15 |
| HV *sh = poa_hash_of(aTHX_ stash); |
| 356 |
|
| /* |
| 357 |
|
| # uncoverable branch false |
| 358 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 359 |
15 |
▶ | if (sh) (void)hv_stores(sh, "auth", newRV_noinc((SV *)auth)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (sh) (void)hv_stores(sh, "auth", newRV_noinc((SV *)auth)); |
15 |
0 |
15 |
|
| 360 |
0 |
| else SvREFCNT_dec((SV *)auth); /* # uncoverable statement */ |
| 361 |
|
| /* |
| 362 |
|
| # uncoverable branch false |
| 363 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 364 |
15 |
▶ | if (stash) SvREFCNT_dec(stash); |
Branch: 1 branch
| Branch | True | False | Total |
| if (stash) SvREFCNT_dec(stash); |
15 |
0 |
15 |
|
| 365 |
15 |
| XSRETURN_EMPTY; /* authorized: the chain continues */ |
| 366 |
|
| } |
| 367 |
17 |
| SvREFCNT_dec((SV *)auth); |
| 368 |
|
| } |
| 369 |
|
| |
| 370 |
|
| { |
| 371 |
14 |
| SV *body = newSVpvs(POA_UNAUTHORIZED); |
| 372 |
14 |
| AV *hdrs = newAV(); |
| 373 |
14 |
| AV *bod = newAV(); |
| 374 |
14 |
| AV *trip = newAV(); |
| 375 |
14 |
| av_push(hdrs, newSVpvs("Content-Type")); |
| 376 |
14 |
| av_push(hdrs, newSVpvs("application/json")); |
| 377 |
14 |
| av_push(hdrs, newSVpvs("Content-Length")); |
| 378 |
14 |
| av_push(hdrs, newSViv((IV)SvCUR(body))); |
| 379 |
14 |
| av_push(bod, body); |
| 380 |
14 |
| av_push(trip, newSViv(401)); |
| 381 |
14 |
| av_push(trip, newRV_noinc((SV *)hdrs)); |
| 382 |
14 |
| av_push(trip, newRV_noinc((SV *)bod)); |
| 383 |
14 |
| ST(0) = sv_2mortal(newRV_noinc((SV *)trip)); |
| 384 |
14 |
| XSRETURN(1); |
| 385 |
|
| } |
| 386 |
|
| } |
| 387 |
|
| |
| 388 |
|
| /* ---- controller discovery -------------------------------------------------- |
| 389 |
|
| * |
| 390 |
|
| * Every .pm under the namespace directory, across @INC, loaded; the class |
| 391 |
|
| * names come back for the operationId search. */ |
| 392 |
|
| |
| 393 |
|
| /* A loadable class name: the only files that can define one are the ones whose |
| 394 |
|
| * path is made of identifiers, so anything else is skipped rather than |
| 395 |
|
| * required. It also makes the name safe to interpolate into the eval below. */ |
| 396 |
11 |
| static int poa_ident_path(const char *s, STRLEN len) { |
| 397 |
11 |
| STRLEN i = 0; |
| 398 |
|
| /* |
| 399 |
|
| # uncoverable branch true |
| 400 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 401 |
11 |
▶ | if (!len) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!len) return 0; |
0 |
11 |
11 |
|
| 402 |
|
| /* |
| 403 |
|
| # uncoverable branch false |
| 404 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 405 |
44 |
▶ | while (i < len) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (i < len) { |
44 |
0 |
44 |
|
| 406 |
44 |
| STRLEN start = i; |
| 407 |
|
| /* |
| 408 |
|
| # uncoverable branch false class:ignore_covered_err |
| 409 |
|
| # uncoverable branch true class:ignore_covered_err |
| 410 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 411 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 412 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 413 |
44 |
▶ | if (!(isALPHA((U8)s[i]) || s[i] == '_')) return 0; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(isALPHA((U8)s[i]) || s[i] == '_')) return 0; |
0 |
44 |
44 |
| if (!(isALPHA((U8)s[i]) || s[i] == '_')) return 0; |
0 |
0 |
0 |
|
| 414 |
311 |
▶ | while (i < len && (isWORDCHAR((U8)s[i]))) i++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (i < len && (isWORDCHAR((U8)s[i]))) i++; |
300 |
11 |
311 |
| while (i < len && (isWORDCHAR((U8)s[i]))) i++; |
267 |
33 |
300 |
|
| 415 |
|
| /* |
| 416 |
|
| # uncoverable branch true |
| 417 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 418 |
44 |
▶ | if (i == start) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (i == start) return 0; |
0 |
44 |
44 |
|
| 419 |
44 |
▶ | if (i == len) return 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (i == len) return 1; |
11 |
33 |
44 |
|
| 420 |
|
| /* |
| 421 |
|
| # uncoverable branch true |
| 422 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 423 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 424 |
|
| # uncoverable condition left count:3 class:ignore_covered_err */ |
| 425 |
33 |
▶ | if (!(s[i] == ':' && i + 1 < len && s[i + 1] == ':')) return 0; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(s[i] == ':' && i + 1 < len && s[i + 1] == ':')) return 0; |
33 |
0 |
33 |
| if (!(s[i] == ':' && i + 1 < len && s[i + 1] == ':')) return 0; |
33 |
0 |
33 |
| if (!(s[i] == ':' && i + 1 < len && s[i + 1] == ':')) return 0; |
0 |
33 |
33 |
|
| 426 |
33 |
| i += 2; |
| 427 |
|
| } |
| 428 |
0 |
| return 0; /* # uncoverable statement */ |
| 429 |
|
| } |
| 430 |
|
| |
| 431 |
267 |
| static void poa_walk_dir(pTHX_ SV *inc, SV *rel, HV *seen, AV *out) { |
| 432 |
267 |
| SV *dir = sv_2mortal(newSVsv(inc)); |
| 433 |
|
| DIR *dh; |
| 434 |
|
| Direntry_t *de; |
| 435 |
267 |
| AV *ents = (AV *)sv_2mortal((SV *)newAV()); |
| 436 |
|
| SSize_t i, n; |
| 437 |
|
| |
| 438 |
267 |
| sv_catpvs(dir, "/"); |
| 439 |
267 |
| sv_catsv(dir, rel); |
| 440 |
267 |
| dh = PerlDir_open(SvPV_nolen(dir)); |
| 441 |
267 |
▶ | if (!dh) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!dh) return; |
260 |
7 |
267 |
|
| 442 |
32 |
▶ | while ((de = PerlDir_read(dh))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((de = PerlDir_read(dh))) { |
25 |
7 |
32 |
|
| 443 |
25 |
| const char *nm = de->d_name; |
| 444 |
|
| /* |
| 445 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 446 |
|
| # uncoverable condition right count:3 class:ignore_covered_err |
| 447 |
|
| # uncoverable condition right count:4 class:ignore_covered_err */ |
| 448 |
25 |
▶ | if (nm[0] == '.' && (nm[1] == '\0' || (nm[1] == '.' && nm[2] == '\0'))) |
Branch: 4 branches
| Branch | True | False | Total |
| if (nm[0] == '.' && (nm[1] == '\0' || (nm[1] == '.' && nm[2] == '\0'))) |
14 |
11 |
25 |
| if (nm[0] == '.' && (nm[1] == '\0' || (nm[1] == '.' && nm[2] == '\0'))) |
7 |
7 |
14 |
| if (nm[0] == '.' && (nm[1] == '\0' || (nm[1] == '.' && nm[2] == '\0'))) |
7 |
0 |
7 |
| if (nm[0] == '.' && (nm[1] == '\0' || (nm[1] == '.' && nm[2] == '\0'))) |
7 |
0 |
7 |
|
| 449 |
14 |
| continue; |
| 450 |
11 |
| av_push(ents, newSVpv(nm, 0)); |
| 451 |
|
| } |
| 452 |
7 |
| PerlDir_close(dh); |
| 453 |
|
| |
| 454 |
|
| /* sorted so the traversal is stable across filesystems */ |
| 455 |
7 |
| n = av_len(ents) + 1; |
| 456 |
7 |
▶ | if (n > 1) sortsv(AvARRAY(ents), (STRLEN)n, Perl_sv_cmp); |
Branch: 1 branch
| Branch | True | False | Total |
| if (n > 1) sortsv(AvARRAY(ents), (STRLEN)n, Perl_sv_cmp); |
2 |
5 |
7 |
|
| 457 |
|
| |
| 458 |
18 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
11 |
7 |
18 |
|
| 459 |
11 |
| SV *ent = *av_fetch(ents, i, 0); |
| 460 |
|
| STRLEN el; |
| 461 |
11 |
| const char *es = SvPV_const(ent, el); |
| 462 |
11 |
| SV *child = sv_2mortal(newSVsv(rel)); |
| 463 |
11 |
| SV *full = sv_2mortal(newSVsv(dir)); |
| 464 |
|
| Stat_t st; |
| 465 |
11 |
| sv_catpvs(child, "/"); sv_catsv(child, ent); |
| 466 |
11 |
| sv_catpvs(full, "/"); sv_catsv(full, ent); |
| 467 |
|
| |
| 468 |
|
| /* |
| 469 |
|
| # uncoverable branch true |
| 470 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 471 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 472 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 473 |
11 |
▶ | if (PerlLIO_stat(SvPV_nolen(full), &st) == 0 && S_ISDIR(st.st_mode)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (PerlLIO_stat(SvPV_nolen(full), &st) == 0 && S_ISDIR(st.st_mode)) { |
11 |
0 |
11 |
| if (PerlLIO_stat(SvPV_nolen(full), &st) == 0 && S_ISDIR(st.st_mode)) { |
0 |
11 |
11 |
|
| 474 |
0 |
| poa_walk_dir(aTHX_ inc, child, seen, out); /* # uncoverable statement */ |
| 475 |
0 |
| continue; /* # uncoverable statement */ |
| 476 |
|
| } |
| 477 |
|
| /* |
| 478 |
|
| # uncoverable branch true |
| 479 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 480 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 481 |
11 |
▶ | if (!(el > 3 && memEQ(es + el - 3, ".pm", 3))) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(el > 3 && memEQ(es + el - 3, ".pm", 3))) continue; |
11 |
0 |
11 |
| if (!(el > 3 && memEQ(es + el - 3, ".pm", 3))) continue; |
0 |
11 |
11 |
|
| 482 |
|
| |
| 483 |
|
| { |
| 484 |
|
| /* the @INC-relative path minus .pm, as a class name */ |
| 485 |
11 |
| SV *mod = sv_2mortal(newSVpvn(SvPVX(child), SvCUR(child) - 3)); |
| 486 |
11 |
| char *p = SvPVX(mod); |
| 487 |
11 |
| STRLEN j, ml = SvCUR(mod); |
| 488 |
11 |
| SV *colons = sv_2mortal(newSVpvs("")); |
| 489 |
311 |
▶ | for (j = 0; j < ml; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < ml; j++) { |
300 |
11 |
311 |
|
| 490 |
300 |
▶ | if (p[j] == '/') sv_catpvs(colons, "::"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (p[j] == '/') sv_catpvs(colons, "::"); |
33 |
267 |
300 |
|
| 491 |
267 |
| else sv_catpvn(colons, p + j, 1); |
| 492 |
|
| } |
| 493 |
|
| /* |
| 494 |
|
| # uncoverable branch true |
| 495 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 496 |
11 |
▶ | if (!poa_ident_path(SvPVX(colons), SvCUR(colons))) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!poa_ident_path(SvPVX(colons), SvCUR(colons))) continue; |
0 |
11 |
11 |
|
| 497 |
|
| /* |
| 498 |
|
| # uncoverable branch true |
| 499 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 500 |
11 |
▶ | if (hv_exists_ent(seen, colons, 0)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists_ent(seen, colons, 0)) continue; |
0 |
11 |
11 |
|
| 501 |
11 |
| (void)hv_store_ent(seen, colons, newSViv(1), 0); |
| 502 |
|
| |
| 503 |
|
| /* Require by module name, which is the same %INC key |
| 504 |
|
| * `require Foo::Bar` and Punk::App's target resolver both use. |
| 505 |
|
| * Loading by absolute path instead made one file two %INC |
| 506 |
|
| * entries and ran it twice - "Subroutine redefined" for every |
| 507 |
|
| * controller reachable both ways, and two generations of the |
| 508 |
|
| * same coderefs. */ |
| 509 |
|
| { |
| 510 |
11 |
| SV *code = sv_2mortal(newSVpvs("require ")); |
| 511 |
11 |
| sv_catsv(code, colons); |
| 512 |
11 |
| sv_catpvs(code, "; 1"); |
| 513 |
11 |
| eval_sv(code, G_SCALAR | G_DISCARD); |
| 514 |
|
| /* |
| 515 |
|
| # uncoverable branch true |
| 516 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 517 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 518 |
11 |
▶ | if (SvTRUE(ERRSV)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) |
11 |
0 |
11 |
| if (SvTRUE(ERRSV)) |
0 |
11 |
11 |
|
| 519 |
0 |
▶ | croak("Punk: controller %s failed to load: %s", /* # uncoverable statement */ |
Branch: 2 branches
| Branch | True | False | Total |
| croak("Punk: controller %s failed to load: %s", /* # uncoverable statement */ |
0 |
0 |
0 |
| croak("Punk: controller %s failed to load: %s", /* # uncoverable statement */ |
0 |
0 |
0 |
|
| 520 |
|
| SvPV_nolen(colons), SvPV_nolen(ERRSV)); /* # uncoverable statement */ |
| 521 |
|
| } |
| 522 |
11 |
| av_push(out, newSVsv(colons)); |
| 523 |
|
| } |
| 524 |
|
| } |
| 525 |
|
| } |
| 526 |
|
| |
| 527 |
|
| /* The classes under $ns, loaded, sorted. Mortal AV. */ |
| 528 |
32 |
| static AV *poa_load_namespace(pTHX_ SV *ns) { |
| 529 |
32 |
| AV *out = (AV *)sv_2mortal((SV *)newAV()); |
| 530 |
32 |
| HV *seen = (HV *)sv_2mortal((SV *)newHV()); |
| 531 |
32 |
| AV *inc = GvAV(PL_incgv); |
| 532 |
32 |
▶ | SSize_t i, n = inc ? av_len(inc) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t i, n = inc ? av_len(inc) + 1 : 0; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
32 |
0 |
32 |
|
| 533 |
|
| STRLEN nl, j; |
| 534 |
32 |
| const char *ns_s = SvPV_const(ns, nl); |
| 535 |
32 |
| SV *rel = sv_2mortal(newSVpvs("")); |
| 536 |
|
| |
| 537 |
718 |
▶ | for (j = 0; j < nl; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < nl; j++) { |
686 |
32 |
718 |
|
| 538 |
|
| /* |
| 539 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 540 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 541 |
686 |
▶ | if (ns_s[j] == ':' && j + 1 < nl && ns_s[j + 1] == ':') { |
Branch: 3 branches
| Branch | True | False | Total |
| if (ns_s[j] == ':' && j + 1 < nl && ns_s[j + 1] == ':') { |
64 |
622 |
686 |
| if (ns_s[j] == ':' && j + 1 < nl && ns_s[j + 1] == ':') { |
64 |
0 |
64 |
| if (ns_s[j] == ':' && j + 1 < nl && ns_s[j + 1] == ':') { |
64 |
0 |
64 |
|
| 542 |
64 |
| sv_catpvs(rel, "/"); j++; |
| 543 |
|
| } |
| 544 |
622 |
| else sv_catpvn(rel, ns_s + j, 1); |
| 545 |
|
| } |
| 546 |
|
| |
| 547 |
299 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
267 |
32 |
299 |
|
| 548 |
267 |
| SV **ip = av_fetch(inc, i, 0); |
| 549 |
|
| /* |
| 550 |
|
| # uncoverable branch true |
| 551 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 552 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 553 |
|
| # uncoverable condition left count:3 class:ignore_covered_err |
| 554 |
|
| # uncoverable condition left count:4 class:ignore_covered_err */ |
| 555 |
267 |
▶ | if (!ip || !*ip || SvROK(*ip) || !SvOK(*ip)) continue; |
Branch: 4 branches
| Branch | True | False | Total |
| if (!ip || !*ip || SvROK(*ip) || !SvOK(*ip)) continue; |
267 |
0 |
267 |
| if (!ip || !*ip || SvROK(*ip) || !SvOK(*ip)) continue; |
267 |
0 |
267 |
| if (!ip || !*ip || SvROK(*ip) || !SvOK(*ip)) continue; |
267 |
0 |
267 |
| if (!ip || !*ip || SvROK(*ip) || !SvOK(*ip)) continue; |
0 |
267 |
267 |
|
| 556 |
267 |
| poa_walk_dir(aTHX_ *ip, rel, seen, out); |
| 557 |
|
| } |
| 558 |
32 |
| n = av_len(out) + 1; |
| 559 |
32 |
▶ | if (n > 1) sortsv(AvARRAY(out), (STRLEN)n, Perl_sv_cmp); |
Branch: 1 branch
| Branch | True | False | Total |
| if (n > 1) sortsv(AvARRAY(out), (STRLEN)n, Perl_sv_cmp); |
2 |
30 |
32 |
|
| 560 |
32 |
| return out; |
| 561 |
|
| } |
| 562 |
|
| |
| 563 |
|
| /* operationId -> coderef: an explicit handler first, then the one discovered |
| 564 |
|
| * class implementing it. Two implementers is an ambiguity the application has |
| 565 |
|
| * to resolve; none is only allowed under `stub`. Returns +1, or NULL. */ |
| 566 |
75 |
| static SV *poa_find_handler(pTHX_ SV *id, HV *handlers, AV *classes, |
| 567 |
|
| SV *resolve) { |
| 568 |
75 |
▶ | HE *he = handlers ? hv_fetch_ent(handlers, id, 0, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| HE *he = handlers ? hv_fetch_ent(handlers, id, 0, 0) : NULL; |
42 |
33 |
75 |
|
| 569 |
75 |
| SSize_t i, n = av_len(classes) + 1; |
| 570 |
75 |
| SV *found = NULL, *names = NULL; |
| 571 |
75 |
| int hits = 0; |
| 572 |
|
| |
| 573 |
75 |
▶ | if (he && SvOK(HeVAL(he))) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (he && SvOK(HeVAL(he))) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
37 |
38 |
75 |
| if (he && SvOK(HeVAL(he))) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
37 |
0 |
37 |
|
| 574 |
37 |
| SV *what = sv_2mortal(newSVpvs("handler for '")); |
| 575 |
37 |
| sv_catsv(what, id); |
| 576 |
37 |
| sv_catpvs(what, "'"); |
| 577 |
37 |
| return poa_resolve(aTHX_ resolve, HeVAL(he), SvPV_nolen(what)); |
| 578 |
|
| } |
| 579 |
|
| |
| 580 |
71 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
33 |
38 |
71 |
|
| 581 |
33 |
| SV *cls = *av_fetch(classes, i, 0); |
| 582 |
33 |
| HV *stash = gv_stashsv(cls, 0); |
| 583 |
33 |
| GV *gv = stash ? gv_fetchmethod_autoload(stash, SvPV_nolen(id), 0) |
| 584 |
33 |
▶ | : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| : NULL; |
33 |
0 |
33 |
|
| 585 |
33 |
▶ | if (!(gv && GvCV(gv))) continue; /* # uncoverable condition left count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(gv && GvCV(gv))) continue; /* # uncoverable condition left count:2 class:ignore_covered_err */ |
21 |
12 |
33 |
| if (!(gv && GvCV(gv))) continue; /* # uncoverable condition left count:2 class:ignore_covered_err */ |
0 |
21 |
21 |
|
| 586 |
21 |
| hits++; |
| 587 |
|
| /* |
| 588 |
|
| # uncoverable branch false |
| 589 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 590 |
21 |
▶ | if (!found) found = newRV_inc((SV *)GvCV(gv)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!found) found = newRV_inc((SV *)GvCV(gv)); |
21 |
0 |
21 |
|
| 591 |
|
| /* |
| 592 |
|
| # uncoverable branch false |
| 593 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 594 |
21 |
▶ | if (!names) names = sv_2mortal(newSVsv(cls)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!names) names = sv_2mortal(newSVsv(cls)); |
21 |
0 |
21 |
|
| 595 |
0 |
| else { sv_catpvs(names, ", "); sv_catsv(names, cls); } /* # uncoverable statement */ |
| 596 |
|
| } |
| 597 |
|
| /* |
| 598 |
|
| # uncoverable branch true |
| 599 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 600 |
38 |
▶ | if (hits > 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hits > 1) |
0 |
38 |
38 |
|
| 601 |
0 |
▶ | croak("Punk: operation '%s' is implemented by more than one " /* # uncoverable statement */ |
Branch: 1 branch
| Branch | True | False | Total |
| croak("Punk: operation '%s' is implemented by more than one " /* # uncoverable statement */ |
0 |
0 |
0 |
|
| 602 |
|
| "controller (%s)", SvPV_nolen(id), SvPV_nolen(names)); /* # uncoverable statement */ |
| 603 |
38 |
| return found; |
| 604 |
|
| } |
| 605 |
|
| |
| 606 |
|
| #endif /* PUNK_OAMOUNT_H */ |