X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=inline;f=lib%2FCWMP%2FSession.pm;h=81190260bcdc27917f58db957fb229c83cd30505;hb=0d33363815949458c69e5b01bf5a899bb52a8ab3;hp=25dd084af6243d99b7d96d8e575feb7870e94e1d;hpb=7b15acb7d67a6679a3c498850a4fffa1459eb0b9;p=perl-cwmp.git diff --git a/lib/CWMP/Session.pm b/lib/CWMP/Session.pm index 25dd084..8119026 100644 --- a/lib/CWMP/Session.pm +++ b/lib/CWMP/Session.pm @@ -18,9 +18,10 @@ store use Data::Dump qw/dump/; use Carp qw/carp confess cluck croak/; -use CWMP::Request; +use CWMP::Parser; use CWMP::Methods; use CWMP::Store; +use CWMP::Vendor; #use Devel::LeakTrace::Fast; @@ -88,16 +89,16 @@ sub process_request { warn "## request payload: ",length($xml)," bytes\n$xml\n" if $self->debug; - $state = CWMP::Request->parse( $xml ); + $state = CWMP::Parser->parse( $xml ); warn "## acquired state = ", dump( $state ), "\n" if $self->debug; - if ( ! defined( $state->{DeviceID} ) ) { + if ( ! defined( $state->{DeviceId} ) ) { if ( $self->state ) { - warn "## state without DeviceID, using old one...\n"; - $state->{DeviceID} = $self->state->{DeviceID}; + warn "## state without DeviceId, using old one...\n"; + $state->{DeviceId} = $self->state->{DeviceId}; } else { - warn "WARNING: state without DeviceID, and I don't have old one!\n"; + warn "WARNING: state without DeviceId, and I don't have old one!\n"; warn "## state = ",dump( $state ); } } @@ -114,49 +115,48 @@ 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", - # board - $state->{Parameter}->{'InternetGatewayDevice.DeviceInfo.HardwareVersion'}, - # version - $state->{Parameter}->{'InternetGatewayDevice.DeviceInfo.SoftwareVersion'}, - # summary -# $state->{Parameter}->{'InternetGatewayDevice.DeviceSummary'}, - ) . "\n"; - my $queue = CWMP::Queue->new({ id => $uid, debug => $self->debug, }); - my $job; + $xml = ''; + my $status = 200; 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 @dispatch; +# @dispatch = CWMP::Vendor->all_parameters( $self->store, $uid, $queue ); +warn "XXX", dump @dispatch; + @dispatch = CWMP::Vendor->vendor_config( $self->store, $uid, $queue ) unless @dispatch; +warn "XXX", dump @dispatch; + $xml = $self->dispatch( @dispatch ) if @dispatch; + if ( ! $xml ) { + warn ">>> no more work for $uid sending empty response\n"; + $state->{NoMoreRequests} = 1; + $xml = ''; + $status = 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 };