[gupnp-av] Add dlna namespace only when it's actually used
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp-av] Add dlna namespace only when it's actually used
- Date: Wed, 16 Oct 2013 11:56:17 +0000 (UTC)
commit 50a5e45591e7bccb79250502c22233793dc6b2cb
Author: Parthiban Balasubramanian <p balasubramanian cablelabs com>
Date: Tue Sep 3 14:26:42 2013 -0600
Add dlna namespace only when it's actually used
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=705564
libgupnp-av/gupnp-didl-lite-resource.c | 5 ---
libgupnp-av/gupnp-didl-lite-resource.h | 1 -
libgupnp-av/gupnp-didl-lite-writer.c | 45 ++++++++++++++++++++++++++++---
3 files changed, 40 insertions(+), 11 deletions(-)
---
diff --git a/libgupnp-av/gupnp-didl-lite-resource.c b/libgupnp-av/gupnp-didl-lite-resource.c
index dbb2789..56827a2 100644
--- a/libgupnp-av/gupnp-didl-lite-resource.c
+++ b/libgupnp-av/gupnp-didl-lite-resource.c
@@ -1294,11 +1294,6 @@ gupnp_didl_lite_resource_set_clear_text_size
resource->priv->dlna_ns,
(unsigned char *) "cleartextSize",
(unsigned char *) str);
- if (resource->priv->dlna_ns) {
- xmlNewNs (resource->priv->xml_node,
- resource->priv->dlna_ns->href,
- GUPNP_DIDL_LITE_RESOURCE_NAMESPACE_DLNA);
- }
g_free (str);
}
diff --git a/libgupnp-av/gupnp-didl-lite-resource.h b/libgupnp-av/gupnp-didl-lite-resource.h
index c3b8967..9ecb6bc 100644
--- a/libgupnp-av/gupnp-didl-lite-resource.h
+++ b/libgupnp-av/gupnp-didl-lite-resource.h
@@ -80,7 +80,6 @@ typedef struct {
void (* _gupnp_reserved4) (void);
} GUPnPDIDLLiteResourceClass;
-#define GUPNP_DIDL_LITE_RESOURCE_NAMESPACE_DLNA "dlna"
void
gupnp_didl_lite_resource_set_uri (GUPnPDIDLLiteResource *resource,
diff --git a/libgupnp-av/gupnp-didl-lite-writer.c b/libgupnp-av/gupnp-didl-lite-writer.c
index bd57138..5b0291f 100644
--- a/libgupnp-av/gupnp-didl-lite-writer.c
+++ b/libgupnp-av/gupnp-didl-lite-writer.c
@@ -51,6 +51,8 @@ struct _GUPnPDIDLLiteWriterPrivate {
xmlNs *dlna_ns;
char *language;
+
+ gboolean dlna_attr_present;
};
enum {
@@ -206,6 +208,19 @@ filter_attributes (xmlNode *node,
}
static void
+check_dlna_attr (xmlNode *node,
+ GUPnPDIDLLiteWriter *writer)
+{
+ xmlAttr *attr;
+
+ /* check if dlna prefix is present for a node */
+ for (attr = node->properties; attr != NULL; attr = attr->next) {
+ if (attr->ns && g_strcmp0 (attr->ns->prefix, "dlna") == 0)
+ writer->priv->dlna_attr_present = TRUE;
+ }
+}
+
+static void
filter_node (xmlNode *node,
GList *allowed,
GUPnPDIDLLiteWriter *writer,
@@ -220,10 +235,14 @@ filter_node (xmlNode *node,
if (!tags_only)
filter_attributes (node, allowed);
+ // Check if dlna namespace attribute is present
+ if (!writer->priv->dlna_attr_present)
+ check_dlna_attr (node, writer);
+
if (strcmp ((const char *) node->name, "container") == 0) {
- is_container = TRUE;
- container_class = xml_util_get_child_element_content (node,
- "class");
+ is_container = TRUE;
+ container_class = xml_util_get_child_element_content (node,
+ "class");
}
forbidden = NULL;
@@ -278,8 +297,13 @@ apply_filter (GUPnPDIDLLiteWriter *writer,
g_return_if_fail (GUPNP_IS_DIDL_LITE_WRITER (writer));
g_return_if_fail (filter != NULL);
- if (filter[0] == '*')
+ if (filter[0] == '*') {
+ /* Create DLNA namespace as we include anything anyway */
+ xmlNewNs (writer->priv->xml_node,
+ writer->priv->dlna_ns->href,
+ writer->priv->dlna_ns->prefix);
return; /* Wildcard */
+ }
tokens = g_strsplit (filter, ",", -1);
g_return_if_fail (tokens != NULL);
@@ -292,6 +316,12 @@ apply_filter (GUPnPDIDLLiteWriter *writer,
node = node->next)
filter_node (node, allowed, writer, tags_only);
+ if (writer->priv->dlna_attr_present) {
+ xmlNewNs (writer->priv->xml_node,
+ writer->priv->dlna_ns->href,
+ writer->priv->dlna_ns->prefix);
+ }
+
g_list_free (allowed);
g_strfreev (tokens);
}
@@ -378,7 +408,10 @@ gupnp_didl_lite_writer_constructed (GObject *object)
"urn:schemas-upnp-org:metadata-1-0/upnp/",
(unsigned char *)
GUPNP_DIDL_LITE_WRITER_NAMESPACE_UPNP);
- priv->dlna_ns = xmlNewNs (priv->xml_node,
+ /* Not adding dlna namespace declaration to any node yet.
+ Add the namespace to Didl-Lite element only if any of the child
+ nodes have dlna namespace prefix attributes */
+ priv->dlna_ns = xmlNewNs (NULL,
(unsigned char *)
"urn:schemas-dlna-org:metadata-1-0/",
(unsigned char *)
@@ -393,6 +426,8 @@ gupnp_didl_lite_writer_constructed (GObject *object)
(unsigned char *) "lang",
(unsigned char *) priv->language);
+ priv->dlna_attr_present = FALSE;
+
object_class = G_OBJECT_CLASS (gupnp_didl_lite_writer_parent_class);
if (object_class->constructed != NULL)
object_class->constructed (object);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]