include/punk/punk_multipart.h

filter: Statementstmt 100% 25 / 25 Branchbran 81.2% 26 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 89.4% 51 / 57 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_proxy.h ↑ Summary include/punk/punk_asset.h »
1 /* punk_multipart.h - multipart/form-data parsing, in C.
2 *
3 * Punk::Request->form() gains a multipart branch beside its urlencoded one:
4 * field parts merge into the form hash (so $c->param sees them), file parts
5 * become Punk::Upload objects collected in PQ_UPLOADS. Boundary and line
6 * scanning use Perl's ninstr (portable substring search). Upload content is
7 * held in memory this cut.
8 *
9 * Must be included after punk_request.h (the PQ_* slots).
10 */
11  
12 #ifndef PUNK_MULTIPART_H
13 #define PUNK_MULTIPART_H
14  
15 /* add a value under a key, promoting a repeat to an arrayref (as the
16 * urlencoded parser does), without decoding */
17 1023 static void pq_hv_add(pTHX_ HV *out, const char *k, STRLEN kl, SV *val) {
18 1023 SV *key = sv_2mortal(newSVpvn(k, kl));
19 1023 HE *he = hv_fetch_ent(out, key, 0, 0);
20 1023 ▶ if (he) {
Branch: 1 branch
BranchTrueFalseTotal
if (he) { 38 985 1023
21 38 SV *have = HeVAL(he);
22 AV *list;
23 38 ▶ if (SvROK(have) && SvTYPE(SvRV(have)) == SVt_PVAV) list = (AV *)SvRV(have); /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(have) && SvTYPE(SvRV(have)) == SVt_PVAV) list = (AV *)SvRV(have); /* # uncoverable condition right count:1 class:ignore_covered_err */ 38 0 38
if (SvROK(have) && SvTYPE(SvRV(have)) == SVt_PVAV) list = (AV *)SvRV(have); /* # uncoverable condition right count:1 class:ignore_covered_err */ 32 6 38
24 else {
25 6 list = newAV();
26 6 av_push(list, newSVsv(have));
27 6 (void)hv_store_ent(out, key, newRV_noinc((SV *)list), 0);
28 }
29 38 av_push(list, val);
30 }
31 985 else (void)hv_store_ent(out, key, val, 0);
32 1023 }
33  
34 /* the value of a header parameter: name=value or name="value". Returns a
35 * pointer into s (with *vl set) or NULL. */
36 8148 static const char *pq_hdr_param(const char *s, STRLEN sl, const char *p,
37 STRLEN *vl) {
38 8148 STRLEN pl = strlen(p), i;
39 136417 ▶ for (i = 0; i + pl + 1 <= sl; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i + pl + 1 <= sl; i++) { 134558 1859 136417
40 /*
41 # uncoverable condition left count:1 class:ignore_covered_err
42 # uncoverable condition left count:3 class:ignore_covered_err
43 # uncoverable condition left count:4 class:ignore_covered_err
44 # uncoverable condition right count:6 class:ignore_covered_err */
45 134558 ▶ if ((i == 0 || s[i-1] == ' ' || s[i-1] == ';' || s[i-1] == '\t')
Branch: 4 branches
BranchTrueFalseTotal
if ((i == 0 || s[i-1] == ' ' || s[i-1] == ';' || s[i-1] == '\t') 126410 8148 134558
if ((i == 0 || s[i-1] == ' ' || s[i-1] == ';' || s[i-1] == '\t') 112841 13569 126410
if ((i == 0 || s[i-1] == ' ' || s[i-1] == ';' || s[i-1] == '\t') 103509 9332 112841
if ((i == 0 || s[i-1] == ' ' || s[i-1] == ';' || s[i-1] == '\t') 0 103509 103509
46 31049 ▶ && memEQ(s + i, p, pl) && s[i + pl] == '=') {
Branch: 2 branches
BranchTrueFalseTotal
&& memEQ(s + i, p, pl) && s[i + pl] == '=') { 6289 24760 31049
&& memEQ(s + i, p, pl) && s[i + pl] == '=') { 6289 0 6289
47 6289 const char *v = s + i + pl + 1;
48 const char *e;
49 /*
50 # uncoverable condition right count:1 class:ignore_covered_err */
51 6289 ▶ if (v < s + sl && *v == '"') {
Branch: 2 branches
BranchTrueFalseTotal
if (v < s + sl && *v == '"') { 6289 0 6289
if (v < s + sl && *v == '"') { 4227 2062 6289
52 4227 v++; e = v;
53 /*
54 # uncoverable condition right count:1 class:ignore_covered_err */
55 13449 ▶ while (e < s + sl && *e != '"') e++;
Branch: 2 branches
BranchTrueFalseTotal
while (e < s + sl && *e != '"') e++; 13449 0 13449
while (e < s + sl && *e != '"') e++; 9222 4227 13449
56 }
57 20869 ▶ else { e = v; while (e < s + sl && *e != ';') e++; } /* # uncoverable condition right count:2 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
else { e = v; while (e < s + sl && *e != ';') e++; } /* # uncoverable condition right count:2 class:ignore_covered_err */ 18807 2062 20869
else { e = v; while (e < s + sl && *e != ';') e++; } /* # uncoverable condition right count:2 class:ignore_covered_err */ 18807 0 18807
58 6289 *vl = (STRLEN)(e - v);
59 6289 return v;
60 }
61 }
62 1859 return NULL;
63 }
64  
65 /* The whole-body parser that used to live here had no callers: every
66 * multipart body goes through pq_parse_multipart_stream (punk_mpstream.h),
67 * which spills large parts to disk and bounds what it holds. */
68  
69 #endif /* PUNK_MULTIPART_H */
« include/punk/punk_proxy.h ↑ Summary include/punk/punk_asset.h »