From 404719834facfd31ccd878872a42697bab78d368 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 28 Oct 2007 13:01:03 +0000 Subject: [PATCH] - implement parametars to commands in queue (just pass array as command) - 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 | 2 +- bin/acs.pl | 11 ++++++----- lib/CWMP/Session.pm | 26 +++++++++++++++++++------- lib/CWMP/Store.pm | 11 ++++------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 25d66c7..7431569 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -3,7 +3,7 @@ use lib './lib'; use inc::Module::Install; name 'CWMP'; -version '0.05'; +version '0.06'; license 'GPL'; requires 'Net::Server'; requires 'HTTP::Daemon'; diff --git a/bin/acs.pl b/bin/acs.pl index ddfa2b8..c472fd6 100755 --- a/bin/acs.pl +++ b/bin/acs.pl @@ -30,11 +30,12 @@ my $server = CWMP::Server->new({ 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(); diff --git a/lib/CWMP/Session.pm b/lib/CWMP/Session.pm index bd24efd..b128f66 100644 --- a/lib/CWMP/Session.pm +++ b/lib/CWMP/Session.pm @@ -35,7 +35,10 @@ CWMP::Session - implement logic of CWMP protocol 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, }); @@ -98,25 +101,27 @@ sub process_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 "### request dump: $file\n"; + warn "### request dumped to file: $file\n"; } 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"; @@ -179,12 +184,19 @@ sub 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 $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); diff --git a/lib/CWMP/Store.pm b/lib/CWMP/Store.pm index 8bd72a5..37c3a84 100644 --- a/lib/CWMP/Store.pm +++ b/lib/CWMP/Store.pm @@ -63,7 +63,7 @@ sub current_store { 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; } @@ -84,7 +84,7 @@ sub update_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; @@ -117,7 +117,7 @@ sub get_state { 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; @@ -166,7 +166,7 @@ sub ID_to_uid { 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(); @@ -183,13 +183,10 @@ sub ID_to_uid { return $uid; } else { warn "## can't find uid for ID $ID, first seen?\n"; - return; } # TODO: expire sessions longer than 30m - warn "current session = ",dump( $session ); - return; } -- 2.20.1