You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by so...@apache.org on 2005/09/18 23:58:12 UTC

svn commit: r289983 - /httpd/mod_smtpd/trunk/modules/queue/mod_smtpd_queue_postfix/mod_smtpd_queue_postfix.c

Author: soc-rian
Date: Sun Sep 18 14:58:10 2005
New Revision: 289983

URL: http://svn.apache.org/viewcvs?rev=289983&view=rev
Log:
Reads configuration directives to enable

Modified:
    httpd/mod_smtpd/trunk/modules/queue/mod_smtpd_queue_postfix/mod_smtpd_queue_postfix.c

Modified: httpd/mod_smtpd/trunk/modules/queue/mod_smtpd_queue_postfix/mod_smtpd_queue_postfix.c
URL: http://svn.apache.org/viewcvs/httpd/mod_smtpd/trunk/modules/queue/mod_smtpd_queue_postfix/mod_smtpd_queue_postfix.c?rev=289983&r1=289982&r2=289983&view=diff
==============================================================================
--- httpd/mod_smtpd/trunk/modules/queue/mod_smtpd_queue_postfix/mod_smtpd_queue_postfix.c (original)
+++ httpd/mod_smtpd/trunk/modules/queue/mod_smtpd_queue_postfix/mod_smtpd_queue_postfix.c Sun Sep 18 14:58:10 2005
@@ -4,10 +4,13 @@
 
 #include "httpd.h"
 #include "http_config.h"
+#include "http_log.h"
 #include "apr_strings.h"
 
 #include "mod_smtpd.h"
 
+module AP_MODULE_DECLARE_DATA smtpd_queue_postfix_module;
+
 typedef enum {
     REC_TYPE_SIZE = 'C',    /* first record, created by cleanup */
     REC_TYPE_TIME = 'T',    /* time stamp, required */
@@ -31,8 +34,12 @@
     REC_TYPE_END  = 'E',    /* terminator, required */
 } smtpd_postfix_printrec_t;
 
-#define POSTFIX_CLEANUP_PATH "/var/spool/postfix/public/cleanup"
-static int open_cleanup()
+typedef struct {
+    const char *cleanup_path;
+    int on; 
+} smtpd_queue_postfix_config;
+
+static int open_cleanup(const char *cleanup_path)
 {
     struct sockaddr_un cleanup_sockaddr;
     int fd, rv, servlen;
@@ -45,9 +52,10 @@
 
     memset(&cleanup_sockaddr, 0, sizeof(cleanup_sockaddr));
     cleanup_sockaddr.sun_family = AF_UNIX;
-    strcpy(cleanup_sockaddr.sun_path, POSTFIX_CLEANUP_PATH);
+    apr_cpystrn(cleanup_sockaddr.sun_path, cleanup_path,
+                sizeof(cleanup_sockaddr.sun_path));
     cleanup_sockaddr.sun_len = sizeof(cleanup_sockaddr) +
-      - sizeof(cleanup_sockaddr.sun_path) + sizeof(POSTFIX_CLEANUP_PATH);
+      - sizeof(cleanup_sockaddr.sun_path) + strlen(cleanup_path) + 1;
     
     rv = connect(fd, (struct sockaddr *) &cleanup_sockaddr,
                  cleanup_sockaddr.sun_len);
@@ -158,11 +166,22 @@
     int status_int;
     int i;
     int cleanup_socket;
+    smtpd_queue_postfix_config *cfg =
+      ap_get_module_config(scr->s->module_config,
+                           &smtpd_queue_postfix_module);
 
-    cleanup_socket = open_cleanup();
-    if (cleanup_socket < 0)
+    if (!cfg->on)
         return SMTPD_DECLINED;
 
+    cleanup_socket = open_cleanup(cfg->cleanup_path);
+    if (cleanup_socket < 0) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, 0, scr->s,
+                     "mod_smtpd_queue_postfix: "
+                     "Could not make unix domain connection to: %s",
+                     cfg->cleanup_path);
+        return SMTPD_DECLINED;
+    }
+
     /* get attributes */
     get_attr(cleanup_socket, first_attr, str->p);
     qid = apr_hash_get(first_attr, "queue_id", APR_HASH_KEY_STRING);
@@ -236,12 +255,58 @@
     APR_OPTIONAL_HOOK(smtpd, queue, postfix_queue, NULL, NULL, APR_HOOK_MIDDLE);
 }
 
+static void *smtpd_queue_postfix_create_server_config(apr_pool_t *p,
+                                                   server_rec *s)
+{
+  smtpd_queue_postfix_config *cfg = 
+    apr_pcalloc(p, sizeof(smtpd_queue_postfix_config));
+  cfg->on = 0;
+  cfg->cleanup_path = "/var/spool/postfix/public/cleanup";
+  return cfg;
+}
+
+static const char *enable_queue_postfix(cmd_parms *cmd,
+                                        void *baton,
+                                        int arg)
+{
+    smtpd_queue_postfix_config *cfg = ap_get_module_config(
+        cmd->server->module_config, &smtpd_queue_postfix_module
+    );
+
+    cfg->on = arg;
+
+    return NULL;
+}
+
+static const char *set_cleanup_path(cmd_parms *cmd,
+                                    void *baton,
+                                    const char *arg)
+{
+    smtpd_queue_postfix_config *cfg =
+      ap_get_module_config(cmd->server->module_config,
+                           &smtpd_queue_postfix_module);
+    cfg->cleanup_path = arg;
+
+    return NULL;
+}
+
+static const command_rec smtpd_queue_postfix_cmds[] = {
+    AP_INIT_FLAG("SmtpQueuePostfix", enable_queue_postfix, NULL, RSRC_CONF,
+                 "Enable queuing to a local postfix server.  Default: Off"),
+
+    AP_INIT_TAKE1("SmtpQueuePostfixCleanupPath", set_cleanup_path, NULL, RSRC_CONF,
+                  "Set the path of the unix cleanup socket. "
+                  "Default: /var/spool/postfix/public/cleanup"),
+
+    { NULL }
+};
+
 module AP_MODULE_DECLARE_DATA smtpd_queue_postfix_module = {
   STANDARD20_MODULE_STUFF,
   NULL,                       /* create per-directory config structure */
   NULL,                       /* merge per-directory config structures */
-  NULL,
+  smtpd_queue_postfix_create_server_config,
   NULL,                       /* merge per-server config structures */
-  NULL,
+  smtpd_queue_postfix_cmds,
   register_hooks              /* register hooks */
 };