first cut at outgoing ax25 / external connects
[spider.git] / perl / ExtMsg.pm
index ee2ad231e40dfb8d3b935d62dfcc72fa197e348d..6ea47a516b06f69d9a43f74681cb0b8423855a04 100644 (file)
@@ -58,6 +58,9 @@ sub dequeue
        my $conn = shift;
        my $msg;
 
+       if ($conn->{sort} eq 'ax25' && exists $conn->{msg}) {
+               $conn->{msg} =~ s/\cM/\cJ/g;
+       }
        if ($conn->{state} eq 'WC') {
                if (exists $conn->{cmd}) {
                        if (@{$conn->{cmd}}) {
@@ -193,7 +196,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 +210,30 @@ sub _doconnect
                        dbg('connect', "***Connect Failed to $host $port $!");
                }
        } elsif ($sort eq 'ax25' || $sort eq 'prog') {
-               ;
+               my $pid = fork();
+               if (defined $pid) {
+                       if (!$pid) {
+                               # in child, unset warnings, disable debugging and general clean up from us
+                               $^W = 0;
+                               eval "{ package DB; sub DB {} }";
+                               DXChannel::closeall();
+                               for (@main::listeners) {
+                                       $_->close_server;
+                               }
+                               unless ($^O =~ /^MS/) {
+                                       $SIG{HUP} = 'IGNORE';
+                                       $SIG{CHLD} = $SIG{TERM} = $SIG{INT} = $SIG{__WARN__} = 'DEFAULT';
+                                       alarm(0);
+                               }
+                               exec "$line" or dbg('cron', "exec '$line' failed $!");
+                       }
+                       dbg('connect', "program $sort $line started");
+                       $conn->{pid} = $pid;
+                       $conn->{sort} = $sort;
+                       $conn->{lineend} = "\cM" if $sort eq 'ax25';
+               } else {
+                       dbg('connect', "can't $sort fork for $line $!");
+               }
        } else {
                dbg('err', "invalid type of connection ($sort)");
                $conn->disconnect;
@@ -247,7 +274,7 @@ sub _dochat
        my $conn = shift;
        my $cmd = shift;
        my $line = shift;
-       
+               
        if ($line) {
                my ($expect, $send) = $cmd =~ /^\s*\'(.*)\'\s+\'(.*)\'/;
                if ($expect) {
@@ -261,6 +288,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;
                        }
                }