Commit 6dc229e5 6dc229e55735769991f542ac7d6ecbcdc9dd6e17 by Alain Magloire

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.
1 parent 9544aa12
......@@ -275,7 +275,7 @@ _file_open (stream_t stream, const char *filename, int port, int flags)
char *iobuffer;
iobuffer = malloc (8192);
if (iobuffer != NULL)
if (setvbuf (file, iobuffer, _IOFBF, 8192) != 0)
if (setvbuf (fs->file, iobuffer, _IOFBF, 8192) != 0)
free (iobuffer);
}
#endif
......
......@@ -49,12 +49,17 @@ struct _mailbox
event_t event;
size_t event_num;
/* debug information */
int debug_level;
void *debug_arg;
int (*debug_print) __P ((const char *, void *arg));
/* Back pointer to the specific mailbox */
void *data;
/* Public methods */
int (*_create) __P ((mailbox_t *, const char *));
int (*_create) __P ((mailbox_t *, const char *));
void (*_destroy) __P ((mailbox_t *));
int (*_open) __P ((mailbox_t, int flag));
......
......@@ -98,6 +98,13 @@ extern int mailbox_register __P ((mailbox_t mbox, size_t type,
void *arg));
extern int mailbox_deregister __P ((mailbox_t mbox, void *action));
/* trace */
extern int mailbox_set_debug_level __P ((mailbox_t mbox, size_t level));
extern int mailbox_get_debug_level __P ((mailbox_t mbox, size_t *plevel));
extern int mailbox_set_debug_print __P ((mailbox_t mbox, int (*debug_print)
__P ((const char *, void *arg)),
void *arg));
#ifdef __cplusplus
}
......
......@@ -281,3 +281,32 @@ mailbox_notification (mailbox_t mbox, size_t type)
}
return status;
}
int
mailbox_set_debug_level (mailbox_t mbox, size_t level)
{
if (mbox == NULL)
return EINVAL;
mbox->debug_level = level;
return 0;
}
int
mailbox_get_debug_level (mailbox_t mbox, size_t *plevel)
{
if (mbox == NULL || plevel == NULL)
return EINVAL;
*plevel = mbox->debug_level;
return 0;
}
int
mailbox_set_debug_print (mailbox_t mbox, int (*debug_print)
(const char *, void *arg), void *arg)
{
if (mbox == NULL)
return EINVAL;
mbox->debug_print = debug_print;
mbox->debug_arg = arg;
return 0;
}
......
......@@ -922,7 +922,7 @@ mailbox_pop_scan (mailbox_t mbox, size_t msgno, size_t *pcount)
status = mailbox_pop_messages_count (mbox, pcount);
if (status != 0)
return status;
for (i = msgno; i < *pcount; i++)
for (i = msgno; i <= *pcount; i++)
if (mailbox_notification (mbox, MU_EVT_MBX_MSG_ADD) != 0)
break;
return 0;
......
......@@ -235,8 +235,7 @@ do \
{ \
int bailing = 0; \
mailbox_unix_iunlock (mbox); \
if (mud->messages_count != 0) \
mud->messages_count--; \
mud->messages_count--; \
MAILBOX_NOTIFICATION (mbox, MU_EVT_MBX_PROGRESS,bailing); \
if (bailing != 0) \
{ \
......@@ -245,8 +244,7 @@ do \
mailbox_unix_unlock (mbox); \
return EINTR; \
} \
if (mud->messages_count != 0) \
mud->messages_count++; \
mud->messages_count++; \
mailbox_unix_ilock (mbox, MU_LOCKER_WRLOCK); \
} \
} while (0)
......@@ -264,8 +262,8 @@ do \
} \
} while (0)
// size_t num = 2 * ((mud)->messages_count) + 10;
/* allocate slots for the new messages */
/* size_t num = 2 * ((mud)->messages_count) + 10; */
#define ALLOCATE_MSGS(mbox,mud) \
do \
{ \
......
......@@ -479,6 +479,7 @@ message_write (stream_t os, const char *buf, size_t buflen,
while (!msg->hdr_done && (nl = memchr (buf, '\n', buflen)) != NULL)
{
len = nl - buf + 1;
/* allocate more buffer to hold the header */
thdr = realloc (msg->hdr_buf, msg->hdr_buflen + len);
if (thdr == NULL)
{
......@@ -491,6 +492,8 @@ message_write (stream_t os, const char *buf, size_t buflen,
msg->hdr_buf = thdr;
memcpy (msg->hdr_buf + msg->hdr_buflen, buf, len);
msg->hdr_buflen += len;
/* we detect an empty line .i.e "^\n$" this signal the end
* of the header */
if (buf == nl)
{
header_destroy (&(msg->header), msg);
......@@ -509,7 +512,24 @@ message_write (stream_t os, const char *buf, size_t buflen,
buflen -= len;
}
}
if (buflen)
/* message header is not complete but was not a full line */
if (!msg->hdr_done && buflen > 0)
{
char *thdr = realloc (msg->hdr_buf, msg->hdr_buflen + buflen);
if (thdr == NULL)
{
free (msg->hdr_buf);
msg->hdr_buf = NULL;
msg->hdr_buflen = 0;
return ENOMEM;
}
else
msg->hdr_buf = thdr;
memcpy (msg->hdr_buf + msg->hdr_buflen, buf, buflen);
msg->hdr_buflen += buflen;
}
else if (buflen > 0) /* in the body */
{
stream_t bs;
body_t body;
......
......@@ -357,6 +357,7 @@ int mime_create(mime_t *pmime, message_t msg, int flags)
else if ( ( ret = header_get_value(mime->hdrs, "Content-Type", mime->content_type, size+1, 0) ) == 0 )
_mime_munge_content_header(mime->content_type);
} else {
ret = 0;
if ( ( mime->content_type = strdup("text/plain; charset=us-ascii") ) == NULL ) /* default as per spec. */
ret = ENOMEM;
}
......