XMPP/PrivacyLists.pm

filter: Statementstmt 12.3% 14 / 113 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 17.3% 4 / 23 Podpod 0.0% 0 / 18 totaltotal 9.3% 18 / 192 CC 22 SCAR 29.2
CC
22
Cov
10%
handleIQ
72.0
exists
12.0
lists
12.0
CRAP 18.5
« XMPP/JID.pm ↑ Summary XMPP/Client.pm »
1 ##############################################################################
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Library General Public
5 # License as published by the Free Software Foundation; either
6 # version 2 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Library General Public License for more details.
12 #
13 # You should have received a copy of the GNU Library General Public
14 # License along with this library; if not, write to the
15 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 # Boston, MA 02111-1307, USA.
17 #
18 # Copyright (C) 1998-2004 Jabber Software Foundation http://jabber.org/
19 #
20 ##############################################################################
21  
22 package Net::XMPP::PrivacyLists;
23  
24 =head1 NAME
25  
26 Net::XMPP::PrivacyLists - XMPP Privacy Lists Object
27  
28 =head1 SYNOPSIS
29  
30 This module is not yet complete. Do not use.
31  
32 =head1 DESCRIPTION
33  
34 =head2 Basic Functions
35  
36 =head2 Advanced Functions
37  
38 =head1 METHODS
39  
40 =head2 Basic Functions
41  
42 =head2 Advanced Functions
43  
44 =head1 AUTHOR
45  
46 Originally authored by Ryan Eatmon.
47  
48 Previously maintained by Eric Hacker.
49  
50 Currently maintained by Darian Anthony Patrick.
51  
52 =head1 COPYRIGHT
53  
54 This module is free software, you can redistribute it and/or modify it
55 under the LGPL 2.1.
56  
57 =cut
58  
59 15 require 5.003;
60 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 15 ▶use XML::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
65  
66 sub new
67 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
68 0 my $proto = shift;
69 0 my $self = { };
70  
71 0 my %args;
72 0 ▶ while($#_ >= 0) { $args{ lc(pop(@_)) } = pop(@_); }
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ >= 0) 0 0 0
73  
74 0 $self->{CONNECTION} = $args{connection};
75  
76 0 bless($self, $proto);
77  
78 0 $self->init();
79  
80 0 return $self;
81 }
82  
83  
84 ##############################################################################
85 #
86 # init - initialize the module to use the privacy lists.
87 #
88 ##############################################################################
89 sub init
90 0 ▶{
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
91 0 my $self = shift;
92  
93 0 ▶ $self->{CONNECTION}-> SetXPathCallBacks('/iq[@type="result" or @type="set"]/query[@xmlns="jabber:iq:privacy"]'=>sub{ $self->handler(@_) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
94 }
95  
96  
97 ##############################################################################
98 #
99 # debug - print out a representation of the privacy lists.
100 #
101 ##############################################################################
102 sub debug
103 0 ▶{
Subroutine debug: not called CC=1 SCAR=6.9
Pod undocumented
104 0 my $self = shift;
105  
106 0 &XML::Stream::printData("\$self->{LISTS}",$self->{LISTS});
107 }
108  
109  
110 ##############################################################################
111 #
112 # addItem - add list item to a list.
113 #
114 ##############################################################################
115 sub addItem
116 0 ▶{
Subroutine addItem: not called CC=1 SCAR=6.9
Pod undocumented
117 0 my $self = shift;
118 0 my ($list,%item) = @_;
119  
120 0 my $order = delete($item{order});
121 0 $self->{LISTS}->{$list}->{$order} = \%item;
122 }
123  
124  
125 ###############################################################################
126 #
127 # clear - delete all of the JIDs from the DB completely.
128 #
129 ###############################################################################
130 sub clear
131 0 ▶{
Subroutine clear: not called CC=2 SCAR=17.9
Pod undocumented
132 0 my $self = shift;
133  
134 0 $self->{CONNECTION}->{DEBUG}->Log3("PrivacyLists::clear: clearing the database");
135 0 foreach my $list ($self->lists())
136 {
137 0 $self->remove($list);
138 }
139 0 $self->{CONNECTION}->{DEBUG}->Log3("PrivacyLists::clear: database is empty");
140 }
141  
142  
143 ##############################################################################
144 #
145 # exists - allows you to query if the JID exists in the Roster DB.
146 #
147 ##############################################################################
148 sub exists
149 0 ▶{
Subroutine exists: not called CC=3 SCAR=24.8
Pod undocumented
150 0 my $self = shift;
151 0 my $list = shift;
152  
153 0 ▶ return unless exists($self->{LISTS});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"LISTS"} 0 0 0
154 0 ▶ return unless exists($self->{LISTS}->{$list});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"LISTS"}{$list} 0 0 0
155 0 return 1;
156 }
157  
158  
159 ##############################################################################
160 #
161 # fetch - fetch the privacy lists from the server and populate the database.
162 #
163 ##############################################################################
164 sub fetch
165 0 ▶{
Subroutine fetch: not called CC=1 SCAR=6.9
Pod undocumented
166 0 my $self = shift;
167  
168 0 my $iq = $self->{CONNECTION}->PrivacyListsGet();
169 0 $self->handleIQ($iq);
170 }
171  
172  
173 ##############################################################################
174 #
175 # fetchList - fetch the privacy list from the server and populate the database.
176 #
177 ##############################################################################
178 sub fetchList
179 0 ▶{
Subroutine fetchList: not called CC=1 SCAR=6.9
Pod undocumented
180 0 my $self = shift;
181 0 my $list = shift;
182  
183 0 my $iq = $self->{CONNECTION}->PrivacyListsGet(list=>$list);
184 0 $self->handleIQ($iq);
185 }
186  
187  
188 ##############################################################################
189 #
190 # lists - returns a list of the current privacy lists.
191 #
192 ##############################################################################
193 sub lists
194 0 ▶{
Subroutine lists: not called CC=3 SCAR=24.8
Pod undocumented
195 0 my $self = shift;
196  
197 0 ▶ return () unless exists($self->{LISTS});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"LISTS"} 0 0 0
198 0 ▶ return () if (scalar(keys(%{$self->{LISTS}})) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %{$$self{"LISTS"};} == 0 0 0 0
199 0 return keys(%{$self->{LISTS}});
200 }
201  
202  
203 ##############################################################################
204 #
205 # items - returns a list of all of the items in the specified privacy list.
206 #
207 ##############################################################################
208 sub items
209 0 ▶{
Subroutine items: not called CC=3 SCAR=24.8
Pod undocumented
210 0 my $self = shift;
211 0 my $list = shift;
212  
213 0 my @items;
214  
215 0 ▶ return () unless $self->exists($list);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->exists($list) 0 0 0
216 0 foreach my $order (sort{ $a <=> $b } keys(%{$self->{LISTS}->{$list}}))
217 {
218 0 my %item = %{$self->{LISTS}->{$list}->{$order}};
219 0 $item{order} = $order;
220 0 push(@items,\%item);
221 }
222  
223 0 return @items;
224 }
225  
226  
227 ##############################################################################
228 #
229 # handler - takes a packet and calls the correct handler.
230 #
231 ##############################################################################
232 sub handler
233 0 ▶{
Subroutine handler: not called CC=2 SCAR=17.9
Pod undocumented
234 0 my $self = shift;
235 0 my $sid = shift;
236 0 my $packet = shift;
237  
238 0 ▶ $self->handleIQ($packet) if ($packet->GetTag() eq "iq");
Branch: 1 branch
BranchTrueFalseTotal
if $packet->GetTag eq "iq" 0 0 0
239 }
240  
241  
242 ##############################################################################
243 #
244 # handleIQ - takes an iq packet that contains roster, parses it, and puts
245 # the roster into the Roster DB.
246 #
247 ##############################################################################
248 sub handleIQ
249 0 ▶{
Subroutine handleIQ: not called CC=8 SCAR=42.8
Pod undocumented
250 0 my $self = shift;
251 0 my $iq = shift;
252  
253 0 print "handleIQ: iq(",$iq->GetXML(),")\n";
254  
255 0 my $type = $iq->GetType();
256 0 ▶ return unless (($type eq "set") || ($type eq "result"));
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "set" or $type eq "result" 0 0 0
Condition0%0/3
$type eq "set" or $type eq "result"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "set" or $type eq "result"
$type eq "set" $type eq "result"
Truth table0%0/3
A or B
A= $type eq "set"B= $type eq "result"
ABresult
1X1
011
000
257  
258 0 ▶ if ($type eq "result")
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "result") 0 0 0
259 {
260 0 my $query = $iq->GetChild("jabber:iq:privacy");
261  
262 0 my @lists = $query->GetLists();
263  
264 0 ▶ return unless ($#lists > -1);
Branch: 1 branch
BranchTrueFalseTotal
unless $#lists > -1 0 0 0
265  
266 0 my @items = $lists[0]->GetItems();
267  
268 0 ▶ if (($#lists == 0) && ($#items > -1))
Branch: 2 branches
BranchTrueFalseTotal
if ($#lists == 0 and $#items > -1) { } 0 0 0
elsif ($#lists >= -1) { } 0 0 0
Condition0%0/3
$#lists == 0 and $#items > -1
!ll&&!rl&&r
000
MC/DC0%0/2
$#lists == 0 and $#items > -1
$#lists == 0 $#items > -1
Truth table0%0/3
A and B
A= $#lists == 0B= $#items > -1
ABresult
0X0
100
111
269 {
270 0 $self->parseList($lists[0]);
271 }
272 elsif ($#lists >= -1)
273 {
274 0 $self->parseLists(\@lists);
275 }
276 }
277 }
278  
279  
280 sub parseList
281 0 ▶{
Subroutine parseList: not called CC=2 SCAR=17.9
Pod undocumented
282 0 my $self = shift;
283 0 my $list = shift;
284  
285 0 my $name = $list->GetName();
286  
287 0 foreach my $item ($list->GetItems())
288 {
289 0 my %item = $item->GetItem();
290  
291 0 $self->addItem($name,%item);
292 }
293 }
294  
295  
296 sub parseLists
297 0 ▶{
Subroutine parseLists: not called CC=2 SCAR=17.9
Pod undocumented
298 0 my $self = shift;
299 0 my $lists = shift;
300  
301 0 foreach my $list (@{$lists})
302 {
303 0 my $name = $list->GetName();
304 0 $self->fetchList($name);
305 }
306 }
307  
308  
309 ##############################################################################
310 #
311 # reload - clear and refetch the privacy lists.
312 #
313 ##############################################################################
314 sub reload
315 0 ▶{
Subroutine reload: not called CC=1 SCAR=6.9
Pod undocumented
316 0 my $self = shift;
317  
318 0 $self->clear();
319 0 $self->fetch();
320 }
321  
322  
323 ##############################################################################
324 #
325 # remove - removes the list from the database.
326 #
327 ##############################################################################
328 sub remove
329 0 ▶{
Subroutine remove: not called CC=3 SCAR=24.8
Pod undocumented
330 0 my $self = shift;
331 0 my $list = shift;
332  
333 0 ▶ if ($self->exists($list))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->exists($list)) 0 0 0
334 {
335 0 $self->{CONNECTION}->{DEBUG}->Log3("PrivacyLists::remove: deleting $list from the DB");
336  
337 0 delete($self->{LISTS}->{$list});
338 0 ▶ delete($self->{LISTS}) if (scalar(keys(%{$self->{LISTS}})) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %{$$self{"LISTS"};} == 0 0 0 0
339 }
340 }
341  
342  
343 sub save
344 0 ▶{
Subroutine save: not called CC=2 SCAR=17.9
Pod undocumented
345 0 my $self = shift;
346  
347 0 foreach my $list ($self->lists())
348 {
349 0 $self->saveList($list);
350 }
351 }
352  
353  
354 sub saveList
355 0 ▶{
Subroutine saveList: not called CC=1 SCAR=6.9
Pod undocumented
356 0 my $self = shift;
357 0 my $list = shift;
358  
359 0 my @items = $self->items($list);
360 0 $self->{CONNECTION}->PrivacyListsSet(list=>$list,
361 items=>\@items);
362 }
363  
364  
365 15 1;
366  
« XMPP/JID.pm ↑ Summary XMPP/Client.pm »