| 1 |
|
| /* punk_flash.h - one-request flash messages over the signed-cookie session. |
| 2 |
|
| * |
| 3 |
|
| * One reserved key inside the session hashref, `punk.flash`, holds the |
| 4 |
|
| * outbound flash - what the NEXT request will read. On the first flash call |
| 5 |
|
| * of a request the inbound hash is deleted out of the session into the |
| 6 |
|
| * stash (`punk.flash.in`): the delete dirties the session, so the response |
| 7 |
|
| * of the request that consumed it rewrites the cookie without it - the |
| 8 |
|
| * one-request lifetime falls out of the ordinary change-detected write-back, |
| 9 |
|
| * and a request that never touches flash leaves it riding. Everything else |
| 10 |
|
| * is the session's existing machinery: the signing, the 4KB cap, and the |
| 11 |
|
| * croak when no `session` keyword is configured. |
| 12 |
|
| * |
| 13 |
|
| * Needs punk_session.h (ps_load, ps_stash). |
| 14 |
|
| */ |
| 15 |
|
| |
| 16 |
|
| #ifndef PUNK_FLASH_H |
| 17 |
|
| #define PUNK_FLASH_H |
| 18 |
|
| |
| 19 |
|
| /* this request's inbound flash, rotated out of the session on first call; |
| 20 |
|
| * never NULL (borrowed - the stash owns it) */ |
| 21 |
38 |
| static HV *pf_inbound(pTHX_ SV *c) { |
| 22 |
38 |
| AV *av = pcx_av(aTHX_ c); |
| 23 |
38 |
| HV *stash = ps_stash(aTHX_ av); |
| 24 |
38 |
| SV **in = hv_fetchs(stash, "punk.flash.in", 0); |
| 25 |
|
| SV *sess_rv, *moved, *rv; |
| 26 |
|
| HV *inh; |
| 27 |
|
| /* |
| 28 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 29 |
|
| # uncoverable condition right count:3 class:ignore_covered_err |
| 30 |
|
| # uncoverable condition right count:4 class:ignore_covered_err */ |
| 31 |
38 |
▶ | if (in && *in && SvROK(*in) && SvTYPE(SvRV(*in)) == SVt_PVHV) |
Branch: 4 branches
| Branch | True | False | Total |
| if (in && *in && SvROK(*in) && SvTYPE(SvRV(*in)) == SVt_PVHV) |
7 |
31 |
38 |
| if (in && *in && SvROK(*in) && SvTYPE(SvRV(*in)) == SVt_PVHV) |
7 |
0 |
7 |
| if (in && *in && SvROK(*in) && SvTYPE(SvRV(*in)) == SVt_PVHV) |
7 |
0 |
7 |
| if (in && *in && SvROK(*in) && SvTYPE(SvRV(*in)) == SVt_PVHV) |
7 |
0 |
7 |
|
| 32 |
7 |
| return (HV *)SvRV(*in); |
| 33 |
31 |
| sess_rv = sv_2mortal(ps_load(aTHX_ c)); /* croaks unconfigured */ |
| 34 |
30 |
| moved = hv_delete((HV *)SvRV(sess_rv), "punk.flash", 10, 0); |
| 35 |
|
| /* |
| 36 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 37 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 38 |
30 |
▶ | if (moved && SvROK(moved) && SvTYPE(SvRV(moved)) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (moved && SvROK(moved) && SvTYPE(SvRV(moved)) == SVt_PVHV) { |
13 |
17 |
30 |
| if (moved && SvROK(moved) && SvTYPE(SvRV(moved)) == SVt_PVHV) { |
13 |
0 |
13 |
| if (moved && SvROK(moved) && SvTYPE(SvRV(moved)) == SVt_PVHV) { |
13 |
0 |
13 |
|
| 39 |
13 |
| inh = (HV *)SvRV(moved); |
| 40 |
13 |
| rv = newRV_inc((SV *)inh); /* moved is mortal; keep the HV */ |
| 41 |
|
| } |
| 42 |
|
| else { |
| 43 |
17 |
| inh = newHV(); |
| 44 |
17 |
| rv = newRV_noinc((SV *)inh); |
| 45 |
|
| } |
| 46 |
30 |
| (void)hv_stores(stash, "punk.flash.in", rv); /* the stash owns rv */ |
| 47 |
30 |
| return inh; |
| 48 |
|
| } |
| 49 |
|
| |
| 50 |
|
| /* the outbound flash inside the session, created on demand (borrowed) */ |
| 51 |
14 |
| static HV *pf_outbound(pTHX_ SV *c) { |
| 52 |
14 |
| SV *sess_rv = sv_2mortal(ps_load(aTHX_ c)); |
| 53 |
14 |
| HV *sess = (HV *)SvRV(sess_rv); |
| 54 |
14 |
| SV **e = hv_fetchs(sess, "punk.flash", 0); |
| 55 |
|
| HV *out; |
| 56 |
|
| /* |
| 57 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 58 |
|
| # uncoverable condition right count:3 class:ignore_covered_err |
| 59 |
|
| # uncoverable condition right count:4 class:ignore_covered_err */ |
| 60 |
14 |
▶ | if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV) |
Branch: 4 branches
| Branch | True | False | Total |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV) |
1 |
13 |
14 |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV) |
1 |
0 |
1 |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV) |
1 |
0 |
1 |
| if (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV) |
1 |
0 |
1 |
|
| 61 |
1 |
| return (HV *)SvRV(*e); |
| 62 |
13 |
| out = newHV(); |
| 63 |
13 |
| (void)hv_stores(sess, "punk.flash", newRV_noinc((SV *)out)); |
| 64 |
13 |
| return out; |
| 65 |
|
| } |
| 66 |
|
| |
| 67 |
|
| #endif /* PUNK_FLASH_H */ |