aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmanuele Aina <emanuele.aina@collabora.com>2013-03-26 20:00:17 +0800
committerEmanuele Aina <emanuele.aina@collabora.com>2013-04-01 17:50:28 +0800
commit4299f29ac941292054b4e004aac51e1b143a386a (patch)
tree4fe15b853e51cdf37c06989ead96343c71208e21
parenta169a5c76e983532b4a0699bfc39cd510768a923 (diff)
downloadgsoc2013-empathy-4299f29ac941292054b4e004aac51e1b143a386a.tar
gsoc2013-empathy-4299f29ac941292054b4e004aac51e1b143a386a.tar.gz
gsoc2013-empathy-4299f29ac941292054b4e004aac51e1b143a386a.tar.bz2
gsoc2013-empathy-4299f29ac941292054b4e004aac51e1b143a386a.tar.lz
gsoc2013-empathy-4299f29ac941292054b4e004aac51e1b143a386a.tar.xz
gsoc2013-empathy-4299f29ac941292054b4e004aac51e1b143a386a.tar.zst
gsoc2013-empathy-4299f29ac941292054b4e004aac51e1b143a386a.zip
utils: Add empathy_xml_validate_from_resource()
Validate against dtd stored in a GResource. https://bugzilla.gnome.org/show_bug.cgi?id=696974
-rw-r--r--libempathy/empathy-utils.c35
-rw-r--r--libempathy/empathy-utils.h2
2 files changed, 37 insertions, 0 deletions
diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c
index 74770c159..e074327b6 100644
--- a/libempathy/empathy-utils.c
+++ b/libempathy/empathy-utils.c
@@ -109,6 +109,41 @@ empathy_init (void)
}
gboolean
+empathy_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;
+}
+
+gboolean
empathy_xml_validate (xmlDoc *doc,
const gchar *dtd_filename)
{
diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h
index 5fe79e9ee..7077d835e 100644
--- a/libempathy/empathy-utils.h
+++ b/libempathy/empathy-utils.h
@@ -44,6 +44,8 @@ G_BEGIN_DECLS
void empathy_init (void);
/* XML */
+gboolean empathy_xml_validate_from_resource (xmlDoc *doc,
+ const gchar *dtd_resourcename);
gboolean empathy_xml_validate (xmlDoc *doc,
const gchar *dtd_filename);
xmlNodePtr empathy_xml_node_get_child (xmlNodePtr node,