diff --git a/lib/Qpsmtpd.pm b/lib/Qpsmtpd.pm index 9e3d3e2..ea3da78 100644 --- a/lib/Qpsmtpd.pm +++ b/lib/Qpsmtpd.pm @@ -1,13 +1,14 @@ package Qpsmtpd; use strict; -use vars qw($VERSION $TraceLevel $Spool_dir $Size_threshold); +#use warnings; +use vars qw($TraceLevel $Spool_dir $Size_threshold); use Sys::Hostname; use Qpsmtpd::Constants; #use DashProfiler; -$VERSION = "0.94"; +our $VERSION = "0.94"; my $git; @@ -17,17 +18,17 @@ if (-e ".git") { $git && chomp $git; } -my $hooks = {}; +our $hooks = {}; my %defaults = ( me => hostname, timeout => 1200, ); my $_config_cache = {}; -my %config_dir_memo; +our %config_dir_memo; #DashProfiler->add_profile("qpsmtpd"); #my $SAMPLER = DashProfiler->prepare("qpsmtpd"); -my $LOGGING_LOADED = 0; +our $LOGGING_LOADED = 0; sub _restart { my $self = shift; @@ -57,12 +58,11 @@ sub TRACE_LEVEL { $TraceLevel }; # leave for plugin compatibility sub hooks { $hooks; } sub load_logging { - - # need to do this differently than other plugins so as to - # not trigger logging activity - return if $LOGGING_LOADED; my $self = shift; - return if $hooks->{"logging"}; + + # avoid triggering log activity + return if ($LOGGING_LOADED || $hooks->{'logging'}); + my $configdir = $self->config_dir("logging"); my $configfile = "$configdir/logging"; my @loggers = $self->_config_from_file($configfile, 'logging'); @@ -97,10 +97,7 @@ sub load_logging { return @loggers; } -sub trace_level { - my $self = shift; - return $TraceLevel; -} +sub trace_level { return $TraceLevel; } sub init_logger { # needed for compatibility purposes shift->trace_level(); @@ -205,7 +202,7 @@ sub config_dir { } my $configdir = ($ENV{QMAIL} || '/var/qmail') . '/control'; my ($path) = ($ENV{PROCESS} ? $ENV{PROCESS} : $0) =~ m!(.*?)/([^/]+)$!; - $configdir = "$path/config" if (-e "$path/config/$config"); + $configdir = "$path/config" if -e "$path/config/$config"; if (exists $ENV{QPSMTPD_CONFIG}) { $ENV{QPSMTPD_CONFIG} =~ /^(.*)$/; # detaint $configdir = $1 if -e "$1/$config"; diff --git a/t/qpsmtpd.t b/t/qpsmtpd.t new file mode 100644 index 0000000..d2b04a2 --- /dev/null +++ b/t/qpsmtpd.t @@ -0,0 +1,46 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use Data::Dumper; +use Test::More; + +use lib 'lib'; # test lib/Qpsmtpd (vs site_perl) +BEGIN { use_ok('Qpsmtpd'); } +BEGIN { use_ok('Qpsmtpd::Constants'); } + +my $package = 'Qpsmtpd'; +my $qp = bless {}, $package; + +ok( $qp->version(), "version, " . $qp->version()); +is_deeply( Qpsmtpd::hooks(), {}, 'hooks, empty'); + +__config_dir(); +__log(); +__load_logging(); + +done_testing(); + +sub __log { + ok( $qp->log(LOGWARN, "test log message"), 'log'); +} + +sub __config_dir { + my $dir = $qp->config_dir('logging'); + ok( $dir, "config_dir, $dir"); + + #warn Data::Dumper::Dumper($Qpsmtpd::config_dir_memo{logging}); + $dir = $Qpsmtpd::config_dir_memo{logging}; + ok( $dir, "config_dir, $dir (memo)"); +}; + +sub __load_logging { + $Qpsmtpd::LOGGING_LOADED = 1; + ok( !$qp->load_logging(), "load_logging, loaded"); + + $Qpsmtpd::LOGGING_LOADED = 0; + $Qpsmtpd::hooks->{logging} = 1; + ok( !$qp->load_logging(), "load_logging, logging hook"); + + $Qpsmtpd::hooks->{logging} = undef; # restore +}