Allow an xml tag to be unregistered from the xml parser.
[dana/openbox.git] / obt / xml.c
index 35f3d83..fde3b76 100644 (file)
--- a/obt/xml.c
+++ b/obt/xml.c
@@ -1,6 +1,6 @@
 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
 
-   obt/parse.c for the Openbox window manager
+   obt/xml.c for the Openbox window manager
    Copyright (c) 2003-2007   Dana Jansens
 
    This program is free software; you can redistribute it and/or modify
@@ -19,6 +19,7 @@
 #include "obt/xml.h"
 #include "obt/paths.h"
 
+#include <libxml/xinclude.h>
 #include <glib.h>
 
 #ifdef HAVE_STDLIB_H
@@ -52,12 +53,12 @@ struct _ObtXmlInst {
 static void destfunc(struct Callback *c)
 {
     g_free(c->tag);
-    g_free(c);
+    g_slice_free(struct Callback, c);
 }
 
 ObtXmlInst* obt_xml_instance_new(void)
 {
-    ObtXmlInst *i = g_new(ObtXmlInst, 1);
+    ObtXmlInst *i = g_slice_new(ObtXmlInst);
     i->ref = 1;
     i->xdg_paths = obt_paths_new();
     i->callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
@@ -78,7 +79,7 @@ void obt_xml_instance_unref(ObtXmlInst *i)
     if (i && --i->ref == 0) {
         obt_paths_unref(i->xdg_paths);
         g_hash_table_destroy(i->callbacks);
-        g_free(i);
+        g_slice_free(ObtXmlInst, i);
     }
 }
 
@@ -104,13 +105,18 @@ void obt_xml_register(ObtXmlInst *i, const gchar *tag,
         return;
     }
 
-    c = g_new(struct Callback, 1);
+    c = g_slice_new(struct Callback);
     c->tag = g_strdup(tag);
     c->func = func;
     c->data = data;
     g_hash_table_insert(i->callbacks, c->tag, c);
 }
 
+void obt_xml_unregister(ObtXmlInst *i, const gchar *tag)
+{
+    g_hash_table_remove(i->callbacks, tag);
+}
+
 static gboolean load_file(ObtXmlInst *i,
                           const gchar *domain,
                           const gchar *filename,
@@ -136,6 +142,8 @@ static gboolean load_file(ObtXmlInst *i,
                with extra nodes in it. */
             i->doc = xmlReadFile(path, NULL, (XML_PARSE_NOBLANKS |
                                               XML_PARSE_RECOVER));
+            xmlXIncludeProcessFlags(i->doc, (XML_PARSE_NOBLANKS |
+                                             XML_PARSE_RECOVER));
             if (i->doc) {
                 i->root = xmlDocGetRootElement(i->doc);
                 if (!i->root) {
@@ -300,8 +308,10 @@ void obt_xml_tree(ObtXmlInst *i, xmlNodePtr node)
     g_assert(i->doc); /* a doc is open? */
 
     while (node) {
-        struct Callback *c = g_hash_table_lookup(i->callbacks, node->name);
-        if (c) c->func(node, c->data);
+        if (node->name) {
+            struct Callback *c = g_hash_table_lookup(i->callbacks, node->name);
+            if (c) c->func(node, c->data);
+        }
         node = node->next;
     }
 }