X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=lib%2FCWMP%2FSession.pm;h=26b135883da04084f3c9cd9cf62bf0ef868da31d;hb=2692c36a40349a6d2ba75e7e63c7808e7e40e574;hp=25dd084af6243d99b7d96d8e575feb7870e94e1d;hpb=7b15acb7d67a6679a3c498850a4fffa1459eb0b9;p=perl-cwmp.git diff --git a/lib/CWMP/Session.pm b/lib/CWMP/Session.pm index 25dd084..26b1358 100644 --- a/lib/CWMP/Session.pm +++ b/lib/CWMP/Session.pm @@ -114,15 +114,6 @@ sub process_request { #warn "last request state = ", dump( $state ), "\n" if $self->debug > 1; } - my $out = join("\r\n", - 'HTTP/1.1 200 OK', - 'Content-Type: text/xml; charset="utf-8"', - 'Server: Perl-CWMP/42', - 'SOAPServer: Perl-CWMP/42' - ) . "\r\n"; - - $out .= "Set-Cookie: ID=" . $state->{ID} . "; path=/\r\n" if $state->{ID}; - my $uid = $self->store->state_to_uid( $state ); my $to_uid = join(" ", grep { defined($_) } "to $uid", @@ -138,23 +129,51 @@ sub process_request { id => $uid, debug => $self->debug, }); - my $job; $xml = ''; if ( my $dispatch = $state->{_dispatch} ) { $xml = $self->dispatch( $dispatch ); - } elsif ( $job = $queue->dequeue ) { + } elsif ( my $job = $queue->dequeue ) { $xml = $self->dispatch( $job->dispatch ); + $job->finish; } else { - warn ">>> empty response $to_uid"; - $state->{NoMoreRequests} = 1; - $xml = ''; + my $stored = $self->store->get_state( $uid ); + if ( ! defined $stored->{ParameterInfo} ) { + $xml = $self->dispatch( 'GetParameterNames', [ 'InternetGatewayDevice.', 1 ] ); + } else { + my @params = grep { m/\.$/ } keys %{ $stored->{ParameterInfo} }; + if ( @params ) { + warn "# GetParameterNames ", dump( @params ); + my $first = shift @params; + delete $stored->{ParameterInfo}->{$first}; + $xml = $self->dispatch( 'GetParameterNames', [ $first, 1 ] ); + foreach ( @params ) { + $queue->enqueue( 'GetParameterNames', [ $_, 1 ] ); + delete $stored->{ParameterInfo}->{ $_ }; + } + $self->store->set_state( $uid, $stored ); + } else { + warn ">>> empty response $to_uid"; + $state->{NoMoreRequests} = 1; + $xml = ''; + } + } } + my $status = length($xml) ? 200 : 204; + + my $out = join("\r\n", + "HTTP/1.1 $status OK", + 'Content-Type: text/xml; charset="utf-8"', + 'Server: Perl-CWMP/42', + 'SOAPServer: Perl-CWMP/42' + ) . "\r\n"; + + $out .= "Set-Cookie: ID=" . $state->{ID} . "; path=/\r\n" if $state->{ID}; + $out .= "Content-Length: " . length( $xml ) . "\r\n\r\n"; $out .= $xml if length($xml); - $job->finish if $job; warn "### request over for $uid\n" if $self->debug; return $out; # next request