10 |
port |
port |
11 |
sock |
sock |
12 |
state |
state |
13 |
|
queue |
14 |
/ ); |
/ ); |
15 |
|
|
16 |
use IO::Socket::INET; |
use IO::Socket::INET; |
171 |
warn "last request state = ", dump( $state ), "\n"; |
warn "last request state = ", dump( $state ), "\n"; |
172 |
} |
} |
173 |
|
|
|
my $response = CWMP::Response->new({ debug => $self->debug }); |
|
174 |
|
|
175 |
$sock->send(join("\r\n", |
$sock->send(join("\r\n", |
176 |
'HTTP/1.1 200 OK', |
'HTTP/1.1 200 OK', |
184 |
my $xml = ''; |
my $xml = ''; |
185 |
|
|
186 |
if ( my $dispatch = $state->{_dispatch} ) { |
if ( my $dispatch = $state->{_dispatch} ) { |
187 |
if ( $response->can( $dispatch ) ) { |
$xml = $self->dispatch( $dispatch ); |
188 |
warn ">>> dispatching to $dispatch\n"; |
} elsif ( $dispatch = shift @{ $self->queue } ) { |
189 |
$xml = $response->$dispatch( $state ) . "\r\n"; |
$xml = $self->dispatch( $dispatch ); |
190 |
warn "## response payload: ",length($xml)," bytes\n$xml\n"; |
} elsif ( $size == 0 ) { |
191 |
} else { |
warn ">>> closing connection\n"; |
192 |
confess "can't dispatch to $dispatch"; |
return 0; |
|
} |
|
193 |
} else { |
} else { |
194 |
warn ">>> empty response\n"; |
warn ">>> empty response\n"; |
195 |
|
$state->{NoMoreRequests} = 1; |
196 |
|
$xml = $self->dispatch( 'xml', sub {} ); |
197 |
} |
} |
198 |
|
|
199 |
$sock->send( "Content-Length: " . length( $xml ) . "\r\n\r\n" ); |
$sock->send( "Content-Length: " . length( $xml ) . "\r\n\r\n" ); |
203 |
|
|
204 |
}; |
}; |
205 |
|
|
206 |
|
=head2 dispatch |
207 |
|
|
208 |
|
$xml = $self->dispatch('Inform', $response_arguments ); |
209 |
|
|
210 |
|
=cut |
211 |
|
|
212 |
|
sub dispatch { |
213 |
|
my $self = shift; |
214 |
|
|
215 |
|
my $dispatch = shift || die "no dispatch?"; |
216 |
|
|
217 |
|
my $response = CWMP::Response->new({ debug => $self->debug }); |
218 |
|
|
219 |
|
if ( $response->can( $dispatch ) ) { |
220 |
|
warn ">>> dispatching to $dispatch\n"; |
221 |
|
my $xml = $response->$dispatch( $self->state, @_ ) . "\r\n"; |
222 |
|
warn "## response payload: ",length($xml)," bytes\n$xml\n"; |
223 |
|
return $xml; |
224 |
|
} else { |
225 |
|
confess "can't dispatch to $dispatch"; |
226 |
|
} |
227 |
|
}; |
228 |
|
|
229 |
=head2 read_headers |
=head2 read_headers |
230 |
|
|
231 |
parse headers from request |
parse headers from request |