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) ...@@ -307,14 +307,8 @@ _file_open (stream_t stream, const char *filename, int port, int flags)
307 return ret; 307 return ret;
308 } 308 }
309 #if BUFSIZ <= 1024 309 #if BUFSIZ <= 1024
310 /* Give us some roo to breathe, for OS with two small stdio buffers. */ 310 /* Give us some room to breath, for OS with two small stdio buffers. */
311 { 311 setvbuf (fs->file, iobuffer, _IOFBF, 8192);
312 char *iobuffer;
313 iobuffer = malloc (8192);
314 if (iobuffer != NULL)
315 if (setvbuf (fs->file, iobuffer, _IOFBF, 8192) != 0)
316 free (iobuffer);
317 }
318 #endif 312 #endif
319 stream_set_flags (stream, flags |MU_STREAM_NO_CHECK); 313 stream_set_flags (stream, flags |MU_STREAM_NO_CHECK);
320 return 0; 314 return 0;
......
...@@ -368,7 +368,9 @@ static int _mime_set_content_type(mime_t mime) ...@@ -368,7 +368,9 @@ static int _mime_set_content_type(mime_t mime)
368 { 368 {
369 char content_type[256]; 369 char content_type[256];
370 char boundary[128]; 370 char boundary[128];
371 371 header_t hdr = NULL;
372 size_t size;
373
372 if ( mime->nmtp_parts > 1 ) { 374 if ( mime->nmtp_parts > 1 ) {
373 if ( mime->flags & MIME_ADDED_MULTIPART ) 375 if ( mime->flags & MIME_ADDED_MULTIPART )
374 return 0; 376 return 0;
...@@ -389,7 +391,12 @@ static int _mime_set_content_type(mime_t mime) ...@@ -389,7 +391,12 @@ static int _mime_set_content_type(mime_t mime)
389 if ( (mime->flags & (MIME_ADDED_CONTENT_TYPE|MIME_ADDED_MULTIPART)) == MIME_ADDED_CONTENT_TYPE ) 391 if ( (mime->flags & (MIME_ADDED_CONTENT_TYPE|MIME_ADDED_MULTIPART)) == MIME_ADDED_CONTENT_TYPE )
390 return 0; 392 return 0;
391 mime->flags &= ~MIME_ADDED_MULTIPART; 393 mime->flags &= ~MIME_ADDED_MULTIPART;
392 strcpy(content_type, "text/plain; charset=us-ascii"); 394 if ( mime->nmtp_parts )
395 message_get_header(mime->mtp_parts[0]->msg, &hdr);
396 if ( hdr == NULL || header_get_value(hdr, "Content-Type", NULL, 0, &size) != 0 || size == 0 )
397 strcpy(content_type, "text/plain; charset=us-ascii");
398 else
399 header_get_value(hdr, "Content-Type", content_type, sizeof(content_type), &size);
393 } 400 }
394 mime->flags |= MIME_ADDED_CONTENT_TYPE; 401 mime->flags |= MIME_ADDED_CONTENT_TYPE;
395 return header_set_value(mime->hdrs, "Content-Type", content_type, 1); 402 return header_set_value(mime->hdrs, "Content-Type", content_type, 1);
...@@ -424,40 +431,46 @@ static int _mime_body_read(stream_t stream, char *buf, size_t buflen, off_t off, ...@@ -424,40 +431,46 @@ static int _mime_body_read(stream_t stream, char *buf, size_t buflen, off_t off,
424 if ( ( ret = _mime_set_content_type(mime) ) == 0 ) { 431 if ( ( ret = _mime_set_content_type(mime) ) == 0 ) {
425 do { 432 do {
426 len = 0; 433 len = 0;
427 if ( mime->nmtp_parts > 1 && ( mime->flags & MIME_INSERT_BOUNDARY || mime->cur_offset == 0 ) ) { 434 if ( mime->nmtp_parts > 1 ) {
428 mime->cur_part++; 435 if ( ( mime->flags & MIME_INSERT_BOUNDARY || mime->cur_offset == 0 ) ) {
429 len = 2; 436 mime->cur_part++;
430 buf[0] = buf[1] = '-'; 437 len = 2;
431 buf+=2;
432 len += strlen(mime->boundary);
433 strcpy(buf, mime->boundary);
434 buf+= strlen(mime->boundary);
435 if ( mime->cur_part == mime->nmtp_parts ) {
436 len+=2;
437 buf[0] = buf[1] = '-'; 438 buf[0] = buf[1] = '-';
438 buf+=2; 439 buf+=2;
440 len += strlen(mime->boundary);
441 strcpy(buf, mime->boundary);
442 buf+= strlen(mime->boundary);
443 if ( mime->cur_part == mime->nmtp_parts ) {
444 len+=2;
445 buf[0] = buf[1] = '-';
446 buf+=2;
447 }
448 len++;
449 buf[0] = '\n';
450 buf++;
451 mime->flags &= ~MIME_INSERT_BOUNDARY;
452 buflen =- len;
453 mime->part_offset = 0;
454 if ( mime->cur_part == mime->nmtp_parts ) {
455 if ( nbytes )
456 *nbytes += len;
457 mime->cur_offset +=len;
458 break;
459 }
439 } 460 }
440 len++; 461 message_get_stream(mime->mtp_parts[mime->cur_part]->msg, &msg_stream);
441 buf[0] = '\n'; 462 } else {
442 buf++; 463 body_t body;
443 mime->flags &= ~MIME_INSERT_BOUNDARY; 464 message_get_body(mime->mtp_parts[mime->cur_part]->msg, &body);
444 buflen =- len; 465 body_get_stream(body, &msg_stream);
445 mime->part_offset = 0;
446 if ( mime->cur_part == mime->nmtp_parts ) {
447 if ( nbytes )
448 *nbytes += len;
449 mime->cur_offset +=len;
450 break;
451 }
452 } 466 }
453 message_get_stream(mime->mtp_parts[mime->cur_part]->msg, &msg_stream);
454 ret = stream_read(msg_stream, buf, buflen, mime->part_offset, &part_nbytes ); 467 ret = stream_read(msg_stream, buf, buflen, mime->part_offset, &part_nbytes );
455 len += part_nbytes; 468 len += part_nbytes;
456 mime->part_offset += part_nbytes; 469 mime->part_offset += part_nbytes;
457 if ( nbytes ) 470 if ( nbytes )
458 *nbytes += len; 471 *nbytes += len;
459 mime->cur_offset += len; 472 mime->cur_offset += len;
460 if ( ret == 0 && part_nbytes == 0 ) 473 if ( ret == 0 && part_nbytes == 0 && mime->nmtp_parts > 1 )
461 mime->flags |= MIME_INSERT_BOUNDARY; 474 mime->flags |= MIME_INSERT_BOUNDARY;
462 } while( ret == 0 && part_nbytes == 0 ); 475 } while( ret == 0 && part_nbytes == 0 );
463 } 476 }
...@@ -487,6 +500,7 @@ static int _mime_body_size (body_t body, size_t *psize) ...@@ -487,6 +500,7 @@ static int _mime_body_size (body_t body, size_t *psize)
487 if ( mime->nmtp_parts == 0 ) 500 if ( mime->nmtp_parts == 0 )
488 return EINVAL; 501 return EINVAL;
489 502
503 _mime_set_content_type(mime);
490 for ( i=0;i<mime->nmtp_parts;i++ ) { 504 for ( i=0;i<mime->nmtp_parts;i++ ) {
491 message_size(mime->mtp_parts[i]->msg, &size); 505 message_size(mime->mtp_parts[i]->msg, &size);
492 *psize+=size; 506 *psize+=size;
...@@ -509,6 +523,7 @@ static int _mime_body_lines (body_t body, size_t *plines) ...@@ -509,6 +523,7 @@ static int _mime_body_lines (body_t body, size_t *plines)
509 if ( mime->nmtp_parts == 0 ) 523 if ( mime->nmtp_parts == 0 )
510 return EINVAL; 524 return EINVAL;
511 525
526 _mime_set_content_type(mime);
512 for ( i = 0; i < mime->nmtp_parts; i++ ) { 527 for ( i = 0; i < mime->nmtp_parts; i++ ) {
513 message_lines(mime->mtp_parts[i]->msg, &lines); 528 message_lines(mime->mtp_parts[i]->msg, &lines);
514 plines+=lines; 529 plines+=lines;
......