[evolution-rss] Avoid camel_stream_printf().



commit 62d6e9a7a68dc90abd244431afb47de9826cb423
Author: Lucian Langa <lucilanga gnome org>
Date:   Thu Jul 7 23:34:45 2011 +0300

    Avoid camel_stream_printf().

 src/parser.c |    2 +-
 src/rss.c    |  117 +++++++++++++++++++++++++++++++++++++--------------------
 2 files changed, 77 insertions(+), 42 deletions(-)
---
diff --git a/src/parser.c b/src/parser.c
index 9755b31..4d19ab4 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -185,7 +185,7 @@ xml_parse_sux (const char *buf, int len)
 	 * application/ is often misdetected as text/html
 	 */
 	mime_type = g_content_type_guess(NULL, (guchar *)buf, 100, &uncertain);
-	dp("mime:%s, uncertain:%d\n", mime_type, uncertain);
+	d("mime:%s, uncertain:%d\n", mime_type, uncertain);
 	//feeding parsed anything other than xml results in blocking delays
 	//it's possible we can relax parser by using xmlErrorFunc
 	//UPDATE: add text/* - but exclude text/html I've seen huge delays because of this
diff --git a/src/rss.c b/src/rss.c
index 60d1715..d6b211c 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -2174,6 +2174,7 @@ void org_gnome_cooly_format_rss(void *ep, EMFormatHookTarget *t)	//camelmimepart
 	GdkPixbuf *pix;
 	gchar *feed_dir, *feed_file, *iconfile;
 	gchar *tmp_path, *tmp_file;
+	gchar *str;
 #if EVOLUTION_VERSION >= 22900 //kb//
 	GdkColor color;
 #endif
@@ -2261,10 +2262,11 @@ void org_gnome_cooly_format_rss(void *ep, EMFormatHookTarget *t)	//camelmimepart
 	pobj->website = g_strstrip(g_strdup((gchar *)website));
 	pobj->stream = t->stream;
 	pobj->object.free = free_rss_controls;
-	camel_stream_printf (
-		t->stream,
+	str = g_strdup_printf (
 		"<object classid=%s></object>\n",
 		classid);
+	camel_stream_write_string (t->stream, str, NULL, NULL);
+	g_free(str);
 	g_free (classid);
 
 
@@ -2288,14 +2290,18 @@ void org_gnome_cooly_format_rss(void *ep, EMFormatHookTarget *t)	//camelmimepart
 			pobj->format = (EMFormatHTML *)t->format;
 			pobj->object.free = free_rss_browser;
 			pobj->part = t->part;
-			camel_stream_printf(t->stream,
+			str = g_strdup_printf (
 				"<table style=\"border: solid #%06x 1px; background-color: #%06x; color: #%06x;\" cellpadding=1 cellspacing=0><tr><td align=center>",
 				frame_colour & 0xffffff,
 				frame_colour & 0xffffff,
 				text_colour & 0xffffff);
-			camel_stream_printf (t->stream,
+			camel_stream_write_string (t->stream, str, NULL, NULL);
+			g_free (str);
+			str = g_strdup_printf (
 				"<object classid=%s></object></td></tr></table>",//</div>\n",
 				classid);
+			camel_stream_write_string (t->stream, str, NULL, NULL);
+			g_free (str);
 			g_free (classid);
 			goto out;
 		}
@@ -2306,16 +2312,17 @@ void org_gnome_cooly_format_rss(void *ep, EMFormatHookTarget *t)	//camelmimepart
 			//we do not need to setup a pop error menu since we're in
 			//formatting process. But instead display mail body an error
 			//such proxy error or transport error
-			camel_stream_printf (t->stream,
+			str = g_strdup_printf (
 				"<div style=\"border: solid #%06x 1px; background-color: #%06x; color: #%06x;\">\n",
 				frame_colour & 0xffffff,
 				content_colour & 0xffffff,
 				text_colour & 0xffffff);
-			camel_stream_printf(t->stream,
-				"<div style=\"border: solid 0px; padding: 4px;\">\n");
-			camel_stream_printf (t->stream, "<h3>Error!</h3>");
-			camel_stream_printf (t->stream, "%s", err->message);
-			camel_stream_printf (t->stream, "</div>");
+			camel_stream_write_string (t->stream, str, NULL, NULL);
+			g_free (str);
+			camel_stream_write_string (t->stream, "<div style=\"border: solid 0px; padding: 4px;\">\n", NULL, NULL);
+			camel_stream_write_string (t->stream, "<h3>Error!</h3>", NULL, NULL);
+			camel_stream_write_string (t->stream, err->message, NULL, NULL);
+			camel_stream_write_string (t->stream, "</div>", NULL, NULL);
 			goto out;
 		}
 
@@ -2329,30 +2336,39 @@ void org_gnome_cooly_format_rss(void *ep, EMFormatHookTarget *t)	//camelmimepart
 		} else
 			goto out;
 
-		camel_stream_printf (fstream,
+		str = g_strdup_printf (
 			"<div style=\"border: solid #%06x 1px; background-color: #%06x; color: #%06x;\">\n",
 			frame_colour & 0xffffff,
 			content_colour & 0xffffff,
 			text_colour & 0xffffff);
-		camel_stream_printf (fstream,
+		camel_stream_write_string (fstream, str, NULL, NULL);
+		g_free (str);
+		str = g_strdup_printf (
 			"<div style=\"border: solid 0px; background-color: #%06x; padding: 2px; color: #%06x;\">"
 			"<b><font size=+1><a href=%s>%s</a></font></b></div>",
 			content_colour & 0xEDECEB & 0xffffff,
 			text_colour & 0xffffff,
 			website, subject);
-		if (category)
-			camel_stream_printf(fstream,
+		camel_stream_write_string (fstream, str, NULL, NULL);
+		g_free (str);
+		if (category) {
+			str = g_strdup_printf (
 				"<div style=\"border: solid 0px; background-color: #%06x; padding: 2px; color: #%06x;\">"
 				"<b><font size=-1>%s: %s</font></b></div>",
 				content_colour & 0xEDECEB & 0xffffff, text_colour & 0xffffff,
 				_("Posted under"), category);
-		camel_stream_printf (fstream,
+			camel_stream_write_string (fstream, str, NULL, NULL);
+			g_free (str);
+		}
+		str = g_strdup_printf (
 				"<div style=\"border: solid #%06x 0px; background-color: #%06x; padding: 2px; color: #%06x;\">"
 				"%s</div>",
 				frame_colour & 0xffffff,
 				content_colour & 0xffffff,
 				text_colour & 0xffffff,
 				buff);
+		camel_stream_write_string (fstream, str, NULL, NULL);
+		g_free (str);
 
 		g_string_free(content, 1);
 	} else {
@@ -2479,15 +2495,16 @@ pixdone:			g_free(real_image);
 		feed_file = g_strdup(tmp_path);
 #endif
 
-		camel_stream_printf (
-			fstream,
+		str = g_strdup_printf (
 			"<div style=\"border: solid #%06x 1px; background-color: #%06x; padding: 2px; color: #%06x;\">",
 			frame_colour & 0xffffff,
 			content_colour & 0xEDECEB & 0xffffff,
 			text_colour & 0xffffff);
+		camel_stream_write_string (fstream, str, NULL, NULL);
+		g_free (str);
 		if (g_file_test(tmp_path, G_FILE_TEST_EXISTS)){
 			if ((pixbuf = gdk_pixbuf_new_from_file(tmp_path, NULL))) {
-				camel_stream_printf (fstream,
+				str = g_strdup_printf (
 					"<div style=\"border: solid 0px; background-color: #%06x; padding: 2px; color: #%06x;\">"
 					"<img height=16 src=%s>"
 					"<b><font size=+1><a href=%s>%s</a></font></b></div>",
@@ -2496,6 +2513,8 @@ pixdone:			g_free(real_image);
 					feed_file,
 					website,
 					subject);
+				camel_stream_write_string (fstream, str, NULL, NULL);
+				g_free (str);
 				g_object_unref(pixbuf);
 				g_free(feed_file);
 				goto render_body;
@@ -2511,38 +2530,47 @@ pixdone:			g_free(real_image);
 		iconfile = g_strdup(tmp_file);
 #endif
 		g_free(tmp_file);
-		camel_stream_printf (fstream,
+		str = g_strdup_printf (
 			"<div style=\"border: solid 0px; background-color: #%06x; padding: 2px; color: #%06x;\">"
 			"<img height=16 src=%s>"
 			"<b><font size=+1><a href=%s>%s</a></font></b></div>",
 			content_colour & 0xEDECEB & 0xffffff, text_colour & 0xffffff,
 			iconfile, website, subject);
+		camel_stream_write_string (fstream, str, NULL, NULL);
+		g_free (str);
 		g_free(iconfile);
 		g_free(feed_file);
 
-render_body:	if (category)
-			camel_stream_printf(fstream,
+render_body:	if (category) {
+			str = g_strdup_printf (
 				"<div style=\"border: solid 0px; background-color: #%06x; padding: 2px; color: #%06x;\">"
 				"<b><font size=-1>Posted under: %s</font></b></div>",
 				content_colour & 0xEDECEB & 0xffffff,
 				text_colour & 0xffffff,
 				category);
-		camel_stream_printf (fstream,
-				"<div style=\"border: solid #%06x 0px; background-color: #%06x; padding: 10px; color: #%06x;\">"
-				"%s</div>",
-				frame_colour & 0xffffff,
-				content_colour & 0xffffff,
-				text_colour & 0xffffff,
-				buff);
+			camel_stream_write_string (fstream, str, NULL, NULL);
+			g_free (str);
+		}
+		str = g_strdup_printf (
+			"<div style=\"border: solid #%06x 0px; background-color: #%06x; padding: 10px; color: #%06x;\">"
+			"%s</div>",
+			frame_colour & 0xffffff,
+			content_colour & 0xffffff,
+			text_colour & 0xffffff,
+			buff);
+		camel_stream_write_string (fstream, str, NULL, NULL);
+		g_free (str);
 		if (comments && gconf_client_get_bool (rss_gconf,
 						GCONF_KEY_SHOW_COMMENTS,
 						NULL)) {
 			if (commstream) {
-				camel_stream_printf (fstream,
+				str = g_strdup_printf (
 					"<div style=\"border: solid #%06x 0px; background-color: #%06x; padding: 2px; color: #%06x;\">",
 					frame_colour & 0xffffff,
 					content_colour & 0xEDECEB & 0xffffff,
 					text_colour & 0xffffff);
+				camel_stream_write_string (fstream, str, NULL, NULL);
+				g_free (str);
 				result = print_comments(comments, commstream, (EMFormatHTML *)t->format);
 				g_free(commstream);
 				rfrclsid = g_strdup_printf ("org-gnome-rss-controls-%d",
@@ -2558,15 +2586,19 @@ render_body:	if (category)
 				pobj->website = g_strdup(comments);
 				//this might not be needed but we want to make sure po->html is destroyed
 				pobj->object.free = free_rss_controls;
-				camel_stream_printf(fstream,
+				str = g_strdup_printf (
 					"<object height=25 classid=%s></object>", rfrclsid);
+				camel_stream_write_string (fstream, str, NULL, NULL);
+				g_free (str);
 				if (result && strlen(result)) {
-					camel_stream_printf(fstream,
+					str = g_strdup_printf (
 					"<div style=\"border: solid #%06x 0px; background-color: #%06x; padding: 10px; color: #%06x;\">%s",
 						frame_colour & 0xffffff,
 						content_colour & 0xffffff,
 						text_colour & 0xffffff,
 						result);
+					camel_stream_write_string (fstream, str, NULL, NULL);
+					g_free (str);
 					g_free(result);
 				}
 				g_free(rfrclsid);
@@ -2576,9 +2608,9 @@ render_body:	if (category)
 						rf->hr, g_strstrip(feedid)));
 				fetch_comments(comments, g_strdup(uri), (EMFormatHTML *)t->format);
 			}
-			camel_stream_printf (fstream, "</div>");
+			camel_stream_write_string (fstream, "</div>", NULL, NULL);
 		}
-		camel_stream_printf (fstream, "</div>");
+		camel_stream_write_string (fstream, "</div>", NULL, NULL);
 	}
 
 	//this is required for proper charset rendering when html
@@ -2617,16 +2649,19 @@ out:	if (addr)
 		g_free(addr);
 	return;
 fmerror:
-	camel_stream_printf (t->stream,
+	str = g_strdup_printf (
 		"<div style=\"border: solid #%06x 1px; background-color: #%06x; color: #%06x;\">\n",
 		frame_colour & 0xffffff, content_colour & 0xffffff, text_colour & 0xffffff);
-	camel_stream_printf(t->stream,
-		"<div style=\"border: solid 0px; padding: 4px;\">\n");
-	camel_stream_printf (t->stream,
+	camel_stream_write_string (t->stream, str, NULL, NULL);
+	g_free (str);
+	camel_stream_write_string (t->stream,
+		"<div style=\"border: solid 0px; padding: 4px;\">\n",
+		NULL, NULL);
+	camel_stream_write_string (t->stream,
 		"<h3>Formatting error!</h3>"
-		"Feed article corrupted! Cannot format article.");
-	camel_stream_printf (t->stream,
-		"</div></div>");
+                "Feed article corrupted! Cannot format article.",
+		NULL, NULL);
+	camel_stream_write_string (t->stream, "</div></div>", NULL, NULL);
 	return;
 }
 
@@ -5139,7 +5174,7 @@ create_mail(create_feed *CF)
 	camel_content_type_unref (type);
 	stream = camel_stream_mem_new ();
 	// w/out an format argument this throws and seg fault
-	camel_stream_printf (stream, "%s", CF->body);
+	camel_stream_write_string (stream, CF->body, NULL, NULL);
 #if (DATASERVER_VERSION >= 2033001)
 	/*FIXME may block */
 	camel_data_wrapper_construct_from_stream_sync (rtext, stream, NULL, NULL);



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