8 use Data::Dump qw/dump/;
9 use Carp qw/confess cluck/;
13 CWMP::Request - parse SOAP request metods
19 Get value of tag. Tag name is case insensitive (don't ask why),
20 we ignore namespaces and can take optional C<sub_key>
21 (usually C<_content>).
23 _tag( $tag_hash, $name, $sub_key )
28 my ( $tag_hash, $name, $sub_key ) = @_;
29 confess "need hash as first argument" unless ( ref $tag_hash eq 'HASH' );
30 $name = (grep { m/^(?:\w+:)*$name$/i } keys %$tag_hash )[0];
32 if ( defined $tag_hash->{$name} ) {
33 if ( ! defined $sub_key ) {
34 return $tag_hash->{$name};
35 } elsif ( defined $tag_hash->{$name}->{$sub_key} ) {
36 return $tag_hash->{$name}->{$sub_key};
38 return if ( $name =~ m/^value$/i );
39 warn "can't find '$name/$sub_key' in ", dump( $tag_hash );
43 warn "can't find '$name' in ", dump( $tag_hash );
50 my $state = CWMP::Request->parse( "<soap>request</soap>" );
57 my $xml = shift || confess "no xml?";
60 $parser->parsestring( $xml );
68 our $state; # FIXME check this!
70 my $tree = CWMP::Tree->new({ debug => 0 });
72 my $parser = XML::Rules->new(
74 # '^division_name,fax' => 'skip',
77 'http://schemas.xmlsoap.org/soap/envelope/' => 'soapenv',
78 'http://schemas.xmlsoap.org/soap/encoding/' => 'soap',
79 'http://www.w3.org/2001/XMLSchema' => 'xsd',
80 'http://www.w3.org/2001/XMLSchema-instance' => 'xsi',
81 'urn:dslforum-org:cwmp-1-0' => '',
84 #_default => 'content trim',
86 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
87 warn dump( $tag_name, $tag_hash, $context );
90 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
91 $state->{ID} = $tag_hash->{_content};
96 Generate InformResponse to CPE
101 $state->{_dispatch} = 'InformResponse'; # what reponse to call
104 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
105 foreach my $name ( keys %$tag_hash ) {
106 next if $name eq '_content';
108 $key =~ s/^\w+://; # stip namespace
109 $state->{DeviceID}->{ $key } = _tag( $tag_hash, $name, '_content' );
112 'EventStruct' => sub {
113 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
114 push @{ $state->{EventStruct} }, $tag_hash->{EventCode}->{_content};
116 qr/(MaxEnvelopes|CurrentTime|RetryCount)/ => sub {
117 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
118 $state->{$tag_name} = $tag_hash->{_content};
120 'ParameterValueStruct' => sub {
121 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
122 # Name/Value tags must be case insnesitive
123 my $value = (grep( /value/i, keys %$tag_hash ))[0];
124 $state->{Parameter}->{ _tag($tag_hash, 'Name', '_content') } = _tag($tag_hash, 'Value', '_content' );
127 =head2 GetRPCMethodsResponse
130 qr/^(?:^\w+:)*string$/ => 'content array',
131 'MethodList' => sub {
132 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
133 $state->{MethodList} = _tag( $tag_hash, 'string' );
136 =head2 GetParameterNamesResponse
140 'ParameterInfoStruct' => sub {
141 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
142 my $name = _tag($tag_hash, 'Name', '_content');
143 my $writable = _tag($tag_hash, 'Writable', '_content' );
145 confess "need state" unless ( $state ); # don't remove!
147 # XXX dragons ahead: convert name to tree rewriting it into perl
148 my $s = '$state->{ParameterInfo}->' . $tree->name2perl( $name ) . "->{writable} = $writable;";
150 confess "can't eval $s : $@" if ($@);
152 #warn "## state = dump( $state ), "\n";
160 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
162 FaultCode => _tag( $tag_hash, 'FaultCode', '_content' ),
163 FaultString => _tag( $tag_hash, 'FaultString', '_content' ),
165 warn "FAULT: ", $state->{Fault}->{FaultCode}, " ", $state->{Fault}->{FaultString}, "\n";