3 # Local 'autoqsl' module for DXSpider
5 # Copyright (c) 2003-2020 Dirk Koopman G1TLH
18 use Data::Structure::Util qw(unbless);
20 use vars qw($qslfn $dbm $maxentries);
31 my $ufn = localdata("$qslfn.v2");
33 Prefix::load() unless Prefix::loaded();
34 $json = JSON->new->canonical(1);
39 $dbm = tie (%u, 'DB_File', $ufn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open qsl file: $qslfn ($!)";
41 $dbm = tie (%u, 'DB_File', $ufn, O_RDONLY, 0666, $DB_BTREE) or confess "can't open qsl file: $qslfn ($!)";
54 my ($pkg, $call) = @_;
55 return undef if $call =~ /INFO|QSL|VIA/;
56 return bless [uc $call, []], $pkg;
59 # called $self->update(comment, time, spotter)
60 # $self has the callsign as the first argument in an array of array references
61 # the format of each entry is [manager, times found, last time, last reporter]
71 return unless length $line && $line =~ /\b(?:QSL|VIA|BUR[OE]?A?U?|OQRS|LOTW)\b/i;
72 foreach my $man (split /\b/, uc $line) {
75 if (is_callsign($man) && !is_qra($man)) {
76 my @pre = Prefix::extract($man);
77 $tok = $man if @pre && $pre[0] ne 'Q';
78 } elsif ($man =~ /^BUR/) {
80 } elsif ($man =~ /^LOTW/) {
82 } elsif ($man =~ /^OQRS/) {
84 } elsif ($man eq 'HC' || $man =~ /^HOM/ || $man =~ /^DIR/) {
86 } elsif ($man =~ /^QRZ/) {
92 my ($r) = grep {$_->[0] eq $tok} @{$self->[1]};
101 $r = [$tok, 1, $t, $by];
102 unshift @{$self->[1]}, $r;
105 # prune the number of entries
106 pop @{$self->[1]} while (@{$self->[1]} > $maxentries);
109 $self->put if $changed;
114 return undef unless $dbm;
118 my $r = $dbm->get($key, $value);
120 return json_decode($value);
127 my $key = $self->[0];
128 my $value = json_encode($self);
129 $dbm->put($key, $value);
136 eval { $ref = $json->decode($s) };
138 return bless $ref, __PACKAGE__;
140 LogDbg('DXUser', "__PACKAGE_::json_decode: on '$s' $@");
149 my $s = $json->encode($ref);
150 bless $ref, __PACKAGE__;