| 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
| |||||||||||||||||||||||||||||
| 22 | 0 | $cb->decline; | |||||||||||||||||||||||||||
| 23 | 0 | return; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if(my $to = $iq->to_jid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | unless ($vh->handles_jid($to)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | $cb->decline; | |||||||||||||||||||||||||||
| 28 | 0 | return; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ($iq->signature eq 'get-{jabber:iq:private}query') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $result and $result
MC/DC0%0/2
defined $result and $result
defined $result
$result
Truth table0%0/3
A and B
A= defined $resultB= $result
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||