include/punk/punk_context.h

filter: Statementstmt 94.3% 217 / 230 Branchbran 62.6% 233 / 372 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 74.7% 450 / 602 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_validate.h ↑ Summary xs/sitemap.xs »
1 /* punk_context.h - the per-request context object, in C.
2 *
3 * Punk::Context is a blessed AV whose slots are defined here and nowhere else:
4 * this enum is the whole storage contract. Both faces of it are C - the plain
5 * accessors (env/app/_req/_res/stash_hv/openapi_params/match) and the hot
6 * methods (req/res/stash/param/json/text/html/...) are all XSUBs in
7 * xs/context.xs reading these slots directly, and _build fills them. There is
8 * no Perl-side class builder to keep in step, so lib/Punk/Context.pm is
9 * documentation only.
10 *
11 * Perl headers and punk_response.h (punk_triplet, the PS_* Response slots)
12 * must be in scope before this file.
13 */
14  
15 #ifndef PUNK_CONTEXT_H
16 #define PUNK_CONTEXT_H
17  
18 /* The slot layout. The accessor XSUB's ALIAS indices run in this same order
19 * (see xs/context.xs), which is what lets it map ix straight to a slot. */
20 enum {
21 PCX_ENV = 0,
22 PCX_APP = 1,
23 PCX_REQ = 2,
24 PCX_RES = 3,
25 PCX_STASH = 4,
26 PCX_OPENAPI = 5,
27 PCX_MATCH = 6,
28 PCX_UA = 7, /* memoised $c->ua; the agent itself lives on the app */
29 PCX_REQID = 8, /* Punk::Plugin::RequestId's id, when it is loaded */
30 PCX_AFTER_RES = 9, /* $c->after_response's queue, vivified on first use */
31 PCX_CANON = 10, /* set when the route's body is hashed for an ETag:
32 JSON is then encoded with its keys in order */
33 PCX_T0 = 11 /* Punk::Plugin::Metrics' request start, seconds;
34 negative for a request it does not count */
35 };
36  
37 896064 static AV *pcx_av(pTHX_ SV *self) {
38 896064 ▶ if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVAV) 896064 0 896064
if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVAV) 1 896063 896064
39 1 croak("Punk::Context: not a context object");
40 896063 return (AV *)SvRV(self);
41 }
42  
43 /* the slot value, or NULL when unset */
44 1458710 static SV *pcx_get(pTHX_ AV *av, I32 slot) {
45 1458710 SV **e = av_fetch(av, slot, 0);
46 1458710 ▶ return (e && *e && SvOK(*e)) ? *e : NULL;
Branch: 3 branches
BranchTrueFalseTotal
return (e && *e && SvOK(*e)) ? *e : NULL; 798532 660178 1458710
return (e && *e && SvOK(*e)) ? *e : NULL; 798532 0 798532
return (e && *e && SvOK(*e)) ? *e : NULL; 798532 0 798532
47 }
48  
49 /* JSON for a response body (+1). Keys in hash order, which is whatever this
50 * process happens to hold - unless the route's body is about to be hashed
51 * into an ETag, where an order that differs between workers, hosts and
52 * restarts is a validator that never matches. */
53 105989 static SV *pcx_json(pTHX_ AV *av, SV *data) {
54 105989 SV *canon = pcx_get(aTHX_ av, PCX_CANON);
55 105989 ▶ if (canon && SvTRUE(canon)) {
Branch: 2 branches
BranchTrueFalseTotal
if (canon && SvTRUE(canon)) { 8 105981 105989
if (canon && SvTRUE(canon)) { 8 0 8
56 frj_opts o;
57 8 Zero(&o, 1, frj_opts);
58 8 o.canonical = 1;
59 8 return punk_frj(aTHX)->encode(aTHX_ data, &o);
60 }
61 105981 return punk_frj(aTHX)->encode(aTHX_ data, NULL);
62 }
63  
64 /* the Punk::Response AV at PCX_RES (its slots are the PS_* from
65 * punk_response.h), or NULL when the response was never forced. */
66 220165 static AV *pcx_res_av(pTHX_ AV *av) {
67 220165 SV *r = pcx_get(aTHX_ av, PCX_RES);
68 220165 ▶ return (r && SvROK(r) && SvTYPE(SvRV(r)) == SVt_PVAV) ? (AV *)SvRV(r) : NULL;
Branch: 3 branches
BranchTrueFalseTotal
return (r && SvROK(r) && SvTYPE(SvRV(r)) == SVt_PVAV) ? (AV *)SvRV(r) : NULL; 174 219991 220165
return (r && SvROK(r) && SvTYPE(SvRV(r)) == SVt_PVAV) ? (AV *)SvRV(r) : NULL; 174 0 174
return (r && SvROK(r) && SvTYPE(SvRV(r)) == SVt_PVAV) ? (AV *)SvRV(r) : NULL; 174 0 174
69 }
70  
71 /* the pending response status (PS_STATUS), or 0 */
72 215596 static IV pcx_res_status(pTHX_ AV *res) {
73 215596 ▶ SV **e = res ? av_fetch(res, PS_STATUS, 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV **e = res ? av_fetch(res, PS_STATUS, 0) : NULL; 103 215493 215596
74 215596 ▶ return (e && *e && SvOK(*e)) ? SvIV(*e) : 0;
Branch: 3 branches
BranchTrueFalseTotal
return (e && *e && SvOK(*e)) ? SvIV(*e) : 0; 17 215579 215596
return (e && *e && SvOK(*e)) ? SvIV(*e) : 0; 17 0 17
return (e && *e && SvOK(*e)) ? SvIV(*e) : 0; 16 1 17
75 }
76  
77 /* the pending response header pair-AV (PS_HEADERS), or NULL */
78 145 static AV *pcx_res_headers(pTHX_ AV *res) {
79 145 ▶ SV **e = res ? av_fetch(res, PS_HEADERS, 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV **e = res ? av_fetch(res, PS_HEADERS, 0) : NULL; 145 0 145
80 130 ▶ return (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVAV)
Branch: 3 branches
BranchTrueFalseTotal
return (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVAV) 130 0 130
return (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVAV) 130 0 130
return (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVAV) 130 0 130
81 275 ▶ ? (AV *)SvRV(*e) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (AV *)SvRV(*e) : NULL; 130 15 145
82 }
83  
84 /* Lazily build the sub-object in a slot (Punk::Request / Punk::Response) with
85 * Class->new($arg?), caching it. Returns it borrowed (the slot owns it). */
86 5705 static SV *pcx_force(pTHX_ AV *av, I32 slot, const char *class, SV *arg) {
87 5705 SV *cur = pcx_get(aTHX_ av, slot);
88 5705 ▶ if (cur) return cur;
Branch: 1 branch
BranchTrueFalseTotal
if (cur) return cur; 1653 4052 5705
89 {
90 4052 dSP; SV *obj; int count;
91 4052 ENTER; SAVETMPS;
92 4052 ▶ PUSHMARK(SP); EXTEND(SP, arg ? 2 : 1);
Branch: 4 branches
BranchTrueFalseTotal
PUSHMARK(SP); EXTEND(SP, arg ? 2 : 1); 0 4052 4052
PUSHMARK(SP); EXTEND(SP, arg ? 2 : 1); 3901 151 4052
PUSHMARK(SP); EXTEND(SP, arg ? 2 : 1); 0 4052 4052
PUSHMARK(SP); EXTEND(SP, arg ? 2 : 1); 0 0 0
93 4052 PUSHs(sv_2mortal(newSVpv(class, 0)));
94 4052 ▶ if (arg) PUSHs(arg);
Branch: 1 branch
BranchTrueFalseTotal
if (arg) PUSHs(arg); 3901 151 4052
95 4052 PUTBACK;
96 4052 count = call_method("new", G_SCALAR);
97 4052 SPAGAIN;
98 4052 ▶ obj = count > 0 ? POPs : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
obj = count > 0 ? POPs : &PL_sv_undef; 4052 0 4052
99 4052 SvREFCNT_inc(obj);
100 4052 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 4052 0 4052
101 4052 (void)av_store(av, slot, obj);
102 4052 return obj;
103 }
104 }
105  
106 /* Call $obj->$meth(@argv) in its own stack scope, returning the scalar result
107 * (+1) when want is true, else NULL. argv holds stable SV* captured before any
108 * stack manipulation (EXTEND may move the caller's stack, staling ST()). */
109 138739 static SV *pcx_call_meth(pTHX_ SV *obj, const char *meth,
110 SV **argv, int nargs, int want) {
111 138739 dSP; SV *r = NULL; int count, i;
112 138739 ENTER; SAVETMPS;
113 138739 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 138739 138739
114 138739 ▶ EXTEND(SP, nargs + 1);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, nargs + 1); 138739 0 138739
EXTEND(SP, nargs + 1); 0 138739 138739
115 138739 PUSHs(obj);
116 775853 ▶ for (i = 0; i < nargs; i++) PUSHs(argv[i]);
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < nargs; i++) PUSHs(argv[i]); 637114 138739 775853
117 138739 PUTBACK;
118 138739 ▶ count = call_method(meth, want ? G_SCALAR : G_VOID);
Branch: 1 branch
BranchTrueFalseTotal
count = call_method(meth, want ? G_SCALAR : G_VOID); 137853 886 138739
119 138382 SPAGAIN;
120 138382 ▶ if (want && count > 0) r = SvREFCNT_inc(POPs);
Branch: 2 branches
BranchTrueFalseTotal
if (want && count > 0) r = SvREFCNT_inc(POPs); 137509 873 138382
if (want && count > 0) r = SvREFCNT_inc(POPs); 137509 0 137509
121 138382 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 138382 0 138382
122 138382 return r;
123 }
124  
125 /* The context's own parameter layers, in precedence order: the validated
126 * OpenAPI params (path, then query), then the route captures. Borrowed,
127 * NULL when neither carries the name - the request is the caller's
128 * fallback, because reaching it forces Punk::Request into being. */
129 109545 static SV *pcx_param_local(pTHX_ AV *av, SV *name) {
130 STRLEN nl;
131 109545 const char *n = SvPV_const(name, nl);
132 109545 SV *op = pcx_get(aTHX_ av, PCX_OPENAPI);
133 109545 SV *m = pcx_get(aTHX_ av, PCX_MATCH);
134 109545 ▶ if (op && SvROK(op) && SvTYPE(SvRV(op)) == SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (op && SvROK(op) && SvTYPE(SvRV(op)) == SVt_PVHV) { 20 109525 109545
if (op && SvROK(op) && SvTYPE(SvRV(op)) == SVt_PVHV) { 20 0 20
if (op && SvROK(op) && SvTYPE(SvRV(op)) == SVt_PVHV) { 20 0 20
135 20 HV *oph = (HV *)SvRV(op);
136 static const char *loc[2] = { "path", "query" };
137 int i;
138 40 ▶ for (i = 0; i < 2; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 2; i++) { 33 7 40
139 33 SV **lv = hv_fetch(oph, loc[i], (I32)strlen(loc[i]), 0);
140 33 ▶ if (lv && *lv && SvROK(*lv) && SvTYPE(SvRV(*lv)) == SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (lv && *lv && SvROK(*lv) && SvTYPE(SvRV(*lv)) == SVt_PVHV) { 33 0 33
if (lv && *lv && SvROK(*lv) && SvTYPE(SvRV(*lv)) == SVt_PVHV) { 33 0 33
if (lv && *lv && SvROK(*lv) && SvTYPE(SvRV(*lv)) == SVt_PVHV) { 33 0 33
if (lv && *lv && SvROK(*lv) && SvTYPE(SvRV(*lv)) == SVt_PVHV) { 33 0 33
141 33 SV **v = hv_fetch((HV *)SvRV(*lv), n, (I32)nl, 0);
142 33 ▶ if (v) return *v ? *v : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
if (v) return *v ? *v : &PL_sv_undef; 13 20 33
if (v) return *v ? *v : &PL_sv_undef; 13 0 13
143 }
144 }
145 }
146 109532 ▶ if (m && SvROK(m) && SvTYPE(SvRV(m)) == SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (m && SvROK(m) && SvTYPE(SvRV(m)) == SVt_PVHV) { 109532 0 109532
if (m && SvROK(m) && SvTYPE(SvRV(m)) == SVt_PVHV) { 109532 0 109532
if (m && SvROK(m) && SvTYPE(SvRV(m)) == SVt_PVHV) { 109532 0 109532
147 109532 SV **cap = hv_fetchs((HV *)SvRV(m), "captures", 0);
148 109532 ▶ if (cap && *cap && SvROK(*cap) && SvTYPE(SvRV(*cap)) == SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (cap && *cap && SvROK(*cap) && SvTYPE(SvRV(*cap)) == SVt_PVHV) { 109532 0 109532
if (cap && *cap && SvROK(*cap) && SvTYPE(SvRV(*cap)) == SVt_PVHV) { 109532 0 109532
if (cap && *cap && SvROK(*cap) && SvTYPE(SvRV(*cap)) == SVt_PVHV) { 109532 0 109532
if (cap && *cap && SvROK(*cap) && SvTYPE(SvRV(*cap)) == SVt_PVHV) { 109532 0 109532
149 109532 SV **v = hv_fetch((HV *)SvRV(*cap), n, (I32)nl, 0);
150 109532 ▶ if (v) return *v ? *v : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
if (v) return *v ? *v : &PL_sv_undef; 107101 2431 109532
if (v) return *v ? *v : &PL_sv_undef; 107101 0 107101
151 }
152 }
153 2431 return NULL;
154 }
155  
156 /* The lazy Punk::Request for this context, borrowed. */
157 2491 static SV *pcx_req(pTHX_ AV *av) {
158 2491 return pcx_force(aTHX_ av, PCX_REQ, "Punk::Request",
159 pcx_get(aTHX_ av, PCX_ENV));
160 }
161  
162 /* $c->param($name): the layers above, else the request (query, then form
163 * body). Owned (+1), NULL when nothing carries the name. */
164 109545 static SV *pcx_param(pTHX_ AV *av, SV *name) {
165 109545 SV *found = pcx_param_local(aTHX_ av, name);
166 SV *argv[1];
167 SV *r;
168 109545 ▶ if (found) return newSVsv(found);
Branch: 1 branch
BranchTrueFalseTotal
if (found) return newSVsv(found); 107114 2431 109545
169 2431 argv[0] = name;
170 2431 r = pcx_call_meth(aTHX_ pcx_req(aTHX_ av), "param", argv, 1, 1);
171 2431 ▶ if (r && SvOK(r)) return r;
Branch: 2 branches
BranchTrueFalseTotal
if (r && SvOK(r)) return r; 2431 0 2431
if (r && SvOK(r)) return r; 209 2222 2431
172 2222 ▶ if (r) SvREFCNT_dec(r);
Branch: 1 branch
BranchTrueFalseTotal
if (r) SvREFCNT_dec(r); 2222 0 2222
173 2222 return NULL;
174 }
175  
176 /* Every parameter the context can see, stacked in the same precedence
177 * pcx_param resolves one by: the request's merged table underneath, then
178 * the route captures, then the validated OpenAPI query and path. +1. */
179 14 static HV *pcx_params_merged(pTHX_ AV *av) {
180 14 HV *out = newHV();
181 14 SV *rp = pcx_call_meth(aTHX_ pcx_req(aTHX_ av), "params", NULL, 0, 1);
182 14 SV *m = pcx_get(aTHX_ av, PCX_MATCH);
183 14 SV *op = pcx_get(aTHX_ av, PCX_OPENAPI);
184 14 pq_overlay(aTHX_ out, rp);
185 14 ▶ if (rp) SvREFCNT_dec(rp);
Branch: 1 branch
BranchTrueFalseTotal
if (rp) SvREFCNT_dec(rp); 14 0 14
186 14 ▶ if (m && SvROK(m) && SvTYPE(SvRV(m)) == SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (m && SvROK(m) && SvTYPE(SvRV(m)) == SVt_PVHV) { 14 0 14
if (m && SvROK(m) && SvTYPE(SvRV(m)) == SVt_PVHV) { 14 0 14
if (m && SvROK(m) && SvTYPE(SvRV(m)) == SVt_PVHV) { 14 0 14
187 14 SV **cap = hv_fetchs((HV *)SvRV(m), "captures", 0);
188 14 ▶ if (cap) pq_overlay(aTHX_ out, *cap);
Branch: 1 branch
BranchTrueFalseTotal
if (cap) pq_overlay(aTHX_ out, *cap); 14 0 14
189 }
190 14 ▶ if (op && SvROK(op) && SvTYPE(SvRV(op)) == SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (op && SvROK(op) && SvTYPE(SvRV(op)) == SVt_PVHV) { 3 11 14
if (op && SvROK(op) && SvTYPE(SvRV(op)) == SVt_PVHV) { 3 0 3
if (op && SvROK(op) && SvTYPE(SvRV(op)) == SVt_PVHV) { 3 0 3
191 3 HV *oph = (HV *)SvRV(op);
192 3 SV **qry = hv_fetchs(oph, "query", 0);
193 3 SV **pth = hv_fetchs(oph, "path", 0);
194 3 ▶ if (qry) pq_overlay(aTHX_ out, *qry);
Branch: 1 branch
BranchTrueFalseTotal
if (qry) pq_overlay(aTHX_ out, *qry); 3 0 3
195 3 ▶ if (pth) pq_overlay(aTHX_ out, *pth);
Branch: 1 branch
BranchTrueFalseTotal
if (pth) pq_overlay(aTHX_ out, *pth); 3 0 3
196 }
197 14 return out;
198 }
199  
200 /* does the blessed ref have method $meth? (a ->can without the call) */
201 /* Is this exactly a Punk::Future? A cached stash pointer compare, so the two
202 * dispatch paths can skip the ->can and ->isa probes they would otherwise pay
203 * per request. Deliberately not sv_derived_from: a subclass answers no and
204 * takes the general duck-typed path, which is the safe way round.
205 *
206 * pcx_pf_get1 is its companion - the value of a settled future, awaiting a
207 * pending one and croaking exactly as ->get does. It is defined in
208 * punk_future.h, which the unity build includes after this file. */
209 static HV *PCX_PF_STASH = NULL;
210 32 static int pcx_is_punk_future(pTHX_ SV *sv) {
211 32 ▶ if (!(SvROK(sv) && SvOBJECT(SvRV(sv)))) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!(SvROK(sv) && SvOBJECT(SvRV(sv)))) return 0; 32 0 32
if (!(SvROK(sv) && SvOBJECT(SvRV(sv)))) return 0; 0 32 32
212 32 ▶ if (!PCX_PF_STASH) PCX_PF_STASH = gv_stashpvs("Punk::Future", 0);
Branch: 1 branch
BranchTrueFalseTotal
if (!PCX_PF_STASH) PCX_PF_STASH = gv_stashpvs("Punk::Future", 0); 10 22 32
213 32 ▶ return PCX_PF_STASH && SvSTASH(SvRV(sv)) == PCX_PF_STASH;
Branch: 2 branches
BranchTrueFalseTotal
return PCX_PF_STASH && SvSTASH(SvRV(sv)) == PCX_PF_STASH; 32 0 32
return PCX_PF_STASH && SvSTASH(SvRV(sv)) == PCX_PF_STASH; 5 27 32
214 }
215 static SV *pcx_pf_get1(pTHX_ SV *f);
216  
217 745 static int pcx_can(pTHX_ SV *obj, const char *meth) {
218 745 ▶ HV *stash = (SvROK(obj) && SvOBJECT(SvRV(obj))) ? SvSTASH(SvRV(obj)) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
HV *stash = (SvROK(obj) && SvOBJECT(SvRV(obj))) ? SvSTASH(SvRV(obj)) : NULL; 745 0 745
HV *stash = (SvROK(obj) && SvOBJECT(SvRV(obj))) ? SvSTASH(SvRV(obj)) : NULL; 745 0 745
219 745 ▶ return (stash && gv_fetchmethod_autoload(stash, meth, 0)) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
return (stash && gv_fetchmethod_autoload(stash, meth, 0)) ? 1 : 0; 745 0 745
return (stash && gv_fetchmethod_autoload(stash, meth, 0)) ? 1 : 0; 724 21 745
220 }
221  
222 /* $h->($c, $resp) trapping a die; result (+1) or NULL, *died set. */
223 721 static SV *pcx_call2(pTHX_ SV *h, SV *a, SV *b, int *died) {
224 721 dSP; SV *r; int count;
225 721 ENTER; SAVETMPS;
226 721 ▶ PUSHMARK(SP); EXTEND(SP, 2); PUSHs(a); PUSHs(b); PUTBACK;
Branch: 2 branches
BranchTrueFalseTotal
PUSHMARK(SP); EXTEND(SP, 2); PUSHs(a); PUSHs(b); PUTBACK; 0 721 721
PUSHMARK(SP); EXTEND(SP, 2); PUSHs(a); PUSHs(b); PUTBACK; 0 721 721
227 721 count = call_sv(h, G_SCALAR | G_EVAL);
228 721 SPAGAIN;
229 721 ▶ r = count > 0 ? SvREFCNT_inc(POPs) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
r = count > 0 ? SvREFCNT_inc(POPs) : NULL; 721 0 721
230 721 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 593 128 721
231 721 ▶ *died = SvTRUE(ERRSV) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
*died = SvTRUE(ERRSV) ? 1 : 0; 721 0 721
232 721 return r;
233 }
234  
235 /* Is $ret already a PSGI triplet [ $status, \@headers, \@body ]? */
236 437961 static int pcx_is_triplet(pTHX_ SV *ret) {
237 AV *a;
238 SV **s, **h;
239 437961 ▶ if (!SvROK(ret) || SvTYPE(SvRV(ret)) != SVt_PVAV) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(ret) || SvTYPE(SvRV(ret)) != SVt_PVAV) return 0; 437786 175 437961
if (!SvROK(ret) || SvTYPE(SvRV(ret)) != SVt_PVAV) return 0; 105092 332694 437786
240 332694 a = (AV *)SvRV(ret);
241 332694 ▶ if (av_len(a) != 2) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(a) != 2) return 0; 12 332682 332694
242 332682 s = av_fetch(a, 0, 0);
243 332682 h = av_fetch(a, 1, 0);
244 332682 ▶ if (!(s && *s && SvOK(*s) && !SvROK(*s))) return 0;
Branch: 4 branches
BranchTrueFalseTotal
if (!(s && *s && SvOK(*s) && !SvROK(*s))) return 0; 332682 0 332682
if (!(s && *s && SvOK(*s) && !SvROK(*s))) return 0; 332682 0 332682
if (!(s && *s && SvOK(*s) && !SvROK(*s))) return 0; 332682 0 332682
if (!(s && *s && SvOK(*s) && !SvROK(*s))) return 0; 0 332682 332682
245 332682 ▶ if (!(h && *h && SvROK(*h) && SvTYPE(SvRV(*h)) == SVt_PVAV)) return 0;
Branch: 4 branches
BranchTrueFalseTotal
if (!(h && *h && SvROK(*h) && SvTYPE(SvRV(*h)) == SVt_PVAV)) return 0; 332682 0 332682
if (!(h && *h && SvROK(*h) && SvTYPE(SvRV(*h)) == SVt_PVAV)) return 0; 332682 0 332682
if (!(h && *h && SvROK(*h) && SvTYPE(SvRV(*h)) == SVt_PVAV)) return 0; 332680 2 332682
if (!(h && *h && SvROK(*h) && SvTYPE(SvRV(*h)) == SVt_PVAV)) return 0; 0 332680 332680
246 /* the status Punk itself built is an integer: read it as one rather
247 * than upgrade it to a string on every response */
248 332680 ▶ if (SvIOK(*s) && !SvPOK(*s)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(*s) && !SvPOK(*s)) { 332679 1 332680
if (SvIOK(*s) && !SvPOK(*s)) { 332679 0 332679
249 332679 IV v = SvIVX(*s);
250 332679 ▶ return v >= 100 && v <= 599;
Branch: 2 branches
BranchTrueFalseTotal
return v >= 100 && v <= 599; 332677 2 332679
return v >= 100 && v <= 599; 332676 1 332677
251 }
252 {
253 STRLEN l;
254 1 const char *p = SvPV_const(*s, l);
255 0 ▶ return (l == 3 && p[0] >= '1' && p[0] <= '5'
Branch: 2 branches
BranchTrueFalseTotal
return (l == 3 && p[0] >= '1' && p[0] <= '5' 0 0 0
return (l == 3 && p[0] >= '1' && p[0] <= '5' 0 0 0
256 1 ▶ && isDIGIT(p[1]) && isDIGIT(p[2]));
Branch: 3 branches
BranchTrueFalseTotal
&& isDIGIT(p[1]) && isDIGIT(p[2])); 0 1 1
&& isDIGIT(p[1]) && isDIGIT(p[2])); 0 0 0
&& isDIGIT(p[1]) && isDIGIT(p[2])); 0 0 0
257 }
258 }
259  
260 /* A triplet in everything but its status: an integer first, then a headers
261 * arrayref of name and value pairs whose names are words, then a body that
262 * is an arrayref, a handle or an object. Narrow on purpose, because a
263 * handler may return three things that are simply data - [ 1, 2, 3 ],
264 * [ 'series', \@xs, \@ys ], [ 5, [ 1, 2 ], [ 3, 4 ] ] - and those must
265 * stay data. */
266 105099 static int pcx_triplet_shaped(pTHX_ SV *ret) {
267 AV *a, *hav;
268 SV **s, **h, **b;
269 SSize_t i, n;
270 105099 ▶ if (!SvROK(ret) || SvTYPE(SvRV(ret)) != SVt_PVAV) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(ret) || SvTYPE(SvRV(ret)) != SVt_PVAV) return 0; 105099 0 105099
if (!SvROK(ret) || SvTYPE(SvRV(ret)) != SVt_PVAV) return 0; 105081 18 105099
271 18 a = (AV *)SvRV(ret);
272 18 ▶ if (av_len(a) != 2) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(a) != 2) return 0; 12 6 18
273 6 s = av_fetch(a, 0, 0);
274 6 h = av_fetch(a, 1, 0);
275 6 b = av_fetch(a, 2, 0);
276 6 ▶ if (!(h && *h && SvROK(*h) && SvTYPE(SvRV(*h)) == SVt_PVAV)) return 0;
Branch: 4 branches
BranchTrueFalseTotal
if (!(h && *h && SvROK(*h) && SvTYPE(SvRV(*h)) == SVt_PVAV)) return 0; 6 0 6
if (!(h && *h && SvROK(*h) && SvTYPE(SvRV(*h)) == SVt_PVAV)) return 0; 6 0 6
if (!(h && *h && SvROK(*h) && SvTYPE(SvRV(*h)) == SVt_PVAV)) return 0; 4 2 6
if (!(h && *h && SvROK(*h) && SvTYPE(SvRV(*h)) == SVt_PVAV)) return 0; 0 4 4
277 4 ▶ if (!(b && *b && SvROK(*b))) return 0;
Branch: 3 branches
BranchTrueFalseTotal
if (!(b && *b && SvROK(*b))) return 0; 4 0 4
if (!(b && *b && SvROK(*b))) return 0; 4 0 4
if (!(b && *b && SvROK(*b))) return 0; 0 4 4
278 4 ▶ if (!(SvTYPE(SvRV(*b)) == SVt_PVAV || SvTYPE(SvRV(*b)) == SVt_PVGV
Branch: 2 branches
BranchTrueFalseTotal
if (!(SvTYPE(SvRV(*b)) == SVt_PVAV || SvTYPE(SvRV(*b)) == SVt_PVGV 0 4 4
if (!(SvTYPE(SvRV(*b)) == SVt_PVAV || SvTYPE(SvRV(*b)) == SVt_PVGV 0 0 0
279 0 ▶ || SvOBJECT(SvRV(*b)))) return 0;
Branch: 1 branch
BranchTrueFalseTotal
|| SvOBJECT(SvRV(*b)))) return 0; 0 0 0
280 /* An integer, asked WITHOUT numifying it: this value may yet be encoded
281 * as data, and SvIV or SvNV here would leave a number flag on the
282 * caller's scalar that changes how it is written - a 1 became 1.0. */
283 4 ▶ if (!(s && *s && SvOK(*s) && !SvROK(*s))) return 0;
Branch: 4 branches
BranchTrueFalseTotal
if (!(s && *s && SvOK(*s) && !SvROK(*s))) return 0; 4 0 4
if (!(s && *s && SvOK(*s) && !SvROK(*s))) return 0; 4 0 4
if (!(s && *s && SvOK(*s) && !SvROK(*s))) return 0; 4 0 4
if (!(s && *s && SvOK(*s) && !SvROK(*s))) return 0; 0 4 4
284 4 ▶ if (!SvIOK(*s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvIOK(*s)) { 1 3 4
285 1 STRLEN sl, si = 0;
286 const char *sp;
287 1 ▶ if (!SvPOK(*s)) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!SvPOK(*s)) return 0; 0 1 1
288 1 sp = SvPVX_const(*s);
289 1 sl = SvCUR(*s);
290 1 ▶ if (sl && sp[0] == '-') si = 1;
Branch: 2 branches
BranchTrueFalseTotal
if (sl && sp[0] == '-') si = 1; 1 0 1
if (sl && sp[0] == '-') si = 1; 0 1 1
291 1 ▶ if (si == sl) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (si == sl) return 0; 0 1 1
292 1 ▶ for (; si < sl; si++) if (!isDIGIT(sp[si])) return 0;
Branch: 2 branches
BranchTrueFalseTotal
for (; si < sl; si++) if (!isDIGIT(sp[si])) return 0; 1 0 1
for (; si < sl; si++) if (!isDIGIT(sp[si])) return 0; 1 0 1
293 }
294 3 hav = (AV *)SvRV(*h);
295 3 n = av_len(hav) + 1;
296 3 ▶ if (n == 0 || (n & 1)) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (n == 0 || (n & 1)) return 0; 3 0 3
if (n == 0 || (n & 1)) return 0; 0 3 3
297 6 ▶ for (i = 0; i < n; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i += 2) { 4 2 6
298 4 SV **k = av_fetch(hav, i, 0);
299 4 ▶ if (!(k && *k && SvOK(*k) && !SvROK(*k)) || looks_like_number(*k))
Branch: 5 branches
BranchTrueFalseTotal
if (!(k && *k && SvOK(*k) && !SvROK(*k)) || looks_like_number(*k)) 4 0 4
if (!(k && *k && SvOK(*k) && !SvROK(*k)) || looks_like_number(*k)) 4 0 4
if (!(k && *k && SvOK(*k) && !SvROK(*k)) || looks_like_number(*k)) 4 0 4
if (!(k && *k && SvOK(*k) && !SvROK(*k)) || looks_like_number(*k)) 4 0 4
if (!(k && *k && SvOK(*k) && !SvROK(*k)) || looks_like_number(*k)) 1 3 4
300 1 return 0;
301 }
302 2 return 1;
303 }
304  
305 /* Coerce a handler return into a PSGI triplet: a triplet passes through, a
306 * Punk::Response finalizes, a Future is awaited and re-coerced, anything else
307 * is JSON-encoded (folding in the context's pending status/headers). +1. */
308 /* The 500 envelope, or $on_error's own response. Defined in punk_serve.h,
309 * which is included later because it is the dispatcher and needs everything;
310 * it calls punk_coerce in turn, so one of the two has to be declared ahead of
311 * the other. Same arrangement as pk_after_res below. */
312 static SV *punk_handle_error(pTHX_ SV *c, SV *err, SV *on_error);
313  
314 218333 static SV *punk_coerce(pTHX_ SV *c, SV *ret) {
315 /* a coderef is a PSGI streaming / delayed-response body (SSE uses this on
316 * a psgi.streaming server) - hand it straight to the server */
317 218333 ▶ if (SvROK(ret) && SvTYPE(SvRV(ret)) == SVt_PVCV) return SvREFCNT_inc(ret);
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(ret) && SvTYPE(SvRV(ret)) == SVt_PVCV) return SvREFCNT_inc(ret); 218333 0 218333
if (SvROK(ret) && SvTYPE(SvRV(ret)) == SVt_PVCV) return SvREFCNT_inc(ret); 14 218319 218333
318 218319 ▶ if (pcx_is_triplet(aTHX_ ret)) return SvREFCNT_inc(ret);
Branch: 1 branch
BranchTrueFalseTotal
if (pcx_is_triplet(aTHX_ ret)) return SvREFCNT_inc(ret); 113220 105099 218319
319 105099 ▶ if (pcx_triplet_shaped(aTHX_ ret))
Branch: 1 branch
BranchTrueFalseTotal
if (pcx_triplet_shaped(aTHX_ ret)) 2 105097 105099
320 /* [ $something, \@headers, \@body ] where $something is not a
321 * status. That is a response somebody built wrongly, and encoding it
322 * as data would publish its headers - a Set-Cookie among them - in
323 * the body of a 200. An error says so instead. */
324 2 return punk_handle_error(aTHX_ c, sv_2mortal(newSVpvs(
325 "Punk: a handler returned a response whose status is not a "
326 "number from 100 to 599")), NULL);
327 105097 ▶ if (SvROK(ret) && SvOBJECT(SvRV(ret))) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(ret) && SvOBJECT(SvRV(ret))) { 105097 0 105097
if (SvROK(ret) && SvOBJECT(SvRV(ret))) { 21 105076 105097
328 /* One of ours: read the value in C rather than walking @ISA for
329 * Punk::Response and then dispatching ->get through perl. */
330 21 ▶ if (pcx_is_punk_future(aTHX_ ret)) {
Branch: 1 branch
BranchTrueFalseTotal
if (pcx_is_punk_future(aTHX_ ret)) { 0 21 21
331 0 SV *got = pcx_pf_get1(aTHX_ ret);
332 0 ▶ SV *r = punk_coerce(aTHX_ c, got ? got : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
SV *r = punk_coerce(aTHX_ c, got ? got : &PL_sv_undef); 0 0 0
333 0 ▶ if (got) SvREFCNT_dec(got);
Branch: 1 branch
BranchTrueFalseTotal
if (got) SvREFCNT_dec(got); 0 0 0
334 0 return r;
335 }
336 21 ▶ if (sv_derived_from(ret, "Punk::Response"))
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(ret, "Punk::Response")) 11 10 21
337 {
338 /* canonical JSON on an etag route, as pcx_json does for $c->json */
339 11 SV *canon = pcx_get(aTHX_ pcx_av(aTHX_ c), PCX_CANON);
340 SV *argv[1];
341 11 ▶ argv[0] = (canon && SvTRUE(canon)) ? &PL_sv_yes : &PL_sv_no;
Branch: 2 branches
BranchTrueFalseTotal
argv[0] = (canon && SvTRUE(canon)) ? &PL_sv_yes : &PL_sv_no; 0 11 11
argv[0] = (canon && SvTRUE(canon)) ? &PL_sv_yes : &PL_sv_no; 0 0 0
342 11 return pcx_call_meth(aTHX_ ret, "finalize", argv, 1, 1);
343 }
344 /* An XML document, before the on_ready probe below (which walks the
345 * stash of every object) and before the JSON fallthrough (which would
346 * encode it as the blessed reference it is). This is also what makes
347 * respond_to(xml => sub { $doc }) answer application/xml: respond_to
348 * sets no type of its own, it returns whatever its branch returned. */
349 10 ▶ if (punk_xml_is(aTHX_ ret)) {
Branch: 1 branch
BranchTrueFalseTotal
if (punk_xml_is(aTHX_ ret)) { 10 0 10
350 10 AV *res = pcx_res_av(aTHX_ pcx_av(aTHX_ c));
351 10 IV st = pcx_res_status(aTHX_ res);
352 10 SV *err = NULL;
353 10 SV *bytes = punk_xml_bytes(aTHX_ ret, &err);
354 /* write reports a refusal rather than croaking, which is what
355 * lets this be a branch: punk_coerce runs from loop callbacks
356 * with no eval around them, so a croak here would leave Punk
357 * instead of becoming a response. */
358 10 ▶ if (!bytes)
Branch: 1 branch
BranchTrueFalseTotal
if (!bytes) 0 10 10
359 0 return punk_handle_error(aTHX_ c,
360 0 ▶ err ? err : sv_2mortal(newSVpvs("Punk: xml")), NULL);
Branch: 1 branch
BranchTrueFalseTotal
err ? err : sv_2mortal(newSVpvs("Punk: xml")), NULL); 0 0 0
361 10 ▶ if (!st) st = 200;
Branch: 1 branch
BranchTrueFalseTotal
if (!st) st = 200; 10 0 10
362 15 ▶ return punk_triplet(aTHX_ st,
Branch: 1 branch
BranchTrueFalseTotal
return punk_triplet(aTHX_ st, 5 5 10
363 sv_2mortal(newSVpvs(PK_XML_CT)),
364 5 bytes, res ? pcx_res_headers(aTHX_ res) : NULL);
365 }
366 0 ▶ if (pcx_can(aTHX_ ret, "on_ready")) {
Branch: 1 branch
BranchTrueFalseTotal
if (pcx_can(aTHX_ ret, "on_ready")) { 0 0 0
367 0 SV *got = pcx_call_meth(aTHX_ ret, "get", NULL, 0, 1);
368 0 ▶ SV *r = punk_coerce(aTHX_ c, got ? got : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
SV *r = punk_coerce(aTHX_ c, got ? got : &PL_sv_undef); 0 0 0
369 0 ▶ if (got) SvREFCNT_dec(got);
Branch: 1 branch
BranchTrueFalseTotal
if (got) SvREFCNT_dec(got); 0 0 0
370 0 return r;
371 }
372 }
373 {
374 105076 AV *res = pcx_res_av(aTHX_ pcx_av(aTHX_ c));
375 105076 IV st = pcx_res_status(aTHX_ res);
376 105076 SV *bytes = pcx_json(aTHX_ pcx_av(aTHX_ c), ret);
377 105076 ▶ if (!st) st = 200;
Branch: 1 branch
BranchTrueFalseTotal
if (!st) st = 200; 105071 5 105076
378 105081 ▶ return punk_triplet_ct(aTHX_ st, "application/json", 16,
Branch: 1 branch
BranchTrueFalseTotal
return punk_triplet_ct(aTHX_ st, "application/json", 16, 5 105071 105076
379 5 bytes, res ? pcx_res_headers(aTHX_ res) : NULL);
380 }
381 }
382  
383 /* The after_response phase: scheduled here because this is the one place a
384 * final response exists. Defined in punk_afterres.h, which is included after
385 * hm_abi.h because the loop timer is one of the three ways it defers - the
386 * pcg_check / pi_check arrangement. */
387 static void pk_after_res(pTHX_ SV *c, SV *resp);
388  
389 /* Finish a response: coerce if needed, run the after-dispatch hooks (each may
390 * replace the triplet), and blank the body on HEAD. +1. */
391 218973 static SV *punk_deliver(pTHX_ SV *c, SV *resp, int is_head, AV *after) {
392 437935 SV *r = pcx_is_triplet(aTHX_ resp) ? SvREFCNT_inc(resp)
393 218973 ▶ : punk_coerce(aTHX_ c, resp);
Branch: 1 branch
BranchTrueFalseTotal
: punk_coerce(aTHX_ c, resp); 218962 11 218973
394 /* a streaming coderef has no triplet to mutate: skip after-hooks and HEAD */
395 218973 ▶ if (SvROK(r) && SvTYPE(SvRV(r)) == SVt_PVCV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(r) && SvTYPE(SvRV(r)) == SVt_PVCV) { 218973 0 218973
if (SvROK(r) && SvTYPE(SvRV(r)) == SVt_PVCV) { 7 218966 218973
396 7 ▶ if (PK_OBS_WANT_RES) pk_obs_fire_res(aTHX_ c, r);
Branch: 1 branch
BranchTrueFalseTotal
if (PK_OBS_WANT_RES) pk_obs_fire_res(aTHX_ c, r); 1 6 7
397 7 pk_after_res(aTHX_ c, r);
398 7 return r;
399 }
400 218966 ▶ if (after) {
Branch: 1 branch
BranchTrueFalseTotal
if (after) { 218966 0 218966
401 218966 SSize_t i, n = av_len(after) + 1;
402 219635 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 669 218966 219635
403 669 SV **hp = av_fetch(after, i, 0);
404 669 int died = 0;
405 SV *hr;
406 669 ▶ if (!hp || !*hp) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!hp || !*hp) continue; 669 0 669
if (!hp || !*hp) continue; 0 669 669
407 669 hr = pcx_call2(aTHX_ *hp, c, r, &died);
408 669 ▶ if (!died && hr && pcx_is_triplet(aTHX_ hr)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!died && hr && pcx_is_triplet(aTHX_ hr)) { 669 0 669
if (!died && hr && pcx_is_triplet(aTHX_ hr)) { 669 0 669
if (!died && hr && pcx_is_triplet(aTHX_ hr)) { 494 175 669
409 494 SvREFCNT_dec(r);
410 494 r = SvREFCNT_inc(hr);
411 }
412 669 ▶ if (hr) SvREFCNT_dec(hr);
Branch: 1 branch
BranchTrueFalseTotal
if (hr) SvREFCNT_dec(hr); 669 0 669
413 }
414 }
415 218966 ▶ if (is_head && SvROK(r) && SvTYPE(SvRV(r)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (is_head && SvROK(r) && SvTYPE(SvRV(r)) == SVt_PVAV) { 17 218949 218966
if (is_head && SvROK(r) && SvTYPE(SvRV(r)) == SVt_PVAV) { 17 0 17
if (is_head && SvROK(r) && SvTYPE(SvRV(r)) == SVt_PVAV) { 17 0 17
416 17 AV *ra = (AV *)SvRV(r);
417 17 SV **b = av_fetch(ra, 2, 0);
418 17 ▶ if (b && *b && SvROK(*b) && SvTYPE(SvRV(*b)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (b && *b && SvROK(*b) && SvTYPE(SvRV(*b)) == SVt_PVAV) { 17 0 17
if (b && *b && SvROK(*b) && SvTYPE(SvRV(*b)) == SVt_PVAV) { 17 0 17
if (b && *b && SvROK(*b) && SvTYPE(SvRV(*b)) == SVt_PVAV) { 17 0 17
if (b && *b && SvROK(*b) && SvTYPE(SvRV(*b)) == SVt_PVAV) { 17 0 17
419 17 AV *empty = newAV();
420 17 av_push(empty, newSVpvs(""));
421 17 (void)av_store(ra, 2, newRV_noinc((SV *)empty));
422 }
423 }
424 /* The C ABI's response observers. Here rather than in the dispatcher
425 * because this is the ONE place a final triplet is produced: the
426 * synchronous path reaches it through punk_finish_c, and every
427 * asynchronous completion reaches it from punk_compile.h when the future
428 * settles - so an observer sees the response that was actually sent, at
429 * the moment it was, and sees it exactly once either way. The four
430 * dispatcher exits that never come through here fire it themselves. */
431 218966 ▶ if (PK_OBS_WANT_RES) pk_obs_fire_res(aTHX_ c, r);
Branch: 1 branch
BranchTrueFalseTotal
if (PK_OBS_WANT_RES) pk_obs_fire_res(aTHX_ c, r); 175 218791 218966
432 218966 pk_after_res(aTHX_ c, r);
433 218966 return r;
434 }
435  
436 /* Is this a same-origin relative path - somewhere on this site, and nowhere
437 * else? Backs $c->safe_path, the guard for a redirect destination that came
438 * out of the request (?to=, ?return=, ?next=).
439 *
440 * Checking for a leading '/' and no leading '//' is NOT enough, because the
441 * browser does not read the string byte for byte the way this does:
442 *
443 * - it removes every TAB, CR and LF from a URL before parsing it, so
444 * "/<TAB>/evil.example" is parsed as "//evil.example";
445 * - under a special scheme it treats '\' as '/', so "/\evil.example" is
446 * protocol-relative too.
447 *
448 * Either one leaves the site, which is why this refuses the whole class -
449 * every C0 control, DEL, and a backslash anywhere - rather than trying to
450 * enumerate the bytes some parser somewhere might drop. The same rule (and
451 * the same reasoning) as Punk::OAuth2's same_origin_path, which is where it
452 * was learned the expensive way: CVE-2026-75628. A path that genuinely wants
453 * one of these spells it percent-encoded. */
454 19 static int pk_same_origin_path(pTHX_ SV *path) {
455 STRLEN n, i;
456 const char *p;
457 19 ▶ if (!path || !SvOK(path)) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!path || !SvOK(path)) return 0; 19 0 19
if (!path || !SvOK(path)) return 0; 0 19 19
458 19 p = SvPV_const(path, n);
459 19 ▶ if (n < 1 || p[0] != '/') return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (n < 1 || p[0] != '/') return 0; 18 1 19
if (n < 1 || p[0] != '/') return 0; 3 15 18
460 15 ▶ if (n >= 2 && p[1] == '/') return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (n >= 2 && p[1] == '/') return 0; 14 1 15
if (n >= 2 && p[1] == '/') return 0; 2 12 14
461 61 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 55 6 61
462 55 const unsigned char ch = (unsigned char)p[i];
463 55 ▶ if (ch < 0x20 || ch == 0x7f || ch == '\\') return 0;
Branch: 3 branches
BranchTrueFalseTotal
if (ch < 0x20 || ch == 0x7f || ch == '\\') return 0; 51 4 55
if (ch < 0x20 || ch == 0x7f || ch == '\\') return 0; 50 1 51
if (ch < 0x20 || ch == 0x7f || ch == '\\') return 0; 2 48 50
464 }
465 6 return 1;
466 }
467  
468 #endif /* PUNK_CONTEXT_H */
« include/punk/punk_validate.h ↑ Summary xs/sitemap.xs »