From: Jason Mills <jmmi...@cpan.org>
Signed-off-by: Jason Mills <jmmi...@cpan.org> --- lib/Qpsmtpd.pm | 35 +++++++++++++++++++++++++---------- lib/Qpsmtpd/Plugin.pm | 1 + 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/Qpsmtpd.pm b/lib/Qpsmtpd.pm index a47d330..7f4298f 100644 --- a/lib/Qpsmtpd.pm +++ b/lib/Qpsmtpd.pm @@ -141,6 +141,14 @@ sub clear_config_cache { $_config_cache = {}; } + +sub _run_cfg_cachekey_hook { + my ($self, $k) = (shift, shift); + my @r = $self->run_hooks_no_respond( "config-get-cachekey", $k, @_ ); + return $r[1] unless $r[0] != OK; + return $k; +} + # # method to get the configuration. It just calls get_qmail_config by # default, but it could be overwritten to look configuration up in a @@ -149,28 +157,30 @@ sub clear_config_cache { sub config { my ($self, $c, $type) = @_; + my $k = $self->_run_cfg_cachekey_hook($c, $type); + #my $timer = $SAMPLER->("config", undef, 1); - if ($_config_cache->{$c}) { - return wantarray ? @{$_config_cache->{$c}} : $_config_cache->{$c}->[0]; + if ($_config_cache->{$k}) { + return wantarray ? @{$_config_cache->{$k}} : $_config_cache->{$k}->[0]; } - $_config_cache->{$c} = [$defaults{$c}] if exists($defaults{$c}); + $_config_cache->{$k} = [$defaults{$k}] if exists($defaults{$k}); #warn "SELF->config($c) ", ref $self; - my ($rc, @config) = $self->run_hooks_no_respond("config", $c); + my ($rc, @config) = $self->run_hooks_no_respond("config", $k); @config = () unless $rc == OK; if (wantarray) { @config = $self->get_qmail_config($c, $type) unless @config; - @config = $defaults{$c} if (!...@config and $defaults{$c}); + @config = $defaults{$k} if (!...@config and $defaults{$k}); return @config; } else { return $config[0] if defined($config[0]); - my $val = $self->get_qmail_config($c, $type); + my $val = $self->get_qmail_config($k, $type); return $val if defined($val); - return $defaults{$c}; + return $defaults{$k}; } } @@ -207,10 +217,12 @@ sub get_qmail_config { my $configfile = "$configdir/$config"; + my $k = $self->_run_cfg_cachekey_hook( $config, $type ); + # CDB config support really should be moved to a plugin if ($type and $type eq "map") { unless (-e $configfile . ".cdb") { - $_config_cache->{$config} ||= []; + $_config_cache->{$k} ||= []; return +{}; } eval { require CDB_File }; @@ -236,8 +248,11 @@ sub get_qmail_config { sub _config_from_file { my ($self, $configfile, $config, $visited) = @_; + + my $k = $self->_run_cfg_cachekey_hook( $config ); + unless (-e $configfile) { - $_config_cache->{$config} ||= []; + $_config_cache->{$k} ||= []; return; } @@ -288,7 +303,7 @@ sub _config_from_file { } } - $_config_cache->{$config} = \...@config; + $_config_cache->{$k} = \...@config; return wantarray ? @config : $config[0]; } diff --git a/lib/Qpsmtpd/Plugin.pm b/lib/Qpsmtpd/Plugin.pm index 7758788..2fc7a7e 100644 --- a/lib/Qpsmtpd/Plugin.pm +++ b/lib/Qpsmtpd/Plugin.pm @@ -10,6 +10,7 @@ our @hooks = qw( data data_headers_end data_post queue_pre queue queue_post vrfy noop quit reset_transaction disconnect post-connection unrecognized_command deny ok received_line help + config-get-cachekey ); our %hooks = map { $_ => 1 } @hooks; -- 1.6.0.4