connection_time: add compat with tcpserver deployment model

This commit is contained in:
Matt Simerson 2012-06-23 00:40:02 -04:00
parent e9395d6a79
commit b53bd08540

View File

@ -31,7 +31,7 @@ use Qpsmtpd::Constants;
use Time::HiRes qw(gettimeofday tv_interval); use Time::HiRes qw(gettimeofday tv_interval);
sub register { sub register {
my ($self, $qp) = shift, shift; my ($self, $qp) = (shift, shift);
if ( @_ == 1 ) { # backwards compatible if ( @_ == 1 ) { # backwards compatible
$self->{_args}{loglevel} = shift; $self->{_args}{loglevel} = shift;
if ( $self->{_args}{loglevel} =~ /\D/ ) { if ( $self->{_args}{loglevel} =~ /\D/ ) {
@ -45,21 +45,17 @@ sub register {
else { else {
$self->{_args} = { @_ }; # named args, inherits loglevel $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; my $self = shift;
return DECLINED if ( $self->hook_name eq 'connect' && defined $self->{_connection_start} );
$self->{_connection_start} = [gettimeofday]; $self->{_connection_start} = [gettimeofday];
$self->log(LOGDEBUG, "started at " . $self->{_connection_start} ); $self->log(LOGDEBUG, "started at " . scalar gettimeofday );
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} );
return (DECLINED); return (DECLINED);
} }