pidgin: 162eda80: Better error checking on the theme loade...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Sun Jun 28 02:40:36 EDT 2009


-----------------------------------------------------------------
Revision: 162eda80c93b079a055b5ddd44fe2e203f8364ee
Ancestor: 660ac01f6c98d9118248b4c11254cf37e4b282ce
Author: ffdragon at soc.pidgin.im
Date: 2009-06-28T06:26:48
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/162eda80c93b079a055b5ddd44fe2e203f8364ee

Modified files:
        libpurple/sound-theme-loader.c
        pidgin/gtkblist-theme-loader.c pidgin/gtkblist-theme.c
        pidgin/gtkicon-theme-loader.c

ChangeLog: 

Better error checking on the theme loaders.

Patch from Justin "ffdragon6" Rodriguez. Refs #8085.

-------------- next part --------------
============================================================
--- libpurple/sound-theme-loader.c	cb7ea5fc1839510f929c3e1d39b8097957e48382
+++ libpurple/sound-theme-loader.c	d46e7d010970c85fa999acbb85fdce88dc5ce48c
@@ -25,6 +25,7 @@
 #include "sound-theme.h"
 #include "util.h"
 #include "xmlnode.h"
+#include "debug.h"
 
 /*****************************************************************************
  * Sound Theme Builder
@@ -34,8 +35,9 @@ purple_sound_loader_build(const gchar *d
 purple_sound_loader_build(const gchar *dir)
 {
 	xmlnode *root_node = NULL, *sub_node;
-	gchar *filename_full, *data;
+	gchar *filename_full, *data = NULL;
 	PurpleSoundTheme *theme = NULL;
+	const gchar *name;
 
 	/* Find the theme file */
 	g_return_val_if_fail(dir != NULL, NULL);
@@ -45,30 +47,35 @@ purple_sound_loader_build(const gchar *d
 		root_node = xmlnode_from_file(dir, "theme.xml", "sound themes", "sound-theme-loader");
 
 	g_free(filename_full);
-	g_return_val_if_fail(root_node != NULL, NULL);
+	if (root_node == NULL)
+		return NULL;
 
-	/* Parse the tree */
-	sub_node = xmlnode_get_child(root_node, "description");
-	data = xmlnode_get_data(sub_node);
+	name = xmlnode_get_attrib(root_node, "name");
 
-	if (xmlnode_get_attrib(root_node, "name") != NULL) {
-		theme = g_object_new(PURPLE_TYPE_SOUND_THEME,
-				"type", "sound",
-				"name", xmlnode_get_attrib(root_node, "name"),
-				"author", xmlnode_get_attrib(root_node, "author"),
-				"image", xmlnode_get_attrib(root_node, "image"),
-				"directory", dir,
-				"description", data, NULL);
+	if (name && purple_strequal(xmlnode_get_attrib(root_node, "type"), "sound")) {
+		/* Parse the tree */
+		sub_node = xmlnode_get_child(root_node, "description");
+		data = xmlnode_get_data(sub_node);
 
-		sub_node = xmlnode_get_child(root_node, "event");
+		if (xmlnode_get_attrib(root_node, "name") != NULL) {
+			theme = g_object_new(PURPLE_TYPE_SOUND_THEME,
+					"type", "sound",
+					"name", name,
+					"author", xmlnode_get_attrib(root_node, "author"),
+					"image", xmlnode_get_attrib(root_node, "image"),
+					"directory", dir,
+					"description", data, NULL);
 
-		while (sub_node) {
-			purple_sound_theme_set_file(theme,
-					xmlnode_get_attrib(sub_node, "name"),
-					xmlnode_get_attrib(sub_node, "file"));
-			sub_node = xmlnode_get_next_twin(sub_node);
+			sub_node = xmlnode_get_child(root_node, "event");
+
+			while (sub_node) {
+				purple_sound_theme_set_file(theme,
+						xmlnode_get_attrib(sub_node, "name"),
+						xmlnode_get_attrib(sub_node, "file"));
+				sub_node = xmlnode_get_next_twin(sub_node);
+			}
 		}
-	}
+	} else purple_debug_warning("sound-theme-loader", "Missing attribute or problem with the root element\n");
 
 	xmlnode_free(root_node);
 	g_free(data);
============================================================
--- pidgin/gtkblist-theme-loader.c	5641a47495bb7b54f8470c66c2605d5bcddcf44b
+++ pidgin/gtkblist-theme-loader.c	9c20f296d60c9bb7d067377e92afd24d3984d541
@@ -24,6 +24,8 @@
 #include <string.h>
 
 #include "xmlnode.h"
+#include "debug.h"
+#include "util.h"
 
 #include "gtkblist-theme-loader.h"
 #include "gtkblist-theme.h"
@@ -58,8 +60,8 @@ pidgin_blist_loader_build(const gchar *d
 pidgin_blist_loader_build(const gchar *dir)
 {
 	xmlnode *root_node = NULL, *sub_node, *sub_sub_node;
-	gchar *filename_full, *data;
-	const gchar *temp;
+	gchar *filename_full, *data = NULL;
+	const gchar *temp, *name;
 	gboolean success = TRUE;
 	GdkColor bgcolor, expanded_bgcolor, collapsed_bgcolor, contact_color;
 	PidginThemeFont *expanded, *collapsed, *contact, *online, *away, *offline, *idle, *message, *message_nick_said, *status;
@@ -100,58 +102,81 @@ pidgin_blist_loader_build(const gchar *d
 		root_node = xmlnode_from_file(dir, "theme.xml", "buddy list themes", "blist-loader");
 
 	g_free(filename_full);
-	g_return_val_if_fail(root_node != NULL, NULL);
+	if (root_node == NULL)
+		return NULL;
 
 	sub_node = xmlnode_get_child(root_node, "description");
 	data = xmlnode_get_data(sub_node);
 
+	name = xmlnode_get_attrib(root_node, "name");
+
 	/* <blist> */
-	if ((success = (sub_node = xmlnode_get_child(root_node, "blist")) != NULL)) {
-		if ((temp = xmlnode_get_attrib(sub_node, "color")) != NULL && gdk_color_parse(temp, &bgcolor))
-			gdk_colormap_alloc_color(gdk_colormap_get_system(), &bgcolor, FALSE, TRUE);
-		else
-			memset(&bgcolor, 0, sizeof(GdkColor));
+	success = name && purple_strequal(xmlnode_get_attrib(root_node, "type"), "pidgin buddy list");
+
+	if (!success)
+		purple_debug_warning("gtkblist-theme-loader", "Missing attribute or problem with the root element\n");
+
+	if (success) {
+		if ((success = (sub_node = xmlnode_get_child(root_node, "blist")) != NULL)) {
+
+			if ((temp = xmlnode_get_attrib(sub_node, "color")) != NULL && gdk_color_parse(temp, &bgcolor))
+				gdk_colormap_alloc_color(gdk_colormap_get_system(), &bgcolor, FALSE, TRUE);
+			else
+				memset(&bgcolor, 0, sizeof(GdkColor));
+
+		} else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <blist>.\n");
 	}
 
 	/* <groups> */
-	if ((success = (success && (sub_node = xmlnode_get_child(root_node, "groups")) != NULL
-		     && (sub_sub_node = xmlnode_get_child(sub_node, "expanded")) != NULL)))
-	{
-		expanded = pidgin_theme_font_parse(sub_sub_node);
+	if (success) {
+		if ((success = (sub_node = xmlnode_get_child(root_node, "groups")) != NULL
+			     && (sub_sub_node = xmlnode_get_child(sub_node, "expanded")) != NULL)) {
+			expanded = pidgin_theme_font_parse(sub_sub_node);
 
-		if ((temp = xmlnode_get_attrib(sub_sub_node, "background")) != NULL && gdk_color_parse(temp, &expanded_bgcolor))
-			gdk_colormap_alloc_color(gdk_colormap_get_system(), &expanded_bgcolor, FALSE, TRUE);
-		else
-			memset(&expanded_bgcolor, 0, sizeof(GdkColor));
+			if ((temp = xmlnode_get_attrib(sub_sub_node, "background")) != NULL && gdk_color_parse(temp, &expanded_bgcolor))
+				gdk_colormap_alloc_color(gdk_colormap_get_system(), &expanded_bgcolor, FALSE, TRUE);
+			else
+				memset(&expanded_bgcolor, 0, sizeof(GdkColor));
+
+		} else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <expanded>.\n");
 	}
 
-	if ((success = (success && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "collapsed")) != NULL)))
-	{
-		collapsed = pidgin_theme_font_parse(sub_sub_node);
+	if (success) {
+		if ((success = sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "collapsed")) != NULL)) {
 
-		if ((temp = xmlnode_get_attrib(sub_sub_node, "background")) != NULL && gdk_color_parse(temp, &collapsed_bgcolor))
-			gdk_colormap_alloc_color(gdk_colormap_get_system(), &collapsed_bgcolor, FALSE, TRUE);
-		else
-			memset(&collapsed_bgcolor, 0, sizeof(GdkColor));
+			collapsed = pidgin_theme_font_parse(sub_sub_node);
+
+			if ((temp = xmlnode_get_attrib(sub_sub_node, "background")) != NULL && gdk_color_parse(temp, &collapsed_bgcolor))
+				gdk_colormap_alloc_color(gdk_colormap_get_system(), &collapsed_bgcolor, FALSE, TRUE);
+			else
+				memset(&collapsed_bgcolor, 0, sizeof(GdkColor));
+
+		} else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <groups> <collapsed>.\n");
 	}
 
 	/* <buddys> */
-	if ((success = (success && (sub_node = xmlnode_get_child(root_node, "buddys")) != NULL &&
-		     (sub_sub_node = xmlnode_get_child(sub_node, "placement")) != NULL)))
-	{
-		layout.status_icon = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) : 0;
-		layout.text = (temp = xmlnode_get_attrib(sub_sub_node, "name")) != NULL ? atoi(temp) : 1;
-		layout.emblem = (temp = xmlnode_get_attrib(sub_sub_node, "emblem")) != NULL ? atoi(temp) : 2;
-		layout.protocol_icon = (temp = xmlnode_get_attrib(sub_sub_node, "protocol_icon")) != NULL ? atoi(temp) : 3;
-		layout.buddy_icon = (temp = xmlnode_get_attrib(sub_sub_node, "buddy_icon")) != NULL ? atoi(temp) : 4;
-		layout.show_status = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) != 0 : 1;
+	if (success) {
+		if ((success = (sub_node = xmlnode_get_child(root_node, "buddys")) != NULL &&
+			     (sub_sub_node = xmlnode_get_child(sub_node, "placement")) != NULL)) {
+
+			layout.status_icon = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) : 0;
+			layout.text = (temp = xmlnode_get_attrib(sub_sub_node, "name")) != NULL ? atoi(temp) : 1;
+			layout.emblem = (temp = xmlnode_get_attrib(sub_sub_node, "emblem")) != NULL ? atoi(temp) : 2;
+			layout.protocol_icon = (temp = xmlnode_get_attrib(sub_sub_node, "protocol_icon")) != NULL ? atoi(temp) : 3;
+			layout.buddy_icon = (temp = xmlnode_get_attrib(sub_sub_node, "buddy_icon")) != NULL ? atoi(temp) : 4;
+			layout.show_status = (temp = xmlnode_get_attrib(sub_sub_node, "status_icon")) != NULL ? atoi(temp) != 0 : 1;
+
+		} else purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <buddys> <placement>.\n");
 	}
 
-	if ((success = (success && sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "background")) != NULL))) {
-		if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), &contact_color))
-			gdk_colormap_alloc_color(gdk_colormap_get_system(), &contact_color, FALSE, TRUE);
-		else
-			memset(&contact_color, 0, sizeof(GdkColor));
+	if (success) {
+		if ((success = (sub_node != NULL && (sub_sub_node = xmlnode_get_child(sub_node, "background")) != NULL))) {
+			if(gdk_color_parse(xmlnode_get_attrib(sub_sub_node, "color"), &contact_color))
+				gdk_colormap_alloc_color(gdk_colormap_get_system(), &contact_color, FALSE, TRUE);
+			else
+				memset(&contact_color, 0, sizeof(GdkColor));
+
+		} purple_debug_warning("gtkblist-theme-loader", "Missing or problem with tags: <buddys> <background>.\n");
 	}
 
 	for (i = 0; success && lookups[i].tag; i++) {
@@ -169,7 +194,7 @@ pidgin_blist_loader_build(const gchar *d
 	/* the new theme */
 	theme = g_object_new(PIDGIN_TYPE_BLIST_THEME,
 			"type", "blist",
-			"name", xmlnode_get_attrib(root_node, "name"),
+			"name", name,
 			"author", xmlnode_get_attrib(root_node, "author"),
 			"image", xmlnode_get_attrib(root_node, "image"),
 			"directory", dir,
============================================================
--- pidgin/gtkblist-theme.c	0e6e2151b2784b35bb93d6dd71b36cedfe172972
+++ pidgin/gtkblist-theme.c	95dcccdfffc92cb912fe3973f69ab12b353a03a7
@@ -124,6 +124,9 @@ copy_font_and_color(const PidginThemeFon
 static PidginThemeFont *
 copy_font_and_color(const PidginThemeFont *pair)
 {
+	if (pair == NULL)
+		return NULL;
+
 	PidginThemeFont *copy = g_new0(PidginThemeFont, 1);
 	copy->font  = g_strdup(pair->font);
 	strncpy(copy->color, pair->color, sizeof(copy->color) - 1);
============================================================
--- pidgin/gtkicon-theme-loader.c	706aa2831eb50000c4f16377d8ae7b1cfd65a7b5
+++ pidgin/gtkicon-theme-loader.c	6b0618c4d851c91f26d118ef33ecd2b4b6c996ad
@@ -24,6 +24,7 @@
 #include "gtkstatus-icon-theme.h"
 
 #include "xmlnode.h"
+#include "debug.h"
 
 /*****************************************************************************
  * Icon Theme Builder
@@ -33,8 +34,9 @@ pidgin_icon_loader_build(const gchar *di
 pidgin_icon_loader_build(const gchar *dir)
 {
 	xmlnode *root_node = NULL, *sub_node;
-	gchar *filename_full, *data;
+	gchar *filename_full, *data = NULL;
 	PidginIconTheme *theme = NULL;
+	const gchar *name;
 
 	/* Find the theme file */
 	g_return_val_if_fail(dir != NULL, NULL);
@@ -44,28 +46,33 @@ pidgin_icon_loader_build(const gchar *di
 		root_node = xmlnode_from_file(dir, "theme.xml", "icon themes", "icon-theme-loader");
 
 	g_free(filename_full);
-	g_return_val_if_fail(root_node != NULL, NULL);
+	if (root_node == NULL)
+		return NULL;
 
-	/* Parse the tree */
-	sub_node = xmlnode_get_child(root_node, "description");
-	data = xmlnode_get_data(sub_node);
+	name = xmlnode_get_attrib(root_node, "name");
 
-	if (xmlnode_get_attrib(root_node, "name") != NULL) {
-		theme = g_object_new(PIDGIN_TYPE_STATUS_ICON_THEME,
-				"type", "status-icon",
-				"name", xmlnode_get_attrib(root_node, "name"),
-				"author", xmlnode_get_attrib(root_node, "author"),
-				"image", xmlnode_get_attrib(root_node, "image"),
-				"directory", dir,
-				"description", data, NULL);
+	if (name) {
+		/* Parse the tree */
+		sub_node = xmlnode_get_child(root_node, "description");
+		data = xmlnode_get_data(sub_node);
 
-		sub_node = xmlnode_get_child(root_node, "icon");
+		if (xmlnode_get_attrib(root_node, "name") != NULL) {
+			theme = g_object_new(PIDGIN_TYPE_STATUS_ICON_THEME,
+					"type", "status-icon",
+					"name", name,
+					"author", xmlnode_get_attrib(root_node, "author"),
+					"image", xmlnode_get_attrib(root_node, "image"),
+					"directory", dir,
+					"description", data, NULL);
 
-		while (sub_node) {
-			pidgin_icon_theme_set_icon(theme,
-					xmlnode_get_attrib(sub_node, "id"),
-					xmlnode_get_attrib(sub_node, "file"));
-			sub_node = xmlnode_get_next_twin(sub_node);
+			sub_node = xmlnode_get_child(root_node, "icon");
+
+			while (sub_node) {
+				pidgin_icon_theme_set_icon(theme,
+						xmlnode_get_attrib(sub_node, "id"),
+						xmlnode_get_attrib(sub_node, "file"));
+				sub_node = xmlnode_get_next_twin(sub_node);
+			}
 		}
 	}
 


More information about the Commits mailing list