diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-01-08 12:55:58 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-01-08 18:46:12 +0200 |
commit | 537d254b0836ac1b2be629edf381d1bf0cbc1061 (patch) | |
tree | d5e2e208f999abd2aa1ae32532e7c7f4b2d3013c | |
parent | 028b820e468880abe113193dd79b31ccc17b0068 (diff) | |
download | mailfromd-537d254b0836ac1b2be629edf381d1bf0cbc1061.tar.gz mailfromd-537d254b0836ac1b2be629edf381d1bf0cbc1061.tar.bz2 |
sa,clamav: bugfixes.
* lib/server.c (mf_server_check_pidfile): Use mu_program_name.
* src/builtin/sa.bi: Major cleanup.
(set_xscript): Do not switch to MU_XSCRIPT_PAYLOAD at once.
(spamd_send_stream): New function.
(spamd_connect): Do not unreference transport streams.
(open_connection): Use _aget to obtain path.
(sa,clamav): Rewind message stream; use spamd_send_stream to
send it.
* src/builtin/mail.bi (build_mime): Reposition the stream to its
beginning.
-rw-r--r-- | lib/server.c | 4 | ||||
-rw-r--r-- | src/builtin/mail.bi | 6 | ||||
-rw-r--r-- | src/builtin/sa.bi | 124 |
3 files changed, 92 insertions, 42 deletions
diff --git a/lib/server.c b/lib/server.c index b5328a08..9a0c326c 100644 --- a/lib/server.c +++ b/lib/server.c @@ -1,5 +1,5 @@ /* This file is part of Mailfromd. - Copyright (C) 2005, 2006, 2007, 2008, 2010 Sergey Poznyakoff + Copyright (C) 2005, 2006, 2007, 2008, 2010, 2011 Sergey Poznyakoff This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -55,7 +55,7 @@ mf_server_check_pidfile(const char *name) } else { if (kill(pid, 0) == 0) { mu_error(_("%s appears to run with pid %lu. If it does not, remove `%s' and retry."), - program_invocation_short_name, + mu_program_name, pid, name); exit(EX_USAGE); diff --git a/src/builtin/mail.bi b/src/builtin/mail.bi index 390ee48a..6134bb86 100644 --- a/src/builtin/mail.bi +++ b/src/builtin/mail.bi @@ -1,5 +1,5 @@ /* This file is part of Mailfromd. -*- c -*- - Copyright (C) 2006, 2007, 2008, 2009, 2010 Sergey Poznyakoff + Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Sergey Poznyakoff This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -246,7 +246,9 @@ build_mime(mu_mime_t *pmime, mu_stream_t msgstr, mu_mime_create(&mime, NULL, 0); mime_create_reason(mime, sender, text); mime_create_ds(mime, recpt); - status = mime_create_quote(mime, msgstr); + status = mu_stream_seek(msgstr, 0, MU_SEEK_SET, NULL); + if (status == 0) + status = mime_create_quote(mime, msgstr); if (status) { mu_mime_destroy (&mime); return status; diff --git a/src/builtin/sa.bi b/src/builtin/sa.bi index 2a304a14..1e872c6b 100644 --- a/src/builtin/sa.bi +++ b/src/builtin/sa.bi @@ -1,5 +1,5 @@ /* This file is part of Mailfromd. -*- c -*- - Copyright (C) 2006, 2007, 2008, 2009, 2010 Sergey Poznyakoff + Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Sergey Poznyakoff This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -35,38 +35,68 @@ set_xscript(mu_stream_t *pstr) if (mu_debug_level_p(debug_handle, MU_DEBUG_PROT)) { int rc; - mu_stream_t dstr, xstr; + mu_stream_t dstr; rc = mu_dbgstream_create(&dstr, MU_DIAG_DEBUG); if (rc) mu_error(_("cannot create debug stream; " "transcript disabled: %s"), - mu_strerror (rc)); + mu_strerror(rc)); else { - rc = mu_xscript_stream_create(&xstr, tstr, dstr, NULL); + rc = mu_xscript_stream_create(pstr, tstr, dstr, NULL); + mu_stream_unref(dstr); if (rc) - mu_error (_("cannot create transcript " - "stream: %s"), - mu_strerror (rc)); - else { + mu_error(_("cannot create transcript " + "stream: %s"), + mu_strerror(rc)); + else mu_stream_unref(tstr); - tstr = xstr; - if (mu_debug_level_p(debug_handle, - MU_DEBUG_TRACE9)) { - int xlev = MU_XSCRIPT_PAYLOAD; - mu_stream_ioctl (tstr, - MU_IOCTL_XSCRIPTSTREAM, - MU_IOCTL_XSCRIPTSTREAM_LEVEL, - &xlev); - } - *pstr = tstr; - } } } return rc; } static int +spamd_send_stream(mu_stream_t out, mu_stream_t in) +{ + int rc; + struct mu_buffer_query newbuf, oldbuf; + int bufchg = 0; + int xlev; + int xlevchg = 0; + + /* Ensure effective transport buffering */ + if (mu_stream_ioctl(out, MU_IOCTL_TRANSPORT_BUFFER, + MU_IOCTL_OP_GET, &oldbuf) == 0) { + newbuf.type = MU_TRANSPORT_OUTPUT; + newbuf.buftype = mu_buffer_full; + newbuf.bufsize = 64*1024; + mu_stream_ioctl(out, MU_IOCTL_TRANSPORT_BUFFER, MU_IOCTL_OP_SET, + &newbuf); + bufchg = 1; + } + + if (!mu_debug_level_p(debug_handle, MU_DEBUG_TRACE9)) { + /* Mark out the following data as payload */ + xlev = MU_XSCRIPT_PAYLOAD; + if (mu_stream_ioctl(out, MU_IOCTL_XSCRIPTSTREAM, + MU_IOCTL_XSCRIPTSTREAM_LEVEL, &xlev) == 0) + xlevchg = 1; + } + + rc = mu_stream_copy(out, in, 0, NULL); + + /* Restore prior transport buffering and xscript level */ + if (bufchg) + mu_stream_ioctl(out, MU_IOCTL_TRANSPORT_BUFFER, MU_IOCTL_OP_SET, &oldbuf); + if (xlevchg) + mu_stream_ioctl(out, MU_IOCTL_XSCRIPTSTREAM, + MU_IOCTL_XSCRIPTSTREAM_LEVEL, &xlev); + return rc; +} + + +static int spamd_connect(eval_environ_t env, mu_stream_t *pstream, const char *host, int port) { @@ -81,27 +111,33 @@ spamd_connect(eval_environ_t env, mu_stream_t *pstream, fname = "mu_socket_stream_create"; rc = mu_socket_stream_create(&tstr, host, MU_STREAM_RDWR); } - mu_stream_set_buffer (tstr, mu_buffer_line, 0); - + MF_ASSERT(rc == 0, mfe_failure, "%s: %s", fname, mu_strerror(rc)); + mu_stream_set_buffer (tstr, mu_buffer_line, 0); + rc = mu_filter_create(&istr, tstr, "CRLF", MU_FILTER_DECODE, MU_FILTER_READ); - mu_stream_unref(tstr); - MF_ASSERT(rc == 0, mfe_failure, - "%s input filter: %s", - fname, mu_strerror(rc)); - mu_stream_set_buffer (istr, mu_buffer_line, 0); + if (rc) { + mu_stream_unref(tstr); + MF_THROW(mfe_failure, + "%s input filter: %s", + fname, mu_strerror(rc)); + } + mu_stream_set_buffer(istr, mu_buffer_line, 0); rc = mu_filter_create(&ostr, tstr, "CRLF", MU_FILTER_ENCODE, MU_FILTER_WRITE); + if (rc) { + mu_stream_unref(tstr); + MF_THROW(mfe_failure, + "%s output filter: %s", + fname, mu_strerror(rc)); + } + mu_stream_set_buffer(ostr, mu_buffer_line, 0); mu_stream_unref(tstr); - MF_ASSERT(rc == 0, mfe_failure, - "%s output filter: %s", - fname, mu_strerror(rc)); - mu_stream_set_buffer (ostr, mu_buffer_line, 0); rc = mu_iostream_create(&tstr, istr, ostr); mu_stream_unref(istr); @@ -109,7 +145,7 @@ spamd_connect(eval_environ_t env, mu_stream_t *pstream, MF_ASSERT(rc == 0, mfe_failure, "I/O stream: %s", mu_strerror(rc)); - mu_stream_set_buffer (tstr, mu_buffer_line, 0); + mu_stream_set_buffer(tstr, mu_buffer_line, 0); set_xscript(&tstr); *pstream = tstr; return rc; @@ -200,7 +236,7 @@ sigpipe_handler (int sig) mu_stream_t open_connection(eval_environ_t env, char *urlstr, char **phost) { - const char *path = NULL; + char *path = NULL; short port = 0; mu_stream_t str = NULL; int rc; @@ -228,7 +264,7 @@ open_connection(eval_environ_t env, char *urlstr, char **phost) if (strcmp(buf, "file") == 0 || strcmp(buf, "socket") == 0) { - if (rc = mu_url_sget_path(url, &path)) { + if (rc = mu_url_aget_path(url, &path)) { MF_THROW(mfe_url, _("%s: cannot get path: %s"), urlstr, mu_strerror(rc)); @@ -250,7 +286,7 @@ open_connection(eval_environ_t env, char *urlstr, char **phost) n); } - if (rc = mu_url_sget_host(url, &path)) { + if (rc = mu_url_aget_host(url, &path)) { mu_url_destroy(&url); MF_THROW(mfe_url, _("%s: cannot get host: %s"), @@ -267,7 +303,7 @@ open_connection(eval_environ_t env, char *urlstr, char **phost) if (rc == 0 && phost) { if (port) - *phost = strdup(path); + *phost = path; else *phost = NULL; } @@ -299,6 +335,12 @@ MF_DEFUN(sa, NUMBER, STRING urlstr, NUMBER prec, OPTIONAL, NUMBER report) "mu_stream_size: %s", mu_strerror (rc)); + rc = mu_stream_seek(mstr, 0, SEEK_SET, NULL); + MF_ASSERT(rc == 0, + mfe_failure, + "mu_stream_seek: %s", + mu_strerror(rc)); + ostr = open_connection(env, urlstr, NULL); msize += env_get_line_count(env); @@ -311,7 +353,7 @@ MF_DEFUN(sa, NUMBER, STRING urlstr, NUMBER prec, OPTIONAL, NUMBER report) got_sigpipe = 0; handler = set_signal_handler(SIGPIPE, sigpipe_handler); mu_stream_write(ostr, "\n", 1, NULL); - if (rc = mu_stream_copy(ostr, mstr, 0, NULL)) { + if (rc = spamd_send_stream(ostr, mstr)) { mu_stream_destroy(&ostr); MF_THROW(mfe_failure, _("send stream failed: %s"), @@ -413,7 +455,6 @@ MF_STATE(eom) MF_CAPTURE MF_DEFUN(clamav, NUMBER, STRING urlstr) { - mu_stream_t mstr = env_get_stream(env); mu_stream_t cstr, dstr; char *buffer = NULL; size_t bufsize = 0; @@ -422,6 +463,13 @@ MF_DEFUN(clamav, NUMBER, STRING urlstr) int rc; signal_handler_fn handler; char *p; + mu_stream_t mstr = env_get_stream(env); + + rc = mu_stream_seek(mstr, 0, SEEK_SET, NULL); + MF_ASSERT(rc == 0, + mfe_failure, + "mu_stream_seek: %s", + mu_strerror(rc)); cstr = open_connection(env, urlstr, &host); @@ -447,7 +495,7 @@ MF_DEFUN(clamav, NUMBER, STRING urlstr) } handler = set_signal_handler(SIGPIPE, sigpipe_handler); - rc = mu_stream_copy(dstr, mstr, 0, NULL); + rc = spamd_send_stream(dstr, mstr); mu_stream_shutdown(dstr, MU_STREAM_WRITE); mu_stream_destroy(&dstr); set_signal_handler(SIGPIPE, handler); |