2 # This class is the internal subclass that does the equivalent of a
3 # GET http://<some site>/<some path> and passes the result back to the caller.
5 # This merely starts up a Msg handler (and no DXChannel) ($conn in other words)
6 # does the GET, parses out the result and the data and then (assuming a positive
7 # result and that the originating callsign is still online) punts out the data
10 # It isn't designed to be very clever.
12 # Copyright (c) 2013 - Dirk Koopman G1TLH
22 use vars qw(@ISA $deftimeout);
34 my $state = $conn->{state};
36 dbg("httpmsg: $msg") if isdbg('http');
38 # no point in going on if there is no-one wanting the output anymore
39 my $dxchan = DXChannel::get($conn->{caller});
40 return unless $dxchan;
42 if ($state eq 'waitreply') {
43 # look at the reply code and decide whether it is a success
44 my ($http, $code, $ascii) = $msg =~ m|(HTTP/\d\.\d)\s+(\d+)\s+(.*)|;
47 $conn->{state} = 'waitblank';
49 $dxchan->send("$code $ascii");
52 } elsif ($state eq 'waitblank') {
54 $conn->{state} = 'indata';
57 if (my $filter = $conn->{filter}) {
59 # this will crash if the command has been redefined and the filter is a
60 # function defined there whilst the request is in flight,
61 # but this isn't exactly likely in a production environment.
62 $filter->($conn, $msg, $dxchan);
78 my $conn = $pkg->new(\&handle);
79 $conn->{caller} = $call;
80 $conn->{state} = 'waitreply';
81 $conn->{host} = $host;
82 $conn->{port} = $port;
83 $conn->{filter} = $filter if $filter;
86 $outstanding{$conn} = $conn;
88 $r = $conn->connect($host, $port);
90 dbg("Sending 'GET $path HTTP/1.0'") if isdbg('http');
91 $conn->send_later("GET $path HTTP/1.0\nHost: $host\nUser-Agent: DxSpider;$main::version;$main::build;$^O;$main::mycall;$call\n\n");
104 my $r = $conn->SUPER::connect($host, $port);
106 dbg("HTTPMsg: Connected $conn->{cnum} to $host $port") if isdbg('http');
108 dbg("HTTPMsg: ***Connect $conn->{cnum} Failed to $host $port $!") if isdbg('http');
117 delete $outstanding{$conn};
118 $conn->SUPER::disconnect;
124 delete $outstanding{$conn};
125 $conn->SUPER::DESTROY;