DJabberd/Connection/ServerIn.pm

filter: Statementstmt 19.7% 13 / 66 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 20.0% 4 / 20 Podpod 0.0% 0 / 11 totaltotal 15.6% 17 / 109 CC 7 SCAR 15.5
CC
7
Cov
17%
on_stream_start
12.0
on_stanza_received
12.0
set_vhost
6.0
CRAP 4.7
« DJabberd/Authen/InMemoryOnly.pm ↑ Summary DJabberd/Bot/Admin.pm »
1 package DJabberd::Connection::ServerIn;
2 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 17 ▶use base 'DJabberd::Connection';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 use fields
5 17 ('announced_dialback',
6 'verified_remote_domain', # once we know it
7 17 ▶ );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 17 ▶use DJabberd::Stanza::DialbackResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub set_vhost {
12 0 ▶ my ($self, $vhost) = @_;
Subroutine set_vhost: not called CC=2 SCAR=17.9
Pod undocumented
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 sub peer_domain_is_verified {
18 0 ▶ my ($self, $domain) = @_;
Subroutine peer_domain_is_verified: not called CC=1 SCAR=6.9
Pod undocumented
19 0 return $self->{verified_remote_domain}->{lc $domain};
20 }
21  
22 sub on_stream_start {
23 0 ▶ my ($self, $ss) = @_;
Subroutine on_stream_start: not called CC=3 SCAR=24.8
Pod undocumented
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 sub on_stanza_received {
49 0 ▶ my ($self, $node) = @_;
Subroutine on_stanza_received: not called CC=3 SCAR=24.8
Pod undocumented
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 ▶ reject => sub { }, # just stops the chain
Subroutine __ANON__: not called CC=1 SCAR=0.0
77 },
78 fallback => sub {
79 0 ▶ $self->filter_incoming_server_builtin($stanza);
Subroutine __ANON__: not called CC=1 SCAR=6.9
80 0 });
81 }
82  
83 sub filter_incoming_server_builtin {
84 0 ▶ my ($self, $stanza) = @_;
Subroutine filter_incoming_server_builtin: not called CC=2 SCAR=17.9
Pod undocumented
85  
86 0 ▶ unless ($stanza->acceptable_from_server($self)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stanza->acceptable_from_server($self)) 0 0 0
87 # FIXME: who knows. send something else.
88 0 $self->log->error("Stansa of type '$stanza' not acceptable");
89 0 $self->stream_error;
90 0 return 0;
91 }
92  
93 $self->run_hook_chain(phase => "switch_incoming_server",
94 deprecated => 1, # yes, we know this is deprecated, but we don't have a vhost always during dialback.
95 args => [ $stanza ],
96 methods => {
97 0 ▶ process => sub { $stanza->process($self) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
98 0 ▶ deliver => sub { $stanza->deliver($self) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 },
100 fallback => sub {
101 0 ▶ $stanza->on_recv_from_server($self);
Subroutine __ANON__: not called CC=1 SCAR=6.9
102 0 });
103 }
104  
105 0 ▶sub is_server { 1 }
Subroutine is_server: not called CC=1 SCAR=6.9
Pod undocumented
106  
107 sub namespace {
108 0 ▶ return "jabber:server";
Subroutine namespace: not called CC=1 SCAR=6.9
Pod undocumented
109 }
110  
111 sub dialback_verify_valid {
112 0 ▶ my $self = shift;
Subroutine dialback_verify_valid: not called CC=1 SCAR=6.9
Pod undocumented
113 0 my %opts = @_;
114  
115 # according to page 45 of the spec we have to send the ID back
116 0 my $res = qq{<db:verify from='$opts{recv_server}' to='$opts{orig_server}' id='$opts{id}' type='valid'/>};
117  
118 0 $self->log->debug("Dialback verify valid for connection $self->{id}. from=$opts{recv_server}, to=$opts{orig_server}: $res\n");
119 0 $self->write($res);
120 }
121  
122 sub dialback_verify_invalid {
123 0 ▶ my $self = shift;
Subroutine dialback_verify_invalid: not called CC=1 SCAR=6.9
Pod undocumented
124 0 my %opts = @_;
125  
126 0 $self->log->warn("Dialback verify invalid for $self, from $opts{orig_server} to $opts{recv_server}, reason: $opts{reason}");
127 0 $self->close_stream;
128 }
129  
130 sub dialback_result_valid {
131 0 ▶ my $self = shift;
Subroutine dialback_result_valid: not called CC=1 SCAR=6.9
Pod undocumented
132 0 my %opts = @_;
133  
134 0 my $res = qq{<db:result from='$opts{recv_server}' to='$opts{orig_server}' type='valid'/>};
135 0 $self->{verified_remote_domain}->{lc $opts{orig_server}} = $opts{orig_server};
136 0 $self->log->debug("Dialback result valid for connection $self->{id}. from=$opts{recv_server}, to=$opts{orig_server}: $res\n");
137 0 $self->write($res);
138 }
139  
140 sub dialback_result_invalid {
141 0 ▶ my $self = shift;
Subroutine dialback_result_invalid: not called CC=1 SCAR=6.9
Pod undocumented
142 0 my %opts = @_;
143  
144 0 $self->log->warn("Dialback result invalid for $self, from $opts{orig_server} to $opts{recv_server}, reason: $opts{reason}");
145 0 $self->close_stream;
146 }
147  
148  
149 17 1;
« DJabberd/Authen/InMemoryOnly.pm ↑ Summary DJabberd/Bot/Admin.pm »