summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2013-12-14 14:21:08 +0100
committerJens Georg <mail@jensge.org>2014-06-10 12:49:41 +0200
commit655de6ecfa71d341e8782004f352de06fb6e3bca (patch)
treedc4b1774d6406657cc76259d8c76a52e7a29be2e
parent9b4e5e8b0969a62aabb618dcee4be60b48794ee8 (diff)
downloadgupnp-av-655de6ecfa71d341e8782004f352de06fb6e3bca.tar.gz
Add utility function to lazy-create ns
https://bugzilla.gnome.org/show_bug.cgi?id=705564
-rw-r--r--libgupnp-av/xml-util.c31
-rw-r--r--libgupnp-av/xml-util.h6
2 files changed, 37 insertions, 0 deletions
diff --git a/libgupnp-av/xml-util.c b/libgupnp-av/xml-util.c
index dd32089..cf79a02 100644
--- a/libgupnp-av/xml-util.c
+++ b/libgupnp-av/xml-util.c
@@ -494,3 +494,34 @@ xml_util_lookup_namespace (xmlDocPtr doc, GUPnPXMLNamespace ns)
return retval;
}
+
+/**
+ * xml_util_get_ns:
+ * @doc: A #xmlDoc.
+ * @ns: A #GUPnPXMLNamespace.
+ * @ns_out: (out) (allow-none): return location for the namespace or %NULL.
+ *
+ * Lazy-create a XML namespace on @doc.
+ *
+ * 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__ */