--- FTP.pm.org Wed Mar 19 01:21:07 2008
+++ FTP.pm Fri Apr 18 13:13:49 2008
@@ -294,8 +294,7 @@
delete $heap->{cmd_rw_wheel};
delete $heap->{cmd_sock_wheel};
- delete $heap->{data_rw_wheel};
- delete $heap->{data_sock_wheel};
+ clean_up_complex_cmd();
$poe_kernel->alias_remove( $heap->{alias} );
return;
@@ -309,8 +308,7 @@
my $coderef;
- $input =~ s/^(\d\d\d)(.?)//o;
- my ($code, $more) = ($1, $2);
+ my ($code, $major, $more) = parse_cmd_string($input);
$input =~ s/^ // if defined $more && $more eq "-";
@@ -320,8 +318,6 @@
$heap->{ftp_message} =~ s/\s+$//;
- my $major = substr($code, 0, 1);
-
if ($major == 1) {
# 1yz Positive Preliminary reply
@@ -470,8 +466,7 @@
elsif ($heap->{data_suicidal}) {
warn "killing suicidal socket" . $heap->{data_rw_wheel}->get_driver_out_octets() if DEBUG;
- delete $heap->{data_sock_wheel};
- delete $heap->{data_rw_wheel};
+ clean_up_complex_cmd();
$heap->{data_suicidal} = 0;
send_event("put_closed",
@@ -489,8 +484,7 @@
send_event( "put_error", $error,
$heap->{complex_stack}->{command}->[1] );
- delete $heap->{data_sock_wheel};
- delete $heap->{data_rw_wheel};
+ clean_up_complex_cmd();
goto_state("ready");
return;
}
@@ -808,8 +802,6 @@
command($heap->{complex_stack}->{command});
}
else {
- send_event( $heap->{complex_stack}->{command}->[0] . "_done",
- $heap->{complex_stack}->{command}->[1] );
goto_state("ready");
}
return;
@@ -826,9 +818,7 @@
$status, $line,
$heap->{complex_stack}->{command}->[1] );
- delete $heap->{data_sock_wheel};
- delete $heap->{data_rw_wheel};
-
+ clean_up_complex_cmd();
goto_state("ready");
return;
}
@@ -891,8 +881,7 @@
send_event( $heap->{complex_stack}->{command}->[0] . "_error", $error,
$heap->{complex_stack}->{command}->[1] );
- delete $heap->{data_sock_wheel};
- delete $heap->{data_rw_wheel};
+ clean_up_complex_cmd();
goto_state("ready");
return;
}
@@ -911,9 +900,11 @@
sub handler_complex_list_error {
my ($kernel, $heap, $input) = @_[KERNEL, HEAP, ARG0];
warn "error: complex_list: $input" if DEBUG;
+ send_event( $heap->{complex_stack}->{command}->[0] . "_done",
+ $heap->{complex_stack}->{command}->[1] );
- delete $heap->{data_sock_wheel};
- delete $heap->{data_rw_wheel};
+ clean_up_complex_cmd();
+ dequeue_complex_cmd();
return;
}
@@ -958,8 +949,15 @@
# if active session knows how to handle this event, dispatch it to them
# if not, enqueue the event
sub dispatch {
- my ($kernel, $heap, $state) = @_[KERNEL, HEAP, STATE];
+ my ($kernel, $heap, $state, $input) = @_[KERNEL, HEAP, STATE, ARG0];
+ if ($state eq 'cmd_input' && defined $heap->{data_rw_wheel} ) {
+ my ($code, $major, $msg) = parse_cmd_string($input);
+ if ( $major == 2 ) {
+ enqueue_complex_cmd(@_);
+ return;
+ }
+ }
my $coderef = ( $state_map->{ $heap->{state} }->{$state} ||
$state_map->{global}->{$state} ||
\&enqueue_event );
@@ -1058,6 +1056,38 @@
command("PORT " . join ",", @addr, @port);
}
return;
+}
+
+sub parse_cmd_string {
+ my $string = shift;
+ $string =~ s/^(\d\d\d)(.?)//o;
+ my ($code, $more) = ($1, $2);
+ my $major = substr($code, 0, 1);
+ return ($code, $major, $more);
+}
+
+sub clean_up_complex_cmd {
+ my $heap = $poe_kernel->get_active_session()->get_heap();
+ delete $heap->{data_sock_wheel};
+ delete $heap->{data_rw_wheel};
+ $heap->{complex_stack} = {};
+}
+
+sub enqueue_complex_cmd {
+ my $heap = $poe_kernel->get_active_session()->get_heap();
+ warn "enqueue_complex_cmd $_[STATE]" if DEBUG;
+ $heap->{pending_complex_cmd} = \@_;
+}
+
+sub dequeue_complex_cmd {
+ my $heap = $poe_kernel->get_active_session()->get_heap();
+ return unless $heap->{pending_complex_cmd};
+
+ my $state = $heap->{pending_complex_cmd}->[STATE];
+ warn "dequeue_complex_cmd $state" if DEBUG;
+ my @event = @{ $heap->{pending_complex_cmd} };
+ $heap->{pending_complex_cmd} = undef;
+ dispatch( @event );
}
1;