- implement parametars to commands in queue (just pass array as command)
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 28 Oct 2007 13:01:03 +0000 (13:01 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 28 Oct 2007 13:01:03 +0000 (13:01 +0000)
- store debugging moved to debug level 4 (makes make dump much more useful)
- version bump [0.06]

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

Makefile.PL
bin/acs.pl
lib/CWMP/Session.pm
lib/CWMP/Store.pm

index 25d66c7..7431569 100644 (file)
@@ -3,7 +3,7 @@ use lib './lib';
 use inc::Module::Install;
 
 name           'CWMP';
 use inc::Module::Install;
 
 name           'CWMP';
-version                '0.05';
+version                '0.06';
 license                'GPL';
 requires       'Net::Server';
 requires       'HTTP::Daemon';
 license                'GPL';
 requires       'Net::Server';
 requires       'HTTP::Daemon';
index ddfa2b8..c472fd6 100755 (executable)
@@ -30,11 +30,12 @@ my $server = CWMP::Server->new({
                debug => $debug,
        },
        debug => $debug,
                debug => $debug,
        },
        debug => $debug,
-       default_queue => [ qw/
-               GetRPCMethods
-               GetParameterNames
-       / ],
-#              Reboot
+       default_queue => [
+               'GetRPCMethods',
+               [ 'GetParameterNames', 'InternetGatewayDevice.DeviceInfo.SerialNumber', 0 ],
+               [ 'GetParameterValues', 'InternetGatewayDevice.DeviceInfo.SerialNumber', 1 ],
+#              'Reboot',
+       ],
 });
 $server->run();
 
 });
 $server->run();
 
index bd24efd..b128f66 100644 (file)
@@ -35,7 +35,10 @@ CWMP::Session - implement logic of CWMP protocol
   my $server = CWMP::Session->new({
        sock => $io_socket_object,
        store => 'state.db',
   my $server = CWMP::Session->new({
        sock => $io_socket_object,
        store => 'state.db',
-       queue => [ qw/GetRPCMethods GetParameterNames/ ],
+       queue => [
+               'GetRPCMethods',
+               [ 'GetParameterValyes', 'InternetGatewayDevice.DeviceInfo.SerialNumber', 0 ],
+       ],
        debug => 1,
   });
 
        debug => 1,
   });
 
@@ -98,25 +101,27 @@ sub process_request {
 
        my $r = $sock->get_request || confess "can't get_request";
 
 
        my $r = $sock->get_request || confess "can't get_request";
 
-       my $chunk = $r->content;
+       my $xml = $r->content;
 
 
-       my $size = length( $chunk );
+       my $size = length( $xml );
 
        warn "<<<< ", $sock->peerhost, " [" . localtime() . "] ", $r->method, " ", $r->uri, " $size bytes\n";
 
        if ( $self->debug > 2 ) {
                my $file = sprintf("dump/%04d-%s.request", $dump_nr++, $sock->peerhost);
                write_file( $file, $r->as_string );
 
        warn "<<<< ", $sock->peerhost, " [" . localtime() . "] ", $r->method, " ", $r->uri, " $size bytes\n";
 
        if ( $self->debug > 2 ) {
                my $file = sprintf("dump/%04d-%s.request", $dump_nr++, $sock->peerhost);
                write_file( $file, $r->as_string );
-               warn "### request dump: $file\n";
+               warn "### request dumped to file: $file\n";
        }
 
        my $state;
 
        if ( $size > 0 ) {
 
        }
 
        my $state;
 
        if ( $size > 0 ) {
 
-               die "no SOAPAction header in ",dump($chunk) unless defined ( $r->header('SOAPAction') );
+               die "no SOAPAction header in ",dump($xml) unless defined ( $r->header('SOAPAction') );
 
 
-               $state = CWMP::Request->parse( $chunk );
+               warn "## request payload: ",length($xml)," bytes\n$xml\n" if $self->debug;
+
+               $state = CWMP::Request->parse( $xml );
 
                warn "## acquired state = ", dump( $state ), "\n";
 
 
                warn "## acquired state = ", dump( $state ), "\n";
 
@@ -179,12 +184,19 @@ sub dispatch {
        my $self = shift;
 
        my $dispatch = shift || die "no dispatch?";
        my $self = shift;
 
        my $dispatch = shift || die "no dispatch?";
+       my @args = @_;
+
+       if ( ref($dispatch) eq 'ARRAY' ) {
+               my @a = @$dispatch;
+               $dispatch = shift @a;
+               push @args, @a;
+       }
 
        my $response = CWMP::Response->new({ debug => $self->debug });
 
        if ( $response->can( $dispatch ) ) {
                warn ">>> dispatching to $dispatch\n";
 
        my $response = CWMP::Response->new({ debug => $self->debug });
 
        if ( $response->can( $dispatch ) ) {
                warn ">>> dispatching to $dispatch\n";
-               my $xml = $response->$dispatch( $self->state, @_ );
+               my $xml = $response->$dispatch( $self->state, @args );
                warn "## response payload: ",length($xml)," bytes\n$xml\n" if $self->debug;
                if ( $self->debug > 2 ) {
                        my $file = sprintf("dump/%04d-%s.response", $dump_nr++, $self->sock->peerhost);
                warn "## response payload: ",length($xml)," bytes\n$xml\n" if $self->debug;
                if ( $self->debug > 2 ) {
                        my $file = sprintf("dump/%04d-%s.response", $dump_nr++, $self->sock->peerhost);
index 8bd72a5..37c3a84 100644 (file)
@@ -63,7 +63,7 @@ sub current_store {
 
        confess "unknown store module $module not one of ", dump( $self->possible_stores ) unless $s;
 
 
        confess "unknown store module $module not one of ", dump( $self->possible_stores ) unless $s;
 
-       warn "## current store = $s\n" if $self->debug;
+       warn "#### current store = $s\n" if $self->debug > 4;
 
        return $s;
 }
 
        return $s;
 }
@@ -84,7 +84,7 @@ sub update_state {
        confess "need $k value" unless $v;
        confess "need state" unless $state;
 
        confess "need $k value" unless $v;
        confess "need state" unless $state;
 
-       warn "## update_state( $k => $v, ", dump( $state ), " )\n" if $self->debug;
+       warn "#### update_state( $k => $v, ", dump( $state ), " )\n" if $self->debug > 4;
 
        my $uid;
 
 
        my $uid;
 
@@ -117,7 +117,7 @@ sub get_state {
        confess "need ID or uid" unless $k =~ m/^(ID|uid)$/;
        confess "need $k value" unless $v;
 
        confess "need ID or uid" unless $k =~ m/^(ID|uid)$/;
        confess "need $k value" unless $v;
 
-       warn "## get_state( $k => $v )\n" if $self->debug;
+       warn "#### get_state( $k => $v )\n" if $self->debug > 4;
 
        my $uid;
 
 
        my $uid;
 
@@ -166,7 +166,7 @@ sub ID_to_uid {
 
        confess "need ID" unless $ID;
 
 
        confess "need ID" unless $ID;
 
-       warn "ID_to_uid",dump( $ID, $state ),$/ if $self->debug;
+       warn "#### ID_to_uid",dump( $ID, $state ),$/ if $self->debug > 4;
 
        $session->{ $ID }->{last_seen} = time();
 
 
        $session->{ $ID }->{last_seen} = time();
 
@@ -183,13 +183,10 @@ sub ID_to_uid {
                return $uid;
        } else {
                warn "## can't find uid for ID $ID, first seen?\n";
                return $uid;
        } else {
                warn "## can't find uid for ID $ID, first seen?\n";
-               return;
        }
 
        # TODO: expire sessions longer than 30m
 
        }
 
        # TODO: expire sessions longer than 30m
 
-       warn "current session = ",dump( $session );
-
        return;
 }
 
        return;
 }