Commit 64b00582 64b00582e8b3b08cbf1b6e530583b1757a8bdf77 by Sergey Poznyakoff

filter subsystem: bugfixes.

* include/mailutils/sys/filter.h (_mu_filter_stream)<eof>: New member.
* libmailutils/filter/binflt.c (_bit8_filter): Change name initializer
to "8bit".
(_bit7_filter): Change name initializer to "7bit".
* libmailutils/filter/filter.c (mu_filter_create): Limit line
length for encoding streams only.
* libmailutils/stream/fltstream.c (filter_read): Use fs->eof instead
of the regular stream EOF marker.
* libmailutils/stream/stream.c (mu_stream_eof): Bugfix: take into
account eventual buffered data.
(_stream_read_unbuffered): Call mu_stream_eof instead of checking
the _MU_STR_EOF bit.
1 parent 439f8c1a
......@@ -41,6 +41,7 @@ struct _mu_filter_stream
struct _mu_stream stream;
mu_stream_t transport;
int mode;
int eof;
struct _mu_filter_buffer inbuf, outbuf;
mu_filter_xcode_t xcode;
......
......@@ -93,7 +93,7 @@ mu_filter_record_t mu_binary_filter = &_binary_filter;
static struct _mu_filter_record _bit8_filter = {
"bit8",
"8bit",
0,
NULL,
_copy_codec,
......@@ -103,7 +103,7 @@ static struct _mu_filter_record _bit8_filter = {
mu_filter_record_t mu_bit8_filter = &_bit8_filter;
static struct _mu_filter_record _bit7_filter = {
"bit7",
"7bit",
0,
NULL,
_bit7_coder,
......
......@@ -182,7 +182,7 @@ mu_filter_create (mu_stream_t *pstream, mu_stream_t stream, const char *name,
status = ((flags & MU_STREAM_WRITE) ? filter_create_wr : filter_create_rd)
(pstream, stream,
frec->max_line_length,
mode == MU_FILTER_ENCODE ? frec->max_line_length : 0,
mode,
mode == MU_FILTER_ENCODE ? frec->encoder : frec->decoder,
xdata,
......
......@@ -128,6 +128,9 @@ filter_read (mu_stream_t stream, char *buf, size_t size, size_t *pret)
enum mu_filter_result res;
int rc;
if (fs->eof)
break;
if (MFB_RDBYTES (fs->inbuf) < min_input_level && !again)
{
rc = MFB_require (&fs->inbuf, min_input_level);
......@@ -174,7 +177,7 @@ filter_read (mu_stream_t stream, char *buf, size_t size, size_t *pret)
again = 0;
if (cmd == mu_filter_lastbuf || iobuf.eof)
{
_mu_stream_seteof (stream);
fs->eof = 1;
stop = 1;
}
break;
......@@ -517,8 +520,10 @@ mu_filter_stream_create (mu_stream_t *pflt,
fs->xcode = xcode;
fs->xdata = xdata;
fs->mode = mode;
fs->eof = 0;
mu_stream_set_buffer ((mu_stream_t) fs, mu_buffer_full, MU_FILTER_BUF_SIZE);
mu_stream_set_buffer ((mu_stream_t) fs, mu_buffer_full,
MU_FILTER_BUF_SIZE);
rc = filter_stream_init (fs);
if (rc)
......
......@@ -368,7 +368,7 @@ mu_stream_clearerr (mu_stream_t stream)
int
mu_stream_eof (mu_stream_t stream)
{
return stream->flags & _MU_STR_EOF;
return (stream->flags & _MU_STR_EOF) && (stream->pos == stream->level);
}
int
......@@ -589,7 +589,7 @@ _stream_read_unbuffered (mu_stream_t stream, void *buf, size_t size,
if (stream->flags & _MU_STR_ERR)
return stream->last_err;
if ((stream->flags & _MU_STR_EOF) || size == 0)
if (mu_stream_eof (stream) || size == 0)
{
if (pnread)
*pnread = 0;
......