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 $conn->{linesin} += @lines;
65 $Msg::total_lines_in += @lines;
66 while (defined ($msg = shift @lines)) {
67 dbg("connect $conn->{cnum}: $msg") if $conn->{state} ne 'C' && isdbg('connect');
69 $msg =~ s/\xff\xfa.*\xff\xf0|\xff[\xf0-\xfe].//g; # remove telnet options
71 &{$conn->{rproc}}($conn, $msg);
80 my $conn = ExtMsg->new(\&main::new_channel);
81 $conn->{outgoing} = 1;
84 my $f = new IO::File $fn;
85 push @{$conn->{cmd}}, <$f>;
87 $conn->{state} = 'WC';
88 $conn->_dotimeout($deftimeout);
93 my ($conn, $sort, $line) = @_;
96 $sort = lc $sort; # in this case telnet, ax25 or prog
97 dbg("CONNECT $conn->{cnum} sort: $sort command: $line") if isdbg('connect');
98 if ($sort eq 'telnet') {
99 # this is a straight network connect
100 my ($host, $port) = split /\s+/, $line;
101 $port = 23 if !$port;
102 $r = $conn->connect($host, $port);
104 dbg("Connected $conn->{cnum} to $host $port") if isdbg('connect');
106 dbg("***Connect $conn->{cnum} Failed to $host $port $!") if isdbg('connect');
108 } elsif ($sort eq 'prog') {
109 $r = $conn->start_program($line, $sort);
111 dbg("invalid type of connection ($sort)");
113 $conn->disconnect unless $r;
121 dbg("connect $conn->{cnum}: abort $string") if isdbg('connect');
122 $conn->{abort} = $string;
129 dbg("connect $conn->{cnum}: timeout set to $val") if isdbg('connect');
130 $conn->{timeout}->del if $conn->{timeout};
131 $conn->{timeval} = $val;
132 $conn->{timeout} = Timer->new($val, sub{ &_timedout($conn) });
139 dbg("connect $conn->{cnum}: timed out after $conn->{timeval} seconds") if isdbg('connect');
143 # handle callsign and connection type firtling
148 my @f = split /\s+/, $line;
149 my $call = uc $f[0] if $f[0];
151 $conn->{csort} = $f[1] if $f[1];
152 $conn->{state} = 'C';
153 &{$conn->{rproc}}($conn, "O$call|$conn->{csort}");
155 $conn->{timeout}->del if $conn->{timeout};
164 my $f = new IO::File $fn;
169 dbg("connect $conn->{cnum}: $l") if isdbg('connll');
170 $conn->send_raw($l . $conn->{lineend});