| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # pRPC - Perl RPC, package for writing simple, RPC like clients and | ||||||||||||||||||||||||||||
| 5 | # servers | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # RPC::pClient.pm is the module for writing the pRPC client. | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # Copyright (c) 1997 Jochen Wiedmann | ||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||
| 12 | # You may distribute under the terms of either the GNU General Public | ||||||||||||||||||||||||||||
| 13 | # License or the Artistic License, as specified in the Perl README file. | ||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||
| 15 | # Author: Jochen Wiedmann | ||||||||||||||||||||||||||||
| 16 | # Am Eisteich 9 | ||||||||||||||||||||||||||||
| 17 | # 72555 Metzingen | ||||||||||||||||||||||||||||
| 18 | # Germany | ||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||
| 20 | # Email: wiedmann@neckar-alb.de | ||||||||||||||||||||||||||||
| 21 | # Phone: +49 7123 14881 | ||||||||||||||||||||||||||||
| 22 | # | ||||||||||||||||||||||||||||
| 23 | # | ||||||||||||||||||||||||||||
| 24 | # $Id: pClient.pm,v 0.1001 1997/09/14 22:53:27 joe Exp $ | ||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||
| 26 | package RPC::pClient; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 7 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 7 | require Exporter; | |||||||||||||||||||||||||||
| 33 | 7 | require DynaLoader; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 7 | @ISA = qw(Exporter DynaLoader); | |||||||||||||||||||||||||||
| 36 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||||||||||
| 37 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||||||||||
| 38 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||||||||||
| 39 | 7 | @EXPORT = qw( | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | 7 | $VERSION = '0.1002'; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 7 | ▶ | use POSIX(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 7 | ▶ | use Sys::Syslog(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 7 | ▶ | use IO::Socket(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | 7 | ▶ | use Storable(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 7 | ▶ | use Socket(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 52 | ▶ | sub error ($) { my $self = shift; $self->{'error'}; } | ||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | ############################################################################ | ||||||||||||||||||||||||||||
| 55 | # | ||||||||||||||||||||||||||||
| 56 | # Name: new | ||||||||||||||||||||||||||||
| 57 | # | ||||||||||||||||||||||||||||
| 58 | # Purpose: Constructor of the pRPC::Client module | ||||||||||||||||||||||||||||
| 59 | # | ||||||||||||||||||||||||||||
| 60 | # Inputs: Hash list of attributes; see pRPC::Client(3) | ||||||||||||||||||||||||||||
| 61 | # | ||||||||||||||||||||||||||||
| 62 | # Returns: connection object or error message | ||||||||||||||||||||||||||||
| 63 | # | ||||||||||||||||||||||||||||
| 64 | ############################################################################ | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 2 | ▶ | sub new ($@) { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=14 SCAR=37.1
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 2 | my ($proto) = shift; | |||||||||||||||||||||||||||
| 68 | 2 | ▶ | my ($class) = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 69 | 2 | my ($self) = {@_}; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 2 | bless($self, $class); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 2 | ▶ | if (!defined($self->{'application'}) || !defined($self->{'version'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"application"} and defined $self->{"version"}
MC/DC0%0/2
defined $self->{"application"} and defined $self->{"version"}
defined $self->{"application"}
defined $self->{"version"}
Truth table33%1/3
A and B
A= defined $self->{"application"}B= defined $self->{"version"}
| |||||||||||||||||||||||||||||
| 74 | 0 | return "Required attributes 'application' or 'version' missing."; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # | ||||||||||||||||||||||||||||
| 78 | # Create Storable objects and send the login message. | ||||||||||||||||||||||||||||
| 79 | # | ||||||||||||||||||||||||||||
| 80 | 2 | ▶ | if ($self->_HaveOoStorable) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | $self->{'io'} = Storable->new('file' => *{$self->{'sock'}}{IO}, | |||||||||||||||||||||||||||
| 82 | 0 | 'crypt' => $self->{'cipher'}, | |||||||||||||||||||||||||||
| 83 | 'netorder' => 1, | ||||||||||||||||||||||||||||
| 84 | 'forgive_me' => 1); | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if (!defined($self->{'io'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | return "Cannot create Storable object: $!"; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||
| 89 | 2 | $self->{'file'} = $self->{'sock'}; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 2 | ▶ | if ($self->{'debug'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | Sys::Syslog::syslog('debug', "Sending login message: %s %s %s", | ||||||||||||||||||||||||||||
| 94 | $self->{'application'}, $self->{'version'}, | ||||||||||||||||||||||||||||
| 95 | 2 | $self->{'user'}); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 2 | ▶ | if (!$self->_Store([$self->{'application'}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | $self->{'version'}, | ||||||||||||||||||||||||||||
| 99 | $self->{'user'}, | ||||||||||||||||||||||||||||
| 100 | $self->{'password'}])) { | ||||||||||||||||||||||||||||
| 101 | 0 | return "Cannot send login message: " . $self->{'error'}; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 2 | ▶ | if ($self->{'debug'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 2 | Sys::Syslog::syslog('debug', "Waiting for server's response ..."); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 2 | my ($msg) = $self->_Retrieve(); | |||||||||||||||||||||||||||
| 108 | 2 | ▶ | if (!$msg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | $msg = "Error while reading server reply: " . $self->{'error'}; | |||||||||||||||||||||||||||
| 110 | 0 | Sys::Syslog::syslog('debug', $msg); | |||||||||||||||||||||||||||
| 111 | 0 | return $msg; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 2 | ▶ | if (ref($msg) ne 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | $msg = "Error while reading server reply: Expected array"; | |||||||||||||||||||||||||||
| 115 | 0 | Sys::Syslog::syslog('debug', $msg); | |||||||||||||||||||||||||||
| 116 | 0 | return $msg; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 2 | ▶ | if (!$$msg[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | $msg = "Refused by server: " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | . (defined($$msg[1]) ? $$msg[1] : "No cause"); | ||||||||||||||||||||||||||||
| 122 | 0 | Sys::Syslog::syslog('debug', $msg); | |||||||||||||||||||||||||||
| 123 | 0 | return $msg; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 2 | ▶ | Sys::Syslog::syslog('debug', "Logged in, server replies %s", | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | defined($$msg[1]) ? $$msg[1] : "undef"); | ||||||||||||||||||||||||||||
| 128 | 2 | $self->{'error'} = ''; | |||||||||||||||||||||||||||
| 129 | 2 | $self; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | ############################################################################ | ||||||||||||||||||||||||||||
| 134 | # | ||||||||||||||||||||||||||||
| 135 | # Name: Call, CallInt | ||||||||||||||||||||||||||||
| 136 | # | ||||||||||||||||||||||||||||
| 137 | # Purpose: coerce method located on the server | ||||||||||||||||||||||||||||
| 138 | # | ||||||||||||||||||||||||||||
| 139 | # Inputs: $con - connection attributes | ||||||||||||||||||||||||||||
| 140 | # $method - method name | ||||||||||||||||||||||||||||
| 141 | # @args - method attributes | ||||||||||||||||||||||||||||
| 142 | # | ||||||||||||||||||||||||||||
| 143 | # Returns: method results; you *must* check $con->error for potential | ||||||||||||||||||||||||||||
| 144 | # error conditions | ||||||||||||||||||||||||||||
| 145 | # | ||||||||||||||||||||||||||||
| 146 | ############################################################################ | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 24 | ▶ | sub CallInt ($@) { | ||||||||||||||||||||||||||
|
Subroutine
CallInt: called CC=11 SCAR=26.3
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | 24 | my($self) = shift; | |||||||||||||||||||||||||||
| 150 | 24 | my($error, $msg, @result); | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 24 | ▶ | if (!$self->_Store([@_])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 0 | $error = $self->{'error'}; | |||||||||||||||||||||||||||
| 154 | } else { | ||||||||||||||||||||||||||||
| 155 | 24 | $msg = $self->_Retrieve(); | |||||||||||||||||||||||||||
| 156 | 24 | ▶ | if (!$msg) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 157 | 0 | $error = $self->{'error'}; | |||||||||||||||||||||||||||
| 158 | } elsif (ref($msg) ne 'ARRAY') { | ||||||||||||||||||||||||||||
| 159 | 0 | $error = "Error while reading server reply: Expected array"; | |||||||||||||||||||||||||||
| 160 | ▶ | } elsif (!defined($$msg[0]) || !$$msg[0]) { | |||||||||||||||||||||||||||
|
Condition66%2/3
defined $msg->[0] && $msg->[0]
MC/DC50%1/2
defined $msg->[0] && $msg->[0]
defined $msg->[0]
$msg->[0]
Truth table66%2/3
A && B
A= defined $msg->[0]B= $msg->[0]
| |||||||||||||||||||||||||||||
| 161 | 4 | ▶ | if (defined($$msg[1]) && $$msg[1] ne '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $msg->[1] and $msg->[1] ne ""
MC/DC0%0/2
defined $msg->[1] and $msg->[1] ne ""
defined $msg->[1]
$msg->[1] ne ""
Truth table33%1/3
A and B
A= defined $msg->[1]B= $msg->[1] ne ""
| |||||||||||||||||||||||||||||
| 162 | 4 | $error = $$msg[1]; | |||||||||||||||||||||||||||
| 163 | } else { | ||||||||||||||||||||||||||||
| 164 | 0 | $error = "No error message"; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | } else { | ||||||||||||||||||||||||||||
| 167 | 20 | $error = ''; | |||||||||||||||||||||||||||
| 168 | 20 | @result = @$msg; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 24 | ▶ | if ($self->{'error'} = $error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 4 | @result = (0, $error); | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 24 | ▶ | if ($self->{'debug'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 24 | ▶ | if ($self->error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 4 | Sys::Syslog::syslog('err', "Calling method %s -> error %s", | |||||||||||||||||||||||||||
| 179 | $_[0], $self->error); | ||||||||||||||||||||||||||||
| 180 | } else { | ||||||||||||||||||||||||||||
| 181 | 20 | Sys::Syslog::syslog('debug', "Calling method %s -> ok", | |||||||||||||||||||||||||||
| 182 | $_[0]); | ||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 24 | @result; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 24 | ▶ | sub Call ($@) { | ||||||||||||||||||||||||||
|
Subroutine
Call: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 190 | 24 | my($self) = shift; | |||||||||||||||||||||||||||
| 191 | 24 | my(@result) = $self->CallInt(@_); | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 24 | ▶ | if (!shift @result) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 4 | @result = (); | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 24 | @result; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | ############################################################################ | ||||||||||||||||||||||||||||
| 202 | # | ||||||||||||||||||||||||||||
| 203 | # Name: Encrypt | ||||||||||||||||||||||||||||
| 204 | # | ||||||||||||||||||||||||||||
| 205 | # Purpose: Get or set the current encryption mode | ||||||||||||||||||||||||||||
| 206 | # | ||||||||||||||||||||||||||||
| 207 | # Inputs: $self - client object | ||||||||||||||||||||||||||||
| 208 | # $crypt - encryption object | ||||||||||||||||||||||||||||
| 209 | # | ||||||||||||||||||||||||||||
| 210 | # Returns: current encryption object; 'undef' for no encryption | ||||||||||||||||||||||||||||
| 211 | # | ||||||||||||||||||||||||||||
| 212 | ############################################################################ | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 0 | ▶ | sub Encrypt ($;$) { | ||||||||||||||||||||||||||
|
Subroutine
Encrypt: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 215 | 0 | my ($self, $crypt) = @_; | |||||||||||||||||||||||||||
| 216 | 0 | ▶ | if (@_ == 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if ($self->_HaveOoStorable) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 0 | $self->{'io'}->{'crypt'} = $crypt; | |||||||||||||||||||||||||||
| 219 | } else { | ||||||||||||||||||||||||||||
| 220 | 0 | $self->{'cipher'} = $crypt; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | 0 | ▶ | $self->_HaveOoStorable ? $self->{'io'}->{'crypt'} : $self->{'cipher'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | ############################################################################ | ||||||||||||||||||||||||||||
| 228 | # | ||||||||||||||||||||||||||||
| 229 | # Name: _Store, _Retrieve | ||||||||||||||||||||||||||||
| 230 | # | ||||||||||||||||||||||||||||
| 231 | # Purpose: Preliminary replacements for Storable->Store and | ||||||||||||||||||||||||||||
| 232 | # Storable->Retrieve as long as Raphael hasn't integrated | ||||||||||||||||||||||||||||
| 233 | # my suggestion for an OO API. | ||||||||||||||||||||||||||||
| 234 | # | ||||||||||||||||||||||||||||
| 235 | # Inputs: $self - server object | ||||||||||||||||||||||||||||
| 236 | # $msg - message being sent (_Store only) | ||||||||||||||||||||||||||||
| 237 | # | ||||||||||||||||||||||||||||
| 238 | # Returns: _Retrieve returns a message in case of success. Both | ||||||||||||||||||||||||||||
| 239 | # methods return FALSE in case of error, $self->{'error'} | ||||||||||||||||||||||||||||
| 240 | # will be set in that case. | ||||||||||||||||||||||||||||
| 241 | # | ||||||||||||||||||||||||||||
| 242 | ############################################################################ | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 7 | $RPC::pClient::haveOoStorable = undef; | |||||||||||||||||||||||||||
| 245 | 108 | ▶ | sub _HaveOoStorable () { | ||||||||||||||||||||||||||
|
Subroutine
_HaveOoStorable: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 246 | 108 | ▶ | if (!defined($RPC::pClient::haveOoStorable)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | 2 | $@ = ''; | |||||||||||||||||||||||||||
| 248 | 2 | eval "Storable->new()"; | |||||||||||||||||||||||||||
| 249 | 2 | ▶ | $RPC::pClient::haveOoStorable = $@ ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | 108 | $RPC::pClient::haveOoStorable; | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 52 | ▶ | sub _Retrieve($) { | ||||||||||||||||||||||||||
|
Subroutine
_Retrieve: called CC=11 SCAR=31.4
| |||||||||||||||||||||||||||||
| 255 | 52 | my($self) = @_; | |||||||||||||||||||||||||||
| 256 | 52 | my($result); | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 52 | ▶ | if ($self->_HaveOoStorable) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if (!($result = $self->{'io'}->Retrieve())) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | 0 | $self->{'error'} = $self->{'io'}->errstr; | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | 0 | return $result; | |||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 52 | my($encodedSize, $readSize, $blockSize); | |||||||||||||||||||||||||||
| 266 | 52 | $readSize = 4; | |||||||||||||||||||||||||||
| 267 | 52 | $encodedSize = ''; | |||||||||||||||||||||||||||
| 268 | 52 | ▶ | while ($readSize > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 52 | my $result = $self->{'file'}->read($encodedSize, $readSize, | |||||||||||||||||||||||||||
| 270 | length($encodedSize)); | ||||||||||||||||||||||||||||
| 271 | 52 | ▶ | if ($result < 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | 0 | $self->{'error'} = "Error while reading: $!"; | |||||||||||||||||||||||||||
| 273 | 0 | return undef; | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | 52 | $readSize -= $result; | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | 52 | $encodedSize = unpack("N", $encodedSize); | |||||||||||||||||||||||||||
| 278 | 52 | $readSize = $encodedSize; | |||||||||||||||||||||||||||
| 279 | 52 | ▶ | if ($self->{'cipher'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | 0 | $blockSize = $self->{'cipher'}->blocksize; | |||||||||||||||||||||||||||
| 281 | 0 | ▶ | if (my $addSize = ($encodedSize % $blockSize)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | 0 | $readSize += ($blockSize - $addSize); | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | 52 | my $msg = ''; | |||||||||||||||||||||||||||
| 286 | 52 | my $rs = $readSize; | |||||||||||||||||||||||||||
| 287 | 52 | ▶ | while ($rs > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 288 | 52 | my $result = read($self->{'file'}, $msg, $rs, length($msg)); | |||||||||||||||||||||||||||
| 289 | 52 | ▶ | if ($result < 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | 0 | $self->{'error'} = "Error while reading: $!"; | |||||||||||||||||||||||||||
| 291 | 0 | return undef; | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | 52 | $rs -= $result; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | 52 | ▶ | if ($self->{'cipher'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | 0 | my $cipher = $self->{'cipher'}; | |||||||||||||||||||||||||||
| 297 | 0 | my $encodedMsg = $msg; | |||||||||||||||||||||||||||
| 298 | 0 | $msg = ''; | |||||||||||||||||||||||||||
| 299 | 0 | ▶ | for (my $i = 0; $i < $readSize; $i += $blockSize) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | 0 | $msg .= $cipher->decrypt(substr($encodedMsg, $i, $blockSize)); | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | 0 | $msg = substr($msg, 0, $encodedSize); | |||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | 52 | my $ref = Storable::thaw($msg); | |||||||||||||||||||||||||||
| 305 | 52 | $ref; | |||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | 52 | ▶ | sub _Store($$) { | ||||||||||||||||||||||||||
|
Subroutine
_Store: called CC=6 SCAR=28.8
| |||||||||||||||||||||||||||||
| 308 | 52 | my($self, $msg) = @_; | |||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 52 | ▶ | if ($self->_HaveOoStorable) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 0 | ▶ | if (!$self->{'io'}->Store($msg)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | 0 | $self->{'error'} = $self->{'io'}->errstr; | |||||||||||||||||||||||||||
| 313 | 0 | return undef; | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | 0 | return 1; | |||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 52 | my($encodedMsg) = Storable::nfreeze($msg); | |||||||||||||||||||||||||||
| 319 | 52 | my($encodedSize) = length($encodedMsg); | |||||||||||||||||||||||||||
| 320 | 52 | ▶ | if ($self->{'cipher'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | 0 | my $cipher = $self->{'cipher'}; | |||||||||||||||||||||||||||
| 322 | 0 | my $size = $cipher->blocksize; | |||||||||||||||||||||||||||
| 323 | 0 | ▶ | if (my $addSize = length($encodedMsg) % $size) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | 0 | $encodedMsg .= chr(0) x ($size - $addSize); | |||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | 0 | $msg = $encodedMsg; | |||||||||||||||||||||||||||
| 327 | 0 | $encodedMsg = ''; | |||||||||||||||||||||||||||
| 328 | 0 | ▶ | for (my $i = 0; $i < length($msg); $i += $size) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | 0 | $encodedMsg .= $cipher->encrypt(substr($msg, $i, $size)); | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | 52 | $self->{'file'}->print(pack("N", $encodedSize) . $encodedMsg); | |||||||||||||||||||||||||||
| 333 | 52 | $self->{'file'}->flush(); | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 7 | 1; | |||||||||||||||||||||||||||
| 340 | __END__ | ||||||||||||||||||||||||||||