From 5c0d938cf15d07c0f7511c5acb9a3d8e42278e0d Mon Sep 17 00:00:00 2001 From: Marco Barisione Date: Fri, 10 May 2013 16:08:28 +0100 Subject: tpaw-utils: move empathy_xml_validate_from_resource to tp-aw and rename it This commit also changes the licence of the moved code (all copyrighted by Collabora Ltd.) from GPL to LGPL. https://bugzilla.gnome.org/show_bug.cgi?id=699492 --- tp-account-widgets/tpaw-irc-network-manager.c | 3 ++- tp-account-widgets/tpaw-utils.c | 36 +++++++++++++++++++++++++++ tp-account-widgets/tpaw-utils.h | 6 +++++ 3 files changed, 44 insertions(+), 1 deletion(-) (limited to 'tp-account-widgets') diff --git a/tp-account-widgets/tpaw-irc-network-manager.c b/tp-account-widgets/tpaw-irc-network-manager.c index e6fdebacc..12c73d6d3 100644 --- a/tp-account-widgets/tpaw-irc-network-manager.c +++ b/tp-account-widgets/tpaw-irc-network-manager.c @@ -24,6 +24,7 @@ #include #include "empathy-utils.h" +#include "tpaw-utils.h" #define DEBUG_FLAG EMPATHY_DEBUG_IRC #include "empathy-debug.h" @@ -632,7 +633,7 @@ irc_network_manager_file_parse (TpawIrcNetworkManager *self, return FALSE; } - if (!empathy_xml_validate_from_resource (doc, IRC_NETWORKS_DTD_RESOURCENAME)) { + if (!tpaw_xml_validate_from_resource (doc, IRC_NETWORKS_DTD_RESOURCENAME)) { g_warning ("Failed to validate file:'%s'", filename); xmlFreeDoc (doc); xmlFreeParserCtxt (ctxt); diff --git a/tp-account-widgets/tpaw-utils.c b/tp-account-widgets/tpaw-utils.c index 933b8570e..a31fc2681 100644 --- a/tp-account-widgets/tpaw-utils.c +++ b/tp-account-widgets/tpaw-utils.c @@ -12,6 +12,7 @@ * Richard Hult * Martyn Russell * Steve Frécinaux + * Emanuele Aina * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -181,6 +182,41 @@ tpaw_make_color_whiter (GdkRGBA *color) color->blue = (color->blue + white.blue) / 2; } +gboolean +tpaw_xml_validate_from_resource (xmlDoc *doc, + const gchar *dtd_resourcename) +{ + GBytes *resourcecontents; + gconstpointer resourcedata; + gsize resourcesize; + xmlParserInputBufferPtr buffer; + xmlValidCtxt cvp; + xmlDtd *dtd; + GError *error = NULL; + gboolean ret; + + DEBUG ("Loading dtd resource %s", dtd_resourcename); + + resourcecontents = g_resources_lookup_data (dtd_resourcename, G_RESOURCE_LOOKUP_FLAGS_NONE, &error); + if (error != NULL) + { + g_warning ("Unable to load dtd resource '%s': %s", dtd_resourcename, error->message); + g_error_free (error); + return FALSE; + } + resourcedata = g_bytes_get_data (resourcecontents, &resourcesize); + buffer = xmlParserInputBufferCreateStatic (resourcedata, resourcesize, XML_CHAR_ENCODING_UTF8); + + memset (&cvp, 0, sizeof (cvp)); + dtd = xmlIOParseDTD (NULL, buffer, XML_CHAR_ENCODING_UTF8); + ret = xmlValidateDtd (&cvp, doc, dtd); + + xmlFreeDtd (dtd); + g_bytes_unref (resourcecontents); + + return ret; +} + /* Takes care of moving the window to the current workspace. */ void tpaw_window_present_with_time (GtkWindow *window, diff --git a/tp-account-widgets/tpaw-utils.h b/tp-account-widgets/tpaw-utils.h index f82b5a6f7..8a40dc93b 100644 --- a/tp-account-widgets/tpaw-utils.h +++ b/tp-account-widgets/tpaw-utils.h @@ -12,6 +12,7 @@ * Richard Hult * Martyn Russell * Steve Frécinaux + * Emanuele Aina * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -33,6 +34,7 @@ #include #include +#include #include G_BEGIN_DECLS @@ -44,6 +46,10 @@ gchar *tpaw_protocol_icon_name (const gchar *protocol); const gchar *tpaw_protocol_name_to_display_name (const gchar *proto_name); const gchar *tpaw_service_name_to_display_name (const gchar *proto_name); +/* XML */ +gboolean tpaw_xml_validate_from_resource (xmlDoc *doc, + const gchar *dtd_resourcename); + void tpaw_make_color_whiter (GdkRGBA *color); /* Windows */ -- cgit v1.2.3