X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fshow%2Fqrz.pl;h=b9d70441ea955d0928f071a5a3c8cb342af7c8c9;hb=e941823af33ba0398dfa48dc435438adc5ee365e;hp=5301c2cd6f72d35c39b562eec5eb3db15664dc4a;hpb=4e913f45fcd752c8a084dfb31f2c8e0da30f59b1;p=spider.git diff --git a/cmd/show/qrz.pl b/cmd/show/qrz.pl index 5301c2cd..b9d70441 100644 --- a/cmd/show/qrz.pl +++ b/cmd/show/qrz.pl @@ -2,51 +2,76 @@ # 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, "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', "$call: show/qrz \U$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 +# + +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 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 =~ /^/) { + $conn->{state} = 'go'; + } elsif ($msg =~ /^/) { + _send($conn, $msg, $dxchan); + } + } elsif ($state eq 'go') { + return if $msg =~ m||; + return if $msg =~ m||; + return if $msg =~ m||; + return if $msg =~ m||; + return if $msg =~ m||; + 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?callsign=$line;username=$Internet::qrz_uid;password=$Internet::qrz_pw;agent=dxspider}; + dbg("qrz: $path") if isdbg('qrz'); + + Log('call', "$call: show/qrz \U$line"); + my $conn = AsyncMsg->get($self, $target, $port, $path, filter=>\&filter, prefix=>'qrz> '); + 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); +}