include/oa_client.h

filter: Statementstmt 69.4% 436 / 628 Branchbran 48.1% 385 / 800 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 57.4% 821 / 1428 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/arch/Open/API/Install/Files.pm ↑ Summary include/oa_mock.h »
1 #ifndef OA_CLIENT_H
2 #define OA_CLIENT_H
3  
4 /* Open::API::Client - the spec-driven HTTP client on Fetch's C ABI.
5 *
6 * A client is a blessed HV: { api => Open::API, base_url, validate, ua,
7 * ua_opts => [k, v, ...] }. call($operationId, %params) validates the flat
8 * %params against the operation's compiled JSF handles (croaking BEFORE any
9 * I/O on bad input), builds the URL/headers/body in C, and fires the request
10 * through the Fetch ABI. The returned Fetch::Future resolves to
11 * { status, headers => {lc-name => value}, data, error? }
12 * - `data` is the JSON-decoded body when the response is application/json,
13 * the raw body otherwise; transport failures resolve with status 0 and
14 * `error`; with validate => 1 a response-schema mismatch sets `error` and
15 * `errors`. */
16  
17 /* ---- lazy Fetch ABI resolution (the jsf_fetch.h pattern) ------------------- */
18  
19 11 static int oa_fetch_init(pTHX) {
20 11 dSP; int count; IV p = 0;
21 11 ▶ if (OA_FETCH) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if (OA_FETCH) return 1; 9 2 11
22 2 ▶ if (OA_FETCH_TRIED) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (OA_FETCH_TRIED) return 0; 0 2 2
23 2 OA_FETCH_TRIED = 1;
24 2 eval_pv("require Fetch;", FALSE);
25 2 ▶ if (SvTRUE(ERRSV)) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) return 0; 2 0 2
if (SvTRUE(ERRSV)) return 0; 0 2 2
26 2 SPAGAIN; /* the require may have reallocated the value stack */
27 2 ▶ ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK;
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK; 0 2 2
28 2 count = call_pv("Fetch::_abi_ptr", G_SCALAR | G_EVAL);
29 2 SPAGAIN;
30 2 ▶ if (!SvTRUE(ERRSV) && count > 0) p = POPi;
Branch: 3 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV) && count > 0) p = POPi; 2 0 2
if (!SvTRUE(ERRSV) && count > 0) p = POPi; 2 0 2
if (!SvTRUE(ERRSV) && count > 0) p = POPi; 2 0 2
31 0 ▶ else if (count > 0) (void)POPs;
Branch: 1 branch
BranchTrueFalseTotal
else if (count > 0) (void)POPs; 0 0 0
32 2 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 2 0 2
33 2 ▶ if (p) {
Branch: 1 branch
BranchTrueFalseTotal
if (p) { 2 0 2
34 2 const fetch_abi *f = INT2PTR(const fetch_abi *, p);
35 2 ▶ if (f && f->abi_version >= FETCH_ABI_VERSION) OA_FETCH = f;
Branch: 2 branches
BranchTrueFalseTotal
if (f && f->abi_version >= FETCH_ABI_VERSION) OA_FETCH = f; 2 0 2
if (f && f->abi_version >= FETCH_ABI_VERSION) OA_FETCH = f; 2 0 2
36 }
37 2 return OA_FETCH != NULL;
38 }
39  
40 /* ---- percent-encoding ------------------------------------------------------- */
41  
42 /* RFC 3986 gen-delims + sub-delims. Passed through unencoded only for a query
43 * parameter declared allowReserved, and only for its VALUE - a name is always
44 * encoded, or the pair separators stop meaning anything. */
45 3 static int oa_is_reserved(U8 c) {
46 3 ▶ return c == ':' || c == '/' || c == '?' || c == '#' || c == '['
Branch: 4 branches
BranchTrueFalseTotal
return c == ':' || c == '/' || c == '?' || c == '#' || c == '[' 1 2 3
return c == ':' || c == '/' || c == '?' || c == '#' || c == '[' 1 0 1
return c == ':' || c == '/' || c == '?' || c == '#' || c == '[' 1 0 1
return c == ':' || c == '/' || c == '?' || c == '#' || c == '[' 1 0 1
47 1 ▶ || c == ']' || c == '@' || c == '!' || c == '$' || c == '&'
Branch: 5 branches
BranchTrueFalseTotal
|| c == ']' || c == '@' || c == '!' || c == '$' || c == '&' 1 0 1
|| c == ']' || c == '@' || c == '!' || c == '$' || c == '&' 1 0 1
|| c == ']' || c == '@' || c == '!' || c == '$' || c == '&' 1 0 1
|| c == ']' || c == '@' || c == '!' || c == '$' || c == '&' 1 0 1
|| c == ']' || c == '@' || c == '!' || c == '$' || c == '&' 1 0 1
48 1 ▶ || c == '\'' || c == '(' || c == ')' || c == '*' || c == '+'
Branch: 5 branches
BranchTrueFalseTotal
|| c == '\'' || c == '(' || c == ')' || c == '*' || c == '+' 1 0 1
|| c == '\'' || c == '(' || c == ')' || c == '*' || c == '+' 1 0 1
|| c == '\'' || c == '(' || c == ')' || c == '*' || c == '+' 1 0 1
|| c == '\'' || c == '(' || c == ')' || c == '*' || c == '+' 1 0 1
|| c == '\'' || c == '(' || c == ')' || c == '*' || c == '+' 1 0 1
49 6 ▶ || c == ',' || c == ';' || c == '=';
Branch: 4 branches
BranchTrueFalseTotal
|| c == ',' || c == ';' || c == '='; 3 0 3
|| c == ',' || c == ';' || c == '='; 1 0 1
|| c == ',' || c == ';' || c == '='; 1 0 1
|| c == ',' || c == ';' || c == '='; 0 1 1
50 }
51  
52 198 static void oa_pct_encode_res(pTHX_ SV *out, const char *p, STRLEN l,
53 int reserved) {
54 static const char hex[] = "0123456789ABCDEF";
55 STRLEN i;
56 882 ▶ for (i = 0; i < l; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < l; i++) { 684 198 882
57 684 U8 c = (U8)p[i];
58 684 ▶ if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
Branch: 4 branches
BranchTrueFalseTotal
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') 577 107 684
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') 544 33 577
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') 544 107 651
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') 0 544 544
59 107 ▶ || (c >= '0' && c <= '9') || c == '-' || c == '.'
Branch: 4 branches
BranchTrueFalseTotal
|| (c >= '0' && c <= '9') || c == '-' || c == '.' 101 6 107
|| (c >= '0' && c <= '9') || c == '-' || c == '.' 0 101 101
|| (c >= '0' && c <= '9') || c == '-' || c == '.' 6 0 6
|| (c >= '0' && c <= '9') || c == '-' || c == '.' 6 0 6
60 6 ▶ || c == '_' || c == '~'
Branch: 2 branches
BranchTrueFalseTotal
|| c == '_' || c == '~' 6 0 6
|| c == '_' || c == '~' 6 0 6
61 6 ▶ || (reserved && oa_is_reserved(c))) {
Branch: 2 branches
BranchTrueFalseTotal
|| (reserved && oa_is_reserved(c))) { 3 3 6
|| (reserved && oa_is_reserved(c))) { 2 1 3
62 680 sv_catpvn(out, (const char *)&c, 1);
63 } else {
64 char b[3];
65 4 b[0] = '%'; b[1] = hex[c >> 4]; b[2] = hex[c & 15];
66 4 sv_catpvn(out, b, 3);
67 }
68 }
69 198 }
70  
71 /* the ordinary encoding: nothing reserved passes through */
72 77 static void oa_pct_encode_into(pTHX_ SV *out, const char *p, STRLEN l) {
73 77 oa_pct_encode_res(aTHX_ out, p, l, 0);
74 77 }
75  
76 /* ---- style-aware serialization ----------------------------------------------
77 *
78 * The mirror of oa_style_path and oa_parse_query on the way OUT. Without it the
79 * builder handed whatever it was given to SvPV, so an arrayref or hashref in a
80 * path segment stringified to `ARRAY(0x...)` and went on the wire, and `style`
81 * was ignored everywhere: a matrix parameter emitted a bare value with no
82 * `;name=`, a spaceDelimited list emitted repeat keys. The client built URLs
83 * this library's own server would refuse.
84 *
85 * Structural characters (the `;` `.` `,` `=` a style is MADE of) are written
86 * literally; only the values around them are encoded. That is why each piece is
87 * encoded on its own rather than the finished string being encoded at the end.
88 */
89  
90 /* An object's members in a stable order. Perl randomises hash order, so
91 * serializing one straight out of the hash produces a DIFFERENT URL each run -
92 * the same defect the router had. Sorted, so a URL is reproducible; object
93 * members carry no meaningful order, so the server rebuilds the same value
94 * whatever the order. */
95 17 static AV *oa_cli_sorted_keys(pTHX_ HV *h) {
96 17 AV *keys = (AV *)sv_2mortal((SV *)newAV());
97 HE *he;
98 SSize_t i;
99 17 hv_iterinit(h);
100 62 ▶ while ((he = hv_iternext(h))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(h))) { 45 17 62
101 45 I32 kl; const char *kp = hv_iterkey(he, &kl);
102 45 av_push(keys, newSVpvn(kp, (STRLEN)kl));
103 }
104 45 ▶ for (i = 1; i <= av_len(keys); i++) { /* insertion sort: few members */
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= av_len(keys); i++) { /* insertion sort: few members */ 28 17 45
105 28 SV **cur = av_fetch(keys, i, 0);
106 28 ▶ SV *c = cur && *cur ? SvREFCNT_inc(*cur) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
SV *c = cur && *cur ? SvREFCNT_inc(*cur) : NULL; 28 0 28
SV *c = cur && *cur ? SvREFCNT_inc(*cur) : NULL; 28 0 28
107 28 SSize_t j = i - 1;
108 28 ▶ if (!c) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!c) continue; 0 28 28
109 52 ▶ while (j >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (j >= 0) { 39 13 52
110 39 SV **prev = av_fetch(keys, j, 0);
111 39 ▶ if (!prev || !*prev || sv_cmp(*prev, c) <= 0) break;
Branch: 3 branches
BranchTrueFalseTotal
if (!prev || !*prev || sv_cmp(*prev, c) <= 0) break; 39 0 39
if (!prev || !*prev || sv_cmp(*prev, c) <= 0) break; 39 0 39
if (!prev || !*prev || sv_cmp(*prev, c) <= 0) break; 24 15 39
112 24 (void)av_store(keys, j + 1, SvREFCNT_inc(*prev));
113 24 j--;
114 }
115 28 (void)av_store(keys, j + 1, c);
116 }
117 17 return keys;
118 }
119  
120 /* one value, encoded */
121 112 static void oa_cli_val(pTHX_ SV *out, SV *v, int reserved) {
122 STRLEN l;
123 const char *p;
124 112 ▶ if (!v || !SvOK(v)) return;
Branch: 2 branches
BranchTrueFalseTotal
if (!v || !SvOK(v)) return; 112 0 112
if (!v || !SvOK(v)) return; 0 112 112
125 112 p = SvPV_const(v, l);
126 112 oa_pct_encode_res(aTHX_ out, p, l, reserved);
127 }
128  
129 /* Serialize `val` for a PATH segment per pp->style. `out` already ends at the
130 * '/' this segment follows. */
131 33 static void oa_cli_ser_path(pTHX_ oa_param *pp, SV *val, SV *out) {
132 33 STRLEN nl; const char *np = SvPV_const(pp->name, nl);
133 33 AV *av = oa_av_of(val);
134 21 ▶ HV *hv = (!av && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
HV *hv = (!av && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) 6 15 21
HV *hv = (!av && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) 6 0 6
135 54 ▶ ? (HV *)SvRV(val) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(val) : NULL; 21 12 33
136 66 const char *pfx = pp->style == OA_ST_LABEL ? "."
137 33 ▶ : pp->style == OA_ST_MATRIX ? ";" : "";
Branch: 2 branches
BranchTrueFalseTotal
: pp->style == OA_ST_MATRIX ? ";" : ""; 23 10 33
: pp->style == OA_ST_MATRIX ? ";" : ""; 10 13 23
138 /* the separator BETWEEN elements once exploded */
139 56 ▶ const char *esep = pp->style == OA_ST_LABEL ? "."
Branch: 1 branch
BranchTrueFalseTotal
const char *esep = pp->style == OA_ST_LABEL ? "." 23 10 33
140 23 ▶ : pp->style == OA_ST_MATRIX ? ";" : ",";
Branch: 1 branch
BranchTrueFalseTotal
: pp->style == OA_ST_MATRIX ? ";" : ","; 10 13 23
141  
142 33 ▶ if (*pfx) sv_catpv(out, pfx);
Branch: 1 branch
BranchTrueFalseTotal
if (*pfx) sv_catpv(out, pfx); 20 13 33
143  
144 33 ▶ if (!av && !hv) { /* a scalar */
Branch: 2 branches
BranchTrueFalseTotal
if (!av && !hv) { /* a scalar */ 21 12 33
if (!av && !hv) { /* a scalar */ 15 6 21
145 15 ▶ if (pp->style == OA_ST_MATRIX) {
Branch: 1 branch
BranchTrueFalseTotal
if (pp->style == OA_ST_MATRIX) { 4 11 15
146 /* `;name=value`, and `;name` alone when the value is empty */
147 4 STRLEN vl; const char *vp = SvPV_const(val, vl);
148 4 oa_pct_encode_into(aTHX_ out, np, nl);
149 4 ▶ if (vl) { sv_catpvs(out, "="); oa_cli_val(aTHX_ out, val, 0); }
Branch: 1 branch
BranchTrueFalseTotal
if (vl) { sv_catpvs(out, "="); oa_cli_val(aTHX_ out, val, 0); } 4 0 4
150 } else {
151 11 oa_cli_val(aTHX_ out, val, 0);
152 }
153 27 return;
154 }
155  
156 18 ▶ if (av) {
Branch: 1 branch
BranchTrueFalseTotal
if (av) { 12 6 18
157 12 SSize_t i, n = av_len(av) + 1;
158 /* matrix, not exploded, prefixes the name ONCE: `;name=a,b` */
159 12 ▶ if (pp->style == OA_ST_MATRIX && !pp->explode) {
Branch: 2 branches
BranchTrueFalseTotal
if (pp->style == OA_ST_MATRIX && !pp->explode) { 4 8 12
if (pp->style == OA_ST_MATRIX && !pp->explode) { 2 2 4
160 2 oa_pct_encode_into(aTHX_ out, np, nl);
161 2 sv_catpvs(out, "=");
162 }
163 48 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 36 12 48
164 36 SV **e = av_fetch(av, i, 0);
165 36 ▶ if (i) {
Branch: 1 branch
BranchTrueFalseTotal
if (i) { 24 12 36
166 /* label and simple keep a comma unless exploded; matrix
167 * exploded repeats `;name=` per element */
168 24 ▶ if (pp->explode) sv_catpv(out, esep);
Branch: 1 branch
BranchTrueFalseTotal
if (pp->explode) sv_catpv(out, esep); 12 12 24
169 12 else sv_catpvs(out, ",");
170 }
171 36 ▶ if (pp->style == OA_ST_MATRIX && pp->explode) {
Branch: 2 branches
BranchTrueFalseTotal
if (pp->style == OA_ST_MATRIX && pp->explode) { 12 24 36
if (pp->style == OA_ST_MATRIX && pp->explode) { 6 6 12
172 if (i) { /* the `;` was written above */ }
173 6 oa_pct_encode_into(aTHX_ out, np, nl);
174 6 sv_catpvs(out, "=");
175 }
176 36 ▶ if (e && *e) oa_cli_val(aTHX_ out, *e, 0);
Branch: 2 branches
BranchTrueFalseTotal
if (e && *e) oa_cli_val(aTHX_ out, *e, 0); 36 0 36
if (e && *e) oa_cli_val(aTHX_ out, *e, 0); 36 0 36
177 }
178 12 return;
179 }
180  
181 { /* an object */
182 6 AV *keys = oa_cli_sorted_keys(aTHX_ hv);
183 6 SSize_t i, n = av_len(keys) + 1;
184 6 ▶ if (pp->style == OA_ST_MATRIX && !pp->explode) {
Branch: 2 branches
BranchTrueFalseTotal
if (pp->style == OA_ST_MATRIX && !pp->explode) { 2 4 6
if (pp->style == OA_ST_MATRIX && !pp->explode) { 1 1 2
185 1 oa_pct_encode_into(aTHX_ out, np, nl);
186 1 sv_catpvs(out, "=");
187 }
188 24 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 18 6 24
189 18 SV **k = av_fetch(keys, i, 0);
190 SV **v;
191 STRLEN kl; const char *kp;
192 18 ▶ if (!k || !*k) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!k || !*k) continue; 18 0 18
if (!k || !*k) continue; 0 18 18
193 18 kp = SvPV_const(*k, kl);
194 18 v = hv_fetch(hv, kp, (I32)kl, 0);
195 18 ▶ if (i) {
Branch: 1 branch
BranchTrueFalseTotal
if (i) { 12 6 18
196 12 ▶ if (pp->explode) sv_catpv(out, esep);
Branch: 1 branch
BranchTrueFalseTotal
if (pp->explode) sv_catpv(out, esep); 6 6 12
197 6 else sv_catpvs(out, ",");
198 }
199 /* exploded names each MEMBER with `=`; not exploded, the members
200 * are just more comma-separated pieces. sv_catpv, not sv_catpvs:
201 * the _s form is a macro over a string LITERAL. */
202 18 oa_pct_encode_into(aTHX_ out, kp, kl);
203 18 ▶ sv_catpv(out, pp->explode ? "=" : ",");
Branch: 1 branch
BranchTrueFalseTotal
sv_catpv(out, pp->explode ? "=" : ","); 9 9 18
204 18 ▶ if (v && *v) oa_cli_val(aTHX_ out, *v, 0);
Branch: 2 branches
BranchTrueFalseTotal
if (v && *v) oa_cli_val(aTHX_ out, *v, 0); 18 0 18
if (v && *v) oa_cli_val(aTHX_ out, *v, 0); 18 0 18
205 }
206 }
207 }
208  
209 /* Serialize `val` as QUERY pieces per pp->style, appending to `url`. */
210 13 static void oa_cli_ser_query(pTHX_ oa_param *pp, SV *val, SV *url, int *first) {
211 13 STRLEN nl; const char *np = SvPV_const(pp->name, nl);
212 13 AV *av = oa_av_of(val);
213 5 ▶ HV *hv = (!av && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
HV *hv = (!av && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) 5 0 5
HV *hv = (!av && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) 5 0 5
214 18 ▶ ? (HV *)SvRV(val) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(val) : NULL; 5 8 13
215 13 int res = pp->allow_reserved;
216 26 const char *dsep = pp->style == OA_ST_SPACE ? "%20"
217 13 ▶ : pp->style == OA_ST_PIPE ? "|" : ",";
Branch: 2 branches
BranchTrueFalseTotal
: pp->style == OA_ST_PIPE ? "|" : ","; 10 3 13
: pp->style == OA_ST_PIPE ? "|" : ","; 3 7 10
218  
219 13 ▶ if (!av && !hv) { /* a scalar */
Branch: 2 branches
BranchTrueFalseTotal
if (!av && !hv) { /* a scalar */ 5 8 13
if (!av && !hv) { /* a scalar */ 0 5 5
220 0 ▶ sv_catpvn(url, *first ? "?" : "&", 1); *first = 0;
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvn(url, *first ? "?" : "&", 1); *first = 0; 0 0 0
221 0 oa_pct_encode_into(aTHX_ url, np, nl);
222 0 sv_catpvs(url, "=");
223 0 oa_cli_val(aTHX_ url, val, res);
224 8 return;
225 }
226  
227 13 ▶ if (av) {
Branch: 1 branch
BranchTrueFalseTotal
if (av) { 8 5 13
228 8 SSize_t i, n = av_len(av) + 1;
229 /* form + explode repeats the key; every other query style joins the
230 * elements into ONE value with its own delimiter */
231 8 ▶ if (pp->style == OA_ST_FORM && pp->explode) {
Branch: 2 branches
BranchTrueFalseTotal
if (pp->style == OA_ST_FORM && pp->explode) { 4 4 8
if (pp->style == OA_ST_FORM && pp->explode) { 2 2 4
232 8 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 6 2 8
233 6 SV **e = av_fetch(av, i, 0);
234 6 ▶ if (!e || !*e || !SvOK(*e)) continue;
Branch: 3 branches
BranchTrueFalseTotal
if (!e || !*e || !SvOK(*e)) continue; 6 0 6
if (!e || !*e || !SvOK(*e)) continue; 6 0 6
if (!e || !*e || !SvOK(*e)) continue; 0 6 6
235 6 ▶ sv_catpvn(url, *first ? "?" : "&", 1); *first = 0;
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvn(url, *first ? "?" : "&", 1); *first = 0; 2 4 6
236 6 oa_pct_encode_into(aTHX_ url, np, nl);
237 6 sv_catpvs(url, "=");
238 6 oa_cli_val(aTHX_ url, *e, res);
239 }
240 2 return;
241 }
242 6 ▶ sv_catpvn(url, *first ? "?" : "&", 1); *first = 0;
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvn(url, *first ? "?" : "&", 1); *first = 0; 6 0 6
243 6 oa_pct_encode_into(aTHX_ url, np, nl);
244 6 sv_catpvs(url, "=");
245 24 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 18 6 24
246 18 SV **e = av_fetch(av, i, 0);
247 18 ▶ if (i) sv_catpv(url, dsep);
Branch: 1 branch
BranchTrueFalseTotal
if (i) sv_catpv(url, dsep); 12 6 18
248 18 ▶ if (e && *e) oa_cli_val(aTHX_ url, *e, res);
Branch: 2 branches
BranchTrueFalseTotal
if (e && *e) oa_cli_val(aTHX_ url, *e, res); 18 0 18
if (e && *e) oa_cli_val(aTHX_ url, *e, res); 18 0 18
249 }
250 6 return;
251 }
252  
253 { /* an object */
254 5 AV *keys = oa_cli_sorted_keys(aTHX_ hv);
255 5 SSize_t i, n = av_len(keys) + 1;
256 9 ▶ int one_value = !(pp->style == OA_ST_DEEP
Branch: 1 branch
BranchTrueFalseTotal
int one_value = !(pp->style == OA_ST_DEEP 4 1 5
257 4 ▶ || (pp->style == OA_ST_FORM && pp->explode));
Branch: 2 branches
BranchTrueFalseTotal
|| (pp->style == OA_ST_FORM && pp->explode)); 2 2 4
|| (pp->style == OA_ST_FORM && pp->explode)); 1 1 2
258 5 ▶ if (one_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (one_value) { 3 2 5
259 3 ▶ sv_catpvn(url, *first ? "?" : "&", 1); *first = 0;
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvn(url, *first ? "?" : "&", 1); *first = 0; 3 0 3
260 3 oa_pct_encode_into(aTHX_ url, np, nl);
261 3 sv_catpvs(url, "=");
262 }
263 20 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 15 5 20
264 15 SV **k = av_fetch(keys, i, 0);
265 SV **v;
266 STRLEN kl; const char *kp;
267 24 ▶ if (!k || !*k) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!k || !*k) continue; 15 0 15
if (!k || !*k) continue; 0 15 15
268 15 kp = SvPV_const(*k, kl);
269 15 v = hv_fetch(hv, kp, (I32)kl, 0);
270 15 ▶ if (one_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (one_value) { 9 6 15
271 9 ▶ if (i) sv_catpv(url, dsep);
Branch: 1 branch
BranchTrueFalseTotal
if (i) sv_catpv(url, dsep); 6 3 9
272 9 oa_pct_encode_into(aTHX_ url, kp, kl);
273 9 sv_catpv(url, dsep);
274 9 ▶ if (v && *v) oa_cli_val(aTHX_ url, *v, res);
Branch: 2 branches
BranchTrueFalseTotal
if (v && *v) oa_cli_val(aTHX_ url, *v, res); 9 0 9
if (v && *v) oa_cli_val(aTHX_ url, *v, res); 9 0 9
275 9 continue;
276 }
277 6 ▶ sv_catpvn(url, *first ? "?" : "&", 1); *first = 0;
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvn(url, *first ? "?" : "&", 1); *first = 0; 2 4 6
278 6 ▶ if (pp->style == OA_ST_DEEP) {
Branch: 1 branch
BranchTrueFalseTotal
if (pp->style == OA_ST_DEEP) { 3 3 6
279 /* `name[member]=value` - the brackets are structural */
280 3 oa_pct_encode_into(aTHX_ url, np, nl);
281 3 sv_catpvs(url, "[");
282 3 oa_pct_encode_into(aTHX_ url, kp, kl);
283 3 sv_catpvs(url, "]");
284 } else {
285 /* form + explode: the MEMBER is the key */
286 3 oa_pct_encode_into(aTHX_ url, kp, kl);
287 }
288 6 sv_catpvs(url, "=");
289 6 ▶ if (v && *v) oa_cli_val(aTHX_ url, *v, res);
Branch: 2 branches
BranchTrueFalseTotal
if (v && *v) oa_cli_val(aTHX_ url, *v, res); 6 0 6
if (v && *v) oa_cli_val(aTHX_ url, *v, res); 6 0 6
290 }
291 }
292 }
293  
294 /* A header or cookie value. Neither is percent-encoded - the server splits
295 * them but does not decode - so this joins the pieces literally rather than
296 * going through oa_cli_val. Both locations are comma separated: a header is
297 * `simple` by definition, and a cookie is `form`, whose non-exploded list is
298 * also a comma. Without this an arrayref reached SvPV and the request carried
299 * `X-H: ARRAY(0x...)`, which was verified going out over a socket. */
300 3 static void oa_cli_ser_flat(pTHX_ oa_param *pp, SV *val, SV *out) {
301 3 AV *av = oa_av_of(val);
302 2 ▶ HV *hv = (!av && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
HV *hv = (!av && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) 2 0 2
HV *hv = (!av && SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) 2 0 2
303 5 ▶ ? (HV *)SvRV(val) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(val) : NULL; 2 1 3
304 3 ▶ if (!av && !hv) { sv_catsv(out, val); return; }
Branch: 2 branches
BranchTrueFalseTotal
if (!av && !hv) { sv_catsv(out, val); return; } 2 1 3
if (!av && !hv) { sv_catsv(out, val); return; } 0 2 2
305 3 ▶ if (av) {
Branch: 1 branch
BranchTrueFalseTotal
if (av) { 1 2 3
306 1 SSize_t i, n = av_len(av) + 1;
307 4 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 3 1 4
308 3 SV **e = av_fetch(av, i, 0);
309 3 ▶ if (i) sv_catpvs(out, ",");
Branch: 1 branch
BranchTrueFalseTotal
if (i) sv_catpvs(out, ","); 2 1 3
310 3 ▶ if (e && *e && SvOK(*e)) sv_catsv(out, *e);
Branch: 3 branches
BranchTrueFalseTotal
if (e && *e && SvOK(*e)) sv_catsv(out, *e); 3 0 3
if (e && *e && SvOK(*e)) sv_catsv(out, *e); 3 0 3
if (e && *e && SvOK(*e)) sv_catsv(out, *e); 3 0 3
311 }
312 1 return;
313 }
314 {
315 2 AV *keys = oa_cli_sorted_keys(aTHX_ hv);
316 2 SSize_t i, n = av_len(keys) + 1;
317 6 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 4 2 6
318 4 SV **k = av_fetch(keys, i, 0);
319 SV **v;
320 STRLEN kl; const char *kp;
321 4 ▶ if (!k || !*k) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!k || !*k) continue; 4 0 4
if (!k || !*k) continue; 0 4 4
322 4 kp = SvPV_const(*k, kl);
323 4 v = hv_fetch(hv, kp, (I32)kl, 0);
324 4 ▶ if (i) sv_catpvs(out, ",");
Branch: 1 branch
BranchTrueFalseTotal
if (i) sv_catpvs(out, ","); 2 2 4
325 4 sv_catpvn(out, kp, kl);
326 4 ▶ sv_catpv(out, pp->explode ? "=" : ",");
Branch: 1 branch
BranchTrueFalseTotal
sv_catpv(out, pp->explode ? "=" : ","); 2 2 4
327 4 ▶ if (v && *v && SvOK(*v)) sv_catsv(out, *v);
Branch: 3 branches
BranchTrueFalseTotal
if (v && *v && SvOK(*v)) sv_catsv(out, *v); 4 0 4
if (v && *v && SvOK(*v)) sv_catsv(out, *v); 4 0 4
if (v && *v && SvOK(*v)) sv_catsv(out, *v); 4 0 4
328 }
329 }
330 }
331  
332 /* ---- client-side validation -------------------------------------------------- */
333  
334 /* croak with the first JSF error message for a bad client-side value */
335 2 static void oa_cli_bad(pTHX_ oa_op *o, const char *in, SV *name, SV *value,
336 SV *handle) {
337 2 AV *errs = (AV *)sv_2mortal((SV *)newAV());
338 2 const char *msg = "value does not match the schema";
339 2 (void)JSF->validate(aTHX_ handle, value, errs);
340 2 ▶ if (av_len(errs) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(errs) >= 0) { 2 0 2
341 2 SV **e = av_fetch(errs, 0, 0);
342 2 ▶ HV *h = (e && *e && SvROK(*e)) ? (HV *)SvRV(*e) : NULL;
Branch: 3 branches
BranchTrueFalseTotal
HV *h = (e && *e && SvROK(*e)) ? (HV *)SvRV(*e) : NULL; 2 0 2
HV *h = (e && *e && SvROK(*e)) ? (HV *)SvRV(*e) : NULL; 2 0 2
HV *h = (e && *e && SvROK(*e)) ? (HV *)SvRV(*e) : NULL; 2 0 2
343 2 ▶ SV *m = h ? oa_get(aTHX_ h, "message") : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV *m = h ? oa_get(aTHX_ h, "message") : NULL; 2 0 2
344 4 ▶ if (m) msg = SvPV_nolen(m);
Branch: 1 branch
BranchTrueFalseTotal
if (m) msg = SvPV_nolen(m); 2 0 2
345 }
346 3 ▶ croak("Open::API::Client: %s: invalid %s parameter '%s': %s",
Branch: 1 branch
BranchTrueFalseTotal
croak("Open::API::Client: %s: invalid %s parameter '%s': %s", 1 1 2
347 SvPV_nolen(o->op_id), in, name ? SvPV_nolen(name) : "body", msg);
348 }
349  
350 /* The wire form of a parameter value.
351 *
352 * A `content` parameter carries a whole document in one value, so a structure
353 * is encoded to its media type before it goes into the URL or a header -
354 * without this it would stringify as HASH(0x...). A caller who has already
355 * encoded it passes a string, which travels as it is. Mortal, or the original
356 * SV when nothing needs doing. */
357 46 static SV *oa_cli_wire(pTHX_ oa_param *pp, SV *v) {
358 46 ▶ if (pp->ctype && SvROK(v)
Branch: 2 branches
BranchTrueFalseTotal
if (pp->ctype && SvROK(v) 0 46 46
if (pp->ctype && SvROK(v) 0 0 0
359 0 ▶ && (SvTYPE(SvRV(v)) == SVt_PVHV || SvTYPE(SvRV(v)) == SVt_PVAV)) {
Branch: 2 branches
BranchTrueFalseTotal
&& (SvTYPE(SvRV(v)) == SVt_PVHV || SvTYPE(SvRV(v)) == SVt_PVAV)) { 0 0 0
&& (SvTYPE(SvRV(v)) == SVt_PVHV || SvTYPE(SvRV(v)) == SVt_PVAV)) { 0 0 0
360 0 STRLEN cl; const char *cp = SvPV_const(pp->ctype, cl);
361 0 ▶ if (oa_ctype_is_json(cp, cl)) {
Branch: 1 branch
BranchTrueFalseTotal
if (oa_ctype_is_json(cp, cl)) { 0 0 0
362 0 SV *j = oa_json_encode(aTHX_ v);
363 0 ▶ if (j) return j;
Branch: 1 branch
BranchTrueFalseTotal
if (j) return j; 0 0 0
364 }
365 }
366 46 return v;
367 }
368  
369 /* The value a `content` parameter's schema should see: the decoded document.
370 * Croaks on undecodable input, so the client fails before any I/O. */
371 8 static SV *oa_cli_decoded(pTHX_ oa_op *o, oa_param *pp, const char *in, SV *v) {
372 8 ▶ if (pp->ctype && !SvROK(v)) {
Branch: 2 branches
BranchTrueFalseTotal
if (pp->ctype && !SvROK(v)) { 0 8 8
if (pp->ctype && !SvROK(v)) { 0 0 0
373 0 STRLEN cl; const char *cp = SvPV_const(pp->ctype, cl);
374 0 ▶ if (oa_ctype_is_json(cp, cl)) {
Branch: 1 branch
BranchTrueFalseTotal
if (oa_ctype_is_json(cp, cl)) { 0 0 0
375 0 SV *d = oa_body_decode(aTHX_ v);
376 0 ▶ if (!d) croak("Open::API::Client: %s: %s parameter '%s' is not "
Branch: 2 branches
BranchTrueFalseTotal
if (!d) croak("Open::API::Client: %s: %s parameter '%s' is not " 0 0 0
if (!d) croak("Open::API::Client: %s: %s parameter '%s' is not " 0 0 0
377 "valid JSON", SvPV_nolen(o->op_id), in,
378 SvPV_nolen(pp->name));
379 0 return d;
380 }
381 }
382 8 return v;
383 }
384  
385 /* ---- the response map callback ------------------------------------------------ */
386  
387 typedef struct oa_cli_ctx {
388 SV *api_sv; /* keeps the op table alive (+1) */
389 oa_op *op;
390 int validate;
391 SV *cli; /* RV to the client HV, for CSRF token capture (+1) */
392 SV *csrf_cookie; /* CSRF cookie name to watch for in Set-Cookie (+1) */
393 } oa_cli_ctx;
394  
395 6 static SV *oa_cli_map(pTHX_ int ok, int status, AV *headers, SV *body,
396 SV *err, void *ud) {
397 6 oa_cli_ctx *c = (oa_cli_ctx *)ud;
398 6 HV *out = newHV();
399 6 HV *hh = newHV();
400 6 int is_json = 0;
401 SSize_t i, n;
402 6 SV *data = NULL;
403  
404 6 ▶ if (!ok) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ok) { 2 4 6
405 2 (void)hv_stores(out, "status", newSViv(0));
406 2 ▶ (void)hv_stores(out, "error",
Branch: 2 branches
BranchTrueFalseTotal
(void)hv_stores(out, "error", 2 0 2
(void)hv_stores(out, "error", 2 0 2
407 (err && SvOK(err)) ? newSVsv(err)
408 : newSVpvs("request failed"));
409 2 SvREFCNT_dec((SV *)hh);
410 2 goto done;
411 }
412  
413 4 (void)hv_stores(out, "status", newSViv(status));
414 4 ▶ n = headers ? av_len(headers) + 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
n = headers ? av_len(headers) + 1 : 0; 4 0 4
415 16 ▶ for (i = 0; i + 1 < n; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i + 1 < n; i += 2) { 12 4 16
416 12 SV **k = av_fetch(headers, i, 0);
417 12 SV **v = av_fetch(headers, i + 1, 0);
418 12 ▶ if (k && *k && v && *v) {
Branch: 4 branches
BranchTrueFalseTotal
if (k && *k && v && *v) { 12 0 12
if (k && *k && v && *v) { 12 0 12
if (k && *k && v && *v) { 12 0 12
if (k && *k && v && *v) { 12 0 12
419 12 STRLEN kl; const char *kp = SvPV_const(*k, kl);
420 char lc[128];
421 STRLEN j;
422 12 ▶ if (kl >= sizeof lc) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (kl >= sizeof lc) continue; 0 12 12
423 156 ▶ for (j = 0; j < kl; j++) lc[j] = (char)toLOWER((U8)kp[j]);
Branch: 2 branches
BranchTrueFalseTotal
for (j = 0; j < kl; j++) lc[j] = (char)toLOWER((U8)kp[j]); 20 124 144
for (j = 0; j < kl; j++) lc[j] = (char)toLOWER((U8)kp[j]); 144 12 156
424 12 (void)hv_store(hh, lc, (I32)kl, newSVsv(*v), 0);
425 12 ▶ if (kl == 12 && memEQ(lc, "content-type", 12)) {
Branch: 2 branches
BranchTrueFalseTotal
if (kl == 12 && memEQ(lc, "content-type", 12)) { 4 8 12
if (kl == 12 && memEQ(lc, "content-type", 12)) { 4 0 4
426 4 STRLEN vl; const char *vp = SvPV_const(*v, vl);
427 4 ▶ if (vl >= 16 && memEQ(vp, "application/json", 16))
Branch: 2 branches
BranchTrueFalseTotal
if (vl >= 16 && memEQ(vp, "application/json", 16)) 0 4 4
if (vl >= 16 && memEQ(vp, "application/json", 16)) 0 0 0
428 0 is_json = 1;
429 }
430 }
431 }
432 4 (void)hv_stores(out, "headers", newRV_noinc((SV *)hh));
433  
434 /* transparent CSRF: capture the (rotated) token the server set, so the
435 * next unsafe call can echo it in the token header */
436 4 ▶ if (c->csrf_cookie && c->cli && headers) {
Branch: 3 branches
BranchTrueFalseTotal
if (c->csrf_cookie && c->cli && headers) { 0 4 4
if (c->csrf_cookie && c->cli && headers) { 0 0 0
if (c->csrf_cookie && c->cli && headers) { 0 0 0
437 0 STRLEN wnl; const char *wnp = SvPV_const(c->csrf_cookie, wnl);
438 0 ▶ for (i = 0; i + 1 < n; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i + 1 < n; i += 2) { 0 0 0
439 0 SV **k = av_fetch(headers, i, 0);
440 0 SV **v = av_fetch(headers, i + 1, 0);
441 STRLEN kl, vl; const char *kp, *vp;
442 0 ▶ if (!k || !*k || !v || !*v) continue;
Branch: 4 branches
BranchTrueFalseTotal
if (!k || !*k || !v || !*v) continue; 0 0 0
if (!k || !*k || !v || !*v) continue; 0 0 0
if (!k || !*k || !v || !*v) continue; 0 0 0
if (!k || !*k || !v || !*v) continue; 0 0 0
443 0 kp = SvPV_const(*k, kl);
444 0 ▶ if (!(kl == 10 && oa_ci_eq(kp, kl, "set-cookie", 10))) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!(kl == 10 && oa_ci_eq(kp, kl, "set-cookie", 10))) continue; 0 0 0
if (!(kl == 10 && oa_ci_eq(kp, kl, "set-cookie", 10))) continue; 0 0 0
445 0 vp = SvPV_const(*v, vl);
446 0 ▶ if (vl > wnl + 1 && memEQ(vp, wnp, wnl) && vp[wnl] == '=') {
Branch: 3 branches
BranchTrueFalseTotal
if (vl > wnl + 1 && memEQ(vp, wnp, wnl) && vp[wnl] == '=') { 0 0 0
if (vl > wnl + 1 && memEQ(vp, wnp, wnl) && vp[wnl] == '=') { 0 0 0
if (vl > wnl + 1 && memEQ(vp, wnp, wnl) && vp[wnl] == '=') { 0 0 0
447 0 STRLEN s = wnl + 1, e = s;
448 0 ▶ while (e < vl && vp[e] != ';') e++;
Branch: 2 branches
BranchTrueFalseTotal
while (e < vl && vp[e] != ';') e++; 0 0 0
while (e < vl && vp[e] != ';') e++; 0 0 0
449 0 (void)hv_stores((HV *)SvRV(c->cli), "_csrf_token",
450 newSVpvn(vp + s, e - s));
451 }
452 }
453 }
454  
455 4 ▶ if (is_json && body && SvOK(body) && SvCUR(body))
Branch: 4 branches
BranchTrueFalseTotal
if (is_json && body && SvOK(body) && SvCUR(body)) 0 4 4
if (is_json && body && SvOK(body) && SvCUR(body)) 0 0 0
if (is_json && body && SvOK(body) && SvCUR(body)) 0 0 0
if (is_json && body && SvOK(body) && SvCUR(body)) 0 0 0
456 0 data = oa_body_decode(aTHX_ body); /* mortal or NULL */
457 4 ▶ if (data) (void)hv_stores(out, "data", newSVsv(data));
Branch: 1 branch
BranchTrueFalseTotal
if (data) (void)hv_stores(out, "data", newSVsv(data)); 0 4 4
458 4 ▶ else (void)hv_stores(out, "data",
Branch: 2 branches
BranchTrueFalseTotal
else (void)hv_stores(out, "data", 4 0 4
else (void)hv_stores(out, "data", 4 0 4
459 body && SvOK(body) ? newSVsv(body) : newSV(0));
460  
461 /* optional response-schema validation */
462 4 ▶ if (c->validate && c->op && data) {
Branch: 3 branches
BranchTrueFalseTotal
if (c->validate && c->op && data) { 4 0 4
if (c->validate && c->op && data) { 0 0 0
if (c->validate && c->op && data) { 0 0 0
463 0 SV *handle = NULL;
464 char sbuf[8];
465 0 STRLEN sl = (STRLEN)my_snprintf(sbuf, sizeof sbuf, "%d", status);
466 int ri;
467 0 ▶ for (ri = 0; ri < c->op->nresps; ri++) {
Branch: 1 branch
BranchTrueFalseTotal
for (ri = 0; ri < c->op->nresps; ri++) { 0 0 0
468 0 STRLEN rl; const char *rp = SvPV_const(c->op->resps[ri].status, rl);
469 0 ▶ if (rl == sl && memEQ(rp, sbuf, sl))
Branch: 2 branches
BranchTrueFalseTotal
if (rl == sl && memEQ(rp, sbuf, sl)) 0 0 0
if (rl == sl && memEQ(rp, sbuf, sl)) 0 0 0
470 0 { handle = c->op->resps[ri].handle; break; }
471 }
472 0 ▶ if (!handle) { /* a range key: 2XX, 4XX, ... (same order as the server) */
Branch: 1 branch
BranchTrueFalseTotal
if (!handle) { /* a range key: 2XX, 4XX, ... (same order as the server) */ 0 0 0
473 0 ▶ for (ri = 0; ri < c->op->nresps; ri++) {
Branch: 1 branch
BranchTrueFalseTotal
for (ri = 0; ri < c->op->nresps; ri++) { 0 0 0
474 0 STRLEN rl; const char *rp = SvPV_const(c->op->resps[ri].status, rl);
475 0 ▶ if (oa_status_covers(rp, rl, sbuf, sl))
Branch: 1 branch
BranchTrueFalseTotal
if (oa_status_covers(rp, rl, sbuf, sl)) 0 0 0
476 0 { handle = c->op->resps[ri].handle; break; }
477 }
478 }
479 0 ▶ if (!handle) {
Branch: 1 branch
BranchTrueFalseTotal
if (!handle) { 0 0 0
480 0 ▶ for (ri = 0; ri < c->op->nresps; ri++) {
Branch: 1 branch
BranchTrueFalseTotal
for (ri = 0; ri < c->op->nresps; ri++) { 0 0 0
481 0 STRLEN rl; const char *rp = SvPV_const(c->op->resps[ri].status, rl);
482 0 ▶ if (rl == 7 && memEQ(rp, "default", 7))
Branch: 2 branches
BranchTrueFalseTotal
if (rl == 7 && memEQ(rp, "default", 7)) 0 0 0
if (rl == 7 && memEQ(rp, "default", 7)) 0 0 0
483 0 { handle = c->op->resps[ri].handle; break; }
484 }
485 }
486 0 ▶ if (handle) {
Branch: 1 branch
BranchTrueFalseTotal
if (handle) { 0 0 0
487 0 AV *errs = newAV();
488 0 ▶ if (!JSF->validate(aTHX_ handle, data, errs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!JSF->validate(aTHX_ handle, data, errs)) { 0 0 0
489 0 (void)hv_stores(out, "error",
490 newSVpvs("response validation failed"));
491 0 (void)hv_stores(out, "errors", newRV_noinc((SV *)errs));
492 } else {
493 0 SvREFCNT_dec((SV *)errs);
494 }
495 }
496 }
497  
498 4 done:
499 6 ▶ if (c) {
Branch: 1 branch
BranchTrueFalseTotal
if (c) { 6 0 6
500 6 ▶ if (c->api_sv) SvREFCNT_dec(c->api_sv);
Branch: 1 branch
BranchTrueFalseTotal
if (c->api_sv) SvREFCNT_dec(c->api_sv); 6 0 6
501 6 ▶ if (c->cli) SvREFCNT_dec(c->cli);
Branch: 1 branch
BranchTrueFalseTotal
if (c->cli) SvREFCNT_dec(c->cli); 0 6 6
502 6 ▶ if (c->csrf_cookie) SvREFCNT_dec(c->csrf_cookie);
Branch: 1 branch
BranchTrueFalseTotal
if (c->csrf_cookie) SvREFCNT_dec(c->csrf_cookie); 0 6 6
503 6 Safefree(c);
504 }
505 6 return newRV_noinc((SV *)out);
506 }
507  
508 /* ---- call ----------------------------------------------------------------------- */
509  
510 /* the client HV field, or NULL */
511 161 static SV *oa_cli_get(pTHX_ HV *self, const char *k) {
512 161 return oa_get(aTHX_ self, k);
513 }
514  
515 /* lazily build (and cache) the client's Fetch UA from ua_opts */
516 6 static SV *oa_cli_ua(pTHX_ HV *self) {
517 6 SV *ua = oa_cli_get(aTHX_ self, "ua");
518 AV *opts;
519 SV *kv[16];
520 6 int nkv = 0;
521 6 ▶ if (ua && SvROK(ua)) return ua;
Branch: 2 branches
BranchTrueFalseTotal
if (ua && SvROK(ua)) return ua; 1 5 6
if (ua && SvROK(ua)) return ua; 1 0 1
522 5 opts = oa_av_of(oa_cli_get(aTHX_ self, "ua_opts"));
523 5 ▶ if (opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (opts) { 5 0 5
524 5 SSize_t i, n = av_len(opts) + 1;
525 5 ▶ for (i = 0; i < n && nkv < 16; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < n && nkv < 16; i++) { 0 5 5
for (i = 0; i < n && nkv < 16; i++) { 0 0 0
526 0 SV **e = av_fetch(opts, i, 0);
527 0 ▶ kv[nkv++] = (e && *e) ? *e : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
kv[nkv++] = (e && *e) ? *e : &PL_sv_undef; 0 0 0
kv[nkv++] = (e && *e) ? *e : &PL_sv_undef; 0 0 0
528 }
529 }
530 5 ua = OA_FETCH->ua_new(aTHX_ kv, nkv); /* +1 */
531 5 (void)hv_stores(self, "ua", ua); /* HV takes the ref */
532 5 return ua;
533 }
534  
535 /* "user:pass" (or an [user, pass] arrayref) -> mortal "Basic base64" value */
536 0 static SV *oa_cli_basic(pTHX_ SV *cred) {
537 0 AV *av = oa_av_of(cred);
538 0 SV *joined = cred;
539 SV *out;
540 STRLEN l; const char *pv;
541 0 ▶ if (av) {
Branch: 1 branch
BranchTrueFalseTotal
if (av) { 0 0 0
542 0 SV **u = av_fetch(av, 0, 0), **p = av_fetch(av, 1, 0);
543 0 joined = sv_2mortal(newSVpvs(""));
544 0 ▶ if (u && *u && SvOK(*u)) sv_catsv(joined, *u);
Branch: 3 branches
BranchTrueFalseTotal
if (u && *u && SvOK(*u)) sv_catsv(joined, *u); 0 0 0
if (u && *u && SvOK(*u)) sv_catsv(joined, *u); 0 0 0
if (u && *u && SvOK(*u)) sv_catsv(joined, *u); 0 0 0
545 0 sv_catpvs(joined, ":");
546 0 ▶ if (p && *p && SvOK(*p)) sv_catsv(joined, *p);
Branch: 3 branches
BranchTrueFalseTotal
if (p && *p && SvOK(*p)) sv_catsv(joined, *p); 0 0 0
if (p && *p && SvOK(*p)) sv_catsv(joined, *p); 0 0 0
if (p && *p && SvOK(*p)) sv_catsv(joined, *p); 0 0 0
547 }
548 0 pv = SvPV_const(joined, l);
549 0 out = sv_2mortal(newSVpvs("Basic "));
550 0 sv_catsv(out, sv_2mortal(oa_b64_encode(aTHX_ pv, l)));
551 0 return out;
552 }
553  
554 /* An apiKey credential selected from the op's security requirements, to be
555 * attached as a header, a query pair or a cookie. Named rather than anonymous
556 * because oa_cli_url below takes the query ones as an argument. */
557 typedef struct oa_cli_sec { SV *name; SV *val; } oa_cli_sec;
558  
559 /* The request URL: base + interpolated path + query. Split out of
560 * oa_cli_call so the same construction can be inspected without firing a
561 * request - a client's serialization rules (allowReserved) are otherwise
562 * observable only by standing up a real server. `sec_q`/`nsec_q` carry
563 * apiKey-in-query credentials; pass 0 for none. Mortal. */
564 59 static SV *oa_cli_url(pTHX_ oa_op *o, HV *params, SV *base,
565 const oa_cli_sec *sec_q, int nsec_q) {
566 59 SV *url = sv_2mortal(newSVpvs(""));
567 int i;
568  
569 59 ▶ if (base && SvOK(base)) {
Branch: 2 branches
BranchTrueFalseTotal
if (base && SvOK(base)) { 59 0 59
if (base && SvOK(base)) { 59 0 59
570 59 STRLEN bl; const char *bpv = SvPV_const(base, bl);
571 59 ▶ while (bl && bpv[bl - 1] == '/') bl--;
Branch: 2 branches
BranchTrueFalseTotal
while (bl && bpv[bl - 1] == '/') bl--; 59 0 59
while (bl && bpv[bl - 1] == '/') bl--; 0 59 59
572 59 sv_catpvn(url, bpv, bl);
573 }
574 151 ▶ for (i = 0; i < o->nsegs; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < o->nsegs; i++) { 92 59 151
575 92 sv_catpvs(url, "/");
576 92 ▶ if (o->segs[i].lit) {
Branch: 1 branch
BranchTrueFalseTotal
if (o->segs[i].lit) { 59 33 92
577 59 sv_catsv(url, o->segs[i].lit);
578 } else {
579 33 STRLEN nl; const char *np = SvPV_const(o->segs[i].pname, nl);
580 33 SV **v = hv_fetch(params, np, (I32)nl, 0);
581 SV *w;
582 33 oa_param *decl = NULL;
583 int k;
584 /* declared path params were checked by the caller, but a template
585 * var the spec never declared as a parameter reaches here
586 * unchecked */
587 33 ▶ if (!v || !*v || !SvOK(*v))
Branch: 3 branches
BranchTrueFalseTotal
if (!v || !*v || !SvOK(*v)) 33 0 33
if (!v || !*v || !SvOK(*v)) 33 0 33
if (!v || !*v || !SvOK(*v)) 0 33 33
588 0 croak("Open::API::Client: %s: missing required path parameter "
589 "'%.*s'", SvPV_nolen(o->op_id), (int)nl, np);
590 33 w = *v;
591 33 ▶ for (k = 0; k < o->nparams[OA_IN_PATH]; k++)
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k < o->nparams[OA_IN_PATH]; k++) 33 0 33
592 33 ▶ if (sv_eq(o->params[OA_IN_PATH][k].name, o->segs[i].pname)) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv_eq(o->params[OA_IN_PATH][k].name, o->segs[i].pname)) { 33 0 33
593 33 decl = &o->params[OA_IN_PATH][k];
594 33 w = oa_cli_wire(aTHX_ decl, *v);
595 33 break;
596 }
597 /* Always fully encoded: a reserved character in a path segment
598 * changes the SHAPE of the path, so allowReserved does not reach
599 * here even when a path parameter declares it. The style's own
600 * structural characters are written by the serializer and are not
601 * encoded - they ARE the shape. */
602 33 ▶ if (decl) {
Branch: 1 branch
BranchTrueFalseTotal
if (decl) { 33 0 33
603 33 oa_cli_ser_path(aTHX_ decl, w, url);
604 } else {
605 0 STRLEN vl; const char *vp = SvPV_const(w, vl);
606 0 oa_pct_encode_into(aTHX_ url, vp, vl);
607 }
608 }
609 }
610 59 ▶ if (!o->nsegs) sv_catpvs(url, "/");
Branch: 1 branch
BranchTrueFalseTotal
if (!o->nsegs) sv_catpvs(url, "/"); 0 59 59
611 {
612 59 int first = 1;
613 81 ▶ for (i = 0; i < o->nparams[OA_IN_QUERY]; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < o->nparams[OA_IN_QUERY]; i++) { 22 59 81
614 22 oa_param *pp = &o->params[OA_IN_QUERY][i];
615 22 STRLEN nl; const char *np = SvPV_const(pp->name, nl);
616 22 SV **v = hv_fetch(params, np, (I32)nl, 0);
617 int structured;
618 22 ▶ if (!v || !*v || !SvOK(*v)) continue;
Branch: 3 branches
BranchTrueFalseTotal
if (!v || !*v || !SvOK(*v)) continue; 22 0 22
if (!v || !*v || !SvOK(*v)) continue; 22 0 22
if (!v || !*v || !SvOK(*v)) continue; 0 22 22
619 /* a content parameter's arrayref is its DOCUMENT, not a list to
620 * serialize per style: it goes through oa_cli_wire as one value */
621 22 ▶ structured = !pp->ctype && SvROK(*v)
Branch: 1 branch
BranchTrueFalseTotal
structured = !pp->ctype && SvROK(*v) 13 9 22
622 49 ▶ && (SvTYPE(SvRV(*v)) == SVt_PVAV
Branch: 2 branches
BranchTrueFalseTotal
&& (SvTYPE(SvRV(*v)) == SVt_PVAV 22 0 22
&& (SvTYPE(SvRV(*v)) == SVt_PVAV 5 8 13
623 5 ▶ || SvTYPE(SvRV(*v)) == SVt_PVHV);
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*v)) == SVt_PVHV); 5 0 5
624 22 ▶ if (structured) {
Branch: 1 branch
BranchTrueFalseTotal
if (structured) { 13 9 22
625 13 oa_cli_ser_query(aTHX_ pp, *v, url, &first);
626 } else {
627 9 SV *w = oa_cli_wire(aTHX_ pp, *v);
628 9 STRLEN vl; const char *vp = SvPV_const(w, vl);
629 9 ▶ sv_catpvn(url, first ? "?" : "&", 1); first = 0;
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvn(url, first ? "?" : "&", 1); first = 0; 9 0 9
630 9 oa_pct_encode_into(aTHX_ url, np, nl);
631 9 sv_catpvs(url, "=");
632 9 oa_pct_encode_res(aTHX_ url, vp, vl, pp->allow_reserved);
633 }
634 }
635 59 ▶ for (i = 0; i < nsec_q; i++) { /* apiKey-in-query schemes */
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < nsec_q; i++) { /* apiKey-in-query schemes */ 0 59 59
636 STRLEN nl2, vl2;
637 0 const char *np2 = SvPV_const(sec_q[i].name, nl2);
638 0 ▶ const char *vp2 = SvPV_const(sec_q[i].val, vl2);
Branch: 1 branch
BranchTrueFalseTotal
const char *vp2 = SvPV_const(sec_q[i].val, vl2); 0 0 0
639 0 ▶ sv_catpvn(url, first ? "?" : "&", 1); first = 0;
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvn(url, first ? "?" : "&", 1); first = 0; 0 0 0
640 0 oa_pct_encode_into(aTHX_ url, np2, nl2);
641 0 sv_catpvs(url, "=");
642 0 oa_pct_encode_into(aTHX_ url, vp2, vl2);
643 }
644 }
645 59 return url;
646 }
647  
648 /* ---- the request body, per the media type the operation DECLARES ------------
649 *
650 * The builder used to JSON-encode whatever it was handed and label it
651 * `application/json`, whatever the document said. An operation declaring only
652 * `application/x-www-form-urlencoded` therefore sent JSON under the wrong
653 * Content-Type, and this library's OWN server answered 415: a client and a
654 * server generated from one document could not talk to each other.
655 *
656 * Split out of oa_cli_call so `_request_body` can expose it, the way
657 * oa_cli_url is exposed as `_request_url`. Untestable otherwise: a body that
658 * only exists inside a live request cannot be asserted against.
659 */
660  
661 /* Which declared body to send. JSON when the operation declares it - the
662 * safest default and what callers already relied on - then form, then
663 * multipart, then whatever is first. */
664 8 static oa_body *oa_cli_pick_body(oa_op *o) {
665 int i;
666 8 oa_body *form = NULL, *multi = NULL, *any = NULL;
667 12 ▶ for (i = 0; i < o->nbodies; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < o->nbodies; i++) { 8 4 12
668 8 oa_body *b = &o->bodies[i];
669 8 ▶ if (b->kind == OA_MT_JSON) return b;
Branch: 1 branch
BranchTrueFalseTotal
if (b->kind == OA_MT_JSON) return b; 4 4 8
670 4 ▶ if (!form && b->kind == OA_MT_FORM) form = b;
Branch: 2 branches
BranchTrueFalseTotal
if (!form && b->kind == OA_MT_FORM) form = b; 4 0 4
if (!form && b->kind == OA_MT_FORM) form = b; 2 2 4
671 4 ▶ if (!multi && b->kind == OA_MT_MULTIPART) multi = b;
Branch: 2 branches
BranchTrueFalseTotal
if (!multi && b->kind == OA_MT_MULTIPART) multi = b; 4 0 4
if (!multi && b->kind == OA_MT_MULTIPART) multi = b; 2 2 4
672 4 ▶ if (!any) any = b;
Branch: 1 branch
BranchTrueFalseTotal
if (!any) any = b; 4 0 4
673 }
674 4 ▶ return form ? form : multi ? multi : any;
Branch: 2 branches
BranchTrueFalseTotal
return form ? form : multi ? multi : any; 2 2 4
return form ? form : multi ? multi : any; 2 0 2
675 }
676  
677 /* `a=1&b=2`, with an array member repeated unless its Encoding says otherwise.
678 * Members are sorted for the same reason the URL builder sorts them: hash
679 * order is randomised and a body that changes between runs is not one a test
680 * or a signature can rely on. */
681 2 static SV *oa_cli_form_encode(pTHX_ oa_op *o, SV *val) {
682 2 SV *out = sv_2mortal(newSVpvs(""));
683 HV *hv;
684 AV *keys;
685 SSize_t i, n;
686 2 int first = 1;
687 2 ▶ if (!val || !SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVHV)
Branch: 3 branches
BranchTrueFalseTotal
if (!val || !SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVHV) 2 0 2
if (!val || !SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVHV) 2 0 2
if (!val || !SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVHV) 0 2 2
688 0 croak("Open::API::Client: %s: a form body wants a hashref",
689 SvPV_nolen(o->op_id));
690 2 hv = (HV *)SvRV(val);
691 2 keys = oa_cli_sorted_keys(aTHX_ hv);
692 2 n = av_len(keys) + 1;
693 6 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 4 2 6
694 4 SV **k = av_fetch(keys, i, 0);
695 SV **v;
696 STRLEN kl; const char *kp;
697 AV *av;
698 4 ▶ if (!k || !*k) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!k || !*k) continue; 4 0 4
if (!k || !*k) continue; 0 4 4
699 4 kp = SvPV_const(*k, kl);
700 4 v = hv_fetch(hv, kp, (I32)kl, 0);
701 4 ▶ if (!v || !*v || !SvOK(*v)) continue;
Branch: 3 branches
BranchTrueFalseTotal
if (!v || !*v || !SvOK(*v)) continue; 4 0 4
if (!v || !*v || !SvOK(*v)) continue; 4 0 4
if (!v || !*v || !SvOK(*v)) continue; 0 4 4
702 4 av = oa_av_of(*v);
703 4 ▶ if (av) {
Branch: 1 branch
BranchTrueFalseTotal
if (av) { 0 4 4
704 0 SSize_t j, m = av_len(av) + 1;
705 0 ▶ for (j = 0; j < m; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < m; j++) { 0 0 0
706 0 SV **e = av_fetch(av, j, 0);
707 0 ▶ if (!e || !*e || !SvOK(*e)) continue;
Branch: 3 branches
BranchTrueFalseTotal
if (!e || !*e || !SvOK(*e)) continue; 0 0 0
if (!e || !*e || !SvOK(*e)) continue; 0 0 0
if (!e || !*e || !SvOK(*e)) continue; 0 0 0
708 0 ▶ if (!first) sv_catpvs(out, "&");
Branch: 1 branch
BranchTrueFalseTotal
if (!first) sv_catpvs(out, "&"); 0 0 0
709 0 first = 0;
710 0 oa_pct_encode_into(aTHX_ out, kp, kl);
711 0 sv_catpvs(out, "=");
712 0 oa_cli_val(aTHX_ out, *e, 0);
713 }
714 0 continue;
715 }
716 4 ▶ if (!first) sv_catpvs(out, "&");
Branch: 1 branch
BranchTrueFalseTotal
if (!first) sv_catpvs(out, "&"); 2 2 4
717 4 first = 0;
718 4 oa_pct_encode_into(aTHX_ out, kp, kl);
719 4 sv_catpvs(out, "=");
720 4 oa_cli_val(aTHX_ out, *v, 0);
721 }
722 2 return out;
723 }
724  
725 /* multipart/form-data. The boundary is fixed rather than random: this library
726 * sends no binary parts of its own, a body that differs run to run cannot be
727 * asserted, and the value is checked against the payload below. */
728 2 static SV *oa_cli_multipart_encode(pTHX_ oa_op *o, SV *val, const char *bnd) {
729 2 SV *out = sv_2mortal(newSVpvs(""));
730 HV *hv;
731 AV *keys;
732 SSize_t i, n;
733 2 ▶ if (!val || !SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVHV)
Branch: 3 branches
BranchTrueFalseTotal
if (!val || !SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVHV) 2 0 2
if (!val || !SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVHV) 2 0 2
if (!val || !SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVHV) 0 2 2
734 0 croak("Open::API::Client: %s: a multipart body wants a hashref",
735 SvPV_nolen(o->op_id));
736 2 hv = (HV *)SvRV(val);
737 2 keys = oa_cli_sorted_keys(aTHX_ hv);
738 2 n = av_len(keys) + 1;
739 6 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 4 2 6
740 4 SV **k = av_fetch(keys, i, 0);
741 SV **v;
742 STRLEN kl, vl; const char *kp, *vp;
743 4 ▶ if (!k || !*k) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!k || !*k) continue; 4 0 4
if (!k || !*k) continue; 0 4 4
744 4 kp = SvPV_const(*k, kl);
745 4 v = hv_fetch(hv, kp, (I32)kl, 0);
746 4 ▶ if (!v || !*v || !SvOK(*v)) continue;
Branch: 3 branches
BranchTrueFalseTotal
if (!v || !*v || !SvOK(*v)) continue; 4 0 4
if (!v || !*v || !SvOK(*v)) continue; 4 0 4
if (!v || !*v || !SvOK(*v)) continue; 0 4 4
747 /* a boundary that appears inside a part would end it early */
748 4 vp = SvPV_const(*v, vl);
749 4 ▶ if (vl && ninstr(vp, vp + vl, bnd, bnd + strlen(bnd)))
Branch: 2 branches
BranchTrueFalseTotal
if (vl && ninstr(vp, vp + vl, bnd, bnd + strlen(bnd))) 4 0 4
if (vl && ninstr(vp, vp + vl, bnd, bnd + strlen(bnd))) 0 4 4
750 0 croak("Open::API::Client: %s: a multipart value contains the "
751 "boundary", SvPV_nolen(o->op_id));
752 4 sv_catpvs(out, "--"); sv_catpv(out, bnd); sv_catpvs(out, "\r\n");
753 4 sv_catpvs(out, "Content-Disposition: form-data; name=\"");
754 4 sv_catpvn(out, kp, kl);
755 4 sv_catpvs(out, "\"\r\n\r\n");
756 4 sv_catpvn(out, vp, vl);
757 4 sv_catpvs(out, "\r\n");
758 }
759 2 sv_catpvs(out, "--"); sv_catpv(out, bnd); sv_catpvs(out, "--\r\n");
760 2 return out;
761 }
762  
763 #define OA_CLI_BOUNDARY "OpenAPIClientBoundary1"
764  
765 /* Returns a mortal body SV, or NULL when the operation sends none. *ctype is
766 * set to a mortal Content-Type SV whenever a body is returned. */
767 16 static SV *oa_cli_build_body(pTHX_ oa_op *o, HV *params, SV **ctype) {
768 16 SV **bv = hv_fetchs(params, "body", 0);
769 16 ▶ SV *bsv = (bv && *bv && SvOK(*bv)) ? *bv : NULL;
Branch: 3 branches
BranchTrueFalseTotal
SV *bsv = (bv && *bv && SvOK(*bv)) ? *bv : NULL; 8 8 16
SV *bsv = (bv && *bv && SvOK(*bv)) ? *bv : NULL; 8 0 8
SV *bsv = (bv && *bv && SvOK(*bv)) ? *bv : NULL; 8 0 8
770 oa_body *b;
771 SV *out;
772  
773 16 *ctype = NULL;
774 16 ▶ if (!o->nbodies) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!o->nbodies) return NULL; 6 10 16
775 10 ▶ if (!bsv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!bsv) { 2 8 10
776 2 ▶ if (o->body_required)
Branch: 1 branch
BranchTrueFalseTotal
if (o->body_required) 2 0 2
777 4 croak("Open::API::Client: %s: missing required body",
778 SvPV_nolen(o->op_id));
779 0 return NULL;
780 }
781 8 b = oa_cli_pick_body(o);
782 8 ▶ if (!b) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!b) return NULL; 0 8 8
783  
784 /* the declared schema still decides, whatever the media type */
785 8 ▶ if (b->handle && !JSF->is_valid(aTHX_ b->handle, bsv))
Branch: 2 branches
BranchTrueFalseTotal
if (b->handle && !JSF->is_valid(aTHX_ b->handle, bsv)) 8 0 8
if (b->handle && !JSF->is_valid(aTHX_ b->handle, bsv)) 1 7 8
786 1 oa_cli_bad(aTHX_ o, "body", NULL, bsv, b->handle);
787  
788 7 ▶ if (b->kind == OA_MT_FORM) {
Branch: 1 branch
BranchTrueFalseTotal
if (b->kind == OA_MT_FORM) { 2 5 7
789 2 out = oa_cli_form_encode(aTHX_ o, bsv);
790 2 *ctype = sv_2mortal(newSVpvs("application/x-www-form-urlencoded"));
791 2 return out;
792 }
793 5 ▶ if (b->kind == OA_MT_MULTIPART) {
Branch: 1 branch
BranchTrueFalseTotal
if (b->kind == OA_MT_MULTIPART) { 2 3 5
794 2 out = oa_cli_multipart_encode(aTHX_ o, bsv, OA_CLI_BOUNDARY);
795 2 *ctype = sv_2mortal(newSVpvs("multipart/form-data; boundary="
796 OA_CLI_BOUNDARY));
797 2 return out;
798 }
799 3 ▶ if (b->kind == OA_MT_JSON) {
Branch: 1 branch
BranchTrueFalseTotal
if (b->kind == OA_MT_JSON) { 3 0 3
800 3 out = oa_json_encode(aTHX_ bsv);
801 3 ▶ if (!out) croak("Open::API::Client: %s: could not encode body",
Branch: 1 branch
BranchTrueFalseTotal
if (!out) croak("Open::API::Client: %s: could not encode body", 0 3 3
802 SvPV_nolen(o->op_id));
803 3 *ctype = sv_2mortal(newSVsv(b->ctype));
804 3 return out;
805 }
806 /* opaque: send what the caller gave, under the declared type */
807 0 ▶ if (SvROK(bsv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(bsv)) 0 0 0
808 0 croak("Open::API::Client: %s: %" SVf " wants a plain string body",
809 SvPV_nolen(o->op_id), SVfARG(b->ctype));
810 0 out = sv_2mortal(newSVsv(bsv));
811 0 *ctype = sv_2mortal(newSVsv(b->ctype));
812 0 return out;
813 }
814  
815 /* Build and fire one call. params is the flat name => value HV. Returns the
816 * request future (+1). */
817 12 static SV *oa_cli_call(pTHX_ HV *self, SV *op_id, HV *params) {
818 12 SV *api_sv = oa_cli_get(aTHX_ self, "api");
819 oa_api *a;
820 oa_op *o;
821 12 SV *base = oa_cli_get(aTHX_ self, "base_url");
822 SV *url;
823 fetch_hdr hdrs[32];
824 12 int nh = 0;
825 12 SV *cookie = NULL, *bodyjson = NULL;
826 12 const char *bp = NULL;
827 12 STRLEN blen = 0;
828 char method[16];
829 STRLEN ml, mk;
830 const char *mmp;
831 oa_cli_ctx *ctx;
832 int loc, i;
833 SV *ua, *csrf_cfg;
834 12 SV *csrf_cookie_name = NULL; /* set when transparent CSRF is enabled */
835 /* security attachments, selected from the op's requirements below */
836 12 SV *sec_auth = NULL; /* Authorization */
837 oa_cli_sec sec_h[8], sec_q[8], sec_c[8];
838 12 int nsec_h = 0, nsec_q = 0, nsec_c = 0;
839  
840 12 ▶ if (!api_sv || !SvROK(api_sv))
Branch: 2 branches
BranchTrueFalseTotal
if (!api_sv || !SvROK(api_sv)) 12 0 12
if (!api_sv || !SvROK(api_sv)) 0 12 12
841 0 croak("Open::API::Client: no api on this client");
842 12 a = (oa_api *)INT2PTR(void *, SvIV(SvRV(api_sv)));
843 12 o = oa_op_by_id(aTHX_ a, op_id);
844 13 ▶ if (!o) croak("Open::API::Client: unknown operationId '%s'",
Branch: 1 branch
BranchTrueFalseTotal
if (!o) croak("Open::API::Client: unknown operationId '%s'", 1 11 12
845 SvPV_nolen(op_id));
846 11 ▶ if (!oa_fetch_init(aTHX))
Branch: 1 branch
BranchTrueFalseTotal
if (!oa_fetch_init(aTHX)) 0 11 11
847 0 croak("Open::API::Client requires Fetch with its C ABI "
848 "(Fetch 0.05 or later)");
849  
850 /* ---- security: first requirement alternative the credentials cover ---- */
851 11 ▶ if (o->nsec) {
Branch: 1 branch
BranchTrueFalseTotal
if (o->nsec) { 0 11 11
852 0 HV *creds = oa_hv_of(oa_cli_get(aTHX_ self, "security"));
853 0 oa_ops *t = (oa_ops *)a->ops;
854 0 int ai, found = -1;
855 0 ▶ for (ai = 0; ai < o->nsec && found < 0; ai++) {
Branch: 2 branches
BranchTrueFalseTotal
for (ai = 0; ai < o->nsec && found < 0; ai++) { 0 0 0
for (ai = 0; ai < o->nsec && found < 0; ai++) { 0 0 0
856 0 int ii, all = 1;
857 0 ▶ for (ii = 0; ii < o->sec[ai].n; ii++) {
Branch: 1 branch
BranchTrueFalseTotal
for (ii = 0; ii < o->sec[ai].n; ii++) { 0 0 0
858 0 oa_scheme *s = &t->schemes[o->sec[ai].items[ii].scheme];
859 0 STRLEN nl; const char *np = SvPV_const(s->name, nl);
860 0 ▶ SV **c = creds ? hv_fetch(creds, np, (I32)nl, 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV **c = creds ? hv_fetch(creds, np, (I32)nl, 0) : NULL; 0 0 0
861 0 ▶ if (!c || !*c || !SvOK(*c)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!c || !*c || !SvOK(*c)) { 0 0 0
if (!c || !*c || !SvOK(*c)) { 0 0 0
if (!c || !*c || !SvOK(*c)) { 0 0 0
862 /* an apiKey-in-cookie (e.g. a session cookie set at login)
863 * is carried ambiently by the cookie jar, so it needs no
864 * explicit credential; every other scheme does */
865 0 ▶ if (!(s->type == OA_SEC_APIKEY && s->loc == OA_IN_COOKIE))
Branch: 2 branches
BranchTrueFalseTotal
if (!(s->type == OA_SEC_APIKEY && s->loc == OA_IN_COOKIE)) 0 0 0
if (!(s->type == OA_SEC_APIKEY && s->loc == OA_IN_COOKIE)) 0 0 0
866 0 { all = 0; break; }
867 }
868 }
869 0 ▶ if (all) found = ai;
Branch: 1 branch
BranchTrueFalseTotal
if (all) found = ai; 0 0 0
870 }
871 0 ▶ if (found < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (found < 0) 0 0 0
872 0 croak("Open::API::Client: %s: no satisfiable security requirement "
873 "- pass security => { scheme_name => credential }",
874 SvPV_nolen(o->op_id));
875 0 ▶ for (i = 0; i < o->sec[found].n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < o->sec[found].n; i++) { 0 0 0
876 0 oa_scheme *s = &t->schemes[o->sec[found].items[i].scheme];
877 0 STRLEN nl; const char *np = SvPV_const(s->name, nl);
878 0 ▶ SV **cp = creds ? hv_fetch(creds, np, (I32)nl, 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV **cp = creds ? hv_fetch(creds, np, (I32)nl, 0) : NULL; 0 0 0
879 0 ▶ SV *cred = (cp && *cp && SvOK(*cp)) ? *cp : NULL;
Branch: 3 branches
BranchTrueFalseTotal
SV *cred = (cp && *cp && SvOK(*cp)) ? *cp : NULL; 0 0 0
SV *cred = (cp && *cp && SvOK(*cp)) ? *cp : NULL; 0 0 0
SV *cred = (cp && *cp && SvOK(*cp)) ? *cp : NULL; 0 0 0
880 0 switch (s->type) {
881 0 case OA_SEC_APIKEY:
882 0 ▶ if (!cred) break; /* cookie carried by the jar: nothing to add */
Branch: 1 branch
BranchTrueFalseTotal
if (!cred) break; /* cookie carried by the jar: nothing to add */ 0 0 0
883 0 ▶ if (s->loc == OA_IN_HEADER && nsec_h < 8)
Branch: 2 branches
BranchTrueFalseTotal
if (s->loc == OA_IN_HEADER && nsec_h < 8) 0 0 0
if (s->loc == OA_IN_HEADER && nsec_h < 8) 0 0 0
884 0 { sec_h[nsec_h].name = s->pname; sec_h[nsec_h].val = cred; nsec_h++; }
885 0 ▶ else if (s->loc == OA_IN_QUERY && nsec_q < 8)
Branch: 2 branches
BranchTrueFalseTotal
else if (s->loc == OA_IN_QUERY && nsec_q < 8) 0 0 0
else if (s->loc == OA_IN_QUERY && nsec_q < 8) 0 0 0
886 0 { sec_q[nsec_q].name = s->pname; sec_q[nsec_q].val = cred; nsec_q++; }
887 0 ▶ else if (s->loc == OA_IN_COOKIE && nsec_c < 8)
Branch: 2 branches
BranchTrueFalseTotal
else if (s->loc == OA_IN_COOKIE && nsec_c < 8) 0 0 0
else if (s->loc == OA_IN_COOKIE && nsec_c < 8) 0 0 0
888 0 { sec_c[nsec_c].name = s->pname; sec_c[nsec_c].val = cred; nsec_c++; }
889 0 break;
890 0 case OA_SEC_BEARER:
891 0 ▶ if (!cred) break;
Branch: 1 branch
BranchTrueFalseTotal
if (!cred) break; 0 0 0
892 0 sec_auth = sv_2mortal(newSVpvs("Bearer "));
893 0 sv_catsv(sec_auth, cred);
894 0 break;
895 0 case OA_SEC_BASIC:
896 0 ▶ if (!cred) break;
Branch: 1 branch
BranchTrueFalseTotal
if (!cred) break; 0 0 0
897 0 sec_auth = oa_cli_basic(aTHX_ cred);
898 0 break;
899 }
900 }
901 }
902  
903 /* ---- validate every declared parameter (fail before I/O) ---- */
904 46 ▶ for (loc = 0; loc < OA_IN_N; loc++) {
Branch: 1 branch
BranchTrueFalseTotal
for (loc = 0; loc < OA_IN_N; loc++) { 38 8 46
905 47 ▶ for (i = 0; i < o->nparams[loc]; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < o->nparams[loc]; i++) { 12 35 47
906 12 oa_param *pp = &o->params[loc][i];
907 12 STRLEN nl; const char *np = SvPV_const(pp->name, nl);
908 12 SV **v = hv_fetch(params, np, (I32)nl, 0);
909 19 ▶ if (v && *v && SvOK(*v)) {
Branch: 3 branches
BranchTrueFalseTotal
if (v && *v && SvOK(*v)) { 8 4 12
if (v && *v && SvOK(*v)) { 8 0 8
if (v && *v && SvOK(*v)) { 8 0 8
910 8 SV *chk = oa_cli_decoded(aTHX_ o, pp, oa_loc_name(loc), *v);
911 8 ▶ if (pp->handle && !JSF->is_valid(aTHX_ pp->handle, chk))
Branch: 2 branches
BranchTrueFalseTotal
if (pp->handle && !JSF->is_valid(aTHX_ pp->handle, chk)) 8 0 8
if (pp->handle && !JSF->is_valid(aTHX_ pp->handle, chk)) 1 7 8
912 1 oa_cli_bad(aTHX_ o, oa_loc_name(loc), pp->name, chk,
913 pp->handle);
914 4 ▶ } else if (pp->required) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (pp->required) { 2 2 4
915 4 croak("Open::API::Client: %s: missing required %s parameter '%.*s'",
916 SvPV_nolen(o->op_id), oa_loc_name(loc), (int)nl, np);
917 }
918 }
919 }
920  
921 /* ---- body ---- */
922 {
923 8 SV *bctype = NULL;
924 8 bodyjson = oa_cli_build_body(aTHX_ o, params, &bctype);
925 6 ▶ if (bodyjson && bctype) {
Branch: 2 branches
BranchTrueFalseTotal
if (bodyjson && bctype) { 0 6 6
if (bodyjson && bctype) { 0 0 0
926 STRLEN ctl;
927 0 ▶ const char *ctp = SvPV_const(bctype, ctl);
Branch: 1 branch
BranchTrueFalseTotal
const char *ctp = SvPV_const(bctype, ctl); 0 0 0
928 0 bp = SvPV_const(bodyjson, blen);
929 0 hdrs[nh].name = "Content-Type"; hdrs[nh].nlen = 12;
930 0 hdrs[nh].val = ctp; hdrs[nh].vlen = ctl;
931 0 nh++;
932 }
933 }
934  
935 /* ---- URL: base + interpolated path + query ---- */
936 6 url = oa_cli_url(aTHX_ o, params, base, sec_q, nsec_q);
937  
938 /* ---- headers + cookies ---- */
939 12 ▶ for (i = 0; i < o->nparams[OA_IN_HEADER] && nh < 31; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < o->nparams[OA_IN_HEADER] && nh < 31; i++) { 6 6 12
for (i = 0; i < o->nparams[OA_IN_HEADER] && nh < 31; i++) { 6 0 6
940 6 oa_param *pp = &o->params[OA_IN_HEADER][i];
941 6 STRLEN nl; const char *np = SvPV_const(pp->name, nl);
942 6 SV **v = hv_fetch(params, np, (I32)nl, 0);
943 6 ▶ if (v && *v && SvOK(*v)) {
Branch: 3 branches
BranchTrueFalseTotal
if (v && *v && SvOK(*v)) { 4 2 6
if (v && *v && SvOK(*v)) { 4 0 4
if (v && *v && SvOK(*v)) { 4 0 4
944 4 SV *w = oa_cli_wire(aTHX_ pp, *v);
945 STRLEN vl; const char *vp;
946 /* a list or object header is joined, not stringified: SvPV on a
947 * reference puts `ARRAY(0x...)` on the wire */
948 4 ▶ if (SvROK(w) && (SvTYPE(SvRV(w)) == SVt_PVAV
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(w) && (SvTYPE(SvRV(w)) == SVt_PVAV 3 1 4
if (SvROK(w) && (SvTYPE(SvRV(w)) == SVt_PVAV 2 1 3
949 2 ▶ || SvTYPE(SvRV(w)) == SVt_PVHV)) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(w)) == SVt_PVHV)) { 2 0 2
950 3 SV *flat = sv_2mortal(newSVpvs(""));
951 3 oa_cli_ser_flat(aTHX_ pp, w, flat);
952 3 w = flat;
953 }
954 4 vp = SvPV_const(w, vl);
955 4 hdrs[nh].name = np; hdrs[nh].nlen = nl;
956 4 hdrs[nh].val = vp; hdrs[nh].vlen = vl;
957 4 nh++;
958 }
959 }
960 6 ▶ for (i = 0; i < o->nparams[OA_IN_COOKIE]; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < o->nparams[OA_IN_COOKIE]; i++) { 0 6 6
961 0 oa_param *pp = &o->params[OA_IN_COOKIE][i];
962 0 STRLEN nl; const char *np = SvPV_const(pp->name, nl);
963 0 SV **v = hv_fetch(params, np, (I32)nl, 0);
964 0 ▶ if (v && *v && SvOK(*v)) {
Branch: 3 branches
BranchTrueFalseTotal
if (v && *v && SvOK(*v)) { 0 0 0
if (v && *v && SvOK(*v)) { 0 0 0
if (v && *v && SvOK(*v)) { 0 0 0
965 0 ▶ if (!cookie) cookie = sv_2mortal(newSVpvs(""));
Branch: 1 branch
BranchTrueFalseTotal
if (!cookie) cookie = sv_2mortal(newSVpvs("")); 0 0 0
966 0 else sv_catpvs(cookie, "; ");
967 0 sv_catpvn(cookie, np, nl);
968 0 sv_catpvs(cookie, "=");
969 { /* same reference trap as the header loop above */
970 0 SV *w = oa_cli_wire(aTHX_ pp, *v);
971 0 ▶ if (SvROK(w) && (SvTYPE(SvRV(w)) == SVt_PVAV
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(w) && (SvTYPE(SvRV(w)) == SVt_PVAV 0 0 0
if (SvROK(w) && (SvTYPE(SvRV(w)) == SVt_PVAV 0 0 0
972 0 ▶ || SvTYPE(SvRV(w)) == SVt_PVHV))
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(w)) == SVt_PVHV)) 0 0 0
973 0 oa_cli_ser_flat(aTHX_ pp, w, cookie);
974 else
975 0 sv_catsv(cookie, w);
976 }
977 }
978 }
979 6 ▶ for (i = 0; i < nsec_c; i++) { /* apiKey-in-cookie schemes */
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < nsec_c; i++) { /* apiKey-in-cookie schemes */ 0 6 6
980 0 ▶ if (!cookie) cookie = sv_2mortal(newSVpvs(""));
Branch: 1 branch
BranchTrueFalseTotal
if (!cookie) cookie = sv_2mortal(newSVpvs("")); 0 0 0
981 0 else sv_catpvs(cookie, "; ");
982 0 sv_catsv(cookie, sec_c[i].name);
983 0 sv_catpvs(cookie, "=");
984 0 sv_catsv(cookie, sec_c[i].val);
985 }
986 6 ▶ for (i = 0; i < nsec_h && nh < 31; i++) { /* apiKey-in-header schemes */
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < nsec_h && nh < 31; i++) { /* apiKey-in-header schemes */ 0 6 6
for (i = 0; i < nsec_h && nh < 31; i++) { /* apiKey-in-header schemes */ 0 0 0
987 STRLEN nl2, vl2;
988 0 hdrs[nh].name = SvPV_const(sec_h[i].name, nl2); hdrs[nh].nlen = nl2;
989 0 ▶ hdrs[nh].val = SvPV_const(sec_h[i].val, vl2); hdrs[nh].vlen = vl2;
Branch: 1 branch
BranchTrueFalseTotal
hdrs[nh].val = SvPV_const(sec_h[i].val, vl2); hdrs[nh].vlen = vl2; 0 0 0
990 0 nh++;
991 }
992 6 ▶ if (sec_auth && nh < 31) { /* bearer / basic */
Branch: 2 branches
BranchTrueFalseTotal
if (sec_auth && nh < 31) { /* bearer / basic */ 0 6 6
if (sec_auth && nh < 31) { /* bearer / basic */ 0 0 0
993 STRLEN al;
994 0 hdrs[nh].name = "Authorization"; hdrs[nh].nlen = 13;
995 0 hdrs[nh].val = SvPV_const(sec_auth, al); hdrs[nh].vlen = al;
996 0 nh++;
997 }
998 6 ▶ if (cookie && nh < 31) {
Branch: 2 branches
BranchTrueFalseTotal
if (cookie && nh < 31) { 0 6 6
if (cookie && nh < 31) { 0 0 0
999 0 STRLEN cl; const char *cp = SvPV_const(cookie, cl);
1000 0 hdrs[nh].name = "Cookie"; hdrs[nh].nlen = 6;
1001 0 hdrs[nh].val = cp; hdrs[nh].vlen = cl;
1002 0 nh++;
1003 }
1004  
1005 /* ---- transparent CSRF ---- *
1006 * On a state-changing method, present the Origin the server expects and
1007 * echo the CSRF token captured from the previous response into the token
1008 * header (a custom header a cross-site page could not set). The response
1009 * map (oa_cli_map) captures the rotated token for the next call. */
1010 6 csrf_cfg = oa_cli_get(aTHX_ self, "_csrf");
1011 6 ▶ if (csrf_cfg && SvROK(csrf_cfg)) {
Branch: 2 branches
BranchTrueFalseTotal
if (csrf_cfg && SvROK(csrf_cfg)) { 0 6 6
if (csrf_cfg && SvROK(csrf_cfg)) { 0 0 0
1012 0 HV *cd = (HV *)SvRV(csrf_cfg);
1013 0 STRLEN mml; const char *mp2 = SvPV_const(o->method, mml);
1014 0 ▶ int unsafe = !((mml == 3 && memEQ(mp2, "get", 3))
Branch: 2 branches
BranchTrueFalseTotal
int unsafe = !((mml == 3 && memEQ(mp2, "get", 3)) 0 0 0
int unsafe = !((mml == 3 && memEQ(mp2, "get", 3)) 0 0 0
1015 0 ▶ || (mml == 4 && memEQ(mp2, "head", 4))
Branch: 2 branches
BranchTrueFalseTotal
|| (mml == 4 && memEQ(mp2, "head", 4)) 0 0 0
|| (mml == 4 && memEQ(mp2, "head", 4)) 0 0 0
1016 0 ▶ || (mml == 7 && memEQ(mp2, "options", 7))
Branch: 2 branches
BranchTrueFalseTotal
|| (mml == 7 && memEQ(mp2, "options", 7)) 0 0 0
|| (mml == 7 && memEQ(mp2, "options", 7)) 0 0 0
1017 0 ▶ || (mml == 5 && memEQ(mp2, "trace", 5)));
Branch: 2 branches
BranchTrueFalseTotal
|| (mml == 5 && memEQ(mp2, "trace", 5))); 0 0 0
|| (mml == 5 && memEQ(mp2, "trace", 5))); 0 0 0
1018 0 csrf_cookie_name = *hv_fetchs(cd, "cookie", 0); /* for capture */
1019 0 ▶ if (unsafe) {
Branch: 1 branch
BranchTrueFalseTotal
if (unsafe) { 0 0 0
1020 0 SV **org = hv_fetchs(cd, "origin", 0);
1021 0 SV *tok = oa_cli_get(aTHX_ self, "_csrf_token");
1022 0 ▶ if (org && *org && SvOK(*org) && nh < 31) {
Branch: 4 branches
BranchTrueFalseTotal
if (org && *org && SvOK(*org) && nh < 31) { 0 0 0
if (org && *org && SvOK(*org) && nh < 31) { 0 0 0
if (org && *org && SvOK(*org) && nh < 31) { 0 0 0
if (org && *org && SvOK(*org) && nh < 31) { 0 0 0
1023 0 STRLEN ol; const char *op = SvPV_const(*org, ol);
1024 0 hdrs[nh].name = "Origin"; hdrs[nh].nlen = 6;
1025 0 hdrs[nh].val = op; hdrs[nh].vlen = ol;
1026 0 nh++;
1027 }
1028 0 ▶ if (tok && SvOK(tok) && nh < 31) {
Branch: 3 branches
BranchTrueFalseTotal
if (tok && SvOK(tok) && nh < 31) { 0 0 0
if (tok && SvOK(tok) && nh < 31) { 0 0 0
if (tok && SvOK(tok) && nh < 31) { 0 0 0
1029 0 SV *hn = *hv_fetchs(cd, "header", 0);
1030 0 ▶ STRLEN hnl; const char *hnp = SvPV_const(hn, hnl);
Branch: 1 branch
BranchTrueFalseTotal
STRLEN hnl; const char *hnp = SvPV_const(hn, hnl); 0 0 0
1031 0 STRLEN tl; const char *tp = SvPV_const(tok, tl);
1032 0 hdrs[nh].name = hnp; hdrs[nh].nlen = hnl;
1033 0 hdrs[nh].val = tp; hdrs[nh].vlen = tl;
1034 0 nh++;
1035 }
1036 }
1037 }
1038  
1039 /* ---- fire ---- */
1040 6 mmp = SvPV_const(o->method, ml);
1041 6 ▶ if (ml >= sizeof method) ml = sizeof method - 1;
Branch: 1 branch
BranchTrueFalseTotal
if (ml >= sizeof method) ml = sizeof method - 1; 0 6 6
1042 24 ▶ for (mk = 0; mk < ml; mk++) method[mk] = (char)toUPPER((U8)mmp[mk]);
Branch: 2 branches
BranchTrueFalseTotal
for (mk = 0; mk < ml; mk++) method[mk] = (char)toUPPER((U8)mmp[mk]); 18 0 18
for (mk = 0; mk < ml; mk++) method[mk] = (char)toUPPER((U8)mmp[mk]); 18 6 24
1043 6 method[ml] = '\0';
1044 6 Newxz(ctx, 1, oa_cli_ctx);
1045 6 ctx->api_sv = SvREFCNT_inc(api_sv);
1046 6 ctx->op = o;
1047 6 ctx->validate = oa_cli_get(aTHX_ self, "validate")
1048 6 ▶ && SvTRUE(oa_cli_get(aTHX_ self, "validate")) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
&& SvTRUE(oa_cli_get(aTHX_ self, "validate")) ? 1 : 0; 0 6 6
&& SvTRUE(oa_cli_get(aTHX_ self, "validate")) ? 1 : 0; 0 0 0
1049 6 ▶ if (csrf_cookie_name) { /* capture the rotated token from the response */
Branch: 1 branch
BranchTrueFalseTotal
if (csrf_cookie_name) { /* capture the rotated token from the response */ 0 6 6
1050 0 ctx->cli = newRV_inc((SV *)self);
1051 0 ctx->csrf_cookie = newSVsv(csrf_cookie_name);
1052 }
1053 6 ua = oa_cli_ua(aTHX_ self);
1054 12 ▶ return OA_FETCH->request(aTHX_ ua, method, SvPV_nolen(url),
Branch: 1 branch
BranchTrueFalseTotal
return OA_FETCH->request(aTHX_ ua, method, SvPV_nolen(url), 4 2 6
1055 nh ? hdrs : NULL, nh, bp, blen,
1056 0.0, -1, oa_cli_map, ctx);
1057 }
1058  
1059 #endif /* OA_CLIENT_H */
« blib/arch/Open/API/Install/Files.pm ↑ Summary include/oa_mock.h »