X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fshow%2Fqrz.pl;h=1bcd834787455f97aaffd6095eb2f2b480ea85a3;hb=d0b55caa8a609da9ccc5ea59bb376795a99d04b5;hp=51a63c41afd3521fbb1e7291dde0a2066589ff01;hpb=575a26ea68a641f895f68ed28391962d92bf1912;p=spider.git diff --git a/cmd/show/qrz.pl b/cmd/show/qrz.pl index 51a63c41..1bcd8347 100644 --- a/cmd/show/qrz.pl +++ b/cmd/show/qrz.pl @@ -1,51 +1,87 @@ # -# Query the PineKnot Database server for a callsign +# 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 @out; - -return (1, "SHOW/QRZ , e.g. SH/QRZ g1tlh") unless @list; - -use Net::Telnet; - -my $t = new Net::Telnet; - -push @out, $self->msg('call1', "QRZ.com"); -foreach $l (@list) { - $t->open(Host => "qrz.com", - Port => 80, - Timeout => 5); - if ($t) { - $t->print("GET /database?callsign=$l HTTP/1.0\n\n"); - Log('call', "show/qrz $l"); - my $state = "call"; - while (my $result = $t->getline) { -# print "$state: $result"; - if ($state eq 'call' && $result =~ /$l/i) { - $state = 'getaddr'; - push @out, uc $l; - } elsif ($state eq 'getaddr' || $state eq 'inaddr') { - if ($result =~ /^\s+([\w\s.,;:-]+)(?:
)?$/) { - my $line = $1; - unless ($line =~ /^\s+$/) { - push @out, $line; - $state = 'inaddr' unless $state eq 'inaddr'; - } - } else { - $state = 'runout' if $state eq 'inaddr'; - } - } +# Copyright (c) 2001-2013 Dirk Koopman G1TLH +# + +use vars qw (%allowed %convert); + +%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 dxcc 1 ); +%convert = qw(dxcc ADIF); + +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; +# $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 || 'xml.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'); + my $addr = $self->hostname || '127.0.0.1'; + Log('cmd', "$self->{call}|$addr|show/qrz|$line"); + my $conn = AsyncMsg->get($self, $target, $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); +}