| 1 | package DJabberd::Stanza; | ||||||||||||||||||||||||||||
| 2 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use base qw(DJabberd::XMLElement); | ||||||||||||||||||||||||||
|
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 fields ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 20 | '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 | 20 | ); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub downbless { | ||||||||||||||||||||||||||
|
Subroutine
downbless: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 16 | 0 | ▶ | if (ref $_[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub as_summary { | ||||||||||||||||||||||||||
|
Subroutine
as_summary: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 33 | 0 | return "[Stanza of type " . $self->element_name . " to " . $self->to_jid->as_string . "]"; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub on_recv_from_server { | ||||||||||||||||||||||||||
|
Subroutine
on_recv_from_server: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 0 | my ($self, $conn) = @_; | |||||||||||||||||||||||||||
| 38 | 0 | $self->deliver($conn->vhost); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub process { | ||||||||||||||||||||||||||
|
Subroutine
process: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | 0 | my ($self, $conn) = @_; | |||||||||||||||||||||||||||
| 43 | 0 | die "$self ->process not implemented\n"; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub connection { | ||||||||||||||||||||||||||
|
Subroutine
connection: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | 0 | return $self->{connection}; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub set_connection { | ||||||||||||||||||||||||||
|
Subroutine
set_connection: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 0 | my ($self, $conn) = @_; | |||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub deliver { | ||||||||||||||||||||||||||
|
Subroutine
deliver: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 0 | my ($stanza, $arg) = @_; | |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | $vhost->hook_chain_fast("deliver", | ||||||||||||||||||||||||||||
| 73 | [ $stanza ], | ||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | 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 | 0 | ▶ | error => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 80 | 0 | my $reason = $_[1]; | |||||||||||||||||||||||||||
| 81 | 0 | $stanza->delivery_failure($vhost, $reason); | |||||||||||||||||||||||||||
| 82 | }, | ||||||||||||||||||||||||||||
| 83 | }, | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 85 | 0 | $stanza->delivery_failure($vhost); | |||||||||||||||||||||||||||
| 86 | 0 | }); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # by default, stanzas need to and from coming from a server | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub acceptable_from_server { | ||||||||||||||||||||||||||
|
Subroutine
acceptable_from_server: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 91 | 0 | my ($self, $conn) = @_; # where $conn is a serverin connection | |||||||||||||||||||||||||||
| 92 | 0 | my ($to, $from) = ($self->to_jid, $self->from_jid); | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | return 0 unless $to && $from; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$to and $from
MC/DC0%0/2
$to and $from
$to
$from
Truth table0%0/3
A and B
A= $toB= $from
| |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | return 0 unless $conn->peer_domain_is_verified($from->domain); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | #return 0 unless $conn->vhost; FIXME? yes? | ||||||||||||||||||||||||||||
| 96 | 0 | return 1; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub delivery_failure { | ||||||||||||||||||||||||||
|
Subroutine
delivery_failure: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 100 | 0 | my ($self, $vh, $reason) = @_; | |||||||||||||||||||||||||||
| 101 | #warn "$self has no ->delivery_failure method implemented\n"; | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub to { | ||||||||||||||||||||||||||
|
Subroutine
to: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 105 | 0 | my DJabberd::Stanza $self = shift; | |||||||||||||||||||||||||||
| 106 | 0 | return $self->{attrs}{"{}to"}; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub from { | ||||||||||||||||||||||||||
|
Subroutine
from: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 110 | 0 | my DJabberd::Stanza $self = shift; | |||||||||||||||||||||||||||
| 111 | 0 | return $self->{attrs}{"{}from"}; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub to_jid { | ||||||||||||||||||||||||||
|
Subroutine
to_jid: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | 0 | my DJabberd::Stanza $self = shift; | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | return $self->{_memo_tojid} ||= DJabberd::JID->new($self->{attrs}{"{}to"}); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"_memo_tojid"} ||= "DJabberd::JID"->new($self->{"attrs"}{"{}to"})
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"})
| |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub from_jid { | ||||||||||||||||||||||||||
|
Subroutine
from_jid: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 120 | 0 | my DJabberd::Stanza $self = shift; | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | return $self->{_memo_fromjid} ||= DJabberd::JID->new($self->{attrs}{"{}from"}); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"_memo_fromjid"} ||= "DJabberd::JID"->new($self->{"attrs"}{"{}from"})
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"})
| |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub set_from { | ||||||||||||||||||||||||||
|
Subroutine
set_from: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 125 | #my ($self, $from) = @_; | ||||||||||||||||||||||||||||
| 126 | 0 | my DJabberd::Stanza $self = $_[0]; | |||||||||||||||||||||||||||
| 127 | 0 | $self->{_memo_fromjid} = undef; | |||||||||||||||||||||||||||
| 128 | 0 | ▶ | $self->{attrs}{"{}from"} = ref $_[1] ? $_[1]->as_string : $_[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub set_to { | ||||||||||||||||||||||||||
|
Subroutine
set_to: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 132 | #my ($self, $to) = @_; | ||||||||||||||||||||||||||||
| 133 | 0 | my DJabberd::Stanza $self = $_[0]; | |||||||||||||||||||||||||||
| 134 | 0 | $self->{_memo_tojid} = undef; | |||||||||||||||||||||||||||
| 135 | 0 | ▶ | $self->{attrs}{"{}to"} = ref $_[1] ? $_[1]->as_string : $_[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub deliver_when_unavailable { | ||||||||||||||||||||||||||
|
Subroutine
deliver_when_unavailable: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 139 | 0 | 0; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub make_response { | ||||||||||||||||||||||||||
|
Subroutine
make_response: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 143 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | $response->set_raw(""); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | return $response; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub make_error_response { | ||||||||||||||||||||||||||
|
Subroutine
make_error_response: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 159 | 0 | my ($self, $code, $type, $error) = @_; | |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | my $error_elem = new DJabberd::XMLElement( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 20 | 1; | |||||||||||||||||||||||||||