[svn:qpsmtpd] r577 - in trunk: lib/Danga plugins
[email protected] 22 Nov 2005 23:03:06 -0000
| Newsgroups | perl.cvs.qpsmtpd |
|---|---|
| Message-ID | <[email protected]> |
Author: msergeant
Date: Tue Nov 22 15:03:05 2005
New Revision: 577
Modified:
trunk/lib/Danga/DNS.pm
trunk/plugins/dnsbl
Log:
Slight cleanup.
Support a finished() callback as the readable() thing didn't work.
Modified: trunk/lib/Danga/DNS.pm
==============================================================================
--- trunk/lib/Danga/DNS.pm (original)
+++ trunk/lib/Danga/DNS.pm Tue Nov 22 15:03:05 2005
@@ -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 (!$resolver->query($self, @{$self->{hosts}})) {
- $client->enable_read() if $client;
- return;
- }
- }
- elsif ($options{type} eq 'PTR') {
+ 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 '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;
Modified: trunk/plugins/dnsbl
==============================================================================
--- trunk/plugins/dnsbl (original)
+++ trunk/plugins/dnsbl Tue Nov 22 15:03:05 2005
@@ -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 {