r589@jpeacock: jpeacock | 2005-07-10 06:54:32 -0400
Track hooks as array and hash. Re-revert changes to logging plugins to use new-style hooking. logging/adaptive assumed that register() has been called before hook_logging. git-svn-id: https://svn.perl.org/qpsmtpd/trunk@491 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
parent
00c53652c9
commit
1f7ece38f2
@ -2,12 +2,13 @@ package Qpsmtpd::Plugin;
|
||||
use Qpsmtpd::Constants;
|
||||
use strict;
|
||||
|
||||
our %hooks = map { $_ => 1 } qw(
|
||||
config queue data data_post quit rcpt mail ehlo helo
|
||||
our @hooks = qw(
|
||||
logging config queue data data_post quit rcpt mail ehlo helo
|
||||
auth auth-plain auth-login auth-cram-md5
|
||||
connect reset_transaction unrecognized_command disconnect
|
||||
deny logging ok pre-connection post-connection
|
||||
deny ok pre-connection post-connection
|
||||
);
|
||||
our %hooks = map { $_ => 1 } @hooks;
|
||||
|
||||
sub new {
|
||||
my $proto = shift;
|
||||
@ -155,7 +156,7 @@ sub compile {
|
||||
sub _register_standard_hooks {
|
||||
my ($plugin, $qp) = @_;
|
||||
|
||||
for my $hook (keys %hooks) {
|
||||
for my $hook (@hooks) {
|
||||
my $hooksub = "hook_$hook";
|
||||
$hooksub =~ s/\W/_/g;
|
||||
$plugin->register_hook( $hook, $hooksub )
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/perl
|
||||
#!perl
|
||||
# Adaptive logging plugin - logs at one level for successful messages and
|
||||
# one level for DENY'd messages
|
||||
|
||||
@ -30,16 +30,12 @@ sub register {
|
||||
$self->{_prefix} = $1;
|
||||
}
|
||||
|
||||
$self->register_hook( 'logging', 'wlog' );
|
||||
$self->register_hook( 'deny', 'dlog' );
|
||||
$self->register_hook( 'reset_transaction', 'slog' );
|
||||
|
||||
# If you want to capture this log entry with this plugin, you need to
|
||||
# wait until after you register the plugin
|
||||
$self->log( LOGINFO, 'Initializing logging::adaptive plugin' );
|
||||
}
|
||||
|
||||
sub wlog {
|
||||
sub hook_logging { # wlog
|
||||
my ( $self, $transaction, $trace, $hook, $plugin, @log ) = @_;
|
||||
|
||||
# Don't log your own log entries! If this is the only logging plugin
|
||||
@ -47,7 +43,7 @@ sub wlog {
|
||||
# out this line and it will not cause an infinite loop.
|
||||
return DECLINED if defined $plugin and $plugin eq $self->plugin_name;
|
||||
|
||||
if ( $trace <= $self->{_maxlevel} ) {
|
||||
if ( defined $self->{_maxlevel} && $trace <= $self->{_maxlevel} ) {
|
||||
warn join(
|
||||
" ", $$.
|
||||
(
|
||||
@ -60,18 +56,18 @@ sub wlog {
|
||||
"\n"
|
||||
unless $log[0] =~ /logging::adaptive/;
|
||||
push @{ $transaction->{_log} }, [ $trace, $hook, $plugin, @log ]
|
||||
if ( $trace <= $self->{_minlevel} );
|
||||
if ( defined $self->{_minlevel} && $trace <= $self->{_minlevel} );
|
||||
}
|
||||
|
||||
return DECLINED;
|
||||
}
|
||||
|
||||
sub dlog {
|
||||
sub hook_deny { # dlog
|
||||
my ( $self, $transaction, $prev_hook, $return, $return_text ) = @_;
|
||||
$self->{_denied} = 1;
|
||||
}
|
||||
|
||||
sub slog {
|
||||
sub hook_reset_transaction { # slog
|
||||
|
||||
# fires when a message is accepted
|
||||
my ( $self, $transaction, @args ) = @_;
|
||||
|
@ -1,13 +1,7 @@
|
||||
#!/usr/bin/perl
|
||||
# this is a simple 'drop packets on the floor' plugin
|
||||
|
||||
sub register {
|
||||
my $self = shift;
|
||||
|
||||
$self->register_hook('logging', 'wlog');
|
||||
}
|
||||
|
||||
sub wlog {
|
||||
sub hook_logging {
|
||||
return DECLINED;
|
||||
}
|
||||
|
||||
|
@ -16,14 +16,13 @@ sub register {
|
||||
$self->{_level} = log_level($loglevel);
|
||||
}
|
||||
}
|
||||
$self->register_hook('logging', 'wlog');
|
||||
|
||||
# If you want to capture this log entry with this plugin, you need to
|
||||
# wait until after you register the plugin
|
||||
$self->log(LOGINFO,'Initializing logging::warn plugin');
|
||||
}
|
||||
|
||||
sub wlog {
|
||||
sub hook_logging {
|
||||
my ($self, $transaction, $trace, $hook, $plugin, @log) = @_;
|
||||
|
||||
# Don't log your own log entries! If this is the only logging plugin
|
||||
|
Loading…
Reference in New Issue
Block a user