[empathy] utils: Add empathy_xml_validate_from_resource()
- From: Emanuele Aina <emaaa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [empathy] utils: Add empathy_xml_validate_from_resource()
- Date: Mon, 1 Apr 2013 10:30:49 +0000 (UTC)
commit 4299f29ac941292054b4e004aac51e1b143a386a
Author: Emanuele Aina <emanuele aina collabora com>
Date: Tue Mar 26 13:00:17 2013 +0100
utils: Add empathy_xml_validate_from_resource()
Validate against dtd stored in a GResource.
https://bugzilla.gnome.org/show_bug.cgi?id=696974
libempathy/empathy-utils.c | 35 +++++++++++++++++++++++++++++++++++
libempathy/empathy-utils.h | 2 ++
2 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c
index 74770c1..e074327 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 5fe79e9..7077d83 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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]