fix for ERROR: no ID in state
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 4 Mar 2010 21:22:08 +0000 (21:22 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 4 Mar 2010 21:22:08 +0000 (21:22 +0000)
Message-ID: <95a4ccfc0901140401w41ec15d3o86dcffbc355389b1@mail.gmail.com>
Date: Wed, 14 Jan 2009 13:01:32 +0100
Author: "Lars Thegler" <lars.thegler@gmail.com>
To: "Perl CWMP server" <perl-cwmp@googlegroups.com>
Subject: [perl-cwmp] Re: Help needed: ERROR: no ID in state

On Wed, Jan 14, 2009 at 11:42 AM, tagg <lars.thegler@gmail.com> 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
lib/CWMP/Session.pm
t/methods/SetParameterValues.xml

index f032733..c529ed3 100644 (file)
@@ -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
                        )
                );
        });
index 52140c3..27a2557 100644 (file)
@@ -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";
 
index 2bf5ab3..f72471c 100644 (file)
@@ -8,16 +8,14 @@
   <soap:Body>
     <cwmp:SetParameterValues>
       <cwmp:ParameterList>
-        <cwmp:ParameterNames>
-          <cwmp:ParameterValueStruct>
-            <cwmp:Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</cwmp:Name>
-            <cwmp:Value>test provision</cwmp:Value>
-          </cwmp:ParameterValueStruct>
-          <cwmp:ParameterValueStruct>
-            <cwmp:Name>InternetGatewayDevice.DeviceInfo.X_000E50_Country</cwmp:Name>
-            <cwmp:Value>42</cwmp:Value>
-          </cwmp:ParameterValueStruct>
-        </cwmp:ParameterNames>
+        <cwmp:ParameterValueStruct>
+          <cwmp:Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</cwmp:Name>
+          <cwmp:Value>test provision</cwmp:Value>
+        </cwmp:ParameterValueStruct>
+        <cwmp:ParameterValueStruct>
+          <cwmp:Name>InternetGatewayDevice.DeviceInfo.X_000E50_Country</cwmp:Name>
+          <cwmp:Value>42</cwmp:Value>
+        </cwmp:ParameterValueStruct>
       </cwmp:ParameterList>
     </cwmp:SetParameterValues>
   </soap:Body>