Commit ad9f147e ad9f147e49bedaf11d6816f9edc6e740ec1d443b by Alain Magloire

pass null to setvbuf, to let stdio free the buffer.

1 parent d431f390
......@@ -307,14 +307,8 @@ _file_open (stream_t stream, const char *filename, int port, int flags)
return ret;
}
#if BUFSIZ <= 1024
/* Give us some roo to breathe, for OS with two small stdio buffers. */
{
char *iobuffer;
iobuffer = malloc (8192);
if (iobuffer != NULL)
if (setvbuf (fs->file, iobuffer, _IOFBF, 8192) != 0)
free (iobuffer);
}
/* Give us some room to breath, for OS with two small stdio buffers. */
setvbuf (fs->file, iobuffer, _IOFBF, 8192);
#endif
stream_set_flags (stream, flags |MU_STREAM_NO_CHECK);
return 0;
......
......@@ -368,6 +368,8 @@ static int _mime_set_content_type(mime_t mime)
{
char content_type[256];
char boundary[128];
header_t hdr = NULL;
size_t size;
if ( mime->nmtp_parts > 1 ) {
if ( mime->flags & MIME_ADDED_MULTIPART )
......@@ -389,7 +391,12 @@ static int _mime_set_content_type(mime_t mime)
if ( (mime->flags & (MIME_ADDED_CONTENT_TYPE|MIME_ADDED_MULTIPART)) == MIME_ADDED_CONTENT_TYPE )
return 0;
mime->flags &= ~MIME_ADDED_MULTIPART;
if ( mime->nmtp_parts )
message_get_header(mime->mtp_parts[0]->msg, &hdr);
if ( hdr == NULL || header_get_value(hdr, "Content-Type", NULL, 0, &size) != 0 || size == 0 )
strcpy(content_type, "text/plain; charset=us-ascii");
else
header_get_value(hdr, "Content-Type", content_type, sizeof(content_type), &size);
}
mime->flags |= MIME_ADDED_CONTENT_TYPE;
return header_set_value(mime->hdrs, "Content-Type", content_type, 1);
......@@ -424,7 +431,8 @@ static int _mime_body_read(stream_t stream, char *buf, size_t buflen, off_t off,
if ( ( ret = _mime_set_content_type(mime) ) == 0 ) {
do {
len = 0;
if ( mime->nmtp_parts > 1 && ( mime->flags & MIME_INSERT_BOUNDARY || mime->cur_offset == 0 ) ) {
if ( mime->nmtp_parts > 1 ) {
if ( ( mime->flags & MIME_INSERT_BOUNDARY || mime->cur_offset == 0 ) ) {
mime->cur_part++;
len = 2;
buf[0] = buf[1] = '-';
......@@ -451,13 +459,18 @@ static int _mime_body_read(stream_t stream, char *buf, size_t buflen, off_t off,
}
}
message_get_stream(mime->mtp_parts[mime->cur_part]->msg, &msg_stream);
} else {
body_t body;
message_get_body(mime->mtp_parts[mime->cur_part]->msg, &body);
body_get_stream(body, &msg_stream);
}
ret = stream_read(msg_stream, buf, buflen, mime->part_offset, &part_nbytes );
len += part_nbytes;
mime->part_offset += part_nbytes;
if ( nbytes )
*nbytes += len;
mime->cur_offset += len;
if ( ret == 0 && part_nbytes == 0 )
if ( ret == 0 && part_nbytes == 0 && mime->nmtp_parts > 1 )
mime->flags |= MIME_INSERT_BOUNDARY;
} while( ret == 0 && part_nbytes == 0 );
}
......@@ -487,6 +500,7 @@ static int _mime_body_size (body_t body, size_t *psize)
if ( mime->nmtp_parts == 0 )
return EINVAL;
_mime_set_content_type(mime);
for ( i=0;i<mime->nmtp_parts;i++ ) {
message_size(mime->mtp_parts[i]->msg, &size);
*psize+=size;
......@@ -509,6 +523,7 @@ static int _mime_body_lines (body_t body, size_t *plines)
if ( mime->nmtp_parts == 0 )
return EINVAL;
_mime_set_content_type(mime);
for ( i = 0; i < mime->nmtp_parts; i++ ) {
message_lines(mime->mtp_parts[i]->msg, &lines);
plines+=lines;
......