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

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

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

revision 55 by dpavlin, Wed Jun 20 20:49:53 2007 UTC revision 77 by dpavlin, Fri Jun 22 13:09:08 2007 UTC
# Line 8  use base qw/Class::Accessor/; Line 8  use base qw/Class::Accessor/;
8  __PACKAGE__->mk_accessors( qw/  __PACKAGE__->mk_accessors( qw/
9  debug  debug
10  port  port
11    store_path
12    
13  sock  sock
14  state  state
15  queue  queue
16    store
17  / );  / );
18    
19  use IO::Socket::INET;  use IO::Socket::INET;
20  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
21    use Carp qw/confess cluck croak/;
22    
23  use CWMP::Request;  use CWMP::Request;
24  use CWMP::Response;  use CWMP::Response;
25  use Carp qw/confess cluck/;  use CWMP::Store;
26    
27  =head1 NAME  =head1 NAME
28    
# Line 27  CWMP::Server - implement logic of CWMP p Line 32  CWMP::Server - implement logic of CWMP p
32    
33  =head2 new  =head2 new
34    
35    my $server = CWMP::Server->new({ port => 3333 });    my $server = CWMP::Server->new({
36            port => 3333,
37            store_path => 'state.db',
38            debug => 1,
39      });
40    
41  =head2 run  =head2 run
42    
# Line 51  sub run { Line 60  sub run {
60                  $self->queue ? " queue ( " . join(",",@{$self->queue}) . " )" : "",                  $self->queue ? " queue ( " . join(",",@{$self->queue}) . " )" : "",
61                  "\n";                  "\n";
62    
63            $self->debug( 0 ) unless $self->debug;
64          warn "## debug level: ", $self->debug, "\n" if $self->debug;          warn "## debug level: ", $self->debug, "\n" if $self->debug;
65    
66            $self->store( CWMP::Store->new({
67                    debug => $self->debug,
68                    path => $self->store_path,
69            }) );
70            croak "can't open ", $self->store_path, ": $!" unless $self->store;
71    
72          while ( my $sock = $listen->accept ) {          while ( my $sock = $listen->accept ) {
73                  $sock->autoflush(1);                  $sock->autoflush(1);
74    
# Line 120  sub process_request { Line 136  sub process_request {
136    
137                  do {                  do {
138    
139                          warn "get chunk len\n" if $self->debug;                          warn "get chunk len\n" if $self->debug > 1;
140                                                    
141                          my $hex;                          my $hex;
142                          do {                          do {
# Line 131  sub process_request { Line 147  sub process_request {
147                          die "chunk size not valid hex: $hex" unless ( $hex =~ m/^[0-9a-f]+$/i);                          die "chunk size not valid hex: $hex" unless ( $hex =~ m/^[0-9a-f]+$/i);
148                          $len = hex( $hex );                          $len = hex( $hex );
149    
150                          warn "getting chunk of $len bytes\n" if $self->debug;                          warn "getting chunk of $len bytes\n" if $self->debug > 1;
151    
152                          $sock->read( my $buff, $len );                          $sock->read( my $buff, $len );
153                          $chunk .= $buff;                          $chunk .= $buff;
154    
155                          warn "--- $len bytes: --=>||$buff||<=--\n" if $self->debug;                          warn "--- $len bytes: --=>||$buff||<=--\n" if $self->debug > 1;
156    
157                  } while ( $len > 0 );                  } while ( $len > 0 );
158                  my $sep = $sock->getline;                  my $sep = $sock->getline;
# Line 148  sub process_request { Line 164  sub process_request {
164    
165          my $size = length( $chunk );          my $size = length( $chunk );
166    
167          warn "<<< " . $sock->peerhost . " [" . localtime() . "] request $size bytes\n";          warn "<<<< " . $sock->peerhost . " [" . localtime() . "] request $size bytes\n";
168    
169          my $state;          my $state;
170    
# Line 162  sub process_request { Line 178  sub process_request {
178    
179                          $state = CWMP::Request->parse( $chunk );                          $state = CWMP::Request->parse( $chunk );
180    
181                          warn "acquired state = ", dump( $state ), "\n";                          warn "## acquired state = ", dump( $state ), "\n";
182    
183                          $self->state( $state );                          $self->state( $state );
184    
185                  } else {                  } else {
186                          warn "empty request\n";                          warn "## empty request\n";
187                  }                  }
188    
189          } else {          } else {
190                  $state = $self->state;                  $state = $self->state;
191                  warn "last request state = ", dump( $state ), "\n";                  warn "last request state = ", dump( $state ), "\n" if $self->debug > 1;
192          }          }
193    
194    
# Line 203  sub process_request { Line 219  sub process_request {
219          $sock->send( "Content-Length: " . length( $xml ) . "\r\n\r\n" );          $sock->send( "Content-Length: " . length( $xml ) . "\r\n\r\n" );
220          $sock->send( $xml ) or die "can't send response";          $sock->send( $xml ) or die "can't send response";
221    
222          warn "### request over";          warn ">>>> " . $sock->peerhost . " [" . localtime() . "] sent ", length( $xml )," bytes\n";
223    
224            warn "### request over\n" if $self->debug;
225    
226            return 1;       # next request
227  };  };
228    
229  =head2 dispatch  =head2 dispatch
# Line 222  sub dispatch { Line 241  sub dispatch {
241    
242          if ( $response->can( $dispatch ) ) {          if ( $response->can( $dispatch ) ) {
243                  warn ">>> dispatching to $dispatch\n";                  warn ">>> dispatching to $dispatch\n";
244                  my $xml = $response->$dispatch( $self->state, @_ ) . "\r\n";                  my $xml = $response->$dispatch( $self->state, @_ );
245                  warn "## response payload: ",length($xml)," bytes\n$xml\n" if $self->debug;                  warn "## response payload: ",length($xml)," bytes\n$xml\n" if $self->debug;
246                  return $xml;                  return $xml;
247          } else {          } else {

Legend:
Removed from v.55  
changed lines
  Added in v.77

  ViewVC Help
Powered by ViewVC 1.1.26