$Log$
+ Revision 641.13 2005/03/02 03:01:18 ajc
+ * serv_spam.c: use redirect_buffer instead of redirect_sock
+ * Removed redirect_sock from the API. redirect_fp is next!
+
Revision 641.12 2005/03/02 02:42:06 ajc
* Finished moving the POP3 server to the new redirect_buffer semantics
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
-
* Load the message into a temp file for translation
* and measurement
*/
- CtdlRedirectOutput(tmp, -1);
+ CtdlRedirectOutput(tmp);
CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1);
- CtdlRedirectOutput(NULL, -1);
+ CtdlRedirectOutput(NULL);
IMAP->cached_fetch = tmp;
IMAP->cached_msgnum = msgnum;
tmp = IMAP->cached_body;
}
else if ( (!strcmp(section, "1")) && (msg->cm_format_type != 4) ) {
- CtdlRedirectOutput(tmp, -1);
+ CtdlRedirectOutput(tmp);
CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822,
HEADERS_NONE, 0, 1);
- CtdlRedirectOutput(NULL, -1);
+ CtdlRedirectOutput(NULL);
}
else if (!strcmp(section, "")) {
- CtdlRedirectOutput(tmp, -1);
+ CtdlRedirectOutput(tmp);
/* lprintf(CTDL_DEBUG, "calling CtdlOutputPreLoadedMsg()\n");
lprintf(CTDL_DEBUG, "msg %s null\n", ((msg == NULL) ? "is" : "is not") );
lprintf(CTDL_DEBUG, "msgnum is %ld\n", msgnum); */
CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822,
HEADERS_ALL, 0, 1);
- CtdlRedirectOutput(NULL, -1);
+ CtdlRedirectOutput(NULL);
}
/*
* fields, strip it down.
*/
else if (!strncasecmp(section, "HEADER", 6)) {
- CtdlRedirectOutput(tmp, -1);
+ CtdlRedirectOutput(tmp);
/* lprintf(CTDL_DEBUG, "calling CtdlOutputPreLoadedMsg()\n");
lprintf(CTDL_DEBUG, "msg %s null\n", ((msg == NULL) ? "is" : "is not") );
lprintf(CTDL_DEBUG, "msgnum is %ld\n", msgnum); */
CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822,
HEADERS_ONLY, 0, 1);
- CtdlRedirectOutput(NULL, -1);
+ CtdlRedirectOutput(NULL);
imap_strip_headers(tmp, section);
}
* Strip it down if the client asked for everything _except_ headers.
*/
else if (!strncasecmp(section, "TEXT", 4)) {
- CtdlRedirectOutput(tmp, -1);
+ CtdlRedirectOutput(tmp);
/* lprintf(CTDL_DEBUG, "calling CtdlOutputPreLoadedMsg()\n");
lprintf(CTDL_DEBUG, "msg %s null\n", ((msg == NULL) ? "is" : "is not") );
lprintf(CTDL_DEBUG, "msgnum is %ld\n", msgnum); */
CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822,
HEADERS_NONE, 0, 1);
- CtdlRedirectOutput(NULL, -1);
+ CtdlRedirectOutput(NULL);
}
/*
*/
tmp = tmpfile();
if (tmp == NULL) return;
- CtdlRedirectOutput(tmp, -1);
+ CtdlRedirectOutput(tmp);
CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, 0, 0, 1);
- CtdlRedirectOutput(NULL, -1);
+ CtdlRedirectOutput(NULL);
rewind(tmp);
while (fgets(buf, sizeof buf, tmp) != NULL) {
fprintf(sc->digestfp, " -----------------------------------"
"------------------------------------"
"-------\n");
- CtdlRedirectOutput(sc->digestfp, -1);
+ CtdlRedirectOutput(sc->digestfp);
CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 0);
- CtdlRedirectOutput(NULL, -1);
+ CtdlRedirectOutput(NULL);
sc->num_msgs_spooled += 1;
}
return;
}
else {
- CtdlRedirectOutput(msg_fp, -1);
+ CtdlRedirectOutput(msg_fp);
CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1);
- CtdlRedirectOutput(NULL, -1);
+ CtdlRedirectOutput(NULL);
fseek(msg_fp, 0L, SEEK_END);
msg_size = ftell(msg_fp);
}
char buf[SIZ];
int is_spam = 0;
int sa;
+ char *msgtext;
+ size_t msglen;
/* For users who have authenticated to this server we never want to
* apply spam filtering, because presumably they're trustworthy.
sock_write(sock, buf, strlen(buf));
/* Message */
- CtdlRedirectOutput(NULL, sock);
+ CC->redirect_buffer = malloc(SIZ);
+ CC->redirect_len = 0;
+ CC->redirect_alloc = SIZ;
CtdlOutputPreLoadedMsg(msg, 0L, MT_RFC822, HEADERS_ALL, 0, 1);
- CtdlRedirectOutput(NULL, -1);
+ CC->redirect_buffer[CC->redirect_len] = 0;
+ msgtext = CC->redirect_buffer;
+ msglen = CC->redirect_len;
+ CC->redirect_buffer = NULL;
+ CC->redirect_len = 0;
+ CC->redirect_alloc = 0;
+
+ sock_write(sock, msgtext, msglen);
+ free(msgtext);
/* Close one end of the socket connection; this tells SpamAssassin
* that we're done.
char cs_nonce[NONCE_SIZE]; /* The nonce for this session's next auth transaction */
/* Redirect this session's output to somewhere else? */
- FILE *redirect_fp;
- int redirect_sock;
+ FILE *redirect_fp; /* a file instead (will go away) */
char *redirect_buffer; /* the buffer */
size_t redirect_len; /* length of data in buffer */
size_t redirect_alloc; /* length of allocated buffer */
{
int bytes_written = 0;
int retval;
- int sock;
#ifndef HAVE_TCP_BUFFERING
int old_buffer_len = 0;
#endif
return;
}
- if (CC->redirect_sock > 0) {
- sock = CC->redirect_sock; /* and continue below... */
- }
- else {
- sock = CC->client_socket;
- }
-
#ifndef HAVE_TCP_BUFFERING
/* If we're buffering for later, do that now. */
if (CC->buffering) {
#endif
while (bytes_written < nbytes) {
- retval = write(sock, &buf[bytes_written],
+ retval = write(CC->client_socket, &buf[bytes_written],
nbytes - bytes_written);
if (retval < 1) {
lprintf(CTDL_ERR, "client_write() failed: %s\n",
strerror(errno));
- if (sock == CC->client_socket) CC->kill_me = 1;
+ CC->kill_me = 1;
return;
}
bytes_written = bytes_written + retval;
/*
- * Redirect a session's output to a file or socket.
- * This function may be called with a file handle *or* a socket (but not
- * both). Call with neither to return output to its normal client socket.
+ * Redirect a session's output to a file.
+ * This function may be called with a file handle.
+ * Call with NULL to return output to its normal client socket.
*/
-void CtdlRedirectOutput(FILE *fp, int sock) {
-
+void CtdlRedirectOutput(FILE *fp)
+{
if (fp != NULL) CC->redirect_fp = fp;
else CC->redirect_fp = NULL;
-
- if (sock > 0) CC->redirect_sock = sock;
- else CC->redirect_sock = (-1);
-
}
int convert_login (char *NameToConvert);
void *worker_thread (void *arg);
void become_session(struct CitContext *which_con);
-void CtdlRedirectOutput(FILE *fp, int sock);
+void CtdlRedirectOutput(FILE *fp);
void InitializeMasterCC(void);
void init_master_fdset(void);
void create_worker(void);