my $target = $Internet::http_proxy || $Internet::qrz_url || 'xml.qrz.com';
my $port = $Internet::http_proxy_port || 80;
my $url = '';
-$url = 'http://' . ($Internet::qrz_url | 'xml.qrz.com') if $Internet::http_proxy;
+$url = 'http://' . ($Internet::qrz_url || 'xml.qrz.com') if $Internet::http_proxy;
+foreach $l (@list) {
-use Net::Telnet;
+ my $host = $url?$url:$target;
+ my $s = "$url/xml?callsign=$l;username=$Internet::qrz_uid;password=$Internet::qrz_pw;agent=dxspider";
+ if (isdbg('qrz')) {
+ dbg("qrz: $host");
+ dbg("qrz: $s");
+ }
-my $t = new Net::Telnet;
+ Log('call', "$call: show/qrz \U$l");
+ push @out, $self->msg('http1', "show/qrz \U$l");
-foreach $l (@list) {
- eval {
- $t->open(Host => $target,
- Port => $port,
- Timeout => 15);
- };
+ $self->http_get($host, $s, sub
+ {
+ my ($response, $header, $body) = @_;
+ my @out;
- if (!$t || $@) {
- push @out, $self->msg('e18', 'QRZ.com');
- } else {
- my $s = "GET /xml?callsign=$l;username=$Internet::qrz_uid;password=$Internet::qrz_pw;agent=dxspider HTTP/1.0\n\n";
- dbg($s) if isdbg('qrz');
- $t->print($s);
- Log('call', "$call: show/qrz \U$l");
- my $state = "blank";
- while (my $result = eval { $t->getline(Timeout => 30) } || $@) {
- dbg($result) if isdbg('qrz') && $result;
- if ($@) {
- push @out, $self->msg('e18', 'QRZ.com');
- last;
- }
- if ($state eq 'blank' && $result =~ /^<Callsign>/i) {
- $state = 'go';
- } elsif ($state eq 'go') {
- next if $result =~ m|<user>|;
- next if $result =~ m|<u_views>|;
- next if $result =~ m|<locref>|;
- next if $result =~ m|<ccode>|;
- next if $result =~ m|<dxcc>|;
- last if $result =~ m|</Callsign>|;
- my ($tag, $data) = $result =~ m|^\s*<(\w+)>(.*)</|;
- push @out, sprintf "%10s: $data", $tag;
- }
- }
- $t->close;
- push @out, $self->msg('e3', 'qrz.com', uc $l) unless @out;
- }
+ if (isdbg('qrz')) {
+ dbg("qrz response: $response");
+ dbg("qrz body: $body");
+ }
+ Log('call', "$call: show/qrz \U$body");
+ my $state = "blank";
+ foreach my $result (split /\r?\n/, $body) {
+ dbg("qrz: $result") if isdbg('qrz') && $result;
+ if ($state eq 'blank' && $result =~ /^<Callsign>/i) {
+ $state = 'go';
+ } elsif ($state eq 'go') {
+ next if $result =~ m|<user>|;
+ next if $result =~ m|<u_views>|;
+ next if $result =~ m|<locref>|;
+ next if $result =~ m|<ccode>|;
+ next if $result =~ m|<dxcc>|;
+ last if $result =~ m|</Callsign>|;
+ my ($tag, $data) = $result =~ m|^\s*<(\w+)>(.*)</|;
+ push @out, sprintf "%10s: $data", $tag;
+ }
+ }
+ if (@out) {
+ unshift @out, $self->msg('http2', "show/qrz \U$l");
+ } else {
+ push @out, $self->msg('e3', 'show/qrz', uc $l);
+ }
+ $self->send_ans(@out);
+ }
+ );
}
return (1, @out);
inqueue => '9,Input Queue,parray',
next_pc92_update => '9,Next PC92 Update,atime',
next_pc92_keepalive => '9,Next PC92 KeepAlive,atime',
+ anyevents => '9,outstanding AnyEvent handles,parray',
);
$maxerrors = 20; # the maximum number of concurrent errors allowed before disconnection
$self->{cq} = $dxcc[1]->cq;
}
$self->{inqueue} = [];
+ $self->{anyevents} = [];
$count++;
dbg("DXChannel $self->{call} created ($count)") if isdbg('chan');
return $r;
}
+sub anyevent_add
+{
+ my $self = shift;
+ my $handle = shift;
+ my $sort = shift || "unknown";
+
+ push @{$self->{anyevents}}, $handle;
+ dbg("anyevent: add $sort handle making " . scalar @{$self->{anyevents}} . " handles in use") if isdbg('anyevent');
+}
+
+sub anyevent_del
+{
+ my $self = shift;
+ my $handle = shift;
+ my $sort = shift || "unknown";
+ $self->{anyevents} = [ grep {$_ != $handle} @{$self->{anyevents}} ];
+ dbg("anyevent: delete $sort handle making " . scalar @{$self->{anyevents}} . " handles in use") if isdbg('anyevent');
+}
+
#no strict;
sub AUTOLOAD
{
@ISA = qw(DXChannel);
+use AnyEvent;
+use AnyEvent::Handle;
+use AnyEvent::Socket;
+
use POSIX qw(:math_h);
use DXUtil;
use DXChannel;
}
$self->send_file($motd) if -e $motd;
}
+
+sub http_get
+{
+ my $self = shift;
+ my ($host, $uri, $cb) = @_;
+
+ # store results here
+ my ($response, $header, $body);
+
+ my $handle;
+ $handle = AnyEvent::Handle->new(
+ connect => [$host => 'http'],
+ on_error => sub {
+ $cb->("HTTP/1.0 500 $!");
+ $self->anyevent_del($handle);
+ $handle->destroy; # explicitly destroy handle
+ },
+ on_eof => sub {
+ $cb->($response, $header, $body);
+ $self->anyevent_del($handle);
+ $handle->destroy; # explicitly destroy handle
+ }
+ );
+ $self->anyevent_add($handle);
+ $handle->push_write ("GET $uri HTTP/1.0\015\012\015\012");
+
+ # now fetch response status line
+ $handle->push_read (line => sub {
+ my ($handle, $line) = @_;
+ $response = $line;
+ });
+
+ # then the headers
+ $handle->push_read (line => "\015\012\015\012", sub {
+ my ($handle, $line) = @_;
+ $header = $line;
+ });
+
+ # and finally handle any remaining data as body
+ $handle->on_read (sub {
+ $body .= $_[0]->rbuf;
+ $_[0]->rbuf = "";
+ });
+}
+
1;
__END__
hnodee1 => 'Please enter your Home Node, set/homenode <your home DX Cluster>',
hnodee2 => 'Failed to set homenode on $_[0]',
hnode => 'Your Homenode is now \"$_[0]\"',
+ http1 => '$_[0] working ...',
+ http2 => '$_[0] returned:',
init1 => 'sent initialisation message to $_[0]',
iso => '$_[0] Isolated',
isou => '$_[0] UnIsolated',
$version = '1.56';
$subversion = '0';
-$build = '9';
-$gitversion = 'a22dbff';
+$build = '10';
+$gitversion = '370d356';
1;
unless ($DB::VERSION) {
$sigint = AnyEvent->signal(signal=>'INT', cb=> sub{$decease->send});
$sigterm = AnyEvent->signal(signal=>'TERM', cb=> sub{$decease->send});
+# $sigint = AnyEvent->signal(signal=>'INT', cb=> sub{AnyEvent->unloop});
+# $sigterm = AnyEvent->signal(signal=>'TERM', cb=> sub{AnyEvent->unloop});
}
unless ($is_win) {
# main loop
$decease->recv;
+#AnyEvent->loop;
idle_loop() for (1..25);
cease(0);