| 1 | package DJabberd::Plugin::JabberIqVersion; | ||||||||||||||||||||||||||||
| 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::JabberIqVersion - Add support for "XEP 0092, Software version" to DJabberd | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 VERSION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Version 0.40 | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 3 | $VERSION = '0.40'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | <Vhost example.com> | ||||||||||||||||||||||||||||
| 24 | ... | ||||||||||||||||||||||||||||
| 25 | <Plugin DJabberd::Plugin::JabberIqVersion> | ||||||||||||||||||||||||||||
| 26 | OS Gnu/Windows | ||||||||||||||||||||||||||||
| 27 | Name PerlJabberServer Professional | ||||||||||||||||||||||||||||
| 28 | Version Gold | ||||||||||||||||||||||||||||
| 29 | </Plugin> | ||||||||||||||||||||||||||||
| 30 | ... | ||||||||||||||||||||||||||||
| 31 | </VHost> | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head2 set_config_version($self, $val) | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | Configure the <version/> returned by module. | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub set_config_version { | ||||||||||||||||||||||||||
|
Subroutine
set_config_version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 0 | my ($self, $val) = @_; | |||||||||||||||||||||||||||
| 43 | 0 | $self->{version} = $val; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head2 set_config_os($self, $val) | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | Configure the <os/> returned by module. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub set_config_os { | ||||||||||||||||||||||||||
|
Subroutine
set_config_os: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 0 | my ($self, $val) = @_; | |||||||||||||||||||||||||||
| 54 | 0 | $self->{os} = $val; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =head2 set_config_name($self, $val) | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | Configure the <name/> returned by module. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =cut | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub set_config_name { | ||||||||||||||||||||||||||
|
Subroutine
set_config_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 1 | my ($self, $val) = @_; | |||||||||||||||||||||||||||
| 65 | 1 | $self->{name} = $val; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =head2 finalize($self) | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | Fill default value. name is set to Djabberd, and version to the | ||||||||||||||||||||||||||||
| 71 | server version. Os is not filled, for the moment. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | ▶ | sub finalize { | ||||||||||||||||||||||||||
|
Subroutine
finalize: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 77 | 1 | ▶ | $self->{name} ||= 'DJabberd'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"name"} ||= "DJabberd"
MC/DC0%0/1
$self->{"name"} ||= "DJabberd"
$self->{"name"}
Truth table50%1/2
A
A= $self->{"name"}
| |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | $self->{version} ||= $DJabberd::VERSION; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"version"} ||= $DJabberd::VERSION
MC/DC0%0/2
$self->{"version"} ||= $DJabberd::VERSION
$self->{"version"}
$DJabberd::VERSION
Truth table33%1/3
A ||= B
A= $self->{"version"}B= $DJabberd::VERSION
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 1 | my ($sysname, $nodename, $release, $version, $machine) = POSIX::uname(); | |||||||||||||||||||||||||||
| 81 | 1 | ▶ | $self->{os} ||= "$sysname $release"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"os"} ||= "$sysname $release"
MC/DC0%0/1
$self->{"os"} ||= "$sysname $release"
$self->{"os"}
Truth table50%1/2
A
A= $self->{"os"}
| |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head2 register($self, $vhost) | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Register the vhost with the module. | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 1 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=1 SCAR=4.2
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | 1 | my ($self, $vhost) = @_; | |||||||||||||||||||||||||||
| 94 | 0 | ▶ | my $private_cb = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 95 | 0 | my ($vh, $cb, $iq) = @_; | |||||||||||||||||||||||||||
| 96 | 0 | ▶ | unless ($iq->isa("DJabberd::IQ") and defined $iq->to) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$iq->isa("DJabberd::IQ") and defined $iq->to
MC/DC0%0/2
$iq->isa("DJabberd::IQ") and defined $iq->to
$iq->isa("DJabberd::IQ")
defined $iq->to
Truth table0%0/3
A and B
A= $iq->isa("DJabberd::IQ")B= defined $iq->to
| |||||||||||||||||||||||||||||
| 97 | 0 | $cb->decline; | |||||||||||||||||||||||||||
| 98 | 0 | return; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | unless ($iq->to eq $vhost->{server_name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | $cb->decline; | |||||||||||||||||||||||||||
| 102 | 0 | return; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ($iq->signature eq 'get-{jabber:iq:version}query') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | $self->_get_version($vh, $iq); | |||||||||||||||||||||||||||
| 107 | 0 | $cb->stop_chain; | |||||||||||||||||||||||||||
| 108 | 0 | return; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | 0 | $cb->decline; | |||||||||||||||||||||||||||
| 111 | 1 | }; | |||||||||||||||||||||||||||
| 112 | 1 | $vhost->register_hook("switch_incoming_client",$private_cb); | |||||||||||||||||||||||||||
| 113 | 1 | $vhost->register_hook("switch_incoming_server",$private_cb); | |||||||||||||||||||||||||||
| 114 | 1 | $vhost->add_feature("jabber:iq:version"); | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub _get_version { | ||||||||||||||||||||||||||
|
Subroutine
_get_version: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 119 | 0 | my ($self, $vhost, $iq) = @_; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | $logger->info("Get version from : " . $iq->from_jid); | |||||||||||||||||||||||||||
| 122 | $iq->send_reply('result', qq(<query xmlns="jabber:iq:version">) | ||||||||||||||||||||||||||||
| 123 | . "<name>" . $self->{name} . "</name>" | ||||||||||||||||||||||||||||
| 124 | . ( $self->{os} ? "<os>" . $self->{os} . "</os>" : "" ) | ||||||||||||||||||||||||||||
| 125 | 0 | ▶ | . "<version>" . $self->{version} . "</version>" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | . qq(</query>) ); | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | Michael Scherer, C<< <misc@zarb.org> >> | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =head1 BUGS | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||
| 137 | C<bug-djabberd-plugin-jabberiqversion@rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||
| 138 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DJabberd-Plugin-JabberIqVersion>. | ||||||||||||||||||||||||||||
| 139 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||
| 140 | your bug as I make changes. | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | Copyright 2006 Michael Scherer, all rights reserved. | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 149 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =cut | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 3 | 1; | |||||||||||||||||||||||||||