cvs commit: qpsmtpd/lib/Qpsmtpd Plugin.pm SMTP.pm
[email protected] (Matt Sergeant)
| Newsgroups | perl.cvs.qpsmtpd |
|---|---|
| Message-ID | <[email protected]> |
cvsuser 04/08/30 18:58:57
Modified: lib Qpsmtpd.pm
lib/Qpsmtpd Plugin.pm SMTP.pm
Log:
Attempt to clean up circular refs problems
Revision Changes Path
1.36 +14 -12 qpsmtpd/lib/Qpsmtpd.pm
Index: Qpsmtpd.pm
===================================================================
RCS file: /cvs/public/qpsmtpd/lib/Qpsmtpd.pm,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -w -r1.35 -r1.36
--- Qpsmtpd.pm 18 Jul 2004 11:02:08 -0000 1.35
+++ Qpsmtpd.pm 31 Aug 2004 01:58:57 -0000 1.36
@@ -10,8 +10,6 @@
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 load_plugins {
my $self = shift;
+
+ $self->{hooks} ||= {};
+
my @plugins = $self->config('plugins');
my ($name) = ($0 =~ m!(.*?)/([^/]+)$!);
@@ -206,20 +207,24 @@
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 @@
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;
}
1.10 +12 -2 qpsmtpd/lib/Qpsmtpd/Plugin.pm
Index: Plugin.pm
===================================================================
RCS file: /cvs/public/qpsmtpd/lib/Qpsmtpd/Plugin.pm,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -w -r1.9 -r1.10
--- Plugin.pm 16 Jul 2004 07:27:26 -0000 1.9
+++ Plugin.pm 31 Aug 2004 01:58:57 -0000 1.10
@@ -10,8 +10,7 @@
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 {
+ my $self = shift;
+ my $qp = shift;
+ local $self->{_qp} = $qp;
+ $self->register($qp, @_);
+}
+
sub qp {
shift->{_qp};
}
@@ -42,4 +48,8 @@
shift->qp->transaction;
}
+sub connection {
+ shift->qp->connection;
+}
+
1;
1.36 +1 -1 qpsmtpd/lib/Qpsmtpd/SMTP.pm
Index: SMTP.pm
===================================================================
RCS file: /cvs/public/qpsmtpd/lib/Qpsmtpd/SMTP.pm,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -w -r1.35 -r1.36
--- SMTP.pm 20 Jul 2004 12:46:20 -0000 1.35
+++ SMTP.pm 31 Aug 2004 01:58:57 -0000 1.36
@@ -169,7 +169,7 @@
# 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;