Mercurial > pidgin
changeset 27202:9ad4b5200f24
Better error checking on the theme loaders.
Patch from Justin "ffdragon6" Rodriguez. Refs #8085.
committer: Paul Aurich <paul@darkrain42.org>
author | Justin Rodriguez <ffdragon@soc.pidgin.im> |
---|---|
date | Sun, 28 Jun 2009 06:26:48 +0000 |
parents | 702ebcb059fd |
children | d629a42c8340 |
files | libpurple/sound-theme-loader.c pidgin/gtkblist-theme-loader.c pidgin/gtkblist-theme.c pidgin/gtkicon-theme-loader.c |
diffstat | 4 files changed, 119 insertions(+), 77 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/sound-theme-loader.c Sun Jun 28 06:21:40 2009 +0000 +++ b/libpurple/sound-theme-loader.c Sun Jun 28 06:26:48 2009 +0000 @@ -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 *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 @@ 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; + + name = xmlnode_get_attrib(root_node, "name"); - /* Parse the tree */ - sub_node = xmlnode_get_child(root_node, "description"); - data = xmlnode_get_data(sub_node); + 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); - 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 (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); - sub_node = xmlnode_get_child(root_node, "event"); + 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); + 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);
--- a/pidgin/gtkblist-theme-loader.c Sun Jun 28 06:21:40 2009 +0000 +++ b/pidgin/gtkblist-theme-loader.c Sun Jun 28 06:26:48 2009 +0000 @@ -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 *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 @@ 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)) { + + 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)); + 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 @@ /* 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,
--- a/pidgin/gtkblist-theme.c Sun Jun 28 06:21:40 2009 +0000 +++ b/pidgin/gtkblist-theme.c Sun Jun 28 06:26:48 2009 +0000 @@ -124,6 +124,9 @@ 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);
--- a/pidgin/gtkicon-theme-loader.c Sun Jun 28 06:21:40 2009 +0000 +++ b/pidgin/gtkicon-theme-loader.c Sun Jun 28 06:26:48 2009 +0000 @@ -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 *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 @@ 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; + + name = xmlnode_get_attrib(root_node, "name"); - /* Parse the tree */ - sub_node = xmlnode_get_child(root_node, "description"); - data = xmlnode_get_data(sub_node); + if (name) { + /* Parse the tree */ + sub_node = xmlnode_get_child(root_node, "description"); + data = xmlnode_get_data(sub_node); - 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 (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); - sub_node = xmlnode_get_child(root_node, "icon"); + 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); + 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); + } } }