| 1 | package DJabberd::Plugin::Ping; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use base 'DJabberd::Plugin'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | our $logger = DJabberd::Log->get_logger(); | |||||||||||||||||||||||||||
| 7 | 3 | ▶ | use DJabberd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | DJabberd::Plugin::Ping - Add support for "XEP 0199, Xmpp Ping" to DJabberd. | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 VERSION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Version 0.46 | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 3 | $VERSION = '0.46'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | <Vhost example.com> | ||||||||||||||||||||||||||||
| 24 | ... | ||||||||||||||||||||||||||||
| 25 | <Plugin DJabberd::Plugin::Ping /> | ||||||||||||||||||||||||||||
| 26 | ... | ||||||||||||||||||||||||||||
| 27 | </VHost> | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head2 register($self, $vhost) | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | Register the vhost with the module. | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =cut | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 1 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=1 SCAR=4.2
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 1 | my ($self, $vhost) = @_; | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | my $private_cb = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 41 | 0 | my ($vh, $cb, $iq) = @_; | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | unless ($iq->isa('DJabberd::IQ')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | $cb->decline; | |||||||||||||||||||||||||||
| 44 | 0 | return; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | unless ( ! $iq->to || $iq->to eq $vhost->{server_name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $iq->to or $iq->to eq $vhost->{"server_name"}
MC/DC0%0/2
not $iq->to or $iq->to eq $vhost->{"server_name"}
not $iq->to
$iq->to eq $vhost->{"server_name"}
Truth table0%0/3
not(A) or B
A= not $iq->toB= $iq->to eq $vhost->{"server_name"}
| |||||||||||||||||||||||||||||
| 47 | 0 | $cb->decline; | |||||||||||||||||||||||||||
| 48 | 0 | return; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($iq->signature eq 'get-{urn:xmpp:ping}ping') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | $self->_get_ping($vh, $iq); | |||||||||||||||||||||||||||
| 53 | 0 | $cb->stop_chain; | |||||||||||||||||||||||||||
| 54 | 0 | return; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | $cb->decline; | |||||||||||||||||||||||||||
| 57 | 1 | }; | |||||||||||||||||||||||||||
| 58 | 1 | $vhost->register_hook('switch_incoming_client',$private_cb); | |||||||||||||||||||||||||||
| 59 | 1 | $vhost->register_hook('switch_incoming_server',$private_cb); | |||||||||||||||||||||||||||
| 60 | # for version 0.3 of the spec | ||||||||||||||||||||||||||||
| 61 | # http://mail.jabber.org/pipermail/standards/2006-November/013207.html | ||||||||||||||||||||||||||||
| 62 | 1 | $vhost->add_feature('urn:xmpp:ping'); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub _get_ping { | ||||||||||||||||||||||||||
|
Subroutine
_get_ping: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 67 | 0 | my ($self, $vhost, $iq) = @_; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | $logger->info('Get ping from : ' . $iq->from_jid); | |||||||||||||||||||||||||||
| 70 | 0 | $iq->send_result(); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Michael Scherer, C<< <misc@zarb.org> >> | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head1 BUGS | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||
| 80 | C<bug-djabberd-plugin-ping@rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||
| 81 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DJabberd-Plugin-Ping>. | ||||||||||||||||||||||||||||
| 82 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||
| 83 | your bug as I make changes. | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Copyright 2007 Michael Scherer, all rights reserved. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 92 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 3 | 1; | |||||||||||||||||||||||||||