X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fshow%2Fqrz.pl;h=6782b1a16377d8c5cf0941c2aedf314e8a5b756c;hb=HEAD;hp=4468e13161990504238e8e2f3eba5436c2a82ee5;hpb=4857e1753d2fa365287d222e5fe8eacff9236eb5;p=spider.git diff --git a/cmd/show/qrz.pl b/cmd/show/qrz.pl index 4468e131..6782b1a1 100644 --- a/cmd/show/qrz.pl +++ b/cmd/show/qrz.pl @@ -2,47 +2,84 @@ # Query the QRZ Database server for a callsign # # from an idea by Steve Franke K9AN and information from Angel EA7WA +# and finally (!) modified to use the XML interface # -# $Id$ +# Then made asyncronous... # -my ($self, $line) = @_; -my @list = split /\s+/, $line; # generate a list of callsigns -my $l; -my $call = $self->call; -my @out; - -return (1, $self->msg('e24')) unless $Internet::allow; -return (1, "SHOW/QRZ , e.g. SH/QRZ g1tlh") unless @list; - -use Net::Telnet; - -my $t = new Net::Telnet; - -foreach $l (@list) { - $t->open(Host => "qrz.com", - Port => 80, - Timeout => 15); - if ($t) { - my $s = "GET /dxcluster.cgi?callsign=$l\&uid=$Internet::qrz_uid\&pw=$Internet::qrz_pw HTTP/1.0\n\n"; -# print $s; - $t->print($s); - Log('call', "$call: show/qrz \U$l"); - my $state = "blank"; - while (my $result = $t->getline) { -# print $result; - if ($state eq 'blank' && $result =~ /^\s*Callsign\s*:/i) { - $state = 'go'; - } elsif ($state eq 'go') { - next if $result =~ /^\s*Usage\s*:/i; - chomp $result; - push @out, $result; - } +# Copyright (c) 2001-2013 Dirk Koopman G1TLH +# + +use vars qw (%allowed); + +%allowed = qw(call 1 fname 1 name 1 addr2 1 state 1 country 1 lat 1 lon 1 county 1 moddate 1 qslmgr 1 grid 1 Error 1 ); + +sub _send +{ + my $conn = shift; + my $msg = shift; + my $dxchan = shift; + + my ($tag, $data) = $msg =~ m|^\s*<(\w+)>(.*){prefix} || ' '; + $dxchan->send($prefix . sprintf("%-10s: $data", $tag)); + } +} + +sub _on_disc +{ + my $conn = shift; + my $dxchan = shift; + $dxchan->send("Data provided by www.qrz.com"); +} + +sub filter +{ + my $conn = shift; + my $msg = shift; + my $dxchan = shift; + + my $state = $conn->{state}; + + dbg("qrz: $state $msg") if isdbg('qrz'); + + if ($state eq 'blank') { + if ($msg =~ /^\s*/) { + $conn->{state} = 'go'; + } elsif ($msg =~ /^\s*/) { + _send($conn, $msg, $dxchan); + } + } elsif ($state eq 'go') { + if ($msg =~ m||) { + $conn->{state} = 'skip'; + return; } - $t->close; - push @out, $self->msg('e3', 'qrz.com', $l) unless @out; +# $DB::single = 1; + _send($conn, $msg, $dxchan); + } +} + +sub handle +{ + my ($self, $line) = @_; + my $call = $self->call; + my @out; + + return (1, $self->msg('e24')) unless $Internet::allow; + return (1, "SHOW/QRZ , e.g. SH/QRZ g1tlh") unless $line; + my $target = $Internet::qrz_url || 'xmldata.qrz.com'; + my $port = 80; + my $path = qq{/xml/current/?callsign=$line;username=$Internet::qrz_uid;password=$Internet::qrz_pw;agent=dxspider}; + dbg("qrz: $target:$port$path") if isdbg('qrz'); + + Log('call', "$call: show/qrz \U$line"); + my $conn = AsyncMsg->get($self, $target, $port, $path, filter=>\&filter, prefix=>'qrz> ', on_disc=>\&_on_disc); + if ($conn) { + $conn->{state} = 'blank'; + push @out, $self->msg('m21', "show/qrz"); } else { push @out, $self->msg('e18', 'QRZ.com'); } -} -return (1, @out); + return (1, @out); +}