spamassassin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j.@apache.org
Subject svn commit: rev 6377 - incubator/spamassassin/trunk/spamc
Date Sat, 31 Jan 2004 04:18:09 GMT
Author: jm
Date: Fri Jan 30 20:18:08 2004
New Revision: 6377

Modified:
   incubator/spamassassin/trunk/spamc/libspamc.c
   incubator/spamassassin/trunk/spamc/libspamc.h
   incubator/spamassassin/trunk/spamc/qmail-spamc.c
   incubator/spamassassin/trunk/spamc/spamc.c
   incubator/spamassassin/trunk/spamc/utils.c
   incubator/spamassassin/trunk/spamc/utils.h
Log:
ran indent -i4 -npsl -di0 -br -nce -d0 -cli0 -npcs -nfc1 (the Apache C style, http://www.apache.org/dev/styleguide.html) over the .c and .h files in spamc

Modified: incubator/spamassassin/trunk/spamc/libspamc.c
==============================================================================
--- incubator/spamassassin/trunk/spamc/libspamc.c	(original)
+++ incubator/spamassassin/trunk/spamc/libspamc.c	Fri Jan 30 20:18:08 2004
@@ -69,13 +69,13 @@
 /* KAM 12-4-01 */
 /* SJF 2003/04/25 - now test for macros directly */
 #ifndef SHUT_RD
-#  define SHUT_RD 0	/* no more receptions */
+#  define SHUT_RD 0		/* no more receptions */
 #endif
 #ifndef SHUT_WR
-#  define SHUT_WR 1	/* no more transmissions */
+#  define SHUT_WR 1		/* no more transmissions */
 #endif
 #ifndef SHUT_RDWR
-#  define SHUT_RDWR 2	/* no more receptions or transmissions */
+#  define SHUT_RDWR 2		/* no more receptions or transmissions */
 #endif
 
 #ifndef HAVE_H_ERRNO
@@ -95,13 +95,13 @@
 
 #ifndef HAVE_EX__MAX
 /* jm: very conservative figure, should be well out of range on almost all NIXes */
-#define EX__MAX 200 
+#define EX__MAX 200
 #endif
 
 #undef DO_CONNECT_DEBUG_SYSLOGS
 /* or #define DO_CONNECT_DEBUG_SYSLOGS 1 */
 
-static const int ESC_PASSTHROUGHRAW = EX__MAX+666;
+static const int ESC_PASSTHROUGHRAW = EX__MAX + 666;
 
 /* set EXPANSION_ALLOWANCE to something more than might be
    added to a message in X-headers and the report template */
@@ -114,14 +114,15 @@
  */
 
 /* Set the protocol version that this spamc speaks */
-static const char *PROTOCOL_VERSION="SPAMC/1.3";
+static const char *PROTOCOL_VERSION = "SPAMC/1.3";
 
 /* "private" part of struct message.
  * we use this instead of the struct message directly, so that we
  * can add new members without affecting the ABI.
  */
-struct libspamc_private_message {
-  int flags;	/* copied from "flags" arg to message_read() */
+struct libspamc_private_message
+{
+    int flags;			/* copied from "flags" arg to message_read() */
 };
 
 int libspamc_timeout = 0;
@@ -135,32 +136,30 @@
  *
  *	This should ONLY be called when there is an error.
  */
-static int
-translate_connect_errno(int err)
+static int translate_connect_errno(int err)
 {
-	switch (err)
-	{
-	  case EBADF:
-	  case EFAULT:
-	  case ENOTSOCK:
-	  case EISCONN:
-	  case EADDRINUSE:
-	  case EINPROGRESS:
-	  case EALREADY:
-	  case EAFNOSUPPORT:
-		return EX_SOFTWARE;
+    switch (err) {
+    case EBADF:
+    case EFAULT:
+    case ENOTSOCK:
+    case EISCONN:
+    case EADDRINUSE:
+    case EINPROGRESS:
+    case EALREADY:
+    case EAFNOSUPPORT:
+	return EX_SOFTWARE;
+
+    case ECONNREFUSED:
+    case ETIMEDOUT:
+    case ENETUNREACH:
+	return EX_UNAVAILABLE;
 
-	  case ECONNREFUSED:
-	  case ETIMEDOUT:
-	  case ENETUNREACH:
-		return EX_UNAVAILABLE;
+    case EACCES:
+	return EX_NOPERM;
 
-	  case EACCES:
-		return EX_NOPERM;
-
-	  default:
-		return EX_SOFTWARE;
-	}
+    default:
+	return EX_SOFTWARE;
+    }
 }
 
 /*
@@ -175,42 +174,40 @@
  */
 static int opensocket(int type, int *psock)
 {
-const char *typename;
-int	    proto = 0;
+    const char *typename;
+    int proto = 0;
 
-	assert(psock != 0);
+    assert(psock != 0);
 
 	/*----------------------------------------------------------------
 	 * Create a few induction variables that are implied by the socket
 	 * type given by the user. The typename is strictly used for debug
 	 * reporting.
 	 */
-	if ( type == PF_UNIX )
-	{
-		typename = "PF_UNIX";
-	}
-	else
-	{
-		typename = "PF_INET";
-		proto    = IPPROTO_TCP;
-	}
+    if (type == PF_UNIX) {
+	typename = "PF_UNIX";
+    }
+    else {
+	typename = "PF_INET";
+	proto = IPPROTO_TCP;
+    }
 
 #ifdef DO_CONNECT_DEBUG_SYSLOGS
 #ifndef _WIN32
-	syslog (DEBUG_LEVEL, "dbg: create socket(%s)", typename);
+    syslog(DEBUG_LEVEL, "dbg: create socket(%s)", typename);
 #else
-	fprintf (stderr, "dbg: create socket(%s)\n", typename);
+    fprintf(stderr, "dbg: create socket(%s)\n", typename);
 #endif
 #endif
 
-	if ( (*psock = socket(type, SOCK_STREAM, proto))
+    if ((*psock = socket(type, SOCK_STREAM, proto))
 #ifndef _WIN32
-         < 0
+	< 0
 #else
-         == INVALID_SOCKET
+	== INVALID_SOCKET
 #endif
-         ) {
-	int	origerr;
+	) {
+	int origerr;
 
 		/*--------------------------------------------------------
 		 * At this point we had a failure creating the socket, and
@@ -218,32 +215,31 @@
 		 * into something the user can understand.
 		 */
 #ifndef _WIN32
-		origerr = errno;    /* take a copy before syslog() */
-		syslog (LOG_ERR, "socket(%s) to spamd failed: %m", typename);
+	origerr = errno;	/* take a copy before syslog() */
+	syslog(LOG_ERR, "socket(%s) to spamd failed: %m", typename);
 #else
-      origerr = WSAGetLastError();
-      printf ("socket(%s) to spamd failed: %d\n", typename, origerr);
+	origerr = WSAGetLastError();
+	printf("socket(%s) to spamd failed: %d\n", typename, origerr);
 #endif
 
-		switch (origerr)
-		{
-		  case EPROTONOSUPPORT:
-		  case EINVAL:
-			return EX_SOFTWARE;
-
-		  case EACCES:
-			return EX_NOPERM;
-
-		  case ENFILE:
-		  case EMFILE:
-		  case ENOBUFS:
-		  case ENOMEM:
-			return EX_OSERR;
+	switch (origerr) {
+	case EPROTONOSUPPORT:
+	case EINVAL:
+	    return EX_SOFTWARE;
 
-		  default:
-			return EX_SOFTWARE;
-		}
+	case EACCES:
+	    return EX_NOPERM;
+
+	case ENFILE:
+	case EMFILE:
+	case ENOBUFS:
+	case ENOMEM:
+	    return EX_OSERR;
+
+	default:
+	    return EX_SOFTWARE;
 	}
+    }
 
 
 	/*----------------------------------------------------------------
@@ -251,42 +247,40 @@
 	 * suggest this is probably not set
 	 */
 #ifdef USE_TCP_NODELAY
-	{
-		int one = 1;
+    {
+	int one = 1;
 
-		if ( type == PF_INET
-		 &&  setsockopt(*psock, 0, TCP_NODELAY, &one, sizeof one) != 0 )
-		{
-          int origerrno;
+	if (type == PF_INET
+	    && setsockopt(*psock, 0, TCP_NODELAY, &one, sizeof one) != 0) {
+	    int origerrno;
 #ifndef _WIN32
-          origerr = errno;
+	    origerr = errno;
 #else
-          origerrno = WSAGetLastError();
+	    origerrno = WSAGetLastError();
 #endif
-			switch(origerr)
-			{
-			  case EBADF:
-			  case ENOTSOCK:
-			  case ENOPROTOOPT:
-			  case EFAULT:
+	    switch (origerr) {
+	    case EBADF:
+	    case ENOTSOCK:
+	    case ENOPROTOOPT:
+	    case EFAULT:
 #ifndef _WIN32
-				syslog(LOG_ERR,
-				   "setsockopt(TCP_NODELAY) failed: %m");
+		syslog(LOG_ERR,
+		       "setsockopt(TCP_NODELAY) failed: %m", origerr);
 #else
-				fprintf(stderr,
-				   "setsockopt(TCP_NODELAY) failed: %d\n", origerr));
+		fprintf(stderr,
+			"setsockopt(TCP_NODELAY) failed: %d\n", origerr);
 #endif
-				closesocket (*psock);
-				return EX_SOFTWARE;
+		closesocket(*psock);
+		return EX_SOFTWARE;
 
-			  default:
-				break;            /* ignored */
-			}
-		}
+	    default:
+		break;		/* ignored */
+	    }
 	}
+    }
 #endif /* USE_TCP_NODELAY */
 
-	return EX_OK;	/* all is well */
+    return EX_OK;		/* all is well */
 }
 
 /*
@@ -297,55 +291,53 @@
  *	file descriptor in *sockptr. Return is EX_OK if we did it,
  *	and some other error code otherwise.
  */
-static int
-try_to_connect_unix (struct transport *tp, int *sockptr)
+static int try_to_connect_unix(struct transport *tp, int *sockptr)
 {
 #ifndef _WIN32
-int mysock, status, origerr;
-struct sockaddr_un addrbuf;
-int ret;
+    int mysock, status, origerr;
+    struct sockaddr_un addrbuf;
+    int ret;
 
-	assert(tp             != 0);
-	assert(sockptr        != 0);
-	assert(tp->socketpath != 0);
+    assert(tp != 0);
+    assert(sockptr != 0);
+    assert(tp->socketpath != 0);
 
 	/*----------------------------------------------------------------
 	 * If the socket itself can't be created, this is a fatal error.
 	 */
-	if ( (ret = opensocket(PF_UNIX, &mysock)) != EX_OK )
-		return ret;
+    if ((ret = opensocket(PF_UNIX, &mysock)) != EX_OK)
+	return ret;
 
-	/* set up the UNIX domain socket */
-	memset(&addrbuf, 0, sizeof addrbuf);
-	addrbuf.sun_family = AF_UNIX;
-	strncpy(addrbuf.sun_path, tp->socketpath, sizeof addrbuf.sun_path - 1);
-	addrbuf.sun_path[sizeof addrbuf.sun_path - 1] = '\0';
+    /* set up the UNIX domain socket */
+    memset(&addrbuf, 0, sizeof addrbuf);
+    addrbuf.sun_family = AF_UNIX;
+    strncpy(addrbuf.sun_path, tp->socketpath, sizeof addrbuf.sun_path - 1);
+    addrbuf.sun_path[sizeof addrbuf.sun_path - 1] = '\0';
 
 #ifdef DO_CONNECT_DEBUG_SYSLOGS
-	syslog (DEBUG_LEVEL, "dbg: connect(AF_UNIX) to spamd at %s",
-		addrbuf.sun_path);
+    syslog(DEBUG_LEVEL, "dbg: connect(AF_UNIX) to spamd at %s",
+	   addrbuf.sun_path);
 #endif
 
-	status = connect(mysock, (struct sockaddr *) &addrbuf, sizeof(addrbuf));
+    status = connect(mysock, (struct sockaddr *) &addrbuf, sizeof(addrbuf));
 
-	origerr = errno;
+    origerr = errno;
 
-	if ( status >= 0 )
-	{
+    if (status >= 0) {
 #ifdef DO_CONNECT_DEBUG_SYSLOGS
-		syslog(DEBUG_LEVEL, "dbg: connect(AF_UNIX) ok");
+	syslog(DEBUG_LEVEL, "dbg: connect(AF_UNIX) ok");
 #endif
 
-		*sockptr = mysock;
+	*sockptr = mysock;
 
-		return EX_OK;
-	}
+	return EX_OK;
+    }
 
-	syslog(LOG_ERR, "connect(AF_UNIX) to spamd %s failed: %m",
-		addrbuf.sun_path);
-	closesocket(mysock);
+    syslog(LOG_ERR, "connect(AF_UNIX) to spamd %s failed: %m",
+	   addrbuf.sun_path);
+    closesocket(mysock);
 
-	return translate_connect_errno(origerr);
+    return translate_connect_errno(origerr);
 #else
     return EX_OSERR;
 #endif
@@ -359,115 +351,103 @@
  *	list of IP addresses has already been randomized (if requested)
  *	and limited to just one if fallback has been enabled.
  */
-static int
-try_to_connect_tcp (const struct transport *tp, int *sockptr)
+static int try_to_connect_tcp(const struct transport *tp, int *sockptr)
 {
-int	numloops;
-int	origerr = 0;
-int	ret;
-
-	assert(tp        != 0);
-	assert(sockptr   != 0);
-	assert(tp->nhosts > 0);
+    int numloops;
+    int origerr = 0;
+    int ret;
+
+    assert(tp != 0);
+    assert(sockptr != 0);
+    assert(tp->nhosts > 0);
 
 #ifdef DO_CONNECT_DEBUG_SYSLOGS
-	for (numloops = 0; numloops < tp->nhosts; numloops++)
-	{
+    for (numloops = 0; numloops < tp->nhosts; numloops++) {
 #ifndef _WIN32
-		syslog(LOG_ERR,
-			"dbg: %d/%d: %s",
+	syslog(LOG_ERR, "dbg: %d/%d: %s",
 #else
-		fprintf(stderr,
-			"dbg: %d/%d: %s\n",
+	fprintf(stderr, "dbg: %d/%d: %s\n",
 #endif
-			numloops+1, tp->nhosts, inet_ntoa(tp->hosts[numloops]));
-	}
+		numloops + 1, tp->nhosts, inet_ntoa(tp->hosts[numloops]));
+    }
 #endif
 
-	for (numloops = 0; numloops < MAX_CONNECT_RETRIES; numloops++)
-	{
+    for (numloops = 0; numloops < MAX_CONNECT_RETRIES; numloops++) {
 	struct sockaddr_in addrbuf;
-	const int          hostix = numloops % tp->nhosts;
-	int                status, mysock;
-	const char	 * ipaddr;
+	const int hostix = numloops % tp->nhosts;
+	int status, mysock;
+	const char *ipaddr;
 
 		/*--------------------------------------------------------
 		 * We always start by creating the socket, as we get only
 		 * one attempt to connect() on each one. If this fails,
 		 * we're done.
 		 */
-		if ( (ret = opensocket(PF_INET, &mysock)) != EX_OK )
-			return ret;
+	if ((ret = opensocket(PF_INET, &mysock)) != EX_OK)
+	    return ret;
 
-		memset(&addrbuf, 0, sizeof(addrbuf));
+	memset(&addrbuf, 0, sizeof(addrbuf));
 
-		addrbuf.sin_family = AF_INET;
-		addrbuf.sin_port   = htons(tp->port);
-		addrbuf.sin_addr   = tp->hosts[hostix];
+	addrbuf.sin_family = AF_INET;
+	addrbuf.sin_port = htons(tp->port);
+	addrbuf.sin_addr = tp->hosts[hostix];
 
-		ipaddr = inet_ntoa(addrbuf.sin_addr);
+	ipaddr = inet_ntoa(addrbuf.sin_addr);
 
 #ifdef DO_CONNECT_DEBUG_SYSLOGS
 #ifndef _WIN32
-		syslog(DEBUG_LEVEL,
-			"dbg: connect(AF_INET) to spamd at %s (try #%d of %d)",
+	syslog(DEBUG_LEVEL,
+	       "dbg: connect(AF_INET) to spamd at %s (try #%d of %d)",
 #else
-		fprintf(stderr,
-			"dbg: connect(AF_INET) to spamd at %s (try #%d of %d\)\n",
+	fprintf(stderr,
+		"dbg: connect(AF_INET) to spamd at %s (try #%d of %d\)\n",
 #endif
-			ipaddr,
-			numloops+1,
-			MAX_CONNECT_RETRIES);
+		ipaddr, numloops + 1, MAX_CONNECT_RETRIES);
 #endif
 
-		status = connect(mysock, (struct sockaddr *)&addrbuf, sizeof(addrbuf));
+	status =
+	    connect(mysock, (struct sockaddr *) &addrbuf, sizeof(addrbuf));
 
-		if (status != 0)
-		{
+	if (status != 0) {
 #ifndef _WIN32
-          origerr = errno;
-			syslog (LOG_ERR,
-			"connect(AF_INET) to spamd at %s failed, retrying (#%d of %d): %m",
-				ipaddr, numloops+1, MAX_CONNECT_RETRIES);
+	    origerr = errno;
+	    syslog(LOG_ERR,
+		   "connect(AF_INET) to spamd at %s failed, retrying (#%d of %d): %m",
+		   ipaddr, numloops + 1, MAX_CONNECT_RETRIES);
 #else
-          origerr = WSAGetLastError();
-          fprintf (stderr,
-                  "connect(AF_INET) to spamd at %s failed, retrying (#%d of %d): %d\n",
-                  ipaddr, numloops+1, MAX_CONNECT_RETRIES, origerr);
+	    origerr = WSAGetLastError();
+	    fprintf(stderr,
+		    "connect(AF_INET) to spamd at %s failed, retrying (#%d of %d): %d\n",
+		    ipaddr, numloops + 1, MAX_CONNECT_RETRIES, origerr);
 #endif
-          closesocket(mysock);
+	    closesocket(mysock);
 
-			sleep(CONNECT_RETRY_SLEEP);
-		}
-		else
-		{
+	    sleep(CONNECT_RETRY_SLEEP);
+	}
+	else {
 #ifdef DO_CONNECT_DEBUG_SYSLOGS
 #ifndef _WIN32
-			syslog(DEBUG_LEVEL,
-				"dbg: connect(AF_INET) to spamd at %s done",
-				ipaddr);
+	    syslog(DEBUG_LEVEL,
+		   "dbg: connect(AF_INET) to spamd at %s done", ipaddr);
 #else
-			fprintf(stderr,
-				"dbg: connect(AF_INET) to spamd at %s done\n",
-				ipaddr);
+	    fprintf(stderr,
+		    "dbg: connect(AF_INET) to spamd at %s done\n", ipaddr);
 #endif
 #endif
-			*sockptr = mysock;
+	    *sockptr = mysock;
 
-			return EX_OK;
-		}
+	    return EX_OK;
 	}
+    }
 
 #ifndef _WIN32
-	syslog (LOG_ERR,
-		"connection attempt to spamd aborted after %d retries",
+    syslog(LOG_ERR, "connection attempt to spamd aborted after %d retries",
 #else
-	fprintf(stderr,
-		"connection attempt to spamd aborted after %d retries\n",
+    fprintf(stderr, "connection attempt to spamd aborted after %d retries\n",
 #endif
-		MAX_CONNECT_RETRIES);
+	    MAX_CONNECT_RETRIES);
 
-	return translate_connect_errno(origerr);
+    return translate_connect_errno(origerr);
 }
 
 /* Aug 14, 2002 bj: Reworked things. Now we have message_read, message_write,
@@ -475,212 +455,240 @@
  * of helper functions.
  */
 
-static void clear_message(struct message *m){
-    m->type=MESSAGE_NONE;
-    m->raw=NULL; m->raw_len=0;
-    m->pre=NULL; m->pre_len=0;
-    m->msg=NULL; m->msg_len=0;
-    m->post=NULL; m->post_len=0;
-    m->is_spam=EX_TOOBIG;
-    m->score=0.0; m->threshold=0.0;
-    m->out=NULL; m->out_len=0;
-    m->content_length=-1;
+static void clear_message(struct message *m)
+{
+    m->type = MESSAGE_NONE;
+    m->raw = NULL;
+    m->raw_len = 0;
+    m->pre = NULL;
+    m->pre_len = 0;
+    m->msg = NULL;
+    m->msg_len = 0;
+    m->post = NULL;
+    m->post_len = 0;
+    m->is_spam = EX_TOOBIG;
+    m->score = 0.0;
+    m->threshold = 0.0;
+    m->out = NULL;
+    m->out_len = 0;
+    m->content_length = -1;
 }
 
-static int
-message_read_raw(int fd, struct message *m){
+static int message_read_raw(int fd, struct message *m)
+{
     clear_message(m);
-    if((m->raw=malloc(m->max_len+1))==NULL) return EX_OSERR;
-    m->raw_len=full_read(fd, 1, m->raw, m->max_len+1, m->max_len+1);
-    if(m->raw_len<=0){
-        free(m->raw); m->raw=NULL; m->raw_len=0;
-        return EX_IOERR;
-    }
-    m->type=MESSAGE_ERROR;
-    if(m->raw_len>m->max_len) return EX_TOOBIG;
-    m->type=MESSAGE_RAW;
-    m->msg=m->raw;
-    m->msg_len=m->raw_len;
-    m->out=m->msg;
-    m->out_len=m->msg_len;
+    if ((m->raw = malloc(m->max_len + 1)) == NULL)
+	return EX_OSERR;
+    m->raw_len = full_read(fd, 1, m->raw, m->max_len + 1, m->max_len + 1);
+    if (m->raw_len <= 0) {
+	free(m->raw);
+	m->raw = NULL;
+	m->raw_len = 0;
+	return EX_IOERR;
+    }
+    m->type = MESSAGE_ERROR;
+    if (m->raw_len > m->max_len)
+	return EX_TOOBIG;
+    m->type = MESSAGE_RAW;
+    m->msg = m->raw;
+    m->msg_len = m->raw_len;
+    m->out = m->msg;
+    m->out_len = m->msg_len;
     return EX_OK;
 }
 
-static int message_read_bsmtp(int fd, struct message *m){
+static int message_read_bsmtp(int fd, struct message *m)
+{
     off_t i, j;
     char prev;
 
     clear_message(m);
-    if((m->raw=malloc(m->max_len+1))==NULL) return EX_OSERR;
+    if ((m->raw = malloc(m->max_len + 1)) == NULL)
+	return EX_OSERR;
 
     /* Find the DATA line */
-    m->raw_len=full_read(fd, 1, m->raw, m->max_len+1, m->max_len+1);
-    if(m->raw_len<=0){
-        free(m->raw); m->raw=NULL; m->raw_len=0;
-        return EX_IOERR;
-    }
-    m->type=MESSAGE_ERROR;
-    if(m->raw_len>m->max_len) return EX_TOOBIG;
-    m->pre=m->raw;
-    for(i=0; i<m->raw_len-6; i++){
-        if((m->raw[i]=='\n') &&
-           (m->raw[i+1]=='D' || m->raw[i+1]=='d') &&
-           (m->raw[i+2]=='A' || m->raw[i+2]=='a') &&
-           (m->raw[i+3]=='T' || m->raw[i+3]=='t') &&
-           (m->raw[i+4]=='A' || m->raw[i+4]=='a') &&
-           ((m->raw[i+5]=='\r' && m->raw[i+6]=='\n') || m->raw[i+5]=='\n')){
-            /* Found it! */
-            i+=6;
-            if(m->raw[i-1]=='\r') i++;
-            m->pre_len=i;
-            m->msg=m->raw+i;
-            m->msg_len=m->raw_len-i;
-            break;
-        }
+    m->raw_len = full_read(fd, 1, m->raw, m->max_len + 1, m->max_len + 1);
+    if (m->raw_len <= 0) {
+	free(m->raw);
+	m->raw = NULL;
+	m->raw_len = 0;
+	return EX_IOERR;
+    }
+    m->type = MESSAGE_ERROR;
+    if (m->raw_len > m->max_len)
+	return EX_TOOBIG;
+    m->pre = m->raw;
+    for (i = 0; i < m->raw_len - 6; i++) {
+	if ((m->raw[i] == '\n') &&
+	    (m->raw[i + 1] == 'D' || m->raw[i + 1] == 'd') &&
+	    (m->raw[i + 2] == 'A' || m->raw[i + 2] == 'a') &&
+	    (m->raw[i + 3] == 'T' || m->raw[i + 3] == 't') &&
+	    (m->raw[i + 4] == 'A' || m->raw[i + 4] == 'a') &&
+	    ((m->raw[i + 5] == '\r' && m->raw[i + 6] == '\n')
+	     || m->raw[i + 5] == '\n')) {
+	    /* Found it! */
+	    i += 6;
+	    if (m->raw[i - 1] == '\r')
+		i++;
+	    m->pre_len = i;
+	    m->msg = m->raw + i;
+	    m->msg_len = m->raw_len - i;
+	    break;
+	}
     }
-    if(m->msg==NULL) return EX_DATAERR;
+    if (m->msg == NULL)
+	return EX_DATAERR;
 
     /* Find the end-of-DATA line */
-    prev='\n';
-    for(i=j=0; i<m->msg_len; i++){
-        if(prev=='\n' && m->msg[i]=='.'){
-            /* Dot at the beginning of a line */
-            if((m->msg[i+1]=='\r' && m->msg[i+2]=='\n') || m->msg[i+1]=='\n'){
-                /* Lone dot! That's all, folks */
-                m->post=m->msg+i;
-                m->post_len=m->msg_len-i;
-                m->msg_len=j;
-                break;
-            } else if(m->msg[i+1]=='.'){
-                /* Escaping dot, eliminate. */
-                prev='.';
-                continue;
-            } /* Else an ordinary dot, drop down to ordinary char handler */
-        }
-        prev=m->msg[i];
-        m->msg[j++]=m->msg[i];
-    }
-
-    m->type=MESSAGE_BSMTP;
-    m->out=m->msg;
-    m->out_len=m->msg_len;
+    prev = '\n';
+    for (i = j = 0; i < m->msg_len; i++) {
+	if (prev == '\n' && m->msg[i] == '.') {
+	    /* Dot at the beginning of a line */
+	    if ((m->msg[i + 1] == '\r' && m->msg[i + 2] == '\n')
+		|| m->msg[i + 1] == '\n') {
+		/* Lone dot! That's all, folks */
+		m->post = m->msg + i;
+		m->post_len = m->msg_len - i;
+		m->msg_len = j;
+		break;
+	    }
+	    else if (m->msg[i + 1] == '.') {
+		/* Escaping dot, eliminate. */
+		prev = '.';
+		continue;
+	    }			/* Else an ordinary dot, drop down to ordinary char handler */
+	}
+	prev = m->msg[i];
+	m->msg[j++] = m->msg[i];
+    }
+
+    m->type = MESSAGE_BSMTP;
+    m->out = m->msg;
+    m->out_len = m->msg_len;
     return EX_OK;
 }
 
-int message_read(int fd, int flags, struct message *m){
+int message_read(int fd, int flags, struct message *m)
+{
     libspamc_timeout = 0;
 
     /* create the "private" part of the struct message */
-    m->priv = malloc (sizeof (struct libspamc_private_message));
+    m->priv = malloc(sizeof(struct libspamc_private_message));
     if (m->priv == NULL) {
-        syslog(LOG_ERR, "message_read: malloc failed");
-        return EX_OSERR;
+	syslog(LOG_ERR, "message_read: malloc failed");
+	return EX_OSERR;
     }
     m->priv->flags = flags;
 
-    switch(flags&SPAMC_MODE_MASK){
-      case SPAMC_RAW_MODE:
-        return message_read_raw(fd, m);
+    switch (flags & SPAMC_MODE_MASK) {
+    case SPAMC_RAW_MODE:
+	return message_read_raw(fd, m);
 
-      case SPAMC_BSMTP_MODE:
-        return message_read_bsmtp(fd, m);
+    case SPAMC_BSMTP_MODE:
+	return message_read_bsmtp(fd, m);
 
-      default:
+    default:
 #ifndef _WIN32
-        syslog(LOG_ERR, "message_read: Unknown mode %d",
+	syslog(LOG_ERR, "message_read: Unknown mode %d",
 #else
-        fprintf(stderr, "message_read: Unknown mode %d\n",
+	fprintf(stderr, "message_read: Unknown mode %d\n",
 #endif
-			flags&SPAMC_MODE_MASK);
-        return EX_USAGE;
+		flags & SPAMC_MODE_MASK);
+	return EX_USAGE;
     }
 }
 
-long message_write(int fd, struct message *m){
-    long total=0;
+long message_write(int fd, struct message *m)
+{
+    long total = 0;
     off_t i, j;
     off_t jlimit;
     char buffer[1024];
 
-    if (m->priv->flags&SPAMC_CHECK_ONLY) {
-	if(m->is_spam==EX_ISSPAM || m->is_spam==EX_NOTSPAM){
+    if (m->priv->flags & SPAMC_CHECK_ONLY) {
+	if (m->is_spam == EX_ISSPAM || m->is_spam == EX_NOTSPAM) {
 	    return full_write(fd, 1, m->out, m->out_len);
 
-	} else {
+	}
+	else {
 #ifndef _WIN32
 	    syslog(LOG_ERR, "oops! SPAMC_CHECK_ONLY is_spam: %d", m->is_spam);
 #else
-	    fprintf(stderr, "oops! SPAMC_CHECK_ONLY is_spam: %d\n", m->is_spam);
+	    fprintf(stderr, "oops! SPAMC_CHECK_ONLY is_spam: %d\n",
+		    m->is_spam);
 #endif
 	    return -1;
 	}
     }
 
     /* else we're not in CHECK_ONLY mode */
-    switch(m->type){
-      case MESSAGE_NONE:
-        syslog(LOG_ERR, "Cannot write this message, it's MESSAGE_NONE!");
-        return -1;
-
-      case MESSAGE_ERROR:
-        return full_write(fd, 1, m->raw, m->raw_len);
-
-      case MESSAGE_RAW:
-        return full_write(fd, 1, m->out, m->out_len);
-
-      case MESSAGE_BSMTP:
-        total=full_write(fd, 1, m->pre, m->pre_len);
-        for(i=0; i<m->out_len; ){
-	    jlimit = (off_t) (sizeof(buffer)/sizeof(*buffer)-4);
-            for(j=0; i < (off_t) m->out_len &&
-                                j < jlimit;)
-            {
-                if(i+1<m->out_len && m->out[i]=='\n' && m->out[i+1]=='.'){
+    switch (m->type) {
+    case MESSAGE_NONE:
+	syslog(LOG_ERR, "Cannot write this message, it's MESSAGE_NONE!");
+	return -1;
+
+    case MESSAGE_ERROR:
+	return full_write(fd, 1, m->raw, m->raw_len);
+
+    case MESSAGE_RAW:
+	return full_write(fd, 1, m->out, m->out_len);
+
+    case MESSAGE_BSMTP:
+	total = full_write(fd, 1, m->pre, m->pre_len);
+	for (i = 0; i < m->out_len;) {
+	    jlimit = (off_t) (sizeof(buffer) / sizeof(*buffer) - 4);
+	    for (j = 0; i < (off_t) m->out_len && j < jlimit;) {
+		if (i + 1 < m->out_len && m->out[i] == '\n'
+		    && m->out[i + 1] == '.') {
 		    if (j > jlimit - 4) {
-			break;		/* avoid overflow */
+			break;	/* avoid overflow */
 		    }
-                    buffer[j++]=m->out[i++];
-                    buffer[j++]=m->out[i++];
-                    buffer[j++]='.';
-                } else {
-                    buffer[j++]=m->out[i++];
-                }
-            }
-            total+=full_write(fd, 1, buffer, j);
-        }
-        return total+full_write(fd, 1, m->post, m->post_len);
+		    buffer[j++] = m->out[i++];
+		    buffer[j++] = m->out[i++];
+		    buffer[j++] = '.';
+		}
+		else {
+		    buffer[j++] = m->out[i++];
+		}
+	    }
+	    total += full_write(fd, 1, buffer, j);
+	}
+	return total + full_write(fd, 1, m->post, m->post_len);
 
-      default:
+    default:
 #ifndef _WIN32
-        syslog(LOG_ERR, "Unknown message type %d", m->type);
+	syslog(LOG_ERR, "Unknown message type %d", m->type);
 #else
-        fprintf(stderr, "Unknown message type %d\n", m->type);
+	fprintf(stderr, "Unknown message type %d\n", m->type);
 #endif
-        return -1;
+	return -1;
     }
 }
 
-void message_dump(int in_fd, int out_fd, struct message *m){
+void message_dump(int in_fd, int out_fd, struct message *m)
+{
     char buf[8196];
     int bytes;
-    
-    if(m!=NULL && m->type!=MESSAGE_NONE) {
-        message_write(out_fd, m);
+
+    if (m != NULL && m->type != MESSAGE_NONE) {
+	message_write(out_fd, m);
     }
-    while((bytes=full_read(in_fd, 1, buf, 8192, 8192))>0){
-        if (bytes!=full_write(out_fd, 1, buf, bytes)) {
+    while ((bytes = full_read(in_fd, 1, buf, 8192, 8192)) > 0) {
+	if (bytes != full_write(out_fd, 1, buf, bytes)) {
 #ifndef _WIN32
-            syslog(LOG_ERR, "oops! message_dump of %d returned different", bytes);
+	    syslog(LOG_ERR, "oops! message_dump of %d returned different",
+		   bytes);
 #else
-            fprintf(stderr, "oops! message_dump of %d returned different\n", bytes);
+	    fprintf(stderr, "oops! message_dump of %d returned different\n",
+		    bytes);
 #endif
-        }
+	}
     }
 }
 
 static int
-_spamc_read_full_line (struct message *m, int flags, SSL *ssl, int sock,
-		char *buf, int *lenp, int bufsiz)
+_spamc_read_full_line(struct message *m, int flags, SSL * ssl, int sock,
+		      char *buf, int *lenp, int bufsiz)
 {
     int failureval;
     int bytesread = 0;
@@ -689,26 +697,28 @@
     UNUSED_VARIABLE(m);
 
     /* Now, read from spamd */
-    for(len=0; len<bufsiz-1; len++) {
-	if(flags&SPAMC_USE_SSL) {
-	  bytesread = ssl_timeout_read (ssl, buf+len, 1);
-	} else {
-	  bytesread = fd_timeout_read (sock, 0, buf+len, 1);
+    for (len = 0; len < bufsiz - 1; len++) {
+	if (flags & SPAMC_USE_SSL) {
+	    bytesread = ssl_timeout_read(ssl, buf + len, 1);
+	}
+	else {
+	    bytesread = fd_timeout_read(sock, 0, buf + len, 1);
 	}
 
-        if(buf[len]=='\n') {
-            buf[len]='\0';
-	    if (len > 0 && buf[len-1] == '\r') {
+	if (buf[len] == '\n') {
+	    buf[len] = '\0';
+	    if (len > 0 && buf[len - 1] == '\r') {
 		len--;
-		buf[len]='\0';
+		buf[len] = '\0';
 	    }
 	    *lenp = len;
 	    return EX_OK;
 	}
 
-        if(bytesread<=0){
-	    failureval = EX_IOERR; goto failure;
-        }
+	if (bytesread <= 0) {
+	    failureval = EX_IOERR;
+	    goto failure;
+	}
     }
 
 #ifndef _WIN32
@@ -718,7 +728,7 @@
 #endif
     failureval = EX_TOOBIG;
 
-failure:
+  failure:
     return failureval;
 }
 
@@ -726,58 +736,67 @@
  * May  7 2003 jm: using %f is bad where LC_NUMERIC is "," in the locale.
  * work around using our own locale-independent float-parser code.
  */
-static float
-_locale_safe_string_to_float (char *buf, int siz)
+static float _locale_safe_string_to_float(char *buf, int siz)
 {
-  int is_neg;
-  char *cp, *dot;
-  int divider;
-  float ret, postdot;
-
-  buf[siz-1] = '\0';	/* ensure termination */
-
-  /* ok, let's illustrate using "100.033" as an example... */
-  
-  is_neg = 0;
-  if (*buf == '-') { is_neg = 1; }
-
-  ret = (float) (strtol (buf, &dot, 10));
-  if (dot == NULL) { return 0.0; }
-  if (dot != NULL && *dot != '.') { return ret; }
-
-  /* ex: ret == 100.0 */
-
-  cp = (dot + 1);
-  postdot = (float) (strtol (cp, NULL, 10));
-  if (postdot == 0.0) { return ret; }
-
-  /* ex: postdot == 33.0, cp="033" */
-
-  /* now count the number of decimal places and figure out what power of 10 to use */
-  divider = 1;
-  while (*cp != '\0') {
-    divider *= 10; cp++;
-  }
-
-  /* ex:
-   * cp="033", divider=1
-   * cp="33", divider=10
-   * cp="3", divider=100
-   * cp="", divider=1000
-   */
-
-  if (is_neg) {
-    ret -= (postdot / ((float) divider));
-  } else {
-    ret += (postdot / ((float) divider));
-  }
-  /* ex: ret == 100.033, tada! ... hopefully */
+    int is_neg;
+    char *cp, *dot;
+    int divider;
+    float ret, postdot;
+
+    buf[siz - 1] = '\0';	/* ensure termination */
+
+    /* ok, let's illustrate using "100.033" as an example... */
+
+    is_neg = 0;
+    if (*buf == '-') {
+	is_neg = 1;
+    }
+
+    ret = (float) (strtol(buf, &dot, 10));
+    if (dot == NULL) {
+	return 0.0;
+    }
+    if (dot != NULL && *dot != '.') {
+	return ret;
+    }
 
-  return ret;
+    /* ex: ret == 100.0 */
+
+    cp = (dot + 1);
+    postdot = (float) (strtol(cp, NULL, 10));
+    if (postdot == 0.0) {
+	return ret;
+    }
+
+    /* ex: postdot == 33.0, cp="033" */
+
+    /* now count the number of decimal places and figure out what power of 10 to use */
+    divider = 1;
+    while (*cp != '\0') {
+	divider *= 10;
+	cp++;
+    }
+
+    /* ex:
+     * cp="033", divider=1
+     * cp="33", divider=10
+     * cp="3", divider=100
+     * cp="", divider=1000
+     */
+
+    if (is_neg) {
+	ret -= (postdot / ((float) divider));
+    }
+    else {
+	ret += (postdot / ((float) divider));
+    }
+    /* ex: ret == 100.033, tada! ... hopefully */
+
+    return ret;
 }
 
 static int
-_handle_spamd_header (struct message *m, int flags, char *buf, int len)
+_handle_spamd_header(struct message *m, int flags, char *buf, int len)
 {
     char is_spam[6];
     char s_str[21], t_str[21];
@@ -789,42 +808,44 @@
      * May  7 2003 jm: using %f is bad where LC_NUMERIC is "," in the locale.
      * work around using our own locale-independent float-parser code.
      */
-    if (sscanf(buf, "Spam: %5s ; %20s / %20s", is_spam, s_str, t_str) == 3)
-    {
-	m->score = _locale_safe_string_to_float (s_str, 20);
-	m->threshold = _locale_safe_string_to_float (t_str, 20);
+    if (sscanf(buf, "Spam: %5s ; %20s / %20s", is_spam, s_str, t_str) == 3) {
+	m->score = _locale_safe_string_to_float(s_str, 20);
+	m->threshold = _locale_safe_string_to_float(t_str, 20);
 
 	/* set bounds on these to ensure no buffer overflow in the sprintf */
 	if (m->score > 1e10)
-	  m->score = 1e10;
+	    m->score = 1e10;
 	else if (m->score < -1e10)
-	  m->score = -1e10;
+	    m->score = -1e10;
 	if (m->threshold > 1e10)
-	  m->threshold = 1e10;
+	    m->threshold = 1e10;
 	else if (m->threshold < -1e10)
-	  m->threshold = -1e10;
+	    m->threshold = -1e10;
 
 	/* Format is "Spam: x; y / x" */
-	m->is_spam=strcasecmp("true", is_spam) == 0 ? EX_ISSPAM: EX_NOTSPAM;
+	m->is_spam =
+	    strcasecmp("true", is_spam) == 0 ? EX_ISSPAM : EX_NOTSPAM;
 
-	if(flags&SPAMC_CHECK_ONLY) {
-	    m->out_len=sprintf (m->out,
-			"%.1f/%.1f\n", m->score, m->threshold);
+	if (flags & SPAMC_CHECK_ONLY) {
+	    m->out_len = sprintf(m->out,
+				 "%.1f/%.1f\n", m->score, m->threshold);
 	}
 	else if ((flags & SPAMC_REPORT_IFSPAM && m->is_spam == EX_ISSPAM)
-		|| (flags & SPAMC_REPORT))
-	{
-	    m->out_len=sprintf (m->out,
-			"%.1f/%.1f\n", m->score, m->threshold);
+		 || (flags & SPAMC_REPORT)) {
+	    m->out_len = sprintf(m->out,
+				 "%.1f/%.1f\n", m->score, m->threshold);
 	}
 	return EX_OK;
 
-    } else if(sscanf(buf, "Content-length: %d", &m->content_length) == 1) {
+    }
+    else if (sscanf(buf, "Content-length: %d", &m->content_length) == 1) {
 	if (m->content_length < 0) {
 #ifndef _WIN32
-	    syslog(LOG_ERR, "spamd responded with bad Content-length '%s'", buf);
+	    syslog(LOG_ERR, "spamd responded with bad Content-length '%s'",
+		   buf);
 #else
-	    fprintf(stderr, "spamd responded with bad Content-length '%s'\n", buf);
+	    fprintf(stderr, "spamd responded with bad Content-length '%s'\n",
+		    buf);
 #endif
 	    return EX_PROTOCOL;
 	}
@@ -840,10 +861,10 @@
 }
 
 int message_filter(struct transport *tp, const char *username,
-                int flags, struct message *m)
+		   int flags, struct message *m)
 {
     char buf[8192];
-    int bufsiz = (sizeof(buf) / sizeof(*buf)) - 4; /* bit of breathing room */
+    int bufsiz = (sizeof(buf) / sizeof(*buf)) - 4;	/* bit of breathing room */
     int len;
     int sock = -1;
     int rc;
@@ -851,257 +872,312 @@
     float version;
     int response;
     int failureval;
-    SSL_CTX* ctx;
-    SSL* ssl = NULL;
+    SSL_CTX *ctx;
+    SSL *ssl = NULL;
     SSL_METHOD *meth;
 
-    if (flags&SPAMC_USE_SSL) {
+    if (flags & SPAMC_USE_SSL) {
 #ifdef SPAMC_SSL
-      SSLeay_add_ssl_algorithms();
-      meth = SSLv2_client_method();
-      SSL_load_error_strings();
-      ctx = SSL_CTX_new(meth);
-#else
-      UNUSED_VARIABLE(ssl);
-      UNUSED_VARIABLE(meth);
-      UNUSED_VARIABLE(ctx);
-      syslog(LOG_ERR, "spamc not built with SSL support");
-      return EX_SOFTWARE;
-#endif
-    }    
-
-    m->is_spam=EX_TOOBIG;
-    if((m->out=malloc(m->max_len+EXPANSION_ALLOWANCE+1))==NULL){
-        failureval = EX_OSERR; goto failure;
+	SSLeay_add_ssl_algorithms();
+	meth = SSLv2_client_method();
+	SSL_load_error_strings();
+	ctx = SSL_CTX_new(meth);
+#else
+	UNUSED_VARIABLE(ssl);
+	UNUSED_VARIABLE(meth);
+	UNUSED_VARIABLE(ctx);
+	syslog(LOG_ERR, "spamc not built with SSL support");
+	return EX_SOFTWARE;
+#endif
+    }
+
+    m->is_spam = EX_TOOBIG;
+    if ((m->out = malloc(m->max_len + EXPANSION_ALLOWANCE + 1)) == NULL) {
+	failureval = EX_OSERR;
+	goto failure;
     }
-    m->out_len=0;
+    m->out_len = 0;
 
 
     /* Build spamd protocol header */
-    if(flags & SPAMC_CHECK_ONLY) 
-	  strcpy(buf, "CHECK ");
-    else if(flags & SPAMC_REPORT_IFSPAM)
-      strcpy(buf, "REPORT_IFSPAM ");
-    else if(flags & SPAMC_REPORT) 
-      strcpy(buf, "REPORT ");
-    else if(flags & SPAMC_SYMBOLS) 
-      strcpy(buf, "SYMBOLS ");
+    if (flags & SPAMC_CHECK_ONLY)
+	strcpy(buf, "CHECK ");
+    else if (flags & SPAMC_REPORT_IFSPAM)
+	strcpy(buf, "REPORT_IFSPAM ");
+    else if (flags & SPAMC_REPORT)
+	strcpy(buf, "REPORT ");
+    else if (flags & SPAMC_SYMBOLS)
+	strcpy(buf, "SYMBOLS ");
     else
-      strcpy(buf, "PROCESS ");
+	strcpy(buf, "PROCESS ");
 
     len = strlen(buf);
-    if(len+strlen(PROTOCOL_VERSION)+2 >= bufsiz){ free(m->out); m->out=m->msg; m->out_len=m->msg_len; return EX_OSERR; }
+    if (len + strlen(PROTOCOL_VERSION) + 2 >= bufsiz) {
+	free(m->out);
+	m->out = m->msg;
+	m->out_len = m->msg_len;
+	return EX_OSERR;
+    }
 
     strcat(buf, PROTOCOL_VERSION);
     strcat(buf, "\r\n");
     len = strlen(buf);
 
-    if(username!=NULL) {
-      if (strlen(username)+8 >= (bufsiz - len)) { free(m->out); m->out=m->msg; m->out_len=m->msg_len; return EX_OSERR; }
-      strcpy(buf+len, "User: ");
-      strcat(buf+len, username);
-      strcat(buf+len, "\r\n");
-      len += strlen(buf+len);
+    if (username != NULL) {
+	if (strlen(username) + 8 >= (bufsiz - len)) {
+	    free(m->out);
+	    m->out = m->msg;
+	    m->out_len = m->msg_len;
+	    return EX_OSERR;
+	}
+	strcpy(buf + len, "User: ");
+	strcat(buf + len, username);
+	strcat(buf + len, "\r\n");
+	len += strlen(buf + len);
     }
     if ((m->msg_len > 9999999) || ((len + 27) >= (bufsiz - len))) {
-      free(m->out); m->out=m->msg; m->out_len=m->msg_len;
-      return EX_OSERR;
+	free(m->out);
+	m->out = m->msg;
+	m->out_len = m->msg_len;
+	return EX_OSERR;
     }
-    len += sprintf(buf+len, "Content-length: %d\r\n\r\n", m->msg_len);
+    len += sprintf(buf + len, "Content-length: %d\r\n\r\n", m->msg_len);
 
     libspamc_timeout = m->timeout;
 
-    if ( tp->socketpath )
-        rc = try_to_connect_unix(tp, &sock);
+    if (tp->socketpath)
+	rc = try_to_connect_unix(tp, &sock);
     else
-        rc = try_to_connect_tcp(tp, &sock);
+	rc = try_to_connect_tcp(tp, &sock);
 
-    if ( rc != EX_OK )
-    {
-        free(m->out); m->out=m->msg; m->out_len=m->msg_len;
-        return EX_OSERR;
+    if (rc != EX_OK) {
+	free(m->out);
+	m->out = m->msg;
+	m->out_len = m->msg_len;
+	return EX_OSERR;
     }
 
-    if(flags&SPAMC_USE_SSL) {
+    if (flags & SPAMC_USE_SSL) {
 #ifdef SPAMC_SSL
-      ssl = SSL_new(ctx);
-      SSL_set_fd(ssl, sock);
-      SSL_connect(ssl);
-#endif    
+	ssl = SSL_new(ctx);
+	SSL_set_fd(ssl, sock);
+	SSL_connect(ssl);
+#endif
     }
 
     /* Send to spamd */
-    if(flags&SPAMC_USE_SSL) {
+    if (flags & SPAMC_USE_SSL) {
 #ifdef SPAMC_SSL
-      SSL_write(ssl, buf, len);
-      SSL_write(ssl, m->msg, m->msg_len);
+	SSL_write(ssl, buf, len);
+	SSL_write(ssl, m->msg, m->msg_len);
 #endif
-    } else {
-      full_write(sock, 0, buf, len);
-      full_write(sock, 0, m->msg, m->msg_len);
-      shutdown(sock, SHUT_WR);
+    }
+    else {
+	full_write(sock, 0, buf, len);
+	full_write(sock, 0, m->msg, m->msg_len);
+	shutdown(sock, SHUT_WR);
     }
 
     /* ok, now read and parse it.  SPAMD/1.2 line first... */
-    failureval = _spamc_read_full_line (m, flags, ssl, sock, buf, &len, bufsiz);
-    if (failureval != EX_OK) { goto failure; }
+    failureval =
+	_spamc_read_full_line(m, flags, ssl, sock, buf, &len, bufsiz);
+    if (failureval != EX_OK) {
+	goto failure;
+    }
 
-    if(sscanf(buf, "SPAMD/%18s %d %*s", versbuf, &response)!=2) {
+    if (sscanf(buf, "SPAMD/%18s %d %*s", versbuf, &response) != 2) {
 #ifndef _WIN32
 	syslog(LOG_ERR, "spamd responded with bad string '%s'", buf);
 #else
 	fprintf(stderr, "spamd responded with bad string '%s'\n", buf);
 #endif
-	failureval = EX_PROTOCOL; goto failure;
+	failureval = EX_PROTOCOL;
+	goto failure;
     }
 
     versbuf[19] = '\0';
-    version = _locale_safe_string_to_float (versbuf, 20);
+    version = _locale_safe_string_to_float(versbuf, 20);
     if (version < 1.0) {
 #ifndef _WIN32
-	syslog(LOG_ERR, "spamd responded with bad version string '%s'", versbuf);
+	syslog(LOG_ERR, "spamd responded with bad version string '%s'",
+	       versbuf);
 #else
-	fprintf(stderr, "spamd responded with bad version string '%s'\n", versbuf);
+	fprintf(stderr, "spamd responded with bad version string '%s'\n",
+		versbuf);
 #endif
-	failureval = EX_PROTOCOL; goto failure;
+	failureval = EX_PROTOCOL;
+	goto failure;
     }
 
     m->score = 0;
     m->threshold = 0;
     m->is_spam = EX_TOOBIG;
     while (1) {
-	failureval = _spamc_read_full_line (m, flags, ssl, sock, buf, &len, bufsiz);
-	if (failureval != EX_OK) { goto failure; }
+	failureval =
+	    _spamc_read_full_line(m, flags, ssl, sock, buf, &len, bufsiz);
+	if (failureval != EX_OK) {
+	    goto failure;
+	}
 
 	if (len == 0 && buf[0] == '\0') {
-	    break;	/* end of headers */
+	    break;		/* end of headers */
 	}
 
 	if (_handle_spamd_header(m, flags, buf, len) < 0) {
-	    failureval = EX_PROTOCOL; goto failure;
+	    failureval = EX_PROTOCOL;
+	    goto failure;
 	}
     }
 
-    len = 0;		/* overwrite those headers */
+    len = 0;			/* overwrite those headers */
 
-    if (flags&SPAMC_CHECK_ONLY) {
-	closesocket(sock); sock = -1;
+    if (flags & SPAMC_CHECK_ONLY) {
+	closesocket(sock);
+	sock = -1;
 	if (m->is_spam == EX_TOOBIG) {
-	      /* We should have gotten headers back... Damnit. */
-	      failureval = EX_PROTOCOL; goto failure;
+	    /* We should have gotten headers back... Damnit. */
+	    failureval = EX_PROTOCOL;
+	    goto failure;
 	}
 	return EX_OK;
     }
     else {
 	if (m->content_length < 0) {
 	    /* should have got a length too. */
-	    failureval = EX_PROTOCOL; goto failure;
+	    failureval = EX_PROTOCOL;
+	    goto failure;
 	}
 
 	/* have we already got something in the buffer (e.g. REPORT and
-         * REPORT_IFSPAM both create a line from the "Spam:" hdr)?  If
+	 * REPORT_IFSPAM both create a line from the "Spam:" hdr)?  If
 	 * so, add the size of that so our sanity check passes.
 	 */
 	if (m->out_len > 0) {
 	    m->content_length += m->out_len;
 	}
 
-	if (flags&SPAMC_USE_SSL) {
-	  len = full_read_ssl (ssl, (unsigned char *) m->out+m->out_len,
-		     m->max_len+EXPANSION_ALLOWANCE+1-m->out_len,
-		     m->max_len+EXPANSION_ALLOWANCE+1-m->out_len);
-	} else{
-	  len = full_read (sock, 0, m->out+m->out_len,
-		     m->max_len+EXPANSION_ALLOWANCE+1-m->out_len,
-		     m->max_len+EXPANSION_ALLOWANCE+1-m->out_len);
+	if (flags & SPAMC_USE_SSL) {
+	    len = full_read_ssl(ssl, (unsigned char *) m->out + m->out_len,
+				m->max_len + EXPANSION_ALLOWANCE + 1 -
+				m->out_len,
+				m->max_len + EXPANSION_ALLOWANCE + 1 -
+				m->out_len);
+	}
+	else {
+	    len = full_read(sock, 0, m->out + m->out_len,
+			    m->max_len + EXPANSION_ALLOWANCE + 1 - m->out_len,
+			    m->max_len + EXPANSION_ALLOWANCE + 1 -
+			    m->out_len);
 	}
 
 
-	if(len+m->out_len>m->max_len+EXPANSION_ALLOWANCE){
-	    failureval = EX_TOOBIG; goto failure;
+	if (len + m->out_len > m->max_len + EXPANSION_ALLOWANCE) {
+	    failureval = EX_TOOBIG;
+	    goto failure;
 	}
-	m->out_len+=len;
+	m->out_len += len;
 
 	shutdown(sock, SHUT_RD);
-	closesocket(sock); sock = -1;
+	closesocket(sock);
+	sock = -1;
     }
     libspamc_timeout = 0;
 
-    if(m->out_len!=m->content_length) {
+    if (m->out_len != m->content_length) {
 #ifndef _WIN32
-        syslog(LOG_ERR, "failed sanity check, %d bytes claimed, %d bytes seen",
-				m->content_length, m->out_len);
+	syslog(LOG_ERR,
+	       "failed sanity check, %d bytes claimed, %d bytes seen",
+	       m->content_length, m->out_len);
 #else
-        fprintf(stderr, "failed sanity check, %d bytes claimed, %d bytes seen\n",
-				m->content_length, m->out_len);
+	fprintf(stderr,
+		"failed sanity check, %d bytes claimed, %d bytes seen\n",
+		m->content_length, m->out_len);
 #endif
-	failureval = EX_PROTOCOL; goto failure;
+	failureval = EX_PROTOCOL;
+	goto failure;
     }
 
     return EX_OK;
 
-failure:
-    free(m->out); m->out=m->msg; m->out_len=m->msg_len;
+  failure:
+    free(m->out);
+    m->out = m->msg;
+    m->out_len = m->msg_len;
     if (sock != -1) {
-      closesocket(sock);
+	closesocket(sock);
     }
     libspamc_timeout = 0;
 
-    if(flags&SPAMC_USE_SSL) {
+    if (flags & SPAMC_USE_SSL) {
 #ifdef SPAMC_SSL
-      SSL_free(ssl);
-      SSL_CTX_free(ctx);
+	SSL_free(ssl);
+	SSL_CTX_free(ctx);
 #endif
     }
     return failureval;
 }
 
 
-int message_process(struct transport *trans, char *username, int max_size, int in_fd, int out_fd, const int flags){
+int message_process(struct transport *trans, char *username, int max_size,
+		    int in_fd, int out_fd, const int flags)
+{
     int ret;
     struct message m;
 
-    m.type=MESSAGE_NONE;
+    m.type = MESSAGE_NONE;
 
-    m.max_len=max_size;
-    ret=message_read(in_fd, flags, &m);
-    if(ret!=EX_OK) goto FAIL;
-    ret=message_filter(trans, username, flags, &m);
-    if(ret!=EX_OK) goto FAIL;
-    if(message_write(out_fd, &m)<0) goto FAIL;
-    if(m.is_spam!=EX_TOOBIG) {
-       message_cleanup(&m);
-       return m.is_spam;
+    m.max_len = max_size;
+    ret = message_read(in_fd, flags, &m);
+    if (ret != EX_OK)
+	goto FAIL;
+    ret = message_filter(trans, username, flags, &m);
+    if (ret != EX_OK)
+	goto FAIL;
+    if (message_write(out_fd, &m) < 0)
+	goto FAIL;
+    if (m.is_spam != EX_TOOBIG) {
+	message_cleanup(&m);
+	return m.is_spam;
     }
     message_cleanup(&m);
     return ret;
 
-FAIL:
-   if(flags&SPAMC_CHECK_ONLY){
-       full_write(out_fd, 1, "0/0\n", 4);
-       message_cleanup(&m);
-       return EX_NOTSPAM;
-   } else {
-       message_dump(in_fd, out_fd, &m);
-       message_cleanup(&m);
-       return ret;
+  FAIL:
+    if (flags & SPAMC_CHECK_ONLY) {
+	full_write(out_fd, 1, "0/0\n", 4);
+	message_cleanup(&m);
+	return EX_NOTSPAM;
+    }
+    else {
+	message_dump(in_fd, out_fd, &m);
+	message_cleanup(&m);
+	return ret;
     }
 }
 
-void message_cleanup(struct message *m) {
-   if (m->out != NULL && m->out != m->raw) free(m->out);
-   if (m->raw != NULL) free(m->raw);
-   if (m->priv != NULL) free(m->priv);
-   clear_message(m);
+void message_cleanup(struct message *m)
+{
+    if (m->out != NULL && m->out != m->raw)
+	free(m->out);
+    if (m->raw != NULL)
+	free(m->raw);
+    if (m->priv != NULL)
+	free(m->priv);
+    clear_message(m);
 }
 
 /* Aug 14, 2002 bj: Obsolete! */
-int process_message(struct transport *tp, char *username, int max_size, int in_fd, int out_fd, const int my_check_only, const int my_safe_fallback){
+int process_message(struct transport *tp, char *username, int max_size,
+		    int in_fd, int out_fd, const int my_check_only,
+		    const int my_safe_fallback)
+{
     int flags;
 
-    flags=SPAMC_RAW_MODE;
-    if(my_check_only) flags|=SPAMC_CHECK_ONLY;
-    if(my_safe_fallback) flags|=SPAMC_SAFE_FALLBACK;
+    flags = SPAMC_RAW_MODE;
+    if (my_check_only)
+	flags |= SPAMC_CHECK_ONLY;
+    if (my_safe_fallback)
+	flags |= SPAMC_SAFE_FALLBACK;
 
     return message_process(tp, username, max_size, in_fd, out_fd, flags);
 }
@@ -1114,12 +1190,12 @@
  */
 void transport_init(struct transport *tp)
 {
-	assert(tp != 0);
+    assert(tp != 0);
 
-	memset(tp, 0, sizeof *tp);
+    memset(tp, 0, sizeof *tp);
 
-	tp->type = TRANSPORT_LOCALHOST;
-	tp->port = 783;
+    tp->type = TRANSPORT_LOCALHOST;
+    tp->port = 783;
 }
 
 /*
@@ -1134,24 +1210,24 @@
 
 static void randomize_hosts(struct transport *tp)
 {
-int     rnum;
+    int rnum;
 
-	assert(tp != 0);
+    assert(tp != 0);
 
-	if ( tp->nhosts <= 1 ) return;
+    if (tp->nhosts <= 1)
+	return;
 
-	rnum = rand() % tp->nhosts;
+    rnum = rand() % tp->nhosts;
 
-	while ( rnum-- > 0 )
-	{
-	struct in_addr  tmp = tp->hosts[0];
-	int             i;
+    while (rnum-- > 0) {
+	struct in_addr tmp = tp->hosts[0];
+	int i;
 
-		for (i = 1; i < tp->nhosts; i++ )
-			tp->hosts[i-1] = tp->hosts[i];
+	for (i = 1; i < tp->nhosts; i++)
+	    tp->hosts[i - 1] = tp->hosts[i];
 
-		tp->hosts[i-1] = tmp;
-	}
+	tp->hosts[i - 1] = tmp;
+    }
 }
 
 /*
@@ -1171,75 +1247,70 @@
  */
 int transport_setup(struct transport *tp, int flags)
 {
-struct hostent *hp = 0;
-char           **addrp;
+    struct hostent *hp = 0;
+    char **addrp;
 
 #ifdef _WIN32
     // Start Winsock up
     WSADATA wsaData;
     int nCode;
     if ((nCode = WSAStartup(MAKEWORD(1, 1), &wsaData)) != 0) {
-      printf("WSAStartup() returned error code %d\n", nCode);
-      return EX_OSERR;
+	printf("WSAStartup() returned error code %d\n", nCode);
+	return EX_OSERR;
     }
 
 #endif
 
-	assert(tp != 0);
+    assert(tp != 0);
 
-	switch ( tp->type )
-	{
+    switch (tp->type) {
 #ifndef _WIN32
-	  case TRANSPORT_UNIX:
-		assert(tp->socketpath != 0);
-		return EX_OK;
+    case TRANSPORT_UNIX:
+	assert(tp->socketpath != 0);
+	return EX_OK;
 #endif
-	  case TRANSPORT_LOCALHOST:
-		tp->hosts[0].s_addr = inet_addr("127.0.0.1");
-		tp->nhosts          = 1;
-		return EX_OK;
-
-	  case TRANSPORT_TCP:
-		if (NULL == (hp = gethostbyname(tp->hostname)))
-		{
-		int	origherr = h_errno;  /* take a copy before syslog() */
+    case TRANSPORT_LOCALHOST:
+	tp->hosts[0].s_addr = inet_addr("127.0.0.1");
+	tp->nhosts = 1;
+	return EX_OK;
 
-#ifndef _WIN32
-			syslog (LOG_ERR, "gethostbyname(%s) failed: h_errno=%d",
-#else
-			fprintf (stderr, "gethostbyname(%s) failed: h_errno=%d\n",
-#endif
-				tp->hostname, origherr);
-			switch (origherr)
-			{
-			  case HOST_NOT_FOUND:
-			  case NO_ADDRESS:
-			  case NO_RECOVERY:
-				return EX_NOHOST;
-			  case TRY_AGAIN:
-				return EX_TEMPFAIL;
-			  default:
-				return EX_OSERR;
-			}
-		}
+    case TRANSPORT_TCP:
+	if (NULL == (hp = gethostbyname(tp->hostname))) {
+	    int origherr = h_errno;	/* take a copy before syslog() */
+
+#ifndef _WIN32
+	    syslog(LOG_ERR, "gethostbyname(%s) failed: h_errno=%d",
+#else
+	    fprintf(stderr, "gethostbyname(%s) failed: h_errno=%d\n",
+#endif
+		    tp->hostname, origherr);
+	    switch (origherr) {
+	    case HOST_NOT_FOUND:
+	    case NO_ADDRESS:
+	    case NO_RECOVERY:
+		return EX_NOHOST;
+	    case TRY_AGAIN:
+		return EX_TEMPFAIL;
+	    default:
+		return EX_OSERR;
+	    }
+	}
 
 		/*--------------------------------------------------------
 		 * If we have no hosts at all, or if they are some other
 	 	 * kind of address family besides IPv4, then we really
 		 * just have no hosts at all.
 		 */
-		if ( hp->h_addr_list[0] == 0 )
-		{
-			/* no hosts in this list */
-			return EX_NOHOST;
-		}
+	if (hp->h_addr_list[0] == 0) {
+	    /* no hosts in this list */
+	    return EX_NOHOST;
+	}
 
-		if ( hp->h_length   != sizeof tp->hosts[0]
-		  || hp->h_addrtype != AF_INET )
-		{
-			/* FAIL - bad size/protocol/family? */
-			return EX_NOHOST;
-		}
+	if (hp->h_length != sizeof tp->hosts[0]
+	    || hp->h_addrtype != AF_INET) {
+	    /* FAIL - bad size/protocol/family? */
+	    return EX_NOHOST;
+	}
 
 		/*--------------------------------------------------------
 		 * Copy all the IP addresses into our private structure.
@@ -1247,24 +1318,24 @@
 		 * means we won't ever walk all over the list with other
 		 * calls.
 		 */
-		tp->nhosts = 0;
+	tp->nhosts = 0;
 
-		for (addrp = hp->h_addr_list; *addrp; addrp++)
-		{
-			if (tp->nhosts >= TRANSPORT_MAX_HOSTS-1) {
+	for (addrp = hp->h_addr_list; *addrp; addrp++) {
+	    if (tp->nhosts >= TRANSPORT_MAX_HOSTS - 1) {
 #ifndef _WIN32
-				syslog (LOG_ERR, "hit limit of %d hosts, ignoring remainder", TRANSPORT_MAX_HOSTS-1);
+		syslog(LOG_ERR, "hit limit of %d hosts, ignoring remainder",
+		       TRANSPORT_MAX_HOSTS - 1);
 #else
-				fprintf (stderr, "hit limit of %d hosts, ignoring remainder\n", TRANSPORT_MAX_HOSTS-1);
+		fprintf(stderr, "hit limit of %d hosts, ignoring remainder\n",
+			TRANSPORT_MAX_HOSTS - 1);
 #endif
-				break;
-			}
+		break;
+	    }
 
-			memcpy(&tp->hosts[tp->nhosts], *addrp,
-				sizeof tp->hosts[0]);
+	    memcpy(&tp->hosts[tp->nhosts], *addrp, sizeof tp->hosts[0]);
 
-			tp->nhosts++;
-		}
+	    tp->nhosts++;
+	}
 
 		/*--------------------------------------------------------
 		 * QUASI-LOAD-BALANCING
@@ -1274,23 +1345,21 @@
 		 * This may later be truncated to a single item. This is
 		 * meaningful only if we have more than one host.
 		 */
-		if ( (flags & SPAMC_RANDOMIZE_HOSTS)  &&  tp->nhosts > 1 )
-		{
-			randomize_hosts(tp);
-		}
+	if ((flags & SPAMC_RANDOMIZE_HOSTS) && tp->nhosts > 1) {
+	    randomize_hosts(tp);
+	}
 
 		/*--------------------------------------------------------
 		 * If the user wants no fallback, simply truncate the host
 		 * list to just one - this pretends that this is the extent
 		 * of our connection list - then it's not a special case.
 		 */
-		if ( !(flags & SPAMC_SAFE_FALLBACK)  &&  tp->nhosts > 1 )
-		{
-			/* truncating list */
-			tp->nhosts = 1;
-		}
+	if (!(flags & SPAMC_SAFE_FALLBACK) && tp->nhosts > 1) {
+	    /* truncating list */
+	    tp->nhosts = 1;
 	}
-	return EX_OK;
+    }
+    return EX_OK;
 }
 
 
@@ -1305,53 +1374,57 @@
  */
 #ifdef LIBSPAMC_UNIT_TESTS
 
-static void
-_test_locale_safe_string_to_float_val (float input) {
-  char inputstr[99], cmpbuf1[99], cmpbuf2[99];
-  float output;
-
-  /* sprintf instead of snprintf is safe here because it is only a controlled test */
-  sprintf (inputstr, "%f", input);
-  output = _locale_safe_string_to_float (inputstr, 99);
-  if (input == output) { return; }
-
-  /* could be a rounding error.  print as string and compare those */
-  sprintf (cmpbuf1, "%f", input);
-  sprintf (cmpbuf2, "%f", output);
-  if (!strcmp (cmpbuf1, cmpbuf2)) { return; }
-
-  printf ("FAIL: input=%f != output=%f\n", input, output);
-}
-
-static void
-unit_test_locale_safe_string_to_float (void) {
-  float statictestset[] = {	/* will try both +ve and -ve */
+static void _test_locale_safe_string_to_float_val(float input)
+{
+    char inputstr[99], cmpbuf1[99], cmpbuf2[99];
+    float output;
+
+    /* sprintf instead of snprintf is safe here because it is only a controlled test */
+    sprintf(inputstr, "%f", input);
+    output = _locale_safe_string_to_float(inputstr, 99);
+    if (input == output) {
+	return;
+    }
+
+    /* could be a rounding error.  print as string and compare those */
+    sprintf(cmpbuf1, "%f", input);
+    sprintf(cmpbuf2, "%f", output);
+    if (!strcmp(cmpbuf1, cmpbuf2)) {
+	return;
+    }
+
+    printf("FAIL: input=%f != output=%f\n", input, output);
+}
+
+static void unit_test_locale_safe_string_to_float(void)
+{
+    float statictestset[] = {	/* will try both +ve and -ve */
 	0.1, 0.01, 0.001, 0.0001, 0.00001, 0.000001,
 	9.1, 9.91, 9.991, 9.9991, 9.99991, 9.999991,
-	0.0		/* end of set constant */
-  };
-  float num;
-  int i;
-
-  printf ("starting unit_test_locale_safe_string_to_float\n");
-  /* tests of precision */
-  for (i = 0; statictestset[i] != 0.0; i++) {
-    _test_locale_safe_string_to_float_val (statictestset[i]);
-    _test_locale_safe_string_to_float_val (-statictestset[i]);
-    _test_locale_safe_string_to_float_val (1-statictestset[i]);
-    _test_locale_safe_string_to_float_val (1+statictestset[i]);
-  }
-  /* now exhaustive, in steps of 0.01 */
-  for (num = -1000.0; num < 1000.0; num += 0.01) {
-    _test_locale_safe_string_to_float_val (num);
-  }
-  printf ("finished unit_test_locale_safe_string_to_float\n");
-}
-
-void
-do_libspamc_unit_tests (void) {
-  unit_test_locale_safe_string_to_float();
-  exit (0);
+	0.0			/* end of set constant */
+    };
+    float num;
+    int i;
+
+    printf("starting unit_test_locale_safe_string_to_float\n");
+    /* tests of precision */
+    for (i = 0; statictestset[i] != 0.0; i++) {
+	_test_locale_safe_string_to_float_val(statictestset[i]);
+	_test_locale_safe_string_to_float_val(-statictestset[i]);
+	_test_locale_safe_string_to_float_val(1 - statictestset[i]);
+	_test_locale_safe_string_to_float_val(1 + statictestset[i]);
+    }
+    /* now exhaustive, in steps of 0.01 */
+    for (num = -1000.0; num < 1000.0; num += 0.01) {
+	_test_locale_safe_string_to_float_val(num);
+    }
+    printf("finished unit_test_locale_safe_string_to_float\n");
+}
+
+void do_libspamc_unit_tests(void)
+{
+    unit_test_locale_safe_string_to_float();
+    exit(0);
 }
 
 #endif /* LIBSPAMC_UNIT_TESTS */

Modified: incubator/spamassassin/trunk/spamc/libspamc.h
==============================================================================
--- incubator/spamassassin/trunk/spamc/libspamc.h	(original)
+++ incubator/spamassassin/trunk/spamc/libspamc.h	Fri Jan 30 20:18:08 2004
@@ -81,7 +81,8 @@
 
 
 /* Aug 14, 2002 bj: A struct for storing a message-in-progress */
-typedef enum {
+typedef enum
+{
     MESSAGE_NONE,
     MESSAGE_ERROR,
     MESSAGE_RAW,
@@ -91,26 +92,32 @@
 
 struct libspamc_private_message;
 
-struct message {
+struct message
+{
     /* Set before passing the struct on! */
-    int max_len;  /* messages larger than this will return EX_TOOBIG */
-    int timeout;  /* timeout for read() system calls */
+    int max_len;		/* messages larger than this will return EX_TOOBIG */
+    int timeout;		/* timeout for read() system calls */
 
     /* Filled in by message_read */
     message_type_t type;
-    char *raw; int raw_len;   /* Raw message buffer */
-    char *pre; int pre_len;   /* Pre-message data (e.g. SMTP commands) */
-    char *msg; int msg_len;   /* The message */
-    char *post; int post_len; /* Post-message data (e.g. SMTP commands) */
+    char *raw;
+    int raw_len;		/* Raw message buffer */
+    char *pre;
+    int pre_len;		/* Pre-message data (e.g. SMTP commands) */
+    char *msg;
+    int msg_len;		/* The message */
+    char *post;
+    int post_len;		/* Post-message data (e.g. SMTP commands) */
     int content_length;
 
     /* Filled in by filter_message */
-    int is_spam;              /* EX_ISSPAM if the message is spam, EX_NOTSPAM
-                                 if not */
-    float score, threshold;   /* score and threshold */
-    char *out; int out_len;   /* Output from spamd. Either the filtered
-                                 message, or the check-only response. Or else,
-                                 a pointer to msg above. */
+    int is_spam;		/* EX_ISSPAM if the message is spam, EX_NOTSPAM
+				   if not */
+    float score, threshold;	/* score and threshold */
+    char *out;
+    int out_len;		/* Output from spamd. Either the filtered
+				   message, or the check-only response. Or else,
+				   a pointer to msg above. */
 
     /* these members added in SpamAssassin version 2.60: */
     struct libspamc_private_message *priv;
@@ -140,25 +147,26 @@
  * code just loops over that same address.
  */
 #define TRANSPORT_LOCALHOST 0x01	/* TCP to localhost only */
-#define	TRANSPORT_TCP	    0x02	/* standard TCP socket	 */
-#define TRANSPORT_UNIX	    0x03	/* UNIX domain socket	 */
+#define	TRANSPORT_TCP	    0x02	/* standard TCP socket   */
+#define TRANSPORT_UNIX	    0x03	/* UNIX domain socket    */
 
-#define TRANSPORT_MAX_HOSTS 256		/* max hosts we can failover between */
+#define TRANSPORT_MAX_HOSTS 256	/* max hosts we can failover between */
 
-struct transport {
-	int		type;
+struct transport
+{
+    int type;
 
-	const char	*socketpath;	/* for UNIX dommain socket      */
-	const char	*hostname;	/* for TCP sockets              */
+    const char *socketpath;	/* for UNIX dommain socket      */
+    const char *hostname;	/* for TCP sockets              */
 
-	unsigned short	port;		/* for TCP sockets              */
+    unsigned short port;	/* for TCP sockets              */
 
-	struct in_addr	hosts[TRANSPORT_MAX_HOSTS];
-	int		nhosts;
+    struct in_addr hosts[TRANSPORT_MAX_HOSTS];
+    int nhosts;
 };
 
 extern void transport_init(struct transport *tp);
-extern int  transport_setup(struct transport *tp, int flags);
+extern int transport_setup(struct transport *tp, int flags);
 
 /* Aug 14, 2002 bj: New interface functions */
 
@@ -179,7 +187,7 @@
  * no failover is done.
  */
 int message_filter(struct transport *tp, const char *username,
-		int flags, struct message *m);
+		   int flags, struct message *m);
 
 /* Dump the message. If there is any data in the message (typically, m->type
  * will be MESSAGE_ERROR) it will be message_writed. Then, fd_in will be piped
@@ -190,16 +198,16 @@
 /* Do a message_read->message_filter->message_write sequence, handling errors
  * appropriately with dump_message or appropriate CHECK_ONLY output. Returns
  * EX_OK or EX_ISSPAM/EX_NOTSPAM on success, some error EX on error. */
-int message_process(struct transport *trans, char *username, int max_size, int in_fd, int out_fd, const int flags);
+int message_process(struct transport *trans, char *username, int max_size,
+		    int in_fd, int out_fd, const int flags);
 
 /* Cleanup the resources we allocated for storing the message. Call after
  * you're done processing. */
 void message_cleanup(struct message *m);
 
 /* Aug 14, 2002 bj: This is now legacy, don't use it. */
-int process_message(struct transport *tp, char *username, 
-                    int max_size, int in_fd, int out_fd,
-                    const int check_only, const int safe_fallback);
+int process_message(struct transport *tp, char *username,
+		    int max_size, int in_fd, int out_fd,
+		    const int check_only, const int safe_fallback);
 
 #endif
-

Modified: incubator/spamassassin/trunk/spamc/qmail-spamc.c
==============================================================================
--- incubator/spamassassin/trunk/spamc/qmail-spamc.c	(original)
+++ incubator/spamassassin/trunk/spamc/qmail-spamc.c	Fri Jan 30 20:18:08 2004
@@ -26,64 +26,64 @@
 
 int main()
 {
-    int  pfds[2];
-    int  childpid;
-    char *socket = getenv("SPAMDSOCK" ); /* Unix Domain Socket path  */
-    char *host   = getenv("SPAMDHOST" ); /* remote spamd host name   */
-    char *port   = getenv("SPAMDPORT" ); /* remote spamd host port   */
-    char *ssl    = getenv("SPAMDSSL"  ); /* use ssl for spamc/spamd  */
-    char *limit  = getenv("SPAMDLIMIT"); /* message size limit       */
-    char *user   = getenv("SPAMDUSER" ); /* spamc user configuration */
+    int pfds[2];
+    int childpid;
+    char *socket = getenv("SPAMDSOCK");	/* Unix Domain Socket path  */
+    char *host = getenv("SPAMDHOST");	/* remote spamd host name   */
+    char *port = getenv("SPAMDPORT");	/* remote spamd host port   */
+    char *ssl = getenv("SPAMDSSL");	/* use ssl for spamc/spamd  */
+    char *limit = getenv("SPAMDLIMIT");	/* message size limit       */
+    char *user = getenv("SPAMDUSER");	/* spamc user configuration */
     char *options[MAXOPTS];
-    int  opt = 0;
+    int opt = 0;
 
     /* create the array of options */
-    options[opt++] = "spamc"; /* zeroth argument */
-    if ( socket ) {
-        options[opt++] = "-U";
-        options[opt++] = socket;
-    }
-    if ( host ) {
-        options[opt++] = "-d";
-        options[opt++] = host;
-    }
-    if ( port ) {
-        options[opt++] = "-p";
-        options[opt++] = port;
-    }
-    if ( ssl ) {
-        options[opt++] = "-S";
-    }
-    if ( limit ) {
-        options[opt++] = "-s";
-        options[opt++] = limit;
-    }
-    if ( user ) {
-        options[opt++] = "-u";
-        options[opt++] = user;
+    options[opt++] = "spamc";	/* zeroth argument */
+    if (socket) {
+	options[opt++] = "-U";
+	options[opt++] = socket;
+    }
+    if (host) {
+	options[opt++] = "-d";
+	options[opt++] = host;
+    }
+    if (port) {
+	options[opt++] = "-p";
+	options[opt++] = port;
+    }
+    if (ssl) {
+	options[opt++] = "-S";
+    }
+    if (limit) {
+	options[opt++] = "-s";
+	options[opt++] = limit;
+    }
+    if (user) {
+	options[opt++] = "-u";
+	options[opt++] = user;
     }
     options[opt] = NULL;
 
-    if ( pipe(pfds) == -1 ) {
-        perror("Failed to create pipe; quitting\n");
-        exit(1);
+    if (pipe(pfds) == -1) {
+	perror("Failed to create pipe; quitting\n");
+	exit(1);
     }
 
-    if ( ( childpid = fork() ) == -1 ) {
-        perror("Failed to fork; quitting\n");
-        exit(2);
+    if ((childpid = fork()) == -1) {
+	perror("Failed to fork; quitting\n");
+	exit(2);
     }
 
-    if ( childpid == 0 ) {
-        close(1);       /* close normal stdout */
-        dup(pfds[1]);   /* make stdout same as pfds[1] */
-        close(pfds[0]); /* we don't need this */
-        execvp("spamc", options);
-    } else {
-        close(0);       /* close normal stdin */
-        dup(pfds[0]);   /* make stdin same as pfds[0] */
-        close(pfds[1]); /* we don't need this */
-        execlp("qmail-queue", "qmail-queue", NULL);
+    if (childpid == 0) {
+	close(1);		/* close normal stdout */
+	dup(pfds[1]);		/* make stdout same as pfds[1] */
+	close(pfds[0]);		/* we don't need this */
+	execvp("spamc", options);
+    }
+    else {
+	close(0);		/* close normal stdin */
+	dup(pfds[0]);		/* make stdin same as pfds[0] */
+	close(pfds[1]);		/* we don't need this */
+	execlp("qmail-queue", "qmail-queue", NULL);
     }
 }
-

Modified: incubator/spamassassin/trunk/spamc/spamc.c
==============================================================================
--- incubator/spamassassin/trunk/spamc/spamc.c	(original)
+++ incubator/spamassassin/trunk/spamc/spamc.c	Fri Jan 30 20:18:08 2004
@@ -68,7 +68,7 @@
      || (defined(__sgi))  /* IRIX */ \
      || (defined(__osf__)) /* Digital UNIX */ \
      || (defined(hpux) || defined(__hpux)) /* HPUX */ \
-     || (defined(__CYGWIN__)) /* CygWin, Win32 */
+     || (defined(__CYGWIN__))	/* CygWin, Win32 */
 
 extern int optind;
 extern char *optarg;
@@ -77,7 +77,7 @@
 
 #ifdef _WIN32
 #include "replace/getopt.h"
-char* __progname = "spamc";
+char *__progname = "spamc";
 #endif
 
 
@@ -91,189 +91,200 @@
 
 void print_usage(void)
 {
-  printf("Usage: spamc [options] < message\n\n");
-  printf("-B: BSMTP mode - expect input to be a single SMTP-formatted message\n");
-  printf("-c: check only - print score/threshold and exit code set to 0 if message is not spam, 1 if spam\n");
-  printf("-r: report if spam - print report for spam messages\n");
-  printf("-R: report - print report for all messages\n");
-  printf("-y: symbols - print only the names of the tests hit\n");
-  printf("-d host: specify host to connect to  [default: localhost]\n");
-  printf("-e command [args]: Command to output to instead of stdout. MUST BE THE LAST OPTION.\n");
-  printf("-f: fallback safely - in case of comms error, dump original message unchanges instead of setting exitcode\n");
-  printf("-h: print this help message\n");
-  printf("-p port: specify port for connection [default: 783]\n");
-  printf("-s size: specify max message size, any bigger and it will be returned w/out processing [default: 250k]\n");
+    printf("Usage: spamc [options] < message\n\n");
+    printf
+	("-B: BSMTP mode - expect input to be a single SMTP-formatted message\n");
+    printf
+	("-c: check only - print score/threshold and exit code set to 0 if message is not spam, 1 if spam\n");
+    printf("-r: report if spam - print report for spam messages\n");
+    printf("-R: report - print report for all messages\n");
+    printf("-y: symbols - print only the names of the tests hit\n");
+    printf("-d host: specify host to connect to  [default: localhost]\n");
+    printf
+	("-e command [args]: Command to output to instead of stdout. MUST BE THE LAST OPTION.\n");
+    printf
+	("-f: fallback safely - in case of comms error, dump original message unchanges instead of setting exitcode\n");
+    printf("-h: print this help message\n");
+    printf("-p port: specify port for connection [default: 783]\n");
+    printf
+	("-s size: specify max message size, any bigger and it will be returned w/out processing [default: 250k]\n");
 #ifdef SPAMC_SSL
-  printf("-S: use SSL to talk to spamd\n");
+    printf("-S: use SSL to talk to spamd\n");
 #endif
-  printf("-u username: specify the username for spamd to process this message under\n");
-  printf("-x: don't fallback safely - in a comms error, exit with a TEMPFAIL error code\n");
-  printf("-t: timeout in seconds to read from spamd. 0 disables. [default: 600]\n\n");
-  printf("-H: randomize the IP addresses in the looked-up hostname\n");
-  printf("-U path: use UNIX domain socket with path\n");
+    printf
+	("-u username: specify the username for spamd to process this message under\n");
+    printf
+	("-x: don't fallback safely - in a comms error, exit with a TEMPFAIL error code\n");
+    printf
+	("-t: timeout in seconds to read from spamd. 0 disables. [default: 600]\n\n");
+    printf("-H: randomize the IP addresses in the looked-up hostname\n");
+    printf("-U path: use UNIX domain socket with path\n");
 }
 
 int
 read_args(int argc, char **argv, int *max_size, const char **username,
-	struct transport *ptrn)
+	  struct transport *ptrn)
 {
-  int opt;
+    int opt;
 
-  while(-1 != (opt = getopt(argc,argv,
+    while (-1 != (opt = getopt(argc, argv,
 #ifndef _WIN32
-                            "-BcrRd:e:fhyp:t:s:u:xSHU:"
+			       "-BcrRd:e:fhyp:t:s:u:xSHU:"
 #else
-                            "-BcrRd:fhyp:t:s:u:xSH"
+			       "-BcrRd:fhyp:t:s:u:xSH"
 #endif
-)))
-  {
-    switch(opt)
-    {
-    case 'H':
-      {
-        flags |= SPAMC_RANDOMIZE_HOSTS;
-        break;
-      }
+		  ))) {
+	switch (opt) {
+	case 'H':
+	    {
+		flags |= SPAMC_RANDOMIZE_HOSTS;
+		break;
+	    }
 #ifndef _WIN32
-    case 'U':
-      {
-        ptrn->type       = TRANSPORT_UNIX;
-        ptrn->socketpath = optarg;
-        break;
-      }
-#endif
-    case 'B':
-      {
-        flags = (flags & ~SPAMC_MODE_MASK) | SPAMC_BSMTP_MODE;
-        break;
-      }
-    case 'c':
-      {
-        flags |= SPAMC_CHECK_ONLY;
-	break;
-      }
-    case 'r':
-      {
-        flags |= SPAMC_REPORT_IFSPAM;
-	break;
-      }
-    case 'R':
-      {
-        flags |= SPAMC_REPORT;
-	break;
-      }
-    case 'y':
-      {
-        flags |= SPAMC_SYMBOLS;
-	break;
-      }
-    case 'd':
-      {
-        ptrn->type     = TRANSPORT_TCP;
-	ptrn->hostname = optarg;	/* fix the ptr to point to this string */
-	break;
-      }
+	case 'U':
+	    {
+		ptrn->type = TRANSPORT_UNIX;
+		ptrn->socketpath = optarg;
+		break;
+	    }
+#endif
+	case 'B':
+	    {
+		flags = (flags & ~SPAMC_MODE_MASK) | SPAMC_BSMTP_MODE;
+		break;
+	    }
+	case 'c':
+	    {
+		flags |= SPAMC_CHECK_ONLY;
+		break;
+	    }
+	case 'r':
+	    {
+		flags |= SPAMC_REPORT_IFSPAM;
+		break;
+	    }
+	case 'R':
+	    {
+		flags |= SPAMC_REPORT;
+		break;
+	    }
+	case 'y':
+	    {
+		flags |= SPAMC_SYMBOLS;
+		break;
+	    }
+	case 'd':
+	    {
+		ptrn->type = TRANSPORT_TCP;
+		ptrn->hostname = optarg;	/* fix the ptr to point to this string */
+		break;
+	    }
 #ifndef _WIN32
-    case 'e':
-      {
-        int i, j;
-        if((exec_argv=malloc(sizeof(*exec_argv)*(argc-optind+2)))==NULL)
-            return EX_OSERR;
-        for(i=0, j=optind-1; j<argc; i++, j++){
-            exec_argv[i]=argv[j];
-        }
-        exec_argv[i]=NULL;
-        return EX_OK;
-      }
-#endif
-    case 'p':
-      {
-	ptrn->port = atoi(optarg);
-	break;
-      }
-    case 'f':
-      {
-        flags |= SPAMC_SAFE_FALLBACK;
-	break;
-      }
-    case 'x':
-      {
-	flags &= (~SPAMC_SAFE_FALLBACK);
-	break;
-      }
-    case 'u':
-      {
-	*username = optarg;
-	break;
-      }
-    case 's':
-      {
-	*max_size = atoi(optarg);
-	break;
-      }
+	case 'e':
+	    {
+		int i, j;
+		if ((exec_argv =
+		     malloc(sizeof(*exec_argv) * (argc - optind + 2))) ==
+		    NULL)
+		    return EX_OSERR;
+		for (i = 0, j = optind - 1; j < argc; i++, j++) {
+		    exec_argv[i] = argv[j];
+		}
+		exec_argv[i] = NULL;
+		return EX_OK;
+	    }
+#endif
+	case 'p':
+	    {
+		ptrn->port = atoi(optarg);
+		break;
+	    }
+	case 'f':
+	    {
+		flags |= SPAMC_SAFE_FALLBACK;
+		break;
+	    }
+	case 'x':
+	    {
+		flags &= (~SPAMC_SAFE_FALLBACK);
+		break;
+	    }
+	case 'u':
+	    {
+		*username = optarg;
+		break;
+	    }
+	case 's':
+	    {
+		*max_size = atoi(optarg);
+		break;
+	    }
 #ifdef SPAMC_SSL
-    case 'S':
-      {
-	flags |= SPAMC_USE_SSL;
-	break;
-      }
-#endif
-    case 't':
-      {
-	timeout = atoi(optarg);
-	break;
-      }
-    case '?': {
-      syslog (LOG_ERR, "invalid usage");
-      /* NOTE: falls through to usage case below... */
-    }
-    case 'h':
-    case 1:
-      {
-	print_usage();
-	exit(EX_USAGE);
-      }
-    }
-  }
-  return EX_OK;
-}	
+	case 'S':
+	    {
+		flags |= SPAMC_USE_SSL;
+		break;
+	    }
+#endif
+	case 't':
+	    {
+		timeout = atoi(optarg);
+		break;
+	    }
+	case '?':{
+		syslog(LOG_ERR, "invalid usage");
+		/* NOTE: falls through to usage case below... */
+	    }
+	case 'h':
+	case 1:
+	    {
+		print_usage();
+		exit(EX_USAGE);
+	    }
+	}
+    }
+    return EX_OK;
+}
 
-void get_output_fd(int *fd){
+void get_output_fd(int *fd)
+{
 #ifndef _WIN32
     int fds[2];
     pid_t pid;
-#endif    
-    if(*fd!=-1) return;
-    if(exec_argv==NULL){
-        *fd=STDOUT_FILENO;
-        return;
+#endif
+    if (*fd != -1)
+	return;
+    if (exec_argv == NULL) {
+	*fd = STDOUT_FILENO;
+	return;
     }
 #ifndef _WIN32
-    if(pipe(fds)){
-        syslog(LOG_ERR, "pipe creation failed: %m");
-        exit(EX_OSERR);
-    }
-    pid=fork();
-    if(pid<0){
-        syslog(LOG_ERR, "fork failed: %m");
-        exit(EX_OSERR);
-    } else if(pid==0){
-        /* child process */
-        /* Normally you'd expect the parent process here, however that would
-         * screw up an invoker waiting on the death of the parent. So instead,
-         * we fork a child to feed the data and have the parent exec the new
-         * prog */
-        close(fds[0]);
-        *fd=fds[1];
-        return;
+    if (pipe(fds)) {
+	syslog(LOG_ERR, "pipe creation failed: %m");
+	exit(EX_OSERR);
+    }
+    pid = fork();
+    if (pid < 0) {
+	syslog(LOG_ERR, "fork failed: %m");
+	exit(EX_OSERR);
+    }
+    else if (pid == 0) {
+	/* child process */
+	/* Normally you'd expect the parent process here, however that would
+	 * screw up an invoker waiting on the death of the parent. So instead,
+	 * we fork a child to feed the data and have the parent exec the new
+	 * prog */
+	close(fds[0]);
+	*fd = fds[1];
+	return;
     }
     /* parent process (see above) */
     close(fds[1]);
-    if(dup2(fds[0], STDIN_FILENO)){
-        syslog(LOG_ERR, "redirection of stdin failed: %m");
-        exit(EX_OSERR);
+    if (dup2(fds[0], STDIN_FILENO)) {
+	syslog(LOG_ERR, "redirection of stdin failed: %m");
+	exit(EX_OSERR);
     }
-    close(fds[0]); /* no point in leaving extra fds lying around */
+    close(fds[0]);		/* no point in leaving extra fds lying around */
     execv(exec_argv[0], exec_argv);
     syslog(LOG_ERR, "exec failed: %m");
 #else
@@ -282,28 +293,29 @@
     exit(EX_OSERR);
 }
 
-int main (int argc, char **argv) {
-  int max_size = 250*1024;
-  const char *username = NULL;
-  int ret;
-  struct message m;
-  int out_fd;
-  struct transport trans;
-  int result;
+int main(int argc, char **argv)
+{
+    int max_size = 250 * 1024;
+    const char *username = NULL;
+    int ret;
+    struct message m;
+    int out_fd;
+    struct transport trans;
+    int result;
 
-  transport_init(&trans);
+    transport_init(&trans);
 
 #ifdef LIBSPAMC_UNIT_TESTS
-  /* unit test support; divert execution.  will not return */
-  do_libspamc_unit_tests();
+    /* unit test support; divert execution.  will not return */
+    do_libspamc_unit_tests();
 #endif
 
 #ifndef _WIN32
-  openlog ("spamc", LOG_CONS|LOG_PID, LOG_MAIL);
-  signal (SIGPIPE, SIG_IGN);
+    openlog("spamc", LOG_CONS | LOG_PID, LOG_MAIL);
+    signal(SIGPIPE, SIG_IGN);
 #endif
 
-  read_args(argc,argv, &max_size, &username, &trans);
+    read_args(argc, argv, &max_size, &username, &trans);
 
   /*--------------------------------------------------------------------
    * DETERMINE USER
@@ -317,31 +329,36 @@
    * some other part of the system overwriting it, so we copy the username
    * to our own buffer - then this won't arise as a problem.
    */
- 
+
 #ifndef _WIN32
-  if(NULL == username)
-  {
-  static char   userbuf[256];
-  struct passwd *curr_user;
-
-    curr_user = getpwuid(geteuid());
-    if (curr_user == NULL) {
-      perror ("getpwuid failed");
-            if(flags&SPAMC_CHECK_ONLY) { printf("0/0\n"); return EX_NOTSPAM; } else { return EX_OSERR; }
-    }
-    memset(userbuf, 0, sizeof userbuf);
-    strncpy(userbuf, curr_user->pw_name, sizeof userbuf - 1);
-    userbuf[sizeof userbuf - 1] = '\0';
-    username = userbuf;
-  }
-#endif
-
-  if ((flags & SPAMC_RANDOMIZE_HOSTS) != 0) {
-    /* we don't need strong randomness; this is just so we pick
-     * a random host for loadbalancing.
-     */
-    srand(getpid() ^ time(NULL));
-  }
+    if (NULL == username) {
+	static char userbuf[256];
+	struct passwd *curr_user;
+
+	curr_user = getpwuid(geteuid());
+	if (curr_user == NULL) {
+	    perror("getpwuid failed");
+	    if (flags & SPAMC_CHECK_ONLY) {
+		printf("0/0\n");
+		return EX_NOTSPAM;
+	    }
+	    else {
+		return EX_OSERR;
+	    }
+	}
+	memset(userbuf, 0, sizeof userbuf);
+	strncpy(userbuf, curr_user->pw_name, sizeof userbuf - 1);
+	userbuf[sizeof userbuf - 1] = '\0';
+	username = userbuf;
+    }
+#endif
+
+    if ((flags & SPAMC_RANDOMIZE_HOSTS) != 0) {
+	/* we don't need strong randomness; this is just so we pick
+	 * a random host for loadbalancing.
+	 */
+	srand(getpid() ^ time(NULL));
+    }
 
   /*--------------------------------------------------------------------
    * SET UP TRANSPORT
@@ -350,63 +367,68 @@
    * we connect to the spam daemon. Mainly this involves lookup up the
    * hostname and getting the IP addresses to connect to.
    */
-    m.type    = MESSAGE_NONE;
-  m.out = NULL;
-  m.raw = NULL;
-  m.priv = NULL;
+    m.type = MESSAGE_NONE;
+    m.out = NULL;
+    m.raw = NULL;
+    m.priv = NULL;
     m.max_len = max_size;
     m.timeout = timeout;
-  m.is_spam = EX_NOHOST; // default err code if can't reach the daemon
+    m.is_spam = EX_NOHOST;	// default err code if can't reach the daemon
 #ifdef _WIN32
-  setmode(STDIN_FILENO, O_BINARY);
-  setmode(STDOUT_FILENO, O_BINARY);
+    setmode(STDIN_FILENO, O_BINARY);
+    setmode(STDOUT_FILENO, O_BINARY);
 #endif
-  if ( (ret = transport_setup(&trans, flags)) == EX_OK ) {
-    out_fd=-1;
-
-    ret=message_read(STDIN_FILENO, flags, &m);
-    if(ret==EX_OK) {
-    ret=message_filter(&trans, username, flags, &m);
-      if(ret==EX_OK) {
-    get_output_fd(&out_fd);
-
-        if(message_write(out_fd, &m)>=0) {
+    if ((ret = transport_setup(&trans, flags)) == EX_OK) {
+	out_fd = -1;
 
-    result = m.is_spam;
-    if ((flags&SPAMC_CHECK_ONLY) && result != EX_TOOBIG) {
-      message_cleanup (&m);
-            ret = result;
-    } else {
-      message_cleanup (&m);
-          }
+	ret = message_read(STDIN_FILENO, flags, &m);
+	if (ret == EX_OK) {
+	    ret = message_filter(&trans, username, flags, &m);
+	    if (ret == EX_OK) {
+		get_output_fd(&out_fd);
+
+		if (message_write(out_fd, &m) >= 0) {
+
+		    result = m.is_spam;
+		    if ((flags & SPAMC_CHECK_ONLY) && result != EX_TOOBIG) {
+			message_cleanup(&m);
+			ret = result;
+		    }
+		    else {
+			message_cleanup(&m);
+		    }
 #ifdef _WIN32
-          WSACleanup();
+		    WSACleanup();
 #endif
-      return ret;
-    }
-      }
+		    return ret;
+		}
+	    }
+	}
     }
-  }
 
 /* FAIL: */
     get_output_fd(&out_fd);
 
     result = m.is_spam;
-    if((flags&SPAMC_CHECK_ONLY) && result != EX_TOOBIG) {
+    if ((flags & SPAMC_CHECK_ONLY) && result != EX_TOOBIG) {
 	/* probably, the write to stdout failed; we can still report exit code */
-	message_cleanup (&m);
-      ret = result;      
-    } else if(flags&SPAMC_CHECK_ONLY || flags&SPAMC_REPORT || flags&SPAMC_REPORT_IFSPAM) {
-      full_write(out_fd, 1, "0/0\n", 4);
-	message_cleanup (&m);
-      ret = EX_NOTSPAM;      
-    } else {
-        message_dump(STDIN_FILENO, out_fd, &m);
-	message_cleanup (&m);
-        if (ret == EX_TOOBIG) {
-        ret = 0;
-        } else if (flags & SPAMC_SAFE_FALLBACK) {
-        ret = EX_OK;
+	message_cleanup(&m);
+	ret = result;
+    }
+    else if (flags & SPAMC_CHECK_ONLY || flags & SPAMC_REPORT
+	     || flags & SPAMC_REPORT_IFSPAM) {
+	full_write(out_fd, 1, "0/0\n", 4);
+	message_cleanup(&m);
+	ret = EX_NOTSPAM;
+    }
+    else {
+	message_dump(STDIN_FILENO, out_fd, &m);
+	message_cleanup(&m);
+	if (ret == EX_TOOBIG) {
+	    ret = 0;
+	}
+	else if (flags & SPAMC_SAFE_FALLBACK) {
+	    ret = EX_OK;
 	}
     }
 #ifdef _WIN32

Modified: incubator/spamassassin/trunk/spamc/utils.c
==============================================================================
--- incubator/spamassassin/trunk/spamc/utils.c	(original)
+++ incubator/spamassassin/trunk/spamc/utils.c	Fri Jan 30 20:18:08 2004
@@ -43,180 +43,181 @@
 
 /* -------------------------------------------------------------------------- */
 #ifndef _WIN32
-typedef void    sigfunc(int);   /* for signal handlers */
+typedef void sigfunc(int);	/* for signal handlers */
 
-sigfunc* sig_catch(int sig, void (*f)(int))
+sigfunc *sig_catch(int sig, void (*f) (int))
 {
-  struct sigaction act, oact;
-  act.sa_handler = f;
-  act.sa_flags = 0;
-  sigemptyset(&act.sa_mask);
-  sigaction(sig, &act, &oact);
-  return oact.sa_handler;
+    struct sigaction act, oact;
+    act.sa_handler = f;
+    act.sa_flags = 0;
+    sigemptyset(&act.sa_mask);
+    sigaction(sig, &act, &oact);
+    return oact.sa_handler;
 }
 
-static void catch_alrm(int x) {
-  UNUSED_VARIABLE(x);
+static void catch_alrm(int x)
+{
+    UNUSED_VARIABLE(x);
 }
 #endif
 
-ssize_t
-fd_timeout_read (int fd, char fdflag, void *buf, size_t nbytes)
+ssize_t fd_timeout_read(int fd, char fdflag, void *buf, size_t nbytes)
 {
-  ssize_t nred;
-  int origerr;
+    ssize_t nred;
+    int origerr;
 #ifndef _WIN32
-  sigfunc* sig;
+    sigfunc *sig;
 
-  sig = sig_catch(SIGALRM, catch_alrm);
-  if (libspamc_timeout > 0) {
-    alarm(libspamc_timeout);
-  }
+    sig = sig_catch(SIGALRM, catch_alrm);
+    if (libspamc_timeout > 0) {
+	alarm(libspamc_timeout);
+    }
 #endif
 
-  do {
-    if (fdflag) {
-    nred = read (fd, buf, nbytes);
-      origerr = errno;
-    } else {
-      nred = recv (fd, buf, nbytes, 0);
+    do {
+	if (fdflag) {
+	    nred = read(fd, buf, nbytes);
+	    origerr = errno;
+	}
+	else {
+	    nred = recv(fd, buf, nbytes, 0);
 #ifndef _WIN32
-      origerr = errno;
+	    origerr = errno;
 #else
-      origerr = WSAGetLastError();
+	    origerr = WSAGetLastError();
 #endif
-    }
-  } while(nred < 0 && origerr == EWOULDBLOCK);
+	}
+    } while (nred < 0 && origerr == EWOULDBLOCK);
 
 #ifndef _WIN32
-  if(nred < 0 && origerr == EINTR)
-    errno = ETIMEDOUT;
+    if (nred < 0 && origerr == EINTR)
+	errno = ETIMEDOUT;
 
-  if (libspamc_timeout > 0) {
-    alarm(0);
-  }
+    if (libspamc_timeout > 0) {
+	alarm(0);
+    }
 
-  /* restore old signal handler */
-  sig_catch(SIGALRM, sig);
+    /* restore old signal handler */
+    sig_catch(SIGALRM, sig);
 #endif
 
-  return nred;
+    return nred;
 }
 
-int
-ssl_timeout_read (SSL *ssl, void *buf, int nbytes)
+int ssl_timeout_read(SSL * ssl, void *buf, int nbytes)
 {
-  int nred;
+    int nred;
 
 #ifndef _WIN32
-  sigfunc* sig;
+    sigfunc *sig;
 
-  sig = sig_catch(SIGALRM, catch_alrm);
-  if (libspamc_timeout > 0) {
-    alarm(libspamc_timeout);
-  }
+    sig = sig_catch(SIGALRM, catch_alrm);
+    if (libspamc_timeout > 0) {
+	alarm(libspamc_timeout);
+    }
 #endif
 
-  do {
+    do {
 
 #ifdef SPAMC_SSL
-    nred = SSL_read (ssl, buf, nbytes);
+	nred = SSL_read(ssl, buf, nbytes);
 #else
-    UNUSED_VARIABLE(ssl);
-    UNUSED_VARIABLE(buf);
-    UNUSED_VARIABLE(nbytes);
-    nred = 0;			/* never used */
+	UNUSED_VARIABLE(ssl);
+	UNUSED_VARIABLE(buf);
+	UNUSED_VARIABLE(nbytes);
+	nred = 0;		/* never used */
 #endif
 
-  } while(nred < 0 && errno == EWOULDBLOCK);
+    } while (nred < 0 && errno == EWOULDBLOCK);
 
 #ifndef _WIN32
-  if(nred < 0 && errno == EINTR)
-    errno = ETIMEDOUT;
+    if (nred < 0 && errno == EINTR)
+	errno = ETIMEDOUT;
 
-  if (libspamc_timeout > 0) {
-    alarm(0);
-  }
+    if (libspamc_timeout > 0) {
+	alarm(0);
+    }
 
-  /* restore old signal handler */
-  sig_catch(SIGALRM, sig);
+    /* restore old signal handler */
+    sig_catch(SIGALRM, sig);
 #endif
 
-  return nred;
+    return nred;
 }
 
 /* -------------------------------------------------------------------------- */
 
-int
-full_read (int fd, char fdflag, void *vbuf, int min, int len)
+int full_read(int fd, char fdflag, void *vbuf, int min, int len)
 {
-  unsigned char *buf = (unsigned char *)vbuf;
-  int total;
-  int thistime;
+    unsigned char *buf = (unsigned char *) vbuf;
+    int total;
+    int thistime;
+
+    for (total = 0; total < min;) {
+	thistime = fd_timeout_read(fd, fdflag, buf + total, len - total);
+
+	if (thistime < 0) {
+	    return -1;
+	}
+	else if (thistime == 0) {
+	    /* EOF, but we didn't read the minimum.  return what we've read
+	     * so far and next read (if there is one) will return 0. */
+	    return total;
+	}
 
-  for (total = 0; total < min; ) {
-    thistime = fd_timeout_read (fd, fdflag, buf+total, len-total);
-
-    if (thistime < 0) {
-      return -1;
-    } else if (thistime == 0) {
-      /* EOF, but we didn't read the minimum.  return what we've read
-       * so far and next read (if there is one) will return 0. */
-      return total;
+	total += thistime;
     }
-
-    total += thistime;
-  }
-  return total;
+    return total;
 }
 
-int
-full_read_ssl (SSL *ssl, unsigned char *buf, int min, int len)
+int full_read_ssl(SSL * ssl, unsigned char *buf, int min, int len)
 {
-  int total;
-  int thistime;
+    int total;
+    int thistime;
 
-  for (total = 0; total < min; ) {
-    thistime = ssl_timeout_read (ssl, buf+total, len-total);
+    for (total = 0; total < min;) {
+	thistime = ssl_timeout_read(ssl, buf + total, len - total);
 
-    if (thistime < 0) {
-      return -1;
-    } else if (thistime == 0) {
-      /* EOF, but we didn't read the minimum.  return what we've read
-       * so far and next read (if there is one) will return 0. */
-      return total;
-    }
+	if (thistime < 0) {
+	    return -1;
+	}
+	else if (thistime == 0) {
+	    /* EOF, but we didn't read the minimum.  return what we've read
+	     * so far and next read (if there is one) will return 0. */
+	    return total;
+	}
 
-    total += thistime;
-  }
-  return total;
+	total += thistime;
+    }
+    return total;
 }
 
-int
-full_write (int fd, char fdflag, const void *vbuf, int len)
+int full_write(int fd, char fdflag, const void *vbuf, int len)
 {
-  const unsigned char *buf = (const unsigned char *)vbuf;
-  int total;
-  int thistime;
-  int origerr;
+    const unsigned char *buf = (const unsigned char *) vbuf;
+    int total;
+    int thistime;
+    int origerr;
 
-  for (total = 0; total < len; ) {
-    if (fdflag) {
-    thistime = write (fd, buf+total, len-total);
-      origerr = errno;
-    } else {
-      thistime = send (fd, buf+total, len-total, 0);
+    for (total = 0; total < len;) {
+	if (fdflag) {
+	    thistime = write(fd, buf + total, len - total);
+	    origerr = errno;
+	}
+	else {
+	    thistime = send(fd, buf + total, len - total, 0);
 #ifndef _WIN32
-      origerr = errno;
+	    origerr = errno;
 #else
-      origerr = WSAGetLastError();
+	    origerr = WSAGetLastError();
 #endif
+	}
+	if (thistime < 0) {
+	    if (EINTR == origerr || EWOULDBLOCK == origerr)
+		continue;
+	    return thistime;	/* always an error for writes */
+	}
+	total += thistime;
     }
-    if (thistime < 0) {
-      if(EINTR == origerr || EWOULDBLOCK == origerr) continue;
-      return thistime;        /* always an error for writes */
-    }
-    total += thistime;
-  }
-  return total;
+    return total;
 }

Modified: incubator/spamassassin/trunk/spamc/utils.h
==============================================================================
--- incubator/spamassassin/trunk/spamc/utils.h	(original)
+++ incubator/spamassassin/trunk/spamc/utils.h	Fri Jan 30 20:18:08 2004
@@ -21,7 +21,7 @@
 
 #define UNUSED_VARIABLE(v)	((void)(v))
 
-extern int libspamc_timeout;  /* default timeout in seconds */
+extern int libspamc_timeout;	/* default timeout in seconds */
 
 #ifdef SPAMC_SSL
 #include <openssl/crypto.h>
@@ -29,9 +29,9 @@
 #include <openssl/ssl.h>
 #include <openssl/err.h>
 #else
-typedef int	SSL;	/* fake type to avoid conditional compilation */
-typedef int	SSL_CTX;
-typedef int	SSL_METHOD;
+typedef int SSL;		/* fake type to avoid conditional compilation */
+typedef int SSL_CTX;
+typedef int SSL_METHOD;
 #endif
 #ifdef _WIN32
 #include <winsock.h>
@@ -40,58 +40,58 @@
 // BSD-compatible socket error codes for Win32
 //
 
-#define EWOULDBLOCK             WSAEWOULDBLOCK 
-#define EINPROGRESS             WSAEINPROGRESS 
-#define EALREADY                WSAEALREADY 
-#define ENOTSOCK                WSAENOTSOCK 
-#define EDESTADDRREQ            WSAEDESTADDRREQ 
-#define EMSGSIZE                WSAEMSGSIZE 
-#define EPROTOTYPE              WSAEPROTOTYPE 
-#define ENOPROTOOPT             WSAENOPROTOOPT 
-#define EPROTONOSUPPORT         WSAEPROTONOSUPPORT 
-#define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT 
-#define EOPNOTSUPP              WSAEOPNOTSUPP 
-#define EPFNOSUPPORT            WSAEPFNOSUPPORT 
-#define EAFNOSUPPORT            WSAEAFNOSUPPORT 
-#define EADDRINUSE              WSAEADDRINUSE 
-#define EADDRNOTAVAIL           WSAEADDRNOTAVAIL 
-#define ENETDOWN                WSAENETDOWN 
-#define ENETUNREACH             WSAENETUNREACH 
-#define ENETRESET               WSAENETRESET 
-#define ECONNABORTED            WSAECONNABORTED 
-#define ECONNRESET              WSAECONNRESET 
-#define ENOBUFS                 WSAENOBUFS 
-#define EISCONN                 WSAEISCONN 
-#define ENOTCONN                WSAENOTCONN 
-#define ESHUTDOWN               WSAESHUTDOWN 
-#define ETOOMANYREFS            WSAETOOMANYREFS 
-#define ETIMEDOUT               WSAETIMEDOUT 
-#define ECONNREFUSED            WSAECONNREFUSED 
-#define ELOOP                   WSAELOOP 
+#define EWOULDBLOCK             WSAEWOULDBLOCK
+#define EINPROGRESS             WSAEINPROGRESS
+#define EALREADY                WSAEALREADY
+#define ENOTSOCK                WSAENOTSOCK
+#define EDESTADDRREQ            WSAEDESTADDRREQ
+#define EMSGSIZE                WSAEMSGSIZE
+#define EPROTOTYPE              WSAEPROTOTYPE
+#define ENOPROTOOPT             WSAENOPROTOOPT
+#define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
+#define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
+#define EOPNOTSUPP              WSAEOPNOTSUPP
+#define EPFNOSUPPORT            WSAEPFNOSUPPORT
+#define EAFNOSUPPORT            WSAEAFNOSUPPORT
+#define EADDRINUSE              WSAEADDRINUSE
+#define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
+#define ENETDOWN                WSAENETDOWN
+#define ENETUNREACH             WSAENETUNREACH
+#define ENETRESET               WSAENETRESET
+#define ECONNABORTED            WSAECONNABORTED
+#define ECONNRESET              WSAECONNRESET
+#define ENOBUFS                 WSAENOBUFS
+#define EISCONN                 WSAEISCONN
+#define ENOTCONN                WSAENOTCONN
+#define ESHUTDOWN               WSAESHUTDOWN
+#define ETOOMANYREFS            WSAETOOMANYREFS
+#define ETIMEDOUT               WSAETIMEDOUT
+#define ECONNREFUSED            WSAECONNREFUSED
+#define ELOOP                   WSAELOOP
 // #define ENAMETOOLONG            WSAENAMETOOLONG
-#define EHOSTDOWN               WSAEHOSTDOWN 
-#define EHOSTUNREACH            WSAEHOSTUNREACH 
+#define EHOSTDOWN               WSAEHOSTDOWN
+#define EHOSTUNREACH            WSAEHOSTUNREACH
 // #define ENOTEMPTY               WSAENOTEMPTY
-#define EPROCLIM                WSAEPROCLIM 
-#define EUSERS                  WSAEUSERS 
-#define EDQUOT                  WSAEDQUOT 
-#define ESTALE                  WSAESTALE 
-#define EREMOTE                 WSAEREMOTE 
+#define EPROCLIM                WSAEPROCLIM
+#define EUSERS                  WSAEUSERS
+#define EDQUOT                  WSAEDQUOT
+#define ESTALE                  WSAESTALE
+#define EREMOTE                 WSAEREMOTE
 
 // NOTE: these are not errno constants in UNIX!
-#define HOST_NOT_FOUND          WSAHOST_NOT_FOUND 
-#define TRY_AGAIN               WSATRY_AGAIN 
-#define NO_RECOVERY             WSANO_RECOVERY 
-#define NO_DATA                 WSANO_DATA 
+#define HOST_NOT_FOUND          WSAHOST_NOT_FOUND
+#define TRY_AGAIN               WSATRY_AGAIN
+#define NO_RECOVERY             WSANO_RECOVERY
+#define NO_DATA                 WSANO_DATA
 
 #endif
 
-ssize_t fd_timeout_read (int fd, char fdflag, void *, size_t );  
-int ssl_timeout_read (SSL *ssl, void *, int );  
+ssize_t fd_timeout_read(int fd, char fdflag, void *, size_t);
+int ssl_timeout_read(SSL * ssl, void *, int);
 
 /* these are fd-only, no SSL support */
 int full_read(int fd, char fdflag, void *buf, int min, int len);
-int full_read_ssl(SSL *ssl, unsigned char *buf, int min, int len);
+int full_read_ssl(SSL * ssl, unsigned char *buf, int min, int len);
 int full_write(int fd, char fdflag, const void *buf, int len);
 
 #endif

Mime
View raw message