XDR/RPC.pm

filter: Statementstmt 88.6% 47 / 53 Branchbran 80.0% 16 / 20 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 81.8% 9 / 11 Podpod 0.0% 0 / 7 totaltotal 80.2% 77 / 96 CC 12 SCAR 16.0
CC
12
Cov
87%
args
9.1
decode
4.0
cred
2.0
CRAP 5.0
« XDR/RPC/Reply.pm ↑ Summary XDR/Decode.pm »
1 # RPC.pm - base class for SunRPC packets
2 # Copyright (C) 2000 Mountain View Data, Inc.
3 # Written by Gordon Matzigkeit <gord@fig.org>, 2000-12-16
4 #
5 # This file is part of Perl XDR.
6 #
7 # Perl XDR is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # Perl XDR is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 # USA
21  
22 package XDR::RPC;
23 # [guilt]
24 # [maint
25 # File: RPC.pm
26 # Summary: base class for SunRPC packets
27 # Package: Perl XDR
28 # Owner: Mountain View Data, Inc.
29 # Years: 2000
30 # Author: Gordon Matzigkeit
31 # Contact: <gord@fig.org>
32 # Date: 2000-12-16
33 # License: GPL]
34 # [clemency]
35  
36 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 3 ▶use XDR ':msg_type';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 3 ▶use XDR::Decode;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 sub XID () {0}
43 sub PRIVATE () {1}
44 sub ARGS () {2}
45 sub CRED () {3}
46 sub VERF () {4}
47 sub COOKED_ARGS () {5}
48  
49 sub new
50 10 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
51 10 my ($type, $xid, $private, $args, $cred, $verf) = @_;
52 10 return bless [$xid, $private, $args, $cred, $verf], $type;
53 }
54  
55  
56 sub xid
57 15 ▶{
Subroutine xid: called CC=1 SCAR=0.0
Pod undocumented
58 15 my ($self) = @_;
59 15 return $self->[XID];
60 }
61  
62  
63 sub private
64 22 ▶{
Subroutine private: called CC=1 SCAR=0.0
Pod undocumented
65 22 my ($self) = @_;
66 22 return $self->[PRIVATE];
67 }
68  
69  
70 sub cred
71 0 ▶{
Subroutine cred: not called CC=1 SCAR=6.9
Pod undocumented
72 0 my ($self) = @_;
73 0 return $self->[CRED];
74 }
75  
76  
77 sub verf
78 0 ▶{
Subroutine verf: not called CC=1 SCAR=6.9
Pod undocumented
79 0 my ($self) = @_;
80 0 return $self->[VERF];
81 }
82  
83  
84 # Unpack the arguments to or result from an RPC.
85 sub args
86 8 ▶{
Subroutine args: called CC=9 SCAR=22.1
Pod undocumented
87 8 my ($self, $callrep, @proto) = @_;
88  
89 8 ▶ if ($#proto < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($#proto < 0) 2 6 8
90 {
91 # Return the raw arguments...
92 2 ▶ return $self->[ARGS] if (! defined $callrep);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $callrep 2 0 2
93  
94 # Or something from the last cooked ones.
95 0 return $self->[COOKED_ARGS]->[$callrep];
96 }
97 6 my ($dec) = XDR::Decode->new ($self->[ARGS]);
98  
99 6 my (@args, $i);
100 6 ▶ for ($i = 0; $i <= $#proto; $i ++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#proto) 8 6 14
101 {
102 8 my ($type, $name) = split (/ /, $proto[$i]);
103 8 my $tname = $type;
104 8 ▶ while (! ref $type && defined $callrep->{TYPES}->{$type})
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $type and defined $callrep->{"TYPES"}{$type}) 4 8 12
Condition100%3/3
not ref $type and defined $callrep->{"TYPES"}{$type}
!ll&&!rl&&r
354
MC/DC100%2/2
not ref $type and defined $callrep->{"TYPES"}{$type}
not ref $type defined $callrep->{"TYPES"}{$type}
Truth table100%3/3
not(A) and B
A= not ref $typeB= defined $callrep->{"TYPES"}{$type}
ABresult
0X0
100
111
105 {
106 4 $tname = $type;
107 4 $type = $callrep->{TYPES}->{$type};
108 }
109  
110 8 ▶ if (ref $type)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $type) { } 3 5 8
111 {
112 # Decode an interface-defined structure.
113 3 push (@args, eval "\$callrep->struct ('$tname', \$dec)");
114 }
115 else
116 {
117 # Decode a basic type.
118 5 push (@args, eval "\$dec->$type;");
119 }
120 8 ▶ croak $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 8 8
121 }
122  
123 6 my $leftlen = length ($dec->buffer (1));
124 6 ▶ croak "$leftlen too many bytes in RPC arguments"
Branch: 1 branch
BranchTrueFalseTotal
if $leftlen > 0 0 6 6
125 if ($leftlen > 0);
126  
127 # Cache the decoded values.
128 6 $self->[COOKED_ARGS] = \@args;
129 6 return @args;
130 }
131  
132  
133 # Unpack the buffer as if it is an RPC.
134 sub decode
135 10 ▶{
Subroutine decode: called CC=4 SCAR=13.9
Pod undocumented
136 10 my ($type, $dec) = @_;
137  
138 10 ▶ $dec = XDR::Decode->new ($dec)
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($dec, "XDR::Decode") 8 2 10
139 if (! UNIVERSAL::isa ($dec, 'XDR::Decode'));
140  
141 10 my ($xid) = $dec->unsigned;
142 10 my ($msg_type) = $dec->unsigned;
143  
144 10 ▶ if ($msg_type == CALL)
Branch: 2 branches
BranchTrueFalseTotal
if ($msg_type == 0) { } 7 3 10
elsif ($msg_type == 1) { } 3 0 3
145 {
146 7 require 'XDR/RPC/Call.pm';
147 7 return XDR::RPC::Call->finish_decode ($dec, $xid);
148 }
149 elsif ($msg_type == REPLY)
150 {
151 3 require 'XDR/RPC/Reply.pm';
152 3 return XDR::RPC::Reply->finish_decode ($dec, $xid);
153 }
154 else
155 {
156 0 croak "Unrecognized msg_type $msg_type";
157 }
158 }
159  
160  
161 3 1;
« XDR/RPC/Reply.pm ↑ Summary XDR/Decode.pm »