DJabberd/Stanza.pm

filter: Statementstmt 15.6% 13 / 83 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 16.0% 4 / 25 Podpod 0.0% 0 / 18 totaltotal 10.1% 17 / 167 CC 17 SCAR 22.5
CC
17
Cov
11%
deliver
30.0
acceptable_from_server
20.0
downbless
12.0
CRAP 9.5
« DJabberd/SASL/AuthenSASL.pm ↑ Summary DJabberd/BotContext.pm »
1 package DJabberd::Stanza;
2 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 17 ▶use base qw(DJabberd::XMLElement);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 use fields (
6 17 'connection', # Store the connection the stanza came in on so we can respond.
7 # may be undef, as it's a weakref. if you want to mess with the
8 # structure, you can't do so unless you're the owner, so clone
9 # it first otherwise.
10 '_memo_tojid', # memoized to jid
11 '_memo_fromjid', # memoized from jid
12 17 ▶ );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub downbless {
15 0 ▶ my $class = shift;
Subroutine downbless: not called CC=3 SCAR=24.8
Pod undocumented
16 0 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
17 0 my ($self, $conn) = @_;
18 0 my $new = fields::new($class);
19 0 %$new = %$self; # copy fields
20 0 ▶ if ($conn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn) 0 0 0
21 0 $new->{connection} = $conn;
22 0 Scalar::Util::weaken($new->{connection});
23 }
24 0 return $new;
25 } else {
26 0 croak("Bogus use of downbless.");
27 }
28  
29 }
30  
31 sub as_summary {
32 0 ▶ my $self = shift;
Subroutine as_summary: not called CC=1 SCAR=6.9
Pod undocumented
33 0 return "[Stanza of type " . $self->element_name . " to " . $self->to_jid->as_string . "]";
34 }
35  
36 sub on_recv_from_server {
37 0 ▶ my ($self, $conn) = @_;
Subroutine on_recv_from_server: not called CC=1 SCAR=6.9
Pod undocumented
38 0 $self->deliver($conn->vhost);
39 }
40  
41 sub process {
42 0 ▶ my ($self, $conn) = @_;
Subroutine process: not called CC=1 SCAR=6.9
Pod undocumented
43 0 die "$self ->process not implemented\n";
44 }
45  
46 sub connection {
47 0 ▶ my $self = shift;
Subroutine connection: not called CC=1 SCAR=6.9
Pod undocumented
48 0 return $self->{connection};
49 }
50  
51 sub set_connection {
52 0 ▶ my ($self, $conn) = @_;
Subroutine set_connection: not called CC=1 SCAR=6.9
Pod undocumented
53 0 $self->{connection} = $conn;
54 }
55  
56 # at this point, it's assumed the stanza has passed filtering checks,
57 # and should be delivered.
58 sub deliver {
59 0 ▶ my ($stanza, $arg) = @_;
Subroutine deliver: not called CC=5 SCAR=34.0
Pod undocumented
60  
61 # arg can be a connection, vhost, or nothing. TODO: kinda ghetto. fix callers?
62 0 my $vhost;
63 0 ▶ if (UNIVERSAL::isa($arg, "DJabberd::VHost")) {
Branch: 3 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($arg, 'DJabberd::VHost')) { } 0 0 0
elsif (UNIVERSAL::isa($arg, 'DJabberd::Connection')) { } 0 0 0
elsif ($stanza->{'connection'}) { } 0 0 0
64 0 $vhost = $arg;
65 } elsif (UNIVERSAL::isa($arg, "DJabberd::Connection")) {
66 0 $vhost = $arg->vhost;
67 } elsif ($stanza->{connection}) {
68 0 $vhost = $stanza->{connection}->vhost;
69 }
70 0 ▶ Carp::croak("Can't determine vhost delivering: " . $stanza->as_xml) unless $vhost;
Branch: 1 branch
BranchTrueFalseTotal
unless $vhost 0 0 0
71  
72 $vhost->hook_chain_fast("deliver",
73 [ $stanza ],
74 {
75 ▶ delivered => sub { },
Subroutine __ANON__: not called CC=1 SCAR=0.0
76 # FIXME: in future, this should note deliver was
77 # complete and the next message to this jid should be dequeued and
78 # subsequently delivered. (in order deliver)
79 error => sub {
80 0 ▶ my $reason = $_[1];
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 0 $stanza->delivery_failure($vhost, $reason);
82 },
83 },
84 sub {
85 0 ▶ $stanza->delivery_failure($vhost);
Subroutine __ANON__: not called CC=1 SCAR=6.9
86 0 });
87 }
88  
89 # by default, stanzas need to and from coming from a server
90 sub acceptable_from_server {
91 0 ▶ my ($self, $conn) = @_; # where $conn is a serverin connection
Subroutine acceptable_from_server: not called CC=4 SCAR=30.0
Pod undocumented
92 0 my ($to, $from) = ($self->to_jid, $self->from_jid);
93 0 ▶ return 0 unless $to && $from;
Branch: 1 branch
BranchTrueFalseTotal
unless $to and $from 0 0 0
Condition0%0/3
$to and $from
!ll&&!rl&&r
000
MC/DC0%0/2
$to and $from
$to $from
Truth table0%0/3
A and B
A= $toB= $from
ABresult
0X0
100
111
94 0 ▶ return 0 unless $conn->peer_domain_is_verified($from->domain);
Branch: 1 branch
BranchTrueFalseTotal
unless $conn->peer_domain_is_verified($from->domain) 0 0 0
95 #return 0 unless $conn->vhost; FIXME? yes?
96 0 return 1;
97 }
98  
99 sub delivery_failure {
100 0 ▶ my ($self, $vh, $reason) = @_;
Subroutine delivery_failure: not called CC=1 SCAR=6.9
Pod undocumented
101 #warn "$self has no ->delivery_failure method implemented\n";
102 }
103  
104 sub to {
105 0 ▶ my DJabberd::Stanza $self = shift;
Subroutine to: not called CC=1 SCAR=6.9
Pod undocumented
106 0 return $self->{attrs}{"{}to"};
107 }
108  
109 sub from {
110 0 ▶ my DJabberd::Stanza $self = shift;
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
111 0 return $self->{attrs}{"{}from"};
112 }
113  
114 sub to_jid {
115 0 ▶ my DJabberd::Stanza $self = shift;
Subroutine to_jid: not called CC=2 SCAR=17.9
Pod undocumented
116 0 ▶ return $self->{_memo_tojid} ||= DJabberd::JID->new($self->{attrs}{"{}to"});
Condition0%0/3
$self->{"_memo_tojid"} ||= "DJabberd::JID"->new($self->{"attrs"}{"{}to"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_memo_tojid"} ||= "DJabberd::JID"->new($self->{"attrs"}{"{}to"})
$self->{"_memo_tojid"} "DJabberd::JID"->new($self->{"attrs"}{"{}to"})
Truth table0%0/3
A ||= B
A= $self->{"_memo_tojid"}B= "DJabberd::JID"->new($self->{"attrs"}{"{}to"})
ABresult
1X1
011
000
117 }
118  
119 sub from_jid {
120 0 ▶ my DJabberd::Stanza $self = shift;
Subroutine from_jid: not called CC=2 SCAR=17.9
Pod undocumented
121 0 ▶ return $self->{_memo_fromjid} ||= DJabberd::JID->new($self->{attrs}{"{}from"});
Condition0%0/3
$self->{"_memo_fromjid"} ||= "DJabberd::JID"->new($self->{"attrs"}{"{}from"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_memo_fromjid"} ||= "DJabberd::JID"->new($self->{"attrs"}{"{}from"})
$self->{"_memo_fromjid"} "DJabberd::JID"->new($self->{"attrs"}{"{}from"})
Truth table0%0/3
A ||= B
A= $self->{"_memo_fromjid"}B= "DJabberd::JID"->new($self->{"attrs"}{"{}from"})
ABresult
1X1
011
000
122 }
123  
124 sub set_from {
125 #my ($self, $from) = @_;
126 0 ▶ my DJabberd::Stanza $self = $_[0];
Subroutine set_from: not called CC=2 SCAR=17.9
Pod undocumented
127 0 $self->{_memo_fromjid} = undef;
128 0 ▶ $self->{attrs}{"{}from"} = ref $_[1] ? $_[1]->as_string : $_[1];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] ? : 0 0 0
129 }
130  
131 sub set_to {
132 #my ($self, $to) = @_;
133 0 ▶ my DJabberd::Stanza $self = $_[0];
Subroutine set_to: not called CC=2 SCAR=17.9
Pod undocumented
134 0 $self->{_memo_tojid} = undef;
135 0 ▶ $self->{attrs}{"{}to"} = ref $_[1] ? $_[1]->as_string : $_[1];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] ? : 0 0 0
136 }
137  
138 sub deliver_when_unavailable {
139 0 ▶ 0;
Subroutine deliver_when_unavailable: not called CC=1 SCAR=6.9
Pod undocumented
140 }
141  
142 sub make_response {
143 0 ▶ my ($self) = @_;
Subroutine make_response: not called CC=2 SCAR=17.9
Pod undocumented
144  
145 # Common to all stanzas is a switching of the from/to addresses.
146 0 my $response = $self->clone;
147 0 my $from = $self->from;
148 0 my $to = $self->to;
149  
150 0 $response->set_to($from);
151 0 ▶ $to ? $response->set_from($to) : delete($response->attrs->{"{}from"});
Branch: 1 branch
BranchTrueFalseTotal
$to ? : 0 0 0
152
153 0 $response->set_raw("");
154  
155 0 return $response;
156 }
157  
158 sub make_error_response {
159 0 ▶ my ($self, $code, $type, $error) = @_;
Subroutine make_error_response: not called CC=3 SCAR=24.8
Pod undocumented
160
161 0 my $response = $self->clone;
162 0 my $from = $self->from;
163 0 my $to = $self->to;
164  
165 0 $response->set_to($from);
166 0 ▶ $to ? $response->set_from($to) : delete($response->attrs->{"{}from"});
Branch: 1 branch
BranchTrueFalseTotal
$to ? : 0 0 0
167  
168 0 ▶ my $error_elem = new DJabberd::XMLElement(
Branch: 1 branch
BranchTrueFalseTotal
ref $error ? : 0 0 0
169 "jabber:server",
170 "error",
171 {
172 "{}code" => $code,
173 "{}type" => $type,
174 },
175 [
176 ref $error ? $error : new DJabberd::XMLElement("urn:ietf:params:xml:ns:xmpp-stanzas", $error, {}, []),
177 ],
178 );
179  
180 0 $response->attrs->{"{}type"} = "error";
181 0 $response->push_child($error_elem);
182
183 0 return $response;
184 }
185  
186 17 1;
« DJabberd/SASL/AuthenSASL.pm ↑ Summary DJabberd/BotContext.pm »