Commit 50a5e455 authored by Parthiban Balasubramanian's avatar Parthiban Balasubramanian Committed by Jens Georg

Add dlna namespace only when it's actually used

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=705564
parent fa3cef8c
......@@ -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);
}
......
......@@ -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,
......
......@@ -51,6 +51,8 @@ struct _GUPnPDIDLLiteWriterPrivate {
xmlNs *dlna_ns;
char *language;
gboolean dlna_attr_present;
};
enum {
......@@ -205,6 +207,19 @@ filter_attributes (xmlNode *node,
g_list_free (forbidden);
}
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,
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment