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