File Coverage

blib/lib/DJabberd/Plugin/PrivateStorage.pm
Criterion Covered Total %
statement 12 51 23.5
branch 0 14 0.0
condition 0 3 0.0
subroutine 4 10 40.0
pod n/a
total 16 78 20.5


line stmt bran cond sub pod time code
1             package DJabberd::Plugin::PrivateStorage;
2 1     1   28999 use strict;
  1         3  
  1         37  
3 1     1   5 use base 'DJabberd::Plugin';
  1         2  
  1         524  
4 1     1   6 use warnings;
  1         12  
  1         52  
5              
6             our $logger = DJabberd::Log->get_logger();
7              
8 1     1   5 use vars qw($VERSION);
  1         2  
  1         618  
9             $VERSION = '0.60';
10              
11             =head2 register($self, $vhost)
12              
13             Register the vhost with the module.
14              
15             =cut
16              
17             sub register {
18 0     0     my ($self, $vhost) = @_;
19             my $private_cb = sub {
20 0     0     my ($vh, $cb, $iq) = @_;
21 0 0         unless ($iq->isa("DJabberd::IQ")) {
22 0           $cb->decline;
23 0           return;
24             }
25 0 0         if(my $to = $iq->to_jid) {
26 0 0         unless ($vh->handles_jid($to)) {
27 0           $cb->decline;
28 0           return;
29             }
30             }
31 0 0         if ($iq->signature eq 'get-{jabber:iq:private}query') {
    0          
32 0           $self->_get_privatestorage($vh, $iq);
33 0           $cb->stop_chain;
34 0           return;
35             } elsif ($iq->signature eq 'set-{jabber:iq:private}query') {
36 0           $self->_set_privatestorage($vh, $iq);
37 0           $cb->stop_chain;
38 0           return;
39             }
40 0           $cb->decline;
41 0           };
42 0           $vhost->register_hook("switch_incoming_client",$private_cb);
43 0           $vhost->register_hook("switch_incoming_server",$private_cb);
44             # should be done ?
45             #$vhost->add_feature("vcard-temp");
46              
47             }
48              
49             sub _get_privatestorage {
50 0     0     my ($self, $vhost, $iq) = @_;
51 0           my $user = $iq->connection->bound_jid->as_bare_string;
52 0           my $content = $iq->first_element()->first_element();;
53 0           my $element = $content->element();
54 0           $logger->info("Get private storage for user : $user, $element ");
55 0           my $result = $self->load_privatestorage($user, $element);
56 0 0 0       if (defined $result and $result) {
57 0           $iq->send_reply('result', qq()
58             . $result
59             . qq() );
60             } else {
61             #
62             #
63             # this is $iq->first_element()
64             #
65             #
66             #
67             #
68 0           $iq->send_reply('result', $iq->first_element()->as_xml());
69             }
70             }
71              
72             sub _set_privatestorage {
73 0     0     my ($self, $vhost, $iq) = @_;
74              
75 0           my $user = $iq->connection->bound_jid->as_bare_string;
76 0           my $content = $iq->first_element()->first_element();;
77 0           my $element = $content->element();
78 0           $logger->info("Set private storage for user '$user', on $element");
79 0 0         if (! $self->store_privatestorage( $user, $element, $content)) {
80 0           $iq->make_error_response('501',"cancel", "feature-not-implemented")->deliver($vhost);
81             } else {
82 0           $iq->make_response()->deliver($vhost);
83             }
84             }
85              
86             =head2 store_privatestorage($self, $user, $element, $content)
87              
88             Store $content for $element and $user in the storage module.
89              
90             =cut
91              
92             sub store_privatestorage {
93 0     0     return undef;
94             }
95              
96             =head2 load_privatestorage($self, $user, $element, )
97              
98             Return the $element for $user from the storage module.
99              
100             =cut
101              
102             sub load_privatestorage {
103 0     0     return undef;
104             }
105              
106             1;
107              
108              
109             __END__