added show/425 command
[spider.git] / cmd / show / db0sdx.pl
1 #
2 # Query the DB0SDX QSL server for a callsign
3 #
4 # Copyright (c) 2003 Dirk Koopman G1TLH
5 #
6 # $Id$
7 #
8
9 my ($self, $line) = @_;
10 my $call = $self->call;
11 my @out;
12
13 $line = uc $line;
14 return (1, $self->msg('e24')) unless $Internet::allow;
15 return (1, "SHOW/DB0SDX <callsign>, e.g. SH/DB0SDX ea7wa") unless $line && is_callsign($line);
16 my $target = $Internet::db0sdx_url || 'dotnet.grossmann.com';
17 my $port = 80;
18 my $cmdprompt = '/query->.*$/';
19
20 my($info, $t);
21                                     
22 $t = new Net::Telnet;
23
24 dbg("db0sdx: contacting $target:$port") if isdbg('db0sdx');
25 $info =  $t->open(Host    => $target,
26                   Port    => $port,
27                   Timeout => 15);
28
29 if (!$info) {
30         push @out, $self->msg('e18', 'DB0SDX Database server');
31 } else {
32
33         dbg("db0sdx: connected to $target:$port") if isdbg('db0sdx');
34
35         my $s = qq(<?xml version="1.0" encoding="utf-8"?>
36 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
37   <soap:Body>
38     <qslinfo xmlns="http://dotnet.grossmann.com/qslinfo">
39       <callsign>$line</callsign>
40     </qslinfo>
41   </soap:Body>
42 </soap:Envelope>
43 );
44         
45
46         my $lth = length($s)+7;
47         
48         dbg("db0sdx out: $s") if isdbg('db0sdx');
49         
50         $t->print("POST /qslinfo/qslinfo.asmx HTTP/1.0");
51         $t->print("Host: dotnet.grossmann.com");
52         $t->print("Content-Type: text/xml; charset=utf-8");
53         $t->print("Content-Length: $lth");
54         $t->print("Connection: Close");
55         $t->print("SOAPAction: \"http://dotnet.grossmann.com/qslinfo/qslinfo\"");
56         $t->print("");
57         $t->put($s);
58
59         my $in;
60         
61         while (my $result = eval { $t->getline(Timeout => 30) } || $@) {
62                 if ($@) {
63                         push @out, $self->msg('e18', 'DB0SDX Server');
64                         last;
65                 } else {
66                         $in .= $result;
67                 }
68         }
69
70         dbg("db0sdx in: $in") if isdbg('db0sdx');
71         
72         # Log the lookup
73         Log('call', "$call: show/db0sdx $line");
74         $t->close;
75
76         my ($info) = $in =~ m|<qslinfoResult>([^<]*)</qslinfoResult>|;
77         my @in = split /[\r\n]/, $info if $info;
78         if (@in && $in[0]) {
79                 push @out, @in;
80         } else {
81                 ($info) = $in =~ m|<faultstring>([^<]*)</faultstring>|;
82                 push @out, $info if $info;
83                 push @out, $self->msg('e3', 'DB0SDX', $line) unless @out;               
84         }
85 }
86 return (1, @out);