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->{csort} eq '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);
76 my ($conn, $call, $dir, $sort) = @_;
80 $conn->{timeout}->del if $conn->{timeout};
81 delete $conn->{timeout};
83 &{$conn->{rproc}}($conn, "$dir$call|$sort");
91 my $conn = ExtMsg->new(\&main::new_channel);
92 $conn->{outgoing} = 1;
95 my $f = new IO::File $fn;
96 push @{$conn->{cmd}}, <$f>;
98 $conn->{state} = 'WC';
99 $conn->_dotimeout($deftimeout);
104 my ($conn, $sort, $line) = @_;
107 $sort = lc $sort; # in this case telnet, ax25 or prog
108 dbg("CONNECT $conn->{cnum} sort: $sort command: $line") if isdbg('connect');
109 if ($sort eq 'telnet') {
110 # this is a straight network connect
111 my ($host, $port) = split /\s+/, $line;
112 $port = 23 if !$port;
113 $r = $conn->connect($host, $port);
115 dbg("Connected $conn->{cnum} to $host $port") if isdbg('connect');
117 dbg("***Connect $conn->{cnum} Failed to $host $port $!") if isdbg('connect');
119 } elsif ($sort eq 'prog') {
120 $r = $conn->start_program($line, $sort);
122 dbg("invalid type of connection ($sort)");
124 $conn->disconnect unless $r;
132 dbg("connect $conn->{cnum}: abort $string") if isdbg('connect');
133 $conn->{abort} = $string;
140 dbg("connect $conn->{cnum}: timeout set to $val") if isdbg('connect');
141 $conn->{timeout}->del if $conn->{timeout};
142 $conn->{timeval} = $val;
143 $conn->{timeout} = Timer->new($val, sub{ &_timedout($conn) });
150 dbg("connect $conn->{cnum}: timed out after $conn->{timeval} seconds") if isdbg('connect');
154 # handle callsign and connection type firtling
159 my @f = split /\s+/, $line;
160 my $call = uc $f[0] if $f[0];
162 $conn->{csort} = $f[1] if $f[1];
163 $conn->{state} = 'C';
164 &{$conn->{rproc}}($conn, "O$call|$conn->{csort}");
166 $conn->{timeout}->del if $conn->{timeout};
175 my $f = new IO::File $fn;
180 dbg("connect $conn->{cnum}: $l") if isdbg('connll');
181 $conn->send_raw($l . $conn->{lineend});