line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BrLock::BrXML; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20138
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
5
|
use base 'Exporter'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
431
|
|
5
|
|
|
|
|
|
|
our @EXPORT = qw(xmlmessage_brpack xmlparse_brmsg brxml_debug); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub xmlmessage_brpack { |
25
|
0
|
|
|
0
|
0
|
|
my ($type, $site_id, $site_seq, $random) = @_; |
26
|
0
|
0
|
0
|
|
|
|
if ($type ne "REQ" and $type ne "REP"){ |
27
|
0
|
0
|
|
|
|
|
print "xmlmessage_brpack(): Message must be either \"REQ\"". |
28
|
|
|
|
|
|
|
" or \"REP\".\n" if $brxml_debug; |
29
|
0
|
|
|
|
|
|
return undef; |
30
|
|
|
|
|
|
|
} |
31
|
0
|
|
|
|
|
|
my $xml_msg = "\$xml_msg = \" |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
\$type |
34
|
|
|
|
|
|
|
\$site_id |
35
|
|
|
|
|
|
|
\$site_seq |
36
|
|
|
|
|
|
|
\$random |
37
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my $xmlparse_tagtofill; |
51
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub xmlhandler_tagstart { |
63
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub xmlhandler_tagchar { |
73
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub xmlparse_brmsg { |
86
|
0
|
|
|
0
|
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
|
0
|
|
|
|
|
|
return ($xmlparse_data{'type'}, $xmlparse_data{'site_id'}, |
97
|
|
|
|
|
|
|
$xmlparse_data{'site_seq'}, $xmlparse_data{'body'}); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
1
|
|
|
1
|
|
28
|
BEGIN{ |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
return 1; |