| 1 | package WebSphere::MQTT::Persist::File; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | ################ | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # MQTT: WebSphere MQ Telemetry Transport persistence object | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # Re-written in Perl since the IBM C source (mspfp.c) is not in | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # the list of redistributable files. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # Brian Candler | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # B.Candler@pobox.com | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Fcntl qw(SEEK_END SEEK_SET); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | my $basedir = shift; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | $basedir = '/tmp/wmqtt' unless defined $basedir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | # Store parameters | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 25 | 'basedir' => $basedir, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # Bless the hash into an object | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | sub open { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | my ($self, $clientid, $broker, $port) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | $self->{'sentdir'} = sprintf("%s/%s/%s_%s/sent", | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | $self->{'basedir'}, $clientid, $broker, $port); | |||||||||||||||||||||||||||||||||||||||||
| 39 | $self->{'rcvddir'} = sprintf("%s/%s/%s_%s/rcvd", | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | $self->{'basedir'}, $clientid, $broker, $port); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | mkdir_p($self->{'sentdir'}, 0740); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | mkdir_p($self->{'rcvddir'}, 0740); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | ▶ | sub mkdir_p { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mkdir_p: called CC=7 SCAR=20.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | my ($name, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | ▶ | $mode = 0777 unless defined $mode; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | my @dirs = split('/', $name); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | my $path = ''; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | ▶ | while(@dirs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 10 | $path .= shift(@dirs).'/'; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 10 | ▶ | next if $path eq '/'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | next if mkdir($path, $mode) || $!{EEXIST} || $!{EISDIR}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Branch: 1 branch
Condition50%3/6
mkdir $path, $mode or $!{"EEXIST"} or $!{"EISDIR"}
mkdir $path, $mode or $!{"EEXIST"}
MC/DC0%0/3
mkdir $path, $mode or $!{"EEXIST"} or $!{"EISDIR"}
mkdir $path, $mode
$!{"EEXIST"}
$!{"EISDIR"}
Truth table50%2/4
A or B or C
A= mkdir $path, $modeB= $!{"EEXIST"}C= $!{"EISDIR"}
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | croak("mkdir_p: $!"); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub close { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # Called if clean_start=1 on connect. Delete all files in | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # the sent and rcvd directories | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | sub reset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | forallfiles($self->{'sentdir'}, sub { unlink $_[0] }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | forallfiles($self->{'rcvddir'}, sub { unlink $_[0] }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | # Run the passed function for all files in a directory | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # (can you tell I prefer Ruby? :-) | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 14 | ▶ | sub forallfiles { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
forallfiles: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 14 | my $dir = shift; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 14 | my $callback = shift; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 14 | ▶ | opendir(DIR,$dir) || croak("opendir $dir: $!"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 14 | ▶ | while (my $f = readdir(DIR)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 58 | ▶ | next if ($f eq '.' || $f eq '..'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$f eq "." or $f eq ".."
MC/DC100%2/2
$f eq "." or $f eq ".."
$f eq "."
$f eq ".."
Truth table100%3/3
A or B
A= $f eq "."B= $f eq ".."
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 30 | $callback->("$dir/$f"); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 14 | closedir(DIR); | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # Called if clean_start=0 on connect. Load all received messages found on | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # disk into an array of [id,message,id,message,...] | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 6 | ▶ | sub getAllReceivedMessages { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getAllReceivedMessages: called CC=1 SCAR=0.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 6 | my @res = (); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 10 | ▶ | forallfiles($self->{'rcvddir'}, sub { BLOCK: { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=19.0
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 10 | ▶ | last BLOCK unless $_[0] =~ /\/(\d+)$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 7 | my $key = $1; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 7 | ▶ | unless (CORE::open(F, '<', $_[0])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | warn("open $_[0]: $!\n"); | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | last BLOCK; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 7 | my @stat = stat(F); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 7 | ▶ | unless (@stat) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | warn("stat $_[0]: $!\n"); | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | CORE::close(F); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | last BLOCK; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 7 | my $len = $stat[7]; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 7 | my $data = ""; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 7 | ▶ | if (sysread(F, $data, $len) != $len) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | warn("sysread $_[0]: $!\n"); | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | CORE::close(F); | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | last BLOCK; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 7 | push @res, $key, $data; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 7 | CORE::close(F); | |||||||||||||||||||||||||||||||||||||||||
| 117 | 6 | }}); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | @res; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | # Called if clean_start=0 on connect. Load all received messages found on | ||||||||||||||||||||||||||||||||||||||||||
| 122 | # disk into an array of [id,message,id,message,...]. Note that the library | ||||||||||||||||||||||||||||||||||||||||||
| 123 | # may not actually attempt to send these messages until 'retry_interval' | ||||||||||||||||||||||||||||||||||||||||||
| 124 | # seconds have passed. | ||||||||||||||||||||||||||||||||||||||||||
| 125 | # | ||||||||||||||||||||||||||||||||||||||||||
| 126 | # When recovering sent messages we need to ensure that we only restore the | ||||||||||||||||||||||||||||||||||||||||||
| 127 | # latest message associated with a particular key. When updSentMessage is | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # called to replace a PUBLISH with a PUBREL there is a small overlap where | ||||||||||||||||||||||||||||||||||||||||||
| 129 | # both files (NNN and NNNu) are present. Failure at this point would result | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # in both messages be available for recovery, which would result in | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # duplication. So if both a PUBLISH and PUBREL are found for the same key, | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # we need to ensure that only the PUBREL is recovered. | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 6 | ▶ | sub getAllSentMessages { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getAllSentMessages: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 6 | my @res = (); | |||||||||||||||||||||||||||||||||||||||||
| 138 | 6 | my %seen = (); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 10 | ▶ | forallfiles($self->{'sentdir'}, sub { BLOCK: { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=23.5
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 10 | ▶ | last BLOCK unless $_[0] =~ /\/(\d+)(u?)$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 9 | my ($key, $u) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 142 | # This is NNN and we've already seen NNNu? Ignore it | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 9 | ▶ | last BLOCK if ($u eq '' && $seen{$key}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$u eq "" and $seen{$key}
MC/DC100%2/2
$u eq "" and $seen{$key}
$u eq ""
$seen{$key}
Truth table100%3/3
A and B
A= $u eq ""B= $seen{$key}
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | # Read in the file | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 8 | ▶ | unless (CORE::open(F, '<', $_[0])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | warn("open $_[0]: $!"); | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | last BLOCK; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 8 | my @stat = stat(F); | |||||||||||||||||||||||||||||||||||||||||
| 150 | 8 | ▶ | unless (@stat) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | warn("stat $_[0]: $!\n"); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | CORE::close(F); | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | last BLOCK; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 8 | my $len = $stat[7]; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 8 | my $data = ""; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 8 | ▶ | if (sysread(F, $data, $len) != $len) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | warn("sysread $_[0]: $!\n"); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | CORE::close(F); | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | last BLOCK; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 8 | CORE::close(F); | |||||||||||||||||||||||||||||||||||||||||
| 163 | # This is NNNu and we've already seen NNN? Replace it | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 8 | ▶ | if ($u eq 'u' && $seen{$key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$u eq "u" and $seen{$key}
MC/DC100%2/2
$u eq "u" and $seen{$key}
$u eq "u"
$seen{$key}
Truth table100%3/3
A and B
A= $u eq "u"B= $seen{$key}
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | $res[$seen{$key}] = $data; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | last BLOCK; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 7 | push @res, $key, $data; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 7 | $seen{$key} = $#res; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 6 | }}); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 6 | @res; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | # The actual writing of a message file. We take a bit of care here | ||||||||||||||||||||||||||||||||||||||||||
| 175 | # to ensure only whole messages are left in the filesystem | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 5 | ▶ | sub addMessage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addMessage: called CC=5 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 5 | my ($self, $key, $data, $dir, $suffix) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 5 | my $tmp = "$dir/tmp$key${suffix}_$$"; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 5 | ▶ | CORE::open(F,'>',$tmp) || return 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 5 | binmode(F); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 5 | ▶ | goto FAIL unless syswrite(F, $data) == length($data); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 5 | ▶ | goto FAIL2 unless CORE::close(F); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 5 | ▶ | goto FAIL2 unless rename($tmp,"$dir/$key$suffix"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 5 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | FAIL: | |||||||||||||||||||||||||||||||||||||||||
| 187 | CORE::close(F); | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | FAIL2: | |||||||||||||||||||||||||||||||||||||||||
| 189 | unlink($tmp); | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 2 | ▶ | sub addSentMessage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addSentMessage: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | my ($self, $key, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 2 | $self->addMessage($key,$data,$self->{'sentdir'}, ''); | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | sub updSentMessage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
updSentMessage: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | my ($self, $key, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | my $rc = $self->addMessage($key,$data,$self->{'sentdir'}, 'u'); | |||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | ▶ | unlink("$self->{'sentdir'}/$key") if $rc == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | $rc; | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 2 | ▶ | sub delSentMessage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delSentMessage: called CC=5 SCAR=17.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 2 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 2 | ▶ | return 1 if (unlink("$self->{'sentdir'}/$key") == 0 && ! $!{ENOENT}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
unlink(qq[$self->{"sentdir"}/$key]) == 0 and not $!{"ENOENT"}
MC/DC0%0/2
unlink(qq[$self->{"sentdir"}/$key]) == 0 and not $!{"ENOENT"}
unlink(qq[$self->{"sentdir"}/$key]) == 0
not $!{"ENOENT"}
Truth table66%2/3
A and not(B)
A= unlink(qq[$self->{"sentdir"}/$key]) == 0B= not $!{"ENOENT"}
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | ▶ | return 1 if (unlink("$self->{'sentdir'}/${key}u") == 0 && ! $!{ENOENT}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
unlink(qq[$self->{"sentdir"}/${key}u]) == 0 and not $!{"ENOENT"}
MC/DC0%0/2
unlink(qq[$self->{"sentdir"}/${key}u]) == 0 and not $!{"ENOENT"}
unlink(qq[$self->{"sentdir"}/${key}u]) == 0
not $!{"ENOENT"}
Truth table66%2/3
A and not(B)
A= unlink(qq[$self->{"sentdir"}/${key}u]) == 0B= not $!{"ENOENT"}
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 2 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | ▶ | sub addReceivedMessage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addReceivedMessage: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | my ($self, $key, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 2 | $self->addMessage($key,$data,$self->{'rcvddir'}, ''); | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | # This is the weird one. We have to OR the last byte of the file with 0x01 | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | ▶ | sub updReceivedMessage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
updReceivedMessage: called CC=8 SCAR=23.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | ▶ | CORE::open(F,'+<',"$self->{'rcvddir'}/$key") || return 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | binmode(F); | |||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | my $pos = sysseek(F, -1, Fcntl::SEEK_END); | |||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | ▶ | goto FAIL unless defined $pos && $pos >= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $pos and $pos >= 0
MC/DC0%0/2
defined $pos and $pos >= 0
defined $pos
$pos >= 0
Truth table33%1/3
A and B
A= defined $posB= $pos >= 0
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | my $d = ''; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | ▶ | goto FAIL unless sysread(F, $d, 1) == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 1 | $d = chr(ord($d)|0x01); | |||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | my $pos2 = sysseek(F, $pos, Fcntl::SEEK_SET); | |||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | ▶ | goto FAIL unless $pos2 == $pos; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 1 | ▶ | goto FAIL unless syswrite(F, $d, 1) == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | ▶ | return 1 unless CORE::close(F); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | FAIL: | |||||||||||||||||||||||||||||||||||||||||
| 237 | CORE::close(F); | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | ▶ | sub delReceivedMessage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delReceivedMessage: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | return unlink("$self->{'rcvddir'}/$key") != 1; | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | __END__ | ||||||||||||||||||||||||||||||||||||||||||