Hi,
this patch sets a way to disable any loaded plugin(s) for the current
client. I'm not going to commit this before Ask released 0.43. Matt
(and others with high traffic) should be ok with the one more line
next unless $code->{run};
per hook.
The plugins_loaded() should be in to Qpsmtpd.pm. Any other comments on
this?
I'm currently looking for a way to have plugins loaded but disabled (so
some other plugin can enable it later). Loading plugins on connect or
later at runtime would probably be possible, but too slow...
(Note to self: write docs before any commit)
Example plugins are
http://ankh-morp.org/~vetinari/qpsmtpd/dnswl_disable_plugins
http://ankh-morp.org/~vetinari/qpsmtpd/disable_plugins
The dnswl_disable_plugins requires
http://svn.perl.org/qpsmtpd/contrib/vetinari/dnswl
Hanno
Index: lib/Qpsmtpd.pm
===================================================================
--- lib/Qpsmtpd.pm (revision 874)
+++ lib/Qpsmtpd.pm (working copy)
@@ -415,6 +415,7 @@
my @r;
while (@$todo) {
my $code = shift @$todo;
+ next unless $code->{run};
#my $t2 = $SAMPLER->($hook . "_" . $code->{name}, undef, 1);
#warn("Got sampler called: ${hook}_$code->{name}\n");
$self->varlog(LOGDEBUG, $hook, $code->{name});
@@ -495,6 +496,20 @@
}
}
+sub plugin_status {
+ my ($self, $name, $status) = @_;
+ return undef unless $name;
+ foreach my $hook (keys %{$hooks}) {
+ foreach my $plugin (@{$hooks->{$hook}}) {
+ next unless $name eq $plugin->{name};
+ defined $status or return $plugin->{run};
+ $plugin->{run} = $status;
+ ### XXX: NO "last;": plugins may register a hook twice (see spamassassin)
+ }
+ }
+ $status;
+}
+
sub spool_dir {
my $self = shift;
Index: lib/Qpsmtpd/Plugin.pm
===================================================================
--- lib/Qpsmtpd/Plugin.pm (revision 874)
+++ lib/Qpsmtpd/Plugin.pm (working copy)
@@ -40,11 +40,40 @@
$plugin->$method(@_)
},
name => $plugin->plugin_name,
+ run => 1,
},
$unshift,
);
}
+sub plugin_status { $_[0]->qp->plugin_status($_[1]); }
+
+sub plugins_loaded {
+ my $self = shift;
+ my $hooks = $self->qp->hooks;
+ my %loaded = ();
+ foreach my $hook (keys %{$hooks}) {
+ foreach my $p (@{$hooks->{$hook}}) {
+ ++$loaded{$p->{name}};
+ }
+ }
+ return keys %loaded;
+}
+
+sub disable_plugin {
+ my ($self, $name) = @_;
+ $name = $self->plugin_name
+ unless defined $name;
+ $self->qp->plugin_status($name, 0);
+}
+
+sub enable_plugin {
+ my ($self, $name) = @_;
+ $name = $self->plugin_name # err, you can't enable yourself when disabled ;-)
+ unless defined $name;
+ $self->qp->plugin_status($name, 1);
+}
+
sub _register {
my $self = shift;
my $qp = shift;