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