xs/auth.xs

filter: Statementstmt 98.0% 148 / 151 Branchbran 60.6% 108 / 178 (4 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 77.8% 256 / 329 (4 uncoverable) CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_scope.h ↑ Summary xs/model.xs »
1 MODULE = Punk PACKAGE = Punk::Context
2  
3 PROTOTYPES: DISABLE
4  
5 # The authentication context surface, all C (punk_auth.h): login/logout/
6 # auth_id are a session load and a hash write; current_user loads through
7 # the configured model and the await seam; check_password fronts the KDF
8 # with the dummy-verify rule; the token pair carries the delete-first spend
9 # order. lib/Punk/Auth.pm is documentation only.
10  
11 # $c->login($user_or_id): record the signed-in user in the session. A hashref
12 # uses its id field (the auth fields map); anything else is the id itself.
13 # Chains.
14 SV *
15 login(self, user)
16 SV *self
17 SV *user
18 CODE:
19 {
20 39 HV *cfg = pauth_cfg(aTHX_ self);
21 39 SV *id = NULL, *sess;
22 STRLEN kl;
23 const char *key;
24 39 ▶ if (!cfg)
Branch: 1 branch
BranchTrueFalseTotal
if (!cfg) 1 38 39
25 1 croak("Punk: login needs the auth keyword (add `auth ...`)");
26 38 ▶ if (SvROK(user) && SvTYPE(SvRV(user)) == SVt_PVHV) { /* # uncoverable condition right count:2 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(user) && SvTYPE(SvRV(user)) == SVt_PVHV) { /* # uncoverable condition right count:2 class:ignore_covered_err */ 24 14 38
if (SvROK(user) && SvTYPE(SvRV(user)) == SVt_PVHV) { /* # uncoverable condition right count:2 class:ignore_covered_err */ 24 0 24
27 24 HV *u = (HV *)SvRV(user);
28 STRLEN idl;
29 24 const char *idf = pauth_field(aTHX_ cfg, "id", "id", &idl);
30 24 SV **e = hv_fetch(u, idf, (I32)idl, 0);
31 24 ▶ # uncoverable condition left count:2 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition left count:2 class:ignore_covered_err 23 1 24
# uncoverable condition left count:2 class:ignore_covered_err 23 0 23
# uncoverable condition left count:2 class:ignore_covered_err 0 23 23
32 1 # uncoverable condition left count:3 class:ignore_covered_err
33 23 if (!(e && *e && SvOK(*e)))
34 croak("Punk: login was handed a user with no '%s'", idf);
35 14 ▶ id = *e;
Branch: 1 branch
BranchTrueFalseTotal
id = *e; 13 1 14
36 1 }
37 36 ▶ else if (SvOK(user)) id = user;
Branch: 1 branch
BranchTrueFalseTotal
else if (SvOK(user)) id = user; 3 33 36
38 3 else croak("Punk: login needs a user row or id");
39 if (!pauth_id_ok(aTHX_ id))
40 33 croak("Punk: login needs a user id that is not empty and not 0");
41 33  
42 33 ▶ key = ps_cfg_str(aTHX_ cfg, "session_key", "user_id", &kl);
Branch: 3 branches
BranchTrueFalseTotal
key = ps_cfg_str(aTHX_ cfg, "session_key", "user_id", &kl); 33 0 33
key = ps_cfg_str(aTHX_ cfg, "session_key", "user_id", &kl); 33 0 33
key = ps_cfg_str(aTHX_ cfg, "session_key", "user_id", &kl); 33 0 33
43 33 sess = ps_load(aTHX_ self);
44 # uncoverable branch false
45 # uncoverable condition right count:1 class:ignore_covered_err
46 # uncoverable condition right count:2 class:ignore_covered_err
47 33 # uncoverable condition right count:3 class:ignore_covered_err
48 if (sess && SvROK(sess) && SvTYPE(SvRV(sess)) == SVt_PVHV) {
49 33 ▶ (void)hv_store((HV *)SvRV(sess), key, (I32)kl, newSVsv(id), 0);
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_store((HV *)SvRV(sess), key, (I32)kl, newSVsv(id), 0); 33 0 33
50 /* the CSRF token minted for the anonymous session goes with it:
51 33 * one planted before the login would otherwise validate for the
52 * user after it */
53 33 (void)hv_delete((HV *)SvRV(sess), "punk.csrf", 9, G_DISCARD);
54 }
55 # uncoverable branch false
56 # uncoverable condition right count:1 class:ignore_covered_err
57 33 if (sess) SvREFCNT_dec(sess);
58 {
59 HV *stash = ps_stash(aTHX_ pcx_av(aTHX_ self));
60 33 /* a fresh login invalidates this request's memoized user */
61 (void)hv_delete(stash, "punk.auth", 9, G_DISCARD);
62 33 /* A login is the privilege boundary, so a stored session gets a
63 * new id here: one planted in the browser before the login must
64 * not be the name of the session after it. */
65 ps_mark_rotate(aTHX_ self, ps_cfg(aTHX_ self), stash);
66 /* ...and it outranks a logout earlier in the same request, whose
67 * deletion cookie would otherwise be the only thing written. */
68 (void)hv_delete(stash, "punk.session.expire", 19, G_DISCARD);
69 }
70 RETVAL = newSVsv(self);
71 }
72 OUTPUT:
73 RETVAL
74  
75 # $c->logout: empty the session and delete its cookie (session_expire), and
76 # forget the memoized user. Chains.
77 SV *
78 logout(self)
79 SV *self
80 CODE:
81 {
82 6 SV *r = pcx_call_meth(aTHX_ self, "session_expire", NULL, 0, 1);
83 6 ▶ # uncoverable branch false
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable branch false 6 0 6
84 # uncoverable condition right count:1 class:ignore_covered_err
85 6 if (r) SvREFCNT_dec(r);
86 6 {
87 HV *stash = ps_stash(aTHX_ pcx_av(aTHX_ self));
88 6 (void)hv_delete(stash, "punk.auth", 9, G_DISCARD);
89 }
90 RETVAL = newSVsv(self);
91 }
92 OUTPUT:
93 RETVAL
94  
95 # $c->auth_id: the signed-in user id straight off the session - no database.
96 # The oauth2_server authenticate shape: an id, or undef.
97 SV *
98 auth_id(self)
99 SV *self
100 CODE:
101 {
102 17 HV *cfg = pauth_cfg(aTHX_ self);
103 SV *id;
104 17 ▶ if (!cfg)
Branch: 1 branch
BranchTrueFalseTotal
if (!cfg) 1 16 17
105 1 croak("Punk: auth_id needs the auth keyword (add `auth ...`)");
106 16 id = pauth_session_id(aTHX_ self, cfg);
107 16 ▶ RETVAL = id ? id : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = id ? id : &PL_sv_undef; 10 6 16
108 }
109 OUTPUT:
110 RETVAL
111  
112 # $c->current_user: the signed-in user's row, loaded once per request and
113 # memoized; undef when nobody is signed in or the row is gone.
114 SV *
115 current_user(self)
116 SV *self
117 CODE:
118 {
119 12 HV *cfg = pauth_cfg(aTHX_ self);
120 SV *user;
121 12 ▶ if (!cfg)
Branch: 1 branch
BranchTrueFalseTotal
if (!cfg) 1 11 12
122 1 croak("Punk: current_user needs the auth keyword "
123 "(add `auth ...`)");
124 11 user = pauth_current_user(aTHX_ self, cfg);
125 11 ▶ RETVAL = user ? user : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = user ? user : &PL_sv_undef; 10 1 11
126 }
127 OUTPUT:
128 RETVAL
129  
130 # $c->check_password($user, $password): true only for a real match. With no
131 # user or no stored hash the same PBKDF2 work is burned before returning
132 # false, so login response time cannot say which emails exist.
133 IV
134 check_password(self, user, password)
135 SV *self
136 SV *user
137 SV *password
138 CODE:
139 {
140 4 HV *cfg = pauth_cfg(aTHX_ self);
141 4 SV *stored = NULL;
142 4 U32 iterations = 0;
143 STRLEN pfl;
144 const char *pf;
145 4 ▶ if (!cfg)
Branch: 1 branch
BranchTrueFalseTotal
if (!cfg) 1 3 4
146 1 croak("Punk: check_password needs the auth keyword "
147 "(add `auth ...`)");
148 3 pf = pauth_field(aTHX_ cfg, "password", "password_hash", &pfl);
149 {
150 3 SV **it = hv_fetchs(cfg, "iterations", 0);
151 3 ▶ # uncoverable branch true
Branch: 4 branches
BranchTrueFalseTotal
# uncoverable branch true 0 3 3
# uncoverable branch true 0 0 0
# uncoverable branch true 0 0 0
# uncoverable branch true 0 0 0
152 0 # uncoverable condition left count:1 class:ignore_covered_err
153 # uncoverable condition left count:2 class:ignore_covered_err
154 3 # uncoverable condition right count:2 class:ignore_covered_err
155 3 ▶ # uncoverable condition left count:3 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition left count:3 class:ignore_covered_err 3 0 3
# uncoverable condition left count:3 class:ignore_covered_err 3 0 3
# uncoverable condition left count:3 class:ignore_covered_err 3 0 3
156 # uncoverable condition right count:3 class:ignore_covered_err
157 # uncoverable condition left count:4 class:ignore_covered_err
158 3 ▶ # uncoverable condition right count:4 class:ignore_covered_err
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable condition right count:4 class:ignore_covered_err 2 1 3
# uncoverable condition right count:4 class:ignore_covered_err 2 0 2
159 2 if (it && *it && SvOK(*it) && SvIV(*it) > 0)
160 2 ▶ iterations = (U32)SvIV(*it); /* # uncoverable statement */
Branch: 4 branches
BranchTrueFalseTotal
iterations = (U32)SvIV(*it); /* # uncoverable statement */ 2 0 2
iterations = (U32)SvIV(*it); /* # uncoverable statement */ 2 0 2
iterations = (U32)SvIV(*it); /* # uncoverable statement */ 2 0 2
iterations = (U32)SvIV(*it); /* # uncoverable statement */ 2 0 2
161 else {
162 3 ▶ SV *g = get_sv("Punk::Auth::Password::ITERATIONS", 0);
Branch: 1 branch
BranchTrueFalseTotal
SV *g = get_sv("Punk::Auth::Password::ITERATIONS", 0); 1 2 3
163 1 # uncoverable branch false
164 2 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 1 0 1
165 1 # uncoverable condition right count:2 class:ignore_covered_err
166 1 # uncoverable condition right count:3 class:ignore_covered_err
167 if (g && SvOK(g) && SvIV(g) > 0) iterations = (U32)SvIV(g);
168 }
169 }
170 if (SvROK(user) && SvTYPE(SvRV(user)) == SVt_PVHV) { /* # uncoverable condition right count:2 class:ignore_covered_err */
171 SV **e = hv_fetch((HV *)SvRV(user), pf, (I32)pfl, 0);
172 2 # uncoverable branch false
173 4 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 2 0 2
174 2 # uncoverable condition right count:2 class:ignore_covered_err
175 2 # uncoverable condition right count:3 class:ignore_covered_err
176 # uncoverable condition right count:4 class:ignore_covered_err
177 if (e && *e && SvOK(*e) && SvCUR(*e)) stored = *e;
178 }
179 if (!stored) {
180 STRLEN pl = 0;
181 const char *p = SvOK(password) ? SvPV_const(password, pl) : ""; /* # uncoverable condition right count:1 class:ignore_covered_err */
182 pwd_dummy_verify(aTHX_ (const unsigned char *)p, pl, iterations);
183 RETVAL = 0;
184 }
185 else {
186 /* an undef password is the empty one, verified in full: the
187 * early return it used to take answered faster for a known
188 * email than for an unknown one */
189 STRLEN pl = 0, sl;
190 const char *p = SvOK(password) ? SvPV_const(password, pl) : ""; /* # uncoverable condition right count:1 class:ignore_covered_err */
191 const char *s = SvPV_const(stored, sl);
192 RETVAL = pwd_verify(aTHX_ (const unsigned char *)p, pl, s, sl);
193 }
194 }
195 OUTPUT:
196 RETVAL
197  
198 # $c->issue_token($user_id, $kind, $ttl): a single-use token on the token
199 # model. Storage sees only the sha256 digest with an absolute expiry; a new
200 # token invalidates the user's older tokens of the same kind, so a re-sent
201 # mail leaves exactly one live link. Returns the plaintext, once.
202 SV *
203 issue_token(self, user_id, kind, ttl)
204 SV *self
205 SV *user_id
206 SV *kind
207 SV *ttl
208 CODE:
209 {
210 11 HV *cfg = pauth_cfg(aTHX_ self);
211 SV *m, *tok;
212 11 ▶ if (!cfg)
Branch: 1 branch
BranchTrueFalseTotal
if (!cfg) 1 10 11
213 1 croak("Punk: issue_token needs the auth keyword "
214 "(add `auth ...`)");
215 10 ▶ # uncoverable branch true
Branch: 4 branches
BranchTrueFalseTotal
# uncoverable branch true 10 0 10
# uncoverable branch true 10 0 10
# uncoverable branch true 10 0 10
# uncoverable branch true 0 10 10
216 0 # uncoverable condition left count:1 class:ignore_covered_err
217 10 # uncoverable condition left count:2 class:ignore_covered_err
218 # uncoverable condition left count:3 class:ignore_covered_err
219 9 # uncoverable condition left count:4 class:ignore_covered_err
220 if (!SvOK(user_id) || !SvOK(kind) || !SvOK(ttl) || SvIV(ttl) <= 0)
221 croak("Punk: issue_token needs a user id, a kind and a ttl"); /* # uncoverable statement */
222 9 m = pauth_model(aTHX_ self, cfg, "token_model", "issue_token");
223 9 { /* older same-kind tokens die first */
224 9 HV *filter = newHV();
225 9 SV *argv[1], *raw, *res;
226 9 ▶ AV *rows;
Branch: 1 branch
BranchTrueFalseTotal
AV *rows; 9 0 9
227 9 ▶ (void)hv_stores(filter, "user_id", newSVsv(user_id));
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(filter, "user_id", newSVsv(user_id)); 9 0 9
228 9 (void)hv_stores(filter, "kind", newSVsv(kind));
229 9 ▶ argv[0] = sv_2mortal(newRV_noinc((SV *)filter));
Branch: 1 branch
BranchTrueFalseTotal
argv[0] = sv_2mortal(newRV_noinc((SV *)filter)); 9 0 9
230 9 raw = pcx_call_meth(aTHX_ m, "search", argv, 1, 1);
231 11 ▶ res = pauth_await(aTHX_ self, raw ? raw : &PL_sv_undef); /* # uncoverable condition left count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
res = pauth_await(aTHX_ self, raw ? raw : &PL_sv_undef); /* # uncoverable condition left count:1 class:ignore_covered_err */ 2 9 11
232 2 # uncoverable branch false
233 # uncoverable condition right count:1 class:ignore_covered_err
234 if (raw) SvREFCNT_dec(raw);
235 2 ▶ rows = pauth_rows(aTHX_ res);
Branch: 3 branches
BranchTrueFalseTotal
rows = pauth_rows(aTHX_ res); 2 0 2
rows = pauth_rows(aTHX_ res); 2 0 2
rows = pauth_rows(aTHX_ res); 0 2 2
236 2 # uncoverable branch false
237 2 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 2 0 2
# uncoverable condition right count:1 class:ignore_covered_err 2 0 2
# uncoverable condition right count:1 class:ignore_covered_err 0 2 2
238 2 if (rows) {
239 2 SSize_t i, n = av_len(rows) + 1;
240 2 for (i = 0; i < n; i++) {
241 2 ▶ SV **rp = av_fetch(rows, i, 0);
Branch: 1 branch
BranchTrueFalseTotal
SV **rp = av_fetch(rows, i, 0); 2 0 2
242 SV **idp;
243 2 ▶ SV *dargv[2], *draw, *dres;
Branch: 1 branch
BranchTrueFalseTotal
SV *dargv[2], *draw, *dres; 2 0 2
244 2 ▶ # uncoverable branch true
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable branch true 2 0 2
245 # uncoverable condition left count:1 class:ignore_covered_err
246 # uncoverable condition left count:2 class:ignore_covered_err
247 9 ▶ # uncoverable condition left count:3 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:3 class:ignore_covered_err 9 0 9
248 if (!(rp && *rp && SvROK(*rp))) continue;
249 9 idp = hv_fetchs((HV *)SvRV(*rp), "id", 0);
250 # uncoverable branch true
251 9 # uncoverable condition left count:1 class:ignore_covered_err
252 # uncoverable condition left count:2 class:ignore_covered_err
253 # uncoverable condition left count:3 class:ignore_covered_err
254 if (!(idp && *idp && SvOK(*idp))) continue;
255 9 dargv[0] = sv_2mortal(newSVpvs("id"));
256 9 dargv[1] = *idp;
257 9 draw = pcx_call_meth(aTHX_ m, "delete", dargv, 2, 1);
258 9 dres = pauth_await(aTHX_ self,
259 9 draw ? draw : &PL_sv_undef);
260 # uncoverable branch false
261 9 # uncoverable condition right count:1 class:ignore_covered_err
262 9 if (draw) SvREFCNT_dec(draw);
263 9 ▶ # uncoverable branch false
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable branch false 9 0 9
264 9 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 9 0 9
265 9 ▶ if (dres) SvREFCNT_dec(dres);
Branch: 1 branch
BranchTrueFalseTotal
if (dres) SvREFCNT_dec(dres); 9 0 9
266 }
267 9 }
268 9 # uncoverable branch false
269 # uncoverable condition right count:1 class:ignore_covered_err
270 if (res) SvREFCNT_dec(res);
271 }
272 tok = pwd_token(aTHX);
273 {
274 HV *data = newHV();
275 SV *argv[1], *raw, *res;
276 STRLEN tl;
277 const unsigned char *tp =
278 (const unsigned char *)SvPV_const(tok, tl);
279 (void)hv_stores(data, "user_id", newSVsv(user_id));
280 (void)hv_stores(data, "kind", newSVsv(kind));
281 (void)hv_stores(data, "digest", pwd_token_digest(aTHX_ tp, tl));
282 (void)hv_stores(data, "expires",
283 newSViv((IV)time(NULL) + SvIV(ttl)));
284 argv[0] = sv_2mortal(newRV_noinc((SV *)data));
285 raw = pcx_call_meth(aTHX_ m, "create", argv, 1, 1);
286 res = pauth_await(aTHX_ self, raw ? raw : &PL_sv_undef); /* # uncoverable condition left count:1 class:ignore_covered_err */
287 # uncoverable branch false
288 # uncoverable condition right count:1 class:ignore_covered_err
289 if (raw) SvREFCNT_dec(raw);
290 # uncoverable branch false
291 # uncoverable condition right count:1 class:ignore_covered_err
292 if (res) SvREFCNT_dec(res);
293 }
294 SvREFCNT_dec(m);
295 RETVAL = tok;
296 }
297 OUTPUT:
298 RETVAL
299  
300 # $c->take_token($token, @kinds): the row, or nothing. THE ORDER IS THE
301 # FEATURE: look up by digest, delete FIRST, then validate kind and expiry -
302 # a token is spent whether or not it turns out valid, so a wrong-kind probe
303 # burns it rather than leaving it live for its real endpoint.
304 SV *
305 take_token(self, token, ...)
306 SV *self
307 SV *token
308 CODE:
309 {
310 9 HV *cfg = pauth_cfg(aTHX_ self);
311 9 SV *m, *row_copy = NULL;
312 9 ▶ if (!cfg)
Branch: 1 branch
BranchTrueFalseTotal
if (!cfg) 1 8 9
313 1 croak("Punk: take_token needs the auth keyword "
314 "(add `auth ...`)");
315 8 ▶ # uncoverable branch true
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable branch true 8 0 8
# uncoverable branch true 8 0 8
# uncoverable branch true 0 8 8
316 0 # uncoverable condition left count:1 class:ignore_covered_err
317 8 # uncoverable condition left count:2 class:ignore_covered_err
318 # uncoverable condition left count:3 class:ignore_covered_err
319 8 if (!SvOK(token) || !SvCUR(token) || items < 3)
320 XSRETURN_UNDEF; /* # uncoverable statement */
321 m = pauth_model(aTHX_ self, cfg, "token_model", "take_token");
322 8 {
323 HV *filter = newHV();
324 SV *argv[1], *raw, *res;
325 8 AV *rows;
326 8 SV **rp = NULL;
327 8 STRLEN tl;
328 8 const unsigned char *tp =
329 8 ▶ (const unsigned char *)SvPV_const(token, tl);
Branch: 1 branch
BranchTrueFalseTotal
(const unsigned char *)SvPV_const(token, tl); 8 0 8
330 8 ▶ (void)hv_stores(filter, "digest", pwd_token_digest(aTHX_ tp, tl));
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_stores(filter, "digest", pwd_token_digest(aTHX_ tp, tl)); 8 0 8
331 8 argv[0] = sv_2mortal(newRV_noinc((SV *)filter));
332 8 ▶ raw = pcx_call_meth(aTHX_ m, "search", argv, 1, 1);
Branch: 2 branches
BranchTrueFalseTotal
raw = pcx_call_meth(aTHX_ m, "search", argv, 1, 1); 8 0 8
raw = pcx_call_meth(aTHX_ m, "search", argv, 1, 1); 5 3 8
333 8 ▶ res = pauth_await(aTHX_ self, raw ? raw : &PL_sv_undef); /* # uncoverable condition left count:1 class:ignore_covered_err */
Branch: 3 branches
BranchTrueFalseTotal
res = pauth_await(aTHX_ self, raw ? raw : &PL_sv_undef); /* # uncoverable condition left count:1 class:ignore_covered_err */ 5 3 8
res = pauth_await(aTHX_ self, raw ? raw : &PL_sv_undef); /* # uncoverable condition left count:1 class:ignore_covered_err */ 5 0 5
res = pauth_await(aTHX_ self, raw ? raw : &PL_sv_undef); /* # uncoverable condition left count:1 class:ignore_covered_err */ 5 0 5
334 5 ▶ # uncoverable branch false
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable branch false 5 0 5
335 5 # uncoverable condition right count:1 class:ignore_covered_err
336 5 if (raw) SvREFCNT_dec(raw);
337 5 rows = pauth_rows(aTHX_ res);
338 5 if (rows && av_len(rows) >= 0) rp = av_fetch(rows, 0, 0); /* # uncoverable condition right count:1 class:ignore_covered_err */
339 5 # uncoverable condition right count:2 class:ignore_covered_err
340 5 ▶ # uncoverable condition right count:3 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:3 class:ignore_covered_err 5 0 5
# uncoverable condition right count:3 class:ignore_covered_err 5 0 5
# uncoverable condition right count:3 class:ignore_covered_err 5 0 5
341 # uncoverable condition right count:4 class:ignore_covered_err
342 5 if (rp && *rp && SvROK(*rp)
343 5 && SvTYPE(SvRV(*rp)) == SVt_PVHV) {
344 5 HV *row = (HV *)SvRV(*rp);
345 5 ▶ SV **idp = hv_fetchs(row, "id", 0);
Branch: 1 branch
BranchTrueFalseTotal
SV **idp = hv_fetchs(row, "id", 0); 5 0 5
346 SV **kp = hv_fetchs(row, "kind", 0);
347 5 ▶ SV **xp = hv_fetchs(row, "expires", 0);
Branch: 1 branch
BranchTrueFalseTotal
SV **xp = hv_fetchs(row, "expires", 0); 5 0 5
348 5 ▶ int i, kind_ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
int i, kind_ok = 0; 5 0 5
349 # uncoverable branch false
350 5 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 5 0 5
# uncoverable condition right count:1 class:ignore_covered_err 5 0 5
# uncoverable condition right count:1 class:ignore_covered_err 5 0 5
351 # uncoverable condition right count:2 class:ignore_covered_err
352 5 # uncoverable condition right count:3 class:ignore_covered_err
353 11 ▶ if (idp && *idp && SvOK(*idp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (idp && *idp && SvOK(*idp)) { 6 5 11
if (idp && *idp && SvOK(*idp)) { 6 0 6
354 SV *dargv[2], *draw, *dres;
355 dargv[0] = sv_2mortal(newSVpvs("id"));
356 6 ▶ dargv[1] = *idp;
Branch: 1 branch
BranchTrueFalseTotal
dargv[1] = *idp; 0 6 6
357 6 draw = pcx_call_meth(aTHX_ m, "delete", dargv, 2, 1);
358 6 ▶ dres = pauth_await(aTHX_ self,
Branch: 2 branches
BranchTrueFalseTotal
dres = pauth_await(aTHX_ self, 4 2 6
dres = pauth_await(aTHX_ self, 4 0 4
359 draw ? draw : &PL_sv_undef);
360 # uncoverable branch false
361 5 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 4 branches
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 4 1 5
# uncoverable condition right count:1 class:ignore_covered_err 4 0 4
# uncoverable condition right count:1 class:ignore_covered_err 4 0 4
# uncoverable condition right count:1 class:ignore_covered_err 4 0 4
362 4 ▶ if (draw) SvREFCNT_dec(draw);
Branch: 1 branch
BranchTrueFalseTotal
if (draw) SvREFCNT_dec(draw); 3 1 4
363 3 # uncoverable branch false
364 # uncoverable condition right count:1 class:ignore_covered_err
365 8 ▶ if (dres) SvREFCNT_dec(dres);
Branch: 1 branch
BranchTrueFalseTotal
if (dres) SvREFCNT_dec(dres); 8 0 8
366 }
367 8 # uncoverable branch false
368 8 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 5 3 8
369 3 # uncoverable condition right count:2 class:ignore_covered_err
370 # uncoverable condition right count:3 class:ignore_covered_err
371 if (kp && *kp && SvOK(*kp)) {
372 STRLEN kl2;
373 const char *k2 = SvPV_const(*kp, kl2);
374 for (i = 2; i < items && !kind_ok; i++) { /* # uncoverable condition right count:2 class:ignore_covered_err */
375 STRLEN wl;
376 const char *w;
377 # uncoverable branch true
378 # uncoverable condition left count:1 class:ignore_covered_err
379 if (!SvOK(ST(i))) continue;
380 w = SvPV_const(ST(i), wl);
381 if (wl == kl2 && memEQ(w, k2, kl2)) kind_ok = 1; /* # uncoverable condition right count:2 class:ignore_covered_err */
382 }
383 }
384 # uncoverable condition right count:2 class:ignore_covered_err
385 # uncoverable condition right count:3 class:ignore_covered_err
386 # uncoverable condition right count:4 class:ignore_covered_err
387 if (kind_ok && xp && *xp && SvOK(*xp)
388 && SvIV(*xp) >= (IV)time(NULL))
389 row_copy = newRV_noinc((SV *)newHVhv(row));
390 }
391 # uncoverable branch false
392 # uncoverable condition right count:1 class:ignore_covered_err
393 if (res) SvREFCNT_dec(res);
394 }
395 SvREFCNT_dec(m);
396 if (!row_copy) XSRETURN_UNDEF;
397 RETVAL = row_copy;
398 }
399 OUTPUT:
400 RETVAL
401  
402 MODULE = Punk PACKAGE = Punk::Auth
403  
404 PROTOTYPES: DISABLE
405  
406 # The await seam, exposed: Punk::Auth::_await($c, $value) unwraps a
407 # future-returning model backend's result (Punk::Future through $c->await,
408 # any other ->get-bearing object through its own get), and passes a plain
409 # value straight through - so glue code stays backend-agnostic.
410 SV *
411 _await(c, v)
412 SV *c
413 SV *v
414 CODE:
415 1 RETVAL = pauth_await(aTHX_ c, v);
416 OUTPUT:
417 RETVAL
« include/punk/punk_scope.h ↑ Summary xs/model.xs »