[evolution/gnome-2-30] Bug #612178 - Do not access CamelStreamMem::buffer directly



commit 5ff9e8dc50e289e49a2177cf032be627c7c5ae85
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jul 14 10:57:56 2010 +0200

    Bug #612178 - Do not access CamelStreamMem::buffer directly

 calendar/gui/dialogs/comp-editor.c          |   14 ++++++++------
 em-format/em-format.c                       |    7 +++++--
 em-format/em-format.h                       |    2 +-
 mail/em-composer-utils.c                    |    6 ++++--
 mail/em-format-html-display.c               |   18 +++++++++++-------
 mail/em-utils.c                             |    8 +++++---
 plugins/groupwise-features/install-shared.c |   14 ++++++++------
 plugins/mail-to-task/mail-to-task.c         |    6 ++++--
 8 files changed, 46 insertions(+), 29 deletions(-)
---
diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c
index 0b1701d..d6d13d5 100644
--- a/calendar/gui/dialogs/comp-editor.c
+++ b/calendar/gui/dialogs/comp-editor.c
@@ -2917,7 +2917,8 @@ comp_editor_get_mime_attach_list (CompEditor *editor)
 		EAttachment *attachment;
 		CamelDataWrapper *wrapper;
 		CamelMimePart *mime_part;
-		CamelStreamMem *mstream;
+		CamelStream *mem_stream;
+		GByteArray *mem_bytes;
 		guchar *buffer = NULL;
 		const gchar *desc, *disp;
 		gint column_id;
@@ -2934,15 +2935,16 @@ comp_editor_get_mime_attach_list (CompEditor *editor)
 
 		cal_mime_attach = g_malloc0 (sizeof (struct CalMimeAttach));
 		wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part));
-		mstream = (CamelStreamMem *) camel_stream_mem_new ();
+		mem_bytes = g_byte_array_new ();
+		mem_stream = camel_stream_mem_new_with_byte_array (mem_bytes);
 
-		camel_data_wrapper_decode_to_stream (wrapper, (CamelStream *) mstream);
-		buffer = g_memdup (mstream->buffer->data, mstream->buffer->len);
+		camel_data_wrapper_decode_to_stream (wrapper, mem_stream);
+		buffer = g_memdup (mem_bytes->data, mem_bytes->len);
 
 		camel_mime_part_set_content_id (mime_part, NULL);
 
 		cal_mime_attach->encoded_data = (gchar *)buffer;
-		cal_mime_attach->length = mstream->buffer->len;
+		cal_mime_attach->length = mem_bytes->len;
 		cal_mime_attach->filename = g_strdup (camel_mime_part_get_filename (mime_part));
 		desc = camel_mime_part_get_description (mime_part);
 		if (!desc || *desc == '\0')
@@ -2957,7 +2959,7 @@ comp_editor_get_mime_attach_list (CompEditor *editor)
 
 		attach_list = g_slist_append (attach_list, cal_mime_attach);
 
-		camel_object_unref (mstream);
+		camel_object_unref (mem_stream);
 
 	}
 
diff --git a/em-format/em-format.c b/em-format/em-format.c
index a2034b4..93eab4d 100644
--- a/em-format/em-format.c
+++ b/em-format/em-format.c
@@ -1229,6 +1229,7 @@ em_format_format_text(EMFormat *emf, CamelStream *stream, CamelDataWrapper *dw)
 	const gchar *charset = NULL;
 	CamelMimeFilterWindows *windows = NULL;
 	CamelStream *mem_stream = NULL;
+	GByteArray *mem_bytes;
 	gsize size;
 	gsize max;
 	GConfClient *gconf;
@@ -1261,7 +1262,8 @@ em_format_format_text(EMFormat *emf, CamelStream *stream, CamelDataWrapper *dw)
 		charset = emf->default_charset;
 	}
 
-	mem_stream = (CamelStream *)camel_stream_mem_new ();
+	mem_bytes = g_byte_array_new ();
+	mem_stream = camel_stream_mem_new_with_byte_array (mem_bytes);
 	filter_stream = camel_stream_filter_new_with_stream(mem_stream);
 
 	if ((filter = camel_mime_filter_charset_new_convert(charset, "UTF-8"))) {
@@ -1288,11 +1290,12 @@ em_format_format_text(EMFormat *emf, CamelStream *stream, CamelDataWrapper *dw)
 		camel_stream_write_to_stream(mem_stream, (CamelStream *)stream);
 		camel_stream_flush((CamelStream *)stream);
 	} else {
-		((EMFormatClass *)G_OBJECT_GET_CLASS(emf))->format_optional(emf, stream, (CamelMimePart *)dw, mem_stream);
+		((EMFormatClass *)G_OBJECT_GET_CLASS(emf))->format_optional(emf, stream, (CamelMimePart *)dw, mem_bytes);
 	}
 
 	if (windows)
 		camel_object_unref(windows);
+	camel_object_unref (mem_stream);
 }
 
 /**
diff --git a/em-format/em-format.h b/em-format/em-format.h
index 4d8beaa..c5bf160 100644
--- a/em-format/em-format.h
+++ b/em-format/em-format.h
@@ -255,7 +255,7 @@ struct _EMFormatClass {
 	gboolean (*busy)(EMFormat *);
 
 	/* Shows optional way to open messages  */
-	void (*format_optional)(EMFormat *, CamelStream *, CamelMimePart *, CamelStream* );
+	void (*format_optional)(EMFormat *, CamelStream *, CamelMimePart *, const GByteArray *mem_bytes);
 
 	/* signals */
 	/* complete, alternative to polling busy, for asynchronous work */
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 63d0811..d44c0ca 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -925,6 +925,7 @@ traverse_parts (GSList *clues, CamelMimeMessage *message, CamelDataWrapper *cont
 		CamelMimePart *part = CAMEL_MIME_PART (content);
 		CamelContentType *type;
 		CamelStream *mem;
+		GByteArray *mem_bytes;
 		gchar *str;
 
 		content = camel_medium_get_content_object (CAMEL_MEDIUM (part));
@@ -940,10 +941,11 @@ traverse_parts (GSList *clues, CamelMimeMessage *message, CamelDataWrapper *cont
 		if (!camel_content_type_is (type, "text", "*"))
 			return;
 
-		mem = camel_stream_mem_new ();
+		mem_bytes = g_byte_array_new ();
+		mem = camel_stream_mem_new_with_byte_array (mem_bytes);
 		camel_data_wrapper_decode_to_stream (content, mem);
 
-		str = g_strndup ((const gchar *)((CamelStreamMem *) mem)->buffer->data, ((CamelStreamMem *) mem)->buffer->len);
+		str = g_strndup ((const gchar *)mem_bytes->data, mem_bytes->len);
 		camel_object_unref (mem);
 
 		if (replace_variables (clues, message, &str)) {
diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c
index 14a74af..479e8e3 100644
--- a/mail/em-format-html-display.c
+++ b/mail/em-format-html-display.c
@@ -151,8 +151,8 @@ struct _attach_puri {
 	GtkImage *image;
 	GtkWidget *event_box;
 
-	/* Optional Text Mem Stream */
-	CamelStreamMem *mstream;
+	/* Optional Text Data */
+	GByteArray *mem_bytes;
 
 	/* Signed / Encrypted */
         camel_cipher_validity_sign_t sign;
@@ -472,7 +472,7 @@ static void
 efhd_format_optional (EMFormat *emf,
                       CamelStream *fstream,
                       CamelMimePart *part,
-                      CamelStream *mstream)
+                      const GByteArray *mem_bytes)
 {
 	gchar *classid, *html;
 	struct _attach_puri *info;
@@ -494,7 +494,9 @@ efhd_format_optional (EMFormat *emf,
 	info->snoop_mime_type = "text/plain";
 	info->attachment = e_attachment_new ();
 	e_attachment_set_mime_part (info->attachment, info->puri.part);
-	info->mstream = (CamelStreamMem *) mstream;
+	info->mem_bytes = g_byte_array_new ();
+	g_byte_array_append (info->mem_bytes, mem_bytes ? mem_bytes->data : (const guint8 *) "", mem_bytes ? mem_bytes->len : 1);
+
 	if (emf->valid) {
 		info->sign = emf->valid->sign.status;
 		info->encrypt = emf->valid->encrypt.status;
@@ -1038,9 +1040,11 @@ efhd_attachment_optional(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPOb
 	gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
 	gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
 	buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW (view));
-	gtk_text_buffer_set_text (buffer, (gchar *)info->mstream->buffer->data, info->mstream->buffer->len);
-	camel_object_unref(info->mstream);
-	info->mstream = NULL;
+	if (info->mem_bytes) {
+		gtk_text_buffer_set_text (buffer, (gchar *)info->mem_bytes->data, info->mem_bytes->len);
+		g_byte_array_free (info->mem_bytes, TRUE);
+	}
+	info->mem_bytes = NULL;
 	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
 					GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
 	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN);
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 692e461..e7db6d9 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -637,12 +637,14 @@ void
 em_utils_selection_set_mailbox(GtkSelectionData *data, CamelFolder *folder, GPtrArray *uids)
 {
 	CamelStream *stream;
+	GByteArray *mem_bytes;
 
-	stream = camel_stream_mem_new();
+	mem_bytes = g_byte_array_new ();
+	stream = camel_stream_mem_new_with_byte_array (mem_bytes);
 	if (em_utils_write_messages_to_stream(folder, uids, stream) == 0)
 		gtk_selection_data_set(data, data->target, 8,
-				       ((CamelStreamMem *)stream)->buffer->data,
-				       ((CamelStreamMem *)stream)->buffer->len);
+				       mem_bytes->data,
+				       mem_bytes->len);
 
 	camel_object_unref(stream);
 }
diff --git a/plugins/groupwise-features/install-shared.c b/plugins/groupwise-features/install-shared.c
index b570d64..e01221f 100644
--- a/plugins/groupwise-features/install-shared.c
+++ b/plugins/groupwise-features/install-shared.c
@@ -194,7 +194,8 @@ org_gnome_popup_wizard (EPlugin *ep, EMEventTargetMessage *target)
 	const gchar *name;
 	const gchar *email;
 	CamelMimeMessage *msg = (CamelMimeMessage *) target->message;
-	CamelStreamMem *content;
+	CamelStream *mem_content;
+	GByteArray *mem_bytes;
 	CamelDataWrapper *dw;
 	gchar *start_message;
 
@@ -213,9 +214,10 @@ org_gnome_popup_wizard (EPlugin *ep, EMEventTargetMessage *target)
 				return;
 		}
 
-		content = (CamelStreamMem *)camel_stream_mem_new();
-		camel_data_wrapper_write_to_stream(dw, (CamelStream *)content);
-		camel_stream_write((CamelStream *)content, "", 1);
+		mem_bytes = g_byte_array_new ();
+		mem_content = camel_stream_mem_new_with_byte_array (mem_bytes);
+		camel_data_wrapper_write_to_stream(dw, mem_content);
+		camel_stream_write (mem_content, "", 1);
 
 		from_addr = camel_mime_message_get_from ((CamelMimeMessage *)target->message);
 		if (from_addr && camel_internet_address_get(from_addr, 0, &name, &email)) {
@@ -226,7 +228,7 @@ org_gnome_popup_wizard (EPlugin *ep, EMEventTargetMessage *target)
 							   "Message from '%s'\n\n\n"
 							   "%s\n\n\n"
 							   "Click 'Apply' to install the shared folder\n\n"),
-							   name, name, content->buffer->data);
+							   name, name, mem_bytes->data);
 
 			page = gtk_label_new (start_message);
 			gtk_label_set_line_wrap (GTK_LABEL (page), TRUE);
@@ -252,7 +254,7 @@ org_gnome_popup_wizard (EPlugin *ep, EMEventTargetMessage *target)
 		} else
 			g_warning ("Could not get the sender name");
 
-		camel_object_unref(content);
+		camel_object_unref (mem_content);
 	}
 }
 
diff --git a/plugins/mail-to-task/mail-to-task.c b/plugins/mail-to-task/mail-to-task.c
index 17bc6a9..d7ef652 100644
--- a/plugins/mail-to-task/mail-to-task.c
+++ b/plugins/mail-to-task/mail-to-task.c
@@ -182,6 +182,7 @@ set_description (ECalComponent *comp, CamelMimeMessage *message)
 	CamelStream *mem;
 	CamelContentType *type;
 	CamelMimePart *mime_part = CAMEL_MIME_PART (message);
+	GByteArray *mem_bytes;
 	ECalComponentText text;
 	GSList sl;
 	gchar *str, *convert_str = NULL;
@@ -208,10 +209,11 @@ set_description (ECalComponent *comp, CamelMimeMessage *message)
 	if (!camel_content_type_is (type, "text", "plain"))
 		return;
 
-	mem = camel_stream_mem_new ();
+	mem_bytes = g_byte_array_new ();
+	mem = camel_stream_mem_new_with_byte_array (mem_bytes);
 	camel_data_wrapper_decode_to_stream (content, mem);
 
-	str = g_strndup ((const gchar *)((CamelStreamMem *) mem)->buffer->data, ((CamelStreamMem *) mem)->buffer->len);
+	str = g_strndup ((const gchar *) mem_bytes->data, mem_bytes->len);
 	camel_object_unref (mem);
 
 	/* convert to UTF-8 string */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]