DJabberd/Connection.pm

filter: Statementstmt 19.1% 76 / 397 Branchbran 2.3% 3 / 128 Conditioncond 0.0% 0 / 69 MC/DCmcdc 0.0% 0 / 41 Subroutinesub 29.1% 23 / 79 Podpod 14.8% 7 / 47 totaltotal 14.3% 109 / 761 CC 93 SCAR 45.9
CC
93
Cov
13%
event_read
380.0
start_stream_back
380.0
write_stanza
110.0
CRAP 98.9
« DJabberd.pm ↑ Summary DJabberd/Authen/AllowedUsers.pm »
1 package DJabberd::Connection;
2 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use base 'Danga::Socket';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 20 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 20 ▶use fields (
Subroutine BEGIN: called CC=1 SCAR=0.0
7 20 'saxhandler',
8 'parser',
9  
10 'bound_jid', # undef until resource binding - then DJabberd::JID object
11  
12 'vhost', # DJabberd::VHost instance (undef until they send a stream start element)
13 'server', # our DJabberd server object, which we used to find the VHost
14 'ssl', # undef when not in ssl mode, else the $ssl object from Net::SSLeay
15 'stream_id', # undef until set first time
16 'to_host', # undef until stream start
17 'version', # the DJabberd::StreamVersion we negotiated
18 'rcvd_features', # the features stanza we've received from the other party
19 'log', # Log::Log4perl object for this connection
20 'xmllog', # Log::Log4perl object that controls raw xml logging
21 'id', # connection id, used for logging purposes
22 'write_when_readable', # arrayref/bool, for SSL: as boolean, we're only readable so we can write again.
23 # but bool true is actually an arrayref of previous watch_read state
24 'iqctr', # iq counter. incremented whenever we SEND an iq to the party (roster pushes, etc)
25 'in_stream', # bool: true if we're in a stream tag
26 'counted_close', # bool: temporary here to track down the overcounting of disconnects
27 'disconnect_handlers', # array of coderefs to call when this connection is closed for any reason
28 'sasl', # the sasl connection object, when sasl has been or is being negotiated
29 20 );
30  
31 20 our $connection_id = 1;
32  
33 20 ▶use XML::SAX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
34 20 ▶use DJabberd::XMLParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 20 ▶use Digest::SHA1 qw(sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 20 ▶use DJabberd::SAXHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 20 ▶use DJabberd::JID;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 20 ▶use DJabberd::IQ;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 20 ▶use DJabberd::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 20 ▶use DJabberd::Util qw(exml tsub);
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 20 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 20 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 20 ▶use DJabberd::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 20 our $hook_logger = DJabberd::Log->get_logger("DJabberd::Hook");
48  
49 20 ▶use constant POLLIN => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 20 ▶use constant POLLOUT => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 20 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.0
53 20 my $xmldebug = $ENV{XMLDEBUG};
54  
55 20 ▶ if ($xmldebug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xmldebug) { } 1 19 20
56 1 ▶ eval 'use constant XMLDEBUG => "' . quotemeta($xmldebug) . '"';
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 ▶ die "XMLDEBUG path '$xmldebug' needs to be a directory writable by the user you are running $0 as\n" unless -w $xmldebug;
Branch: 1 branch
BranchTrueFalseTotal
unless -w $xmldebug 0 1 1
58 } else {
59 19 ▶ eval "use constant XMLDEBUG => ''";
Subroutine BEGIN: called CC=1 SCAR=0.0
60 }
61 }
62  
63 20 our %LOGMAP;
64  
65 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=27.0
Pod documented
66 0 my ($class, $sock, $server) = @_;
67 0 my $self = $class->SUPER::new($sock);
68  
69 0 ▶ croak("Server param not a DJabberd (server) object, '" . ref($server) . "'")
Branch: 1 branch
BranchTrueFalseTotal
unless $server->isa("DJabberd") 0 0 0
70 unless $server->isa("DJabberd");
71  
72 0 $self->{vhost} = undef; # set once we get a stream start header from them.
73 0 $self->{server} = $server;
74 0 Scalar::Util::weaken($self->{server});
75  
76 0 $self->{log} = DJabberd::Log->get_logger($class);
77  
78 # hack to inject XML after Connection:: in the logger category
79 0 my $xml_category = $class;
80 0 $xml_category =~ s/Connection::/Connection::XML::/;
81  
82 0 $self->{xmllog} = DJabberd::Log->get_logger($xml_category);
83  
84 0 ▶ my $fromip = $self->peer_ip_string || "<undef>";
Condition0%0/2
$self->peer_ip_string || '<undef>'
l!l
00
MC/DC0%0/1
$self->peer_ip_string || '<undef>'
$self->peer_ip_string
Truth table0%0/2
A
A= $self->peer_ip_string
Aresult
11
00
85  
86 # a health check monitor doesn't get an id assigned/wasted on it, and doesn't log
87 # so it's less annoying to look at:
88 0 ▶ unless ($server->is_monitor_host($fromip)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($server->is_monitor_host($fromip)) 0 0 0
89 0 $self->{id} = $connection_id++;
90 0 $self->log->debug("New connection '$self->{id}' from $fromip");
91 }
92  
93 0 if (XMLDEBUG) {
94 system("mkdir -p " . XMLDEBUG ."/$$/");
95 my $handle = IO::Handle->new;
96 20 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 my $from = $fromip || "outbound";
98 my $filename = "+>" . XMLDEBUG . "/$$/$from-$self->{id}";
99 open ($handle, $filename) || die "Cannot open $filename: $!";
100 $handle->autoflush(1);
101 $LOGMAP{$self} = $handle;
102 }
103 0 return $self;
104 }
105  
106 0 ▶sub log {
Subroutine log: not called CC=1 SCAR=6.9
Pod undocumented
107 0 return $_[0]->{log};
108 }
109  
110 0 ▶sub xmllog {
Subroutine xmllog: not called CC=1 SCAR=6.9
Pod undocumented
111 0 return $_[0]->{xmllog};
112 }
113  
114 0 ▶sub handler {
Subroutine handler: not called CC=1 SCAR=6.9
Pod undocumented
115 0 return $_[0]->{saxhandler};
116 }
117  
118 0 ▶sub vhost {
Subroutine vhost: not called CC=1 SCAR=6.9
Pod undocumented
119 0 my DJabberd::Connection $self = $_[0];
120 0 return $self->{vhost};
121 }
122  
123 0 ▶sub server {
Subroutine server: not called CC=1 SCAR=6.9
Pod undocumented
124 0 my DJabberd::Connection $self = $_[0];
125 0 return $self->{server};
126 }
127  
128 0 ▶sub bound_jid {
Subroutine bound_jid: not called CC=1 SCAR=6.9
Pod undocumented
129 0 my DJabberd::Connection $self = $_[0];
130 0 return $self->{bound_jid};
131 }
132  
133 0 ▶sub new_iq_id {
Subroutine new_iq_id: not called CC=1 SCAR=6.9
Pod undocumented
134 0 my DJabberd::Connection $self = shift;
135 0 $self->{iqctr}++;
136 0 return "iq$self->{iqctr}";
137 }
138  
139 0 ▶sub log_outgoing_data {
Subroutine log_outgoing_data: not called CC=3 SCAR=24.8
Pod undocumented
140 0 my ($self, $text) = @_;
141 0 ▶ my $id = $self->{id} ||= 'no_id';
Condition0%0/2
$self->{"id"} ||= "no_id"
l!l
00
MC/DC0%0/1
$self->{"id"} ||= "no_id"
$self->{"id"}
Truth table0%0/2
A
A= $self->{"id"}
Aresult
11
00
142
143 0 ▶ if($self->xmllog->is_debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->xmllog->is_debug) { } 0 0 0
144 0 $self->xmllog->debug("$id > " . $text);
145 } else {
146 0 local $DJabberd::ASXML_NO_TEXT = 1;
147 0 $self->xmllog->info("$id > " . $text);
148 }
149 }
150  
151 0 ▶sub log_incoming_data {
Subroutine log_incoming_data: not called CC=2 SCAR=17.9
Pod undocumented
152 0 my ($self, $node) = @_;
153 0 ▶ if($self->xmllog->is_debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->xmllog->is_debug) { } 0 0 0
154 0 $self->xmllog->debug("$self->{id} < " . $node->as_xml);
155 } else {
156 0 local $DJabberd::ASXML_NO_TEXT = 1;
157 0 $self->xmllog->info("$self->{id} < " . $node->as_xml);
158 }
159 }
160  
161 0 ▶sub discard_parser {
Subroutine discard_parser: not called CC=2 SCAR=17.9
Pod undocumented
162 0 my DJabberd::Connection $self = shift;
163 # TODOTEST: bunch of new connections speaking not-well-formed xml and getting booted, then watch for mem leaks
164 0 ▶ my $p = $self->{parser} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $p = $self->{"parser"} or return 0 0 0
165 0 $self->{parser} = undef;
166 0 $self->{saxhandler}->cleanup;
167 0 $self->{saxhandler} = undef;
168 0 ▶ Danga::Socket->AddTimer(0, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
169 0 $p->finish_push;
170 0 });
171 }
172  
173 20 my %free_parsers; # $ns -> [ [parser,handler]* ]
174 0 ▶sub borrow_a_parser {
Subroutine borrow_a_parser: not called CC=6 SCAR=37.4
Pod undocumented
175 0 my DJabberd::Connection $self = $_[0];
176  
177 # get a parser off the freelist
178 0 ▶ if ($self->{in_stream}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"in_stream"}) 0 0 0
179 0 my $ns = $self->namespace;
180 0 ▶ my $freelist = $free_parsers{$ns} || [];
Condition0%0/2
$free_parsers{$ns} || []
l!l
00
MC/DC0%0/1
$free_parsers{$ns} || []
$free_parsers{$ns}
Truth table0%0/2
A
A= $free_parsers{$ns}
Aresult
11
00
181 0 ▶ if (my $ent = pop @$freelist) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ent = pop @$freelist) 0 0 0
182 0 ($self->{parser}, $self->{saxhandler}) = @$ent;
183 0 $self->{saxhandler}->set_connection($self);
184 # die "ASSERT" unless $self->{parser}{LibParser};
185 0 return $self->{parser};
186 }
187 }
188  
189 # no parser? gotta make one.
190 0 my $handler = DJabberd::SAXHandler->new;
191 0 my $p = DJabberd::XMLParser->new(Handler => $handler);
192  
193 0 ▶ if ($self->{in_stream}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"in_stream"}) 0 0 0
194 # gotta get it into stream-able state with an open root node
195 # so client can send us multiple stanzas. unless we're waiting for
196 # the start stream, in which case it may also have an xml declaration
197 # like <?xml ... ?> at top, which can only come at top, so we need
198 # a virgin parser.
199 0 my $ns = $self->namespace;
200  
201 # this is kinda a hack, in that it hard-codes the namespace
202 # prefixes 'db' and 'stream',... however, RFC 3920 seection
203 # 11.2.1, 11.2.3, etc say it's okay for historical reasons to
204 # force the prefixes for both 'stream' and 'db'
205 0 ▶ my $other = $ns eq "jabber:server" ? "xmlns:db='jabber:server:dialback'" : "";
Branch: 1 branch
BranchTrueFalseTotal
$ns eq 'jabber:server' ? : 0 0 0
206 0 $p->parse_chunk_scalarref(\ qq{<stream:stream
207 xmlns='$ns'
208 xmlns:stream='http://etherx.jabber.org/streams'
209 $other>});
210 }
211  
212 0 $handler->set_connection($self);
213 0 $self->{saxhandler} = $handler;
214 0 $self->{parser} = $p;
215 0 return $p;
216 }
217  
218 0 ▶sub return_parser {
Subroutine return_parser: not called CC=5 SCAR=34.0
Pod undocumented
219 0 my DJabberd::Connection $self = $_[0];
220 0 ▶ return unless $self->{server}->share_parsers;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"server"}->share_parsers 0 0 0
221 0 ▶ return unless $self->{in_stream};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"in_stream"} 0 0 0
222  
223 0 ▶ my $freelist = $free_parsers{$self->namespace} ||= [];
Condition0%0/2
$free_parsers{$self->namespace} ||= []
l!l
00
MC/DC0%0/1
$free_parsers{$self->namespace} ||= []
$free_parsers{$self->namespace}
Truth table0%0/2
A
A= $free_parsers{$self->namespace}
Aresult
11
00
224  
225 # BIG FAT WARNING: with fields objects, you can't do:
226 # my $p = delete $self->{parser}.
227 # You'd think you could, but it leaves $self->{parser} with some magic fucked up undef/but not
228 # value and $p's refcount never goes down. Some Perl bug due to fields, weakrefs, etc? Who knows.
229 # This affects Perl 5.8.4, but not Perl 5.8.8.
230 0 my $p = $self->{parser}; $self->{parser} = undef;
231 0 my $handler = $self->{saxhandler}; $self->{saxhandler} = undef;
232 0 $handler->set_connection(undef);
233  
234 0 ▶ if (@$freelist < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$freelist < 5) { } 0 0 0
235 0 push @$freelist, [$p, $handler];
236  
237 } else {
238 0 ▶ Danga::Socket->AddTimer(0, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
239 0 $p->finish_push;
240 0 });
241 }
242 }
243  
244 0 ▶sub set_rcvd_features {
Subroutine set_rcvd_features: not called CC=1 SCAR=6.9
Pod undocumented
245 0 my ($self, $feat_stanza) = @_;
246 0 $self->{rcvd_features} = $feat_stanza;
247 }
248  
249 0 ▶sub set_bound_jid {
Subroutine set_bound_jid: not called CC=3 SCAR=24.8
Pod undocumented
250 0 my ($self, $jid) = @_;
251 0 ▶ die unless $jid && $jid->isa('DJabberd::JID');
Branch: 1 branch
BranchTrueFalseTotal
unless $jid and $jid->isa("DJabberd::JID") 0 0 0
Condition0%0/3
$jid and $jid->isa("DJabberd::JID")
!ll&&!rl&&r
000
MC/DC0%0/2
$jid and $jid->isa("DJabberd::JID")
$jid $jid->isa("DJabberd::JID")
Truth table0%0/3
A and B
A= $jidB= $jid->isa("DJabberd::JID")
ABresult
0X0
100
111
252 0 $self->{bound_jid} = $jid;
253 }
254  
255 0 ▶sub set_to_host {
Subroutine set_to_host: not called CC=1 SCAR=6.9
Pod undocumented
256 0 my ($self, $host) = @_;
257 0 $self->{to_host} = $host;
258 }
259  
260 0 ▶sub to_host {
Subroutine to_host: not called CC=1 SCAR=6.9
Pod undocumented
261 0 my $self = shift;
262 return $self->{to_host} or
263 0 die "To host accessed before it was set";
264 }
265  
266 0 ▶sub set_version {
Subroutine set_version: not called CC=1 SCAR=6.9
Pod undocumented
267 0 my ($self, $verob) = @_;
268 0 $self->{version} = $verob;
269 }
270  
271 0 ▶sub version {
Subroutine version: not called CC=1 SCAR=6.9
Pod undocumented
272 0 my $self = shift;
273 return $self->{version} or
274 0 die "Version accessed before it was set";
275 }
276  
277 0 ▶sub stream_id {
Subroutine stream_id: not called CC=2 SCAR=17.9
Pod undocumented
278 0 my $self = shift;
279 0 ▶ return $self->{stream_id} ||= Digest::SHA1::sha1_hex(rand() . rand() . rand());
Condition0%0/3
$self->{"stream_id"} ||= Digest::SHA1::sha1_hex((rand()) . (rand()) . (rand()))
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"stream_id"} ||= Digest::SHA1::sha1_hex((rand()) . (rand()) . (rand()))
$self->{"stream_id"} Digest::SHA1::sha1_hex((rand()) . (rand()) . (rand()))
Truth table0%0/3
A ||= B
A= $self->{"stream_id"}B= Digest::SHA1::sha1_hex((rand()) . (rand()) . (rand()))
ABresult
1X1
011
000
280 }
281  
282 # only use this run_hook_chain when
283 0 ▶sub run_hook_chain {
Subroutine run_hook_chain: not called CC=2 SCAR=17.9
Pod undocumented
284 0 my $self = shift;
285 0 my %opts = @_;
286 0 $opts{hook_invocant} = $self;
287  
288 0 my $known_deprecated = delete $opts{deprecated};
289 0 my ($pkg, $filename, $line) = caller;
290 0 my $vhost = $self->vhost;
291  
292 0 ▶ unless ($known_deprecated) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($known_deprecated) 0 0 0
293 0 warn("DEPRECATED caller ($pkg/$filename/$line) of run_hook_chain on a connection\n");
294 }
295 0 return DJabberd::VHost::run_hook_chain($vhost, %opts);
296 }
297  
298 # this can fail to signal that this connection can't work on this
299 # vhost for instance, this vhost doesn't support s2s, so a serverin or
300 # dialback subclass can override this to return 0 when s2s isn't
301 # enabled for the vhost
302 0 ▶sub set_vhost {
Subroutine set_vhost: not called CC=2 SCAR=17.9
Pod undocumented
303 0 my ($self, $vhost) = @_;
304 0 ▶ Carp::croak("Not a DJabberd::VHost: $vhost") unless UNIVERSAL::isa($vhost, "DJabberd::VHost");
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($vhost, "DJabberd::VHost") 0 0 0
305 0 $self->{vhost} = $vhost;
306 0 Scalar::Util::weaken($self->{vhost});
307 0 return 1;
308 }
309  
310 # called by DJabberd::SAXHandler
311 0 ▶sub on_stanza_received {
Subroutine on_stanza_received: not called CC=1 SCAR=6.9
Pod undocumented
312 0 my ($self, $node) = @_;
313 0 die "SUBCLASSES MUST OVERRIDE 'on_stanza_received' for $self\n";
314 }
315  
316 # subclasses should override returning 0 or 1
317 0 ▶sub is_server {
Subroutine is_server: not called CC=1 SCAR=6.9
Pod undocumented
318 0 die "Undefined 'is_server' for $_[0]";
319 }
320  
321 0 ▶sub process_incoming_stanza_from_s2s_out {
Subroutine process_incoming_stanza_from_s2s_out: not called CC=2 SCAR=17.9
Pod undocumented
322 0 my ($self, $node) = @_;
323  
324 0 my %stanzas = (
325 "{urn:ietf:params:xml:ns:xmpp-tls}starttls" => 'DJabberd::Stanza::StartTLS',
326 "{http://etherx.jabber.org/streams}features" => 'DJabberd::Stanza::StreamFeatures',
327 );
328  
329 0 my $class = $stanzas{$node->element};
330 0 ▶ unless ($class) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class) 0 0 0
331 0 warn "Unknown/handled stanza: " . $node->element . " on connection ($self->{id}), " . ref($self) . "\n";
332 0 return;
333 }
334  
335 0 my $obj = $class->downbless($node, $self);
336 0 $obj->on_recv_from_server($self);
337 }
338  
339 0 ▶sub send_stanza {
Subroutine send_stanza: not called CC=1 SCAR=6.9
Pod undocumented
340 0 my ($self, $stanza) = @_;
341  
342 # getter subref for pre_stanza_write hooks to
343 # get at their own private copy of the stanza
344 0 my $cloned;
345 0 ▶ my $getter = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
346 0 ▶ return $cloned if $cloned;
Branch: 1 branch
BranchTrueFalseTotal
if $cloned 0 0 0
347 0 ▶ if ($self != $stanza->connection) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self != $stanza->connection) { } 0 0 0
348 0 $cloned = $stanza->clone;
349 0 $cloned->set_connection($self);
350 } else {
351 0 $cloned = $stanza;
352 }
353 0 return $cloned;
354 0 };
355  
356 $self->vhost->hook_chain_fast("pre_stanza_write",
357 [ $getter ],
358 {
359 # TODO: implement.
360 },
361 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
362 # if any hooks called the $getter, instantiating
363 # the $cloned copy, then that's what we write.
364 # as an optimization (the fast path), we just
365 # write the untouched, uncloned original.
366 0 ▶ $self->write_stanza($cloned || $stanza);
Condition0%0/3
$cloned || $stanza
l!l&&r!l&&!r
000
MC/DC0%0/2
$cloned || $stanza
$cloned $stanza
Truth table0%0/3
A || B
A= $clonedB= $stanza
ABresult
1X1
011
000
367 0 });
368 }
369  
370 0 ▶sub write_stanza {
Subroutine write_stanza: not called CC=10 SCAR=47.0
Pod undocumented
371 0 my ($self, $stanza) = @_;
372  
373 0 ▶ my $to_jid = $stanza->to_jid || die "missing 'to' attribute in ".$stanza->element_name." stanza";
Condition0%0/2
$stanza->to_jid || die(q[missing 'to' attribute in ] . $stanza->element_name . ' stanza')
l!l
00
MC/DC0%0/1
$stanza->to_jid || die(q[missing 'to' attribute in ] . $stanza->element_name . ' stanza')
$stanza->to_jid
Truth table0%0/2
A
A= $stanza->to_jid
Aresult
11
00
374 0 my $from_jid = $stanza->from_jid; # this can be iq
375 0 my $elename = $stanza->element_name;
376  
377 0 my $other_attrs = "";
378 0 my $attrs = $stanza->attrs;
379 0 ▶ while (my ($k, $v) = each %$attrs) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$attrs) 0 0 0
380 0 $k =~ s/.+\}//; # get rid of the namespace
381 0 ▶ next if $k eq "to" || $k eq "from";
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "to" or $k eq "from" 0 0 0
Condition0%0/3
$k eq "to" or $k eq "from"
l!l&&r!l&&!r
000
MC/DC0%0/2
$k eq "to" or $k eq "from"
$k eq "to" $k eq "from"
Truth table0%0/3
A or B
A= $k eq "to"B= $k eq "from"
ABresult
1X1
011
000
382 0 $other_attrs .= "$k=\"" . exml($v) . "\" ";
383 }
384  
385 0 my $from = "";
386 0 ▶ die "no from" if ($elename ne 'iq' && !$from_jid);
Branch: 1 branch
BranchTrueFalseTotal
if $elename ne "iq" and not $from_jid 0 0 0
Condition0%0/3
$elename ne "iq" and not $from_jid
!ll&&!rl&&r
000
MC/DC0%0/2
$elename ne "iq" and not $from_jid
$elename ne "iq" not $from_jid
Truth table0%0/3
A and not(B)
A= $elename ne "iq"B= not $from_jid
ABresult
0X0
100
111
387  
388 0 ▶ $from = $from_jid ? " from='" . $from_jid->as_string_exml . "'" : "";
Branch: 1 branch
BranchTrueFalseTotal
$from_jid ? : 0 0 0
389  
390 0 my $to_str = $to_jid->as_string_exml;
391 0 my $ns = $self->namespace;
392  
393 0 my $xml = "<$elename $other_attrs to='$to_str'$from>" . $stanza->innards_as_xml . "</$elename>";
394  
395 0 ▶ if ($self->xmllog->is_info) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->xmllog->is_info) 0 0 0
396 # refactor this out
397 0 my $debug;
398 0 ▶ if($self->xmllog->is_debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->xmllog->is_debug) { } 0 0 0
399 0 $debug = "<$elename $other_attrs to='$to_str'$from>" . $stanza->innards_as_xml . "</$elename>";
400 } else {
401 0 local $DJabberd::ASXML_NO_TEXT = 1;
402 0 $debug = "<$elename $other_attrs to='$to_str'$from>" . $stanza->innards_as_xml . "</$elename>";
403 }
404 0 $self->log_outgoing_data($debug);
405 }
406  
407 0 $self->write(\$xml);
408 }
409  
410 0 ▶sub namespace {
Subroutine namespace: not called CC=1 SCAR=6.9
Pod undocumented
411 0 my $self = shift;
412 0 Carp::confess("namespace called on $self which has no namespace");
413 }
414  
415 # return SSL state object. more useful as a boolean if conn is in SSL mode.
416 0 ▶sub ssl {
Subroutine ssl: not called CC=1 SCAR=6.9
Pod undocumented
417 0 my $self = shift;
418 0 return $self->{ssl};
419 }
420  
421 # return the DJabberd::SASL::Connection object attached to this connection
422 # if SASL is being or has been negotiated
423 0 ▶sub sasl {
Subroutine sasl: not called CC=1 SCAR=6.9
Pod undocumented
424 0 my $self = shift;
425 0 return $self->{sasl};
426 }
427  
428 # called by Danga::Socket when a write doesn't fully go through. by default it
429 # enables writability. but we want to do nothing if we're waiting for a read for SSL
430 0 ▶sub on_incomplete_write {
Subroutine on_incomplete_write: not called CC=2 SCAR=17.9
Pod undocumented
431 0 my $self = shift;
432 0 ▶ return if $self->{write_when_readable};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"write_when_readable"} 0 0 0
433 0 $self->SUPER::on_incomplete_write;
434 }
435  
436 # called by SSL machinery to let us know a write is stalled on readability.
437 # so we need to (at least temporarily) go readable and then process writes.
438 0 ▶sub write_when_readable {
Subroutine write_when_readable: not called CC=2 SCAR=17.9
Pod undocumented
439 0 my $self = shift;
440  
441 # enable readability, but remember old value so we can pop it back
442 0 ▶ my $prev_readable = ($self->{event_watch} & POLLIN) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'event_watch'} & 1 ? : 0 0 0
443 0 $self->watch_read(1);
444 0 $self->{write_when_readable} = [ $prev_readable ];
445  
446 # don't need to push/pop its state because Danga::Socket->write, called later,
447 # will do the one final write, or if not all written, will turn on watch_write
448 0 $self->watch_write(0);
449 }
450  
451 0 ▶sub restart_stream {
Subroutine restart_stream: not called CC=1 SCAR=6.9
Pod undocumented
452 0 my DJabberd::Connection $self = shift;
453  
454 0 $self->{in_stream} = 0;
455  
456 # to be safe, we just discard the parser, as they might've sent,
457 # say, "<starttls/><attack", knowing the next user will get that
458 # parser with "<attack" open and get a parser error and be
459 # disconnected.
460 0 $self->discard_parser;
461 }
462  
463  
464 # this is a hack to get everything we print
465 # this is a slow down now, will fix later but
466 # eval is being annoying
467 0 ▶sub write {
Subroutine write: not called CC=1 SCAR=1.2
Pod documented
468 0 my $self = shift;
469 0 if (XMLDEBUG) {
470 my $time = Time::HiRes::time;
471 20 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
472 my $data = $_[0];
473 $data = $$data if (ref($data) eq 'SCALAR');
474 $LOGMAP{$self}->print("$time\t> $data\n") if $LOGMAP{$self} && ref($data) ne 'CODE' ;
475 }
476 0 $self->SUPER::write(@_);
477 }
478  
479  
480 # DJabberd::Connection
481 0 ▶sub event_read {
Subroutine event_read: not called CC=19 SCAR=59.4
Pod documented
482 0 my DJabberd::Connection $self = shift;
483  
484 # for async SSL: if a session renegotation is in progress,
485 # our previous write wants us to become readable first.
486 # we then go back into the write path (by flushing the write
487 # buffer) and it then does a read on this socket.
488 0 ▶ if (my $ar = $self->{write_when_readable}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ar = $self->{"write_when_readable"}) 0 0 0
489 0 $self->{write_when_readable} = 0;
490 0 $self->watch_read($ar->[0]); # restore previous readability state
491 0 $self->watch_write(1);
492 0 return;
493 }
494  
495 0 my $bref;
496 0 ▶ if (my $ssl = $self->{ssl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ssl = $self->{'ssl'}) { } 0 0 0
497 0 my $data = Net::SSLeay::read($ssl);
498  
499 0 my $errs = Net::SSLeay::print_errs('SSL_read');
500 0 ▶ if ($errs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errs) 0 0 0
501 0 warn "SSL Read error: $errs\n";
502 0 $self->close;
503 0 return;
504 }
505  
506 # Net::SSLeays buffers internally, so if we didn't read anything, it's
507 # in its buffer
508 0 ▶ unless ($data && length $data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data and length $data) 0 0 0
Condition0%0/3
$data and length $data
!ll&&!rl&&r
000
MC/DC0%0/2
$data and length $data
$data length $data
Truth table0%0/3
A and B
A= $dataB= length $data
ABresult
0X0
100
111
509 # a few of these in a row implies an EOF. else it could
510 # just be the underlying socket was readable, but there
511 # wasn't enough of an SSL packet for OpenSSL/etc to return
512 # any unencrypted data back to us.
513 # We call 'actual_error_on_empty_read' to avoid counting
514 # SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE as 'actual' errors
515 0 my $err = DJabberd::Stanza::StartTLS->actual_error_on_empty_read($ssl);
516 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
517 0 $self->log->warn("SSL Read error: $err (assuming ssl_eof)");
518 0 $self->close('ssl_eof');
519 }
520 0 return;
521 }
522 0 $bref = \$data;
523 } else {
524 # non-ssl mode:
525 0 $bref = $self->read(20_000);
526 }
527  
528 0 ▶ return $self->close unless defined $bref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bref 0 0 0
529  
530 # clients send whitespace between stanzas as keep-alives. let's just ignore those,
531 # not going through the bother to checkout a parser and all.
532 0 ▶ return if ! $self->{parser} && $$bref !~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parser"} or $$bref =~ /\S/ 0 0 0
Condition0%0/3
$self->{"parser"} or $$bref =~ /\S/
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"parser"} or $$bref =~ /\S/
$self->{"parser"} $$bref =~ /\S/
Truth table0%0/3
A or B
A= $self->{"parser"}B= $$bref =~ /\S/
ABresult
1X1
011
000
533  
534 0 ▶ Carp::confess if ($self->{closed});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 0 0
535  
536 0 if (XMLDEBUG) {
537 my $time = Time::HiRes::time;
538 $LOGMAP{$self}->print("$time\t< $$bref\n");
539 }
540  
541 0 ▶ my $p = $self->{parser} || $self->borrow_a_parser;
Condition0%0/3
$self->{'parser'} || $self->borrow_a_parser
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'parser'} || $self->borrow_a_parser
$self->{'parser'} $self->borrow_a_parser
Truth table0%0/3
A || B
A= $self->{'parser'}B= $self->borrow_a_parser
ABresult
1X1
011
000
542 0 my $len = length $$bref;
543 #$self->log->debug("$self->{id} parsing $len bytes...") unless $len == 1;
544  
545 # remove invalid low unicode code points which aren't allowed in XML,
546 # but both iChat and gaim have been observed to send in the wild, often
547 # when copy/pasting from bizarre sources. this probably isn't compliant,
548 # and there's a speed hit, so only regexp them out in quirks mode:
549 0 ▶ if ($self->{vhost} && $self->{vhost}{quirksmode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"vhost"} and $self->{"vhost"}{"quirksmode"}) 0 0 0
Condition0%0/3
$self->{"vhost"} and $self->{"vhost"}{"quirksmode"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"vhost"} and $self->{"vhost"}{"quirksmode"}
$self->{"vhost"} $self->{"vhost"}{"quirksmode"}
Truth table0%0/3
A and B
A= $self->{"vhost"}B= $self->{"vhost"}{"quirksmode"}
ABresult
0X0
100
111
550 0 $$bref =~ s/&\#([\da-f]{0,8});/DJabberd::Util::numeric_entity_clean($1)/ieg;
551 }
552  
553 0 eval {
554 0 $p->parse_chunk_scalarref($bref);
555 };
556  
557 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
558 # FIXME: give them stream error before closing them,
559 # wait until they get the stream error written to them before closing
560 0 $self->discard_parser;
561 0 $self->log->error("$self->{id} disconnected $self because: $@");
562 0 $self->log->warn("$self->{id} parsing *****\n$$bref\n*******\n\n\n");
563 0 $self->close;
564 0 return;
565 }
566  
567 # if we still have a handler and haven't already closed down (cleanly),
568 # then let's consider giving our xml parser/sax pair back, if we're at
569 # a good breaking point.
570 0 ▶ if ((my $handler = $self->handler) && ! $self->{closed}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = $self->handler and not $self->{"closed"}) 0 0 0
Condition0%0/3
my $handler = $self->handler and not $self->{"closed"}
!ll&&!rl&&r
000
MC/DC0%0/2
my $handler = $self->handler and not $self->{"closed"}
my $handler = $self->handler not $self->{"closed"}
Truth table0%0/3
A and not(B)
A= my $handler = $self->handlerB= not $self->{"closed"}
ABresult
0X0
100
111
571 0 my $depth = $handler->depth;
572 0 ▶ if ($depth == 0 && $$bref =~ m!>\s*$!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth == 0 and $$bref =~ />\s*$/) 0 0 0
Condition0%0/3
$depth == 0 and $$bref =~ />\s*$/
!ll&&!rl&&r
000
MC/DC0%0/2
$depth == 0 and $$bref =~ />\s*$/
$depth == 0 $$bref =~ />\s*$/
Truth table0%0/3
A and B
A= $depth == 0B= $$bref =~ />\s*$/
ABresult
0X0
100
111
573 # if no errors and not inside a stanza, return our parser to save memory
574 0 $self->return_parser;
575 }
576 }
577 }
578  
579 0 ▶sub on_stream_start {
Subroutine on_stream_start: not called CC=1 SCAR=6.9
Pod undocumented
580 0 my DJabberd::Connection $self = shift;
581 0 my $ss = shift;
582  
583 0 die "on_stream_start not defined for $self";
584 }
585  
586 # when we're the client of a stream (we're talking first)
587 0 ▶sub start_init_stream {
Subroutine start_init_stream: not called CC=6 SCAR=37.4
Pod undocumented
588 0 my DJabberd::Connection $self = shift;
589 0 my %opts = @_;
590 0 ▶ my $extra_attr = delete $opts{'extra_attr'} || "";
Condition0%0/2
delete $opts{'extra_attr'} || ''
l!l
00
MC/DC0%0/1
delete $opts{'extra_attr'} || ''
delete $opts{'extra_attr'}
Truth table0%0/2
A
A= delete $opts{'extra_attr'}
Aresult
11
00
591 0 ▶ my $to = delete $opts{'to'} || Carp::croak("need 'to' domain");
Condition0%0/2
delete $opts{'to'} || Carp::croak(q[need 'to' domain])
l!l
00
MC/DC0%0/1
delete $opts{'to'} || Carp::croak(q[need 'to' domain])
delete $opts{'to'}
Truth table0%0/2
A
A= delete $opts{'to'}
Aresult
11
00
592 0 ▶ my $xmlns = delete $opts{'xmlns'} || "jabber:server";
Condition0%0/2
delete $opts{'xmlns'} || 'jabber:server'
l!l
00
MC/DC0%0/1
delete $opts{'xmlns'} || 'jabber:server'
delete $opts{'xmlns'}
Truth table0%0/2
A
A= delete $opts{'xmlns'}
Aresult
11
00
593 0 ▶ die if %opts;
Branch: 1 branch
BranchTrueFalseTotal
if %opts 0 0 0
594  
595 # {=init-version-is-max} -- we must announce the highest version we support
596 0 my $our_version = $self->server->spec_version;
597 0 my $ver_attr = $our_version->as_attr_string;
598  
599 # by default we send the optional to='' attribute in our stream, but we have support for
600 # disabling it for our test suite.
601 0 $to = "to='$to'";
602 0 ▶ $to = "" if $DJabberd::_T_NO_TO_IN_DIALBACKVERIFY_STREAM;
Branch: 1 branch
BranchTrueFalseTotal
if $DJabberd::_T_NO_TO_IN_DIALBACKVERIFY_STREAM 0 0 0
603  
604 # {=xml-lang}
605 0 my $xml = qq{<?xml version="1.0" encoding="UTF-8"?><stream:stream $to xmlns:stream='http://etherx.jabber.org/streams' xmlns='}.exml($xmlns).qq{' xml:lang='en' $extra_attr $ver_attr>};
606 0 $self->log_outgoing_data($xml);
607 0 $self->write($xml);
608 }
609  
610 # sending a stream when we're the server (replier) of the stream. a client already
611 # started one with us (the $ss object)
612 0 ▶sub start_stream_back {
Subroutine start_stream_back: not called CC=19 SCAR=59.4
Pod undocumented
613 0 my DJabberd::Connection $self = shift;
614 0 my DJabberd::StreamStart $ss = shift;
615  
616 # bind us to a vhost now.
617 0 my $to_host = $ss->to;
618 0 ▶ $self->set_to_host($to_host) if $to_host;
Branch: 1 branch
BranchTrueFalseTotal
if $to_host 0 0 0
619  
620 # Spec rfc3920 (dialback section) says: Note: The 'to' and 'from'
621 # attributes are OPTIONAL on the root stream element. (during
622 # dialback)
623 0 ▶ if ($to_host || ! $ss->announced_dialback) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to_host or not $ss->announced_dialback) 0 0 0
Condition0%0/3
$to_host or not $ss->announced_dialback
l!l&&r!l&&!r
000
MC/DC0%0/2
$to_host or not $ss->announced_dialback
$to_host not $ss->announced_dialback
Truth table0%0/3
A or not(B)
A= $to_hostB= not $ss->announced_dialback
ABresult
1X1
011
000
624 0 my $exist_vhost = $self->vhost;
625 0 my $vhost = $self->server->lookup_vhost($to_host);
626  
627 0 ▶ return $self->close_no_vhost($to_host)
Branch: 1 branch
BranchTrueFalseTotal
unless $vhost 0 0 0
628 unless ($vhost);
629  
630 # if they previously had a stream open, it shouldn't change (after SASL/SSL)
631 0 ▶ if ($exist_vhost && $exist_vhost != $vhost) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exist_vhost and $exist_vhost != $vhost) 0 0 0
Condition0%0/3
$exist_vhost and $exist_vhost != $vhost
!ll&&!rl&&r
000
MC/DC0%0/2
$exist_vhost and $exist_vhost != $vhost
$exist_vhost $exist_vhost != $vhost
Truth table0%0/3
A and B
A= $exist_vhostB= $exist_vhost != $vhost
ABresult
0X0
100
111
632 0 $self->log->info("Vhost changed for connection, disconnecting.");
633 0 $self->close;
634 0 return;
635 }
636  
637 # set_vhost returns 0 to signal that this connection won't
638 # accept this vhost. and by then it probably closed the stream
639 # with an error, so we just stop processing if we can't set it.
640 0 ▶ return unless $self->set_vhost($vhost);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->set_vhost($vhost) 0 0 0
641 }
642  
643 0 my %opts = @_;
644 0 ▶ my $ns = delete $opts{'namespace'} or
Branch: 1 branch
BranchTrueFalseTotal
my $ns = delete $opts{"namespace"} or die "No default namespace" 0 0 0
645 die "No default namespace"; # {=stream-def-namespace}
646  
647 0 ▶ my $extra_attr = delete $opts{'extra_attr'} || "";
Condition0%0/2
delete $opts{'extra_attr'} || ''
l!l
00
MC/DC0%0/1
delete $opts{'extra_attr'} || ''
delete $opts{'extra_attr'}
Truth table0%0/2
A
A= delete $opts{'extra_attr'}
Aresult
11
00
648 0 ▶ my $features_body = delete $opts{'features'} || "";
Condition0%0/2
delete $opts{'features'} || ''
l!l
00
MC/DC0%0/1
delete $opts{'features'} || ''
delete $opts{'features'}
Truth table0%0/2
A
A= delete $opts{'features'}
Aresult
11
00
649 0 ▶ die if %opts;
Branch: 1 branch
BranchTrueFalseTotal
if %opts 0 0 0
650  
651 0 my $features = "";
652 0 ▶ if ($ss->version->supports_features) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ss->version->supports_features) 0 0 0
653 # unless we're already in SSL mode, advertise it as a feature...
654 # {=must-send-features-on-1.0}
655 0 ▶ if (!$self->{ssl}
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"ssl"} and $self->server->ssl_cert_file and not $self->isa("DJabberd::Connection::ServerIn")) 0 0 0
Condition0%0/6
not $self->{"ssl"} and $self->server->ssl_cert_file and not $self->isa("DJabberd::Connection::ServerIn")
!ll&&!rl&&r
000
not $self->{"ssl"} and $self->server->ssl_cert_file
!ll&&!rl&&r
000
MC/DC0%0/3
not $self->{"ssl"} and $self->server->ssl_cert_file and not $self->isa("DJabberd::Connection::ServerIn")
not $self->{"ssl"} $self->server->ssl_cert_file not $self->isa("DJabberd::Connection::ServerIn")
Truth table0%0/4
not(A) and B and not(C)
A= not $self->{"ssl"}B= $self->server->ssl_cert_fileC= not $self->isa("DJabberd::Connection::ServerIn")
ABCresult
0XX0
10X0
1100
1111
656 && $self->server->ssl_cert_file
657 && !$self->isa("DJabberd::Connection::ServerIn")) {
658 0 $features_body .= "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls' />";
659 }
660 0 ▶ if (my $vh = $self->vhost) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $vh = $self->vhost) 0 0 0
661 $vh->hook_chain_fast("SendFeatures",
662 [ $self ],
663 {
664 0 ▶ stanza => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
665 0 my ($self, $xml_string) = @_;
666 0 $features_body .= $xml_string;
667 },
668 }
669 0 );
670 }
671 0 $features = qq{<stream:features>$features_body</stream:features>};
672 }
673  
674 # The receiving entity MUST set the value of the 'version'
675 # attribute on the response stream header to either the value
676 # supplied by the initiating entity or the highest version number
677 # supported by the receiving entity, whichever is lower.
678 # {=response-version-is-min}
679 0 my $our_version = $self->server->spec_version;
680 0 my $min_version = $ss->version->min($our_version);
681 0 $self->set_version($min_version);
682 0 my $ver_attr = $min_version->as_attr_string;
683  
684 0 my $id = $self->stream_id;
685  
686 # only include a from='hostname' attribute if we know our vhost.
687 # if they didn't send one to set us, it's probably dialback
688 # and they can cope without knowing ours yet.
689 0 my $vhost = $self->vhost;
690 0 ▶ my $sname = $vhost ? $vhost->name : "";
Branch: 1 branch
BranchTrueFalseTotal
$vhost ? : 0 0 0
691 0 ▶ my $from_attr = $sname ? "from='$sname'" : "";
Branch: 1 branch
BranchTrueFalseTotal
$sname ? : 0 0 0
692  
693 # {=streams-namespace}
694 0 my $back = qq{<?xml version="1.0" encoding="UTF-8"?><stream:stream $from_attr id="$id" $ver_attr $extra_attr xmlns:stream="http://etherx.jabber.org/streams" xmlns="$ns">$features};
695 0 $self->log_outgoing_data($back);
696 0 $self->write($back);
697 }
698  
699 0 ▶sub end_stream {
Subroutine end_stream: not called CC=1 SCAR=6.9
Pod undocumented
700 0 my DJabberd::Connection $self = shift;
701 0 $self->write("</stream:stream>");
702 0 ▶ $self->write(sub { $self->close; });
Subroutine __ANON__: not called CC=1 SCAR=6.9
703 }
704  
705 0 ▶sub event_write {
Subroutine event_write: not called CC=2 SCAR=17.9
Pod documented
706 0 my $self = shift;
707 0 ▶ $self->watch_write(0) if $self->write(undef);
Branch: 1 branch
BranchTrueFalseTotal
if $self->write(undef) 0 0 0
708 }
709  
710 # info is optional descriptive text
711 0 ▶sub stream_error {
Subroutine stream_error: not called CC=4 SCAR=30.0
Pod undocumented
712 0 my ($self, $err, $info) = @_;
713 0 ▶ $info ||= "";
Condition0%0/2
$info ||= ""
l!l
00
MC/DC0%0/1
$info ||= ""
$info
Truth table0%0/2
A
A= $info
Aresult
11
00
714  
715 # {=stream-errors}
716 0 $self->log->warn("$self->{id} stream error '$err': $info");
717 0 my $infoxml = "";
718 0 ▶ if ($info) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info) 0 0 0
719 0 $infoxml = "<text xmlns='urn:ietf:params:xml:ns:xmpp-streams'>" . exml($info) . "</text>";
720 }
721 0 ▶ unless ($self->{in_stream}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"in_stream"}) 0 0 0
722 0 $self->write(qq{<?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='bye' xml:lang='en'>});
723 }
724  
725 0 $self->write("<stream:error><$err xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>$infoxml</stream:error>");
726 # {=error-must-close-stream}
727 0 $self->close_stream;
728 }
729  
730 0 ▶sub close_no_vhost {
Subroutine close_no_vhost: not called CC=1 SCAR=6.9
Pod undocumented
731 0 my ($self, $vhost) = @_;
732  
733 # FIXME: send proper "vhost not found message"
734 # spec says:
735 # -- we have to start stream back to them,
736 # -- then send stream error
737 # -- stream should have proper 'from' address (but what if we have 2+)
738 #
739 # If the error occurs while the stream is being set up, the
740 # receiving entity MUST still send the opening <stream> tag,
741 # include the <error/> element as a child of the stream
742 # element, send the closing </stream> tag, and terminate the
743 # underlying TCP connection. In this case, if the initiating
744 # entity provides an unknown host in the 'to' attribute (or
745 # provides no 'to' attribute at all), the server SHOULD
746 # provide the server's authoritative hostname in the 'from'
747 # attribute of the stream header sent before termination
748  
749 # FIXME: send proper "vhost not found message"
750 # spec says:
751 # -- we have to start stream back to them,
752 # -- then send stream error
753 # -- stream should have proper 'from' address (but what if we have 2+)
754 # If the error occurs while the stream is being set up, the receiving entity MUST still send the opening <stream> tag, include the <error/> element as a child of the stream element, send the closing </stream> tag, and terminate the underlying TCP connection. In this case, if the initiating entity provides an unknown host in the 'to' attribute (or provides no 'to' attribute at all), the server SHOULD provide the server's authoritative hostname in the 'from' attribute of the stream header sent before termination
755  
756 0 $self->log->info("No vhost found for host '$vhost', disconnecting");
757 0 $self->close;
758 0 return;
759 }
760  
761 0 ▶sub close_stream {
Subroutine close_stream: not called CC=1 SCAR=6.9
Pod undocumented
762 0 my ($self, $err) = @_;
763 0 $self->write("</stream:stream>");
764 0 ▶ $self->write(sub { $self->close; });
Subroutine __ANON__: not called CC=1 SCAR=6.9
765 }
766  
767 0 ▶sub add_disconnect_handler {
Subroutine add_disconnect_handler: not called CC=2 SCAR=17.9
Pod undocumented
768 0 my ($self, $callback) = @_;
769 0 ▶ $self->{disconnect_handlers} ||= [];
Condition0%0/2
$self->{"disconnect_handlers"} ||= []
l!l
00
MC/DC0%0/1
$self->{"disconnect_handlers"} ||= []
$self->{"disconnect_handlers"}
Truth table0%0/2
A
A= $self->{"disconnect_handlers"}
Aresult
11
00
770 0 push @{$self->{disconnect_handlers}}, $callback;
771 }
772  
773 0 ▶sub _run_callback_list {
Subroutine _run_callback_list: not called CC=4 SCAR=30.0
774 0 my ($self, $listref, @args) = @_;
775
776 0 ▶ return unless ref $listref eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $listref eq "ARRAY" 0 0 0
777
778 0 foreach my $callback (@$listref) {
779 0 ▶ next unless ref $callback eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callback eq "CODE" 0 0 0
780
781 0 $callback->($self, @args);
782 }
783
784 }
785  
786 0 ▶sub close {
Subroutine close: not called CC=5 SCAR=34.0
Pod documented
787 0 my DJabberd::Connection $self = shift;
788 0 ▶ return if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 0 0
789  
790  
791 0 ▶ if ($self->{counted_close}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'counted_close'}++) { } 0 0 0
792 0 $self->log->logcluck("We are about to increment the diconnect counter one time too many, but we didn't");
793 } else {
794 0 $DJabberd::Stats::counter{disconnect}++;
795 }
796  
797 0 ▶ $self->log->debug("DISCONNECT: $self->{id}\n") if $self->{id};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"id"} 0 0 0
798 0 $self->_run_callback_list($self->{disconnect_handlers});
799  
800 0 ▶ if (my $p = $self->{parser}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $p = $self->{"parser"}) 0 0 0
801 # libxml isn't reentrant apparently, so we can't finish_push
802 # from inside an existint callback. so schedule immediately,
803 # after event loop.
804 0 ▶ Danga::Socket->AddTimer(0, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
805 0 $p->finish_push;
806 0 ▶ $self->{saxhandler}->cleanup if $self->{saxhandler};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"saxhandler"} 0 0 0
807 0 $self->{saxhandler} = undef;
808 0 $self->{parser} = undef;
809 0 });
810 }
811 0 if (XMLDEBUG) {
812 $LOGMAP{$self}->close;
813 delete $LOGMAP{$self};
814 }
815 0 $self->SUPER::close;
816  
817 }
818  
819 # DJabberd::Connection
820 0 ▶sub event_err { my $self = shift; $self->close; }
Subroutine event_err: not called CC=1 SCAR=6.9
Pod documented
821 0 ▶sub event_hup { my $self = shift; $self->close; }
Subroutine event_hup: not called CC=1 SCAR=6.9
Pod documented
822  
823  
824 # Local Variables:
825 # mode: perl
826 # c-basic-indent: 4
827 # indent-tabs-mode: nil
828 # End:
829  
830 20 1;
« DJabberd.pm ↑ Summary DJabberd/Authen/AllowedUsers.pm »