From b5312b7c069d4c93c9be9f2c1aa713d8ec441c05 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 4 Mar 2010 21:22:08 +0000 Subject: [PATCH] fix for ERROR: no ID in state Message-ID: <95a4ccfc0901140401w41ec15d3o86dcffbc355389b1@mail.gmail.com> Date: Wed, 14 Jan 2009 13:01:32 +0100 Author: "Lars Thegler" To: "Perl CWMP server" Subject: [perl-cwmp] Re: Help needed: ERROR: no ID in state On Wed, Jan 14, 2009 at 11:42 AM, tagg wrote: > At $WORK, we've worked a bit with the ZyXEL 2602, and had to change > some code to make it work. Patch attached. Some notes: * The soap:Header/cwmp:ID element is indeed optional [1], and the ZyXEL doesn't send it. * In SetParamenterValues, there is no ParameterNames element [2]. The Thomson devices ignore it, but the ZyXEL device croaks. * The server must not close the connection, only the client may do so [3]. The Thomson devices survive this gracefully, but the ZyXEL just gets confused. Hope this helps. /Lars [1] TR.069, p. 17. [2] TR-069, p. 31. [3] TR-069, p. 25. git-svn-id: https://perl-cwmp.googlecode.com/svn/trunk@244 836a5e1a-633d-0410-964b-294494ad4392 --- lib/CWMP/Methods.pm | 25 +++++++++++-------------- lib/CWMP/Session.pm | 10 ++++------ t/methods/SetParameterValues.xml | 18 ++++++++---------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/lib/CWMP/Methods.pm b/lib/CWMP/Methods.pm index f032733..c529ed3 100644 --- a/lib/CWMP/Methods.pm +++ b/lib/CWMP/Methods.pm @@ -51,17 +51,16 @@ sub xml { confess "no state?" unless ($state); confess "no body closure" unless ( $closure ); - confess "no ID in state ", dump( $state ) unless ( $state->{ID} ); - #warn "state used to generate xml = ", dump( $state ) if $self->debug; my $X = XML::Generator->new(':pretty'); + my @header; + push( @header, $X->ID( $cwmp, { mustUnderstand => 1 }, $state->{ID} )) if $state->{ID}; + push( @header, $X->NoMoreRequests( $cwmp, $state->{NoMoreRequests} || 0 )); + return $X->Envelope( $soap, { 'soap:encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/" }, - $X->Header( $soap, - $X->ID( $cwmp, { mustUnderstand => 1 }, $state->{ID} ), - $X->NoMoreRequests( $cwmp, $state->{NoMoreRequests} || 0 ), - ), + $X->Header( $soap, @header ), $X->Body( $soap, $closure->( $X, $state ) ), ); } @@ -112,14 +111,12 @@ sub SetParameterValues { $X->SetParameterValues( $cwmp, $X->ParameterList( $cwmp, - $X->ParameterNames( $cwmp, - map { - $X->ParameterValueStruct( $cwmp, - $X->Name( $cwmp, $_ ), - $X->Value( $cwmp, $params->{$_} ) - ) - } sort keys %$params - ) + map { + $X->ParameterValueStruct( $cwmp, + $X->Name( $cwmp, $_ ), + $X->Value( $cwmp, $params->{$_} ) + ) + } sort keys %$params ) ); }); diff --git a/lib/CWMP/Session.pm b/lib/CWMP/Session.pm index 52140c3..27a2557 100644 --- a/lib/CWMP/Session.pm +++ b/lib/CWMP/Session.pm @@ -198,18 +198,16 @@ sub process_request { $xml = $self->dispatch( $dispatch ); } elsif ( $job = $queue->dequeue ) { $xml = $self->dispatch( $job->dispatch ); - } elsif ( $size == 0 ) { - warn ">>> over, closing connection $to_uid"; - $sock->close; - return; } else { warn ">>> empty response $to_uid"; $state->{NoMoreRequests} = 1; - $xml = $self->dispatch( 'xml', sub {} ); + $xml = ''; } $sock->send( "Content-Length: " . length( $xml ) . "\r\n\r\n" ); - $sock->send( $xml ) or die "can't send response"; + if (length($xml)) { + $sock->send( $xml ) or die "can't send response"; + } warn ">>>> " . $ip . " [" . localtime() . "] sent ", length( $xml )," bytes $to_uid"; diff --git a/t/methods/SetParameterValues.xml b/t/methods/SetParameterValues.xml index 2bf5ab3..f72471c 100644 --- a/t/methods/SetParameterValues.xml +++ b/t/methods/SetParameterValues.xml @@ -8,16 +8,14 @@ - - - InternetGatewayDevice.DeviceInfo.ProvisioningCode - test provision - - - InternetGatewayDevice.DeviceInfo.X_000E50_Country - 42 - - + + InternetGatewayDevice.DeviceInfo.ProvisioningCode + test provision + + + InternetGatewayDevice.DeviceInfo.X_000E50_Country + 42 + -- 2.20.1