httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From soc-r...@apache.org
Subject svn commit: r289981 - /httpd/mod_smtpd/trunk/modules/queue/mod_smtpd_queue_postfix/mod_smtpd_queue_postfix.c
Date Sun, 18 Sep 2005 21:22:07 GMT
Author: soc-rian
Date: Sun Sep 18 14:22:05 2005
New Revision: 289981

URL: http://svn.apache.org/viewcvs?rev=289981&view=rev
Log:
removed socket global, so now it's thread-safe

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=289981&r1=289980&r2=289981&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:22:05 2005
@@ -31,17 +31,15 @@
     REC_TYPE_END  = 'E',    /* terminator, required */
 } smtpd_postfix_printrec_t;
 
-static int cleanup_socket;
-
 #define POSTFIX_CLEANUP_PATH "/var/spool/postfix/public/cleanup"
-static apr_status_t open_cleanup()
+static int open_cleanup()
 {
     struct sockaddr_un cleanup_sockaddr;
     int fd, rv, servlen;
     
     rv = socket(AF_UNIX, SOCK_STREAM, 0);
     if (rv < 0)
-        return APR_ENOSOCKET;
+        return rv;
  
     fd = rv;
 
@@ -54,25 +52,25 @@
     rv = connect(fd, (struct sockaddr *) &cleanup_sockaddr,
                  cleanup_sockaddr.sun_len);
     if (rv < 0)
-        return APR_ENOSOCKET;
+        return rv;
 
-    cleanup_socket = fd;
-    return APR_SUCCESS;
+    return fd;
 }
 
-static void close_cleanup()
+static void close_cleanup(int fd)
 {
-    close(cleanup_socket);
+    close(fd);
 }
 
-static void print_rec(smtpd_postfix_printrec_t type, void *data, int len)
+static void print_rec(int fd, smtpd_postfix_printrec_t type,
+                      void *data, int len)
 {
     char stack_buf[1024];
     int i;
     
     stack_buf[0] = type;
     /* send message type */
-    write(cleanup_socket, stack_buf, 1);
+    write(fd, stack_buf, 1);
 
     /* data len is a little-endian base 128 number
      * where each byte except the last has the high bit set
@@ -81,16 +79,13 @@
         stack_buf[i] = (len & 0x7F) | 0x80;
     }
     stack_buf[i++] = len;
-    write(cleanup_socket, stack_buf, i);
+    write(fd, stack_buf, i);
     
     /* write data */
-    write(cleanup_socket, data, len);
+    write(fd, data, len);
 }
 
-/* XXX: lines are limited to 990 chars, but
- * we should only print 72 char lines at a time, recommended by RFC 2821
- */
-static void print_msg_line(char *line)
+static void print_msg_line(int fd, char *line)
 {
     char *newline_loc = strchr(line, '\n');
     
@@ -98,26 +93,26 @@
         if (newline_loc[-1] == '\r')
             newline_loc--;
 
-        print_rec(REC_TYPE_NORM, line, newline_loc - line);
+        print_rec(fd, REC_TYPE_NORM, line, newline_loc - line);
     } else {
-        print_rec(REC_TYPE_NORM, line, strlen(line));
+        print_rec(fd, REC_TYPE_NORM, line, strlen(line));
     }
 }
 
-static void print_rec_time(apr_time_t record)
+static void print_rec_time(int fd, apr_time_t record)
 {
     char stack_buf[1024];
     int num_printed = apr_snprintf(stack_buf, 1024, "%" APR_TIME_T_FMT,
                                    apr_time_sec(record));
-    print_rec(REC_TYPE_TIME, stack_buf, num_printed);
+    print_rec(fd, REC_TYPE_TIME, stack_buf, num_printed);
 }
 
-static int get_attr_el(char *buf, int len)
+static int get_attr_el(int fd, char *buf, int len)
 {
     int i;
 
     for (i = 0; i < len-1; i++) {
-        read(cleanup_socket, buf + i, 1);
+        read(fd, buf + i, 1);
         if (buf[i] == '\0') 
             break;
     }
@@ -125,31 +120,31 @@
     return i;
 }
 
-static void get_attr(apr_hash_t *kv, apr_pool_t *p)
+static void get_attr(int fd, apr_hash_t *kv, apr_pool_t *p)
 {
     char stack_buf[1024];
     char *key;
     char *val;
 
     while(1) {
-        if (!get_attr_el(stack_buf, 1024))
+        if (!get_attr_el(fd, stack_buf, 1024))
             break;
 
         key = apr_pstrdup(p, stack_buf);
 
-        get_attr_el(stack_buf, 1024);
+        get_attr_el(fd, stack_buf, 1024);
         val = apr_pstrdup(p, stack_buf);
 
         apr_hash_set(kv, key, APR_HASH_KEY_STRING, val);
     }
 }
 
-static int write_out_headers(void *not_important, const char *key,
+static int write_out_headers(void *fd, const char *key,
                              const char *val)
 {
     char stack_buf[1024];
     sprintf(stack_buf, "%s: %s", key, val);
-    print_msg_line(stack_buf);
+    print_msg_line((int)fd, stack_buf);
 }
 
 smtpd_retcode postfix_queue(smtpd_conn_rec *scr, smtpd_return_data *out)
@@ -162,13 +157,14 @@
     const char *msg_id;
     int status_int;
     int i;
+    int cleanup_socket;
 
-    if (open_cleanup() != APR_SUCCESS) {
+    cleanup_socket = open_cleanup();
+    if (cleanup_socket < 0)
         return SMTPD_DECLINED;
-    }
 
     /* get attributes */
-    get_attr(first_attr, str->p);
+    get_attr(cleanup_socket, first_attr, str->p);
     qid = apr_hash_get(first_attr, "queue_id", APR_HASH_KEY_STRING);
 
     /* log queue id?
@@ -181,12 +177,13 @@
     write(cleanup_socket, "", sizeof(""));
 
     /* send time */
-    print_rec_time(apr_time_now());
+    print_rec_time(cleanup_socket, apr_time_now());
     
     /* send sender and receiver */
-    print_rec(REC_TYPE_FROM, str->mail_from, strlen(str->mail_from));
+    print_rec(cleanup_socket, REC_TYPE_FROM, str->mail_from,
+              strlen(str->mail_from));
     for (i = 0; i < str->rcpt_to->nelts; ++i) {
-        print_rec(REC_TYPE_RCPT,
+        print_rec(cleanup_socket, REC_TYPE_RCPT,
                   ((char **)str->rcpt_to->elts)[i],
                   strlen(((char **)str->rcpt_to->elts)[i]));
     }
@@ -195,25 +192,26 @@
      * cleanup is supposed to understand that.
      * see src/pickup/pickup.c 
      */
-    print_rec(REC_TYPE_MESG, "", 0);
+    print_rec(cleanup_socket, REC_TYPE_MESG, "", 0);
     
-    apr_table_do(write_out_headers, NULL, str->headers, NULL);
+    apr_table_do(write_out_headers, (void *) cleanup_socket,
+                 str->headers, NULL);
 
     smtpd_body_resetpos(str, SMTPD_BODY);
     while (smtpd_body_getline(str, stack_buf, 1024) == APR_SUCCESS) {
-        print_msg_line(stack_buf);
+        print_msg_line(cleanup_socket, stack_buf);
     }
 
     /* finish it. */
-    print_rec(REC_TYPE_XTRA, "", 0);
-    print_rec(REC_TYPE_END, "", 0);
-    get_attr(last_attr, str->p);
+    print_rec(cleanup_socket, REC_TYPE_XTRA, "", 0);
+    print_rec(cleanup_socket, REC_TYPE_END, "", 0);
+    get_attr(cleanup_socket, last_attr, str->p);
     
     status = apr_hash_get(last_attr, "status", APR_HASH_KEY_STRING);
     reason = apr_hash_get(last_attr, "reason", APR_HASH_KEY_STRING);
     status_int = atoi(status);
 
-    close_cleanup();
+    close_cleanup(cleanup_socket);
 
     out->msgs = apr_array_make(out->p, 1, sizeof(char *));
 



Mime
View raw message