/[cwmp]/google/rules.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /google/rules.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (show annotations)
Sun Jun 17 22:14:59 2007 UTC (16 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 1445 byte(s)
correctly strip cwmp namespace, and parse all (implemented) tags
1 #!/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 # 'http://schemas.xmlsoap.org/soap/envelope/' => 'soapenv',
20 # 'http://schemas.xmlsoap.org/soap/encoding/' => 'soap',
21 'urn:dslforum-org:cwmp-1-0' => '',
22 },
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 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 },
38 qr/EventStruct/ => sub {
39 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
40 warn dump( $tag_name, $tag_hash );
41 push @{ $state->{EventStruct} }, $tag_hash->{EventCode}->{_content};
42 },
43 qr/MaxEnvelopes/ => sub {
44 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
45 $state->{MaxEnvelopes} = $tag_hash->{_content};
46 }
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 #warn $xml;
54 $parser->parsestring( $xml );
55
56 print "state = ", dump( $state );

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26