From 0fa0f08b975665c25c4b039a13fac255131b6dbf Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Sat, 23 Jun 2012 00:40:02 -0400 Subject: [PATCH] connection_time: add compat with tcpserver deployment model --- plugins/connection_time | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/plugins/connection_time b/plugins/connection_time index 9cff7f9..2c9d8f7 100644 --- a/plugins/connection_time +++ b/plugins/connection_time @@ -31,7 +31,7 @@ use Qpsmtpd::Constants; use Time::HiRes qw(gettimeofday tv_interval); sub register { - my ($self, $qp) = shift, shift; + my ($self, $qp) = (shift, shift); if ( @_ == 1 ) { # backwards compatible $self->{_args}{loglevel} = shift; if ( $self->{_args}{loglevel} =~ /\D/ ) { @@ -45,21 +45,17 @@ sub register { else { $self->{_args} = { @_ }; # named args, inherits loglevel }; +# pre-connection is not available in the tcpserver deployment model. +# duplicate the handler, so it works both ways with no redudant methods + $self->register_hook('pre-connection', 'connect_handler'); + $self->register_hook('connect', 'connect_handler'); } -sub hook_pre_connection { +sub connect_handler { my $self = shift; + return DECLINED if ( $self->hook_name eq 'connect' && defined $self->{_connection_start} ); $self->{_connection_start} = [gettimeofday]; - $self->log(LOGDEBUG, "started at " . $self->{_connection_start} ); - return (DECLINED); -} - -sub hook_connect { - my $self = shift; -# this method is needed to function with the tcpserver deployment model - return (DECLINED) if defined $self->{_connection_start}; - $self->{_connection_start} = [gettimeofday]; - $self->log(LOGDEBUG, "started at " . $self->{_connection_start} ); + $self->log(LOGDEBUG, "started at " . scalar gettimeofday ); return (DECLINED); }