* serv_spam.c: use redirect_buffer instead of redirect_sock
authorArt Cancro <ajc@citadel.org>
Wed, 2 Mar 2005 03:01:18 +0000 (03:01 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 2 Mar 2005 03:01:18 +0000 (03:01 +0000)
* Removed redirect_sock from the API.  redirect_fp is next!

citadel/ChangeLog
citadel/imap_fetch.c
citadel/serv_network.c
citadel/serv_smtp.c
citadel/serv_spam.c
citadel/server.h
citadel/sysdep.c
citadel/sysdep_decls.h

index 381942952fd1fb2529da201189ca103f3ab1eccc..c0b3881f1d790740c3fa8a77316a34ea72c94b2c 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 641.13  2005/03/02 03:01:18  ajc
+ * serv_spam.c: use redirect_buffer instead of redirect_sock
+ * Removed redirect_sock from the API.  redirect_fp is next!
+
  Revision 641.12  2005/03/02 02:42:06  ajc
  * Finished moving the POP3 server to the new redirect_buffer semantics
 
@@ -6472,4 +6476,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
-
index 4abc2d36156d8e8b6a34b383963e5fff97b4e6d5..a2e557bb721a769eb7dfbdd405f652aed64fc2a3 100644 (file)
@@ -156,9 +156,9 @@ void imap_fetch_rfc822(long msgnum, char *whichfmt) {
                 * Load the message into a temp file for translation
                 * and measurement
                 */
-               CtdlRedirectOutput(tmp, -1);
+               CtdlRedirectOutput(tmp);
                CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1);
-               CtdlRedirectOutput(NULL, -1);
+               CtdlRedirectOutput(NULL);
 
                IMAP->cached_fetch = tmp;
                IMAP->cached_msgnum = msgnum;
@@ -585,20 +585,20 @@ void imap_fetch_body(long msgnum, char *item, int is_peek) {
                tmp = IMAP->cached_body;
        }
        else if ( (!strcmp(section, "1")) && (msg->cm_format_type != 4) ) {
-               CtdlRedirectOutput(tmp, -1);
+               CtdlRedirectOutput(tmp);
                CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822,
                                                HEADERS_NONE, 0, 1);
-               CtdlRedirectOutput(NULL, -1);
+               CtdlRedirectOutput(NULL);
        }
 
        else if (!strcmp(section, "")) {
-               CtdlRedirectOutput(tmp, -1);
+               CtdlRedirectOutput(tmp);
                /* lprintf(CTDL_DEBUG, "calling CtdlOutputPreLoadedMsg()\n");
                lprintf(CTDL_DEBUG, "msg %s null\n", ((msg == NULL) ? "is" : "is not") );
                lprintf(CTDL_DEBUG, "msgnum is %ld\n", msgnum); */
                CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822,
                                                HEADERS_ALL, 0, 1);
-               CtdlRedirectOutput(NULL, -1);
+               CtdlRedirectOutput(NULL);
        }
 
        /*
@@ -606,13 +606,13 @@ void imap_fetch_body(long msgnum, char *item, int is_peek) {
         * fields, strip it down.
         */
        else if (!strncasecmp(section, "HEADER", 6)) {
-               CtdlRedirectOutput(tmp, -1);
+               CtdlRedirectOutput(tmp);
                /* lprintf(CTDL_DEBUG, "calling CtdlOutputPreLoadedMsg()\n");
                lprintf(CTDL_DEBUG, "msg %s null\n", ((msg == NULL) ? "is" : "is not") );
                lprintf(CTDL_DEBUG, "msgnum is %ld\n", msgnum); */
                CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822,
                                                HEADERS_ONLY, 0, 1);
-               CtdlRedirectOutput(NULL, -1);
+               CtdlRedirectOutput(NULL);
                imap_strip_headers(tmp, section);
        }
 
@@ -620,13 +620,13 @@ void imap_fetch_body(long msgnum, char *item, int is_peek) {
         * Strip it down if the client asked for everything _except_ headers.
         */
        else if (!strncasecmp(section, "TEXT", 4)) {
-               CtdlRedirectOutput(tmp, -1);
+               CtdlRedirectOutput(tmp);
                /* lprintf(CTDL_DEBUG, "calling CtdlOutputPreLoadedMsg()\n");
                lprintf(CTDL_DEBUG, "msg %s null\n", ((msg == NULL) ? "is" : "is not") );
                lprintf(CTDL_DEBUG, "msgnum is %ld\n", msgnum); */
                CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822,
                                                HEADERS_NONE, 0, 1);
-               CtdlRedirectOutput(NULL, -1);
+               CtdlRedirectOutput(NULL);
        }
 
        /*
@@ -853,9 +853,9 @@ void imap_fetch_bodystructure (long msgnum, char *item,
                 */
                tmp = tmpfile();
                if (tmp == NULL) return;
-               CtdlRedirectOutput(tmp, -1);
+               CtdlRedirectOutput(tmp);
                CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, 0, 0, 1);
-               CtdlRedirectOutput(NULL, -1);
+               CtdlRedirectOutput(NULL);
 
                rewind(tmp);
                while (fgets(buf, sizeof buf, tmp) != NULL) {
index 66fe1c8642219608c2923f93a86d84b8e78f06e9..794c8449f9c06e4effeff5d5b35e5d03058a9951 100644 (file)
@@ -501,9 +501,9 @@ void network_spool_msg(long msgnum, void *userdata) {
                fprintf(sc->digestfp,   " -----------------------------------"
                                        "------------------------------------"
                                        "-------\n");
-               CtdlRedirectOutput(sc->digestfp, -1);
+               CtdlRedirectOutput(sc->digestfp);
                CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 0);
-               CtdlRedirectOutput(NULL, -1);
+               CtdlRedirectOutput(NULL);
                sc->num_msgs_spooled += 1;
        }
 
index 7c3718676b2dbf4690027507b51e8eae9b29df06..480727511ecd56d0fff3ac542003573a8f1aec54 100644 (file)
@@ -922,9 +922,9 @@ void smtp_try(const char *key, const char *addr, int *status,
                return;
        }
        else {
-               CtdlRedirectOutput(msg_fp, -1);
+               CtdlRedirectOutput(msg_fp);
                CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1);
-               CtdlRedirectOutput(NULL, -1);
+               CtdlRedirectOutput(NULL);
                fseek(msg_fp, 0L, SEEK_END);
                msg_size = ftell(msg_fp);
        }
index 599869afd3e5ec1bc8d645533067082e029e1e9f..ea73e70f3ba3091e83ebcc938183ce1109e9ea9a 100644 (file)
@@ -105,6 +105,8 @@ int spam_assassin(struct CtdlMessage *msg) {
        char buf[SIZ];
        int is_spam = 0;
        int sa;
+       char *msgtext;
+       size_t msglen;
 
        /* For users who have authenticated to this server we never want to
         * apply spam filtering, because presumably they're trustworthy.
@@ -136,9 +138,19 @@ int spam_assassin(struct CtdlMessage *msg) {
        sock_write(sock, buf, strlen(buf));
 
        /* Message */
-       CtdlRedirectOutput(NULL, sock);
+       CC->redirect_buffer = malloc(SIZ);
+       CC->redirect_len = 0;
+       CC->redirect_alloc = SIZ;
        CtdlOutputPreLoadedMsg(msg, 0L, MT_RFC822, HEADERS_ALL, 0, 1);
-       CtdlRedirectOutput(NULL, -1);
+       CC->redirect_buffer[CC->redirect_len] = 0;
+       msgtext = CC->redirect_buffer;
+       msglen = CC->redirect_len;
+       CC->redirect_buffer = NULL;
+       CC->redirect_len = 0;
+       CC->redirect_alloc = 0;
+
+       sock_write(sock, msgtext, msglen);
+       free(msgtext);
 
        /* Close one end of the socket connection; this tells SpamAssassin
         * that we're done.
index 6de5716d740ed14ea3209b3b46be3e85803d5854..6ecfa2983d7ea5d5a8e07a7ad80c6bc0569f9b0b 100644 (file)
@@ -122,8 +122,7 @@ struct CitContext {
        char cs_nonce[NONCE_SIZE];      /* The nonce for this session's next auth transaction */
 
        /* Redirect this session's output to somewhere else? */
-       FILE *redirect_fp;
-       int redirect_sock;
+       FILE *redirect_fp;              /* a file instead (will go away) */
        char *redirect_buffer;          /* the buffer */
        size_t redirect_len;            /* length of data in buffer */
        size_t redirect_alloc;          /* length of allocated buffer */
index c8137cda397a0349b38dc7049179dc42e9cef02d..7484552fb97e54fefba34befd7f56636be92c8e7 100644 (file)
@@ -542,7 +542,6 @@ void client_write(char *buf, int nbytes)
 {
        int bytes_written = 0;
        int retval;
-       int sock;
 #ifndef HAVE_TCP_BUFFERING
        int old_buffer_len = 0;
 #endif
@@ -563,13 +562,6 @@ void client_write(char *buf, int nbytes)
                return;
        }
 
-       if (CC->redirect_sock > 0) {
-               sock = CC->redirect_sock;       /* and continue below... */
-       }
-       else {
-               sock = CC->client_socket;
-       }
-
 #ifndef HAVE_TCP_BUFFERING
        /* If we're buffering for later, do that now. */
        if (CC->buffering) {
@@ -591,12 +583,12 @@ void client_write(char *buf, int nbytes)
 #endif
 
        while (bytes_written < nbytes) {
-               retval = write(sock, &buf[bytes_written],
+               retval = write(CC->client_socket, &buf[bytes_written],
                        nbytes - bytes_written);
                if (retval < 1) {
                        lprintf(CTDL_ERR, "client_write() failed: %s\n",
                                strerror(errno));
-                       if (sock == CC->client_socket) CC->kill_me = 1;
+                       CC->kill_me = 1;
                        return;
                }
                bytes_written = bytes_written + retval;
@@ -903,18 +895,14 @@ void dead_session_purge(int force) {
 
 
 /*
- * Redirect a session's output to a file or socket.
- * This function may be called with a file handle *or* a socket (but not
- * both).  Call with neither to return output to its normal client socket.
+ * Redirect a session's output to a file.
+ * This function may be called with a file handle.
+ * Call with NULL to return output to its normal client socket.
  */
-void CtdlRedirectOutput(FILE *fp, int sock) {
-
+void CtdlRedirectOutput(FILE *fp)
+{
        if (fp != NULL) CC->redirect_fp = fp;
        else CC->redirect_fp = NULL;
-
-       if (sock > 0) CC->redirect_sock = sock;
-       else CC->redirect_sock = (-1);
-
 }
 
 
index 191be0f5ef1346b63e49261df78880e4a748e710..f2b6fe50b29b45870366a8f6510c831f3d3df388 100644 (file)
@@ -64,7 +64,7 @@ void cmd_nset (char *cmdbuf);
 int convert_login (char *NameToConvert);
 void *worker_thread (void *arg);
 void become_session(struct CitContext *which_con);
-void CtdlRedirectOutput(FILE *fp, int sock);
+void CtdlRedirectOutput(FILE *fp);
 void InitializeMasterCC(void);
 void init_master_fdset(void);
 void create_worker(void);