line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
|
|
|
|
require 5.003; |
60
|
15
|
|
|
15
|
|
89
|
use strict; |
|
15
|
|
|
|
|
26
|
|
|
15
|
|
|
|
|
592
|
|
61
|
15
|
|
|
15
|
|
74
|
use warnings; |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
494
|
|
62
|
|
|
|
|
|
|
|
63
|
15
|
|
|
15
|
|
65
|
use Carp; |
|
15
|
|
|
|
|
23
|
|
|
15
|
|
|
|
|
1076
|
|
64
|
15
|
|
|
15
|
|
83
|
use XML::Stream; |
|
15
|
|
|
|
|
19
|
|
|
15
|
|
|
|
|
128
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub new |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
69
|
0
|
|
|
|
|
|
my $self = { }; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my %args; |
72
|
0
|
|
|
|
|
|
while($#_ >= 0) { $args{ lc(pop(@_)) } = pop(@_); } |
|
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
|
|
|
|
|
|
|
{ |
91
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
0
|
|
|
$self->{CONNECTION}-> SetXPathCallBacks('/iq[@type="result" or @type="set"]/query[@xmlns="jabber:iq:privacy"]'=>sub{ $self->handler(@_) }); |
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
############################################################################## |
98
|
|
|
|
|
|
|
# |
99
|
|
|
|
|
|
|
# debug - print out a representation of the privacy lists. |
100
|
|
|
|
|
|
|
# |
101
|
|
|
|
|
|
|
############################################################################## |
102
|
|
|
|
|
|
|
sub debug |
103
|
|
|
|
|
|
|
{ |
104
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
{ |
117
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
{ |
132
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
{ |
150
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
151
|
0
|
|
|
|
|
|
my $list = shift; |
152
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
return unless exists($self->{LISTS}); |
154
|
0
|
0
|
|
|
|
|
return unless exists($self->{LISTS}->{$list}); |
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
|
|
|
|
|
|
|
{ |
166
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
{ |
180
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
{ |
195
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
196
|
|
|
|
|
|
|
|
197
|
0
|
0
|
|
|
|
|
return () unless exists($self->{LISTS}); |
198
|
0
|
0
|
|
|
|
|
return () if (scalar(keys(%{$self->{LISTS}})) == 0); |
|
0
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
return keys(%{$self->{LISTS}}); |
|
0
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
{ |
210
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
211
|
0
|
|
|
|
|
|
my $list = shift; |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
my @items; |
214
|
|
|
|
|
|
|
|
215
|
0
|
0
|
|
|
|
|
return () unless $self->exists($list); |
216
|
0
|
|
|
|
|
|
foreach my $order (sort{ $a <=> $b } keys(%{$self->{LISTS}->{$list}})) |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
{ |
218
|
0
|
|
|
|
|
|
my %item = %{$self->{LISTS}->{$list}->{$order}}; |
|
0
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
{ |
234
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
235
|
0
|
|
|
|
|
|
my $sid = shift; |
236
|
0
|
|
|
|
|
|
my $packet = shift; |
237
|
|
|
|
|
|
|
|
238
|
0
|
0
|
|
|
|
|
$self->handleIQ($packet) if ($packet->GetTag() eq "iq"); |
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
|
|
|
|
|
|
|
{ |
250
|
0
|
|
|
0
|
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
|
0
|
0
|
|
|
|
return unless (($type eq "set") || ($type eq "result")); |
257
|
|
|
|
|
|
|
|
258
|
0
|
0
|
|
|
|
|
if ($type eq "result") |
259
|
|
|
|
|
|
|
{ |
260
|
0
|
|
|
|
|
|
my $query = $iq->GetChild("jabber:iq:privacy"); |
261
|
|
|
|
|
|
|
|
262
|
0
|
|
|
|
|
|
my @lists = $query->GetLists(); |
263
|
|
|
|
|
|
|
|
264
|
0
|
0
|
|
|
|
|
return unless ($#lists > -1); |
265
|
|
|
|
|
|
|
|
266
|
0
|
|
|
|
|
|
my @items = $lists[0]->GetItems(); |
267
|
|
|
|
|
|
|
|
268
|
0
|
0
|
0
|
|
|
|
if (($#lists == 0) && ($#items > -1)) |
|
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
{ |
282
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
{ |
298
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
299
|
0
|
|
|
|
|
|
my $lists = shift; |
300
|
|
|
|
|
|
|
|
301
|
0
|
|
|
|
|
|
foreach my $list (@{$lists}) |
|
0
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
{ |
316
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
{ |
330
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
331
|
0
|
|
|
|
|
|
my $list = shift; |
332
|
|
|
|
|
|
|
|
333
|
0
|
0
|
|
|
|
|
if ($self->exists($list)) |
334
|
|
|
|
|
|
|
{ |
335
|
0
|
|
|
|
|
|
$self->{CONNECTION}->{DEBUG}->Log3("PrivacyLists::remove: deleting $list from the DB"); |
336
|
|
|
|
|
|
|
|
337
|
0
|
|
|
|
|
|
delete($self->{LISTS}->{$list}); |
338
|
0
|
0
|
|
|
|
|
delete($self->{LISTS}) if (scalar(keys(%{$self->{LISTS}})) == 0); |
|
0
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
sub save |
344
|
|
|
|
|
|
|
{ |
345
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
{ |
356
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
1; |
366
|
|
|
|
|
|
|
|