2002-07-06 09:18:48 +02:00
|
|
|
package Qpsmtpd::Plugin;
|
|
|
|
use strict;
|
|
|
|
|
2004-03-05 13:46:24 +01:00
|
|
|
my %hooks = map { $_ => 1 } qw(
|
|
|
|
config queue data_post quit rcpt mail ehlo helo
|
2004-06-29 23:45:35 +02:00
|
|
|
auth auth-plain auth-login auth-cram-md5
|
2004-03-05 13:46:24 +01:00
|
|
|
connect reset_transaction unrecognized_command disconnect
|
|
|
|
);
|
|
|
|
|
2002-07-06 09:18:48 +02:00
|
|
|
sub new {
|
|
|
|
my $proto = shift;
|
|
|
|
my $class = ref($proto) || $proto;
|
2002-07-08 04:30:11 +02:00
|
|
|
my %args = @_;
|
|
|
|
bless ({ _qp => $args{qpsmtpd} }, $class);
|
2002-07-06 09:18:48 +02:00
|
|
|
}
|
|
|
|
|
2002-07-08 04:30:11 +02:00
|
|
|
sub register_hook {
|
2004-06-11 22:01:17 +02:00
|
|
|
my ($plugin, $hook, $method, $unshift) = @_;
|
2004-03-05 13:46:24 +01:00
|
|
|
|
|
|
|
die $plugin->plugin_name . " : Invalid hook: $hook" unless $hooks{$hook};
|
|
|
|
|
2002-07-08 04:30:11 +02:00
|
|
|
# I can't quite decide if it's better to parse this code ref or if
|
|
|
|
# we should pass the plugin object and method name ... hmn.
|
2003-11-02 12:13:08 +01:00
|
|
|
$plugin->qp->_register_hook($hook, { code => sub { local $plugin->{_qp} = shift; $plugin->$method(@_) },
|
2004-06-11 22:01:17 +02:00
|
|
|
name => $plugin->plugin_name,
|
|
|
|
},
|
|
|
|
$unshift,
|
2002-09-24 12:56:35 +02:00
|
|
|
);
|
2002-07-08 04:30:11 +02:00
|
|
|
}
|
2002-07-06 09:18:48 +02:00
|
|
|
|
2002-07-08 04:30:11 +02:00
|
|
|
sub qp {
|
|
|
|
shift->{_qp};
|
|
|
|
}
|
2002-07-06 09:18:48 +02:00
|
|
|
|
2002-07-08 04:30:11 +02:00
|
|
|
sub log {
|
2002-09-08 12:00:02 +02:00
|
|
|
my $self = shift;
|
|
|
|
$self->qp->log(shift, $self->plugin_name . " plugin: " . shift, @_);
|
2002-07-06 09:18:48 +02:00
|
|
|
}
|
|
|
|
|
2002-07-08 04:30:11 +02:00
|
|
|
sub transaction {
|
|
|
|
# not sure if this will work in a non-forking or a threaded daemon
|
|
|
|
shift->qp->transaction;
|
|
|
|
}
|
2002-07-06 09:18:48 +02:00
|
|
|
|
|
|
|
1;
|