blib/lib/OpenCA/Configuration.pm

filter: Statementstmt 5.7% 6 / 105 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 11.1% 1 / 9 Podpod 0.0% 0 / 8 totaltotal 3.6% 7 / 190 CC 28 SCAR 36.4
CC
28
Cov
4%
parsecfg
56.0
checkParam
56.0
loadCfg
42.0
CRAP 38.2
↑ Summary
1 ## OpenCA::Configuration.pm
2 ##
3 ## Copyright (C) 1998-1999 Massimiliano Pala (madwolf@openca.org)
4 ## All rights reserved.
5 ##
6 ## This library is free for commercial and non-commercial use as long as
7 ## the following conditions are aheared to. The following conditions
8 ## apply to all code found in this distribution, be it the RC4, RSA,
9 ## lhash, DES, etc., code; not just the SSL code. The documentation
10 ## included with this distribution is covered by the same copyright terms
11 ##
12 ## Copyright remains Massimiliano Pala's, and as such any Copyright notices
13 ## in the code are not to be removed.
14 ## If this package is used in a product, Massimiliano Pala should be given
15 ## attribution as the author of the parts of the library used.
16 ## This can be in the form of a textual message at program startup or
17 ## in documentation (online or textual) provided with the package.
18 ##
19 ## Redistribution and use in source and binary forms, with or without
20 ## modification, are permitted provided that the following conditions
21 ## are met:
22 ## 1. Redistributions of source code must retain the copyright
23 ## notice, this list of conditions and the following disclaimer.
24 ## 2. Redistributions in binary form must reproduce the above copyright
25 ## notice, this list of conditions and the following disclaimer in the
26 ## documentation and/or other materials provided with the distribution.
27 ## 3. All advertising materials mentioning features or use of this software
28 ## must display the following acknowledgement:
29 ## "This product includes OpenCA software written by Massimiliano Pala
30 ## (madwolf@openca.org) and the OpenCA Group (www.openca.org)"
31 ## 4. If you include any Windows specific code (or a derivative thereof) from
32 ## some directory (application code) you must include an acknowledgement:
33 ## "This product includes OpenCA software (www.openca.org)"
34 ##
35 ## THIS SOFTWARE IS PROVIDED BY OPENCA DEVELOPERS ``AS IS'' AND
36 ## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
39 ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 ## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 ## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 ## SUCH DAMAGE.
46 ##
47 ## The licence and distribution terms for any publically available version or
48 ## derivative of this code cannot be changed. i.e. this code cannot simply be
49 ## copied and put under another distribution licence
50 ## [including the GNU Public Licence.]
51 ##
52 ## Porpouse:
53 ## =========
54 ##
55 ## Get easily configuration parameters passed into a config file
56 ##
57 ## Status:
58 ## =======
59 ##
60 ## Started: 10/11/1998
61 ## Last Modified: 28/04/1999
62 ##
63  
64 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
65  
66 package OpenCA::Configuration;
67  
68 1 $OpenCA::Configuration::VERSION = '1.5.3';
69  
70 # Preloaded methods go here.
71  
72 ## Define Error Messages for the Configuration Manager Errors
73 1 my %params = {
74 cnfLines => undef,
75 cnfDB => undef,
76 };
77  
78 ## Create an instance of the Class
79 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
80 0 my $that = shift;
81 0 ▶ my $class = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
82  
83 0 my $self = {
84 %params,
85 };
86  
87 0 bless $self, $class;
88  
89 0 my @keys = @_ ;
90 0 my $fileName = $keys[0];
91  
92 0 ▶ if( defined $fileName and $fileName ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fileName and $fileName ne "") 0 0 0
Condition0%0/3
defined $fileName and $fileName ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $fileName and $fileName ne ""
defined $fileName $fileName ne ""
Truth table0%0/3
A and B
A= defined $fileNameB= $fileName ne ""
ABresult
0X0
100
111
93 0 my $ret = $self->loadCfg ( $fileName );
94 0 ▶ return undef if ( not $ret );
Branch: 1 branch
BranchTrueFalseTotal
unless $ret 0 0 0
95 }
96  
97 0 return $self;
98 }
99  
100 ## Configuration Manager Functions
101 0 ▶sub loadCfg {
Subroutine loadCfg: not called CC=6 SCAR=37.4
Pod undocumented
102 0 my $self = shift;
103 0 my @keys = @_ ;
104  
105 0 my $temp;
106 my $temp2;
107 0 my @configLines;
108 0 my $sameLine;
109  
110 0 my $fileName = $keys[0];
111  
112 0 $sameLine = 0;
113 0 $temp2 = "";
114 0 ▶ open( FD, "$fileName" ) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
open FD, "$fileName" or return undef 0 0 0
115 0 ▶ while( $temp = <FD> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($temp = readline FD)) 0 0 0
116 0 ▶ if( $temp =~ /\\\n$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($temp =~ /\\\n$/) { } 0 0 0
117 0 $temp =~ s/\\\n$//;
118 0 $temp2 .= $temp;
119 0 $sameLine = 1;
120 } else {
121 0 ▶ if( $sameLine == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sameLine == 1) 0 0 0
122 0 $temp2 .= $temp;
123 0 $temp = $temp2;
124 0 $sameLine = 0;
125 0 $temp2 = "";
126 }
127  
128 0 $sameLine = 0;
129 0 push ( @configLines, $temp);
130 }
131 }
132 0 close(FD);
133  
134 0 ▶ if( $self->parsecfg( @configLines ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parsecfg(@configLines)) { } 0 0 0
135 0 $self->{cnfLines} = [ @configLines ];
136 0 return 1;
137 } else {
138 0 return 0;
139 }
140 }
141  
142 ## Parsing Function
143 0 ▶sub parsecfg {
Subroutine parsecfg: not called CC=7 SCAR=40.3
Pod undocumented
144 0 my $self = shift;
145 0 my @keys = @_;
146  
147 0 my @configDB = ();
148 0 my $num = -1;
149 0 my $line;
150
151 0 foreach $line (@keys) {
152 0 my $paramName;
153 my %par;
154 0 my @values;
155  
156 ## Take count of Config Line Number
157 0 $num++;
158  
159 ## Trial line and discard Comments
160 0 chop($line);
161 ## next if ($line =~ /\#.*/)||($line eq "")||($line =~ /HASH.*/);
162 0 ▶ next if ($line =~ /\#.*/)||($line =~ /^\s*[\n\r]*$/)||($line =~ /HASH.*/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\#.*/ or $line =~ /^\s*[\n\r]*$/ or $line =~ /HASH.*/ 0 0 0
Condition0%0/6
$line =~ /\#.*/ or $line =~ /^\s*[\n\r]*$/ or $line =~ /HASH.*/
l!l&&r!l&&!r
000
$line =~ /\#.*/ or $line =~ /^\s*[\n\r]*$/
l!l&&r!l&&!r
000
MC/DC0%0/3
$line =~ /\#.*/ or $line =~ /^\s*[\n\r]*$/ or $line =~ /HASH.*/
$line =~ /\#.*/ $line =~ /^\s*[\n\r]*$/ $line =~ /HASH.*/
Truth table0%0/4
A or B or C
A= $line =~ /\#.*/B= $line =~ /^\s*[\n\r]*$/C= $line =~ /HASH.*/
ABCresult
1XX1
01X1
0011
0000
163 0 $line =~ s/#.*//;
164 0 $line =~ s/^[\s]*//;
165 0 $line =~ s/(\r|\n)//g;
166  
167 ## Get the Parameter Name
168 0 ( $paramName ) =
169 ( $line =~ /([\S]+).*/ );
170  
171 ## Erase the parameter Name from the Line
172 0 $line =~ s/$paramName// ;
173  
174 0 @values = ();
175  
176 ## Start displacing command
177 0 ▶ while ( length($line) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $line > 0) 0 0 0
178 0 my ( $param, $match );
179  
180 ## Delete remaining Spaces
181 0 $line =~ s/^[\s]*//;
182  
183 0 ▶ if ( $line =~ /^\"/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\"/) { } 0 0 0
184 0 ( $param ) = ( $line =~ /^\"(.*?)\"/ );
185 0 $line =~ s/^\".*?\"//;
186 } else {
187 0 ( $param ) = ( $line =~ /^([\S]+)/ );
188 0 $line =~ s/^([\S]+)//;
189 };
190  
191 0 @values = ( @values, $param );
192
193 }
194  
195 ## Get the parameter set up
196 0 my $par = { NAME=>$paramName,
197 LINE_NUMBER=>$num,
198 VALUES=>[ @values ] };
199  
200 0 push ( @configDB, $par);
201 }
202  
203 0 $self->{cnfDB} = [ @configDB ];
204 0 return 1;
205 }
206  
207 ## Get Single Parameter
208 0 ▶sub getParam {
Subroutine getParam: not called CC=1 SCAR=6.9
Pod undocumented
209 0 my $self = shift;
210 0 my @keys = @_;
211  
212 0 return $self->getNextParam( NAME=>$keys[0],
213 LINE_NUMBER=>-1 );
214 };
215  
216 ## Get next Parameter
217 0 ▶sub getNextParam {
Subroutine getNextParam: not called CC=5 SCAR=34.0
Pod undocumented
218 0 my $self = shift;
219 0 my $k = { @_ };
220 0 my $par;
221  
222 0 ▶ return if( not ( $k->{NAME} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $k->{"NAME"} 0 0 0
223  
224 0 foreach $par ( @{$self->{cnfDB}} ) {
225 0 my $tmp = $par->{NAME};
226  
227 0 ▶ if( (lc( $tmp ) eq lc($k->{NAME})) and
Branch: 1 branch
BranchTrueFalseTotal
if (lc $tmp eq lc $k->{"NAME"} and $par->{"LINE_NUMBER"} > $k->{"LINE_NUMBER"}) 0 0 0
Condition0%0/3
lc $tmp eq lc $k->{"NAME"} and $par->{"LINE_NUMBER"} > $k->{"LINE_NUMBER"}
!ll&&!rl&&r
000
MC/DC0%0/2
lc $tmp eq lc $k->{"NAME"} and $par->{"LINE_NUMBER"} > $k->{"LINE_NUMBER"}
lc $tmp eq lc $k->{"NAME"} $par->{"LINE_NUMBER"} > $k->{"LINE_NUMBER"}
Truth table0%0/3
A and B
A= lc $tmp eq lc $k->{"NAME"}B= $par->{"LINE_NUMBER"} > $k->{"LINE_NUMBER"}
ABresult
0X0
100
111
228 ( $par->{LINE_NUMBER} > $k->{LINE_NUMBER}) ) {
229 0 return $par;
230 };
231 };
232  
233 0 return undef;
234 }
235  
236 0 ▶sub checkParam {
Subroutine checkParam: not called CC=7 SCAR=40.3
Pod undocumented
237 0 my $self = shift;
238 0 my $k = { @_ };
239 0 my ( $par, $pnum );
240  
241 0 ▶ return unless ( exists $k->{NAME} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $k->{"NAME"} 0 0 0
242  
243 0 $par = $self->getParam( $k->{NAME} );
244 0 ▶ return unless ( not ( keys %$par ));
Branch: 1 branch
BranchTrueFalseTotal
if keys %$par 0 0 0
245  
246 ## $pnum = $#($par->{VALUES});
247  
248 0 ▶ if( ($k->{MIN}) && ($pnum < $k->{MIN}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k->{"MIN"} and $pnum < $k->{"MIN"}) 0 0 0
Condition0%0/3
$k->{"MIN"} and $pnum < $k->{"MIN"}
!ll&&!rl&&r
000
MC/DC0%0/2
$k->{"MIN"} and $pnum < $k->{"MIN"}
$k->{"MIN"} $pnum < $k->{"MIN"}
Truth table0%0/3
A and B
A= $k->{"MIN"}B= $pnum < $k->{"MIN"}
ABresult
0X0
100
111
249 0 return $par->{LINE_NUMBER};
250 }
251  
252 0 ▶ if( ($k->{MAX}) && ($pnum > $k->{MAX}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k->{"MAX"} and $pnum > $k->{"MAX"}) 0 0 0
Condition0%0/3
$k->{"MAX"} and $pnum > $k->{"MAX"}
!ll&&!rl&&r
000
MC/DC0%0/2
$k->{"MAX"} and $pnum > $k->{"MAX"}
$k->{"MAX"} $pnum > $k->{"MAX"}
Truth table0%0/3
A and B
A= $k->{"MAX"}B= $pnum > $k->{"MAX"}
ABresult
0X0
100
111
253 0 return $par->{LINE_NUMBER};
254 }
255  
256 0 return 0;
257 }
258  
259 0 ▶sub checkConfig {
Subroutine checkConfig: not called CC=3 SCAR=24.8
Pod undocumented
260 0 my $self = shift;
261 0 my @keys = @_;
262 0 my ( $ret, $par );
263  
264 0 foreach $par ( @keys ) {
265 0 $ret = $self->ceckParam( $par );
266 0 ▶ return if ( not $ret);
Branch: 1 branch
BranchTrueFalseTotal
unless $ret 0 0 0
267 }
268  
269 0 return 0;
270 }
271  
272 0 ▶sub getVersion {
Subroutine getVersion: not called CC=1 SCAR=6.9
Pod undocumented
273 0 my $self = shift;
274  
275 0 return $OpenCA::Configuration::VERSION;
276 }
277  
278 1 1;
↑ Summary