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:
John Peacock 2005-07-10 10:56:55 +00:00
parent 00c53652c9
commit 1f7ece38f2
4 changed files with 13 additions and 23 deletions

View File

@ -2,12 +2,13 @@ package Qpsmtpd::Plugin;
use Qpsmtpd::Constants; use Qpsmtpd::Constants;
use strict; use strict;
our %hooks = map { $_ => 1 } qw( our @hooks = qw(
config queue data data_post quit rcpt mail ehlo helo logging config queue data data_post quit rcpt mail ehlo helo
auth auth-plain auth-login auth-cram-md5 auth auth-plain auth-login auth-cram-md5
connect reset_transaction unrecognized_command disconnect 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 { sub new {
my $proto = shift; my $proto = shift;
@ -155,7 +156,7 @@ sub compile {
sub _register_standard_hooks { sub _register_standard_hooks {
my ($plugin, $qp) = @_; my ($plugin, $qp) = @_;
for my $hook (keys %hooks) { for my $hook (@hooks) {
my $hooksub = "hook_$hook"; my $hooksub = "hook_$hook";
$hooksub =~ s/\W/_/g; $hooksub =~ s/\W/_/g;
$plugin->register_hook( $hook, $hooksub ) $plugin->register_hook( $hook, $hooksub )

View File

@ -1,4 +1,4 @@
#!/usr/bin/perl #!perl
# Adaptive logging plugin - logs at one level for successful messages and # Adaptive logging plugin - logs at one level for successful messages and
# one level for DENY'd messages # one level for DENY'd messages
@ -30,16 +30,12 @@ sub register {
$self->{_prefix} = $1; $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 # If you want to capture this log entry with this plugin, you need to
# wait until after you register the plugin # wait until after you register the plugin
$self->log( LOGINFO, 'Initializing logging::adaptive plugin' ); $self->log( LOGINFO, 'Initializing logging::adaptive plugin' );
} }
sub wlog { sub hook_logging { # wlog
my ( $self, $transaction, $trace, $hook, $plugin, @log ) = @_; my ( $self, $transaction, $trace, $hook, $plugin, @log ) = @_;
# Don't log your own log entries! If this is the only logging plugin # 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. # out this line and it will not cause an infinite loop.
return DECLINED if defined $plugin and $plugin eq $self->plugin_name; return DECLINED if defined $plugin and $plugin eq $self->plugin_name;
if ( $trace <= $self->{_maxlevel} ) { if ( defined $self->{_maxlevel} && $trace <= $self->{_maxlevel} ) {
warn join( warn join(
" ", $$. " ", $$.
( (
@ -60,18 +56,18 @@ sub wlog {
"\n" "\n"
unless $log[0] =~ /logging::adaptive/; unless $log[0] =~ /logging::adaptive/;
push @{ $transaction->{_log} }, [ $trace, $hook, $plugin, @log ] push @{ $transaction->{_log} }, [ $trace, $hook, $plugin, @log ]
if ( $trace <= $self->{_minlevel} ); if ( defined $self->{_minlevel} && $trace <= $self->{_minlevel} );
} }
return DECLINED; return DECLINED;
} }
sub dlog { sub hook_deny { # dlog
my ( $self, $transaction, $prev_hook, $return, $return_text ) = @_; my ( $self, $transaction, $prev_hook, $return, $return_text ) = @_;
$self->{_denied} = 1; $self->{_denied} = 1;
} }
sub slog { sub hook_reset_transaction { # slog
# fires when a message is accepted # fires when a message is accepted
my ( $self, $transaction, @args ) = @_; my ( $self, $transaction, @args ) = @_;

View File

@ -1,13 +1,7 @@
#!/usr/bin/perl #!/usr/bin/perl
# this is a simple 'drop packets on the floor' plugin # this is a simple 'drop packets on the floor' plugin
sub register { sub hook_logging {
my $self = shift;
$self->register_hook('logging', 'wlog');
}
sub wlog {
return DECLINED; return DECLINED;
} }

View File

@ -16,14 +16,13 @@ sub register {
$self->{_level} = log_level($loglevel); $self->{_level} = log_level($loglevel);
} }
} }
$self->register_hook('logging', 'wlog');
# If you want to capture this log entry with this plugin, you need to # If you want to capture this log entry with this plugin, you need to
# wait until after you register the plugin # wait until after you register the plugin
$self->log(LOGINFO,'Initializing logging::warn plugin'); $self->log(LOGINFO,'Initializing logging::warn plugin');
} }
sub wlog { sub hook_logging {
my ($self, $transaction, $trace, $hook, $plugin, @log) = @_; my ($self, $transaction, $trace, $hook, $plugin, @log) = @_;
# Don't log your own log entries! If this is the only logging plugin # Don't log your own log entries! If this is the only logging plugin