[gupnp] [PATCH] Require namespaces to be passed to gupnp_didl_lite_object_new_from_xml()
- From: Sven Neumann <s neumann raumfeld com>
- To: gupnp o-hand com
- Cc: Sven Neumann <s neumann raumfeld com>
- Subject: [gupnp] [PATCH] Require namespaces to be passed to gupnp_didl_lite_object_new_from_xml()
- Date: Fri, 28 May 2010 23:13:35 +0200
Move namespace lookup from GUPnPDIDLLiteObject to GUPnPDIDLLiteParser
and require the upnp_ns and dc_ns parameters to be non-NULL in
gupnp_didl_lite_object_new_from_xml().
The parser now registers the namespaces in case that they can't be found.
Otherwise modifying GUPnPDIDLLiteObject objects created by the parser
will fail.
Signed-off-by: Sven Neumann <s neumann raumfeld com>
---
libgupnp-av/gupnp-didl-lite-object.c | 55 ++-------------------------------
libgupnp-av/gupnp-didl-lite-parser.c | 49 +++++++++++++++++++++++++++--
2 files changed, 49 insertions(+), 55 deletions(-)
diff --git a/libgupnp-av/gupnp-didl-lite-object.c b/libgupnp-av/gupnp-didl-lite-object.c
index a43e669..890a9c7 100644
--- a/libgupnp-av/gupnp-didl-lite-object.c
+++ b/libgupnp-av/gupnp-didl-lite-object.c
@@ -285,55 +285,6 @@ gupnp_didl_lite_object_get_property (GObject *object,
}
static void
-gupnp_didl_lite_object_lookup_namespaces (GUPnPDIDLLiteObjectPrivate *priv)
-{
- xmlNs **ns_list;
-
- if (priv->upnp_ns && priv->dc_ns)
- return;
-
- ns_list = xmlGetNsList (priv->xml_doc->doc,
- xmlDocGetRootElement (priv->xml_doc->doc));
-
- if (ns_list) {
- short i;
-
- for (i = 0; ns_list[i] != NULL; i++) {
- const char *prefix;
-
- prefix = (const char *) ns_list[i]->prefix;
-
- if (prefix == NULL)
- continue;
-
- if (! priv->upnp_ns &&
- g_ascii_strcasecmp (prefix, "upnp") == 0)
- priv->upnp_ns = ns_list[i];
- else if (! priv->dc_ns &&
- g_ascii_strcasecmp (prefix, "dc") == 0)
- priv->dc_ns = ns_list[i];
- }
-
- xmlFree (ns_list);
- }
-}
-
-static void
-gupnp_didl_lite_object_constructed (GObject *object)
-{
- GObjectClass *object_class;
- GUPnPDIDLLiteObjectPrivate *priv;
-
- priv = GUPNP_DIDL_LITE_OBJECT (object)->priv;
-
- gupnp_didl_lite_object_lookup_namespaces (priv);
-
- object_class = G_OBJECT_CLASS (gupnp_didl_lite_object_parent_class);
- if (object_class->constructed != NULL)
- object_class->constructed (object);
-}
-
-static void
gupnp_didl_lite_object_dispose (GObject *object)
{
GObjectClass *object_class;
@@ -359,7 +310,6 @@ gupnp_didl_lite_object_class_init (GUPnPDIDLLiteObjectClass *klass)
object_class->set_property = gupnp_didl_lite_object_set_property;
object_class->get_property = gupnp_didl_lite_object_get_property;
- object_class->constructed = gupnp_didl_lite_object_constructed;
object_class->dispose = gupnp_didl_lite_object_dispose;
g_type_class_add_private (klass, sizeof (GUPnPDIDLLiteObjectPrivate));
@@ -785,6 +735,8 @@ get_contributor_list_by_name (GUPnPDIDLLiteObject *object,
* gupnp_didl_lite_object_new_from_xml:
* @xml_node: The pointer to 'res' node in XML document
* @xml_doc: The reference to XML document containing this object
+ * @upnp_ns: The pointer to 'upnp' namespace in XML document
+ * @dc_ns: The pointer to 'dc' namespace in XML document
*
* Creates a new #GUPnPDIDLLiteObject for the @xml_node.
*
@@ -798,7 +750,8 @@ gupnp_didl_lite_object_new_from_xml (xmlNode *xml_node,
{
g_return_val_if_fail (xml_node != NULL, NULL);
g_return_val_if_fail (xml_node->name != NULL, NULL);
- g_return_val_if_fail (GUPNP_IS_XML_DOC (xml_doc), NULL);
+ g_return_val_if_fail (upnp_ns != NULL, NULL);
+ g_return_val_if_fail (dc_ns != NULL, NULL);
if (g_ascii_strcasecmp ((char *) xml_node->name, "container") == 0)
return g_object_new (GUPNP_TYPE_DIDL_LITE_CONTAINER,
diff --git a/libgupnp-av/gupnp-didl-lite-parser.c b/libgupnp-av/gupnp-didl-lite-parser.c
index e7e24ac..ad554ae 100644
--- a/libgupnp-av/gupnp-didl-lite-parser.c
+++ b/libgupnp-av/gupnp-didl-lite-parser.c
@@ -163,9 +163,12 @@ gupnp_didl_lite_parser_parse_didl (GUPnPDIDLLiteParser *parser,
const char *didl,
GError **error)
{
- xmlDoc *doc;
- xmlNode *element;
- GUPnPXMLDoc *xml_doc;
+ xmlDoc *doc;
+ xmlNode *element;
+ xmlNs **ns_list;
+ xmlNs *upnp_ns = NULL;
+ xmlNs *dc_ns = NULL;
+ GUPnPXMLDoc *xml_doc;
doc = xmlRecoverMemory (didl, strlen (didl));
if (doc == NULL) {
@@ -203,13 +206,51 @@ gupnp_didl_lite_parser_parse_didl (GUPnPDIDLLiteParser *parser,
return FALSE;
}
+ /* Lookup UPnP and DC namespaces */
+ ns_list = xmlGetNsList (doc,
+ xmlDocGetRootElement (doc));
+
+ if (ns_list) {
+ short i;
+
+ for (i = 0; ns_list[i] != NULL; i++) {
+ const char *prefix = (const char *) ns_list[i]->prefix;
+
+ if (prefix == NULL)
+ continue;
+
+ if (! upnp_ns &&
+ g_ascii_strcasecmp (prefix, "upnp") == 0)
+ upnp_ns = ns_list[i];
+ else if (! dc_ns &&
+ g_ascii_strcasecmp (prefix, "dc") == 0)
+ dc_ns = ns_list[i];
+ }
+
+ xmlFree (ns_list);
+ }
+
+ /* Create UPnP and DC namespaces if they don't exist */
+ if (! upnp_ns)
+ upnp_ns = xmlNewNs (xmlDocGetRootElement (doc),
+ (unsigned char *)
+ "urn:schemas-upnp-org:metadata-1-0/upnp/",
+ (unsigned char *)
+ GUPNP_DIDL_LITE_WRITER_NAMESPACE_UPNP);
+ if (! dc_ns)
+ dc_ns = xmlNewNs (xmlDocGetRootElement (doc),
+ (unsigned char *)
+ "http://purl.org/dc/elements/1.1/",
+ (unsigned char *)
+ GUPNP_DIDL_LITE_WRITER_NAMESPACE_DC);
+
xml_doc = gupnp_xml_doc_new (doc);
for (element = element->children; element; element = element->next) {
GUPnPDIDLLiteObject *object;
object = gupnp_didl_lite_object_new_from_xml (element, xml_doc,
- NULL, NULL);
+ upnp_ns, dc_ns);
if (object == NULL)
continue;
--
1.7.1
--
To unsubscribe send a mail to gupnp+unsubscribe\@o-hand.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]