| 1 | package DJabberd::VHost; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use B (); # improved debugging when hooks are called | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 20 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 20 | ▶ | use DJabberd::Util qw(tsub as_bool); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 20 | ▶ | use DJabberd::Log; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 20 | ▶ | use DJabberd::JID; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 20 | ▶ | use DJabberd::Roster; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 20 | our $logger = DJabberd::Log->get_logger(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 20 | our $hook_logger = DJabberd::Log->get_logger("DJabberd::Hook"); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 43 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=20.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 43 | my ($class, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | my $self = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 'server_name' => lc(delete $opts{server_name} || ""), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 'require_ssl' => delete $opts{require_ssl}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 's2s' => delete $opts{s2s}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 43 | ▶ | 'hooks' => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $opts{'server_name'} || ''
MC/DC0%0/1
delete $opts{'server_name'} || ''
delete $opts{'server_name'}
Truth table50%1/2
A
A= delete $opts{'server_name'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 'server' => undef, # set when added to a server | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # local connections | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 'jid2sock' => {}, # bob@207.7.148.210/rez -> DJabberd::Connection | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 'bare2fulls' => {}, # barejids -> { fulljid -> 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 'quirksmode' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 'server_secret' => undef, # server secret we use for dialback HMAC keys. trumped | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # if a plugin implements a cluster-wide keyed shared secret | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | features => [], # list of features | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | subdomain => {}, # subdomain => plugin mapping of subdomains we should accept | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | inband_reg => 0, # bool: inband registration | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | roster_cache => {}, # $barejid_str -> DJabberd::Roster | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | roster_wanters => {}, # $barejid_str -> [ [$on_success, $on_fail]+ ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | disco_kids => {}, # $jid_str -> "Description" - children of this vhost for service discovery | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | plugin_types => {}, # ref($plugin instance) -> 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | croak("Missing/invalid vhost name") unless | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 43 | ▶ | $self->{server_name} && $self->{server_name} =~ /^[-\w\.]+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"server_name"} and $self->{"server_name"} =~ /^[-\w\.]+$/
MC/DC0%0/2
$self->{"server_name"} and $self->{"server_name"} =~ /^[-\w\.]+$/
$self->{"server_name"}
$self->{"server_name"} =~ /^[-\w\.]+$/
Truth table33%1/3
A and B
A= $self->{"server_name"}B= $self->{"server_name"} =~ /^[-\w\.]+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 43 | my $plugins = delete $opts{plugins}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 43 | ▶ | croak("Unknown vhost parameters: " . join(", ", keys %opts)) if %opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 43 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 43 | $logger->info("Addding plugins..."); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 43 | ▶ | foreach my $pl (@{ $plugins || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$plugins || []
MC/DC100%1/1
$plugins || []
$plugins
Truth table100%2/2
A
A= $plugins
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 210 | $self->add_plugin($pl); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 43 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub register_subdomain { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_subdomain: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my ($self, $subdomain, $plugin) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $qualified_subdomain = $subdomain . "." . $self->{server_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | $logger->logdie("VHost '$self->{server_name}' already has '$subdomain' registered by plugin '$self->{subdomain}->{$qualified_subdomain}'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if $self->{subdomain}->{$qualified_subdomain}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $self->{subdomain}->{$qualified_subdomain} = $plugin; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub handles_domain { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handles_domain: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my ($self, $domain) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($self->{server_name} eq $domain) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } elsif (exists $self->{subdomain}->{$domain}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub server_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | return $self->{server_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub add_feature { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_feature: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my ($self, $feature) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | push @{$self->{features}}, $feature; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub features { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
features: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return @{$self->{features}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 43 | ▶ | sub setup_default_plugins { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup_default_plugins: called CC=9 SCAR=23.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 43 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 43 | ▶ | unless ($self->are_hooks("deliver")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | ▶ | unless ($self->has_plugin_of_type("DJabberd::Delivery::Local")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | $logger->logwarn("Adding implicit plugin DJabberd::Delivery::Local"); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | $self->add_plugin(DJabberd::Delivery::Local->new); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | if ($self->s2s && ! $self->has_plugin_of_type("DJabberd::Delivery::S2S")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->s2s and not $self->has_plugin_of_type("DJabberd::Delivery::S2S")
MC/DC0%0/2
$self->s2s and not $self->has_plugin_of_type("DJabberd::Delivery::S2S")
$self->s2s
not $self->has_plugin_of_type("DJabberd::Delivery::S2S")
Truth table33%1/3
A and not(B)
A= $self->s2sB= not $self->has_plugin_of_type("DJabberd::Delivery::S2S")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | $logger->logwarn("Adding implicit plugin DJabberd::Delivery::S2S"); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | $self->add_plugin(DJabberd::Delivery::S2S->new); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 43 | ▶ | unless ($self->has_plugin_of_type("DJabberd::Delivery::Local")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $logger->logwarn("No DJabberd::Delivery::Local delivery plugin configured"); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 43 | ▶ | if ($self->s2s && ! $self->has_plugin_of_type("DJabberd::Delivery::S2S")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->s2s and not $self->has_plugin_of_type("DJabberd::Delivery::S2S")
MC/DC0%0/2
$self->s2s and not $self->has_plugin_of_type("DJabberd::Delivery::S2S")
$self->s2s
not $self->has_plugin_of_type("DJabberd::Delivery::S2S")
Truth table66%2/3
A and not(B)
A= $self->s2sB= not $self->has_plugin_of_type("DJabberd::Delivery::S2S")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $logger->logdie("s2s enabled, but no implicit or explicit DJabberd::Delivery::S2S plugin."); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 43 | ▶ | unless ($self->are_hooks("PresenceCheck")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 42 | $self->add_plugin(DJabberd::PresenceChecker::Local->new); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub quirksmode { $_[0]{quirksmode} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quirksmode: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 6 | ▶ | sub set_config_quirksmode { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_config_quirksmode: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 6 | my ($self, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | $self->{quirksmode} = as_bool($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub set_config_s2s { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_config_s2s: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my ($self, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->{s2s} = as_bool($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | sub set_config_inbandreg { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_config_inbandreg: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | my ($self, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | $self->{inband_reg} = as_bool($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub set_config_childservice { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_config_childservice: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my ($self, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my ($strjid, $desc) = split(/\s+/, $val, 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $jid = DJabberd::JID->new($strjid); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $logger->logdie("Invalid JID ".$strjid) unless $jid; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | $desc ||= $jid->node; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$desc ||= $jid->node
MC/DC0%0/2
$desc ||= $jid->node
$desc
$jid->node
Truth table0%0/3
A ||= B
A= $descB= $jid->node
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $logger->info("Registered $strjid as VHost child service: $desc"); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $self->{disco_kids}{$jid} = $desc; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub allow_inband_registration { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allow_inband_registration: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | return $self->{inband_reg}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub set_config_requiressl { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_config_requiressl: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my ($self, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $self->{require_ssl} = as_bool($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # true if vhost has s2s enabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 44 | ▶ | sub s2s { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
s2s: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 44 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 44 | return $self->{s2s}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub child_services { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
child_services: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | return $_[0]->{disco_kids}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 43 | ▶ | sub server { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 43 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 43 | return $self->{server}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 43 | ▶ | sub set_server { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_server: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 43 | my ($self, $server) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 43 | $self->{server} = $server; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 43 | Scalar::Util::weaken($self->{server}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 5 | ▶ | sub run_hook_chain { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_hook_chain: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 5 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | my ($phase, $methods, $args, $fallback, $hook_inv) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 5 | = @opts{qw(phase methods args fallback hook_invocant)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 5 | if (0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | delete @opts{qw(phase methods args fallback hook_invocant)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | die if %opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | hook_chain_fast($self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | $phase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | $args || [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | $methods || {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | ▶ | $fallback || sub {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 5 | ▶ | $hook_inv); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition57%4/7
$args || []
$methods || {}
$fallback || sub {
}
MC/DC0%0/1
$args || []
$args
MC/DC0%0/1
$methods || {}
$methods
MC/DC0%0/2
$fallback || sub {
}
$fallback
sub {
}
Truth table50%1/2
A
A= $args
Truth table50%1/2
A
A= $methods
Truth table66%2/3
A || B
A= $fallbackB= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 20 | ▶ | my $dummy_sub = sub {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 5 | ▶ | sub hook_chain_fast { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hook_chain_fast: called CC=12 SCAR=28.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 5 | my ($self, $phase, $args, $methods, $fallback, $hook_inv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # fast path, no phases, only fallback: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 5 | ▶ | if ($self && ! ref $phase && ! @{ $self->{hooks}->{$phase} || []}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition62%5/8
$self and not ref $phase and not @{$self->{"hooks"}{$phase} or [];}
$self and not ref $phase
$self->{'hooks'}{$phase} || []
MC/DC33%1/3
$self and not ref $phase and not @{$self->{"hooks"}{$phase} or [];}
$self
not ref $phase
not @{$self->{"hooks"}{$phase} or [];}
MC/DC100%1/1
$self->{'hooks'}{$phase} || []
$self->{'hooks'}{$phase}
Truth table50%2/4
A and not(B) and not(C)
A= $selfB= not ref $phaseC= not @{$self->{"hooks"}{$phase} or [];}
Truth table100%2/2
A
A= $self->{'hooks'}{$phase}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | ▶ | $fallback->($self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | DJabberd::Callback->new({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | _phase => $phase, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | decline => $dummy_sub, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | declined => $dummy_sub, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | stop_chain => $dummy_sub, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | %$methods, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | @$args) if $fallback; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # make phase into an arrayref; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 4 | ▶ | $phase = [ $phase ] unless ref $phase; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 4 | my @hooks; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 4 | foreach my $ph (@$phase) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | $logger->logcroak("Undocumented hook phase: '$ph'") unless | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 4 | ▶ | $DJabberd::HookDocs::hook{$ph}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # self can be undef if the connection object invokes us. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # because sometimes there is no vhost, as in the case of | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # old serverin dialback without a to address. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 4 | ▶ | if ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 4 | ▶ | push @hooks, @{ $self->{hooks}->{$ph} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'hooks'}{$ph} || []
MC/DC0%0/1
$self->{'hooks'}{$ph} || []
$self->{'hooks'}{$ph}
Truth table50%1/2
A
A= $self->{'hooks'}{$ph}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 4 | ▶ | push @hooks, $fallback if $fallback; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # pre-declared here so they're captured by closures below | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 4 | my ($cb, $try_another, $depth); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 4 | my $hook_count = scalar @hooks; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | my $stopper = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $try_another = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 5 | ▶ | $try_another = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=27.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 5 | ▶ | my $hk = shift @hooks | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # conditional debug statement -- computing this is costly, so only do this | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # when we are actually running in debug mode --kane | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 5 | ▶ | if ($logger->is_debug) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $depth++; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # most hooks are anonymous sub refs, and it's hard to determine where they | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # came from. Sub::Identify gives you only the name (which is __ANON__) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # the filename. This gives us both the filename and line number it's defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # on, giving the user a very clear pointer to which subref will be invoked --kane | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # Since this is B pokery, protect us from doing anything wrong and exiting the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # server accidentally. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $cv = B::svref_2object($hk); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | my $line = eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
my $obj = $cv->ROOT->first;
$obj = $obj->first while $obj->can('first');
$obj->line
}
} || "Unknown ($@)"
MC/DC0%0/1
eval {
do {
my $obj = $cv->ROOT->first;
$obj = $obj->first while $obj->can('first');
$obj->line
}
} || "Unknown ($@)"
eval {
do {
my $obj = $cv->ROOT->first;
$obj = $obj->first while $obj->can('first');
$obj->line
}
}
Truth table0%0/2
A
A= eval {
do {
my $obj = $cv->ROOT->first;
$obj = $obj->first while $obj->can('first');
$obj->line
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # $obj is either a B::LISTOP or a B::COP, keep walking up | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # till we reach the B::COP, so we can get the line number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $obj = $cv->ROOT->first; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | $obj = $obj->first while $obj->can('first'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $obj->line; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } || "Unknown ($@)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | $logger->debug( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | "For phase [@$phase] invoking hook $depth of $hook_count defined at: ". | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | $cv->FILE .':'. $line | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 5 | $cb->{_has_been_called} = 0; # cheating version of: $cb->reset; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 5 | ▶ | $hk->($self || $hook_inv, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self || $hook_inv
MC/DC0%0/2
$self || $hook_inv
$self
$hook_inv
Truth table33%1/3
A || B
A= $selfB= $hook_inv
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | $cb, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | @$args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # just in case the last person in the chain forgets | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # to call a callback, we destroy the circular reference ourselves. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 5 | ▶ | unless (@hooks) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | $try_another = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 2 | $cb = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | $cb = DJabberd::Callback->new({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | _phase => $phase->[0], # just for leak tracking, not needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | decline => $try_another, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | declined => $try_another, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | stop_chain => $stopper, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 4 | ▶ | _post_fire => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # when somebody fires this callback, we know | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # we're done (unless it was decline/declined) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # and we need to clean up circular references | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 4 | my $fired = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 4 | ▶ | unless ($fired =~ /^decline/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 3 | $try_another = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 3 | $cb = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 4 | %$methods, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 4 | $try_another->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # return the version of the spec we implement | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | sub spec_version { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spec_version: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | return $self->{_spec_version} ||= DJabberd::StreamVersion->new("1.0"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"_spec_version"} ||= "DJabberd::StreamVersion"->new("1.0")
MC/DC0%0/2
$self->{"_spec_version"} ||= "DJabberd::StreamVersion"->new("1.0")
$self->{"_spec_version"}
"DJabberd::StreamVersion"->new("1.0")
Truth table0%0/3
A ||= B
A= $self->{"_spec_version"}B= "DJabberd::StreamVersion"->new("1.0")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 43 | ▶ | sub name { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 43 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 43 | return $self->{server_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # vhost method | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 255 | ▶ | sub add_plugin { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_plugin: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 255 | my ($self, $plugin) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 255 | $logger->info("Adding plugin: $plugin"); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 255 | $self->{plugin_types}{ref $plugin} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 255 | $plugin->register($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 20 | *requires_ssl = \&require_ssl; # english | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | sub require_ssl { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
require_ssl: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | return $self->{require_ssl}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 86 | ▶ | sub are_hooks { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
are_hooks: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 86 | my ($self, $phase) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 86 | ▶ | return scalar @{ $self->{hooks}{$phase} || [] } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{'hooks'}{$phase} || []
MC/DC100%1/1
$self->{'hooks'}{$phase} || []
$self->{'hooks'}{$phase}
Truth table100%2/2
A
A= $self->{'hooks'}{$phase}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 86 | ▶ | sub has_plugin_of_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_plugin_of_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 86 | my ($self, $class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 86 | return $self->{plugin_types}{$class}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 594 | ▶ | sub register_hook { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_hook: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 594 | my ($self, $phase, $subref) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 594 | ▶ | Carp::croak("Can't register hook on a non-VHost") unless UNIVERSAL::isa($self, "DJabberd::VHost"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | $logger->logcroak("Undocumented hook phase: '$phase'") unless | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 594 | ▶ | $DJabberd::HookDocs::hook{$phase}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 594 | ▶ | push @{ $self->{hooks}{$phase} ||= [] }, $subref; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"hooks"}{$phase} ||= []
MC/DC100%1/1
$self->{"hooks"}{$phase} ||= []
$self->{"hooks"}{$phase}
Truth table100%2/2
A
A= $self->{"hooks"}{$phase}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # lookup a local user by fulljid | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | sub find_jid { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_jid: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my ($self, $jid) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | return $self->find_jid($jid->as_string) if ref $jid; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | my $sock = $self->{jid2sock}{$jid} or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | return undef if $sock->{closed}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | return $sock; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | sub register_jid { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_jid: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | my ($self, $jid, $resource, $conn, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | my $barestr = $jid->as_bare_string; ## $jid should be bare anyway | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | my $fullstr = "$barestr/$resource"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | # $cb can ->registered, ->error | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | $logger->info("Registering '$fullstr' to connection '$conn->{id}'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | ## deprecated 0078 appears a bit conflicting with RFC 3920 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | ## the recommended behaviour in the latter is to generate a resource for | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | ## the dupe. Don't ask me if one resource uses RFC 3920 and the other | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | ## XEP 0078 :D. If we detect a sasl connection, we go with the RFC way. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | if (my $econn = $self->{jid2sock}{$fullstr}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | if ($conn->sasl) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | my $resource = DJabberd::JID->rand_resource; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $fullstr = "$barestr/$resource"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | $econn->stream_error("conflict"); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my $fulljid = DJabberd::JID->new($fullstr); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | $self->{jid2sock}{$fullstr} = $conn; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | ($self->{bare2fulls}{$barestr} ||= {})->{$fullstr} = 1; # TODO: this should be the connection, not a 1, saves work in unregister JID? | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"bare2fulls"}{$barestr} ||= {}
MC/DC0%0/1
$self->{"bare2fulls"}{$barestr} ||= {}
$self->{"bare2fulls"}{$barestr}
Truth table0%0/2
A
A= $self->{"bare2fulls"}{$barestr}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $cb->registered($fulljid); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | sub unregister_jid { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unregister_jid: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my ($self, $jid, $conn) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | my $barestr = $jid->as_bare_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my $fullstr = $jid->as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | my $deleted_fulljid; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | if (my $exist = $self->{jid2sock}{$fullstr}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | if ($exist == $conn) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | delete $self->{jid2sock}{$fullstr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $deleted_fulljid = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | if ($deleted_fulljid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | if ($self->{bare2fulls}{$barestr}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | delete $self->{bare2fulls}{$barestr}{$fullstr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | unless (%{ $self->{bare2fulls}{$barestr} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | delete $self->{bare2fulls}{$barestr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # given a bare jid, find all local connections | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | sub find_conns_of_bare { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_conns_of_bare: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | my ($self, $jid) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | my $barestr = $jid->as_bare_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | my @conns; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | foreach my $fullstr (keys %{ $self->{bare2fulls}{$barestr} || {} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'bare2fulls'}{$barestr} || {}
MC/DC0%0/1
$self->{'bare2fulls'}{$barestr} || {}
$self->{'bare2fulls'}{$barestr}
Truth table0%0/2
A
A= $self->{'bare2fulls'}{$barestr}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | my $conn = $self->find_jid($fullstr) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | push @conns, $conn; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | return @conns; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # returns true if given jid is recognized as "for the server" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | sub uses_jid { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uses_jid: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | my ($self, $jid) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | return 0 unless $jid; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | return lc($jid->as_string) eq $self->{server_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # returns true if given jid is controlled by this vhost | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | sub handles_jid { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handles_jid: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | my ($self, $jid) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | return 0 unless $jid; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | return lc($jid->domain) eq $self->{server_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | sub roster_push { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
roster_push: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | my ($self, $jid, $ritem) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | croak("no ritem") unless $ritem; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # kill cache if roster checked; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | my $barestr = $jid->as_bare_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | delete $self->{roster_cache}{$barestr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | # XMPP-IM: howwever a server SHOULD NOT push or deliver roster items | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | # in that state to the contact. (None + Pending In) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | return if $ritem->subscription->is_none_pending_in; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | # TODO: single-server roster push only. need to use a hook | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # to go across the cluster | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | my $xml = "<query xmlns='jabber:iq:roster'>"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $xml .= $ritem->as_xml; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | $xml .= "</query>"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | my @conns = $self->find_conns_of_bare($jid); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | foreach my $c (@conns) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | next unless $c->is_available && $c->requested_roster; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$c->is_available and $c->requested_roster
MC/DC0%0/2
$c->is_available and $c->requested_roster
$c->is_available
$c->requested_roster
Truth table0%0/3
A and B
A= $c->is_availableB= $c->requested_roster
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | my $id = $c->new_iq_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my $iq = "<iq to='" . $c->bound_jid->as_string_exml . "' type='set' id='$id'>$xml</iq>"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | $c->xmllog->info($iq); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | $c->write(\$iq); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | sub get_secret_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_secret_key: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | my ($self, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | $cb->("i", $self->{server_secret} ||= join('', map { rand() } (1..20))); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"server_secret"} ||= join("", map({rand();} 1..20))
MC/DC0%0/2
$self->{"server_secret"} ||= join("", map({rand();} 1..20))
$self->{"server_secret"}
join("", map({rand();} 1..20))
Truth table0%0/3
A ||= B
A= $self->{"server_secret"}B= join("", map({rand();} 1..20))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | sub get_secret_key_by_handle { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_secret_key_by_handle: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | my ($self, $handle, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | if ($handle eq "i") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | # internal | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | $cb->($self->{server_secret}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # bogus handle. currently only handle "i" is supported. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | $cb->(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | sub get_roster { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_roster: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | my ($self, $jid, %meth) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | my $good_cb = delete $meth{'on_success'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | my $bad_cb = delete $meth{'on_fail'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | Carp::croak("unknown args") if %meth; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | my $barestr = $jid->as_bare_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | # see if it's cached. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | if (my $roster = $self->{roster_cache}{$barestr}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | if ($roster->inc_cache_gets >= 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | delete $self->{roster_cache}{$barestr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | $good_cb->($roster); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | # upon connect there are three immediate requests of a user's | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # roster, then pretty much never again, but those three can, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | # depending on the client's preference between sending initial | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | # presence vs. roster get first, be 3 loads in parallel, or 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | # then 2 in parallel. in any case, multiple async loads can be in | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | # flight at once, so let's keep a list of roster-wanters and only | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # do one request, then send the answer to everybody. the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | # $kick_off_load is to keep track of whether or not this is the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | # first request that actually has to start loading it, or we're a | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | # 2nd/3rd caller. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | my $kick_off_load = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | my $list = $self->{roster_wanters}{$barestr} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"roster_wanters"}{$barestr} ||= []
MC/DC0%0/1
$self->{"roster_wanters"}{$barestr} ||= []
$self->{"roster_wanters"}{$barestr}
Truth table0%0/2
A
A= $self->{"roster_wanters"}{$barestr}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | ▶ | $kick_off_load = 1 unless @$list; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | push @$list, [$good_cb, $bad_cb]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | return unless $kick_off_load; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | $self->run_hook_chain(phase => "RosterGet", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | args => [ $jid ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | methods => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | set_roster => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | my $roster = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | $self->{roster_cache}{$barestr} = $roster; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | # upon connect there are three immediate requests of a user's | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | # roster, then pretty much never again, so we keep it cached 5 seconds, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | # then discard it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | Danga::Socket->AddTimer(5.0, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | delete $self->{roster_cache}{$barestr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | # call all the on-success items, but deleting the current list | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | # first, lest any of the callbacks load more roster items | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | delete $self->{roster_wanters}{$barestr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | my $done = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | foreach my $li (@$list) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | $li->[0]->($roster); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | $done = 1 if $roster->inc_cache_gets >= 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | # if they've used it three times, they're done with | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | # the initial roster, probes, and broadcast, so drop | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | # it early, not waiting for 5 seconds. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | ▶ | if ($done) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | delete $self->{roster_cache}{$barestr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | fallback => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # call all the on-fail items, but deleting the current list | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | # first, lest any of the callbacks load more roster items | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | delete $self->{roster_wanters}{$barestr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | foreach my $li (@$list) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | $li->[1]->() if $li->[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | # $jidarg can be a $jid for now. future: arrayref of jid objs | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # $cb is $cb->($map) where $map is hashref of fulljidstr -> $presence_stanza_obj | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | ▶ | sub check_presence { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_presence: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | my ($self, $jidarg, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | my %map; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | ▶ | my $add_presence = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | my ($jid, $stanza) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | $map{$jid->as_string} = $stanza; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | # this hook chain is a little different, it's expected | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | # to always fall through to the end. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | $self->run_hook_chain(phase => "PresenceCheck", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | args => [ $jidarg, $add_presence ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | fallback => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | $cb->(\%map); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | ▶ | sub debug { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | ▶ | return unless $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | printf STDERR @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | # Local Variables: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | # mode: perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | # c-basic-indent: 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | # indent-tabs-mode: nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | # End: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 20 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||