1 |
dpavlin |
23 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
use warnings; |
4 |
|
|
use strict; |
5 |
|
|
|
6 |
|
|
use XML::Rules; |
7 |
|
|
use File::Slurp; |
8 |
|
|
use Data::Dump qw/dump/; |
9 |
|
|
|
10 |
|
|
my $path = $ARGV[0] || 'protocol/inform.xml'; |
11 |
|
|
|
12 |
|
|
my $state; |
13 |
|
|
|
14 |
|
|
my $parser = XML::Rules->new( |
15 |
|
|
# start_rules => [ |
16 |
|
|
# '^division_name,fax' => 'skip', |
17 |
|
|
# ], |
18 |
|
|
namespaces => { |
19 |
dpavlin |
24 |
# 'http://schemas.xmlsoap.org/soap/envelope/' => 'soapenv', |
20 |
|
|
# 'http://schemas.xmlsoap.org/soap/encoding/' => 'soap', |
21 |
|
|
'urn:dslforum-org:cwmp-1-0' => '', |
22 |
dpavlin |
23 |
}, |
23 |
|
|
rules => [ |
24 |
|
|
#_default => 'content trim', |
25 |
|
|
x_default => sub { |
26 |
|
|
my ($tag_name, $tag_hash, $context, $parent_data) = @_; |
27 |
|
|
warn dump( $tag_name, $tag_hash, $context ); |
28 |
|
|
}, |
29 |
|
|
qr/DeviceId/ => sub { |
30 |
|
|
my ($tag_name, $tag_hash, $context, $parent_data) = @_; |
31 |
dpavlin |
24 |
foreach my $name ( keys %$tag_hash ) { |
32 |
|
|
next if $name eq '_content'; |
33 |
|
|
my $key = $name; |
34 |
|
|
$key =~ s/^\w+://; # stip namespace |
35 |
|
|
$state->{DeviceID}->{ $key } = $tag_hash->{$name}->{_content}; |
36 |
|
|
} |
37 |
dpavlin |
23 |
}, |
38 |
dpavlin |
24 |
qr/EventStruct/ => sub { |
39 |
dpavlin |
23 |
my ($tag_name, $tag_hash, $context, $parent_data) = @_; |
40 |
dpavlin |
24 |
warn dump( $tag_name, $tag_hash ); |
41 |
|
|
push @{ $state->{EventStruct} }, $tag_hash->{EventCode}->{_content}; |
42 |
dpavlin |
23 |
}, |
43 |
dpavlin |
24 |
qr/MaxEnvelopes/ => sub { |
44 |
dpavlin |
23 |
my ($tag_name, $tag_hash, $context, $parent_data) = @_; |
45 |
dpavlin |
24 |
$state->{MaxEnvelopes} = $tag_hash->{_content}; |
46 |
dpavlin |
23 |
} |
47 |
|
|
] |
48 |
|
|
); |
49 |
|
|
|
50 |
|
|
my $xml = read_file( $path ); |
51 |
|
|
print "## $1 ##\n" if ( $xml =~ s/^Name:\s+(.*?)$//sm ); |
52 |
|
|
$xml =~ s/^.*Response:\s+//sm; |
53 |
dpavlin |
24 |
#warn $xml; |
54 |
dpavlin |
23 |
$parser->parsestring( $xml ); |
55 |
|
|
|
56 |
|
|
print "state = ", dump( $state ); |