xs/cookiejar.xs

filter: Statementstmt 26.9% 14 / 52 Branchbran 14.0% 9 / 64 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 19.8% 23 / 116 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/fetch/ft_altsvc.h ↑ Summary include/fetch/ft_h2.h »
1 MODULE = Fetch PACKAGE = Fetch::CookieJar
2  
3 # RFC-6265-ish cookie store; the jar is a C struct behind a blessed IV and all
4 # logic lives in include/fetch/ft_cookiejar.h.
5  
6 SV *
7 new(class, ...)
8 SV *class
9 CODE:
10 {
11 0 ▶ const char *cls = (SvROK(class) && SvOBJECT(SvRV(class)))
Branch: 1 branch
BranchTrueFalseTotal
const char *cls = (SvROK(class) && SvOBJECT(SvRV(class))) 0 0 0
12 18 ▶ ? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class);
Branch: 7 branches
BranchTrueFalseTotal
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 9 9
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
? HvNAME(SvSTASH(SvRV(class))) : SvPV_nolen(class); 0 0 0
13 9 ft_jar *j = ft_jar_new();
14 9 ▶ if (!j) croak("Fetch::CookieJar: out of memory");
Branch: 1 branch
BranchTrueFalseTotal
if (!j) croak("Fetch::CookieJar: out of memory"); 0 9 9
15 9 RETVAL = sv_bless(newRV_noinc(newSViv(PTR2IV(j))),
16 gv_stashpv(cls, GV_ADD));
17 }
18 OUTPUT:
19 RETVAL
20  
21 void
22 DESTROY(self)
23 SV *self
24 CODE:
25 9 ft_jar_free(ft_jar_of(aTHX_ self));
26  
27 # Parse one Set-Cookie value in the context of the request host/path; returns
28 # the jar on a store/delete, or undef if the value was malformed/ignored.
29 SV *
30 set_cookie(self, str, host, req_path)
31 SV *self
32 SV *str
33 const char *host
34 const char *req_path
35 CODE:
36 {
37 6 int touched = 0;
38 6 ▶ if (SvOK(str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(str)) { 6 0 6
39 STRLEN sl;
40 6 const char *ss = SvPV(str, sl);
41 6 ▶ if (sl) touched = ft_jar_set_cookie(ft_jar_of(aTHX_ self),
Branch: 1 branch
BranchTrueFalseTotal
if (sl) touched = ft_jar_set_cookie(ft_jar_of(aTHX_ self), 6 0 6
42 ss, host, req_path);
43 }
44 6 ▶ RETVAL = touched ? SvREFCNT_inc(self) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = touched ? SvREFCNT_inc(self) : newSV(0); 5 1 6
45 }
46 OUTPUT:
47 RETVAL
48  
49 # Pull every Set-Cookie from a Fetch::Response (or Fetch::Headers) and store.
50 SV *
51 extract(self, src, host, req_path)
52 SV *self
53 SV *src
54 const char *host
55 const char *req_path
56 CODE:
57 {
58 0 ft_jar *j = ft_jar_of(aTHX_ self);
59 0 SV *h = src;
60 0 int own_h = 0;
61 0 ▶ if (SvROK(src) && ft_obj_can(aTHX_ src, "headers")) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(src) && ft_obj_can(aTHX_ src, "headers")) { 0 0 0
if (SvROK(src) && ft_obj_can(aTHX_ src, "headers")) { 0 0 0
62 0 dSP;
63 int n;
64 0 ENTER; SAVETMPS;
65 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
66 0 ▶ XPUSHs(src);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(src); 0 0 0
67 0 PUTBACK;
68 0 n = call_method("headers", G_SCALAR);
69 0 SPAGAIN;
70 /* keep a real ref: the returned SV would otherwise be freed by the
71 * FREETMPS below before the get_all call can use it. */
72 0 ▶ if (n) { h = SvREFCNT_inc(POPs); own_h = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (n) { h = SvREFCNT_inc(POPs); own_h = 1; } 0 0 0
73 0 else { h = &PL_sv_undef; }
74 0 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 0 0 0
75 }
76 0 ▶ if (SvROK(h) && ft_obj_can(aTHX_ h, "get_all")) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(h) && ft_obj_can(aTHX_ h, "get_all")) { 0 0 0
if (SvROK(h) && ft_obj_can(aTHX_ h, "get_all")) { 0 0 0
77 0 dSP;
78 int n, i;
79 SV **tmp;
80 0 ENTER; SAVETMPS;
81 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
82 0 ▶ XPUSHs(h);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(h); 0 0 0
83 0 ▶ XPUSHs(sv_2mortal(newSVpvs("set-cookie")));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvs("set-cookie"))); 0 0 0
84 0 PUTBACK;
85 0 n = call_method("get_all", G_ARRAY);
86 0 SPAGAIN;
87 0 ▶ Newx(tmp, n > 0 ? n : 1, SV *);
Branch: 1 branch
BranchTrueFalseTotal
Newx(tmp, n > 0 ? n : 1, SV *); 0 0 0
88 0 ▶ for (i = n - 1; i >= 0; i--) tmp[i] = POPs; /* restore order */
Branch: 1 branch
BranchTrueFalseTotal
for (i = n - 1; i >= 0; i--) tmp[i] = POPs; /* restore order */ 0 0 0
89 0 PUTBACK;
90 0 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 0 0 0
91 0 ▶ if (SvOK(tmp[i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(tmp[i])) { 0 0 0
92 STRLEN vl;
93 0 const char *vs = SvPV(tmp[i], vl);
94 0 ▶ if (vl) ft_jar_set_cookie(j, vs, host, req_path);
Branch: 1 branch
BranchTrueFalseTotal
if (vl) ft_jar_set_cookie(j, vs, host, req_path); 0 0 0
95 }
96 }
97 0 Safefree(tmp);
98 0 ▶ FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; LEAVE; 0 0 0
99 }
100 0 ▶ if (own_h) SvREFCNT_dec(h);
Branch: 1 branch
BranchTrueFalseTotal
if (own_h) SvREFCNT_dec(h); 0 0 0
101 0 RETVAL = SvREFCNT_inc(self);
102 }
103 OUTPUT:
104 RETVAL
105  
106 # The Cookie header value for a request, or undef if nothing matches.
107 SV *
108 cookie_header(self, host, req_path, secure)
109 SV *self
110 const char *host
111 const char *req_path
112 int secure
113 CODE:
114 {
115 7 char *s = ft_jar_cookie_str(ft_jar_of(aTHX_ self), host, req_path, secure);
116 7 ▶ RETVAL = s ? newSVpv(s, 0) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = s ? newSVpv(s, 0) : newSV(0); 4 3 7
117 7 free(s);
118 }
119 OUTPUT:
120 RETVAL
121  
122 SV *
123 clear(self)
124 SV *self
125 CODE:
126 0 ft_jar_clear(ft_jar_of(aTHX_ self));
127 0 RETVAL = SvREFCNT_inc(self);
128 OUTPUT:
129 RETVAL
130  
131 int
132 count(self)
133 SV *self
134 CODE:
135 2 ▶ RETVAL = (int)ft_jar_of(aTHX_ self)->n;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (int)ft_jar_of(aTHX_ self)->n; 0 2 2
136 OUTPUT:
137 RETVAL
138  
139 int
140 purge(self)
141 SV *self
142 CODE:
143 0 RETVAL = ft_jar_purge(ft_jar_of(aTHX_ self));
144 OUTPUT:
145 RETVAL
« include/fetch/ft_altsvc.h ↑ Summary include/fetch/ft_h2.h »