2 # This class is the internal subclass that deals with 'Ephmeral'
3 # communications like: querying http servers and other network
4 # connected data services and using Msg.pm
6 # An instance of this is setup by a command together with a load
7 # of callbacks and then runs with a state machine until completion
11 # Copyright (c) 2001 - Dirk Koopman G1TLH
25 use vars qw(@ISA $deftimeout);
36 # we probably won't use the normal format
39 my ($conn, $msg) = @_;
40 push (@{$conn->{outqueue}}, $msg . $conn->{lineend});
48 if ($conn->ax25 && exists $conn->{msg}) {
49 $conn->{msg} =~ s/\cM/\cJ/g;
52 if ($conn->{state} eq 'WC') {
53 $conn->to_connected($conn->{call}, 'O', $conn->{csort});
56 if ($conn->{msg} =~ /\cJ/) {
57 my @lines = $conn->{msg} =~ /([^\cM\cJ]*)\cM?\cJ/g;
58 if ($conn->{msg} =~ /\cJ$/) {
61 $conn->{msg} =~ s/([^\cM\cJ]*)\cM?\cJ//g;
64 while (defined ($msg = shift @lines)) {
65 dbg("connect $conn->{cnum}: $msg") if $conn->{state} ne 'C' && isdbg('connect');
67 $msg =~ s/\xff\xfa.*\xff\xf0|\xff[\xf0-\xfe].//g; # remove telnet options
69 &{$conn->{rproc}}($conn, $msg);
78 my $conn = ExtMsg->new(\&main::new_channel);
79 $conn->{outgoing} = 1;
82 my $f = new IO::File $fn;
83 push @{$conn->{cmd}}, <$f>;
85 $conn->{state} = 'WC';
86 $conn->_dotimeout($deftimeout);
91 my ($conn, $sort, $line) = @_;
94 $sort = lc $sort; # in this case telnet, ax25 or prog
95 dbg("CONNECT $conn->{cnum} sort: $sort command: $line") if isdbg('connect');
96 if ($sort eq 'telnet') {
97 # this is a straight network connect
98 my ($host, $port) = split /\s+/, $line;
100 $r = $conn->connect($host, $port);
102 dbg("Connected $conn->{cnum} to $host $port") if isdbg('connect');
104 dbg("***Connect $conn->{cnum} Failed to $host $port $!") if isdbg('connect');
106 } elsif ($sort eq 'prog') {
107 $r = $conn->start_program($line, $sort);
109 dbg("invalid type of connection ($sort)");
111 $conn->disconnect unless $r;
119 dbg("connect $conn->{cnum}: abort $string") if isdbg('connect');
120 $conn->{abort} = $string;
127 dbg("connect $conn->{cnum}: timeout set to $val") if isdbg('connect');
128 $conn->{timeout}->del if $conn->{timeout};
129 $conn->{timeval} = $val;
130 $conn->{timeout} = Timer->new($val, sub{ &_timedout($conn) });
137 dbg("connect $conn->{cnum}: timed out after $conn->{timeval} seconds") if isdbg('connect');
141 # handle callsign and connection type firtling
146 my @f = split /\s+/, $line;
147 my $call = uc $f[0] if $f[0];
149 $conn->{csort} = $f[1] if $f[1];
150 $conn->{state} = 'C';
151 &{$conn->{rproc}}($conn, "O$call|$conn->{csort}");
153 $conn->{timeout}->del if $conn->{timeout};
162 my $f = new IO::File $fn;
167 dbg("connect $conn->{cnum}: $l") if isdbg('connll');
168 $conn->send_raw($l . $conn->{lineend});