DJabberd/Connection/ServerIn.pm

filter: Statementstmt 17.3% 13 / 75 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 20.0% 4 / 20 Podpod 0.0% 0 / 11 totaltotal 13.9% 17 / 122 CC 9 SCAR 19.2
CC
9
Cov
14%
filter_incoming_server_builtin
20.0
on_stream_start
12.0
on_stanza_received
12.0
CRAP 6.8
« DJabberd/Callback.pm ↑ Summary DJabberd/PresenceChecker/Local.pm »
1 package DJabberd::Connection::ServerIn;
2 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 20 ▶use base 'DJabberd::Connection';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 use fields
5 20 ▶ ('announced_dialback',
Subroutine BEGIN: called CC=1 SCAR=0.0
6 'verified_remote_domain', # once we know it
7 20 );
8  
9 20 ▶use DJabberd::Stanza::DialbackResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub set_vhost {
Subroutine set_vhost: not called CC=2 SCAR=17.9
Pod undocumented
12 0 my ($self, $vhost) = @_;
13 0 ▶ return 0 unless $vhost->{s2s};
Branch: 1 branch
BranchTrueFalseTotal
unless $vhost->{"s2s"} 0 0 0
14 0 return $self->SUPER::set_vhost($vhost);
15 }
16  
17 0 ▶sub peer_domain_is_verified {
Subroutine peer_domain_is_verified: not called CC=1 SCAR=6.9
Pod undocumented
18 0 my ($self, $domain) = @_;
19 0 return $self->{verified_remote_domain}->{lc $domain};
20 }
21  
22 0 ▶sub on_stream_start {
Subroutine on_stream_start: not called CC=3 SCAR=24.8
Pod undocumented
23 0 my ($self, $ss) = @_;
24 0 $self->{in_stream} = 1;
25  
26 ### namespace mismatch is a streamerror
27 0 ▶ unless ($ss->xmlns eq $self->namespace) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ss->xmlns eq $self->namespace) 0 0 0
28 0 $self->stream_error(
29 sprintf(
30 "namespace mismatch: client->%s server->%s",
31 $ss->xmlns, $self->namespace
32 )
33 );
34 0 $self->close;
35 }
36
37 0 ▶ if ($ss->announced_dialback) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ss->announced_dialback) { } 0 0 0
38 0 $self->{announced_dialback} = 1;
39 0 $self->start_stream_back($ss,
40 extra_attr => "xmlns:db='jabber:server:dialback'",
41 namespace => 'jabber:server');
42 } else {
43 0 $self->start_stream_back($ss,
44 namespace => 'jabber:server');
45 }
46 }
47  
48 0 ▶sub on_stanza_received {
Subroutine on_stanza_received: not called CC=3 SCAR=24.8
Pod undocumented
49 0 my ($self, $node) = @_;
50  
51 0 ▶ if ($self->xmllog->is_info) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->xmllog->is_info) 0 0 0
52 0 $self->log_incoming_data($node);
53 }
54  
55 0 my %class = (
56 "{jabber:server:dialback}result" => "DJabberd::Stanza::DialbackResult",
57 "{jabber:server:dialback}verify" => "DJabberd::Stanza::DialbackVerify",
58 "{jabber:server}iq" => 'DJabberd::IQ',
59 "{jabber:server}message" => 'DJabberd::Message',
60 "{jabber:server}presence" => 'DJabberd::Presence',
61 "{http://etherx.jabber.org/streams}features" => 'DJabberd::Stanza::StreamFeatures',
62 );
63  
64 0 ▶ my $class = $class{$node->element} or
Branch: 1 branch
BranchTrueFalseTotal
my $class = $class{$node->element} or return $self->stream_error("unsupported-stanza-type", $node->element) 0 0 0
65 return $self->stream_error("unsupported-stanza-type", $node->element);
66  
67 0 $DJabberd::Stats::counter{"ServerIn:$class"}++;
68  
69 # same variable as $node, but down(specific)-classed.
70 0 my $stanza = $class->downbless($node, $self);
71  
72 $self->run_hook_chain(phase => "filter_incoming_server",
73 deprecated => 1, # yes, we know this is deprecated, but we don't have a vhost always during dialback.
74 args => [ $stanza ],
75 methods => {
76 0 ▶ reject => sub { }, # just stops the chain
Subroutine __ANON__: not called CC=1 SCAR=0.0
77 },
78 0 ▶ fallback => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
79 0 $self->filter_incoming_server_builtin($stanza);
80 0 });
81 }
82  
83 0 ▶sub filter_incoming_server_builtin {
Subroutine filter_incoming_server_builtin: not called CC=4 SCAR=30.0
Pod undocumented
84 0 my ($self, $stanza) = @_;
85  
86 0 ▶ unless ($stanza->acceptable_from_server($self)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stanza->acceptable_from_server($self)) 0 0 0
87 0 ▶ if (not $stanza->from_jid) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $stanza->from_jid) { } 0 0 0
elsif (not $stanza->to_jid) { } 0 0 0
88 0 $self->log->error("Invalid 'from': @{[$stanza->from]}");
89 } elsif (not $stanza->to_jid) {
90 0 $self->log->error("Invalid 'to': @{[$stanza->to]}");
91 } else {
92 0 my $domain = $stanza->from_jid->domain;
93 0 my @known = sort keys %{$self->{verified_remote_domain}};
94 0 $self->log->error("Stanza of type '@{[ref $stanza]}' from $domain not acceptable; accept @known");
95 }
96 # FIXME: who knows. send something else.
97 0 $self->stream_error;
98 0 return 0;
99 }
100  
101 $self->run_hook_chain(phase => "switch_incoming_server",
102 deprecated => 1, # yes, we know this is deprecated, but we don't have a vhost always during dialback.
103 args => [ $stanza ],
104 methods => {
105 0 ▶ process => sub { $stanza->process($self) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
106 0 ▶ deliver => sub { $stanza->deliver($self) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
107 },
108 0 ▶ fallback => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
109 0 $stanza->on_recv_from_server($self);
110 0 });
111 }
112  
113 0 ▶sub is_server { 1 }
Subroutine is_server: not called CC=1 SCAR=6.9
Pod undocumented
114  
115 0 ▶sub namespace {
Subroutine namespace: not called CC=1 SCAR=6.9
Pod undocumented
116 0 return "jabber:server";
117 }
118  
119 0 ▶sub dialback_verify_valid {
Subroutine dialback_verify_valid: not called CC=1 SCAR=6.9
Pod undocumented
120 0 my $self = shift;
121 0 my %opts = @_;
122  
123 # according to page 45 of the spec we have to send the ID back
124 0 my $res = qq{<db:verify from='$opts{recv_server}' to='$opts{orig_server}' id='$opts{id}' type='valid'/>};
125  
126 0 $self->log->debug("Dialback verify valid for connection $self->{id}. from=$opts{recv_server}, to=$opts{orig_server}: $res\n");
127 0 $self->write($res);
128 }
129  
130 0 ▶sub dialback_verify_invalid {
Subroutine dialback_verify_invalid: not called CC=1 SCAR=6.9
Pod undocumented
131 0 my $self = shift;
132 0 my %opts = @_;
133  
134 0 $self->log->warn("Dialback verify invalid for $self, from $opts{orig_server} to $opts{recv_server}, reason: $opts{reason}");
135 0 $self->close_stream;
136 }
137  
138 0 ▶sub dialback_result_valid {
Subroutine dialback_result_valid: not called CC=1 SCAR=6.9
Pod undocumented
139 0 my $self = shift;
140 0 my %opts = @_;
141  
142 0 my $res = qq{<db:result from='$opts{recv_server}' to='$opts{orig_server}' type='valid'/>};
143 0 $self->{verified_remote_domain}->{lc $opts{orig_server}} = $opts{orig_server};
144 0 $self->log->debug("Dialback result valid for connection $self->{id}. from=$opts{recv_server}, to=$opts{orig_server}: $res\n");
145 0 $self->write($res);
146 }
147  
148 0 ▶sub dialback_result_invalid {
Subroutine dialback_result_invalid: not called CC=1 SCAR=6.9
Pod undocumented
149 0 my $self = shift;
150 0 my %opts = @_;
151  
152 0 $self->log->warn("Dialback result invalid for $self, from $opts{orig_server} to $opts{recv_server}, reason: $opts{reason}");
153 0 $self->close_stream;
154 }
155  
156  
157 20 1;
« DJabberd/Callback.pm ↑ Summary DJabberd/PresenceChecker/Local.pm »