[gupnp-av/wip/lazy-namespaces: 5/5] Revert "Add dlna namespace only when it's actually used"



commit bb2f6e67ac1b673a609873f71003dfb94776050e
Author: Jens Georg <mail jensge org>
Date:   Sat Dec 14 15:32:29 2013 +0100

    Revert "Add dlna namespace only when it's actually used"
    
    This reverts commit 50a5e45591e7bccb79250502c22233793dc6b2cb.
    
    Conflicts:
        libgupnp-av/gupnp-didl-lite-writer.c

 libgupnp-av/gupnp-didl-lite-resource.c |    5 +++
 libgupnp-av/gupnp-didl-lite-resource.h |    1 +
 libgupnp-av/gupnp-didl-lite-writer.c   |   46 ++++---------------------------
 3 files changed, 12 insertions(+), 40 deletions(-)
---
diff --git a/libgupnp-av/gupnp-didl-lite-resource.c b/libgupnp-av/gupnp-didl-lite-resource.c
index e11f204..b8a964a 100644
--- a/libgupnp-av/gupnp-didl-lite-resource.c
+++ b/libgupnp-av/gupnp-didl-lite-resource.c
@@ -1470,6 +1470,11 @@ gupnp_didl_lite_resource_set_cleartext_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 cec572c..b2bb862 100644
--- a/libgupnp-av/gupnp-didl-lite-resource.h
+++ b/libgupnp-av/gupnp-didl-lite-resource.h
@@ -80,6 +80,7 @@ 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 a357705..365a37a 100644
--- a/libgupnp-av/gupnp-didl-lite-writer.c
+++ b/libgupnp-av/gupnp-didl-lite-writer.c
@@ -52,8 +52,6 @@ struct _GUPnPDIDLLiteWriterPrivate {
         xmlNs       *pv_ns;
 
         char        *language;
-
-        gboolean    dlna_attr_present;
 };
 
 enum {
@@ -209,19 +207,6 @@ 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,
@@ -236,14 +221,10 @@ 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;
@@ -298,13 +279,8 @@ apply_filter (GUPnPDIDLLiteWriter *writer,
         g_return_if_fail (GUPNP_IS_DIDL_LITE_WRITER (writer));
         g_return_if_fail (filter != NULL);
 
-        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);
+        if (filter[0] == '*')
                 return;         /* Wildcard */
-        }
 
         tokens = g_strsplit (filter, ",", -1);
         g_return_if_fail (tokens != NULL);
@@ -317,12 +293,6 @@ 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);
 }
@@ -405,10 +375,8 @@ gupnp_didl_lite_writer_constructed (GObject *object)
 
         priv->upnp_ns = xml_util_create_namespace (priv->xml_node,
                                                    GUPNP_XML_NAMESPACE_UPNP);
-        /* 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 = xml_util_create_namespace (NULL,
+        priv->dlna_ns = xmlNewNs (priv->xml_node,
+        priv->dlna_ns = xml_util_create_namespace (priv->xml_node,
                                                    GUPNP_XML_NAMESPACE_DLNA);
         priv->pv_ns = xml_util_create_namespace (priv->xml_node,
                                                  GUPNP_XML_NAMESPACE_PV);
@@ -421,8 +389,6 @@ 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]