/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 186 - (hide annotations)
Tue Oct 30 15:26:41 2007 UTC (16 years, 6 months ago) by dpavlin
File size: 4240 byte(s)
added a pod documentation
1 dpavlin 31 package CWMP::Request;
2    
3     use warnings;
4     use strict;
5    
6     use XML::Rules;
7 dpavlin 103 use CWMP::Tree;
8 dpavlin 31 use Data::Dump qw/dump/;
9     use Carp qw/confess cluck/;
10    
11     =head1 NAME
12    
13 dpavlin 186 CWMP::Request - parse SOAP request metods
14 dpavlin 31
15     =head1 METHODS
16    
17     =head2 _tag
18    
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>).
22    
23     _tag( $tag_hash, $name, $sub_key )
24    
25     =cut
26    
27     sub _tag {
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];
31     # $name =~ s/^\w+://;
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};
37     } else {
38     return if ( $name =~ m/^value$/i );
39     warn "can't find '$name/$sub_key' in ", dump( $tag_hash );
40     return;
41     }
42     } else {
43     warn "can't find '$name' in ", dump( $tag_hash );
44     return;
45     }
46     }
47    
48 dpavlin 186 =head2 parse
49    
50     my $state = CWMP::Request->parse( "<soap>request</soap>" );
51    
52     =cut
53    
54     sub parse {
55     my $self = shift;
56    
57     my $xml = shift || confess "no xml?";
58    
59     $state = {};
60     $parser->parsestring( $xml );
61     return $state;
62     }
63    
64     =head1 CPE metods
65    
66     =cut
67    
68 dpavlin 90 our $state; # FIXME check this!
69 dpavlin 31
70 dpavlin 103 my $tree = CWMP::Tree->new({ debug => 0 });
71    
72 dpavlin 31 my $parser = XML::Rules->new(
73     # start_rules => [
74     # '^division_name,fax' => 'skip',
75     # ],
76     namespaces => {
77 dpavlin 62 '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 dpavlin 31 'urn:dslforum-org:cwmp-1-0' => '',
82     },
83     rules => [
84     #_default => 'content trim',
85     x_default => sub {
86     my ($tag_name, $tag_hash, $context, $parent_data) = @_;
87     warn dump( $tag_name, $tag_hash, $context );
88     },
89     'ID' => sub {
90     my ($tag_name, $tag_hash, $context, $parent_data) = @_;
91     $state->{ID} = $tag_hash->{_content};
92     },
93 dpavlin 186
94     =head2 Inform
95    
96     Generate InformResponse to CPE
97    
98     =cut
99    
100 dpavlin 36 'Inform' => sub {
101 dpavlin 71 $state->{_dispatch} = 'InformResponse'; # what reponse to call
102 dpavlin 36 },
103 dpavlin 65 'DeviceId' => sub {
104 dpavlin 31 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
105     foreach my $name ( keys %$tag_hash ) {
106     next if $name eq '_content';
107     my $key = $name;
108     $key =~ s/^\w+://; # stip namespace
109     $state->{DeviceID}->{ $key } = _tag( $tag_hash, $name, '_content' );
110     }
111     },
112 dpavlin 65 'EventStruct' => sub {
113 dpavlin 31 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
114     push @{ $state->{EventStruct} }, $tag_hash->{EventCode}->{_content};
115     },
116     qr/(MaxEnvelopes|CurrentTime|RetryCount)/ => sub {
117     my ($tag_name, $tag_hash, $context, $parent_data) = @_;
118     $state->{$tag_name} = $tag_hash->{_content};
119     },
120 dpavlin 65 'ParameterValueStruct' => sub {
121 dpavlin 31 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' );
125     },
126 dpavlin 186
127     =head2 GetRPCMethodsResponse
128    
129     =cut
130 dpavlin 31 qr/^(?:^\w+:)*string$/ => 'content array',
131 dpavlin 65 'MethodList' => sub {
132 dpavlin 31 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
133     $state->{MethodList} = _tag( $tag_hash, 'string' );
134 dpavlin 65 },
135 dpavlin 186
136     =head2 GetParameterNamesResponse
137    
138     =cut
139    
140 dpavlin 65 'ParameterInfoStruct' => sub {
141     my ($tag_name, $tag_hash, $context, $parent_data) = @_;
142 dpavlin 90 my $name = _tag($tag_hash, 'Name', '_content');
143     my $writable = _tag($tag_hash, 'Writable', '_content' );
144    
145     confess "need state" unless ( $state ); # don't remove!
146    
147     # XXX dragons ahead: convert name to tree rewriting it into perl
148 dpavlin 103 my $s = '$state->{ParameterInfo}->' . $tree->name2perl( $name ) . "->{writable} = $writable;";
149 dpavlin 90 eval "$s";
150     confess "can't eval $s : $@" if ($@);
151    
152 dpavlin 92 #warn "## state = dump( $state ), "\n";
153 dpavlin 65 },
154 dpavlin 186
155     =head2 Fault
156    
157     =cut
158    
159 dpavlin 65 'Fault' => sub {
160 dpavlin 50 my ($tag_name, $tag_hash, $context, $parent_data) = @_;
161     $state->{Fault} = {
162     FaultCode => _tag( $tag_hash, 'FaultCode', '_content' ),
163     FaultString => _tag( $tag_hash, 'FaultString', '_content' ),
164     };
165     warn "FAULT: ", $state->{Fault}->{FaultCode}, " ", $state->{Fault}->{FaultString}, "\n";
166     }
167 dpavlin 31 ]
168     );
169    
170 dpavlin 32 1;

  ViewVC Help
Powered by ViewVC 1.1.26