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

Diff of /google/trunk/lib/CWMP/Request.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 36 by dpavlin, Tue Jun 19 00:38:49 2007 UTC revision 92 by dpavlin, Sat Jun 23 09:15:19 2007 UTC
# Line 44  sub _tag { Line 44  sub _tag {
44          }          }
45  }  }
46    
47  my $state;  our $state;     # FIXME check this!
48    
49  my $parser = XML::Rules->new(  my $parser = XML::Rules->new(
50  #       start_rules => [  #       start_rules => [
51  #               '^division_name,fax' => 'skip',  #               '^division_name,fax' => 'skip',
52  #       ],  #       ],
53          namespaces => {          namespaces => {
54  #               'http://schemas.xmlsoap.org/soap/envelope/' => 'soapenv',                  'http://schemas.xmlsoap.org/soap/envelope/' => 'soapenv',
55  #               'http://schemas.xmlsoap.org/soap/encoding/' => 'soap',                  'http://schemas.xmlsoap.org/soap/encoding/' => 'soap',
56                    'http://www.w3.org/2001/XMLSchema' => 'xsd',
57                    'http://www.w3.org/2001/XMLSchema-instance' => 'xsi',
58                  'urn:dslforum-org:cwmp-1-0' => '',                  'urn:dslforum-org:cwmp-1-0' => '',
59          },          },
60          rules => [          rules => [
# Line 69  my $parser = XML::Rules->new( Line 71  my $parser = XML::Rules->new(
71                  # Inform                  # Inform
72                  #                  #
73                  'Inform' => sub {                  'Inform' => sub {
74                          $state->{_dispatch} = 'Inform';         # what reponse to call                          $state->{_dispatch} = 'InformResponse';         # what reponse to call
75                  },                  },
76                  qr/DeviceId/ => sub {                  'DeviceId' => sub {
77                          my ($tag_name, $tag_hash, $context, $parent_data) = @_;                          my ($tag_name, $tag_hash, $context, $parent_data) = @_;
78                          foreach my $name ( keys %$tag_hash ) {                          foreach my $name ( keys %$tag_hash ) {
79                                  next if $name eq '_content';                                  next if $name eq '_content';
# Line 80  my $parser = XML::Rules->new( Line 82  my $parser = XML::Rules->new(
82                                  $state->{DeviceID}->{ $key } = _tag( $tag_hash, $name, '_content' );                                  $state->{DeviceID}->{ $key } = _tag( $tag_hash, $name, '_content' );
83                          }                          }
84                  },                  },
85                  qr/EventStruct/ => sub {                  'EventStruct' => sub {
86                          my ($tag_name, $tag_hash, $context, $parent_data) = @_;                          my ($tag_name, $tag_hash, $context, $parent_data) = @_;
87                          push @{ $state->{EventStruct} }, $tag_hash->{EventCode}->{_content};                          push @{ $state->{EventStruct} }, $tag_hash->{EventCode}->{_content};
88                  },                  },
# Line 88  my $parser = XML::Rules->new( Line 90  my $parser = XML::Rules->new(
90                          my ($tag_name, $tag_hash, $context, $parent_data) = @_;                          my ($tag_name, $tag_hash, $context, $parent_data) = @_;
91                          $state->{$tag_name} = $tag_hash->{_content};                          $state->{$tag_name} = $tag_hash->{_content};
92                  },                  },
93                  qr/ParameterValueStruct/ => sub {                  'ParameterValueStruct' => sub {
94                          my ($tag_name, $tag_hash, $context, $parent_data) = @_;                          my ($tag_name, $tag_hash, $context, $parent_data) = @_;
95                          # Name/Value tags must be case insnesitive                          # Name/Value tags must be case insnesitive
96                          my $value = (grep( /value/i, keys %$tag_hash ))[0];                          my $value = (grep( /value/i, keys %$tag_hash ))[0];
# Line 98  my $parser = XML::Rules->new( Line 100  my $parser = XML::Rules->new(
100                  # GetRPCMethodsResponse                  # GetRPCMethodsResponse
101                  #                  #
102                  qr/^(?:^\w+:)*string$/ => 'content array',                  qr/^(?:^\w+:)*string$/ => 'content array',
103                  qr/MethodList/ => sub {                  'MethodList' => sub {
104                          my ($tag_name, $tag_hash, $context, $parent_data) = @_;                          my ($tag_name, $tag_hash, $context, $parent_data) = @_;
105                          $state->{MethodList} = _tag( $tag_hash, 'string' );                          $state->{MethodList} = _tag( $tag_hash, 'string' );
106                  },                        },
107                    #
108                    # GetParameterNamesResponse
109                    #
110                    'ParameterInfoStruct' => sub {
111                            my ($tag_name, $tag_hash, $context, $parent_data) = @_;
112                            my $name = _tag($tag_hash, 'Name', '_content');
113                            my $writable = _tag($tag_hash, 'Writable', '_content' );
114    
115                            confess "need state" unless ( $state ); # don't remove!
116    
117                            # XXX dragons ahead: convert name to tree rewriting it into perl
118    
119                            my $s = $name;
120                            warn "===> $name\n";
121                            $s =~ s/^([^\.]+)/\$state->{ParameterInfo}->{'$1'}/;
122                            warn "---> $s\n";
123    
124                            my $stat;
125                            while ( $s =~ s/\.(\d+)/->[$1]/ ) {
126                                    $stat->{array}++;
127                                    warn "-\@-> $s\n";
128                            }
129                            while ( $s =~ s/\.([a-zA-Z0-9_]+)/->{'$1'}/ ) {
130                                    $stat->{scalar}++;
131                                    warn "-\$-> $s\n";
132                            };
133                            $s .= "->{'writable'} = $writable;";
134    
135                            warn "## $name\n## tree: $s\n## stat: ",dump( $stat ), "\n";
136    
137                            eval "$s";
138                            confess "can't eval $s : $@" if ($@);
139    
140                            #warn "## state = dump( $state ), "\n";
141                    },
142                    #
143                    # Fault
144                    #
145                    'Fault' => sub {
146                            my ($tag_name, $tag_hash, $context, $parent_data) = @_;
147                            $state->{Fault} = {
148                                    FaultCode => _tag( $tag_hash, 'FaultCode', '_content' ),
149                                    FaultString => _tag( $tag_hash, 'FaultString', '_content' ),
150                            };
151                            warn "FAULT: ", $state->{Fault}->{FaultCode}, " ", $state->{Fault}->{FaultString}, "\n";
152                    }
153          ]          ]
154  );  );
155    

Legend:
Removed from v.36  
changed lines
  Added in v.92

  ViewVC Help
Powered by ViewVC 1.1.26