Attached is the patch to Qpsmptd.pm required by my per_user_config 
plugin. It basically just adds argument passing to config plugins,
and tweaks the caching code to be per-config-file rather per-config-name
(and adds a 'cache' named argument to config to allow caching to be 
turned off, since #configs * #users may make it dreadfully expensive
for your environment).

IMO the argument passing stuff is useful in its own right, and the
caching changes are pretty trivial and have no effect on stock 
configurations. It would be great to have it included so people can play
with per_user_config without having to patch the core.

I know 'proper' per-user configs are on the todo list, but nothing seems
to have happened for on that for the last 18 months ...

Cheers,
Gavin

--- Qpsmtpd.pm.1        2005-07-06 11:58:28.000000000 +1000
+++ Qpsmtpd.pm  2005-07-06 12:10:54.000000000 +1000
@@ -87,7 +87,8 @@
 # database or whatever.
 #
 sub config {
-  my ($self, $c, $type) = @_;
+  my ($self, $c, $arg) = @_;
+  my $type = ref $arg ? $arg->{type} : $arg;
 
   #warn "SELF->config($c) ", ref $self;
 
@@ -96,7 +97,7 @@
                  timeout => 1200,
                  );
 
-  my ($rc, @config) = $self->run_hooks("config", $c);
+  my ($rc, @config) = $self->run_hooks("config", $c, $arg);
   return wantarray ? @config : $config[0] if $rc == OK;
 
   @config = $self->get_qmail_config($c, $type);
@@ -120,12 +121,12 @@
 sub get_qmail_config {
   my ($self, $config, $type) = @_;
   $self->log(LOGDEBUG, "trying to get config for $config");
-  if ($self->{_config_cache}->{$config}) {
-    return wantarray ? @{$self->{_config_cache}->{$config}} : 
$self->{_config_cache}->{$config}->[0];
-  }
   my $configdir = $self->config_dir($config);
 
   my $configfile = "$configdir/$config";
+  if ($self->{_config_cache}->{$configfile}) {
+    return wantarray ? @{$self->{_config_cache}->{$configfile}} : 
$self->{_config_cache}->{$configfile}->[0];
+  }
 
   if ($type and $type eq "map")  {
     return +{} unless -e $configfile . ".cdb";
@@ -150,7 +151,7 @@
 }
 
 sub _config_from_file {
-  my ($self, $configfile, $config) = @_;
+  my ($self, $configfile, $config, $arg) = @_;
   return unless -e $configfile;
   open CF, "<$configfile" or warn "$$ could not open configfile $configfile: 
$!" and return;
   my @config = <CF>;
@@ -158,7 +159,8 @@
   @config = grep { length($_) and $_ !~ m/^\s*#/ and $_ =~ m/\S/} @config;
   close CF;
   #$self->log(10, "returning get_config for $config 
",Data::Dumper->Dump([EMAIL PROTECTED], [qw(config)]));
-  $self->{_config_cache}->{$config} = [EMAIL PROTECTED];
+  $self->{_config_cache}->{$configfile} = [EMAIL PROTECTED] 
+      unless exists $arg->{cache} && $arg->{cache} == 0;
   return wantarray ? @config : $config[0];
 }
 

Reply via email to