Changeset 3455

Show
Ignore:
Timestamp:
03/04/08 12:54:43
Author:
pvanhoof
Message:

2008-03-04 Philip Van Hoof <pvanhoof@gnome.org>

        • Attempt at making mime parsing use the seekable capability of

streams in stead of copying them in memory. This is experimental!

2008-03-04 Philip Van Hoof <pvanhoof@gnome.org>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r3454 r3455  
    112008-03-04  Philip Van Hoof <pvanhoof@gnome.org> 
    22 
     3        * Attempt at making mime parsing use the seekable capability of 
     4        streams in stead of copying them in memory. This is experimental! 
     5 
     62008-03-04  Philip Van Hoof <pvanhoof@gnome.org> 
     7 
    38        * Introduction of TnySeekable 
     9        * This is experimental 
    410 
    5112008-03-03  Philip Van Hoof <pvanhoof@gnome.org> 
  • trunk/libtinymail-camel/camel-lite/camel/camel-mime-part-utils.c

    r3361 r3455  
    5959simple_data_wrapper_construct_from_parser (CamelDataWrapper *dw, CamelMimeParser *mp) 
    6060{ 
     61        GByteArray *buffer = NULL; 
     62        CamelStream *stream; 
     63        off_t start, end; 
     64        int fd = -1; 
     65        size_t len; 
    6166        char *buf; 
    62         GByteArray *buffer; 
    63         CamelStream *mem; 
    64         size_t len; 
     67         
     68        d(printf ("simple_data_wrapper_construct_from_parser()\n")); 
     69         
     70        if (!(stream = camel_mime_parser_stream (mp))) 
     71                fd = camel_mime_parser_fd (mp); 
     72        else if (!CAMEL_IS_SEEKABLE_SUBSTREAM (stream)) 
     73                stream = NULL; 
     74         
     75        if ((stream || fd != -1) && (start = camel_mime_parser_tell (mp)) != -1) { 
     76                /* we can keep content on disk */ 
     77        } else { 
     78                /* need to load content into memory */ 
     79                buffer = g_byte_array_new (); 
     80        } 
     81         
     82        while (camel_mime_parser_step (mp, &buf, &len) != CAMEL_MIME_PARSER_STATE_BODY_END) { 
     83                if (buffer != NULL) { 
     84                        d(printf("appending o/p data: %d: %.*s\n", len, len, buf)); 
     85                        g_byte_array_append (buffer, (guint8 *) buf, len); 
     86                } 
     87        } 
     88         
     89        if (buffer == NULL) { 
     90                end = camel_mime_parser_tell (mp); 
     91                 
     92                if (stream != NULL) 
     93                        stream = camel_seekable_substream_new ((CamelSeekableStream *) stream, start, end); 
     94                else 
     95                        stream = camel_stream_fs_new_with_fd_and_bounds (dup (fd), start, end); 
     96        } else { 
     97                stream = camel_stream_mem_new_with_byte_array (buffer); 
     98        } 
     99         
     100        camel_data_wrapper_construct_from_stream (dw, stream); 
     101        camel_object_unref (stream); 
     102
    65103 
    66         d(printf ("simple_data_wrapper_construct_from_parser()\n")); 
    67  
    68         /* read in the entire content */ 
    69         buffer = e_byte_array_new (); 
    70         while (camel_mime_parser_step (mp, &buf, &len) != CAMEL_MIME_PARSER_STATE_BODY_END) { 
    71                 d(printf("appending o/p data: %d: %.*s\n", len, len, buf)); 
    72                 if (!e_byte_array_append (buffer, (guint8 *) buf, len)) 
    73                         break; 
    74         } 
    75  
    76         d(printf("message part kept in memory!\n")); 
    77  
    78         mem = camel_stream_mem_new_with_byte_array (buffer); 
    79         camel_data_wrapper_construct_from_stream (dw, mem); 
    80         camel_object_unref (mem); 
    81 } 
    82104 
    83105/* This replaces the data wrapper repository ... and/or could be replaced by it? */