| 1 |
|
| /* Copyright (c) 2015-2018 by Pali <pali@cpan.org> */ |
| 2 |
|
| |
| 3 |
|
| #define PERL_NO_GET_CONTEXT |
| 4 |
|
| #include "EXTERN.h" |
| 5 |
|
| #include "perl.h" |
| 6 |
|
| #include "XSUB.h" |
| 7 |
|
| |
| 8 |
|
| #include "dovecot-parser.h" |
| 9 |
|
| |
| 10 |
|
| /* Perl pre 5.6.1 support */ |
| 11 |
|
| #if PERL_VERSION < 6 || (PERL_VERSION == 6 && PERL_SUBVERSION < 1) |
| 12 |
|
| #define BROKEN_SvPVutf8 |
| 13 |
|
| #endif |
| 14 |
|
| |
| 15 |
|
| /* Perl pre 5.7.2 support */ |
| 16 |
|
| #ifndef SvPV_nomg |
| 17 |
|
| #define WITHOUT_SvPV_nomg |
| 18 |
|
| #endif |
| 19 |
|
| |
| 20 |
|
| /* Perl pre 5.8.0 support */ |
| 21 |
|
| #ifndef UTF8_IS_INVARIANT |
| 22 |
|
| #define UTF8_IS_INVARIANT(c) (((U8)c) < 0x80) |
| 23 |
|
| #endif |
| 24 |
|
| |
| 25 |
|
| /* Perl pre 5.9.5 support */ |
| 26 |
|
| #ifndef SVfARG |
| 27 |
|
| #define SVfARG(p) ((void*)(p)) |
| 28 |
|
| #endif |
| 29 |
|
| |
| 30 |
|
| /* Perl pre 5.13.1 support */ |
| 31 |
|
| #ifndef warn_sv |
| 32 |
|
| #define warn_sv(scalar) warn("%" SVf, SVfARG(scalar)) |
| 33 |
|
| #endif |
| 34 |
|
| #ifndef croak_sv |
| 35 |
|
| #define croak_sv(scalar) croak("%" SVf, SVfARG(scalar)) |
| 36 |
|
| #endif |
| 37 |
|
| |
| 38 |
|
| /* Perl pre 5.15.4 support */ |
| 39 |
|
| #ifndef sv_derived_from_pvn |
| 40 |
|
| #define sv_derived_from_pvn(scalar, name, len, flags) sv_derived_from(scalar, name) |
| 41 |
|
| #endif |
| 42 |
|
| |
| 43 |
|
| /* Exported i_panic function for other C files */ |
| 44 |
0 |
| void i_panic(const char *format, ...) |
| 45 |
|
| { |
| 46 |
|
| dTHX; |
| 47 |
|
| va_list args; |
| 48 |
|
| |
| 49 |
0 |
| va_start(args, format); |
| 50 |
0 |
| vcroak(format, &args); |
| 51 |
|
| va_end(args); |
| 52 |
|
| } |
| 53 |
|
| |
| 54 |
23 |
| static void append_carp_shortmess(pTHX_ SV *scalar) |
| 55 |
|
| { |
| 56 |
23 |
| dSP; |
| 57 |
|
| int count; |
| 58 |
|
| |
| 59 |
23 |
| ENTER; |
| 60 |
23 |
| SAVETMPS; |
| 61 |
23 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
23 |
23 |
|
| 62 |
|
| |
| 63 |
23 |
| count = call_pv("Carp::shortmess", G_SCALAR); |
| 64 |
|
| |
| 65 |
23 |
| SPAGAIN; |
| 66 |
|
| |
| 67 |
23 |
▶ | if (count > 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (count > 0) |
23 |
0 |
23 |
|
| 68 |
23 |
| sv_catsv(scalar, POPs); |
| 69 |
|
| |
| 70 |
23 |
| PUTBACK; |
| 71 |
23 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
23 |
0 |
23 |
|
| 72 |
23 |
| LEAVE; |
| 73 |
23 |
| } |
| 74 |
|
| |
| 75 |
|
| #define CARP_WARN false |
| 76 |
|
| #define CARP_DIE true |
| 77 |
23 |
| static void carp(bool fatal, const char *format, ...) |
| 78 |
|
| { |
| 79 |
|
| dTHX; |
| 80 |
|
| va_list args; |
| 81 |
|
| SV *scalar; |
| 82 |
|
| |
| 83 |
23 |
| va_start(args, format); |
| 84 |
23 |
| scalar = sv_2mortal(vnewSVpvf(format, &args)); |
| 85 |
23 |
| va_end(args); |
| 86 |
|
| |
| 87 |
23 |
| append_carp_shortmess(aTHX_ scalar); |
| 88 |
|
| |
| 89 |
23 |
▶ | if (!fatal) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!fatal) |
23 |
0 |
23 |
|
| 90 |
23 |
| warn_sv(scalar); |
| 91 |
|
| else |
| 92 |
0 |
| croak_sv(scalar); |
| 93 |
23 |
| } |
| 94 |
|
| |
| 95 |
35 |
| static bool string_needs_utf8_upgrade(const char *str, STRLEN len) |
| 96 |
|
| { |
| 97 |
|
| STRLEN i; |
| 98 |
|
| |
| 99 |
438 |
▶ | for (i = 0; i < len; ++i) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; ++i) |
411 |
27 |
438 |
|
| 100 |
411 |
▶ | if (!UTF8_IS_INVARIANT(str[i])) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!UTF8_IS_INVARIANT(str[i])) |
8 |
403 |
411 |
|
| 101 |
8 |
| return true; |
| 102 |
|
| |
| 103 |
27 |
| return false; |
| 104 |
|
| } |
| 105 |
|
| |
| 106 |
1355 |
| static const char *get_perl_scalar_value(pTHX_ SV *scalar, STRLEN *len, bool utf8, bool nomg) |
| 107 |
|
| { |
| 108 |
|
| const char *string; |
| 109 |
|
| |
| 110 |
|
| #ifndef WITHOUT_SvPV_nomg |
| 111 |
1355 |
▶ | if (!nomg) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!nomg) |
870 |
485 |
1355 |
|
| 112 |
870 |
| SvGETMAGIC(scalar); |
| 113 |
|
| |
| 114 |
1355 |
▶ | if (!SvOK(scalar)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(scalar)) |
400 |
955 |
1355 |
|
| 115 |
400 |
| return NULL; |
| 116 |
|
| |
| 117 |
955 |
| string = SvPV_nomg(scalar, *len); |
| 118 |
|
| #else |
| 119 |
|
| COP cop; |
| 120 |
|
| |
| 121 |
|
| if (!SvGMAGICAL(scalar) && !SvOK(scalar)) |
| 122 |
|
| return NULL; |
| 123 |
|
| |
| 124 |
|
| /* Temporary turn off all warnings because SvPV can throw uninitialized warning */ |
| 125 |
|
| cop = *PL_curcop; |
| 126 |
|
| cop.cop_warnings = pWARN_NONE; |
| 127 |
|
| |
| 128 |
|
| ENTER; |
| 129 |
|
| SAVEVPTR(PL_curcop); |
| 130 |
|
| PL_curcop = &cop; |
| 131 |
|
| |
| 132 |
|
| string = SvPV(scalar, *len); |
| 133 |
|
| |
| 134 |
|
| LEAVE; |
| 135 |
|
| |
| 136 |
|
| if (SvGMAGICAL(scalar) && !SvOK(scalar)) |
| 137 |
|
| return NULL; |
| 138 |
|
| #endif |
| 139 |
|
| |
| 140 |
955 |
▶ | if (utf8 && !SvUTF8(scalar) && string_needs_utf8_upgrade(string, *len)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (utf8 && !SvUTF8(scalar) && string_needs_utf8_upgrade(string, *len)) { |
55 |
900 |
955 |
| if (utf8 && !SvUTF8(scalar) && string_needs_utf8_upgrade(string, *len)) { |
35 |
20 |
55 |
| if (utf8 && !SvUTF8(scalar) && string_needs_utf8_upgrade(string, *len)) { |
8 |
27 |
35 |
|
| 141 |
8 |
| scalar = sv_2mortal(newSVpvn(string, *len)); |
| 142 |
|
| #ifdef BROKEN_SvPVutf8 |
| 143 |
|
| sv_utf8_upgrade(scalar); |
| 144 |
|
| *len = SvCUR(scalar); |
| 145 |
|
| return SvPVX(scalar); |
| 146 |
|
| #else |
| 147 |
8 |
| return SvPVutf8(scalar, *len); |
| 148 |
|
| #endif |
| 149 |
|
| } |
| 150 |
|
| |
| 151 |
947 |
| return string; |
| 152 |
|
| } |
| 153 |
|
| |
| 154 |
386 |
| static const char *get_perl_scalar_string_value(pTHX_ SV *scalar, STRLEN *len, const char *name, bool utf8) |
| 155 |
|
| { |
| 156 |
|
| const char *string; |
| 157 |
|
| |
| 158 |
386 |
| string = get_perl_scalar_value(aTHX_ scalar, len, utf8, false); |
| 159 |
386 |
▶ | if (!string) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!string) { |
4 |
382 |
386 |
|
| 160 |
4 |
| carp(CARP_WARN, "Use of uninitialized value for %s", name); |
| 161 |
4 |
| *len = 0; |
| 162 |
4 |
| return ""; |
| 163 |
|
| } |
| 164 |
|
| |
| 165 |
382 |
| return string; |
| 166 |
|
| } |
| 167 |
|
| |
| 168 |
784 |
| static SV *get_perl_hash_scalar(pTHX_ HV *hash, const char *key) |
| 169 |
|
| { |
| 170 |
|
| I32 klen; |
| 171 |
|
| SV **scalar_ptr; |
| 172 |
|
| |
| 173 |
784 |
| klen = strlen(key); |
| 174 |
|
| |
| 175 |
784 |
▶ | if (!hv_exists(hash, key, klen)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hv_exists(hash, key, klen)) |
0 |
784 |
784 |
|
| 176 |
0 |
| return NULL; |
| 177 |
|
| |
| 178 |
784 |
| scalar_ptr = hv_fetch(hash, key, klen, 0); |
| 179 |
784 |
▶ | if (!scalar_ptr) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!scalar_ptr) |
0 |
784 |
784 |
|
| 180 |
0 |
| return NULL; |
| 181 |
|
| |
| 182 |
784 |
| return *scalar_ptr; |
| 183 |
|
| } |
| 184 |
|
| |
| 185 |
392 |
| static const char *get_perl_hash_value(pTHX_ HV *hash, const char *key, STRLEN *len, bool utf8, bool *taint) |
| 186 |
|
| { |
| 187 |
|
| SV *scalar; |
| 188 |
|
| |
| 189 |
392 |
| scalar = get_perl_hash_scalar(aTHX_ hash, key); |
| 190 |
392 |
▶ | if (!scalar) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!scalar) |
0 |
392 |
392 |
|
| 191 |
0 |
| return NULL; |
| 192 |
|
| |
| 193 |
392 |
▶ | if (!*taint && SvTAINTED(scalar)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!*taint && SvTAINTED(scalar)) |
375 |
17 |
392 |
| if (!*taint && SvTAINTED(scalar)) |
37 |
338 |
375 |
| if (!*taint && SvTAINTED(scalar)) |
8 |
29 |
37 |
|
| 194 |
8 |
| *taint = true; |
| 195 |
|
| |
| 196 |
392 |
| return get_perl_scalar_value(aTHX_ scalar, len, utf8, true); |
| 197 |
|
| } |
| 198 |
|
| |
| 199 |
340 |
| static void set_perl_hash_value(pTHX_ HV *hash, const char *key, const char *value, STRLEN len, bool utf8, bool taint) |
| 200 |
|
| { |
| 201 |
|
| I32 klen; |
| 202 |
|
| SV *scalar; |
| 203 |
|
| |
| 204 |
340 |
| klen = strlen(key); |
| 205 |
|
| |
| 206 |
340 |
▶ | if (!len && value && value[0]) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!len && value && value[0]) |
91 |
249 |
340 |
| if (!len && value && value[0]) |
0 |
91 |
91 |
| if (!len && value && value[0]) |
0 |
0 |
0 |
|
| 207 |
0 |
| value = NULL; |
| 208 |
|
| |
| 209 |
340 |
▶ | if (value) |
Branch: 1 branch
| Branch | True | False | Total |
| if (value) |
249 |
91 |
340 |
|
| 210 |
249 |
| scalar = newSVpvn(value, len); |
| 211 |
|
| else |
| 212 |
91 |
| scalar = newSV(0); |
| 213 |
|
| |
| 214 |
340 |
▶ | if (utf8 && value) |
Branch: 2 branches
| Branch | True | False | Total |
| if (utf8 && value) |
5 |
335 |
340 |
| if (utf8 && value) |
5 |
0 |
5 |
|
| 215 |
5 |
| sv_utf8_decode(scalar); |
| 216 |
|
| |
| 217 |
340 |
▶ | if (taint) |
Branch: 1 branch
| Branch | True | False | Total |
| if (taint) |
5 |
335 |
340 |
|
| 218 |
5 |
▶ | SvTAINTED_on(scalar); |
Branch: 1 branch
| Branch | True | False | Total |
| SvTAINTED_on(scalar); |
5 |
0 |
5 |
|
| 219 |
|
| |
| 220 |
340 |
| (void)hv_store(hash, key, klen, scalar, 0); |
| 221 |
340 |
| } |
| 222 |
|
| |
| 223 |
34 |
| static HV *get_perl_class_from_perl_cv(pTHX_ CV *cv) |
| 224 |
|
| { |
| 225 |
|
| GV *gv; |
| 226 |
|
| HV *class; |
| 227 |
|
| |
| 228 |
34 |
| class = NULL; |
| 229 |
34 |
| gv = CvGV(cv); |
| 230 |
|
| |
| 231 |
34 |
▶ | if (gv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (gv) |
34 |
0 |
34 |
|
| 232 |
34 |
| class = GvSTASH(gv); |
| 233 |
|
| |
| 234 |
34 |
▶ | if (!class) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!class) |
0 |
34 |
34 |
|
| 235 |
0 |
| class = CvSTASH(cv); |
| 236 |
|
| |
| 237 |
34 |
▶ | if (!class) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!class) |
0 |
34 |
34 |
|
| 238 |
0 |
| class = PL_curstash; |
| 239 |
|
| |
| 240 |
34 |
▶ | if (!class) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!class) |
0 |
34 |
34 |
|
| 241 |
0 |
| carp(CARP_DIE, "Cannot retrieve class"); |
| 242 |
|
| |
| 243 |
34 |
| return class; |
| 244 |
|
| } |
| 245 |
|
| |
| 246 |
17 |
| static HV *get_perl_class_from_perl_scalar(pTHX_ SV *scalar) |
| 247 |
|
| { |
| 248 |
|
| HV *class; |
| 249 |
|
| STRLEN class_len; |
| 250 |
|
| const char *class_name; |
| 251 |
|
| |
| 252 |
17 |
| class_name = get_perl_scalar_string_value(aTHX_ scalar, &class_len, "class", true); |
| 253 |
|
| |
| 254 |
17 |
▶ | if (class_len == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (class_len == 0) { |
0 |
17 |
17 |
|
| 255 |
0 |
| carp(CARP_WARN, "Explicit blessing to '' (assuming package main)"); |
| 256 |
0 |
| class_name = "main"; |
| 257 |
0 |
| class_len = strlen(class_name); |
| 258 |
|
| } |
| 259 |
|
| |
| 260 |
17 |
| class = gv_stashpvn(class_name, class_len, GV_ADD | SVf_UTF8); |
| 261 |
17 |
▶ | if (!class) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!class) |
0 |
17 |
17 |
|
| 262 |
0 |
| carp(CARP_DIE, "Cannot retrieve class %" SVf, SVfARG(scalar)); |
| 263 |
|
| |
| 264 |
17 |
| return class; |
| 265 |
|
| } |
| 266 |
|
| |
| 267 |
51 |
| static HV *get_perl_class_from_perl_scalar_or_cv(pTHX_ SV *scalar, CV *cv) |
| 268 |
|
| { |
| 269 |
51 |
▶ | if (scalar) |
Branch: 1 branch
| Branch | True | False | Total |
| if (scalar) |
17 |
34 |
51 |
|
| 270 |
17 |
| return get_perl_class_from_perl_scalar(aTHX_ scalar); |
| 271 |
|
| else |
| 272 |
34 |
| return get_perl_class_from_perl_cv(aTHX_ cv); |
| 273 |
|
| } |
| 274 |
|
| |
| 275 |
215 |
| static bool is_class_object(pTHX_ SV *class, const char *class_name, STRLEN class_len, SV *object) |
| 276 |
|
| { |
| 277 |
215 |
| dSP; |
| 278 |
|
| SV *sv; |
| 279 |
|
| bool ret; |
| 280 |
|
| int count; |
| 281 |
|
| |
| 282 |
215 |
▶ | if (!sv_isobject(object)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv_isobject(object)) |
8 |
207 |
215 |
|
| 283 |
8 |
| return false; |
| 284 |
|
| |
| 285 |
207 |
| ENTER; |
| 286 |
207 |
| SAVETMPS; |
| 287 |
|
| |
| 288 |
207 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
207 |
207 |
|
| 289 |
207 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
207 |
207 |
|
| 290 |
|
| |
| 291 |
207 |
▶ | if (class) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (class) { |
5 |
202 |
207 |
|
| 292 |
5 |
| sv = newSVsv(class); |
| 293 |
|
| } else { |
| 294 |
202 |
| sv = newSVpvn(class_name, class_len); |
| 295 |
202 |
| SvUTF8_on(sv); |
| 296 |
|
| } |
| 297 |
|
| |
| 298 |
207 |
| PUSHs(sv_2mortal(newSVsv(object))); |
| 299 |
207 |
| PUSHs(sv_2mortal(sv)); |
| 300 |
|
| |
| 301 |
207 |
| PUTBACK; |
| 302 |
|
| |
| 303 |
207 |
| count = call_method("isa", G_SCALAR); |
| 304 |
|
| |
| 305 |
207 |
| SPAGAIN; |
| 306 |
|
| |
| 307 |
207 |
▶ | if (count > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (count > 0) { |
207 |
0 |
207 |
|
| 308 |
207 |
| sv = POPs; |
| 309 |
207 |
| ret = SvTRUE(sv); |
| 310 |
|
| } else { |
| 311 |
0 |
| ret = false; |
| 312 |
|
| } |
| 313 |
|
| |
| 314 |
207 |
| PUTBACK; |
| 315 |
207 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
207 |
0 |
207 |
|
| 316 |
207 |
| LEAVE; |
| 317 |
|
| |
| 318 |
207 |
| return ret; |
| 319 |
|
| } |
| 320 |
|
| |
| 321 |
14 |
| static void fill_element_message(char *buffer, size_t len, I32 index1, I32 index2) |
| 322 |
|
| { |
| 323 |
|
| static const char message[] = "Element at index "; |
| 324 |
|
| |
| 325 |
14 |
▶ | if (len < 10 || buffer[0]) |
Branch: 2 branches
| Branch | True | False | Total |
| if (len < 10 || buffer[0]) |
14 |
0 |
14 |
| if (len < 10 || buffer[0]) |
0 |
14 |
14 |
|
| 326 |
0 |
| return; |
| 327 |
|
| |
| 328 |
14 |
▶ | if (len+10+1+10 < sizeof(message)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len+10+1+10 < sizeof(message)) { |
0 |
14 |
14 |
|
| 329 |
0 |
| buffer[0] = 0; |
| 330 |
0 |
| return; |
| 331 |
|
| } |
| 332 |
|
| |
| 333 |
14 |
▶ | if (index2 == -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (index2 == -1) { |
14 |
0 |
14 |
|
| 334 |
14 |
| strcpy(buffer, "Argument"); |
| 335 |
14 |
| return; |
| 336 |
|
| } |
| 337 |
|
| |
| 338 |
0 |
| memcpy(buffer, message, sizeof(message)); |
| 339 |
|
| |
| 340 |
0 |
▶ | if (index1 == -1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (index1 == -1) |
0 |
0 |
0 |
|
| 341 |
0 |
| sprintf(buffer+sizeof(message)-1, "%d", (int)index2); |
| 342 |
|
| else |
| 343 |
0 |
| sprintf(buffer+sizeof(message)-1, "%d/%d", (int)index1, (int)index2); |
| 344 |
|
| } |
| 345 |
|
| |
| 346 |
204 |
| static HV* get_object_hash_from_perl_array(pTHX_ AV *array, I32 index1, I32 index2, const char *class_name, STRLEN class_len, bool warn) |
| 347 |
|
| { |
| 348 |
|
| SV *scalar; |
| 349 |
|
| SV *object; |
| 350 |
|
| SV **object_ptr; |
| 351 |
204 |
| char buffer[40] = { 0 }; |
| 352 |
|
| |
| 353 |
|
| #ifdef WITHOUT_SvPV_nomg |
| 354 |
|
| warn = true; |
| 355 |
|
| #endif |
| 356 |
|
| |
| 357 |
204 |
▶ | object_ptr = av_fetch(array, (index2 == -1 ? 0 : index2), 0); |
Branch: 1 branch
| Branch | True | False | Total |
| object_ptr = av_fetch(array, (index2 == -1 ? 0 : index2), 0); |
76 |
128 |
204 |
|
| 358 |
204 |
▶ | if (!object_ptr) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!object_ptr) { |
0 |
204 |
204 |
|
| 359 |
0 |
▶ | if (warn) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (warn) { |
0 |
0 |
0 |
|
| 360 |
0 |
| fill_element_message(buffer, sizeof(buffer), index1, index2); |
| 361 |
0 |
| carp(CARP_WARN, "%s is NULL", buffer); |
| 362 |
|
| } |
| 363 |
0 |
| return NULL; |
| 364 |
|
| } |
| 365 |
|
| |
| 366 |
204 |
| object = *object_ptr; |
| 367 |
204 |
▶ | if (!is_class_object(aTHX_ NULL, class_name, class_len, object)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_class_object(aTHX_ NULL, class_name, class_len, object)) { |
8 |
196 |
204 |
|
| 368 |
8 |
▶ | if (warn) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (warn) { |
4 |
4 |
8 |
|
| 369 |
4 |
| fill_element_message(buffer, sizeof(buffer), index1, index2); |
| 370 |
4 |
| carp(CARP_WARN, "%s is not %s object", buffer, class_name); |
| 371 |
|
| } |
| 372 |
8 |
| return NULL; |
| 373 |
|
| } |
| 374 |
|
| |
| 375 |
196 |
| scalar = SvRV(object); |
| 376 |
196 |
▶ | if (SvTYPE(scalar) != SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(scalar) != SVt_PVHV) { |
0 |
196 |
196 |
|
| 377 |
0 |
▶ | if (warn) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (warn) { |
0 |
0 |
0 |
|
| 378 |
0 |
| fill_element_message(buffer, sizeof(buffer), index1, index2); |
| 379 |
0 |
| carp(CARP_WARN, "%s is not HASH reference", buffer); |
| 380 |
|
| } |
| 381 |
0 |
| return NULL; |
| 382 |
|
| } |
| 383 |
|
| |
| 384 |
196 |
| return (HV *)scalar; |
| 385 |
|
| |
| 386 |
|
| } |
| 387 |
|
| |
| 388 |
102 |
| static void message_address_add_from_perl_array(pTHX_ struct message_address **first_address, struct message_address **last_address, bool utf8, bool *taint, AV *array, I32 index1, I32 index2, const char *class_name, STRLEN class_len) |
| 389 |
|
| { |
| 390 |
|
| HV *hash; |
| 391 |
|
| const char *name; |
| 392 |
|
| const char *mailbox; |
| 393 |
|
| const char *domain; |
| 394 |
|
| const char *comment; |
| 395 |
|
| STRLEN name_len; |
| 396 |
|
| STRLEN mailbox_len; |
| 397 |
|
| STRLEN domain_len; |
| 398 |
|
| STRLEN comment_len; |
| 399 |
102 |
| char buffer[40] = { 0 }; |
| 400 |
|
| |
| 401 |
102 |
| hash = get_object_hash_from_perl_array(aTHX_ array, index1, index2, class_name, class_len, false); |
| 402 |
102 |
▶ | if (!hash) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hash) |
4 |
98 |
102 |
|
| 403 |
14 |
| return; |
| 404 |
|
| |
| 405 |
98 |
| name = get_perl_hash_value(aTHX_ hash, "phrase", &name_len, utf8, taint); |
| 406 |
98 |
| mailbox = get_perl_hash_value(aTHX_ hash, "user", &mailbox_len, utf8, taint); |
| 407 |
98 |
| domain = get_perl_hash_value(aTHX_ hash, "host", &domain_len, utf8, taint); |
| 408 |
98 |
| comment = get_perl_hash_value(aTHX_ hash, "comment", &comment_len, utf8, taint); |
| 409 |
|
| |
| 410 |
98 |
▶ | if (domain && !domain[0] && domain_len == 0) |
Branch: 3 branches
| Branch | True | False | Total |
| if (domain && !domain[0] && domain_len == 0) |
89 |
9 |
98 |
| if (domain && !domain[0] && domain_len == 0) |
0 |
89 |
89 |
| if (domain && !domain[0] && domain_len == 0) |
0 |
0 |
0 |
|
| 411 |
0 |
| domain = NULL; |
| 412 |
|
| |
| 413 |
98 |
▶ | if (!mailbox && !domain) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!mailbox && !domain) { |
6 |
92 |
98 |
| if (!mailbox && !domain) { |
5 |
1 |
6 |
|
| 414 |
5 |
| fill_element_message(buffer, sizeof(buffer), index1, index2); |
| 415 |
5 |
| carp(CARP_WARN, "%s contains empty address", buffer); |
| 416 |
5 |
| return; |
| 417 |
|
| } |
| 418 |
|
| |
| 419 |
93 |
▶ | if (!mailbox) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!mailbox) { |
1 |
92 |
93 |
|
| 420 |
1 |
| fill_element_message(buffer, sizeof(buffer), index1, index2); |
| 421 |
1 |
| carp(CARP_WARN, "%s contains empty user portion of address", buffer); |
| 422 |
1 |
| return; |
| 423 |
|
| } |
| 424 |
|
| |
| 425 |
92 |
▶ | if (!domain) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!domain) { |
4 |
88 |
92 |
|
| 426 |
4 |
| fill_element_message(buffer, sizeof(buffer), index1, index2); |
| 427 |
4 |
| carp(CARP_WARN, "%s contains empty host portion of address", buffer); |
| 428 |
4 |
| return; |
| 429 |
|
| } |
| 430 |
|
| |
| 431 |
88 |
| message_address_add(first_address, last_address, name, name_len, NULL, 0, mailbox, mailbox_len, domain, domain_len, comment, comment_len); |
| 432 |
|
| } |
| 433 |
|
| |
| 434 |
184 |
| static AV *get_perl_array_from_scalar(SV *scalar, const char *group_name, bool warn) |
| 435 |
|
| { |
| 436 |
|
| SV *scalar_ref; |
| 437 |
|
| |
| 438 |
|
| #ifdef WITHOUT_SvPV_nomg |
| 439 |
|
| warn = true; |
| 440 |
|
| #endif |
| 441 |
|
| |
| 442 |
184 |
▶ | if (scalar && !SvROK(scalar)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (scalar && !SvROK(scalar)) { |
184 |
0 |
184 |
| if (scalar && !SvROK(scalar)) { |
4 |
180 |
184 |
|
| 443 |
4 |
▶ | if (warn) |
Branch: 1 branch
| Branch | True | False | Total |
| if (warn) |
2 |
2 |
4 |
|
| 444 |
2 |
| carp(CARP_WARN, "Value for group '%s' is not reference", group_name); |
| 445 |
4 |
| return NULL; |
| 446 |
|
| } |
| 447 |
|
| |
| 448 |
180 |
| scalar_ref = SvRV(scalar); |
| 449 |
|
| |
| 450 |
180 |
▶ | if (!scalar_ref || SvTYPE(scalar_ref) != SVt_PVAV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!scalar_ref || SvTYPE(scalar_ref) != SVt_PVAV) { |
180 |
0 |
180 |
| if (!scalar_ref || SvTYPE(scalar_ref) != SVt_PVAV) { |
0 |
180 |
180 |
|
| 451 |
0 |
▶ | if (warn) |
Branch: 1 branch
| Branch | True | False | Total |
| if (warn) |
0 |
0 |
0 |
|
| 452 |
0 |
| carp(CARP_WARN, "Value for group '%s' is not ARRAY reference", group_name); |
| 453 |
0 |
| return NULL; |
| 454 |
|
| } |
| 455 |
|
| |
| 456 |
180 |
| return (AV *)scalar_ref; |
| 457 |
|
| } |
| 458 |
|
| |
| 459 |
92 |
| static void message_address_add_from_perl_group(pTHX_ struct message_address **first_address, struct message_address **last_address, bool utf8, bool *taint, SV *scalar_group, SV *scalar_list, I32 index1, const char *class_name, STRLEN class_len) |
| 460 |
|
| { |
| 461 |
|
| I32 len; |
| 462 |
|
| I32 index2; |
| 463 |
|
| AV *array; |
| 464 |
|
| STRLEN group_len; |
| 465 |
|
| const char *group_name; |
| 466 |
|
| |
| 467 |
92 |
| group_name = get_perl_scalar_value(aTHX_ scalar_group, &group_len, utf8, true); |
| 468 |
92 |
| array = get_perl_array_from_scalar(scalar_list, group_name, false); |
| 469 |
92 |
▶ | len = array ? (av_len(array) + 1) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| len = array ? (av_len(array) + 1) : 0; |
90 |
2 |
92 |
|
| 470 |
|
| |
| 471 |
92 |
▶ | if (index1 == -1 && group_name) |
Branch: 2 branches
| Branch | True | False | Total |
| if (index1 == -1 && group_name) |
79 |
13 |
92 |
| if (index1 == -1 && group_name) |
11 |
68 |
79 |
|
| 472 |
11 |
| index1 = 0; |
| 473 |
|
| |
| 474 |
92 |
▶ | if (group_name) |
Branch: 1 branch
| Branch | True | False | Total |
| if (group_name) |
21 |
71 |
92 |
|
| 475 |
21 |
| message_address_add(first_address, last_address, NULL, 0, NULL, 0, group_name, group_len, NULL, 0, NULL, 0); |
| 476 |
|
| |
| 477 |
194 |
▶ | for (index2 = 0; index2 < len; ++index2) |
Branch: 1 branch
| Branch | True | False | Total |
| for (index2 = 0; index2 < len; ++index2) |
102 |
92 |
194 |
|
| 478 |
102 |
▶ | message_address_add_from_perl_array(aTHX_ first_address, last_address, utf8, taint, array, index1, ((index1 == -1 && len == 1) ? -1 : index2), class_name, class_len); |
Branch: 2 branches
| Branch | True | False | Total |
| message_address_add_from_perl_array(aTHX_ first_address, last_address, utf8, taint, array, index1, ((index1 == -1 && len == 1) ? -1 : index2), class_name, class_len); |
76 |
26 |
102 |
| message_address_add_from_perl_array(aTHX_ first_address, last_address, utf8, taint, array, index1, ((index1 == -1 && len == 1) ? -1 : index2), class_name, class_len); |
12 |
64 |
76 |
|
| 479 |
|
| |
| 480 |
92 |
▶ | if (group_name) |
Branch: 1 branch
| Branch | True | False | Total |
| if (group_name) |
21 |
71 |
92 |
|
| 481 |
21 |
| message_address_add(first_address, last_address, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0); |
| 482 |
|
| |
| 483 |
92 |
▶ | if (!*taint && SvTAINTED(scalar_group)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!*taint && SvTAINTED(scalar_group)) |
84 |
8 |
92 |
| if (!*taint && SvTAINTED(scalar_group)) |
5 |
79 |
84 |
| if (!*taint && SvTAINTED(scalar_group)) |
0 |
5 |
5 |
|
| 484 |
0 |
| *taint = true; |
| 485 |
92 |
| } |
| 486 |
|
| |
| 487 |
|
| #ifndef WITHOUT_SvPV_nomg |
| 488 |
92 |
| static bool perl_group_needs_utf8(pTHX_ SV *scalar_group, SV *scalar_list, I32 index1, const char *class_name, STRLEN class_len) |
| 489 |
|
| { |
| 490 |
|
| I32 len; |
| 491 |
|
| I32 index2; |
| 492 |
|
| SV *scalar; |
| 493 |
|
| HV *hash; |
| 494 |
|
| AV *array; |
| 495 |
|
| STRLEN len_na; |
| 496 |
|
| bool utf8; |
| 497 |
|
| const char *group_name; |
| 498 |
|
| const char **hash_key_ptr; |
| 499 |
|
| |
| 500 |
|
| static const char *hash_keys[] = { "phrase", "user", "host", "comment", NULL }; |
| 501 |
|
| |
| 502 |
92 |
| utf8 = false; |
| 503 |
|
| |
| 504 |
92 |
| group_name = get_perl_scalar_value(aTHX_ scalar_group, &len_na, false, false); |
| 505 |
92 |
▶ | if (SvUTF8(scalar_group)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8(scalar_group)) |
1 |
91 |
92 |
|
| 506 |
1 |
| utf8 = true; |
| 507 |
|
| |
| 508 |
92 |
▶ | if (index1 == -1 && group_name) |
Branch: 2 branches
| Branch | True | False | Total |
| if (index1 == -1 && group_name) |
79 |
13 |
92 |
| if (index1 == -1 && group_name) |
11 |
68 |
79 |
|
| 509 |
11 |
| index1 = 0; |
| 510 |
|
| |
| 511 |
92 |
| array = get_perl_array_from_scalar(scalar_list, group_name, true); |
| 512 |
92 |
▶ | len = array ? (av_len(array) + 1) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| len = array ? (av_len(array) + 1) : 0; |
90 |
2 |
92 |
|
| 513 |
|
| |
| 514 |
194 |
▶ | for (index2 = 0; index2 < len; ++index2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (index2 = 0; index2 < len; ++index2) { |
102 |
92 |
194 |
|
| 515 |
102 |
▶ | hash = get_object_hash_from_perl_array(aTHX_ array, index1, ((index1 == -1 && len == 1) ? -1 : index2), class_name, class_len, true); |
Branch: 2 branches
| Branch | True | False | Total |
| hash = get_object_hash_from_perl_array(aTHX_ array, index1, ((index1 == -1 && len == 1) ? -1 : index2), class_name, class_len, true); |
76 |
26 |
102 |
| hash = get_object_hash_from_perl_array(aTHX_ array, index1, ((index1 == -1 && len == 1) ? -1 : index2), class_name, class_len, true); |
12 |
64 |
76 |
|
| 516 |
102 |
▶ | if (!hash) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hash) |
4 |
98 |
102 |
|
| 517 |
4 |
| continue; |
| 518 |
490 |
▶ | for (hash_key_ptr = hash_keys; *hash_key_ptr; ++hash_key_ptr) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (hash_key_ptr = hash_keys; *hash_key_ptr; ++hash_key_ptr) { |
392 |
98 |
490 |
|
| 519 |
392 |
| scalar = get_perl_hash_scalar(aTHX_ hash, *hash_key_ptr); |
| 520 |
392 |
▶ | if (scalar && get_perl_scalar_value(aTHX_ scalar, &len_na, false, false) && SvUTF8(scalar)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (scalar && get_perl_scalar_value(aTHX_ scalar, &len_na, false, false) && SvUTF8(scalar)) |
392 |
0 |
392 |
| if (scalar && get_perl_scalar_value(aTHX_ scalar, &len_na, false, false) && SvUTF8(scalar)) |
265 |
127 |
392 |
| if (scalar && get_perl_scalar_value(aTHX_ scalar, &len_na, false, false) && SvUTF8(scalar)) |
19 |
246 |
265 |
|
| 521 |
19 |
| utf8 = true; |
| 522 |
|
| } |
| 523 |
|
| } |
| 524 |
|
| |
| 525 |
92 |
| return utf8; |
| 526 |
|
| } |
| 527 |
|
| #endif |
| 528 |
|
| |
| 529 |
49 |
| static int count_address_groups(struct message_address *first_address) |
| 530 |
|
| { |
| 531 |
|
| int count; |
| 532 |
|
| bool in_group; |
| 533 |
|
| struct message_address *address; |
| 534 |
|
| |
| 535 |
49 |
| count = 0; |
| 536 |
49 |
| in_group = false; |
| 537 |
|
| |
| 538 |
135 |
▶ | for (address = first_address; address; address = address->next) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (address = first_address; address; address = address->next) { |
86 |
49 |
135 |
|
| 539 |
86 |
▶ | if (!address->domain) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!address->domain) |
18 |
68 |
86 |
|
| 540 |
18 |
| in_group = !in_group; |
| 541 |
86 |
▶ | if (in_group) |
Branch: 1 branch
| Branch | True | False | Total |
| if (in_group) |
19 |
67 |
86 |
|
| 542 |
19 |
| continue; |
| 543 |
67 |
| ++count; |
| 544 |
|
| } |
| 545 |
|
| |
| 546 |
49 |
| return count; |
| 547 |
|
| } |
| 548 |
|
| |
| 549 |
97 |
| static bool get_next_perl_address_group(pTHX_ struct message_address **address, SV **group_scalar, SV **addresses_scalar, HV *class, bool utf8, bool taint) |
| 550 |
|
| { |
| 551 |
|
| HV *hash; |
| 552 |
|
| SV *object; |
| 553 |
|
| SV *hash_ref; |
| 554 |
|
| bool in_group; |
| 555 |
|
| AV *addresses_array; |
| 556 |
|
| |
| 557 |
97 |
▶ | if (!*address) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!*address) |
49 |
48 |
97 |
|
| 558 |
49 |
| return false; |
| 559 |
|
| |
| 560 |
48 |
| in_group = !(*address)->domain; |
| 561 |
|
| |
| 562 |
48 |
▶ | if (in_group && (*address)->mailbox) |
Branch: 2 branches
| Branch | True | False | Total |
| if (in_group && (*address)->mailbox) |
9 |
39 |
48 |
| if (in_group && (*address)->mailbox) |
9 |
0 |
9 |
|
| 563 |
9 |
| *group_scalar = sv_2mortal(newSVpvn((*address)->mailbox, (*address)->mailbox_len)); |
| 564 |
|
| else |
| 565 |
39 |
| *group_scalar = sv_newmortal(); |
| 566 |
|
| |
| 567 |
48 |
▶ | if (utf8 && in_group && (*address)->mailbox) |
Branch: 3 branches
| Branch | True | False | Total |
| if (utf8 && in_group && (*address)->mailbox) |
1 |
47 |
48 |
| if (utf8 && in_group && (*address)->mailbox) |
1 |
0 |
1 |
| if (utf8 && in_group && (*address)->mailbox) |
1 |
0 |
1 |
|
| 568 |
1 |
| sv_utf8_decode(*group_scalar); |
| 569 |
|
| |
| 570 |
48 |
▶ | if (taint) |
Branch: 1 branch
| Branch | True | False | Total |
| if (taint) |
1 |
47 |
48 |
|
| 571 |
1 |
▶ | SvTAINTED_on(*group_scalar); |
Branch: 1 branch
| Branch | True | False | Total |
| SvTAINTED_on(*group_scalar); |
1 |
0 |
1 |
|
| 572 |
|
| |
| 573 |
48 |
| addresses_array = newAV(); |
| 574 |
48 |
| *addresses_scalar = sv_2mortal(newRV_noinc((SV *)addresses_array)); |
| 575 |
|
| |
| 576 |
48 |
▶ | if (in_group) |
Branch: 1 branch
| Branch | True | False | Total |
| if (in_group) |
9 |
39 |
48 |
|
| 577 |
9 |
| *address = (*address)->next; |
| 578 |
|
| |
| 579 |
116 |
▶ | while (*address && (*address)->domain) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (*address && (*address)->domain) { |
79 |
37 |
116 |
| while (*address && (*address)->domain) { |
68 |
11 |
79 |
|
| 580 |
68 |
| hash = newHV(); |
| 581 |
|
| |
| 582 |
68 |
| set_perl_hash_value(aTHX_ hash, "phrase", (*address)->name, (*address)->name_len, utf8, taint); |
| 583 |
68 |
▶ | set_perl_hash_value(aTHX_ hash, "user", ( (*address)->mailbox && (*address)->mailbox[0] ) ? (*address)->mailbox : NULL, (*address)->mailbox_len, utf8, taint); |
Branch: 2 branches
| Branch | True | False | Total |
| set_perl_hash_value(aTHX_ hash, "user", ( (*address)->mailbox && (*address)->mailbox[0] ) ? (*address)->mailbox : NULL, (*address)->mailbox_len, utf8, taint); |
68 |
0 |
68 |
| set_perl_hash_value(aTHX_ hash, "user", ( (*address)->mailbox && (*address)->mailbox[0] ) ? (*address)->mailbox : NULL, (*address)->mailbox_len, utf8, taint); |
61 |
7 |
68 |
|
| 584 |
68 |
▶ | set_perl_hash_value(aTHX_ hash, "host", ( (*address)->domain && (*address)->domain[0] ) ? (*address)->domain : NULL, (*address)->domain_len, utf8, taint); |
Branch: 2 branches
| Branch | True | False | Total |
| set_perl_hash_value(aTHX_ hash, "host", ( (*address)->domain && (*address)->domain[0] ) ? (*address)->domain : NULL, (*address)->domain_len, utf8, taint); |
68 |
0 |
68 |
| set_perl_hash_value(aTHX_ hash, "host", ( (*address)->domain && (*address)->domain[0] ) ? (*address)->domain : NULL, (*address)->domain_len, utf8, taint); |
60 |
8 |
68 |
|
| 585 |
68 |
| set_perl_hash_value(aTHX_ hash, "comment", (*address)->comment, (*address)->comment_len, utf8, taint); |
| 586 |
68 |
| set_perl_hash_value(aTHX_ hash, "original", (*address)->original, (*address)->original_len, utf8, taint); |
| 587 |
|
| |
| 588 |
68 |
▶ | if ((*address)->invalid_syntax) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((*address)->invalid_syntax) |
11 |
57 |
68 |
|
| 589 |
11 |
| (void)hv_store(hash, "invalid", sizeof("invalid")-1, newSViv(1), 0); |
| 590 |
|
| |
| 591 |
68 |
| hash_ref = newRV_noinc((SV *)hash); |
| 592 |
68 |
| object = sv_bless(hash_ref, class); |
| 593 |
|
| |
| 594 |
68 |
| av_push(addresses_array, object); |
| 595 |
|
| |
| 596 |
68 |
| *address = (*address)->next; |
| 597 |
|
| } |
| 598 |
|
| |
| 599 |
48 |
▶ | if (in_group && *address) |
Branch: 2 branches
| Branch | True | False | Total |
| if (in_group && *address) |
9 |
39 |
48 |
| if (in_group && *address) |
9 |
0 |
9 |
|
| 600 |
9 |
| *address = (*address)->next; |
| 601 |
|
| |
| 602 |
48 |
| return true; |
| 603 |
|
| } |
| 604 |
|
| |
| 605 |
|
| |
| 606 |
|
| MODULE = Email::Address::XS PACKAGE = Email::Address::XS |
| 607 |
|
| |
| 608 |
|
| PROTOTYPES: DISABLE |
| 609 |
|
| |
| 610 |
|
| void |
| 611 |
|
| format_email_groups(...) |
| 612 |
|
| PREINIT: |
| 613 |
|
| I32 i; |
| 614 |
|
| bool utf8; |
| 615 |
|
| bool taint; |
| 616 |
|
| char *string; |
| 617 |
|
| size_t string_len; |
| 618 |
|
| struct message_address *first_address; |
| 619 |
|
| struct message_address *last_address; |
| 620 |
|
| SV *string_scalar; |
| 621 |
|
| INPUT: |
| 622 |
|
| const char *this_class_name = "$Package"; |
| 623 |
|
| STRLEN this_class_len = sizeof("$Package")-1; |
| 624 |
|
| INIT: |
| 625 |
85 |
▶ | if (items % 2 == 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (items % 2 == 1) { |
1 |
84 |
85 |
|
| 626 |
1 |
| carp(CARP_WARN, "Odd number of elements in argument list"); |
| 627 |
1 |
| XSRETURN_UNDEF; |
| 628 |
|
| } |
| 629 |
|
| PPCODE: |
| 630 |
84 |
| first_address = NULL; |
| 631 |
84 |
| last_address = NULL; |
| 632 |
84 |
| taint = false; |
| 633 |
|
| #ifndef WITHOUT_SvPV_nomg |
| 634 |
84 |
| utf8 = false; |
| 635 |
176 |
▶ | for (i = 0; i < items; i += 2) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < items; i += 2) |
92 |
84 |
176 |
|
| 636 |
92 |
▶ | if (perl_group_needs_utf8(aTHX_ ST(i), ST(i+1), (items == 2 ? -1 : i), this_class_name, this_class_len)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (perl_group_needs_utf8(aTHX_ ST(i), ST(i+1), (items == 2 ? -1 : i), this_class_name, this_class_len)) |
13 |
79 |
92 |
| if (perl_group_needs_utf8(aTHX_ ST(i), ST(i+1), (items == 2 ? -1 : i), this_class_name, this_class_len)) |
7 |
85 |
92 |
|
| 637 |
7 |
| utf8 = true; |
| 638 |
|
| #else |
| 639 |
|
| utf8 = true; |
| 640 |
|
| #endif |
| 641 |
176 |
▶ | for (i = 0; i < items; i += 2) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < items; i += 2) |
92 |
84 |
176 |
|
| 642 |
92 |
▶ | message_address_add_from_perl_group(aTHX_ &first_address, &last_address, utf8, &taint, ST(i), ST(i+1), (items == 2 ? -1 : i), this_class_name, this_class_len); |
Branch: 1 branch
| Branch | True | False | Total |
| message_address_add_from_perl_group(aTHX_ &first_address, &last_address, utf8, &taint, ST(i), ST(i+1), (items == 2 ? -1 : i), this_class_name, this_class_len); |
13 |
79 |
92 |
|
| 643 |
84 |
| message_address_write(&string, &string_len, first_address); |
| 644 |
84 |
| message_address_free(&first_address); |
| 645 |
84 |
| string_scalar = sv_2mortal(newSVpvn(string, string_len)); |
| 646 |
84 |
| string_free(string); |
| 647 |
84 |
▶ | if (utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) |
6 |
78 |
84 |
|
| 648 |
6 |
| sv_utf8_decode(string_scalar); |
| 649 |
84 |
▶ | if (taint) |
Branch: 1 branch
| Branch | True | False | Total |
| if (taint) |
8 |
76 |
84 |
|
| 650 |
8 |
▶ | SvTAINTED_on(string_scalar); |
Branch: 1 branch
| Branch | True | False | Total |
| SvTAINTED_on(string_scalar); |
8 |
0 |
8 |
|
| 651 |
84 |
▶ | EXTEND(SP, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 1); |
0 |
84 |
84 |
|
| 652 |
84 |
| PUSHs(string_scalar); |
| 653 |
|
| |
| 654 |
|
| void |
| 655 |
|
| parse_email_groups(...) |
| 656 |
|
| PREINIT: |
| 657 |
|
| SV *string_scalar; |
| 658 |
|
| SV *class_scalar; |
| 659 |
|
| int count; |
| 660 |
|
| HV *hv_class; |
| 661 |
|
| SV *group_scalar; |
| 662 |
|
| SV *addresses_scalar; |
| 663 |
|
| bool utf8; |
| 664 |
|
| bool taint; |
| 665 |
|
| STRLEN input_len; |
| 666 |
|
| const char *input; |
| 667 |
|
| struct message_address *address; |
| 668 |
|
| struct message_address *first_address; |
| 669 |
|
| INPUT: |
| 670 |
|
| const char *this_class_name = "$Package"; |
| 671 |
|
| STRLEN this_class_len = sizeof("$Package")-1; |
| 672 |
|
| INIT: |
| 673 |
51 |
▶ | string_scalar = items >= 1 ? ST(0) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| string_scalar = items >= 1 ? ST(0) : &PL_sv_undef; |
51 |
0 |
51 |
|
| 674 |
51 |
▶ | class_scalar = items >= 2 ? ST(1) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| class_scalar = items >= 2 ? ST(1) : NULL; |
17 |
34 |
51 |
|
| 675 |
51 |
| input = get_perl_scalar_string_value(aTHX_ string_scalar, &input_len, "string", false); |
| 676 |
51 |
| utf8 = SvUTF8(string_scalar); |
| 677 |
51 |
▶ | taint = SvTAINTED(string_scalar); |
Branch: 2 branches
| Branch | True | False | Total |
| taint = SvTAINTED(string_scalar); |
2 |
49 |
51 |
| taint = SvTAINTED(string_scalar); |
1 |
1 |
2 |
|
| 678 |
51 |
| hv_class = get_perl_class_from_perl_scalar_or_cv(aTHX_ class_scalar, cv); |
| 679 |
51 |
▶ | if (class_scalar && !sv_derived_from_pvn(class_scalar, this_class_name, this_class_len, SVf_UTF8)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (class_scalar && !sv_derived_from_pvn(class_scalar, this_class_name, this_class_len, SVf_UTF8)) { |
17 |
34 |
51 |
| if (class_scalar && !sv_derived_from_pvn(class_scalar, this_class_name, this_class_len, SVf_UTF8)) { |
2 |
15 |
17 |
|
| 680 |
2 |
| carp(CARP_WARN, "Class %" SVf " is not derived from %s", SVfARG(class_scalar), this_class_name); |
| 681 |
2 |
| XSRETURN_EMPTY; |
| 682 |
|
| } |
| 683 |
|
| PPCODE: |
| 684 |
49 |
| first_address = message_address_parse(input, input_len, UINT_MAX, MESSAGE_ADDRESS_PARSE_FLAG_NON_STRICT_DOTS_AS_INVALID); |
| 685 |
49 |
| count = count_address_groups(first_address); |
| 686 |
49 |
▶ | EXTEND(SP, count * 2); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, count * 2); |
49 |
0 |
49 |
| EXTEND(SP, count * 2); |
0 |
49 |
49 |
|
| 687 |
49 |
| address = first_address; |
| 688 |
97 |
▶ | while (get_next_perl_address_group(aTHX_ &address, &group_scalar, &addresses_scalar, hv_class, utf8, taint)) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (get_next_perl_address_group(aTHX_ &address, &group_scalar, &addresses_scalar, hv_class, utf8, taint)) { |
48 |
49 |
97 |
|
| 689 |
48 |
| PUSHs(group_scalar); |
| 690 |
48 |
| PUSHs(addresses_scalar); |
| 691 |
|
| } |
| 692 |
49 |
| message_address_free(&first_address); |
| 693 |
|
| |
| 694 |
|
| void |
| 695 |
|
| compose_address(...) |
| 696 |
|
| PREINIT: |
| 697 |
|
| char *string; |
| 698 |
|
| const char *mailbox; |
| 699 |
|
| const char *domain; |
| 700 |
|
| size_t string_len; |
| 701 |
|
| STRLEN mailbox_len; |
| 702 |
|
| STRLEN domain_len; |
| 703 |
|
| bool mailbox_utf8; |
| 704 |
|
| bool domain_utf8; |
| 705 |
|
| bool utf8; |
| 706 |
|
| bool taint; |
| 707 |
|
| SV *mailbox_scalar; |
| 708 |
|
| SV *domain_scalar; |
| 709 |
|
| SV *string_scalar; |
| 710 |
|
| INIT: |
| 711 |
109 |
▶ | mailbox_scalar = items >= 1 ? ST(0) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| mailbox_scalar = items >= 1 ? ST(0) : &PL_sv_undef; |
109 |
0 |
109 |
|
| 712 |
109 |
▶ | domain_scalar = items >= 2 ? ST(1) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| domain_scalar = items >= 2 ? ST(1) : &PL_sv_undef; |
109 |
0 |
109 |
|
| 713 |
109 |
| mailbox = get_perl_scalar_string_value(aTHX_ mailbox_scalar, &mailbox_len, "mailbox", false); |
| 714 |
109 |
| domain = get_perl_scalar_string_value(aTHX_ domain_scalar, &domain_len, "domain", false); |
| 715 |
109 |
| mailbox_utf8 = SvUTF8(mailbox_scalar); |
| 716 |
109 |
| domain_utf8 = SvUTF8(domain_scalar); |
| 717 |
109 |
▶ | utf8 = (mailbox_utf8 || domain_utf8); |
Branch: 2 branches
| Branch | True | False | Total |
| utf8 = (mailbox_utf8 || domain_utf8); |
108 |
1 |
109 |
| utf8 = (mailbox_utf8 || domain_utf8); |
1 |
107 |
108 |
|
| 718 |
109 |
▶ | if (utf8 && !mailbox_utf8) |
Branch: 2 branches
| Branch | True | False | Total |
| if (utf8 && !mailbox_utf8) |
2 |
107 |
109 |
| if (utf8 && !mailbox_utf8) |
1 |
1 |
2 |
|
| 719 |
1 |
| mailbox = get_perl_scalar_value(aTHX_ mailbox_scalar, &mailbox_len, true, true); |
| 720 |
109 |
▶ | if (utf8 && !domain_utf8) |
Branch: 2 branches
| Branch | True | False | Total |
| if (utf8 && !domain_utf8) |
2 |
107 |
109 |
| if (utf8 && !domain_utf8) |
0 |
2 |
2 |
|
| 721 |
0 |
| domain = get_perl_scalar_value(aTHX_ domain_scalar, &domain_len, true, true); |
| 722 |
109 |
▶ | taint = (SvTAINTED(mailbox_scalar) || SvTAINTED(domain_scalar)); |
Branch: 4 branches
| Branch | True | False | Total |
| taint = (SvTAINTED(mailbox_scalar) || SvTAINTED(domain_scalar)); |
6 |
103 |
109 |
| taint = (SvTAINTED(mailbox_scalar) || SvTAINTED(domain_scalar)); |
0 |
6 |
6 |
| taint = (SvTAINTED(mailbox_scalar) || SvTAINTED(domain_scalar)); |
1 |
102 |
103 |
| taint = (SvTAINTED(mailbox_scalar) || SvTAINTED(domain_scalar)); |
1 |
0 |
1 |
|
| 723 |
|
| PPCODE: |
| 724 |
109 |
| compose_address(&string, &string_len, mailbox, mailbox_len, domain, domain_len); |
| 725 |
109 |
| string_scalar = sv_2mortal(newSVpvn(string, string_len)); |
| 726 |
109 |
| string_free(string); |
| 727 |
109 |
▶ | if (utf8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) |
2 |
107 |
109 |
|
| 728 |
2 |
| sv_utf8_decode(string_scalar); |
| 729 |
109 |
▶ | if (taint) |
Branch: 1 branch
| Branch | True | False | Total |
| if (taint) |
7 |
102 |
109 |
|
| 730 |
7 |
▶ | SvTAINTED_on(string_scalar); |
Branch: 1 branch
| Branch | True | False | Total |
| SvTAINTED_on(string_scalar); |
7 |
0 |
7 |
|
| 731 |
109 |
▶ | EXTEND(SP, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 1); |
0 |
109 |
109 |
|
| 732 |
109 |
| PUSHs(string_scalar); |
| 733 |
|
| |
| 734 |
|
| void |
| 735 |
|
| split_address(...) |
| 736 |
|
| PREINIT: |
| 737 |
|
| const char *string; |
| 738 |
|
| char *mailbox; |
| 739 |
|
| char *domain; |
| 740 |
|
| STRLEN string_len; |
| 741 |
|
| size_t mailbox_len; |
| 742 |
|
| size_t domain_len; |
| 743 |
|
| bool utf8; |
| 744 |
|
| bool taint; |
| 745 |
|
| SV *string_scalar; |
| 746 |
|
| SV *mailbox_scalar; |
| 747 |
|
| SV *domain_scalar; |
| 748 |
|
| INIT: |
| 749 |
100 |
▶ | string_scalar = items >= 1 ? ST(0) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| string_scalar = items >= 1 ? ST(0) : &PL_sv_undef; |
100 |
0 |
100 |
|
| 750 |
100 |
| string = get_perl_scalar_string_value(aTHX_ string_scalar, &string_len, "string", false); |
| 751 |
100 |
| utf8 = SvUTF8(string_scalar); |
| 752 |
100 |
▶ | taint = SvTAINTED(string_scalar); |
Branch: 2 branches
| Branch | True | False | Total |
| taint = SvTAINTED(string_scalar); |
2 |
98 |
100 |
| taint = SvTAINTED(string_scalar); |
2 |
0 |
2 |
|
| 753 |
|
| PPCODE: |
| 754 |
100 |
| split_address(string, string_len, &mailbox, &mailbox_len, &domain, &domain_len); |
| 755 |
100 |
▶ | mailbox_scalar = mailbox ? sv_2mortal(newSVpvn(mailbox, mailbox_len)) : sv_newmortal(); |
Branch: 1 branch
| Branch | True | False | Total |
| mailbox_scalar = mailbox ? sv_2mortal(newSVpvn(mailbox, mailbox_len)) : sv_newmortal(); |
92 |
8 |
100 |
|
| 756 |
100 |
▶ | domain_scalar = domain ? sv_2mortal(newSVpvn(domain, domain_len)) : sv_newmortal(); |
Branch: 1 branch
| Branch | True | False | Total |
| domain_scalar = domain ? sv_2mortal(newSVpvn(domain, domain_len)) : sv_newmortal(); |
92 |
8 |
100 |
|
| 757 |
100 |
| string_free(mailbox); |
| 758 |
100 |
| string_free(domain); |
| 759 |
100 |
▶ | if (utf8) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (utf8) { |
0 |
100 |
100 |
|
| 760 |
0 |
| sv_utf8_decode(mailbox_scalar); |
| 761 |
0 |
| sv_utf8_decode(domain_scalar); |
| 762 |
|
| } |
| 763 |
100 |
▶ | if (taint) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (taint) { |
2 |
98 |
100 |
|
| 764 |
2 |
▶ | SvTAINTED_on(mailbox_scalar); |
Branch: 1 branch
| Branch | True | False | Total |
| SvTAINTED_on(mailbox_scalar); |
2 |
0 |
2 |
|
| 765 |
2 |
▶ | SvTAINTED_on(domain_scalar); |
Branch: 1 branch
| Branch | True | False | Total |
| SvTAINTED_on(domain_scalar); |
2 |
0 |
2 |
|
| 766 |
|
| } |
| 767 |
100 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
100 |
100 |
|
| 768 |
100 |
| PUSHs(mailbox_scalar); |
| 769 |
100 |
| PUSHs(domain_scalar); |
| 770 |
|
| |
| 771 |
|
| bool |
| 772 |
|
| is_obj(...) |
| 773 |
|
| PREINIT: |
| 774 |
11 |
▶ | SV *class = items >= 1 ? ST(0) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| SV *class = items >= 1 ? ST(0) : &PL_sv_undef; |
11 |
0 |
11 |
|
| 775 |
11 |
▶ | SV *object = items >= 2 ? ST(1) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| SV *object = items >= 2 ? ST(1) : &PL_sv_undef; |
11 |
0 |
11 |
|
| 776 |
|
| CODE: |
| 777 |
11 |
| RETVAL = is_class_object(aTHX_ class, NULL, 0, object); |
| 778 |
|
| OUTPUT: |
| 779 |
|
| RETVAL |