File Coverage

blib/lib/DJabberd/Plugin/JabberIqVersion.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package DJabberd::Plugin::JabberIqVersion;
2              
3 1     1   24322 use warnings;
  1         3  
  1         31  
4 1     1   6 use strict;
  1         1  
  1         37  
5 1     1   6 use base 'DJabberd::Plugin';
  1         16  
  1         664  
6             our $logger = DJabberd::Log->get_logger();
7 1     1   440 use DJabberd;
  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             use vars qw($VERSION);
19             $VERSION = '0.40';
20              
21             =head1 SYNOPSIS
22              
23            
24             ...
25            
26             OS Gnu/Windows
27             Name PerlJabberServer Professional
28             Version Gold
29            
30             ...
31            
32              
33             =cut
34              
35             =head2 set_config_version($self, $val)
36              
37             Configure the returned by module.
38              
39             =cut
40              
41             sub set_config_version {
42             my ($self, $val) = @_;
43             $self->{version} = $val;
44             }
45              
46             =head2 set_config_os($self, $val)
47              
48             Configure the returned by module.
49              
50             =cut
51              
52             sub set_config_os {
53             my ($self, $val) = @_;
54             $self->{os} = $val;
55             }
56              
57             =head2 set_config_name($self, $val)
58              
59             Configure the returned by module.
60              
61             =cut
62              
63             sub set_config_name {
64             my ($self, $val) = @_;
65             $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             sub finalize {
76             my ($self) = @_;
77             $self->{name} ||= 'DJabberd';
78             $self->{version} ||= $DJabberd::VERSION;
79              
80             my ($sysname, $nodename, $release, $version, $machine) = POSIX::uname();
81             $self->{os} ||= "$sysname $release";
82             }
83              
84              
85              
86             =head2 register($self, $vhost)
87              
88             Register the vhost with the module.
89              
90             =cut
91              
92             sub register {
93             my ($self, $vhost) = @_;
94             my $private_cb = sub {
95             my ($vh, $cb, $iq) = @_;
96             unless ($iq->isa("DJabberd::IQ") and defined $iq->to) {
97             $cb->decline;
98             return;
99             }
100             unless ($iq->to eq $vhost->{server_name}) {
101             $cb->decline;
102             return;
103             }
104            
105             if ($iq->signature eq 'get-{jabber:iq:version}query') {
106             $self->_get_version($vh, $iq);
107             $cb->stop_chain;
108             return;
109             }
110             $cb->decline;
111             };
112             $vhost->register_hook("switch_incoming_client",$private_cb);
113             $vhost->register_hook("switch_incoming_server",$private_cb);
114             $vhost->add_feature("jabber:iq:version");
115              
116             }
117              
118             sub _get_version {
119             my ($self, $vhost, $iq) = @_;
120            
121             $logger->info("Get version from : " . $iq->from_jid);
122             $iq->send_reply('result', qq()
123             . "" . $self->{name} . ""
124             . ( $self->{os} ? "" . $self->{os} . "" : "" )
125             . "" . $self->{version} . ""
126             . qq() );
127            
128             }
129              
130             =head1 AUTHOR
131              
132             Michael Scherer, C<< >>
133              
134             =head1 BUGS
135              
136             Please report any bugs or feature requests to
137             C, or through the web interface at
138             L.
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             1;