Fix amd
* mailbox/amd.c (_amd_attach_message): Store body. (amd_scan_message): Scan the message only if it has been modified after the last scan. Fix loop condition. Store mhm->mtime on success. (amd_message_stream_open): Enforce full buffering. (amd_body_stream_read): Fix. (amd_body_stream_seek): Don't call mu_stream_seek on mhm->stream.
Showing
1 changed file
with
15 additions
and
12 deletions
... | @@ -494,6 +494,7 @@ _amd_attach_message (mu_mailbox_t mailbox, struct _amd_message *mhm, | ... | @@ -494,6 +494,7 @@ _amd_attach_message (mu_mailbox_t mailbox, struct _amd_message *mhm, |
494 | mu_body_set_size (body, amd_body_size, msg); | 494 | mu_body_set_size (body, amd_body_size, msg); |
495 | mu_body_set_lines (body, amd_body_lines, msg); | 495 | mu_body_set_lines (body, amd_body_lines, msg); |
496 | mu_message_set_body (msg, body, mhm); | 496 | mu_message_set_body (msg, body, mhm); |
497 | str->body = body; | ||
497 | } | 498 | } |
498 | 499 | ||
499 | /* Set the envelope. */ | 500 | /* Set the envelope. */ |
... | @@ -1341,13 +1342,10 @@ amd_scan_message (struct _amd_message *mhm) | ... | @@ -1341,13 +1342,10 @@ amd_scan_message (struct _amd_message *mhm) |
1341 | size_t hlines = 0; | 1342 | size_t hlines = 0; |
1342 | size_t blines = 0; | 1343 | size_t blines = 0; |
1343 | size_t body_start = 0; | 1344 | size_t body_start = 0; |
1344 | |||
1345 | /* Check if the message was modified after the last scan */ | ||
1346 | if (mhm->mtime) | ||
1347 | { | ||
1348 | struct stat st; | 1345 | struct stat st; |
1349 | char *msg_name; | 1346 | char *msg_name; |
1350 | 1347 | ||
1348 | /* Check if the message was modified after the last scan */ | ||
1351 | status = mhm->amd->cur_msg_file_name (mhm, &msg_name); | 1349 | status = mhm->amd->cur_msg_file_name (mhm, &msg_name); |
1352 | if (status) | 1350 | if (status) |
1353 | return status; | 1351 | return status; |
... | @@ -1359,12 +1357,11 @@ amd_scan_message (struct _amd_message *mhm) | ... | @@ -1359,12 +1357,11 @@ amd_scan_message (struct _amd_message *mhm) |
1359 | return 0; | 1357 | return 0; |
1360 | } | 1358 | } |
1361 | free (msg_name); | 1359 | free (msg_name); |
1362 | } | ||
1363 | 1360 | ||
1364 | off = 0; | 1361 | off = 0; |
1365 | status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL); | 1362 | status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL); |
1366 | if (status == 0) | 1363 | if (status == 0) |
1367 | while ((status = mu_stream_readline (stream, buf, sizeof (buf), &n) == 0) | 1364 | while ((status = mu_stream_readline (stream, buf, sizeof (buf), &n)) == 0 |
1368 | && n != 0) | 1365 | && n != 0) |
1369 | { | 1366 | { |
1370 | if (in_header) | 1367 | if (in_header) |
... | @@ -1401,6 +1398,7 @@ amd_scan_message (struct _amd_message *mhm) | ... | @@ -1401,6 +1398,7 @@ amd_scan_message (struct _amd_message *mhm) |
1401 | 1398 | ||
1402 | if (status == 0) | 1399 | if (status == 0) |
1403 | { | 1400 | { |
1401 | mhm->mtime = st.st_mtime; | ||
1404 | if (!body_start) | 1402 | if (!body_start) |
1405 | body_start = off; | 1403 | body_start = off; |
1406 | mhm->header_lines = hlines; | 1404 | mhm->header_lines = hlines; |
... | @@ -1552,6 +1550,9 @@ amd_message_stream_open (struct _amd_message *mhm) | ... | @@ -1552,6 +1550,9 @@ amd_message_stream_open (struct _amd_message *mhm) |
1552 | if (status != 0) | 1550 | if (status != 0) |
1553 | return status; | 1551 | return status; |
1554 | 1552 | ||
1553 | /* FIXME: Select buffer size dynamically */ | ||
1554 | mu_stream_set_buffer (mhm->stream, mu_buffer_full, 16384); | ||
1555 | |||
1555 | status = mu_stream_open (mhm->stream); | 1556 | status = mu_stream_open (mhm->stream); |
1556 | 1557 | ||
1557 | if (status != 0) | 1558 | if (status != 0) |
... | @@ -1614,9 +1615,15 @@ amd_body_stream_read (mu_stream_t is, char *buffer, size_t buflen, | ... | @@ -1614,9 +1615,15 @@ amd_body_stream_read (mu_stream_t is, char *buffer, size_t buflen, |
1614 | if (ln > 0) | 1615 | if (ln > 0) |
1615 | { | 1616 | { |
1616 | nread = ((size_t)ln < buflen) ? (size_t)ln : buflen; | 1617 | nread = ((size_t)ln < buflen) ? (size_t)ln : buflen; |
1617 | status = mu_stream_read (mhm->stream, buffer, nread, pnread); | 1618 | status = mu_stream_seek (mhm->stream, mhm->body_start + amdstr->off, |
1619 | MU_SEEK_SET, NULL); | ||
1618 | if (status == 0) | 1620 | if (status == 0) |
1619 | amdstr->off += pnread ? *pnread : nread; | 1621 | { |
1622 | status = mu_stream_read (mhm->stream, buffer, nread, &nread); | ||
1623 | amdstr->off += nread; | ||
1624 | if (pnread) | ||
1625 | *pnread = nread; | ||
1626 | } | ||
1620 | } | 1627 | } |
1621 | 1628 | ||
1622 | mu_monitor_unlock (mhm->amd->mailbox->monitor); | 1629 | mu_monitor_unlock (mhm->amd->mailbox->monitor); |
... | @@ -1631,7 +1638,6 @@ static int | ... | @@ -1631,7 +1638,6 @@ static int |
1631 | amd_body_stream_seek (mu_stream_t str, mu_off_t off, int whence, | 1638 | amd_body_stream_seek (mu_stream_t str, mu_off_t off, int whence, |
1632 | mu_off_t *presult) | 1639 | mu_off_t *presult) |
1633 | { | 1640 | { |
1634 | int rc; | ||
1635 | size_t size; | 1641 | size_t size; |
1636 | struct _amd_body_stream *amdstr = (struct _amd_body_stream *)str; | 1642 | struct _amd_body_stream *amdstr = (struct _amd_body_stream *)str; |
1637 | mu_message_t msg = mu_body_get_owner (amdstr->body); | 1643 | mu_message_t msg = mu_body_get_owner (amdstr->body); |
... | @@ -1655,9 +1661,6 @@ amd_body_stream_seek (mu_stream_t str, mu_off_t off, int whence, | ... | @@ -1655,9 +1661,6 @@ amd_body_stream_seek (mu_stream_t str, mu_off_t off, int whence, |
1655 | if (off < 0 || off >= size) | 1661 | if (off < 0 || off >= size) |
1656 | return ESPIPE; | 1662 | return ESPIPE; |
1657 | 1663 | ||
1658 | rc = mu_stream_seek (mhm->stream, mhm->body_start + off, MU_SEEK_SET, NULL); | ||
1659 | if (rc) | ||
1660 | return rc; | ||
1661 | amdstr->off = off; | 1664 | amdstr->off = off; |
1662 | if (presult) | 1665 | if (presult) |
1663 | *presult = off; | 1666 | *presult = off; | ... | ... |
-
Please register or sign in to post a comment