| 1 | package BrLock::BrXML; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | our @EXPORT = qw(xmlmessage_brpack xmlparse_brmsg brxml_debug); | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | our $brxml_debug = 0; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | #TODO: now that we've separated these functions in this package, we | ||||||||||||||||||||||||||||
| 10 | # should update the comments. | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # xmlmessage_brpack(type, site_id, site_seq, random_data): | ||||||||||||||||||||||||||||
| 14 | # this function returns a string containing a XML message as | ||||||||||||||||||||||||||||
| 15 | # specified in the file mutex.txt. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | #TODO: verify the return values (I don't know if it's good | ||||||||||||||||||||||||||||
| 18 | # to return undefined because, if the main/superfunction wants this | ||||||||||||||||||||||||||||
| 19 | # value to pass to another function, it'll need a variable to receive | ||||||||||||||||||||||||||||
| 20 | # this value. However, I don't know if there is a good solution for | ||||||||||||||||||||||||||||
| 21 | # him (if he wants to test, he'll need another variable anyway)). | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | #TODO: change the name of this function. Maybe xmlpack_brmessage(). | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub xmlmessage_brpack { | ||||||||||||||||||||||||||
|
Subroutine
xmlmessage_brpack: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 0 | my ($type, $site_id, $site_seq, $random) = @_; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | if ($type ne "REQ" and $type ne "REP"){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type ne "REQ" and $type ne "REP"
MC/DC0%0/2
$type ne "REQ" and $type ne "REP"
$type ne "REQ"
$type ne "REP"
Truth table0%0/3
A and B
A= $type ne "REQ"B= $type ne "REP"
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | print "xmlmessage_brpack(): Message must be either \"REQ\"". | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | " or \"REP\".\n" if $brxml_debug; | ||||||||||||||||||||||||||||
| 29 | 0 | return undef; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 0 | my $xml_msg = "\$xml_msg = \" | |||||||||||||||||||||||||||
| 32 | <msg> | ||||||||||||||||||||||||||||
| 33 | <type>\$type</type> | ||||||||||||||||||||||||||||
| 34 | <site_id>\$site_id</site_id> | ||||||||||||||||||||||||||||
| 35 | <site_seq>\$site_seq</site_seq> | ||||||||||||||||||||||||||||
| 36 | <body>\$random</body> | ||||||||||||||||||||||||||||
| 37 | </msg> | ||||||||||||||||||||||||||||
| 38 | \";"; | ||||||||||||||||||||||||||||
| 39 | 0 | eval $xml_msg; | |||||||||||||||||||||||||||
| 40 | 0 | return $xml_msg; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | ### | ||||||||||||||||||||||||||||
| 45 | # XML parsing variables and functions (We all will go to hell for | ||||||||||||||||||||||||||||
| 46 | # using globals). You're probably only interested in the sub | ||||||||||||||||||||||||||||
| 47 | # xmlparse_brmsg (xml_msg). | ||||||||||||||||||||||||||||
| 48 | ### | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | my $xmlparse_tagtofill; | |||||||||||||||||||||||||||
| 51 | 1 | my %xmlparse_data = ( | |||||||||||||||||||||||||||
| 52 | type => '', | ||||||||||||||||||||||||||||
| 53 | site_id => '', | ||||||||||||||||||||||||||||
| 54 | site_seq => '', | ||||||||||||||||||||||||||||
| 55 | body => '', | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # xmlhandler_tagstart(): | ||||||||||||||||||||||||||||
| 59 | # handler for the parsing process (see the function xmlparse_brmsg). | ||||||||||||||||||||||||||||
| 60 | # it sets which tag in the hash %xmlparse_data must be filled by | ||||||||||||||||||||||||||||
| 61 | # the handler xmlhandler_tagchar. | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub xmlhandler_tagstart { | ||||||||||||||||||||||||||
|
Subroutine
xmlhandler_tagstart: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 0 | my ($p, $element, %attrs) = @_ ; | |||||||||||||||||||||||||||
| 64 | 0 | $xmlparse_tagtofill = $element; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # xmlhandler_tagchar(): | ||||||||||||||||||||||||||||
| 69 | # handler for the parsing process (see the function xmlparse_brmsg). | ||||||||||||||||||||||||||||
| 70 | # it fills the tag in the hash %xmlparse_data which | ||||||||||||||||||||||||||||
| 71 | # xmlhandler_tagstart has set to be filled. | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub xmlhandler_tagchar { | ||||||||||||||||||||||||||
|
Subroutine
xmlhandler_tagchar: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 73 | 0 | my ($p, $data) = @_ ; | |||||||||||||||||||||||||||
| 74 | 0 | $xmlparse_data{$xmlparse_tagtofill} = $data; | |||||||||||||||||||||||||||
| 75 | 0 | $xmlparse_tagtofill = ''; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # xmlparse_brmsg (xml_msg): | ||||||||||||||||||||||||||||
| 79 | # parses the XML message xml_msg as specified (see the file | ||||||||||||||||||||||||||||
| 80 | # mutex.txt) and returns the existing data for the tags as a list: | ||||||||||||||||||||||||||||
| 81 | # ($type, $site_id, $site_sequence, $random). | ||||||||||||||||||||||||||||
| 82 | # | ||||||||||||||||||||||||||||
| 83 | # the xml_msg data may either be a string containing the | ||||||||||||||||||||||||||||
| 84 | # whole XML document, or it may be an open IO::Handle. | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub xmlparse_brmsg { | ||||||||||||||||||||||||||
|
Subroutine
xmlparse_brmsg: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 0 | my ($xml_msg) = $_[0]; | |||||||||||||||||||||||||||
| 87 | 0 | my ($type, $site_id, $site_sequence, $random) = 0; | |||||||||||||||||||||||||||
| 88 | 0 | my $xp = new XML::Parser(); | |||||||||||||||||||||||||||
| 89 | 0 | $xp->setHandlers ( | |||||||||||||||||||||||||||
| 90 | Start => \&xmlhandler_tagstart, | ||||||||||||||||||||||||||||
| 91 | Char => \&xmlhandler_tagchar, | ||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||
| 93 | # $xp->parsestring($xml_msg); | ||||||||||||||||||||||||||||
| 94 | # it doesn't need to be a string: | ||||||||||||||||||||||||||||
| 95 | 0 | $xp->parse($xml_msg); | |||||||||||||||||||||||||||
| 96 | return ($xmlparse_data{'type'}, $xmlparse_data{'site_id'}, | ||||||||||||||||||||||||||||
| 97 | 0 | $xmlparse_data{'site_seq'}, $xmlparse_data{'body'}); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 1 | ▶ | BEGIN{ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | 1 | return 1; | |||||||||||||||||||||||||||