[empathy] Embed DTDs for XML validation as GResources



commit 3992967e7a3015a48b5db9c7e652105abe38856e
Author: Emanuele Aina <emanuele aina collabora com>
Date:   Tue Mar 26 13:09:29 2013 +0100

    Embed DTDs for XML validation as GResources
    
    https://bugzilla.gnome.org/show_bug.cgi?id=696974

 libempathy/.gitignore                    |    1 +
 libempathy/Makefile.am                   |   18 ++++++++++++++----
 libempathy/empathy-chatroom-manager.c    |    4 ++--
 libempathy/empathy-contact-groups.c      |    4 ++--
 libempathy/empathy-dtd.gresource.xml     |   10 ++++++++++
 libempathy/empathy-irc-network-manager.c |    4 ++--
 libempathy/empathy-status-presets.c      |    4 ++--
 7 files changed, 33 insertions(+), 12 deletions(-)
---
diff --git a/libempathy/.gitignore b/libempathy/.gitignore
index 8617dcb..5cc6b33 100644
--- a/libempathy/.gitignore
+++ b/libempathy/.gitignore
@@ -1,4 +1,5 @@
 empathy-chandler-glue.h
+empathy-dtd-resources.[ch]
 empathy-marshal.*
 empathy-filter-glue.h
 tp-stream-engine-gen.h
diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am
index 36de4d6..77484d2 100644
--- a/libempathy/Makefile.am
+++ b/libempathy/Makefile.am
@@ -21,6 +21,8 @@ AM_CPPFLAGS =                                           \
        $(DISABLE_DEPRECATED)
 
 BUILT_SOURCES =                                        \
+       empathy-dtd-resources.c                         \
+       empathy-dtd-resources.h                         \
        empathy-enum-types.h                            \
        empathy-enum-types.c
 
@@ -134,8 +136,7 @@ libempathy_la_LIBADD =              \
        $(UOA_LIBS) \
        $(LIBM)
 
-dtddir = $(datadir)/empathy
-dtd_DATA =                                     \
+dtd_resources_files =                          \
        empathy-status-presets.dtd              \
        empathy-contact-groups.dtd              \
        empathy-chatroom-manager.dtd            \
@@ -145,8 +146,17 @@ ircnetworksdir = $(datadir)/empathy
 ircnetworks_DATA =             \
        irc-networks.xml
 
-EXTRA_DIST =                   \
-       $(dtd_DATA)             \
+dtd_resource_files: $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies 
$(srcdir)/empathy-dtd.gresource.xml)
+
+empathy-dtd-resources.c: empathy-dtd.gresource.xml $(dtd_resource_files)
+       $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source $<
+
+empathy-dtd-resources.h: empathy-dtd.gresource.xml $(dtd_resource_files)
+       $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-header $<
+
+EXTRA_DIST =                           \
+       empathy-dtd.gresource.xml       \
+       $(dtd_resources_files)          \
        $(ircnetworks_DATA)
 
 CLEANFILES =                           \
diff --git a/libempathy/empathy-chatroom-manager.c b/libempathy/empathy-chatroom-manager.c
index ebdc504..7a6532f 100644
--- a/libempathy/empathy-chatroom-manager.c
+++ b/libempathy/empathy-chatroom-manager.c
@@ -33,7 +33,7 @@
 #include "empathy-debug.h"
 
 #define CHATROOMS_XML_FILENAME "chatrooms.xml"
-#define CHATROOMS_DTD_FILENAME "empathy-chatroom-manager.dtd"
+#define CHATROOMS_DTD_RESOURCENAME "/org/gnome/Empathy/empathy-chatroom-manager.dtd"
 #define SAVE_TIMER 4
 
 static EmpathyChatroomManager *chatroom_manager_singleton = NULL;
@@ -320,7 +320,7 @@ chatroom_manager_file_parse (EmpathyChatroomManager *manager,
       return FALSE;
     }
 
-  if (!empathy_xml_validate (doc, CHATROOMS_DTD_FILENAME))
+  if (!empathy_xml_validate_from_resource (doc, CHATROOMS_DTD_RESOURCENAME))
     {
       g_warning ("Failed to validate file:'%s'", filename);
       xmlFreeDoc (doc);
diff --git a/libempathy/empathy-contact-groups.c b/libempathy/empathy-contact-groups.c
index 8d49f05..7fb0249 100644
--- a/libempathy/empathy-contact-groups.c
+++ b/libempathy/empathy-contact-groups.c
@@ -31,7 +31,7 @@
 #include "empathy-debug.h"
 
 #define CONTACT_GROUPS_XML_FILENAME "contact-groups.xml"
-#define CONTACT_GROUPS_DTD_FILENAME "empathy-contact-groups.dtd"
+#define CONTACT_GROUPS_DTD_RESOURCENAME "/org/gnome/Empathy/empathy-contact-groups.dtd"
 
 typedef struct {
        gchar    *name;
@@ -91,7 +91,7 @@ contact_groups_file_parse (const gchar *filename)
                return;
        }
 
-       if (!empathy_xml_validate (doc, CONTACT_GROUPS_DTD_FILENAME)) {
+       if (!empathy_xml_validate_from_resource (doc, CONTACT_GROUPS_DTD_RESOURCENAME)) {
                g_warning ("Failed to validate file:'%s'", filename);
                xmlFreeDoc (doc);
                xmlFreeParserCtxt (ctxt);
diff --git a/libempathy/empathy-dtd.gresource.xml b/libempathy/empathy-dtd.gresource.xml
new file mode 100644
index 0000000..76cc817
--- /dev/null
+++ b/libempathy/empathy-dtd.gresource.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/Empathy">
+    <file>empathy-status-presets.dtd</file>
+    <file>empathy-contact-groups.dtd</file>
+    <file>empathy-chatroom-manager.dtd</file>
+    <file>empathy-irc-networks.dtd</file>
+  </gresource>
+</gresources>
+
diff --git a/libempathy/empathy-irc-network-manager.c b/libempathy/empathy-irc-network-manager.c
index 7f6ed9d..3c2a315 100644
--- a/libempathy/empathy-irc-network-manager.c
+++ b/libempathy/empathy-irc-network-manager.c
@@ -28,7 +28,7 @@
 #define DEBUG_FLAG EMPATHY_DEBUG_IRC
 #include "empathy-debug.h"
 
-#define IRC_NETWORKS_DTD_FILENAME "empathy-irc-networks.dtd"
+#define IRC_NETWORKS_DTD_RESOURCENAME "/org/gnome/Empathy/empathy-irc-networks.dtd"
 #define IRC_NETWORKS_FILENAME "irc-networks.xml"
 #define SAVE_TIMER 4
 
@@ -632,7 +632,7 @@ irc_network_manager_file_parse (EmpathyIrcNetworkManager *self,
       return FALSE;
     }
 
-  if (!empathy_xml_validate (doc, IRC_NETWORKS_DTD_FILENAME)) {
+  if (!empathy_xml_validate_from_resource (doc, IRC_NETWORKS_DTD_RESOURCENAME)) {
     g_warning ("Failed to validate file:'%s'", filename);
     xmlFreeDoc (doc);
     xmlFreeParserCtxt (ctxt);
diff --git a/libempathy/empathy-status-presets.c b/libempathy/empathy-status-presets.c
index d8faa4f..1de36d8 100644
--- a/libempathy/empathy-status-presets.c
+++ b/libempathy/empathy-status-presets.c
@@ -31,7 +31,7 @@
 #include "empathy-debug.h"
 
 #define STATUS_PRESETS_XML_FILENAME "status-presets.xml"
-#define STATUS_PRESETS_DTD_FILENAME "empathy-status-presets.dtd"
+#define STATUS_PRESETS_DTD_RESOURCENAME "/org/gnome/Empathy/empathy-status-presets.dtd"
 #define STATUS_PRESETS_MAX_EACH     15
 
 typedef struct {
@@ -92,7 +92,7 @@ status_presets_file_parse (const gchar *filename)
                return;
        }
 
-       if (!empathy_xml_validate (doc, STATUS_PRESETS_DTD_FILENAME)) {
+       if (!empathy_xml_validate_from_resource (doc, STATUS_PRESETS_DTD_RESOURCENAME)) {
                g_warning ("Failed to validate file:'%s'", filename);
                xmlFreeDoc (doc);
                xmlFreeParserCtxt (ctxt);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]