file_stream.c mailbox.c mbx_pop.c mbx_unixscan.c message.c
mime.c include/private/mailbox0.h include/public/mailbox.h mbx_pop.c corrected a bug. mbx_unixscan.c corrected a subtile bug for PROGRESS.
Showing
8 changed files
with
66 additions
and
6 deletions
... | @@ -275,7 +275,7 @@ _file_open (stream_t stream, const char *filename, int port, int flags) | ... | @@ -275,7 +275,7 @@ _file_open (stream_t stream, const char *filename, int port, int flags) |
275 | char *iobuffer; | 275 | char *iobuffer; |
276 | iobuffer = malloc (8192); | 276 | iobuffer = malloc (8192); |
277 | if (iobuffer != NULL) | 277 | if (iobuffer != NULL) |
278 | if (setvbuf (file, iobuffer, _IOFBF, 8192) != 0) | 278 | if (setvbuf (fs->file, iobuffer, _IOFBF, 8192) != 0) |
279 | free (iobuffer); | 279 | free (iobuffer); |
280 | } | 280 | } |
281 | #endif | 281 | #endif | ... | ... |
... | @@ -49,6 +49,11 @@ struct _mailbox | ... | @@ -49,6 +49,11 @@ struct _mailbox |
49 | event_t event; | 49 | event_t event; |
50 | size_t event_num; | 50 | size_t event_num; |
51 | 51 | ||
52 | /* debug information */ | ||
53 | int debug_level; | ||
54 | void *debug_arg; | ||
55 | int (*debug_print) __P ((const char *, void *arg)); | ||
56 | |||
52 | /* Back pointer to the specific mailbox */ | 57 | /* Back pointer to the specific mailbox */ |
53 | void *data; | 58 | void *data; |
54 | 59 | ... | ... |
... | @@ -98,6 +98,13 @@ extern int mailbox_register __P ((mailbox_t mbox, size_t type, | ... | @@ -98,6 +98,13 @@ extern int mailbox_register __P ((mailbox_t mbox, size_t type, |
98 | void *arg)); | 98 | void *arg)); |
99 | extern int mailbox_deregister __P ((mailbox_t mbox, void *action)); | 99 | extern int mailbox_deregister __P ((mailbox_t mbox, void *action)); |
100 | 100 | ||
101 | /* trace */ | ||
102 | extern int mailbox_set_debug_level __P ((mailbox_t mbox, size_t level)); | ||
103 | extern int mailbox_get_debug_level __P ((mailbox_t mbox, size_t *plevel)); | ||
104 | extern int mailbox_set_debug_print __P ((mailbox_t mbox, int (*debug_print) | ||
105 | __P ((const char *, void *arg)), | ||
106 | void *arg)); | ||
107 | |||
101 | 108 | ||
102 | #ifdef __cplusplus | 109 | #ifdef __cplusplus |
103 | } | 110 | } | ... | ... |
... | @@ -281,3 +281,32 @@ mailbox_notification (mailbox_t mbox, size_t type) | ... | @@ -281,3 +281,32 @@ mailbox_notification (mailbox_t mbox, size_t type) |
281 | } | 281 | } |
282 | return status; | 282 | return status; |
283 | } | 283 | } |
284 | |||
285 | int | ||
286 | mailbox_set_debug_level (mailbox_t mbox, size_t level) | ||
287 | { | ||
288 | if (mbox == NULL) | ||
289 | return EINVAL; | ||
290 | mbox->debug_level = level; | ||
291 | return 0; | ||
292 | } | ||
293 | |||
294 | int | ||
295 | mailbox_get_debug_level (mailbox_t mbox, size_t *plevel) | ||
296 | { | ||
297 | if (mbox == NULL || plevel == NULL) | ||
298 | return EINVAL; | ||
299 | *plevel = mbox->debug_level; | ||
300 | return 0; | ||
301 | } | ||
302 | |||
303 | int | ||
304 | mailbox_set_debug_print (mailbox_t mbox, int (*debug_print) | ||
305 | (const char *, void *arg), void *arg) | ||
306 | { | ||
307 | if (mbox == NULL) | ||
308 | return EINVAL; | ||
309 | mbox->debug_print = debug_print; | ||
310 | mbox->debug_arg = arg; | ||
311 | return 0; | ||
312 | } | ... | ... |
... | @@ -922,7 +922,7 @@ mailbox_pop_scan (mailbox_t mbox, size_t msgno, size_t *pcount) | ... | @@ -922,7 +922,7 @@ mailbox_pop_scan (mailbox_t mbox, size_t msgno, size_t *pcount) |
922 | status = mailbox_pop_messages_count (mbox, pcount); | 922 | status = mailbox_pop_messages_count (mbox, pcount); |
923 | if (status != 0) | 923 | if (status != 0) |
924 | return status; | 924 | return status; |
925 | for (i = msgno; i < *pcount; i++) | 925 | for (i = msgno; i <= *pcount; i++) |
926 | if (mailbox_notification (mbox, MU_EVT_MBX_MSG_ADD) != 0) | 926 | if (mailbox_notification (mbox, MU_EVT_MBX_MSG_ADD) != 0) |
927 | break; | 927 | break; |
928 | return 0; | 928 | return 0; | ... | ... |
... | @@ -235,7 +235,6 @@ do \ | ... | @@ -235,7 +235,6 @@ do \ |
235 | { \ | 235 | { \ |
236 | int bailing = 0; \ | 236 | int bailing = 0; \ |
237 | mailbox_unix_iunlock (mbox); \ | 237 | mailbox_unix_iunlock (mbox); \ |
238 | if (mud->messages_count != 0) \ | ||
239 | mud->messages_count--; \ | 238 | mud->messages_count--; \ |
240 | MAILBOX_NOTIFICATION (mbox, MU_EVT_MBX_PROGRESS,bailing); \ | 239 | MAILBOX_NOTIFICATION (mbox, MU_EVT_MBX_PROGRESS,bailing); \ |
241 | if (bailing != 0) \ | 240 | if (bailing != 0) \ |
... | @@ -245,7 +244,6 @@ do \ | ... | @@ -245,7 +244,6 @@ do \ |
245 | mailbox_unix_unlock (mbox); \ | 244 | mailbox_unix_unlock (mbox); \ |
246 | return EINTR; \ | 245 | return EINTR; \ |
247 | } \ | 246 | } \ |
248 | if (mud->messages_count != 0) \ | ||
249 | mud->messages_count++; \ | 247 | mud->messages_count++; \ |
250 | mailbox_unix_ilock (mbox, MU_LOCKER_WRLOCK); \ | 248 | mailbox_unix_ilock (mbox, MU_LOCKER_WRLOCK); \ |
251 | } \ | 249 | } \ |
... | @@ -264,8 +262,8 @@ do \ | ... | @@ -264,8 +262,8 @@ do \ |
264 | } \ | 262 | } \ |
265 | } while (0) | 263 | } while (0) |
266 | 264 | ||
267 | // size_t num = 2 * ((mud)->messages_count) + 10; | ||
268 | /* allocate slots for the new messages */ | 265 | /* allocate slots for the new messages */ |
266 | /* size_t num = 2 * ((mud)->messages_count) + 10; */ | ||
269 | #define ALLOCATE_MSGS(mbox,mud) \ | 267 | #define ALLOCATE_MSGS(mbox,mud) \ |
270 | do \ | 268 | do \ |
271 | { \ | 269 | { \ | ... | ... |
... | @@ -479,6 +479,7 @@ message_write (stream_t os, const char *buf, size_t buflen, | ... | @@ -479,6 +479,7 @@ message_write (stream_t os, const char *buf, size_t buflen, |
479 | while (!msg->hdr_done && (nl = memchr (buf, '\n', buflen)) != NULL) | 479 | while (!msg->hdr_done && (nl = memchr (buf, '\n', buflen)) != NULL) |
480 | { | 480 | { |
481 | len = nl - buf + 1; | 481 | len = nl - buf + 1; |
482 | /* allocate more buffer to hold the header */ | ||
482 | thdr = realloc (msg->hdr_buf, msg->hdr_buflen + len); | 483 | thdr = realloc (msg->hdr_buf, msg->hdr_buflen + len); |
483 | if (thdr == NULL) | 484 | if (thdr == NULL) |
484 | { | 485 | { |
... | @@ -491,6 +492,8 @@ message_write (stream_t os, const char *buf, size_t buflen, | ... | @@ -491,6 +492,8 @@ message_write (stream_t os, const char *buf, size_t buflen, |
491 | msg->hdr_buf = thdr; | 492 | msg->hdr_buf = thdr; |
492 | memcpy (msg->hdr_buf + msg->hdr_buflen, buf, len); | 493 | memcpy (msg->hdr_buf + msg->hdr_buflen, buf, len); |
493 | msg->hdr_buflen += len; | 494 | msg->hdr_buflen += len; |
495 | /* we detect an empty line .i.e "^\n$" this signal the end | ||
496 | * of the header */ | ||
494 | if (buf == nl) | 497 | if (buf == nl) |
495 | { | 498 | { |
496 | header_destroy (&(msg->header), msg); | 499 | header_destroy (&(msg->header), msg); |
... | @@ -509,7 +512,24 @@ message_write (stream_t os, const char *buf, size_t buflen, | ... | @@ -509,7 +512,24 @@ message_write (stream_t os, const char *buf, size_t buflen, |
509 | buflen -= len; | 512 | buflen -= len; |
510 | } | 513 | } |
511 | } | 514 | } |
512 | if (buflen) | 515 | |
516 | /* message header is not complete but was not a full line */ | ||
517 | if (!msg->hdr_done && buflen > 0) | ||
518 | { | ||
519 | char *thdr = realloc (msg->hdr_buf, msg->hdr_buflen + buflen); | ||
520 | if (thdr == NULL) | ||
521 | { | ||
522 | free (msg->hdr_buf); | ||
523 | msg->hdr_buf = NULL; | ||
524 | msg->hdr_buflen = 0; | ||
525 | return ENOMEM; | ||
526 | } | ||
527 | else | ||
528 | msg->hdr_buf = thdr; | ||
529 | memcpy (msg->hdr_buf + msg->hdr_buflen, buf, buflen); | ||
530 | msg->hdr_buflen += buflen; | ||
531 | } | ||
532 | else if (buflen > 0) /* in the body */ | ||
513 | { | 533 | { |
514 | stream_t bs; | 534 | stream_t bs; |
515 | body_t body; | 535 | body_t body; | ... | ... |
... | @@ -357,6 +357,7 @@ int mime_create(mime_t *pmime, message_t msg, int flags) | ... | @@ -357,6 +357,7 @@ int mime_create(mime_t *pmime, message_t msg, int flags) |
357 | else if ( ( ret = header_get_value(mime->hdrs, "Content-Type", mime->content_type, size+1, 0) ) == 0 ) | 357 | else if ( ( ret = header_get_value(mime->hdrs, "Content-Type", mime->content_type, size+1, 0) ) == 0 ) |
358 | _mime_munge_content_header(mime->content_type); | 358 | _mime_munge_content_header(mime->content_type); |
359 | } else { | 359 | } else { |
360 | ret = 0; | ||
360 | if ( ( mime->content_type = strdup("text/plain; charset=us-ascii") ) == NULL ) /* default as per spec. */ | 361 | if ( ( mime->content_type = strdup("text/plain; charset=us-ascii") ) == NULL ) /* default as per spec. */ |
361 | ret = ENOMEM; | 362 | ret = ENOMEM; |
362 | } | 363 | } | ... | ... |
-
Please register or sign in to post a comment