src/xs/protocol/http.h

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 75 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/xs/protocol/http.cc ↑ Summary xs/Compression.xsi »
1 #pragma once
2 #include <xs/uri.h>
3 #include <xs/date.h>
4 #include <xs/function.h>
5 #include <panda/protocol/http/RequestParser.h>
6 #include <panda/protocol/http/ResponseParser.h>
7 #include <panda/protocol/http/CookieJar.h>
8  
9 namespace xs { namespace protocol { namespace http {
10 using namespace panda::protocol::http;
11  
12 void fill (Request*, const Hash&);
13 void fill (Response*, const Hash&);
14 void fill_form(Request*, const Sv&);
15  
16 void set_headers (Message*, const Hash&);
17 void set_method (Request*, const Sv&);
18 void set_request_cookies (Request*, const Hash&);
19 void set_response_cookies (Response*, const Hash&);
20  
21 template <typename T>
22 0 Simple strings_to_sv (const T& v) {
23 0 size_t len = 0;
24 0 ▶ for (const auto& s : v) len += s.length();
Branch: 2 branches
BranchTrueFalseTotal
for (const auto& s : v) len += s.length(); 0 0 0
for (const auto& s : v) len += s.length(); 0 0 0
25 0 ▶ if (!len) return Simple::undef;
Branch: 4 branches
BranchTrueFalseTotal
if (!len) return Simple::undef; 0 0 0
if (!len) return Simple::undef; 0 0 0
if (!len) return Simple::undef; 0 0 0
if (!len) return Simple::undef; 0 0 0
26  
27 0 ▶ auto ret = Simple::create(len);
Branch: 2 branches
BranchTrueFalseTotal
auto ret = Simple::create(len); 0 0 0
auto ret = Simple::create(len); 0 0 0
28 0 char* dest = ret.get<char*>();
29 0 ▶ for (const auto& s : v) {
Branch: 2 branches
BranchTrueFalseTotal
for (const auto& s : v) { 0 0 0
for (const auto& s : v) { 0 0 0
30 0 memcpy(dest, s.data(), s.length());
31 0 dest += s.length();
32 }
33 0 *dest = 0;
34 0 ret.length(len);
35 0 return ret;
36 0 }
37 }}}
38  
39 namespace xs {
40  
41 template <>
42 struct Typemap<panda::protocol::http::State> : TypemapBase<panda::protocol::http::State> {
43 using State = panda::protocol::http::State;
44 static inline State in (SV* arg) { return (State)SvIV(arg); }
45 0 ▶ static inline Sv out (State var, const Sv& = Sv()) { return Simple((int)var); }
Branch: 1 branch
BranchTrueFalseTotal
static inline Sv out (State var, const Sv& = Sv()) { return Simple((int)var); } 0 0 0
46 };
47  
48 template <class TYPE>
49 struct Typemap<panda::protocol::http::Message*, TYPE> : TypemapObject<panda::protocol::http::Message*, TYPE, ObjectTypeRefcntPtr, ObjectStorageMGBackref> {};
50  
51 template <class TYPE>
52 struct Typemap<panda::protocol::http::Request*, TYPE> : Typemap<panda::protocol::http::Message*, TYPE> {
53 0 static panda::string_view package () { return "Protocol::HTTP::Request"; }
54 };
55  
56 template <class TYPE>
57 struct Typemap<panda::protocol::http::RequestSP, panda::iptr<TYPE>> : Typemap<TYPE*> {
58 using Super = Typemap<TYPE*>;
59 static panda::iptr<TYPE> in (Sv arg) {
60 if (arg.is_object_ref()) return Super::in(arg);
61 else if (!arg.defined()) return {};
62 panda::iptr<TYPE> ret = make_backref<TYPE>();
63 xs::protocol::http::fill(ret.get(), arg);
64 return ret;
65 }
66 };
67  
68 template <class TYPE>
69 struct Typemap<panda::protocol::http::Response*, TYPE> : Typemap<panda::protocol::http::Message*, TYPE> {
70 0 static panda::string_view package () { return "Protocol::HTTP::Response"; }
71 };
72  
73 template <class TYPE>
74 struct Typemap<panda::protocol::http::ResponseSP, panda::iptr<TYPE>> : Typemap<TYPE*> {
75 using Super = Typemap<TYPE*>;
76 static panda::iptr<TYPE> in (Sv arg) {
77 if (arg.is_object_ref()) return Super::in(arg);
78 else if (!arg.defined()) return {};
79 panda::iptr<TYPE> ret = make_backref<TYPE>();
80 xs::protocol::http::fill(ret.get(), arg);
81 return ret;
82 }
83 };
84  
85 template <>
86 struct Typemap<panda::protocol::http::Response::Cookie> : TypemapBase<panda::protocol::http::Response::Cookie> {
87 using Cookie = panda::protocol::http::Response::Cookie;
88 static Cookie in (const Hash& arg);
89 static Sv out (const Cookie&, const Sv& = {});
90 };
91  
92 template <class TYPE>
93 struct Typemap<panda::protocol::http::RequestParser*, TYPE> : TypemapObject<panda::protocol::http::RequestParser*, TYPE, ObjectTypePtr, ObjectStorageMG> {
94 0 ▶ static std::string package () { return "Protocol::HTTP::RequestParser"; }
Branch: 1 branch
BranchTrueFalseTotal
static std::string package () { return "Protocol::HTTP::RequestParser"; } 0 0 0
95 };
96  
97 template <class TYPE>
98 struct Typemap<panda::protocol::http::ResponseParser*, TYPE> : TypemapObject<panda::protocol::http::ResponseParser*, TYPE, ObjectTypePtr, ObjectStorageMG> {
99 0 ▶ static std::string package () { return "Protocol::HTTP::ResponseParser"; }
Branch: 1 branch
BranchTrueFalseTotal
static std::string package () { return "Protocol::HTTP::ResponseParser"; } 0 0 0
100 };
101  
102 template <class TYPE>
103 struct Typemap<panda::protocol::http::CookieJar*, TYPE> : TypemapObject<panda::protocol::http::CookieJar*, TYPE, ObjectTypeRefcntPtr, ObjectStorageMG> {
104 0 ▶ static std::string package () { return "Protocol::HTTP::CookieJar"; }
Branch: 1 branch
BranchTrueFalseTotal
static std::string package () { return "Protocol::HTTP::CookieJar"; } 0 0 0
105 };
106  
107 template <>
108 struct Typemap<panda::protocol::http::CookieJar::Cookie> : Typemap<panda::protocol::http::Response::Cookie> {
109 using Cookie = panda::protocol::http::CookieJar::Cookie;
110 static Sv out (const Cookie&, const Sv& = {});
111 };
112  
113 template <>
114 struct Typemap<panda::protocol::http::CookieJar::Cookies> : TypemapBase<panda::protocol::http::CookieJar::Cookies> {
115 using Cookies = panda::protocol::http::CookieJar::Cookies;
116 static Sv out (const Cookies&, const Sv& = {});
117 };
118  
119 template <>
120 struct Typemap<panda::protocol::http::CookieJar::DomainCookies> : TypemapBase<panda::protocol::http::CookieJar::DomainCookies> {
121 using DomainCookies = panda::protocol::http::CookieJar::DomainCookies;
122 static Sv out (const DomainCookies&, const Sv& = {});
123 };
124  
125  
126 }
« src/xs/protocol/http.cc ↑ Summary xs/Compression.xsi »