include/oa_abi_impl.h

filter: Statementstmt 87.8% 29 / 33 Branchbran 50.0% 15 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 69.8% 44 / 63 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/oa_mock.h ↑ Summary API.xs »
1 #ifndef OA_ABI_IMPL_H
2 #define OA_ABI_IMPL_H
3  
4 /* Open::API-side implementation of the shared C ABI (oa_abi.h). Included by
5 * API.xs AFTER oa_route.h / oa_validate.h / oa_compile.h, so oa_route,
6 * oa_validate_op, oa_op_by_id and the oa_get/oa_hv_of helpers are in scope.
7 * Everything here is private to Open::API's translation unit; consumers reach
8 * it only through the OA_ABI table returned by Open::API::_abi_ptr. */
9  
10 #include "oa_abi.h"
11  
12 /* Like oa_api_of but never croaks - the fall-back path must be able to probe a
13 * value safely. Returns NULL for anything that is not a reference. */
14 5 static void *oa_abi_api_of(pTHX_ SV *api_sv) {
15 5 ▶ if (!api_sv || !SvROK(api_sv)) return NULL;
Branch: 2 branches
BranchTrueFalseTotal
if (!api_sv || !SvROK(api_sv)) return NULL; 5 0 5
if (!api_sv || !SvROK(api_sv)) return NULL; 0 5 5
16 5 return INT2PTR(void *, SvIV(SvRV(api_sv)));
17 }
18  
19 5 static void *oa_abi_route(pTHX_ void *api, const char *method, STRLEN mlen,
20 const char *path, STRLEN plen, HV *caps, AV *allow) {
21 5 oa_api *a = (oa_api *)api;
22 5 ▶ AV *sink = allow ? allow : (AV *)sv_2mortal((SV *)newAV());
Branch: 1 branch
BranchTrueFalseTotal
AV *sink = allow ? allow : (AV *)sv_2mortal((SV *)newAV()); 0 5 5
23 5 ▶ if (!a) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!a) return NULL; 0 5 5
24 5 return (void *)oa_route(aTHX_ a, method, mlen, path, plen, caps, sink);
25 }
26  
27 0 static void *oa_abi_op_by_id(pTHX_ void *api, SV *op_id) {
28 0 oa_api *a = (oa_api *)api;
29 0 ▶ if (!a || !op_id) return NULL;
Branch: 2 branches
BranchTrueFalseTotal
if (!a || !op_id) return NULL; 0 0 0
if (!a || !op_id) return NULL; 0 0 0
30 0 return (void *)oa_op_by_id(aTHX_ a, op_id);
31 }
32  
33 2 static int oa_abi_validate(pTHX_ void *api, void *op, HV *raw,
34 HV *typed, AV *errors) {
35 2 oa_api *a = (oa_api *)api;
36 2 oa_op *o = (oa_op *)op;
37 HV *rawpath, *headers;
38 SV *query, *body;
39 2 HV *params = NULL;
40 int ok;
41 2 ▶ if (!a || !o || !raw) return 0;
Branch: 3 branches
BranchTrueFalseTotal
if (!a || !o || !raw) return 0; 2 0 2
if (!a || !o || !raw) return 0; 2 0 2
if (!a || !o || !raw) return 0; 0 2 2
42 2 rawpath = oa_hv_of(oa_get(aTHX_ raw, "path"));
43 2 headers = oa_hv_of(oa_get(aTHX_ raw, "header"));
44 2 query = oa_get(aTHX_ raw, "query");
45 2 body = oa_get(aTHX_ raw, "body");
46 2 ▶ ok = oa_validate_op(aTHX_ a, o, rawpath, query, headers, body,
Branch: 1 branch
BranchTrueFalseTotal
ok = oa_validate_op(aTHX_ a, o, rawpath, query, headers, body, 2 0 2
47 typed ? &params : NULL, errors);
48 2 ▶ if (ok && typed && params) {
Branch: 3 branches
BranchTrueFalseTotal
if (ok && typed && params) { 1 1 2
if (ok && typed && params) { 1 0 1
if (ok && typed && params) { 1 0 1
49 /* move path/query/header/cookie/body into the caller's HV, then drop
50 * the shell oa_validate_op allocated */
51 HE *he;
52 1 hv_iterinit(params);
53 5 ▶ while ((he = hv_iternext(params))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(params))) { 4 1 5
54 4 I32 kl; const char *k = hv_iterkey(he, &kl);
55 4 SV *v = hv_iterval(params, he);
56 4 (void)hv_store(typed, k, kl, SvREFCNT_inc(v), 0);
57 }
58 1 SvREFCNT_dec((SV *)params);
59 }
60 2 return ok;
61 }
62  
63 3 static SV *oa_abi_op_id(pTHX_ void *op) {
64 3 oa_op *o = (oa_op *)op;
65 3 ▶ return o ? o->op_id : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return o ? o->op_id : NULL; 3 0 3
66 }
67  
68 static const oa_abi OA_ABI = {
69 OA_ABI_VERSION,
70 oa_abi_api_of,
71 oa_abi_route,
72 oa_abi_op_by_id,
73 oa_abi_validate,
74 oa_abi_op_id,
75 };
76  
77 #endif /* OA_ABI_IMPL_H */
« include/oa_mock.h ↑ Summary API.xs »