[svn:qpsmtpd] rev 491 - in trunk: . lib/Qpsmtpd plugins/logging

[email protected] 10 Jul 2005 10:56:56 -0000
Newsgroups perl.cvs.qpsmtpd
Message-ID <[email protected]>
Author: jpeacock
Date: Sun Jul 10 03:56:55 2005
New Revision: 491

Modified:
   trunk/   (props changed)
   trunk/lib/Qpsmtpd/Plugin.pm
   trunk/plugins/logging/adaptive
   trunk/plugins/logging/devnull
   trunk/plugins/logging/warn
Log:
 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.


Modified: trunk/lib/Qpsmtpd/Plugin.pm
==============================================================================
--- trunk/lib/Qpsmtpd/Plugin.pm	(original)
+++ trunk/lib/Qpsmtpd/Plugin.pm	Sun Jul 10 03:56:55 2005
@@ -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 )

Modified: trunk/plugins/logging/adaptive
==============================================================================
--- trunk/plugins/logging/adaptive	(original)
+++ trunk/plugins/logging/adaptive	Sun Jul 10 03:56:55 2005
@@ -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 ) = @_;

Modified: trunk/plugins/logging/devnull
==============================================================================
--- trunk/plugins/logging/devnull	(original)
+++ trunk/plugins/logging/devnull	Sun Jul 10 03:56:55 2005
@@ -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;
 }
 

Modified: trunk/plugins/logging/warn
==============================================================================
--- trunk/plugins/logging/warn	(original)
+++ trunk/plugins/logging/warn	Sun Jul 10 03:56:55 2005
@@ -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