Attempt to clean up circular refs problems
git-svn-id: https://svn.perl.org/qpsmtpd/trunk@292 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
parent
acbb51a555
commit
e6e2091ee0
@ -10,8 +10,6 @@ sub TRACE_LEVEL { $LogLevel }
|
|||||||
|
|
||||||
sub version { $VERSION };
|
sub version { $VERSION };
|
||||||
|
|
||||||
$Qpsmtpd::_hooks = {};
|
|
||||||
|
|
||||||
sub init_logger {
|
sub init_logger {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
# Get the loglevel - we localise loglevel to zero while we do this
|
# Get the loglevel - we localise loglevel to zero while we do this
|
||||||
@ -116,6 +114,9 @@ sub _config_from_file {
|
|||||||
|
|
||||||
sub load_plugins {
|
sub load_plugins {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
|
$self->{hooks} ||= {};
|
||||||
|
|
||||||
my @plugins = $self->config('plugins');
|
my @plugins = $self->config('plugins');
|
||||||
|
|
||||||
my ($name) = ($0 =~ m!(.*?)/([^/]+)$!);
|
my ($name) = ($0 =~ m!(.*?)/([^/]+)$!);
|
||||||
@ -206,20 +207,24 @@ sub _load_plugins {
|
|||||||
eval $eval;
|
eval $eval;
|
||||||
die "eval $@" if $@;
|
die "eval $@" if $@;
|
||||||
|
|
||||||
my $plug = $package->new(qpsmtpd => $self);
|
my $plug = $package->new();
|
||||||
$plug->register($self, @args);
|
$plug->_register($self, @args);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub transaction {
|
||||||
|
return {}; # base class implements empty transaction
|
||||||
|
}
|
||||||
|
|
||||||
sub run_hooks {
|
sub run_hooks {
|
||||||
my ($self, $hook) = (shift, shift);
|
my ($self, $hook) = (shift, shift);
|
||||||
$self->{_hooks} = $Qpsmtpd::_hooks;
|
my $hooks = $self->{hooks};
|
||||||
if ($self->{_hooks}->{$hook}) {
|
if ($hooks->{$hook}) {
|
||||||
my @r;
|
my @r;
|
||||||
for my $code (@{$self->{_hooks}->{$hook}}) {
|
for my $code (@{$hooks->{$hook}}) {
|
||||||
$self->log(LOGINFO, "running plugin ", $code->{name});
|
$self->log(LOGINFO, "running plugin ", $code->{name});
|
||||||
eval { (@r) = $code->{code}->($self, $self->can('transaction') ? $self->transaction : {}, @_); };
|
eval { (@r) = $code->{code}->($self, $self->transaction, @_); };
|
||||||
$@ and $self->log(LOGCRIT, "FATAL PLUGIN ERROR: ", $@) and next;
|
$@ and $self->log(LOGCRIT, "FATAL PLUGIN ERROR: ", $@) and next;
|
||||||
!defined $r[0]
|
!defined $r[0]
|
||||||
and $self->log(LOGERROR, "plugin ".$code->{name}
|
and $self->log(LOGERROR, "plugin ".$code->{name}
|
||||||
@ -245,10 +250,7 @@ sub _register_hook {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($hook, $code, $unshift) = @_;
|
my ($hook, $code, $unshift) = @_;
|
||||||
|
|
||||||
#my $plugin = shift; # see comment in Plugin.pm:register_hook
|
my $hooks = $self->{hooks};
|
||||||
|
|
||||||
$self->{_hooks} = $Qpsmtpd::_hooks;
|
|
||||||
my $hooks = $self->{_hooks};
|
|
||||||
if ($unshift) {
|
if ($unshift) {
|
||||||
unshift @{$hooks->{$hook}}, $code;
|
unshift @{$hooks->{$hook}}, $code;
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,7 @@ my %hooks = map { $_ => 1 } qw(
|
|||||||
sub new {
|
sub new {
|
||||||
my $proto = shift;
|
my $proto = shift;
|
||||||
my $class = ref($proto) || $proto;
|
my $class = ref($proto) || $proto;
|
||||||
my %args = @_;
|
bless ({}, $class);
|
||||||
bless ({ _qp => $args{qpsmtpd} }, $class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub register_hook {
|
sub register_hook {
|
||||||
@ -28,6 +27,13 @@ sub register_hook {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub _register {
|
||||||
|
my $self = shift;
|
||||||
|
my $qp = shift;
|
||||||
|
local $self->{_qp} = $qp;
|
||||||
|
$self->register($qp, @_);
|
||||||
|
}
|
||||||
|
|
||||||
sub qp {
|
sub qp {
|
||||||
shift->{_qp};
|
shift->{_qp};
|
||||||
}
|
}
|
||||||
@ -42,4 +48,8 @@ sub transaction {
|
|||||||
shift->qp->transaction;
|
shift->qp->transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub connection {
|
||||||
|
shift->qp->connection;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -169,7 +169,7 @@ sub ehlo {
|
|||||||
|
|
||||||
# Check for possible AUTH mechanisms
|
# Check for possible AUTH mechanisms
|
||||||
my %auth_mechanisms;
|
my %auth_mechanisms;
|
||||||
HOOK: foreach my $hook ( keys %{$self->{_hooks}} ) {
|
HOOK: foreach my $hook ( keys %{$self->{hooks}} ) {
|
||||||
if ( $hook =~ m/^auth-?(.+)?$/ ) {
|
if ( $hook =~ m/^auth-?(.+)?$/ ) {
|
||||||
if ( defined $1 ) {
|
if ( defined $1 ) {
|
||||||
$auth_mechanisms{uc($1)} = 1;
|
$auth_mechanisms{uc($1)} = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user