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
27 use vars qw(@ISA $deftimeout);
38 # we probably won't use the normal format
41 my ($conn, $msg) = @_;
42 push (@{$conn->{outqueue}}, $msg . $conn->{lineend});
50 if ($conn->ax25 && exists $conn->{msg}) {
51 $conn->{msg} =~ s/\cM/\cJ/g;
54 if ($conn->{state} eq 'WC') {
55 $conn->to_connected($conn->{call}, 'O', $conn->{csort});
58 if ($conn->{msg} =~ /\cJ/) {
59 my @lines = $conn->{msg} =~ /([^\cM\cJ]*)\cM?\cJ/g;
60 if ($conn->{msg} =~ /\cJ$/) {
63 $conn->{msg} =~ s/([^\cM\cJ]*)\cM?\cJ//g;
66 $conn->{linesin} += @lines;
67 $Msg::total_lines_in += @lines;
68 while (defined ($msg = shift @lines)) {
69 dbg("connect $conn->{cnum}: $msg") if $conn->{state} ne 'C' && isdbg('connect');
71 $msg =~ s/\xff\xfa.*\xff\xf0|\xff[\xf0-\xfe].//g; # remove telnet options
73 &{$conn->{rproc}}($conn, $msg);
82 my $conn = ExtMsg->new(\&main::new_channel);
83 $conn->{outgoing} = 1;
86 my $f = new IO::File $fn;
87 push @{$conn->{cmd}}, <$f>;
89 $conn->{state} = 'WC';
90 $conn->_dotimeout($deftimeout);
95 my ($conn, $sort, $line) = @_;
98 $sort = lc $sort; # in this case telnet, ax25 or prog
99 dbg("CONNECT $conn->{cnum} sort: $sort command: $line") if isdbg('connect');
100 if ($sort eq 'telnet') {
101 # this is a straight network connect
102 my ($host, $port) = split /\s+/, $line;
103 $port = 23 if !$port;
104 $r = $conn->connect($host, $port);
106 dbg("Connected $conn->{cnum} to $host $port") if isdbg('connect');
108 dbg("***Connect $conn->{cnum} Failed to $host $port $!") if isdbg('connect');
110 } elsif ($sort eq 'prog') {
111 $r = $conn->start_program($line, $sort);
113 dbg("invalid type of connection ($sort)");
115 $conn->disconnect unless $r;
123 dbg("connect $conn->{cnum}: abort $string") if isdbg('connect');
124 $conn->{abort} = $string;
131 dbg("connect $conn->{cnum}: timeout set to $val") if isdbg('connect');
132 $conn->{timeout}->del if $conn->{timeout};
133 $conn->{timeval} = $val;
134 $conn->{timeout} = DXTimer->new($val, sub{ &_timedout($conn) });
141 dbg("connect $conn->{cnum}: timed out after $conn->{timeval} seconds") if isdbg('connect');
145 # handle callsign and connection type firtling
150 my @f = split /\s+/, $line;
151 my $call = uc $f[0] if $f[0];
153 $conn->{csort} = $f[1] if $f[1];
154 $conn->{state} = 'C';
155 &{$conn->{rproc}}($conn, "O$call|$conn->{csort}");
157 $conn->{timeout}->del if $conn->{timeout};
166 my $f = new IO::File $fn;
171 dbg("connect $conn->{cnum}: $l") if isdbg('connll');
172 $conn->send_raw($l . $conn->{lineend});