On Mar 1, 2005, at 21:53, Robert Spier wrote:

If we added something like the (untested) patch below it'd allow us to write plugins like this. (Another plugin will then register into "somehook").

 - ask

<snip>
sub register {
  my $self = shift;
  $self->create_hook('somehook');
  $self->register_hook('connect', 'connect_handler');
}

sub connect_handler {
  my $qp = shift->qp;

  my ($rc, $msg) = $qp->run_hooks("somehook");
  if ($rc == DENY) {
    $qp->respond(521, $msg);
    return $qp->disconnect;
  }
  elsif ($rc == DONE) {
    return 1;
  }
}
</snip>


Index: lib/Qpsmtpd/Plugin.pm =================================================================== RCS file: /cvs/public/qpsmtpd/lib/Qpsmtpd/Plugin.pm,v retrieving revision 1.14 diff -u -r1.14 Plugin.pm --- lib/Qpsmtpd/Plugin.pm 18 Nov 2004 19:47:10 -0000 1.14 +++ lib/Qpsmtpd/Plugin.pm 2 Mar 2005 23:57:22 -0000 @@ -14,6 +14,15 @@ bless ({}, $class); }

+sub create_hook {
+  my ($plugin, $hook) = @_;
+  if ($hooks{$hook}) {
+    $plugin->log("hook $hook already exists!");
+    return 0;
+  }
+  $hooks{$hook} = 1;
+}
+
 sub register_hook {
   my ($plugin, $hook, $method, $unshift) = @_;



--
http://www.askbjoernhansen.com/



Reply via email to