| 1 | package DJabberd::JID; | ||||||||||||||||||||||||||||||||
| 2 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use DJabberd::Util qw(exml); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 20 | ▶ | use Digest::SHA1; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | # Configurable via 'CaseSensitive' config option | ||||||||||||||||||||||||||||||||
| 7 | 20 | our $CASE_SENSITIVE = 0; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | use overload | ||||||||||||||||||||||||||||||||
| 10 | 20 | ▶ | '""' => \&as_string_exml; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 20 | ▶ | use constant NODE => 0; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 20 | ▶ | use constant DOMAIN => 1; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 20 | ▶ | use constant RES => 2; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 20 | ▶ | use constant AS_STRING => 3; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 20 | ▶ | use constant AS_BSTRING => 4; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 20 | ▶ | use constant AS_STREXML => 5; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | # Stringprep functions for converting to canonical form | ||||||||||||||||||||||||||||||||
| 20 | 20 | ▶ | use Unicode::Stringprep; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | 20 | ▶ | use Unicode::Stringprep::Mapping; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | 20 | ▶ | use Unicode::Stringprep::Prohibited; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 23 | 20 | my $nodeprep = Unicode::Stringprep->new( | |||||||||||||||||||||||||||||||
| 24 | 3.2, | ||||||||||||||||||||||||||||||||
| 25 | [ | ||||||||||||||||||||||||||||||||
| 26 | \@Unicode::Stringprep::Mapping::B1, | ||||||||||||||||||||||||||||||||
| 27 | \@Unicode::Stringprep::Mapping::B2, | ||||||||||||||||||||||||||||||||
| 28 | ], | ||||||||||||||||||||||||||||||||
| 29 | 'KC', | ||||||||||||||||||||||||||||||||
| 30 | [ | ||||||||||||||||||||||||||||||||
| 31 | \@Unicode::Stringprep::Prohibited::C11, | ||||||||||||||||||||||||||||||||
| 32 | \@Unicode::Stringprep::Prohibited::C12, | ||||||||||||||||||||||||||||||||
| 33 | \@Unicode::Stringprep::Prohibited::C21, | ||||||||||||||||||||||||||||||||
| 34 | \@Unicode::Stringprep::Prohibited::C22, | ||||||||||||||||||||||||||||||||
| 35 | \@Unicode::Stringprep::Prohibited::C3, | ||||||||||||||||||||||||||||||||
| 36 | \@Unicode::Stringprep::Prohibited::C4, | ||||||||||||||||||||||||||||||||
| 37 | \@Unicode::Stringprep::Prohibited::C5, | ||||||||||||||||||||||||||||||||
| 38 | \@Unicode::Stringprep::Prohibited::C6, | ||||||||||||||||||||||||||||||||
| 39 | \@Unicode::Stringprep::Prohibited::C7, | ||||||||||||||||||||||||||||||||
| 40 | \@Unicode::Stringprep::Prohibited::C8, | ||||||||||||||||||||||||||||||||
| 41 | \@Unicode::Stringprep::Prohibited::C9, | ||||||||||||||||||||||||||||||||
| 42 | [ | ||||||||||||||||||||||||||||||||
| 43 | 0x0022, undef, # " | ||||||||||||||||||||||||||||||||
| 44 | 0x0026, undef, # & | ||||||||||||||||||||||||||||||||
| 45 | 0x0027, undef, # ' | ||||||||||||||||||||||||||||||||
| 46 | 0x002F, undef, # / | ||||||||||||||||||||||||||||||||
| 47 | 0x003A, undef, # : | ||||||||||||||||||||||||||||||||
| 48 | 0x003C, undef, # < | ||||||||||||||||||||||||||||||||
| 49 | 0x003E, undef, # > | ||||||||||||||||||||||||||||||||
| 50 | 0x0040, undef, # @ | ||||||||||||||||||||||||||||||||
| 51 | ] | ||||||||||||||||||||||||||||||||
| 52 | ], | ||||||||||||||||||||||||||||||||
| 53 | 1, | ||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||
| 55 | 20 | my $nameprep = Unicode::Stringprep->new( | |||||||||||||||||||||||||||||||
| 56 | 3.2, | ||||||||||||||||||||||||||||||||
| 57 | [ | ||||||||||||||||||||||||||||||||
| 58 | \@Unicode::Stringprep::Mapping::B1, | ||||||||||||||||||||||||||||||||
| 59 | \@Unicode::Stringprep::Mapping::B2, | ||||||||||||||||||||||||||||||||
| 60 | ], | ||||||||||||||||||||||||||||||||
| 61 | 'KC', | ||||||||||||||||||||||||||||||||
| 62 | [ | ||||||||||||||||||||||||||||||||
| 63 | \@Unicode::Stringprep::Prohibited::C12, | ||||||||||||||||||||||||||||||||
| 64 | \@Unicode::Stringprep::Prohibited::C22, | ||||||||||||||||||||||||||||||||
| 65 | \@Unicode::Stringprep::Prohibited::C3, | ||||||||||||||||||||||||||||||||
| 66 | \@Unicode::Stringprep::Prohibited::C4, | ||||||||||||||||||||||||||||||||
| 67 | \@Unicode::Stringprep::Prohibited::C5, | ||||||||||||||||||||||||||||||||
| 68 | \@Unicode::Stringprep::Prohibited::C6, | ||||||||||||||||||||||||||||||||
| 69 | \@Unicode::Stringprep::Prohibited::C7, | ||||||||||||||||||||||||||||||||
| 70 | \@Unicode::Stringprep::Prohibited::C8, | ||||||||||||||||||||||||||||||||
| 71 | \@Unicode::Stringprep::Prohibited::C9, | ||||||||||||||||||||||||||||||||
| 72 | ], | ||||||||||||||||||||||||||||||||
| 73 | 1, | ||||||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||||||
| 75 | 20 | my $resourceprep = Unicode::Stringprep->new( | |||||||||||||||||||||||||||||||
| 76 | 3.2, | ||||||||||||||||||||||||||||||||
| 77 | [ | ||||||||||||||||||||||||||||||||
| 78 | \@Unicode::Stringprep::Mapping::B1, | ||||||||||||||||||||||||||||||||
| 79 | ], | ||||||||||||||||||||||||||||||||
| 80 | 'KC', | ||||||||||||||||||||||||||||||||
| 81 | [ | ||||||||||||||||||||||||||||||||
| 82 | \@Unicode::Stringprep::Prohibited::C12, | ||||||||||||||||||||||||||||||||
| 83 | \@Unicode::Stringprep::Prohibited::C21, | ||||||||||||||||||||||||||||||||
| 84 | \@Unicode::Stringprep::Prohibited::C22, | ||||||||||||||||||||||||||||||||
| 85 | \@Unicode::Stringprep::Prohibited::C3, | ||||||||||||||||||||||||||||||||
| 86 | \@Unicode::Stringprep::Prohibited::C4, | ||||||||||||||||||||||||||||||||
| 87 | \@Unicode::Stringprep::Prohibited::C5, | ||||||||||||||||||||||||||||||||
| 88 | \@Unicode::Stringprep::Prohibited::C6, | ||||||||||||||||||||||||||||||||
| 89 | \@Unicode::Stringprep::Prohibited::C7, | ||||||||||||||||||||||||||||||||
| 90 | \@Unicode::Stringprep::Prohibited::C8, | ||||||||||||||||||||||||||||||||
| 91 | \@Unicode::Stringprep::Prohibited::C9, | ||||||||||||||||||||||||||||||||
| 92 | ], | ||||||||||||||||||||||||||||||||
| 93 | 1, | ||||||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | # returns DJabberd::JID object, or undef on failure due to invalid format | ||||||||||||||||||||||||||||||||
| 98 | 20 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 99 | #my ($class, $jidstring) = @_; | ||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | # The following regex is loosely based on the EBNF grammar in | ||||||||||||||||||||||||||||||||
| 102 | # JEP-0029. This JEP has actually been retracted, but seems to be | ||||||||||||||||||||||||||||||||
| 103 | # the only reasonable spec for JID syntax. | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | # NOTE: Currently this only supports US-ASCII characters. | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | 20 | ▶ | return undef unless $_[1] && $_[1] =~ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_[1] and $_[1] =~ m[^(?: ([\x29\x23-\x25\x28-\x2E\x30-\x39\x3B\x3D\x3F\x41-\x7E]{1,1023}) \@)? # $1: optional node
([a-zA-Z0-9\.\-]{1,1023}) # $2: domain
(?: /(.{1,1023}) )? # $3: optional resource
$]x
MC/DC0%0/2
$_[1] and $_[1] =~ m[^(?: ([\x29\x23-\x25\x28-\x2E\x30-\x39\x3B\x3D\x3F\x41-\x7E]{1,1023}) \@)? # $1: optional node
([a-zA-Z0-9\.\-]{1,1023}) # $2: domain
(?: /(.{1,1023}) )? # $3: optional resource
$]x
$_[1]
$_[1] =~ m[^(?: ([\x29\x23-\x25\x28-\x2E\x30-\x39\x3B\x3D\x3F\x41-\x7E]{1,1023}) \@)? # $1: optional node
([a-zA-Z0-9\.\-]{1,1023}) # $2: domain
(?: /(.{1,1023}) )? # $3: optional resource
$]x
Truth table33%1/3
A and B
A= $_[1]B= $_[1] =~ m[^(?: ([\x29\x23-\x25\x28-\x2E\x30-\x39\x3B\x3D\x3F\x41-\x7E]{1,1023}) \@)? # $1: optional node
([a-zA-Z0-9\.\-]{1,1023}) # $2: domain
(?: /(.{1,1023}) )? # $3: optional resource
$]x
| |||||||||||||||||||||||||||||||||
| 108 | m!^(?: ([\x29\x23-\x25\x28-\x2E\x30-\x39\x3B\x3D\x3F\x41-\x7E]{1,1023}) \@)? # $1: optional node | ||||||||||||||||||||||||||||||||
| 109 | ([a-zA-Z0-9\.\-]{1,1023}) # $2: domain | ||||||||||||||||||||||||||||||||
| 110 | (?: /(.{1,1023}) )? # $3: optional resource | ||||||||||||||||||||||||||||||||
| 111 | $!x; | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | # If we're in case-sensitive mode, for backwards-compatibility, | ||||||||||||||||||||||||||||||||
| 114 | # then skip stringprep | ||||||||||||||||||||||||||||||||
| 115 | 20 | ▶ | return bless [ $1, $2, $3 ], $_[0] if $DJabberd::JID::CASE_SENSITIVE; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | # Stringprep uses regexes, so store these away first | ||||||||||||||||||||||||||||||||
| 118 | 10 | my ($node, $host, $res) = ($1, $2, $3); | |||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 10 | return eval { | |||||||||||||||||||||||||||||||
| 121 | 10 | ▶ | bless [ | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 122 | defined $node ? $nodeprep->($node) : undef, | ||||||||||||||||||||||||||||||||
| 123 | $nameprep->($host), | ||||||||||||||||||||||||||||||||
| 124 | defined $res ? $resourceprep->($res) : undef, | ||||||||||||||||||||||||||||||||
| 125 | ], $_[0] | ||||||||||||||||||||||||||||||||
| 126 | }; | ||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub is_bare { | ||||||||||||||||||||||||||||||
|
Subroutine
is_bare: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | return $_[0]->[RES] ? 0 : 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub node { | ||||||||||||||||||||||||||||||
|
Subroutine
node: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 134 | 0 | return $_[0]->[NODE]; | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub domain { | ||||||||||||||||||||||||||||||
|
Subroutine
domain: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 138 | 0 | return $_[0]->[DOMAIN]; | |||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub resource { | ||||||||||||||||||||||||||||||
|
Subroutine
resource: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 142 | 0 | return $_[0]->[RES]; | |||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub eq { | ||||||||||||||||||||||||||||||
|
Subroutine
eq: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 146 | 0 | my ($self, $jid) = @_; | |||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | return $jid && $self->as_string eq $jid->as_string; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$jid && $self->as_string eq $jid->as_string
MC/DC0%0/2
$jid && $self->as_string eq $jid->as_string
$jid
$self->as_string eq $jid->as_string
Truth table0%0/3
A && B
A= $jidB= $self->as_string eq $jid->as_string
| |||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | 20 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 151 | 20 | my $self = $_[0]; | |||||||||||||||||||||||||||||||
| 152 | 20 | ▶ | return $self->[AS_STRING] ||= | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$self->[3] ||= join("", $self->[0] ? ($self->[0], "\@") : (), $self->[1], $self->[2] ? ("/", $self->[2]) : ())
MC/DC0%0/2
$self->[3] ||= join("", $self->[0] ? ($self->[0], "\@") : (), $self->[1], $self->[2] ? ("/", $self->[2]) : ())
$self->[3]
join("", $self->[0] ? ($self->[0], "\@") : (), $self->[1], $self->[2] ? ("/", $self->[2]) : ())
Truth table33%1/3
A ||= B
A= $self->[3]B= join("", $self->[0] ? ($self->[0], "\@") : (), $self->[1], $self->[2] ? ("/", $self->[2]) : ())
| |||||||||||||||||||||||||||||||||
| 153 | join('', | ||||||||||||||||||||||||||||||||
| 154 | ($self->[NODE] ? ($self->[NODE], '@') : ()), | ||||||||||||||||||||||||||||||||
| 155 | $self->[DOMAIN], | ||||||||||||||||||||||||||||||||
| 156 | ($self->[RES] ? ('/', $self->[RES]) : ())); | ||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub as_string_exml { | ||||||||||||||||||||||||||||||
|
Subroutine
as_string_exml: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 160 | 0 | my $self = $_[0]; | |||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | return $self->[AS_STREXML] ||= | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->[5] ||= exml($self->as_string)
MC/DC0%0/2
$self->[5] ||= exml($self->as_string)
$self->[5]
exml($self->as_string)
Truth table0%0/3
A ||= B
A= $self->[5]B= exml($self->as_string)
| |||||||||||||||||||||||||||||||||
| 162 | exml($self->as_string); | ||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub as_bare_string { | ||||||||||||||||||||||||||||||
|
Subroutine
as_bare_string: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 166 | 0 | my $self = $_[0]; | |||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | return $self->[AS_BSTRING] ||= | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->[4] ||= join("", $self->[0] ? ($self->[0], "\@") : (), $self->[1])
MC/DC0%0/2
$self->[4] ||= join("", $self->[0] ? ($self->[0], "\@") : (), $self->[1])
$self->[4]
join("", $self->[0] ? ($self->[0], "\@") : (), $self->[1])
Truth table0%0/3
A ||= B
A= $self->[4]B= join("", $self->[0] ? ($self->[0], "\@") : (), $self->[1])
| |||||||||||||||||||||||||||||||||
| 168 | join('', | ||||||||||||||||||||||||||||||||
| 169 | ($self->[NODE] ? ($self->[NODE], '@') : ()), | ||||||||||||||||||||||||||||||||
| 170 | $self->[DOMAIN]); | ||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub rand_resource { | ||||||||||||||||||||||||||||||
|
Subroutine
rand_resource: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 174 | 0 | Digest::SHA1::sha1_hex(rand() . rand() . rand()); | |||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||
| 177 | 20 | 1; | |||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||