/[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 117 by dpavlin, Fri Oct 26 15:11:50 2007 UTC revision 150 by dpavlin, Sat Oct 27 22:53:14 2007 UTC
# Line 7  use warnings; Line 7  use warnings;
7  use base qw/Class::Accessor/;  use base qw/Class::Accessor/;
8  __PACKAGE__->mk_accessors( qw/  __PACKAGE__->mk_accessors( qw/
9  debug  debug
10  store_path  store
11    
12  sock  sock
13  state  state
# Line 34  CWMP::Session - implement logic of CWMP Line 34  CWMP::Session - implement logic of CWMP
34    
35    my $server = CWMP::Session->new({    my $server = CWMP::Session->new({
36          sock => $io_socket_object,          sock => $io_socket_object,
37          store_path => 'state.db',          store => 'state.db',
38          queue => [ qw/GetRPCMethods GetParameterNames/ ],          queue => [ qw/GetRPCMethods GetParameterNames/ ],
39          debug => 1,          debug => 1,
40    });    });
# Line 51  sub new { Line 51  sub new {
51    
52          warn "created ", __PACKAGE__, "(", dump( @_ ), ") for ", $self->sock->peerhost, "\n" if $self->debug;          warn "created ", __PACKAGE__, "(", dump( @_ ), ") for ", $self->sock->peerhost, "\n" if $self->debug;
53    
54          $self->store( CWMP::Store->new({          my $store_obj = CWMP::Store->new({
55                  debug => $self->debug,                  debug => $self->debug,
56                  path => $self->store_path,                  %{ $self->store },
57          }) );          });
58    
59            croak "can't open ", dump( $self->store ), ": $!" unless $store_obj;
60    
61          croak "can't open ", $self->store_path, ": $!" unless $self->store;          # FIXME looks ugly. Should we have separate accessor for this?
62            $self->store( $store_obj );
63    
64          return $self;          return $self;
65  }  }
# Line 102  sub process_request { Line 105  sub process_request {
105          warn "<<<< ", $sock->peerhost, " [" . localtime() . "] ", $r->method, " ", $r->uri, " $size bytes\n";          warn "<<<< ", $sock->peerhost, " [" . localtime() . "] ", $r->method, " ", $r->uri, " $size bytes\n";
106    
107          if ( $self->debug > 2 ) {          if ( $self->debug > 2 ) {
108                  my $file = sprintf("dump/%04d.request", $dump_nr);                  my $file = sprintf("dump/%04d-%s.request", $dump_nr++, $sock->peerhost);
109                  write_file( $file, $r->as_string );                  write_file( $file, $r->as_string );
110                  warn "### request dump: $file\n";                  warn "### request dump: $file\n";
111          }          }
# Line 113  sub process_request { Line 116  sub process_request {
116    
117                  die "no SOAPAction header in ",dump($chunk) unless defined ( $r->header('SOAPAction') );                  die "no SOAPAction header in ",dump($chunk) unless defined ( $r->header('SOAPAction') );
118    
119                    $state = CWMP::Request->parse( $chunk );
120    
121                  if ( $chunk ) {                  warn "## acquired state = ", dump( $state ), "\n";
                         warn "## request chunk: ",length($chunk)," bytes\n$chunk\n" if $self->debug;  
   
                         $state = CWMP::Request->parse( $chunk );  
122    
123                          warn "## acquired state = ", dump( $state ), "\n";                  $self->state( $state );
124                    $self->store->update_state( ID => $state->{ID}, $state );
125    
126                          $self->state( $state );          } else {
                         $self->store->update_state( ID => $state->{ID}, $state );  
127    
128                  } else {                  warn "## empty request, using last request state\n";
                         warn "## empty request\n";  
                 }  
129    
         } else {  
130                  $state = $self->state;                  $state = $self->state;
131                  warn "last request state = ", dump( $state ), "\n" if $self->debug > 1;                  delete( $state->{_dispatch} );
132                    #warn "last request state = ", dump( $state ), "\n" if $self->debug > 1;
133          }          }
134    
135    
# Line 150  sub process_request { Line 149  sub process_request {
149          } elsif ( $dispatch = shift @{ $self->queue } ) {          } elsif ( $dispatch = shift @{ $self->queue } ) {
150                  $xml = $self->dispatch( $dispatch );                  $xml = $self->dispatch( $dispatch );
151          } elsif ( $size == 0 ) {          } elsif ( $size == 0 ) {
152                  warn ">>> closing connection\n";                  warn ">>> no more queued commands, closing connection\n";
153                  return 0;                  return 0;
154          } else {          } else {
155                  warn ">>> empty response\n";                  warn ">>> empty response\n";
# Line 188  sub dispatch { Line 187  sub dispatch {
187                  my $xml = $response->$dispatch( $self->state, @_ );                  my $xml = $response->$dispatch( $self->state, @_ );
188                  warn "## response payload: ",length($xml)," bytes\n$xml\n" if $self->debug;                  warn "## response payload: ",length($xml)," bytes\n$xml\n" if $self->debug;
189                  if ( $self->debug > 2 ) {                  if ( $self->debug > 2 ) {
190                          my $file = sprintf("dump/%04d.response", $dump_nr++);                          my $file = sprintf("dump/%04d-%s.response", $dump_nr++, $self->sock->peerhost);
191                          write_file( $file, $xml );                          write_file( $file, $xml );
192                          warn "### response dump: $file\n";                          warn "### response dump: $file\n";
193                  }                  }

Legend:
Removed from v.117  
changed lines
  Added in v.150

  ViewVC Help
Powered by ViewVC 1.1.26