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.
Showing
5 changed files
with
13 additions
and
7 deletions
... | @@ -41,6 +41,7 @@ struct _mu_filter_stream | ... | @@ -41,6 +41,7 @@ struct _mu_filter_stream |
41 | struct _mu_stream stream; | 41 | struct _mu_stream stream; |
42 | mu_stream_t transport; | 42 | mu_stream_t transport; |
43 | int mode; | 43 | int mode; |
44 | int eof; | ||
44 | 45 | ||
45 | struct _mu_filter_buffer inbuf, outbuf; | 46 | struct _mu_filter_buffer inbuf, outbuf; |
46 | mu_filter_xcode_t xcode; | 47 | mu_filter_xcode_t xcode; | ... | ... |
... | @@ -93,7 +93,7 @@ mu_filter_record_t mu_binary_filter = &_binary_filter; | ... | @@ -93,7 +93,7 @@ mu_filter_record_t mu_binary_filter = &_binary_filter; |
93 | 93 | ||
94 | 94 | ||
95 | static struct _mu_filter_record _bit8_filter = { | 95 | static struct _mu_filter_record _bit8_filter = { |
96 | "bit8", | 96 | "8bit", |
97 | 0, | 97 | 0, |
98 | NULL, | 98 | NULL, |
99 | _copy_codec, | 99 | _copy_codec, |
... | @@ -103,7 +103,7 @@ static struct _mu_filter_record _bit8_filter = { | ... | @@ -103,7 +103,7 @@ static struct _mu_filter_record _bit8_filter = { |
103 | mu_filter_record_t mu_bit8_filter = &_bit8_filter; | 103 | mu_filter_record_t mu_bit8_filter = &_bit8_filter; |
104 | 104 | ||
105 | static struct _mu_filter_record _bit7_filter = { | 105 | static struct _mu_filter_record _bit7_filter = { |
106 | "bit7", | 106 | "7bit", |
107 | 0, | 107 | 0, |
108 | NULL, | 108 | NULL, |
109 | _bit7_coder, | 109 | _bit7_coder, | ... | ... |
... | @@ -182,7 +182,7 @@ mu_filter_create (mu_stream_t *pstream, mu_stream_t stream, const char *name, | ... | @@ -182,7 +182,7 @@ mu_filter_create (mu_stream_t *pstream, mu_stream_t stream, const char *name, |
182 | 182 | ||
183 | status = ((flags & MU_STREAM_WRITE) ? filter_create_wr : filter_create_rd) | 183 | status = ((flags & MU_STREAM_WRITE) ? filter_create_wr : filter_create_rd) |
184 | (pstream, stream, | 184 | (pstream, stream, |
185 | frec->max_line_length, | 185 | mode == MU_FILTER_ENCODE ? frec->max_line_length : 0, |
186 | mode, | 186 | mode, |
187 | mode == MU_FILTER_ENCODE ? frec->encoder : frec->decoder, | 187 | mode == MU_FILTER_ENCODE ? frec->encoder : frec->decoder, |
188 | xdata, | 188 | xdata, | ... | ... |
... | @@ -127,6 +127,9 @@ filter_read (mu_stream_t stream, char *buf, size_t size, size_t *pret) | ... | @@ -127,6 +127,9 @@ filter_read (mu_stream_t stream, char *buf, size_t size, size_t *pret) |
127 | { | 127 | { |
128 | enum mu_filter_result res; | 128 | enum mu_filter_result res; |
129 | int rc; | 129 | int rc; |
130 | |||
131 | if (fs->eof) | ||
132 | break; | ||
130 | 133 | ||
131 | if (MFB_RDBYTES (fs->inbuf) < min_input_level && !again) | 134 | if (MFB_RDBYTES (fs->inbuf) < min_input_level && !again) |
132 | { | 135 | { |
... | @@ -174,7 +177,7 @@ filter_read (mu_stream_t stream, char *buf, size_t size, size_t *pret) | ... | @@ -174,7 +177,7 @@ filter_read (mu_stream_t stream, char *buf, size_t size, size_t *pret) |
174 | again = 0; | 177 | again = 0; |
175 | if (cmd == mu_filter_lastbuf || iobuf.eof) | 178 | if (cmd == mu_filter_lastbuf || iobuf.eof) |
176 | { | 179 | { |
177 | _mu_stream_seteof (stream); | 180 | fs->eof = 1; |
178 | stop = 1; | 181 | stop = 1; |
179 | } | 182 | } |
180 | break; | 183 | break; |
... | @@ -517,8 +520,10 @@ mu_filter_stream_create (mu_stream_t *pflt, | ... | @@ -517,8 +520,10 @@ mu_filter_stream_create (mu_stream_t *pflt, |
517 | fs->xcode = xcode; | 520 | fs->xcode = xcode; |
518 | fs->xdata = xdata; | 521 | fs->xdata = xdata; |
519 | fs->mode = mode; | 522 | fs->mode = mode; |
523 | fs->eof = 0; | ||
520 | 524 | ||
521 | mu_stream_set_buffer ((mu_stream_t) fs, mu_buffer_full, MU_FILTER_BUF_SIZE); | 525 | mu_stream_set_buffer ((mu_stream_t) fs, mu_buffer_full, |
526 | MU_FILTER_BUF_SIZE); | ||
522 | 527 | ||
523 | rc = filter_stream_init (fs); | 528 | rc = filter_stream_init (fs); |
524 | if (rc) | 529 | if (rc) | ... | ... |
... | @@ -368,7 +368,7 @@ mu_stream_clearerr (mu_stream_t stream) | ... | @@ -368,7 +368,7 @@ mu_stream_clearerr (mu_stream_t stream) |
368 | int | 368 | int |
369 | mu_stream_eof (mu_stream_t stream) | 369 | mu_stream_eof (mu_stream_t stream) |
370 | { | 370 | { |
371 | return stream->flags & _MU_STR_EOF; | 371 | return (stream->flags & _MU_STR_EOF) && (stream->pos == stream->level); |
372 | } | 372 | } |
373 | 373 | ||
374 | int | 374 | int |
... | @@ -589,7 +589,7 @@ _stream_read_unbuffered (mu_stream_t stream, void *buf, size_t size, | ... | @@ -589,7 +589,7 @@ _stream_read_unbuffered (mu_stream_t stream, void *buf, size_t size, |
589 | if (stream->flags & _MU_STR_ERR) | 589 | if (stream->flags & _MU_STR_ERR) |
590 | return stream->last_err; | 590 | return stream->last_err; |
591 | 591 | ||
592 | if ((stream->flags & _MU_STR_EOF) || size == 0) | 592 | if (mu_stream_eof (stream) || size == 0) |
593 | { | 593 | { |
594 | if (pnread) | 594 | if (pnread) |
595 | *pnread = 0; | 595 | *pnread = 0; | ... | ... |
-
Please register or sign in to post a comment