Changeset 3171

Show
Ignore:
Timestamp:
12/21/07 13:23:41
Author:
felipe
Message:

2007-12-21 Felipe Erias Morandeira <femorandeira@igalia.com>

        • libtinymail/tny-mime-part.[hc] : changed the signature of

tny_mime_part_write_to_stream and tny_mime_part_decode_to_stream to
return the number of bytes written and use a GError to notify problems.

        • libtinymail-camel/tny-camel-mime-part.[hc] : adapted the functions that

implemented the previous two functions to comply with their new
signatures.

        • libtinymail-camel/tny-camel-bs-mime-part.[hc] : adapted the functions

that implemented the previous two functions to comply with their
new signatures.

        • libtinymail-camel/camel-lite/camel/providers/local/camel-maildir-store.c:
        • libtinymailui-webkit/tny-webkit-html-mime-part-view.c:
        • libtinymailui/tny-mime-part-save-strategy.c:
        • libtinymail-test/tny-mime-part-test.c:

Small changes to use the new signatures of the two functions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r3170 r3171  
     12007-12-21 Felipe Erias Morandeira <femorandeira@igalia.com> 
     2 
     3        * libtinymail/tny-mime-part.[hc] : changed the signature of 
     4                tny_mime_part_write_to_stream and tny_mime_part_decode_to_stream to 
     5                return the number of bytes written and use a GError to notify problems. 
     6        * libtinymail-camel/tny-camel-mime-part.[hc] : adapted the functions that 
     7                implemented the previous two functions to comply with their new 
     8                signatures. 
     9        * libtinymail-camel/tny-camel-bs-mime-part.[hc] : adapted the functions 
     10                that implemented the previous two functions to comply with their 
     11                new signatures. 
     12        * libtinymail-camel/camel-lite/camel/providers/local/camel-maildir-store.c: 
     13        * libtinymailui-webkit/tny-webkit-html-mime-part-view.c: 
     14        * libtinymailui/tny-mime-part-save-strategy.c: 
     15        * libtinymail-test/tny-mime-part-test.c: 
     16                Small changes to use the new signatures of the two functions. 
     17 
    1182007-12-21  Philip Van Hoof <pvanhoof@gnome.org> 
    219 
  • trunk/libtinymail-camel/camel-lite/camel/providers/local/camel-maildir-store.c

    r2950 r3171  
    488488                        g_free(name); 
    489489                        camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, 
    490                                              _("Could not scan folder `%s': %s"), 
    491                                              root, g_strerror(errno)); 
     490                                             _("Could not scan folder `%s', opendir(`%s') failed: %s"), 
     491                                             root, name, g_strerror(errno)); 
    492492                        goto fail; 
    493493                } 
  • trunk/libtinymail-camel/tny-camel-bs-mime-part.c

    r3151 r3171  
    125125} 
    126126 
    127 static void 
     127static gssize 
    128128bs_camel_stream_format_text (CamelStream *from_stream, CamelStream *stream, const gchar *charset, const gchar *encoding) 
    129129{ 
     
    131131        CamelMimeFilterCharset *filter; 
    132132        CamelMimeFilterWindows *windows = NULL; 
    133  
     133        gssize bytes_written = -1; 
     134                 
    134135        if (g_ascii_strncasecmp (charset, "iso-8859-", 9) == 0) { 
    135136                CamelStream *null; 
     
    162163        } 
    163164 
    164         decode_to_stream (from_stream, (CamelStream *)filter_stream, encoding, TRUE); 
     165        bytes_written = (gssize) decode_to_stream (from_stream, (CamelStream *)filter_stream, encoding, TRUE); 
    165166        camel_stream_flush ((CamelStream *)filter_stream); 
    166167        camel_object_unref (filter_stream); 
     
    169170                camel_object_unref(windows); 
    170171 
    171         return
    172 } 
    173  
    174 static void  
     172        return bytes_written
     173} 
     174 
     175static gssize  
    175176decode_from_stream_to (TnyMimePart *self, TnyStream *from_stream, TnyStream *stream, gboolean binary, gboolean decode_text) 
    176177{ 
     178        gssize bytes_written = -1; 
    177179        TnyCamelBsMimePartPriv *priv = TNY_CAMEL_BS_MIME_PART_GET_PRIVATE (self); 
    178180 
     
    190192                        charset = "UTF-8"; 
    191193 
    192                 bs_camel_stream_format_text (cfrom_stream, cto_stream, charset, encoding); 
     194                bytes_written = (gssize) bs_camel_stream_format_text (cfrom_stream, cto_stream, charset, encoding); 
    193195 
    194196                camel_object_unref (cfrom_stream); 
     
    196198        } else { 
    197199                if (binary) 
    198                         tny_stream_write_to_stream (from_stream, stream); 
     200                        bytes_written = tny_stream_write_to_stream (from_stream, stream); 
    199201                else { 
    200202                        CamelStream *cfrom_stream = tny_stream_camel_new (from_stream); 
     
    202204                        gchar *encoding = priv->bodystructure->encoding; 
    203205 
    204                         decode_to_stream (cfrom_stream, cto_stream, encoding, FALSE); 
     206                        bytes_written = (gssize) decode_to_stream (cfrom_stream, cto_stream, encoding, FALSE); 
    205207 
    206208                        camel_object_unref (cfrom_stream); 
     
    208210                } 
    209211        } 
    210 
    211  
    212 static void  
     212        return bytes_written; 
     213
     214 
     215static gssize  
    213216fetch_part (TnyMimePart *self, TnyStream *stream, gboolean decode_text) 
    214217{ 
     
    217220        gboolean binary = TRUE; 
    218221        TnyStream *from_stream; 
     222        gssize return_value = 0; 
    219223 
    220224        /* binary = !camel_strcase_equal (priv->bodystructure->content.type, "TEXT"); */ 
     
    225229                g_warning ("Error while fetching part: %s", err->message); 
    226230                g_error_free (err); 
     231                return_value = -1; 
    227232        } else if (from_stream) 
    228                 decode_from_stream_to (self, from_stream, stream, binary, decode_text); 
     233                return_value = decode_from_stream_to (self, from_stream, stream, binary, decode_text); 
    229234 
    230235        if (from_stream) 
     
    232237 
    233238 
    234         return
     239        return return_value
    235240} 
    236241 
     
    403408} 
    404409 
    405 static void 
    406 tny_camel_bs_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream) 
    407 
    408         TNY_CAMEL_BS_MIME_PART_GET_CLASS (self)->write_to_stream_func (self, stream); 
    409         return; 
    410 
    411  
    412 static void 
    413 tny_camel_bs_mime_part_write_to_stream_default (TnyMimePart *self, TnyStream *stream) 
    414 
    415         fetch_part (self, stream, FALSE); 
    416         return; 
     410static gssize 
     411tny_camel_bs_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream, GError **err) 
     412
     413        return TNY_CAMEL_BS_MIME_PART_GET_CLASS (self)->write_to_stream_func (self, stream, err); 
     414
     415 
     416static gssize 
     417tny_camel_bs_mime_part_write_to_stream_default (TnyMimePart *self, TnyStream *stream, GError **err) 
     418
     419        return fetch_part (self, stream, FALSE); 
    417420} 
    418421 
     
    620623 
    621624 
    622 static void 
    623 tny_camel_bs_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream) 
    624 
    625         TNY_CAMEL_BS_MIME_PART_GET_CLASS (self)->decode_to_stream_func (self, stream); 
    626         return; 
    627 
    628  
    629 static void 
    630 tny_camel_bs_mime_part_decode_to_stream_default (TnyMimePart *self, TnyStream *stream) 
    631 
    632         fetch_part (self, stream, TRUE); 
    633         return; 
     625static gssize 
     626tny_camel_bs_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream, GError **err) 
     627
     628        return TNY_CAMEL_BS_MIME_PART_GET_CLASS (self)->decode_to_stream_func (self, stream, err); 
     629
     630 
     631static gssize 
     632tny_camel_bs_mime_part_decode_to_stream_default (TnyMimePart *self, TnyStream *stream, GError **err) 
     633
     634        return fetch_part (self, stream, TRUE); 
    634635} 
    635636 
  • trunk/libtinymail-camel/tny-camel-bs-mime-part.h

    r3070 r3171  
    5151        gboolean (*content_type_is_func) (TnyMimePart *self, const gchar *content_type); 
    5252        TnyStream* (*get_stream_func) (TnyMimePart *self); 
    53         void (*decode_to_stream_func) (TnyMimePart *self, TnyStream *stream); 
    54         void (*write_to_stream_func) (TnyMimePart *self, TnyStream *stream); 
     53        gssize (*decode_to_stream_func) (TnyMimePart *self, TnyStream *stream, GError **err); 
     54        gssize (*write_to_stream_func) (TnyMimePart *self, TnyStream *stream, GError **err); 
    5555        gint (*construct_from_stream_func) (TnyMimePart *self, TnyStream *stream, const gchar *type); 
    5656        const gchar* (*get_filename_func) (TnyMimePart *self); 
  • trunk/libtinymail-camel/tny-camel-mime-part.c

    r3151 r3171  
    2727 
    2828#include <string.h> 
     29#include <errno.h> 
    2930 
    3031#include <tny-mime-part.h> 
     
    3839#include <tny-simple-list.h> 
    3940#include <tny-camel-msg.h> 
     41#include <tny-error.h> 
    4042 
    4143static GObjectClass *parent_class = NULL; 
     
    245247        DecodeAsyncInfo *info = g_slice_new0 (DecodeAsyncInfo); 
    246248 
    247         tny_mime_part_decode_to_stream (self, stream); 
     249        tny_mime_part_decode_to_stream (self, stream, NULL); 
    248250 
    249251        info->self = g_object_ref (self); 
     
    538540} 
    539541 
    540 static void 
    541 tny_camel_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream) 
    542 
    543         TNY_CAMEL_MIME_PART_GET_CLASS (self)->write_to_stream_func (self, stream); 
    544         return; 
    545 
    546  
    547 static void 
    548 tny_camel_mime_part_write_to_stream_default (TnyMimePart *self, TnyStream *stream) 
     542static gssize 
     543tny_camel_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream, GError **err) 
     544
     545        return TNY_CAMEL_MIME_PART_GET_CLASS (self)->write_to_stream_func (self, stream, err); 
     546
     547 
     548static gssize 
     549tny_camel_mime_part_write_to_stream_default (TnyMimePart *self, TnyStream *stream, GError **err) 
    549550{ 
    550551        TnyCamelMimePartPriv *priv = TNY_CAMEL_MIME_PART_GET_PRIVATE (self); 
     
    552553        CamelMedium *medium; 
    553554        CamelStream *cstream; 
     555        gssize bytes = -1; 
    554556 
    555557        g_assert (TNY_IS_STREAM (stream)); 
     
    568570                        "tny_mime_part_construct_from_stream first")); 
    569571                camel_object_unref (cstream); 
    570                 return; 
     572                g_set_error (err, TNY_FOLDER_ERROR,  
     573                                TNY_ERROR_UNSPEC, 
     574                                _("Mime part does not yet have a source stream, use " 
     575                                "tny_mime_part_construct_from_stream first")); 
     576                return bytes; 
    571577        } 
    572578 
     
    575581 
    576582        camel_stream_reset (wrapper->stream); 
    577         camel_stream_write_to_stream (wrapper->stream, cstream); 
     583        bytes = (gssize) camel_stream_write_to_stream (wrapper->stream, cstream); 
    578584 
    579585        camel_object_unref (cstream); 
    580586        camel_object_unref (medium); 
    581587 
    582         return; 
    583 
    584  
    585  
    586  
    587 static void 
     588        if (bytes < 0) { 
     589                g_set_error (err, TNY_FOLDER_ERROR,  
     590                                TNY_ERROR_UNSPEC, 
     591                                strerror (errno)); 
     592        } 
     593         
     594        return bytes; 
     595
     596 
     597 
     598 
     599static ssize_t 
    588600camel_stream_format_text (CamelDataWrapper *dw, CamelStream *stream) 
    589601{ 
     
    594606        const char *charset = "UTF-8"; /* I default to UTF-8, like it or not */ 
    595607        CamelMimeFilterWindows *windows = NULL; 
     608        ssize_t bytes = -1; 
    596609 
    597610        if (dw->mime_type && (charset = camel_content_type_param  
     
    624637        } 
    625638 
    626         camel_data_wrapper_decode_to_stream (dw, (CamelStream *)filter_stream); 
     639        bytes = camel_data_wrapper_decode_to_stream (dw, (CamelStream *)filter_stream); 
    627640        camel_stream_flush ((CamelStream *)filter_stream); 
    628641        camel_object_unref (filter_stream); 
     
    631644                camel_object_unref(windows); 
    632645 
    633         return; 
    634 
    635  
    636 static void 
    637 tny_camel_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream) 
    638 
    639         TNY_CAMEL_MIME_PART_GET_CLASS (self)->decode_to_stream_func (self, stream); 
    640         return; 
    641 
    642  
    643 static void 
    644 tny_camel_mime_part_decode_to_stream_default (TnyMimePart *self, TnyStream *stream) 
     646        return bytes; 
     647
     648 
     649static gssize 
     650tny_camel_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream, GError **err) 
     651
     652        return TNY_CAMEL_MIME_PART_GET_CLASS (self)->decode_to_stream_func (self, stream, err); 
     653
     654 
     655static gssize 
     656tny_camel_mime_part_decode_to_stream_default (TnyMimePart *self, TnyStream *stream, GError **err) 
    645657{ 
    646658 
     
    668680        } 
    669681 
     682        gssize bytes = -1; 
     683         
    670684        if (camel_content_type_is (wrapper->mime_type, "text", "*")) 
    671                 camel_stream_format_text (wrapper, cstream); 
     685                bytes = (gssize) camel_stream_format_text (wrapper, cstream); 
    672686        else 
    673                 camel_data_wrapper_decode_to_stream (wrapper, cstream); 
     687                bytes = (gssize) camel_data_wrapper_decode_to_stream (wrapper, cstream); 
    674688 
    675689        camel_object_unref (cstream); 
    676690        camel_object_unref (medium); 
    677  
    678         return; 
     691         
     692        if (bytes < 0) { 
     693                g_set_error (err, TNY_FOLDER_ERROR,  
     694                                TNY_ERROR_UNSPEC, 
     695                                strerror (errno)); 
     696        } 
     697 
     698        return bytes; 
    679699} 
    680700 
  • trunk/libtinymail-camel/tny-camel-mime-part.h

    r3070 r3171  
    5353        gboolean (*content_type_is_func) (TnyMimePart *self, const gchar *content_type); 
    5454        TnyStream* (*get_stream_func) (TnyMimePart *self); 
    55         void (*decode_to_stream_func) (TnyMimePart *self, TnyStream *stream); 
    56         void (*write_to_stream_func) (TnyMimePart *self, TnyStream *stream); 
     55        gssize (*decode_to_stream_func) (TnyMimePart *self, TnyStream *stream, GError **err); 
     56        gssize (*write_to_stream_func) (TnyMimePart *self, TnyStream *stream, GError **err); 
    5757        gint (*construct_from_stream_func) (TnyMimePart *self, TnyStream *stream, const gchar *type); 
    5858        const gchar* (*get_filename_func) (TnyMimePart *self); 
  • trunk/libtinymail-test/tny-mime-part-test.c

    r1339 r3171  
    133133 
    134134        tny_mime_part_construct_from_stream (iface, from, "text/plain"); 
    135         tny_mime_part_write_to_stream (iface, to); 
     135        tny_mime_part_write_to_stream (iface, to, NULL); 
    136136 
    137137        while (!tny_stream_is_eos (to) && n < 1) 
  • trunk/libtinymail/tny-mime-part.c

    r3161 r3171  
    619619 * </programlisting></informalexample> 
    620620 * 
    621  * since: 1.0 
    622  * audience: application-developer 
    623  **/ 
    624 void 
    625 tny_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream) 
     621 * returns: Returns %-1 on error, or the number of bytes succesfully copied. 
     622 * since: 1.0 
     623 * audience: application-developer 
     624 **/ 
     625gssize 
     626tny_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream, GError **err) 
    626627{ 
    627628#ifdef DBC /* require */ 
     
    632633#endif 
    633634 
    634         TNY_MIME_PART_GET_IFACE (self)->write_to_stream_func (self, stream); 
    635         return; 
     635        return TNY_MIME_PART_GET_IFACE (self)->write_to_stream_func (self, stream, err); 
    636636} 
    637637 
     
    675675 * </programlisting></informalexample> 
    676676 * 
    677  * since: 1.0 
    678  * audience: application-developer 
    679  **/ 
    680 void 
    681 tny_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream) 
     677 * returns: Returns %-1 on error, or the number of bytes succesfully copied. 
     678 * since: 1.0 
     679 * audience: application-developer 
     680 **/ 
     681gssize 
     682tny_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream, GError **err) 
    682683{ 
    683684#ifdef DBC /* require */ 
     
    688689#endif 
    689690 
    690         TNY_MIME_PART_GET_IFACE (self)->decode_to_stream_func (self, stream); 
    691         return; 
     691        return TNY_MIME_PART_GET_IFACE (self)->decode_to_stream_func (self, stream, err); 
    692692} 
    693693 
  • trunk/libtinymail/tny-mime-part.h

    r3070 r3171  
    4747        gboolean (*content_type_is_func) (TnyMimePart *self, const gchar *content_type); 
    4848        TnyStream* (*get_stream_func) (TnyMimePart *self); 
    49         void (*decode_to_stream_func) (TnyMimePart *self, TnyStream *stream); 
    50         void (*write_to_stream_func) (TnyMimePart *self, TnyStream *stream); 
     49        gssize (*decode_to_stream_func) (TnyMimePart *self, TnyStream *stream, GError **err); 
     50        gssize (*write_to_stream_func) (TnyMimePart *self, TnyStream *stream, GError **err); 
    5151        gint (*construct_from_stream_func) (TnyMimePart *self, TnyStream *stream, const gchar *type); 
    5252        const gchar* (*get_filename_func) (TnyMimePart *self); 
     
    7676gboolean tny_mime_part_content_type_is (TnyMimePart *self, const gchar *type); 
    7777TnyStream* tny_mime_part_get_stream (TnyMimePart *self); 
    78 void tny_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream); 
     78gssize tny_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream, GError **err); 
    7979gint tny_mime_part_construct_from_stream (TnyMimePart *self, TnyStream *stream, const gchar *type); 
    8080const gchar* tny_mime_part_get_filename (TnyMimePart *self); 
     
    9090void tny_mime_part_set_purged (TnyMimePart *self); 
    9191gboolean tny_mime_part_is_attachment (TnyMimePart *self); 
    92 void tny_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream); 
     92gssize tny_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream, GError **err); 
    9393void tny_mime_part_get_parts (TnyMimePart *self, TnyList *list); 
    9494gint tny_mime_part_add_part (TnyMimePart *self, TnyMimePart *part); 
  • trunk/libtinymailui-webkit/tny-webkit-html-mime-part-view.c

    r2825 r3171  
    8989                dest = tny_webkit_stream_new (GTK_WEBKIT (self)); 
    9090                tny_stream_reset (dest); 
    91                 tny_mime_part_decode_to_stream (part, dest); 
     91                tny_mime_part_decode_to_stream (part, dest, NULL); 
    9292                g_object_unref (G_OBJECT (dest)); 
    9393 
  • trunk/libtinymailui/tny-mime-part-save-strategy.c

    r3151 r3171  
    7979 *            if (fd != -1) { 
    8080 *                      TnyStream *stream = tny_fs_stream_new (fd); 
    81  *                      tny_mime_part_decode_to_stream (part, stream); 
     81 *                      tny_mime_part_decode_to_stream (part, stream, NULL); 
    8282 *                      g_object_unref (stream); 
    8383 *            }