blib/lib/TAP3/Tap3edit.pm

filter: Statementstmt 76.5% 215 / 281 Branchbran 66.4% 93 / 140 Conditioncond 51.7% 15 / 29 MC/DCmcdc 36.8% 7 / 19 Subroutinesub 87.1% 27 / 31 Podpod 0.0% 0 / 15 totaltotal 69.3% 357 / 515 CC 82 SCAR 31.6
CC
82
Cov
72%
_get_file_version
57.2
_select_asn_struct
36.7
bcd_to_asc
6.0
CRAP 23.6
↑ Summary
1 # Package Tap3edit (http://www.tap3edit.com)
2 # designed to decode, modify and encode Roaming GSM TAP/RAP/
3 # NRT files
4 #
5 # $Id: Tap3edit.pm,v 1.14 2012/05/11 00:47:07 javier Exp $
6 #
7 # Copyright (c) 2004-2012 Javier Gutierrez. All rights
8 # reserved.
9 # This program is free software; you can redistribute
10 # it and/or modify it under the same terms as Perl itself.
11 #
12 # This program contains TAP, RAP and NRTRDE ASN.1
13 # Specification. The ownership of the TAP/RAP/NRTRDE ASN.1
14 # Specifications belong to the GSM MoU Association
15 # (http://www.gsm.org) and should be used under following
16 # conditions:
17 #
18 # Copyright (c) 2000 GSM MoU Association. Restricted − Con­
19 # fidential Information. Access to and distribution of this
20 # document is restricted to the persons listed under the
21 # heading Security Classification Category*. This document
22 # is confidential to the Association and is subject to copy­
23 # right protection. This document is to be used only for
24 # the purposes for which it has been supplied and informa­
25 # tion contained in it must not be disclosed or in any other
26 # way made available, in whole or in part, to persons other
27 # than those listed under Security Classification Category*
28 # without the prior written approval of the Association. The
29 # GSM MoU Association (âAssociationâ) makes no representa­
30 # tion, warranty or undertaking (express or implied) with
31 # respect to and does not accept any responsibility for, and
32 # hereby disclaims liability for the accuracy or complete­
33 # ness or timeliness of the information contained in this
34 # document. The information contained in this document may
35 # be subject to change without prior notice.
36  
37  
38  
39 package TAP3::Tap3edit;
40  
41 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶use Convert::ASN1 qw(:io :debug); # Handler of ASN1 Codes. Should be installed first.
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47  
48 BEGIN {
49 1 ▶ use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 ▶ our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 $VERSION = "0.33";
52 }
53  
54  
55 sub new {
56 14 ▶ my $proto = shift;
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
57 14 ▶ my $class = ref($proto) || $proto ;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0140
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
58 14 my $self = {};
59 14 $self->{_filename} = undef;
60 14 $self->{_spec_file} = undef;
61 14 $self->{_supl_spec_file} = undef;
62 14 $self->{_asn} = Convert::ASN1->new();
63 14 $self->{_dic_decode} = {}; # Stores the file decode with $self->{_dic_asn}
64 14 $self->{_dic_asn} = $self->{_asn}; # Stores the ASN Specification
65 14 $self->{spec_path} = [ ( grep(-d $_, map(File::Spec->catdir($_, qw(TAP3 Spec)), @INC)), File::Spec->curdir) ];
66 14 $self->{_version} = undef;
67 14 $self->{_release} = undef;
68 14 $self->{_supl_version} = undef; # Tap version inside the RAP file
69 14 $self->{_supl_release} = undef; # Tap release inside the RAP file
70 14 $self->{_file_type} = undef; # TAP, RAP or NRT
71 14 $self->{error} = undef;
72 14 bless ($self, $class);
73 14 return $self;
74 }
75  
76  
77 #----------------------------------------------------------------
78 # Method: structure
79 # Description: Contains the structure of the TAP/RAP/NRT file
80 # into a HASH
81 # Parameters: N/A
82 # Returns: HASH
83 # Type: Public
84 # Restrictions: N/A
85 #----------------------------------------------------------------
86 sub structure {
87 14 ▶ my $self = shift;
Subroutine structure: called CC=2 SCAR=7.0
Pod undocumented
88 14 ▶ if (@_) { $self->{_dic_decode} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 0 14
89 14 return $self->{_dic_decode};
90 }
91  
92  
93 #----------------------------------------------------------------
94 # Method: version
95 # Description: contains and updates the main version of the
96 # TAP/RAP/NRT file
97 # Parameters: N/A
98 # Returns: SCALAR: version number
99 # Type: Public
100 # Restrictions: N/A
101 #----------------------------------------------------------------
102 sub version {
103 14 ▶ my $self = shift;
Subroutine version: called CC=3 SCAR=12.3
Pod undocumented
104 14 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 0 14
105 14 ▶ if ( ! $self->{_version} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'_version'}) { } 14 0 14
106 14 $self->{_version} = shift ;
107 } else {
108 0 $self->{error}="The Version cannot be changed";
109 0 croak $self->error();
110 }
111 }
112 14 return $self->{_version};
113 }
114  
115  
116 #----------------------------------------------------------------
117 # Method: supl_version
118 # Description: contains and updates the suplementary version of the
119 # RAP file
120 # Parameters: N/A
121 # Returns: SCALAR: release number
122 # Type: Public
123 # Restrictions: Valid just for RAP files
124 #----------------------------------------------------------------
125 sub supl_version {
126 5 ▶ my $self = shift;
Subroutine supl_version: called CC=3 SCAR=12.3
Pod undocumented
127 5 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 5 0 5
128 5 ▶ if ( ! $self->{_supl_version} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'_supl_version'}) { } 5 0 5
129 5 $self->{_supl_version} = shift ;
130 } else {
131 0 $self->{error}="The Suplementary Version cannot be changed";
132 0 croak $self->error();
133 }
134 }
135 5 return $self->{_supl_version};
136 }
137  
138 #----------------------------------------------------------------
139 # Method: release
140 # Description: contains and updates the main release of the
141 # TAP/RAP/NRT file
142 # Parameters: N/A
143 # Returns: SCALAR: release number
144 # Type: Public
145 # Restrictions: N/A
146 #----------------------------------------------------------------
147 sub release {
148 14 ▶ my $self = shift;
Subroutine release: called CC=3 SCAR=12.3
Pod undocumented
149 14 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 0 14
150 14 ▶ if ( ! $self->{_release} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'_release'}) { } 14 0 14
151 14 $self->{_release} = shift ;
152 } else {
153 0 $self->{error}="The Release cannot be changed";
154 0 croak $self->error();
155 }
156 }
157 14 return $self->{_release};
158 }
159  
160  
161 #----------------------------------------------------------------
162 # Method: supl_release
163 # Description: contains and updates the suplementary release of the
164 # RAP file
165 # Parameters: N/A
166 # Returns: SCALAR: release number
167 # Type: Public
168 # Restrictions: Valid just for RAP files
169 #----------------------------------------------------------------
170 sub supl_release {
171 5 ▶ my $self = shift;
Subroutine supl_release: called CC=3 SCAR=12.3
Pod undocumented
172 5 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 5 0 5
173 5 ▶ if ( ! $self->{_supl_release} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'_supl_release'}) { } 5 0 5
174 5 $self->{_supl_release} = shift ;
175 } else {
176 0 $self->{error}="The Suplementary Release cannot be changed";
177 0 croak $self->error();
178 }
179 }
180 5 return $self->{_supl_release};
181 }
182  
183 #----------------------------------------------------------------
184 # Method: file_type
185 # Description: contains and updates the type of the file
186 # the values can be: TAP/RAP/NRT.
187 # Parameters: N/A
188 # Returns: SCALAR: file type ("RAP","TAP","NRT")
189 # Type: Public
190 # Restrictions: N/A
191 #----------------------------------------------------------------
192 sub file_type {
193 119 ▶ my $self = shift;
Subroutine file_type: called CC=4 SCAR=15.0
Pod undocumented
194 119 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 105 119
195 14 ▶ if ( ! $self->{_file_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'_file_type'}) { } 14 0 14
196 14 my $file_type = shift;
197  
198 14 ▶ unless ($file_type =~ /^[TR]AP$|^NRT$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file_type =~ /^[TR]AP$|^NRT$/) 0 14 14
199 0 croak("Unsupported File Type $file_type");
200 }
201  
202 14 $self->{_file_type} = $file_type ;
203 } else {
204 0 $self->{error}="The File Type cannot be changed";
205 0 croak $self->error();
206 }
207 }
208 119 return $self->{_file_type};
209 }
210  
211  
212 #----------------------------------------------------------------
213 # Method: get_info
214 # Description: gets the basic information of the TAP/RAP/NRT
215 # files: version, release, supl_version (for RAP
216 # files), supl_release (for RAP files), file type.
217 # Parameters: filename
218 # Returns: N/A
219 # Type: Public
220 # Restrictions: N/A
221 #----------------------------------------------------------------
222 sub get_info {
223 14 ▶ my $self = shift;
Subroutine get_info: called CC=2 SCAR=7.0
Pod undocumented
224 14 my $filename = shift;
225 14 $self->_filename($filename);
226 14 ▶ $self->_get_file_version || return undef ;
Branch: 1 branch
BranchTrueFalseTotal
$self->_get_file_version or return undef 0 14 14
227 }
228  
229  
230 #----------------------------------------------------------------
231 # Method: _filename
232 # Description: contains and updates the name of the TAP/RAP/NRT
233 # files
234 # Parameters: filename
235 # Returns: filename
236 # Type: Private
237 # Restrictions: N/A
238 #----------------------------------------------------------------
239 sub _filename {
240 70 ▶ my $self = shift;
Subroutine _filename: called CC=2 SCAR=6.9
241 70 ▶ if (@_) { $self->{_filename} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 42 28 70
242 70 return $self->{_filename};
243 }
244  
245  
246 #----------------------------------------------------------------
247 # Method: spec_file
248 # Description: contains and updates the name of the file
249 # with specifications ASN.1
250 # Parameters: filename of specifications ASN.1
251 # Returns: filename of specifications ASN.1
252 # Type: Public
253 # Restrictions: N/A
254 #----------------------------------------------------------------
255 sub spec_file {
256 98 ▶ my $self = shift;
Subroutine spec_file: called CC=2 SCAR=6.9
Pod undocumented
257 98 ▶ if (@_) { $self->{_spec_file} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 84 98
258 98 return $self->{_spec_file};
259 }
260  
261  
262 #----------------------------------------------------------------
263 # Method: supl_spec_file
264 # Description: contains and updates the name of the file
265 # with specifications ASN.1 for the version of
266 # the TAP file included in the RAP file.
267 # Parameters: filename of specifications ASN.1
268 # Returns: filename of specifications ASN.1
269 # Type: Public
270 # Restrictions: Valid just for RAP files
271 #----------------------------------------------------------------
272 sub supl_spec_file {
273 53 ▶ my $self = shift;
Subroutine supl_spec_file: called CC=2 SCAR=6.9
Pod undocumented
274 53 ▶ if (@_) { $self->{_supl_spec_file} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 5 48 53
275 53 return $self->{_supl_spec_file};
276 }
277  
278  
279 #----------------------------------------------------------------
280 # Method: _dic_decode
281 # Description: contains and updates the HASH which stores
282 # the decoded information from the TAP/RAP/NRT file.
283 # This variable is also used for the method:
284 # "structure".
285 # Parameters: HASH
286 # Returns: HASH
287 # Type: Private
288 # Restrictions: N/A
289 #----------------------------------------------------------------
290 sub _dic_decode {
291 14 ▶ my $self = shift;
Subroutine _dic_decode: called CC=2 SCAR=7.6
292 14 ▶ if (@_) { $self->{_dic_decode} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 14 14
293 14 return $self->{_dic_decode};
294 }
295  
296  
297 #----------------------------------------------------------------
298 # Method: _dic_asn
299 # Description: contains and updates the object used to store
300 # the tree of the specifictions ASN.1 starting
301 # from the DataInterChange/RapDataInterChange tag.
302 # Parameters: object
303 # Returns: object
304 # Type: Private
305 # Restrictions: N/A
306 #----------------------------------------------------------------
307 sub _dic_asn {
308 56 ▶ my $self = shift;
Subroutine _dic_asn: called CC=2 SCAR=6.9
309 56 ▶ if (@_) { $self->{_dic_asn} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 28 28 56
310 56 return $self->{_dic_asn};
311 }
312  
313  
314 #----------------------------------------------------------------
315 # Method: _asn
316 # Description: contains and updates the object used to store
317 # the constructor of Convert::ASN1
318 # Parameters: object
319 # Returns: object
320 # Type: Private
321 # Restrictions: N/A
322 #----------------------------------------------------------------
323 sub _asn {
324 28 ▶ my $self = shift;
Subroutine _asn: called CC=2 SCAR=7.6
325 28 ▶ if (@_) { $self->{_asn} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 28 28
326 28 return $self->{_asn};
327 }
328  
329  
330 #----------------------------------------------------------------
331 # Method: _asn_path
332 # Description: contains the list of PATH where
333 # to find the specifications ASN.1.
334 # The default values are "TAP3/Spec" from the insta-
335 # llation and "." (current directory). The used
336 # array (spec_path) can be updated with new PATHs
337 # Parameters: ARRAY
338 # Returns: ARRAY
339 # Type: Private
340 # Restrictions: N/A
341 #----------------------------------------------------------------
342 sub _asn_path {
343 19 ▶ my $self = shift;
Subroutine _asn_path: called CC=1 SCAR=0.0
344 19 return $self->{spec_path};
345 }
346  
347  
348  
349 #----------------------------------------------------------------
350 # Function: bcd_to_hexa
351 # Description: Converts the input binary format from the
352 # TAP/RAP/NRT files into Hexadecimal string.
353 # Parameters: binary_string
354 # Returns: hexadecimal value
355 # Type: Private
356 # Restrictions: N/A
357 #----------------------------------------------------------------
358 sub bcd_to_hexa
359 {
360 0 ▶ my $in=shift;
Subroutine bcd_to_hexa: not called CC=1 SCAR=6.9
Pod undocumented
361 0 unpack("H*",$in);
362 }
363  
364  
365 #----------------------------------------------------------------
366 # Function: bcd_to_asc
367 # Description: Converts the input binary format from the
368 # TAP/RAP/NRT files into decimal.
369 # Parameters: binary_string
370 # Returns: ascii value
371 # Type: Private
372 # Restrictions: N/A
373 #----------------------------------------------------------------
374 sub bcd_to_asc
375 {
376 0 ▶ my $in=shift;
Subroutine bcd_to_asc: not called CC=2 SCAR=17.9
Pod undocumented
377 0 my $out=0;
378 0 ▶ for (my $i=0;$i<length($in);$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $in) 0 0 0
379 0 $out.=sprintf("%03d", ord(substr($in,$i,1)));
380 }
381 0 return $out;
382 }
383  
384  
385  
386 #----------------------------------------------------------------
387 # Method: _get_file_version
388 # Description: sets the file version/release of the TAP/RAP/NRT
389 # file by matching patterns
390 # Parameters: N/A
391 # Returns: N/A
392 # Type: Private
393 # Restrictions: N/A
394 #----------------------------------------------------------------
395 sub _get_file_version
396 {
397 28 ▶ my $self=shift;
Subroutine _get_file_version: called CC=27 SCAR=40.5
398  
399 28 my $filename=$self->_filename;
400  
401 28 my $file_type=undef;
402 28 my $version=undef;
403 28 my $release=undef;
404 28 my $rap_version=undef;
405 28 my $rap_release=undef;
406 28 my $buf_in;
407  
408  
409 ##
410 ## 1. If we decode the file we just encoded the file type, version and release should be empty
411 ##
412  
413 28 $self->{_version} = undef;
414 28 $self->{_release} = undef;
415 28 $self->{_supl_version} = undef; # Tap version inside the RAP file
416 28 $self->{_supl_release} = undef; # Tap release inside the RAP file
417 28 $self->{_file_type}=undef;
418  
419  
420 ##
421 ## 2. We get the file_type, version and release by matching strings
422 ##
423  
424 28 ▶ open FILE, "<$filename" or do { $self->{error}="$! for file $filename" ; return undef };
Branch: 1 branch
BranchTrueFalseTotal
open FILE, "<$filename" or do { $self->{"error"} = "$! for file $filename"; return undef } 0 28 28
425 28 binmode FILE;
426  
427 # 1 Kb should be more than enough to find the Release and Version
428 28 read FILE, $buf_in, 1000;
429  
430 28 close FILE;
431  
432 28 $buf_in=unpack("H*", $buf_in);
433  
434  
435 ##
436 ## 3. Here we scan the buffer matching the patterns
437 ##
438  
439 28 ▶ while ($buf_in =~ /(?:
Branch: 1 branch
BranchTrueFalseTotal
if ($buf_in =~ /(?: (^61.+5f814405) (?# For Tap files) | (^62) (?# For Notification files) | (^7f8416) (?# For Rap files) | (^7f8417) (?# For Acknowledment files) | (?:5f814901)(..) (?# Will match: SpecificationVersionNumber ) | (?:5f813d01)(..) (?# Will match: ReleaseVersionNumber ) | (?:5f842001)(..) (?# Will match: RapSpecificationVersionNumber ) | (?:5f841f01)(..) (?# Will match: RapReleaseVersionNumber ) | (^61.+5f2901)(..) (?# For NRTRDE files, and SpecificationVersionNumber for NRTRDE) | (?:5f2501)(..) (?# Will match: ReleaseVersionNumber for NRTRDE ) | . )/gosx) 6090 28 6118
440 (^61.+5f814405) (?# For Tap files)
441 |
442 (^62) (?# For Notification files)
443 |
444 (^7f8416) (?# For Rap files)
445 |
446 (^7f8417) (?# For Acknowledment files)
447 |
448 (?:5f814901)(..) (?# Will match: SpecificationVersionNumber )
449 |
450 (?:5f813d01)(..) (?# Will match: ReleaseVersionNumber )
451 |
452 (?:5f842001)(..) (?# Will match: RapSpecificationVersionNumber )
453 |
454 (?:5f841f01)(..) (?# Will match: RapReleaseVersionNumber )
455 |
456 (^61.+5f2901)(..) (?# For NRTRDE files, and SpecificationVersionNumber for NRTRDE)
457 |
458 (?:5f2501)(..) (?# Will match: ReleaseVersionNumber for NRTRDE )
459 |
460 .
461 )/sgxo ) {
462 6090 ▶ if (defined $1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1) 0 6090 6090
463 0 $file_type="TAP";
464 }
465 6090 ▶ if (defined $2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $2) 16 6074 6090
466 16 $file_type="NOT";
467 }
468 6090 ▶ if (defined $3) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $3) 0 6090 6090
469 0 $file_type="RAP";
470 }
471 6090 ▶ if (defined $4) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $4) 10 6080 6090
472 10 $file_type="ACK";
473 }
474 6090 ▶ if (defined $5) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $5) 16 6074 6090
475 16 $version=ord(pack("H*",$5));
476 }
477 6090 ▶ if (defined $6) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $6) 16 6074 6090
478 16 $release=ord(pack("H*",$6));
479 }
480 6090 ▶ if (defined $7) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $7) 0 6090 6090
481 0 $rap_version=ord(pack("H*",$7));
482 }
483 6090 ▶ if (defined $8) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $8) 0 6090 6090
484 0 $rap_release=ord(pack("H*",$8));
485 }
486 6090 ▶ if (defined $9) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $9) 2 6088 6090
487 2 $file_type="NRT";
488 }
489 6090 ▶ if (defined $10) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $10) 2 6088 6090
490 2 $version=ord(pack("H*",$10));
491 }
492 6090 ▶ if (defined $11) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $11) 2 6088 6090
493 2 $release=ord(pack("H*",$11));
494 }
495 }
496  
497 ##
498 ## 4. According to what is found we set the file_type, version and release.
499 ##
500  
501 28 ▶ if ($file_type eq "TAP" or $file_type eq "NOT") {
Branch: 4 branches
BranchTrueFalseTotal
if ($file_type eq 'TAP' or $file_type eq 'NOT') { } 16 12 28
elsif ($file_type eq 'RAP') { } 0 12 12
elsif ($file_type eq 'ACK') { } 10 2 12
elsif ($file_type eq 'NRT') { } 2 0 2
Condition66%2/3
$file_type eq "TAP" or $file_type eq "NOT"
l!l&&r!l&&!r
01612
MC/DC50%1/2
$file_type eq "TAP" or $file_type eq "NOT"
$file_type eq "TAP" $file_type eq "NOT"
Truth table66%2/3
A or B
A= $file_type eq "TAP"B= $file_type eq "NOT"
ABresult
1X1
011
000
502 16 ▶ if (! $release or ! $version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $release && $version) { } 0 16 16
Condition33%1/3
$release && $version
!ll&&!rl&&r
0016
MC/DC0%0/2
$release && $version
$release $version
Truth table33%1/3
A && B
A= $releaseB= $version
ABresult
0X0
100
111
503 0 $self->{error}="'specificationVersionNumer' or 'releaseVersionNumber' not found in TAP File";
504 0 croak $self->error();
505 } else {
506 16 $self->{_version}=$version;
507 16 $self->{_release}=$release;
508 16 $self->{_file_type}="TAP";
509 }
510 } elsif ($file_type eq "RAP") {
511 0 ▶ if ( $rap_version && $rap_release ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rap_version and $rap_release) 0 0 0
Condition0%0/3
$rap_version and $rap_release
!ll&&!rl&&r
000
MC/DC0%0/2
$rap_version and $rap_release
$rap_version $rap_release
Truth table0%0/3
A and B
A= $rap_versionB= $rap_release
ABresult
0X0
100
111
512 0 ▶ if (! $release or ! $version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $release && $version) { } 0 0 0
Condition0%0/3
$release && $version
!ll&&!rl&&r
000
MC/DC0%0/2
$release && $version
$release $version
Truth table0%0/3
A && B
A= $releaseB= $version
ABresult
0X0
100
111
513 0 $self->{error}="'specificationVersionNumer' or 'releaseVersionNumber' not found in RAP File";
514 0 croak $self->error();
515 } else {
516 0 $self->{_version}=$rap_version;
517 0 $self->{_release}=$rap_release;
518 0 $self->{_supl_version}=$version;
519 0 $self->{_supl_release}=$release;
520 0 $self->{_file_type}="RAP";
521 }
522 }
523 } elsif ($file_type eq "ACK") {
524 10 $self->{_version}=1;
525 10 $self->{_release}=4;
526 10 $self->{_supl_version}=3;
527 10 $self->{_supl_release}=10;
528 10 $self->{_file_type}="RAP";
529 } elsif ($file_type eq "NRT") {
530 2 ▶ if (! $release or ! $version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $release && $version) { } 0 2 2
Condition33%1/3
$release && $version
!ll&&!rl&&r
002
MC/DC0%0/2
$release && $version
$release $version
Truth table33%1/3
A && B
A= $releaseB= $version
ABresult
0X0
100
111
531 0 $self->{error}="'specificationVersionNumer' or 'releaseVersionNumber' not found in NRT File";
532 0 croak $self->error();
533 } else {
534 2 $self->{_version}=$version;
535 2 $self->{_release}=$release;
536 2 $self->{_file_type}="NRT";
537 }
538 } else {
539 0 $self->{error}="Unknown File format. Cannot decode.";
540 0 croak $self->error();
541 }
542
543 28 1;
544 }
545  
546  
547 #----------------------------------------------------------------
548 # Method: _select_spec_file
549 # Description: Selects the file with the ASN Specifications
550 # according to the version of the file.
551 # Nomenclature specified: TAP0309.asn for the spec-
552 # ifications of the TAP3r9 and RAP0102.asn for the
553 # specifications of the RAP1r2.
554 # Parameters: version
555 # release
556 # file_type
557 # Returns: filename of the Specification ASN.1
558 # Type: Private
559 # Restrictions: N/A
560 #----------------------------------------------------------------
561 sub _select_spec_file
562 {
563 19 ▶ my $self=shift;
Subroutine _select_spec_file: called CC=4 SCAR=13.9
564  
565 19 my $version=shift;
566 19 my $release=shift;
567 19 my $file_type=shift;
568  
569 19 $version=sprintf("%02d", $version);
570 19 $release=sprintf("%02d", $release);
571  
572 19 my $spec_file;
573  
574 19 NEXT_CYCLE1: foreach ( @{$self->_asn_path} ) {
575 19 $spec_file=$_."/".$file_type.$version.$release.".asn";
576 19 ▶ if ( $spec_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec_file) 19 0 19
577 19 last NEXT_CYCLE1;
578 }
579 }
580  
581 19 ▶ return $spec_file || return undef;
Condition50%1/2
$spec_file || (return undef)
l!l
190
MC/DC0%0/1
$spec_file || (return undef)
$spec_file
Truth table50%1/2
A
A= $spec_file
Aresult
11
00
582 }
583  
584  
585  
586 #----------------------------------------------------------------
587 # Method: _select_asn_struct
588 # Description: Selects and prepares the ASN specification
589 # to be used.
590 # Parameters: N/A
591 # Returns: N/A
592 # Type: Private
593 # Restrictions: $self->version, $self->release and
594 # $self->file_type should defined.
595 #----------------------------------------------------------------
596 sub _select_asn_struct
597 {
598 28 ▶ my $self=shift;
Subroutine _select_asn_struct: called CC=25 SCAR=36.0
599  
600 28 my $size;
601 my $spec_buf_in;
602 28 my $spec_buf_in_tmp;
603  
604 ##
605 ## 1. Select the ASN.1 structure
606 ##
607  
608 ##
609 ## 1.1. Main ASN.1 structure file.
610 ##
611  
612 28 ▶ if ( ! $self->spec_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->spec_file) 14 14 28
613 14 ▶ $self->spec_file($self->_select_spec_file($self->{_version}, $self->{_release}, $self->file_type)) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->spec_file($self->_select_spec_file($self->{"_version"}, $self->{"_release"}, $self->file_type)) or return undef 0 14 14
614 }
615  
616 ##
617 ## 1.2. If we are working with a RAP file we need to know also the version of TAP Inside the RAP.
618 ##
619  
620 28 ▶ if ( ! $self->supl_spec_file and $self->file_type eq "RAP" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->supl_spec_file and $self->file_type eq "RAP") 5 23 28
Condition100%3/3
not $self->supl_spec_file and $self->file_type eq "RAP"
!ll&&!rl&&r
5185
MC/DC100%2/2
not $self->supl_spec_file and $self->file_type eq "RAP"
not $self->supl_spec_file $self->file_type eq "RAP"
Truth table100%3/3
not(A) and B
A= not $self->supl_spec_fileB= $self->file_type eq "RAP"
ABresult
0X0
100
111
621 5 ▶ $self->supl_spec_file($self->_select_spec_file($self->{_supl_version}, $self->{_supl_release}, "TAP")) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->supl_spec_file($self->_select_spec_file($self->{"_supl_version"}, $self->{"_supl_release"}, "TAP")) or return undef 0 5 5
622 }
623  
624 ##
625 ## 2. The content of the definitions files are stored into a scalar.
626 ##
627  
628 ##
629 ## 2.1. First the definition file is opend and the content filtered and stored into $spec_buf_in
630 ##
631  
632 28 ▶ ($size) = (stat($self->spec_file))[7] or do { $self->{error}="$! reading ".$self->spec_file; return undef };
Branch: 1 branch
BranchTrueFalseTotal
($size) = (stat $self->spec_file)[7] or do { $self->{"error"} = "$! reading " . $self->spec_file; return undef } 0 28 28
633 28 ▶ open FILE, "<".$self->spec_file or do { $self->{error}="$! opening ".$self->spec_file; return undef };
Branch: 1 branch
BranchTrueFalseTotal
open FILE, '<' . $self->spec_file or do { $self->{"error"} = "$! opening " . $self->spec_file; return undef } 0 28 28
634  
635 28 ▶ while (<FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 25172 28 25200
636 25172 ▶ if ( /^...Structure of a (... batch|...... record)/.../END/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^...Structure of a (... batch|...... record)/ ... /END/) 23812 1360 25172
637 23812 ▶ if ( $_ !~ m/Structure of a (Tap batch|NRTRDE)/ and $_ !~ m/END/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ =~ /Structure of a (Tap batch|NRTRDE)/ or $_ =~ /END/) 23766 46 23812
Condition100%3/3
$_ =~ /Structure of a (Tap batch|NRTRDE)/ or $_ =~ /END/
l!l&&r!l&&!r
182823766
MC/DC100%2/2
$_ =~ /Structure of a (Tap batch|NRTRDE)/ or $_ =~ /END/
$_ =~ /Structure of a (Tap batch|NRTRDE)/ $_ =~ /END/
Truth table100%3/3
A or B
A= $_ =~ /Structure of a (Tap batch|NRTRDE)/B= $_ =~ /END/
ABresult
1X1
011
000
638 23766 $spec_buf_in_tmp=$spec_buf_in_tmp.$_;
639 }
640 }
641 }
642  
643 28 close FILE;
644  
645 ##
646 ## 2.2. If it is a RAP file, we read as well the specification of its tap file.
647 ##
648  
649 28 ▶ if ( $self->file_type eq "RAP" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->file_type eq "RAP") 10 18 28
650 10 ▶ ($size) = (stat($self->supl_spec_file))[7] or do { $self->{error}="$! reading ".$self->supl_spec_file; return undef };
Branch: 1 branch
BranchTrueFalseTotal
($size) = (stat $self->supl_spec_file)[7] or do { $self->{"error"} = "$! reading " . $self->supl_spec_file; return undef } 0 10 10
651 10 ▶ open FILE, "<".$self->supl_spec_file or do { $self->{error}="$! opening ".$self->supl_spec_file; return undef };
Branch: 1 branch
BranchTrueFalseTotal
open FILE, '<' . $self->supl_spec_file or do { $self->{"error"} = "$! opening " . $self->supl_spec_file; return undef } 0 10 10
652 10 ▶ while (<FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 16190 10 16200
653 16190 ▶ if ( /^...Structure of a ... batch/.../END/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^...Structure of a ... batch/ ... /END/) 15710 480 16190
654 15710 ▶ if ( $_ !~ m/Structure of a Tap batch/ and $_ !~ m/END/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ =~ /Structure of a Tap batch/ or $_ =~ /END/) 15690 20 15710
Condition100%3/3
$_ =~ /Structure of a Tap batch/ or $_ =~ /END/
l!l&&r!l&&!r
101015690
MC/DC100%2/2
$_ =~ /Structure of a Tap batch/ or $_ =~ /END/
$_ =~ /Structure of a Tap batch/ $_ =~ /END/
Truth table100%3/3
A or B
A= $_ =~ /Structure of a Tap batch/B= $_ =~ /END/
ABresult
1X1
011
000
655 15690 $spec_buf_in_tmp=$spec_buf_in_tmp.$_;
656 }
657 }
658 }
659 10 close FILE;
660 }
661  
662 # Following algorithm will strip the chain ",\n..." since the three dots and a comma
663 # in the last element is not supported by Convert::ASN1
664  
665 ### 20120501: Following code was commented out because of performance.
666 ### The specifications were modified instead.
667  
668 # while($spec_buf_in_tmp =~ /(?:
669 # (,[^\n]*\n(?:\s|\t)*?\.\.\.[^\n,]*\n)
670 # |
671 # ([\s|\t]*?\.\.\.(?:\s|\t)*?,[^\n]*\n)
672 # |
673 # (\(SIZE\(\d+(?:\.\.\d+)*?\)\))
674 # |
675 # (.*?)
676 # )/sgxo) {
677 # if (defined $1 or defined $2 or defined $3) {
678 # $spec_buf_in=$spec_buf_in."\n";
679 # } else {
680 # $spec_buf_in=$spec_buf_in."$+";
681 # }
682 # }
683  
684 28 $spec_buf_in = $spec_buf_in_tmp;
685  
686 ##
687 ## 3. let's prepare the asn difinition.
688 ##
689  
690 28 my $asn = $self->_asn;
691 28 ▶ $asn->prepare( $spec_buf_in ) or do { $self->{error}=$asn->error; return undef };
Branch: 1 branch
BranchTrueFalseTotal
$asn->prepare($spec_buf_in) or do { $self->{"error"} = $asn->error; return undef } 0 28 28
692  
693  
694 ##
695 ## 4. Initialization with DataInterChange
696 ##
697  
698 28 my $dic_asn;
699 28 ▶ if ( $self->file_type eq "TAP" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->file_type eq 'TAP') { } 16 12 28
elsif ($self->file_type eq 'NRT') { } 2 10 12
700 16 ▶ $dic_asn = $asn->find('DataInterChange') or do { $self->{error}=$asn->error; return undef };
Branch: 1 branch
BranchTrueFalseTotal
$dic_asn = $asn->find("DataInterChange") or do { $self->{"error"} = $asn->error; return undef } 0 16 16
701 } elsif ( $self->file_type eq "NRT" ) {
702 2 ▶ $dic_asn = $asn->find('Nrtrde') or do { $self->{error}=$asn->error; return undef };
Branch: 1 branch
BranchTrueFalseTotal
$dic_asn = $asn->find("Nrtrde") or do { $self->{"error"} = $asn->error; return undef } 0 2 2
703 } else {
704 10 ▶ $dic_asn = $asn->find('RapDataInterChange') or do { $self->{error}=$asn->error; return undef };
Branch: 1 branch
BranchTrueFalseTotal
$dic_asn = $asn->find("RapDataInterChange") or do { $self->{"error"} = $asn->error; return undef } 0 10 10
705 }
706 28 $self->_dic_asn($dic_asn);
707  
708 }
709  
710  
711  
712 #----------------------------------------------------------------
713 # Method: decode
714 # Description: decodes the TAP/RAP/NRT file into a HASH for its
715 # later editing.
716 # Parameters: filename
717 # Returns: N/A
718 # Type: Public
719 # Restrictions: N/A
720 #----------------------------------------------------------------
721 sub decode {
722 14 ▶ my $self=shift;
Subroutine decode: called CC=5 SCAR=17.8
Pod undocumented
723  
724 14 my $filename=shift;
725 14 my $buf_in;
726 my $size;
727
728 14 $self->_filename($filename);
729  
730  
731 ##
732 ## 1. Get the version to decode the file.
733 ##
734  
735 14 ▶ $self->_get_file_version || return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_get_file_version or return undef 0 14 14
736  
737  
738 ##
739 ## 2. Selection of ASN Structure.
740 ##
741  
742 14 ▶ $self->_select_asn_struct || return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_select_asn_struct or return undef 0 14 14
743  
744  
745 ##
746 ## 3. We open and read all the TAP/RAP/NRT file at once.
747 ##
748  
749 14 my $FILE;
750 14 ▶ open $FILE, "<$filename" or do { $self->{error}="$! opening $filename"; return undef };
Branch: 1 branch
BranchTrueFalseTotal
open $FILE, "<$filename" or do { $self->{"error"} = "$! opening $filename"; return undef } 0 14 14
751 14 binmode $FILE;
752 14 asn_read ($FILE, $buf_in);
753 14 close $FILE;
754  
755  
756 ##
757 ## 4. Decode file buffer into the ASN1 tree.
758 ##
759  
760 14 ▶ $self->{_dic_decode} = $self->_dic_asn->decode($buf_in) or do { $self->{error}=$self->_dic_asn->error; croak $self->error() };
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_dic_decode"} = $self->_dic_asn->decode($buf_in) or do { $self->{"error"} = $self->_dic_asn->error; croak($self->error) } 0 14 14
761  
762 }
763  
764  
765  
766 #----------------------------------------------------------------
767 # Method: encode
768 # Description: encode the HASH structure into a new TAP/RAP/NRT
769 # file
770 # Parameters: filename
771 # Returns: N/A
772 # Type: Public
773 # Restrictions: N/A
774 #----------------------------------------------------------------
775 sub encode {
776  
777 14 ▶ my $self = shift;
Subroutine encode: called CC=4 SCAR=15.7
Pod undocumented
778  
779 14 my $filename=shift;
780 14 $self->_filename($filename);
781  
782  
783 ##
784 ## 1. _dic_decode will be the decoded tree of a real tap file
785 ##
786  
787 ##
788 ## 2. Select structure according to version, release and type.
789 ##
790  
791 ## In the case we want just to encode, we need to select and prepare
792 ## the structure we want to use. E.g If we want to get a TAP3r9
793 ## we need to select the ASN.1 structure for the TAP3r9
794 14 ▶ $self->_select_asn_struct || return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_select_asn_struct or return undef 0 14 14
795  
796  
797 ##
798 ## 3. Encode ASN1 tree into the file.
799 ##
800  
801 14 ▶ my $buf_out = $self->_dic_asn->encode($self->_dic_decode) or do { $self->{error}=$self->_dic_asn->error; croak $self->error() };
Branch: 1 branch
BranchTrueFalseTotal
my $buf_out = $self->_dic_asn->encode($self->_dic_decode) or do { $self->{"error"} = $self->_dic_asn->error; croak($self->error) } 0 14 14
802  
803  
804 ##
805 ## 4. Write and close file
806 ##
807  
808 14 ▶ open FILE_OUT, ">$filename" or do { $self->{error}="$! writing $filename"; croak $self->error() };
Branch: 1 branch
BranchTrueFalseTotal
open FILE_OUT, ">$filename" or do { $self->{"error"} = "$! writing $filename"; croak($self->error) } 0 14 14
809 14 binmode FILE_OUT;
810 14 print FILE_OUT $buf_out ;
811 14 close FILE_OUT;
812 }
813  
814 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
815  
816 0 ▶sub error { $_[0]->{error} }
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
817  
818 1 1;
↑ Summary