Commit 841fc484 841fc4842ae81579edab2a7752b0347944575d2c by Sergey Poznyakoff

Remove MU_STREAM_AUTOCLOSE flag. Use mu_stream_unref, if necessary.

* examples/mta.c: Use MU_STREAM_FD_AUTOCLOSE.
* imap4d/io.c: Likewise.
* libmailutils/stream/file_stream.c: Likewise.
* libmailutils/stream/prog_stream.c: Likewise.
* libmailutils/stream/socket_stream.c: Likewise.
* libmailutils/stream/temp_file_stream.c: Likewise.
* maidag/lmtp.c: Likewise.
* pop3d/extra.c: Likewise.

* imap4d/preauth.c: Do not use MU_STREAM_AUTOCLOSE.  Instead unref the
transport stream after creating the derived one.
* libmailutils/base/rfc2047.c: Likewise.
* libmailutils/stream/fltstream.c: Likewise.
* libmailutils/tests/fltst.c: Likewise.
* libmu_auth/ldap.c: Likewise.
* libmu_auth/tls.c: Likewise.
* libmu_sieve/extensions/vacation.c: Likewise.
* libproto/pop/pop3_stream.c: Likewise.
* mail/decode.c: Likewise.
* mh/mhn.c: Likewise.

* libmailutils/filter/filter_iconv.c: Do not handle MU_STREAM_AUTOCLOSE.
* libmailutils/stream/rdcache_stream.c: Likewise.
* libmailutils/stream/streamref.c: Likewise.
* libmailutils/stream/xscript-stream.c: Likewise.

* include/mailutils/stream.h (MU_STREAM_AUTOCLOSE): Rename to
MU_STREAM_FD_AUTOCLOSE.
1 parent 8f8d9036
......@@ -570,13 +570,9 @@ eval_biffrc (struct biffrc_environ *env)
if (!sp)
report_error (env, _("unknown keyword"));
else if (ws.ws_wordc < sp->argmin)
{
report_error (env, _("too few arguments"));
}
else if (sp->argmax != -1 && ws.ws_wordc > sp->argmax)
{
report_error (env, _("too many arguments"));
}
else
{
if (sp->expand)
......
......@@ -825,7 +825,7 @@ mta_smtp (int argc, char **argv)
}
rc = mu_fd_stream_create (&str, NULL, sfd,
MU_STREAM_RDWR|MU_STREAM_AUTOCLOSE);
MU_STREAM_RDWR|MU_STREAM_FD_AUTOCLOSE);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_fd_stream_create", NULL, rc);
......
......@@ -30,12 +30,12 @@ io_setio (int ifd, int ofd)
imap4d_bye (ERR_NO_OFILE);
if (mu_stdio_stream_create (&istream, ifd,
MU_STREAM_READ | MU_STREAM_AUTOCLOSE))
MU_STREAM_READ | MU_STREAM_FD_AUTOCLOSE))
imap4d_bye (ERR_STREAM_CREATE);
mu_stream_set_buffer (istream, mu_buffer_line, 0);
if (mu_stdio_stream_create (&ostream, ofd,
MU_STREAM_WRITE | MU_STREAM_AUTOCLOSE))
MU_STREAM_WRITE | MU_STREAM_FD_AUTOCLOSE))
imap4d_bye (ERR_STREAM_CREATE);
mu_stream_set_buffer (ostream, mu_buffer_line, 0);
......
......@@ -193,8 +193,8 @@ decode64_buf (const char *name, unsigned char **pbuf, size_t *psize)
name++;
namelen = strlen (name) - 1;
mu_static_memory_stream_create (&str, name, namelen);
mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, MU_STREAM_READ);
mu_stream_unref (str);
mu_stream_read (flt, buf, sizeof buf, &size);
mu_stream_destroy (&flt);
*pbuf = malloc (size);
......
......@@ -43,7 +43,8 @@ enum mu_buffer_type
#define MU_STREAM_CREAT 0x00000010
/* So far used only by TCP streams. */
#define MU_STREAM_NONBLOCK 0x00000020
#define MU_STREAM_AUTOCLOSE 0x00000040
/* For fd streams only */
#define MU_STREAM_FD_AUTOCLOSE 0x00000040
/* Not used. Intended for mailboxes only. */
#define MU_STREAM_NONLOCK 0x00000080
/* Not used as well 0x00000100 */
......
......@@ -269,8 +269,8 @@ mu_rfc2047_encode (const char *charset, const char *encoding,
if (rc)
return rc;
rc = mu_filter_create (&output_stream, input_stream,
encoding, MU_FILTER_ENCODE,
MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
encoding, MU_FILTER_ENCODE, MU_STREAM_READ);
mu_stream_unref (input_stream);
if (rc == 0)
{
/* Assume strlen(qp_encoded_text) <= strlen(text) * 3 */
......
......@@ -453,7 +453,6 @@ mu_filter_iconv_create (mu_stream_t *s, mu_stream_t transport,
return ENOMEM;
}
if (!(flags & MU_STREAM_AUTOCLOSE))
mu_stream_ref (transport);
iptr->transport = transport;
iptr->fallback_mode = fallback_mode;
......
......@@ -65,7 +65,7 @@ fd_close (struct _mu_stream *str)
struct _mu_file_stream *fstr = (struct _mu_file_stream *) str;
if (fstr->fd != -1)
{
if ((str->flags & MU_STREAM_AUTOCLOSE) && close (fstr->fd))
if ((str->flags & MU_STREAM_FD_AUTOCLOSE) && close (fstr->fd))
return errno;
fstr->fd = -1;
}
......@@ -119,7 +119,7 @@ fd_open (struct _mu_stream *str)
str->flags &= ~MU_STREAM_SEEK;
/* Make sure it will be closed */
str->flags |= MU_STREAM_AUTOCLOSE;
str->flags |= MU_STREAM_FD_AUTOCLOSE;
fstr->fd = fd;
return 0;
......@@ -331,7 +331,8 @@ mu_file_stream_create (mu_stream_t *pstream, const char *filename, int flags)
int rc = _mu_file_stream_create (&fstr,
sizeof (struct _mu_file_stream),
filename, -1,
flags | MU_STREAM_SEEK | MU_STREAM_AUTOCLOSE);
flags | MU_STREAM_SEEK |
MU_STREAM_FD_AUTOCLOSE);
if (rc == 0)
{
mu_stream_t stream = (mu_stream_t) fstr;
......
......@@ -520,7 +520,6 @@ mu_filter_stream_create (mu_stream_t *pflt,
fs->stream.error_string = filter_error_string;
fs->stream.flags = flags;
if (!(flags & MU_STREAM_AUTOCLOSE))
mu_stream_ref (str);
fs->transport = str;
fs->xcode = xcode;
......
......@@ -440,7 +440,7 @@ _prog_open (mu_stream_t stream)
if (REDIRECT_STDOUT_P (flags))
{
rc = mu_stdio_stream_create (&fs->in, pfd[0],
MU_STREAM_READ|MU_STREAM_AUTOCLOSE|seekable_flag);
MU_STREAM_READ|MU_STREAM_FD_AUTOCLOSE|seekable_flag);
if (rc)
{
_prog_close (stream);
......@@ -451,7 +451,7 @@ _prog_open (mu_stream_t stream)
if (REDIRECT_STDIN_P (flags))
{
rc = mu_stdio_stream_create (&fs->out, pfd[1],
MU_STREAM_WRITE|MU_STREAM_AUTOCLOSE|seekable_flag);
MU_STREAM_WRITE|MU_STREAM_FD_AUTOCLOSE|seekable_flag);
if (rc)
{
_prog_close (stream);
......
......@@ -188,7 +188,7 @@ mu_rdcache_stream_create (mu_stream_t *pstream, mu_stream_t transport,
{
struct _mu_rdcache_stream *sp;
int rc;
int sflags = MU_STREAM_READ | MU_STREAM_SEEK | (flags & MU_STREAM_AUTOCLOSE);
int sflags = MU_STREAM_READ | MU_STREAM_SEEK;
if (flags & ~sflags)
return EINVAL;
......@@ -207,7 +207,6 @@ mu_rdcache_stream_create (mu_stream_t *pstream, mu_stream_t transport,
sp->stream.ctl = rdcache_ioctl;
sp->stream.wait = rdcache_wait;
if (!(flags & MU_STREAM_AUTOCLOSE))
mu_stream_ref (transport);
sp->transport = transport;
......
......@@ -99,7 +99,8 @@ mu_socket_stream_create (mu_stream_t *pstream, const char *filename, int flags)
/* Create transport stream. */
rc = _mu_file_stream_create (&fstr, sizeof (*fstr),
filename, -1,
(flags | MU_STREAM_AUTOCLOSE) & ~MU_STREAM_SEEK);
(flags | MU_STREAM_FD_AUTOCLOSE) &
~MU_STREAM_SEEK);
if (rc)
return rc;
fstr->stream.open = _socket_open;
......
......@@ -280,8 +280,7 @@ mu_streamref_create_abridged (mu_stream_t *pref, mu_stream_t str,
return rc;
mu_stream_get_flags (str, &flags);
sp = (struct _mu_streamref *)
_mu_stream_create (sizeof (*sp),
(flags & ~MU_STREAM_AUTOCLOSE) | _MU_STR_OPEN);
_mu_stream_create (sizeof (*sp), flags | _MU_STR_OPEN);
if (!sp)
return ENOMEM;
......
......@@ -68,7 +68,7 @@ mu_temp_file_stream_create (mu_stream_t *pstream,
-1,
MU_STREAM_RDWR | MU_STREAM_SEEK |
MU_STREAM_CREAT |
MU_STREAM_AUTOCLOSE);
MU_STREAM_FD_AUTOCLOSE);
if (rc == 0)
{
struct _mu_temp_file_stream *tstr = (struct _mu_temp_file_stream *)str;
......
......@@ -438,11 +438,9 @@ mu_xscript_stream_create(mu_stream_t *pref, mu_stream_t transport,
sp->stream.event_cb = _xscript_event_cb;
sp->stream.event_mask = _MU_STR_EVMASK(_MU_STR_EVENT_FILLBUF) |
_MU_STR_EVMASK(_MU_STR_EVENT_FLUSHBUF);
if (!(flags & MU_STREAM_AUTOCLOSE))
{
mu_stream_ref (transport);
mu_stream_ref (logstr);
}
sp->transport = transport;
sp->logstr = logstr;
......
......@@ -148,8 +148,8 @@ main (int argc, char * argv [])
MU_ASSERT (mu_filter_create_args (&flt, in, fltname,
argc, (const char **)argv,
mode,
MU_STREAM_READ|MU_STREAM_SEEK|
MU_STREAM_AUTOCLOSE));
MU_STREAM_READ|MU_STREAM_SEEK));
mu_stream_unref (in);
if (shift)
MU_ASSERT (mu_stream_seek (flt, shift, MU_SEEK_SET, NULL));
c_copy (out, flt);
......
......@@ -599,8 +599,8 @@ chk_md5 (const char *db_pass, const char *pass)
mu_md5_finish_ctx (&md5context, md5digest);
mu_static_memory_stream_create (&str, db_pass, strlen (db_pass));
mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, MU_STREAM_READ);
mu_stream_unref (str);
mu_stream_read (flt, (char*) d1, sizeof d1, NULL);
mu_stream_destroy (&flt);
......@@ -621,8 +621,8 @@ chk_smd5 (const char *db_pass, const char *pass)
size = strlen (db_pass);
mu_static_memory_stream_create (&str, db_pass, size);
mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, MU_STREAM_READ);
mu_stream_unref (str);
d1 = malloc (size);
if (!d1)
......@@ -664,8 +664,8 @@ chk_sha (const char *db_pass, const char *pass)
mu_sha1_finish_ctx (&sha1context, sha1digest);
mu_static_memory_stream_create (&str, db_pass, strlen (db_pass));
mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, MU_STREAM_READ);
mu_stream_unref (str);
mu_stream_read (flt, (char*) d1, sizeof d1, NULL);
mu_stream_destroy (&flt);
......@@ -686,8 +686,8 @@ chk_ssha (const char *db_pass, const char *pass)
size = strlen (db_pass);
mu_static_memory_stream_create (&str, db_pass, size);
mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE, MU_STREAM_READ);
mu_stream_unref (str);
d1 = malloc (size);
if (!d1)
......
......@@ -327,7 +327,6 @@ _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;
......@@ -642,7 +641,6 @@ _mu_tls_stream_create (mu_stream_t *pstream,
mu_stream_t strin, mu_stream_t strout, int flags)
{
struct _mu_tls_stream *sp;
int autoclose = flags & MU_STREAM_AUTOCLOSE;
int rc;
mu_stream_t stream;
......@@ -664,16 +662,15 @@ _mu_tls_stream_create (mu_stream_t *pstream,
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 | autoclose, sp);
rc = _mu_tls_io_stream_create (&sp->transport[0], strin, MU_STREAM_READ, sp);
if (rc)
{
free (sp);
return rc;
}
rc = _mu_tls_io_stream_create (&sp->transport[1], strout,
MU_STREAM_WRITE | autoclose, sp);
rc = _mu_tls_io_stream_create (&sp->transport[1], strout, MU_STREAM_WRITE,
sp);
if (rc)
{
free (sp);
......
......@@ -75,7 +75,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_STREAM_AUTOCLOSE);
MU_STREAM_READ);
mu_stream_unref (input);
if (rc == 0)
{
header = "Content-Type: text/plain;charset=" MU_SIEVE_CHARSET "\n"
......
......@@ -73,7 +73,8 @@ mu_pop3_filter_create (mu_stream_t *pstream, mu_stream_t stream)
int rc;
rc = mu_filter_create (pstream, stream, "CRLFDOT", MU_FILTER_DECODE,
MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
MU_STREAM_READ);
mu_stream_unref (stream);
if (rc == 0)
{
struct mu_pop3_stream *sp = (struct mu_pop3_stream *) stream;
......
......@@ -580,7 +580,7 @@ lmtp_connection (int fd, struct sockaddr *sa, int salen, void *data,
int rc;
rc = mu_fd_stream_create (&str, NULL, fd,
MU_STREAM_RDWR|MU_STREAM_AUTOCLOSE);
MU_STREAM_RDWR | MU_STREAM_FD_AUTOCLOSE);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_fd_stream_create", NULL, rc);
......
......@@ -260,8 +260,11 @@ 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_AUTOCLOSE) == 0)
MU_STREAM_READ) == 0)
{
mu_stream_unref (b_stream);
stream = d_stream;
}
else
stream = b_stream;
......
......@@ -2498,13 +2498,13 @@ edit_mime (char *cmd, struct compose_env *env, mu_message_t *msg, int level)
free (subtype);
}
rc = mu_filter_create (&fstr, in, encoding, MU_FILTER_ENCODE,
MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
rc = mu_filter_create (&fstr, in, encoding, MU_FILTER_ENCODE, MU_STREAM_READ);
if (rc)
{
fstr = in;
in = NULL;
mu_stream_ref (in);
}
mu_stream_unref (in);
free (encoding);
mu_message_get_body (*msg, &body);
......
......@@ -135,12 +135,12 @@ pop3d_setio (int ifd, int ofd)
pop3d_abquit (ERR_NO_OFILE);
if (mu_stdio_stream_create (&istream, ifd,
MU_STREAM_READ | MU_STREAM_AUTOCLOSE))
MU_STREAM_READ | MU_STREAM_FD_AUTOCLOSE))
pop3d_abquit (ERR_NO_IFILE);
mu_stream_set_buffer (istream, mu_buffer_line, 0);
if (mu_stdio_stream_create (&ostream, ofd,
MU_STREAM_WRITE | MU_STREAM_AUTOCLOSE))
MU_STREAM_WRITE | MU_STREAM_FD_AUTOCLOSE))
pop3d_abquit (ERR_NO_OFILE);
/* Combine the two streams into an I/O one. */
......