On 2005-07-15 20:08:43 +0200, Peter J. Holzer wrote:
> On 2005-07-06 20:58:21 -0400, Matt Sergeant wrote:
> > On 6 Jul 2005, at 20:47, Gavin Carr wrote:
> > 
> > >What about just using named arguments and honouring 'nolog => 1' or
> > >something?
> > 
> > The only downside is that they're not used anywhere else in the
> > source so it's a bit of a deviation from what's currently done.
> 
> In a qpsmtpd-0.28+patches I still have running Qpsmtpd::config looks
> like this:
> 
>     sub config {
>       my ($self, $c, $arg) = @_;
>       my $type;
>       if (ref $arg) { 
>       $type = $arg->{type};
>       } else {
>       $type = $arg; 
>       $arg = { type => $type };
>       }
[...]
> I think this particular patch was from Gavin.

Yep, it was. BTW, the greylisting plugin calls config with a second
parameter { rcpt => $rcpt }, so there is at least one plugin in the
standard distribution which makes use of an interface which doesn't yet
exist :-).

Anyway, attached is a corrected patch (against 0.31-dev) which combines
Gavin's per-user-config patch and my directory patch.

        hp

-- 
   _  | Peter J. Holzer    | Ich sehe nun ein, dass Computer wenig
|_|_) | Sysadmin WSR       | geeignet sind, um sich was zu merken.
| |   | [EMAIL PROTECTED]         |
__/   | http://www.hjp.at/ |    -- Holger Lembke in dan-am
--- lib/Qpsmtpd.pm.dirs 2005-07-14 13:05:11.000000000 +0200
+++ lib/Qpsmtpd.pm      2005-07-15 21:02:48.426595479 +0200
@@ -87,7 +87,10 @@
 # database or whatever.
 #
 sub config {
-  my ($self, $c, $type) = @_;
+  my ($self, $c, $arg) = @_;
+  unless (ref $arg) {
+    $arg = { type => $arg };
+  }
 
   #warn "SELF->config($c) ", ref $self;
 
@@ -96,17 +99,13 @@
                  timeout => 1200,
                  );
 
-  my ($rc, @config) = $self->run_hooks("config", $c);
-  @config = () unless $rc == OK;
+  my ($rc, @config) = $self->run_hooks("config", $c, $arg);
+  unless ($rc == OK) {
+    @config = $self->get_qmail_config($c, $arg);
+    @config = $defaults{$c} if ([EMAIL PROTECTED] and $defaults{$c});
+  }
 
-  if (wantarray) {
-      @config = $self->get_qmail_config($c, $type) unless @config;
-      @config = $defaults{$c} if ([EMAIL PROTECTED] and $defaults{$c});
-      return @config;
-  } 
-  else {
-      return ($config[0] || $self->get_qmail_config($c, $type) || 
$defaults{$c});
-   }
+  return wantarray ? @config : $config[0];
 }
 
 sub config_dir {
@@ -114,17 +113,25 @@
   my $configdir = ($ENV{QMAIL} || '/var/qmail') . '/control';
   my ($name) = ($0 =~ m!(.*?)/([^/]+)$!);
   $configdir = "$name/config" if (-e "$name/config/$config");
+  if (exists $ENV{QPSMTPD_CONFIG}) {
+    $configdir = $ENV{QPSMTPD_CONFIG} if (-e "$ENV{QPSMTPD_CONFIG}/$config");
+  }
   return $configdir;
 }
 
 sub plugin_dir {
-    my ($name) = ($0 =~ m!(.*?)/([^/]+)$!);
-    my $dir = "$name/plugins";
+    my $self = shift;
+    my $plugin_dir = $self->config('plugin_dir', {nolog => 1});
+    unless (defined($plugin_dir)) {
+      my ($name) = ($0 =~ m!(.*?)/([^/]+)$!);
+      $plugin_dir = "$name/plugins";
+    }
+    return $plugin_dir;
 }
 
 sub get_qmail_config {
-  my ($self, $config, $type) = @_;
-  $self->log(LOGDEBUG, "trying to get config for $config");
+  my ($self, $config, $arg) = @_;
+  $self->log(LOGDEBUG, "trying to get config for $config") 
unless($arg->{nolog});
   if ($self->{_config_cache}->{$config}) {
     return wantarray ? @{$self->{_config_cache}->{$config}} : 
$self->{_config_cache}->{$config}->[0];
   }
@@ -132,7 +139,7 @@
 
   my $configfile = "$configdir/$config";
 
-  if ($type and $type eq "map")  {
+  if ($arg->{type} and $arg->{type} eq "map")  {
     return +{} unless -e $configfile . ".cdb";
     eval { require CDB_File };
 
@@ -155,7 +162,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>;
@@ -163,7 +170,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];
 }
 

Attachment: pgpHyxtIJ7uRw.pgp
Description: PGP signature

Reply via email to