X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fshow%2Fqrz.pl;h=1bcd834787455f97aaffd6095eb2f2b480ea85a3;hb=d0b55caa8a609da9ccc5ea59bb376795a99d04b5;hp=fdcdc59dce4205f7ca992f8c6ee15f83e92633be;hpb=cd651c730ce8a5078bf36d24a9d679dac8fc4a3b;p=spider.git diff --git a/cmd/show/qrz.pl b/cmd/show/qrz.pl index fdcdc59d..1bcd8347 100644 --- a/cmd/show/qrz.pl +++ b/cmd/show/qrz.pl @@ -2,65 +2,86 @@ # 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 # -# Copyright (c) 2001 Dirk Koopman G1TLH +# Then made asyncronous... # -# $Id$ +# Copyright (c) 2001-2013 Dirk Koopman G1TLH # -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; -#my $target = $Internet::http_proxy || 'www.qrz.com'; -#my $port = $Internet::http_proxy_port || 80; -#my $url = ''; -#$url = 'http://www.qrz.com' if $Internet::http_proxy; -my $target = $Internet::http_proxy || $Internet::qrz_url || 'www.qrz.com'; -my $port = $Internet::http_proxy_port || 80; -my $url = ''; -$url = 'http://' . ($Internet::qrz_url | 'www.qrz.com') if $Internet::http_proxy; +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); -use Net::Telnet; +sub _send +{ + my $conn = shift; + my $msg = shift; + my $dxchan = shift; -my $t = new Net::Telnet; + my ($tag, $data) = $msg =~ m|^\s*<(\w+)>(.*){prefix} || ' '; + $dxchan->send($prefix . sprintf("%-10s: $data", $tag)); + } +} -foreach $l (@list) { - eval { - $t->open(Host => $target, - Port => $port, - Timeout => 15); - }; +sub _on_disc +{ + my $conn = shift; + my $dxchan = shift; + $dxchan->send("Data provided by www.qrz.com"); +} - if (!$t || $@) { - push @out, $self->msg('e18', 'QRZ.com'); - } else { - my $s = "GET $url/p/dxcluster.pl?callsign=$l\&username=$Internet::qrz_uid\&password=$Internet::qrz_pw 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 =~ /^\s*Callsign\s*:/i) { - $state = 'go'; - } elsif ($state eq 'go') { - next if $result =~ /^\s*Usage\s*:/i; - chomp $result; - push @out, $result; - } +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); } - $t->close; - push @out, $self->msg('e3', 'qrz.com', uc $l) unless @out; + } elsif ($state eq 'go') { + if ($msg =~ m||) { + $conn->{state} = 'skip'; + return; + } +# $DB::single = 1; + _send($conn, $msg, $dxchan); } } -return (1, @out); +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); +}