]> dxcluster.org Git - spider.git/blob - cmd/show/db0sdx.pl
130951e1b1747d4143e8b7b2a083620a940538c8
[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 = 'dotnet.grossmann.com';
17 my $port = 80;
18 my $cmdprompt = '/query->.*$/';
19
20 my($info, $t);
21                                     
22 $t = new Net::Telnet;
23 $info =  $t->open(Host    => $target,
24                   Port    => $port,
25                   Timeout => 15);
26
27 if (!$info) {
28         push @out, $self->msg('e18', 'DB0SDX Database server');
29 } else {
30
31         my $s = qq(<?xml version="1.0" encoding="utf-8"?>
32 <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/">
33   <soap:Body>
34     <qslinfo xmlns="http://dotnet.grossmann.com/qslinfo">
35       <callsign>$line</callsign>
36     </qslinfo>
37   </soap:Body>
38 </soap:Envelope>
39 );
40         
41
42         my $lth = length($s)+7;
43         
44         dbg("db0sdx out: $s") if isdbg('db0sdx');
45         
46         $t->print("POST /qslinfo/qslinfo.asmx HTTP/1.1");
47         $t->print("Host: dotnet.grossmann.com");
48         $t->print("Content-Type: text/xml; charset=utf-8");
49         $t->print("Content-Length: $lth");
50         $t->print("Connection: Close");
51         $t->print("SOAPAction: \"http://dotnet.grossmann.com/qslinfo/qslinfo\"");
52         $t->print("");
53         $t->put($s);
54
55         my $in;
56         
57         while (my $result = eval { $t->getline(Timeout => 30) } || $@) {
58                 if ($@) {
59                         push @out, $self->msg('e18', 'DB0SDX Server');
60                         last;
61                 } else {
62                         $in .= $result;
63                 }
64         }
65
66         dbg("db0sdx in: $in") if isdbg('db0sdx');
67         
68         # Log the lookup
69         Log('call', "$call: show/db0sdx $line");
70         $t->close;
71
72         my ($info) = $in =~ m|<qslinfoResult>([^<]*)</qslinfoResult>|;
73         my @in = split /[\r\n]/, $info if $info;
74         if (@in && $in[0]) {
75                 push @out, @in;
76         } else {
77                 ($info) = $in =~ m|<faultstring>([^<]*)</faultstring>|;
78                 push @out, $info if $info;
79                 push @out, $self->msg('e3', 'DB0SDX', $line) unless @out;               
80         }
81 }
82 return (1, @out);