use HTTP::Daemon;
use Data::Dump qw/dump/;
-use Carp qw/confess cluck croak/;
+use Carp qw/carp confess cluck croak/;
use File::Slurp;
use CWMP::Request;
use CWMP::Methods;
use CWMP::Store;
+#use Devel::LeakTrace::Fast;
+
=head1 NAME
CWMP::Session - implement logic of CWMP protocol
# solution from http://use.perl.org/~Matts/journal/12896
${*$sock}{'httpd_daemon'} = HTTP::Daemon->new;
- my $r = $sock->get_request || confess "can't get_request";
+ my $r = $sock->get_request;
+
+ if ( ! $r ) {
+ carp "can't get_request";
+ return 0;
+ }
my $xml = $r->content;
#warn "last request state = ", dump( $state ), "\n" if $self->debug > 1;
}
-
$sock->send(join("\r\n",
'HTTP/1.1 200 OK',
'Content-Type: text/xml; charset="utf-8"',
- 'Server: AcmeCWMP/42',
- 'SOAPServer: AcmeCWMP/42'
+ 'Server: PerlCWMP/42',
+ 'SOAPServer: PerlCWMP/42'
)."\r\n");
$sock->send( "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,
} elsif ( $job = $queue->dequeue ) {
$xml = $self->dispatch( $job->dispatch );
} elsif ( $size == 0 ) {
- warn ">>> no more queued commands, closing connection to $uid\n";
- return 0;
+ warn ">>> over, closing connection $to_uid";
+ $sock->close;
+ return;
} else {
- warn ">>> empty response to $uid\n";
+ warn ">>> empty response $to_uid";
$state->{NoMoreRequests} = 1;
$xml = $self->dispatch( 'xml', sub {} );
}
$sock->send( "Content-Length: " . length( $xml ) . "\r\n\r\n" );
$sock->send( $xml ) or die "can't send response";
- warn ">>>> " . $sock->peerhost . " [" . localtime() . "] sent ", length( $xml )," bytes to $uid\n";
+ warn ">>>> " . $sock->peerhost . " [" . localtime() . "] sent ", length( $xml )," bytes $to_uid";
$job->finish if $job;
warn "### request over for $uid\n" if $self->debug;