| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| #define NEED_sv_2pv_flags |
| 6 |
|
| #include "ppport.h" |
| 7 |
|
| |
| 8 |
|
| static SV * |
| 9 |
259 |
| url_decode(pTHX_ const char *s, const STRLEN len, SV *dsv) { |
| 10 |
|
| #define __ 0xFF |
| 11 |
|
| static const U8 hexval[0x100] = { |
| 12 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* 00-0F */ |
| 13 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* 10-1F */ |
| 14 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* 20-2F */ |
| 15 |
|
| 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,__,__,__,__,__,__, /* 30-3F */ |
| 16 |
|
| __,10,11,12,13,14,15,__,__,__,__,__,__,__,__,__, /* 40-4F */ |
| 17 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* 50-5F */ |
| 18 |
|
| __,10,11,12,13,14,15,__,__,__,__,__,__,__,__,__, /* 60-6F */ |
| 19 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* 70-7F */ |
| 20 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* 80-8F */ |
| 21 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* 90-9F */ |
| 22 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* A0-AF */ |
| 23 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* B0-BF */ |
| 24 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* C0-CF */ |
| 25 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* D0-DF */ |
| 26 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* E0-EF */ |
| 27 |
|
| __,__,__,__,__,__,__,__,__,__,__,__,__,__,__,__, /* F0-FF */ |
| 28 |
|
| }; |
| 29 |
|
| #undef __ |
| 30 |
|
| const char *e; |
| 31 |
|
| char *d; |
| 32 |
|
| |
| 33 |
259 |
▶ | if (!dsv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!dsv) |
9 |
250 |
259 |
|
| 34 |
9 |
| dsv = sv_newmortal(); |
| 35 |
|
| |
| 36 |
259 |
▶ | SvUPGRADE(dsv, SVt_PV); |
Branch: 1 branch
| Branch | True | False | Total |
| SvUPGRADE(dsv, SVt_PV); |
67 |
192 |
259 |
|
| 37 |
259 |
▶ | d = SvGROW(dsv, len + 1); |
Branch: 2 branches
| Branch | True | False | Total |
| d = SvGROW(dsv, len + 1); |
258 |
1 |
259 |
| d = SvGROW(dsv, len + 1); |
68 |
190 |
258 |
|
| 38 |
|
| |
| 39 |
259 |
| e = s + len - 2; |
| 40 |
583 |
▶ | for (; s < e; s++, d++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (; s < e; s++, d++) { |
324 |
259 |
583 |
|
| 41 |
324 |
| const U8 c = *s; |
| 42 |
324 |
▶ | if (c == '+') |
Branch: 1 branch
| Branch | True | False | Total |
| if (c == '+') |
10 |
314 |
324 |
|
| 43 |
10 |
| *d = ' '; |
| 44 |
314 |
▶ | else if (c != '%') |
Branch: 1 branch
| Branch | True | False | Total |
| else if (c != '%') |
95 |
219 |
314 |
|
| 45 |
95 |
| *d = c; |
| 46 |
|
| else { |
| 47 |
219 |
| const U8 v1 = hexval[(U8)*++s]; |
| 48 |
219 |
| const U8 v2 = hexval[(U8)*++s]; |
| 49 |
219 |
▶ | if ((v1 | v2) != 0xFF) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((v1 | v2) != 0xFF) |
219 |
0 |
219 |
|
| 50 |
219 |
| *d = (v1 << 4) | v2; |
| 51 |
|
| else |
| 52 |
0 |
| *d = c, s -= 2; |
| 53 |
|
| } |
| 54 |
|
| } |
| 55 |
|
| |
| 56 |
259 |
| e += 2; |
| 57 |
313 |
▶ | for (; s < e; s++, d++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (; s < e; s++, d++) { |
54 |
259 |
313 |
|
| 58 |
54 |
| const U8 c = *s; |
| 59 |
54 |
▶ | if (c == '+') |
Branch: 1 branch
| Branch | True | False | Total |
| if (c == '+') |
7 |
47 |
54 |
|
| 60 |
7 |
| *d = ' '; |
| 61 |
|
| else |
| 62 |
47 |
| *d = c; |
| 63 |
|
| } |
| 64 |
|
| |
| 65 |
259 |
| *d = 0; |
| 66 |
259 |
| SvCUR_set(dsv, d - SvPVX(dsv)); |
| 67 |
259 |
| SvPOK_only(dsv); |
| 68 |
259 |
| return dsv; |
| 69 |
|
| } |
| 70 |
|
| |
| 71 |
|
| static SV * |
| 72 |
1 |
| url_decode_utf8(pTHX_ const char *s, const STRLEN len, SV *dsv) { |
| 73 |
1 |
| dsv = url_decode(aTHX_ s, len, dsv); |
| 74 |
1 |
▶ | if (!sv_utf8_decode(dsv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv_utf8_decode(dsv)) |
0 |
1 |
1 |
|
| 75 |
0 |
| croak("Malformed UTF-8 in URL decoded string"); |
| 76 |
1 |
| return dsv; |
| 77 |
|
| } |
| 78 |
|
| |
| 79 |
|
| static SV * |
| 80 |
195 |
| url_encode(pTHX_ const char *s, const STRLEN len, SV *dsv) { |
| 81 |
|
| static const char xdigit[0x10] = "0123456789ABCDEF"; |
| 82 |
|
| static const U8 url_unreserved[0x100] = { |
| 83 |
|
| 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x00-0x0F */ |
| 84 |
|
| 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x10-0x1F */ |
| 85 |
|
| 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0, /* 0x20-0x2F */ |
| 86 |
|
| 1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0, /* 0x30-0x3F */ |
| 87 |
|
| 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0x40-0x4F */ |
| 88 |
|
| 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, /* 0x50-0x5F */ |
| 89 |
|
| 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0x60-0x6F */ |
| 90 |
|
| 1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0, /* 0x70-0x7F */ |
| 91 |
|
| 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x80-0x8F */ |
| 92 |
|
| 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x90-0x9F */ |
| 93 |
|
| 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xA0-0xAF */ |
| 94 |
|
| 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xB0-0xBF */ |
| 95 |
|
| 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xC0-0xCF */ |
| 96 |
|
| 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xD0-0xDF */ |
| 97 |
|
| 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xE0-0xEF */ |
| 98 |
|
| 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xF0-0xFF */ |
| 99 |
|
| }; |
| 100 |
195 |
| const char *e = s + len; |
| 101 |
|
| char *d; |
| 102 |
|
| |
| 103 |
195 |
▶ | if (!dsv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!dsv) |
0 |
195 |
195 |
|
| 104 |
0 |
| dsv = sv_newmortal(); |
| 105 |
|
| |
| 106 |
195 |
▶ | SvUPGRADE(dsv, SVt_PV); |
Branch: 1 branch
| Branch | True | False | Total |
| SvUPGRADE(dsv, SVt_PV); |
3 |
192 |
195 |
|
| 107 |
195 |
▶ | d = SvGROW(dsv, len * 3 + 1); |
Branch: 2 branches
| Branch | True | False | Total |
| d = SvGROW(dsv, len * 3 + 1); |
195 |
0 |
195 |
| d = SvGROW(dsv, len * 3 + 1); |
4 |
191 |
195 |
|
| 108 |
|
| |
| 109 |
486 |
▶ | for (; s < e; s++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (; s < e; s++) { |
291 |
195 |
486 |
|
| 110 |
291 |
| const U8 c = *s; |
| 111 |
291 |
▶ | if (url_unreserved[c]) |
Branch: 1 branch
| Branch | True | False | Total |
| if (url_unreserved[c]) |
82 |
209 |
291 |
|
| 112 |
82 |
| *d++ = *s; |
| 113 |
209 |
▶ | else if (c == ' ') |
Branch: 1 branch
| Branch | True | False | Total |
| else if (c == ' ') |
5 |
204 |
209 |
|
| 114 |
5 |
| *d++ = '+'; |
| 115 |
|
| else { |
| 116 |
204 |
| *d++ = '%'; |
| 117 |
204 |
| *d++ = xdigit[c >> 4]; |
| 118 |
204 |
| *d++ = xdigit[c & 15]; |
| 119 |
|
| } |
| 120 |
|
| } |
| 121 |
195 |
| *d = 0; |
| 122 |
195 |
| SvCUR_set(dsv, d - SvPVX(dsv)); |
| 123 |
195 |
| SvPOK_only(dsv); |
| 124 |
195 |
| return dsv; |
| 125 |
|
| } |
| 126 |
|
| |
| 127 |
|
| static bool |
| 128 |
118 |
| url_encoded(const char *s, const STRLEN len) { |
| 129 |
118 |
| const char *e = s + len; |
| 130 |
218 |
▶ | for (; s < e; s++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (; s < e; s++) { |
109 |
109 |
218 |
|
| 131 |
109 |
▶ | switch (*s) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch (*s) { |
9 |
100 |
109 |
|
| 132 |
9 |
| case '+': |
| 133 |
|
| case '%': |
| 134 |
9 |
| return TRUE; |
| 135 |
|
| } |
| 136 |
|
| } |
| 137 |
109 |
| return FALSE; |
| 138 |
|
| } |
| 139 |
|
| |
| 140 |
|
| typedef struct _ust ust_t; |
| 141 |
|
| struct _ust { |
| 142 |
|
| SV * (*decode) (pTHX_ const char *, const STRLEN, SV *); |
| 143 |
|
| void (*cb) (pTHX_ const ust_t *, const char *, STRLEN, bool, const char *, STRLEN); |
| 144 |
|
| SV *sv; |
| 145 |
|
| }; |
| 146 |
|
| |
| 147 |
|
| static void |
| 148 |
69 |
| url_params_each(pTHX_ const char *cur, const STRLEN len, const ust_t *u) { |
| 149 |
69 |
| const char * const end = cur + len; |
| 150 |
|
| const char *key, *val; |
| 151 |
|
| STRLEN klen, vlen; |
| 152 |
69 |
| SV *tmpsv = NULL; |
| 153 |
69 |
| bool is_utf8 = FALSE; |
| 154 |
|
| |
| 155 |
187 |
▶ | while (cur < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (cur < end) { |
118 |
69 |
187 |
|
| 156 |
254 |
▶ | for (key = cur; cur < end; cur++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (key = cur; cur < end; cur++) { |
234 |
20 |
254 |
|
| 157 |
234 |
| const char c = *cur; |
| 158 |
234 |
▶ | if (c == '=' || c == '&' || c == ';') |
Branch: 3 branches
| Branch | True | False | Total |
| if (c == '=' || c == '&' || c == ';') |
180 |
54 |
234 |
| if (c == '=' || c == '&' || c == ';') |
158 |
22 |
180 |
| if (c == '=' || c == '&' || c == ';') |
136 |
22 |
158 |
|
| 159 |
|
| break; |
| 160 |
|
| } |
| 161 |
118 |
| klen = cur - key; |
| 162 |
118 |
▶ | if (*cur != '=') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*cur != '=') { |
64 |
54 |
118 |
|
| 163 |
64 |
| val = NULL; |
| 164 |
64 |
| vlen = 0; |
| 165 |
|
| } |
| 166 |
|
| else { |
| 167 |
120 |
▶ | for (val = ++cur; cur < end; cur++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (val = ++cur; cur < end; cur++) { |
86 |
34 |
120 |
|
| 168 |
86 |
| const char c = *cur; |
| 169 |
86 |
▶ | if (c == '&' || c == ';') |
Branch: 2 branches
| Branch | True | False | Total |
| if (c == '&' || c == ';') |
75 |
11 |
86 |
| if (c == '&' || c == ';') |
66 |
9 |
75 |
|
| 170 |
|
| break; |
| 171 |
|
| } |
| 172 |
54 |
| vlen = cur - val; |
| 173 |
|
| } |
| 174 |
|
| |
| 175 |
118 |
▶ | if (u->decode == &url_decode_utf8 || url_encoded(key, klen)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (u->decode == &url_decode_utf8 || url_encoded(key, klen)) { |
118 |
0 |
118 |
| if (u->decode == &url_decode_utf8 || url_encoded(key, klen)) { |
9 |
109 |
118 |
|
| 176 |
9 |
| tmpsv = u->decode(aTHX_ key, klen, tmpsv); |
| 177 |
9 |
| key = (const char *)SvPVX(tmpsv); |
| 178 |
9 |
| klen = SvCUR(tmpsv); |
| 179 |
9 |
▶ | if (u->decode == &url_decode_utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (u->decode == &url_decode_utf8) |
0 |
9 |
9 |
|
| 180 |
0 |
| is_utf8 = SvUTF8(tmpsv); |
| 181 |
|
| } |
| 182 |
118 |
| u->cb(aTHX_ u, key, klen, is_utf8, val, vlen); |
| 183 |
118 |
| cur++; |
| 184 |
|
| } |
| 185 |
|
| |
| 186 |
69 |
▶ | if (len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len) { |
66 |
3 |
69 |
|
| 187 |
66 |
| const char c = end[-1]; |
| 188 |
66 |
▶ | if (c == '&' || c == ';') |
Branch: 2 branches
| Branch | True | False | Total |
| if (c == '&' || c == ';') |
60 |
6 |
66 |
| if (c == '&' || c == ';') |
6 |
54 |
60 |
|
| 189 |
12 |
| u->cb(aTHX_ u, "", 0, FALSE, NULL, 0); |
| 190 |
|
| } |
| 191 |
69 |
| } |
| 192 |
|
| |
| 193 |
|
| static void |
| 194 |
47 |
| url_params_mixed_cb(pTHX_ const ust_t *u, const char *k, STRLEN klen, bool is_utf8, const char *v, STRLEN vlen) { |
| 195 |
|
| SV **svp, *sv; |
| 196 |
|
| |
| 197 |
47 |
▶ | if (!hv_exists((HV *)u->sv, k, is_utf8 ? -klen : klen)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!hv_exists((HV *)u->sv, k, is_utf8 ? -klen : klen)) { |
0 |
47 |
47 |
| if (!hv_exists((HV *)u->sv, k, is_utf8 ? -klen : klen)) { |
33 |
14 |
47 |
|
| 198 |
33 |
▶ | svp = hv_fetch((HV *)u->sv, k, is_utf8 ? -klen : klen, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| svp = hv_fetch((HV *)u->sv, k, is_utf8 ? -klen : klen, 1); |
0 |
33 |
33 |
|
| 199 |
33 |
▶ | if (v) |
Branch: 1 branch
| Branch | True | False | Total |
| if (v) |
13 |
20 |
33 |
|
| 200 |
13 |
| u->decode(aTHX_ v, vlen, *svp); |
| 201 |
|
| } |
| 202 |
|
| else { |
| 203 |
14 |
| SV *val = newSV(0); |
| 204 |
|
| AV *av; |
| 205 |
|
| |
| 206 |
14 |
▶ | svp = hv_fetch((HV *)u->sv, k, is_utf8 ? -klen : klen, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| svp = hv_fetch((HV *)u->sv, k, is_utf8 ? -klen : klen, 0); |
0 |
14 |
14 |
|
| 207 |
14 |
▶ | if (SvROK(*svp)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(*svp)) |
0 |
14 |
14 |
|
| 208 |
0 |
| av = (AV *)SvRV(*svp); |
| 209 |
|
| else { |
| 210 |
14 |
| sv = *svp; |
| 211 |
14 |
| av = newAV(); |
| 212 |
14 |
| *svp = newRV_noinc((SV *)av); |
| 213 |
14 |
| av_push(av, sv); |
| 214 |
|
| } |
| 215 |
14 |
| av_push(av, val); |
| 216 |
14 |
▶ | if (v) |
Branch: 1 branch
| Branch | True | False | Total |
| if (v) |
4 |
10 |
14 |
|
| 217 |
4 |
| u->decode(aTHX_ v, vlen, val); |
| 218 |
|
| } |
| 219 |
47 |
| } |
| 220 |
|
| |
| 221 |
|
| static void |
| 222 |
47 |
| url_params_multi_cb(pTHX_ const ust_t *u, const char *k, STRLEN klen, bool is_utf8, const char *v, STRLEN vlen) { |
| 223 |
|
| SV **svp, *val; |
| 224 |
|
| AV *av; |
| 225 |
|
| |
| 226 |
47 |
▶ | svp = hv_fetch((HV *)u->sv, k, is_utf8 ? -klen : klen, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| svp = hv_fetch((HV *)u->sv, k, is_utf8 ? -klen : klen, 1); |
0 |
47 |
47 |
|
| 227 |
47 |
| val = newSV(0); |
| 228 |
|
| |
| 229 |
47 |
▶ | if (SvROK(*svp)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(*svp)) |
14 |
33 |
47 |
|
| 230 |
14 |
| av = (AV *)SvRV(*svp); |
| 231 |
|
| else { |
| 232 |
33 |
| av = newAV(); |
| 233 |
33 |
| SvREFCNT_dec(*svp); |
| 234 |
33 |
| *svp = newRV_noinc((SV *)av); |
| 235 |
|
| } |
| 236 |
47 |
| av_push(av, val); |
| 237 |
47 |
▶ | if (v) |
Branch: 1 branch
| Branch | True | False | Total |
| if (v) |
17 |
30 |
47 |
|
| 238 |
17 |
| u->decode(aTHX_ v, vlen, val); |
| 239 |
47 |
| } |
| 240 |
|
| |
| 241 |
|
| static void |
| 242 |
33 |
| url_params_flat_cb(pTHX_ const ust_t *u, const char *k, STRLEN klen, bool is_utf8, const char *v, STRLEN vlen) { |
| 243 |
|
| SV *key, *val; |
| 244 |
|
| |
| 245 |
33 |
| key = newSVpvn(k, klen); |
| 246 |
33 |
| val = newSV(0); |
| 247 |
|
| |
| 248 |
33 |
▶ | if (is_utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_utf8) |
0 |
33 |
33 |
|
| 249 |
0 |
| SvUTF8_on(key); |
| 250 |
|
| |
| 251 |
33 |
| av_push((AV *)u->sv, key); |
| 252 |
33 |
| av_push((AV *)u->sv, val); |
| 253 |
33 |
▶ | if (v) |
Branch: 1 branch
| Branch | True | False | Total |
| if (v) |
17 |
16 |
33 |
|
| 254 |
17 |
| u->decode(aTHX_ v, vlen, val); |
| 255 |
33 |
| } |
| 256 |
|
| |
| 257 |
|
| static void |
| 258 |
3 |
| url_params_each_cb(pTHX_ const ust_t *u, const char *k, STRLEN klen, bool is_utf8, const char *v, STRLEN vlen) { |
| 259 |
|
| SV *key, *val; |
| 260 |
3 |
| dSP; |
| 261 |
|
| |
| 262 |
3 |
| key = sv_2mortal(newSVpvn(k, klen)); |
| 263 |
3 |
| val = sv_2mortal(newSV(0)); |
| 264 |
|
| |
| 265 |
3 |
▶ | if (v) |
Branch: 1 branch
| Branch | True | False | Total |
| if (v) |
3 |
0 |
3 |
|
| 266 |
3 |
| u->decode(aTHX_ v, vlen, val); |
| 267 |
|
| |
| 268 |
3 |
▶ | if (is_utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_utf8) |
0 |
3 |
3 |
|
| 269 |
0 |
| SvUTF8_on(key); |
| 270 |
|
| |
| 271 |
3 |
| ENTER; |
| 272 |
3 |
| SAVETMPS; |
| 273 |
|
| |
| 274 |
3 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
3 |
3 |
|
| 275 |
3 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
3 |
3 |
|
| 276 |
3 |
| PUSHs(key); |
| 277 |
3 |
| PUSHs(val); |
| 278 |
3 |
| PUTBACK; |
| 279 |
|
| |
| 280 |
3 |
| call_sv(u->sv, G_DISCARD); |
| 281 |
|
| |
| 282 |
3 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
0 |
3 |
3 |
|
| 283 |
3 |
| LEAVE; |
| 284 |
3 |
| } |
| 285 |
|
| |
| 286 |
|
| |
| 287 |
|
| MODULE = URL::Encode::XS PACKAGE = URL::Encode::XS |
| 288 |
|
| |
| 289 |
|
| PROTOTYPES: DISABLE |
| 290 |
|
| |
| 291 |
|
| void |
| 292 |
|
| url_decode(octets) |
| 293 |
|
| SV *octets |
| 294 |
|
| ALIAS: |
| 295 |
|
| URL::Encode::XS::url_decode = 0 |
| 296 |
|
| URL::Encode::XS::url_decode_utf8 = 1 |
| 297 |
|
| URL::Encode::XS::url_encode = 2 |
| 298 |
|
| PREINIT: |
| 299 |
390 |
▶ | dXSTARG; |
Branch: 1 branch
| Branch | True | False | Total |
| dXSTARG; |
390 |
0 |
390 |
|
| 300 |
|
| const char *s; |
| 301 |
|
| STRLEN len; |
| 302 |
|
| PPCODE: |
| 303 |
390 |
| SvGETMAGIC(octets); |
| 304 |
390 |
▶ | if (SvUTF8(octets)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(octets)) { |
1 |
389 |
390 |
|
| 305 |
1 |
| octets = sv_mortalcopy(octets); |
| 306 |
1 |
▶ | if (!sv_utf8_downgrade(octets, 1)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv_utf8_downgrade(octets, 1)) |
0 |
1 |
1 |
|
| 307 |
0 |
| croak("Wide character in octet string"); |
| 308 |
|
| } |
| 309 |
390 |
| s = SvPV_nomg_const(octets, len); |
| 310 |
390 |
| switch (ix) { |
| 311 |
195 |
| case 0: |
| 312 |
195 |
| url_decode(aTHX_ s, len, TARG); |
| 313 |
195 |
| break; |
| 314 |
1 |
| case 1: |
| 315 |
1 |
| url_decode_utf8(aTHX_ s, len, TARG); |
| 316 |
1 |
| break; |
| 317 |
194 |
| case 2: |
| 318 |
194 |
| url_encode(aTHX_ s, len, TARG); |
| 319 |
194 |
| break; |
| 320 |
|
| } |
| 321 |
390 |
▶ | PUSHTARG; |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHTARG; |
0 |
390 |
390 |
|
| 322 |
|
| |
| 323 |
|
| void |
| 324 |
|
| url_encode_utf8(string) |
| 325 |
|
| SV *string |
| 326 |
|
| PREINIT: |
| 327 |
1 |
▶ | dXSTARG; |
Branch: 1 branch
| Branch | True | False | Total |
| dXSTARG; |
1 |
0 |
1 |
|
| 328 |
|
| const char *s; |
| 329 |
|
| STRLEN len; |
| 330 |
|
| PPCODE: |
| 331 |
1 |
| SvGETMAGIC(string); |
| 332 |
1 |
▶ | if (!SvUTF8(string)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvUTF8(string)) { |
0 |
1 |
1 |
|
| 333 |
0 |
| string = sv_mortalcopy(string); |
| 334 |
0 |
| sv_utf8_encode(string); |
| 335 |
|
| } |
| 336 |
1 |
| s = SvPV_nomg_const(string, len); |
| 337 |
1 |
| url_encode(aTHX_ s, len, TARG); |
| 338 |
1 |
▶ | PUSHTARG; |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHTARG; |
0 |
1 |
1 |
|
| 339 |
|
| |
| 340 |
|
| void |
| 341 |
|
| url_params_flat(octets, utf8=FALSE) |
| 342 |
|
| SV *octets |
| 343 |
|
| bool utf8 |
| 344 |
|
| ALIAS: |
| 345 |
|
| URL::Encode::XS::url_params_flat = 0 |
| 346 |
|
| URL::Encode::XS::url_params_mixed = 1 |
| 347 |
|
| URL::Encode::XS::url_params_multi = 2 |
| 348 |
|
| PREINIT: |
| 349 |
|
| const char *s; |
| 350 |
|
| STRLEN len; |
| 351 |
|
| ust_t u; |
| 352 |
|
| PPCODE: |
| 353 |
68 |
| SvGETMAGIC(octets); |
| 354 |
68 |
▶ | if (SvUTF8(octets)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(octets)) { |
0 |
68 |
68 |
|
| 355 |
0 |
| octets = sv_mortalcopy(octets); |
| 356 |
0 |
▶ | if (!sv_utf8_downgrade(octets, 1)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv_utf8_downgrade(octets, 1)) |
0 |
0 |
0 |
|
| 357 |
0 |
| croak("Wide character in octet string"); |
| 358 |
|
| } |
| 359 |
|
| |
| 360 |
68 |
▶ | u.decode = utf8 ? &url_decode_utf8 : &url_decode; |
Branch: 1 branch
| Branch | True | False | Total |
| u.decode = utf8 ? &url_decode_utf8 : &url_decode; |
0 |
68 |
68 |
|
| 361 |
68 |
| switch(ix) { |
| 362 |
20 |
| case 0: |
| 363 |
20 |
| u.cb = &url_params_flat_cb; |
| 364 |
20 |
| u.sv = (SV *)newAV(); |
| 365 |
20 |
| break; |
| 366 |
24 |
| case 1: |
| 367 |
24 |
| u.cb = &url_params_mixed_cb; |
| 368 |
24 |
| u.sv = (SV *)newHV(); |
| 369 |
24 |
| break; |
| 370 |
24 |
| case 2: |
| 371 |
24 |
| u.cb = &url_params_multi_cb; |
| 372 |
24 |
| u.sv = (SV *)newHV(); |
| 373 |
24 |
| break; |
| 374 |
|
| } |
| 375 |
68 |
| s = SvPV_nomg_const(octets, len); |
| 376 |
68 |
| ST(0) = sv_2mortal(newRV_noinc(u.sv)); |
| 377 |
68 |
| url_params_each(aTHX_ s, len, &u); |
| 378 |
68 |
| XSRETURN(1); |
| 379 |
|
| |
| 380 |
|
| |
| 381 |
|
| void |
| 382 |
|
| url_params_each(octets, callback, utf8=FALSE) |
| 383 |
|
| SV *octets |
| 384 |
|
| CV *callback |
| 385 |
|
| bool utf8 |
| 386 |
|
| PREINIT: |
| 387 |
|
| const char *s; |
| 388 |
|
| STRLEN len; |
| 389 |
|
| ust_t u; |
| 390 |
|
| PPCODE: |
| 391 |
1 |
| SvGETMAGIC(octets); |
| 392 |
1 |
▶ | if (SvUTF8(octets)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(octets)) { |
0 |
1 |
1 |
|
| 393 |
0 |
| octets = sv_mortalcopy(octets); |
| 394 |
0 |
▶ | if (!sv_utf8_downgrade(octets, 1)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv_utf8_downgrade(octets, 1)) |
0 |
0 |
0 |
|
| 395 |
0 |
| croak("Wide character in octet string"); |
| 396 |
|
| } |
| 397 |
1 |
| s = SvPV_nomg_const(octets, len); |
| 398 |
1 |
▶ | u.decode = utf8 ? &url_decode_utf8 : &url_decode; |
Branch: 1 branch
| Branch | True | False | Total |
| u.decode = utf8 ? &url_decode_utf8 : &url_decode; |
0 |
1 |
1 |
|
| 399 |
1 |
| u.cb = &url_params_each_cb; |
| 400 |
1 |
| u.sv = (SV *)callback; |
| 401 |
1 |
| url_params_each(aTHX_ s, len, &u); |
| 402 |
|
| |
| 403 |
|
| |