/[cwmp]/google/trunk/lib/CWMP/Session.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/Session.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (hide annotations)
Tue Jun 19 00:18:56 2007 UTC (16 years, 11 months ago) by dpavlin
Original Path: google/lib/CWMP/Server.pm
File size: 1880 byte(s)
and fix it to actually work
1 dpavlin 30 # Dobrica Pavlinusic, <dpavlin@rot13.org> 06/18/07 10:19:50 CEST
2     package CWMP::Server;
3    
4     use strict;
5     use warnings;
6    
7     use base qw/HTTP::Server::Simple::CGI Class::Accessor/;
8     __PACKAGE__->mk_accessors( qw/
9     debug
10     / );
11    
12     use Data::Dump qw/dump/;
13 dpavlin 35 use CWMP::Request;
14     use CWMP::Response;
15 dpavlin 30
16 dpavlin 34 =head1 NAME
17    
18     CWMP::Server - implement logic of CWMP protocol
19    
20     =head1 METHODS
21    
22     =head2 handler
23    
24     We override L<HTTP::Server::Simple::CGI/handler> so that we can support
25     chunked transfer encoding.
26    
27     =cut
28    
29 dpavlin 30 sub handler {
30     my $self = shift;
31    
32     my $chunk;
33    
34     my $transfer_encoding = $self->header('Transfer-Encoding');
35    
36     if ( $transfer_encoding && $transfer_encoding =~ qr/^chunked/i ) {
37    
38 dpavlin 31 my $len = 0;
39 dpavlin 35 my $hex;
40 dpavlin 30 do {
41 dpavlin 35 $hex = <STDIN>; # get chunk length
42     $hex =~ s/[\n\r]*$//s;
43     $len = hex( $hex );
44 dpavlin 30
45 dpavlin 35 warn "getting chunk of 0x$hex $len bytes\n" if $self->debug;
46 dpavlin 30
47     while( $len > 0 ) {
48     my $line = <STDIN>;
49     $chunk .= $line;
50     $len -= length( $line );
51     }
52    
53 dpavlin 35 } while ( hex( $hex ) != 0 );
54 dpavlin 30 }
55    
56 dpavlin 35 warn "handler got ", length($chunk), " bytes\n" if $self->debug;
57 dpavlin 30
58     my $cgi = new CGI( $chunk );
59    
60     eval { $self->handle_request($cgi) };
61     if ($@) {
62     my $error = $@;
63     warn $error;
64     }
65     }
66    
67 dpavlin 34 =head2 handle_request
68    
69     Implementation of dispatch logic
70    
71     =cut
72    
73 dpavlin 30 sub handle_request {
74     my ($self, $cgi) = @_;
75    
76     #... do something, print output to default
77     # selected filehandle...
78    
79 dpavlin 34 warn ">> " . localtime() . " " . $ENV{REMOTE_ADDR} . "\n";
80 dpavlin 30
81     warn "not SOAP request" unless defined ( $cgi->header('SOAPAction') );
82    
83 dpavlin 34 if ( my $payload = $cgi->param('POSTDATA') ) {
84     warn "request payload:\n$payload\n" if $self->debug;
85 dpavlin 30
86 dpavlin 34 my $state = CWMP::Request->parse( $payload );
87    
88     warn "acquired state = ", dump( $state );
89    
90     }
91    
92 dpavlin 35 my $response = CWMP::Response->new({ debug => $self->debug });
93 dpavlin 34
94 dpavlin 30 print "Content-Type: text/xml\r\n\r\n";
95    
96 dpavlin 34 print $response->Inform;
97    
98 dpavlin 30 };
99    
100     1;
101    

  ViewVC Help
Powered by ViewVC 1.1.26