JAM.pm

filter: Statementstmt 22.3% 139 / 623 Branchbran 11.7% 41 / 350 Conditioncond 18.1% 6 / 33 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 60.8% 14 / 23 Podpod 100% 18 / 18 totaltotal 20.5% 218 / 1063 CC 187 SCAR 66.4
CC
187
Cov
18%
AddMessage
2352.0
ChangeMessage
1122.0
ReadMessage
306.0
CRAP 768.6
↑ Summary JAM/Attr.pm »
1 # FTN::JAM
2  
3 package FTN::JAM;
4  
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Time::Zone;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 FTN::JAM - A Perl extension for handleing JAM messagebases.
15  
16 =head1 VERSION
17  
18 Version 0.30
19  
20 =cut
21  
22 3 our $VERSION = '0.30';
23  
24 =head1 SYNOPSIS
25  
26 This module can be used for operations related to JAM messagebases, including the following:
27 creating or removing a messagebase, listing the contents of a messagebase, adding a
28 message to a messagebase, reading a message in a messagebase, changing a message in a
29 messagebase, or finding a user in a messagebase.
30  
31 Here is an example of how it can being used:
32  
33 use FTN::JAM;
34  
35 my $mb = $ARGV[0];
36 my $basemsgnum = $ARGV[1];
37  
38 my $handle = FTN::JAM::CreateMB($mb,$basemsgnum);
39  
40 FTN::JAM::CloseMB($handle);
41 ...
42  
43  
44 =head1 EXPORT
45  
46 The following functions are available in the module: OpenMB, CreateMB, CloseMB,
47 RemoveMB, LockMB, UnlockMB, ReadMBHeader, WriteMBHeader, GetMBSize, ReadMessage,
48 ChangeMessage, AddMessage, Crc32, FindUser, GetLastRead, SetLastRead, TimeToLocal,
49 and LocalToTime.
50  
51 The global variable $Errnum is used for returning error numbers from functions
52 and can be accessed as $FTN::JAM::Errnum. It defaults to undefined.
53  
54 =cut
55  
56 3 our $Errnum;
57  
58 =head1 FUNCTIONS
59  
60 =head2 OpenMB
61  
62 Syntax: $handle = FTN::JAM::OpenMB($jampath)
63  
64 =cut
65  
66 0 ▶sub OpenMB {
Subroutine OpenMB: not called CC=10 SCAR=47.0
Pod documented
67  
68 0 ▶ my ($jampath) = @_ or croak 'OpenMB requires a base file name and path as a parameter.';
Branch: 1 branch
BranchTrueFalseTotal
my($jampath) = or croak("OpenMB requires a base file name and path as a parameter.") 0 0 0
69  
70 0 my ($JHR, $JDX, $JDT, $JLR);
71  
72 0 my $jhrres = open( $JHR, q{+<}, $jampath . ".jhr" );
73 0 my $jdxres = open( $JDX, q{+<}, $jampath . ".jdx" );
74 0 my $jdtres = open( $JDT, q{+<}, $jampath . ".jdt" );
75 0 my $jlrres = open( $JLR, q{+<}, $jampath . ".jlr" );
76  
77 0 ▶ if ( !$jhrres || !$jdxres || !$jdtres || !$jlrres ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($jhrres and $jdxres and $jdtres and $jlrres) 0 0 0
Condition0%0/9
$jhrres and $jdxres and $jdtres and $jlrres
!ll&&!rl&&r
000
$jhrres and $jdxres and $jdtres
!ll&&!rl&&r
000
$jhrres and $jdxres
!ll&&!rl&&r
000
MC/DC0%0/4
$jhrres and $jdxres and $jdtres and $jlrres
$jhrres $jdxres $jdtres $jlrres
Truth table0%0/5
A and B and C and D
A= $jhrresB= $jdxresC= $jdtresD= $jlrres
ABCDresult
0XXX0
10XX0
110X0
11100
11111
78 0 ▶ if ($jhrres) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jhrres) 0 0 0
79 0 close($JHR);
80 }
81 0 ▶ if ($jdxres) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jdxres) 0 0 0
82 0 close($JDX);
83 }
84 0 ▶ if ($jdtres) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jdtres) 0 0 0
85 0 close($JDT);
86 }
87 0 ▶ if ($jlrres) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jlrres) 0 0 0
88 0 close($JLR);
89 }
90  
91 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
92 0 return;
93 }
94  
95 0 binmode($JHR);
96 0 binmode($JDX);
97 0 binmode($JDT);
98 0 binmode($JLR);
99  
100 0 my $old;
101  
102 0 $old = select($JHR);
103 0 local $| = 1;
104 0 select($old);
105 0 $old = select($JDX);
106 0 local $| = 1;
107 0 select($old);
108 0 $old = select($JDT);
109 0 local $| = 1;
110 0 select($old);
111 0 $old = select($JLR);
112 0 local $| = 1;
113 0 select($old);
114  
115 0 my %filehash;
116  
117 0 $filehash{jhr} = *$JHR;
118 0 $filehash{jdx} = *$JDX;
119 0 $filehash{jdt} = *$JDT;
120 0 $filehash{jlr} = *$JLR;
121  
122 0 return \%filehash;
123 }
124  
125 =head2 CreateMB
126  
127 Syntax: $handle = FTN::JAM::CreateMB($jampath,$basemsg)
128  
129 =cut
130  
131 1 ▶sub CreateMB {
Subroutine CreateMB: called CC=16 SCAR=36.0
Pod documented
132 1 ▶ if ( $#_ != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != 1) 0 1 1
133 0 croak "Wrong number of arguments for FTN::JAM::CreateMB";
134 }
135  
136 1 my $jampath = $_[0];
137 1 my $basemsg = $_[1];
138  
139 1 my $hasjdx = ( -e $jampath . ".jdx" );
140 1 my $hasjhr = ( -e $jampath . ".jhr" );
141 1 my $hasjdt = ( -e $jampath . ".jdt" );
142 1 my $hasjlr = ( -e $jampath . ".jlr" );
143  
144 1 ▶ if ( $hasjdx or $hasjhr or $hasjdt or $hasjlr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hasjdx or $hasjhr or $hasjdt or $hasjlr) 0 1 1
Condition33%3/9
$hasjdx or $hasjhr or $hasjdt or $hasjlr
l!l&&r!l&&!r
001
$hasjdx or $hasjhr or $hasjdt
l!l&&r!l&&!r
001
$hasjdx or $hasjhr
l!l&&r!l&&!r
001
MC/DC0%0/4
$hasjdx or $hasjhr or $hasjdt or $hasjlr
$hasjdx $hasjhr $hasjdt $hasjlr
Truth table20%1/5
A or B or C or D
A= $hasjdxB= $hasjhrC= $hasjdtD= $hasjlr
ABCDresult
1XXX1
01XX1
001X1
00011
00000
145 0 $Errnum = $FTN::JAM::Errnum::BASE_EXISTS;
146 0 return;
147 }
148  
149 1 my ($JHR, $JDX, $JDT, $JLR);
150  
151 1 my $jhrres = open( $JHR, q{+>}, $jampath . ".jhr" );
152 1 my $jdxres = open( $JDX, q{+>}, $jampath . ".jdx" );
153 1 my $jdtres = open( $JDT, q{+>}, $jampath . ".jdt" );
154 1 my $jlrres = open( $JLR, q{+>}, $jampath . ".jlr" );
155  
156 1 ▶ if ( !$jhrres || !$jdxres || !$jdtres || !$jlrres ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($jhrres and $jdxres and $jdtres and $jlrres) 0 1 1
Condition33%3/9
$jhrres and $jdxres and $jdtres and $jlrres
!ll&&!rl&&r
001
$jhrres and $jdxres and $jdtres
!ll&&!rl&&r
001
$jhrres and $jdxres
!ll&&!rl&&r
001
MC/DC0%0/4
$jhrres and $jdxres and $jdtres and $jlrres
$jhrres $jdxres $jdtres $jlrres
Truth table20%1/5
A and B and C and D
A= $jhrresB= $jdxresC= $jdtresD= $jlrres
ABCDresult
0XXX0
10XX0
110X0
11100
11111
157 0 ▶ if ($jhrres) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jhrres) 0 0 0
158 0 close($JHR);
159 }
160 0 ▶ if ($jdxres) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jdxres) 0 0 0
161 0 close($JDX);
162 }
163 0 ▶ if ($jdtres) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jdtres) 0 0 0
164 0 close($JDT);
165 }
166 0 ▶ if ($jlrres) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jlrres) 0 0 0
167 0 close($JLR);
168 }
169  
170 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
171 0 return;
172 }
173  
174 1 binmode($JHR);
175 1 binmode($JDX);
176 1 binmode($JDT);
177 1 binmode($JLR);
178  
179 1 my $old;
180  
181 1 $old = select($JHR);
182 1 local $| = 1;
183 1 select($old);
184 1 $old = select($JDX);
185 1 local $| = 1;
186 1 select($old);
187 1 $old = select($JDT);
188 1 local $| = 1;
189 1 select($old);
190 1 $old = select($JLR);
191 1 local $| = 1;
192 1 select($old);
193  
194 1 my %filehash;
195  
196 1 $filehash{jhr} = *$JHR;
197 1 $filehash{jdx} = *$JDX;
198 1 $filehash{jdt} = *$JDT;
199 1 $filehash{jlr} = *$JLR;
200  
201 1 my %header;
202  
203 1 $header{DateCreated} = TimeToLocal(time);
204 1 $header{PasswordCRC} = 0xffffffff;
205 1 $header{BaseMsgNum} = $basemsg;
206  
207 1 ▶ if ( !LockMB( \%filehash, 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (LockMB(\%filehash, 0)) 0 1 1
208 0 CloseMB( \%filehash );
209 0 return;
210 }
211  
212 1 ▶ if ( !WriteMBHeader( \%filehash, \%header ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (WriteMBHeader(\%filehash, \%header)) 0 1 1
213 0 CloseMB( \%filehash );
214 0 return;
215 }
216  
217 1 UnlockMB( \%filehash );
218  
219 1 return \%filehash;
220 }
221  
222 =head2 CloseMB
223  
224 Syntax: FTN::JAM::CloseMB($handle)
225  
226 =cut
227  
228 1 ▶sub CloseMB {
Subroutine CloseMB: called CC=6 SCAR=19.6
Pod documented
229  
230 1 ▶ my ($handleref) = @_ or croak 'CloseMB requires a hash reference parameter.';
Branch: 1 branch
BranchTrueFalseTotal
my($handleref) = or croak("CloseMB requires a hash reference parameter.") 1 0 1
231  
232 1 ▶ close( $$handleref{jdx} ) or croak "Unable to close: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $handleref->{"jdx"} or croak("Unable to close: $!") 1 0 1
233 1 ▶ close( $$handleref{jhr} ) or croak "Unable to close: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $handleref->{"jhr"} or croak("Unable to close: $!") 1 0 1
234 1 ▶ close( $$handleref{jdt} ) or croak "Unable to close: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $handleref->{"jdt"} or croak("Unable to close: $!") 1 0 1
235 1 ▶ close( $$handleref{jlr} ) or croak "Unable to close: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $handleref->{"jlr"} or croak("Unable to close: $!") 1 0 1
236  
237 1 return 1;
238 }
239  
240 =head2 RemoveMB
241  
242 Syntax: FTN::JAM::RemoveMB($jampath)
243  
244 =cut
245  
246 1 ▶sub RemoveMB {
Subroutine RemoveMB: called CC=10 SCAR=28.7
Pod documented
247  
248 1 ▶ my ($jampath) = @_ or croak 'RemoveMB requires a base file name and path as a parameter.';
Branch: 1 branch
BranchTrueFalseTotal
my($jampath) = or croak("RemoveMB requires a base file name and path as a parameter.") 1 0 1
249  
250 1 my $hasjdx = ( -e $jampath . ".jdx" );
251 1 my $hasjhr = ( -e $jampath . ".jhr" );
252 1 my $hasjdt = ( -e $jampath . ".jdt" );
253 1 my $hasjlr = ( -e $jampath . ".jlr" );
254  
255 1 ▶ if ($hasjdx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hasjdx) 1 0 1
256 1 ▶ if ( !unlink( $jampath . ".jdx" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (unlink $jampath . '.jdx') 0 1 1
257 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
258 0 return;
259 }
260 }
261  
262 1 ▶ if ($hasjhr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hasjhr) 1 0 1
263 1 ▶ if ( !unlink( $jampath . ".jhr" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (unlink $jampath . '.jhr') 0 1 1
264 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
265 0 return;
266 }
267 }
268  
269 1 ▶ if ($hasjdt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hasjdt) 1 0 1
270 1 ▶ if ( !unlink( $jampath . ".jdt" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (unlink $jampath . '.jdt') 0 1 1
271 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
272 0 return;
273 }
274 }
275  
276 1 ▶ if ($hasjlr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hasjlr) 1 0 1
277 1 ▶ if ( !unlink( $jampath . ".jlr" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (unlink $jampath . '.jlr') 0 1 1
278 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
279 0 return;
280 }
281 }
282  
283 1 return 1;
284 }
285  
286 =head2 LockMB
287  
288 Syntax: $success = FTN::JAM::LockMB($handle,$timeout)
289  
290 =cut
291  
292 1 ▶sub LockMB {
Subroutine LockMB: called CC=6 SCAR=26.7
Pod documented
293 1 ▶ if ( $#_ != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != 1) 0 1 1
294 0 croak "Wrong number of arguments for FTN::JAM::LockMB";
295 }
296  
297 1 my $handleref = $_[0];
298 1 my $timeout = $_[1];
299  
300 1 ▶ if ( $$handleref{locked} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handleref->{"locked"}) 0 1 1
301 0 return 1;
302 }
303  
304 1 ▶ if ( flock( $$handleref{jhr}, 6 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (flock $handleref->{"jhr"}, 6) 1 0 1
305 1 $$handleref{locked} = 1;
306 1 return 1;
307 }
308  
309 0 ▶ for ( my $i = 0 ; $i < $timeout ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $timeout) 0 0 0
310 0 sleep(1);
311  
312 0 ▶ if ( flock( $$handleref{jhr}, 6 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (flock $handleref->{"jhr"}, 6) 0 0 0
313 0 $$handleref{locked} = 1;
314 0 return 1;
315 }
316 }
317  
318 0 $Errnum = $FTN::JAM::Errnum::BASE_NOT_LOCKED;
319 0 return;
320 }
321  
322 =head2 UnlockMB
323  
324 Syntax: FTN::JAM::UnlockMB($handle)
325  
326 =cut
327  
328 1 ▶sub UnlockMB {
Subroutine UnlockMB: called CC=3 SCAR=11.3
Pod documented
329  
330 1 ▶ my ($handleref) = @_ or croak 'UnlockMB requires a reference to a file hash as a parameter.';
Branch: 1 branch
BranchTrueFalseTotal
my($handleref) = or croak("UnlockMB requires a reference to a file hash as a parameter.") 1 0 1
331  
332 1 ▶ if ( $$handleref{locked} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handleref->{"locked"}) 1 0 1
333 1 flock( $$handleref{jhr}, 8 );
334 1 delete $$handleref{locked};
335 }
336 1 return 1;
337 }
338  
339 =head2 ReadMBHeader
340  
341 Syntax: $success = FTN::JAM::ReadMBHeader($handle,\%header)
342  
343 =cut
344  
345 1 ▶sub ReadMBHeader {
Subroutine ReadMBHeader: called CC=5 SCAR=18.1
Pod documented
346 1 ▶ if ( $#_ != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != 1) 0 1 1
347 0 croak "Wrong number of arguments for FTN::JAM::ReadMBHeader";
348 }
349  
350 1 my $handleref = $_[0];
351 1 my $headerref = $_[1];
352  
353 1 my $buf;
354 my @data;
355  
356 1 ▶ if ( !seek( $$handleref{jhr}, 0, 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jhr"}, 0, 0) 0 1 1
357 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
358 0 return;
359 }
360  
361 1 ▶ if ( read( $$handleref{jhr}, $buf, 1024 ) != 1024 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($handleref->{"jhr"}, $buf, 1024) != 1024) 0 1 1
362 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
363 0 return;
364 }
365  
366 1 @data = unpack( "Z[4]LLLLL", $buf );
367  
368 1 ▶ if ( $data[0] ne "JAM" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data[0] ne "JAM") 0 1 1
369 0 $Errnum = $FTN::JAM::Errnum::BASEHEADER_CORRUPT;
370 0 return;
371 }
372  
373 1 %$headerref = ();
374  
375 1 $$headerref{Signature} = $data[0];
376 1 $$headerref{DateCreated} = $data[1];
377 1 $$headerref{ModCounter} = $data[2];
378 1 $$headerref{ActiveMsgs} = $data[3];
379 1 $$headerref{PasswordCRC} = $data[4];
380 1 $$headerref{BaseMsgNum} = $data[5];
381  
382 1 return 1;
383 }
384  
385 =head2 WriteMBHeader
386  
387 Syntax: $success = FTN::JAM::WriteMBHeader($handle,\%header)
388  
389 =cut
390  
391 1 ▶sub WriteMBHeader {
Subroutine WriteMBHeader: called CC=10 SCAR=28.4
Pod documented
392 1 ▶ if ( $#_ != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != 1) 0 1 1
393 0 croak "Wrong number of arguments for FTN::JAM::WriteMBHeader";
394 }
395  
396 1 my $handleref = $_[0];
397 1 my $headerref = $_[1];
398  
399 1 ▶ if ( !defined( $$headerref{DateCreated} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"DateCreated"}) 0 1 1
400 0 $$headerref{DateCreated} = 0;
401 }
402 1 ▶ if ( !defined( $$headerref{ModCounter} ) ) { $$headerref{ModCounter} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"ModCounter"}) 1 0 1
403 1 ▶ if ( !defined( $$headerref{ActiveMsgs} ) ) { $$headerref{ActiveMsgs} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"ActiveMsgs"}) 1 0 1
404 1 ▶ if ( !defined( $$headerref{PasswordCRC} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"PasswordCRC"}) 0 1 1
405 0 $$headerref{PasswordCRC} = 0;
406 }
407 0 ▶ if ( !defined( $$headerref{BaseMsgNum} ) ) { $$headerref{BaseMsgNum} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"BaseMsgNum"}) 0 1 1
408  
409 1 ▶ if ( !$$handleref{locked} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($handleref->{"locked"}) 0 1 1
410 0 $Errnum = $FTN::JAM::Errnum::BASE_NOT_LOCKED;
411 0 return;
412 }
413  
414 1 $$headerref{Signature} = "JAM";
415 1 $$headerref{ModCounter}++;
416  
417 1 ▶ if ( !seek( $$handleref{jhr}, 0, 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jhr"}, 0, 0) 0 1 1
418 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
419 0 return;
420 }
421  
422 1 my $printres = print { $$handleref{jhr} } pack(
423 "Z[4]LLLLLx[1000]",
424 $$headerref{Signature}, $$headerref{DateCreated},
425 $$headerref{ModCounter}, $$headerref{ActiveMsgs},
426 $$headerref{PasswordCRC}, $$headerref{BaseMsgNum}
427 1 );
428  
429 1 ▶ if ( !$printres ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($printres) 0 1 1
430 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
431 0 return;
432 }
433  
434 1 return 1;
435 }
436  
437 =head2 GetMBSize
438  
439 Syntax: $success = FTN::JAM::GetMBSize($handle,\$num)
440  
441 =cut
442  
443 1 ▶sub GetMBSize {
Subroutine GetMBSize: called CC=4 SCAR=16.1
Pod documented
444 1 ▶ if ( $#_ != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != 1) 0 1 1
445 0 croak "Wrong number of arguments for FTN::JAM::GetMBSize";
446 }
447  
448 1 my $handleref = $_[0];
449 1 my $numref = $_[1];
450  
451 1 my $buf;
452 my @data;
453  
454 1 ▶ if ( !seek( $$handleref{jdx}, 0, 2 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jdx"}, 0, 2) 0 1 1
455 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
456 0 return;
457 }
458  
459 1 my $offset = tell( $$handleref{jdx} );
460  
461 1 ▶ if ( $offset == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset == -1) 0 1 1
462 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
463 0 return;
464 }
465  
466 1 $$numref = $offset / 8;
467  
468 1 return 1;
469 }
470  
471 =head2 ReadMessage
472  
473 Syntax: $success = FTN::JAM::ReadMessage($handle,$msgnum,\%header,\@subfields,\$text)
474  
475 =cut
476  
477 0 ▶sub ReadMessage {
Subroutine ReadMessage: not called CC=17 SCAR=57.2
Pod documented
478 0 ▶ if ( $#_ != 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != 4) 0 0 0
479 0 croak "Wrong number of arguments for FTN::JAM::ReadMessage";
480 }
481  
482 0 my $handleref = $_[0];
483 0 my $msgnum = $_[1];
484 0 my $headerref = $_[2];
485 0 my $subfieldsref = $_[3];
486 0 my $textref = $_[4];
487  
488 0 my $buf;
489 my @data;
490 0 my %mbheader;
491  
492 0 ▶ if ( !ReadMBHeader( $handleref, \%mbheader ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ReadMBHeader($handleref, \%mbheader)) 0 0 0
493 0 return;
494 }
495  
496 0 ▶ if ( !seek( $$handleref{jdx}, ( $msgnum - $mbheader{BaseMsgNum} ) * 8, 0 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jdx"}, ($msgnum - $mbheader{"BaseMsgNum"}) * 8, 0) 0 0 0
497 {
498 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
499 0 return;
500 }
501  
502 0 ▶ if ( read( $$handleref{jdx}, $buf, 8 ) != 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($handleref->{"jdx"}, $buf, 8) != 8) 0 0 0
503 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
504 0 return;
505 }
506  
507 0 @data = unpack( "LL", $buf );
508  
509 0 ▶ if ( $data[0] == 0xffffffff and $data[1] == 0xffffffff ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data[0] == 4294967295 and $data[1] == 4294967295) 0 0 0
Condition0%0/3
$data[0] == 4294967295 and $data[1] == 4294967295
!ll&&!rl&&r
000
MC/DC0%0/2
$data[0] == 4294967295 and $data[1] == 4294967295
$data[0] == 4294967295 $data[1] == 4294967295
Truth table0%0/3
A and B
A= $data[0] == 4294967295B= $data[1] == 4294967295
ABresult
0X0
100
111
510 0 $Errnum = $FTN::JAM::Errnum::MSG_DELETED;
511 0 return;
512 }
513  
514 0 ▶ if ( !seek( $$handleref{jhr}, $data[1], 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jhr"}, $data[1], 0) 0 0 0
515 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
516 0 return;
517 }
518  
519 0 ▶ if ( read( $$handleref{jhr}, $buf, 76 ) != 76 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($handleref->{"jhr"}, $buf, 76) != 76) 0 0 0
520 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
521 0 return;
522 }
523  
524 0 @data = unpack( "Z[4]SSLLLLLLLLLLLLLLLLL", $buf );
525  
526 0 ▶ if ( $data[0] ne "JAM" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data[0] ne "JAM") 0 0 0
527 0 $Errnum = $FTN::JAM::Errnum::MSGHEADER_CORRUPT;
528 0 return;
529 }
530  
531 0 ▶ if ( $data[1] != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data[1] != 1) 0 0 0
532 0 $Errnum = $FTN::JAM::Errnum::MSGHEADER_UNKNOWN;
533 0 return;
534 }
535  
536 0 %$headerref = ();
537  
538 0 $$headerref{Signature} = $data[0];
539 0 $$headerref{Revision} = $data[1];
540 0 $$headerref{ReservedWord} = $data[2];
541 0 $$headerref{SubfieldLen} = $data[3];
542 0 $$headerref{TimesRead} = $data[4];
543 0 $$headerref{MsgIdCRC} = $data[5];
544 0 $$headerref{ReplyCRC} = $data[6];
545 0 $$headerref{ReplyTo} = $data[7];
546 0 $$headerref{Reply1st} = $data[8];
547 0 $$headerref{ReplyNext} = $data[9];
548 0 $$headerref{DateWritten} = $data[10];
549 0 $$headerref{DateReceived} = $data[11];
550 0 $$headerref{DateProcessed} = $data[12];
551 0 $$headerref{MsgNum} = $data[13];
552 0 $$headerref{Attributes} = $data[14];
553 0 $$headerref{Attributes2} = $data[15];
554 0 $$headerref{TxtOffset} = $data[16];
555 0 $$headerref{TxtLen} = $data[17];
556 0 $$headerref{PasswordCRC} = $data[18];
557 0 $$headerref{Cost} = $data[19];
558  
559 0 ▶ if ($subfieldsref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subfieldsref) 0 0 0
560 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (read($handleref->{"jhr"}, $buf, $headerref->{"SubfieldLen"}) != $headerref->{"SubfieldLen"}) 0 0 0
561 read( $$handleref{jhr}, $buf, $$headerref{SubfieldLen} ) !=
562 $$headerref{SubfieldLen} )
563 {
564 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
565 0 return;
566 }
567  
568 0 @$subfieldsref = ();
569  
570 0 ▶ while ($buf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf) 0 0 0
571 0 @data = unpack( "LL", $buf );
572 0 push( @$subfieldsref, $data[0] );
573 0 push( @$subfieldsref, substr( $buf, 8, $data[1] ) );
574 0 $buf = substr( $buf, 8 + $data[1] );
575 }
576 }
577  
578 0 ▶ if ($textref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($textref) 0 0 0
579 0 ▶ if ( !seek( $$handleref{jdt}, $$headerref{TxtOffset}, 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jdt"}, $headerref->{"TxtOffset"}, 0) 0 0 0
580 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
581 0 return;
582 }
583  
584 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (read($handleref->{"jdt"}, $$textref, $headerref->{"TxtLen"}) != $headerref->{"TxtLen"}) 0 0 0
585 read( $$handleref{jdt}, $$textref, $$headerref{TxtLen} ) !=
586 $$headerref{TxtLen} )
587 {
588 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
589 0 return;
590 }
591 }
592  
593 0 return 1;
594 }
595  
596 =head2 ChangeMessage
597  
598 Syntax: $success = FTN::JAM::ChangeMessage($handle,$msgnum,\%header)
599  
600 =cut
601  
602 0 ▶sub ChangeMessage {
Subroutine ChangeMessage: not called CC=33 SCAR=70.2
Pod documented
603 0 ▶ if ( $#_ != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != 2) 0 0 0
604 0 croak "Wrong number of arguments for FTN::JAM::ChangeMessage";
605 }
606  
607 0 my $handleref = $_[0];
608 0 my $msgnum = $_[1];
609 0 my $headerref = $_[2];
610  
611 0 ▶ if ( !defined( $$headerref{Signature} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"Signature"}) 0 0 0
612 0 $$headerref{Signature} = "JAM";
613 }
614 0 ▶ if ( !defined( $$headerref{Revision} ) ) { $$headerref{Revision} = 1; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"Revision"}) 0 0 0
615 0 ▶ if ( !defined( $$headerref{ReservedWord} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"ReservedWord"}) 0 0 0
616 0 $$headerref{ReservedWord} = 0;
617 }
618 0 ▶ if ( !defined( $$headerref{SubfieldLen} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"SubfieldLen"}) 0 0 0
619 0 $$headerref{SubfieldLen} = 0;
620 }
621 0 ▶ if ( !defined( $$headerref{TimesRead} ) ) { $$headerref{TimesRead} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"TimesRead"}) 0 0 0
622 0 ▶ if ( !defined( $$headerref{MsgIdCRC} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"MsgIdCRC"}) 0 0 0
623 0 $$headerref{MsgIdCRC} = 0xffffffff;
624 }
625 0 ▶ if ( !defined( $$headerref{ReplyCRC} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"ReplyCRC"}) 0 0 0
626 0 $$headerref{ReplyCRC} = 0xffffffff;
627 }
628 0 ▶ if ( !defined( $$headerref{ReplyTo} ) ) { $$headerref{ReplyTo} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"ReplyTo"}) 0 0 0
629 0 ▶ if ( !defined( $$headerref{Reply1st} ) ) { $$headerref{Reply1st} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"Reply1st"}) 0 0 0
630 0 ▶ if ( !defined( $$headerref{ReplyNext} ) ) { $$headerref{ReplyNext} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"ReplyNext"}) 0 0 0
631 0 ▶ if ( !defined( $$headerref{DateWritten} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"DateWritten"}) 0 0 0
632 0 $$headerref{DateWritten} = 0;
633 }
634 0 ▶ if ( !defined( $$headerref{DateReceived} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"DateReceived"}) 0 0 0
635 0 $$headerref{DateReceived} = 0;
636 }
637 0 ▶ if ( !defined( $$headerref{DateProcessed} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"DateProcessed"}) 0 0 0
638 0 $$headerref{DateProcessed} = 0;
639 }
640 0 ▶ if ( !defined( $$headerref{MsgNum} ) ) { $$headerref{MsgNum} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"MsgNum"}) 0 0 0
641 0 ▶ if ( !defined( $$headerref{Attributes} ) ) { $$headerref{Attributes} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"Attributes"}) 0 0 0
642 0 ▶ if ( !defined( $$headerref{Attributes2} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"Attributes2"}) 0 0 0
643 0 $$headerref{Attributes2} = 0;
644 }
645 0 ▶ if ( !defined( $$headerref{TxtOffset} ) ) { $$headerref{TxtOffset} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"TxtOffset"}) 0 0 0
646 0 ▶ if ( !defined( $$headerref{TxtLen} ) ) { $$headerref{TxtLen} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"TxtLen"}) 0 0 0
647 0 ▶ if ( !defined( $$headerref{PasswordCRC} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"PasswordCRC"}) 0 0 0
648 0 $$headerref{PasswordCRC} = 0xffffffff;
649 }
650 0 ▶ if ( !defined( $$headerref{Cost} ) ) { $$headerref{Cost} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"Cost"}) 0 0 0
651  
652 0 ▶ if ( !$$handleref{locked} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($handleref->{"locked"}) 0 0 0
653 0 $Errnum = $FTN::JAM::Errnum::BASE_NOT_LOCKED;
654 0 return;
655 }
656  
657 0 my $buf;
658 my @data;
659 0 my %mbheader;
660  
661 0 ▶ if ( !ReadMBHeader( $handleref, \%mbheader ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ReadMBHeader($handleref, \%mbheader)) 0 0 0
662 0 return;
663 }
664  
665 0 ▶ if ( ( $$headerref{Attributes} & $FTN::JAM::Attr::DELETED ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headerref->{"Attributes"} & $FTN::JAM::Attr::DELETED) 0 0 0
666 0 my %oldheader;
667  
668 0 ▶ if ( !ReadMessage( $handleref, $msgnum, \%oldheader, 0, 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ReadMessage($handleref, $msgnum, \%oldheader, 0, 0)) 0 0 0
669 0 return;
670 }
671  
672 0 ▶ if ( !( $oldheader{Attributes} & $FTN::JAM::Attr::DELETED ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($oldheader{"Attributes"} & $FTN::JAM::Attr::DELETED) 0 0 0
673 0 ▶ if ( $mbheader{ActiveMsgs} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mbheader{"ActiveMsgs"}) 0 0 0
674 0 $mbheader{ActiveMsgs}--;
675 }
676 }
677 }
678  
679 0 ▶ if ( !seek( $$handleref{jdx}, ( $msgnum - $mbheader{BaseMsgNum} ) * 8, 0 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jdx"}, ($msgnum - $mbheader{"BaseMsgNum"}) * 8, 0) 0 0 0
680 {
681 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
682 0 return;
683 }
684  
685 0 ▶ if ( read( $$handleref{jdx}, $buf, 8 ) != 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($handleref->{"jdx"}, $buf, 8) != 8) 0 0 0
686 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
687 0 return;
688 }
689  
690 0 @data = unpack( "LL", $buf );
691  
692 0 ▶ if ( !seek( $$handleref{jhr}, $data[1], 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jhr"}, $data[1], 0) 0 0 0
693 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
694 0 return;
695 }
696  
697 0 my $printres = print { $$handleref{jhr} } pack(
698 "Z[4]SSLLLLLLLLLLLLLLLLL",
699 $$headerref{Signature}, $$headerref{Revision},
700 $$headerref{ReservedWord}, $$headerref{SubfieldLen},
701 $$headerref{TimesRead}, $$headerref{MsgIdCRC},
702 $$headerref{ReplyCRC}, $$headerref{ReplyTo},
703 $$headerref{Reply1st}, $$headerref{ReplyNext},
704 $$headerref{DateWritten}, $$headerref{DateReceived},
705 $$headerref{DateProcessed}, $$headerref{MsgNum},
706 $$headerref{Attributes}, $$headerref{Attributes2},
707 $$headerref{TxtOffset}, $$headerref{TxtLen},
708 $$headerref{PasswordCRC}, $$headerref{Cost}
709 0 );
710  
711 0 ▶ if ( !$printres ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($printres) 0 0 0
712 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
713 0 return;
714 }
715  
716 0 ▶ if ( !WriteMBHeader( $handleref, \%mbheader ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (WriteMBHeader($handleref, \%mbheader)) 0 0 0
717 0 return;
718 }
719  
720 0 return 1;
721 }
722  
723 =head2 AddMessage
724  
725 Syntax: $success = FTN::JAM::AddMessage($handle,\%header,\@subfields,\$text)
726  
727 =cut
728  
729 0 ▶sub AddMessage {
Subroutine AddMessage: not called CC=48 SCAR=77.6
Pod documented
730 0 ▶ if ( $#_ != 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != 3) 0 0 0
731 0 croak "Wrong number of arguments for FTN::JAM::AddMessage";
732 }
733  
734 0 my $handleref = $_[0];
735 0 my $headerref = $_[1];
736 0 my $subfieldsref = $_[2];
737 0 my $textref = $_[3];
738  
739 0 my %mbheader;
740 my $printres;
741  
742 0 ▶ if ( !$headerref ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($headerref) 0 0 0
743 0 ▶ if ( !ReadMBHeader( $handleref, \%mbheader ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ReadMBHeader($handleref, \%mbheader)) 0 0 0
744 0 return;
745 }
746  
747 0 ▶ if ( !seek( $$handleref{jdx}, 0, 2 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jdx"}, 0, 2) 0 0 0
748 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
749 0 return;
750 }
751  
752 0 my $jdxoffset = tell( $$handleref{jdx} );
753  
754 0 ▶ if ( $jdxoffset == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jdxoffset == -1) 0 0 0
755 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
756 0 return;
757 }
758  
759 0 print { $$handleref{jdx} } pack( "LL", 0xffffffff, 0xffffffff );
760  
761 0 ▶ if ( !$printres ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($printres) 0 0 0
762 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
763 0 return;
764 }
765  
766 0 return $jdxoffset / 8 + $mbheader{BaseMsgNum};
767 }
768  
769 0 ▶ if ( !defined( $$headerref{Signature} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"Signature"}) 0 0 0
770 0 $$headerref{Signature} = "JAM";
771 }
772 0 ▶ if ( !defined( $$headerref{Revision} ) ) { $$headerref{Revision} = 1; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"Revision"}) 0 0 0
773 0 ▶ if ( !defined( $$headerref{ReservedWord} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"ReservedWord"}) 0 0 0
774 0 $$headerref{ReservedWord} = 0;
775 }
776 0 ▶ if ( !defined( $$headerref{SubfieldLen} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"SubfieldLen"}) 0 0 0
777 0 $$headerref{SubfieldLen} = 0;
778 }
779 0 ▶ if ( !defined( $$headerref{TimesRead} ) ) { $$headerref{TimesRead} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"TimesRead"}) 0 0 0
780 0 ▶ if ( !defined( $$headerref{MsgIdCRC} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"MsgIdCRC"}) 0 0 0
781 0 $$headerref{MsgIdCRC} = 0xffffffff;
782 }
783 0 ▶ if ( !defined( $$headerref{ReplyCRC} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"ReplyCRC"}) 0 0 0
784 0 $$headerref{ReplyCRC} = 0xffffffff;
785 }
786 0 ▶ if ( !defined( $$headerref{ReplyTo} ) ) { $$headerref{ReplyTo} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"ReplyTo"}) 0 0 0
787 0 ▶ if ( !defined( $$headerref{Reply1st} ) ) { $$headerref{Reply1st} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"Reply1st"}) 0 0 0
788 0 ▶ if ( !defined( $$headerref{ReplyNext} ) ) { $$headerref{ReplyNext} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"ReplyNext"}) 0 0 0
789 0 ▶ if ( !defined( $$headerref{DateWritten} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"DateWritten"}) 0 0 0
790 0 $$headerref{DateWritten} = 0;
791 }
792 0 ▶ if ( !defined( $$headerref{DateReceived} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"DateReceived"}) 0 0 0
793 0 $$headerref{DateReceived} = 0;
794 }
795 0 ▶ if ( !defined( $$headerref{DateProcessed} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"DateProcessed"}) 0 0 0
796 0 $$headerref{DateProcessed} = 0;
797 }
798 0 ▶ if ( !defined( $$headerref{MsgNum} ) ) { $$headerref{MsgNum} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"MsgNum"}) 0 0 0
799 0 ▶ if ( !defined( $$headerref{Attributes} ) ) { $$headerref{Attributes} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"Attributes"}) 0 0 0
800 0 ▶ if ( !defined( $$headerref{Attributes2} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"Attributes2"}) 0 0 0
801 0 $$headerref{Attributes2} = 0;
802 }
803 0 ▶ if ( !defined( $$headerref{TxtOffset} ) ) { $$headerref{TxtOffset} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"TxtOffset"}) 0 0 0
804 0 ▶ if ( !defined( $$headerref{TxtLen} ) ) { $$headerref{TxtLen} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"TxtLen"}) 0 0 0
805 0 ▶ if ( !defined( $$headerref{PasswordCRC} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"PasswordCRC"}) 0 0 0
806 0 $$headerref{PasswordCRC} = 0xffffffff;
807 }
808 0 ▶ if ( !defined( $$headerref{Cost} ) ) { $$headerref{Cost} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headerref->{"Cost"}) 0 0 0
809  
810 0 ▶ if ( !$$handleref{locked} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($handleref->{"locked"}) 0 0 0
811 0 $Errnum = $FTN::JAM::Errnum::BASE_NOT_LOCKED;
812 0 return;
813 }
814  
815 0 my $buf;
816 my @data;
817  
818 0 ▶ if ( !ReadMBHeader( $handleref, \%mbheader ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ReadMBHeader($handleref, \%mbheader)) 0 0 0
819 0 return;
820 }
821  
822 0 $$headerref{TxtOffset} = 0;
823 0 $$headerref{TxtLen} = 0;
824  
825 0 ▶ if ( $textref and length($$textref) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($textref and length $$textref) 0 0 0
Condition0%0/3
$textref and length $$textref
!ll&&!rl&&r
000
MC/DC0%0/2
$textref and length $$textref
$textref length $$textref
Truth table0%0/3
A and B
A= $textrefB= length $$textref
ABresult
0X0
100
111
826 0 ▶ if ( !seek( $$handleref{jdt}, 0, 2 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jdt"}, 0, 2) 0 0 0
827 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
828 0 return;
829 }
830  
831 0 my $jdtoffset = tell( $$handleref{jdt} );
832  
833 0 ▶ if ( $jdtoffset == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jdtoffset == -1) 0 0 0
834 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
835 0 return;
836 }
837  
838 0 $$headerref{TxtOffset} = $jdtoffset;
839 0 $$headerref{TxtLen} = length($$textref);
840  
841 0 $printres = print { $$handleref{jdt} } $$textref;
842  
843 0 ▶ if ( !$printres ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($printres) 0 0 0
844 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
845 0 return;
846 }
847 }
848  
849 0 $$headerref{SubfieldLen} = 0;
850 0 $$headerref{MsgIdCRC} = 0xffffffff;
851 0 $$headerref{ReplyCRC} = 0xffffffff;
852 0 my $usercrc = 0xffffffff;
853  
854 0 ▶ for ( my $i = 0 ; $i <= $#$subfieldsref ; $i = $i + 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $subfieldsref->$#*) 0 0 0
855 0 ▶ if ( $$subfieldsref[$i] == $FTN::JAM::Subfields::RECVRNAME ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subfieldsref->[$i] == $FTN::JAM::Subfields::RECVRNAME) 0 0 0
856 0 $usercrc = Crc32( $$subfieldsref[ $i + 1 ] );
857 }
858  
859 0 ▶ if ( $$subfieldsref[$i] == $FTN::JAM::Subfields::MSGID ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subfieldsref->[$i] == $FTN::JAM::Subfields::MSGID) 0 0 0
860 0 $$headerref{MsgIdCRC} = Crc32( $$subfieldsref[ $i + 1 ] );
861 }
862  
863 0 ▶ if ( $$subfieldsref[$i] == $FTN::JAM::Subfields::REPLYID ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subfieldsref->[$i] == $FTN::JAM::Subfields::REPLYID) 0 0 0
864 0 $$headerref{ReplyCRC} = Crc32( $$subfieldsref[ $i + 1 ] );
865 }
866  
867 0 $$headerref{SubfieldLen} += 8 + length( $$subfieldsref[ $i + 1 ] );
868 }
869  
870 0 ▶ if ( !seek( $$handleref{jdx}, 0, 2 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jdx"}, 0, 2) 0 0 0
871 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
872 0 return;
873 }
874  
875 0 my $jdxoffset = tell( $$handleref{jdx} );
876  
877 0 ▶ if ( $jdxoffset == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jdxoffset == -1) 0 0 0
878 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
879 0 return;
880 }
881  
882 0 $$headerref{MsgNum} = $jdxoffset / 8 + $mbheader{BaseMsgNum};
883 0 $$headerref{Signature} = "JAM";
884 0 $$headerref{Revision} = 1;
885  
886 0 ▶ if ( !seek( $$handleref{jhr}, 0, 2 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jhr"}, 0, 2) 0 0 0
887 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
888 0 return;
889 }
890  
891 0 my $jhroffset = tell( $$handleref{jhr} );
892  
893 0 ▶ if ( $jhroffset == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jhroffset == -1) 0 0 0
894 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
895 0 return;
896 }
897  
898 0 $printres = print { $$handleref{jhr} } pack(
899 "Z[4]SSLLLLLLLLLLLLLLLLL",
900 $$headerref{Signature}, $$headerref{Revision},
901 $$headerref{ReservedWord}, $$headerref{SubfieldLen},
902 $$headerref{TimesRead}, $$headerref{MsgIdCRC},
903 $$headerref{ReplyCRC}, $$headerref{ReplyTo},
904 $$headerref{Reply1st}, $$headerref{ReplyNext},
905 $$headerref{DateWritten}, $$headerref{DateReceived},
906 $$headerref{DateProcessed}, $$headerref{MsgNum},
907 $$headerref{Attributes}, $$headerref{Attributes2},
908 $$headerref{TxtOffset}, $$headerref{TxtLen},
909 $$headerref{PasswordCRC}, $$headerref{Cost}
910 0 );
911  
912 0 ▶ if ( !$printres ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($printres) 0 0 0
913 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
914 0 return;
915 }
916  
917 0 ▶ for ( my $i = 0 ; $i <= $#$subfieldsref ; $i = $i + 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $subfieldsref->$#*) 0 0 0
918 $printres =
919 0 print { $$handleref{jhr} }
920 pack( "LL", $$subfieldsref[$i], length( $$subfieldsref[ $i + 1 ] ) ),
921 $$subfieldsref[ $i + 1 ];
922  
923 0 ▶ if ( !$printres ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($printres) 0 0 0
924 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
925 0 return;
926 }
927 }
928  
929 0 $printres = print { $$handleref{jdx} } pack( "LL", $usercrc, $jhroffset );
930  
931 0 ▶ if ( !$printres ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($printres) 0 0 0
932 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
933 0 return;
934 }
935  
936 0 ▶ if ( !( $$headerref{Attributes} & $FTN::JAM::Attr::DELETED ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($headerref->{"Attributes"} & $FTN::JAM::Attr::DELETED) 0 0 0
937 0 $mbheader{ActiveMsgs}++;
938 }
939  
940 0 ▶ if ( !FTN::JAM::WriteMBHeader( $handleref, \%mbheader ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (WriteMBHeader($handleref, \%mbheader)) 0 0 0
941 0 return;
942 }
943  
944 0 return $$headerref{MsgNum};
945 }
946  
947 =head2 Crc32
948  
949 Syntax: $crc32 = FTN::JAM::Crc32($data)
950  
951 =cut
952  
953 0 ▶sub Crc32 {
Subroutine Crc32: not called CC=6 SCAR=37.4
Pod documented
954  
955 0 ▶ my ($data) = @_ or croak 'Crc32 requires the data to be checked as a parameter.';
Branch: 1 branch
BranchTrueFalseTotal
my($data) = or croak("Crc32 requires the data to be checked as a parameter.") 0 0 0
956  
957 0 my $crc;
958 my @table;
959 0 my $i;
960 0 my $j;
961  
962 0 ▶ for ( $i = 0 ; $i < 256 ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 256) 0 0 0
963 0 $crc = $i;
964  
965 0 ▶ for ( $j = 8 ; $j > 0 ; $j-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j > 0) 0 0 0
966 0 ▶ if ( $crc & 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($crc & 1) { } 0 0 0
967 0 $crc = ( $crc >> 1 ) ^ 0xedb88320;
968 }
969 else {
970 0 $crc >>= 1;
971 }
972 }
973  
974 0 $table[$i] = $crc;
975 }
976  
977 0 $crc = 0xffffffff;
978  
979 0 ▶ for ( $i = 0 ; $i < length($data) ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $data) 0 0 0
980 0 $crc =
981 ( ( $crc >> 8 ) & 0x00ffffff )
982 ^ $table[ ( $crc ^ ord( lc( substr( $data, $i, 1 ) ) ) ) & 0xff ];
983 }
984  
985 0 return $crc;
986 }
987  
988 =head2 FindUser
989  
990 Syntax: $msgnum = FTN::JAM::FindUser($handle,$usercrc,$start)
991  
992 =cut
993  
994 0 ▶sub FindUser {
Subroutine FindUser: not called CC=7 SCAR=40.3
Pod documented
995 0 ▶ if ( $#_ != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != 2) 0 0 0
996 0 croak "Wrong number of arguments for FTN::JAM::FindUser";
997 }
998  
999 0 my $handleref = $_[0];
1000 0 my $usercrc = $_[1];
1001 0 my $start = $_[2];
1002  
1003 0 my %mbheader;
1004  
1005 0 ▶ if ( !ReadMBHeader( $handleref, \%mbheader ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ReadMBHeader($handleref, \%mbheader)) 0 0 0
1006 0 return;
1007 }
1008  
1009 0 ▶ if ( !seek( $$handleref{jdx}, ( $start - $mbheader{BaseMsgNum} ) * 8, 0 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jdx"}, ($start - $mbheader{"BaseMsgNum"}) * 8, 0) 0 0 0
1010 {
1011 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
1012 0 return;
1013 }
1014  
1015 0 my $msgnum = $start;
1016  
1017 0 my $buf;
1018 my @data;
1019  
1020 0 while (1) {
1021 0 ▶ if ( read( $$handleref{jdx}, $buf, 8 ) != 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($handleref->{"jdx"}, $buf, 8) != 8) 0 0 0
1022 0 ▶ if ( eof( $$handleref{jdx} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eof $handleref->{'jdx'}) { } 0 0 0
1023 0 $Errnum = $FTN::JAM::Errnum::USER_NOT_FOUND;
1024 }
1025 else {
1026 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
1027 }
1028  
1029 0 return;
1030 }
1031  
1032 0 @data = unpack( "LL", $buf );
1033  
1034 0 ▶ if ( $data[0] == $usercrc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data[0] == $usercrc) 0 0 0
1035 0 return $msgnum;
1036 }
1037  
1038 0 $msgnum++;
1039 }
1040 0 return;
1041 }
1042  
1043 =head2 GetLastRead
1044  
1045 Syntax: $success = FTN::JAM::GetLastRead($handle,$usernum,\%lastread)
1046  
1047 =cut
1048  
1049 0 ▶sub GetLastRead {
Subroutine GetLastRead: not called CC=6 SCAR=37.4
Pod documented
1050 0 ▶ if ( $#_ != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != 2) 0 0 0
1051 0 croak "Wrong number of arguments for FTN::JAM::GetLastRead";
1052 }
1053  
1054 0 my $handleref = $_[0];
1055 0 my $usernum = $_[1];
1056 0 my $lastreadref = $_[2];
1057  
1058 0 ▶ if ( !seek( $$handleref{jlr}, 0, 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jlr"}, 0, 0) 0 0 0
1059 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
1060 0 return;
1061 }
1062  
1063 0 my $buf;
1064 my @data;
1065  
1066 0 ▶ while ( read( $$handleref{jlr}, $buf, 16 ) == 16 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($handleref->{"jlr"}, $buf, 16) == 16) 0 0 0
1067 0 @data = unpack( "LLLL", $buf );
1068  
1069 0 ▶ if ( $data[1] == $usernum ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data[1] == $usernum) 0 0 0
1070 0 %$lastreadref = ();
1071  
1072 0 $$lastreadref{UserCRC} = $data[0];
1073 0 $$lastreadref{UserID} = $data[1];
1074 0 $$lastreadref{LastReadMsg} = $data[2];
1075 0 $$lastreadref{HighReadMsg} = $data[3];
1076  
1077 0 return 1;
1078 }
1079 }
1080  
1081 0 ▶ if ( eof( $$handleref{jlr} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eof $handleref->{'jlr'}) { } 0 0 0
1082 0 $Errnum = $FTN::JAM::Errnum::USER_NOT_FOUND;
1083 }
1084 else {
1085 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
1086 }
1087  
1088 0 return;
1089 }
1090  
1091 =head2 SetLastRead
1092  
1093 Syntax: $success = FTN::JAM::SetLastRead($handle,$usernum,/%lastread)
1094  
1095 =cut
1096  
1097 0 ▶sub SetLastRead {
Subroutine SetLastRead: not called CC=13 SCAR=52.0
Pod documented
1098 0 ▶ if ( $#_ != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != 2) 0 0 0
1099 0 croak "Wrong number of arguments for FTN::JAM::SetLastRead";
1100 }
1101  
1102 0 my $handleref = $_[0];
1103 0 my $usernum = $_[1];
1104 0 my $lastreadref = $_[2];
1105  
1106 0 ▶ if ( !defined( $$lastreadref{UserCRC} ) ) { $$lastreadref{UserCRC} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $lastreadref->{"UserCRC"}) 0 0 0
1107 0 ▶ if ( !defined( $$lastreadref{UserID} ) ) { $$lastreadref{UserID} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $lastreadref->{"UserID"}) 0 0 0
1108 0 ▶ if ( !defined( $$lastreadref{LastReadMsg} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $lastreadref->{"LastReadMsg"}) 0 0 0
1109 0 $$lastreadref{LastReadMsg} = 0;
1110 }
1111 0 ▶ if ( !defined( $$lastreadref{HighReadMsg} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $lastreadref->{"HighReadMsg"}) 0 0 0
1112 0 $$lastreadref{HighReadMsg} = 0;
1113 }
1114  
1115 0 ▶ if ( !seek( $$handleref{jlr}, 0, 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jlr"}, 0, 0) 0 0 0
1116 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
1117 0 return;
1118 }
1119  
1120 0 my $buf;
1121 my @data;
1122  
1123 0 ▶ while ( read( $$handleref{jlr}, $buf, 16 ) == 16 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($handleref->{"jlr"}, $buf, 16) == 16) 0 0 0
1124 0 @data = unpack( "LLLL", $buf );
1125  
1126 0 ▶ if ( $data[1] == $usernum ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data[1] == $usernum) 0 0 0
1127 0 ▶ if ( !seek( $$handleref{jlr}, -16, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $handleref->{"jlr"}, -16, 1) 0 0 0
1128 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
1129 0 return;
1130 }
1131  
1132 0 my $printres = print { $$handleref{jlr} } pack( "LLLL",
1133 $$lastreadref{UserCRC}, $$lastreadref{UserID},
1134 0 $$lastreadref{LastReadMsg}, $$lastreadref{HighReadMsg} );
1135  
1136 0 ▶ if ( !$printres ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($printres) 0 0 0
1137 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
1138 0 return;
1139 }
1140  
1141 0 return 1;
1142 }
1143 }
1144  
1145 0 ▶ if ( !eof( $$handleref{jlr} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eof $handleref->{"jlr"}) 0 0 0
1146 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
1147 }
1148  
1149 0 my $printres = print { $$handleref{jlr} } pack( "LLLL",
1150 $$lastreadref{UserCRC}, $$lastreadref{UserID},
1151 0 $$lastreadref{LastReadMsg}, $$lastreadref{HighReadMsg} );
1152  
1153 0 ▶ if ( !$printres ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($printres) 0 0 0
1154 0 $Errnum = $FTN::JAM::Errnum::IO_ERROR;
1155 0 return;
1156 }
1157  
1158 0 return 1;
1159 }
1160  
1161 =head2 TimeToLocal
1162  
1163 Syntax $local = FTN::JAM::TimeToLocal($time)
1164  
1165 =cut
1166  
1167 1 ▶sub TimeToLocal {
Subroutine TimeToLocal: called CC=2 SCAR=8.1
Pod documented
1168 1 ▶ if ( $#_ != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != 0) 0 1 1
1169 0 croak "Wrong number of arguments for FTN::JAM::TimeToLocal";
1170 }
1171  
1172 1 return $_[0] - timegm( 0, 0, 0, 1, 0, 70 ) + tz_local_offset();
1173 }
1174  
1175 =head2 LocalToTime
1176  
1177 Syntax $time = FTN::JAM::LocalToTime($local)
1178  
1179 =cut
1180  
1181 0 ▶sub LocalToTime {
Subroutine LocalToTime: not called CC=2 SCAR=17.9
Pod documented
1182 0 ▶ if ( $#_ != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ != 0) 0 0 0
1183 0 croak "Wrong number of arguments for FTN::JAM::LocalToTime";
1184 }
1185  
1186 0 return $_[0] + timegm( 0, 0, 0, 1, 0, 70 ) - tz_local_offset();
1187 }
1188  
1189 =head1 AUTHOR
1190  
1191 Robert James Clay, C<< <jame at rocasa.us> >>
1192  
1193 =head1 BUGS
1194  
1195 Please report any bugs or feature requests to C<bug-ftn-jam at rt.cpan.org>, or through the web
1196 interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ftn-jam>. I will be notified, and
1197 then you'll automatically be notified of progress on your bug as I make changes.
1198  
1199 =head1 SUPPORT
1200  
1201 You can find documentation for this module with the perldoc command.
1202  
1203 perldoc FTN::JAM
1204  
1205 You can also look for information at:
1206  
1207 =over 4
1208  
1209 =item * FTN::JAM Home Page
1210  
1211 L<http://ftnpl.sourceforge.net/ftnpljam.html>
1212  
1213 =item * Browse the FTN::JAM GIT repository at SourceForge
1214  
1215 L<http://sourceforge.net/p/ftnpl/ftn-jam/code>
1216  
1217 =item * RT: CPAN's request tracker
1218  
1219 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=ftn-jam>
1220  
1221 =item * AnnoCPAN: Annotated CPAN documentation
1222  
1223 L<http://annocpan.org/dist/ftn-jam>
1224  
1225 =item * CPAN Ratings
1226  
1227 L<http://cpanratings.perl.org/d/ftn-jam>
1228  
1229 =item * Search CPAN
1230  
1231 L<http://search.cpan.org/dist/ftn-jam>
1232  
1233 =back
1234  
1235 =head1 ACKNOWLEDGEMENTS
1236  
1237 Originally based on the public domain Perl::JAM module by Johan Billing, which
1238 can be found at L<https://bitbucket.org/johanbilling/jampm/overview>.
1239  
1240 =head1 SEE ALSO
1241  
1242 L<FTN::JAM>, L<FTN::JAM::Examples>
1243  
1244 =head1 COPYRIGHT & LICENSE
1245  
1246 Copyright 2010-2012 Robert James Clay, all rights reserved.
1247  
1248 This program is free software; you can redistribute it and/or modify it
1249 under the same terms as Perl itself.
1250  
1251 =cut
1252  
1253 3 1; # End of FTN::JAM
↑ Summary JAM/Attr.pm »