I wanted to add some kind of extended config support for plugins that
I'm writing that run at connect, mail from and rcpt to stages.  I hacked
in YAML support into lib/Qpsmtpd.pm (the diff is below but I'm not
submitting this as a patch ... at this point at least).  I've noticed
that the config file is loaded every time a new connection comes in (I
put the config into connection->notes()).  Actually this is also
mentioned in the CDB section.  Is this expected or am I overlooking a
persistent place to cache data?

I was also unsure of how to get the config read relative to qpsmtpd on
disk so I hacked config_dir() to look for a config directory relative to
the current dir.  What is the proper way of doing this?

I'll post the plugins I'm working on when they're stable if there is any
interest.  They're basically for spamtrapping work.


--- lib/Qpsmtpd.pm.orig   2005-06-06 18:27:03.110888842 -0700
+++ lib/Qpsmtpd.pm      2005-06-07 21:19:49.845209464 -0700
@@ -69,6 +69,7 @@
   my $configdir = ($ENV{QMAIL} || '/var/qmail') . '/control';
   my ($name) = ($0 =~ m!(.*?)/([^/]+)$!);
   $configdir = "$name/config" if (-e "$name/config/$config");
+  $configdir = "./config" if (-e "./config");
   return $configdir;
 }

@@ -105,6 +106,33 @@
     # should we cache this?
     return \%h;
   }
+  elsif ($type and $type eq 'yaml') {
+    $self->log(LOGDEBUG, "loading YAML config file '$configfile.yml'");
+
+    if ( ! -e "$configfile.yml" ) {
+      require Cwd;
+      $self->log(LOGERROR, "YAML config file '$configfile.yml' not
found at " . Cwd::cwd() . "\n");
+      return +{};
+    }
+
+    eval { require YAML };
+
+    if ($@) {
+      $self->log(LOGERROR, "No YAML Support! Did NOT read
$configfile.yml, could not load YAML module: $@");
+      return +{};
+    }
+
+    my $h;
+    eval { $h = YAML::LoadFile("$configfile.yml") };
+
+    if ($@) {
+      $self->log(LOGERROR, "Error parsing config file $configfile.yml:
$@");
+      return +{};
+    }
+#    warn Data::Dumper->Dump([$h]);
+
+    return $h;
+  }

   return $self->_config_from_file($configfile, $config);
 }

Reply via email to