[svn:qpsmtpd] r669 - in branches/0.3x: . lib/Qpsmtpd/Postfix

[email protected] Tue, 31 Oct 2006 18:28:45 -0800 (PST)
Newsgroups perl.cvs.qpsmtpd
Message-ID <[email protected]>
Author: jpeacock
Date: Tue Oct 31 18:28:41 2006
New Revision: 669

Added:
   branches/0.3x/lib/Qpsmtpd/Postfix/pf2qp.pl   (contents, props changed)
Modified:
   branches/0.3x/Changes

Log:
Script to generate Qpsmtpd::Postfix::Constants from the Postfix source.
From Hanno Hecker (tweaks by John Peacock).

Modified: branches/0.3x/Changes
==============================================================================
--- branches/0.3x/Changes	(original)
+++ branches/0.3x/Changes	Tue Oct 31 18:28:41 2006
@@ -1,4 +1,7 @@
 0.33
+  New Qpsmtpd::Postfix::Constants to encapsulate all of the current return
+  codes from Postfix, plus script to generate it.  (Hanno Hecker)
+
   Add ability to specific socket for syslog (Peter Eisch)
 
   Do the right thing for unimplemented AUTH mechanisms (Brian Szymanski)

Added: branches/0.3x/lib/Qpsmtpd/Postfix/pf2qp.pl
==============================================================================
--- (empty file)
+++ branches/0.3x/lib/Qpsmtpd/Postfix/pf2qp.pl	Tue Oct 31 18:28:41 2006
@@ -0,0 +1,115 @@
+#/usr/bin/perl -w
+#
+#
+my $version = "0.1";
+$0 =~ s#.*/##;
+my $path = $&; # sneaky way to get path back
+
+my $POSTFIX_SRC = shift || die <<"EOF";
+Usage:
+  $0 /path/to/postfix/source
+
+EOF
+
+my $header  = "$POSTFIX_SRC/src/global/cleanup_user.h";
+my $src     = "$POSTFIX_SRC/src/global/cleanup_strerror.c";
+my $pf_vers = "$POSTFIX_SRC/src/global/mail_version.h";
+my $postfix_version = "";
+
+open VERS, $pf_vers
+  or die "Could not open $pf_vers: $!\n";
+while (<VERS>) {
+    next unless /^\s*#\s*define\s+MAIL_VERSION_NUMBER\s+"(.+)"\s*$/;
+    $postfix_version = $1;
+    last;
+}
+close VERS;
+$postfix_version =~ s/^(\d+\.\d+).*/$1/;
+if ($postfix_version < 2.3) {
+    die "Need at least postfix v2.3";
+}
+my $start = <<'_END';
+#
+# Qpsmtpd::Postfix::Constants
+#
+# This is a generated file, do not edit
+#
+_END
+$start .= "# created by $0 v$version @ ".scalar(gmtime)."\n"
+         ."# postfix version $postfix_version\n"
+         ."#\n";
+$start .= <<'_END';
+package Qpsmtpd::Postfix::Constants;
+
+use Qpsmtpd::Constants;
+
+require Exporter;
+
+use vars qw(@ISA @EXPORT %cleanup_soft %cleanup_hard $postfix_version);
+use strict;
+
+@ISA = qw(Exporter);
+_END
+
+my @export = qw(%cleanup_soft %cleanup_hard $postfix_version);
+my @out = ();
+
+open HEAD, $header
+  or die "Could not open $header: $!\n";
+
+while (<HEAD>) {
+    while (s/\\\n$//) {
+        $_ .= <HEAD>;
+    }
+    chomp;
+    if (/^\s*#define\s/) {
+        s/^\s*#define\s*//;
+        next if /^_/;
+        s#(/\*.*\*/)##;
+        my $comment = $1 || "";
+        my @words = split ' ', $_;
+        my $const = shift @words;
+        if ($const eq "CLEANUP_STAT_OK") {
+            push @out, "";
+        }
+        push @export, $const;
+        push @out, "use constant $const => ". join(" ", @words). "; " 
+               .($comment ? "# $comment ": "");
+    }
+}
+close HEAD;
+
+open SRC, $src
+  or die "Could not open $src: $!\n";
+my $data;
+{ 
+  local $/ = undef;
+  $data = <SRC>;
+}
+close SRC;
+$data =~ s/.*cleanup_stat_map\[\]\s*=\s*{\s*\n//s;
+$data =~ s/};.*$//s;
+my @array = split "\n", $data;
+my (@denysoft,@denyhard);
+foreach (@array) {
+    chomp;
+    s/,/ => /;
+    s/"(\d\.\d\.\d)",\s+"(.*)",/"$2 (#$1)",/;
+    s!(/\*.*\*/)!# $1!;
+    s/4\d\d,\s// && push @denysoft, $_;
+    s/5\d\d,\s// && push @denyhard, $_;
+}
+
+open my $CONSTANTS, '>', "$path/Constants.pm";
+
+print ${CONSTANTS} $start, '@EXPORT = qw(', "\n";
+while (@export) {
+    print ${CONSTANTS} "\t", shift @export, "\n";
+}
+print ${CONSTANTS} ");\n\n", 
+       "\$postfix_version = \"$postfix_version\";\n",
+       join("\n", @out),"\n\n";
+print ${CONSTANTS} "\%cleanup_soft = (\n", join("\n", @denysoft), "\n);\n\n";
+print ${CONSTANTS} "\%cleanup_hard = (\n", join("\n", @denyhard), "\n);\n\n1;\n";
+
+close $CONSTANTS;