blib/lib/Net/Citadel.pm

filter: Statementstmt 26.3% 54 / 205 Branchbran 1.5% 1 / 66 Conditioncond 1.7% 2 / 114 MC/DCmcdc 0.0% 0 / 56 Subroutinesub 37.5% 9 / 24 Podpod 93.7% 15 / 16 totaltotal 16.8% 81 / 481 SCAR 76.7
CC
58
Cov
15%
assert_room
72.0
change_user
56.0
retract_floor
42.0
CRAP 2138.2
↑ Summary
1 package Net::Citadel;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 require Exporter;
7 1 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =pod
17  
18 =head1 NAME
19  
20 Net::Citadel - Citadel.org protocol coverage
21  
22 =head1 VERSION
23  
24 Version 0.24
25  
26 =cut
27  
28 1 our $VERSION = '0.24';
29  
30 =head1 SYNOPSIS
31  
32 use Net::Citadel;
33 my $c = new Net::Citadel (host => 'citadel.example.org');
34 $c->login ('Administrator', 'goodpassword');
35 my @floors = $c->floors;
36  
37 eval {
38 $c->assert_floor ('Level 6 (Management)');
39 }; warn $@ if $@;
40  
41 $c->retract_floor ('Level 6 (Management)');
42  
43 $c->logout;
44  
45 =head1 DESCRIPTION
46  
47 Citadel is a "turnkey open-source solution for email and collaboration" (this is as far as marketing
48 can go :-). The main component is the I<citadel server>. To communicate with it you can use either
49 a web interface, or - if you have to automate things - with a protocol
50  
51 L<http://www.citadel.org/doku.php?id=documentation:appproto:start>
52  
53 This package tries to do a bit of abstraction (more could be done) and handles some of the protocol
54 handling. The basic idea is that the application using the package deals with Citadel's objects:
55 rooms, floors, users.
56  
57 =head1 CONSTANTS
58  
59 =head2 Configuration
60  
61 =over 4
62  
63 =item CITADEL_PORT
64  
65 The constant $CITADEL_PORT is equal to C<504>, which is the IANA standard Citadel port.
66  
67 =back
68  
69 =cut
70  
71 1 Readonly our $CITADEL_PORT => 504;
72  
73 =head2 Result Codes
74  
75 =over 4
76  
77 =item LISTING_FOLLOWS
78  
79 The result code $LISTING_FOLLOWS is equal to C<100> and is used by the Citadel
80 server to indicate that after the server response, the server will output a
81 listing of some sort.
82  
83 =cut
84  
85 1 Readonly our $LISTING_FOLLOWS => 100;
86  
87 =item CIT_OK
88  
89 The result code $CIT_OK is equal to C<200> and is used by the Citadel
90 server to indicate that the requested operation succeeded.
91  
92 =cut
93  
94 1 Readonly our $CIT_OK => 200;
95  
96 =item MORE_DATA
97  
98 The result code $MORE_DATA is equal to C<300> and is used by the Citadel server
99 to indicate that the requested operation succeeded but that another command is
100 required to complete it.
101  
102 =cut
103  
104 1 Readonly our $MORE_DATA => 300;
105  
106 =item SEND_LISTING
107  
108 The result code $SEND_LISTING is equal to C<400> and is used by the Citadel
109 server to indicate that the requested operation is progressing and it is now
110 expecting zero or more lines of text.
111  
112 =cut
113  
114 1 Readonly our $SEND_LISTING => 400;
115  
116 =item ERROR
117  
118 The result code $ERROR is equal to C<500> and is used by the Citadel server to
119 indicate that the requested operation failed. The second and third digits of
120 the error code and/or the error message following it describes why.
121  
122 =cut
123  
124 1 Readonly our $ERROR => 500;
125  
126  
127 =item BINARY_FOLLOWS
128  
129 The result code $BINARY_FOLLOWS is equal to C<600> and is used by the Citadel server to
130 indicate that after this line, read C<n> bytes. (<Cn> follows after a blank)
131  
132 =cut
133  
134 1 Readonly our $BINARY_FOLLOWS => 600;
135  
136 =item SEND_BINARY
137  
138 The result code $SEND_BINARY is equal to C<700> and is used by the Citadel server to
139 indicate that C<n> bytes of binary data can now be sent. (C<n> follows after a blank.
140  
141 =cut
142  
143 1 Readonly our $SEND_BINARY => 700;
144  
145 =item START_CHAT_MODE
146  
147 The result code $START_CHAT_MODE is equal to C<800> and is used by the Citadel
148 server to indicate that the system is in chat mode now. Every line sent will be
149 broadcasted.
150  
151 =cut
152  
153 1 Readonly our $START_CHAT_MODE => 800;
154  
155 =item ASYNC_MSG
156  
157 The result code $ASYC_MSG is equal to C<900> and is used by the Citadel
158 server to indicate that there is a page waiting that needs to be fetched.
159  
160 =back
161  
162 =cut
163  
164 1 Readonly our $ASYNC_MSG => 900;
165  
166 =head2 Room Access
167  
168 =over 4
169  
170 =item PUBLIC
171  
172 The room access code $PUBLIC is equal to C<0> and is used to indicate that a
173 room is to have public access.
174  
175 =cut
176  
177 1 Readonly our $PUBLIC => 0;
178  
179 =item PRIVATE
180  
181 The room access code $PRIVATE is equal to C<1> and is used to indicate that a
182 room is to have private access.
183  
184 =cut
185  
186 1 Readonly our $PRIVATE => 1;
187  
188 =item PRIVATE_PASSWORD
189  
190 The room access code $PRIVATE_PASSWORD is equal to C<2> and is used to indicate
191 that a room is to have private access using a password.
192  
193 =cut
194  
195 1 Readonly our $PRIVATE_PASSWORD => 2;
196  
197 =item PRIVATE_INVITATION
198  
199 The room access code $PRIVATE_INVITATION is equal to C<3> and is used to indicate
200 that a room is to have private access by invitation.
201  
202 =cut
203  
204 1 Readonly our $PRIVATE_INVITATION => 3;
205  
206 =item PERSONAL
207  
208 The room access code $PERSONAL is equal to C<4> and is used to indicate
209 that a room is to be a private mailbox only for a particular user.
210  
211 =back
212  
213 =cut
214  
215 1 Readonly our $PERSONAL => 4;
216  
217 =head2 User related
218  
219 =over 4
220  
221 =item DELETED_USER
222  
223 The room access code $DELETED_USER is equal to C<0>.
224  
225 =cut
226  
227 1 Readonly our $DELETED_USER => 0;
228  
229 =item NEW_USER
230  
231 The User related constant $NEW_USER is equal to C<1>.
232  
233 =cut
234  
235 1 Readonly our $NEW_USER => 1;
236  
237 =item PROBLEM_USER
238  
239 The User related constant $PROBLEM_USER is equal to C<2>.
240  
241 =cut
242  
243 1 Readonly our $PROBLEM_USER => 2;
244  
245 =item LOCAL_USER
246  
247 The User related constant $LOCAL_USER is equal to C<3>.
248  
249 =cut
250  
251 1 Readonly our $LOCAL_USER => 3;
252  
253 =item NETWORK_USER
254  
255 The User related constant $NETWORK_USER is equal to C<4>.
256  
257 =cut
258  
259 1 Readonly our $NETWORK_USER => 4;
260  
261 =item PREFERRED_USER
262  
263 The User related constant $PREFERRED_USER is equal to C<5>.
264  
265 =cut
266  
267 1 Readonly our $PREFERRED_USER => 5;
268  
269 =item AIDE_USER
270  
271 The User related constant $AIDE user is equal to C<6>.
272  
273 =back
274  
275 =cut
276  
277 1 Readonly our $AIDE => 6;
278  
279 =pod
280  
281 =head1 INTERFACE
282  
283 =head2 Constructor
284  
285 C<$c = new Net::Citadel (host => $ctdl_host)>
286  
287 The constructor creates a handle to the citadel server (and creates the TCP
288 connection). It uses the following named parameters:
289  
290 =over
291  
292 =item I<host> (default: C<localhost>)
293  
294 The hostname (or IP address) where the citadel server is running. Defaults
295 to C<localhost>.
296  
297 =item I<port> (default: C<$CITADEL_PORT>)
298  
299 The port where the citadel server is running. Defaults to the standard Citadel
300 port number C<504>.
301  
302 =back
303  
304 The constructor will croak if no connection can be established.
305  
306 =cut
307  
308 sub new {
309 1 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=16.0
Pod undocumented
310 1 my $self = bless { @_ }, $class;
311 1 ▶ $self->{host} ||= 'localhost';
Condition50%1/2
$self->{"host"} ||= "localhost"
l!l
10
MC/DC0%0/1
$self->{"host"} ||= "localhost"
$self->{"host"}
Truth table50%1/2
A
A= $self->{"host"}
Aresult
11
00
312 1 ▶ $self->{port} ||= $CITADEL_PORT;
Condition33%1/3
$self->{"port"} ||= $Net::Citadel::CITADEL_PORT
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"port"} ||= $Net::Citadel::CITADEL_PORT
$self->{"port"} $Net::Citadel::CITADEL_PORT
Truth table33%1/3
A ||= B
A= $self->{"port"}B= $Net::Citadel::CITADEL_PORT
ABresult
1X1
011
000
313 1 ▶ use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
314 $self->{socket} = IO::Socket::INET->new (PeerAddr => $self->{host},
315 PeerPort => $self->{port},
316 1 ▶ Proto => 'tcp',
Branch: 1 branch
BranchTrueFalseTotal
$self->{"socket"} = "IO::Socket::INET"->new("PeerAddr", $self->{"host"}, "PeerPort", $self->{"port"}, "Proto", "tcp", "Type", 1) or croak(qq[cannot connect to $self->{"host"}:$self->{"port"} ($@)]) 1 0 1
317 Type => SOCK_STREAM) or croak "cannot connect to $self->{host}:$self->{port} ($@)";
318 0 my $s = $self->{socket}; <$s>; # consume banner
319 0 return $self;
320 }
321  
322 =pod
323  
324 =head2 Methods
325  
326 =head3 Authentication
327  
328 =over
329  
330 =item I<login>
331  
332 I<$c>->login (I<$user>, I<$pwd>)
333  
334 Logs in this user, or will croak if that fails.
335  
336 =cut
337  
338 sub login {
339 0 ▶ my $self = shift;
Subroutine login: not called CC=5 SCAR=34.0
Pod documented
340 0 my $user = shift;
341 0 my $pwd = shift;
342 0 my $s = $self->{socket};
343  
344 0 print $s "USER $user\n";
345 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 3 or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 3 || croak($2) 0 0 0
Condition0%0/6
readline($s) =~ /(\d).. (.*)/ && ($1 == 3 || croak($2))
!ll&&!rl&&r
000
$1 == 3 or croak($2)
l!l&&r!l&&!r
000
MC/DC0%0/3
readline($s) =~ /(\d).. (.*)/ && ($1 == 3 || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 3 croak($2)
Truth table0%0/4
A && B or C
A= readline($s) =~ /(\d).. (.*)/B= $1 == 3C= croak($2)
ABCresult
0XX0
1000
11X1
1011
346  
347 0 print $s "PASS $pwd\n";
348 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 2 or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 2 || croak($2) 0 0 0
Condition0%0/6
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
!ll&&!rl&&r
000
$1 == 2 or croak($2)
l!l&&r!l&&!r
000
MC/DC0%0/3
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 2 croak($2)
Truth table0%0/4
A && B or C
A= readline($s) =~ /(\d).. (.*)/B= $1 == 2C= croak($2)
ABCresult
0XX0
1000
11X1
1011
349  
350 0 return 1;
351 }
352  
353 =pod
354  
355 =item I<logout>
356  
357 I<$c>->logout
358  
359 Well, logs out the current user.
360  
361 =cut
362  
363 sub logout {
364 0 ▶ my $self = shift;
Subroutine logout: not called CC=3 SCAR=24.8
Pod documented
365 0 my $s = $self->{socket};
366  
367 0 print $s "LOUT\n";
368 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 2 or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 2 || croak($2) 0 0 0
Condition0%0/6
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
!ll&&!rl&&r
000
$1 == 2 or croak($2)
l!l&&r!l&&!r
000
MC/DC0%0/3
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 2 croak($2)
Truth table0%0/4
A && B or C
A= readline($s) =~ /(\d).. (.*)/B= $1 == 2C= croak($2)
ABCresult
0XX0
1000
11X1
1011
369  
370 0 return 1;
371 }
372  
373 =pod
374  
375 =back
376  
377 =head3 Floors
378  
379 =over
380  
381 =item I<floors>
382  
383 I<@floors> = I<$c>->floors
384  
385 Retrieves a list (ARRAY) of known floors. Each entry is a hash reference with the name, the number
386 of rooms in that floor and the index as ID. The index within the array is also the ID of the floor.
387  
388 =cut
389  
390 sub floors {
391 0 ▶ my $self = shift;
Subroutine floors: not called CC=4 SCAR=30.0
Pod documented
392 0 my $s = $self->{socket};
393  
394 0 print $s "LFLR\n";
395 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 1 or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 1 || croak($2) 0 0 0
Condition0%0/6
readline($s) =~ /(\d).. (.*)/ && ($1 == 1 || croak($2))
!ll&&!rl&&r
000
$1 == 1 or croak($2)
l!l&&r!l&&!r
000
MC/DC0%0/3
readline($s) =~ /(\d).. (.*)/ && ($1 == 1 || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 1 croak($2)
Truth table0%0/4
A && B or C
A= readline($s) =~ /(\d).. (.*)/B= $1 == 1C= croak($2)
ABCresult
0XX0
1000
11X1
1011
396  
397 0 my @floors;
398 0 ▶ while (($_ = <$s>) !~ /^000/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (($_ = readline $s) =~ /^000/) 0 0 0
399 #warn "_floors $_";
400 0 my ($nr, $name, $nr_rooms) = /(.+)\|(.+)\|(.+)/;
401 0 push @floors, { id => $nr, name => $name, nr_rooms => $nr_rooms };
402 }
403 0 return @floors;
404 #100 Known floors:
405 #0|Main Floor|33
406 #1|SecondLevel|1
407 #000
408 }
409  
410 =pod
411  
412 =item I<assert_floor>
413  
414 I<$c>->assert_floor (I<$floor_name>)
415  
416 Creates the floor with the name provided, or if it already exists simply returns. This only croaks if
417 there are insufficient privileges.
418  
419 =cut
420  
421 sub assert_floor {
422 0 ▶ my $self = shift;
Subroutine assert_floor: not called CC=5 SCAR=34.0
Pod documented
423 0 my $name = shift;
424  
425 0 my $s = $self->{socket};
426 0 print $s "CFLR $name|1\n"; # we really want to create it
427 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 1 or $1 == 2 or $2 =~ /already exists/ or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 1 || $1 == 2 || $2 =~ /already exists/ || croak($2) 0 0 0
Condition0%0/12
readline($s) =~ /(\d).. (.*)/ && ($1 == 1 || $1 == 2 || $2 =~ /already exists/ || croak($2))
!ll&&!rl&&r
000
$1 == 1 or $1 == 2 or $2 =~ /already exists/ or croak($2)
l!l&&r!l&&!r
000
$1 == 1 or $1 == 2 or $2 =~ /already exists/
l!l&&r!l&&!r
000
$1 == 1 or $1 == 2
l!l&&r!l&&!r
000
MC/DC0%0/5
readline($s) =~ /(\d).. (.*)/ && ($1 == 1 || $1 == 2 || $2 =~ /already exists/ || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 1 $1 == 2 $2 =~ /already exists/ croak($2)
Truth table0%0/6
A && B or C or D or E
A= readline($s) =~ /(\d).. (.*)/B= $1 == 1C= $1 == 2D= $2 =~ /already exists/E= croak($2)
ABCDEresult
0XXXX0
100000
11XXX1
101XX1
1001X1
100011
428 #CFLR XXX|1
429 #550 This command requires Aide access.
430 0 return 1;
431 }
432  
433 =pod
434  
435 =item I<retract_floor>
436  
437 I<$c>->retract_floor (I<$floor_name>)
438  
439 Retracts a floor with this name. croaks if that fails because of insufficient privileges. Does
440 not croak if the floor did not exist.
441  
442 B<NOTE>: Citadel server (v7.20) seems to have the bug that you cannot
443 delete an empty floor without restarting the server. Not much I can do
444 here about that.
445  
446 =cut
447  
448 sub retract_floor {
449 0 ▶ my $self = shift;
Subroutine retract_floor: not called CC=6 SCAR=37.4
Pod documented
450 0 my $name = shift;
451  
452 0 my @floors = $self->floors;
453 0 ▶ for (my $i = 0; $i <= $#floors; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#floors) 0 0 0
454 0 ▶ if ($floors[$i]->{name} eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($floors[$i]{"name"} eq $name) 0 0 0
455 0 my $s = $self->{socket};
456 0 print $s "KFLR $i|1\n"; # we really want to delete it
457 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 2 or $2 =~ /not in use/ or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 2 || $2 =~ /not in use/ || croak($2) 0 0 0
Condition0%0/9
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || $2 =~ /not in use/ || croak($2))
!ll&&!rl&&r
000
$1 == 2 or $2 =~ /not in use/ or croak($2)
l!l&&r!l&&!r
000
$1 == 2 or $2 =~ /not in use/
l!l&&r!l&&!r
000
MC/DC0%0/4
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || $2 =~ /not in use/ || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 2 $2 =~ /not in use/ croak($2)
Truth table0%0/5
A && B or C or D
A= readline($s) =~ /(\d).. (.*)/B= $1 == 2C= $2 =~ /not in use/D= croak($2)
ABCDresult
0XXX0
10000
11XX1
101X1
10011
458 0 return;
459 }
460 }
461 0 return 1;
462 }
463  
464 =pod
465  
466 =item I<rooms>
467  
468 I<@rooms> = I<$c>->rooms (I<$floor_name>)
469  
470 Retrieves the rooms on that given floor.
471  
472 =cut
473  
474 sub rooms {
475 0 ▶ my $self = shift;
Subroutine rooms: not called CC=5 SCAR=34.0
Pod documented
476 0 my $name = shift;
477  
478 0 my $s = $self->{socket};
479  
480 0 my @floors = $self->floors;
481 #warn "looking for $name rooms ". Dumper \@floors;
482 0 ▶ my ($floor) = grep { $_->{name} eq $name } @floors or croak "no floor '$name' known";
Branch: 1 branch
BranchTrueFalseTotal
my($floor) = grep({$_->{"name"} eq $name;} @floors) or croak("no floor '${name}' known") 0 0 0
483 #warn "found floor: ".Dumper $floor;
484  
485 0 print $s "LKRA ".$floor->{id}."\n";
486 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 1 or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 1 || croak($2) 0 0 0
Condition0%0/6
readline($s) =~ /(\d).. (.*)/ && ($1 == 1 || croak($2))
!ll&&!rl&&r
000
$1 == 1 or croak($2)
l!l&&r!l&&!r
000
MC/DC0%0/3
readline($s) =~ /(\d).. (.*)/ && ($1 == 1 || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 1 croak($2)
Truth table0%0/4
A && B or C
A= readline($s) =~ /(\d).. (.*)/B= $1 == 1C= croak($2)
ABCresult
0XX0
1000
11X1
1011
487 0 my @rooms;
488 0 ▶ while (($_ = <$s>) !~ /^000/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (($_ = readline $s) =~ /^000/) 0 0 0
489 #warn "processing $_";
490 0 my %room;
491 0 @room{ ('name', 'qr_flags', 'qr2_flags', 'floor', 'order', 'ua_flags', 'view', 'default', 'last_mod') } = split /\|/, $_;
492 0 push @rooms, \%room;
493 }
494 0 return @rooms;
495 #LKRA
496 #100 Known rooms:
497 #Calendar|16390|0|0|0|230|3|3|1191241353|
498 #Contacts|16390|0|0|0|230|2|2|1191241353|
499 #..
500 #ramsti|2|1|64|0|230|0|0|1191241691|
501 #000
502 }
503  
504 =pod
505  
506 =back
507  
508 =head3 Rooms
509  
510 =over
511  
512 =item I<assert_room>
513  
514 I<$c>->assert_room (I<$floor_name>, I<$room_name>, [ I<$room_attributes> ])
515  
516 Creates the room on the given floor. If the room already exists there, nothing
517 else happens. If the floor does not exist, it will complain.
518  
519 The optional room attributes are provided as hash with the following fields
520  
521 =over
522  
523 =item C<access> (default: C<PUBLIC>)
524  
525 One of the constants C<PUBLIC>, C<PRIVATE>, C<PRIVATE_PASSWORD>, C<PRIVATE_INVITATION> or
526 C<PERSONAL>.
527  
528 =item C<password> (default: empty)
529  
530 =item C<default_view> (default: empty)
531  
532 =back
533  
534 =cut
535  
536 sub assert_room {
537 0 ▶ my $self = shift;
Subroutine assert_room: not called CC=8 SCAR=42.8
Pod documented
538 0 my $fname = shift;
539 0 my @floors = $self->floors;
540 0 ▶ my ($floor) = grep { $_->{name} eq $fname } @floors or croak "no floor '$fname' known";
Branch: 1 branch
BranchTrueFalseTotal
my($floor) = grep({$_->{"name"} eq $fname;} @floors) or croak("no floor '${fname}' known") 0 0 0
541  
542 0 my $name = shift;
543 0 my $attrs = shift;
544 0 ▶ $attrs->{access} ||= $PUBLIC;
Condition0%0/3
$attrs->{"access"} ||= $Net::Citadel::PUBLIC
l!l&&r!l&&!r
000
MC/DC0%0/2
$attrs->{"access"} ||= $Net::Citadel::PUBLIC
$attrs->{"access"} $Net::Citadel::PUBLIC
Truth table0%0/3
A ||= B
A= $attrs->{"access"}B= $Net::Citadel::PUBLIC
ABresult
1X1
011
000
545 0 ▶ $attrs->{password} ||= '';
Condition0%0/2
$attrs->{"password"} ||= ""
l!l
00
MC/DC0%0/1
$attrs->{"password"} ||= ""
$attrs->{"password"}
Truth table0%0/2
A
A= $attrs->{"password"}
Aresult
11
00
546 0 ▶ $attrs->{default_view} ||= '';
Condition0%0/2
$attrs->{"default_view"} ||= ""
l!l
00
MC/DC0%0/1
$attrs->{"default_view"} ||= ""
$attrs->{"default_view"}
Truth table0%0/2
A
A= $attrs->{"default_view"}
Aresult
11
00
547  
548 0 my $s = $self->{socket};
549  
550 print $s "CRE8 1|$name|".
551 $attrs->{access}.'|'.
552 $attrs->{password}.'|'.
553 $floor->{id}.'|'.
554 '|'. # no idea what this is
555 0 $attrs->{default_view}.'|'.
556 "\n";
557 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 2 or $2 =~ /already exists/ or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 2 || $2 =~ /already exists/ || croak($2) 0 0 0
Condition0%0/9
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || $2 =~ /already exists/ || croak($2))
!ll&&!rl&&r
000
$1 == 2 or $2 =~ /already exists/ or croak($2)
l!l&&r!l&&!r
000
$1 == 2 or $2 =~ /already exists/
l!l&&r!l&&!r
000
MC/DC0%0/4
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || $2 =~ /already exists/ || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 2 $2 =~ /already exists/ croak($2)
Truth table0%0/5
A && B or C or D
A= readline($s) =~ /(\d).. (.*)/B= $1 == 2C= $2 =~ /already exists/D= croak($2)
ABCDresult
0XXX0
10000
11XX1
101X1
10011
558  
559 0 return 1;
560 }
561  
562 #CRE8 1|Bumsti|0||0|||
563 #200 'Bumsti' has been created.
564  
565 =pod
566  
567 =item I<retract_room>
568  
569 I<$c>->retract_room (I<$floor_name>, I<$room_name>)
570  
571 B<NOTE>: Not implemented yet.
572  
573 =cut
574  
575 sub retract_room {
576 0 ▶ my $self = shift;
Subroutine retract_room: not called CC=5 SCAR=34.0
Pod documented
577 0 my $name = shift;
578 0 my $s = $self->{socket};
579 0 print $s "GOTO $name\n";
580 #GOTO Bumsti
581 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 2 or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 2 || croak($2) 0 0 0
Condition0%0/6
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
!ll&&!rl&&r
000
$1 == 2 or croak($2)
l!l&&r!l&&!r
000
MC/DC0%0/3
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 2 croak($2)
Truth table0%0/4
A && B or C
A= readline($s) =~ /(\d).. (.*)/B= $1 == 2C= croak($2)
ABCresult
0XX0
1000
11X1
1011
582 #200 Lobby|0|0|0|2|0|0|0|1|0|0|0|0|0|0|
583 0 print $s "KILL 1\n";
584 #KILL 1
585 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 2 or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 2 || croak($2) 0 0 0
Condition0%0/6
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
!ll&&!rl&&r
000
$1 == 2 or croak($2)
l!l&&r!l&&!r
000
MC/DC0%0/3
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 2 croak($2)
Truth table0%0/4
A && B or C
A= readline($s) =~ /(\d).. (.*)/B= $1 == 2C= croak($2)
ABCresult
0XX0
1000
11X1
1011
586 #200 'Bumsti' deleted.
587 0 return 1;
588 }
589  
590 =pod
591  
592 =back
593  
594 =head3 Users
595  
596 =over
597  
598 =item I<create_user>
599  
600 I<$c>->create_user (I<$username>, I<$password>)
601  
602 Tries to create a user with name and password. Fails if this user already exists (or some other
603 reason).
604  
605 =cut
606  
607 sub create_user {
608 0 ▶ my $self = shift;
Subroutine create_user: not called CC=3 SCAR=24.8
Pod documented
609 0 my $name = shift;
610 0 my $pwd = shift;
611 0 my $s = $self->{socket};
612 0 print $s "CREU $name|$pwd\n";
613 #CREU TestUser|xxx
614 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 2 or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 2 || croak($2) 0 0 0
Condition0%0/6
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
!ll&&!rl&&r
000
$1 == 2 or croak($2)
l!l&&r!l&&!r
000
MC/DC0%0/3
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 2 croak($2)
Truth table0%0/4
A && B or C
A= readline($s) =~ /(\d).. (.*)/B= $1 == 2C= croak($2)
ABCresult
0XX0
1000
11X1
1011
615 #200 User 'TestUser' created and password set.
616 0 return 1;
617 }
618  
619 =pod
620  
621 =item I<change_user>
622  
623 I<$c>->change_user (I<$user_name>, I<$aspect> => I<$value>)
624  
625 Changes certain aspects of a user. Currently understood aspects are
626  
627 =over
628  
629 =item C<password> (string)
630  
631 =item C<access_level> (0..6, constants available)
632  
633 =back
634  
635 =cut
636  
637 sub change_user {
638 0 ▶ my $self = shift;
Subroutine change_user: not called CC=7 SCAR=40.3
Pod documented
639 0 my $name = shift;
640 0 my %changes = @_;
641 0 my $s = $self->{socket};
642  
643 0 print $s "AGUP $name\n";
644 #AGUP TestUser
645 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 2 or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 2 || croak($2) 0 0 0
Condition0%0/6
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
!ll&&!rl&&r
000
$1 == 2 or croak($2)
l!l&&r!l&&!r
000
MC/DC0%0/3
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 2 croak($2)
Truth table0%0/4
A && B or C
A= readline($s) =~ /(\d).. (.*)/B= $1 == 2C= croak($2)
ABCresult
0XX0
1000
11X1
1011
646 #200 TestUser|ggg|10768|1|0|4|4|1191255938|0
647 0 my %user;
648 0 my @attrs = ('name', 'password', 'flags', 'times_called', 'messages_posted', 'access_level', 'user_number', 'timestamp', 'purge_time');
649 0 @user{ @attrs } = split /\|/, $2;
650  
651 0 ▶ $user{password} = $changes{password} if $changes{password};
Branch: 1 branch
BranchTrueFalseTotal
if $changes{"password"} 0 0 0
652 0 ▶ $user{access_level} = $changes{access_level} if $changes{access_level};
Branch: 1 branch
BranchTrueFalseTotal
if $changes{"access_level"} 0 0 0
653  
654 0 print $s "ASUP ".(join "|", @user{ @attrs })."\n";
655 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 2 or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 2 || croak($2) 0 0 0
Condition0%0/6
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
!ll&&!rl&&r
000
$1 == 2 or croak($2)
l!l&&r!l&&!r
000
MC/DC0%0/3
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 2 croak($2)
Truth table0%0/4
A && B or C
A= readline($s) =~ /(\d).. (.*)/B= $1 == 2C= croak($2)
ABCresult
0XX0
1000
11X1
1011
656  
657 0 return 1;
658 }
659  
660 =pod
661  
662 =item I<remove_user>
663  
664 I<$c>->remove_user (I<$name>)
665  
666 Removes the user (actually sets level to C<DELETED_USER>).
667  
668 =cut
669  
670 sub remove_user {
671 0 ▶ my $self = shift;
Subroutine remove_user: not called CC=5 SCAR=34.0
Pod documented
672 0 my $name = shift;
673  
674 0 my $s = $self->{socket};
675  
676 0 print $s "AGUP $name\n";
677 #AGUP TestUser
678 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 2 or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 2 || croak($2) 0 0 0
Condition0%0/6
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
!ll&&!rl&&r
000
$1 == 2 or croak($2)
l!l&&r!l&&!r
000
MC/DC0%0/3
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 2 croak($2)
Truth table0%0/4
A && B or C
A= readline($s) =~ /(\d).. (.*)/B= $1 == 2C= croak($2)
ABCresult
0XX0
1000
11X1
1011
679 #200 TestUser|ggg|10768|1|0|4|4|1191255938|0
680 0 my %user;
681 0 my @attrs = ('name', 'password', 'flags', 'times_called', 'messages_posted', 'access_level', 'user_number', 'timestamp', 'purge_time');
682 0 @user{ @attrs } = split /\|/, $2;
683  
684 0 $user{access_level} = $DELETED_USER;
685  
686 0 print $s "ASUP ".(join "|", @user{ @attrs })."\n";
687 0 ▶ <$s> =~ /(\d).. (.*)/ and ($1 == 2 or croak $2);
Branch: 1 branch
BranchTrueFalseTotal
readline($s) =~ /(\d).. (.*)/ and $1 == 2 || croak($2) 0 0 0
Condition0%0/6
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
!ll&&!rl&&r
000
$1 == 2 or croak($2)
l!l&&r!l&&!r
000
MC/DC0%0/3
readline($s) =~ /(\d).. (.*)/ && ($1 == 2 || croak($2))
readline($s) =~ /(\d).. (.*)/ $1 == 2 croak($2)
Truth table0%0/4
A && B or C
A= readline($s) =~ /(\d).. (.*)/B= $1 == 2C= croak($2)
ABCresult
0XX0
1000
11X1
1011
688  
689 0 return 1;
690 }
691  
692 =pod
693  
694 =back
695  
696 =head3 Miscellaneous
697  
698 =over
699  
700 =item I<citadel_echo>
701  
702 I<$c>->citadel_echo (I<$string>)
703  
704 Tests a connection to the Citadel server by sending a message string to it and
705 then checking to see if that same string is echoed back.
706  
707 =cut
708  
709 sub citadel_echo {
710 0 ▶ my $self = shift;
Subroutine citadel_echo: not called CC=2 SCAR=17.9
Pod documented
711 0 my $msg = shift;
712 0 my $s = $self->{socket};
713  
714 0 print $s "ECHO $msg\n";
715 0 ▶ croak "message not echoed ($msg)" unless <$s> =~ /2.. $msg/;
Branch: 1 branch
BranchTrueFalseTotal
unless readline($s) =~ /2.. $msg/ 0 0 0
716  
717 0 return 1;
718 }
719  
720 =item I<citadel_info>
721  
722 $info_aref = I<$c>->citadel_info()
723  
724 Sends the C<INFO> command to the Citadel server and returns the lines it receives
725 from that as a reference to an array. An example of getting and then displaying the
726 server information lines the following:
727  
728 my $c = new Net::Citadel (host => $host_name);
729 my $info_aref = $c->citadel_info;
730 foreach $line (@{$info_aref}) {
731 print $line;
732 }
733  
734 For more details about the server information lines that are returned, see the
735 C<INFO> entry at L<http://www.citadel.org/doku.php/documentation:appproto:connection>.
736  
737 =cut
738  
739 sub citadel_info {
740 0 ▶ my $self = shift;
Subroutine citadel_info: not called CC=4 SCAR=30.0
Pod documented
741 0 my $s = $self->{socket};
742 0 my ( @info, $line );
743  
744 0 print $s "INFO\n";
745  
746 0 ▶ if ((<$s>) !~ /1../) { croak "Incorrect response from Citadel INFO command." };
Branch: 1 branch
BranchTrueFalseTotal
unless (readline($s) =~ /1../) 0 0 0
747  
748 0 ▶ while ($line = <$s>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $s)) 0 0 0
749 0 ▶ if ( $line !~ /^000/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $line =~ /^000/) { } 0 0 0
750 0 push @info, $line;
751 }
752 0 else { last; }
753 }
754  
755 0 return \@info;
756 }
757  
758 =item I<citadel_mrtg>
759  
760 %mrtg_hash = I<$c>->citadel_mrtg($type)
761  
762 Sends the C<MRTG> command to the Citadel server. It expects a type of either
763 C<users> or C<messages> to be passed to it and returns a hash containing the
764 information from the server.
765  
766 =over 4
767  
768 =item ActiveUsers
769 Number of active users on the system. Only returned for type C<users>.
770  
771 =item ConnectedUsers
772  
773 Number of connected users on the system. Only returned for type C<users>.
774  
775 =item HighMsg
776  
777 Higest message number on the system. Only returned for type C<messages>.
778  
779 =item SystemUptime
780  
781 The uptime for the system formatted as days, hours, minutes.
782  
783 =item SystemName
784  
785 Human readable name of the Citadel system.
786  
787 =back
788  
789 =cut
790  
791 sub citadel_mrtg {
792 0 ▶ my $self = shift;
Subroutine citadel_mrtg: not called CC=5 SCAR=34.0
Pod documented
793 0 my $type = shift;
794 0 my $s = $self->{socket};
795 0 my ( %mrtg, @mrtg_lines, $line );
796  
797 0 print $s "MRTG $type\n";
798  
799 0 ▶ if ((<$s>) !~ /1../) { croak "Incorrect response from Citadel MRTG command." };
Branch: 1 branch
BranchTrueFalseTotal
unless (readline($s) =~ /1../) 0 0 0
800  
801 # Get the listing of the MRTG information from the server.
802 0 ▶ while ($line = <$s>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $s)) 0 0 0
803 0 ▶ if ( $line !~ /^000/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $line =~ /^000/) { } 0 0 0
804 0 push @mrtg_lines, $line;
805 }
806 0 else { last; }
807 }
808  
809 # Create the %mrtg hash from the information in the @mrtg_lines array
810 0 ▶ if ( lc($type) eq q{users} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $type eq 'users') { } 0 0 0
811 0 $mrtg{'ConnectedUsers'} = $mrtg_lines[0];
812 0 $mrtg{'ActiveUsers'} = $mrtg_lines[1];
813 } else {
814 0 $mrtg{'HighMsg'} = $mrtg_lines[0];
815 }
816 0 $mrtg{'SystemUptime'} = $mrtg_lines[2];
817 0 $mrtg{'SystemName'} = $mrtg_lines[3];
818  
819 # Return the MRTG information as the mrtg hash.
820 0 return %mrtg;
821 }
822  
823 =pod
824  
825 =item I<citadel_time>
826  
827 I<$t> = I<$c>->citadel_time
828  
829 Gets the current system time and time zone offset from UTC in UNIX timestamp format from the Citadel server.
830  
831 C<TODO>: Rewrite function to return the unpacked parameters as a hash upon success.
832  
833 =cut
834  
835 sub citadel_time {
836 0 ▶ my $self = shift;
Subroutine citadel_time: not called CC=2 SCAR=17.9
Pod documented
837 0 my $s = $self->{socket};
838 0 print $s "TIME\n";
839 0 ▶ croak "protocol: citadel_time failed" unless <$s> =~ /2.. (.*)\|(.*)\|(.*)/; # not sure what the others are
Branch: 1 branch
BranchTrueFalseTotal
unless readline($s) =~ /2.. (.*)\|(.*)\|(.*)/ 0 0 0
840 0 return $1;
841 }
842  
843 =pod
844  
845 =back
846  
847 =head1 TODOs
848  
849 - Decent GUI using Mason + AJAX
850  
851 =head1 SEE ALSO
852  
853 L<http://www.citadel.org/doku.php?id=documentation:appproto:app_proto>
854  
855 =head1 AUTHORS
856  
857 Robert Barta, E<lt>drrho@cpan.orgE<gt>
858 Robert James Clay, E<lt>jame@rocasa.usE<gt>
859  
860 =head1 COPYRIGHT AND LICENSE
861  
862 Copyright (C) 2007-2008 by Robert Barta
863 Copyright (C) 2012-2017 by Robert James Clay
864  
865 This library is free software; you can redistribute it and/or modify
866 it under the same terms as Perl itself, either Perl version 5.8.8 or,
867 at your option, any later version of Perl 5 you may have available.
868  
869  
870 =cut
871  
872  
873 1 1;
874  
875 __END__
↑ Summary