From 5994a79d9fad652373359f27cfddc46a4467f5e2 Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Tue, 22 Nov 2005 23:03:05 +0000 Subject: [PATCH] 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 --- lib/Danga/DNS.pm | 24 +++++------------------- plugins/dnsbl | 15 +++++++++++---- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/lib/Danga/DNS.pm b/lib/Danga/DNS.pm index 1e3a55c..02cd525 100644 --- a/lib/Danga/DNS.pm +++ b/lib/Danga/DNS.pm @@ -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; diff --git a/plugins/dnsbl b/plugins/dnsbl index 01c4106..d9b7c75 100644 --- a/plugins/dnsbl +++ b/plugins/dnsbl @@ -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 {