diff options
-rw-r--r-- | libempathy/empathy-utils.c | 35 | ||||
-rw-r--r-- | 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 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, |