add bits on sh/debug and set/debug to adminmanual
[spider.git] / perl / ExtMsg.pm
index a601d4edfa01c0a09da64a74859e50ffdd9d94c6..9b4bb061a0bf2dc637c45020c8823db2a8ac0932 100644 (file)
@@ -19,6 +19,7 @@ use DXUtil;
 use DXDebug;
 use IO::File;
 use IO::Socket;
+use IPC::Open3;
 
 use vars qw(@ISA $deftimeout);
 
@@ -58,6 +59,9 @@ sub dequeue
        my $conn = shift;
        my $msg;
 
+       if ($conn->{csort} eq 'ax25' && exists $conn->{msg}) {
+               $conn->{msg} =~ s/\cM/\cJ/g;
+       }
        if ($conn->{state} eq 'WC') {
                if (exists $conn->{cmd}) {
                        if (@{$conn->{cmd}}) {
@@ -68,9 +72,9 @@ sub dequeue
                if ($conn->{state} eq 'WC' && exists $conn->{cmd} && @{$conn->{cmd}} == 0) {
                        $conn->to_connected($conn->{call}, 'O', 'telnet');
                }
-       } elsif ($conn->{msg} =~ /\n/) {
-               my @lines = split /\r?\n/, $conn->{msg};
-               if ($conn->{msg} =~ /\n$/) {
+       } elsif ($conn->{msg} =~ /\cJ/) {
+               my @lines =  $conn->{msg} =~ /([^\cM\cJ]*)\cM?\cJ/g;
+               if ($conn->{msg} =~ /\cJ$/) {
                        delete $conn->{msg};
                } else {
                        $conn->{msg} = pop @lines;
@@ -79,7 +83,7 @@ sub dequeue
                        dbg('connect', $msg) unless $conn->{state} eq 'C';
                
                        $msg =~ s/\xff\xfa.*\xff\xf0|\xff[\xf0-\xfe].//g; # remove telnet options
-                       $msg =~ s/[\x00-\x08\x0a-\x1f\x80-\x9f]/./g;         # immutable CSI sequence + control characters
+                       $msg =~ s/[\x00-\x08\x0a-\x19\x1b-\x1f\x80-\x9f]/./g;         # immutable CSI sequence + control characters
                        
                        if ($conn->{state} eq 'C') {
                                &{$conn->{rproc}}($conn, "I$conn->{call}|$msg");
@@ -193,7 +197,8 @@ sub _doconnect
 {
        my ($conn, $sort, $line) = @_;
        my $r;
-       
+
+       $sort = lc $sort;
        dbg('connect', "CONNECT sort: $sort command: $line");
        if ($sort eq 'telnet') {
                # this is a straight network connect
@@ -206,7 +211,18 @@ sub _doconnect
                        dbg('connect', "***Connect Failed to $host $port $!");
                }
        } elsif ($sort eq 'ax25' || $sort eq 'prog') {
-               ;
+               my $sock = new IO::Socket::INET;
+               local *H;
+               my $wrt = \*H;
+               
+               if ($conn->{pid} = open3("<&$sock", ">&$sock", '', $line)) {
+                       $conn->{sock} = $sock;
+                       $conn->{csort} = $sort;
+                       $conn->{lineend} = "\cM" if $sort eq 'ax25';
+                       dbg('connect', "started pid: $conn->{pid} as $line");
+               } else {
+                       dbg('connect', "can't start $line $!");
+               }
        } else {
                dbg('err', "invalid type of connection ($sort)");
                $conn->disconnect;
@@ -247,7 +263,7 @@ sub _dochat
        my $conn = shift;
        my $cmd = shift;
        my $line = shift;
-       
+               
        if ($line) {
                my ($expect, $send) = $cmd =~ /^\s*\'(.*)\'\s+\'(.*)\'/;
                if ($expect) {
@@ -261,6 +277,7 @@ sub _dochat
                        if ($line =~ /$expect/i) {
                                dbg('connect', "got: \"$expect\" sending: \"$send\"");
                                $conn->send_later($send);
+                               delete $conn->{msg}; # get rid any input if a match
                                return;
                        }
                }