X-Git-Url: http://www.dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fshow%2Fqrz.pl;h=9a3f9c3fc93ed9dd334b64ac259c7e271ac7ae14;hb=99077d96c91df307092394bf1028212adeec4c37;hp=4b05c7e0a5020b6d69369d084868dd5bc9969567;hpb=dc016a0633cdb15d29b9a71fdec2c230fbad201b;p=spider.git diff --git a/cmd/show/qrz.pl b/cmd/show/qrz.pl index 4b05c7e0..9a3f9c3f 100644 --- a/cmd/show/qrz.pl +++ b/cmd/show/qrz.pl @@ -2,8 +2,9 @@ # 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$ +# Copyright (c) 2001-2009 Dirk Koopman G1TLH # my ($self, $line) = @_; my @list = split /\s+/, $line; # generate a list of callsigns @@ -13,35 +14,52 @@ 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 || $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; + 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; + eval { + $t->open(Host => $target, + Port => $port, + Timeout => 15); + }; + + 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 = $t->getline) { -# print $result; - if ($state eq 'blank' && $result =~ /^\s*Callsign\s*:/i) { + 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 =~ /^/i) { $state = 'go'; } elsif ($state eq 'go') { - next if $result =~ /^\s*Usage\s*:/i; - chomp $result; - push @out, $result; + next if $result =~ m||; + next if $result =~ m||; + next if $result =~ m||; + next if $result =~ m||; + next if $result =~ m||; + last if $result =~ m||; + my ($tag, $data) = $result =~ m|^\s*<(\w+)>(.*)close; - push @out, $self->msg('e3', 'qrz.com', $call) unless @out; - } else { - push @out, $self->msg('e18', 'QRZ.com'); + push @out, $self->msg('e3', 'qrz.com', uc $l) unless @out; } }