Re: About tny-mime-part-write-to-stream
- From: Felipe Erias Morandeira <femorandeira igalia com>
- To: Philip Van Hoof <spam pvanhoof be>
- Cc: tinymail-devel-list gnome org
- Subject: Re: About tny-mime-part-write-to-stream
- Date: Thu, 20 Dec 2007 19:09:41 +0100
Hello,
This patch modifies tny_camel_mime_part_write_to_stream and
tny_camel_mime_part_write_to_stream_default so they have the following
signature:
static gssize
tny_camel_mime_part_write_to_stream (
TnyMimePart *self, TnyStream *stream, GError **err)
static gssize
tny_camel_mime_part_write_to_stream_default (
TnyMimePart *self, TnyStream *stream, GError **err)
O Xov, 20-12-2007 ás 11:23 +0100, Philip Van Hoof escribiu:
> Felipe Erias Morandeira wrote:
> > Hi,
> >
> > the attached patch adds a return value to the functions
> > tny_mime_part_write_to_stream and tny_mime_part_decode_to_stream, so
> > they return -1 if there was an error, or the number of bytes transferred
> > otherwise. The implementation use the output of the underlying functions
> > (i.e. camel_data_wrapper_decode_to_stream) to get that value.
>
> That's correct behaviour indeed.
>
> >> void
> >> tny_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream)
>
> Don't you want to adapt tny_mime_part_decode_to_stream too then?
>
> >>
> >> Since this function deals with data I/O, I think that it would be good
> >> to add a return value or a GError parameter, so we can get notified in
> >> case there is some error and inform the user.
> >>
> >> What are your thoughts about it?
>
> What about adding a GError to write_to_stream and decode_to_stream and
> returning -1 in case of error. In the implementations of write_to_stream
> and decode_to_stream you put perror in the GError's description.
>
>
Index: tinymail/libtinymail/tny-mime-part.h
===================================================================
--- tinymail/libtinymail/tny-mime-part.h (revision 3166)
+++ tinymail/libtinymail/tny-mime-part.h (working copy)
@@ -46,8 +46,8 @@
const gchar* (*get_content_type_func) (TnyMimePart *self);
gboolean (*content_type_is_func) (TnyMimePart *self, const gchar *content_type);
TnyStream* (*get_stream_func) (TnyMimePart *self);
- void (*decode_to_stream_func) (TnyMimePart *self, TnyStream *stream);
- void (*write_to_stream_func) (TnyMimePart *self, TnyStream *stream);
+ gssize (*decode_to_stream_func) (TnyMimePart *self, TnyStream *stream, GError **err);
+ gssize (*write_to_stream_func) (TnyMimePart *self, TnyStream *stream, GError **err);
gint (*construct_from_stream_func) (TnyMimePart *self, TnyStream *stream, const gchar *type);
const gchar* (*get_filename_func) (TnyMimePart *self);
const gchar* (*get_content_id_func) (TnyMimePart *self);
@@ -75,7 +75,7 @@
const gchar* tny_mime_part_get_content_type (TnyMimePart *self);
gboolean tny_mime_part_content_type_is (TnyMimePart *self, const gchar *type);
TnyStream* tny_mime_part_get_stream (TnyMimePart *self);
-void tny_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream);
+gssize tny_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream, GError **err);
gint tny_mime_part_construct_from_stream (TnyMimePart *self, TnyStream *stream, const gchar *type);
const gchar* tny_mime_part_get_filename (TnyMimePart *self);
const gchar* tny_mime_part_get_content_id (TnyMimePart *self);
@@ -89,7 +89,7 @@
void tny_mime_part_set_content_type (TnyMimePart *self, const gchar *contenttype);
void tny_mime_part_set_purged (TnyMimePart *self);
gboolean tny_mime_part_is_attachment (TnyMimePart *self);
-void tny_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream);
+gssize tny_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream, GError **err);
void tny_mime_part_get_parts (TnyMimePart *self, TnyList *list);
gint tny_mime_part_add_part (TnyMimePart *self, TnyMimePart *part);
void tny_mime_part_del_part (TnyMimePart *self, TnyMimePart *part);
Index: tinymail/libtinymail/tny-mime-part.c
===================================================================
--- tinymail/libtinymail/tny-mime-part.c (revision 3166)
+++ tinymail/libtinymail/tny-mime-part.c (working copy)
@@ -618,11 +618,13 @@
* }
* </programlisting></informalexample>
*
+ * returns (null-ok): Returns %-1 on error, or the number of bytes succesfully
+ * copied across streams.
* since: 1.0
* audience: application-developer
**/
-void
-tny_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream)
+gssize
+tny_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream, GError **err)
{
#ifdef DBC /* require */
g_assert (TNY_IS_MIME_PART (self));
@@ -631,7 +633,7 @@
g_assert (TNY_MIME_PART_GET_IFACE (self)->write_to_stream_func != NULL);
#endif
- TNY_MIME_PART_GET_IFACE (self)->write_to_stream_func (self, stream);
+ TNY_MIME_PART_GET_IFACE (self)->write_to_stream_func (self, stream, err);
return;
}
@@ -674,11 +676,13 @@
* }
* </programlisting></informalexample>
*
+ * returns (null-ok): Returns %-1 on error, or the number of bytes succesfully
+ * copied across streams.
* since: 1.0
* audience: application-developer
**/
-void
-tny_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream)
+gssize
+tny_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream, GError **err)
{
#ifdef DBC /* require */
g_assert (TNY_IS_MIME_PART (self));
@@ -687,7 +691,7 @@
g_assert (TNY_MIME_PART_GET_IFACE (self)->decode_to_stream_func != NULL);
#endif
- TNY_MIME_PART_GET_IFACE (self)->decode_to_stream_func (self, stream);
+ TNY_MIME_PART_GET_IFACE (self)->decode_to_stream_func (self, stream, err);
return;
}
Index: tinymail/libtinymail-camel/tny-camel-mime-part.h
===================================================================
--- tinymail/libtinymail-camel/tny-camel-mime-part.h (revision 3166)
+++ tinymail/libtinymail-camel/tny-camel-mime-part.h (working copy)
@@ -52,8 +52,8 @@
const gchar* (*get_content_type_func) (TnyMimePart *self);
gboolean (*content_type_is_func) (TnyMimePart *self, const gchar *content_type);
TnyStream* (*get_stream_func) (TnyMimePart *self);
- void (*decode_to_stream_func) (TnyMimePart *self, TnyStream *stream);
- void (*write_to_stream_func) (TnyMimePart *self, TnyStream *stream);
+ gssize (*decode_to_stream_func) (TnyMimePart *self, TnyStream *stream, GError **err);
+ gssize (*write_to_stream_func) (TnyMimePart *self, TnyStream *stream, GError **err);
gint (*construct_from_stream_func) (TnyMimePart *self, TnyStream *stream, const gchar *type);
const gchar* (*get_filename_func) (TnyMimePart *self);
const gchar* (*get_content_id_func) (TnyMimePart *self);
Index: tinymail/libtinymail-camel/tny-camel-mime-part.c
===================================================================
--- tinymail/libtinymail-camel/tny-camel-mime-part.c (revision 3166)
+++ tinymail/libtinymail-camel/tny-camel-mime-part.c (working copy)
@@ -26,6 +26,7 @@
#endif
#include <string.h>
+#include <errno.h>
#include <tny-mime-part.h>
#include <tny-camel-mime-part.h>
@@ -37,6 +38,7 @@
#include <tny-list.h>
#include <tny-simple-list.h>
#include <tny-camel-msg.h>
+#include <tny-error.h>
static GObjectClass *parent_class = NULL;
@@ -244,7 +246,7 @@
{
DecodeAsyncInfo *info = g_slice_new0 (DecodeAsyncInfo);
- tny_mime_part_decode_to_stream (self, stream);
+ tny_mime_part_decode_to_stream (self, stream, NULL);
info->self = g_object_ref (self);
info->stream = g_object_ref (stream);
@@ -537,15 +539,14 @@
return FALSE;
}
-static void
-tny_camel_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream)
+static gssize
+tny_camel_mime_part_write_to_stream (TnyMimePart *self, TnyStream *stream, GError **err)
{
- TNY_CAMEL_MIME_PART_GET_CLASS (self)->write_to_stream_func (self, stream);
- return;
+ return TNY_CAMEL_MIME_PART_GET_CLASS (self)->write_to_stream_func (self, stream, err);
}
-static void
-tny_camel_mime_part_write_to_stream_default (TnyMimePart *self, TnyStream *stream)
+static gssize
+tny_camel_mime_part_write_to_stream_default (TnyMimePart *self, TnyStream *stream, GError **err)
{
TnyCamelMimePartPriv *priv = TNY_CAMEL_MIME_PART_GET_PRIVATE (self);
CamelDataWrapper *wrapper;
@@ -567,24 +568,34 @@
g_error (_("Mime part does not yet have a source stream, use "
"tny_mime_part_construct_from_stream first"));
camel_object_unref (cstream);
- return;
+ g_set_error (err, TNY_FOLDER_ERROR,
+ TNY_ERROR_UNSPEC,
+ _("Mime part does not yet have a source stream, use "
+ "tny_mime_part_construct_from_stream first"));
+ return -1;
}
/* This should work but doesn't . . .
camel_data_wrapper_write_to_stream (wrapper, cstream); */
camel_stream_reset (wrapper->stream);
- camel_stream_write_to_stream (wrapper->stream, cstream);
+ gssize bytes = (gssize) camel_stream_write_to_stream (wrapper->stream, cstream);
camel_object_unref (cstream);
camel_object_unref (medium);
- return;
+ if (bytes < 0 && err != NULL) {
+ g_set_error (err, TNY_FOLDER_ERROR,
+ TNY_ERROR_UNSPEC,
+ strerror (errno));
+ }
+
+ return bytes;
}
-static void
+static ssize_t
camel_stream_format_text (CamelDataWrapper *dw, CamelStream *stream)
{
/* Stolen from evolution, evil evil me!! moehahah */
@@ -623,25 +634,26 @@
camel_object_unref (filter);
}
- camel_data_wrapper_decode_to_stream (dw, (CamelStream *)filter_stream);
+ ssize_t bytes =
+ camel_data_wrapper_decode_to_stream (dw, (CamelStream *)filter_stream);
camel_stream_flush ((CamelStream *)filter_stream);
camel_object_unref (filter_stream);
if (windows)
camel_object_unref(windows);
- return;
+ return bytes;
}
static void
-tny_camel_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream)
+tny_camel_mime_part_decode_to_stream (TnyMimePart *self, TnyStream *stream, GError **err)
{
- TNY_CAMEL_MIME_PART_GET_CLASS (self)->decode_to_stream_func (self, stream);
+ TNY_CAMEL_MIME_PART_GET_CLASS (self)->decode_to_stream_func (self, stream, err);
return;
}
static void
-tny_camel_mime_part_decode_to_stream_default (TnyMimePart *self, TnyStream *stream)
+tny_camel_mime_part_decode_to_stream_default (TnyMimePart *self, TnyStream *stream, GError **err)
{
TnyCamelMimePartPriv *priv = TNY_CAMEL_MIME_PART_GET_PRIVATE (self);
@@ -667,15 +679,23 @@
return;
}
+ gssize bytes = -1;
+
if (camel_content_type_is (wrapper->mime_type, "text", "*"))
- camel_stream_format_text (wrapper, cstream);
+ bytes = (gssize) camel_stream_format_text (wrapper, cstream);
else
- camel_data_wrapper_decode_to_stream (wrapper, cstream);
+ bytes = (gssize) camel_data_wrapper_decode_to_stream (wrapper, cstream);
camel_object_unref (cstream);
camel_object_unref (medium);
+
+ if (bytes < 0 && err != NULL) {
+ g_set_error (err, TNY_FOLDER_ERROR,
+ TNY_ERROR_UNSPEC,
+ strerror (errno));
+ }
- return;
+ return bytes;
}
static gint
Index: tinymail/libtinymailui/tny-mime-part-save-strategy.c
===================================================================
--- tinymail/libtinymailui/tny-mime-part-save-strategy.c (revision 3166)
+++ tinymail/libtinymailui/tny-mime-part-save-strategy.c (working copy)
@@ -78,7 +78,7 @@
* fd = open (uri, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
* if (fd != -1) {
* TnyStream *stream = tny_fs_stream_new (fd);
- * tny_mime_part_decode_to_stream (part, stream);
+ * tny_mime_part_decode_to_stream (part, stream, NULL);
* g_object_unref (stream);
* }
* }
Index: tinymail/libtinymailui-webkit/tny-webkit-html-mime-part-view.c
===================================================================
--- tinymail/libtinymailui-webkit/tny-webkit-html-mime-part-view.c (revision 3166)
+++ tinymail/libtinymailui-webkit/tny-webkit-html-mime-part-view.c (working copy)
@@ -88,7 +88,7 @@
dest = tny_webkit_stream_new (GTK_WEBKIT (self));
tny_stream_reset (dest);
- tny_mime_part_decode_to_stream (part, dest);
+ tny_mime_part_decode_to_stream (part, dest, NULL);
g_object_unref (G_OBJECT (dest));
g_object_ref (G_OBJECT (part));
Index: tinymail/libtinymail-camel/camel-lite/camel/providers/local/camel-maildir-store.c
===================================================================
--- tinymail/libtinymail-camel/camel-lite/camel/providers/local/camel-maildir-store.c (revision 3166)
+++ tinymail/libtinymail-camel/camel-lite/camel/providers/local/camel-maildir-store.c (working copy)
@@ -487,8 +487,8 @@
if (dir == NULL) {
g_free(name);
camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
- _("Could not scan folder `%s': %s"),
- root, g_strerror(errno));
+ _("Could not scan folder `%s', opendir(`%s') failed: %s"),
+ root, name, g_strerror(errno));
goto fail;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]