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->{num_hosts} = scalar(@{$self->{hosts}}) || "No hosts supplied";
|
||||||
$self->{client} = $client;
|
$self->{client} = $client;
|
||||||
$self->{callback} = $options{callback} || die "No callback given";
|
$self->{callback} = $options{callback} || die "No callback given";
|
||||||
|
$self->{finished} = $options{finished};
|
||||||
$self->{results} = {};
|
$self->{results} = {};
|
||||||
$self->{start} = time;
|
$self->{start} = time;
|
||||||
|
|
||||||
if ($options{type}) {
|
if ($options{type}) {
|
||||||
if ($options{type} eq 'TXT') {
|
if ( ($options{type} eq 'A') || ($options{type} eq 'PTR') ) {
|
||||||
if (!$resolver->query_txt($self, @{$self->{hosts}})) {
|
|
||||||
$client->enable_read() if $client;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elsif ($options{type} eq 'A') {
|
|
||||||
if (!$resolver->query($self, @{$self->{hosts}})) {
|
if (!$resolver->query($self, @{$self->{hosts}})) {
|
||||||
$client->enable_read() if $client;
|
$client->enable_read() if $client;
|
||||||
return;
|
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 {
|
else {
|
||||||
if (!$resolver->query_type($self, $options{type}, @{$self->{hosts}})) {
|
if (!$resolver->query_type($self, $options{type}, @{$self->{hosts}})) {
|
||||||
$client->enable_read() if $client;
|
$client->enable_read() if $client;
|
||||||
@ -102,6 +85,9 @@ sub DESTROY {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$self->{client}->enable_read if $self->{client};
|
$self->{client}->enable_read if $self->{client};
|
||||||
|
if ($self->{finished}) {
|
||||||
|
$self->{finished}->();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -41,6 +41,7 @@ sub connect_handler {
|
|||||||
$self->log(LOGDEBUG, "Checking $reversed_ip.$dnsbl for A record in the background");
|
$self->log(LOGDEBUG, "Checking $reversed_ip.$dnsbl for A record in the background");
|
||||||
Danga::DNS->new(
|
Danga::DNS->new(
|
||||||
callback => sub { process_a_result($qp, $dnsbl_zones{$dnsbl}, @_) },
|
callback => sub { process_a_result($qp, $dnsbl_zones{$dnsbl}, @_) },
|
||||||
|
finished => sub { finished($qp) },
|
||||||
host => "$reversed_ip.$dnsbl",
|
host => "$reversed_ip.$dnsbl",
|
||||||
type => 'A',
|
type => 'A',
|
||||||
client => $self->qp->input_sock,
|
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");
|
$self->log(LOGDEBUG, "Checking $reversed_ip.$dnsbl for TXT record in the background");
|
||||||
Danga::DNS->new(
|
Danga::DNS->new(
|
||||||
callback => sub { process_txt_result($qp, @_) },
|
callback => sub { process_txt_result($qp, @_) },
|
||||||
|
finished => sub { finished($qp) },
|
||||||
host => "$reversed_ip.$dnsbl",
|
host => "$reversed_ip.$dnsbl",
|
||||||
type => 'TXT',
|
type => 'TXT',
|
||||||
client => $self->qp->input_sock,
|
client => $self->qp->input_sock,
|
||||||
@ -59,13 +61,18 @@ sub connect_handler {
|
|||||||
return CONTINUATION;
|
return CONTINUATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub finished {
|
||||||
|
my ($qp) = @_;
|
||||||
|
$qp->finish_continuation;
|
||||||
|
}
|
||||||
|
|
||||||
sub process_a_result {
|
sub process_a_result {
|
||||||
my ($qp, $template, $result, $query) = @_;
|
my ($qp, $template, $result, $query) = @_;
|
||||||
|
|
||||||
warn("Result for A $query: $result\n");
|
warn("Result for A $query: $result\n");
|
||||||
if ($result !~ /^\d+\.\d+\.\d+\.\d+$/) {
|
if ($result !~ /^\d+\.\d+\.\d+\.\d+$/) {
|
||||||
# NXDOMAIN or ERROR possibly...
|
# NXDOMAIN or ERROR possibly...
|
||||||
$qp->finish_continuation if $qp->input_sock->readable;
|
# $qp->finish_continuation if $qp->input_sock->readable;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +80,7 @@ sub process_a_result {
|
|||||||
my $ip = $conn->remote_ip;
|
my $ip = $conn->remote_ip;
|
||||||
$template =~ s/%IP%/$ip/g;
|
$template =~ s/%IP%/$ip/g;
|
||||||
$conn->notes('dnsbl', $template) unless $conn->notes('dnsbl');
|
$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 {
|
sub process_txt_result {
|
||||||
@ -82,13 +89,13 @@ sub process_txt_result {
|
|||||||
warn("Result for TXT $query: $result\n");
|
warn("Result for TXT $query: $result\n");
|
||||||
if ($result !~ /[a-z]/) {
|
if ($result !~ /[a-z]/) {
|
||||||
# NXDOMAIN or ERROR probably...
|
# NXDOMAIN or ERROR probably...
|
||||||
$qp->finish_continuation if $qp->input_sock->readable;
|
# $qp->finish_continuation if $qp->input_sock->readable;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $conn = $qp->connection;
|
my $conn = $qp->connection;
|
||||||
$conn->notes('dnsbl', $result) unless $conn->notes('dnsbl');
|
$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 {
|
sub pickup_handler {
|
||||||
|
Loading…
Reference in New Issue
Block a user