Fixes in message_stream.
* libmailutils/mailbox/message.c (_message_stream_seek): Fix ESPIPE conditional. (_message_stream_read): Keep running until buffer is full or _mss_eof state is reached. (_message_stream_readdelim): Keep running until buffer is full, _mss_eof state is reached or delimiter is found.
Showing
1 changed file
with
10 additions
and
3 deletions
... | @@ -159,9 +159,8 @@ _message_stream_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *ppos) | ... | @@ -159,9 +159,8 @@ _message_stream_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *ppos) |
159 | return rc; | 159 | return rc; |
160 | mu_header_size (sp->msg->header, &hsize); | 160 | mu_header_size (sp->msg->header, &hsize); |
161 | mu_body_size (sp->msg->body, &size); | 161 | mu_body_size (sp->msg->body, &size); |
162 | size += hsize; | ||
163 | 162 | ||
164 | if (off < 0 || off >= size) | 163 | if (off < 0 || off >= size + hsize) |
165 | return ESPIPE; | 164 | return ESPIPE; |
166 | 165 | ||
167 | switch (sp->state) | 166 | switch (sp->state) |
... | @@ -224,6 +223,10 @@ _message_stream_read (struct _mu_stream *str, char *buf, size_t bufsize, | ... | @@ -224,6 +223,10 @@ _message_stream_read (struct _mu_stream *str, char *buf, size_t bufsize, |
224 | if (sp->state == _mss_eof) | 223 | if (sp->state == _mss_eof) |
225 | break; | 224 | break; |
226 | rc = mu_stream_read (sp->transport, buf, bufsize, &n); | 225 | rc = mu_stream_read (sp->transport, buf, bufsize, &n); |
226 | if (rc) | ||
227 | break; | ||
228 | if (n == 0) | ||
229 | continue; | ||
227 | nread += n; | 230 | nread += n; |
228 | buf += n; | 231 | buf += n; |
229 | bufsize -= n; | 232 | bufsize -= n; |
... | @@ -249,9 +252,13 @@ _message_stream_readdelim (struct _mu_stream *str, char *buf, size_t bufsize, | ... | @@ -249,9 +252,13 @@ _message_stream_readdelim (struct _mu_stream *str, char *buf, size_t bufsize, |
249 | if (sp->state == _mss_eof) | 252 | if (sp->state == _mss_eof) |
250 | break; | 253 | break; |
251 | rc = mu_stream_readdelim (sp->transport, buf, bufsize, delim, &n); | 254 | rc = mu_stream_readdelim (sp->transport, buf, bufsize, delim, &n); |
252 | if (rc || n == 0) | 255 | if (rc) |
253 | break; | 256 | break; |
257 | if (n == 0) | ||
258 | continue; | ||
254 | nread += n; | 259 | nread += n; |
260 | if (buf[n-1] == delim) | ||
261 | break; | ||
255 | buf += n; | 262 | buf += n; |
256 | bufsize -= n; | 263 | bufsize -= n; |
257 | } | 264 | } | ... | ... |
-
Please register or sign in to post a comment