Debian Codegraph @

lib/Qpsmtpd/Plugin/Async/DNSBLBase.pm

raw
1 package Qpsmtpd::Plugin::Async::DNSBLBase;
2
3 # Class methods shared by the async plugins using DNS based blacklists or
4 # whitelists.
5
6 use strict;
7 use Qpsmtpd::Constants;
8 use ParaDNS;
9
10 sub lookup {
11 my ($class, $qp, $A_lookups, $TXT_lookups) = @_;
12
13 my $total_zones = @$A_lookups + @$TXT_lookups;
14
15 my ($A_pdns, $TXT_pdns);
16
17 if (@$A_lookups) {
18 $qp->log(LOGDEBUG, "Checking ",
19 join(", ", @$A_lookups),
20 " for A record in the background");
21
22 $A_pdns = ParaDNS->new(
23 callback => sub {
24 my ($result, $query) = @_;
25 return if $result !~ /^\d+\.\d+\.\d+\.\d+$/;
26 $qp->log(LOGDEBUG, "Result for A $query: $result");
27 $class->process_a_result($qp, $result, $query);
28 },
29 finished => sub {
30 $total_zones -= @$A_lookups;
31 $class->finished($qp, $total_zones);
32 },
33 hosts => [@$A_lookups],
34 type => 'A',
35 client => $qp->input_sock,
36 );
37
38 return unless defined $A_pdns;
39 }
40
41 if (@$TXT_lookups) {
42 $qp->log(LOGDEBUG, "Checking ",
43 join(", ", @$TXT_lookups),
44 " for TXT record in the background");
45
46 $TXT_pdns = ParaDNS->new(
47 callback => sub {
48 my ($result, $query) = @_;
49 return if $result !~ /[a-z]/;
50 $qp->log(LOGDEBUG, "Result for TXT $query: $result");
51 $class->process_txt_result($qp, $result, $query);
52 },
53 finished => sub {
54 $total_zones -= @$TXT_lookups;
55 $class->finished($qp, $total_zones);
56 },
57 hosts => [@$TXT_lookups],
58 type => 'TXT',
59 client => $qp->input_sock,
60 );
61
62 unless (defined $TXT_pdns) {
63 undef $A_pdns;
64 return;
65 }
66 }
67
68 return 1;
69 }
70
71 sub finished {
72 my ($class, $qp, $total_zones) = @_;
73 $qp->log(LOGDEBUG, "Finished ($total_zones)");
74 $qp->run_continuation unless $total_zones;
75 }
76
77 # plugins should implement the following two methods to do something
78 # useful with the results
79 sub process_a_result {
80 my ($class, $qp, $result, $query) = @_;
81 }
82
83 sub process_txt_result {
84 my ($class, $qp, $result, $query) = @_;
85 }
86
87 1;