Commit baea3184 baea3184ad1cf5c6124ac1697a52d782ed7bebab by Sergey Poznyakoff

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.
1 parent 814b9791
...@@ -166,7 +166,8 @@ main (int argc, char * argv []) ...@@ -166,7 +166,8 @@ main (int argc, char * argv [])
166 if (flags == MU_STREAM_READ) 166 if (flags == MU_STREAM_READ)
167 { 167 {
168 MU_ASSERT (mu_filter_create (&flt, in, encoding, mode, 168 MU_ASSERT (mu_filter_create (&flt, in, encoding, mode,
169 MU_STREAM_READ|MU_STREAM_SEEK)); 169 MU_STREAM_READ|MU_STREAM_SEEK|
170 MU_STREAM_AUTOCLOSE));
170 if (shift) 171 if (shift)
171 MU_ASSERT (mu_stream_seek (flt, shift, MU_SEEK_SET, NULL)); 172 MU_ASSERT (mu_stream_seek (flt, shift, MU_SEEK_SET, NULL));
172 c_copy (out, flt); 173 c_copy (out, flt);
...@@ -174,7 +175,7 @@ main (int argc, char * argv []) ...@@ -174,7 +175,7 @@ main (int argc, char * argv [])
174 else 175 else
175 { 176 {
176 MU_ASSERT (mu_filter_create (&flt, out, encoding, mode, 177 MU_ASSERT (mu_filter_create (&flt, out, encoding, mode,
177 MU_STREAM_WRITE)); 178 MU_STREAM_WRITE|MU_STREAM_AUTOCLOSE));
178 if (shift) 179 if (shift)
179 MU_ASSERT (mu_stream_seek (in, shift, MU_SEEK_SET, NULL)); 180 MU_ASSERT (mu_stream_seek (in, shift, MU_SEEK_SET, NULL));
180 c_copy (flt, in); 181 c_copy (flt, in);
......
...@@ -253,7 +253,7 @@ message_display_parts (mu_message_t msg, int indent) ...@@ -253,7 +253,7 @@ message_display_parts (mu_message_t msg, int indent)
253 /* Make sure the original body stream is not closed when 253 /* Make sure the original body stream is not closed when
254 str gets destroyed */ 254 str gets destroyed */
255 mu_filter_create (&str, str, encoding, MU_FILTER_DECODE, 255 mu_filter_create (&str, str, encoding, MU_FILTER_DECODE,
256 MU_STREAM_READ | MU_STREAM_NO_CLOSE); 256 MU_STREAM_READ);
257 257
258 while (mu_stream_readline (str, buf, sizeof (buf), &nbytes) == 0 258 while (mu_stream_readline (str, buf, sizeof (buf), &nbytes) == 0
259 && nbytes) 259 && nbytes)
......
...@@ -71,6 +71,8 @@ main (int argc, char *argv[]) ...@@ -71,6 +71,8 @@ main (int argc, char *argv[])
71 MU_ASSERT (mu_stdio_stream_create (&in, MU_STDIN_FD, 0)); 71 MU_ASSERT (mu_stdio_stream_create (&in, MU_STDIN_FD, 0));
72 MU_ASSERT (mu_stream_open (in)); 72 MU_ASSERT (mu_stream_open (in));
73 rc = mu_filter_prog_stream_create (&stream, cmdline, in); 73 rc = mu_filter_prog_stream_create (&stream, cmdline, in);
74 /* Make sure closing/destroying stream will close/destroy in */
75 mu_stream_unref (in);
74 } 76 }
75 else 77 else
76 rc = mu_prog_stream_create (&stream, cmdline, flags); 78 rc = mu_prog_stream_create (&stream, cmdline, flags);
...@@ -80,7 +82,7 @@ main (int argc, char *argv[]) ...@@ -80,7 +82,7 @@ main (int argc, char *argv[])
80 argv[0], mu_strerror (rc)); 82 argv[0], mu_strerror (rc));
81 exit (1); 83 exit (1);
82 } 84 }
83 85
84 rc = mu_stream_open (stream); 86 rc = mu_stream_open (stream);
85 if (rc) 87 if (rc)
86 { 88 {
......
...@@ -1004,8 +1004,7 @@ com_connect (char *arg) ...@@ -1004,8 +1004,7 @@ com_connect (char *arg)
1004 if (verbose) 1004 if (verbose)
1005 com_verbose ("on"); 1005 com_verbose ("on");
1006 status = 1006 status =
1007 mu_tcp_stream_create (&tcp, host, port, 1007 mu_tcp_stream_create (&tcp, host, port, MU_STREAM_READ);
1008 MU_STREAM_READ | MU_STREAM_NO_CHECK);
1009 if (status == 0) 1008 if (status == 0)
1010 { 1009 {
1011 mu_nntp_set_carrier (nntp, tcp); 1010 mu_nntp_set_carrier (nntp, tcp);
......
...@@ -800,8 +800,7 @@ com_connect (char *arg) ...@@ -800,8 +800,7 @@ com_connect (char *arg)
800 if (verbose) 800 if (verbose)
801 com_verbose ("on"); 801 com_verbose ("on");
802 status = 802 status =
803 mu_tcp_stream_create (&tcp, argv[0], n, 803 mu_tcp_stream_create (&tcp, argv[0], n, MU_STREAM_READ);
804 MU_STREAM_READ | MU_STREAM_NO_CHECK);
805 if (status == 0) 804 if (status == 0)
806 { 805 {
807 mu_pop3_set_carrier (pop3, tcp); 806 mu_pop3_set_carrier (pop3, tcp);
......
...@@ -694,7 +694,7 @@ fetch_io (mu_stream_t stream, size_t start, size_t size, size_t max) ...@@ -694,7 +694,7 @@ fetch_io (mu_stream_t stream, size_t start, size_t size, size_t max)
694 size_t n = 0; 694 size_t n = 0;
695 695
696 mu_filter_create (&rfc, stream, "rfc822", MU_FILTER_ENCODE, 696 mu_filter_create (&rfc, stream, "rfc822", MU_FILTER_ENCODE,
697 MU_STREAM_READ|MU_STREAM_SEEK|MU_STREAM_NO_CLOSE); 697 MU_STREAM_READ|MU_STREAM_SEEK);
698 698
699 if (start == 0 && size == (size_t) -1) 699 if (start == 0 && size == (size_t) -1)
700 { 700 {
...@@ -1038,7 +1038,7 @@ _frt_header_fields (struct fetch_function_closure *ffc, ...@@ -1038,7 +1038,7 @@ _frt_header_fields (struct fetch_function_closure *ffc,
1038 return RESP_OK; 1038 return RESP_OK;
1039 } 1039 }
1040 1040
1041 status = mu_memory_stream_create (&stream, MU_STREAM_NO_CHECK); 1041 status = mu_memory_stream_create (&stream, 0);
1042 if (status != 0) 1042 if (status != 0)
1043 imap4d_bye (ERR_NO_MEM); 1043 imap4d_bye (ERR_NO_MEM);
1044 1044
......
...@@ -210,9 +210,9 @@ decode64_buf (const char *name, unsigned char **pbuf, size_t *psize) ...@@ -210,9 +210,9 @@ decode64_buf (const char *name, unsigned char **pbuf, size_t *psize)
210 210
211 name++; 211 name++;
212 namelen = strlen (name) - 1; 212 namelen = strlen (name) - 1;
213 mu_memory_stream_create (&str, MU_STREAM_NO_CHECK); 213 mu_memory_stream_create (&str, 0);
214 mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, 214 mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
215 MU_STREAM_READ | MU_STREAM_NO_CHECK); 215 MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
216 mu_stream_open (str); 216 mu_stream_open (str);
217 mu_stream_write (str, name, namelen, NULL); 217 mu_stream_write (str, name, namelen, NULL);
218 mu_stream_read (flt, buf, sizeof buf, &size); 218 mu_stream_read (flt, buf, sizeof buf, &size);
...@@ -349,8 +349,7 @@ do_preauth_ident (struct sockaddr *clt_sa, struct sockaddr *srv_sa) ...@@ -349,8 +349,7 @@ do_preauth_ident (struct sockaddr *clt_sa, struct sockaddr *srv_sa)
349 349
350 memcpy (hostaddr, p, 15); 350 memcpy (hostaddr, p, 15);
351 hostaddr[15] = 0; 351 hostaddr[15] = 0;
352 rc = mu_tcp_stream_create (&stream, hostaddr, ident_port, 352 rc = mu_tcp_stream_create (&stream, hostaddr, ident_port, MU_STREAM_RDWR);
353 MU_STREAM_RDWR | MU_STREAM_NO_CHECK);
354 if (rc) 353 if (rc)
355 { 354 {
356 mu_diag_output (MU_DIAG_INFO, _("cannot create TCP stream: %s"), 355 mu_diag_output (MU_DIAG_INFO, _("cannot create TCP stream: %s"),
......
...@@ -813,17 +813,18 @@ util_setio (FILE *in, FILE *out) ...@@ -813,17 +813,18 @@ util_setio (FILE *in, FILE *out)
813 if (!out) 813 if (!out)
814 imap4d_bye (ERR_NO_OFILE); 814 imap4d_bye (ERR_NO_OFILE);
815 815
816 if (mu_stdio_stream_create (&tmp, fileno (in), MU_STREAM_NO_CLOSE)) 816 if (mu_stdio_stream_create (&tmp, fileno (in), 0))
817 imap4d_bye (ERR_NO_IFILE); 817 imap4d_bye (ERR_NO_IFILE);
818 mu_stream_set_buffer (tmp, mu_buffer_line, 1024); 818 mu_stream_set_buffer (tmp, mu_buffer_line, 1024);
819 mu_filter_create (&istream, tmp, "rfc822", MU_FILTER_DECODE, MU_STREAM_READ); 819 mu_filter_create (&istream, tmp, "rfc822", MU_FILTER_DECODE,
820 MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
820 mu_stream_set_buffer (istream, mu_buffer_line, 1024); 821 mu_stream_set_buffer (istream, mu_buffer_line, 1024);
821 822
822 if (mu_stdio_stream_create (&tmp, fileno (out), MU_STREAM_NO_CLOSE)) 823 if (mu_stdio_stream_create (&tmp, fileno (out), 0))
823 imap4d_bye (ERR_NO_OFILE); 824 imap4d_bye (ERR_NO_OFILE);
824 mu_stream_set_buffer (tmp, mu_buffer_line, 1024); 825 mu_stream_set_buffer (tmp, mu_buffer_line, 1024);
825 mu_filter_create (&ostream, tmp, "rfc822", MU_FILTER_ENCODE, 826 mu_filter_create (&ostream, tmp, "rfc822", MU_FILTER_ENCODE,
826 MU_STREAM_WRITE); 827 MU_STREAM_WRITE | MU_STREAM_AUTOCLOSE);
827 mu_stream_set_buffer (ostream, mu_buffer_line, 1024); 828 mu_stream_set_buffer (ostream, mu_buffer_line, 1024);
828 } 829 }
829 830
......
...@@ -41,7 +41,7 @@ enum mu_buffer_type ...@@ -41,7 +41,7 @@ enum mu_buffer_type
41 #define MU_STREAM_APPEND 0x00000008 41 #define MU_STREAM_APPEND 0x00000008
42 #define MU_STREAM_CREAT 0x00000010 42 #define MU_STREAM_CREAT 0x00000010
43 #define MU_STREAM_NONBLOCK 0x00000020 43 #define MU_STREAM_NONBLOCK 0x00000020
44 #define MU_STREAM_NO_CLOSE 0x00000040 44 #define MU_STREAM_AUTOCLOSE 0x00000040
45 #define MU_STREAM_NONLOCK 0x00000080 45 #define MU_STREAM_NONLOCK 0x00000080
46 #define MU_STREAM_ALLOW_LINKS 0x00000100 46 #define MU_STREAM_ALLOW_LINKS 0x00000100
47 /* FIXME: This one affects only mailboxes */ 47 /* FIXME: This one affects only mailboxes */
...@@ -152,8 +152,7 @@ int mu_tcp_stream_create (mu_stream_t *stream, const char *host, int port, ...@@ -152,8 +152,7 @@ int mu_tcp_stream_create (mu_stream_t *stream, const char *host, int port,
152 int mu_xscript_stream_create(mu_stream_t *pref, mu_stream_t transport, 152 int mu_xscript_stream_create(mu_stream_t *pref, mu_stream_t transport,
153 mu_stream_t logstr, 153 mu_stream_t logstr,
154 const char *prefix[]); 154 const char *prefix[]);
155 int mu_iostream_create (mu_stream_t *pref, mu_stream_t in, mu_stream_t out, 155 int mu_iostream_create (mu_stream_t *pref, mu_stream_t in, mu_stream_t out);
156 int flags);
157 int mu_dbgstream_create(mu_stream_t *pref, mu_debug_t debug, 156 int mu_dbgstream_create(mu_stream_t *pref, mu_debug_t debug,
158 mu_log_level_t level, int flags); 157 mu_log_level_t level, int flags);
159 158
......
...@@ -132,8 +132,7 @@ mu_app_init (struct argp *myargp, const char **capa, ...@@ -132,8 +132,7 @@ mu_app_init (struct argp *myargp, const char **capa,
132 char *comment; 132 char *comment;
133 char *canonical_name = get_canonical_name (); 133 char *canonical_name = get_canonical_name ();
134 mu_stream_t stream; 134 mu_stream_t stream;
135 mu_stdio_stream_create (&stream, MU_STDOUT_FD, 135 mu_stdio_stream_create (&stream, MU_STDOUT_FD, 0);
136 MU_STREAM_NO_CHECK|MU_STREAM_NO_CLOSE);
137 mu_stream_open (stream); 136 mu_stream_open (stream);
138 asprintf (&comment, 137 asprintf (&comment,
139 "Configuration file structure for %s utility.", 138 "Configuration file structure for %s utility.",
......
...@@ -256,7 +256,7 @@ mu_gsasl_stream_create (mu_stream_t *stream, mu_stream_t transport, ...@@ -256,7 +256,7 @@ mu_gsasl_stream_create (mu_stream_t *stream, mu_stream_t transport,
256 s->stream = transport; 256 s->stream = transport;
257 s->sess_ctx = ctx; 257 s->sess_ctx = ctx;
258 258
259 rc = mu_stream_create (stream, flags|MU_STREAM_NO_CHECK, s); 259 rc = mu_stream_create (stream, flags, s);
260 if (rc) 260 if (rc)
261 { 261 {
262 free (s); 262 free (s);
......
...@@ -594,9 +594,9 @@ chk_md5 (const char *db_pass, const char *pass) ...@@ -594,9 +594,9 @@ chk_md5 (const char *db_pass, const char *pass)
594 mu_md5_process_bytes (pass, strlen (pass), &md5context); 594 mu_md5_process_bytes (pass, strlen (pass), &md5context);
595 mu_md5_finish_ctx (&md5context, md5digest); 595 mu_md5_finish_ctx (&md5context, md5digest);
596 596
597 mu_memory_stream_create (&str, MU_STREAM_NO_CHECK); 597 mu_memory_stream_create (&str, 0);
598 mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, 598 mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
599 MU_STREAM_READ | MU_STREAM_NO_CHECK); 599 MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
600 mu_stream_open (str); 600 mu_stream_open (str);
601 mu_stream_write (str, db_pass, strlen (db_pass), NULL); 601 mu_stream_write (str, db_pass, strlen (db_pass), NULL);
602 602
...@@ -617,9 +617,9 @@ chk_smd5 (const char *db_pass, const char *pass) ...@@ -617,9 +617,9 @@ chk_smd5 (const char *db_pass, const char *pass)
617 mu_stream_t str = NULL, flt = NULL; 617 mu_stream_t str = NULL, flt = NULL;
618 size_t size; 618 size_t size;
619 619
620 mu_memory_stream_create (&str, MU_STREAM_NO_CHECK); 620 mu_memory_stream_create (&str, 0);
621 mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, 621 mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
622 MU_STREAM_READ | MU_STREAM_NO_CHECK); 622 MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
623 mu_stream_open (str); 623 mu_stream_open (str);
624 size = strlen (db_pass); 624 size = strlen (db_pass);
625 mu_stream_write (str, db_pass, size, NULL); 625 mu_stream_write (str, db_pass, size, NULL);
...@@ -663,9 +663,9 @@ chk_sha (const char *db_pass, const char *pass) ...@@ -663,9 +663,9 @@ chk_sha (const char *db_pass, const char *pass)
663 mu_sha1_process_bytes (pass, strlen (pass), &sha1context); 663 mu_sha1_process_bytes (pass, strlen (pass), &sha1context);
664 mu_sha1_finish_ctx (&sha1context, sha1digest); 664 mu_sha1_finish_ctx (&sha1context, sha1digest);
665 665
666 mu_memory_stream_create (&str, MU_STREAM_NO_CHECK); 666 mu_memory_stream_create (&str, 0);
667 mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, 667 mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
668 MU_STREAM_READ | MU_STREAM_NO_CHECK); 668 MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
669 mu_stream_open (str); 669 mu_stream_open (str);
670 mu_stream_write (str, db_pass, strlen (db_pass), NULL); 670 mu_stream_write (str, db_pass, strlen (db_pass), NULL);
671 671
...@@ -686,9 +686,9 @@ chk_ssha (const char *db_pass, const char *pass) ...@@ -686,9 +686,9 @@ chk_ssha (const char *db_pass, const char *pass)
686 mu_stream_t str = NULL, flt = NULL; 686 mu_stream_t str = NULL, flt = NULL;
687 size_t size; 687 size_t size;
688 688
689 mu_memory_stream_create (&str, MU_STREAM_NO_CHECK); 689 mu_memory_stream_create (&str, 0);
690 mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, 690 mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
691 MU_STREAM_READ | MU_STREAM_NO_CHECK); 691 MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
692 mu_stream_open (str); 692 mu_stream_open (str);
693 size = strlen (db_pass); 693 size = strlen (db_pass);
694 mu_stream_write (str, db_pass, size, NULL); 694 mu_stream_write (str, db_pass, size, NULL);
......
...@@ -241,17 +241,14 @@ _tls_io_close (mu_stream_t stream) ...@@ -241,17 +241,14 @@ _tls_io_close (mu_stream_t stream)
241 { 241 {
242 struct _mu_tls_io_stream *sp = (struct _mu_tls_io_stream *) stream; 242 struct _mu_tls_io_stream *sp = (struct _mu_tls_io_stream *) stream;
243 243
244 if (!(sp->stream.flags & MU_STREAM_NO_CLOSE)) 244 return mu_stream_close (sp->transport);
245 return mu_stream_close (sp->transport);
246 return 0;
247 } 245 }
248 246
249 static void 247 static void
250 _tls_io_done (struct _mu_stream *stream) 248 _tls_io_done (struct _mu_stream *stream)
251 { 249 {
252 struct _mu_tls_io_stream *sp = (struct _mu_tls_io_stream *) stream; 250 struct _mu_tls_io_stream *sp = (struct _mu_tls_io_stream *) stream;
253 if (!(sp->stream.flags & MU_STREAM_NO_CLOSE)) 251 mu_stream_unref (sp->transport);
254 mu_stream_unref (sp->transport);
255 } 252 }
256 253
257 static int 254 static int
...@@ -364,8 +361,7 @@ _mu_tls_io_stream_create (mu_stream_t *pstream, ...@@ -364,8 +361,7 @@ _mu_tls_io_stream_create (mu_stream_t *pstream,
364 struct _mu_tls_io_stream *sp; 361 struct _mu_tls_io_stream *sp;
365 362
366 sp = (struct _mu_tls_io_stream *) 363 sp = (struct _mu_tls_io_stream *)
367 _mu_stream_create (sizeof (*sp), 364 _mu_stream_create (sizeof (*sp), flags & MU_STREAM_RDWR);
368 flags & (MU_STREAM_RDWR | MU_STREAM_NO_CLOSE));
369 if (!sp) 365 if (!sp)
370 return ENOMEM; 366 return ENOMEM;
371 367
...@@ -388,6 +384,8 @@ _mu_tls_io_stream_create (mu_stream_t *pstream, ...@@ -388,6 +384,8 @@ _mu_tls_io_stream_create (mu_stream_t *pstream,
388 /* FIXME: 384 /* FIXME:
389 sp->stream.error_string = _tls_error_string;*/ 385 sp->stream.error_string = _tls_error_string;*/
390 386
387 if (!(flags & MU_STREAM_AUTOCLOSE))
388 mu_stream_ref (transport);
391 sp->transport = transport; 389 sp->transport = transport;
392 sp->up = master; 390 sp->up = master;
393 *pstream = (mu_stream_t) sp; 391 *pstream = (mu_stream_t) sp;
...@@ -625,11 +623,8 @@ _tls_close (mu_stream_t stream) ...@@ -625,11 +623,8 @@ _tls_close (mu_stream_t stream)
625 sp->state = state_closed; 623 sp->state = state_closed;
626 } 624 }
627 625
628 if (!(sp->stream.flags & MU_STREAM_NO_CLOSE)) 626 mu_stream_close (sp->transport[0]);
629 { 627 mu_stream_close (sp->transport[1]);
630 mu_stream_close (sp->transport[0]);
631 mu_stream_close (sp->transport[1]);
632 }
633 return 0; 628 return 0;
634 } 629 }
635 630
...@@ -646,11 +641,8 @@ _tls_done (struct _mu_stream *stream) ...@@ -646,11 +641,8 @@ _tls_done (struct _mu_stream *stream)
646 sp->state = state_destroyed; 641 sp->state = state_destroyed;
647 } 642 }
648 643
649 if (!(sp->stream.flags & MU_STREAM_NO_CLOSE)) 644 mu_stream_destroy (&sp->transport[0]);
650 { 645 mu_stream_destroy (&sp->transport[1]);
651 mu_stream_unref (sp->transport[0]);
652 mu_stream_unref (sp->transport[1]);
653 }
654 } 646 }
655 647
656 static int 648 static int
...@@ -659,12 +651,11 @@ _mu_tls_stream_create (mu_stream_t *pstream, ...@@ -659,12 +651,11 @@ _mu_tls_stream_create (mu_stream_t *pstream,
659 mu_stream_t strin, mu_stream_t strout, int flags) 651 mu_stream_t strin, mu_stream_t strout, int flags)
660 { 652 {
661 struct _mu_tls_stream *sp; 653 struct _mu_tls_stream *sp;
662 int noclose = flags & MU_STREAM_NO_CLOSE; 654 int autoclose = flags & MU_STREAM_AUTOCLOSE;
663 int rc; 655 int rc;
664 656
665 sp = (struct _mu_tls_stream *) 657 sp = (struct _mu_tls_stream *)
666 _mu_stream_create (sizeof (*sp), 658 _mu_stream_create (sizeof (*sp), MU_STREAM_RDWR);
667 MU_STREAM_RDWR | noclose);
668 if (!sp) 659 if (!sp)
669 return ENOMEM; 660 return ENOMEM;
670 661
...@@ -679,13 +670,10 @@ _mu_tls_stream_create (mu_stream_t *pstream, ...@@ -679,13 +670,10 @@ _mu_tls_stream_create (mu_stream_t *pstream,
679 /* FIXME: 670 /* FIXME:
680 sp->stream.error_string = _tls_error_string;*/ 671 sp->stream.error_string = _tls_error_string;*/
681 672
682 if (!noclose && strin == strout)
683 mu_stream_ref (strin);
684
685 mu_stream_set_buffer (strin, mu_buffer_none, 0); 673 mu_stream_set_buffer (strin, mu_buffer_none, 0);
686 mu_stream_set_buffer (strout, mu_buffer_none, 0); 674 mu_stream_set_buffer (strout, mu_buffer_none, 0);
687 rc = _mu_tls_io_stream_create (&sp->transport[0], strin, 675 rc = _mu_tls_io_stream_create (&sp->transport[0], strin,
688 MU_STREAM_READ | noclose, sp); 676 MU_STREAM_READ | autoclose, sp);
689 if (rc) 677 if (rc)
690 { 678 {
691 free (sp); 679 free (sp);
...@@ -693,7 +681,7 @@ _mu_tls_stream_create (mu_stream_t *pstream, ...@@ -693,7 +681,7 @@ _mu_tls_stream_create (mu_stream_t *pstream,
693 } 681 }
694 682
695 rc = _mu_tls_io_stream_create (&sp->transport[1], strout, 683 rc = _mu_tls_io_stream_create (&sp->transport[1], strout,
696 MU_STREAM_WRITE | noclose, sp); 684 MU_STREAM_WRITE | autoclose, sp);
697 if (rc) 685 if (rc)
698 { 686 {
699 free (sp); 687 free (sp);
......
...@@ -46,7 +46,7 @@ static int ...@@ -46,7 +46,7 @@ static int
46 spamd_connect_tcp (mu_sieve_machine_t mach, mu_stream_t *stream, 46 spamd_connect_tcp (mu_sieve_machine_t mach, mu_stream_t *stream,
47 char *host, int port) 47 char *host, int port)
48 { 48 {
49 int rc = mu_tcp_stream_create (stream, host, port, MU_STREAM_NO_CHECK); 49 int rc = mu_tcp_stream_create (stream, host, port, 0);
50 if (rc) 50 if (rc)
51 { 51 {
52 mu_sieve_error (mach, "mu_tcp_stream_create: %s", mu_strerror (rc)); 52 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, ...@@ -64,7 +64,7 @@ spamd_connect_tcp (mu_sieve_machine_t mach, mu_stream_t *stream,
64 static int 64 static int
65 spamd_connect_socket (mu_sieve_machine_t mach, mu_stream_t *stream, char *path) 65 spamd_connect_socket (mu_sieve_machine_t mach, mu_stream_t *stream, char *path)
66 { 66 {
67 int rc = mu_socket_stream_create (stream, path, MU_STREAM_NO_CHECK); 67 int rc = mu_socket_stream_create (stream, path, 0);
68 if (rc) 68 if (rc)
69 { 69 {
70 mu_sieve_error (mach, "mu_socket_stream_create: %s", mu_strerror (rc)); 70 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) ...@@ -110,7 +110,7 @@ spamd_send_message (mu_stream_t stream, mu_message_t msg)
110 if (rc) 110 if (rc)
111 return rc; 111 return rc;
112 rc = mu_filter_create (&flt, mstr, "rfc822", MU_FILTER_ENCODE, 112 rc = mu_filter_create (&flt, mstr, "rfc822", MU_FILTER_ENCODE,
113 MU_STREAM_READ|MU_STREAM_SEEK|MU_STREAM_NO_CLOSE); 113 MU_STREAM_READ|MU_STREAM_SEEK);
114 if (rc) 114 if (rc)
115 { 115 {
116 mu_stream_destroy (&mstr); 116 mu_stream_destroy (&mstr);
......
...@@ -88,7 +88,8 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime, ...@@ -88,7 +88,8 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime,
88 { 88 {
89 mu_stream_t fstr; 89 mu_stream_t fstr;
90 rc = mu_filter_create (&fstr, input, "base64", 90 rc = mu_filter_create (&fstr, input, "base64",
91 MU_FILTER_ENCODE, MU_STREAM_READ); 91 MU_FILTER_ENCODE,
92 MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
92 if (rc == 0) 93 if (rc == 0)
93 { 94 {
94 header = "Content-Type: text/plain;charset=" MU_SIEVE_CHARSET "\n" 95 header = "Content-Type: text/plain;charset=" MU_SIEVE_CHARSET "\n"
......
...@@ -131,7 +131,7 @@ mu_nntp_stream_create (mu_nntp_t nntp, mu_stream_t *pstream) ...@@ -131,7 +131,7 @@ mu_nntp_stream_create (mu_nntp_t nntp, mu_stream_t *pstream)
131 nntp_stream->nntp = nntp; 131 nntp_stream->nntp = nntp;
132 nntp_stream->done = 0; 132 nntp_stream->done = 0;
133 133
134 status = mu_stream_create (pstream, MU_STREAM_READ | MU_STREAM_NO_CLOSE | MU_STREAM_NO_CHECK, nntp_stream); 134 status = mu_stream_create (pstream, MU_STREAM_READ, nntp_stream);
135 if (status != 0) 135 if (status != 0)
136 { 136 {
137 free (nntp_stream); 137 free (nntp_stream);
......
...@@ -131,7 +131,7 @@ mu_pop3_stream_create (mu_pop3_t pop3, mu_stream_t *pstream) ...@@ -131,7 +131,7 @@ mu_pop3_stream_create (mu_pop3_t pop3, mu_stream_t *pstream)
131 pop3_stream->pop3 = pop3; 131 pop3_stream->pop3 = pop3;
132 pop3_stream->done = 0; 132 pop3_stream->done = 0;
133 133
134 status = mu_stream_create (pstream, MU_STREAM_READ | MU_STREAM_NO_CLOSE | MU_STREAM_NO_CHECK, pop3_stream); 134 status = mu_stream_create (pstream, MU_STREAM_READ, pop3_stream);
135 if (status != 0) 135 if (status != 0)
136 { 136 {
137 free (pop3_stream); 137 free (pop3_stream);
......
...@@ -262,7 +262,7 @@ display_submessage (struct mime_descend_closure *closure, void *data) ...@@ -262,7 +262,7 @@ display_submessage (struct mime_descend_closure *closure, void *data)
262 /* Can we decode. */ 262 /* Can we decode. */
263 if (mu_filter_create (&d_stream, b_stream, closure->encoding, 263 if (mu_filter_create (&d_stream, b_stream, closure->encoding,
264 MU_FILTER_DECODE, 264 MU_FILTER_DECODE,
265 MU_STREAM_READ|MU_STREAM_NO_CLOSE) == 0) 265 MU_STREAM_READ | MU_STREAM_AUTOCLOSE) == 0)
266 stream = d_stream; 266 stream = d_stream;
267 else 267 else
268 stream = b_stream; 268 stream = b_stream;
......
...@@ -314,7 +314,7 @@ mu_message_save_attachment (mu_message_t msg, const char *filename, ...@@ -314,7 +314,7 @@ mu_message_save_attachment (mu_message_t msg, const char *filename,
314 ret = 314 ret =
315 mu_filter_create (&info->stream, istream, content_encoding, 315 mu_filter_create (&info->stream, istream, content_encoding,
316 MU_FILTER_DECODE, 316 MU_FILTER_DECODE,
317 MU_STREAM_READ | MU_STREAM_NO_CLOSE); 317 MU_STREAM_READ);
318 free (content_encoding_mem); 318 free (content_encoding_mem);
319 } 319 }
320 } 320 }
......
...@@ -589,8 +589,7 @@ mu_cfg_tree_reduce (mu_cfg_tree_t *parse_tree, const char *progname, ...@@ -589,8 +589,7 @@ mu_cfg_tree_reduce (mu_cfg_tree_t *parse_tree, const char *progname,
589 if (flags & MU_PARSE_CONFIG_DUMP) 589 if (flags & MU_PARSE_CONFIG_DUMP)
590 { 590 {
591 mu_stream_t stream; 591 mu_stream_t stream;
592 mu_stdio_stream_create (&stream, MU_STDERR_FD, 592 mu_stdio_stream_create (&stream, MU_STDERR_FD, 0);
593 MU_STREAM_NO_CHECK|MU_STREAM_NO_CLOSE);
594 mu_stream_open (stream); 593 mu_stream_open (stream);
595 mu_cfg_format_parse_tree (stream, parse_tree, MU_CFG_FMT_LOCUS); 594 mu_cfg_format_parse_tree (stream, parse_tree, MU_CFG_FMT_LOCUS);
596 mu_stream_destroy (&stream); 595 mu_stream_destroy (&stream);
......
...@@ -58,7 +58,7 @@ static void ...@@ -58,7 +58,7 @@ static void
58 _dbg_done (struct _mu_stream *str) 58 _dbg_done (struct _mu_stream *str)
59 { 59 {
60 struct _mu_dbgstream *sp = (struct _mu_dbgstream *)str; 60 struct _mu_dbgstream *sp = (struct _mu_dbgstream *)str;
61 if (!(str->flags & MU_STREAM_NO_CLOSE)) 61 if (str->flags & MU_STREAM_AUTOCLOSE)
62 mu_debug_destroy (&sp->debug, NULL); 62 mu_debug_destroy (&sp->debug, NULL);
63 } 63 }
64 64
...@@ -70,7 +70,7 @@ mu_dbgstream_create(mu_stream_t *pref, mu_debug_t debug, mu_log_level_t level, ...@@ -70,7 +70,7 @@ mu_dbgstream_create(mu_stream_t *pref, mu_debug_t debug, mu_log_level_t level,
70 70
71 sp = (struct _mu_dbgstream *) 71 sp = (struct _mu_dbgstream *)
72 _mu_stream_create (sizeof (*sp), MU_STREAM_WRITE | 72 _mu_stream_create (sizeof (*sp), MU_STREAM_WRITE |
73 (flags & MU_STREAM_NO_CLOSE)); 73 (flags & MU_STREAM_AUTOCLOSE));
74 if (!sp) 74 if (!sp)
75 return ENOMEM; 75 return ENOMEM;
76 sp->stream.write = _dbg_write; 76 sp->stream.write = _dbg_write;
......
...@@ -62,9 +62,12 @@ static int ...@@ -62,9 +62,12 @@ static int
62 fd_close (struct _mu_stream *str) 62 fd_close (struct _mu_stream *str)
63 { 63 {
64 struct _mu_file_stream *fstr = (struct _mu_file_stream *) str; 64 struct _mu_file_stream *fstr = (struct _mu_file_stream *) str;
65 if (close (fstr->fd)) 65 if (fstr->fd != -1)
66 return errno; 66 {
67 fstr->fd = -1; 67 if ((str->flags & MU_STREAM_AUTOCLOSE) && close (fstr->fd))
68 return errno;
69 fstr->fd = -1;
70 }
68 return 0; 71 return 0;
69 } 72 }
70 73
...@@ -234,8 +237,8 @@ _mu_file_stream_create (mu_stream_t *pstream, size_t size, ...@@ -234,8 +237,8 @@ _mu_file_stream_create (mu_stream_t *pstream, size_t size,
234 char *filename, int flags) 237 char *filename, int flags)
235 { 238 {
236 struct _mu_file_stream *str = 239 struct _mu_file_stream *str =
237 (struct _mu_file_stream *) _mu_stream_create (size, 240 (struct _mu_file_stream *)
238 flags | MU_STREAM_SEEK); 241 _mu_stream_create (size, flags | MU_STREAM_SEEK);
239 if (!str) 242 if (!str)
240 return ENOMEM; 243 return ENOMEM;
241 244
...@@ -267,7 +270,7 @@ mu_file_stream_create (mu_stream_t *pstream, const char *filename, int flags) ...@@ -267,7 +270,7 @@ mu_file_stream_create (mu_stream_t *pstream, const char *filename, int flags)
267 return ENOMEM; 270 return ENOMEM;
268 rc = _mu_file_stream_create (pstream, 271 rc = _mu_file_stream_create (pstream,
269 sizeof (struct _mu_file_stream), 272 sizeof (struct _mu_file_stream),
270 fname, flags); 273 fname, flags | MU_STREAM_AUTOCLOSE);
271 if (rc) 274 if (rc)
272 free (fname); 275 free (fname);
273 return rc; 276 return rc;
......
...@@ -92,27 +92,28 @@ filter_create_rd (mu_stream_t *pstream, mu_stream_t stream, ...@@ -92,27 +92,28 @@ filter_create_rd (mu_stream_t *pstream, mu_stream_t stream,
92 { 92 {
93 int status; 93 int status;
94 mu_stream_t fltstream; 94 mu_stream_t fltstream;
95
96 flags &= ~MU_STREAM_AUTOCLOSE;
95 97
96 status = mu_filter_stream_create (&fltstream, stream, 98 status = mu_filter_stream_create (&fltstream, stream,
97 mode, xcode, xdata, 99 mode, xcode, xdata,
98 flags & ~MU_STREAM_NO_CLOSE); 100 flags);
99 if (status == 0) 101 if (status == 0)
100 { 102 {
101 if (max_line_length) 103 if (max_line_length)
102 { 104 {
103 status = mu_linelen_filter_create (pstream, fltstream, 105 status = mu_linelen_filter_create (pstream, fltstream,
104 max_line_length, 106 max_line_length,
105 flags & ~MU_STREAM_NO_CLOSE); 107 flags);
108 mu_stream_unref (fltstream);
106 if (status) 109 if (status)
107 mu_stream_destroy (&fltstream); 110 return status;
108 else if (flags & MU_STREAM_NO_CLOSE)
109 mu_stream_set_flags (*pstream, MU_STREAM_NO_CLOSE);
110 } 111 }
111 else 112 else
112 *pstream = fltstream; 113 *pstream = fltstream;
113 114
114 if (flags & MU_STREAM_NO_CLOSE) 115 if (flags & MU_STREAM_AUTOCLOSE)
115 mu_stream_set_flags (fltstream, MU_STREAM_NO_CLOSE); 116 mu_stream_unref (stream);
116 } 117 }
117 return status; 118 return status;
118 } 119 }
...@@ -125,29 +126,31 @@ filter_create_wr (mu_stream_t *pstream, mu_stream_t stream, ...@@ -125,29 +126,31 @@ filter_create_wr (mu_stream_t *pstream, mu_stream_t stream,
125 int flags) 126 int flags)
126 { 127 {
127 int status; 128 int status;
128 mu_stream_t fltstream, instream = NULL; 129 mu_stream_t fltstream, instream = NULL, tmpstr;
130
131 flags &= ~MU_STREAM_AUTOCLOSE;
129 132
130 if (max_line_length) 133 if (max_line_length)
131 { 134 {
132 status = mu_linelen_filter_create (&instream, stream, 135 status = mu_linelen_filter_create (&instream, stream,
133 max_line_length, 136 max_line_length,
134 flags & ~MU_STREAM_NO_CLOSE); 137 flags);
135 if (status) 138 if (status)
136 return status; 139 return status;
137 stream = instream; 140 tmpstr = instream;
138 } 141 }
142 else
143 tmpstr = stream;
139 144
140 status = mu_filter_stream_create (&fltstream, stream, 145 status = mu_filter_stream_create (&fltstream, tmpstr,
141 mode, xcode, xdata, 146 mode, xcode, xdata,
142 flags); 147 flags);
143 if (instream) 148 mu_stream_unref (instream);
144 { 149 if (status)
145 if (status) 150 return status;
146 mu_stream_destroy (&instream);
147 else if (flags & MU_STREAM_NO_CLOSE)
148 mu_stream_set_flags (fltstream, MU_STREAM_NO_CLOSE);
149 }
150 *pstream = fltstream; 151 *pstream = fltstream;
152 if (flags & MU_STREAM_AUTOCLOSE)
153 mu_stream_unref (stream);
151 return status; 154 return status;
152 } 155 }
153 156
......
...@@ -90,8 +90,7 @@ _icvt_close (mu_stream_t stream) ...@@ -90,8 +90,7 @@ _icvt_close (mu_stream_t stream)
90 struct icvt_stream *s = (struct icvt_stream *)stream; 90 struct icvt_stream *s = (struct icvt_stream *)stream;
91 if (s->state != state_closed) 91 if (s->state != state_closed)
92 { 92 {
93 if (!(stream->flags & MU_STREAM_NO_CLOSE)) 93 mu_stream_close (s->transport);
94 mu_stream_close (s->transport);
95 iconv_close (s->cd); 94 iconv_close (s->cd);
96 s->cd = (iconv_t) -1; 95 s->cd = (iconv_t) -1;
97 s->state = state_closed; 96 s->state = state_closed;
...@@ -106,8 +105,7 @@ _icvt_done (mu_stream_t stream) ...@@ -106,8 +105,7 @@ _icvt_done (mu_stream_t stream)
106 105
107 if (s->state != state_closed) 106 if (s->state != state_closed)
108 _icvt_close (stream); 107 _icvt_close (stream);
109 if (!(stream->flags & MU_STREAM_NO_CLOSE)) 108 mu_stream_destroy (&s->transport);
110 mu_stream_destroy (&s->transport);
111 free (s->buf); 109 free (s->buf);
112 } 110 }
113 111
...@@ -442,6 +440,8 @@ mu_filter_iconv_create (mu_stream_t *s, mu_stream_t transport, ...@@ -442,6 +440,8 @@ mu_filter_iconv_create (mu_stream_t *s, mu_stream_t transport,
442 return ENOMEM; 440 return ENOMEM;
443 } 441 }
444 442
443 if (!(flags & MU_STREAM_AUTOCLOSE))
444 mu_stream_ref (transport);
445 iptr->transport = transport; 445 iptr->transport = transport;
446 iptr->fallback_mode = fallback_mode; 446 iptr->fallback_mode = fallback_mode;
447 iptr->cd = cd; 447 iptr->cd = cd;
......
...@@ -45,8 +45,8 @@ ...@@ -45,8 +45,8 @@
45 static void 45 static void
46 init_iobuf (struct mu_filter_io *io, struct _mu_filter_stream *fs) 46 init_iobuf (struct mu_filter_io *io, struct _mu_filter_stream *fs)
47 { 47 {
48 io->input = MFB_CURPTR (fs->inbuf); 48 io->input = MFB_BASE (fs->inbuf);
49 io->isize = MFB_RDBYTES (fs->inbuf); 49 io->isize = MFB_LEVEL (fs->inbuf);
50 io->output = MFB_ENDPTR (fs->outbuf); 50 io->output = MFB_ENDPTR (fs->outbuf);
51 io->osize = MFB_FREESIZE (fs->outbuf); 51 io->osize = MFB_FREESIZE (fs->outbuf);
52 } 52 }
...@@ -234,7 +234,7 @@ filter_write_internal (mu_stream_t stream, enum mu_filter_command cmd, ...@@ -234,7 +234,7 @@ filter_write_internal (mu_stream_t stream, enum mu_filter_command cmd,
234 break; 234 break;
235 if (rdsize > MFB_FREESIZE (fs->inbuf)) 235 if (rdsize > MFB_FREESIZE (fs->inbuf))
236 rdsize = MFB_FREESIZE (fs->inbuf); 236 rdsize = MFB_FREESIZE (fs->inbuf);
237 memcpy (MFB_BASE (fs->inbuf), buf + total, rdsize); 237 memcpy (MFB_ENDPTR (fs->inbuf), buf + total, rdsize);
238 MFB_advance_level (&fs->inbuf, rdsize); 238 MFB_advance_level (&fs->inbuf, rdsize);
239 total += rdsize; 239 total += rdsize;
240 } 240 }
...@@ -374,8 +374,6 @@ filter_done (mu_stream_t stream) ...@@ -374,8 +374,6 @@ filter_done (mu_stream_t stream)
374 fs->xcode (fs->xdata, mu_filter_done, NULL); 374 fs->xcode (fs->xdata, mu_filter_done, NULL);
375 free (fs->xdata); 375 free (fs->xdata);
376 } 376 }
377 if (stream->flags & MU_STREAM_NO_CLOSE)
378 return;
379 mu_stream_destroy (&fs->transport); 377 mu_stream_destroy (&fs->transport);
380 } 378 }
381 379
...@@ -383,8 +381,6 @@ static int ...@@ -383,8 +381,6 @@ static int
383 filter_close (mu_stream_t stream) 381 filter_close (mu_stream_t stream)
384 { 382 {
385 struct _mu_filter_stream *fs = (struct _mu_filter_stream *)stream; 383 struct _mu_filter_stream *fs = (struct _mu_filter_stream *)stream;
386 if (stream->flags & MU_STREAM_NO_CLOSE)
387 return 0;
388 MBF_CLEAR (fs->inbuf); 384 MBF_CLEAR (fs->inbuf);
389 MBF_CLEAR (fs->outbuf); 385 MBF_CLEAR (fs->outbuf);
390 return mu_stream_close (fs->transport); 386 return mu_stream_close (fs->transport);
...@@ -463,7 +459,9 @@ mu_filter_stream_create (mu_stream_t *pflt, ...@@ -463,7 +459,9 @@ mu_filter_stream_create (mu_stream_t *pflt,
463 fs->stream.ctl = filter_ctl; 459 fs->stream.ctl = filter_ctl;
464 fs->stream.error_string = filter_error_string; 460 fs->stream.error_string = filter_error_string;
465 fs->stream.flags = flags; 461 fs->stream.flags = flags;
466 462
463 if (!(flags & MU_STREAM_AUTOCLOSE))
464 mu_stream_ref (str);
467 fs->transport = str; 465 fs->transport = str;
468 fs->xcode = xcode; 466 fs->xcode = xcode;
469 fs->xdata = xdata; 467 fs->xdata = xdata;
......
...@@ -112,11 +112,8 @@ static int ...@@ -112,11 +112,8 @@ static int
112 _iostream_close (struct _mu_stream *str) 112 _iostream_close (struct _mu_stream *str)
113 { 113 {
114 struct _mu_iostream *sp = (struct _mu_iostream *)str; 114 struct _mu_iostream *sp = (struct _mu_iostream *)str;
115 if (sp->stream.flags & MU_STREAM_NO_CLOSE)
116 return 0;
117 mu_stream_close (sp->transport[_MU_STREAM_INPUT]); 115 mu_stream_close (sp->transport[_MU_STREAM_INPUT]);
118 if (sp->transport[_MU_STREAM_INPUT] != sp->transport[_MU_STREAM_OUTPUT]) 116 mu_stream_close (sp->transport[_MU_STREAM_OUTPUT]);
119 mu_stream_close (sp->transport[_MU_STREAM_OUTPUT]);
120 return 0; 117 return 0;
121 } 118 }
122 119
...@@ -125,8 +122,7 @@ _iostream_done (struct _mu_stream *str) ...@@ -125,8 +122,7 @@ _iostream_done (struct _mu_stream *str)
125 { 122 {
126 struct _mu_iostream *sp = (struct _mu_iostream *)str; 123 struct _mu_iostream *sp = (struct _mu_iostream *)str;
127 mu_stream_unref (sp->transport[_MU_STREAM_INPUT]); 124 mu_stream_unref (sp->transport[_MU_STREAM_INPUT]);
128 if (sp->transport[_MU_STREAM_INPUT] != sp->transport[_MU_STREAM_OUTPUT]) 125 mu_stream_unref (sp->transport[_MU_STREAM_OUTPUT]);
129 mu_stream_unref (sp->transport[_MU_STREAM_OUTPUT]);
130 } 126 }
131 127
132 static int 128 static int
...@@ -212,15 +208,13 @@ _iostream_error_string (struct _mu_stream *str, int rc) ...@@ -212,15 +208,13 @@ _iostream_error_string (struct _mu_stream *str, int rc)
212 } 208 }
213 209
214 int 210 int
215 mu_iostream_create (mu_stream_t *pref, mu_stream_t in, mu_stream_t out, 211 mu_iostream_create (mu_stream_t *pref, mu_stream_t in, mu_stream_t out)
216 int flags)
217 { 212 {
218 struct _mu_iostream *sp; 213 struct _mu_iostream *sp;
219 214
220 sp = (struct _mu_iostream *) 215 sp = (struct _mu_iostream *)
221 _mu_stream_create (sizeof (*sp), 216 _mu_stream_create (sizeof (*sp),
222 MU_STREAM_READ | MU_STREAM_WRITE | 217 MU_STREAM_READ | MU_STREAM_WRITE);
223 (flags & MU_STREAM_NO_CLOSE));
224 if (!sp) 218 if (!sp)
225 return ENOMEM; 219 return ENOMEM;
226 220
......
...@@ -520,7 +520,7 @@ mu_mimehdr_decode_param (const char *value, int flags, ...@@ -520,7 +520,7 @@ mu_mimehdr_decode_param (const char *value, int flags,
520 break; 520 break;
521 521
522 rc = mu_filter_iconv_create (&cvt, instr, source_cs, charset, 522 rc = mu_filter_iconv_create (&cvt, instr, source_cs, charset,
523 MU_STREAM_NO_CLOSE, 523 0,
524 mu_default_fallback_mode); 524 mu_default_fallback_mode);
525 if (rc) 525 if (rc)
526 break; 526 break;
......
...@@ -1328,17 +1328,17 @@ mu_decode_filter (mu_stream_t *pfilter, mu_stream_t input, ...@@ -1328,17 +1328,17 @@ mu_decode_filter (mu_stream_t *pfilter, mu_stream_t input,
1328 if (fromcode && tocode && mu_c_strcasecmp (fromcode, tocode)) 1328 if (fromcode && tocode && mu_c_strcasecmp (fromcode, tocode))
1329 { 1329 {
1330 mu_stream_t cvt; 1330 mu_stream_t cvt;
1331
1331 status = mu_filter_iconv_create (&cvt, filter, fromcode, tocode, 1332 status = mu_filter_iconv_create (&cvt, filter, fromcode, tocode,
1332 MU_STREAM_NO_CLOSE, 1333 0, mu_default_fallback_mode);
1333 mu_default_fallback_mode);
1334 if (status == 0) 1334 if (status == 0)
1335 { 1335 {
1336 if (mu_stream_open (cvt)) 1336 if (mu_stream_open (cvt))
1337 mu_stream_destroy (&cvt); 1337 mu_stream_destroy (&cvt);
1338 else 1338 else
1339 { 1339 {
1340 mu_stream_clr_flags (cvt, MU_STREAM_NO_CLOSE); 1340 mu_stream_unref (filter);
1341 filter = cvt; 1341 filter = cvt;
1342 } 1342 }
1343 } 1343 }
1344 } 1344 }
......
...@@ -301,7 +301,7 @@ _prog_open (mu_stream_t stream) ...@@ -301,7 +301,7 @@ _prog_open (mu_stream_t stream)
301 if (REDIRECT_STDOUT_P (flags)) 301 if (REDIRECT_STDOUT_P (flags))
302 { 302 {
303 rc = mu_stdio_stream_create (&fs->in, pfd[0], 303 rc = mu_stdio_stream_create (&fs->in, pfd[0],
304 MU_STREAM_READ|seekable_flag); 304 MU_STREAM_READ|MU_STREAM_AUTOCLOSE|seekable_flag);
305 if (rc) 305 if (rc)
306 { 306 {
307 _prog_close (stream); 307 _prog_close (stream);
...@@ -318,7 +318,7 @@ _prog_open (mu_stream_t stream) ...@@ -318,7 +318,7 @@ _prog_open (mu_stream_t stream)
318 if (REDIRECT_STDIN_P (flags)) 318 if (REDIRECT_STDIN_P (flags))
319 { 319 {
320 rc = mu_stdio_stream_create (&fs->out, pfd[1], 320 rc = mu_stdio_stream_create (&fs->out, pfd[1],
321 MU_STREAM_WRITE|seekable_flag); 321 MU_STREAM_WRITE|MU_STREAM_AUTOCLOSE|seekable_flag);
322 if (rc) 322 if (rc)
323 { 323 {
324 _prog_close (stream); 324 _prog_close (stream);
...@@ -454,6 +454,7 @@ mu_filter_prog_stream_create (mu_stream_t *pstream, const char *progname, ...@@ -454,6 +454,7 @@ mu_filter_prog_stream_create (mu_stream_t *pstream, const char *progname,
454 fs = _prog_stream_create (progname, MU_STREAM_RDWR); 454 fs = _prog_stream_create (progname, MU_STREAM_RDWR);
455 if (!fs) 455 if (!fs)
456 return ENOMEM; 456 return ENOMEM;
457 mu_stream_ref (input);
457 fs->input = input; 458 fs->input = input;
458 *pstream = (mu_stream_t) fs; 459 *pstream = (mu_stream_t) fs;
459 return 0; 460 return 0;
......
...@@ -166,6 +166,7 @@ mu_rfc2047_decode (const char *tocode, const char *input, char **ptostr) ...@@ -166,6 +166,7 @@ mu_rfc2047_decode (const char *tocode, const char *input, char **ptostr)
166 mu_stream_seek (in_stream, 0, MU_SEEK_SET, NULL); 166 mu_stream_seek (in_stream, 0, MU_SEEK_SET, NULL);
167 status = mu_decode_filter (&filter, in_stream, filter_type, fromcode, 167 status = mu_decode_filter (&filter, in_stream, filter_type, fromcode,
168 tocode); 168 tocode);
169 mu_stream_unref (in_stream);
169 if (status != 0) 170 if (status != 0)
170 break; 171 break;
171 172
...@@ -273,7 +274,8 @@ mu_rfc2047_encode (const char *charset, const char *encoding, ...@@ -273,7 +274,8 @@ mu_rfc2047_encode (const char *charset, const char *encoding,
273 mu_stream_write (input_stream, text, strlen (text), NULL); 274 mu_stream_write (input_stream, text, strlen (text), NULL);
274 mu_stream_seek (input_stream, 0, MU_SEEK_SET, NULL); 275 mu_stream_seek (input_stream, 0, MU_SEEK_SET, NULL);
275 rc = mu_filter_create (&output_stream, input_stream, 276 rc = mu_filter_create (&output_stream, input_stream,
276 encoding, MU_FILTER_ENCODE, MU_STREAM_READ); 277 encoding, MU_FILTER_ENCODE,
278 MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
277 if (rc == 0) 279 if (rc == 0)
278 { 280 {
279 /* Assume strlen(qp_encoded_text) <= strlen(text) * 3 */ 281 /* Assume strlen(qp_encoded_text) <= strlen(text) * 3 */
......
...@@ -114,7 +114,8 @@ mu_socket_stream_create (mu_stream_t *pstream, const char *filename, int flags) ...@@ -114,7 +114,8 @@ mu_socket_stream_create (mu_stream_t *pstream, const char *filename, int flags)
114 struct _mu_socket_stream *s; 114 struct _mu_socket_stream *s;
115 int rc; 115 int rc;
116 116
117 rc = _mu_stdio_stream_create (pstream, sizeof (*s), flags); 117 rc = _mu_stdio_stream_create (pstream, sizeof (*s),
118 flags | MU_STREAM_AUTOCLOSE);
118 if (rc) 119 if (rc)
119 return rc; 120 return rc;
120 s = (struct _mu_socket_stream *) *pstream; 121 s = (struct _mu_socket_stream *) *pstream;
......
...@@ -54,6 +54,9 @@ _stream_seterror (struct _mu_stream *stream, int code, int perm) ...@@ -54,6 +54,9 @@ _stream_seterror (struct _mu_stream *stream, int code, int perm)
54 #define _stream_advance_buffer(s,n) ((s)->cur += n, (s)->level -= n) 54 #define _stream_advance_buffer(s,n) ((s)->cur += n, (s)->level -= n)
55 #define _stream_buffer_offset(s) ((s)->cur - (s)->buffer) 55 #define _stream_buffer_offset(s) ((s)->cur - (s)->buffer)
56 #define _stream_orig_level(s) ((s)->level + _stream_buffer_offset (s)) 56 #define _stream_orig_level(s) ((s)->level + _stream_buffer_offset (s))
57 #define _stream_buffer_freespace(s) \
58 ((s)->bufsize - (s)->level - _stream_buffer_offset(s))
59 #define _stream_buffer_is_full(s) (_stream_buffer_freespace(s) == 0)
57 60
58 static int 61 static int
59 _stream_fill_buffer (struct _mu_stream *stream) 62 _stream_fill_buffer (struct _mu_stream *stream)
...@@ -93,9 +96,6 @@ _stream_fill_buffer (struct _mu_stream *stream) ...@@ -93,9 +96,6 @@ _stream_fill_buffer (struct _mu_stream *stream)
93 return rc; 96 return rc;
94 } 97 }
95 98
96 #define BUFFER_FULL_P(s) \
97 ((s)->cur + (s)->level == (s)->buffer + (s)->bufsize)
98
99 static int 99 static int
100 _stream_buffer_full_p (struct _mu_stream *stream) 100 _stream_buffer_full_p (struct _mu_stream *stream)
101 { 101 {
...@@ -105,11 +105,11 @@ _stream_buffer_full_p (struct _mu_stream *stream) ...@@ -105,11 +105,11 @@ _stream_buffer_full_p (struct _mu_stream *stream)
105 break; 105 break;
106 106
107 case mu_buffer_line: 107 case mu_buffer_line:
108 return BUFFER_FULL_P (stream) 108 return _stream_buffer_is_full (stream)
109 || memchr (stream->cur, '\n', stream->level) != NULL; 109 || memchr (stream->cur, '\n', stream->level) != NULL;
110 110
111 case mu_buffer_full: 111 case mu_buffer_full:
112 return BUFFER_FULL_P (stream); 112 return _stream_buffer_is_full (stream);
113 } 113 }
114 return 0; 114 return 0;
115 } 115 }
...@@ -135,8 +135,7 @@ _stream_flush_buffer (struct _mu_stream *stream, int all) ...@@ -135,8 +135,7 @@ _stream_flush_buffer (struct _mu_stream *stream, int all)
135 if ((rc = mu_stream_write_unbuffered (stream, stream->cur, 135 if ((rc = mu_stream_write_unbuffered (stream, stream->cur,
136 stream->level, 1, NULL))) 136 stream->level, 1, NULL)))
137 return rc; 137 return rc;
138 if (all) 138 _stream_advance_buffer (stream, stream->level);
139 _stream_advance_buffer (stream, stream->level);
140 break; 139 break;
141 140
142 case mu_buffer_line: 141 case mu_buffer_line:
...@@ -154,7 +153,7 @@ _stream_flush_buffer (struct _mu_stream *stream, int all) ...@@ -154,7 +153,7 @@ _stream_flush_buffer (struct _mu_stream *stream, int all)
154 return rc; 153 return rc;
155 _stream_advance_buffer (stream, size); 154 _stream_advance_buffer (stream, size);
156 } 155 }
157 if ((all && stream->level) || BUFFER_FULL_P (stream)) 156 if ((all && stream->level) || _stream_buffer_is_full (stream))
158 { 157 {
159 rc = mu_stream_write_unbuffered (stream, 158 rc = mu_stream_write_unbuffered (stream,
160 stream->cur, 159 stream->cur,
...@@ -799,7 +798,7 @@ mu_stream_write (mu_stream_t stream, const void *buf, size_t size, ...@@ -799,7 +798,7 @@ mu_stream_write (mu_stream_t stream, const void *buf, size_t size,
799 if (size == 0) 798 if (size == 0)
800 break; 799 break;
801 800
802 n = stream->bufsize - stream->level; 801 n = _stream_buffer_freespace (stream);
803 if (n > size) 802 if (n > size)
804 n = size; 803 n = size;
805 memcpy (stream->cur + stream->level, bufp, n); 804 memcpy (stream->cur + stream->level, bufp, n);
......
...@@ -140,8 +140,6 @@ static int ...@@ -140,8 +140,6 @@ static int
140 _streamref_close (struct _mu_stream *str) 140 _streamref_close (struct _mu_stream *str)
141 { 141 {
142 struct _mu_streamref *sp = (struct _mu_streamref *)str; 142 struct _mu_streamref *sp = (struct _mu_streamref *)str;
143 if (sp->stream.flags & MU_STREAM_NO_CLOSE)
144 return 0;
145 return streamref_return (sp, mu_stream_close (sp->transport)); 143 return streamref_return (sp, mu_stream_close (sp->transport));
146 } 144 }
147 145
...@@ -271,9 +269,11 @@ mu_streamref_create_abridged (mu_stream_t *pref, mu_stream_t str, ...@@ -271,9 +269,11 @@ mu_streamref_create_abridged (mu_stream_t *pref, mu_stream_t str,
271 if (rc) 269 if (rc)
272 return rc; 270 return rc;
273 mu_stream_get_flags (str, &flags); 271 mu_stream_get_flags (str, &flags);
274 sp = (struct _mu_streamref *) _mu_stream_create (sizeof (*sp), flags); 272 sp = (struct _mu_streamref *)
273 _mu_stream_create (sizeof (*sp), flags & ~MU_STREAM_AUTOCLOSE);
275 if (!sp) 274 if (!sp)
276 return ENOMEM; 275 return ENOMEM;
276
277 mu_stream_ref (str); 277 mu_stream_ref (str);
278 278
279 sp->stream.read = _streamref_read; 279 sp->stream.read = _streamref_read;
......
...@@ -317,7 +317,7 @@ mu_tcp_stream_create_with_source_ip (mu_stream_t *stream, ...@@ -317,7 +317,7 @@ mu_tcp_stream_create_with_source_ip (mu_stream_t *stream,
317 if (port < 1) 317 if (port < 1)
318 return MU_ERR_TCP_NO_PORT; 318 return MU_ERR_TCP_NO_PORT;
319 319
320 tcp = _create_tcp_stream (flags | MU_STREAM_NO_CHECK | MU_STREAM_RDWR); 320 tcp = _create_tcp_stream (flags | MU_STREAM_RDWR);
321 if (!tcp) 321 if (!tcp)
322 return ENOMEM; 322 return ENOMEM;
323 tcp->host = strdup (host); 323 tcp->host = strdup (host);
......
...@@ -58,7 +58,9 @@ mu_temp_file_stream_create (mu_stream_t *pstream, const char *dir) ...@@ -58,7 +58,9 @@ mu_temp_file_stream_create (mu_stream_t *pstream, const char *dir)
58 58
59 rc = _mu_file_stream_create (pstream, 59 rc = _mu_file_stream_create (pstream,
60 sizeof (struct _mu_file_stream), 60 sizeof (struct _mu_file_stream),
61 fname, MU_STREAM_RDWR|MU_STREAM_CREAT); 61 fname,
62 MU_STREAM_RDWR | MU_STREAM_CREAT |
63 MU_STREAM_AUTOCLOSE);
62 if (rc) 64 if (rc)
63 { 65 {
64 free (fname); 66 free (fname);
......
...@@ -224,7 +224,7 @@ mu_vartab_expand (mu_vartab_t vt, const char *str, char **pres) ...@@ -224,7 +224,7 @@ mu_vartab_expand (mu_vartab_t vt, const char *str, char **pres)
224 return EINVAL; 224 return EINVAL;
225 if (!vt->stream) 225 if (!vt->stream)
226 { 226 {
227 rc = mu_memory_stream_create (&vt->stream, MU_STREAM_NO_CHECK); 227 rc = mu_memory_stream_create (&vt->stream, 0);
228 if (rc) 228 if (rc)
229 return rc; 229 return rc;
230 rc = mu_stream_open (vt->stream); 230 rc = mu_stream_open (vt->stream);
......
...@@ -144,8 +144,6 @@ static int ...@@ -144,8 +144,6 @@ static int
144 _xscript_close (struct _mu_stream *str) 144 _xscript_close (struct _mu_stream *str)
145 { 145 {
146 struct _mu_xscript_stream *sp = (struct _mu_xscript_stream *)str; 146 struct _mu_xscript_stream *sp = (struct _mu_xscript_stream *)str;
147 if (sp->stream.flags & MU_STREAM_NO_CLOSE)
148 return 0;
149 return mu_stream_close (sp->transport); 147 return mu_stream_close (sp->transport);
150 } 148 }
151 149
...@@ -268,9 +266,12 @@ mu_xscript_stream_create(mu_stream_t *pref, mu_stream_t transport, ...@@ -268,9 +266,12 @@ mu_xscript_stream_create(mu_stream_t *pref, mu_stream_t transport,
268 sp->stream.shutdown = _xscript_shutdown; 266 sp->stream.shutdown = _xscript_shutdown;
269 sp->stream.error_string = _xscript_error_string; 267 sp->stream.error_string = _xscript_error_string;
270 268
271 mu_stream_ref (transport); 269 if (!(flags & MU_STREAM_AUTOCLOSE))
270 {
271 mu_stream_ref (transport);
272 mu_stream_ref (logstr);
273 }
272 sp->transport = transport; 274 sp->transport = transport;
273 mu_stream_ref (logstr);
274 sp->logstr = logstr; 275 sp->logstr = logstr;
275 276
276 sp->flags = TRANS_READ | TRANS_WRITE; 277 sp->flags = TRANS_READ | TRANS_WRITE;
......
...@@ -698,9 +698,9 @@ eval_body (struct eval_env *env) ...@@ -698,9 +698,9 @@ eval_body (struct eval_env *env)
698 mu_header_aget_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, &encoding); 698 mu_header_aget_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, &encoding);
699 if (encoding) 699 if (encoding)
700 { 700 {
701 int rc = mu_filter_create(&dstr, input, encoding, 701 int rc = mu_filter_create (&dstr, input, encoding,
702 MU_FILTER_DECODE, 702 MU_FILTER_DECODE,
703 MU_STREAM_READ | MU_STREAM_NO_CLOSE); 703 MU_STREAM_READ);
704 if (rc == 0) 704 if (rc == 0)
705 input = dstr; 705 input = dstr;
706 free (encoding); 706 free (encoding);
......
...@@ -1119,7 +1119,7 @@ mhn_message_size (mu_message_t msg, size_t *psize) ...@@ -1119,7 +1119,7 @@ mhn_message_size (mu_message_t msg, size_t *psize)
1119 1119
1120 rc = mu_filter_create (&dstr, bstr, encoding, 1120 rc = mu_filter_create (&dstr, bstr, encoding,
1121 MU_FILTER_DECODE, 1121 MU_FILTER_DECODE,
1122 MU_STREAM_READ | MU_STREAM_NO_CLOSE); 1122 MU_STREAM_READ);
1123 free (encoding); 1123 free (encoding);
1124 if (rc == 0) 1124 if (rc == 0)
1125 { 1125 {
...@@ -1256,7 +1256,7 @@ show_internal (mu_message_t msg, msg_part_t part, char *encoding, mu_stream_t ou ...@@ -1256,7 +1256,7 @@ show_internal (mu_message_t msg, msg_part_t part, char *encoding, mu_stream_t ou
1256 } 1256 }
1257 mu_body_get_streamref (body, &bstr); 1257 mu_body_get_streamref (body, &bstr);
1258 rc = mu_filter_create (&dstr, bstr, encoding, 1258 rc = mu_filter_create (&dstr, bstr, encoding,
1259 MU_FILTER_DECODE, MU_STREAM_READ | MU_STREAM_NO_CLOSE); 1259 MU_FILTER_DECODE, MU_STREAM_READ);
1260 if (rc == 0) 1260 if (rc == 0)
1261 bstr = dstr; 1261 bstr = dstr;
1262 rc = mu_stream_copy (out, bstr, 0); 1262 rc = mu_stream_copy (out, bstr, 0);
...@@ -2001,7 +2001,7 @@ finish_text_msg (struct compose_env *env, mu_message_t *msg, int ascii) ...@@ -2001,7 +2001,7 @@ finish_text_msg (struct compose_env *env, mu_message_t *msg, int ascii)
2001 mu_body_get_streamref (body, &input); 2001 mu_body_get_streamref (body, &input);
2002 rc = mu_filter_create (&fstr, input, "quoted-printable", 2002 rc = mu_filter_create (&fstr, input, "quoted-printable",
2003 MU_FILTER_ENCODE, 2003 MU_FILTER_ENCODE,
2004 MU_STREAM_READ | MU_STREAM_NO_CLOSE); 2004 MU_STREAM_READ);
2005 if (rc == 0) 2005 if (rc == 0)
2006 { 2006 {
2007 mu_stream_copy (output, fstr, 0); 2007 mu_stream_copy (output, fstr, 0);
...@@ -2276,7 +2276,8 @@ edit_mime (char *cmd, struct compose_env *env, mu_message_t *msg, int level) ...@@ -2276,7 +2276,8 @@ edit_mime (char *cmd, struct compose_env *env, mu_message_t *msg, int level)
2276 free (subtype); 2276 free (subtype);
2277 } 2277 }
2278 2278
2279 rc = mu_filter_create (&fstr, in, encoding, MU_FILTER_ENCODE, MU_STREAM_READ); 2279 rc = mu_filter_create (&fstr, in, encoding, MU_FILTER_ENCODE,
2280 MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
2280 if (rc) 2281 if (rc)
2281 { 2282 {
2282 fstr = in; 2283 fstr = in;
......
...@@ -259,7 +259,7 @@ display_file (const char *type) ...@@ -259,7 +259,7 @@ display_file (const char *type)
259 { 259 {
260 mu_stdio_stream_create (&stream, fileno (mimeview_fp), 260 mu_stdio_stream_create (&stream, fileno (mimeview_fp),
261 MU_STREAM_READ| 261 MU_STREAM_READ|
262 MU_STREAM_SEEK|MU_STREAM_NO_CLOSE); 262 MU_STREAM_SEEK);
263 mu_stream_open (stream); 263 mu_stream_open (stream);
264 264
265 display_stream_mailcap (mimeview_file, stream, hdr, 265 display_stream_mailcap (mimeview_file, stream, hdr,
......
...@@ -144,22 +144,22 @@ pop3d_setio (FILE *in, FILE *out) ...@@ -144,22 +144,22 @@ pop3d_setio (FILE *in, FILE *out)
144 if (!out) 144 if (!out)
145 pop3d_abquit (ERR_NO_OFILE); 145 pop3d_abquit (ERR_NO_OFILE);
146 146
147 if (mu_stdio_stream_create (&istream, fileno (in), 147 if (mu_stdio_stream_create (&istream, fileno (in),
148 MU_STREAM_READ | MU_STREAM_NO_CLOSE)) 148 MU_STREAM_READ | MU_STREAM_AUTOCLOSE))
149 pop3d_abquit (ERR_NO_IFILE); 149 pop3d_abquit (ERR_NO_IFILE);
150 real_istream = istream; 150 real_istream = istream;
151 mu_stream_set_buffer (istream, mu_buffer_line, 1024); 151 mu_stream_set_buffer (istream, mu_buffer_line, 1024);
152 152
153 if (mu_stdio_stream_create (&str, fileno (out), 153 if (mu_stdio_stream_create (&str, fileno (out),
154 MU_STREAM_WRITE | MU_STREAM_NO_CLOSE)) 154 MU_STREAM_WRITE | MU_STREAM_AUTOCLOSE))
155 pop3d_abquit (ERR_NO_OFILE); 155 pop3d_abquit (ERR_NO_OFILE);
156 real_ostream = str; 156 real_ostream = str;
157 if (mu_filter_create (&ostream, str, "rfc822", MU_FILTER_ENCODE, 157 if (mu_filter_create (&ostream, str, "rfc822", MU_FILTER_ENCODE,
158 MU_STREAM_WRITE | MU_STREAM_NO_CLOSE)) 158 MU_STREAM_WRITE))
159 pop3d_abquit (ERR_NO_IFILE); 159 pop3d_abquit (ERR_NO_IFILE);
160 mu_stream_set_buffer (ostream, mu_buffer_line, 1024); 160 mu_stream_set_buffer (ostream, mu_buffer_line, 1024);
161 161
162 if (mu_iostream_create (&iostream, istream, ostream, 0)) 162 if (mu_iostream_create (&iostream, istream, ostream))
163 pop3d_abquit (ERR_FILE); 163 pop3d_abquit (ERR_FILE);
164 if (pop3d_transcript) 164 if (pop3d_transcript)
165 { 165 {
...@@ -169,8 +169,7 @@ pop3d_setio (FILE *in, FILE *out) ...@@ -169,8 +169,7 @@ pop3d_setio (FILE *in, FILE *out)
169 169
170 mu_diag_get_debug (&debug); 170 mu_diag_get_debug (&debug);
171 171
172 rc = mu_dbgstream_create (&dstr, debug, MU_DIAG_DEBUG, 172 rc = mu_dbgstream_create (&dstr, debug, MU_DIAG_DEBUG, 0);
173 MU_STREAM_NO_CLOSE);
174 if (rc) 173 if (rc)
175 mu_error (_("cannot create debug stream; transcript disabled: %s"), 174 mu_error (_("cannot create debug stream; transcript disabled: %s"),
176 mu_strerror (rc)); 175 mu_strerror (rc));
...@@ -181,7 +180,10 @@ pop3d_setio (FILE *in, FILE *out) ...@@ -181,7 +180,10 @@ pop3d_setio (FILE *in, FILE *out)
181 mu_error (_("cannot create transcript stream: %s"), 180 mu_error (_("cannot create transcript stream: %s"),
182 mu_strerror (rc)); 181 mu_strerror (rc));
183 else 182 else
184 iostream = xstr; 183 {
184 mu_stream_unref (iostream);
185 iostream = xstr;
186 }
185 } 187 }
186 } 188 }
187 } 189 }
...@@ -193,8 +195,7 @@ pop3d_init_tls_server () ...@@ -193,8 +195,7 @@ pop3d_init_tls_server ()
193 mu_stream_t stream; 195 mu_stream_t stream;
194 int rc; 196 int rc;
195 197
196 rc = mu_tls_server_stream_create (&stream, real_istream, real_ostream, 198 rc = mu_tls_server_stream_create (&stream, real_istream, real_ostream, 0);
197 MU_STREAM_NO_CLOSE);
198 if (rc) 199 if (rc)
199 return 1; 200 return 1;
200 201
...@@ -208,8 +209,7 @@ pop3d_init_tls_server () ...@@ -208,8 +209,7 @@ pop3d_init_tls_server ()
208 } 209 }
209 210
210 if (mu_filter_create (&stream, stream, "rfc822", MU_FILTER_ENCODE, 211 if (mu_filter_create (&stream, stream, "rfc822", MU_FILTER_ENCODE,
211 MU_STREAM_WRITE | MU_STREAM_RDTHRU | 212 MU_STREAM_WRITE | MU_STREAM_RDTHRU))
212 MU_STREAM_NO_CLOSE))
213 pop3d_abquit (ERR_NO_IFILE); 213 pop3d_abquit (ERR_NO_IFILE);
214 214
215 if (pop3d_transcript) 215 if (pop3d_transcript)
......