Port to CONTINUATIONS style
git-svn-id: https://svn.perl.org/qpsmtpd/branches/high_perf@449 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
parent
6047477c11
commit
a4a62af847
@ -11,9 +11,9 @@ sub register {
|
|||||||
sub mail_handler {
|
sub mail_handler {
|
||||||
my ($self, $transaction, $sender) = @_;
|
my ($self, $transaction, $sender) = @_;
|
||||||
|
|
||||||
$sender->format ne "<>" and $self->check_dns($sender->host);
|
$self->transaction->notes('resolvable', 1);
|
||||||
|
return DECLINED if $sender->format eq "<>";
|
||||||
return DECLINED;
|
return $self->check_dns($sender->host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -21,42 +21,56 @@ sub check_dns {
|
|||||||
my ($self, $host) = @_;
|
my ($self, $host) = @_;
|
||||||
|
|
||||||
# for stuff where we can't even parse a hostname out of the address
|
# for stuff where we can't even parse a hostname out of the address
|
||||||
return unless $host;
|
return DECLINED unless $host;
|
||||||
|
|
||||||
return $self->transaction->notes('resolvable', 1)
|
if( $host =~ m/^\[(\d{1,3}\.){3}\d{1,3}\]$/ ) {
|
||||||
if $host =~ m/^\[(\d{1,3}\.){3}\d{1,3}\]$/;
|
$self->transaction->notes('resolvable', 1);
|
||||||
|
return DECLINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->transaction->notes('pending_dns_queries', 2);
|
||||||
|
my $qp = $self->qp;
|
||||||
|
$self->log(LOGDEBUG, "Checking $host for MX record in the background");
|
||||||
Danga::DNS->new(
|
Danga::DNS->new(
|
||||||
callback => sub { $self->dns_result(@_) },
|
callback => sub { dns_result($qp, @_) },
|
||||||
host => $host,
|
host => $host,
|
||||||
type => "MX",
|
type => "MX",
|
||||||
client => $self->qp->input_sock,
|
client => $qp->input_sock,
|
||||||
);
|
);
|
||||||
|
$self->log(LOGDEBUG, "Checking $host for A record in the background");
|
||||||
Danga::DNS->new(
|
Danga::DNS->new(
|
||||||
callback => sub { $self->dns_result(@_) },
|
callback => sub { dns_result($qp, @_) },
|
||||||
host => $host,
|
host => $host,
|
||||||
client => $self->qp->input_sock,
|
client => $qp->input_sock,
|
||||||
);
|
);
|
||||||
|
return CONTINUATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub dns_result {
|
sub dns_result {
|
||||||
my ($self, $result, $query) = @_;
|
my ($qp, $result, $query) = @_;
|
||||||
|
|
||||||
|
my $pending = $qp->transaction->notes('pending_dns_queries');
|
||||||
|
$qp->transaction->notes('pending_dns_queries', --$pending);
|
||||||
|
|
||||||
if ($result =~ /^[A-Z]+$/) {
|
if ($result =~ /^[A-Z]+$/) {
|
||||||
# probably an error
|
# probably an error
|
||||||
$self->log(LOGDEBUG, "DNS error: $result looking up $query");
|
$qp->log(LOGDEBUG, "DNS error: $result looking up $query");
|
||||||
return;
|
} else {
|
||||||
|
$qp->transaction->notes('resolvable', 1);
|
||||||
|
$qp->log(LOGDEBUG, "DNS lookup $query returned: $result");
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->log(LOGDEBUG, "DNS lookup $query returned: $result");
|
$qp->finish_continuation unless $pending;
|
||||||
$self->transaction->notes('resolvable', 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub rcpt_handler {
|
sub rcpt_handler {
|
||||||
my ($self, $transaction) = @_;
|
my ($self, $transaction) = @_;
|
||||||
|
|
||||||
if (!$transaction->notes('resolvable')) {
|
if (!$transaction->notes('resolvable')) {
|
||||||
my $sender = $transaction->sender;
|
my $sender = $transaction->sender;
|
||||||
|
$self->log(LOGDEBUG, "Could not resolve " .$sender->host) if $sender->host;
|
||||||
return (DENYSOFT,
|
return (DENYSOFT,
|
||||||
($sender->host
|
($sender->host
|
||||||
? "Could not resolve ". $sender->host
|
? "Could not resolve ". $sender->host
|
||||||
|
Loading…
Reference in New Issue
Block a user