/[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 50 - (hide annotations)
Tue Jun 19 21:29:04 2007 UTC (16 years, 10 months ago) by dpavlin
Original Path: google/lib/CWMP/Request.pm
File size: 3414 byte(s)
* added queue to send commands to CPE
* implemented parsing of Fault messages from CPE
* correctly emit NoMoreRequests in SOAP header
* close connection (not verified against TR-069 standard yet)
1 dpavlin 31 package CWMP::Request;
2    
3     use warnings;
4     use strict;
5    
6     use XML::Rules;
7     use Data::Dump qw/dump/;
8     use Carp qw/confess cluck/;
9    
10     =head1 NAME
11    
12     CWMP::Request - parse SOAP request
13    
14     =head1 METHODS
15    
16     =head2 _tag
17    
18     Get value of tag. Tag name is case insensitive (don't ask why),
19     we ignore namespaces and can take optional C<sub_key>
20     (usually C<_content>).
21    
22     _tag( $tag_hash, $name, $sub_key )
23    
24     =cut
25    
26     sub _tag {
27     my ( $tag_hash, $name, $sub_key ) = @_;
28     confess "need hash as first argument" unless ( ref $tag_hash eq 'HASH' );
29     $name = (grep { m/^(?:\w+:)*$name$/i } keys %$tag_hash )[0];
30     # $name =~ s/^\w+://;
31     if ( defined $tag_hash->{$name} ) {
32     if ( ! defined $sub_key ) {
33     return $tag_hash->{$name};
34     } elsif ( defined $tag_hash->{$name}->{$sub_key} ) {
35     return $tag_hash->{$name}->{$sub_key};
36     } else {
37     return if ( $name =~ m/^value$/i );
38     warn "can't find '$name/$sub_key' in ", dump( $tag_hash );
39     return;
40     }
41     } else {
42     warn "can't find '$name' in ", dump( $tag_hash );
43     return;
44     }
45     }
46    
47     my $state;
48    
49     my $parser = XML::Rules->new(
50     # start_rules => [
51     # '^division_name,fax' => 'skip',
52     # ],
53     namespaces => {
54     # 'http://schemas.xmlsoap.org/soap/envelope/' => 'soapenv',
55     # 'http://schemas.xmlsoap.org/soap/encoding/' => 'soap',
56     'urn:dslforum-org:cwmp-1-0' => '',
57     },
58     rules => [
59     #_default => 'content trim',
60     x_default => sub {
61     my ($tag_name, $tag_hash, $context, $parent_data) = @_;
62     warn dump( $tag_name, $tag_hash, $context );
63     },
64     'ID' => sub {
65     my ($tag_name, $tag_hash, $context, $parent_data) = @_;
66     $state->{ID} = $tag_hash->{_content};
67     },
68     #
69     # Inform
70     #
71 dpavlin 36 'Inform' => sub {
72     $state->{_dispatch} = 'Inform'; # what reponse to call
73     },
74 dpavlin 31 qr/DeviceId/ => sub {
75     my ($tag_name, $tag_hash, $context, $parent_data) = @_;
76     foreach my $name ( keys %$tag_hash ) {
77     next if $name eq '_content';
78     my $key = $name;
79     $key =~ s/^\w+://; # stip namespace
80     $state->{DeviceID}->{ $key } = _tag( $tag_hash, $name, '_content' );
81     }
82     },
83     qr/EventStruct/ => sub {
84     my ($tag_name, $tag_hash, $context, $parent_data) = @_;
85     push @{ $state->{EventStruct} }, $tag_hash->{EventCode}->{_content};
86     },
87     qr/(MaxEnvelopes|CurrentTime|RetryCount)/ => sub {
88     my ($tag_name, $tag_hash, $context, $parent_data) = @_;
89     $state->{$tag_name} = $tag_hash->{_content};
90     },
91     qr/ParameterValueStruct/ => sub {
92     my ($tag_name, $tag_hash, $context, $parent_data) = @_;
93     # Name/Value tags must be case insnesitive
94     my $value = (grep( /value/i, keys %$tag_hash ))[0];
95     $state->{Parameter}->{ _tag($tag_hash, 'Name', '_content') } = _tag($tag_hash, 'Value', '_content' );
96     },
97     #
98     # GetRPCMethodsResponse
99     #
100     qr/^(?:^\w+:)*string$/ => 'content array',
101     qr/MethodList/ => sub {
102     my ($tag_name, $tag_hash, $context, $parent_data) = @_;
103     $state->{MethodList} = _tag( $tag_hash, 'string' );
104     },
105 dpavlin 50 #
106     # Fault
107     #
108     qr/^Fault$/ => sub {
109     my ($tag_name, $tag_hash, $context, $parent_data) = @_;
110     $state->{Fault} = {
111     FaultCode => _tag( $tag_hash, 'FaultCode', '_content' ),
112     FaultString => _tag( $tag_hash, 'FaultString', '_content' ),
113     };
114     warn "FAULT: ", $state->{Fault}->{FaultCode}, " ", $state->{Fault}->{FaultString}, "\n";
115     }
116 dpavlin 31 ]
117     );
118    
119     =head2 parse
120    
121     my $state = CWMP::Request->parse( "<soap>request</soap>" );
122    
123     =cut
124    
125     sub parse {
126     my $self = shift;
127    
128     my $xml = shift || confess "no xml?";
129    
130     $state = {};
131     $parser->parsestring( $xml );
132     return $state;
133     }
134 dpavlin 32
135     1;

  ViewVC Help
Powered by ViewVC 1.1.26