Skip to content

Commit

Permalink
Merge pull request #7 from delian/master
Browse files Browse the repository at this point in the history
Please accept those modifications
  • Loading branch information
dpavlin committed Oct 10, 2014
2 parents 2d3b288 + ecb0d61 commit 12e9f1b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 14 deletions.
29 changes: 24 additions & 5 deletions lib/CWMP/Methods.pm
Expand Up @@ -40,9 +40,19 @@ For examples, see source of this module.
=cut

my $cwmp = [ cwmp => 'urn:dslforum-org:cwmp-1-0' ];
my $soap = [ soap => 'http://schemas.xmlsoap.org/soap/envelope/', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/" ];
#my $soap = [ soap => 'http://schemas.xmlsoap.org/soap/envelope/', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/" ];
my $soap = [ "SOAP-ENV" => "http://schemas.xmlsoap.org/soap/envelope/", "SOAP_ENC"=> "http://schemas.xmlsoap.org/soap/encoding/", xsd=>"http://www.w3.org/2001/XMLSchema", xsi=>"http://www.w3.org/2001/XMLSchema-instance" ];
my $xsd = [ xsd => 'http://www.w3.org/2001/XMLSchema-instance' ];

# xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
# xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
# xmlns:xsd="http://www.w3.org/2001/XMLSchema"
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

# xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
# xmlns:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"


sub xml {
my $self = shift;

Expand All @@ -57,7 +67,7 @@ sub xml {

my @header;
push( @header, $X->ID( $cwmp, { 'soap:mustUnderstand' => 1 }, $state->{ID} )) if $state->{ID};
push( @header, $X->NoMoreRequests( $cwmp, $state->{NoMoreRequests} || 0 ));
# push( @header, $X->NoMoreRequests( $cwmp, $state->{NoMoreRequests} || 0 ));

return $X->Envelope( $soap,
$X->Header( $soap, @header ),
Expand Down Expand Up @@ -112,13 +122,22 @@ sub SetParameterValues {
$X->SetParameterValues( $cwmp,
$X->ParameterList( [], { 'encodingStyle:arrayType' => 'cwmp:ParameterValueStruct['.(scalar keys %$params).']' },
map {
if ( $params->{$_}=~ /^\#([^\#]+)\#(.+)$/ ) {
my $type = $1;
my $val = $2;
$X->ParameterValueStruct( [],
$X->Name( [], $_ ),
$X->Value( [], { "xsi:type"=>$1 }, $2 )
);
} else {
$X->ParameterValueStruct( [],
$X->Name( [], $_ ),
$X->Value( [], $params->{$_} )
)
$X->Value( [], { "xsi:type"=>"xsd:string" }, $params->{$_} )
);
}
} sort keys %$params
),
$X->ParameterKey( '' ),
$X->ParameterKey( '' ), # Just for experiment
);
});
}
Expand Down
21 changes: 14 additions & 7 deletions lib/CWMP/Server.pm
Expand Up @@ -88,20 +88,27 @@ sub run {
) || die "can't start server on ", $self->port, ": $!";

warn "ACS waiting for request on port ", $self->port, "\n";

$SIG{CHLD}='IGNORE'; # Ignore the responding forks

while (1) {
my $client = $server->accept() || next; # ALARM trickle us

my $count = 0;
if (fork()==0) {
my $count = 0;

my $session = CWMP::Session->new( $self->session ) || confess "can't create sessision";
my $session = CWMP::Session->new( $self->session ) || confess "can't create sessision";

while ( $self->sock_session( $client, $session ) ) {
$count++;
warn "# finished request $count, waiting for next one\n";
}
while ( $self->sock_session( $client, $session ) ) {
$count++;
warn "# finished request ", $client->peerhost ," $count, waiting for next one\n";
}

warn "# connection to ", $client->peerhost, " closed\n";
warn "# connection to ", $client->peerhost, " closed\n";
$client->close();
exit(1);
}
$client->close();
}

}
Expand Down
3 changes: 2 additions & 1 deletion lib/CWMP/Session.pm
Expand Up @@ -132,7 +132,8 @@ sub process_request {
$job->finish;
} else {
my @dispatch;
@dispatch = CWMP::Vendor->all_parameters( $self->store, $uid, $queue );
# @dispatch = CWMP::Vendor->all_parameters( $self->store, $uid, $queue );
@dispatch = CWMP::Vendor->some_parameters( $self->store, $uid, $queue );
warn "XXX", dump @dispatch;
@dispatch = CWMP::Vendor->vendor_config( $self->store, $uid, $queue ) unless @dispatch;
warn "XXX", dump @dispatch;
Expand Down
29 changes: 28 additions & 1 deletion lib/CWMP/Vendor.pm
Expand Up @@ -71,6 +71,24 @@ sub all_parameters {

our $tried;

sub some_parameters {
my ( $self, $store, $uid, $queue ) = @_;

my $stored = $store->get_state( $uid );

my $vendor = YAML::LoadFile 'param.yaml';

$vendor = $vendor->{Parameter} || die "no Parameter in param.yaml";

foreach my $n ( keys %$vendor ) {
printf "We are getting value for $n\n";
$queue->enqueue( 'GetParameterValues', [ $n ] ); # refresh after change
}

return ( 'GetParameterNames', [ 'InternetGatewayDevice.DeviceInfo.',1] ) if ! defined $stored->{ParameterInfo};
return;
}

sub vendor_config {
my ( $self, $store, $uid, $queue ) = @_;

Expand All @@ -91,7 +109,16 @@ sub vendor_config {
} elsif ( $vendor->{$n} ne $stored->{$n}
&& ( ! $tried->{$uid}->{$n}->{set} || $tried->{$uid}->{$n}->{set} ne $vendor->{$n} )
) {
$queue->enqueue( 'SetParameterValues', { $n => $vendor->{$n} } );
my $value = $vendor->{$n};
if ($stored) {
while(
$value=~ s/\$\{([^\}]+)\}/$stored->{$1}/gei
or
$value=~ s/\$\[([^\]]+)\]/eval($1)/gei
) {};
}
warn "# set value to $n to be $value\n";
$queue->enqueue( 'SetParameterValues', { $n => $value } );
$queue->enqueue( 'GetParameterValues', [ $n ] ); # refresh after change
push @refresh, $n;
$tried->{$uid}->{$n}->{set} = $vendor->{$n};
Expand Down

0 comments on commit 12e9f1b

Please sign in to comment.