[gupnp-av/wip/lazy-namespaces: 3/5] Add utility function to lazy-create ns



commit 801f1fb174a288e15b5e2c1b88a3e9bc9ae8d001
Author: Jens Georg <mail jensge org>
Date:   Sat Dec 14 14:21:08 2013 +0100

    Add utility function to lazy-create ns

 libgupnp-av/xml-util.c |   29 +++++++++++++++++++++++++++++
 libgupnp-av/xml-util.h |    6 ++++++
 2 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/libgupnp-av/xml-util.c b/libgupnp-av/xml-util.c
index dd32089..91d14f4 100644
--- a/libgupnp-av/xml-util.c
+++ b/libgupnp-av/xml-util.c
@@ -494,3 +494,32 @@ xml_util_lookup_namespace (xmlDocPtr doc, GUPnPXMLNamespace ns)
 
         return retval;
 }
+
+/**
+ * xml_util_get_ns:
+ * Lazy-create a XML namespace on @doc.
+ * @doc: A #xmlDoc.
+ * @ns: A #GUPnPXMLNamespace.
+ * @ns_out: return location for the namespace or %NULL. If *ns_out is non-%NULL,
+ * the function will return *ns_out immediately.
+ * @returns: either the existing #xmlNsPtr or a newly created one.
+ */
+xmlNsPtr
+xml_util_get_ns (xmlDocPtr doc, GUPnPXMLNamespace ns, xmlNsPtr *ns_out)
+{
+        xmlNsPtr tmp_ns;
+
+        /* User supplied namespace, just return that */
+        if (ns_out != NULL && *ns_out != NULL)
+                return *ns_out;
+
+        tmp_ns = xml_util_lookup_namespace (doc, ns);
+        if (!tmp_ns)
+                tmp_ns = xml_util_create_namespace (xmlDocGetRootElement (doc),
+                                                    ns);
+
+        if (ns_out != NULL)
+                *ns_out = tmp_ns;
+
+        return tmp_ns;
+}
diff --git a/libgupnp-av/xml-util.h b/libgupnp-av/xml-util.h
index e08fa19..064dfe8 100644
--- a/libgupnp-av/xml-util.h
+++ b/libgupnp-av/xml-util.h
@@ -134,6 +134,12 @@ xml_util_create_namespace               (xmlNodePtr root,
 G_GNUC_INTERNAL xmlNsPtr
 xml_util_lookup_namespace               (xmlDocPtr doc,
                                          GUPnPXMLNamespace ns);
+
+G_GNUC_INTERNAL xmlNsPtr
+xml_util_get_ns                         (xmlDocPtr doc,
+                                         GUPnPXMLNamespace ns,
+                                         xmlNsPtr *ns_out);
+
 G_END_DECLS
 
 #endif /* __XML_UTIL_H__ */


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