line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::SDEE; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# $Id: SDEE.pm,v 1.1 2004/12/23 12:02:30 jminieri Exp $ |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
22
|
use 5.006001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
7
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
668
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
################################################################################ |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
sub sessionId { my $self = shift; return $self->{ _sessionId }; } |
17
|
|
|
|
|
|
|
sub subscriptionId { my $self = shift; return $self->{ _subscriptionId }; } |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
################################################################################ |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
################################################################################ |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# Error reporting methods |
24
|
|
|
|
|
|
|
sub isError{ my $self = shift; return $self->{ _isError };} |
25
|
|
|
|
|
|
|
sub getError{ my $self = shift; return $self->{ _errorMessage }; } |
26
|
|
|
|
|
|
|
sub getErrorReason{ |
27
|
|
|
|
|
|
|
my $self = shift; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
if(exists($self->{ _errorMessage}{ Reason })) { |
30
|
|
|
|
|
|
|
return $self->{ _errorMessage}{ Reason } |
31
|
|
|
|
|
|
|
} else { |
32
|
|
|
|
|
|
|
return undef |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub getErrorSubcode{ |
37
|
|
|
|
|
|
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
if(exists($self->{ _errorMessage }{ Subcode })) { |
40
|
|
|
|
|
|
|
return $self->{ _errorMessage }{ Subcode } |
41
|
|
|
|
|
|
|
} else { |
42
|
|
|
|
|
|
|
return undef |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub getErrorCode{ |
47
|
|
|
|
|
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
if(exists($self->{ _errorMessage }{ Code })) { |
49
|
|
|
|
|
|
|
return $self->{ _errorMessage }{ Code } |
50
|
|
|
|
|
|
|
} else { |
51
|
|
|
|
|
|
|
return undef |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub getErrorString { |
56
|
|
|
|
|
|
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
return $self->getErrorCode . ':' . $self->getErrorSubcode . ':' . $self->getErrorReason; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
################################################################################ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
################################################################################ |
64
|
|
|
|
|
|
|
# |
65
|
|
|
|
|
|
|
# Event retrieval methods |
66
|
|
|
|
|
|
|
sub getEvent { my $self = shift; return pop @{ $self->{ _eventList }}; } |
67
|
|
|
|
|
|
|
sub getEvents { my $self = shift; return $self->{ _events }; } |
68
|
|
|
|
|
|
|
# |
69
|
|
|
|
|
|
|
################################################################################ |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
################################################################################ |
72
|
|
|
|
|
|
|
# |
73
|
|
|
|
|
|
|
# XML retrieval methods |
74
|
|
|
|
|
|
|
sub XML { my $self = shift; return $self->{ _raw_xml }; } |
75
|
|
|
|
|
|
|
sub SDEE { my $self = shift; return $self->{ SDEE }; } |
76
|
|
|
|
|
|
|
# |
77
|
|
|
|
|
|
|
################################################################################ |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub reset { |
80
|
|
|
|
|
|
|
my $self = shift; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$self->{ _raw_xml } = undef; |
83
|
|
|
|
|
|
|
$self->{ SDEE } = undef; |
84
|
|
|
|
|
|
|
$self->{ _sessionId } = undef; |
85
|
|
|
|
|
|
|
$self->{ _subscriptionId } = undef; |
86
|
|
|
|
|
|
|
$self->{ _isError } = undef; |
87
|
|
|
|
|
|
|
$self->{ _errorMessage } = {}; |
88
|
|
|
|
|
|
|
@{$self->{ _eventsList }} = (); |
89
|
|
|
|
|
|
|
$self->{ _events } = undef; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# |
94
|
|
|
|
|
|
|
# document processor |
95
|
|
|
|
|
|
|
sub consume { |
96
|
|
|
|
|
|
|
my ($self, $raw_xml) = @_; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
unless(defined($raw_xml)) { return undef; } |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$self->reset; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$self->{ _raw_xml } = $raw_xml; |
103
|
|
|
|
|
|
|
$self->{ SDEE } = XMLin($raw_xml); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
if (exists($self->{ SDEE }->{ 'env:Header' }->{ 'sd:oobInfo' }->{ 'sd:sessionId' } )) { |
106
|
|
|
|
|
|
|
$self->{ _sessionId } = ($self->{ SDEE }->{ 'env:Header' }->{ 'sd:oobInfo' }->{ 'sd:sessionId' } or undef); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
if(exists($self->{ SDEE }->{ 'env:Body' }->{ 'sd:subscriptionId' })) { |
110
|
|
|
|
|
|
|
$self->{ _subscriptionId } = $self->{ SDEE }->{ 'env:Body' }->{ 'sd:subscriptionId' }; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# |
114
|
|
|
|
|
|
|
# SDEE is made to process a bunch of types of events. 'evIdsAlert' is just one |
115
|
|
|
|
|
|
|
# I should probably store the events in a hash with the event type as a key |
116
|
|
|
|
|
|
|
# |
117
|
|
|
|
|
|
|
if(exists($self->{ SDEE }->{ 'env:Body' }->{ 'sd:events' })) { |
118
|
|
|
|
|
|
|
$self->{ _events } = $self->{ SDEE }->{ 'env:Body' }->{ 'sd:events' }; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $events_ref = $self->{ SDEE }->{ 'env:Body' }->{ 'sd:events' }; |
121
|
|
|
|
|
|
|
foreach my $event_type (keys %$events_ref) { |
122
|
|
|
|
|
|
|
my $events = $events_ref->{ $event_type }; |
123
|
|
|
|
|
|
|
if(ref($events) eq 'ARRAY') { |
124
|
|
|
|
|
|
|
foreach my $event (@$events) { |
125
|
|
|
|
|
|
|
$event->{ eventType } = $event_type; |
126
|
|
|
|
|
|
|
push( @{ $self->{ _eventList }}, $event); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} elsif (ref($events) eq 'HASH') { |
129
|
|
|
|
|
|
|
$events->{ eventType } = $event_type; |
130
|
|
|
|
|
|
|
push( @{ $self->{ _eventList }}, $events); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
if(exists($self->{ SDEE }->{ 'env:Body' }->{ 'env:Fault' })) { |
136
|
|
|
|
|
|
|
$self->{ _errorMessage }{ Code } = |
137
|
|
|
|
|
|
|
($self->{ SDEE }->{ 'env:Body' }->{ 'env:Fault' }->{ 'env:Code' }->{ 'env:Value' } =~ /^env:(.+)$/)[0]; |
138
|
|
|
|
|
|
|
$self->{ _errorMessage }{ Subcode } = |
139
|
|
|
|
|
|
|
($self->{ SDEE }->{ 'env:Body' }->{ 'env:Fault' }->{ 'env:Code' }->{ 'env:Subcode' }->{ 'env:Value' } =~ /^sd:(.+)$/)[0]; |
140
|
|
|
|
|
|
|
$self->{ _errorMessage }{ Reason } = |
141
|
|
|
|
|
|
|
$self->{ SDEE }->{ 'env:Body' }->{ 'env:Fault' }->{ 'env:Reason' }; |
142
|
|
|
|
|
|
|
$self->{ _isError }=1; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
return 1; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub new { |
150
|
|
|
|
|
|
|
my ($class, $document) = @_; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
my $self = {}; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
bless( $self, $class ); |
155
|
|
|
|
|
|
|
if(defined($document)) { $self->consume($document) } |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
return $self; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; |
161
|
|
|
|
|
|
|
|