PrivateStorage.pm

filter: Statementstmt 35.1% 19 / 54 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 5 / 10 Podpod 100% 3 / 3 totaltotal 31.4% 27 / 86 CC 9 SCAR 28.5
CC
9
Cov
27%
__ANON__
42.0
_get_privatestorage
12.0
_set_privatestorage
6.0
CRAP 17.2
↑ Summary PrivateStorage/InMemoryOnly.pm »
1 package DJabberd::Plugin::PrivateStorage;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use base 'DJabberd::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $logger = DJabberd::Log->get_logger();
7  
8 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 $VERSION = '0.60';
10  
11 =head2 register($self, $vhost)
12  
13 Register the vhost with the module.
14  
15 =cut
16  
17 1 ▶sub register {
Subroutine register: called CC=1 SCAR=5.0
Pod documented
18 1 my ($self, $vhost) = @_;
19 0 ▶ my $private_cb = sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
20 0 my ($vh, $cb, $iq) = @_;
21 0 ▶ unless ($iq->isa("DJabberd::IQ")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($iq->isa("DJabberd::IQ")) 0 0 0
22 0 $cb->decline;
23 0 return;
24 }
25 0 ▶ if(my $to = $iq->to_jid) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $to = $iq->to_jid) 0 0 0
26 0 ▶ unless ($vh->handles_jid($to)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vh->handles_jid($to)) 0 0 0
27 0 $cb->decline;
28 0 return;
29 }
30 }
31 0 ▶ if ($iq->signature eq 'get-{jabber:iq:private}query') {
Branch: 2 branches
BranchTrueFalseTotal
if ($iq->signature eq 'get-{jabber:iq:private}query') { } 0 0 0
elsif ($iq->signature eq 'set-{jabber:iq:private}query') { } 0 0 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 1 };
42 1 $vhost->register_hook("switch_incoming_client",$private_cb);
43 1 $vhost->register_hook("switch_incoming_server",$private_cb);
44 # should be done ?
45 #$vhost->add_feature("vcard-temp");
46  
47 }
48  
49 0 ▶sub _get_privatestorage {
Subroutine _get_privatestorage: not called CC=3 SCAR=24.8
50 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 ▶ if (defined $result and $result) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result and $result) { } 0 0 0
Condition0%0/3
defined $result and $result
!ll&&!rl&&r
000
MC/DC0%0/2
defined $result and $result
defined $result $result
Truth table0%0/3
A and B
A= defined $resultB= $result
ABresult
0X0
100
111
57 0 $iq->send_reply('result', qq(<query xmlns="jabber:iq:private">)
58 . $result
59 . qq(</query>) );
60 } else {
61 #
62 #<iq to='brad@localhost/Gajim' type='result' id='237'>
63 # this is $iq->first_element()
64 # <query xmlns='jabber:iq:private'>
65 # <storage xmlns='storage:rosternotes'/>
66 # </query>
67 #</iq>
68 0 $iq->send_reply('result', $iq->first_element()->as_xml());
69 }
70 }
71  
72 0 ▶sub _set_privatestorage {
Subroutine _set_privatestorage: not called CC=2 SCAR=17.9
73 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 ▶ if (! $self->store_privatestorage( $user, $element, $content)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->store_privatestorage($user, $element, $content)) { } 0 0 0
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 0 ▶sub store_privatestorage {
Subroutine store_privatestorage: not called CC=1 SCAR=6.9
Pod documented
93 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 0 ▶sub load_privatestorage {
Subroutine load_privatestorage: not called CC=1 SCAR=6.9
Pod documented
103 0 return undef;
104 }
105  
106 3 1;
107  
108  
109 __END__
↑ Summary PrivateStorage/InMemoryOnly.pm »