r216@brr: dpavlin | 2007-11-14 22:52:27 +0100
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 14 Nov 2007 21:52:45 +0000 (21:52 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 14 Nov 2007 21:52:45 +0000 (21:52 +0000)
 - added create_dump accessor to create dump files on disk
 - if acquired state doesn't have DeviceID, use old one (so that store can map sessions)

git-svn-id: https://perl-cwmp.googlecode.com/svn/trunk@201 836a5e1a-633d-0410-964b-294494ad4392

lib/CWMP/Session.pm

index ff6d95d..25fef34 100644 (file)
@@ -7,6 +7,7 @@ use warnings;
 use base qw/Class::Accessor/;
 __PACKAGE__->mk_accessors( qw/
 debug
+create_dump
 store
 
 sock
@@ -35,6 +36,7 @@ CWMP::Session - implement logic of CWMP protocol
        sock => $io_socket_object,
        store => 'state.db',
        debug => 1,
+       create_dump => 1,
   });
 
 =cut
@@ -59,6 +61,8 @@ sub new {
        # FIXME looks ugly. Should we have separate accessor for this?
        $self->store( $store_obj );
 
+       $self->create_dump( 1 ) if $self->debug > 2;
+
        return $self;
 }
 
@@ -105,7 +109,7 @@ sub process_request {
        $dump_nr++;
        my $file = sprintf("dump/%04d-%s.request", $dump_nr, $sock->peerhost);
 
-       if ( $self->debug > 2 ) {
+       if ( $self->create_dump ) {
                write_file( $file, $r->as_string );
                warn "### request dumped to file: $file\n";
        }
@@ -120,13 +124,18 @@ sub process_request {
 
                $state = CWMP::Request->parse( $xml );
 
-               if ( defined( $state->{_dispatch} ) && $self->debug > 2 ) {
+               if ( defined( $state->{_dispatch} ) && $self->create_dump ) {
                        my $type = sprintf("dump/%04d-%s-%s", $dump_nr, $sock->peerhost, $state->{_dispatch});
                        symlink $file, $type || warn "can't symlink $file -> $type: $!";
                }
 
                warn "## acquired state = ", dump( $state ), "\n";
 
+               if ( ! defined( $state->{DeviceID} ) ) {
+                       warn "## state with DeviceID, using old one...\n";
+                       $state->{DeviceID} = $self->state->{DeviceID};
+               }
+
                $self->state( $state );
                $self->store->update_state( ID => $state->{ID}, $state );
 
@@ -204,7 +213,7 @@ warn "##!!! dispatch(",dump( @_ ),")\n";
                warn ">>> dispatching to $dispatch with args ",dump( $args ),"\n";
                my $xml = $response->$dispatch( $self->state, $args );
                warn "## response payload: ",length($xml)," bytes\n$xml\n" if $self->debug;
-               if ( $self->debug > 2 ) {
+               if ( $self->create_dump ) {
                        my $file = sprintf("dump/%04d-%s.response", $dump_nr++, $self->sock->peerhost);
                        write_file( $file, $xml );
                        warn "### response dump: $file\n";