2 # Query the QRZ Database server for a callsign
4 # from an idea by Steve Franke K9AN and information from Angel EA7WA
5 # and finally (!) modified to use the XML interface
7 # Copyright (c) 2001-2009 Dirk Koopman G1TLH
9 my ($self, $line) = @_;
10 my @list = split /\s+/, $line; # generate a list of callsigns
12 my $call = $self->call;
15 return (1, $self->msg('e24')) unless $Internet::allow;
16 return (1, "SHOW/QRZ <callsign>, e.g. SH/QRZ g1tlh") unless @list;
17 my $target = $Internet::http_proxy || $Internet::qrz_url || 'xml.qrz.com';
18 my $port = $Internet::http_proxy_port || 80;
20 $url = 'http://' . ($Internet::qrz_url || 'xml.qrz.com') if $Internet::http_proxy;
24 my $host = $url?$url:$target;
25 my $s = "$url/xml?callsign=$l;username=$Internet::qrz_uid;password=$Internet::qrz_pw;agent=dxspider";
31 Log('call', "$call: show/qrz \U$l");
32 push @out, $self->msg('http1', 'qrz.com', "\U$l");
34 $self->http_get($host, $s, sub
36 my ($response, $header, $body) = @_;
40 dbg("qrz response: $response");
41 dbg("qrz body: $body");
43 if ($response =~ /^5/) {
44 push @out, $self->msg('e18',"qrz.com $!");
46 Log('call', "$call: show/qrz \U$body");
48 foreach my $result (split /\r?\n/, $body) {
49 dbg("qrz: $result") if isdbg('qrz') && $result;
50 if ($state eq 'blank' && $result =~ /^<Callsign>/i) {
52 } elsif ($state eq 'go') {
53 next if $result =~ m|<user>|;
54 next if $result =~ m|<u_views>|;
55 next if $result =~ m|<locref>|;
56 next if $result =~ m|<ccode>|;
57 next if $result =~ m|<dxcc>|;
58 last if $result =~ m|</Callsign>|;
59 my ($tag, $data) = $result =~ m|^\s*<(\w+)>(.*)</|;
60 push @out, sprintf "%10s: $data", $tag;
64 unshift @out, $self->msg('http2', "show/qrz \U$l");
66 push @out, $self->msg('e3', 'show/qrz', uc $l);
69 $self->send_ans(@out);