| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| #include "ppport.h" |
| 6 |
|
| |
| 7 |
|
| /*------------------------------------------------------------------------------ |
| 8 |
|
| * |
| 9 |
|
| * Macros and definitions |
| 10 |
|
| * |
| 11 |
|
| -----------------------------------------------------------------------------*/ |
| 12 |
|
| |
| 13 |
|
| // Permitted characters |
| 14 |
|
| #define URI_CHARS_AUTH "!$&'()*+,;:=@" |
| 15 |
|
| #define URI_CHARS_USER "!$&'()*+,;=" |
| 16 |
|
| #define URI_CHARS_PATH "!$&'()*+,;:=@/" |
| 17 |
|
| #define URI_CHARS_PATH_SEGMENT "!$&'()*+,;:=@" |
| 18 |
|
| #define URI_CHARS_HOST "!$&'()[]*+,.;=@/" |
| 19 |
|
| #define URI_CHARS_QUERY ":@?/&=;" |
| 20 |
|
| #define URI_CHARS_FRAG ":@?/" |
| 21 |
|
| |
| 22 |
|
| // Returns the uri_t* referenced by the blessed URI::Fast object in the SV ref. |
| 23 |
|
| // Croaks if the SV does not point to a URI::Fast object. |
| 24 |
|
| #define URI(obj) \ |
| 25 |
|
| (((sv_isobject(obj) && sv_derived_from(obj, "URI::Fast")) ? NULL : croak("error: expected instance of URI::Fast")), \ |
| 26 |
|
| ((uri_t*) SvIV(SvRV((obj))))) |
| 27 |
|
| |
| 28 |
|
| // Size constants |
| 29 |
|
| #define URI_SIZE_scheme 32UL |
| 30 |
|
| #define URI_SIZE_usr 32UL |
| 31 |
|
| #define URI_SIZE_pwd 32UL |
| 32 |
|
| #define URI_SIZE_host 64UL |
| 33 |
|
| #define URI_SIZE_port 8UL |
| 34 |
|
| #define URI_SIZE_path 64UL |
| 35 |
|
| #define URI_SIZE_query 64UL |
| 36 |
|
| #define URI_SIZE_frag 32UL |
| 37 |
|
| |
| 38 |
|
| // Enough to fit all pieces + 3 chars for separators (2 colons + @) |
| 39 |
|
| #define URI_SIZE_auth (3 + URI_SIZE_usr + URI_SIZE_pwd + URI_SIZE_host + URI_SIZE_port) |
| 40 |
|
| |
| 41 |
|
| // Returns the size of the member in bytes |
| 42 |
|
| #define URI_SIZE(member) (URI_SIZE_##member) |
| 43 |
|
| |
| 44 |
|
| // Defines a clearer method |
| 45 |
|
| #define URI_SIMPLE_CLEARER(member) \ |
| 46 |
|
| static void clear_##member(pTHX_ SV *uri) { \ |
| 47 |
|
| str_clear(aTHX_ URI(uri)->member); \ |
| 48 |
|
| } |
| 49 |
|
| |
| 50 |
|
| // Returns a (non-mortal) SV from a uri_str_t |
| 51 |
|
| #define URI_STR_2SV(str) (newSVpvn((str)->length == 0 ? "" : (str)->string, (str)->length)) |
| 52 |
|
| |
| 53 |
|
| // Defines a setter method that accepts an unencoded value, encodes it, |
| 54 |
|
| // ignoring characters in string 'allowed', and copies the encoded value into |
| 55 |
|
| // slot 'member'. |
| 56 |
|
| #define URI_SIMPLE_SETTER(member, allowed) \ |
| 57 |
|
| static void set_##member(pTHX_ SV *sv_uri, SV *sv_value) { \ |
| 58 |
|
| uri_t *uri = URI(sv_uri); \ |
| 59 |
|
| if (is_defined(aTHX_ sv_value)) { \ |
| 60 |
|
| size_t len_value, len_enc; \ |
| 61 |
|
| const char *value = SvPV_const(sv_value, len_value); \ |
| 62 |
|
| char enc[len_value * 3 + 1]; \ |
| 63 |
|
| len_enc = uri_encode(value, len_value, enc, allowed, uri->is_iri); \ |
| 64 |
|
| str_set(aTHX_ uri->member, enc, len_enc); \ |
| 65 |
|
| } \ |
| 66 |
|
| else { \ |
| 67 |
|
| str_clear(aTHX_ uri->member); \ |
| 68 |
|
| } \ |
| 69 |
|
| } |
| 70 |
|
| |
| 71 |
|
| // Defines a setter method that accepts an arbitrary string value and copies it |
| 72 |
|
| // into the slot 'member' without changing it in any way. |
| 73 |
|
| #define URI_RAW_SETTER(member) \ |
| 74 |
|
| static void set_raw_##member(pTHX_ SV *sv_uri, SV *sv_value) { \ |
| 75 |
|
| uri_t *uri = URI(sv_uri); \ |
| 76 |
|
| if (is_defined(aTHX_ sv_value)) { \ |
| 77 |
|
| size_t len_value; \ |
| 78 |
|
| const char *value = SvPV_const(sv_value, len_value); \ |
| 79 |
|
| str_set(aTHX_ uri->member, value, len_value); \ |
| 80 |
|
| } \ |
| 81 |
|
| else { \ |
| 82 |
|
| str_clear(aTHX_ uri->member); \ |
| 83 |
|
| } \ |
| 84 |
|
| } |
| 85 |
|
| |
| 86 |
|
| // Defines a getter method that returns the raw, encoded value of the member |
| 87 |
|
| // slot. If the object is an IRI, decodes utf8 characters from hex sequences if |
| 88 |
|
| // present. |
| 89 |
|
| #define URI_RAW_GETTER(member) \ |
| 90 |
|
| static SV* get_raw_##member(pTHX_ SV *sv_uri) { \ |
| 91 |
|
| uri_t *uri = URI(sv_uri); \ |
| 92 |
|
| uri_str_t *str = uri->member; \ |
| 93 |
|
| if (uri->is_iri) { \ |
| 94 |
|
| if (str->length == 0) return newSVpvn("", 0); \ |
| 95 |
|
| char decoded[ str->length + 1 ]; \ |
| 96 |
|
| size_t len = uri_decode_utf8(str->string, str->length, decoded); \ |
| 97 |
|
| SV *out = newSVpvn(decoded, len); \ |
| 98 |
|
| sv_utf8_decode(out); \ |
| 99 |
|
| return out; \ |
| 100 |
|
| } else { \ |
| 101 |
|
| return URI_STR_2SV(str); \ |
| 102 |
|
| } \ |
| 103 |
|
| } |
| 104 |
|
| |
| 105 |
|
| // Defines a getter method that returns the decoded value of the member slot. |
| 106 |
|
| #define URI_SIMPLE_GETTER(member) \ |
| 107 |
|
| static SV* get_##member(pTHX_ SV *uri) { \ |
| 108 |
|
| uri_str_t *str = URI(uri)->member; \ |
| 109 |
|
| if (str->length == 0) return newSVpvn("", 0); \ |
| 110 |
|
| char decoded[ str->length + 1 ]; \ |
| 111 |
|
| size_t len = uri_decode(str->string, str->length, decoded, ""); \ |
| 112 |
|
| SV *out = newSVpvn(decoded, len); \ |
| 113 |
|
| sv_utf8_decode(out); \ |
| 114 |
|
| return out; \ |
| 115 |
|
| } |
| 116 |
|
| |
| 117 |
|
| // Defines a getter method for a structured field that returns the value of the |
| 118 |
|
| // member slot with non-ASCII character decoded, while leaving reserved |
| 119 |
|
| // characters encoded. |
| 120 |
|
| #define URI_COMPOUND_GETTER(member) \ |
| 121 |
|
| static SV* get_##member(pTHX_ SV *uri) { \ |
| 122 |
|
| uri_str_t *str = URI(uri)->member; \ |
| 123 |
|
| if (str->length == 0) return newSVpvn("", 0); \ |
| 124 |
|
| char decoded[ str->length + 1 ]; \ |
| 125 |
|
| size_t len = uri_decode_utf8(str->string, str->length, decoded); \ |
| 126 |
|
| SV *out = newSVpvn(decoded, len); \ |
| 127 |
|
| sv_utf8_decode(out); \ |
| 128 |
|
| return out; \ |
| 129 |
|
| } |
| 130 |
|
| |
| 131 |
|
| // Warns out info about a uri_str_t |
| 132 |
|
| #define URI_STR_DEBUG(str) \ |
| 133 |
|
| (warn( \ |
| 134 |
|
| "STRING< chunk=%lu, allocated=%lu, length=%lu, string='%.*s' >\n", \ |
| 135 |
|
| str->chunk, \ |
| 136 |
|
| str->allocated, \ |
| 137 |
|
| str->length, \ |
| 138 |
|
| (int)str->length, \ |
| 139 |
|
| str->string \ |
| 140 |
|
| )); \ |
| 141 |
|
| |
| 142 |
|
| /* |
| 143 |
|
| * Allocate memory with Newx if it's |
| 144 |
|
| * available - if it's an older perl |
| 145 |
|
| * that doesn't have Newx then we |
| 146 |
|
| * resort to using New. |
| 147 |
|
| */ |
| 148 |
|
| #ifndef Newx |
| 149 |
|
| #define Newx(v,n,t) New(0,v,n,t) |
| 150 |
|
| #endif |
| 151 |
|
| |
| 152 |
|
| // av_top_index not available on Perls < 5.18 |
| 153 |
|
| #ifndef av_top_index |
| 154 |
|
| #define av_top_index(av) av_len(av) |
| 155 |
|
| #endif |
| 156 |
|
| |
| 157 |
|
| /*------------------------------------------------------------------------------ |
| 158 |
|
| * |
| 159 |
|
| * Internal API |
| 160 |
|
| * |
| 161 |
|
| -----------------------------------------------------------------------------*/ |
| 162 |
|
| |
| 163 |
|
| /*------------------------------------------------------------------------------ |
| 164 |
|
| * Utilities |
| 165 |
|
| -----------------------------------------------------------------------------*/ |
| 166 |
|
| |
| 167 |
|
| // Returns the class name of a blessed object. Gets magic before evaluating. |
| 168 |
|
| // Returns an empty string if the object is not defined or is not a reference. |
| 169 |
|
| static |
| 170 |
330 |
| const char* class_name(pTHX_ SV *sv) { |
| 171 |
330 |
| SvGETMAGIC(sv); |
| 172 |
|
| |
| 173 |
330 |
▶ | if (!SvOK(sv) || !SvROK(sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvOK(sv) || !SvROK(sv)) { |
330 |
0 |
330 |
| if (!SvOK(sv) || !SvROK(sv)) { |
0 |
330 |
330 |
|
| 174 |
0 |
| return ""; |
| 175 |
|
| } |
| 176 |
|
| |
| 177 |
330 |
▶ | return HvNAME(SvSTASH(SvRV(sv))); |
Branch: 6 branches
| Branch | True | False | Total |
| return HvNAME(SvSTASH(SvRV(sv))); |
330 |
0 |
330 |
| return HvNAME(SvSTASH(SvRV(sv))); |
330 |
0 |
330 |
| return HvNAME(SvSTASH(SvRV(sv))); |
0 |
330 |
330 |
| return HvNAME(SvSTASH(SvRV(sv))); |
0 |
0 |
0 |
| return HvNAME(SvSTASH(SvRV(sv))); |
330 |
0 |
330 |
| return HvNAME(SvSTASH(SvRV(sv))); |
0 |
330 |
330 |
|
| 178 |
|
| } |
| 179 |
|
| |
| 180 |
|
| // Returns true if the SV is defined. Gets magic before evaluating the |
| 181 |
|
| // definedness of the SV. |
| 182 |
|
| static |
| 183 |
501 |
| bool is_defined(pTHX_ SV *sv) { |
| 184 |
501 |
| SvGETMAGIC(sv); |
| 185 |
501 |
| return SvOK(sv) ? 1 : 0; |
| 186 |
|
| } |
| 187 |
|
| |
| 188 |
|
| // Returns true if the SV is an RV. Gets magic before evaluating. |
| 189 |
|
| static |
| 190 |
76 |
| bool is_ref(pTHX_ SV *sv) { |
| 191 |
76 |
| SvGETMAGIC(sv); |
| 192 |
76 |
| return SvROK(sv) ? 1 : 0; |
| 193 |
|
| } |
| 194 |
|
| |
| 195 |
|
| // Replacement for strspn that is length-aware |
| 196 |
|
| static |
| 197 |
0 |
| size_t strnspn(const char *s, size_t s_len, const char *c) |
| 198 |
|
| { |
| 199 |
0 |
| size_t res = strspn(s, c); |
| 200 |
0 |
| return s_len < res ? s_len : res; |
| 201 |
|
| } |
| 202 |
|
| |
| 203 |
|
| // Replacement for strcspn that is length-aware |
| 204 |
|
| static |
| 205 |
4181 |
| size_t strncspn(const char *s, size_t s_len, const char *c) |
| 206 |
|
| { |
| 207 |
4181 |
| size_t res = strcspn(s, c); |
| 208 |
4181 |
| return s_len < res ? s_len : res; |
| 209 |
|
| } |
| 210 |
|
| |
| 211 |
|
| // Returns true if char c is in char* set. It is up to the caller to ensure |
| 212 |
|
| // that *set is nul-terminated. |
| 213 |
|
| static inline |
| 214 |
2066 |
| bool char_in_str(const char c, const char *set) { |
| 215 |
|
| size_t i; |
| 216 |
|
| |
| 217 |
14057 |
▶ | for (i = 0; set[i] != '\0'; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; set[i] != '\0'; ++i) { |
12062 |
1995 |
14057 |
|
| 218 |
12062 |
▶ | if (set[i] == c) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (set[i] == c) { |
71 |
11991 |
12062 |
|
| 219 |
71 |
| return 1; |
| 220 |
|
| } |
| 221 |
|
| } |
| 222 |
|
| |
| 223 |
1995 |
| return 0; |
| 224 |
|
| } |
| 225 |
|
| |
| 226 |
|
| // returns true for an ASCII whitespace char |
| 227 |
|
| static inline |
| 228 |
1762 |
| bool my_isspace(const char c) { |
| 229 |
1762 |
▶ | switch (c) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch (c) { |
18 |
1744 |
1762 |
|
| 230 |
18 |
| case ' ': case '\t': |
| 231 |
|
| case '\r': case '\n': |
| 232 |
|
| case '\f': case '\v': |
| 233 |
18 |
| return 1; |
| 234 |
1744 |
| default: |
| 235 |
1744 |
| return 0; |
| 236 |
|
| } |
| 237 |
|
| } |
| 238 |
|
| |
| 239 |
|
| // min of two numbers |
| 240 |
|
| static inline |
| 241 |
502 |
| size_t minnum(size_t x, size_t y) { |
| 242 |
502 |
| return x <= y ? x : y; |
| 243 |
|
| } |
| 244 |
|
| |
| 245 |
|
| // max of two numbers |
| 246 |
|
| static inline |
| 247 |
190 |
| size_t maxnum(size_t x, size_t y) { |
| 248 |
190 |
| return x >= y ? x : y; |
| 249 |
|
| } |
| 250 |
|
| |
| 251 |
|
| /*------------------------------------------------------------------------------ |
| 252 |
|
| * Resizable strings |
| 253 |
|
| -----------------------------------------------------------------------------*/ |
| 254 |
|
| typedef struct { |
| 255 |
|
| size_t chunk; // bytes to allocate at a time |
| 256 |
|
| size_t allocated; // number of currently allocated bytes |
| 257 |
|
| size_t length; // length of the string within the allocated buffer |
| 258 |
|
| char *string; // pointer to the allocated string |
| 259 |
|
| } uri_str_t; |
| 260 |
|
| |
| 261 |
|
| #define str_len(str) ((str)->length) |
| 262 |
|
| #define str_get(str) (str_len(str) == 0 ? "" : (const char*)str->string) |
| 263 |
|
| |
| 264 |
|
| // Truncates the string from the right-most occurence of r_char by setting that |
| 265 |
|
| // index to nul. Does not zero out the rest of the string. |
| 266 |
|
| static |
| 267 |
242 |
| void str_rtrim(pTHX_ uri_str_t *str, const char r_char) { |
| 268 |
|
| size_t i; |
| 269 |
806 |
▶ | for (i = str->length; i > 0; --i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = str->length; i > 0; --i) { |
798 |
8 |
806 |
|
| 270 |
798 |
▶ | if (str->string[i - 1] == r_char) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str->string[i - 1] == r_char) { |
234 |
564 |
798 |
|
| 271 |
234 |
| str->string[i - 1] = '\0'; |
| 272 |
234 |
| str->length = i - 1; |
| 273 |
234 |
| break; |
| 274 |
|
| } |
| 275 |
|
| } |
| 276 |
242 |
| } |
| 277 |
|
| |
| 278 |
|
| // Sets str to the first len chars of value. Reallocates another block of |
| 279 |
|
| // memory to fit it if necessary. |
| 280 |
|
| static |
| 281 |
3624 |
| void str_set(pTHX_ uri_str_t *str, const char *value, size_t len) { |
| 282 |
3624 |
| size_t allocate = str->chunk * (((len + 1) / str->chunk) + 1); |
| 283 |
|
| |
| 284 |
3624 |
▶ | if (str->string == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str->string == NULL) { |
3447 |
177 |
3624 |
|
| 285 |
3447 |
| Newx(str->string, allocate, char); |
| 286 |
3447 |
| str->allocated = allocate; |
| 287 |
|
| } |
| 288 |
177 |
▶ | else if (len > str->allocated) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (len > str->allocated) { |
3 |
174 |
177 |
|
| 289 |
3 |
| Renew(str->string, allocate, char); |
| 290 |
3 |
| str->allocated = allocate; |
| 291 |
|
| } |
| 292 |
|
| |
| 293 |
3624 |
▶ | if (value == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (value == NULL) { |
1036 |
2588 |
3624 |
|
| 294 |
1036 |
| Zero(str->string, len + 1, char); |
| 295 |
1036 |
| str->length = 0; |
| 296 |
|
| } |
| 297 |
|
| else { |
| 298 |
2588 |
| Copy(value, str->string, len, char); |
| 299 |
2588 |
| str->string[len] = '\0'; |
| 300 |
2588 |
| str->length = len; |
| 301 |
|
| } |
| 302 |
3624 |
| } |
| 303 |
|
| |
| 304 |
|
| // Appends the first len chars of value to str, allocating more memory if |
| 305 |
|
| // necessary. |
| 306 |
|
| static |
| 307 |
1521 |
| void str_append(pTHX_ uri_str_t *str, const char *value, size_t len) { |
| 308 |
1521 |
▶ | if (str->string == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str->string == NULL) { |
403 |
1118 |
1521 |
|
| 309 |
403 |
| str_set(aTHX_ str, value, len); |
| 310 |
403 |
| return; |
| 311 |
|
| } |
| 312 |
|
| |
| 313 |
1118 |
▶ | if (value != NULL && len > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (value != NULL && len > 0) { |
1118 |
0 |
1118 |
| if (value != NULL && len > 0) { |
1110 |
8 |
1118 |
|
| 314 |
1110 |
| size_t allocate = str->chunk * (((str->length + len + 1) / str->chunk) + 1); |
| 315 |
|
| |
| 316 |
1110 |
▶ | if (allocate != str->allocated) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (allocate != str->allocated) { |
46 |
1064 |
1110 |
|
| 317 |
46 |
| Renew(str->string, allocate, char); |
| 318 |
46 |
| str->allocated = allocate; |
| 319 |
|
| } |
| 320 |
|
| |
| 321 |
1110 |
| Copy(value, &str->string[str->length], len, char); |
| 322 |
1110 |
| str->string[str->length + len] = '\0'; |
| 323 |
1110 |
| str->length += len; |
| 324 |
|
| } |
| 325 |
|
| } |
| 326 |
|
| |
| 327 |
|
| // Zeroes out the contents of str. Does not release memory. |
| 328 |
|
| static |
| 329 |
119 |
| void str_clear(pTHX_ uri_str_t *str) { |
| 330 |
119 |
| str_set(aTHX_ str, NULL, 0); |
| 331 |
119 |
| } |
| 332 |
|
| |
| 333 |
|
| // Copies the contents of from into to. Does not clear to first, but will set |
| 334 |
|
| // the terminating nul and length. |
| 335 |
|
| static |
| 336 |
1414 |
| void str_copy(pTHX_ uri_str_t *from, uri_str_t *to) { |
| 337 |
1414 |
| str_set(aTHX_ to, from->string, from->length); |
| 338 |
1414 |
| } |
| 339 |
|
| |
| 340 |
|
| // Initializes a uri_str_t. |
| 341 |
|
| static |
| 342 |
7214 |
| void str_init(pTHX_ uri_str_t *str, size_t alloc_size) { |
| 343 |
7214 |
| str->chunk = alloc_size; |
| 344 |
7214 |
| str->allocated = 0; |
| 345 |
7214 |
| str->length = 0; |
| 346 |
7214 |
| str->string = NULL; |
| 347 |
7214 |
| } |
| 348 |
|
| |
| 349 |
|
| // Allocates and initializes a new uri_str_t. |
| 350 |
|
| static |
| 351 |
7214 |
| uri_str_t* str_new(pTHX_ size_t alloc_size) { |
| 352 |
|
| uri_str_t *str; |
| 353 |
7214 |
| Newx(str, 1, uri_str_t); |
| 354 |
7214 |
| str_init(aTHX_ str, alloc_size); |
| 355 |
7214 |
| return str; |
| 356 |
|
| } |
| 357 |
|
| |
| 358 |
|
| // Release an allocated uri_str_t and free's its contents. |
| 359 |
|
| static |
| 360 |
7212 |
| void str_free(pTHX_ uri_str_t *str) { |
| 361 |
7212 |
▶ | if (str->string != NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str->string != NULL) { |
3447 |
3765 |
7212 |
|
| 362 |
3447 |
| Safefree(str->string); |
| 363 |
|
| } |
| 364 |
|
| |
| 365 |
7212 |
| Safefree(str); |
| 366 |
7212 |
| } |
| 367 |
|
| |
| 368 |
|
| |
| 369 |
|
| /*------------------------------------------------------------------------------- |
| 370 |
|
| * Percent encoding |
| 371 |
|
| -----------------------------------------------------------------------------*/ |
| 372 |
|
| |
| 373 |
|
| // Taken with respect from URI::Escape::XS. Adapted to accept a configurable |
| 374 |
|
| // string of permissible characters. |
| 375 |
|
| #define _______ "\0\0\0\0" |
| 376 |
|
| static const char uri_encode_tbl[ sizeof(U32) * 0x100 ] = { |
| 377 |
|
| /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ |
| 378 |
|
| "%00\0" "%01\0" "%02\0" "%03\0" "%04\0" "%05\0" "%06\0" "%07\0" "%08\0" "%09\0" "%0A\0" "%0B\0" "%0C\0" "%0D\0" "%0E\0" "%0F\0" /* 0: 0 ~ 15 */ |
| 379 |
|
| "%10\0" "%11\0" "%12\0" "%13\0" "%14\0" "%15\0" "%16\0" "%17\0" "%18\0" "%19\0" "%1A\0" "%1B\0" "%1C\0" "%1D\0" "%1E\0" "%1F\0" /* 1: 16 ~ 31 */ |
| 380 |
|
| "%20\0" "%21\0" "%22\0" "%23\0" "%24\0" "%25\0" "%26\0" "%27\0" "%28\0" "%29\0" "%2A\0" "%2B\0" "%2C\0" _______ _______ "%2F\0" /* 2: 32 ~ 47 */ |
| 381 |
|
| _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ "%3A\0" "%3B\0" "%3C\0" "%3D\0" "%3E\0" "%3F\0" /* 3: 48 ~ 63 */ |
| 382 |
|
| "%40\0" _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ /* 4: 64 ~ 79 */ |
| 383 |
|
| _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ "%5B\0" "%5C\0" "%5D\0" "%5E\0" _______ /* 5: 80 ~ 95 */ |
| 384 |
|
| "%60\0" _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ /* 6: 96 ~ 111 */ |
| 385 |
|
| _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ "%7B\0" "%7C\0" "%7D\0" _______ "%7F\0" /* 7: 112 ~ 127 */ |
| 386 |
|
| "%80\0" "%81\0" "%82\0" "%83\0" "%84\0" "%85\0" "%86\0" "%87\0" "%88\0" "%89\0" "%8A\0" "%8B\0" "%8C\0" "%8D\0" "%8E\0" "%8F\0" /* 8: 128 ~ 143 */ |
| 387 |
|
| "%90\0" "%91\0" "%92\0" "%93\0" "%94\0" "%95\0" "%96\0" "%97\0" "%98\0" "%99\0" "%9A\0" "%9B\0" "%9C\0" "%9D\0" "%9E\0" "%9F\0" /* 9: 144 ~ 159 */ |
| 388 |
|
| "%A0\0" "%A1\0" "%A2\0" "%A3\0" "%A4\0" "%A5\0" "%A6\0" "%A7\0" "%A8\0" "%A9\0" "%AA\0" "%AB\0" "%AC\0" "%AD\0" "%AE\0" "%AF\0" /* A: 160 ~ 175 */ |
| 389 |
|
| "%B0\0" "%B1\0" "%B2\0" "%B3\0" "%B4\0" "%B5\0" "%B6\0" "%B7\0" "%B8\0" "%B9\0" "%BA\0" "%BB\0" "%BC\0" "%BD\0" "%BE\0" "%BF\0" /* B: 176 ~ 191 */ |
| 390 |
|
| "%C0\0" "%C1\0" "%C2\0" "%C3\0" "%C4\0" "%C5\0" "%C6\0" "%C7\0" "%C8\0" "%C9\0" "%CA\0" "%CB\0" "%CC\0" "%CD\0" "%CE\0" "%CF\0" /* C: 192 ~ 207 */ |
| 391 |
|
| "%D0\0" "%D1\0" "%D2\0" "%D3\0" "%D4\0" "%D5\0" "%D6\0" "%D7\0" "%D8\0" "%D9\0" "%DA\0" "%DB\0" "%DC\0" "%DD\0" "%DE\0" "%DF\0" /* D: 208 ~ 223 */ |
| 392 |
|
| "%E0\0" "%E1\0" "%E2\0" "%E3\0" "%E4\0" "%E5\0" "%E6\0" "%E7\0" "%E8\0" "%E9\0" "%EA\0" "%EB\0" "%EC\0" "%ED\0" "%EE\0" "%EF\0" /* E: 224 ~ 239 */ |
| 393 |
|
| "%F0\0" "%F1\0" "%F2\0" "%F3\0" "%F4\0" "%F5\0" "%F6\0" "%F7\0" "%F8\0" "%F9\0" "%FA\0" "%FB\0" "%FC\0" "%FD\0" "%FE\0" "%FF" /* F: 240 ~ 255 */ |
| 394 |
|
| }; |
| 395 |
|
| #undef _______ |
| 396 |
|
| |
| 397 |
|
| static |
| 398 |
376 |
| size_t uri_encode(const char* in, size_t len, char* out, const char* allow, int allow_utf8) { |
| 399 |
376 |
| size_t i = 0; |
| 400 |
376 |
| size_t j = 0; |
| 401 |
|
| size_t k, skip; |
| 402 |
|
| U8 octet; |
| 403 |
|
| U32 code; |
| 404 |
|
| |
| 405 |
2199 |
▶ | while (i < len) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (i < len) { |
1823 |
376 |
2199 |
|
| 406 |
1823 |
| octet = in[i]; |
| 407 |
|
| |
| 408 |
1823 |
▶ | if (allow_utf8 && octet & 0xc0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (allow_utf8 && octet & 0xc0) { |
41 |
1782 |
1823 |
| if (allow_utf8 && octet & 0xc0) { |
38 |
3 |
41 |
|
| 409 |
38 |
| skip = UTF8SKIP(&in[i]); |
| 410 |
|
| |
| 411 |
38 |
▶ | if (skip > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (skip > 0) { |
38 |
0 |
38 |
|
| 412 |
114 |
▶ | for (k = 0; k < skip; ++k) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < skip; ++k) { |
76 |
38 |
114 |
|
| 413 |
76 |
| out[j++] = in[i++]; |
| 414 |
|
| } |
| 415 |
|
| |
| 416 |
38 |
| continue; |
| 417 |
|
| } |
| 418 |
|
| } |
| 419 |
|
| |
| 420 |
1785 |
▶ | if (char_in_str(octet, allow)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (char_in_str(octet, allow)) { |
71 |
1714 |
1785 |
|
| 421 |
71 |
| out[j++] = octet; |
| 422 |
71 |
| ++i; |
| 423 |
|
| } |
| 424 |
|
| else { |
| 425 |
1714 |
| code = ((U32*) uri_encode_tbl)[(unsigned char) octet]; |
| 426 |
|
| |
| 427 |
1714 |
▶ | if (code) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (code) { |
463 |
1251 |
1714 |
|
| 428 |
463 |
| *((U32*) &out[j]) = code; |
| 429 |
463 |
| j += 3; |
| 430 |
|
| } |
| 431 |
|
| else { |
| 432 |
1251 |
| out[j++] = octet; |
| 433 |
|
| } |
| 434 |
|
| |
| 435 |
1714 |
| ++i; |
| 436 |
|
| } |
| 437 |
|
| } |
| 438 |
|
| |
| 439 |
376 |
| out[j] = '\0'; |
| 440 |
|
| |
| 441 |
376 |
| return j; |
| 442 |
|
| } |
| 443 |
|
| |
| 444 |
|
| /*------------------------------------------------------------------------------- |
| 445 |
|
| * Percent decoding |
| 446 |
|
| -----------------------------------------------------------------------------*/ |
| 447 |
|
| |
| 448 |
|
| #define __ 0xFF |
| 449 |
|
| static const unsigned char hex[0x100] = { |
| 450 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* 00-0F */ |
| 451 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* 10-1F */ |
| 452 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* 20-2F */ |
| 453 |
|
| 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,__,__,__,__,__,__, /* 30-3F */ |
| 454 |
|
| __,10,11,12,13,14,15,__,__,__,__,__,__,__,__,__, /* 40-4F */ |
| 455 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* 50-5F */ |
| 456 |
|
| __,10,11,12,13,14,15,__,__,__,__,__,__,__,__,__, /* 60-6F */ |
| 457 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* 70-7F */ |
| 458 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* 80-8F */ |
| 459 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* 90-9F */ |
| 460 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* A0-AF */ |
| 461 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* B0-BF */ |
| 462 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* C0-CF */ |
| 463 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* D0-DF */ |
| 464 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* E0-EF */ |
| 465 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* F0-FF */ |
| 466 |
|
| }; |
| 467 |
|
| #undef __ |
| 468 |
|
| |
| 469 |
|
| static inline |
| 470 |
349 |
| char unhex(const char *in) { |
| 471 |
349 |
| unsigned char v1 = hex[ (unsigned char) in[0] ]; |
| 472 |
349 |
| unsigned char v2 = hex[ (unsigned char) in[1] ]; |
| 473 |
|
| |
| 474 |
|
| /* skip invalid hex sequences */ |
| 475 |
349 |
▶ | if ((v1 | v2) != 0xFF) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v1 | v2) != 0xFF) { |
348 |
1 |
349 |
|
| 476 |
348 |
| return (v1 << 4) | v2; |
| 477 |
|
| } |
| 478 |
|
| |
| 479 |
1 |
| return '\0'; |
| 480 |
|
| } |
| 481 |
|
| |
| 482 |
|
| static |
| 483 |
610 |
| size_t uri_decode(const char *in, size_t len, char *out, const char *ignore) { |
| 484 |
610 |
| size_t i = 0, j = 0; |
| 485 |
|
| char decoded; |
| 486 |
|
| |
| 487 |
3776 |
▶ | while (i < len) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (i < len) { |
3166 |
610 |
3776 |
|
| 488 |
3166 |
| decoded = '\0'; |
| 489 |
|
| |
| 490 |
3166 |
| switch (in[i]) { |
| 491 |
6 |
| case '+': |
| 492 |
6 |
| decoded = ' '; |
| 493 |
6 |
▶ | if (!char_in_str(decoded, ignore)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!char_in_str(decoded, ignore)) { |
6 |
0 |
6 |
|
| 494 |
6 |
| ++i; |
| 495 |
6 |
| break; |
| 496 |
|
| } |
| 497 |
|
| case '%': |
| 498 |
277 |
▶ | if (i + 2 < len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (i + 2 < len) { |
276 |
1 |
277 |
|
| 499 |
276 |
| decoded = unhex( &in[i + 1] ); |
| 500 |
276 |
▶ | if (decoded != '\0' && !char_in_str(decoded, ignore)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (decoded != '\0' && !char_in_str(decoded, ignore)) { |
275 |
1 |
276 |
| if (decoded != '\0' && !char_in_str(decoded, ignore)) { |
275 |
0 |
275 |
|
| 501 |
275 |
| i += 3; |
| 502 |
275 |
| break; |
| 503 |
|
| } |
| 504 |
|
| } |
| 505 |
|
| default: |
| 506 |
2885 |
| decoded = in[i++]; |
| 507 |
|
| } |
| 508 |
|
| |
| 509 |
3166 |
▶ | if (decoded != '\0') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (decoded != '\0') { |
3166 |
0 |
3166 |
|
| 510 |
3166 |
| out[j++] = decoded; |
| 511 |
|
| } |
| 512 |
|
| } |
| 513 |
|
| |
| 514 |
610 |
| out[j] = '\0'; |
| 515 |
|
| |
| 516 |
610 |
| return j; |
| 517 |
|
| } |
| 518 |
|
| |
| 519 |
|
| static |
| 520 |
62 |
| size_t uri_decode_utf8(const char *in, size_t len, char *out) { |
| 521 |
62 |
| size_t i = 0, j = 0; |
| 522 |
|
| char decoded; |
| 523 |
|
| |
| 524 |
1071 |
▶ | while (i < len) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (i < len) { |
1009 |
62 |
1071 |
|
| 525 |
1009 |
| decoded = '\0'; |
| 526 |
|
| |
| 527 |
1009 |
▶ | switch (in[i]) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch (in[i]) { |
73 |
936 |
1009 |
|
| 528 |
73 |
| case '%': |
| 529 |
73 |
▶ | if (i + 2 < len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (i + 2 < len) { |
73 |
0 |
73 |
|
| 530 |
73 |
| decoded = unhex( &in[i + 1] ); |
| 531 |
73 |
▶ | if (decoded != '\0' && (U32)decoded > 127) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (decoded != '\0' && (U32)decoded > 127) { |
73 |
0 |
73 |
| if (decoded != '\0' && (U32)decoded > 127) { |
55 |
18 |
73 |
|
| 532 |
55 |
| i += 3; |
| 533 |
55 |
| break; |
| 534 |
|
| } |
| 535 |
|
| } |
| 536 |
|
| default: |
| 537 |
954 |
| decoded = in[i++]; |
| 538 |
|
| } |
| 539 |
|
| |
| 540 |
1009 |
▶ | if (decoded != '\0') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (decoded != '\0') { |
1009 |
0 |
1009 |
|
| 541 |
1009 |
| out[j++] = decoded; |
| 542 |
|
| } |
| 543 |
|
| } |
| 544 |
|
| |
| 545 |
62 |
| out[j] = '\0'; |
| 546 |
|
| |
| 547 |
62 |
| return j; |
| 548 |
|
| } |
| 549 |
|
| |
| 550 |
|
| // EOT (end of theft) |
| 551 |
|
| |
| 552 |
|
| /* |
| 553 |
|
| * External API for encode/decode. |
| 554 |
|
| */ |
| 555 |
|
| static |
| 556 |
45 |
| SV* encode(pTHX_ SV *in, SV *sv_allowed) { |
| 557 |
|
| size_t ilen, olen, alen; |
| 558 |
|
| const char *allowed; |
| 559 |
|
| SV* out; |
| 560 |
|
| |
| 561 |
45 |
▶ | if (!is_defined(aTHX_ in)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_defined(aTHX_ in)) { |
2 |
43 |
45 |
|
| 562 |
2 |
| return newSVpvn("", 0); |
| 563 |
|
| } |
| 564 |
|
| |
| 565 |
43 |
| const char *src = SvPV_nomg_const(in, ilen); |
| 566 |
43 |
| char dest[(ilen * 3) + 1]; |
| 567 |
|
| |
| 568 |
43 |
▶ | if (sv_allowed == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_allowed == NULL) { |
41 |
2 |
43 |
|
| 569 |
41 |
| allowed = ""; |
| 570 |
|
| } else { |
| 571 |
2 |
| allowed = SvPV_nomg_const(sv_allowed, alen); |
| 572 |
|
| } |
| 573 |
|
| |
| 574 |
43 |
| olen = uri_encode(src, ilen, dest, allowed, 0); |
| 575 |
43 |
| out = newSVpvn(dest, olen); |
| 576 |
43 |
| sv_utf8_downgrade(out, FALSE); |
| 577 |
|
| |
| 578 |
43 |
| return out; |
| 579 |
|
| } |
| 580 |
|
| |
| 581 |
|
| static |
| 582 |
18 |
| SV* decode(pTHX_ SV *in) { |
| 583 |
|
| size_t ilen, olen; |
| 584 |
|
| const char *src; |
| 585 |
|
| SV *out; |
| 586 |
|
| |
| 587 |
18 |
▶ | if (!is_defined(aTHX_ in)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_defined(aTHX_ in)) { |
2 |
16 |
18 |
|
| 588 |
2 |
| return newSVpvn("", 0); |
| 589 |
|
| } |
| 590 |
|
| |
| 591 |
16 |
▶ | if (DO_UTF8(in)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (DO_UTF8(in)) { |
0 |
16 |
16 |
| if (DO_UTF8(in)) { |
0 |
0 |
0 |
|
| 592 |
0 |
| in = sv_mortalcopy(in); |
| 593 |
0 |
| SvUTF8_on(in); |
| 594 |
|
| |
| 595 |
0 |
▶ | if (!sv_utf8_downgrade(in, TRUE)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv_utf8_downgrade(in, TRUE)) { |
0 |
0 |
0 |
|
| 596 |
0 |
| croak("decode: wide character in input octet string"); |
| 597 |
|
| } |
| 598 |
|
| |
| 599 |
0 |
| src = SvPV_nomg_const(in, ilen); |
| 600 |
|
| } |
| 601 |
|
| else { |
| 602 |
16 |
| src = SvPV_nomg_const(in, ilen); |
| 603 |
|
| } |
| 604 |
|
| |
| 605 |
16 |
| char dest[ilen + 1]; |
| 606 |
16 |
| olen = uri_decode(src, ilen, dest, ""); |
| 607 |
16 |
| out = newSVpvn(dest, olen); |
| 608 |
16 |
| sv_utf8_decode(out); |
| 609 |
|
| |
| 610 |
16 |
| return out; |
| 611 |
|
| } |
| 612 |
|
| |
| 613 |
|
| |
| 614 |
|
| /*------------------------------------------------------------------------------ |
| 615 |
|
| * Query string parsing |
| 616 |
|
| -----------------------------------------------------------------------------*/ |
| 617 |
|
| |
| 618 |
|
| typedef enum { |
| 619 |
|
| KEY = 1, |
| 620 |
|
| PARAM = 2, |
| 621 |
|
| DONE = 3, |
| 622 |
|
| } uri_query_token_type_t; |
| 623 |
|
| |
| 624 |
|
| typedef struct { |
| 625 |
|
| uri_query_token_type_t type; |
| 626 |
|
| const char *key; size_t key_length; |
| 627 |
|
| const char *value; size_t value_length; // only present when type=PARAM |
| 628 |
|
| } uri_query_token_t; |
| 629 |
|
| |
| 630 |
|
| typedef struct { |
| 631 |
|
| size_t length; |
| 632 |
|
| size_t cursor; |
| 633 |
|
| const char *source; |
| 634 |
|
| } uri_query_scanner_t; |
| 635 |
|
| |
| 636 |
|
| // Initializes a uri_query_scanner_t with input string *source of at least |
| 637 |
|
| // length characters. It is the caller's responsibility to ensure the lifetime |
| 638 |
|
| // of source matches the lifetime of the scanner. |
| 639 |
225 |
| void query_scanner_init( |
| 640 |
|
| uri_query_scanner_t *scanner, |
| 641 |
|
| const char *source, |
| 642 |
|
| size_t length |
| 643 |
|
| ) |
| 644 |
|
| { |
| 645 |
225 |
| scanner->source = source; |
| 646 |
225 |
| scanner->length = length; |
| 647 |
225 |
| scanner->cursor = 0; |
| 648 |
225 |
| } |
| 649 |
|
| |
| 650 |
|
| // Returns true if the scanner has reached the end of the input string. |
| 651 |
|
| static |
| 652 |
544 |
| int query_scanner_done(uri_query_scanner_t *scanner) { |
| 653 |
544 |
| return scanner->cursor >= scanner->length; |
| 654 |
|
| } |
| 655 |
|
| |
| 656 |
|
| /* |
| 657 |
|
| * Fills the token struct with the next token information. Does not decode |
| 658 |
|
| * any values. |
| 659 |
|
| */ |
| 660 |
|
| static |
| 661 |
319 |
| void query_scanner_next(uri_query_scanner_t *scanner, uri_query_token_t *token) { |
| 662 |
|
| size_t brk; |
| 663 |
319 |
| const char key_sep[4] = {'&', ';', '=', '\0'}; |
| 664 |
319 |
| const char val_sep[4] = {'&', ';', '\0'}; |
| 665 |
|
| |
| 666 |
324 |
| SCAN_KEY: |
| 667 |
324 |
▶ | if (scanner->cursor >= scanner->length) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (scanner->cursor >= scanner->length) { |
5 |
319 |
324 |
|
| 668 |
5 |
| token->key = NULL; token->key_length = 0; |
| 669 |
5 |
| token->value = NULL; token->value_length = 0; |
| 670 |
5 |
| token->type = DONE; |
| 671 |
5 |
| return; |
| 672 |
|
| } |
| 673 |
|
| |
| 674 |
|
| // Scan to end of token |
| 675 |
319 |
| brk = strncspn( |
| 676 |
319 |
| &scanner->source[ scanner->cursor ], |
| 677 |
319 |
| scanner->length - scanner->cursor, |
| 678 |
|
| key_sep |
| 679 |
|
| ); |
| 680 |
|
| |
| 681 |
|
| // Set key members in token struct |
| 682 |
319 |
| token->key = &scanner->source[ scanner->cursor ]; |
| 683 |
319 |
| token->key_length = brk; |
| 684 |
|
| |
| 685 |
|
| // Move cursor to end of token |
| 686 |
319 |
| scanner->cursor += brk; |
| 687 |
|
| |
| 688 |
|
| // If there is an associate value, add it to the token |
| 689 |
319 |
▶ | if (scanner->source[ scanner->cursor ] == '=') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (scanner->source[ scanner->cursor ] == '=') { |
285 |
34 |
319 |
|
| 690 |
|
| // Advance past '=' |
| 691 |
285 |
| ++scanner->cursor; |
| 692 |
|
| |
| 693 |
|
| // Find the end of the value |
| 694 |
285 |
| brk = strncspn(&scanner->source[ scanner->cursor ], scanner->length - scanner->cursor, val_sep); |
| 695 |
|
| |
| 696 |
|
| // Set the value and token type |
| 697 |
285 |
| token->value = &scanner->source[ scanner->cursor ]; |
| 698 |
285 |
| token->value_length = brk; |
| 699 |
285 |
| token->type = PARAM; |
| 700 |
|
| |
| 701 |
|
| // Move cursor to the end of the value, eating the separator terminating it |
| 702 |
285 |
| scanner->cursor += brk + 1; |
| 703 |
|
| } |
| 704 |
|
| // No value assigned to this key |
| 705 |
|
| else { |
| 706 |
34 |
| token->type = KEY; |
| 707 |
34 |
| ++scanner->cursor; // advance past terminating separator |
| 708 |
|
| } |
| 709 |
|
| |
| 710 |
|
| // No key was found; try again |
| 711 |
319 |
▶ | if (token->key_length == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (token->key_length == 0) { |
5 |
314 |
319 |
|
| 712 |
5 |
| goto SCAN_KEY; |
| 713 |
|
| } |
| 714 |
|
| |
| 715 |
314 |
| return; |
| 716 |
|
| } |
| 717 |
|
| |
| 718 |
|
| |
| 719 |
|
| /*------------------------------------------------------------------------------ |
| 720 |
|
| * URI parsing |
| 721 |
|
| -----------------------------------------------------------------------------*/ |
| 722 |
|
| |
| 723 |
|
| typedef struct { |
| 724 |
|
| U8 is_iri; |
| 725 |
|
| uri_str_t *scheme; |
| 726 |
|
| uri_str_t *query; |
| 727 |
|
| uri_str_t *path; |
| 728 |
|
| uri_str_t *host; |
| 729 |
|
| uri_str_t *port; |
| 730 |
|
| uri_str_t *frag; |
| 731 |
|
| uri_str_t *usr; |
| 732 |
|
| uri_str_t *pwd; |
| 733 |
|
| } uri_t; |
| 734 |
|
| |
| 735 |
|
| /* |
| 736 |
|
| * Scans the authorization portion of the URI string |
| 737 |
|
| */ |
| 738 |
|
| static |
| 739 |
340 |
| void uri_scan_auth(pTHX_ uri_t* uri, const char* auth, const size_t len) { |
| 740 |
340 |
| size_t idx = 0; |
| 741 |
340 |
| size_t brk1 = 0; |
| 742 |
340 |
| size_t brk2 = 0; |
| 743 |
|
| size_t i; |
| 744 |
|
| unsigned char flag; |
| 745 |
|
| |
| 746 |
340 |
▶ | if (len > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 0) { |
331 |
9 |
340 |
|
| 747 |
|
| // Credentials |
| 748 |
331 |
| brk1 = strncspn(&auth[idx], len - idx, "@"); |
| 749 |
|
| |
| 750 |
331 |
▶ | if (brk1 > 0 && brk1 != (len - idx)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (brk1 > 0 && brk1 != (len - idx)) { |
331 |
0 |
331 |
| if (brk1 > 0 && brk1 != (len - idx)) { |
27 |
304 |
331 |
|
| 751 |
27 |
| brk2 = strncspn(&auth[idx], len - idx, ":"); |
| 752 |
|
| |
| 753 |
27 |
▶ | if (brk2 > 0 && brk2 < brk1) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (brk2 > 0 && brk2 < brk1) { |
27 |
0 |
27 |
| if (brk2 > 0 && brk2 < brk1) { |
26 |
1 |
27 |
|
| 754 |
|
| // user |
| 755 |
26 |
| str_set(aTHX_ uri->usr, &auth[idx], brk2); |
| 756 |
26 |
| idx += brk2 + 1; |
| 757 |
|
| |
| 758 |
|
| // password |
| 759 |
26 |
| str_set(aTHX_ uri->pwd, &auth[idx], brk1 - brk2 - 1); |
| 760 |
26 |
| idx += brk1 - brk2; |
| 761 |
|
| } |
| 762 |
|
| else { |
| 763 |
|
| // user only |
| 764 |
1 |
| str_set(aTHX_ uri->usr, &auth[idx], brk1); |
| 765 |
1 |
| idx += brk1 + 1; |
| 766 |
|
| } |
| 767 |
|
| } |
| 768 |
|
| |
| 769 |
|
| // Location |
| 770 |
|
| |
| 771 |
|
| // Maybe an IPV6 address |
| 772 |
331 |
| flag = 0; |
| 773 |
331 |
▶ | if (auth[idx] == '[') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (auth[idx] == '[') { |
1 |
330 |
331 |
|
| 774 |
1 |
| brk1 = strncspn(&auth[idx], len - idx, "]"); |
| 775 |
|
| |
| 776 |
1 |
▶ | if (auth[idx + brk1] == ']') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (auth[idx + brk1] == ']') { |
1 |
0 |
1 |
|
| 777 |
|
| // Copy, including the square brackets |
| 778 |
1 |
| str_set(aTHX_ uri->host, &auth[idx], brk1 + 1); |
| 779 |
1 |
| idx += brk1 + 1; |
| 780 |
1 |
| flag = 1; |
| 781 |
|
| } |
| 782 |
|
| } |
| 783 |
|
| |
| 784 |
331 |
▶ | if (flag == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flag == 0) { |
330 |
1 |
331 |
|
| 785 |
330 |
| brk1 = strncspn(&auth[idx], len - idx, ":"); |
| 786 |
|
| |
| 787 |
330 |
▶ | if (brk1 > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (brk1 > 0) { |
330 |
0 |
330 |
|
| 788 |
330 |
| str_set(aTHX_ uri->host, &auth[idx], brk1); |
| 789 |
330 |
| idx += brk1; |
| 790 |
|
| } |
| 791 |
|
| } |
| 792 |
|
| |
| 793 |
331 |
▶ | if (auth[idx] == ':') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (auth[idx] == ':') { |
29 |
302 |
331 |
|
| 794 |
29 |
| ++idx; |
| 795 |
29 |
| str_set(aTHX_ uri->port, &auth[idx], len - idx); |
| 796 |
|
| } |
| 797 |
|
| } |
| 798 |
340 |
| } |
| 799 |
|
| |
| 800 |
|
| /* |
| 801 |
|
| * Scans a URI string and populates the uri_t struct. |
| 802 |
|
| * |
| 803 |
|
| * Correct: |
| 804 |
|
| * scheme:[//[usr[:pwd]@]host[:port]]path[?query][#fragment] |
| 805 |
|
| * |
| 806 |
|
| * Incorrect but supported: |
| 807 |
|
| * /path[?query][#fragment] |
| 808 |
|
| * |
| 809 |
|
| */ |
| 810 |
|
| static |
| 811 |
872 |
| void uri_scan(pTHX_ uri_t *uri, const char *src, size_t len) { |
| 812 |
872 |
| size_t idx = 0; |
| 813 |
|
| size_t brk; |
| 814 |
|
| size_t i; |
| 815 |
|
| |
| 816 |
881 |
▶ | while (my_isspace(src[idx]) == 1) ++idx; // Trim leading whitespace |
Branch: 1 branch
| Branch | True | False | Total |
| while (my_isspace(src[idx]) == 1) ++idx; // Trim leading whitespace |
9 |
872 |
881 |
|
| 817 |
881 |
▶ | while (my_isspace(src[len - 1]) == 1) --len; // Trim trailing whitespace |
Branch: 1 branch
| Branch | True | False | Total |
| while (my_isspace(src[len - 1]) == 1) --len; // Trim trailing whitespace |
9 |
872 |
881 |
|
| 818 |
|
| |
| 819 |
|
| // scheme |
| 820 |
872 |
| brk = strncspn(&src[idx], len - idx, ":/@?#"); |
| 821 |
|
| |
| 822 |
872 |
▶ | if (brk > 0 && src[idx + brk] == ':') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (brk > 0 && src[idx + brk] == ':') { |
516 |
356 |
872 |
| if (brk > 0 && src[idx + brk] == ':') { |
338 |
178 |
516 |
|
| 823 |
338 |
| str_set(aTHX_ uri->scheme, &src[idx], brk); |
| 824 |
338 |
| idx += brk; |
| 825 |
338 |
| ++idx; // skip past ":" |
| 826 |
|
| } |
| 827 |
|
| |
| 828 |
|
| // authority |
| 829 |
872 |
▶ | if (idx + 1 < len // src is long enough to hold two slashes |
Branch: 1 branch
| Branch | True | False | Total |
| if (idx + 1 < len // src is long enough to hold two slashes |
586 |
286 |
872 |
|
| 830 |
586 |
▶ | && src[idx] == '/' // next char is a slash |
Branch: 1 branch
| Branch | True | False | Total |
| && src[idx] == '/' // next char is a slash |
356 |
230 |
586 |
|
| 831 |
356 |
▶ | && src[idx + 1] == '/') // char after that is a slash |
Branch: 1 branch
| Branch | True | False | Total |
| && src[idx + 1] == '/') // char after that is a slash |
329 |
27 |
356 |
|
| 832 |
|
| { |
| 833 |
329 |
| idx += 2; // skip past the double slashes |
| 834 |
|
| |
| 835 |
329 |
| brk = strncspn(&src[idx], len - idx, "/?#"); |
| 836 |
329 |
| uri_scan_auth(aTHX_ uri, &src[idx], brk); |
| 837 |
|
| |
| 838 |
329 |
▶ | if (brk > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (brk > 0) { |
321 |
8 |
329 |
|
| 839 |
321 |
| idx += brk; |
| 840 |
|
| } |
| 841 |
|
| } |
| 842 |
|
| |
| 843 |
|
| // path |
| 844 |
872 |
| brk = strncspn(&src[idx], len - idx, "?#"); |
| 845 |
872 |
▶ | if (brk > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (brk > 0) { |
479 |
393 |
872 |
|
| 846 |
479 |
| str_set(aTHX_ uri->path, &src[idx], brk); |
| 847 |
479 |
| idx += brk; |
| 848 |
|
| } |
| 849 |
|
| |
| 850 |
|
| // query |
| 851 |
872 |
▶ | if (src[idx] == '?') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (src[idx] == '?') { |
313 |
559 |
872 |
|
| 852 |
313 |
| ++idx; // skip past ? |
| 853 |
313 |
| brk = strncspn(&src[idx], len - idx, "#"); |
| 854 |
313 |
▶ | if (brk > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (brk > 0) { |
311 |
2 |
313 |
|
| 855 |
311 |
| str_set(aTHX_ uri->query, &src[idx], brk); |
| 856 |
311 |
| idx += brk; |
| 857 |
|
| } |
| 858 |
|
| } |
| 859 |
|
| |
| 860 |
|
| // fragment |
| 861 |
872 |
▶ | if (src[idx] == '#') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (src[idx] == '#') { |
69 |
803 |
872 |
|
| 862 |
69 |
| ++idx; // skip past # |
| 863 |
69 |
| brk = len - idx; |
| 864 |
69 |
▶ | if (brk > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (brk > 0) { |
66 |
3 |
69 |
|
| 865 |
66 |
| str_set(aTHX_ uri->frag, &src[idx], brk); |
| 866 |
|
| } |
| 867 |
|
| } |
| 868 |
872 |
| } |
| 869 |
|
| |
| 870 |
|
| /* |
| 871 |
|
| * Helper function that returns true if any part of the authority section is |
| 872 |
|
| * set. |
| 873 |
|
| */ |
| 874 |
|
| static inline |
| 875 |
10 |
| int has_authority(pTHX_ uri_t *uri) { |
| 876 |
10 |
| return uri->host->length > 0 |
| 877 |
4 |
▶ | || uri->usr->length > 0 |
Branch: 1 branch
| Branch | True | False | Total |
| || uri->usr->length > 0 |
4 |
0 |
4 |
|
| 878 |
4 |
▶ | || uri->pwd->length > 0 |
Branch: 1 branch
| Branch | True | False | Total |
| || uri->pwd->length > 0 |
4 |
0 |
4 |
|
| 879 |
14 |
▶ | || uri->port->length > 0; |
Branch: 2 branches
| Branch | True | False | Total |
| || uri->port->length > 0; |
4 |
6 |
10 |
| || uri->port->length > 0; |
0 |
4 |
4 |
|
| 880 |
|
| } |
| 881 |
|
| |
| 882 |
|
| /*------------------------------------------------------------------------------ |
| 883 |
|
| * |
| 884 |
|
| * Perl API |
| 885 |
|
| * |
| 886 |
|
| -----------------------------------------------------------------------------*/ |
| 887 |
|
| |
| 888 |
|
| /*------------------------------------------------------------------------------ |
| 889 |
|
| * Clearers |
| 890 |
|
| -----------------------------------------------------------------------------*/ |
| 891 |
|
| |
| 892 |
8 |
▶ | URI_SIMPLE_CLEARER(scheme); |
Branch: 2 branches
| Branch | True | False | Total |
| URI_SIMPLE_CLEARER(scheme); |
8 |
0 |
8 |
| URI_SIMPLE_CLEARER(scheme); |
0 |
8 |
8 |
|
| 893 |
1 |
▶ | URI_SIMPLE_CLEARER(path); |
Branch: 2 branches
| Branch | True | False | Total |
| URI_SIMPLE_CLEARER(path); |
1 |
0 |
1 |
| URI_SIMPLE_CLEARER(path); |
0 |
1 |
1 |
|
| 894 |
5 |
▶ | URI_SIMPLE_CLEARER(query); |
Branch: 2 branches
| Branch | True | False | Total |
| URI_SIMPLE_CLEARER(query); |
5 |
0 |
5 |
| URI_SIMPLE_CLEARER(query); |
0 |
5 |
5 |
|
| 895 |
1 |
▶ | URI_SIMPLE_CLEARER(frag); |
Branch: 2 branches
| Branch | True | False | Total |
| URI_SIMPLE_CLEARER(frag); |
1 |
0 |
1 |
| URI_SIMPLE_CLEARER(frag); |
0 |
1 |
1 |
|
| 896 |
9 |
▶ | URI_SIMPLE_CLEARER(usr); |
Branch: 2 branches
| Branch | True | False | Total |
| URI_SIMPLE_CLEARER(usr); |
9 |
0 |
9 |
| URI_SIMPLE_CLEARER(usr); |
0 |
9 |
9 |
|
| 897 |
9 |
▶ | URI_SIMPLE_CLEARER(pwd); |
Branch: 2 branches
| Branch | True | False | Total |
| URI_SIMPLE_CLEARER(pwd); |
9 |
0 |
9 |
| URI_SIMPLE_CLEARER(pwd); |
0 |
9 |
9 |
|
| 898 |
9 |
▶ | URI_SIMPLE_CLEARER(host); |
Branch: 2 branches
| Branch | True | False | Total |
| URI_SIMPLE_CLEARER(host); |
9 |
0 |
9 |
| URI_SIMPLE_CLEARER(host); |
0 |
9 |
9 |
|
| 899 |
9 |
▶ | URI_SIMPLE_CLEARER(port); |
Branch: 2 branches
| Branch | True | False | Total |
| URI_SIMPLE_CLEARER(port); |
9 |
0 |
9 |
| URI_SIMPLE_CLEARER(port); |
0 |
9 |
9 |
|
| 900 |
|
| |
| 901 |
|
| static |
| 902 |
8 |
| void clear_auth(pTHX_ SV *uri_obj) { |
| 903 |
8 |
| clear_usr(aTHX_ uri_obj); |
| 904 |
8 |
| clear_pwd(aTHX_ uri_obj); |
| 905 |
8 |
| clear_host(aTHX_ uri_obj); |
| 906 |
8 |
| clear_port(aTHX_ uri_obj); |
| 907 |
8 |
| } |
| 908 |
|
| |
| 909 |
|
| /*------------------------------------------------------------------------------ |
| 910 |
|
| * Raw getters |
| 911 |
|
| -----------------------------------------------------------------------------*/ |
| 912 |
|
| |
| 913 |
|
| // Raw getters |
| 914 |
0 |
▶ | URI_RAW_GETTER(scheme); |
Branch: 5 branches
| Branch | True | False | Total |
| URI_RAW_GETTER(scheme); |
0 |
0 |
0 |
| URI_RAW_GETTER(scheme); |
0 |
0 |
0 |
| URI_RAW_GETTER(scheme); |
0 |
0 |
0 |
| URI_RAW_GETTER(scheme); |
0 |
0 |
0 |
| URI_RAW_GETTER(scheme); |
0 |
0 |
0 |
|
| 915 |
1 |
▶ | URI_RAW_GETTER(usr); |
Branch: 5 branches
| Branch | True | False | Total |
| URI_RAW_GETTER(usr); |
1 |
0 |
1 |
| URI_RAW_GETTER(usr); |
0 |
1 |
1 |
| URI_RAW_GETTER(usr); |
0 |
1 |
1 |
| URI_RAW_GETTER(usr); |
0 |
0 |
0 |
| URI_RAW_GETTER(usr); |
1 |
0 |
1 |
|
| 916 |
1 |
▶ | URI_RAW_GETTER(pwd); |
Branch: 5 branches
| Branch | True | False | Total |
| URI_RAW_GETTER(pwd); |
1 |
0 |
1 |
| URI_RAW_GETTER(pwd); |
0 |
1 |
1 |
| URI_RAW_GETTER(pwd); |
0 |
1 |
1 |
| URI_RAW_GETTER(pwd); |
0 |
0 |
0 |
| URI_RAW_GETTER(pwd); |
1 |
0 |
1 |
|
| 917 |
1 |
▶ | URI_RAW_GETTER(host); |
Branch: 5 branches
| Branch | True | False | Total |
| URI_RAW_GETTER(host); |
1 |
0 |
1 |
| URI_RAW_GETTER(host); |
0 |
1 |
1 |
| URI_RAW_GETTER(host); |
0 |
1 |
1 |
| URI_RAW_GETTER(host); |
0 |
0 |
0 |
| URI_RAW_GETTER(host); |
1 |
0 |
1 |
|
| 918 |
0 |
▶ | URI_RAW_GETTER(port); |
Branch: 5 branches
| Branch | True | False | Total |
| URI_RAW_GETTER(port); |
0 |
0 |
0 |
| URI_RAW_GETTER(port); |
0 |
0 |
0 |
| URI_RAW_GETTER(port); |
0 |
0 |
0 |
| URI_RAW_GETTER(port); |
0 |
0 |
0 |
| URI_RAW_GETTER(port); |
0 |
0 |
0 |
|
| 919 |
2 |
▶ | URI_RAW_GETTER(path); |
Branch: 5 branches
| Branch | True | False | Total |
| URI_RAW_GETTER(path); |
2 |
0 |
2 |
| URI_RAW_GETTER(path); |
0 |
2 |
2 |
| URI_RAW_GETTER(path); |
0 |
2 |
2 |
| URI_RAW_GETTER(path); |
0 |
0 |
0 |
| URI_RAW_GETTER(path); |
2 |
0 |
2 |
|
| 920 |
2 |
▶ | URI_RAW_GETTER(query); |
Branch: 5 branches
| Branch | True | False | Total |
| URI_RAW_GETTER(query); |
2 |
0 |
2 |
| URI_RAW_GETTER(query); |
0 |
2 |
2 |
| URI_RAW_GETTER(query); |
0 |
2 |
2 |
| URI_RAW_GETTER(query); |
0 |
0 |
0 |
| URI_RAW_GETTER(query); |
2 |
0 |
2 |
|
| 921 |
0 |
▶ | URI_RAW_GETTER(frag); |
Branch: 5 branches
| Branch | True | False | Total |
| URI_RAW_GETTER(frag); |
0 |
0 |
0 |
| URI_RAW_GETTER(frag); |
0 |
0 |
0 |
| URI_RAW_GETTER(frag); |
0 |
0 |
0 |
| URI_RAW_GETTER(frag); |
0 |
0 |
0 |
| URI_RAW_GETTER(frag); |
0 |
0 |
0 |
|
| 922 |
|
| |
| 923 |
|
| static |
| 924 |
246 |
| SV* get_raw_auth(pTHX_ SV *uri_obj) { |
| 925 |
246 |
▶ | uri_t *uri = URI(uri_obj); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(uri_obj); |
246 |
0 |
246 |
| uri_t *uri = URI(uri_obj); |
0 |
246 |
246 |
|
| 926 |
246 |
| SV *out = newSVpvn("", 0); |
| 927 |
|
| |
| 928 |
246 |
▶ | if (uri->is_iri) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (uri->is_iri) { |
4 |
242 |
246 |
|
| 929 |
4 |
| SvUTF8_on(out); |
| 930 |
|
| } |
| 931 |
|
| |
| 932 |
246 |
▶ | if (str_len(uri->usr) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str_len(uri->usr) > 0) { |
40 |
206 |
246 |
|
| 933 |
40 |
▶ | if (str_len(uri->pwd) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str_len(uri->pwd) > 0) { |
39 |
1 |
40 |
|
| 934 |
39 |
▶ | sv_catpvn(out, str_get(uri->usr), str_len(uri->usr)); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_catpvn(out, str_get(uri->usr), str_len(uri->usr)); |
39 |
0 |
39 |
|
| 935 |
39 |
| sv_catpvn(out, ":", 1); |
| 936 |
39 |
▶ | sv_catpvn(out, str_get(uri->pwd), str_len(uri->pwd)); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_catpvn(out, str_get(uri->pwd), str_len(uri->pwd)); |
39 |
0 |
39 |
|
| 937 |
39 |
| sv_catpvn(out, "@", 1); |
| 938 |
|
| } else { |
| 939 |
1 |
▶ | sv_catpvn(out, str_get(uri->usr), str_len(uri->usr)); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_catpvn(out, str_get(uri->usr), str_len(uri->usr)); |
1 |
0 |
1 |
|
| 940 |
1 |
| sv_catpvn(out, "@", 1); |
| 941 |
|
| } |
| 942 |
|
| } |
| 943 |
|
| |
| 944 |
246 |
▶ | if (str_len(uri->host) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str_len(uri->host) > 0) { |
221 |
25 |
246 |
|
| 945 |
221 |
▶ | if (str_len(uri->port) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str_len(uri->port) > 0) { |
38 |
183 |
221 |
|
| 946 |
38 |
▶ | sv_catpvn(out, str_get(uri->host), str_len(uri->host)); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_catpvn(out, str_get(uri->host), str_len(uri->host)); |
38 |
0 |
38 |
|
| 947 |
38 |
| sv_catpvn(out, ":", 1); |
| 948 |
38 |
▶ | sv_catpvn(out, str_get(uri->port), str_len(uri->port)); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_catpvn(out, str_get(uri->port), str_len(uri->port)); |
38 |
0 |
38 |
|
| 949 |
|
| } else { |
| 950 |
183 |
▶ | sv_catpvn(out, str_get(uri->host), str_len(uri->host)); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_catpvn(out, str_get(uri->host), str_len(uri->host)); |
183 |
0 |
183 |
|
| 951 |
|
| } |
| 952 |
|
| } |
| 953 |
|
| |
| 954 |
246 |
| return out; |
| 955 |
|
| } |
| 956 |
|
| |
| 957 |
|
| /*------------------------------------------------------------------------------ |
| 958 |
|
| * Decoding getters |
| 959 |
|
| -----------------------------------------------------------------------------*/ |
| 960 |
|
| |
| 961 |
138 |
▶ | URI_SIMPLE_GETTER(scheme); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_SIMPLE_GETTER(scheme); |
138 |
0 |
138 |
| URI_SIMPLE_GETTER(scheme); |
0 |
138 |
138 |
| URI_SIMPLE_GETTER(scheme); |
79 |
59 |
138 |
|
| 962 |
123 |
▶ | URI_SIMPLE_GETTER(usr); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_SIMPLE_GETTER(usr); |
123 |
0 |
123 |
| URI_SIMPLE_GETTER(usr); |
0 |
123 |
123 |
| URI_SIMPLE_GETTER(usr); |
94 |
29 |
123 |
|
| 963 |
121 |
▶ | URI_SIMPLE_GETTER(pwd); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_SIMPLE_GETTER(pwd); |
121 |
0 |
121 |
| URI_SIMPLE_GETTER(pwd); |
0 |
121 |
121 |
| URI_SIMPLE_GETTER(pwd); |
94 |
27 |
121 |
|
| 964 |
134 |
▶ | URI_SIMPLE_GETTER(host); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_SIMPLE_GETTER(host); |
134 |
0 |
134 |
| URI_SIMPLE_GETTER(host); |
0 |
134 |
134 |
| URI_SIMPLE_GETTER(host); |
76 |
58 |
134 |
|
| 965 |
120 |
▶ | URI_SIMPLE_GETTER(port); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_SIMPLE_GETTER(port); |
120 |
0 |
120 |
| URI_SIMPLE_GETTER(port); |
0 |
120 |
120 |
| URI_SIMPLE_GETTER(port); |
93 |
27 |
120 |
|
| 966 |
112 |
▶ | URI_SIMPLE_GETTER(frag); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_SIMPLE_GETTER(frag); |
112 |
0 |
112 |
| URI_SIMPLE_GETTER(frag); |
0 |
112 |
112 |
| URI_SIMPLE_GETTER(frag); |
78 |
34 |
112 |
|
| 967 |
|
| |
| 968 |
22 |
▶ | URI_COMPOUND_GETTER(path); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_COMPOUND_GETTER(path); |
22 |
0 |
22 |
| URI_COMPOUND_GETTER(path); |
0 |
22 |
22 |
| URI_COMPOUND_GETTER(path); |
3 |
19 |
22 |
|
| 969 |
48 |
▶ | URI_COMPOUND_GETTER(query); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_COMPOUND_GETTER(query); |
48 |
0 |
48 |
| URI_COMPOUND_GETTER(query); |
0 |
48 |
48 |
| URI_COMPOUND_GETTER(query); |
5 |
43 |
48 |
|
| 970 |
|
| |
| 971 |
|
| static |
| 972 |
20 |
| SV* get_auth(pTHX_ SV *uri_obj) { |
| 973 |
20 |
▶ | uri_t *uri = URI(uri_obj); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(uri_obj); |
20 |
0 |
20 |
| uri_t *uri = URI(uri_obj); |
0 |
20 |
20 |
|
| 974 |
20 |
| SV *out = newSVpvn("", 0); |
| 975 |
|
| |
| 976 |
20 |
▶ | if (uri->is_iri) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (uri->is_iri) { |
0 |
20 |
20 |
|
| 977 |
0 |
| SvUTF8_on(out); |
| 978 |
|
| } |
| 979 |
|
| |
| 980 |
20 |
▶ | if (str_len(uri->usr) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str_len(uri->usr) > 0) { |
13 |
7 |
20 |
|
| 981 |
13 |
▶ | if (str_len(uri->pwd) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str_len(uri->pwd) > 0) { |
12 |
1 |
13 |
|
| 982 |
12 |
| sv_catsv(out, sv_2mortal(get_usr(aTHX_ uri_obj))); |
| 983 |
12 |
| sv_catpvn(out, ":", 1); |
| 984 |
12 |
| sv_catsv(out, sv_2mortal(get_pwd(aTHX_ uri_obj))); |
| 985 |
12 |
| sv_catpvn(out, "@", 1); |
| 986 |
|
| } else { |
| 987 |
1 |
| sv_catsv(out, sv_2mortal(get_usr(aTHX_ uri_obj))); |
| 988 |
1 |
| sv_catpvn(out, "@", 1); |
| 989 |
|
| } |
| 990 |
|
| } |
| 991 |
|
| |
| 992 |
20 |
▶ | if (str_len(uri->host) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str_len(uri->host) > 0) { |
18 |
2 |
20 |
|
| 993 |
18 |
▶ | if (str_len(uri->port) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str_len(uri->port) > 0) { |
12 |
6 |
18 |
|
| 994 |
12 |
| sv_catsv(out, sv_2mortal(get_host(aTHX_ uri_obj))); |
| 995 |
12 |
| sv_catpvn(out, ":", 1); |
| 996 |
12 |
| sv_catsv(out, sv_2mortal(get_port(aTHX_ uri_obj))); |
| 997 |
|
| } else { |
| 998 |
6 |
| sv_catsv(out, sv_2mortal(get_host(aTHX_ uri_obj))); |
| 999 |
|
| } |
| 1000 |
|
| } |
| 1001 |
|
| |
| 1002 |
20 |
| return out; |
| 1003 |
|
| } |
| 1004 |
|
| |
| 1005 |
|
| static |
| 1006 |
103 |
| SV* split_path(pTHX_ SV* sv_uri, int include_leading) { |
| 1007 |
103 |
▶ | uri_t *uri = URI(sv_uri); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(sv_uri); |
103 |
0 |
103 |
| uri_t *uri = URI(sv_uri); |
0 |
103 |
103 |
|
| 1008 |
103 |
| size_t len, segment_len, brk, idx = 0; |
| 1009 |
103 |
| AV* arr = newAV(); |
| 1010 |
|
| SV* tmp; |
| 1011 |
|
| |
| 1012 |
103 |
| const char *str = uri->path->string; |
| 1013 |
103 |
| len = uri->path->length; |
| 1014 |
|
| |
| 1015 |
103 |
▶ | if (len > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 0) { |
75 |
28 |
103 |
|
| 1016 |
75 |
▶ | if (str[0] == '/') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str[0] == '/') { |
45 |
30 |
75 |
|
| 1017 |
45 |
▶ | if (include_leading) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (include_leading) { |
1 |
44 |
45 |
|
| 1018 |
1 |
| tmp = newSVpvn("", 0); |
| 1019 |
1 |
| av_push(arr, tmp); |
| 1020 |
|
| } |
| 1021 |
|
| |
| 1022 |
45 |
| ++idx; // skip past leading / |
| 1023 |
|
| } |
| 1024 |
|
| |
| 1025 |
183 |
▶ | while (idx < len) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (idx < len) { |
108 |
75 |
183 |
|
| 1026 |
|
| // Find the next separator |
| 1027 |
108 |
| brk = strcspn(&str[idx], "/"); |
| 1028 |
|
| |
| 1029 |
|
| // Decode the segment |
| 1030 |
108 |
| char segment[brk + 1]; |
| 1031 |
108 |
| segment_len = uri_decode(&str[idx], brk, segment, ""); |
| 1032 |
|
| |
| 1033 |
|
| // Push new SV to AV |
| 1034 |
108 |
| tmp = newSVpvn(segment, segment_len); |
| 1035 |
108 |
| sv_utf8_decode(tmp); |
| 1036 |
108 |
| av_push(arr, tmp); |
| 1037 |
|
| |
| 1038 |
108 |
| idx += brk + 1; |
| 1039 |
|
| } |
| 1040 |
|
| } |
| 1041 |
|
| |
| 1042 |
103 |
| return newRV_noinc((SV*) arr); |
| 1043 |
|
| } |
| 1044 |
|
| |
| 1045 |
|
| static |
| 1046 |
13 |
| SV* get_query_keys(pTHX_ SV* sv_uri) { |
| 1047 |
13 |
▶ | uri_str_t *str_query = URI(sv_uri)->query; |
Branch: 2 branches
| Branch | True | False | Total |
| uri_str_t *str_query = URI(sv_uri)->query; |
13 |
0 |
13 |
| uri_str_t *str_query = URI(sv_uri)->query; |
0 |
13 |
13 |
|
| 1048 |
13 |
| const char *query = str_query->string; |
| 1049 |
13 |
| size_t klen, qlen = str_query->length; |
| 1050 |
13 |
| HV* out = newHV(); |
| 1051 |
|
| uri_query_scanner_t scanner; |
| 1052 |
|
| uri_query_token_t token; |
| 1053 |
|
| |
| 1054 |
13 |
| query_scanner_init(&scanner, query, qlen); |
| 1055 |
|
| |
| 1056 |
41 |
▶ | while (!query_scanner_done(&scanner)) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (!query_scanner_done(&scanner)) { |
28 |
13 |
41 |
|
| 1057 |
28 |
| query_scanner_next(&scanner, &token); |
| 1058 |
28 |
▶ | if (token.type == DONE) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (token.type == DONE) continue; |
0 |
28 |
28 |
|
| 1059 |
28 |
| char key[token.key_length + 1]; |
| 1060 |
28 |
| klen = uri_decode(token.key, token.key_length, key, ""); |
| 1061 |
28 |
| hv_store(out, key, -klen, &PL_sv_undef, 0); |
| 1062 |
|
| } |
| 1063 |
|
| |
| 1064 |
13 |
| return newRV_noinc((SV*) out); |
| 1065 |
|
| } |
| 1066 |
|
| |
| 1067 |
|
| static |
| 1068 |
66 |
| SV* query_hash(pTHX_ SV *sv_uri) { |
| 1069 |
66 |
▶ | uri_t *uri = URI(sv_uri); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(sv_uri); |
66 |
0 |
66 |
| uri_t *uri = URI(sv_uri); |
0 |
66 |
66 |
|
| 1070 |
|
| SV *tmp, **refval; |
| 1071 |
|
| AV *arr; |
| 1072 |
66 |
| HV *out = newHV(); |
| 1073 |
|
| size_t klen, vlen; |
| 1074 |
|
| |
| 1075 |
|
| uri_query_scanner_t scanner; |
| 1076 |
|
| uri_query_token_t token; |
| 1077 |
|
| |
| 1078 |
66 |
| query_scanner_init(&scanner, uri->query->string, uri->query->length); |
| 1079 |
|
| |
| 1080 |
145 |
▶ | while (!query_scanner_done(&scanner)) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (!query_scanner_done(&scanner)) { |
79 |
66 |
145 |
|
| 1081 |
79 |
| query_scanner_next(&scanner, &token); |
| 1082 |
79 |
▶ | if (token.type == DONE) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (token.type == DONE) continue; |
2 |
77 |
79 |
|
| 1083 |
|
| |
| 1084 |
|
| // Get decoded key |
| 1085 |
77 |
| char key[token.key_length + 1]; |
| 1086 |
77 |
| klen = uri_decode(token.key, token.key_length, key, ""); |
| 1087 |
|
| |
| 1088 |
|
| // Values are stored in an array; this block is the rough equivalent of: |
| 1089 |
|
| // $out{$key} = [] unless exists $out{$key}; |
| 1090 |
77 |
▶ | if (!hv_exists(out, key, klen)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_exists(out, key, klen)) { |
65 |
12 |
77 |
|
| 1091 |
65 |
| arr = newAV(); |
| 1092 |
65 |
| hv_store(out, key, -klen, newRV_noinc((SV*) arr), 0); |
| 1093 |
|
| } |
| 1094 |
|
| else { |
| 1095 |
12 |
| refval = hv_fetch(out, key, -klen, 0); |
| 1096 |
12 |
▶ | if (refval == NULL) croak("query_hash: something went wrong"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (refval == NULL) croak("query_hash: something went wrong"); |
0 |
12 |
12 |
|
| 1097 |
12 |
| arr = (AV*) SvRV(*refval); |
| 1098 |
|
| } |
| 1099 |
|
| |
| 1100 |
|
| // Get decoded value if there is one |
| 1101 |
77 |
▶ | if (token.type == PARAM) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (token.type == PARAM) { |
69 |
8 |
77 |
|
| 1102 |
69 |
| char val[token.value_length + 1]; |
| 1103 |
69 |
| vlen = uri_decode(token.value, token.value_length, val, ""); |
| 1104 |
69 |
| tmp = newSVpvn(val, vlen); |
| 1105 |
69 |
| sv_utf8_decode(tmp); |
| 1106 |
69 |
| av_push(arr, tmp); |
| 1107 |
|
| } |
| 1108 |
|
| } |
| 1109 |
|
| |
| 1110 |
66 |
| return newRV_noinc((SV*) out); |
| 1111 |
|
| } |
| 1112 |
|
| |
| 1113 |
|
| static |
| 1114 |
72 |
| SV* get_param(pTHX_ SV* sv_uri, SV* sv_key) { |
| 1115 |
72 |
▶ | uri_t *uri = URI(sv_uri); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(sv_uri); |
72 |
0 |
72 |
| uri_t *uri = URI(sv_uri); |
0 |
72 |
72 |
|
| 1116 |
|
| size_t klen, vlen, elen; |
| 1117 |
|
| const char *key; |
| 1118 |
|
| uri_query_scanner_t scanner; |
| 1119 |
|
| uri_query_token_t token; |
| 1120 |
72 |
| AV* out = newAV(); |
| 1121 |
|
| SV* value; |
| 1122 |
|
| |
| 1123 |
|
| // Read key to search |
| 1124 |
72 |
▶ | if (!is_defined(aTHX_ sv_key)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_defined(aTHX_ sv_key)) { |
1 |
71 |
72 |
|
| 1125 |
1 |
| croak("get_param: expected key to search"); |
| 1126 |
|
| } |
| 1127 |
|
| else { |
| 1128 |
|
| // Copy input string *before* calling DO_UTF8() in case the SV is an object |
| 1129 |
|
| // with string overloading, which may trigger the utf8 flag. |
| 1130 |
71 |
| key = SvPV_const(sv_key, klen); |
| 1131 |
|
| |
| 1132 |
71 |
▶ | if (!DO_UTF8(sv_key)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!DO_UTF8(sv_key)) { |
5 |
66 |
71 |
| if (!DO_UTF8(sv_key)) { |
0 |
5 |
5 |
|
| 1133 |
66 |
| sv_key = sv_2mortal(newSVpvn(key, klen)); |
| 1134 |
66 |
| sv_utf8_encode(sv_key); |
| 1135 |
66 |
| key = SvPV_const(sv_key, klen); |
| 1136 |
|
| } |
| 1137 |
|
| } |
| 1138 |
|
| |
| 1139 |
71 |
| char enc_key[(klen * 3) + 2]; |
| 1140 |
71 |
| elen = uri_encode(key, klen, enc_key, ":@?/", uri->is_iri); |
| 1141 |
|
| |
| 1142 |
71 |
| query_scanner_init(&scanner, uri->query->string, uri->query->length); |
| 1143 |
|
| |
| 1144 |
195 |
▶ | while (!query_scanner_done(&scanner)) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (!query_scanner_done(&scanner)) { |
124 |
71 |
195 |
|
| 1145 |
124 |
| query_scanner_next(&scanner, &token); |
| 1146 |
124 |
▶ | if (token.type == DONE) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (token.type == DONE) continue; |
3 |
121 |
124 |
|
| 1147 |
|
| |
| 1148 |
121 |
▶ | if (strncmp(enc_key, token.key, maxnum(elen, token.key_length)) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strncmp(enc_key, token.key, maxnum(elen, token.key_length)) == 0) { |
71 |
50 |
121 |
|
| 1149 |
71 |
▶ | if (token.type == PARAM) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (token.type == PARAM) { |
69 |
2 |
71 |
|
| 1150 |
69 |
| char val[token.value_length + 1]; |
| 1151 |
69 |
| vlen = uri_decode(token.value, token.value_length, val, ""); |
| 1152 |
69 |
| value = newSVpvn(val, vlen); |
| 1153 |
69 |
| sv_utf8_decode(value); |
| 1154 |
69 |
| av_push(out, value); |
| 1155 |
|
| } |
| 1156 |
|
| else { |
| 1157 |
2 |
| av_push(out, newSV(0)); |
| 1158 |
|
| } |
| 1159 |
|
| } |
| 1160 |
|
| } |
| 1161 |
|
| |
| 1162 |
71 |
| return newRV_noinc((SV*) out); |
| 1163 |
|
| } |
| 1164 |
|
| |
| 1165 |
|
| /*------------------------------------------------------------------------------ |
| 1166 |
|
| * Raw setters |
| 1167 |
|
| -----------------------------------------------------------------------------*/ |
| 1168 |
|
| |
| 1169 |
0 |
▶ | URI_RAW_SETTER(scheme); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_RAW_SETTER(scheme); |
0 |
0 |
0 |
| URI_RAW_SETTER(scheme); |
0 |
0 |
0 |
| URI_RAW_SETTER(scheme); |
0 |
0 |
0 |
|
| 1170 |
0 |
▶ | URI_RAW_SETTER(path); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_RAW_SETTER(path); |
0 |
0 |
0 |
| URI_RAW_SETTER(path); |
0 |
0 |
0 |
| URI_RAW_SETTER(path); |
0 |
0 |
0 |
|
| 1171 |
0 |
▶ | URI_RAW_SETTER(query); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_RAW_SETTER(query); |
0 |
0 |
0 |
| URI_RAW_SETTER(query); |
0 |
0 |
0 |
| URI_RAW_SETTER(query); |
0 |
0 |
0 |
|
| 1172 |
0 |
▶ | URI_RAW_SETTER(frag); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_RAW_SETTER(frag); |
0 |
0 |
0 |
| URI_RAW_SETTER(frag); |
0 |
0 |
0 |
| URI_RAW_SETTER(frag); |
0 |
0 |
0 |
|
| 1173 |
0 |
▶ | URI_RAW_SETTER(usr); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_RAW_SETTER(usr); |
0 |
0 |
0 |
| URI_RAW_SETTER(usr); |
0 |
0 |
0 |
| URI_RAW_SETTER(usr); |
0 |
0 |
0 |
|
| 1174 |
0 |
▶ | URI_RAW_SETTER(pwd); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_RAW_SETTER(pwd); |
0 |
0 |
0 |
| URI_RAW_SETTER(pwd); |
0 |
0 |
0 |
| URI_RAW_SETTER(pwd); |
0 |
0 |
0 |
|
| 1175 |
0 |
▶ | URI_RAW_SETTER(host); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_RAW_SETTER(host); |
0 |
0 |
0 |
| URI_RAW_SETTER(host); |
0 |
0 |
0 |
| URI_RAW_SETTER(host); |
0 |
0 |
0 |
|
| 1176 |
0 |
▶ | URI_RAW_SETTER(port); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_RAW_SETTER(port); |
0 |
0 |
0 |
| URI_RAW_SETTER(port); |
0 |
0 |
0 |
| URI_RAW_SETTER(port); |
0 |
0 |
0 |
|
| 1177 |
|
| |
| 1178 |
|
| static |
| 1179 |
0 |
| void set_raw_auth(pTHX_ SV *sv_uri, SV *sv_value) { |
| 1180 |
0 |
▶ | uri_t *uri = URI(sv_uri); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(sv_uri); |
0 |
0 |
0 |
| uri_t *uri = URI(sv_uri); |
0 |
0 |
0 |
|
| 1181 |
|
| |
| 1182 |
0 |
| str_clear(aTHX_ uri->usr); |
| 1183 |
0 |
| str_clear(aTHX_ uri->pwd); |
| 1184 |
0 |
| str_clear(aTHX_ uri->host); |
| 1185 |
0 |
| str_clear(aTHX_ uri->port); |
| 1186 |
|
| |
| 1187 |
0 |
▶ | if (is_defined(aTHX_ sv_value)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_defined(aTHX_ sv_value)) { |
0 |
0 |
0 |
|
| 1188 |
|
| size_t vlen; |
| 1189 |
0 |
| const char *value = SvPV_const(sv_value, vlen); |
| 1190 |
|
| |
| 1191 |
0 |
▶ | if (vlen > URI_SIZE_auth) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (vlen > URI_SIZE_auth) { |
0 |
0 |
0 |
|
| 1192 |
0 |
| croak("set_auth: size of auth string exceeds max of %lu", URI_SIZE_auth); |
| 1193 |
|
| } |
| 1194 |
|
| |
| 1195 |
|
| // auth isn't stored as an individual field, so just rescan from the new |
| 1196 |
|
| // source string. |
| 1197 |
0 |
| uri_scan_auth(aTHX_ uri, value, vlen); |
| 1198 |
|
| } |
| 1199 |
0 |
| } |
| 1200 |
|
| |
| 1201 |
|
| /*------------------------------------------------------------------------------ |
| 1202 |
|
| * Setters |
| 1203 |
|
| -----------------------------------------------------------------------------*/ |
| 1204 |
|
| |
| 1205 |
17 |
▶ | URI_SIMPLE_SETTER(scheme, ""); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_SIMPLE_SETTER(scheme, ""); |
9 |
0 |
9 |
| URI_SIMPLE_SETTER(scheme, ""); |
0 |
9 |
9 |
| URI_SIMPLE_SETTER(scheme, ""); |
8 |
1 |
9 |
|
| 1206 |
45 |
▶ | URI_SIMPLE_SETTER(path, URI_CHARS_PATH); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_SIMPLE_SETTER(path, URI_CHARS_PATH); |
23 |
0 |
23 |
| URI_SIMPLE_SETTER(path, URI_CHARS_PATH); |
0 |
23 |
23 |
| URI_SIMPLE_SETTER(path, URI_CHARS_PATH); |
22 |
1 |
23 |
|
| 1207 |
17 |
▶ | URI_SIMPLE_SETTER(query, URI_CHARS_QUERY); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_SIMPLE_SETTER(query, URI_CHARS_QUERY); |
9 |
0 |
9 |
| URI_SIMPLE_SETTER(query, URI_CHARS_QUERY); |
0 |
9 |
9 |
| URI_SIMPLE_SETTER(query, URI_CHARS_QUERY); |
8 |
1 |
9 |
|
| 1208 |
19 |
▶ | URI_SIMPLE_SETTER(frag, URI_CHARS_FRAG); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_SIMPLE_SETTER(frag, URI_CHARS_FRAG); |
10 |
0 |
10 |
| URI_SIMPLE_SETTER(frag, URI_CHARS_FRAG); |
0 |
10 |
10 |
| URI_SIMPLE_SETTER(frag, URI_CHARS_FRAG); |
9 |
1 |
10 |
|
| 1209 |
11 |
▶ | URI_SIMPLE_SETTER(usr, URI_CHARS_USER); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_SIMPLE_SETTER(usr, URI_CHARS_USER); |
6 |
0 |
6 |
| URI_SIMPLE_SETTER(usr, URI_CHARS_USER); |
0 |
6 |
6 |
| URI_SIMPLE_SETTER(usr, URI_CHARS_USER); |
5 |
1 |
6 |
|
| 1210 |
9 |
▶ | URI_SIMPLE_SETTER(pwd, URI_CHARS_USER); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_SIMPLE_SETTER(pwd, URI_CHARS_USER); |
5 |
0 |
5 |
| URI_SIMPLE_SETTER(pwd, URI_CHARS_USER); |
0 |
5 |
5 |
| URI_SIMPLE_SETTER(pwd, URI_CHARS_USER); |
4 |
1 |
5 |
|
| 1211 |
13 |
▶ | URI_SIMPLE_SETTER(host, URI_CHARS_HOST); |
Branch: 3 branches
| Branch | True | False | Total |
| URI_SIMPLE_SETTER(host, URI_CHARS_HOST); |
7 |
0 |
7 |
| URI_SIMPLE_SETTER(host, URI_CHARS_HOST); |
0 |
7 |
7 |
| URI_SIMPLE_SETTER(host, URI_CHARS_HOST); |
6 |
1 |
7 |
|
| 1212 |
|
| |
| 1213 |
|
| static |
| 1214 |
5 |
| void set_port(pTHX_ SV *sv_uri, SV *sv_value) { |
| 1215 |
5 |
▶ | uri_t *uri = URI(sv_uri); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(sv_uri); |
5 |
0 |
5 |
| uri_t *uri = URI(sv_uri); |
0 |
5 |
5 |
|
| 1216 |
5 |
▶ | if (!is_defined(aTHX_ sv_value)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_defined(aTHX_ sv_value)) { |
1 |
4 |
5 |
|
| 1217 |
1 |
| str_clear(aTHX_ uri->port); |
| 1218 |
1 |
| return; |
| 1219 |
|
| } |
| 1220 |
|
| |
| 1221 |
|
| size_t vlen, i; |
| 1222 |
4 |
| const char *value = SvPV_const(sv_value, vlen); |
| 1223 |
4 |
| str_set(aTHX_ uri->port, value, vlen); |
| 1224 |
|
| } |
| 1225 |
|
| |
| 1226 |
|
| static |
| 1227 |
12 |
| void set_auth(pTHX_ SV *sv_uri, SV *sv_value) { |
| 1228 |
12 |
▶ | uri_t *uri = URI(sv_uri); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(sv_uri); |
12 |
0 |
12 |
| uri_t *uri = URI(sv_uri); |
0 |
12 |
12 |
|
| 1229 |
|
| |
| 1230 |
12 |
| str_clear(aTHX_ uri->usr); |
| 1231 |
12 |
| str_clear(aTHX_ uri->pwd); |
| 1232 |
12 |
| str_clear(aTHX_ uri->host); |
| 1233 |
12 |
| str_clear(aTHX_ uri->port); |
| 1234 |
|
| |
| 1235 |
12 |
▶ | if (is_defined(aTHX_ sv_value)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_defined(aTHX_ sv_value)) { |
11 |
1 |
12 |
|
| 1236 |
|
| size_t vlen; |
| 1237 |
11 |
| const char *value = SvPV_const(sv_value, vlen); |
| 1238 |
|
| |
| 1239 |
11 |
▶ | if (vlen > URI_SIZE_auth) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (vlen > URI_SIZE_auth) { |
0 |
11 |
11 |
|
| 1240 |
0 |
| croak("set_auth: size of auth string exceeds max of %lu", URI_SIZE_auth); |
| 1241 |
|
| } |
| 1242 |
|
| |
| 1243 |
|
| // auth isn't stored as an individual field, so encode to local array and rescan |
| 1244 |
|
| char auth[URI_SIZE_auth]; |
| 1245 |
11 |
| size_t len = uri_encode(value, vlen, (char*) &auth, URI_CHARS_AUTH, uri->is_iri); |
| 1246 |
|
| |
| 1247 |
11 |
| uri_scan_auth(aTHX_ uri, auth, len); |
| 1248 |
|
| } |
| 1249 |
12 |
| } |
| 1250 |
|
| |
| 1251 |
|
| static |
| 1252 |
12 |
| void set_path_array(pTHX_ SV *sv_uri, SV *sv_path) { |
| 1253 |
12 |
▶ | uri_t *uri = URI(sv_uri); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(sv_uri); |
12 |
0 |
12 |
| uri_t *uri = URI(sv_uri); |
0 |
12 |
12 |
|
| 1254 |
|
| SV **refval, *tmp; |
| 1255 |
|
| AV *av_path; |
| 1256 |
|
| size_t i, av_idx, seg_len; |
| 1257 |
|
| const char *seg; |
| 1258 |
12 |
| uri_str_t *path = uri->path; |
| 1259 |
|
| |
| 1260 |
12 |
| str_clear(aTHX_ path); |
| 1261 |
|
| |
| 1262 |
12 |
▶ | if (!is_defined(aTHX_ sv_path)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_defined(aTHX_ sv_path)) { |
1 |
11 |
12 |
|
| 1263 |
2 |
| return; |
| 1264 |
|
| } |
| 1265 |
|
| |
| 1266 |
|
| // Inspect input array |
| 1267 |
11 |
| av_path = (AV*) SvRV(sv_path); |
| 1268 |
11 |
| av_idx = av_top_index(av_path); |
| 1269 |
|
| |
| 1270 |
11 |
▶ | if (av_idx == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_idx == -1) { |
1 |
10 |
11 |
|
| 1271 |
1 |
| return; |
| 1272 |
|
| } |
| 1273 |
|
| |
| 1274 |
|
| // Build the new path |
| 1275 |
35 |
▶ | for (i = 0; i <= av_idx; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_idx; ++i) { |
25 |
10 |
35 |
|
| 1276 |
|
| // Add separator. If the next value fetched from the array is invalid, it |
| 1277 |
|
| // just gets an empty segment. |
| 1278 |
25 |
| str_append(aTHX_ path, "/", 1); |
| 1279 |
|
| |
| 1280 |
|
| // Fetch next segment |
| 1281 |
25 |
| refval = av_fetch(av_path, (SSize_t) i, 0); |
| 1282 |
25 |
▶ | if (refval == NULL) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (refval == NULL) continue; |
0 |
25 |
25 |
|
| 1283 |
25 |
▶ | if (!is_defined(aTHX_ *refval)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_defined(aTHX_ *refval)) continue; |
0 |
25 |
25 |
|
| 1284 |
|
| |
| 1285 |
|
| // Copy value over |
| 1286 |
25 |
▶ | if (is_defined(aTHX_ *refval)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_defined(aTHX_ *refval)) { |
25 |
0 |
25 |
|
| 1287 |
25 |
| seg = SvPV_nomg_const(*refval, seg_len); |
| 1288 |
|
| |
| 1289 |
|
| // Convert octets to utf8 if necessary |
| 1290 |
25 |
▶ | if (!DO_UTF8(*refval)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!DO_UTF8(*refval)) { |
1 |
24 |
25 |
| if (!DO_UTF8(*refval)) { |
0 |
1 |
1 |
|
| 1291 |
24 |
| tmp = sv_2mortal(newSVpvn(seg, seg_len)); |
| 1292 |
24 |
| sv_utf8_encode(tmp); |
| 1293 |
24 |
| seg = SvPV_const(tmp, seg_len); |
| 1294 |
|
| } |
| 1295 |
|
| |
| 1296 |
25 |
| char out[seg_len * 3 + 1]; |
| 1297 |
25 |
| size_t out_len = uri_encode(seg, seg_len, out, URI_CHARS_PATH_SEGMENT, uri->is_iri); |
| 1298 |
25 |
| str_append(aTHX_ path, out, out_len); |
| 1299 |
|
| } |
| 1300 |
|
| } |
| 1301 |
|
| } |
| 1302 |
|
| |
| 1303 |
|
| static |
| 1304 |
11 |
| void update_query_keyset(pTHX_ SV *sv_uri, SV *sv_key_set, SV *sv_separator) { |
| 1305 |
11 |
▶ | uri_t *uri = URI(sv_uri); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(sv_uri); |
11 |
0 |
11 |
| uri_t *uri = URI(sv_uri); |
0 |
11 |
11 |
|
| 1306 |
|
| HE *ent; |
| 1307 |
|
| HV *keys, *enc_keys; |
| 1308 |
|
| I32 iterlen, i, klen; |
| 1309 |
|
| SV *val, **refval; |
| 1310 |
|
| bool copy; |
| 1311 |
|
| char *key; |
| 1312 |
11 |
| size_t off = 0; |
| 1313 |
11 |
| uri_str_t *query = uri->query; |
| 1314 |
11 |
| uri_str_t *dest = str_new(aTHX_ URI_SIZE_query); |
| 1315 |
|
| |
| 1316 |
11 |
| size_t slen = 1; |
| 1317 |
21 |
▶ | const char *separator = is_defined(aTHX_ sv_separator) ? SvPV_const(sv_separator, slen) : "&"; |
Branch: 1 branch
| Branch | True | False | Total |
| const char *separator = is_defined(aTHX_ sv_separator) ? SvPV_const(sv_separator, slen) : "&"; |
10 |
1 |
11 |
|
| 1318 |
|
| |
| 1319 |
|
| uri_query_scanner_t scanner; |
| 1320 |
|
| uri_query_token_t token; |
| 1321 |
|
| |
| 1322 |
|
| // Validate reference parameters |
| 1323 |
11 |
▶ | if (!is_ref(aTHX_ sv_key_set) || SvTYPE(SvRV(sv_key_set)) != SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!is_ref(aTHX_ sv_key_set) || SvTYPE(SvRV(sv_key_set)) != SVt_PVHV) { |
11 |
0 |
11 |
| if (!is_ref(aTHX_ sv_key_set) || SvTYPE(SvRV(sv_key_set)) != SVt_PVHV) { |
0 |
11 |
11 |
|
| 1324 |
0 |
| croak("set_query_keys: expected hash ref"); |
| 1325 |
|
| } |
| 1326 |
|
| |
| 1327 |
|
| // Dereference key set hash |
| 1328 |
11 |
| keys = (HV*) SvRV(sv_key_set); |
| 1329 |
|
| |
| 1330 |
|
| // Create new HV with all keys uri-encoded |
| 1331 |
11 |
| enc_keys = newHV(); |
| 1332 |
11 |
| iterlen = hv_iterinit(keys); |
| 1333 |
|
| |
| 1334 |
27 |
▶ | for (i = 0; i < iterlen; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < iterlen; ++i) { |
16 |
11 |
27 |
|
| 1335 |
16 |
| ent = hv_iternext(keys); |
| 1336 |
16 |
| key = hv_iterkey(ent, &klen); |
| 1337 |
16 |
| val = hv_iterval(keys, ent); |
| 1338 |
|
| |
| 1339 |
16 |
| SvGETMAGIC(val); |
| 1340 |
|
| |
| 1341 |
16 |
▶ | if (klen > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (klen > 0) { |
15 |
1 |
16 |
|
| 1342 |
15 |
| char enc_key[(3 * klen) + 1]; |
| 1343 |
15 |
| klen = uri_encode(key, klen, enc_key, ":@?/", uri->is_iri); |
| 1344 |
15 |
▶ | hv_store(enc_keys, enc_key, klen * (uri->is_iri ? -1 : 1), val, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| hv_store(enc_keys, enc_key, klen * (uri->is_iri ? -1 : 1), val, 0); |
0 |
15 |
15 |
|
| 1345 |
|
| } |
| 1346 |
|
| } |
| 1347 |
|
| |
| 1348 |
|
| // Begin building the new query string from the existing one. As each key is |
| 1349 |
|
| // encountered in the query string, exclude ones with a falsish value in the |
| 1350 |
|
| // hash and keep the ones with a truish value. Any not present in the hash |
| 1351 |
|
| // are kept unchanged. |
| 1352 |
11 |
▶ | query_scanner_init(&scanner, str_get(query), str_len(query)); |
Branch: 1 branch
| Branch | True | False | Total |
| query_scanner_init(&scanner, str_get(query), str_len(query)); |
8 |
3 |
11 |
|
| 1353 |
|
| |
| 1354 |
30 |
▶ | while (!query_scanner_done(&scanner)) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (!query_scanner_done(&scanner)) { |
19 |
11 |
30 |
|
| 1355 |
19 |
| query_scanner_next(&scanner, &token); |
| 1356 |
19 |
▶ | if (token.type == DONE) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (token.type == DONE) continue; |
0 |
19 |
19 |
|
| 1357 |
|
| |
| 1358 |
|
| // Use the encoded keys hash to decide whether to copy this key (and |
| 1359 |
|
| // value if present) over to dest. If the key exists, skip. It will be |
| 1360 |
|
| // added to the filtered query string last. |
| 1361 |
19 |
| copy = 1; |
| 1362 |
19 |
▶ | if (hv_exists(enc_keys, token.key, token.key_length * (uri->is_iri ? -1 : 1))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (hv_exists(enc_keys, token.key, token.key_length * (uri->is_iri ? -1 : 1))) { |
0 |
19 |
19 |
| if (hv_exists(enc_keys, token.key, token.key_length * (uri->is_iri ? -1 : 1))) { |
6 |
13 |
19 |
|
| 1363 |
6 |
▶ | refval = hv_fetch(enc_keys, token.key, token.key_length * (uri->is_iri ? -1 : 1), 0); |
Branch: 1 branch
| Branch | True | False | Total |
| refval = hv_fetch(enc_keys, token.key, token.key_length * (uri->is_iri ? -1 : 1), 0); |
0 |
6 |
6 |
|
| 1364 |
|
| // NULL shouldn't be possible since this is guarded with hv_exists, but |
| 1365 |
|
| // perlguts, amirite? |
| 1366 |
6 |
▶ | copy = refval == NULL || SvTRUE(*refval); |
Branch: 2 branches
| Branch | True | False | Total |
| copy = refval == NULL || SvTRUE(*refval); |
6 |
0 |
6 |
| copy = refval == NULL || SvTRUE(*refval); |
0 |
6 |
6 |
|
| 1367 |
|
| } |
| 1368 |
|
| |
| 1369 |
19 |
▶ | if (copy) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (copy) { |
13 |
6 |
19 |
|
| 1370 |
13 |
▶ | if (off > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (off > 0) { |
5 |
8 |
13 |
|
| 1371 |
5 |
| str_append(aTHX_ dest, separator, slen); |
| 1372 |
5 |
| off += slen; |
| 1373 |
|
| } |
| 1374 |
|
| |
| 1375 |
13 |
| str_append(aTHX_ dest, token.key, token.key_length); |
| 1376 |
13 |
| off += token.key_length; |
| 1377 |
|
| |
| 1378 |
13 |
▶ | if (token.type == PARAM) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (token.type == PARAM) { |
4 |
9 |
13 |
|
| 1379 |
4 |
| str_append(aTHX_ dest, "=", 1); |
| 1380 |
4 |
| str_append(aTHX_ dest, token.value, token.value_length); |
| 1381 |
4 |
| off += token.value_length; |
| 1382 |
|
| } |
| 1383 |
|
| } |
| 1384 |
|
| } |
| 1385 |
|
| |
| 1386 |
|
| // Walk through the encoded-key hash, adding remaining keys. |
| 1387 |
11 |
| iterlen = hv_iterinit(enc_keys); |
| 1388 |
|
| |
| 1389 |
26 |
▶ | for (i = 0; i < iterlen; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < iterlen; ++i) { |
15 |
11 |
26 |
|
| 1390 |
15 |
| ent = hv_iternext(enc_keys); |
| 1391 |
15 |
| key = hv_iterkey(ent, &klen); |
| 1392 |
15 |
| val = hv_iterval(enc_keys, ent); |
| 1393 |
|
| |
| 1394 |
15 |
▶ | if (SvTRUE(val)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTRUE(val)) { |
9 |
6 |
15 |
|
| 1395 |
|
| // Add separator if the new query string is not empty |
| 1396 |
9 |
▶ | if (off > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (off > 0) { |
7 |
2 |
9 |
|
| 1397 |
7 |
| str_append(aTHX_ dest, separator, slen); |
| 1398 |
7 |
| off += slen; |
| 1399 |
|
| } |
| 1400 |
|
| |
| 1401 |
9 |
| str_append(aTHX_ dest, key, klen); |
| 1402 |
9 |
| off += klen; |
| 1403 |
|
| } |
| 1404 |
|
| } |
| 1405 |
|
| |
| 1406 |
11 |
| str_free(aTHX_ query); |
| 1407 |
11 |
| uri->query = dest; |
| 1408 |
11 |
| } |
| 1409 |
|
| |
| 1410 |
|
| static |
| 1411 |
66 |
| void set_param(pTHX_ SV *sv_uri, SV *sv_key, SV *sv_values, SV *sv_separator) { |
| 1412 |
66 |
▶ | uri_t *uri = URI(sv_uri); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(sv_uri); |
66 |
0 |
66 |
| uri_t *uri = URI(sv_uri); |
0 |
66 |
66 |
|
| 1413 |
|
| const char *strval; |
| 1414 |
66 |
| size_t vlen, reflen, av_idx, i = 0, off = 0; |
| 1415 |
|
| AV *av_values; |
| 1416 |
|
| SV **refval; |
| 1417 |
66 |
| uri_str_t *dest = str_new(aTHX_ URI_SIZE_query); |
| 1418 |
|
| uri_query_scanner_t scanner; |
| 1419 |
|
| uri_query_token_t token; |
| 1420 |
|
| |
| 1421 |
66 |
| size_t slen = 1; |
| 1422 |
128 |
▶ | const char *separator = is_defined(aTHX_ sv_separator) ? SvPV_const(sv_separator, slen) : "&"; |
Branch: 1 branch
| Branch | True | False | Total |
| const char *separator = is_defined(aTHX_ sv_separator) ? SvPV_const(sv_separator, slen) : "&"; |
62 |
4 |
66 |
|
| 1423 |
|
| |
| 1424 |
|
| // Build encoded key string |
| 1425 |
66 |
▶ | if (!is_defined(aTHX_ sv_key)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_defined(aTHX_ sv_key)) { |
1 |
65 |
66 |
|
| 1426 |
1 |
| croak("set_param: expected key"); |
| 1427 |
|
| } |
| 1428 |
|
| |
| 1429 |
|
| size_t klen; |
| 1430 |
65 |
| const char *key = SvPV_const(sv_key, klen); |
| 1431 |
65 |
| char enc_key[(3 * klen) + 1]; |
| 1432 |
65 |
| klen = uri_encode(key, strlen(key), enc_key, ":@?/", uri->is_iri); |
| 1433 |
|
| |
| 1434 |
|
| // Get array of values to set |
| 1435 |
65 |
▶ | if (!is_ref(aTHX_ sv_values) || SvTYPE(SvRV(sv_values)) != SVt_PVAV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!is_ref(aTHX_ sv_values) || SvTYPE(SvRV(sv_values)) != SVt_PVAV) { |
64 |
1 |
65 |
| if (!is_ref(aTHX_ sv_values) || SvTYPE(SvRV(sv_values)) != SVt_PVAV) { |
0 |
64 |
64 |
|
| 1436 |
1 |
| croak("set_param: expected array of values"); |
| 1437 |
|
| } |
| 1438 |
|
| |
| 1439 |
64 |
| av_values = (AV*) SvRV(sv_values); |
| 1440 |
64 |
| av_idx = av_top_index(av_values); |
| 1441 |
|
| |
| 1442 |
|
| // Begin building the new query string from the existing one, skipping |
| 1443 |
|
| // keys (and their values, if any) matching sv_key. |
| 1444 |
64 |
| query_scanner_init(&scanner, uri->query->string, uri->query->length); |
| 1445 |
|
| |
| 1446 |
133 |
▶ | while (!query_scanner_done(&scanner)) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (!query_scanner_done(&scanner)) { |
69 |
64 |
133 |
|
| 1447 |
69 |
| query_scanner_next(&scanner, &token); |
| 1448 |
69 |
▶ | if (token.type == DONE) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (token.type == DONE) continue; |
0 |
69 |
69 |
|
| 1449 |
|
| |
| 1450 |
|
| // The key does not match the key being set |
| 1451 |
69 |
▶ | if (strncmp(enc_key, token.key, maxnum(klen, token.key_length)) != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strncmp(enc_key, token.key, maxnum(klen, token.key_length)) != 0) { |
28 |
41 |
69 |
|
| 1452 |
|
| // Add separator if this is not the first key being written |
| 1453 |
28 |
▶ | if (off > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (off > 0) { |
7 |
21 |
28 |
|
| 1454 |
7 |
| str_append(aTHX_ dest, separator, slen); |
| 1455 |
7 |
| off += slen; |
| 1456 |
|
| } |
| 1457 |
|
| |
| 1458 |
|
| // Write the key to the buffer |
| 1459 |
28 |
| str_append(aTHX_ dest, token.key, token.key_length); |
| 1460 |
28 |
| off += token.key_length; |
| 1461 |
|
| |
| 1462 |
|
| // The key has a value |
| 1463 |
28 |
▶ | if (token.type == PARAM) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (token.type == PARAM) { |
28 |
0 |
28 |
|
| 1464 |
28 |
| str_append(aTHX_ dest, "=", 1); |
| 1465 |
|
| |
| 1466 |
|
| // If the value's length is 0, it was parsed from "key=", so the value |
| 1467 |
|
| // is not written after the '=' is added above. |
| 1468 |
28 |
▶ | if (token.value_length > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (token.value_length > 0) { |
28 |
0 |
28 |
|
| 1469 |
|
| // Otherwise, write the value to the buffer |
| 1470 |
28 |
| str_append(aTHX_ dest, token.value, token.value_length); |
| 1471 |
28 |
| off += token.value_length; |
| 1472 |
|
| } |
| 1473 |
|
| } |
| 1474 |
|
| } |
| 1475 |
|
| } |
| 1476 |
|
| |
| 1477 |
|
| // Add the new values to the query |
| 1478 |
139 |
▶ | for (i = 0; i <= av_idx; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_idx; ++i) { |
84 |
55 |
139 |
|
| 1479 |
|
| // Fetch next value from the array |
| 1480 |
84 |
| refval = av_fetch(av_values, (SSize_t) i, 0); |
| 1481 |
84 |
▶ | if (refval == NULL) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (refval == NULL) break; |
9 |
75 |
84 |
|
| 1482 |
75 |
▶ | if (!is_defined(aTHX_ *refval)) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_defined(aTHX_ *refval)) break; |
0 |
75 |
75 |
|
| 1483 |
|
| |
| 1484 |
|
| // Add separator if needed to separate pairs |
| 1485 |
75 |
▶ | if (off > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (off > 0) { |
35 |
40 |
75 |
|
| 1486 |
35 |
| str_append(aTHX_ dest, separator, slen); |
| 1487 |
35 |
| off += slen; |
| 1488 |
|
| } |
| 1489 |
|
| |
| 1490 |
|
| // Copy key over |
| 1491 |
75 |
| str_append(aTHX_ dest, enc_key, klen); |
| 1492 |
75 |
| off += klen; |
| 1493 |
|
| |
| 1494 |
75 |
| str_append(aTHX_ dest, "=", 1); |
| 1495 |
|
| |
| 1496 |
|
| // Copy value over |
| 1497 |
75 |
| SvGETMAGIC(*refval); |
| 1498 |
75 |
| strval = SvPV_const(*refval, reflen); |
| 1499 |
|
| |
| 1500 |
75 |
| char tmp[reflen * 3 + 1]; |
| 1501 |
75 |
| vlen = uri_encode(strval, reflen, tmp, ":@?/", uri->is_iri); |
| 1502 |
75 |
| str_append(aTHX_ dest, tmp, vlen); |
| 1503 |
75 |
| off += vlen; |
| 1504 |
|
| } |
| 1505 |
|
| |
| 1506 |
64 |
| str_free(aTHX_ uri->query); |
| 1507 |
64 |
| uri->query = dest; |
| 1508 |
64 |
| } |
| 1509 |
|
| |
| 1510 |
|
| /*------------------------------------------------------------------------------ |
| 1511 |
|
| * Other stuff |
| 1512 |
|
| -----------------------------------------------------------------------------*/ |
| 1513 |
|
| |
| 1514 |
|
| static |
| 1515 |
245 |
| SV* to_string(pTHX_ SV *uri_obj) { |
| 1516 |
245 |
▶ | uri_t *uri = URI(uri_obj); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(uri_obj); |
245 |
0 |
245 |
| uri_t *uri = URI(uri_obj); |
0 |
245 |
245 |
|
| 1517 |
245 |
| SV *out = newSVpvn("", 0); |
| 1518 |
245 |
| SV *auth = sv_2mortal(get_raw_auth(aTHX_ uri_obj)); |
| 1519 |
|
| |
| 1520 |
245 |
▶ | if (uri->is_iri) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (uri->is_iri) { |
4 |
241 |
245 |
|
| 1521 |
4 |
| SvUTF8_on(out); |
| 1522 |
|
| } |
| 1523 |
|
| |
| 1524 |
245 |
▶ | if (str_len(uri->scheme) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str_len(uri->scheme) > 0) { |
223 |
22 |
245 |
|
| 1525 |
223 |
▶ | sv_catpvn(out, str_get(uri->scheme), str_len(uri->scheme)); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_catpvn(out, str_get(uri->scheme), str_len(uri->scheme)); |
223 |
0 |
223 |
|
| 1526 |
223 |
| sv_catpvn(out, ":", 1); |
| 1527 |
|
| |
| 1528 |
223 |
▶ | if (SvTRUE(auth)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTRUE(auth)) { |
220 |
3 |
223 |
|
| 1529 |
|
| // When the authority section is present, the scheme must be followed by |
| 1530 |
|
| // two forward slashes |
| 1531 |
220 |
| sv_catpvn(out, "//", 2); |
| 1532 |
|
| } |
| 1533 |
|
| } |
| 1534 |
|
| |
| 1535 |
245 |
▶ | if (SvTRUE(auth)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTRUE(auth)) { |
220 |
25 |
245 |
|
| 1536 |
220 |
| sv_catsv(out, auth); |
| 1537 |
|
| |
| 1538 |
|
| // When the authority section is present, any path must be separated from |
| 1539 |
|
| // the authority section by a forward slash |
| 1540 |
220 |
▶ | if (str_len(uri->path) > 0 && (str_get(uri->path))[0] != '/') { |
Branch: 3 branches
| Branch | True | False | Total |
| if (str_len(uri->path) > 0 && (str_get(uri->path))[0] != '/') { |
180 |
40 |
220 |
| if (str_len(uri->path) > 0 && (str_get(uri->path))[0] != '/') { |
180 |
0 |
180 |
| if (str_len(uri->path) > 0 && (str_get(uri->path))[0] != '/') { |
11 |
169 |
180 |
|
| 1541 |
11 |
| sv_catpvn(out, "/", 1); |
| 1542 |
|
| } |
| 1543 |
|
| } |
| 1544 |
|
| |
| 1545 |
245 |
▶ | sv_catpvn(out, str_get(uri->path), str_len(uri->path)); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_catpvn(out, str_get(uri->path), str_len(uri->path)); |
191 |
54 |
245 |
|
| 1546 |
|
| |
| 1547 |
245 |
▶ | if (str_len(uri->query) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str_len(uri->query) > 0) { |
96 |
149 |
245 |
|
| 1548 |
96 |
| sv_catpvn(out, "?", 1); |
| 1549 |
96 |
▶ | sv_catpvn(out, str_get(uri->query), str_len(uri->query)); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_catpvn(out, str_get(uri->query), str_len(uri->query)); |
96 |
0 |
96 |
|
| 1550 |
|
| } |
| 1551 |
|
| |
| 1552 |
245 |
▶ | if (str_len(uri->frag) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (str_len(uri->frag) > 0) { |
59 |
186 |
245 |
|
| 1553 |
59 |
| sv_catpvn(out, "#", 1); |
| 1554 |
59 |
▶ | sv_catpvn(out, str_get(uri->frag), str_len(uri->frag)); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_catpvn(out, str_get(uri->frag), str_len(uri->frag)); |
59 |
0 |
59 |
|
| 1555 |
|
| } |
| 1556 |
|
| |
| 1557 |
245 |
| return out; |
| 1558 |
|
| } |
| 1559 |
|
| |
| 1560 |
|
| static |
| 1561 |
0 |
| void explain(pTHX_ SV* sv_uri) { |
| 1562 |
0 |
▶ | uri_t *uri = URI(sv_uri); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(sv_uri); |
0 |
0 |
0 |
| uri_t *uri = URI(sv_uri); |
0 |
0 |
0 |
|
| 1563 |
0 |
| printf("scheme: %s\n", uri->scheme->string); |
| 1564 |
0 |
| printf("auth:\n"); |
| 1565 |
0 |
| printf(" -usr: %s\n", uri->usr->string); |
| 1566 |
0 |
| printf(" -pwd: %s\n", uri->pwd->string); |
| 1567 |
0 |
| printf(" -host: %s\n", uri->host->string); |
| 1568 |
0 |
| printf(" -port: %s\n", uri->port->string); |
| 1569 |
0 |
| printf("path: %s\n", uri->path->string); |
| 1570 |
0 |
| printf("query: %s\n", uri->query->string); |
| 1571 |
0 |
| printf("frag: %s\n", uri->frag->string); |
| 1572 |
0 |
| } |
| 1573 |
|
| |
| 1574 |
|
| static |
| 1575 |
0 |
| void debug(pTHX_ SV* sv_uri) { |
| 1576 |
0 |
▶ | uri_t *uri = URI(sv_uri); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(sv_uri); |
0 |
0 |
0 |
| uri_t *uri = URI(sv_uri); |
0 |
0 |
0 |
|
| 1577 |
0 |
| warn("scheme: %s\n", uri->scheme->string); |
| 1578 |
0 |
| warn("auth:\n"); |
| 1579 |
0 |
| warn(" -usr: %s\n", uri->usr->string); |
| 1580 |
0 |
| warn(" -pwd: %s\n", uri->pwd->string); |
| 1581 |
0 |
| warn(" -host: %s\n", uri->host->string); |
| 1582 |
0 |
| warn(" -port: %s\n", uri->port->string); |
| 1583 |
0 |
| warn("path: %s\n", uri->path->string); |
| 1584 |
0 |
| warn("query: %s\n", uri->query->string); |
| 1585 |
0 |
| warn("frag: %s\n", uri->frag->string); |
| 1586 |
0 |
| } |
| 1587 |
|
| |
| 1588 |
|
| static |
| 1589 |
872 |
| SV* new(pTHX_ const char* class, SV* uri_str, int is_iri) { |
| 1590 |
|
| const char* src; |
| 1591 |
|
| size_t len; |
| 1592 |
|
| uri_t* uri; |
| 1593 |
|
| SV* obj; |
| 1594 |
|
| SV* obj_ref; |
| 1595 |
|
| |
| 1596 |
|
| // Initialize the struct |
| 1597 |
872 |
| Newx(uri, 1, uri_t); |
| 1598 |
872 |
| Zero(uri, 1, uri_t); |
| 1599 |
|
| |
| 1600 |
872 |
| uri->is_iri = is_iri; |
| 1601 |
872 |
| uri->scheme = str_new(aTHX_ URI_SIZE_scheme); |
| 1602 |
872 |
| uri->usr = str_new(aTHX_ URI_SIZE_usr); |
| 1603 |
872 |
| uri->pwd = str_new(aTHX_ URI_SIZE_pwd); |
| 1604 |
872 |
| uri->host = str_new(aTHX_ URI_SIZE_host); |
| 1605 |
872 |
| uri->port = str_new(aTHX_ URI_SIZE_port); |
| 1606 |
872 |
| uri->path = str_new(aTHX_ URI_SIZE_path); |
| 1607 |
872 |
| uri->query = str_new(aTHX_ URI_SIZE_query); |
| 1608 |
872 |
| uri->frag = str_new(aTHX_ URI_SIZE_frag); |
| 1609 |
|
| |
| 1610 |
|
| // Build the blessed instance |
| 1611 |
872 |
| obj = newSViv((IV) uri); |
| 1612 |
872 |
| obj_ref = newRV_noinc(obj); |
| 1613 |
872 |
| sv_bless(obj_ref, gv_stashpv(class, GV_ADD)); |
| 1614 |
|
| |
| 1615 |
|
| // Scan the input string to fill the struct |
| 1616 |
872 |
▶ | if (!SvTRUE(uri_str)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvTRUE(uri_str)) { |
263 |
609 |
872 |
|
| 1617 |
263 |
| src = ""; |
| 1618 |
263 |
| len = 0; |
| 1619 |
|
| } |
| 1620 |
|
| else { |
| 1621 |
|
| // Copy input string *before* calling DO_UTF8() in case the SV is an object |
| 1622 |
|
| // with string overloading, which may trigger the utf8 flag. |
| 1623 |
609 |
| src = SvPV_nomg_const(uri_str, len); |
| 1624 |
|
| |
| 1625 |
|
| // Ensure the pv bytes are utf8-encoded |
| 1626 |
609 |
▶ | if (!DO_UTF8(uri_str)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!DO_UTF8(uri_str)) { |
1 |
608 |
609 |
| if (!DO_UTF8(uri_str)) { |
0 |
1 |
1 |
|
| 1627 |
608 |
| uri_str = sv_2mortal(newSVpvn(src, len)); |
| 1628 |
608 |
| sv_utf8_encode(uri_str); |
| 1629 |
608 |
| src = SvPV_const(uri_str, len); |
| 1630 |
|
| } |
| 1631 |
|
| } |
| 1632 |
|
| |
| 1633 |
872 |
| uri_scan(aTHX_ uri, src, len); |
| 1634 |
|
| |
| 1635 |
872 |
| return obj_ref; |
| 1636 |
|
| } |
| 1637 |
|
| |
| 1638 |
|
| static |
| 1639 |
872 |
| void DESTROY(pTHX_ SV *sv_uri) { |
| 1640 |
872 |
▶ | uri_t *uri = URI(sv_uri); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(sv_uri); |
872 |
0 |
872 |
| uri_t *uri = URI(sv_uri); |
0 |
872 |
872 |
|
| 1641 |
872 |
| str_free(aTHX_ uri->scheme); |
| 1642 |
872 |
| str_free(aTHX_ uri->usr); |
| 1643 |
872 |
| str_free(aTHX_ uri->pwd); |
| 1644 |
872 |
| str_free(aTHX_ uri->host); |
| 1645 |
872 |
| str_free(aTHX_ uri->port); |
| 1646 |
872 |
| str_free(aTHX_ uri->path); |
| 1647 |
872 |
| str_free(aTHX_ uri->query); |
| 1648 |
872 |
| str_free(aTHX_ uri->frag); |
| 1649 |
872 |
| Safefree(uri); |
| 1650 |
872 |
| } |
| 1651 |
|
| |
| 1652 |
|
| /* |
| 1653 |
|
| * Extras |
| 1654 |
|
| */ |
| 1655 |
|
| |
| 1656 |
|
| /* |
| 1657 |
|
| * Splits a uri string into its component sections: scheme, authority, path, |
| 1658 |
|
| * query, fragment. Pushes those values directly onto the results stack. |
| 1659 |
|
| */ |
| 1660 |
|
| static |
| 1661 |
28 |
| void uri_split(pTHX_ SV *uri) { |
| 1662 |
28 |
| dXSARGS; |
| 1663 |
28 |
| sp = mark; |
| 1664 |
|
| |
| 1665 |
|
| // If the object has already been parsed, there is no need to reparse it. |
| 1666 |
28 |
▶ | if (sv_isobject(uri) && sv_derived_from(uri, "URI::Fast")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (sv_isobject(uri) && sv_derived_from(uri, "URI::Fast")) { |
0 |
28 |
28 |
| if (sv_isobject(uri) && sv_derived_from(uri, "URI::Fast")) { |
0 |
0 |
0 |
|
| 1667 |
0 |
▶ | XPUSHs(sv_2mortal(get_scheme(aTHX_ uri))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(get_scheme(aTHX_ uri))); |
0 |
0 |
0 |
|
| 1668 |
0 |
▶ | XPUSHs(sv_2mortal(get_auth(aTHX_ uri))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(get_auth(aTHX_ uri))); |
0 |
0 |
0 |
|
| 1669 |
0 |
▶ | XPUSHs(sv_2mortal(get_path(aTHX_ uri))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(get_path(aTHX_ uri))); |
0 |
0 |
0 |
|
| 1670 |
0 |
▶ | XPUSHs(sv_2mortal(get_query(aTHX_ uri))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(get_query(aTHX_ uri))); |
0 |
0 |
0 |
|
| 1671 |
0 |
▶ | XPUSHs(sv_2mortal(get_frag(aTHX_ uri))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(get_frag(aTHX_ uri))); |
0 |
0 |
0 |
|
| 1672 |
|
| } |
| 1673 |
|
| // The object is defined |
| 1674 |
28 |
▶ | else if (SvOK(uri)) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (SvOK(uri)) { |
27 |
1 |
28 |
|
| 1675 |
27 |
| size_t idx = 0; |
| 1676 |
27 |
| size_t brk = 0; |
| 1677 |
|
| |
| 1678 |
|
| // Read the string from the SV |
| 1679 |
|
| const char *src; |
| 1680 |
|
| size_t len; |
| 1681 |
|
| |
| 1682 |
27 |
▶ | if (sv_len(uri) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_len(uri) == 0) { |
0 |
27 |
27 |
|
| 1683 |
0 |
| src = ""; |
| 1684 |
0 |
| len = 0; |
| 1685 |
|
| } |
| 1686 |
|
| else { |
| 1687 |
|
| // Copy string into new SV |
| 1688 |
27 |
| SV* str = sv_2mortal(newSV(0)); |
| 1689 |
27 |
| sv_copypv(str, ST(0)); |
| 1690 |
27 |
| src = SvPV_const(str, len); |
| 1691 |
|
| |
| 1692 |
27 |
▶ | if (!DO_UTF8(str)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!DO_UTF8(str)) { |
0 |
27 |
27 |
| if (!DO_UTF8(str)) { |
0 |
0 |
0 |
|
| 1693 |
27 |
| sv_utf8_encode(str); |
| 1694 |
27 |
| src = SvPV_const(str, len); |
| 1695 |
|
| } |
| 1696 |
|
| } |
| 1697 |
|
| |
| 1698 |
|
| // scheme |
| 1699 |
27 |
| brk = strcspn(&src[idx], ":/@?#"); |
| 1700 |
|
| |
| 1701 |
27 |
▶ | if (brk > 0 && src[idx + brk] == ':') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (brk > 0 && src[idx + brk] == ':') { |
25 |
2 |
27 |
| if (brk > 0 && src[idx + brk] == ':') { |
21 |
4 |
25 |
|
| 1702 |
21 |
▶ | XPUSHs(sv_2mortal(newSVpvn(&src[idx], brk))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpvn(&src[idx], brk))); |
0 |
21 |
21 |
|
| 1703 |
21 |
| idx += brk; |
| 1704 |
21 |
| ++idx; // skip past ":" |
| 1705 |
|
| } |
| 1706 |
|
| else { |
| 1707 |
6 |
▶ | XPUSHs(&PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(&PL_sv_undef); |
0 |
6 |
6 |
|
| 1708 |
|
| } |
| 1709 |
|
| |
| 1710 |
|
| // authority |
| 1711 |
27 |
▶ | if (idx + 1 < len // src is long enough to hold two slashes |
Branch: 1 branch
| Branch | True | False | Total |
| if (idx + 1 < len // src is long enough to hold two slashes |
26 |
1 |
27 |
|
| 1712 |
26 |
▶ | && src[idx] == '/' // next char is a slash |
Branch: 1 branch
| Branch | True | False | Total |
| && src[idx] == '/' // next char is a slash |
23 |
3 |
26 |
|
| 1713 |
23 |
▶ | && src[idx + 1] == '/') // char after that is a slash |
Branch: 1 branch
| Branch | True | False | Total |
| && src[idx + 1] == '/') // char after that is a slash |
22 |
1 |
23 |
|
| 1714 |
|
| { |
| 1715 |
22 |
| idx += 2; // skip past the double slashes |
| 1716 |
|
| |
| 1717 |
22 |
| brk = strcspn(&src[idx], "/?#"); |
| 1718 |
|
| |
| 1719 |
22 |
▶ | if (brk > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (brk > 0) { |
21 |
1 |
22 |
|
| 1720 |
21 |
▶ | XPUSHs(sv_2mortal(newSVpvn(&src[idx], brk))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpvn(&src[idx], brk))); |
0 |
21 |
21 |
|
| 1721 |
21 |
| idx += brk; |
| 1722 |
|
| } |
| 1723 |
|
| else { |
| 1724 |
1 |
▶ | XPUSHs(sv_2mortal(newSVpvn("", 0))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpvn("", 0))); |
0 |
1 |
1 |
|
| 1725 |
|
| } |
| 1726 |
|
| } |
| 1727 |
|
| else { |
| 1728 |
5 |
▶ | XPUSHs(&PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(&PL_sv_undef); |
0 |
5 |
5 |
|
| 1729 |
|
| } |
| 1730 |
|
| |
| 1731 |
|
| // path |
| 1732 |
27 |
| brk = strcspn(&src[idx], "?#"); |
| 1733 |
27 |
▶ | if (brk > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (brk > 0) { |
23 |
4 |
27 |
|
| 1734 |
23 |
▶ | XPUSHs(sv_2mortal(newSVpvn(&src[idx], brk))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpvn(&src[idx], brk))); |
0 |
23 |
23 |
|
| 1735 |
23 |
| idx += brk; |
| 1736 |
|
| } else { |
| 1737 |
4 |
▶ | XPUSHs(sv_2mortal(newSVpvn("", 0))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpvn("", 0))); |
0 |
4 |
4 |
|
| 1738 |
|
| } |
| 1739 |
|
| |
| 1740 |
|
| // query |
| 1741 |
27 |
▶ | if (src[idx] == '?') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (src[idx] == '?') { |
11 |
16 |
27 |
|
| 1742 |
11 |
| ++idx; // skip past ? |
| 1743 |
11 |
| brk = strcspn(&src[idx], "#"); |
| 1744 |
11 |
▶ | if (brk > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (brk > 0) { |
11 |
0 |
11 |
|
| 1745 |
11 |
▶ | XPUSHs(sv_2mortal(newSVpvn(&src[idx], brk))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpvn(&src[idx], brk))); |
0 |
11 |
11 |
|
| 1746 |
11 |
| idx += brk; |
| 1747 |
|
| } else { |
| 1748 |
0 |
▶ | XPUSHs(sv_2mortal(newSVpvn("", 0))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpvn("", 0))); |
0 |
0 |
0 |
|
| 1749 |
|
| } |
| 1750 |
|
| } else { |
| 1751 |
16 |
▶ | XPUSHs(&PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(&PL_sv_undef); |
0 |
16 |
16 |
|
| 1752 |
|
| } |
| 1753 |
|
| |
| 1754 |
|
| // fragment |
| 1755 |
27 |
▶ | if (src[idx] == '#') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (src[idx] == '#') { |
9 |
18 |
27 |
|
| 1756 |
9 |
| ++idx; // skip past # |
| 1757 |
9 |
| brk = len - idx; |
| 1758 |
9 |
▶ | if (brk > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (brk > 0) { |
9 |
0 |
9 |
|
| 1759 |
9 |
▶ | XPUSHs(sv_2mortal(newSVpvn(&src[idx], brk))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpvn(&src[idx], brk))); |
0 |
9 |
9 |
|
| 1760 |
|
| } else { |
| 1761 |
0 |
▶ | XPUSHs(sv_2mortal(newSVpvn("", 0))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpvn("", 0))); |
0 |
0 |
0 |
|
| 1762 |
|
| } |
| 1763 |
|
| } else { |
| 1764 |
18 |
▶ | XPUSHs(&PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(&PL_sv_undef); |
0 |
18 |
18 |
|
| 1765 |
|
| } |
| 1766 |
|
| } |
| 1767 |
|
| |
| 1768 |
28 |
| PUTBACK; |
| 1769 |
28 |
| } |
| 1770 |
|
| |
| 1771 |
|
| /* |
| 1772 |
|
| * Collapses dotted segments in a path string based on the rules defined in RFC |
| 1773 |
|
| * 3986 section 5.2. |
| 1774 |
|
| */ |
| 1775 |
|
| static |
| 1776 |
179 |
| void remove_dot_segments(pTHX_ uri_str_t *out, const char *path, size_t len) { |
| 1777 |
179 |
▶ | if (len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 0) { |
7 |
172 |
179 |
|
| 1778 |
7 |
| return; |
| 1779 |
|
| } |
| 1780 |
|
| |
| 1781 |
172 |
| size_t brk, idx = 0; |
| 1782 |
172 |
| char in[len]; |
| 1783 |
172 |
| Copy(path, in, len + 1, char); |
| 1784 |
|
| |
| 1785 |
793 |
▶ | while (idx < len) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (idx < len) { |
621 |
172 |
793 |
|
| 1786 |
|
| // in begins with "./" or "../": ignore prefix completely |
| 1787 |
621 |
▶ | if (strncmp(&in[idx], "./", 2) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strncmp(&in[idx], "./", 2) == 0) { |
0 |
621 |
621 |
|
| 1788 |
0 |
| idx += 2; |
| 1789 |
|
| } |
| 1790 |
621 |
▶ | else if (strncmp(&in[idx], "../", 3) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strncmp(&in[idx], "../", 3) == 0) { |
0 |
621 |
621 |
|
| 1791 |
0 |
| idx += 3; |
| 1792 |
|
| } |
| 1793 |
|
| |
| 1794 |
|
| // in begins with /./: replace with / |
| 1795 |
621 |
▶ | else if (strncmp(&in[idx], "/./", 3) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strncmp(&in[idx], "/./", 3) == 0) { |
24 |
597 |
621 |
|
| 1796 |
24 |
| idx += 2; // inc to the final / in /./ instead of editing the buffer |
| 1797 |
|
| } |
| 1798 |
|
| |
| 1799 |
|
| // in begins with /. and . is a complete segment: replace with / |
| 1800 |
597 |
▶ | else if (strncmp(&in[idx], "/.", 2) == 0 && idx + 2 == len) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (strncmp(&in[idx], "/.", 2) == 0 && idx + 2 == len) { |
99 |
498 |
597 |
| else if (strncmp(&in[idx], "/.", 2) == 0 && idx + 2 == len) { |
9 |
90 |
99 |
|
| 1801 |
9 |
| idx += 1; |
| 1802 |
9 |
| in[idx] = '/'; |
| 1803 |
|
| } |
| 1804 |
|
| |
| 1805 |
|
| // in begins with /../: replace with /, remove final segment from out |
| 1806 |
588 |
▶ | else if (strncmp(&in[idx], "/../", 4) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strncmp(&in[idx], "/../", 4) == 0) { |
72 |
516 |
588 |
|
| 1807 |
72 |
| idx += 3; // inc to the final / in /./ instead of editing the buffer |
| 1808 |
72 |
| str_rtrim(aTHX_ out, '/'); |
| 1809 |
|
| } |
| 1810 |
|
| |
| 1811 |
|
| // in begins with /.. and .. is a complete $in segment: replace with /, remove final segment from out |
| 1812 |
516 |
▶ | else if (strncmp(&in[idx], "/..", 3) == 0 && idx + 3 == len) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (strncmp(&in[idx], "/..", 3) == 0 && idx + 3 == len) { |
16 |
500 |
516 |
| else if (strncmp(&in[idx], "/..", 3) == 0 && idx + 3 == len) { |
14 |
2 |
16 |
|
| 1813 |
14 |
| idx += 2; |
| 1814 |
14 |
| in[idx] = '/'; |
| 1815 |
14 |
| str_rtrim(aTHX_ out, '/'); |
| 1816 |
|
| } |
| 1817 |
|
| |
| 1818 |
|
| // in is "." or "..": done |
| 1819 |
502 |
▶ | else if ((in[idx] == '.' && idx + 1 == len) |
Branch: 2 branches
| Branch | True | False | Total |
| else if ((in[idx] == '.' && idx + 1 == len) |
0 |
502 |
502 |
| else if ((in[idx] == '.' && idx + 1 == len) |
0 |
0 |
0 |
|
| 1820 |
502 |
▶ | || (in[idx] == '.' && in[idx + 1] == '.' && idx + 2 == len)) { |
Branch: 3 branches
| Branch | True | False | Total |
| || (in[idx] == '.' && in[idx + 1] == '.' && idx + 2 == len)) { |
0 |
502 |
502 |
| || (in[idx] == '.' && in[idx + 1] == '.' && idx + 2 == len)) { |
0 |
0 |
0 |
| || (in[idx] == '.' && in[idx + 1] == '.' && idx + 2 == len)) { |
0 |
0 |
0 |
|
| 1821 |
|
| break; |
| 1822 |
|
| } |
| 1823 |
|
| |
| 1824 |
|
| // else copy everything up to but not including the next '/' from in to out |
| 1825 |
|
| else { |
| 1826 |
502 |
▶ | if (in[idx] == '/') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (in[idx] == '/') { |
502 |
0 |
502 |
|
| 1827 |
502 |
| brk = minnum(len - idx, 1 + strncspn(&in[idx + 1], len - idx, "/")); |
| 1828 |
|
| } |
| 1829 |
|
| else { |
| 1830 |
0 |
| brk = strncspn(&in[idx], len - idx, "/"); |
| 1831 |
|
| } |
| 1832 |
|
| |
| 1833 |
502 |
| str_append(aTHX_ out, &in[idx], brk); |
| 1834 |
502 |
| idx += brk; |
| 1835 |
|
| } |
| 1836 |
|
| } |
| 1837 |
|
| } |
| 1838 |
|
| |
| 1839 |
|
| /*------------------------------------------------------------------------------ |
| 1840 |
|
| * Absolution |
| 1841 |
|
| * |
| 1842 |
|
| * As defined in https://www.rfc-editor.org/rfc/rfc3986.txt section 5.2 |
| 1843 |
|
| *----------------------------------------------------------------------------*/ |
| 1844 |
|
| static |
| 1845 |
199 |
| void absolute(pTHX_ SV *sv_target, SV *sv_uri, SV *sv_base) { |
| 1846 |
199 |
▶ | uri_t *target = URI(sv_target); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *target = URI(sv_target); |
199 |
0 |
199 |
| uri_t *target = URI(sv_target); |
0 |
199 |
199 |
|
| 1847 |
199 |
▶ | uri_t *rel = URI(sv_uri); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *rel = URI(sv_uri); |
199 |
0 |
199 |
| uri_t *rel = URI(sv_uri); |
0 |
199 |
199 |
|
| 1848 |
199 |
▶ | uri_t *base = URI(sv_base); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *base = URI(sv_base); |
199 |
0 |
199 |
| uri_t *base = URI(sv_base); |
0 |
199 |
199 |
|
| 1849 |
|
| |
| 1850 |
199 |
| const char *class = class_name(aTHX_ sv_target); |
| 1851 |
|
| |
| 1852 |
|
| // Relative URIs may begin with // to indicate an authority section without a |
| 1853 |
|
| // scheme, which is illegal in standard URI syntax (authority may only come |
| 1854 |
|
| // after a scheme, which is required, separated by //). This workaround helps |
| 1855 |
|
| // the parser along by identifying the authority section as such. |
| 1856 |
199 |
▶ | if (rel->scheme->length == 0 |
Branch: 1 branch
| Branch | True | False | Total |
| if (rel->scheme->length == 0 |
195 |
4 |
199 |
|
| 1857 |
195 |
▶ | && rel->host->length == 0 |
Branch: 1 branch
| Branch | True | False | Total |
| && rel->host->length == 0 |
188 |
7 |
195 |
|
| 1858 |
188 |
▶ | && rel->path->length >= 2 |
Branch: 1 branch
| Branch | True | False | Total |
| && rel->path->length >= 2 |
123 |
65 |
188 |
|
| 1859 |
123 |
▶ | && strncmp(rel->path->string, "//", 2) == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| && strncmp(rel->path->string, "//", 2) == 0) |
0 |
123 |
123 |
|
| 1860 |
|
| { |
| 1861 |
0 |
| SV *fixed = newSVpvn("x:", 2); |
| 1862 |
0 |
| sv_catsv(fixed, sv_2mortal(to_string(aTHX_ sv_uri))); |
| 1863 |
|
| |
| 1864 |
0 |
| SV *sv_tmp = sv_2mortal(new(aTHX_ class, sv_2mortal(fixed), 0)); |
| 1865 |
0 |
▶ | rel = URI(sv_tmp); |
Branch: 2 branches
| Branch | True | False | Total |
| rel = URI(sv_tmp); |
0 |
0 |
0 |
| rel = URI(sv_tmp); |
0 |
0 |
0 |
|
| 1866 |
|
| |
| 1867 |
0 |
| str_clear(aTHX_ rel->scheme); |
| 1868 |
|
| } |
| 1869 |
|
| |
| 1870 |
199 |
▶ | if (rel->scheme->length != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rel->scheme->length != 0) { |
4 |
195 |
199 |
|
| 1871 |
4 |
| remove_dot_segments(aTHX_ target->path, rel->path->string, rel->path->length); |
| 1872 |
4 |
| str_copy(aTHX_ rel->scheme, target->scheme); |
| 1873 |
4 |
| str_copy(aTHX_ rel->usr, target->usr); |
| 1874 |
4 |
| str_copy(aTHX_ rel->pwd, target->pwd); |
| 1875 |
4 |
| str_copy(aTHX_ rel->host, target->host); |
| 1876 |
4 |
| str_copy(aTHX_ rel->port, target->port); |
| 1877 |
4 |
| str_copy(aTHX_ rel->query, target->query); |
| 1878 |
|
| } |
| 1879 |
|
| else { |
| 1880 |
195 |
▶ | if (rel->usr->length > 0 || rel->host->length > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (rel->usr->length > 0 || rel->host->length > 0) { |
195 |
0 |
195 |
| if (rel->usr->length > 0 || rel->host->length > 0) { |
7 |
188 |
195 |
|
| 1881 |
7 |
| remove_dot_segments(aTHX_ target->path, rel->path->string, rel->path->length); |
| 1882 |
7 |
| str_copy(aTHX_ rel->usr, target->usr); |
| 1883 |
7 |
| str_copy(aTHX_ rel->pwd, target->pwd); |
| 1884 |
7 |
| str_copy(aTHX_ rel->host, target->host); |
| 1885 |
7 |
| str_copy(aTHX_ rel->port, target->port); |
| 1886 |
7 |
| str_copy(aTHX_ rel->query, target->query); |
| 1887 |
|
| } |
| 1888 |
|
| else { |
| 1889 |
188 |
▶ | if (rel->path->length == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rel->path->length == 0) { |
21 |
167 |
188 |
|
| 1890 |
21 |
| str_copy(aTHX_ base->path, target->path); |
| 1891 |
|
| |
| 1892 |
21 |
▶ | if (rel->query->length != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rel->query->length != 0) { |
7 |
14 |
21 |
|
| 1893 |
7 |
| str_copy(aTHX_ rel->query, target->query); |
| 1894 |
|
| } else { |
| 1895 |
14 |
| str_copy(aTHX_ base->query, target->query); |
| 1896 |
|
| } |
| 1897 |
|
| } |
| 1898 |
|
| else { |
| 1899 |
167 |
▶ | if (rel->path->string[0] == '/') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rel->path->string[0] == '/') { |
11 |
156 |
167 |
|
| 1900 |
11 |
| remove_dot_segments(aTHX_ target->path, rel->path->string, rel->path->length); |
| 1901 |
|
| } |
| 1902 |
|
| else { |
| 1903 |
156 |
| uri_str_t *merged = str_new(aTHX_ rel->path->length + base->path->length); |
| 1904 |
|
| |
| 1905 |
156 |
▶ | if (base->scheme->length > 0 && base->path->length == 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (base->scheme->length > 0 && base->path->length == 0) { |
156 |
0 |
156 |
| if (base->scheme->length > 0 && base->path->length == 0) { |
0 |
156 |
156 |
|
| 1906 |
0 |
| str_append(aTHX_ merged, "/", 1); |
| 1907 |
0 |
| str_append(aTHX_ merged, rel->path->string, rel->path->length); |
| 1908 |
|
| } |
| 1909 |
|
| else { |
| 1910 |
156 |
▶ | if (base->path->length > 0 && strstr(base->path->string, "/") != NULL) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (base->path->length > 0 && strstr(base->path->string, "/") != NULL) { |
156 |
0 |
156 |
| if (base->path->length > 0 && strstr(base->path->string, "/") != NULL) { |
156 |
0 |
156 |
|
| 1911 |
|
| // truncate base path at right-most /, inclusive |
| 1912 |
156 |
| str_append(aTHX_ merged, base->path->string, base->path->length); |
| 1913 |
156 |
| str_rtrim(aTHX_ merged, '/'); |
| 1914 |
|
| } else { |
| 1915 |
|
| // if there is no / in the base path, truncate it completely |
| 1916 |
|
| } |
| 1917 |
|
| |
| 1918 |
156 |
| str_append(aTHX_ merged, "/", 1); |
| 1919 |
156 |
| str_append(aTHX_ merged, rel->path->string, rel->path->length); |
| 1920 |
|
| } |
| 1921 |
|
| |
| 1922 |
156 |
| remove_dot_segments(aTHX_ target->path, merged->string, merged->length); |
| 1923 |
156 |
| str_free(aTHX_ merged); |
| 1924 |
|
| } |
| 1925 |
|
| |
| 1926 |
167 |
| str_copy(aTHX_ rel->query, target->query); |
| 1927 |
|
| } |
| 1928 |
|
| |
| 1929 |
188 |
| str_copy(aTHX_ base->usr, target->usr); |
| 1930 |
188 |
| str_copy(aTHX_ base->pwd, target->pwd); |
| 1931 |
188 |
| str_copy(aTHX_ base->host, target->host); |
| 1932 |
188 |
| str_copy(aTHX_ base->port, target->port); |
| 1933 |
|
| } |
| 1934 |
|
| |
| 1935 |
195 |
| str_copy(aTHX_ base->scheme, target->scheme); |
| 1936 |
|
| } |
| 1937 |
|
| |
| 1938 |
199 |
| str_copy(aTHX_ rel->frag, target->frag); |
| 1939 |
199 |
| } |
| 1940 |
|
| |
| 1941 |
|
| /* |
| 1942 |
|
| * Decodes and then reencodes a uri_str_t. |
| 1943 |
|
| * |
| 1944 |
|
| */ |
| 1945 |
|
| // unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" |
| 1946 |
|
| // 41-5A / 61-7A / 30-39 / 2D / 2E / 5F / 7E |
| 1947 |
|
| static inline |
| 1948 |
102 |
| void normalize_encoding(pTHX_ uri_str_t *str, char *permitted_chars, int allow_utf8) { |
| 1949 |
102 |
▶ | if (str->length == 0 || (strchr(str->string, '+') == NULL && strchr(str->string, '%') == NULL)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (str->length == 0 || (strchr(str->string, '+') == NULL && strchr(str->string, '%') == NULL)) { |
27 |
75 |
102 |
| if (str->length == 0 || (strchr(str->string, '+') == NULL && strchr(str->string, '%') == NULL)) { |
26 |
1 |
27 |
| if (str->length == 0 || (strchr(str->string, '+') == NULL && strchr(str->string, '%') == NULL)) { |
18 |
8 |
26 |
|
| 1950 |
93 |
| return; |
| 1951 |
|
| } |
| 1952 |
|
| |
| 1953 |
9 |
| char decoded[str->length + 1]; |
| 1954 |
9 |
| size_t decoded_len = uri_decode(str->string, str->length, decoded, ""); |
| 1955 |
|
| |
| 1956 |
9 |
| char encoded[(decoded_len * 3) + 2]; |
| 1957 |
9 |
| size_t encoded_len = uri_encode(decoded, decoded_len, encoded, permitted_chars, allow_utf8); |
| 1958 |
|
| |
| 1959 |
9 |
| str_set(aTHX_ str, encoded, encoded_len); |
| 1960 |
|
| } |
| 1961 |
|
| |
| 1962 |
|
| /* |
| 1963 |
|
| * Performs minimal normalization. Scheme and hostname are lower cased. All |
| 1964 |
|
| * members are scanned for lower case percent-encoded sequences. |
| 1965 |
|
| */ |
| 1966 |
|
| static |
| 1967 |
17 |
| void normalize(pTHX_ SV *uri_obj) { |
| 1968 |
17 |
▶ | uri_t *uri = URI(uri_obj); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *uri = URI(uri_obj); |
17 |
0 |
17 |
| uri_t *uri = URI(uri_obj); |
0 |
17 |
17 |
|
| 1969 |
|
| size_t i; |
| 1970 |
|
| |
| 1971 |
|
| // (6.2.2.1) lower case scheme |
| 1972 |
65 |
▶ | for (i = 0; i < uri->scheme->length; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < uri->scheme->length; ++i) { |
48 |
17 |
65 |
|
| 1973 |
48 |
▶ | uri->scheme->string[i] = toLOWER(uri->scheme->string[i]); |
Branch: 1 branch
| Branch | True | False | Total |
| uri->scheme->string[i] = toLOWER(uri->scheme->string[i]); |
4 |
44 |
48 |
|
| 1974 |
|
| } |
| 1975 |
|
| |
| 1976 |
|
| // (6.2.2.1) lower case hostname |
| 1977 |
165 |
▶ | for (i = 0; i < uri->host->length; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < uri->host->length; ++i) { |
148 |
17 |
165 |
|
| 1978 |
148 |
▶ | uri->host->string[i] = toLOWER(uri->host->string[i]); |
Branch: 1 branch
| Branch | True | False | Total |
| uri->host->string[i] = toLOWER(uri->host->string[i]); |
7 |
141 |
148 |
|
| 1979 |
|
| } |
| 1980 |
|
| |
| 1981 |
|
| // (6.2.2) remove dot segments from path |
| 1982 |
|
| // This is expensive, so skip it unless the uri has a path with a dot in it. |
| 1983 |
17 |
▶ | if (uri->path->length > 0 |
Branch: 1 branch
| Branch | True | False | Total |
| if (uri->path->length > 0 |
7 |
10 |
17 |
|
| 1984 |
7 |
▶ | && strchr(uri->path->string, '.') != NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| && strchr(uri->path->string, '.') != NULL) |
1 |
6 |
7 |
|
| 1985 |
|
| { |
| 1986 |
1 |
| uri_str_t *tmp = str_new(aTHX_ URI_SIZE_path); |
| 1987 |
1 |
| remove_dot_segments(aTHX_ tmp, uri->path->string, uri->path->length); |
| 1988 |
1 |
| str_free(aTHX_ uri->path); |
| 1989 |
1 |
| uri->path = tmp; |
| 1990 |
|
| } |
| 1991 |
|
| |
| 1992 |
|
| // (6.2.2.1) upper case hex codes in each section of the uri |
| 1993 |
|
| // (6.2.2.2) decode any percent-encoded sequences decoding to unreserved chars |
| 1994 |
17 |
| normalize_encoding(aTHX_ uri->usr, URI_CHARS_USER, uri->is_iri); |
| 1995 |
17 |
| normalize_encoding(aTHX_ uri->pwd, URI_CHARS_USER, uri->is_iri); |
| 1996 |
17 |
| normalize_encoding(aTHX_ uri->host, URI_CHARS_HOST, uri->is_iri); |
| 1997 |
17 |
| normalize_encoding(aTHX_ uri->path, URI_CHARS_PATH, uri->is_iri); |
| 1998 |
17 |
| normalize_encoding(aTHX_ uri->query, URI_CHARS_QUERY, uri->is_iri); |
| 1999 |
17 |
| normalize_encoding(aTHX_ uri->frag, URI_CHARS_FRAG, uri->is_iri); |
| 2000 |
|
| |
| 2001 |
|
| // (6.2.3) empty path should be represented as "/" when authority is present |
| 2002 |
17 |
▶ | if (uri->path->length == 0 && has_authority(aTHX_ uri)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (uri->path->length == 0 && has_authority(aTHX_ uri)) { |
10 |
7 |
17 |
| if (uri->path->length == 0 && has_authority(aTHX_ uri)) { |
6 |
4 |
10 |
|
| 2003 |
6 |
| str_set(aTHX_ uri->path, "/", 1); |
| 2004 |
|
| } |
| 2005 |
17 |
| } |
| 2006 |
|
| |
| 2007 |
|
| /* |
| 2008 |
|
| * Returns a new copy of the uri string with tabs, line feeds, and carriage |
| 2009 |
|
| * returns stripped, and backslashes replaced with forward slashes. |
| 2010 |
|
| */ |
| 2011 |
4 |
| SV* html_url(pTHX_ SV *uri, SV *base) { |
| 2012 |
|
| SV *rv; |
| 2013 |
4 |
| size_t i = 0; |
| 2014 |
|
| size_t len; |
| 2015 |
4 |
| const char *in = SvPV_const(uri, len); |
| 2016 |
4 |
| uri_str_t *out = str_new(aTHX_ 32); |
| 2017 |
|
| |
| 2018 |
4 |
▶ | if (in[0] == '/' && in[1] == '/') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (in[0] == '/' && in[1] == '/') { |
4 |
0 |
4 |
| if (in[0] == '/' && in[1] == '/') { |
4 |
0 |
4 |
|
| 2019 |
4 |
▶ | if (base != NULL && (SvOK(base) || SvROK(base))) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (base != NULL && (SvOK(base) || SvROK(base))) { |
4 |
0 |
4 |
| if (base != NULL && (SvOK(base) || SvROK(base))) { |
0 |
4 |
4 |
| if (base != NULL && (SvOK(base) || SvROK(base))) { |
0 |
0 |
0 |
|
| 2020 |
4 |
▶ | uri_t *base_uri = URI(base); |
Branch: 2 branches
| Branch | True | False | Total |
| uri_t *base_uri = URI(base); |
4 |
0 |
4 |
| uri_t *base_uri = URI(base); |
0 |
4 |
4 |
|
| 2021 |
4 |
▶ | if (base_uri->scheme->length > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (base_uri->scheme->length > 0) { |
4 |
0 |
4 |
|
| 2022 |
4 |
| str_append(aTHX_ out, base_uri->scheme->string, base_uri->scheme->length); |
| 2023 |
4 |
| str_append(aTHX_ out, ":", 1); |
| 2024 |
|
| } |
| 2025 |
|
| } |
| 2026 |
|
| } |
| 2027 |
|
| |
| 2028 |
|
| // Remove characters specified by the URL standard |
| 2029 |
116 |
▶ | for (i = 0; i < len; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; ++i) { |
112 |
4 |
116 |
|
| 2030 |
112 |
| switch (in[i]) { |
| 2031 |
|
| // Strip tabs, line feeds, and carriage returns |
| 2032 |
12 |
| case '\t': |
| 2033 |
|
| case '\r': |
| 2034 |
|
| case '\n': |
| 2035 |
12 |
| break; |
| 2036 |
|
| |
| 2037 |
|
| // Convert backslashes to forward slashes |
| 2038 |
8 |
| case '\\': |
| 2039 |
8 |
| str_append(aTHX_ out, "/", 1); |
| 2040 |
8 |
| break; |
| 2041 |
|
| |
| 2042 |
92 |
| default: |
| 2043 |
92 |
| str_append(aTHX_ out, &in[i], 1); |
| 2044 |
92 |
| break; |
| 2045 |
|
| } |
| 2046 |
|
| } |
| 2047 |
|
| |
| 2048 |
4 |
▶ | rv = URI_STR_2SV(out); |
Branch: 1 branch
| Branch | True | False | Total |
| rv = URI_STR_2SV(out); |
4 |
0 |
4 |
|
| 2049 |
4 |
| str_free(aTHX_ out); |
| 2050 |
|
| |
| 2051 |
|
| // If the source uri was utf8, ensure that the flag is flipped for the output |
| 2052 |
|
| // buffer as well. |
| 2053 |
4 |
▶ | if (DO_UTF8(uri)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (DO_UTF8(uri)) { |
0 |
4 |
4 |
| if (DO_UTF8(uri)) { |
0 |
0 |
0 |
|
| 2054 |
0 |
| sv_utf8_decode(rv); |
| 2055 |
|
| } |
| 2056 |
|
| |
| 2057 |
4 |
| return rv; |
| 2058 |
|
| } |
| 2059 |
|
| |
| 2060 |
|
| |
| 2061 |
|
| MODULE = URI::Fast PACKAGE = URI::Fast |
| 2062 |
|
| |
| 2063 |
|
| PROTOTYPES: DISABLE |
| 2064 |
|
| |
| 2065 |
|
| FALLBACK: TRUE |
| 2066 |
|
| |
| 2067 |
|
| #------------------------------------------------------------------------------- |
| 2068 |
|
| # URL-encoding |
| 2069 |
|
| #------------------------------------------------------------------------------- |
| 2070 |
|
| SV* encode(in, ...) |
| 2071 |
|
| SV *in |
| 2072 |
|
| ALIAS: |
| 2073 |
|
| uri_encode = 1 |
| 2074 |
|
| url_encode = 2 |
| 2075 |
|
| PREINIT: |
| 2076 |
45 |
| SV *temp = NULL; |
| 2077 |
|
| CODE: |
| 2078 |
45 |
▶ | if (items > 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) { |
2 |
43 |
45 |
|
| 2079 |
2 |
| temp = ST(1); |
| 2080 |
|
| } |
| 2081 |
45 |
| RETVAL = encode(aTHX_ in, temp); |
| 2082 |
|
| OUTPUT: |
| 2083 |
|
| RETVAL |
| 2084 |
|
| |
| 2085 |
|
| SV* decode(in) |
| 2086 |
|
| SV* in |
| 2087 |
|
| ALIAS: |
| 2088 |
|
| uri_decode = 1 |
| 2089 |
|
| url_decode = 2 |
| 2090 |
|
| CODE: |
| 2091 |
18 |
| RETVAL = decode(aTHX_ in); |
| 2092 |
|
| OUTPUT: |
| 2093 |
|
| RETVAL |
| 2094 |
|
| |
| 2095 |
|
| #------------------------------------------------------------------------------- |
| 2096 |
|
| # Constructors and destructors |
| 2097 |
|
| #------------------------------------------------------------------------------- |
| 2098 |
|
| void DESTROY(uri_obj) |
| 2099 |
|
| SV *uri_obj |
| 2100 |
|
| CODE: |
| 2101 |
872 |
| DESTROY(aTHX_ uri_obj); |
| 2102 |
|
| |
| 2103 |
|
| SV* new(class, uri_str) |
| 2104 |
|
| const char *class |
| 2105 |
|
| SV* uri_str |
| 2106 |
|
| ALIAS: |
| 2107 |
|
| new_iri = 1 |
| 2108 |
|
| CODE: |
| 2109 |
11 |
▶ | if (ix == 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 1) { |
0 |
11 |
11 |
|
| 2110 |
0 |
| RETVAL = new(aTHX_ "URI::Fast::IRI", uri_str, 1); |
| 2111 |
|
| } else { |
| 2112 |
11 |
| RETVAL = new(aTHX_ class, uri_str, 0); |
| 2113 |
|
| } |
| 2114 |
|
| OUTPUT: |
| 2115 |
|
| RETVAL |
| 2116 |
|
| |
| 2117 |
|
| SV* new_abs(class, rel, base) |
| 2118 |
|
| const char *class |
| 2119 |
|
| SV *rel |
| 2120 |
|
| SV *base |
| 2121 |
|
| PREINIT: |
| 2122 |
|
| SV *abs; |
| 2123 |
|
| CODE: |
| 2124 |
42 |
▶ | if (!sv_isobject(rel) || !sv_derived_from(rel, class)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv_isobject(rel) || !sv_derived_from(rel, class)) { |
0 |
42 |
42 |
| if (!sv_isobject(rel) || !sv_derived_from(rel, class)) { |
0 |
0 |
0 |
|
| 2125 |
42 |
| rel = sv_2mortal(new(aTHX_ class, rel, 0)); |
| 2126 |
|
| } |
| 2127 |
|
| |
| 2128 |
42 |
▶ | if (!sv_isobject(base) || !sv_derived_from(base, class)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv_isobject(base) || !sv_derived_from(base, class)) { |
0 |
42 |
42 |
| if (!sv_isobject(base) || !sv_derived_from(base, class)) { |
0 |
0 |
0 |
|
| 2129 |
42 |
| base = sv_2mortal(new(aTHX_ class, base, 0)); |
| 2130 |
|
| } |
| 2131 |
|
| |
| 2132 |
42 |
| abs = new(aTHX_ class, sv_2mortal(newSVpvn("", 0)), 0); |
| 2133 |
42 |
| absolute(aTHX_ abs, rel, base); |
| 2134 |
42 |
| RETVAL = abs; |
| 2135 |
|
| OUTPUT: |
| 2136 |
|
| RETVAL |
| 2137 |
|
| |
| 2138 |
|
| SV* new_html_url(class, url, ...) |
| 2139 |
|
| const char *class |
| 2140 |
|
| SV *url |
| 2141 |
|
| PREINIT: |
| 2142 |
2 |
| SV *base = NULL; |
| 2143 |
|
| SV *rel; |
| 2144 |
|
| SV *abs; |
| 2145 |
|
| CODE: |
| 2146 |
2 |
▶ | if (items > 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 2) { |
2 |
0 |
2 |
|
| 2147 |
2 |
▶ | if (!sv_isobject(ST(2)) || !sv_derived_from(ST(2), "URI::Fast")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv_isobject(ST(2)) || !sv_derived_from(ST(2), "URI::Fast")) { |
0 |
2 |
2 |
| if (!sv_isobject(ST(2)) || !sv_derived_from(ST(2), "URI::Fast")) { |
0 |
0 |
0 |
|
| 2148 |
2 |
| base = sv_2mortal(new(aTHX_ "URI::Fast", ST(2), 0)); |
| 2149 |
|
| } else { |
| 2150 |
0 |
| base = ST(2); |
| 2151 |
|
| } |
| 2152 |
|
| |
| 2153 |
2 |
| rel = new(aTHX_ "URI::Fast", sv_2mortal(html_url(aTHX_ url, base)), 0); |
| 2154 |
2 |
| abs = new(aTHX_ "URI::Fast", sv_2mortal(newSVpvn("", 0)), 0); |
| 2155 |
2 |
| absolute(aTHX_ abs, sv_2mortal(rel), base); |
| 2156 |
2 |
| normalize(aTHX_ abs); |
| 2157 |
2 |
| RETVAL = abs; |
| 2158 |
|
| } |
| 2159 |
|
| else { |
| 2160 |
0 |
| rel = new(aTHX_ class, sv_2mortal(html_url(aTHX_ url, base)), 0); |
| 2161 |
0 |
| normalize(aTHX_ rel); |
| 2162 |
0 |
| RETVAL = rel; |
| 2163 |
|
| } |
| 2164 |
|
| |
| 2165 |
|
| OUTPUT: |
| 2166 |
|
| RETVAL |
| 2167 |
|
| |
| 2168 |
|
| #------------------------------------------------------------------------------- |
| 2169 |
|
| # Short-hand constructors |
| 2170 |
|
| #------------------------------------------------------------------------------- |
| 2171 |
|
| SV* uri(...) |
| 2172 |
|
| ALIAS: |
| 2173 |
|
| iri = 1 |
| 2174 |
|
| clone = 2 |
| 2175 |
|
| PREINIT: |
| 2176 |
|
| SV *uri_str; |
| 2177 |
|
| CODE: |
| 2178 |
523 |
▶ | if (items == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (items == 0) { |
32 |
491 |
523 |
|
| 2179 |
32 |
| uri_str = sv_2mortal(newSVpvn("", 0)); |
| 2180 |
|
| } else { |
| 2181 |
491 |
| uri_str = ST(0); |
| 2182 |
|
| } |
| 2183 |
|
| |
| 2184 |
523 |
▶ | if (ix == 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix == 1) { |
1 |
522 |
523 |
|
| 2185 |
1 |
| RETVAL = new(aTHX_ "URI::Fast::IRI", uri_str, 1); |
| 2186 |
|
| } else { |
| 2187 |
522 |
| RETVAL = new(aTHX_ "URI::Fast", uri_str, 0); |
| 2188 |
|
| } |
| 2189 |
|
| OUTPUT: |
| 2190 |
|
| RETVAL |
| 2191 |
|
| |
| 2192 |
|
| SV* abs_uri(rel, base) |
| 2193 |
|
| SV *rel |
| 2194 |
|
| SV *base |
| 2195 |
|
| PREINIT: |
| 2196 |
|
| SV *abs; |
| 2197 |
|
| CODE: |
| 2198 |
22 |
▶ | if (!sv_isobject(rel) || !sv_derived_from(rel, "URI::Fast")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv_isobject(rel) || !sv_derived_from(rel, "URI::Fast")) { |
0 |
22 |
22 |
| if (!sv_isobject(rel) || !sv_derived_from(rel, "URI::Fast")) { |
0 |
0 |
0 |
|
| 2199 |
22 |
| rel = sv_2mortal(new(aTHX_ "URI::Fast", rel, 0)); |
| 2200 |
|
| } |
| 2201 |
|
| |
| 2202 |
22 |
▶ | if (!sv_isobject(base) || !sv_derived_from(base, "URI::Fast")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv_isobject(base) || !sv_derived_from(base, "URI::Fast")) { |
0 |
22 |
22 |
| if (!sv_isobject(base) || !sv_derived_from(base, "URI::Fast")) { |
0 |
0 |
0 |
|
| 2203 |
22 |
| base = sv_2mortal(new(aTHX_ "URI::Fast", base, 0)); |
| 2204 |
|
| } |
| 2205 |
|
| |
| 2206 |
22 |
| abs = new(aTHX_ "URI::Fast", sv_2mortal(newSVpvn("", 0)), 0); |
| 2207 |
22 |
| absolute(aTHX_ abs, rel, base); |
| 2208 |
22 |
| RETVAL = abs; |
| 2209 |
|
| OUTPUT: |
| 2210 |
|
| RETVAL |
| 2211 |
|
| |
| 2212 |
|
| SV* html_url(url, ...) |
| 2213 |
|
| SV *url |
| 2214 |
|
| PREINIT: |
| 2215 |
2 |
| SV *base = NULL; |
| 2216 |
|
| SV *abs; |
| 2217 |
|
| SV *rel; |
| 2218 |
|
| CODE: |
| 2219 |
2 |
▶ | if (items > 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) { |
2 |
0 |
2 |
|
| 2220 |
2 |
▶ | if (!sv_isobject(ST(1)) || !sv_derived_from(ST(1), "URI::Fast")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv_isobject(ST(1)) || !sv_derived_from(ST(1), "URI::Fast")) { |
0 |
2 |
2 |
| if (!sv_isobject(ST(1)) || !sv_derived_from(ST(1), "URI::Fast")) { |
0 |
0 |
0 |
|
| 2221 |
2 |
| base = sv_2mortal(new(aTHX_ "URI::Fast", ST(1), 0)); |
| 2222 |
|
| } else { |
| 2223 |
0 |
| base = ST(1); |
| 2224 |
|
| } |
| 2225 |
|
| |
| 2226 |
2 |
| rel = new(aTHX_ "URI::Fast", sv_2mortal(html_url(aTHX_ url, base)), 0); |
| 2227 |
2 |
| abs = new(aTHX_ "URI::Fast", sv_2mortal(newSVpvn("", 0)), 0); |
| 2228 |
2 |
| absolute(aTHX_ abs, sv_2mortal(rel), base); |
| 2229 |
2 |
| normalize(aTHX_ abs); |
| 2230 |
2 |
| RETVAL = abs; |
| 2231 |
|
| } |
| 2232 |
|
| else { |
| 2233 |
0 |
| rel = new(aTHX_ "URI::Fast", sv_2mortal(html_url(aTHX_ url, base)), 0); |
| 2234 |
0 |
| normalize(aTHX_ rel); |
| 2235 |
0 |
| RETVAL = rel; |
| 2236 |
|
| } |
| 2237 |
|
| OUTPUT: |
| 2238 |
|
| RETVAL |
| 2239 |
|
| |
| 2240 |
|
| #------------------------------------------------------------------------------- |
| 2241 |
|
| # Clearers |
| 2242 |
|
| #------------------------------------------------------------------------------- |
| 2243 |
|
| void clear_scheme(uri_obj) |
| 2244 |
|
| SV* uri_obj |
| 2245 |
|
| CODE: |
| 2246 |
8 |
| clear_scheme(aTHX_ uri_obj); |
| 2247 |
|
| |
| 2248 |
|
| void clear_path(uri_obj) |
| 2249 |
|
| SV* uri_obj |
| 2250 |
|
| CODE: |
| 2251 |
1 |
| clear_path(aTHX_ uri_obj); |
| 2252 |
|
| |
| 2253 |
|
| void clear_query (uri_obj) |
| 2254 |
|
| SV* uri_obj |
| 2255 |
|
| CODE: |
| 2256 |
5 |
| clear_query(aTHX_ uri_obj); |
| 2257 |
|
| |
| 2258 |
|
| void clear_frag(uri_obj) |
| 2259 |
|
| SV* uri_obj |
| 2260 |
|
| CODE: |
| 2261 |
1 |
| clear_frag(aTHX_ uri_obj); |
| 2262 |
|
| |
| 2263 |
|
| void clear_usr(uri_obj) |
| 2264 |
|
| SV* uri_obj |
| 2265 |
|
| CODE: |
| 2266 |
1 |
| clear_usr(aTHX_ uri_obj); |
| 2267 |
|
| |
| 2268 |
|
| void clear_pwd(uri_obj) |
| 2269 |
|
| SV* uri_obj |
| 2270 |
|
| CODE: |
| 2271 |
1 |
| clear_pwd(aTHX_ uri_obj); |
| 2272 |
|
| |
| 2273 |
|
| void clear_host(uri_obj) |
| 2274 |
|
| SV* uri_obj |
| 2275 |
|
| CODE: |
| 2276 |
1 |
| clear_host(aTHX_ uri_obj); |
| 2277 |
|
| |
| 2278 |
|
| void clear_port(uri_obj) |
| 2279 |
|
| SV* uri_obj |
| 2280 |
|
| CODE: |
| 2281 |
1 |
| clear_port(aTHX_ uri_obj); |
| 2282 |
|
| |
| 2283 |
|
| void clear_auth(uri_obj) |
| 2284 |
|
| SV* uri_obj |
| 2285 |
|
| CODE: |
| 2286 |
8 |
| clear_auth(aTHX_ uri_obj); |
| 2287 |
|
| |
| 2288 |
|
| #------------------------------------------------------------------------------- |
| 2289 |
|
| # Raw accessors |
| 2290 |
|
| #------------------------------------------------------------------------------- |
| 2291 |
|
| SV* raw_scheme(uri_obj, ...) |
| 2292 |
|
| SV *uri_obj |
| 2293 |
|
| CODE: |
| 2294 |
0 |
▶ | if (items > 1) set_raw_scheme(aTHX_ uri_obj, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_raw_scheme(aTHX_ uri_obj, ST(1)); |
0 |
0 |
0 |
|
| 2295 |
0 |
| RETVAL = get_raw_scheme(aTHX_ uri_obj); |
| 2296 |
|
| OUTPUT: |
| 2297 |
|
| RETVAL |
| 2298 |
|
| |
| 2299 |
|
| SV* raw_auth(uri_obj, ...) |
| 2300 |
|
| SV *uri_obj |
| 2301 |
|
| CODE: |
| 2302 |
1 |
▶ | if (items > 1) set_raw_auth(aTHX_ uri_obj, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_raw_auth(aTHX_ uri_obj, ST(1)); |
0 |
1 |
1 |
|
| 2303 |
1 |
| RETVAL = get_raw_auth(aTHX_ uri_obj); |
| 2304 |
|
| OUTPUT: |
| 2305 |
|
| RETVAL |
| 2306 |
|
| |
| 2307 |
|
| SV* raw_path(uri_obj, ...) |
| 2308 |
|
| SV *uri_obj |
| 2309 |
|
| CODE: |
| 2310 |
2 |
▶ | if (items > 1) set_raw_path(aTHX_ uri_obj, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_raw_path(aTHX_ uri_obj, ST(1)); |
0 |
2 |
2 |
|
| 2311 |
2 |
| RETVAL = get_raw_path(aTHX_ uri_obj); |
| 2312 |
|
| OUTPUT: |
| 2313 |
|
| RETVAL |
| 2314 |
|
| |
| 2315 |
|
| SV* raw_query(uri_obj, ...) |
| 2316 |
|
| SV *uri_obj |
| 2317 |
|
| CODE: |
| 2318 |
2 |
▶ | if (items > 1) set_raw_query(aTHX_ uri_obj, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_raw_query(aTHX_ uri_obj, ST(1)); |
0 |
2 |
2 |
|
| 2319 |
2 |
| RETVAL = get_raw_query(aTHX_ uri_obj); |
| 2320 |
|
| OUTPUT: |
| 2321 |
|
| RETVAL |
| 2322 |
|
| |
| 2323 |
|
| SV* raw_frag(uri_obj, ...) |
| 2324 |
|
| SV *uri_obj |
| 2325 |
|
| CODE: |
| 2326 |
0 |
▶ | if (items > 1) set_raw_frag(aTHX_ uri_obj, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_raw_frag(aTHX_ uri_obj, ST(1)); |
0 |
0 |
0 |
|
| 2327 |
0 |
| RETVAL = get_raw_frag(aTHX_ uri_obj); |
| 2328 |
|
| OUTPUT: |
| 2329 |
|
| RETVAL |
| 2330 |
|
| |
| 2331 |
|
| SV* raw_usr(uri_obj, ...) |
| 2332 |
|
| SV *uri_obj |
| 2333 |
|
| CODE: |
| 2334 |
1 |
▶ | if (items > 1) set_raw_usr(aTHX_ uri_obj, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_raw_usr(aTHX_ uri_obj, ST(1)); |
0 |
1 |
1 |
|
| 2335 |
1 |
| RETVAL = get_raw_usr(aTHX_ uri_obj); |
| 2336 |
|
| OUTPUT: |
| 2337 |
|
| RETVAL |
| 2338 |
|
| |
| 2339 |
|
| SV* raw_pwd(uri_obj, ...) |
| 2340 |
|
| SV *uri_obj |
| 2341 |
|
| CODE: |
| 2342 |
1 |
▶ | if (items > 1) set_raw_pwd(aTHX_ uri_obj, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_raw_pwd(aTHX_ uri_obj, ST(1)); |
0 |
1 |
1 |
|
| 2343 |
1 |
| RETVAL = get_raw_pwd(aTHX_ uri_obj); |
| 2344 |
|
| OUTPUT: |
| 2345 |
|
| RETVAL |
| 2346 |
|
| |
| 2347 |
|
| SV* raw_host(uri_obj, ...) |
| 2348 |
|
| SV *uri_obj |
| 2349 |
|
| CODE: |
| 2350 |
1 |
▶ | if (items > 1) set_raw_host(aTHX_ uri_obj, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_raw_host(aTHX_ uri_obj, ST(1)); |
0 |
1 |
1 |
|
| 2351 |
1 |
| RETVAL = get_raw_host(aTHX_ uri_obj); |
| 2352 |
|
| OUTPUT: |
| 2353 |
|
| RETVAL |
| 2354 |
|
| |
| 2355 |
|
| SV* raw_port(uri_obj, ...) |
| 2356 |
|
| SV *uri_obj |
| 2357 |
|
| CODE: |
| 2358 |
0 |
▶ | if (items > 1) set_raw_port(aTHX_ uri_obj, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_raw_port(aTHX_ uri_obj, ST(1)); |
0 |
0 |
0 |
|
| 2359 |
0 |
| RETVAL = get_raw_port(aTHX_ uri_obj); |
| 2360 |
|
| OUTPUT: |
| 2361 |
|
| RETVAL |
| 2362 |
|
| |
| 2363 |
|
| |
| 2364 |
|
| #------------------------------------------------------------------------------- |
| 2365 |
|
| # Compound getters |
| 2366 |
|
| #------------------------------------------------------------------------------- |
| 2367 |
|
| SV* get_path(uri_obj) |
| 2368 |
|
| SV *uri_obj |
| 2369 |
|
| CODE: |
| 2370 |
22 |
| RETVAL = get_path(aTHX_ uri_obj); |
| 2371 |
|
| OUTPUT: |
| 2372 |
|
| RETVAL |
| 2373 |
|
| |
| 2374 |
|
| SV* get_query(uri_obj) |
| 2375 |
|
| SV *uri_obj |
| 2376 |
|
| CODE: |
| 2377 |
48 |
| RETVAL = get_query(aTHX_ uri_obj); |
| 2378 |
|
| OUTPUT: |
| 2379 |
|
| RETVAL |
| 2380 |
|
| |
| 2381 |
|
| SV* get_auth(uri_obj) |
| 2382 |
|
| SV *uri_obj |
| 2383 |
|
| CODE: |
| 2384 |
20 |
| RETVAL = get_auth(aTHX_ uri_obj); |
| 2385 |
|
| OUTPUT: |
| 2386 |
|
| RETVAL |
| 2387 |
|
| |
| 2388 |
|
| SV* split_path(uri) |
| 2389 |
|
| SV* uri |
| 2390 |
|
| ALIAS: |
| 2391 |
|
| split_path_compat = 1 |
| 2392 |
|
| CODE: |
| 2393 |
103 |
| RETVAL = split_path(aTHX_ uri, ix == 1 ? 1 : 0); |
| 2394 |
|
| OUTPUT: |
| 2395 |
|
| RETVAL |
| 2396 |
|
| |
| 2397 |
|
| SV* get_query_keys(uri) |
| 2398 |
|
| SV* uri |
| 2399 |
|
| CODE: |
| 2400 |
13 |
| RETVAL = get_query_keys(aTHX_ uri); |
| 2401 |
|
| OUTPUT: |
| 2402 |
|
| RETVAL |
| 2403 |
|
| |
| 2404 |
|
| SV* get_query_hash(uri) |
| 2405 |
|
| SV* uri |
| 2406 |
|
| CODE: |
| 2407 |
66 |
| RETVAL = query_hash(aTHX_ uri); |
| 2408 |
|
| OUTPUT: |
| 2409 |
|
| RETVAL |
| 2410 |
|
| |
| 2411 |
|
| SV* get_param(uri, sv_key) |
| 2412 |
|
| SV* uri |
| 2413 |
|
| SV* sv_key |
| 2414 |
|
| CODE: |
| 2415 |
72 |
| RETVAL = get_param(aTHX_ uri, sv_key); |
| 2416 |
|
| OUTPUT: |
| 2417 |
|
| RETVAL |
| 2418 |
|
| |
| 2419 |
|
| |
| 2420 |
|
| #------------------------------------------------------------------------------- |
| 2421 |
|
| # Compound setters |
| 2422 |
|
| #------------------------------------------------------------------------------- |
| 2423 |
|
| void set_auth(uri_obj, value) |
| 2424 |
|
| SV *uri_obj |
| 2425 |
|
| SV *value |
| 2426 |
|
| CODE: |
| 2427 |
12 |
| set_auth(aTHX_ uri_obj, value); |
| 2428 |
|
| |
| 2429 |
|
| void set_path(uri_obj, value) |
| 2430 |
|
| SV *uri_obj |
| 2431 |
|
| SV *value |
| 2432 |
|
| CODE: |
| 2433 |
23 |
| set_path(aTHX_ uri_obj, value); |
| 2434 |
|
| |
| 2435 |
|
| void set_path_array(uri_obj, segments) |
| 2436 |
|
| SV *uri_obj |
| 2437 |
|
| SV *segments |
| 2438 |
|
| CODE: |
| 2439 |
12 |
| set_path_array(aTHX_ uri_obj, segments); |
| 2440 |
|
| |
| 2441 |
|
| void set_query(uri_obj, value) |
| 2442 |
|
| SV *uri_obj |
| 2443 |
|
| SV *value |
| 2444 |
|
| CODE: |
| 2445 |
9 |
| set_query(aTHX_ uri_obj, value); |
| 2446 |
|
| |
| 2447 |
|
| void set_param(uri, sv_key, sv_values, sv_separator) |
| 2448 |
|
| SV *uri |
| 2449 |
|
| SV *sv_key |
| 2450 |
|
| SV *sv_values |
| 2451 |
|
| SV *sv_separator |
| 2452 |
|
| CODE: |
| 2453 |
66 |
| set_param(aTHX_ uri, sv_key, sv_values, sv_separator); |
| 2454 |
|
| |
| 2455 |
|
| void query_keyset(self, sv_key_set, ...) |
| 2456 |
|
| SV *self |
| 2457 |
|
| SV *sv_key_set |
| 2458 |
|
| CODE: |
| 2459 |
11 |
▶ | SV *sv_separator = items > 2 ? ST(2) : sv_2mortal(newSVpvn("&", 1)); |
Branch: 1 branch
| Branch | True | False | Total |
| SV *sv_separator = items > 2 ? ST(2) : sv_2mortal(newSVpvn("&", 1)); |
2 |
9 |
11 |
|
| 2460 |
11 |
| update_query_keyset(aTHX_ self, sv_key_set, sv_separator); |
| 2461 |
|
| |
| 2462 |
|
| |
| 2463 |
|
| #------------------------------------------------------------------------------- |
| 2464 |
|
| # Unified accessors |
| 2465 |
|
| #------------------------------------------------------------------------------- |
| 2466 |
|
| SV* scheme(self, ...) |
| 2467 |
|
| SV *self |
| 2468 |
|
| CODE: |
| 2469 |
138 |
▶ | if (items > 1) set_scheme(aTHX_ self, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_scheme(aTHX_ self, ST(1)); |
9 |
129 |
138 |
|
| 2470 |
138 |
| RETVAL = get_scheme(aTHX_ self); |
| 2471 |
|
| OUTPUT: |
| 2472 |
|
| RETVAL |
| 2473 |
|
| |
| 2474 |
|
| SV* usr(self, ...) |
| 2475 |
|
| SV *self |
| 2476 |
|
| CODE: |
| 2477 |
110 |
▶ | if (items > 1) set_usr(aTHX_ self, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_usr(aTHX_ self, ST(1)); |
6 |
104 |
110 |
|
| 2478 |
110 |
| RETVAL = get_usr(aTHX_ self); |
| 2479 |
|
| OUTPUT: |
| 2480 |
|
| RETVAL |
| 2481 |
|
| |
| 2482 |
|
| SV* pwd(self, ...) |
| 2483 |
|
| SV *self |
| 2484 |
|
| CODE: |
| 2485 |
109 |
▶ | if (items > 1) set_pwd(aTHX_ self, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_pwd(aTHX_ self, ST(1)); |
5 |
104 |
109 |
|
| 2486 |
109 |
| RETVAL = get_pwd(aTHX_ self); |
| 2487 |
|
| OUTPUT: |
| 2488 |
|
| RETVAL |
| 2489 |
|
| |
| 2490 |
|
| SV* host(self, ...) |
| 2491 |
|
| SV *self |
| 2492 |
|
| CODE: |
| 2493 |
116 |
▶ | if (items > 1) set_host(aTHX_ self, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_host(aTHX_ self, ST(1)); |
7 |
109 |
116 |
|
| 2494 |
116 |
| RETVAL = get_host(aTHX_ self); |
| 2495 |
|
| OUTPUT: |
| 2496 |
|
| RETVAL |
| 2497 |
|
| |
| 2498 |
|
| SV* port(self, ...) |
| 2499 |
|
| SV *self |
| 2500 |
|
| CODE: |
| 2501 |
108 |
▶ | if (items > 1) set_port(aTHX_ self, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_port(aTHX_ self, ST(1)); |
5 |
103 |
108 |
|
| 2502 |
108 |
| RETVAL = get_port(aTHX_ self); |
| 2503 |
|
| OUTPUT: |
| 2504 |
|
| RETVAL |
| 2505 |
|
| |
| 2506 |
|
| SV* frag(self, ...) |
| 2507 |
|
| SV *self |
| 2508 |
|
| ALIAS: |
| 2509 |
|
| fragment = 1 |
| 2510 |
|
| CODE: |
| 2511 |
112 |
▶ | if (items > 1) set_frag(aTHX_ self, ST(1)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 1) set_frag(aTHX_ self, ST(1)); |
10 |
102 |
112 |
|
| 2512 |
112 |
| RETVAL = get_frag(aTHX_ self); |
| 2513 |
|
| OUTPUT: |
| 2514 |
|
| RETVAL |
| 2515 |
|
| |
| 2516 |
|
| |
| 2517 |
|
| #------------------------------------------------------------------------------- |
| 2518 |
|
| # Extras |
| 2519 |
|
| #------------------------------------------------------------------------------- |
| 2520 |
|
| SV* to_string(self, ...) |
| 2521 |
|
| SV *self |
| 2522 |
|
| ALIAS: |
| 2523 |
|
| as_string = 1 |
| 2524 |
|
| TO_JSON = 2 |
| 2525 |
|
| OVERLOAD: |
| 2526 |
|
| to_string \"\" |
| 2527 |
|
| CODE: |
| 2528 |
245 |
| RETVAL = to_string(aTHX_ self); |
| 2529 |
|
| OUTPUT: |
| 2530 |
|
| RETVAL |
| 2531 |
|
| |
| 2532 |
|
| SV* normalize(uri) |
| 2533 |
|
| SV *uri |
| 2534 |
|
| ALIAS: |
| 2535 |
|
| canonical = 1 |
| 2536 |
|
| CODE: |
| 2537 |
13 |
| normalize(aTHX_ uri); |
| 2538 |
|
| OUTPUT: |
| 2539 |
|
| uri |
| 2540 |
|
| |
| 2541 |
|
| SV* absolute(rel, base) |
| 2542 |
|
| SV* rel |
| 2543 |
|
| SV* base |
| 2544 |
|
| ALIAS: |
| 2545 |
|
| abs = 1 |
| 2546 |
|
| PREINIT: |
| 2547 |
|
| SV *abs; |
| 2548 |
|
| const char *class; |
| 2549 |
|
| CODE: |
| 2550 |
131 |
| class = class_name(aTHX_ rel); |
| 2551 |
131 |
| abs = new(aTHX_ class, sv_2mortal(newSVpvn("", 0)), 0); |
| 2552 |
|
| |
| 2553 |
131 |
▶ | if (!sv_isobject(base) || !sv_derived_from(base, class)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv_isobject(base) || !sv_derived_from(base, class)) { |
128 |
3 |
131 |
| if (!sv_isobject(base) || !sv_derived_from(base, class)) { |
0 |
128 |
128 |
|
| 2554 |
3 |
| base = sv_2mortal(new(aTHX_ class, base, 0)); |
| 2555 |
|
| } |
| 2556 |
|
| |
| 2557 |
131 |
| absolute(aTHX_ abs, rel, base); |
| 2558 |
|
| |
| 2559 |
131 |
| RETVAL = abs; |
| 2560 |
|
| OUTPUT: |
| 2561 |
|
| RETVAL |
| 2562 |
|
| |
| 2563 |
|
| void explain(uri_obj) |
| 2564 |
|
| SV* uri_obj |
| 2565 |
|
| CODE: |
| 2566 |
0 |
| explain(aTHX_ uri_obj); |
| 2567 |
|
| |
| 2568 |
|
| void debug(uri_obj) |
| 2569 |
|
| SV* uri_obj |
| 2570 |
|
| CODE: |
| 2571 |
0 |
| debug(aTHX_ uri_obj); |
| 2572 |
|
| |
| 2573 |
|
| void uri_split(uri) |
| 2574 |
|
| SV* uri |
| 2575 |
|
| PREINIT: |
| 2576 |
|
| I32* temp; |
| 2577 |
|
| PPCODE: |
| 2578 |
28 |
| temp = PL_markstack_ptr++; |
| 2579 |
28 |
| uri_split(aTHX_ uri); |
| 2580 |
|
| |
| 2581 |
28 |
▶ | if (PL_markstack_ptr != temp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (PL_markstack_ptr != temp) { |
0 |
28 |
28 |
|
| 2582 |
0 |
| PL_markstack_ptr = temp; |
| 2583 |
0 |
| XSRETURN_EMPTY; |
| 2584 |
|
| } |
| 2585 |
|
| |
| 2586 |
28 |
| return; |