More removal of $Id$ tags
[citadel.git] / citadel / modules / clamav / serv_virus.c
index 31086072015039335297be1bd3c1786f13cb5dea..e31638aee42a5935d4f67b2b754537eae6afe9af 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * This module allows Citadel to use clamd to filter incoming messages
  * arriving via SMTP.  For more information on clamd, visit
  * http://clamav.net (the ClamAV project is not in any way
@@ -58,7 +56,6 @@
 #include "config.h"
 #include "control.h"
 #include "user_ops.h"
-#include "policy.h"
 #include "database.h"
 #include "msgbase.h"
 #include "internet_addressing.h"
@@ -83,8 +80,8 @@ int clamd(struct CtdlMessage *msg) {
         char portbuf[SIZ];
        int is_virus = 0;
        int clamhost;
-       char *msgtext;
-       size_t msglen;
+       StrBuf *msgtext;
+       CitContext *CCC;
 
        /* Don't care if you're logged in.  You can still spread viruses.
         */
@@ -103,10 +100,10 @@ int clamd(struct CtdlMessage *msg) {
                 extract_token(hostbuf, buf, 0, ':', sizeof hostbuf);
                 if (extract_token(portbuf, buf, 1, ':', sizeof portbuf)==-1)
                   /* Didn't specify a port so we'll try the psuedo-standard 3310 */
-                  sock = sock_connect(hostbuf, CLAMD_PORT, "tcp");
+                  sock = sock_connect(hostbuf, CLAMD_PORT);
                 else
                   /* Port specified lets try connecting to it! */
-                  sock = sock_connect(hostbuf, portbuf, "tcp");
+                  sock = sock_connect(hostbuf, portbuf);
 
                 if (sock >= 0) CtdlLogPrintf(CTDL_DEBUG, "Connected!\n");
         }
@@ -117,14 +114,18 @@ int clamd(struct CtdlMessage *msg) {
                 */
                return(0);
        }
+       CCC=CC;
+       CCC->sReadBuf = NewStrBuf();
+       CCC->sMigrateBuf = NewStrBuf();
+       CCC->sPos = NULL;
 
        /* Command */
        CtdlLogPrintf(CTDL_DEBUG, "Transmitting STREAM command\n");
        sprintf(buf, "STREAM\r\n");
-       sock_write(sock, buf, strlen(buf));
+       sock_write(&sock, buf, strlen(buf));
 
        CtdlLogPrintf(CTDL_DEBUG, "Waiting for PORT number\n");
-        if (sock_getln(sock, buf, sizeof buf) < 0) {
+        if (sock_getln(&sock, buf, sizeof buf) < 0) {
                 goto bail;
         }
 
@@ -137,12 +138,14 @@ int clamd(struct CtdlMessage *msg) {
        extract_token(portbuf, buf, 1, ' ', sizeof portbuf);
 
        /* Attempt to establish connection to STREAM socket */
-        streamsock = sock_connect(hostbuf, portbuf, "tcp");
+        streamsock = sock_connect(hostbuf, portbuf);
 
        if (streamsock < 0) {
                /* If the service isn't running, just pass the mail
                 * through.  Potentially throwing away mails isn't good.
                 */
+               FreeStrBuf(&CCC->sReadBuf);
+               FreeStrBuf(&CCC->sMigrateBuf);
                return(0);
         }
        else {
@@ -152,27 +155,23 @@ int clamd(struct CtdlMessage *msg) {
 
 
        /* Message */
-       CC->redirect_buffer = malloc(SIZ);
-       CC->redirect_len = 0;
-       CC->redirect_alloc = SIZ;
+       CC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
        CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ALL, 0, 1, 0);
        msgtext = CC->redirect_buffer;
-       msglen = CC->redirect_len;
        CC->redirect_buffer = NULL;
-       CC->redirect_len = 0;
-       CC->redirect_alloc = 0;
 
-       sock_write(streamsock, msgtext, msglen);
-       free(msgtext);
+       sock_write(&streamsock, SKEY(msgtext));
+       FreeStrBuf(&msgtext);
 
        /* Close the streamsocket connection; this tells clamd
         * that we're done.
         */
-       close(streamsock);
+       if (streamsock != -1)
+               close(streamsock);
        
        /* Response */
        CtdlLogPrintf(CTDL_DEBUG, "Awaiting response\n");
-        if (sock_getln(sock, buf, sizeof buf) < 0) {
+        if (sock_getln(&sock, buf, sizeof buf) < 0) {
                 goto bail;
         }
         CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf);
@@ -188,6 +187,8 @@ int clamd(struct CtdlMessage *msg) {
        }
 
 bail:  close(sock);
+       FreeStrBuf(&CCC->sReadBuf);
+       FreeStrBuf(&CCC->sMigrateBuf);
        return(is_virus);
 }
 
@@ -201,5 +202,5 @@ CTDL_MODULE_INIT(virus)
        }
        
        /* return our Subversion id for the Log */
-        return "$Id$";
+        return "virus";
 }