From 1f7ece38f2df56066067065bd8df0d05c70eeb57 Mon Sep 17 00:00:00 2001 From: John Peacock Date: Sun, 10 Jul 2005 10:56:55 +0000 Subject: [PATCH] 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 --- lib/Qpsmtpd/Plugin.pm | 9 +++++---- plugins/logging/adaptive | 16 ++++++---------- plugins/logging/devnull | 8 +------- plugins/logging/warn | 3 +-- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/lib/Qpsmtpd/Plugin.pm b/lib/Qpsmtpd/Plugin.pm index 23a0996..48f3a43 100644 --- a/lib/Qpsmtpd/Plugin.pm +++ b/lib/Qpsmtpd/Plugin.pm @@ -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 ) diff --git a/plugins/logging/adaptive b/plugins/logging/adaptive index 2964d90..27d0eba 100644 --- a/plugins/logging/adaptive +++ b/plugins/logging/adaptive @@ -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 ) = @_; diff --git a/plugins/logging/devnull b/plugins/logging/devnull index 33d524e..566ab68 100644 --- a/plugins/logging/devnull +++ b/plugins/logging/devnull @@ -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; } diff --git a/plugins/logging/warn b/plugins/logging/warn index 4c79ddd..ce25399 100644 --- a/plugins/logging/warn +++ b/plugins/logging/warn @@ -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