| 1 | package DJabberd::Util; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 20 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 20 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 20 | our @EXPORT_OK = qw(exml tsub lbsub as_bool as_num as_abs_path as_bind_addr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | sub as_bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_bool: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | return 1 if $val =~ /^1|y|yes|true|t|on|enabled?$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | return 0 if $val =~ /^0|n|no|false|f|off|disabled?$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | die "Can't determine booleanness of '$val'\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub as_num { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_num: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | return $val if $val =~ /^\d+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | die "'$val' is not a number\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 85 | ▶ | sub as_bind_addr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_bind_addr: called CC=4 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 85 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # Must either be like 127.0.0.1:1234, a bare port number or an absolute path to a unix domain socket | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 85 | ▶ | if ($val =~ /^(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?:)?\d+$/ || ($val =~ m!^/! && -e $val)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$val =~ /^(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?:)?\d+$/ or $val =~ m[^/] and -e $val
$val =~ m[^/] and -e $val
MC/DC0%0/3
$val =~ /^(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?:)?\d+$/ or $val =~ m[^/] and -e $val
$val =~ /^(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?:)?\d+$/
$val =~ m[^/]
-e $val
Truth table25%1/4
A or B and C
A= $val =~ /^(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?:)?\d+$/B= $val =~ m[^/]C= -e $val
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 85 | return $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | die "'$val' is not a valid bind address or port\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub as_abs_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_abs_path: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | die "Path '$val' isn't absolute" unless $val =~ m!^/!; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | die "File '$val' doesn't exist" unless -f $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | return $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | sub exml | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1130 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exml: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # fast path for the commmon case: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1130 | ▶ | return $_[0] unless $_[0] =~ /[&\"\'<>\x00-\x08\x0B\x0C\x0E-\x1F]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # what are those character ranges? XML 1.0 allows: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 239 | my $a = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 239 | $a =~ s/\&/&/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 239 | $a =~ s/\"/"/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 239 | $a =~ s/\'/'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 239 | $a =~ s/</</g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 239 | $a =~ s/>/>/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 239 | $a =~ s/[\x00-\x08\x0B\x0C\x0E-\x1F]//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 239 | return $a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub durl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
durl: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my ($a) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $a =~ tr/+/ /; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $a =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | return $a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # tracked sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub tsub (&) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tsub: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $subref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | bless $subref, 'DJabberd::TrackedSub'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | DJabberd->track_new_obj($subref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return $subref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # line-blessed sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub lbsub (&) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lbsub: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $subref = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my ($pkg, $file, $line) = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $bpkg = $file . "_" . $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $bpkg =~ s/[^\w]/_/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | return bless $subref, "DJabberd::AnonSubFrom::$bpkg"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub numeric_entity_clean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
numeric_entity_clean: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $hex = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $val = hex $hex; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # under a space, only \n, \r, and \t are allowed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ($val < 32 && ($val != 13 && $val != 10 && $val != 9)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$val < 32 and ($val != 13 and $val != 10 and $val != 9)
$val != 13 and $val != 10 and $val != 9
$val != 13 and $val != 10
MC/DC0%0/4
$val < 32 and ($val != 13 and $val != 10 and $val != 9)
$val < 32
$val != 13
$val != 10
$val != 9
Truth table0%0/5
A and B and C and D
A= $val < 32B= $val != 13C= $val != 10D= $val != 9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | return ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | return "&#$hex;"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | package DJabberd::TrackedSub; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | DJabberd->track_destroyed_obj($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 20 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||