make sure $transaction->notes is blessed before

calling it as such. It doesn't resolve #199 but it does help there.

I'm not sure initializing Qpsmtpd::transaction as {} is a brilliant idea, but I haven't a better solution for that yet.
This commit is contained in:
Matt Simerson 2015-01-28 10:09:50 -08:00
parent 0d79c1ef8e
commit d9ac50f383
4 changed files with 31 additions and 18 deletions

View File

@ -32,8 +32,9 @@ sub register_hook {
die $plugin->plugin_name . ": Invalid hook: $hook" unless $hooks{$hook};
$plugin->{_qp}->log(LOGDEBUG, $plugin->plugin_name, "hooking", $hook)
unless $hook =~ /logging/; # can't log during load_logging()
if ($hook !~ /logging/) { # can't log during load_logging()
$plugin->{_qp}->log(LOGDEBUG, $plugin->plugin_name, 'hooking', $hook);
}
# I can't quite decide if it's better to parse this code ref or if
# we should pass the plugin object and method name ... hmn.

View File

@ -230,7 +230,9 @@ sub maybe_reopen {
unless ($self->open_log($new_output, $transaction)) {
return undef;
}
if (UNIVERSAL::can($transaction,'isa')) {
$transaction->notes('file-reopened-this-session', 1);
}
return 1;
}
return 0;
@ -262,10 +264,12 @@ sub hook_disconnect {
sub hook_logging {
my ($self, $transaction, $trace, $hook, $plugin, @log) = @_;
return DECLINED
if !defined $self->{_loglevel}
or $trace > $self->{_loglevel};
return DECLINED if defined $plugin and $plugin eq $self->plugin_name;
if (!defined $self->{_loglevel}) { return DECLINED; }
if ($trace > $self->{_loglevel}) { return DECLINED; }
if (defined $plugin && $plugin eq $self->plugin_name) {
return DECLINED;
}
# Possibly reopen the log iff:
# - It's not already open
@ -280,8 +284,10 @@ sub hook_logging {
unless (defined $self->maybe_reopen($transaction)) {
return DECLINED;
}
if (UNIVERSAL::can($transaction,'isa')) {
$transaction->notes('file-logged-this-session', 1) if $transaction;
}
}
my $f = $self->{_f};
print $f strftime($self->{_tsformat}, localtime), ' ',

View File

@ -1,11 +1,17 @@
#
# Example configuration file for plugins
# Test configuration file for plugins
#
# enable this to get configuration via http; see perldoc
# plugins/http_config for details.
# http_config http://localhost/~smtpd/config/ http://www.example.com/smtp.pl?config=
logging/syslog
logging/warn
logging/file t/tmp/test-warn.log
content_log
# hosts_allow does not work with the tcpserver deployment model!
# perldoc plugins/hosts_allow for an alternative.
#
@ -13,7 +19,6 @@
# my $MAXCONNIP = 5; # max simultaneous connections from one IP
# settings... without this it will NOT refuse more than $MAXCONNIP connections
# from one IP!
content_log
hosts_allow
# information plugins

View File

@ -141,7 +141,8 @@ sub __log {
warn @_;
}
};
ok($qp->log(LOGWARN, "test log message"), 'log');
$qp->log(LOGWARN, "test log message");
ok(-f 't/tmp/test-warn.log', 'log');
is($warned, "$$ test log message\n", 'LOGWARN emitted correct warning');
}