4 |
use strict; |
use strict; |
5 |
|
|
6 |
use XML::Rules; |
use XML::Rules; |
|
use CWMP::Tree; |
|
7 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
8 |
use Carp qw/confess cluck/; |
use Carp qw/confess cluck/; |
9 |
use Class::Trigger; |
use Class::Trigger; |
18 |
|
|
19 |
=cut |
=cut |
20 |
|
|
|
my $tree = CWMP::Tree->new({ debug => 0 }); |
|
|
|
|
21 |
our $state; # FIXME check this! |
our $state; # FIXME check this! |
22 |
|
|
23 |
my $rules = [ |
our $rules = [ |
24 |
#_default => 'content trim', |
#_default => 'content trim', |
25 |
x_default => sub { |
x_default => sub { |
26 |
my ($tag_name, $tag_hash, $context, $parent_data) = @_; |
my ($tag_name, $tag_hash, $context, $parent_data) = @_; |
53 |
# Name/Value tags must be case insnesitive |
# Name/Value tags must be case insnesitive |
54 |
my $value = (grep( /value/i, keys %$tag_hash ))[0]; |
my $value = (grep( /value/i, keys %$tag_hash ))[0]; |
55 |
$state->{Parameter}->{ _tag($tag_hash, 'Name', '_content') } = _tag($tag_hash, 'Value', '_content' ); |
$state->{Parameter}->{ _tag($tag_hash, 'Name', '_content') } = _tag($tag_hash, 'Value', '_content' ); |
56 |
|
$state->{_trigger} = 'ParameterValue'; |
57 |
}, |
}, |
58 |
|
|
59 |
]; |
]; |
94 |
|
|
95 |
confess "need state" unless ( $state ); # don't remove! |
confess "need state" unless ( $state ); # don't remove! |
96 |
|
|
97 |
# XXX dragons ahead: convert name to tree rewriting it into perl |
$state->{ParameterInfo}->{$name} = $writable; |
|
my $s = '$state->{ParameterInfo}->' . $tree->name2perl( $name ) . "->{writable} = $writable;"; |
|
|
eval "$s"; |
|
|
confess "can't eval $s : $@" if ($@); |
|
98 |
|
|
99 |
#warn "## state = dump( $state ), "\n"; |
#warn "## state = dump( $state ), "\n"; |
100 |
|
|
116 |
$state->{_trigger} = 'Fault'; |
$state->{_trigger} = 'Fault'; |
117 |
}; |
}; |
118 |
|
|
|
my $parser = XML::Rules->new( |
|
|
# start_rules => [ |
|
|
# '^division_name,fax' => 'skip', |
|
|
# ], |
|
|
namespaces => { |
|
|
'http://schemas.xmlsoap.org/soap/envelope/' => 'soapenv', |
|
|
'http://schemas.xmlsoap.org/soap/encoding/' => 'soap', |
|
|
'http://www.w3.org/2001/XMLSchema' => 'xsd', |
|
|
'http://www.w3.org/2001/XMLSchema-instance' => 'xsi', |
|
|
'urn:dslforum-org:cwmp-1-0' => '', |
|
|
}, |
|
|
rules => $rules, |
|
|
); |
|
|
|
|
119 |
=head1 METHODS |
=head1 METHODS |
120 |
|
|
121 |
=head2 parse |
=head2 parse |
124 |
|
|
125 |
=cut |
=cut |
126 |
|
|
127 |
|
my $parser = XML::Rules->new( |
128 |
|
# start_rules => [ |
129 |
|
# '^division_name,fax' => 'skip', |
130 |
|
# ], |
131 |
|
namespaces => { |
132 |
|
'http://schemas.xmlsoap.org/soap/envelope/' => 'soapenv', |
133 |
|
'http://schemas.xmlsoap.org/soap/encoding/' => 'soap', |
134 |
|
'http://www.w3.org/2001/XMLSchema' => 'xsd', |
135 |
|
'http://www.w3.org/2001/XMLSchema-instance' => 'xsi', |
136 |
|
'urn:dslforum-org:cwmp-1-0' => '', |
137 |
|
}, |
138 |
|
rules => $rules, |
139 |
|
); |
140 |
|
|
141 |
sub parse { |
sub parse { |
142 |
my $self = shift; |
my $self = shift; |
143 |
|
|
144 |
my $xml = shift || confess "no xml?"; |
my $xml = shift || confess "no xml?"; |
145 |
|
|
146 |
$state = {}; |
$state = {}; |
147 |
|
|
148 |
$parser->parsestring( $xml ); |
$parser->parsestring( $xml ); |
149 |
if ( my $trigger = $state->{_trigger} ) { |
if ( my $trigger = $state->{_trigger} ) { |
150 |
__PACKAGE__->call_trigger( $trigger, $state ); |
warn "### call_trigger( $trigger )\n"; |
151 |
|
$self->call_trigger( $trigger, $state ); |
152 |
} |
} |
153 |
# XXX don't propagate _trigger (useful?) |
# XXX don't propagate _trigger (useful?) |
154 |
delete( $state->{_trigger} ); |
delete( $state->{_trigger} ); |