HTTP1.xs

filter: Statementstmt 82.0% 801 / 976 Branchbran 62.9% 638 / 1014 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 72.3% 1439 / 1990 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« vendor/picohttpparser/picohttpparser.c ↑ Summary blib/lib/Unblock/HTTP1.pm »
1 #define PERL_NO_GET_CONTEXT
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5 #include "uniform_http_fastpath.h"
6 #include "unblock_http1_native_abi.h"
7  
8 #include "vendor/picohttpparser/picohttpparser.c"
9  
10 #define UB_HTTP1_MAX_HEADERS 256
11 #define UB_BODY_NONE 0
12 #define UB_BODY_CONTENT_LENGTH 1
13 #define UB_BODY_CHUNKED 2
14  
15 static int
16 447 ascii_equal_ci(const char *left, size_t left_len, const char *right, size_t right_len)
17 {
18 size_t i;
19 447 ▶ if (left_len != right_len)
Branch: 1 branch
BranchTrueFalseTotal
if (left_len != right_len) 247 200 447
20 247 return 0;
21 1745 ▶ for (i = 0; i < left_len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < left_len; ++i) { 1547 198 1745
22 1547 unsigned char a = (unsigned char)left[i];
23 1547 unsigned char b = (unsigned char)right[i];
24 1547 ▶ if (a >= 'A' && a <= 'Z') a = (unsigned char)(a + ('a' - 'A'));
Branch: 2 branches
BranchTrueFalseTotal
if (a >= 'A' && a <= 'Z') a = (unsigned char)(a + ('a' - 'A')); 1466 81 1547
if (a >= 'A' && a <= 'Z') a = (unsigned char)(a + ('a' - 'A')); 197 1269 1466
25 1547 ▶ if (b >= 'A' && b <= 'Z') b = (unsigned char)(b + ('a' - 'A'));
Branch: 2 branches
BranchTrueFalseTotal
if (b >= 'A' && b <= 'Z') b = (unsigned char)(b + ('a' - 'A')); 1466 81 1547
if (b >= 'A' && b <= 'Z') b = (unsigned char)(b + ('a' - 'A')); 197 1269 1466
26 1547 ▶ if (a != b) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (a != b) return 0; 2 1545 1547
27 }
28 198 return 1;
29 }
30  
31 static int
32 549 is_ows(unsigned char c)
33 {
34 549 ▶ return c == ' ' || c == '\t';
Branch: 2 branches
BranchTrueFalseTotal
return c == ' ' || c == '\t'; 537 12 549
return c == ' ' || c == '\t'; 0 537 537
35 }
36  
37 static int
38 2639 is_tchar(unsigned char c)
39 {
40 2639 ▶ if ((c >= '0' && c <= '9') ||
Branch: 3 branches
BranchTrueFalseTotal
if ((c >= '0' && c <= '9') || 2520 119 2639
if ((c >= '0' && c <= '9') || 2520 0 2520
if ((c >= '0' && c <= '9') || 2519 120 2639
41 2639 ▶ (c >= 'A' && c <= 'Z') ||
Branch: 2 branches
BranchTrueFalseTotal
(c >= 'A' && c <= 'Z') || 2128 391 2519
(c >= 'A' && c <= 'Z') || 2128 120 2248
42 2128 ▶ (c >= 'a' && c <= 'z'))
Branch: 1 branch
BranchTrueFalseTotal
(c >= 'a' && c <= 'z')) 2128 0 2128
43 2519 return 1;
44 120 ▶ switch (c) {
Branch: 1 branch
BranchTrueFalseTotal
switch (c) { 115 5 120
45 115 case '!': case '#': case '$': case '%': case '&': case '\'':
46 case '*': case '+': case '-': case '.': case '^': case '_':
47 case 0x60: case '|': case '~':
48 115 return 1;
49 5 default:
50 5 return 0;
51 }
52 }
53  
54 static int
55 263 valid_field_name(const char *name, size_t len)
56 {
57 size_t i;
58 263 ▶ if (len == 0) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (len == 0) return 0; 0 263 263
59 2602 ▶ for (i = 0; i < len; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; ++i) 2339 263 2602
60 2339 ▶ if (!is_tchar((unsigned char)name[i])) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!is_tchar((unsigned char)name[i])) return 0; 0 2339 2339
61 263 return 1;
62 }
63  
64 static int
65 325 valid_field_value(const char *value, size_t len)
66 {
67 size_t i;
68 3094 ▶ for (i = 0; i < len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; ++i) { 2769 325 3094
69 2769 unsigned char c = (unsigned char)value[i];
70 2769 ▶ if (c == '\t') continue;
Branch: 1 branch
BranchTrueFalseTotal
if (c == '\t') continue; 0 2769 2769
71 2769 ▶ if (c < 0x20 || c == 0x7f) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (c < 0x20 || c == 0x7f) return 0; 2769 0 2769
if (c < 0x20 || c == 0x7f) return 0; 0 2769 2769
72 }
73 325 return 1;
74 }
75  
76 static int
77 90 valid_host_value(const char *value, size_t len)
78 {
79 size_t i;
80 90 size_t close_bracket = (size_t)-1;
81 90 size_t colon_count = 0;
82 90 ▶ if (len == 0) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if (len == 0) return 1; 0 90 90
83 1175 ▶ for (i = 0; i < len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; ++i) { 1086 89 1175
84 1086 unsigned char c = (unsigned char)value[i];
85 1086 ▶ if (c <= 0x20 || c >= 0x7f) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (c <= 0x20 || c >= 0x7f) return 0; 1085 1 1086
if (c <= 0x20 || c >= 0x7f) return 0; 0 1085 1085
86 1085 ▶ if (c == '/' || c == '?' || c == '#' || c == '@') return 0;
Branch: 4 branches
BranchTrueFalseTotal
if (c == '/' || c == '?' || c == '#' || c == '@') return 0; 1085 0 1085
if (c == '/' || c == '?' || c == '#' || c == '@') return 0; 1085 0 1085
if (c == '/' || c == '?' || c == '#' || c == '@') return 0; 1085 0 1085
if (c == '/' || c == '?' || c == '#' || c == '@') return 0; 0 1085 1085
87 }
88 89 ▶ if (value[0] == '[') {
Branch: 1 branch
BranchTrueFalseTotal
if (value[0] == '[') { 2 87 89
89 8 ▶ for (i = 1; i < len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < len; ++i) { 8 0 8
90 8 ▶ if (value[i] == ']') { close_bracket = i; break; }
Branch: 1 branch
BranchTrueFalseTotal
if (value[i] == ']') { close_bracket = i; break; } 2 6 8
91 }
92 2 ▶ if (close_bracket == (size_t)-1 || close_bracket == 1) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (close_bracket == (size_t)-1 || close_bracket == 1) return 0; 2 0 2
if (close_bracket == (size_t)-1 || close_bracket == 1) return 0; 0 2 2
93 2 ▶ if (close_bracket + 1 == len) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if (close_bracket + 1 == len) return 1; 0 2 2
94 2 ▶ if (value[close_bracket + 1] != ':') return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (value[close_bracket + 1] != ':') return 0; 0 2 2
95 2 ▶ if (close_bracket + 2 == len) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if (close_bracket + 2 == len) return 1; 0 2 2
96 9 ▶ for (i = close_bracket + 2; i < len; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = close_bracket + 2; i < len; ++i) 7 2 9
97 7 ▶ if (value[i] < '0' || value[i] > '9') return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (value[i] < '0' || value[i] > '9') return 0; 7 0 7
if (value[i] < '0' || value[i] > '9') return 0; 0 7 7
98 2 return 1;
99 }
100 1121 ▶ for (i = 0; i < len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; ++i) { 1042 79 1121
101 1042 ▶ if (value[i] == ':') {
Branch: 1 branch
BranchTrueFalseTotal
if (value[i] == ':') { 8 1034 1042
102 size_t j;
103 8 ++colon_count;
104 8 ▶ if (colon_count > 1) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (colon_count > 1) return 0; 0 8 8
105 29 ▶ for (j = i + 1; j < len; ++j)
Branch: 1 branch
BranchTrueFalseTotal
for (j = i + 1; j < len; ++j) 21 8 29
106 21 ▶ if (value[j] < '0' || value[j] > '9') return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (value[j] < '0' || value[j] > '9') return 0; 21 0 21
if (value[j] < '0' || value[j] > '9') return 0; 0 21 21
107 8 break;
108 }
109 }
110 87 return 1;
111 }
112  
113 static int
114 219 ascii_equal_cs(const char *left, size_t left_len, const char *right, size_t right_len)
115 {
116 219 ▶ return left_len == right_len && memEQ(left, right, right_len);
Branch: 2 branches
BranchTrueFalseTotal
return left_len == right_len && memEQ(left, right, right_len); 30 189 219
return left_len == right_len && memEQ(left, right, right_len); 29 1 30
117 }
118  
119 static int
120 12 valid_port_number(const char *value, size_t len)
121 {
122 size_t i;
123 12 unsigned int port = 0;
124 12 ▶ if (len == 0) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (len == 0) return 0; 0 12 12
125 47 ▶ for (i = 0; i < len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; ++i) { 36 11 47
126 unsigned int digit;
127 36 ▶ if (value[i] < '0' || value[i] > '9') return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (value[i] < '0' || value[i] > '9') return 0; 36 0 36
if (value[i] < '0' || value[i] > '9') return 0; 0 36 36
128 36 digit = (unsigned int)(value[i] - '0');
129 36 ▶ if (port > 6553 || (port == 6553 && digit > 5)) return 0;
Branch: 3 branches
BranchTrueFalseTotal
if (port > 6553 || (port == 6553 && digit > 5)) return 0; 36 0 36
if (port > 6553 || (port == 6553 && digit > 5)) return 0; 1 35 36
if (port > 6553 || (port == 6553 && digit > 5)) return 0; 1 0 1
130 35 port = port * 10 + digit;
131 }
132 11 return port != 0;
133 }
134  
135 static int
136 14 valid_connect_authority(const char *target, size_t len)
137 {
138 size_t i;
139 14 ▶ if (len < 3) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (len < 3) return 0; 0 14 14
140  
141 14 ▶ if (target[0] == '[') {
Branch: 1 branch
BranchTrueFalseTotal
if (target[0] == '[') { 1 13 14
142 1 size_t close_bracket = (size_t)-1;
143 4 ▶ for (i = 1; i < len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < len; ++i) { 4 0 4
144 4 ▶ if (target[i] == ']') {
Branch: 1 branch
BranchTrueFalseTotal
if (target[i] == ']') { 1 3 4
145 1 close_bracket = i;
146 1 break;
147 }
148 }
149 1 ▶ if (close_bracket == (size_t)-1 || close_bracket == 1) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (close_bracket == (size_t)-1 || close_bracket == 1) return 0; 1 0 1
if (close_bracket == (size_t)-1 || close_bracket == 1) return 0; 0 1 1
150 1 ▶ if (close_bracket + 2 >= len || target[close_bracket + 1] != ':')
Branch: 2 branches
BranchTrueFalseTotal
if (close_bracket + 2 >= len || target[close_bracket + 1] != ':') 1 0 1
if (close_bracket + 2 >= len || target[close_bracket + 1] != ':') 0 1 1
151 0 return 0;
152 4 ▶ for (i = 1; i < close_bracket; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < close_bracket; ++i) { 3 1 4
153 3 unsigned char ch = (unsigned char)target[i];
154 3 ▶ if (ch <= 0x20 || ch == 0x7f ||
Branch: 3 branches
BranchTrueFalseTotal
if (ch <= 0x20 || ch == 0x7f || 3 0 3
if (ch <= 0x20 || ch == 0x7f || 3 0 3
if (ch <= 0x20 || ch == 0x7f || 3 0 3
155 3 ▶ ch == '/' || ch == '?' || ch == '#' || ch == '@')
Branch: 3 branches
BranchTrueFalseTotal
ch == '/' || ch == '?' || ch == '#' || ch == '@') 3 0 3
ch == '/' || ch == '?' || ch == '#' || ch == '@') 3 0 3
ch == '/' || ch == '?' || ch == '#' || ch == '@') 0 3 3
156 0 return 0;
157 }
158 1 return valid_port_number(
159 1 target + close_bracket + 2,
160 1 len - close_bracket - 2
161 );
162 }
163  
164 {
165 13 size_t colon = (size_t)-1;
166 201 ▶ for (i = 0; i < len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; ++i) { 189 12 201
167 189 unsigned char ch = (unsigned char)target[i];
168 189 ▶ if (ch <= 0x20 || ch == 0x7f ||
Branch: 3 branches
BranchTrueFalseTotal
if (ch <= 0x20 || ch == 0x7f || 189 0 189
if (ch <= 0x20 || ch == 0x7f || 189 0 189
if (ch <= 0x20 || ch == 0x7f || 188 1 189
169 188 ▶ ch == '/' || ch == '?' || ch == '#' || ch == '@')
Branch: 3 branches
BranchTrueFalseTotal
ch == '/' || ch == '?' || ch == '#' || ch == '@') 188 0 188
ch == '/' || ch == '?' || ch == '#' || ch == '@') 188 0 188
ch == '/' || ch == '?' || ch == '#' || ch == '@') 0 188 188
170 1 return 0;
171 188 ▶ if (target[i] == ':') {
Branch: 1 branch
BranchTrueFalseTotal
if (target[i] == ':') { 11 177 188
172 11 ▶ if (colon != (size_t)-1) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (colon != (size_t)-1) return 0; 0 11 11
173 11 colon = i;
174 }
175 }
176 12 ▶ if (colon == (size_t)-1 || colon == 0 || colon + 1 == len) return 0;
Branch: 3 branches
BranchTrueFalseTotal
if (colon == (size_t)-1 || colon == 0 || colon + 1 == len) return 0; 11 1 12
if (colon == (size_t)-1 || colon == 0 || colon + 1 == len) return 0; 11 0 11
if (colon == (size_t)-1 || colon == 0 || colon + 1 == len) return 0; 0 11 11
177 11 return valid_port_number(target + colon + 1, len - colon - 1);
178 }
179 }
180  
181 static int
182 7 connect_host_matches_target(const char *host, size_t host_len,
183 const char *target, size_t target_len)
184 {
185 7 size_t target_host_len = 0;
186 7 size_t compare_host_len = host_len;
187 size_t i;
188  
189 7 ▶ if (ascii_equal_ci(host, host_len, target, target_len))
Branch: 1 branch
BranchTrueFalseTotal
if (ascii_equal_ci(host, host_len, target, target_len)) 5 2 7
190 5 return 1;
191  
192 2 ▶ if (host_len && host[host_len - 1] == ':')
Branch: 2 branches
BranchTrueFalseTotal
if (host_len && host[host_len - 1] == ':') 2 0 2
if (host_len && host[host_len - 1] == ':') 0 2 2
193 0 --compare_host_len;
194  
195 2 ▶ if (target_len == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (target_len == 0) 0 2 2
196 0 return 0;
197  
198 2 ▶ if (target[0] == '[') {
Branch: 1 branch
BranchTrueFalseTotal
if (target[0] == '[') { 0 2 2
199 0 ▶ for (i = 1; i < target_len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < target_len; ++i) { 0 0 0
200 0 ▶ if (target[i] == ']') {
Branch: 1 branch
BranchTrueFalseTotal
if (target[i] == ']') { 0 0 0
201 0 target_host_len = i + 1;
202 0 break;
203 }
204 }
205 } else {
206 26 ▶ for (i = 0; i < target_len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < target_len; ++i) { 26 0 26
207 26 ▶ if (target[i] == ':') {
Branch: 1 branch
BranchTrueFalseTotal
if (target[i] == ':') { 2 24 26
208 2 target_host_len = i;
209 2 break;
210 }
211 }
212 }
213  
214 return target_host_len != 0
215 2 ▶ && ascii_equal_ci(host, compare_host_len, target, target_host_len);
Branch: 2 branches
BranchTrueFalseTotal
&& ascii_equal_ci(host, compare_host_len, target, target_host_len); 2 0 2
&& ascii_equal_ci(host, compare_host_len, target, target_host_len); 1 1 2
216 }
217  
218 static int
219 110 valid_request_target(const char *method, size_t method_len,
220 const char *target, size_t target_len)
221 {
222 size_t i;
223 110 ▶ if (target_len == 0) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (target_len == 0) return 0; 0 110 110
224  
225 653 ▶ for (i = 0; i < target_len; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < target_len; ++i) 544 109 653
226 544 ▶ if (target[i] == '#') return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (target[i] == '#') return 0; 1 543 544
227  
228 109 ▶ if (target_len == 1 && target[0] == '*')
Branch: 2 branches
BranchTrueFalseTotal
if (target_len == 1 && target[0] == '*') 59 50 109
if (target_len == 1 && target[0] == '*') 2 57 59
229 2 return ascii_equal_cs(method, method_len, "OPTIONS", 7);
230  
231 107 ▶ if (ascii_equal_cs(method, method_len, "CONNECT", 7))
Branch: 1 branch
BranchTrueFalseTotal
if (ascii_equal_cs(method, method_len, "CONNECT", 7)) 14 93 107
232 14 return valid_connect_authority(target, target_len);
233  
234 93 ▶ if (target[0] == '/') return 1;
Branch: 1 branch
BranchTrueFalseTotal
if (target[0] == '/') return 1; 88 5 93
235  
236 5 ▶ if (!((target[0] >= 'A' && target[0] <= 'Z') ||
Branch: 2 branches
BranchTrueFalseTotal
if (!((target[0] >= 'A' && target[0] <= 'Z') || 5 0 5
if (!((target[0] >= 'A' && target[0] <= 'Z') || 5 0 5
237 5 ▶ (target[0] >= 'a' && target[0] <= 'z')))
Branch: 2 branches
BranchTrueFalseTotal
(target[0] >= 'a' && target[0] <= 'z'))) 5 0 5
(target[0] >= 'a' && target[0] <= 'z'))) 0 5 5
238 0 return 0;
239  
240 24 ▶ for (i = 1; i < target_len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < target_len; ++i) { 24 0 24
241 24 unsigned char ch = (unsigned char)target[i];
242 24 ▶ if (ch == ':') {
Branch: 1 branch
BranchTrueFalseTotal
if (ch == ':') { 4 20 24
243 4 if (ascii_equal_ci(target, i, "http", 4) ||
244 0 ascii_equal_ci(target, i, "https", 5)) {
245 4 size_t pos = i + 1;
246 size_t authority_start;
247  
248 4 ▶ if (pos + 1 >= target_len ||
Branch: 1 branch
BranchTrueFalseTotal
if (pos + 1 >= target_len || 4 0 4
249 4 ▶ target[pos] != '/' || target[pos + 1] != '/')
Branch: 2 branches
BranchTrueFalseTotal
target[pos] != '/' || target[pos + 1] != '/') 3 1 4
target[pos] != '/' || target[pos + 1] != '/') 0 3 3
250 1 return 0;
251  
252 3 pos += 2;
253 3 authority_start = pos;
254 3 while (pos < target_len &&
255 22 ▶ target[pos] != '/' && target[pos] != '?') {
Branch: 3 branches
BranchTrueFalseTotal
target[pos] != '/' && target[pos] != '?') { 22 0 22
target[pos] != '/' && target[pos] != '?') { 20 2 22
target[pos] != '/' && target[pos] != '?') { 20 0 20
256 20 ▶ if (target[pos] == '@')
Branch: 1 branch
BranchTrueFalseTotal
if (target[pos] == '@') 1 19 20
257 1 return 0;
258 19 ++pos;
259 }
260 2 ▶ if (pos == authority_start || target[authority_start] == ':')
Branch: 2 branches
BranchTrueFalseTotal
if (pos == authority_start || target[authority_start] == ':') 2 0 2
if (pos == authority_start || target[authority_start] == ':') 1 1 2
261 1 return 0;
262 }
263 1 return 1;
264 }
265 21 ▶ if (!((ch >= 'A' && ch <= 'Z') ||
Branch: 4 branches
BranchTrueFalseTotal
if (!((ch >= 'A' && ch <= 'Z') || 19 1 20
if (!((ch >= 'A' && ch <= 'Z') || 19 0 19
if (!((ch >= 'A' && ch <= 'Z') || 19 1 20
if (!((ch >= 'A' && ch <= 'Z') || 1 0 1
266 20 ▶ (ch >= 'a' && ch <= 'z') ||
Branch: 2 branches
BranchTrueFalseTotal
(ch >= 'a' && ch <= 'z') || 0 19 19
(ch >= 'a' && ch <= 'z') || 0 1 1
267 1 ▶ (ch >= '0' && ch <= '9') ||
Branch: 2 branches
BranchTrueFalseTotal
(ch >= '0' && ch <= '9') || 0 0 0
(ch >= '0' && ch <= '9') || 1 0 1
268 1 ▶ ch == '+' || ch == '-' || ch == '.'))
Branch: 1 branch
BranchTrueFalseTotal
ch == '+' || ch == '-' || ch == '.')) 1 0 1
269 1 return 0;
270 }
271 0 return 0;
272 }
273  
274 static int
275 24 parse_content_length(const char *value, size_t len, UV *out, int *seen)
276 {
277 24 size_t pos = 0;
278 24 int members = 0;
279 24 const UV uv_max = ~(UV)0;
280 2 while (1) {
281 26 UV parsed = 0;
282 26 int digits = 0;
283 28 ▶ while (pos < len && is_ows((unsigned char)value[pos])) ++pos;
Branch: 2 branches
BranchTrueFalseTotal
while (pos < len && is_ows((unsigned char)value[pos])) ++pos; 28 0 28
while (pos < len && is_ows((unsigned char)value[pos])) ++pos; 2 26 28
284 26 ▶ if (pos == len) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (pos == len) return 0; 0 26 26
285 69 ▶ while (pos < len && value[pos] >= '0' && value[pos] <= '9') {
Branch: 3 branches
BranchTrueFalseTotal
while (pos < len && value[pos] >= '0' && value[pos] <= '9') { 47 22 69
while (pos < len && value[pos] >= '0' && value[pos] <= '9') { 44 3 47
while (pos < len && value[pos] >= '0' && value[pos] <= '9') { 44 0 44
286 44 UV digit = (UV)(value[pos] - '0');
287 44 ▶ if (parsed > uv_max / 10 ||
Branch: 1 branch
BranchTrueFalseTotal
if (parsed > uv_max / 10 || 44 0 44
288 44 ▶ (parsed == uv_max / 10 && digit > uv_max % 10))
Branch: 2 branches
BranchTrueFalseTotal
(parsed == uv_max / 10 && digit > uv_max % 10)) 1 43 44
(parsed == uv_max / 10 && digit > uv_max % 10)) 1 0 1
289 1 return 0;
290 43 parsed = parsed * 10 + digit;
291 43 ++pos;
292 43 ++digits;
293 }
294 25 ▶ if (!digits) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!digits) return 0; 1 24 25
295 24 ▶ while (pos < len && is_ows((unsigned char)value[pos])) ++pos;
Branch: 2 branches
BranchTrueFalseTotal
while (pos < len && is_ows((unsigned char)value[pos])) ++pos; 2 22 24
while (pos < len && is_ows((unsigned char)value[pos])) ++pos; 0 2 2
296 24 ▶ if (*seen) {
Branch: 1 branch
BranchTrueFalseTotal
if (*seen) { 4 20 24
297 4 ▶ if (*out != parsed) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (*out != parsed) return 0; 2 2 4
298 } else {
299 20 *out = parsed;
300 20 *seen = 1;
301 }
302 22 ++members;
303 22 ▶ if (pos == len) break;
Branch: 1 branch
BranchTrueFalseTotal
if (pos == len) break; 20 2 22
304 2 ▶ if (value[pos] != ',') return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (value[pos] != ',') return 0; 0 2 2
305 2 ++pos;
306 }
307 20 return members != 0;
308 }
309  
310 static int
311 22 parse_connection(const char *value, size_t len, int *close_seen, int *keep_seen)
312 {
313 22 size_t pos = 0;
314 50 ▶ while (pos < len) {
Branch: 1 branch
BranchTrueFalseTotal
while (pos < len) { 29 21 50
315 size_t start, end, i;
316 36 ▶ while (pos < len && is_ows((unsigned char)value[pos])) ++pos;
Branch: 2 branches
BranchTrueFalseTotal
while (pos < len && is_ows((unsigned char)value[pos])) ++pos; 36 0 36
while (pos < len && is_ows((unsigned char)value[pos])) ++pos; 7 29 36
317 29 start = pos;
318 203 ▶ while (pos < len && value[pos] != ',') ++pos;
Branch: 2 branches
BranchTrueFalseTotal
while (pos < len && value[pos] != ',') ++pos; 182 21 203
while (pos < len && value[pos] != ',') ++pos; 174 8 182
319 29 end = pos;
320 29 ▶ while (end > start && is_ows((unsigned char)value[end - 1])) --end;
Branch: 2 branches
BranchTrueFalseTotal
while (end > start && is_ows((unsigned char)value[end - 1])) --end; 27 2 29
while (end > start && is_ows((unsigned char)value[end - 1])) --end; 0 27 27
321 29 ▶ if (end > start) {
Branch: 1 branch
BranchTrueFalseTotal
if (end > start) { 27 2 29
322 195 ▶ for (i = start; i < end; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = start; i < end; ++i) 169 26 195
323 169 ▶ if (!is_tchar((unsigned char)value[i]))
Branch: 1 branch
BranchTrueFalseTotal
if (!is_tchar((unsigned char)value[i])) 1 168 169
324 1 return 0;
325 26 ▶ if (ascii_equal_ci(value + start, end - start, "close", 5))
Branch: 1 branch
BranchTrueFalseTotal
if (ascii_equal_ci(value + start, end - start, "close", 5)) 9 17 26
326 9 *close_seen = 1;
327 17 ▶ else if (ascii_equal_ci(value + start, end - start, "keep-alive", 10))
Branch: 1 branch
BranchTrueFalseTotal
else if (ascii_equal_ci(value + start, end - start, "keep-alive", 10)) 5 12 17
328 5 *keep_seen = 1;
329 }
330 28 ▶ if (pos < len) ++pos;
Branch: 1 branch
BranchTrueFalseTotal
if (pos < len) ++pos; 8 20 28
331 }
332 21 return 1;
333 }
334  
335 static int
336 16 parse_transfer_encoding(const char *value, size_t len,
337 int *count, int *chunked_count,
338 int *final_chunked, int *unsupported)
339 {
340 16 size_t pos = 0;
341 3 while (1) {
342 size_t start, token_end, member_end, tail;
343 int chunked;
344 22 ▶ while (pos < len && is_ows((unsigned char)value[pos])) ++pos;
Branch: 2 branches
BranchTrueFalseTotal
while (pos < len && is_ows((unsigned char)value[pos])) ++pos; 22 0 22
while (pos < len && is_ows((unsigned char)value[pos])) ++pos; 3 19 22
345 19 ▶ if (pos == len) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (pos == len) return 0; 0 19 19
346 19 start = pos;
347 146 ▶ while (pos < len && is_tchar((unsigned char)value[pos])) ++pos;
Branch: 2 branches
BranchTrueFalseTotal
while (pos < len && is_tchar((unsigned char)value[pos])) ++pos; 131 15 146
while (pos < len && is_tchar((unsigned char)value[pos])) ++pos; 127 4 131
348 19 token_end = pos;
349 19 ▶ if (token_end == start) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (token_end == start) return 0; 0 19 19
350 27 ▶ while (pos < len && value[pos] != ',') ++pos;
Branch: 2 branches
BranchTrueFalseTotal
while (pos < len && value[pos] != ',') ++pos; 11 16 27
while (pos < len && value[pos] != ',') ++pos; 8 3 11
351 19 member_end = pos;
352 19 ▶ while (member_end > token_end && is_ows((unsigned char)value[member_end - 1])) --member_end;
Branch: 2 branches
BranchTrueFalseTotal
while (member_end > token_end && is_ows((unsigned char)value[member_end - 1])) --member_end; 1 18 19
while (member_end > token_end && is_ows((unsigned char)value[member_end - 1])) --member_end; 0 1 1
353 19 chunked = ascii_equal_ci(value + start, token_end - start, "chunked", 7);
354 19 ▶ if (chunked) {
Branch: 1 branch
BranchTrueFalseTotal
if (chunked) { 17 2 19
355 17 tail = token_end;
356 17 ▶ while (tail < member_end && is_ows((unsigned char)value[tail])) ++tail;
Branch: 2 branches
BranchTrueFalseTotal
while (tail < member_end && is_ows((unsigned char)value[tail])) ++tail; 1 16 17
while (tail < member_end && is_ows((unsigned char)value[tail])) ++tail; 0 1 1
357 17 ▶ if (tail != member_end) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (tail != member_end) return 0; 1 16 17
358 16 ++*chunked_count;
359 } else {
360 2 *unsupported = 1;
361 }
362 18 ++*count;
363 18 *final_chunked = chunked;
364 18 ▶ if (pos == len) break;
Branch: 1 branch
BranchTrueFalseTotal
if (pos == len) break; 15 3 18
365 3 ++pos;
366 }
367 15 return *count != 0;
368 }
369  
370 static int
371 3 parse_expect(const char *value, size_t len)
372 {
373 3 size_t pos = 0;
374 3 int members = 0;
375 0 while (1) {
376 size_t start, end;
377 3 ▶ while (pos < len && is_ows((unsigned char)value[pos])) ++pos;
Branch: 2 branches
BranchTrueFalseTotal
while (pos < len && is_ows((unsigned char)value[pos])) ++pos; 3 0 3
while (pos < len && is_ows((unsigned char)value[pos])) ++pos; 0 3 3
378 3 start = pos;
379 41 ▶ while (pos < len && value[pos] != ',') ++pos;
Branch: 2 branches
BranchTrueFalseTotal
while (pos < len && value[pos] != ',') ++pos; 38 3 41
while (pos < len && value[pos] != ',') ++pos; 38 0 38
380 3 end = pos;
381 3 ▶ while (end > start && is_ows((unsigned char)value[end - 1])) --end;
Branch: 2 branches
BranchTrueFalseTotal
while (end > start && is_ows((unsigned char)value[end - 1])) --end; 3 0 3
while (end > start && is_ows((unsigned char)value[end - 1])) --end; 0 3 3
382 3 ▶ if (end == start || !ascii_equal_ci(value + start, end - start, "100-continue", 12))
Branch: 2 branches
BranchTrueFalseTotal
if (end == start || !ascii_equal_ci(value + start, end - start, "100-continue", 12)) 3 0 3
if (end == start || !ascii_equal_ci(value + start, end - start, "100-continue", 12)) 1 2 3
383 1 return -1;
384 2 ++members;
385 2 ▶ if (pos == len) break;
Branch: 1 branch
BranchTrueFalseTotal
if (pos == len) break; 2 0 2
386 0 ++pos;
387 }
388 2 ▶ return members ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
return members ? 1 : -1; 2 0 2
389 }
390  
391 static SV *
392 33 new_error_result(pTHX_ int status, const char *message)
393 {
394 33 HV *hv = newHV();
395 33 hv_store(hv, "ok", 2, newSViv(0), 0);
396 33 ▶ if (status) hv_store(hv, "status", 6, newSViv(status), 0);
Branch: 1 branch
BranchTrueFalseTotal
if (status) hv_store(hv, "status", 6, newSViv(status), 0); 33 0 33
397 33 hv_store(hv, "error", 5, newSVpv(message, 0), 0);
398 33 return newRV_noinc((SV *)hv);
399 }
400  
401 static AV *
402 140 headers_to_av(pTHX_ const struct phr_header *headers, size_t count)
403 {
404 140 AV *out = newAV();
405 size_t i;
406 333 ▶ for (i = 0; i < count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) { 193 140 333
407 193 const char *value = headers[i].value;
408 193 size_t value_len = headers[i].value_len;
409 AV *pair;
410 193 ▶ while (value_len && is_ows((unsigned char)*value)) { ++value; --value_len; }
Branch: 2 branches
BranchTrueFalseTotal
while (value_len && is_ows((unsigned char)*value)) { ++value; --value_len; } 193 0 193
while (value_len && is_ows((unsigned char)*value)) { ++value; --value_len; } 0 193 193
411 193 ▶ while (value_len && is_ows((unsigned char)value[value_len - 1])) --value_len;
Branch: 2 branches
BranchTrueFalseTotal
while (value_len && is_ows((unsigned char)value[value_len - 1])) --value_len; 193 0 193
while (value_len && is_ows((unsigned char)value[value_len - 1])) --value_len; 0 193 193
412 193 pair = newAV();
413 193 av_push(pair, newSVpvn(headers[i].name, (STRLEN)headers[i].name_len));
414 193 av_push(pair, newSVpvn(value, (STRLEN)value_len));
415 193 av_push(out, newRV_noinc((SV *)pair));
416 }
417 140 return out;
418 }
419  
420 static int
421 185 strict_headers(const struct phr_header *headers, size_t count)
422 {
423 size_t i;
424 448 ▶ for (i = 0; i < count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) { 264 184 448
425 527 if (headers[i].name == NULL ||
426 526 ▶ !valid_field_name(headers[i].name, headers[i].name_len) ||
Branch: 1 branch
BranchTrueFalseTotal
!valid_field_name(headers[i].name, headers[i].name_len) || 0 263 263
427 263 !valid_field_value(headers[i].value, headers[i].value_len))
428 1 return 0;
429 }
430 184 return 1;
431 }
432  
433  
434 static SV *
435 282 ub_http1_parse_request_head_result(
436 pTHX_
437 const char *buf,
438 size_t buffer_len,
439 size_t last_len,
440 size_t max_headers,
441 const uhttp_native_api *uniform_api,
442 SV **request_out
443 )
444 {
445 const char *method;
446 size_t method_len;
447 const char *target;
448 size_t target_len;
449 int minor;
450 struct phr_header headers[UB_HTTP1_MAX_HEADERS];
451 size_t count;
452 int consumed;
453 size_t i;
454 282 int host_count = 0;
455 282 int has_cl = 0;
456 282 UV content_length = 0;
457 282 int te_present = 0;
458 282 int te_count = 0;
459 282 int chunked_count = 0;
460 282 int final_chunked = 0;
461 282 int unsupported = 0;
462 282 int close_seen = 0;
463 282 int keep_seen = 0;
464 282 int expect_mode = 0;
465 282 int body_mode = UB_BODY_NONE;
466 282 int is_connect = 0;
467 282 const char *host_value = NULL;
468 282 size_t host_value_len = 0;
469 uhttp_native_field native_headers[UB_HTTP1_MAX_HEADERS];
470 char version_bytes[3];
471 282 SV *native_request = NULL;
472 HV *hv;
473 AV *list;
474  
475 282 ▶ if (request_out != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (request_out != NULL) 9 273 282
476 9 *request_out = NULL;
477  
478 282 ▶ if (last_len > buffer_len)
Branch: 1 branch
BranchTrueFalseTotal
if (last_len > buffer_len) 0 282 282
479 0 croak("last_len exceeds input window length");
480 282 ▶ if (max_headers == 0 || max_headers > UB_HTTP1_MAX_HEADERS)
Branch: 2 branches
BranchTrueFalseTotal
if (max_headers == 0 || max_headers > UB_HTTP1_MAX_HEADERS) 282 0 282
if (max_headers == 0 || max_headers > UB_HTTP1_MAX_HEADERS) 0 282 282
481 0 croak("max_headers must be between 1 and %d", UB_HTTP1_MAX_HEADERS);
482  
483 282 count = max_headers;
484 282 consumed = phr_parse_request(
485 buf, buffer_len,
486 &method, &method_len, &target, &target_len, &minor,
487 headers, &count, last_len
488 );
489  
490 282 ▶ if (consumed == -2)
Branch: 1 branch
BranchTrueFalseTotal
if (consumed == -2) 170 112 282
491 170 return NULL;
492  
493 112 ▶ if (consumed == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (consumed == -1) { 1 111 112
494 1 ▶ if (count == max_headers)
Branch: 1 branch
BranchTrueFalseTotal
if (count == max_headers) 1 0 1
495 1 return new_error_result(
496 aTHX_ 431, "too many HTTP/1 request header fields"
497 );
498 0 return new_error_result(aTHX_ 400, "malformed HTTP/1 request");
499 }
500  
501 111 ▶ if (minor < 0 || minor > 9)
Branch: 2 branches
BranchTrueFalseTotal
if (minor < 0 || minor > 9) 111 0 111
if (minor < 0 || minor > 9) 0 111 111
502 0 return new_error_result(aTHX_ 505, "unsupported HTTP/1 version");
503  
504 111 ▶ if (!strict_headers(headers, count))
Branch: 1 branch
BranchTrueFalseTotal
if (!strict_headers(headers, count)) 1 110 111
505 1 return new_error_result(
506 aTHX_ 400, "invalid or folded HTTP/1 header field"
507 );
508  
509 {
510 110 const char *error = NULL;
511 110 int error_status = 0;
512  
513 110 is_connect = ascii_equal_cs(method, method_len, "CONNECT", 7);
514 110 ▶ if (!valid_request_target(method, method_len, target, target_len)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!valid_request_target(method, method_len, target, target_len)) { 10 100 110
515 10 error = "invalid HTTP/1 request target";
516 10 error_status = 400;
517 }
518 110 ▶ if (!error && is_connect && minor == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (!error && is_connect && minor == 0) { 100 10 110
if (!error && is_connect && minor == 0) { 10 90 100
if (!error && is_connect && minor == 0) { 1 9 10
519 1 error = "CONNECT requires HTTP/1.1 semantics";
520 1 error_status = 400;
521 }
522  
523 281 ▶ for (i = 0; i < count && !error; ++i) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < count && !error; ++i) { 182 99 281
for (i = 0; i < count && !error; ++i) { 171 11 182
524 171 const char *name = headers[i].name;
525 171 size_t name_len = headers[i].name_len;
526 171 const char *value = headers[i].value;
527 171 size_t value_len = headers[i].value_len;
528  
529 171 ▶ if (ascii_equal_ci(name, name_len, "Host", 4)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ascii_equal_ci(name, name_len, "Host", 4)) { 90 81 171
530 90 ++host_count;
531 90 ▶ if (host_count == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (host_count == 1) { 89 1 90
532 89 host_value = value;
533 89 host_value_len = value_len;
534 }
535 90 ▶ if (!valid_host_value(value, value_len)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!valid_host_value(value, value_len)) { 1 89 90
536 1 error = "invalid Host field";
537 1 error_status = 400;
538 }
539 81 ▶ } else if (ascii_equal_ci(
Branch: 1 branch
BranchTrueFalseTotal
} else if (ascii_equal_ci( 24 57 81
540 name, name_len, "Content-Length", 14)) {
541 24 ▶ if (!parse_content_length(
Branch: 1 branch
BranchTrueFalseTotal
if (!parse_content_length( 4 20 24
542 value, value_len,
543 &content_length, &has_cl)) {
544 4 error = "invalid or conflicting Content-Length";
545 4 error_status = 400;
546 }
547 57 ▶ } else if (ascii_equal_ci(
Branch: 1 branch
BranchTrueFalseTotal
} else if (ascii_equal_ci( 16 41 57
548 name, name_len, "Transfer-Encoding", 17)) {
549 16 te_present = 1;
550 16 ▶ if (!parse_transfer_encoding(
Branch: 1 branch
BranchTrueFalseTotal
if (!parse_transfer_encoding( 1 15 16
551 value, value_len,
552 &te_count, &chunked_count,
553 &final_chunked, &unsupported)) {
554 1 error = "invalid Transfer-Encoding";
555 1 error_status = 400;
556 }
557 41 ▶ } else if (ascii_equal_ci(
Branch: 1 branch
BranchTrueFalseTotal
} else if (ascii_equal_ci( 22 19 41
558 name, name_len, "Connection", 10)) {
559 22 ▶ if (!parse_connection(
Branch: 1 branch
BranchTrueFalseTotal
if (!parse_connection( 1 21 22
560 value, value_len, &close_seen, &keep_seen)) {
561 1 error = "invalid Connection field";
562 1 error_status = 400;
563 }
564 19 ▶ } else if (ascii_equal_ci(name, name_len, "Expect", 6)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ascii_equal_ci(name, name_len, "Expect", 6)) { 3 16 19
565 3 int e = parse_expect(value, value_len);
566 3 ▶ if (minor == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (minor == 0) { 1 2 3
567 1 expect_mode = 0;
568 2 ▶ } else if (e < 0) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (e < 0) { 1 1 2
569 1 expect_mode = -1;
570 1 ▶ } else if (expect_mode >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (expect_mode >= 0) { 1 0 1
571 1 expect_mode = 1;
572 }
573 }
574 }
575  
576 110 ▶ if (!error && host_count > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (!error && host_count > 1) { 92 18 110
if (!error && host_count > 1) { 1 91 92
577 1 error = "multiple Host fields";
578 1 error_status = 400;
579 }
580 110 ▶ if (!error && minor >= 1 && host_count != 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (!error && minor >= 1 && host_count != 1) { 91 19 110
if (!error && minor >= 1 && host_count != 1) { 83 8 91
if (!error && minor >= 1 && host_count != 1) { 2 81 83
581 2 error = "HTTP/1.1 semantics require exactly one Host field";
582 2 error_status = 400;
583 }
584 110 ▶ if (!error && te_present && has_cl) {
Branch: 3 branches
BranchTrueFalseTotal
if (!error && te_present && has_cl) { 89 21 110
if (!error && te_present && has_cl) { 15 74 89
if (!error && te_present && has_cl) { 3 12 15
585 3 error = "Transfer-Encoding and Content-Length cannot be combined";
586 3 error_status = 400;
587 }
588 110 ▶ if (!error && minor == 0 && te_present) {
Branch: 3 branches
BranchTrueFalseTotal
if (!error && minor == 0 && te_present) { 86 24 110
if (!error && minor == 0 && te_present) { 8 78 86
if (!error && minor == 0 && te_present) { 1 7 8
589 1 error = "HTTP/1.0 request must not contain Transfer-Encoding";
590 1 error_status = 400;
591 }
592 110 ▶ if (!error && is_connect
Branch: 2 branches
BranchTrueFalseTotal
if (!error && is_connect 85 25 110
if (!error && is_connect 9 76 85
593 9 ▶ && (te_present || (has_cl && content_length != 0))) {
Branch: 3 branches
BranchTrueFalseTotal
&& (te_present || (has_cl && content_length != 0))) { 8 1 9
&& (te_present || (has_cl && content_length != 0))) { 2 6 8
&& (te_present || (has_cl && content_length != 0))) { 1 1 2
594 2 error = "CONNECT request must not contain content framing";
595 2 error_status = 400;
596 }
597 110 ▶ if (!error && is_connect && host_count == 1
Branch: 3 branches
BranchTrueFalseTotal
if (!error && is_connect && host_count == 1 83 27 110
if (!error && is_connect && host_count == 1 7 76 83
if (!error && is_connect && host_count == 1 7 0 7
598 7 ▶ && !connect_host_matches_target(
Branch: 1 branch
BranchTrueFalseTotal
&& !connect_host_matches_target( 1 6 7
599 host_value, host_value_len, target, target_len)) {
600 1 error = "CONNECT Host must identify request target";
601 1 error_status = 400;
602 }
603  
604 110 ▶ if (!error && te_present) {
Branch: 2 branches
BranchTrueFalseTotal
if (!error && te_present) { 82 28 110
if (!error && te_present) { 10 72 82
605 10 ▶ if (chunked_count != 1 || !final_chunked) {
Branch: 2 branches
BranchTrueFalseTotal
if (chunked_count != 1 || !final_chunked) { 9 1 10
if (chunked_count != 1 || !final_chunked) { 1 8 9
606 2 error =
607 "chunked must be the final and only chunked transfer coding";
608 2 error_status = 400;
609 8 ▶ } else if (unsupported) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (unsupported) { 1 7 8
610 1 error = "unsupported transfer coding";
611 1 error_status = 501;
612 } else {
613 7 body_mode = UB_BODY_CHUNKED;
614 }
615 100 ▶ } else if (!error && has_cl) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (!error && has_cl) { 72 28 100
} else if (!error && has_cl) { 14 58 72
616 14 body_mode = (is_connect && content_length == 0)
617 14 ▶ ? UB_BODY_NONE : UB_BODY_CONTENT_LENGTH;
Branch: 2 branches
BranchTrueFalseTotal
? UB_BODY_NONE : UB_BODY_CONTENT_LENGTH; 1 13 14
? UB_BODY_NONE : UB_BODY_CONTENT_LENGTH; 0 1 1
618 }
619  
620 110 ▶ if (error)
Branch: 1 branch
BranchTrueFalseTotal
if (error) 31 79 110
621 31 return new_error_result(aTHX_ error_status, error);
622 }
623  
624 79 ▶ if (uniform_api != NULL && request_out != NULL
Branch: 2 branches
BranchTrueFalseTotal
if (uniform_api != NULL && request_out != NULL 8 71 79
if (uniform_api != NULL && request_out != NULL 8 0 8
625 8 ▶ && !is_connect && target_len > 0
Branch: 2 branches
BranchTrueFalseTotal
&& !is_connect && target_len > 0 8 0 8
&& !is_connect && target_len > 0 8 0 8
626 8 ▶ && (target[0] == '/'
Branch: 1 branch
BranchTrueFalseTotal
&& (target[0] == '/' 0 8 8
627 0 ▶ || (target_len == 1 && target[0] == '*'))) {
Branch: 2 branches
BranchTrueFalseTotal
|| (target_len == 1 && target[0] == '*'))) { 0 0 0
|| (target_len == 1 && target[0] == '*'))) { 0 0 0
628 uhttp_native_input input;
629  
630 8 uhttp_native_input_init(&input, UHTTP_KIND_REQUEST);
631 8 input.flags =
632 UHTTP_HEADERS_LOSSLESS
633 | UHTTP_TRAILERS_LOSSLESS
634 | UHTTP_TARGET_EXACT;
635  
636 8 ▶ if (body_mode == UB_BODY_NONE) {
Branch: 1 branch
BranchTrueFalseTotal
if (body_mode == UB_BODY_NONE) { 6 2 8
637 6 input.flags |= UHTTP_COMPLETE;
638 } else {
639 2 input.flags |=
640 UHTTP_MUTABLE
641 | UHTTP_BODY_MUTABLE
642 | UHTTP_TRAILERS_MUTABLE;
643 }
644  
645 8 version_bytes[0] = '1';
646 8 version_bytes[1] = '.';
647 8 version_bytes[2] = (char)('0' + minor);
648 8 input.version.data = version_bytes;
649 8 input.version.len = 3;
650 8 input.method.data = method;
651 8 input.method.len = (STRLEN)method_len;
652 8 input.target.data = target;
653 8 input.target.len = (STRLEN)target_len;
654  
655 22 ▶ for (i = 0; i < count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) { 14 8 22
656 14 const char *value = headers[i].value;
657 14 size_t value_len = headers[i].value_len;
658  
659 14 ▶ while (value_len && is_ows((unsigned char)*value)) {
Branch: 2 branches
BranchTrueFalseTotal
while (value_len && is_ows((unsigned char)*value)) { 14 0 14
while (value_len && is_ows((unsigned char)*value)) { 0 14 14
660 0 ++value;
661 0 --value_len;
662 }
663 14 while (value_len
664 14 ▶ && is_ows((unsigned char)value[value_len - 1]))
Branch: 2 branches
BranchTrueFalseTotal
&& is_ows((unsigned char)value[value_len - 1])) 14 0 14
&& is_ows((unsigned char)value[value_len - 1])) 0 14 14
665 0 --value_len;
666  
667 14 native_headers[i].name.data = headers[i].name;
668 14 native_headers[i].name.len = (STRLEN)headers[i].name_len;
669 14 native_headers[i].value.data = value;
670 14 native_headers[i].value.len = (STRLEN)value_len;
671 }
672  
673 8 input.headers = native_headers;
674 8 input.header_count = (Size_t)count;
675 8 native_request = uhttp_native_from_validated(
676 aTHX_ uniform_api, &input, UHTTP_NATIVE_TRUSTED
677 );
678 8 *request_out = native_request;
679 }
680  
681 79 hv = newHV();
682 79 hv_store(hv, "ok", 2, newSViv(1), 0);
683 79 hv_store(hv, "consumed", 8, newSViv(consumed), 0);
684 79 ▶ if (native_request == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (native_request == NULL) { 71 8 79
685 71 hv_store(hv, "version", 7, newSVpvf("1.%d", minor), 0);
686 71 hv_store(hv, "method", 6, newSVpvn(method, (STRLEN)method_len), 0);
687 71 hv_store(hv, "target", 6, newSVpvn(target, (STRLEN)target_len), 0);
688 71 list = headers_to_av(aTHX_ headers, count);
689 71 hv_store(hv, "headers", 7, newRV_noinc((SV *)list), 0);
690 }
691  
692 79 ▶ if (body_mode == UB_BODY_CHUNKED)
Branch: 1 branch
BranchTrueFalseTotal
if (body_mode == UB_BODY_CHUNKED) 7 72 79
693 7 hv_store(hv, "body_mode", 9, newSVpvs("chunked"), 0);
694 72 ▶ else if (body_mode == UB_BODY_CONTENT_LENGTH)
Branch: 1 branch
BranchTrueFalseTotal
else if (body_mode == UB_BODY_CONTENT_LENGTH) 13 59 72
695 13 hv_store(hv, "body_mode", 9, newSVpvs("content-length"), 0);
696 else
697 59 hv_store(hv, "body_mode", 9, newSVpvs("none"), 0);
698  
699 79 ▶ if (has_cl)
Branch: 1 branch
BranchTrueFalseTotal
if (has_cl) 14 65 79
700 14 hv_store(hv, "content_length", 14, newSVuv(content_length), 0);
701  
702 79 ▶ hv_store(
Branch: 3 branches
BranchTrueFalseTotal
hv_store( 70 9 79
hv_store( 7 63 70
hv_store( 3 4 7
703 hv, "keep_alive", 10,
704 newSViv(close_seen ? 0 : (minor >= 1 ? 1 : (keep_seen ? 1 : 0))),
705 0
706 );
707 79 hv_store(hv, "expect_continue", 15, newSViv(expect_mode), 0);
708  
709 79 return newRV_noinc((SV *)hv);
710 }
711  
712 static SV *
713 175 ub_http1_parse_response_head_result(
714 pTHX_
715 const char *buf,
716 size_t buffer_len,
717 size_t last_len,
718 size_t max_headers,
719 const uhttp_native_api *uniform_api,
720 SV **response_out
721 )
722 {
723 int minor;
724 int status;
725 const char *reason;
726 size_t reason_len;
727 struct phr_header headers[UB_HTTP1_MAX_HEADERS];
728 uhttp_native_field native_headers[UB_HTTP1_MAX_HEADERS];
729 size_t count;
730 int consumed;
731 size_t i;
732 char version_bytes[3];
733 175 SV *native_response = NULL;
734 HV *hv;
735 AV *list;
736  
737 175 ▶ if (response_out != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (response_out != NULL) 6 169 175
738 6 *response_out = NULL;
739 175 ▶ if (last_len > buffer_len)
Branch: 1 branch
BranchTrueFalseTotal
if (last_len > buffer_len) 0 175 175
740 0 croak("last_len exceeds input window length");
741 175 ▶ if (max_headers == 0 || max_headers > UB_HTTP1_MAX_HEADERS)
Branch: 2 branches
BranchTrueFalseTotal
if (max_headers == 0 || max_headers > UB_HTTP1_MAX_HEADERS) 175 0 175
if (max_headers == 0 || max_headers > UB_HTTP1_MAX_HEADERS) 0 175 175
742 0 croak("max_headers must be between 1 and %d", UB_HTTP1_MAX_HEADERS);
743  
744 175 count = max_headers;
745 175 consumed = phr_parse_response(
746 buf, buffer_len, &minor, &status,
747 &reason, &reason_len, headers, &count, last_len
748 );
749  
750 175 ▶ if (consumed == -2)
Branch: 1 branch
BranchTrueFalseTotal
if (consumed == -2) 113 62 175
751 113 return NULL;
752  
753 62 ▶ if (consumed == -1 || minor < 0 || minor > 9
Branch: 3 branches
BranchTrueFalseTotal
if (consumed == -1 || minor < 0 || minor > 9 62 0 62
if (consumed == -1 || minor < 0 || minor > 9 62 0 62
if (consumed == -1 || minor < 0 || minor > 9 62 0 62
754 62 ▶ || status < 100 || status > 599
Branch: 2 branches
BranchTrueFalseTotal
|| status < 100 || status > 599 62 0 62
|| status < 100 || status > 599 62 0 62
755 62 ▶ || buffer_len < 13 || !memEQ(buf, "HTTP/1.", 7)
Branch: 2 branches
BranchTrueFalseTotal
|| buffer_len < 13 || !memEQ(buf, "HTTP/1.", 7) 62 0 62
|| buffer_len < 13 || !memEQ(buf, "HTTP/1.", 7) 62 0 62
756 62 ▶ || buf[7] < '0' || buf[7] > '9' || buf[8] != ' '
Branch: 3 branches
BranchTrueFalseTotal
|| buf[7] < '0' || buf[7] > '9' || buf[8] != ' ' 62 0 62
|| buf[7] < '0' || buf[7] > '9' || buf[8] != ' ' 62 0 62
|| buf[7] < '0' || buf[7] > '9' || buf[8] != ' ' 62 0 62
757 62 ▶ || buf[9] < '0' || buf[9] > '9'
Branch: 2 branches
BranchTrueFalseTotal
|| buf[9] < '0' || buf[9] > '9' 62 0 62
|| buf[9] < '0' || buf[9] > '9' 62 0 62
758 62 ▶ || buf[10] < '0' || buf[10] > '9'
Branch: 2 branches
BranchTrueFalseTotal
|| buf[10] < '0' || buf[10] > '9' 62 0 62
|| buf[10] < '0' || buf[10] > '9' 62 0 62
759 62 ▶ || buf[11] < '0' || buf[11] > '9' || buf[12] != ' '
Branch: 3 branches
BranchTrueFalseTotal
|| buf[11] < '0' || buf[11] > '9' || buf[12] != ' ' 62 0 62
|| buf[11] < '0' || buf[11] > '9' || buf[12] != ' ' 62 0 62
|| buf[11] < '0' || buf[11] > '9' || buf[12] != ' ' 62 0 62
760 62 ▶ || reason != buf + 13
Branch: 1 branch
BranchTrueFalseTotal
|| reason != buf + 13 62 0 62
761 62 ▶ || !valid_field_value(reason, reason_len)
Branch: 1 branch
BranchTrueFalseTotal
|| !valid_field_value(reason, reason_len) 62 0 62
762 62 ▶ || !strict_headers(headers, count)) {
Branch: 1 branch
BranchTrueFalseTotal
|| !strict_headers(headers, count)) { 0 62 62
763 0 return new_error_result(aTHX_ 0, "malformed HTTP/1 response");
764 }
765  
766 62 ▶ if (uniform_api != NULL && response_out != NULL) {
Branch: 2 branches
BranchTrueFalseTotal
if (uniform_api != NULL && response_out != NULL) { 5 57 62
if (uniform_api != NULL && response_out != NULL) { 5 0 5
767 uhttp_native_input input;
768 5 int informational =
769 5 ▶ status >= 100 && status < 200 && status != 101 ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
status >= 100 && status < 200 && status != 101 ? 1 : 0; 5 0 5
status >= 100 && status < 200 && status != 101 ? 1 : 0; 2 3 5
status >= 100 && status < 200 && status != 101 ? 1 : 0; 1 1 2
770  
771 5 uhttp_native_input_init(&input, UHTTP_KIND_RESPONSE);
772 5 input.flags =
773 UHTTP_HEADERS_LOSSLESS
774 | UHTTP_TRAILERS_LOSSLESS;
775  
776 5 ▶ if (informational) {
Branch: 1 branch
BranchTrueFalseTotal
if (informational) { 1 4 5
777 1 input.flags |= UHTTP_COMPLETE;
778 } else {
779 4 input.flags |=
780 UHTTP_MUTABLE
781 | UHTTP_BODY_MUTABLE
782 | UHTTP_TRAILERS_MUTABLE;
783 }
784  
785 5 version_bytes[0] = '1';
786 5 version_bytes[1] = '.';
787 5 version_bytes[2] = (char)('0' + minor);
788 5 input.version.data = version_bytes;
789 5 input.version.len = 3;
790 5 input.status = (IV)status;
791 5 input.reason.data = reason;
792 5 input.reason.len = (STRLEN)reason_len;
793  
794 11 ▶ for (i = 0; i < count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) { 6 5 11
795 6 const char *value = headers[i].value;
796 6 size_t value_len = headers[i].value_len;
797  
798 6 ▶ while (value_len && is_ows((unsigned char)*value)) {
Branch: 2 branches
BranchTrueFalseTotal
while (value_len && is_ows((unsigned char)*value)) { 6 0 6
while (value_len && is_ows((unsigned char)*value)) { 0 6 6
799 0 ++value;
800 0 --value_len;
801 }
802 6 while (value_len
803 6 ▶ && is_ows((unsigned char)value[value_len - 1]))
Branch: 2 branches
BranchTrueFalseTotal
&& is_ows((unsigned char)value[value_len - 1])) 6 0 6
&& is_ows((unsigned char)value[value_len - 1])) 0 6 6
804 0 --value_len;
805  
806 6 native_headers[i].name.data = headers[i].name;
807 6 native_headers[i].name.len = (STRLEN)headers[i].name_len;
808 6 native_headers[i].value.data = value;
809 6 native_headers[i].value.len = (STRLEN)value_len;
810 }
811  
812 5 input.headers = native_headers;
813 5 input.header_count = (Size_t)count;
814 5 native_response = uhttp_native_from_validated(
815 aTHX_ uniform_api, &input, UHTTP_NATIVE_TRUSTED
816 );
817 5 *response_out = native_response;
818 }
819  
820 62 hv = newHV();
821 62 hv_store(hv, "ok", 2, newSViv(1), 0);
822 62 hv_store(hv, "consumed", 8, newSViv(consumed), 0);
823 62 hv_store(hv, "status", 6, newSViv(status), 0);
824 62 ▶ if (native_response == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (native_response == NULL) { 57 5 62
825 57 hv_store(hv, "version", 7, newSVpvf("1.%d", minor), 0);
826 57 hv_store(
827 hv, "reason", 6,
828 newSVpvn(reason, (STRLEN)reason_len), 0
829 );
830 57 list = headers_to_av(aTHX_ headers, count);
831 57 hv_store(hv, "headers", 7, newRV_noinc((SV *)list), 0);
832 }
833  
834 62 return newRV_noinc((SV *)hv);
835 }
836  
837 typedef struct {
838 const char *data;
839 size_t length;
840 size_t offset;
841 int valid;
842 } ub_http1_borrowed_window;
843  
844 typedef struct {
845 SV *engine;
846 CV *input_cv;
847 CV *head_cv;
848 CV *eof_cv;
849 uhttp_native_api uniform_api;
850 int uniform_native;
851 int role;
852 int direct_head;
853 size_t max_headers;
854 size_t max_head_size;
855 } ub_http1_input_context;
856  
857 static ub_http1_borrowed_window *
858 8 ub_http1_window_from_sv(pTHX_ SV *sv)
859 {
860 SV *inner;
861 ub_http1_borrowed_window *window;
862  
863 8 ▶ if (!SvROK(sv)
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(sv) 8 0 8
864 8 ▶ || !sv_derived_from(sv, "Unblock::HTTP1::_Native::BorrowedWindow"))
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_derived_from(sv, "Unblock::HTTP1::_Native::BorrowedWindow")) 0 8 8
865 0 croak("not an Unblock::HTTP1 borrowed input window");
866  
867 8 inner = SvRV(sv);
868 8 window = INT2PTR(ub_http1_borrowed_window *, SvIV(inner));
869 8 ▶ if (window == NULL || !window->valid)
Branch: 2 branches
BranchTrueFalseTotal
if (window == NULL || !window->valid) 8 0 8
if (window == NULL || !window->valid) 0 8 8
870 0 croak("borrowed input window is no longer valid");
871 8 ▶ if (window->offset > window->length)
Branch: 1 branch
BranchTrueFalseTotal
if (window->offset > window->length) 0 8 8
872 0 croak("corrupt borrowed input window");
873 8 return window;
874 }
875  
876 static const char *
877 543 ub_http1_buffer_view(pTHX_ SV *buffer, STRLEN *length)
878 {
879 543 ▶ if (SvROK(buffer)
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(buffer) 3 540 543
880 3 ▶ && sv_derived_from(buffer, "Unblock::HTTP1::_Native::BorrowedWindow")) {
Branch: 1 branch
BranchTrueFalseTotal
&& sv_derived_from(buffer, "Unblock::HTTP1::_Native::BorrowedWindow")) { 3 0 3
881 ub_http1_borrowed_window *window =
882 3 ub_http1_window_from_sv(aTHX_ buffer);
883 3 size_t remaining = window->length - window->offset;
884 if (remaining > (size_t)~(STRLEN)0)
885 croak("borrowed input window exceeds Perl string length range");
886 3 *length = (STRLEN)remaining;
887 3 return window->data + window->offset;
888 }
889  
890 540 return SvPVbyte(buffer, *length);
891 }
892  
893 static CV *
894 16 ub_http1_engine_method_cv(
895 pTHX_
896 ub_http1_input_context *context,
897 CV **slot,
898 const char *name
899 )
900 {
901 GV *gv;
902 CV *cv;
903  
904 16 ▶ if (*slot != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (*slot != NULL) 3 13 16
905 3 return *slot;
906  
907 13 ▶ if (!SvROK(context->engine))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(context->engine)) 0 13 13
908 0 croak("Unblock::HTTP1 native input engine is not an object");
909  
910 13 gv = gv_fetchmethod_autoload(SvSTASH(SvRV(context->engine)), name, 0);
911 13 ▶ if (gv == NULL || (cv = GvCV(gv)) == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if (gv == NULL || (cv = GvCV(gv)) == NULL) 13 0 13
if (gv == NULL || (cv = GvCV(gv)) == NULL) 0 13 13
912 0 croak("Unblock::HTTP1 native input method %s is unavailable", name);
913  
914 13 *slot = (CV *)SvREFCNT_inc((SV *)cv);
915 13 return *slot;
916 }
917  
918 static int
919 0 ub_http1_call_engine_scalar(
920 pTHX_
921 ub_http1_input_context *context,
922 CV **slot,
923 const char *name,
924 SV *arg
925 )
926 {
927 0 CV *cv = ub_http1_engine_method_cv(aTHX_ context, slot, name);
928 0 int result = 0;
929 int count;
930 0 SV *error = NULL;
931 0 dSP;
932  
933 0 ENTER;
934 0 SAVETMPS;
935 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
936 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
937 0 ▶ XPUSHs(context->engine);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(context->engine); 0 0 0
938 0 ▶ if (arg != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (arg != NULL) 0 0 0
939 0 ▶ XPUSHs(arg);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(arg); 0 0 0
940 0 PUTBACK;
941 0 count = call_sv((SV *)cv, G_SCALAR | G_EVAL);
942 0 SPAGAIN;
943 0 ▶ if (SvTRUE(ERRSV))
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) 0 0 0
if (SvTRUE(ERRSV)) 0 0 0
944 0 ▶ error = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
error = newSVsv(ERRSV); 0 0 0
945 0 ▶ else if (count > 0)
Branch: 1 branch
BranchTrueFalseTotal
else if (count > 0) 0 0 0
946 0 result = POPi;
947 0 PUTBACK;
948 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
949 0 LEAVE;
950  
951 0 ▶ if (error != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (error != NULL) { 0 0 0
952 0 const char *message = SvPV_nolen(error);
953 0 croak("%s", message);
954 }
955  
956 0 return result;
957 }
958  
959 static int
960 10 ub_http1_call_engine_input(
961 pTHX_
962 ub_http1_input_context *context,
963 SV *window,
964 size_t length,
965 SV *head,
966 SV *message,
967 size_t *consumed,
968 int *head_ready
969 )
970 {
971 10 CV *cv = ub_http1_engine_method_cv(
972 aTHX_ context, &context->input_cv, "_input_borrowed"
973 );
974 10 int result = 0;
975 int count;
976 10 SV *error = NULL;
977 SV *ready_sv;
978 SV *consumed_sv;
979 SV *status_sv;
980 UV consumed_uv;
981 10 dSP;
982  
983 10 ENTER;
984 10 SAVETMPS;
985 10 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 10 0 10
986 10 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 10 10
987 10 ▶ XPUSHs(context->engine);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(context->engine); 0 10 10
988 10 ▶ XPUSHs(window);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(window); 0 10 10
989 10 mPUSHu((UV)length);
990 10 ▶ XPUSHs(head != NULL ? head : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(head != NULL ? head : &PL_sv_undef); 0 10 10
XPUSHs(head != NULL ? head : &PL_sv_undef); 7 3 10
991 10 ▶ XPUSHs(message != NULL ? message : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(message != NULL ? message : &PL_sv_undef); 0 10 10
XPUSHs(message != NULL ? message : &PL_sv_undef); 7 3 10
992 10 PUTBACK;
993 10 count = call_sv((SV *)cv, G_ARRAY | G_EVAL);
994 10 SPAGAIN;
995 10 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 10 0 10
if (SvTRUE(ERRSV)) { 0 10 10
996 0 ▶ error = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
error = newSVsv(ERRSV); 0 0 0
997 } else {
998 10 ▶ if (count != 3)
Branch: 1 branch
BranchTrueFalseTotal
if (count != 3) 0 10 10
999 0 croak("Unblock::HTTP1 native input returned the wrong number of values");
1000 10 ready_sv = POPs;
1001 10 consumed_sv = POPs;
1002 10 status_sv = POPs;
1003 10 consumed_uv = SvUV(consumed_sv);
1004 10 ▶ if (consumed_uv > (UV)length)
Branch: 1 branch
BranchTrueFalseTotal
if (consumed_uv > (UV)length) 0 10 10
1005 0 croak("Unblock::HTTP1 native input consumed beyond its window");
1006 10 *consumed = (size_t)consumed_uv;
1007 10 *head_ready = SvTRUE(ready_sv) ? 1 : 0;
1008 10 result = SvIV(status_sv);
1009 }
1010 10 PUTBACK;
1011 10 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 10 0 10
1012 10 LEAVE;
1013  
1014 10 ▶ if (error != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (error != NULL) { 0 10 10
1015 0 const char *message = SvPV_nolen(error);
1016 0 croak("%s", message);
1017 }
1018  
1019 10 return result;
1020 }
1021  
1022 static int
1023 6 ub_http1_call_engine_head(
1024 pTHX_
1025 ub_http1_input_context *context,
1026 SV *head,
1027 SV *message,
1028 int *head_ready
1029 )
1030 {
1031 6 CV *cv = ub_http1_engine_method_cv(
1032 aTHX_ context, &context->head_cv, "_input_native_head"
1033 );
1034 6 int result = 0;
1035 int count;
1036 6 SV *error = NULL;
1037 SV *ready_sv;
1038 SV *status_sv;
1039 6 dSP;
1040  
1041 6 ENTER;
1042 6 SAVETMPS;
1043 6 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 6 0 6
1044 6 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 6 6
1045 6 ▶ XPUSHs(context->engine);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(context->engine); 0 6 6
1046 6 ▶ XPUSHs(head);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(head); 0 6 6
1047 6 ▶ XPUSHs(message != NULL ? message : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(message != NULL ? message : &PL_sv_undef); 0 6 6
XPUSHs(message != NULL ? message : &PL_sv_undef); 6 0 6
1048 6 PUTBACK;
1049 6 count = call_sv((SV *)cv, G_ARRAY | G_EVAL);
1050 6 SPAGAIN;
1051 6 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 6 0 6
if (SvTRUE(ERRSV)) { 0 6 6
1052 0 ▶ error = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
error = newSVsv(ERRSV); 0 0 0
1053 } else {
1054 6 ▶ if (count != 2)
Branch: 1 branch
BranchTrueFalseTotal
if (count != 2) 0 6 6
1055 0 croak("Unblock::HTTP1 native head dispatch returned the wrong number of values");
1056 6 ready_sv = POPs;
1057 6 status_sv = POPs;
1058 6 *head_ready = SvTRUE(ready_sv) ? 1 : 0;
1059 6 result = SvIV(status_sv);
1060 }
1061 6 PUTBACK;
1062 6 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 6 0 6
1063 6 LEAVE;
1064  
1065 6 ▶ if (error != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (error != NULL) { 0 6 6
1066 0 const char *message = SvPV_nolen(error);
1067 0 croak("%s", message);
1068 }
1069  
1070 6 return result;
1071 }
1072  
1073 static int
1074 31 ub_http1_input_can_direct_head(pTHX_ ub_http1_input_context *context)
1075 {
1076 HV *engine_hv;
1077 SV **value;
1078 31 int active = 0;
1079  
1080 31 ▶ if (context == NULL || context->role == 0
Branch: 2 branches
BranchTrueFalseTotal
if (context == NULL || context->role == 0 31 0 31
if (context == NULL || context->role == 0 31 0 31
1081 31 ▶ || context->engine == NULL || !SvROK(context->engine)
Branch: 2 branches
BranchTrueFalseTotal
|| context->engine == NULL || !SvROK(context->engine) 31 0 31
|| context->engine == NULL || !SvROK(context->engine) 31 0 31
1082 31 ▶ || SvTYPE(SvRV(context->engine)) != SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(context->engine)) != SVt_PVHV) 0 31 31
1083 0 return 0;
1084  
1085 31 engine_hv = (HV *)SvRV(context->engine);
1086  
1087 31 value = hv_fetch(engine_hv, "closed", 6, 0);
1088 31 ▶ if (value != NULL && SvOK(*value) && SvTRUE(*value))
Branch: 3 branches
BranchTrueFalseTotal
if (value != NULL && SvOK(*value) && SvTRUE(*value)) 31 0 31
if (value != NULL && SvOK(*value) && SvTRUE(*value)) 31 0 31
if (value != NULL && SvOK(*value) && SvTRUE(*value)) 0 31 31
1089 0 return 0;
1090  
1091 31 value = hv_fetch(engine_hv, "switched", 8, 0);
1092 31 ▶ if (value != NULL && SvOK(*value) && SvTRUE(*value))
Branch: 3 branches
BranchTrueFalseTotal
if (value != NULL && SvOK(*value) && SvTRUE(*value)) 31 0 31
if (value != NULL && SvOK(*value) && SvTRUE(*value)) 31 0 31
if (value != NULL && SvOK(*value) && SvTRUE(*value)) 0 31 31
1093 0 return 0;
1094  
1095 31 value = hv_fetch(engine_hv, "input", 5, 0);
1096 31 ▶ if (value != NULL && SvOK(*value) && SvCUR(*value) != 0)
Branch: 3 branches
BranchTrueFalseTotal
if (value != NULL && SvOK(*value) && SvCUR(*value) != 0) 31 0 31
if (value != NULL && SvOK(*value) && SvCUR(*value) != 0) 31 0 31
if (value != NULL && SvOK(*value) && SvCUR(*value) != 0) 0 31 31
1097 0 return 0;
1098  
1099 31 value = hv_fetch(engine_hv, "rx", 2, 0);
1100 31 ▶ if (value != NULL && SvOK(*value) && SvTRUE(*value))
Branch: 3 branches
BranchTrueFalseTotal
if (value != NULL && SvOK(*value) && SvTRUE(*value)) 29 2 31
if (value != NULL && SvOK(*value) && SvTRUE(*value)) 5 24 29
if (value != NULL && SvOK(*value) && SvTRUE(*value)) 5 0 5
1101 5 return 0;
1102  
1103 26 value = hv_fetch(engine_hv, "active", 6, 0);
1104 26 ▶ if (value != NULL && SvOK(*value) && SvTRUE(*value))
Branch: 3 branches
BranchTrueFalseTotal
if (value != NULL && SvOK(*value) && SvTRUE(*value)) 26 0 26
if (value != NULL && SvOK(*value) && SvTRUE(*value)) 8 18 26
if (value != NULL && SvOK(*value) && SvTRUE(*value)) 8 0 8
1105 8 active = 1;
1106  
1107 26 ▶ return context->role == 1 ? !active : active;
Branch: 1 branch
BranchTrueFalseTotal
return context->role == 1 ? !active : active; 17 9 26
1108 }
1109  
1110 static void *
1111 13 ub_http1_input_create(pTHX_ SV *engine)
1112 {
1113 ub_http1_input_context *context;
1114  
1115 13 ▶ if (!SvROK(engine)
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(engine) 13 0 13
1116 13 ▶ || !sv_derived_from(engine, "Unblock::HTTP1::_Engine"))
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_derived_from(engine, "Unblock::HTTP1::_Engine")) 0 13 13
1117 0 return NULL;
1118  
1119 13 Newxz(context, 1, ub_http1_input_context);
1120 13 ▶ if (context == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (context == NULL) 0 13 13
1121 0 return NULL;
1122  
1123 13 context->engine = SvREFCNT_inc(engine);
1124 13 context->uniform_native = uhttp_native_init(
1125 aTHX_ &context->uniform_api, UHTTP_NATIVE_ABI_VERSION
1126 );
1127 13 context->role = sv_derived_from(engine, "Unblock::HTTP1::Server") ? 1
1128 13 ▶ : sv_derived_from(engine, "Unblock::HTTP1::Client") ? 2 : 0;
Branch: 2 branches
BranchTrueFalseTotal
: sv_derived_from(engine, "Unblock::HTTP1::Client") ? 2 : 0; 3 10 13
: sv_derived_from(engine, "Unblock::HTTP1::Client") ? 2 : 0; 3 0 3
1129 13 context->direct_head = 0;
1130 13 context->max_headers = 100;
1131 13 context->max_head_size = 65536;
1132  
1133 13 ▶ if (SvTYPE(SvRV(engine)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(SvRV(engine)) == SVt_PVHV) { 13 0 13
1134 13 HV *engine_hv = (HV *)SvRV(engine);
1135 SV **value;
1136  
1137 13 value = hv_fetch(engine_hv, "max_headers", 11, 0);
1138 13 ▶ if (value != NULL && SvOK(*value))
Branch: 2 branches
BranchTrueFalseTotal
if (value != NULL && SvOK(*value)) 13 0 13
if (value != NULL && SvOK(*value)) 13 0 13
1139 13 context->max_headers = (size_t)SvUV(*value);
1140  
1141 13 value = hv_fetch(engine_hv, "max_head_size", 13, 0);
1142 13 ▶ if (value != NULL && SvOK(*value))
Branch: 2 branches
BranchTrueFalseTotal
if (value != NULL && SvOK(*value)) 13 0 13
if (value != NULL && SvOK(*value)) 13 0 13
1143 13 context->max_head_size = (size_t)SvUV(*value);
1144  
1145 }
1146  
1147 13 context->direct_head = ub_http1_input_can_direct_head(aTHX_ context);
1148 13 return context;
1149 }
1150  
1151 static int
1152 18 ub_http1_input_borrowed(
1153 pTHX_
1154 void *opaque,
1155 const char *data,
1156 size_t length,
1157 size_t *consumed
1158 )
1159 {
1160 18 ub_http1_input_context *context = (ub_http1_input_context *)opaque;
1161 18 ub_http1_borrowed_window *window = NULL;
1162 18 SV *object = NULL;
1163 18 SV *head = NULL;
1164 18 SV *message = NULL;
1165 18 SV *window_arg = &PL_sv_undef;
1166 18 int head_ready = 0;
1167 18 int head_only = 0;
1168 18 int need_window = 1;
1169 int result;
1170  
1171 18 ▶ if (context == NULL || consumed == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if (context == NULL || consumed == NULL) 18 0 18
if (context == NULL || consumed == NULL) 0 18 18
1172 0 croak("invalid Unblock::HTTP1 native input context");
1173  
1174 18 *consumed = 0;
1175 18 ▶ if (data == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (data == NULL) 0 18 18
1176 0 data = "";
1177  
1178 18 context->direct_head = ub_http1_input_can_direct_head(aTHX_ context);
1179  
1180 18 ▶ if (context->direct_head && context->role == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (context->direct_head && context->role == 1) { 15 3 18
if (context->direct_head && context->role == 1) { 9 6 15
1181 9 head = ub_http1_parse_request_head_result(
1182 aTHX_
1183 data,
1184 length,
1185 0,
1186 context->max_headers,
1187 9 ▶ context->uniform_native ? &context->uniform_api : NULL,
Branch: 1 branch
BranchTrueFalseTotal
context->uniform_native ? &context->uniform_api : NULL, 9 0 9
1188 &message
1189 );
1190  
1191 9 ▶ if (head == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (head == NULL) { 1 8 9
1192 1 ▶ if (length <= context->max_head_size)
Branch: 1 branch
BranchTrueFalseTotal
if (length <= context->max_head_size) 1 0 1
1193 1 return UB_HTTP1_INPUT_MORE;
1194 0 head = new_error_result(
1195 aTHX_ 431, "request head exceeds configured limit"
1196 );
1197 0 need_window = 0;
1198 8 ▶ } else if (SvROK(head) && SvTYPE(SvRV(head)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (SvROK(head) && SvTYPE(SvRV(head)) == SVt_PVHV) { 8 0 8
} else if (SvROK(head) && SvTYPE(SvRV(head)) == SVt_PVHV) { 8 0 8
1199 8 HV *head_hv = (HV *)SvRV(head);
1200 8 SV **ok_sv = hv_fetch(head_hv, "ok", 2, 0);
1201  
1202 16 ▶ if (ok_sv != NULL && SvTRUE(*ok_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ok_sv != NULL && SvTRUE(*ok_sv)) { 8 0 8
if (ok_sv != NULL && SvTRUE(*ok_sv)) { 8 0 8
1203 8 SV **consumed_sv = hv_fetch(head_hv, "consumed", 8, 0);
1204 8 ▶ if (consumed_sv != NULL && SvOK(*consumed_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (consumed_sv != NULL && SvOK(*consumed_sv)) { 8 0 8
if (consumed_sv != NULL && SvOK(*consumed_sv)) { 8 0 8
1205 8 UV head_consumed = SvUV(*consumed_sv);
1206 8 ▶ if (head_consumed <= (UV)length
Branch: 1 branch
BranchTrueFalseTotal
if (head_consumed <= (UV)length 8 0 8
1207 8 ▶ && head_consumed == (UV)length) {
Branch: 1 branch
BranchTrueFalseTotal
&& head_consumed == (UV)length) { 4 4 8
1208 4 need_window = 0;
1209 4 head_only = 1;
1210 }
1211 }
1212 } else {
1213 0 need_window = 0;
1214 }
1215 }
1216 9 ▶ } else if (context->direct_head && context->role == 2) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (context->direct_head && context->role == 2) { 6 3 9
} else if (context->direct_head && context->role == 2) { 6 0 6
1217 6 head = ub_http1_parse_response_head_result(
1218 aTHX_
1219 data,
1220 length,
1221 0,
1222 context->max_headers,
1223 6 ▶ context->uniform_native ? &context->uniform_api : NULL,
Branch: 1 branch
BranchTrueFalseTotal
context->uniform_native ? &context->uniform_api : NULL, 6 0 6
1224 &message
1225 );
1226  
1227 6 ▶ if (head == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (head == NULL) { 1 5 6
1228 1 ▶ if (length <= context->max_head_size)
Branch: 1 branch
BranchTrueFalseTotal
if (length <= context->max_head_size) 1 0 1
1229 1 return UB_HTTP1_INPUT_MORE;
1230 0 head = new_error_result(
1231 aTHX_ 0, "HTTP/1 response head exceeds configured limit"
1232 );
1233 0 need_window = 0;
1234 5 ▶ } else if (SvROK(head) && SvTYPE(SvRV(head)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (SvROK(head) && SvTYPE(SvRV(head)) == SVt_PVHV) { 5 0 5
} else if (SvROK(head) && SvTYPE(SvRV(head)) == SVt_PVHV) { 5 0 5
1235 5 HV *head_hv = (HV *)SvRV(head);
1236 5 SV **ok_sv = hv_fetch(head_hv, "ok", 2, 0);
1237  
1238 10 ▶ if (ok_sv != NULL && SvTRUE(*ok_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ok_sv != NULL && SvTRUE(*ok_sv)) { 5 0 5
if (ok_sv != NULL && SvTRUE(*ok_sv)) { 5 0 5
1239 5 SV **consumed_sv = hv_fetch(head_hv, "consumed", 8, 0);
1240 5 ▶ if (consumed_sv != NULL && SvOK(*consumed_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (consumed_sv != NULL && SvOK(*consumed_sv)) { 5 0 5
if (consumed_sv != NULL && SvOK(*consumed_sv)) { 5 0 5
1241 5 UV head_consumed = SvUV(*consumed_sv);
1242 5 ▶ if (head_consumed <= (UV)length
Branch: 1 branch
BranchTrueFalseTotal
if (head_consumed <= (UV)length 5 0 5
1243 5 ▶ && head_consumed == (UV)length) {
Branch: 1 branch
BranchTrueFalseTotal
&& head_consumed == (UV)length) { 2 3 5
1244 2 need_window = 0;
1245 2 head_only = 1;
1246 }
1247 }
1248 } else {
1249 0 need_window = 0;
1250 }
1251 }
1252 }
1253  
1254 16 ▶ if (head_only) {
Branch: 1 branch
BranchTrueFalseTotal
if (head_only) { 6 10 16
1255 int jump_status;
1256 dJMPENV;
1257  
1258 6 *consumed = length;
1259 6 JMPENV_PUSH(jump_status);
1260 6 ▶ if (jump_status == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (jump_status == 0) { 6 0 6
1261 6 result = ub_http1_call_engine_head(
1262 aTHX_ context, head, message, &head_ready
1263 );
1264 6 JMPENV_POP;
1265 } else {
1266 0 JMPENV_POP;
1267 0 ▶ if (message != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (message != NULL) 0 0 0
1268 0 SvREFCNT_dec(message);
1269 0 SvREFCNT_dec(head);
1270 0 ▶ JMPENV_JUMP(jump_status);
Branch: 2 branches
BranchTrueFalseTotal
JMPENV_JUMP(jump_status); 0 0 0
JMPENV_JUMP(jump_status); 0 0 0
1271 }
1272  
1273 6 ▶ if (message != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (message != NULL) 6 0 6
1274 6 SvREFCNT_dec(message);
1275 6 SvREFCNT_dec(head);
1276  
1277 6 ▶ if (result < UB_HTTP1_INPUT_OK || result > UB_HTTP1_INPUT_SWITCH
Branch: 2 branches
BranchTrueFalseTotal
if (result < UB_HTTP1_INPUT_OK || result > UB_HTTP1_INPUT_SWITCH 6 0 6
if (result < UB_HTTP1_INPUT_OK || result > UB_HTTP1_INPUT_SWITCH 6 0 6
1278 6 ▶ || result == 2)
Branch: 1 branch
BranchTrueFalseTotal
|| result == 2) 0 6 6
1279 0 croak("Unblock::HTTP1 engine returned invalid native input status");
1280  
1281 6 context->direct_head = head_ready;
1282 6 return result;
1283 }
1284  
1285 10 ▶ if (need_window) {
Branch: 1 branch
BranchTrueFalseTotal
if (need_window) { 10 0 10
1286 SV *inner;
1287  
1288 10 Newxz(window, 1, ub_http1_borrowed_window);
1289 10 ▶ if (window == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (window == NULL) { 0 10 10
1290 0 ▶ if (head != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (head != NULL) 0 0 0
1291 0 SvREFCNT_dec(head);
1292 0 croak("unable to allocate borrowed input window");
1293 }
1294  
1295 10 window->data = data;
1296 10 window->length = length;
1297 10 window->offset = 0;
1298 10 window->valid = 1;
1299  
1300 10 inner = newSViv(PTR2IV(window));
1301 10 object = newRV_noinc(inner);
1302 10 sv_bless(object,
1303 gv_stashpv("Unblock::HTTP1::_Native::BorrowedWindow", GV_ADD));
1304 10 window_arg = object;
1305 }
1306  
1307 {
1308 int jump_status;
1309 dJMPENV;
1310  
1311 10 JMPENV_PUSH(jump_status);
1312 10 ▶ if (jump_status == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (jump_status == 0) { 10 0 10
1313 10 result = ub_http1_call_engine_input(
1314 aTHX_
1315 context,
1316 window_arg,
1317 length,
1318 head,
1319 message,
1320 consumed,
1321 &head_ready
1322 );
1323 10 JMPENV_POP;
1324 } else {
1325 0 JMPENV_POP;
1326 0 ▶ if (window != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (window != NULL) 0 0 0
1327 0 window->valid = 0;
1328 0 ▶ if (object != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (object != NULL) 0 0 0
1329 0 SvREFCNT_dec(object);
1330 0 ▶ if (message != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (message != NULL) 0 0 0
1331 0 SvREFCNT_dec(message);
1332 0 ▶ if (head != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (head != NULL) 0 0 0
1333 0 SvREFCNT_dec(head);
1334 0 ▶ JMPENV_JUMP(jump_status);
Branch: 2 branches
BranchTrueFalseTotal
JMPENV_JUMP(jump_status); 0 0 0
JMPENV_JUMP(jump_status); 0 0 0
1335 }
1336 }
1337  
1338 10 ▶ if (window != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (window != NULL) 10 0 10
1339 10 window->valid = 0;
1340 10 ▶ if (object != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (object != NULL) 10 0 10
1341 10 SvREFCNT_dec(object);
1342 10 ▶ if (message != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (message != NULL) 7 3 10
1343 7 SvREFCNT_dec(message);
1344 10 ▶ if (head != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (head != NULL) 7 3 10
1345 7 SvREFCNT_dec(head);
1346  
1347 10 ▶ if (result < UB_HTTP1_INPUT_OK || result > UB_HTTP1_INPUT_SWITCH
Branch: 2 branches
BranchTrueFalseTotal
if (result < UB_HTTP1_INPUT_OK || result > UB_HTTP1_INPUT_SWITCH 10 0 10
if (result < UB_HTTP1_INPUT_OK || result > UB_HTTP1_INPUT_SWITCH 10 0 10
1348 10 ▶ || result == 2)
Branch: 1 branch
BranchTrueFalseTotal
|| result == 2) 0 10 10
1349 0 croak("Unblock::HTTP1 engine returned invalid native input status");
1350  
1351 10 ▶ if (context->role)
Branch: 1 branch
BranchTrueFalseTotal
if (context->role) 10 0 10
1352 10 context->direct_head = head_ready;
1353  
1354 10 return result;
1355 }
1356  
1357 static int
1358 0 ub_http1_input_eof(pTHX_ void *opaque)
1359 {
1360 0 ub_http1_input_context *context = (ub_http1_input_context *)opaque;
1361 int result;
1362  
1363 0 ▶ if (context == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (context == NULL) 0 0 0
1364 0 croak("invalid Unblock::HTTP1 native input context");
1365  
1366 0 result = ub_http1_call_engine_scalar(
1367 aTHX_
1368 context,
1369 &context->eof_cv,
1370 "_borrowed_input_eof",
1371 NULL
1372 );
1373  
1374 0 ▶ if (result != UB_HTTP1_INPUT_OK
Branch: 1 branch
BranchTrueFalseTotal
if (result != UB_HTTP1_INPUT_OK 0 0 0
1375 0 ▶ && result != UB_HTTP1_INPUT_CLOSED
Branch: 1 branch
BranchTrueFalseTotal
&& result != UB_HTTP1_INPUT_CLOSED 0 0 0
1376 0 ▶ && result != UB_HTTP1_INPUT_SWITCH)
Branch: 1 branch
BranchTrueFalseTotal
&& result != UB_HTTP1_INPUT_SWITCH) 0 0 0
1377 0 croak("Unblock::HTTP1 engine returned invalid native EOF status");
1378  
1379 0 return result;
1380 }
1381  
1382 static void
1383 13 ub_http1_input_destroy(pTHX_ void *opaque)
1384 {
1385 13 ub_http1_input_context *context = (ub_http1_input_context *)opaque;
1386  
1387 PERL_UNUSED_CONTEXT;
1388 13 ▶ if (context == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (context == NULL) 0 13 13
1389 0 return;
1390  
1391 13 ▶ if (context->input_cv != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (context->input_cv != NULL) 9 4 13
1392 9 SvREFCNT_dec((SV *)context->input_cv);
1393 13 ▶ if (context->head_cv != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (context->head_cv != NULL) 4 9 13
1394 4 SvREFCNT_dec((SV *)context->head_cv);
1395 13 ▶ if (context->eof_cv != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (context->eof_cv != NULL) 0 13 13
1396 0 SvREFCNT_dec((SV *)context->eof_cv);
1397 13 ▶ if (context->engine != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (context->engine != NULL) 13 0 13
1398 13 SvREFCNT_dec(context->engine);
1399 13 Safefree(context);
1400 }
1401  
1402 static const ub_http1_input_ops_v1 ub_http1_input_ops = {
1403 UB_HTTP1_INPUT_ABI_VERSION,
1404 sizeof(ub_http1_input_ops_v1),
1405 "Unblock::HTTP1 borrowed input",
1406 ub_http1_input_create,
1407 ub_http1_input_borrowed,
1408 ub_http1_input_eof,
1409 ub_http1_input_destroy
1410 };
1411  
1412 MODULE = Unblock::HTTP1 PACKAGE = Unblock::HTTP1::_Native
1413 PROTOTYPES: DISABLE
1414  
1415 UV
1416 _borrowed_input_operations_address()
1417 CODE:
1418 1 ▶ RETVAL = PTR2UV(&ub_http1_input_ops);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PTR2UV(&ub_http1_input_ops); 0 1 1
1419 OUTPUT:
1420 RETVAL
1421  
1422 UV
1423 _borrowed_input_operations_size()
1424 CODE:
1425 1 ▶ RETVAL = (UV)sizeof(ub_http1_input_ops_v1);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (UV)sizeof(ub_http1_input_ops_v1); 0 1 1
1426 OUTPUT:
1427 RETVAL
1428  
1429 void
1430 _borrowed_input_once(engine, buffer)
1431 SV *engine
1432 SV *buffer
1433 PREINIT:
1434 STRLEN buffer_len;
1435 const char *data;
1436 void *context;
1437 8 size_t consumed = 0;
1438 int status;
1439 PPCODE:
1440 8 data = SvPVbyte(buffer, buffer_len);
1441 8 context = ub_http1_input_create(aTHX_ engine);
1442 8 ▶ if (context == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (context == NULL) 0 8 8
1443 0 croak("engine does not support Unblock::HTTP1 native input");
1444 8 status = ub_http1_input_borrowed(
1445 aTHX_ context, data, (size_t)buffer_len, &consumed
1446 );
1447 8 ub_http1_input_destroy(aTHX_ context);
1448 8 ▶ XPUSHs(sv_2mortal(newSViv(status)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(status))); 0 8 8
1449 8 ▶ XPUSHs(sv_2mortal(newSVuv((UV)consumed)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVuv((UV)consumed))); 0 8 8
1450  
1451 const char *
1452 pico_version(CLASS)
1453 const char *CLASS
1454 CODE:
1455 (void)CLASS;
1456 0 RETVAL = PICOHTTPPARSER_VERSION;
1457 OUTPUT:
1458 RETVAL
1459  
1460 SV *
1461 parse_request_head(CLASS, buffer, last_len = 0, max_headers = 100, offset = 0)
1462 const char *CLASS
1463 SV *buffer
1464 UV last_len
1465 UV max_headers
1466 UV offset
1467 PREINIT:
1468 STRLEN buffer_len;
1469 const char *buf;
1470 CODE:
1471 (void)CLASS;
1472 273 buf = ub_http1_buffer_view(aTHX_ buffer, &buffer_len);
1473 273 ▶ if (offset > (UV)buffer_len)
Branch: 1 branch
BranchTrueFalseTotal
if (offset > (UV)buffer_len) 0 273 273
1474 0 croak("offset exceeds buffer length");
1475 273 buf += (size_t)offset;
1476 273 buffer_len -= (STRLEN)offset;
1477 273 RETVAL = ub_http1_parse_request_head_result(
1478 aTHX_
1479 buf,
1480 (size_t)buffer_len,
1481 (size_t)last_len,
1482 (size_t)max_headers,
1483 NULL,
1484 NULL
1485 );
1486 273 ▶ if (RETVAL == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL == NULL) 169 104 273
1487 169 XSRETURN_UNDEF;
1488 OUTPUT:
1489 RETVAL
1490  
1491 SV *
1492 parse_response_head(CLASS, buffer, last_len = 0, max_headers = 100, offset = 0)
1493 const char *CLASS
1494 SV *buffer
1495 UV last_len
1496 UV max_headers
1497 UV offset
1498 PREINIT:
1499 STRLEN buffer_len;
1500 const char *buf;
1501 CODE:
1502 (void)CLASS;
1503 169 buf = ub_http1_buffer_view(aTHX_ buffer, &buffer_len);
1504 169 ▶ if (offset > (UV)buffer_len)
Branch: 1 branch
BranchTrueFalseTotal
if (offset > (UV)buffer_len) 0 169 169
1505 0 croak("offset exceeds buffer length");
1506 169 buf += (size_t)offset;
1507 169 buffer_len -= (STRLEN)offset;
1508 169 RETVAL = ub_http1_parse_response_head_result(
1509 aTHX_
1510 buf,
1511 (size_t)buffer_len,
1512 (size_t)last_len,
1513 (size_t)max_headers,
1514 NULL,
1515 NULL
1516 );
1517 169 ▶ if (RETVAL == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL == NULL) 112 57 169
1518 112 XSRETURN_UNDEF;
1519 OUTPUT:
1520 RETVAL
1521  
1522 SV *
1523 parse_trailers(CLASS, buffer, last_len = 0, max_headers = 100, offset = 0)
1524 const char *CLASS
1525 SV *buffer
1526 UV last_len
1527 UV max_headers
1528 UV offset
1529 PREINIT:
1530 STRLEN buffer_len;
1531 const char *buf;
1532 struct phr_header headers[UB_HTTP1_MAX_HEADERS];
1533 size_t count;
1534 int consumed;
1535 HV *hv;
1536 AV *list;
1537 CODE:
1538 (void)CLASS;
1539 41 buf = ub_http1_buffer_view(aTHX_ buffer, &buffer_len);
1540 41 ▶ if (offset > (UV)buffer_len)
Branch: 1 branch
BranchTrueFalseTotal
if (offset > (UV)buffer_len) 0 41 41
1541 0 croak("offset exceeds buffer length");
1542 41 buf += (size_t)offset;
1543 41 buffer_len -= (STRLEN)offset;
1544 41 ▶ if (last_len > (UV)buffer_len)
Branch: 1 branch
BranchTrueFalseTotal
if (last_len > (UV)buffer_len) 0 41 41
1545 0 croak("last_len exceeds input window length");
1546 41 ▶ if (max_headers == 0 || max_headers > UB_HTTP1_MAX_HEADERS)
Branch: 2 branches
BranchTrueFalseTotal
if (max_headers == 0 || max_headers > UB_HTTP1_MAX_HEADERS) 41 0 41
if (max_headers == 0 || max_headers > UB_HTTP1_MAX_HEADERS) 0 41 41
1547 0 croak("max_headers must be between 1 and %d", UB_HTTP1_MAX_HEADERS);
1548 41 count = (size_t)max_headers;
1549 41 consumed = phr_parse_headers(buf, (size_t)buffer_len, headers, &count, (size_t)last_len);
1550 41 ▶ if (consumed == -2) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (consumed == -2) XSRETURN_UNDEF; 29 12 41
1551 12 ▶ if (consumed == -1 || !strict_headers(headers, count)) {
Branch: 2 branches
BranchTrueFalseTotal
if (consumed == -1 || !strict_headers(headers, count)) { 12 0 12
if (consumed == -1 || !strict_headers(headers, count)) { 0 12 12
1552 0 RETVAL = new_error_result(aTHX_ 0, "malformed HTTP/1 trailer section");
1553 } else {
1554 12 hv = newHV();
1555 12 hv_store(hv, "ok", 2, newSViv(1), 0);
1556 12 hv_store(hv, "consumed", 8, newSViv(consumed), 0);
1557 12 list = headers_to_av(aTHX_ headers, count);
1558 12 hv_store(hv, "headers", 7, newRV_noinc((SV *)list), 0);
1559 12 RETVAL = newRV_noinc((SV *)hv);
1560 }
1561 OUTPUT:
1562 RETVAL
1563  
1564 MODULE = Unblock::HTTP1 PACKAGE = Unblock::HTTP1::_Native::BorrowedDriver
1565  
1566 SV *
1567 new(CLASS, engine)
1568 const char *CLASS
1569 SV *engine
1570 PREINIT:
1571 ub_http1_input_context *context;
1572 SV *inner;
1573 SV *object;
1574 CODE:
1575 5 context = (ub_http1_input_context *)ub_http1_input_create(aTHX_ engine);
1576 5 ▶ if (context == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (context == NULL) 0 5 5
1577 0 croak("engine does not support Unblock::HTTP1 native input");
1578 5 inner = newSViv(PTR2IV(context));
1579 5 object = newRV_noinc(inner);
1580 5 sv_bless(object, gv_stashpv(CLASS, GV_ADD));
1581 5 RETVAL = object;
1582 OUTPUT:
1583 RETVAL
1584  
1585 void
1586 feed(self, buffer)
1587 SV *self
1588 SV *buffer
1589 PREINIT:
1590 SV *inner;
1591 ub_http1_input_context *context;
1592 STRLEN buffer_len;
1593 const char *data;
1594 10 size_t consumed = 0;
1595 int status;
1596 PPCODE:
1597 10 ▶ if (!SvROK(self)
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(self) 10 0 10
1598 10 ▶ || !sv_derived_from(self, "Unblock::HTTP1::_Native::BorrowedDriver"))
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_derived_from(self, "Unblock::HTTP1::_Native::BorrowedDriver")) 0 10 10
1599 0 croak("not an Unblock::HTTP1 borrowed input driver");
1600 10 inner = SvRV(self);
1601 10 context = INT2PTR(ub_http1_input_context *, SvIV(inner));
1602 10 ▶ if (context == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (context == NULL) 0 10 10
1603 0 croak("borrowed input driver has already been released");
1604 10 data = SvPVbyte(buffer, buffer_len);
1605 10 status = ub_http1_input_borrowed(
1606 aTHX_ context, data, (size_t)buffer_len, &consumed
1607 );
1608 10 ▶ XPUSHs(sv_2mortal(newSViv(status)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(status))); 0 10 10
1609 10 ▶ XPUSHs(sv_2mortal(newSVuv((UV)consumed)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVuv((UV)consumed))); 0 10 10
1610  
1611 UV
1612 feed_repeat(self, buffer, count)
1613 SV *self
1614 SV *buffer
1615 UV count
1616 PREINIT:
1617 SV *inner;
1618 ub_http1_input_context *context;
1619 STRLEN buffer_len;
1620 const char *data;
1621 UV i;
1622 CODE:
1623 0 ▶ if (!SvROK(self)
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(self) 0 0 0
1624 0 ▶ || !sv_derived_from(self, "Unblock::HTTP1::_Native::BorrowedDriver"))
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_derived_from(self, "Unblock::HTTP1::_Native::BorrowedDriver")) 0 0 0
1625 0 croak("not an Unblock::HTTP1 borrowed input driver");
1626 0 inner = SvRV(self);
1627 0 context = INT2PTR(ub_http1_input_context *, SvIV(inner));
1628 0 ▶ if (context == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (context == NULL) 0 0 0
1629 0 croak("borrowed input driver has already been released");
1630 0 data = SvPVbyte(buffer, buffer_len);
1631 0 ▶ for (i = 0; i < count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) { 0 0 0
1632 0 size_t consumed = 0;
1633 0 int status = ub_http1_input_borrowed(
1634 aTHX_ context, data, (size_t)buffer_len, &consumed
1635 );
1636 0 ▶ if (status != UB_HTTP1_INPUT_OK
Branch: 1 branch
BranchTrueFalseTotal
if (status != UB_HTTP1_INPUT_OK 0 0 0
1637 0 ▶ || consumed != (size_t)buffer_len)
Branch: 1 branch
BranchTrueFalseTotal
|| consumed != (size_t)buffer_len) 0 0 0
1638 0 croak("borrowed repeat input did not consume complete window");
1639 }
1640 0 ▶ RETVAL = count;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = count; 0 0 0
1641 OUTPUT:
1642 RETVAL
1643  
1644 int
1645 eof(self)
1646 SV *self
1647 PREINIT:
1648 SV *inner;
1649 ub_http1_input_context *context;
1650 CODE:
1651 0 ▶ if (!SvROK(self)
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(self) 0 0 0
1652 0 ▶ || !sv_derived_from(self, "Unblock::HTTP1::_Native::BorrowedDriver"))
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_derived_from(self, "Unblock::HTTP1::_Native::BorrowedDriver")) 0 0 0
1653 0 croak("not an Unblock::HTTP1 borrowed input driver");
1654 0 inner = SvRV(self);
1655 0 context = INT2PTR(ub_http1_input_context *, SvIV(inner));
1656 0 ▶ if (context == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (context == NULL) 0 0 0
1657 0 croak("borrowed input driver has already been released");
1658 0 RETVAL = ub_http1_input_eof(aTHX_ context);
1659 OUTPUT:
1660 RETVAL
1661  
1662 void
1663 DESTROY(self)
1664 SV *self
1665 PREINIT:
1666 SV *inner;
1667 ub_http1_input_context *context;
1668 CODE:
1669 5 ▶ if (!SvROK(self))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(self)) 0 5 5
1670 0 XSRETURN_EMPTY;
1671 5 inner = SvRV(self);
1672 5 context = INT2PTR(ub_http1_input_context *, SvIV(inner));
1673 5 ▶ if (context == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (context == NULL) 0 5 5
1674 0 XSRETURN_EMPTY;
1675 5 ub_http1_input_destroy(aTHX_ context);
1676 5 sv_setiv(inner, 0);
1677  
1678 MODULE = Unblock::HTTP1 PACKAGE = Unblock::HTTP1::_Native::BorrowedWindow
1679  
1680 SV *
1681 slice(self, offset, length)
1682 SV *self
1683 UV offset
1684 UV length
1685 PREINIT:
1686 ub_http1_borrowed_window *window;
1687 CODE:
1688 5 window = ub_http1_window_from_sv(aTHX_ self);
1689 5 ▶ if (offset > (UV)window->length
Branch: 1 branch
BranchTrueFalseTotal
if (offset > (UV)window->length 5 0 5
1690 5 ▶ || length > (UV)(window->length - (size_t)offset))
Branch: 1 branch
BranchTrueFalseTotal
|| length > (UV)(window->length - (size_t)offset)) 0 5 5
1691 0 croak("borrowed input slice exceeds window");
1692 5 RETVAL = newSVpvn(
1693 window->data + (size_t)offset,
1694 (STRLEN)length
1695 );
1696 OUTPUT:
1697 RETVAL
1698  
1699 UV
1700 remaining(self)
1701 SV *self
1702 PREINIT:
1703 ub_http1_borrowed_window *window;
1704 CODE:
1705 0 window = ub_http1_window_from_sv(aTHX_ self);
1706 0 ▶ RETVAL = (UV)(window->length - window->offset);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (UV)(window->length - window->offset); 0 0 0
1707 OUTPUT:
1708 RETVAL
1709  
1710 UV
1711 consumed(self)
1712 SV *self
1713 PREINIT:
1714 ub_http1_borrowed_window *window;
1715 CODE:
1716 0 window = ub_http1_window_from_sv(aTHX_ self);
1717 0 ▶ RETVAL = (UV)window->offset;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (UV)window->offset; 0 0 0
1718 OUTPUT:
1719 RETVAL
1720  
1721 SV *
1722 take(self, length)
1723 SV *self
1724 UV length
1725 PREINIT:
1726 ub_http1_borrowed_window *window;
1727 size_t remaining;
1728 CODE:
1729 0 window = ub_http1_window_from_sv(aTHX_ self);
1730 0 remaining = window->length - window->offset;
1731 0 ▶ if (length > (UV)remaining)
Branch: 1 branch
BranchTrueFalseTotal
if (length > (UV)remaining) 0 0 0
1732 0 croak("borrowed input take exceeds remaining window");
1733 0 RETVAL = newSVpvn(window->data + window->offset, (STRLEN)length);
1734 0 window->offset += (size_t)length;
1735 OUTPUT:
1736 RETVAL
1737  
1738 void
1739 discard(self, length)
1740 SV *self
1741 UV length
1742 PREINIT:
1743 ub_http1_borrowed_window *window;
1744 size_t remaining;
1745 CODE:
1746 0 window = ub_http1_window_from_sv(aTHX_ self);
1747 0 remaining = window->length - window->offset;
1748 0 ▶ if (length > (UV)remaining)
Branch: 1 branch
BranchTrueFalseTotal
if (length > (UV)remaining) 0 0 0
1749 0 croak("borrowed input discard exceeds remaining window");
1750 0 window->offset += (size_t)length;
1751  
1752 void
1753 clear(self)
1754 SV *self
1755 PREINIT:
1756 ub_http1_borrowed_window *window;
1757 CODE:
1758 0 window = ub_http1_window_from_sv(aTHX_ self);
1759 0 window->offset = window->length;
1760  
1761 SV *
1762 remaining_bytes(self)
1763 SV *self
1764 PREINIT:
1765 ub_http1_borrowed_window *window;
1766 size_t remaining;
1767 CODE:
1768 0 window = ub_http1_window_from_sv(aTHX_ self);
1769 0 remaining = window->length - window->offset;
1770 0 RETVAL = newSVpvn(window->data + window->offset, (STRLEN)remaining);
1771 OUTPUT:
1772 RETVAL
1773  
1774 void
1775 DESTROY(self)
1776 SV *self
1777 PREINIT:
1778 SV *inner;
1779 ub_http1_borrowed_window *window;
1780 CODE:
1781 10 ▶ if (!SvROK(self))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(self)) 0 10 10
1782 0 XSRETURN_EMPTY;
1783 10 inner = SvRV(self);
1784 10 window = INT2PTR(ub_http1_borrowed_window *, SvIV(inner));
1785 10 ▶ if (window == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (window == NULL) 0 10 10
1786 0 XSRETURN_EMPTY;
1787 10 Safefree(window);
1788 10 sv_setiv(inner, 0);
1789  
1790 MODULE = Unblock::HTTP1 PACKAGE = Unblock::HTTP1::_Native::Chunked
1791  
1792 SV *
1793 new(CLASS, max_chunk_extension_size = 16384)
1794 const char *CLASS
1795 UV max_chunk_extension_size
1796 PREINIT:
1797 struct phr_chunked_decoder *decoder;
1798 SV *inner;
1799 SV *obj;
1800 CODE:
1801 if (max_chunk_extension_size > (UV)SIZE_MAX)
1802 croak("max_chunk_extension_size exceeds native size range");
1803 23 Newxz(decoder, 1, struct phr_chunked_decoder);
1804 23 decoder->consume_trailer = 0;
1805 23 decoder->_max_chunk_ext_size = (size_t)max_chunk_extension_size;
1806 23 inner = newSViv(PTR2IV(decoder));
1807 23 obj = newRV_noinc(inner);
1808 23 sv_bless(obj, gv_stashpv(CLASS, GV_ADD));
1809 23 RETVAL = obj;
1810 OUTPUT:
1811 RETVAL
1812  
1813 void
1814 feed(self, input, emit = 1, offset = 0)
1815 SV *self
1816 SV *input
1817 int emit
1818 UV offset
1819 PREINIT:
1820 struct phr_chunked_decoder *decoder;
1821 SV *inner;
1822 STRLEN input_len;
1823 const char *input_bytes;
1824 char *scratch;
1825 size_t decoded_len;
1826 ssize_t result;
1827 size_t leftover;
1828 PPCODE:
1829 60 ▶ if (!SvROK(self) || !sv_derived_from(self, "Unblock::HTTP1::_Native::Chunked"))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(self) || !sv_derived_from(self, "Unblock::HTTP1::_Native::Chunked")) 60 0 60
if (!SvROK(self) || !sv_derived_from(self, "Unblock::HTTP1::_Native::Chunked")) 0 60 60
1830 0 croak("not an Unblock::HTTP1 chunked decoder object");
1831 60 inner = SvRV(self);
1832 60 decoder = INT2PTR(struct phr_chunked_decoder *, SvIV(inner));
1833 60 ▶ if (!decoder) croak("chunked decoder has already been released");
Branch: 1 branch
BranchTrueFalseTotal
if (!decoder) croak("chunked decoder has already been released"); 0 60 60
1834 60 input_bytes = ub_http1_buffer_view(aTHX_ input, &input_len);
1835 60 ▶ if (offset > (UV)input_len)
Branch: 1 branch
BranchTrueFalseTotal
if (offset > (UV)input_len) 0 60 60
1836 0 croak("offset exceeds input length");
1837 60 input_bytes += (size_t)offset;
1838 60 input_len -= (STRLEN)offset;
1839 60 ▶ Newx(scratch, input_len ? input_len : 1, char);
Branch: 1 branch
BranchTrueFalseTotal
Newx(scratch, input_len ? input_len : 1, char); 60 0 60
1840 60 ▶ if (input_len) Copy(input_bytes, scratch, input_len, char);
Branch: 1 branch
BranchTrueFalseTotal
if (input_len) Copy(input_bytes, scratch, input_len, char); 60 0 60
1841 60 decoded_len = (size_t)input_len;
1842 60 result = phr_decode_chunked(decoder, scratch, &decoded_len);
1843 60 ▶ if (result == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (result == -1) { 7 53 60
1844 7 Safefree(scratch);
1845 7 croak("malformed HTTP/1 chunked body");
1846 }
1847 53 leftover = result >= 0 ? (size_t)result : 0;
1848 53 ▶ XPUSHs(sv_2mortal(newSViv(result >= 0 ? 1 : 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(result >= 0 ? 1 : 0))); 0 53 53
1849 53 ▶ if (emit)
Branch: 1 branch
BranchTrueFalseTotal
if (emit) 53 0 53
1850 53 ▶ XPUSHs(sv_2mortal(newSVpvn(scratch, (STRLEN)decoded_len)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(scratch, (STRLEN)decoded_len))); 0 53 53
1851 else
1852 0 ▶ XPUSHs(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(&PL_sv_undef); 0 0 0
1853 53 ▶ if (leftover)
Branch: 1 branch
BranchTrueFalseTotal
if (leftover) 13 40 53
1854 13 ▶ XPUSHs(sv_2mortal(newSVpvn(scratch + decoded_len, (STRLEN)leftover)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(scratch + decoded_len, (STRLEN)leftover))); 0 13 13
1855 else
1856 40 ▶ XPUSHs(sv_2mortal(newSVpvn("", 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn("", 0))); 0 40 40
1857 53 Safefree(scratch);
1858  
1859 void
1860 DESTROY(self)
1861 SV *self
1862 PREINIT:
1863 SV *inner;
1864 struct phr_chunked_decoder *decoder;
1865 CODE:
1866 23 ▶ if (!SvROK(self)) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(self)) XSRETURN_EMPTY; 0 23 23
1867 23 inner = SvRV(self);
1868 23 decoder = INT2PTR(struct phr_chunked_decoder *, SvIV(inner));
1869 23 ▶ if (!decoder) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (!decoder) XSRETURN_EMPTY; 0 23 23
1870 23 Safefree(decoder);
1871 23 sv_setiv(inner, 0);
« vendor/picohttpparser/picohttpparser.c ↑ Summary blib/lib/Unblock/HTTP1.pm »