diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-08-30 22:19:53 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-09-02 09:51:30 +0300 |
commit | 3e7ab184e897aad84f9f40c541d6b4e3654864d4 (patch) | |
tree | cfd21383943d368e4a1b15d3d9de2273aabf8f74 | |
parent | a783f8c35ed0fc9a7a18dc82f43bbe34a37aae37 (diff) | |
download | mailutils-3e7ab184e897aad84f9f40c541d6b4e3654864d4.tar.gz mailutils-3e7ab184e897aad84f9f40c541d6b4e3654864d4.tar.bz2 |
Redo the support for transport-based streams.
If a stream takes another stream(s) as a transport, it
always increases its reference count. This means that
when that stream is destroyed the underlying stream is
not destroyed by default (its refcount is decreased, that's
all). To force destruction of the underlying stream,
the caller must explicitly unreference it after creating
the stream that uses it (or give its creation function
the MU_STREAM_AUTOCLOSE flag, if it supports flags).
Similarly, if a stream uses a non-stream object (e.g. a file
descriptor) as the transport, it will not destroy it, unless
it has been created with the MU_STREAM_AUTOCLOSE flag. This
differs from the previous behavior.
The MU_STREAM_NO_CHECK and MU_STREAM_NO_CLOSE flags are removed.
* examples/base64.c (main): Call mu_filter_create with the
MU_STREAM_AUTOCLOSE flag.
* examples/mimetest.c (message_display_parts): Likewise.
* examples/murun.c (main): Unref the input stream after
passing it to mu_filter_prog_stream_create.
* imap4d/fetch.c (fetch_io): Update arguments to mu_filter_create
and mu_memory_stream_create.
* imap4d/preauth.c (decode64_buf)
(do_preauth_ident): Update arguments to mu_memory_stream_create and
mu_tcp_stream_create.
* imap4d/util.c (util_setio): Update arguments to mu_filter_create and
mu_stdio_stream_create.
* include/mailutils/stream.h (MU_STREAM_NO_CLOSE)
(MU_STREAM_NO_CHECK): Remove.
(MU_STREAM_AUTOCLOSE): New flag.
(mu_iostream_create): Remove the `flags' argument.
* libmu_argp/muinit.c (mu_app_init): Update arguments to
mu_stdio_stream_create.
* libmu_auth/ldap.c: Update arguments to
mu_memory_stream_create and mu_filter_create.
* libmu_auth/tls.c (_tls_io_close, _tls_close): Always try to close the
transport stream. Rely on refcount to protect it.
(_tls_io_done, _tls_done): Likewise, always unreference it.
(_mu_tls_io_stream_create): Increase reference counter on the
transport stream, unless MU_STREAM_AUTOCLOSE is requested.
(_mu_tls_stream_create): Rewrite using the new MU_STREAM_AUTOCLOSE
logic.
* libmu_sieve/extensions/spamd.c (spamd_connect_tcp): Update arguments to
mu_tcp_stream_create.
(spamd_connect_tcp): Update arguments to mu_socket_stream_create and
mu_filter_create.
* libmu_sieve/extensions/vacation.c (build_mime): Update arguments to
mu_filter_create.
* mail/decode.c (display_submessage): Update arguments to
mu_filter_create.
* mailbox/attachment.c (mu_message_save_attachment): Update arguments to
mu_filter_create.
* mailbox/cfg_driver.c (mu_cfg_tree_reduce): Update arguments to
mu_stdio_stream_create.
* mailbox/dbgstream.c (_dbg_done): Use MU_STREAM_AUTOCLOSE bit to
decide whether to destroy the debug object.
(mu_dbgstream_create): Use MU_STREAM_AUTOCLOSE instead of
MU_STREAM_NO_CLOSE.
* mailbox/file_stream.c (fd_close): Use MU_STREAM_AUTOCLOSE bit to
decide whether to close the descriptor.
(mu_file_stream_create): Force MU_STREAM_AUTOCLOSE bit.
* mailbox/filter.c (filter_create_rd, filter_create_wr): Change
substream creation logic.
* mailbox/filter_iconv.c (_icvt_close): Always try to close the
transport stream. Rely on refcount to protect it.
(_icvt_done): Ditto for destroying it.
(mu_filter_iconv_create): Increase refcount on the transport stream,
unless MU_STREAM_AUTOCLOSE is requested.
* mailbox/fltstream.c (filter_done): Always dereference the
transport stream. Rely on refcount to protect it.
(filter_close): Ditto for closing it.
(mu_filter_stream_create): Increase refcount on the transport stream,
unless MU_STREAM_AUTOCLOSE is requested.
* mailbox/iostream.c (_iostream_close) : Always try to close the
transport stream. Rely on refcount to protect it.
(_iostream_done): Ditto for closing it.
(mu_iostream_create): Remove the use of MU_STREAM_NO_CLOSE.
* mailbox/mimehdr.c (mu_mimehdr_decode_param): Remove the use of
MU_STREAM_NO_CLOSE.
* mailbox/mutil.c (mu_decode_filter) Change substream creation logic.
* mailbox/prog_stream.c (_prog_open): Use MU_STREAM_AUTOCLOSE bit
in arguments to mu_stdio_stream_create.
(mu_filter_prog_stream_create): Increase refcount on the transport
(input) stream.
* mailbox/rfc2047.c (mu_rfc2047_decode): Dereference in_stream after
passing it to mu_decode_filter.
Pass MU_STREAM_AUTOCLOSE in flags to mu_filter_create.
* mailbox/socket_stream.c (mu_socket_stream_create): Force
MU_STREAM_AUTOCLOSE bit.
* mailbox/streamref.c (_streamref_close): Always close the
transport stream (refcount will protect it, if necessary).
(mu_streamref_create_abridged): Mask out the MU_STREAM_AUTOCLOSE bit.
* mailbox/temp_file_stream.c (mu_temp_file_stream_create: Force
MU_STREAM_AUTOCLOSE bit.
* mailbox/xscript-stream.c (_xscript_close): Always close the
transport stream (refcount will protect it, if necessary).
(mu_xscript_stream_create): Increase refcounts on both underlying streams,
unless MU_STREAM_AUTOCLOSE is set.
* pop3d/extra.c (pop3d_setio): Remove uses of MU_STREAM_NO_CLOSE.
* examples/nntpclient.c: Remove uses of MU_STREAM_NO_CHECK/MU_STREAM_NO_CLOSE.
* examples/pop3client.c: Likewise.
* libmu_auth/gsasl.c: Likewise.
* libproto/nntp/nntp_stream.c: Likewise.
* libproto/pop/pop3_stream.c: Likewise.
* mailbox/tcp.c: Likewise.
* mailbox/vartab.c: Likewise.
* mh/mh_list.c: Likewise.
* mimeview/mimeview.c: Likewise.
* mh/mhn.c: Likewise.
(edit_mime): Use MU_STREAM_AUTOCLOSE.
Bugfixes:
* mailbox/fltstream.c (init_iobuf): Fix input initialization.
(filter_write_internal): Bugfix.
* mailbox/stream.c (_stream_buffer_freespace): New macro.
(_stream_buffer_is_full): New macro.
(BUFFER_FULL_P): Remove, use _stream_buffer_is_full instead. All callers
updated.
(_stream_flush_buffer): Operation for full buffered streams does not
depend on the `all' flag.
(mu_stream_write): Fix calculation of the bytes available in the
buffer.
41 files changed, 157 insertions, 165 deletions
diff --git a/examples/base64.c b/examples/base64.c index cc0a7e8b3..226cde96b 100644 --- a/examples/base64.c +++ b/examples/base64.c @@ -166,7 +166,8 @@ main (int argc, char * argv []) if (flags == MU_STREAM_READ) { MU_ASSERT (mu_filter_create (&flt, in, encoding, mode, - MU_STREAM_READ|MU_STREAM_SEEK)); + MU_STREAM_READ|MU_STREAM_SEEK| + MU_STREAM_AUTOCLOSE)); if (shift) MU_ASSERT (mu_stream_seek (flt, shift, MU_SEEK_SET, NULL)); c_copy (out, flt); @@ -174,7 +175,7 @@ main (int argc, char * argv []) else { MU_ASSERT (mu_filter_create (&flt, out, encoding, mode, - MU_STREAM_WRITE)); + MU_STREAM_WRITE|MU_STREAM_AUTOCLOSE)); if (shift) MU_ASSERT (mu_stream_seek (in, shift, MU_SEEK_SET, NULL)); c_copy (flt, in); diff --git a/examples/mimetest.c b/examples/mimetest.c index 8e38ca9e9..56235b883 100644 --- a/examples/mimetest.c +++ b/examples/mimetest.c @@ -254,7 +254,7 @@ message_display_parts (mu_message_t msg, int indent) /* Make sure the original body stream is not closed when str gets destroyed */ mu_filter_create (&str, str, encoding, MU_FILTER_DECODE, - MU_STREAM_READ | MU_STREAM_NO_CLOSE); + MU_STREAM_READ); while (mu_stream_readline (str, buf, sizeof (buf), &nbytes) == 0 && nbytes) diff --git a/examples/murun.c b/examples/murun.c index 59e4a3097..51b471082 100644 --- a/examples/murun.c +++ b/examples/murun.c @@ -71,6 +71,8 @@ main (int argc, char *argv[]) MU_ASSERT (mu_stdio_stream_create (&in, MU_STDIN_FD, 0)); MU_ASSERT (mu_stream_open (in)); rc = mu_filter_prog_stream_create (&stream, cmdline, in); + /* Make sure closing/destroying stream will close/destroy in */ + mu_stream_unref (in); } else rc = mu_prog_stream_create (&stream, cmdline, flags); @@ -80,7 +82,7 @@ main (int argc, char *argv[]) argv[0], mu_strerror (rc)); exit (1); } - + rc = mu_stream_open (stream); if (rc) { diff --git a/examples/nntpclient.c b/examples/nntpclient.c index 4fac95309..4c7722f3a 100644 --- a/examples/nntpclient.c +++ b/examples/nntpclient.c @@ -1004,8 +1004,7 @@ com_connect (char *arg) if (verbose) com_verbose ("on"); status = - mu_tcp_stream_create (&tcp, host, port, - MU_STREAM_READ | MU_STREAM_NO_CHECK); + mu_tcp_stream_create (&tcp, host, port, MU_STREAM_READ); if (status == 0) { mu_nntp_set_carrier (nntp, tcp); diff --git a/examples/pop3client.c b/examples/pop3client.c index 86acaca02..b8f3db2b2 100644 --- a/examples/pop3client.c +++ b/examples/pop3client.c @@ -800,8 +800,7 @@ com_connect (char *arg) if (verbose) com_verbose ("on"); status = - mu_tcp_stream_create (&tcp, argv[0], n, - MU_STREAM_READ | MU_STREAM_NO_CHECK); + mu_tcp_stream_create (&tcp, argv[0], n, MU_STREAM_READ); if (status == 0) { mu_pop3_set_carrier (pop3, tcp); diff --git a/imap4d/fetch.c b/imap4d/fetch.c index ef8ae9a51..7ada8fd3b 100644 --- a/imap4d/fetch.c +++ b/imap4d/fetch.c @@ -693,7 +693,7 @@ fetch_io (mu_stream_t stream, size_t start, size_t size, size_t max) size_t n = 0; mu_filter_create (&rfc, stream, "rfc822", MU_FILTER_ENCODE, - MU_STREAM_READ|MU_STREAM_SEEK|MU_STREAM_NO_CLOSE); + MU_STREAM_READ|MU_STREAM_SEEK); if (start == 0 && size == (size_t) -1) { @@ -1052,7 +1052,7 @@ _frt_header_fields (struct fetch_function_closure *ffc, return RESP_OK; } - status = mu_memory_stream_create (&stream, MU_STREAM_NO_CHECK); + status = mu_memory_stream_create (&stream, 0); if (status != 0) imap4d_bye (ERR_NO_MEM); diff --git a/imap4d/preauth.c b/imap4d/preauth.c index d26efc86a..4c505b396 100644 --- a/imap4d/preauth.c +++ b/imap4d/preauth.c @@ -210,9 +210,9 @@ decode64_buf (const char *name, unsigned char **pbuf, size_t *psize) name++; namelen = strlen (name) - 1; - mu_memory_stream_create (&str, MU_STREAM_NO_CHECK); + mu_memory_stream_create (&str, 0); mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, - MU_STREAM_READ | MU_STREAM_NO_CHECK); + MU_STREAM_READ | MU_STREAM_AUTOCLOSE); mu_stream_open (str); mu_stream_write (str, name, namelen, NULL); mu_stream_read (flt, buf, sizeof buf, &size); @@ -349,8 +349,7 @@ do_preauth_ident (struct sockaddr *clt_sa, struct sockaddr *srv_sa) memcpy (hostaddr, p, 15); hostaddr[15] = 0; - rc = mu_tcp_stream_create (&stream, hostaddr, ident_port, - MU_STREAM_RDWR | MU_STREAM_NO_CHECK); + rc = mu_tcp_stream_create (&stream, hostaddr, ident_port, MU_STREAM_RDWR); if (rc) { mu_diag_output (MU_DIAG_INFO, _("cannot create TCP stream: %s"), diff --git a/imap4d/util.c b/imap4d/util.c index 294782370..e6d828a9c 100644 --- a/imap4d/util.c +++ b/imap4d/util.c @@ -813,17 +813,18 @@ util_setio (FILE *in, FILE *out) if (!out) imap4d_bye (ERR_NO_OFILE); - if (mu_stdio_stream_create (&tmp, fileno (in), MU_STREAM_NO_CLOSE)) + if (mu_stdio_stream_create (&tmp, fileno (in), 0)) imap4d_bye (ERR_NO_IFILE); mu_stream_set_buffer (tmp, mu_buffer_line, 1024); - mu_filter_create (&istream, tmp, "rfc822", MU_FILTER_DECODE, MU_STREAM_READ); + mu_filter_create (&istream, tmp, "rfc822", MU_FILTER_DECODE, + MU_STREAM_READ | MU_STREAM_AUTOCLOSE); mu_stream_set_buffer (istream, mu_buffer_line, 1024); - if (mu_stdio_stream_create (&tmp, fileno (out), MU_STREAM_NO_CLOSE)) + if (mu_stdio_stream_create (&tmp, fileno (out), 0)) imap4d_bye (ERR_NO_OFILE); mu_stream_set_buffer (tmp, mu_buffer_line, 1024); mu_filter_create (&ostream, tmp, "rfc822", MU_FILTER_ENCODE, - MU_STREAM_WRITE); + MU_STREAM_WRITE | MU_STREAM_AUTOCLOSE); mu_stream_set_buffer (ostream, mu_buffer_line, 1024); } diff --git a/include/mailutils/stream.h b/include/mailutils/stream.h index 1b74651c7..431984066 100644 --- a/include/mailutils/stream.h +++ b/include/mailutils/stream.h @@ -41,7 +41,7 @@ enum mu_buffer_type #define MU_STREAM_APPEND 0x00000008 #define MU_STREAM_CREAT 0x00000010 #define MU_STREAM_NONBLOCK 0x00000020 -#define MU_STREAM_NO_CLOSE 0x00000040 +#define MU_STREAM_AUTOCLOSE 0x00000040 #define MU_STREAM_NONLOCK 0x00000080 #define MU_STREAM_ALLOW_LINKS 0x00000100 /* FIXME: This one affects only mailboxes */ @@ -152,8 +152,7 @@ int mu_tcp_stream_create (mu_stream_t *stream, const char *host, int port, int mu_xscript_stream_create(mu_stream_t *pref, mu_stream_t transport, mu_stream_t logstr, const char *prefix[]); -int mu_iostream_create (mu_stream_t *pref, mu_stream_t in, mu_stream_t out, - int flags); +int mu_iostream_create (mu_stream_t *pref, mu_stream_t in, mu_stream_t out); int mu_dbgstream_create(mu_stream_t *pref, mu_debug_t debug, mu_log_level_t level, int flags); diff --git a/libmu_argp/muinit.c b/libmu_argp/muinit.c index 9433fddea..54711166e 100644 --- a/libmu_argp/muinit.c +++ b/libmu_argp/muinit.c @@ -132,8 +132,7 @@ mu_app_init (struct argp *myargp, const char **capa, char *comment; char *canonical_name = get_canonical_name (); mu_stream_t stream; - mu_stdio_stream_create (&stream, MU_STDOUT_FD, - MU_STREAM_NO_CHECK|MU_STREAM_NO_CLOSE); + mu_stdio_stream_create (&stream, MU_STDOUT_FD, 0); mu_stream_open (stream); asprintf (&comment, "Configuration file structure for %s utility.", diff --git a/libmu_auth/gsasl.c b/libmu_auth/gsasl.c index 230a2752a..bdaa1174b 100644 --- a/libmu_auth/gsasl.c +++ b/libmu_auth/gsasl.c @@ -256,7 +256,7 @@ mu_gsasl_stream_create (mu_stream_t *stream, mu_stream_t transport, s->stream = transport; s->sess_ctx = ctx; - rc = mu_stream_create (stream, flags|MU_STREAM_NO_CHECK, s); + rc = mu_stream_create (stream, flags, s); if (rc) { free (s); diff --git a/libmu_auth/ldap.c b/libmu_auth/ldap.c index a8008e0c3..5ced39753 100644 --- a/libmu_auth/ldap.c +++ b/libmu_auth/ldap.c @@ -594,9 +594,9 @@ chk_md5 (const char *db_pass, const char *pass) mu_md5_process_bytes (pass, strlen (pass), &md5context); mu_md5_finish_ctx (&md5context, md5digest); - mu_memory_stream_create (&str, MU_STREAM_NO_CHECK); + mu_memory_stream_create (&str, 0); mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, - MU_STREAM_READ | MU_STREAM_NO_CHECK); + MU_STREAM_READ | MU_STREAM_AUTOCLOSE); mu_stream_open (str); mu_stream_write (str, db_pass, strlen (db_pass), NULL); @@ -617,9 +617,9 @@ chk_smd5 (const char *db_pass, const char *pass) mu_stream_t str = NULL, flt = NULL; size_t size; - mu_memory_stream_create (&str, MU_STREAM_NO_CHECK); + mu_memory_stream_create (&str, 0); mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, - MU_STREAM_READ | MU_STREAM_NO_CHECK); + MU_STREAM_READ | MU_STREAM_AUTOCLOSE); mu_stream_open (str); size = strlen (db_pass); mu_stream_write (str, db_pass, size, NULL); @@ -663,9 +663,9 @@ chk_sha (const char *db_pass, const char *pass) mu_sha1_process_bytes (pass, strlen (pass), &sha1context); mu_sha1_finish_ctx (&sha1context, sha1digest); - mu_memory_stream_create (&str, MU_STREAM_NO_CHECK); + mu_memory_stream_create (&str, 0); mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, - MU_STREAM_READ | MU_STREAM_NO_CHECK); + MU_STREAM_READ | MU_STREAM_AUTOCLOSE); mu_stream_open (str); mu_stream_write (str, db_pass, strlen (db_pass), NULL); @@ -686,9 +686,9 @@ chk_ssha (const char *db_pass, const char *pass) mu_stream_t str = NULL, flt = NULL; size_t size; - mu_memory_stream_create (&str, MU_STREAM_NO_CHECK); + mu_memory_stream_create (&str, 0); mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, - MU_STREAM_READ | MU_STREAM_NO_CHECK); + MU_STREAM_READ | MU_STREAM_AUTOCLOSE); mu_stream_open (str); size = strlen (db_pass); mu_stream_write (str, db_pass, size, NULL); diff --git a/libmu_auth/tls.c b/libmu_auth/tls.c index 7dff47858..f80912ce2 100644 --- a/libmu_auth/tls.c +++ b/libmu_auth/tls.c @@ -241,17 +241,14 @@ _tls_io_close (mu_stream_t stream) { struct _mu_tls_io_stream *sp = (struct _mu_tls_io_stream *) stream; - if (!(sp->stream.flags & MU_STREAM_NO_CLOSE)) - return mu_stream_close (sp->transport); - return 0; + return mu_stream_close (sp->transport); } static void _tls_io_done (struct _mu_stream *stream) { struct _mu_tls_io_stream *sp = (struct _mu_tls_io_stream *) stream; - if (!(sp->stream.flags & MU_STREAM_NO_CLOSE)) - mu_stream_unref (sp->transport); + mu_stream_unref (sp->transport); } static int @@ -364,8 +361,7 @@ _mu_tls_io_stream_create (mu_stream_t *pstream, struct _mu_tls_io_stream *sp; sp = (struct _mu_tls_io_stream *) - _mu_stream_create (sizeof (*sp), - flags & (MU_STREAM_RDWR | MU_STREAM_NO_CLOSE)); + _mu_stream_create (sizeof (*sp), flags & MU_STREAM_RDWR); if (!sp) return ENOMEM; @@ -388,6 +384,8 @@ _mu_tls_io_stream_create (mu_stream_t *pstream, /* FIXME: sp->stream.error_string = _tls_error_string;*/ + if (!(flags & MU_STREAM_AUTOCLOSE)) + mu_stream_ref (transport); sp->transport = transport; sp->up = master; *pstream = (mu_stream_t) sp; @@ -625,11 +623,8 @@ _tls_close (mu_stream_t stream) sp->state = state_closed; } - if (!(sp->stream.flags & MU_STREAM_NO_CLOSE)) - { - mu_stream_close (sp->transport[0]); - mu_stream_close (sp->transport[1]); - } + mu_stream_close (sp->transport[0]); + mu_stream_close (sp->transport[1]); return 0; } @@ -646,11 +641,8 @@ _tls_done (struct _mu_stream *stream) sp->state = state_destroyed; } - if (!(sp->stream.flags & MU_STREAM_NO_CLOSE)) - { - mu_stream_unref (sp->transport[0]); - mu_stream_unref (sp->transport[1]); - } + mu_stream_destroy (&sp->transport[0]); + mu_stream_destroy (&sp->transport[1]); } static int @@ -659,12 +651,11 @@ _mu_tls_stream_create (mu_stream_t *pstream, mu_stream_t strin, mu_stream_t strout, int flags) { struct _mu_tls_stream *sp; - int noclose = flags & MU_STREAM_NO_CLOSE; + int autoclose = flags & MU_STREAM_AUTOCLOSE; int rc; sp = (struct _mu_tls_stream *) - _mu_stream_create (sizeof (*sp), - MU_STREAM_RDWR | noclose); + _mu_stream_create (sizeof (*sp), MU_STREAM_RDWR); if (!sp) return ENOMEM; @@ -679,13 +670,10 @@ _mu_tls_stream_create (mu_stream_t *pstream, /* FIXME: sp->stream.error_string = _tls_error_string;*/ - if (!noclose && strin == strout) - mu_stream_ref (strin); - mu_stream_set_buffer (strin, mu_buffer_none, 0); mu_stream_set_buffer (strout, mu_buffer_none, 0); rc = _mu_tls_io_stream_create (&sp->transport[0], strin, - MU_STREAM_READ | noclose, sp); + MU_STREAM_READ | autoclose, sp); if (rc) { free (sp); @@ -693,7 +681,7 @@ _mu_tls_stream_create (mu_stream_t *pstream, } rc = _mu_tls_io_stream_create (&sp->transport[1], strout, - MU_STREAM_WRITE | noclose, sp); + MU_STREAM_WRITE | autoclose, sp); if (rc) { free (sp); diff --git a/libmu_sieve/extensions/spamd.c b/libmu_sieve/extensions/spamd.c index f31809ebe..26640d4d7 100644 --- a/libmu_sieve/extensions/spamd.c +++ b/libmu_sieve/extensions/spamd.c @@ -46,7 +46,7 @@ static int spamd_connect_tcp (mu_sieve_machine_t mach, mu_stream_t *stream, char *host, int port) { - int rc = mu_tcp_stream_create (stream, host, port, MU_STREAM_NO_CHECK); + int rc = mu_tcp_stream_create (stream, host, port, 0); if (rc) { mu_sieve_error (mach, "mu_tcp_stream_create: %s", mu_strerror (rc)); @@ -64,7 +64,7 @@ spamd_connect_tcp (mu_sieve_machine_t mach, mu_stream_t *stream, static int spamd_connect_socket (mu_sieve_machine_t mach, mu_stream_t *stream, char *path) { - int rc = mu_socket_stream_create (stream, path, MU_STREAM_NO_CHECK); + int rc = mu_socket_stream_create (stream, path, 0); if (rc) { mu_sieve_error (mach, "mu_socket_stream_create: %s", mu_strerror (rc)); @@ -110,7 +110,7 @@ spamd_send_message (mu_stream_t stream, mu_message_t msg) if (rc) return rc; rc = mu_filter_create (&flt, mstr, "rfc822", MU_FILTER_ENCODE, - MU_STREAM_READ|MU_STREAM_SEEK|MU_STREAM_NO_CLOSE); + MU_STREAM_READ|MU_STREAM_SEEK); if (rc) { mu_stream_destroy (&mstr); diff --git a/libmu_sieve/extensions/vacation.c b/libmu_sieve/extensions/vacation.c index 2b19e23e2..f22e0e653 100644 --- a/libmu_sieve/extensions/vacation.c +++ b/libmu_sieve/extensions/vacation.c @@ -88,7 +88,8 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime, { mu_stream_t fstr; rc = mu_filter_create (&fstr, input, "base64", - MU_FILTER_ENCODE, MU_STREAM_READ); + MU_FILTER_ENCODE, + MU_STREAM_READ | MU_STREAM_AUTOCLOSE); if (rc == 0) { header = "Content-Type: text/plain;charset=" MU_SIEVE_CHARSET "\n" diff --git a/libproto/nntp/nntp_stream.c b/libproto/nntp/nntp_stream.c index 9a6a9c779..f2f50ace5 100644 --- a/libproto/nntp/nntp_stream.c +++ b/libproto/nntp/nntp_stream.c @@ -131,7 +131,7 @@ mu_nntp_stream_create (mu_nntp_t nntp, mu_stream_t *pstream) nntp_stream->nntp = nntp; nntp_stream->done = 0; - status = mu_stream_create (pstream, MU_STREAM_READ | MU_STREAM_NO_CLOSE | MU_STREAM_NO_CHECK, nntp_stream); + status = mu_stream_create (pstream, MU_STREAM_READ, nntp_stream); if (status != 0) { free (nntp_stream); diff --git a/libproto/pop/pop3_stream.c b/libproto/pop/pop3_stream.c index c1ad6f54f..d22588c23 100644 --- a/libproto/pop/pop3_stream.c +++ b/libproto/pop/pop3_stream.c @@ -131,7 +131,7 @@ mu_pop3_stream_create (mu_pop3_t pop3, mu_stream_t *pstream) pop3_stream->pop3 = pop3; pop3_stream->done = 0; - status = mu_stream_create (pstream, MU_STREAM_READ | MU_STREAM_NO_CLOSE | MU_STREAM_NO_CHECK, pop3_stream); + status = mu_stream_create (pstream, MU_STREAM_READ, pop3_stream); if (status != 0) { free (pop3_stream); diff --git a/mail/decode.c b/mail/decode.c index 0acceaf6a..1a2f36936 100644 --- a/mail/decode.c +++ b/mail/decode.c @@ -262,7 +262,7 @@ display_submessage (struct mime_descend_closure *closure, void *data) /* Can we decode. */ if (mu_filter_create (&d_stream, b_stream, closure->encoding, MU_FILTER_DECODE, - MU_STREAM_READ|MU_STREAM_NO_CLOSE) == 0) + MU_STREAM_READ | MU_STREAM_AUTOCLOSE) == 0) stream = d_stream; else stream = b_stream; diff --git a/mailbox/attachment.c b/mailbox/attachment.c index 945211994..6bed79fff 100644 --- a/mailbox/attachment.c +++ b/mailbox/attachment.c @@ -314,7 +314,7 @@ mu_message_save_attachment (mu_message_t msg, const char *filename, ret = mu_filter_create (&info->stream, istream, content_encoding, MU_FILTER_DECODE, - MU_STREAM_READ | MU_STREAM_NO_CLOSE); + MU_STREAM_READ); free (content_encoding_mem); } } diff --git a/mailbox/cfg_driver.c b/mailbox/cfg_driver.c index ff9dae025..f4d56f710 100644 --- a/mailbox/cfg_driver.c +++ b/mailbox/cfg_driver.c @@ -589,8 +589,7 @@ mu_cfg_tree_reduce (mu_cfg_tree_t *parse_tree, const char *progname, if (flags & MU_PARSE_CONFIG_DUMP) { mu_stream_t stream; - mu_stdio_stream_create (&stream, MU_STDERR_FD, - MU_STREAM_NO_CHECK|MU_STREAM_NO_CLOSE); + mu_stdio_stream_create (&stream, MU_STDERR_FD, 0); mu_stream_open (stream); mu_cfg_format_parse_tree (stream, parse_tree, MU_CFG_FMT_LOCUS); mu_stream_destroy (&stream); diff --git a/mailbox/dbgstream.c b/mailbox/dbgstream.c index 19c137d3f..b03f29915 100644 --- a/mailbox/dbgstream.c +++ b/mailbox/dbgstream.c @@ -58,7 +58,7 @@ static void _dbg_done (struct _mu_stream *str) { struct _mu_dbgstream *sp = (struct _mu_dbgstream *)str; - if (!(str->flags & MU_STREAM_NO_CLOSE)) + if (str->flags & MU_STREAM_AUTOCLOSE) mu_debug_destroy (&sp->debug, NULL); } @@ -70,7 +70,7 @@ mu_dbgstream_create(mu_stream_t *pref, mu_debug_t debug, mu_log_level_t level, sp = (struct _mu_dbgstream *) _mu_stream_create (sizeof (*sp), MU_STREAM_WRITE | - (flags & MU_STREAM_NO_CLOSE)); + (flags & MU_STREAM_AUTOCLOSE)); if (!sp) return ENOMEM; sp->stream.write = _dbg_write; diff --git a/mailbox/file_stream.c b/mailbox/file_stream.c index 7dc8c90fa..b74bfb038 100644 --- a/mailbox/file_stream.c +++ b/mailbox/file_stream.c @@ -62,9 +62,12 @@ static int fd_close (struct _mu_stream *str) { struct _mu_file_stream *fstr = (struct _mu_file_stream *) str; - if (close (fstr->fd)) - return errno; - fstr->fd = -1; + if (fstr->fd != -1) + { + if ((str->flags & MU_STREAM_AUTOCLOSE) && close (fstr->fd)) + return errno; + fstr->fd = -1; + } return 0; } @@ -234,8 +237,8 @@ _mu_file_stream_create (mu_stream_t *pstream, size_t size, char *filename, int flags) { struct _mu_file_stream *str = - (struct _mu_file_stream *) _mu_stream_create (size, - flags | MU_STREAM_SEEK); + (struct _mu_file_stream *) + _mu_stream_create (size, flags | MU_STREAM_SEEK); if (!str) return ENOMEM; @@ -267,7 +270,7 @@ mu_file_stream_create (mu_stream_t *pstream, const char *filename, int flags) |