Slight cleanup.
Support a finished() callback as the readable() thing didn't work. git-svn-id: https://svn.perl.org/qpsmtpd/trunk@577 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
parent
8454ed40bc
commit
5994a79d9f
@ -33,34 +33,17 @@ sub new {
|
||||
$self->{num_hosts} = scalar(@{$self->{hosts}}) || "No hosts supplied";
|
||||
$self->{client} = $client;
|
||||
$self->{callback} = $options{callback} || die "No callback given";
|
||||
$self->{finished} = $options{finished};
|
||||
$self->{results} = {};
|
||||
$self->{start} = time;
|
||||
|
||||
if ($options{type}) {
|
||||
if ($options{type} eq 'TXT') {
|
||||
if (!$resolver->query_txt($self, @{$self->{hosts}})) {
|
||||
$client->enable_read() if $client;
|
||||
return;
|
||||
}
|
||||
}
|
||||
elsif ($options{type} eq 'A') {
|
||||
if ( ($options{type} eq 'A') || ($options{type} eq 'PTR') ) {
|
||||
if (!$resolver->query($self, @{$self->{hosts}})) {
|
||||
$client->enable_read() if $client;
|
||||
return;
|
||||
}
|
||||
}
|
||||
elsif ($options{type} eq 'PTR') {
|
||||
if (!$resolver->query($self, @{$self->{hosts}})) {
|
||||
$client->enable_read() if $client;
|
||||
return;
|
||||
}
|
||||
}
|
||||
elsif ($options{type} eq 'MX') {
|
||||
if (!$resolver->query_mx($self, @{$self->{hosts}})) {
|
||||
$client->enable_read() if $client;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!$resolver->query_type($self, $options{type}, @{$self->{hosts}})) {
|
||||
$client->enable_read() if $client;
|
||||
@ -102,6 +85,9 @@ sub DESTROY {
|
||||
}
|
||||
}
|
||||
$self->{client}->enable_read if $self->{client};
|
||||
if ($self->{finished}) {
|
||||
$self->{finished}->();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -41,6 +41,7 @@ sub connect_handler {
|
||||
$self->log(LOGDEBUG, "Checking $reversed_ip.$dnsbl for A record in the background");
|
||||
Danga::DNS->new(
|
||||
callback => sub { process_a_result($qp, $dnsbl_zones{$dnsbl}, @_) },
|
||||
finished => sub { finished($qp) },
|
||||
host => "$reversed_ip.$dnsbl",
|
||||
type => 'A',
|
||||
client => $self->qp->input_sock,
|
||||
@ -49,6 +50,7 @@ sub connect_handler {
|
||||
$self->log(LOGDEBUG, "Checking $reversed_ip.$dnsbl for TXT record in the background");
|
||||
Danga::DNS->new(
|
||||
callback => sub { process_txt_result($qp, @_) },
|
||||
finished => sub { finished($qp) },
|
||||
host => "$reversed_ip.$dnsbl",
|
||||
type => 'TXT',
|
||||
client => $self->qp->input_sock,
|
||||
@ -59,13 +61,18 @@ sub connect_handler {
|
||||
return CONTINUATION;
|
||||
}
|
||||
|
||||
sub finished {
|
||||
my ($qp) = @_;
|
||||
$qp->finish_continuation;
|
||||
}
|
||||
|
||||
sub process_a_result {
|
||||
my ($qp, $template, $result, $query) = @_;
|
||||
|
||||
warn("Result for A $query: $result\n");
|
||||
if ($result !~ /^\d+\.\d+\.\d+\.\d+$/) {
|
||||
# NXDOMAIN or ERROR possibly...
|
||||
$qp->finish_continuation if $qp->input_sock->readable;
|
||||
# $qp->finish_continuation if $qp->input_sock->readable;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -73,7 +80,7 @@ sub process_a_result {
|
||||
my $ip = $conn->remote_ip;
|
||||
$template =~ s/%IP%/$ip/g;
|
||||
$conn->notes('dnsbl', $template) unless $conn->notes('dnsbl');
|
||||
$qp->finish_continuation if $qp->input_sock->readable;
|
||||
# $qp->finish_continuation if $qp->input_sock->readable;
|
||||
}
|
||||
|
||||
sub process_txt_result {
|
||||
@ -82,13 +89,13 @@ sub process_txt_result {
|
||||
warn("Result for TXT $query: $result\n");
|
||||
if ($result !~ /[a-z]/) {
|
||||
# NXDOMAIN or ERROR probably...
|
||||
$qp->finish_continuation if $qp->input_sock->readable;
|
||||
# $qp->finish_continuation if $qp->input_sock->readable;
|
||||
return;
|
||||
}
|
||||
|
||||
my $conn = $qp->connection;
|
||||
$conn->notes('dnsbl', $result) unless $conn->notes('dnsbl');
|
||||
$qp->finish_continuation if $qp->input_sock->readable;
|
||||
# $qp->finish_continuation if $qp->input_sock->readable;
|
||||
}
|
||||
|
||||
sub pickup_handler {
|
||||
|
Loading…
Reference in New Issue
Block a user