7 |
use base qw/Class::Accessor/; |
use base qw/Class::Accessor/; |
8 |
__PACKAGE__->mk_accessors( qw/ |
__PACKAGE__->mk_accessors( qw/ |
9 |
debug |
debug |
10 |
|
create_dump |
11 |
store |
store |
12 |
|
|
13 |
sock |
sock |
36 |
sock => $io_socket_object, |
sock => $io_socket_object, |
37 |
store => 'state.db', |
store => 'state.db', |
38 |
debug => 1, |
debug => 1, |
39 |
|
create_dump => 1, |
40 |
}); |
}); |
41 |
|
|
42 |
=cut |
=cut |
61 |
# FIXME looks ugly. Should we have separate accessor for this? |
# FIXME looks ugly. Should we have separate accessor for this? |
62 |
$self->store( $store_obj ); |
$self->store( $store_obj ); |
63 |
|
|
64 |
|
$self->create_dump( 1 ) if $self->debug > 2; |
65 |
|
|
66 |
return $self; |
return $self; |
67 |
} |
} |
68 |
|
|
109 |
$dump_nr++; |
$dump_nr++; |
110 |
my $file = sprintf("dump/%04d-%s.request", $dump_nr, $sock->peerhost); |
my $file = sprintf("dump/%04d-%s.request", $dump_nr, $sock->peerhost); |
111 |
|
|
112 |
if ( $self->debug > 2 ) { |
if ( $self->create_dump ) { |
113 |
write_file( $file, $r->as_string ); |
write_file( $file, $r->as_string ); |
114 |
warn "### request dumped to file: $file\n"; |
warn "### request dumped to file: $file\n"; |
115 |
} |
} |
124 |
|
|
125 |
$state = CWMP::Request->parse( $xml ); |
$state = CWMP::Request->parse( $xml ); |
126 |
|
|
127 |
if ( defined( $state->{_dispatch} ) && $self->debug > 2 ) { |
if ( defined( $state->{_dispatch} ) && $self->create_dump ) { |
128 |
my $type = sprintf("dump/%04d-%s-%s", $dump_nr, $sock->peerhost, $state->{_dispatch}); |
my $type = sprintf("dump/%04d-%s-%s", $dump_nr, $sock->peerhost, $state->{_dispatch}); |
129 |
symlink $file, $type || warn "can't symlink $file -> $type: $!"; |
symlink $file, $type || warn "can't symlink $file -> $type: $!"; |
130 |
} |
} |
131 |
|
|
132 |
warn "## acquired state = ", dump( $state ), "\n"; |
warn "## acquired state = ", dump( $state ), "\n"; |
133 |
|
|
134 |
|
if ( ! defined( $state->{DeviceID} ) ) { |
135 |
|
warn "## state with DeviceID, using old one...\n"; |
136 |
|
$state->{DeviceID} = $self->state->{DeviceID}; |
137 |
|
} |
138 |
|
|
139 |
$self->state( $state ); |
$self->state( $state ); |
140 |
$self->store->update_state( ID => $state->{ID}, $state ); |
$self->store->update_state( ID => $state->{ID}, $state ); |
141 |
|
|
213 |
warn ">>> dispatching to $dispatch with args ",dump( $args ),"\n"; |
warn ">>> dispatching to $dispatch with args ",dump( $args ),"\n"; |
214 |
my $xml = $response->$dispatch( $self->state, $args ); |
my $xml = $response->$dispatch( $self->state, $args ); |
215 |
warn "## response payload: ",length($xml)," bytes\n$xml\n" if $self->debug; |
warn "## response payload: ",length($xml)," bytes\n$xml\n" if $self->debug; |
216 |
if ( $self->debug > 2 ) { |
if ( $self->create_dump ) { |
217 |
my $file = sprintf("dump/%04d-%s.response", $dump_nr++, $self->sock->peerhost); |
my $file = sprintf("dump/%04d-%s.response", $dump_nr++, $self->sock->peerhost); |
218 |
write_file( $file, $xml ); |
write_file( $file, $xml ); |
219 |
warn "### response dump: $file\n"; |
warn "### response dump: $file\n"; |