RPC/pServer.pm

filter: Statementstmt 51.7% 146 / 282 Branchbran 37.3% 47 / 126 Conditioncond 37.1% 13 / 35 MC/DCmcdc 13.0% 3 / 23 Subroutinesub 86.3% 19 / 22 Podpod 75.0% 9 / 12 totaltotal 47.4% 237 / 500 CC 80 SCAR 49.8
CC
80
Cov
47%
new
409.6
_ReadConfigFile
90.0
Loop
28.3
CRAP 145.1
↑ Summary RPC/pClient.pm »
1 # -*- perl -*-
2 #
3 #
4 # pRPC - Perl RPC, package for writing simple, RPC like clients and
5 # servers
6 #
7 # RPC::pServer.pm is the module for writing the pRPC server.
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: pServer.pm,v 0.1001 1997/09/14 22:53:27 joe Exp $
25 #
26 package RPC::pServer;
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 7 ▶use RPC::pClient;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 7 require Exporter;
34 7 require DynaLoader;
35  
36 7 @ISA = qw(Exporter DynaLoader RPC::pClient);
37 # Items to export into callers namespace by default. Note: do not export
38 # names by default without a very good reason. Use EXPORT_OK instead.
39 # Do not simply export all your public functions/methods/constants.
40 7 @EXPORT = qw(
41
42 );
43 7 $VERSION = '0.1005';
44  
45  
46  
47 # Preloaded methods go here.
48  
49 7 ▶use POSIX();
Subroutine BEGIN: called CC=1 SCAR=0.0
50 7 ▶use Sys::Syslog();
Subroutine BEGIN: called CC=1 SCAR=0.0
51 7 ▶use IO::Socket();
Subroutine BEGIN: called CC=1 SCAR=0.0
52 7 ▶use Socket();
Subroutine BEGIN: called CC=1 SCAR=0.0
53 7 ▶use Storable();
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55  
56 ############################################################################
57 #
58 # Name: _ReadConfigFile
59 #
60 # Purpose: Reads a server configuration file
61 #
62 # Inputs: file name
63 #
64 # Returns: a reference to a list of clients, if successfull; the
65 # reference will additionally be stored in the variable
66 # $RPC::pServer::configFile for later use. 'undef'
67 # will be returned in case of errors.
68 #
69 ############################################################################
70  
71 32 ▶sub Log($$$@) {
Subroutine Log: called CC=2 SCAR=7.6
Pod undocumented
72 32 my($self, $level, $msg, @args) = @_;
73 32 ▶ if (!$self->{'stderr'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'stderr'}) { } 32 0 32
74 32 Sys::Syslog::syslog($level, $msg, @args);
75 } else {
76 0 print STDERR "$msg\n";
77 }
78 }
79 7 my $logClass = "RPC::pServer";
80  
81  
82 0 ▶sub _ReadConfigFile ($) {
Subroutine _ReadConfigFile: not called CC=9 SCAR=45.0
83 0 my($file) = @_;
84 0 my($line, $configFile, $client, $mask, $lineNum);
85  
86 0 ▶ if(defined($RPC::pServer::configFile)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $RPC::pServer::configFile) 0 0 0
87 0 return $RPC::pServer::configFile;
88 }
89  
90 0 $configFile = [];
91 0 ▶ if (!open(FILE, "<$file")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open FILE, "<$file") 0 0 0
92 0 return "Cannot read config file $file: $!";
93 }
94  
95 0 $lineNum = 0;
96 0 ▶ while (defined($line = <FILE>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline FILE)) 0 0 0
97 0 ++$lineNum;
98 0 $line =~ s/\#.*//; # Comments are allowed
99 0 ▶ if ($line =~ /^\s*accept\s+(\S+)\s*$/i) {
Branch: 4 branches
BranchTrueFalseTotal
if ($line =~ /^\s*accept\s+(\S+)\s*$/i) { } 0 0 0
elsif ($line =~ /^\s*deny\s+(\S+)\s*$/i) { } 0 0 0
elsif ($line =~ /^\s*(\S+)\s+(.*\S)\s*$/) { } 0 0 0
elsif (not $line =~ /^\s*$/) { } 0 0 0
100 0 $mask = $1;
101 0 $client = { 'mask' => $mask, 'accept' => 1 };
102 0 push(@$configFile, $client);
103 } elsif ($line =~ /^\s*deny\s+(\S+)\s*$/i) {
104 0 $mask = $1;
105 0 $client = { 'mask' => $mask, 'accept' => 0 };
106 0 push(@$configFile, $client);
107 } elsif ($line =~ /^\s*(\S+)\s+(.*\S)\s*$/) {
108 0 ▶ if (defined($client)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $client) { } 0 0 0
109 0 $client->{$1} = $2;
110 } else {
111 0 close(FILE);
112 0 return "Cannot parse line $lineNum of config file $file.";
113 }
114 } elsif ($line !~ /^\s*$/) {
115 0 close(FILE);
116 0 return "Cannot parse line $lineNum of config file $file.";
117 }
118 }
119  
120 0 close(FILE);
121  
122 0 $RPC::pServer::configFile = $configFile;
123 }
124  
125  
126 ############################################################################
127 #
128 # Name: new
129 #
130 # Purpose: Constructor of the RPC::pServer module
131 #
132 # Inputs: Hash list of attributes; see RPC::pServer(3)
133 #
134 # Returns: connection object or 'undef' in case of errors
135 #
136 ############################################################################
137  
138 2 ▶sub new ($@) {
Subroutine new: called CC=32 SCAR=60.2
Pod documented
139 2 my ($proto) = shift;
140 2 ▶ my ($class) = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
141 2 my ($self) = {@_};
142 2 my ($sock);
143  
144 2 bless($self, $class);
145  
146 # Read the configuration file, if not already done.
147 2 ▶ if (defined($self->{'configFile'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"configFile"}) 0 2 2
148 0 my ($result) = _ReadConfigFile($self->{'configFile'});
149 0 ▶ if (!ref($result)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $result) 0 0 0
150 0 $self->Log('err', $result);
151 0 return $result;
152 }
153 0 $self->{'authorizedClients'} = $result;
154 }
155  
156 2 ▶ if (!defined($self->{'inetd'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'inetd'}) { } 2 0 2
157 # Non-Inetd-Server
158 2 $sock = $self->{'sock'}->accept();
159 2 ▶ if (!defined($sock)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sock) 0 2 2
160 0 my $msg = "Cannot accept: $?";
161 0 $self->Log('err', $msg);
162 0 return $msg;
163 }
164 } else {
165 # Inetd based server; need to work out how to create a
166 # IO::socket object for that
167 0 $sock = $self->{'sock'};
168 }
169  
170 #
171 # Check whether the client is authorized to connect
172 #
173 2 my ($name, $aliases, $addrtype, $length, @addrs)
174 = gethostbyaddr($sock->peeraddr, &Socket::AF_INET);
175 2 my $client;
176 2 foreach $client (@{$self->{'authorizedClients'}}) {
177 0 my($alias, $found, $mask);
178 0 my (@cfl) = (%$client);
179 0 $mask = $client->{'mask'};
180 0 $found = 0;
181 0 ▶ if ($sock->peerhost =~ /$mask/ ||
Branch: 1 branch
BranchTrueFalseTotal
if ($sock->peerhost =~ /$mask/ or $name =~ /$mask/) 0 0 0
Condition0%0/3
$sock->peerhost =~ /$mask/ or $name =~ /$mask/
l!l&&r!l&&!r
000
MC/DC0%0/2
$sock->peerhost =~ /$mask/ or $name =~ /$mask/
$sock->peerhost =~ /$mask/ $name =~ /$mask/
Truth table0%0/3
A or B
A= $sock->peerhost =~ /$mask/B= $name =~ /$mask/
ABresult
1X1
011
000
182 $name =~ /$mask/) {
183 0 $found = 1;
184 }
185 0 ▶ if (!$found) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 0 0 0
186 0 foreach $alias (split(/ /, $aliases)) {
187 0 ▶ if ($alias =~ /$mask/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alias =~ /$mask/) 0 0 0
188 0 $found = 1;
189 0 last;
190 }
191 }
192 }
193 0 ▶ if (!$found) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 0 0 0
194 0 my $addr;
195 0 foreach $addr (@addrs) {
196 0 ▶ if (Socket::inet_ntoa($addr) =~ /$mask/) {
Branch: 1 branch
BranchTrueFalseTotal
if (Socket::inet_ntoa($addr) =~ /$mask/) 0 0 0
197 0 $found = 1;
198 0 last;
199 }
200 }
201 }
202 0 ▶ if ($found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) 0 0 0
203 0 my ($class, $key);
204 0 ▶ if (!$client->{'accept'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($client->{"accept"}) 0 0 0
205 0 my $msg = sprintf("Access not permitted from %s, %s",
206 $sock->sockhost, $sock->sockport);
207 0 $self->Log('err', $msg);
208 0 return $msg;
209 }
210 0 $self->{'client'} = $client;
211 0 ▶ if (defined($key = $client->{'key'}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined($key = $client->{"key"}) and defined($class = $client->{"encryption"})) 0 0 0
Condition0%0/3
defined($key = $client->{"key"}) and defined($class = $client->{"encryption"})
!ll&&!rl&&r
000
MC/DC0%0/2
defined($key = $client->{"key"}) and defined($class = $client->{"encryption"})
defined($key = $client->{"key"}) defined($class = $client->{"encryption"})
Truth table0%0/3
A and B
A= defined($key = $client->{"key"})B= defined($class = $client->{"encryption"})
ABresult
0X0
100
111
212 defined($class = $client->{'encryption'})) {
213 0 my ($module);
214 0 ▶ if (!defined($module = $client->{'encryptModule'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($module = $client->{"encryptModule"})) 0 0 0
215 0 $module = $class;
216 }
217 0 ($self->{'cipher'}) = eval qq{
218 use $module;
219 new $class(pack("H*", \$key));
220 };
221 0 $self->Log('debug', "Using encryption: " . $self->{'cipher'});
222  
223 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
224 0 my $msg = "Cannot create cipher object: $@";
225 0 $self->Log('err', $msg);
226 0 return $msg;
227 }
228 }
229 0 last;
230 }
231 }
232 2 ▶ if ($self->{'configFile'} && !$self->{'client'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"configFile"} and not $self->{"client"}) 0 2 2
Condition33%1/3
$self->{"configFile"} and not $self->{"client"}
!ll&&!rl&&r
200
MC/DC0%0/2
$self->{"configFile"} and not $self->{"client"}
$self->{"configFile"} not $self->{"client"}
Truth table33%1/3
A and not(B)
A= $self->{"configFile"}B= not $self->{"client"}
ABresult
0X0
100
111
233 0 my $msg = sprintf("Access not permitted from %s, %s",
234 $sock->sockhost, $sock->sockport);
235 0 $self->Log('err', $msg);
236 0 return $msg;
237 }
238  
239 2 $self->Log('notice', sprintf("Accepting connect from %s, port %s",
240 $sock->sockhost, $sock->sockport));
241  
242 #
243 # Ok, the client is allowed to connect. Create Storable
244 # objects and wait for the login message.
245 #
246 2 ▶ if ($self->_HaveOoStorable) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_HaveOoStorable) { } 0 2 2
247 0 $self->{'io'} = Storable->new('file' => *{$sock}{IO},
248 0 'crypt' => $self->{'cipher'},
249 'netorder' => 1,
250 'forgive_me' => 1);
251 0 ▶ if (!defined($self->{'io'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"io"}) 0 0 0
252 0 my $msg = "Cannot create Storable object for read: $!";
253 0 $self->Log('err', $msg);
254 0 return $msg;
255 }
256 } else {
257 2 $self->{'file'} = $sock;
258 }
259  
260 2 ▶ if ($self->{'debug'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 2 0 2
261 2 $self->Log('debug', "$logClass: Waiting for client to log in.");
262 }
263  
264 2 my $loginMsg;
265 2 $loginMsg = $self->_Retrieve();
266 2 ▶ if (!defined($loginMsg)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $loginMsg) 0 2 2
267 0 my $msg = "Error while logging in: " . $self->error;
268 0 $self->Log('err', $msg);
269 0 return $msg;
270 }
271 2 ▶ if (ref($loginMsg) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $loginMsg ne "ARRAY") 0 2 2
272 0 my $msg = "Error while logging in: Expected array.";
273 0 $self->Log('err', $msg);
274 0 return $msg;
275 }
276  
277 ($self->{'application'}, $self->{'version'}, $self->{'user'},
278 2 $self->{'password'}) = @$loginMsg;
279 2 ▶ if ($self->{'debug'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 2 0 2
280 $self->Log('debug', "$logClass: Client logs in: "
281 . $self->{'application'}
282 . " " . $self->{'version'} . " "
283 2 ▶ . ($self->{'user'} || ''));
Condition50%1/2
$self->{'user'} || ''
l!l
20
MC/DC0%0/1
$self->{'user'} || ''
$self->{'user'}
Truth table50%1/2
A
A= $self->{'user'}
Aresult
11
00
284 }
285 2 ▶ if (!defined($self->{'application'}) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"application"} and defined $self->{"version"}) 0 2 2
Condition33%1/3
defined $self->{"application"} and defined $self->{"version"}
!ll&&!rl&&r
002
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"}
ABresult
0X0
100
111
286 !defined($self->{'version'})) {
287 0 my $msg = "Protocol error while logging in";
288 0 $self->Log('err', $msg);
289 0 return $msg;
290 }
291  
292 2 $self->{'sock'} = $sock;
293 2 $self;
294 }
295  
296  
297 ############################################################################
298 #
299 # Name: Accept, Deny
300 #
301 # Purpose: Methods for accepting or denying a connection
302 #
303 # Inputs: $con - connection object
304 # $msg - Message being sent to the client
305 #
306 # Returns: TRUE for succcess, FALSE otherwise; you might consult
307 # the method $con->error in that case.
308 #
309 ############################################################################
310  
311 2 ▶sub Accept($$) {
Subroutine Accept: called CC=1 SCAR=0.0
Pod documented
312 2 my ($self, $msg) = @_;
313 2 $self->Log('debug', "Accepting client.\n");
314 2 $self->_Store([1, $msg]);
315 }
316  
317 0 ▶sub Deny($$) {
Subroutine Deny: not called CC=1 SCAR=6.9
Pod documented
318 0 my ($self, $msg) = @_;
319 0 $self->Log('debug', "Denying client.\n");
320 0 $self->_Store([0, $msg]);
321 }
322  
323 36 ▶sub error ($) { my $self = shift; $self->{'error'}; }
Subroutine error: called CC=1 SCAR=0.0
Pod undocumented
324  
325  
326 ############################################################################
327 #
328 # Name: Loop
329 #
330 # Purpose: Process client requests
331 #
332 # Inputs: $con - connection object
333 #
334 # Returns: TRUE, if a client request was successfully processed,
335 # FALSE otherwise in which case $con->error is set
336 #
337 ############################################################################
338  
339 24 ▶sub Loop ($) {
Subroutine Loop: called CC=16 SCAR=33.4
Pod documented
340 24 my($self) = shift;
341 24 my($command, $commandRef);
342 24 my(@result);
343  
344 24 ▶ if ($self->{'sock'}->eof()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sock"}->eof) 0 24 24
345 0 $self->{'error'} = "Cannot talk to Client: EOF";
346 0 $self->Log('err', $self->error);
347 0 return 0;
348 }
349  
350 24 my $msg;
351 24 $msg = $self->_Retrieve();
352 24 ▶ if (!defined($msg)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $msg) 0 24 24
353 $self->{'error'} = "Error while reading client request: "
354 0 . $self->{'error'};
355 0 $self->Log('err', $self->error);
356 0 return 0;
357 }
358 24 my $ok = 0;
359 24 ▶ if (ref($msg) ne 'ARRAY') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $msg ne 'ARRAY') { } 0 24 24
elsif (not defined($command = shift @$msg)) { } 0 24 24
elsif (not defined($commandRef = $self->{'funcTable'}{$command})) { } 2 22 24
360 0 $self->{'error'} = "Error in request data: Expected array.";
361 } elsif (!defined($command = shift @$msg)) {
362 0 $self->{'error'} = "Error in request data: Missing command";
363 } elsif (!defined($commandRef = $self->{'funcTable'}->{$command})) {
364 2 $self->{'error'} = "Unknown command ($command)";
365 } else {
366 22 my($code);
367 22 $code = $commandRef->{'code'};
368 22 ($ok, @result) = eval '&$code($self, $commandRef, @$msg)';
369 22 ▶ if ($@ ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ ne '') { } 0 22 22
370 0 $ok = 0;
371 0 $self->{'error'} = "Function evaluation failed: $@";
372 } else {
373 22 ▶ if (!defined($ok)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ok) 0 22 22
374 0 $ok = 0;
375 }
376 22 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ok) { } 2 20 22
377 2 ▶ if (@result) {
Branch: 1 branch
BranchTrueFalseTotal
if (@result) { } 2 0 2
378 2 $self->{'error'} = shift @result;
379 } else {
380 0 $self->{'error'} = "Unknown error";
381 }
382 } else {
383 20 $self->{'error'} = '';
384 }
385 }
386 }
387  
388 24 ▶ if ($self->error) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->error) { } 4 20 24
elsif ($self->{'debug'}) { } 20 0 20
389 4 $self->Log('err', "Client Request -> error " . $self->error);
390 4 $ok = 0;
391 4 @result = ($self->error);
392 } elsif ($self->{'debug'}) {
393 20 $self->Log('debug', "$logClass: Client requested $command -> ok");
394 }
395  
396 24 ▶ if (scalar(@result) == 1 && !defined($result[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @result == 1 and not defined $result[0]) { } 2 22 24
Condition100%3/3
scalar @result == 1 and not defined $result[0]
!ll&&!rl&&r
6162
MC/DC100%2/2
scalar @result == 1 and not defined $result[0]
scalar @result == 1 not defined $result[0]
Truth table100%3/3
A and not(B)
A= scalar @result == 1B= not defined $result[0]
ABresult
0X0
100
111
397 # If we'd simply use @result now, this would give a warning
398 # "Use of uninitialized value"; even worse, the returned
399 # result would differ from the expected.
400 2 ▶ if (!$self->_Store([$ok, undef])) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_Store([$ok, undef])) 0 2 2
401 0 my $error = $self->error;
402 0 $self->Log('err', "Error while replying client: $error");
403 0 $ok = 0;
404 }
405 } else {
406 22 ▶ if (!$self->_Store([$ok, @result])) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_Store([$ok, @result])) 0 22 22
407 0 my $error = $self->error;
408 0 $self->Log('err', "Error while replying client: $error");
409 0 $ok = 0;
410 }
411 }
412  
413 24 return $ok;
414 }
415  
416  
417 ############################################################################
418 #
419 # Name: Encrypt
420 #
421 # Purpose: Get or set the current encryption mode
422 #
423 # Inputs: $self - client object
424 # $crypt - encryption object
425 #
426 # Returns: current encryption object; 'undef' for no encryption
427 #
428 ############################################################################
429  
430 0 ▶sub Encrypt ($;$) {
Subroutine Encrypt: not called CC=4 SCAR=30.0
Pod documented
431 0 my ($self, $crypt) = @_;
432 0 ▶ if (@_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) 0 0 0
433 0 ▶ if ($self->_HaveOoStorable) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_HaveOoStorable) { } 0 0 0
434 0 $self->{'io'}->{'crypt'} = $crypt;
435 } else {
436 0 $self->{'cipher'} = $crypt;
437 }
438 }
439 0 ▶ $self->_HaveOoStorable ? $self->{'io'}->{'crypt'} : $self->{'cipher'};
Branch: 1 branch
BranchTrueFalseTotal
$self->_HaveOoStorable ? : 0 0 0
440 }
441  
442  
443 ############################################################################
444 #
445 # Name: NewHandle, UseHandle, StoreHandle, CallMethod,
446 # DestroyHandle
447 #
448 # Purpose: Support functions for working with objects
449 #
450 # Inputs: $con - server object
451 # $ref - hash reference to the entry in $con's function
452 # table being currently executed; this *must* have
453 # an attribute 'handles' which should be a reference
454 # to a hash array which is part of the server
455 # functions local variables; so you are safe in
456 # a multithreaded environment.
457 # other input, depending on the method
458 #
459 # Returns: All functions guarantee that $con->error is empty in
460 # case of success and nonempty otherwise. StoreHandle
461 # guarantees to return 'undef' for error and a
462 # defined() value for success; so does UseHandle, at
463 # least as long as you don't feed 'undef' objects
464 # into 'StoreHandle'. This is guaranteed by 'NewHandle',
465 # which satisfies the same behaviour. The results of
466 # CallMethod() are unpredictable.
467 #
468 ############################################################################
469  
470 12 ▶sub UseHandle ($$$) {
Subroutine UseHandle: called CC=5 SCAR=17.4
Pod documented
471 12 my ($con, $ref, $objectHandle) = @_;
472 12 my ($hRef);
473 12 ▶ if (!defined($hRef = $ref->{'handles'}) || ref($hRef) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined($hRef = $ref->{"handles"}) or ref $hRef ne "HASH") 0 12 12
Condition33%1/3
not defined($hRef = $ref->{"handles"}) or ref $hRef ne "HASH"
l!l&&r!l&&!r
0012
MC/DC0%0/2
not defined($hRef = $ref->{"handles"}) or ref $hRef ne "HASH"
not defined($hRef = $ref->{"handles"}) ref $hRef ne "HASH"
Truth table33%1/3
not(A) or B
A= not defined($hRef = $ref->{"handles"})B= ref $hRef ne "HASH"
ABresult
1X1
011
000
474 0 $con->{'error'} = "Mising 'handles' attribute on server";
475 0 return;
476 }
477 12 ▶ if (!defined($objectHandle) || !exists($hRef->{$objectHandle})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $objectHandle and exists $hRef->{$objectHandle}) 2 10 12
Condition66%2/3
defined $objectHandle and exists $hRef->{$objectHandle}
!ll&&!rl&&r
0210
MC/DC50%1/2
defined $objectHandle and exists $hRef->{$objectHandle}
defined $objectHandle exists $hRef->{$objectHandle}
Truth table66%2/3
A and B
A= defined $objectHandleB= exists $hRef->{$objectHandle}
ABresult
0X0
100
111
478 2 $con->{'error'} = "Unknown object handle";
479 2 return;
480 }
481 10 $con->{'error'} = '';
482 10 $hRef->{$objectHandle};
483 }
484  
485 2 ▶sub DestroyHandle ($$$) {
Subroutine DestroyHandle: called CC=4 SCAR=17.3
Pod undocumented
486 2 my ($con, $ref, $objectHandle) = @_;
487 2 my ($hRef);
488 2 ▶ if (!defined($hRef = $ref->{'handles'}) || ref($hRef) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined($hRef = $ref->{"handles"}) or ref $hRef ne "HASH") 0 2 2
Condition33%1/3
not defined($hRef = $ref->{"handles"}) or ref $hRef ne "HASH"
l!l&&r!l&&!r
002
MC/DC0%0/2
not defined($hRef = $ref->{"handles"}) or ref $hRef ne "HASH"
not defined($hRef = $ref->{"handles"}) ref $hRef ne "HASH"
Truth table33%1/3
not(A) or B
A= not defined($hRef = $ref->{"handles"})B= ref $hRef ne "HASH"
ABresult
1X1
011
000
489 0 $con->{'error'} = "Mising 'handles' attribute on server";
490 0 return 0;
491 }
492 2 ▶ if (!exists($hRef->{$objectHandle})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $hRef->{$objectHandle}) 0 2 2
493 0 $con->{'error'} = "Unknown object handle";
494 0 return 0;
495 }
496 2 delete $hRef->{$objectHandle};
497 2 1;
498 }
499  
500 12 ▶sub CallMethod ($$@) {
Subroutine CallMethod: called CC=6 SCAR=19.2
Pod documented
501 12 my ($con, $ref, $objectHandle, $method, @arg) = @_;
502 12 my ($objectRef) = UseHandle($con, $ref, $objectHandle);
503 12 my (@result);
504  
505 12 ▶ if (!defined($objectRef)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $objectRef) 2 10 12
506 2 $con->{'error'} = "Illegal object handle";
507 2 return(0, $con->error);
508 }
509 10 ▶ if ($method eq 'DESTROY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq 'DESTROY') { } 2 8 10
510 2 ▶ if (!DestroyHandle($con, $ref, $objectHandle)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&DestroyHandle($con, $ref, $objectHandle)) 0 2 2
511 0 return (0, $con->error);
512 }
513 } else {
514 8 ▶ if (!$objectRef->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($objectRef->can($method)) 0 8 8
515 0 $con->{'error'} = "Unknown method: $method";
516 0 return (0, $con->error);
517 }
518 8 (@result) = eval '$objectRef->' . $method . '(@arg)';
519 8 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 8 8
520 0 $con->{'error'} = "Error while executing method: $@";
521 0 return (0, $con->error);
522 }
523 }
524 10 $con->{'error'} = '';
525 10 (1, @result);
526 }
527  
528 2 ▶sub StoreHandle ($$$) {
Subroutine StoreHandle: called CC=4 SCAR=15.5
Pod documented
529 2 my ($con, $ref, $objectRef) = @_;
530 2 my ($hRef);
531 2 ▶ if (!defined($hRef = $ref->{'handles'}) || ref($hRef) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined($hRef = $ref->{"handles"}) or ref $hRef ne "HASH") 0 2 2
Condition33%1/3
not defined($hRef = $ref->{"handles"}) or ref $hRef ne "HASH"
l!l&&r!l&&!r
002
MC/DC0%0/2
not defined($hRef = $ref->{"handles"}) or ref $hRef ne "HASH"
not defined($hRef = $ref->{"handles"}) ref $hRef ne "HASH"
Truth table33%1/3
not(A) or B
A= not defined($hRef = $ref->{"handles"})B= ref $hRef ne "HASH"
ABresult
1X1
011
000
532 0 $con->{'error'} = "Mising 'handles' attribute on server";
533 0 return;
534 }
535 2 ▶ my ($num) = exists($hRef->{'num'}) ? $hRef->{'num'} : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $hRef->{'num'} ? : 0 2 2
536 2 $hRef->{'num'} = ++$num;
537 2 $hRef->{$num} = $objectRef;
538 2 $con->{'error'} = '';
539 2 $num;
540 }
541  
542 2 ▶sub NewHandle ($$$@) {
Subroutine NewHandle: called CC=7 SCAR=24.0
Pod documented
543 2 my ($con, $ref, $classWanted, @arg) = @_;
544 2 my ($lRef) = $ref->{'classes'};
545  
546 # Check, if access to this class is permitted
547 2 my $class;
548 2 foreach $class (@$lRef) {
549 2 ▶ if ($class eq $classWanted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq $classWanted) 2 0 2
550 # It is, create the method
551 2 my $command = $class . '->new(@arg)';
552 2 my ($object) = eval $command;
553 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
554 0 $con->{'error'} = $@;
555 0 return (0, $@);
556 }
557 2 ▶ if (!defined($object)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $object) 0 2 2
558 0 $con->{'error'} = ' Failed to create object, unknown error';
559 0 return (0, $con->error);
560 }
561 2 my $handle = StoreHandle($con, $ref, $object);
562 2 ▶ if ($con->error || !defined($handle)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($con->error or not defined $handle) 0 2 2
Condition33%1/3
$con->error or not defined $handle
l!l&&r!l&&!r
002
MC/DC0%0/2
$con->error or not defined $handle
$con->error not defined $handle
Truth table33%1/3
A or not(B)
A= $con->errorB= not defined $handle
ABresult
1X1
011
000
563 0 return(0, $con->error);
564 }
565 2 return (1, $handle);
566 }
567 }
568 0 $con->{'error'} = "Not permitted to create objects of class $classWanted";
569 0 (0, $con->{'error'});
570 }
571  
572 # Autoload methods go after =cut, and are processed by the autosplit program.
573  
574 7 1;
575 __END__
↑ Summary RPC/pClient.pm »