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:
Matt Sergeant 2004-08-31 01:58:57 +00:00
parent acbb51a555
commit e6e2091ee0
3 changed files with 27 additions and 15 deletions

View File

@ -10,8 +10,6 @@ sub TRACE_LEVEL { $LogLevel }
sub version { $VERSION };
$Qpsmtpd::_hooks = {};
sub init_logger {
my $self = shift;
# Get the loglevel - we localise loglevel to zero while we do this
@ -116,6 +114,9 @@ sub _config_from_file {
sub load_plugins {
my $self = shift;
$self->{hooks} ||= {};
my @plugins = $self->config('plugins');
my ($name) = ($0 =~ m!(.*?)/([^/]+)$!);
@ -206,20 +207,24 @@ sub _load_plugins {
eval $eval;
die "eval $@" if $@;
my $plug = $package->new(qpsmtpd => $self);
$plug->register($self, @args);
my $plug = $package->new();
$plug->_register($self, @args);
}
}
sub transaction {
return {}; # base class implements empty transaction
}
sub run_hooks {
my ($self, $hook) = (shift, shift);
$self->{_hooks} = $Qpsmtpd::_hooks;
if ($self->{_hooks}->{$hook}) {
my $hooks = $self->{hooks};
if ($hooks->{$hook}) {
my @r;
for my $code (@{$self->{_hooks}->{$hook}}) {
for my $code (@{$hooks->{$hook}}) {
$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;
!defined $r[0]
and $self->log(LOGERROR, "plugin ".$code->{name}
@ -245,10 +250,7 @@ sub _register_hook {
my $self = shift;
my ($hook, $code, $unshift) = @_;
#my $plugin = shift; # see comment in Plugin.pm:register_hook
$self->{_hooks} = $Qpsmtpd::_hooks;
my $hooks = $self->{_hooks};
my $hooks = $self->{hooks};
if ($unshift) {
unshift @{$hooks->{$hook}}, $code;
}

View File

@ -10,8 +10,7 @@ my %hooks = map { $_ => 1 } qw(
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my %args = @_;
bless ({ _qp => $args{qpsmtpd} }, $class);
bless ({}, $class);
}
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 {
shift->{_qp};
}
@ -42,4 +48,8 @@ sub transaction {
shift->qp->transaction;
}
sub connection {
shift->qp->connection;
}
1;

View File

@ -169,7 +169,7 @@ sub ehlo {
# Check for possible AUTH mechanisms
my %auth_mechanisms;
HOOK: foreach my $hook ( keys %{$self->{_hooks}} ) {
HOOK: foreach my $hook ( keys %{$self->{hooks}} ) {
if ( $hook =~ m/^auth-?(.+)?$/ ) {
if ( defined $1 ) {
$auth_mechanisms{uc($1)} = 1;