[gupnp-av] Fix two issues with DIDL_S parsing.



commit 00be47d7ce2640a88896aec2f04032fb9c77e7fc
Author: Krzesimir Nowak <krnowak openismus com>
Date:   Mon Nov 26 17:31:39 2012 +0100

    Fix two issues with DIDL_S parsing.
    
    First was a possibility to unref xml_doc too many times on parse
    failure, which was ignored.
    
    Second that media collection didn't clear container and items on parse
    failure.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=689094

 libgupnp-av/gupnp-didl-lite-parser.c |   79 +++++++++++++++++----------------
 libgupnp-av/gupnp-media-collection.c |   10 ++++
 2 files changed, 51 insertions(+), 38 deletions(-)
---
diff --git a/libgupnp-av/gupnp-didl-lite-parser.c b/libgupnp-av/gupnp-didl-lite-parser.c
index 59e073b..086c2cc 100644
--- a/libgupnp-av/gupnp-didl-lite-parser.c
+++ b/libgupnp-av/gupnp-didl-lite-parser.c
@@ -227,12 +227,12 @@ gupnp_didl_lite_parser_parse_didl_recursive (GUPnPDIDLLiteParser *parser,
 {
         xmlDoc       *doc;
         xmlNode      *element;
-        xmlNode      *node;
         xmlNs       **ns_list;
         xmlNs        *upnp_ns = NULL;
         xmlNs        *dc_ns   = NULL;
         xmlNs        *dlna_ns   = NULL;
         GUPnPXMLDoc  *xml_doc;
+        gboolean      result;
 
         doc = xmlRecoverMemory (didl, strlen (didl));
         if (doc == NULL) {
@@ -319,14 +319,17 @@ gupnp_didl_lite_parser_parse_didl_recursive (GUPnPDIDLLiteParser *parser,
 
         xml_doc = gupnp_xml_doc_new (doc);
 
-        return parse_elements (parser,
-                               element,
-                               xml_doc,
-                               upnp_ns,
-                               dc_ns,
-                               dlna_ns,
-                               recursive,
-                               error);
+        result = parse_elements (parser,
+                                 element,
+                                 xml_doc,
+                                 upnp_ns,
+                                 dc_ns,
+                                 dlna_ns,
+                                 recursive,
+                                 error);
+        g_object_unref (xml_doc);
+
+        return result;
 }
 
 static gboolean
@@ -339,7 +342,7 @@ parse_elements (GUPnPDIDLLiteParser *parser,
                 gboolean             recursive,
                 GError             **error)
 {
-        xmlNode      *element;
+        xmlNode *element;
 
         for (element = node->children; element; element = element->next) {
                 GUPnPDIDLLiteObject *object;
@@ -356,44 +359,44 @@ parse_elements (GUPnPDIDLLiteParser *parser,
                                        signals[CONTAINER_AVAILABLE],
                                        0,
                                        object);
-                        if (recursive)
-                                parse_elements (parser,
-                                                element,
-                                                xml_doc,
-                                                upnp_ns,
-                                                dc_ns,
-                                                dlna_ns,
-                                                recursive,
-                                                error);
+                        if (recursive &&
+                            !parse_elements (parser,
+                                             element,
+                                             xml_doc,
+                                             upnp_ns,
+                                             dc_ns,
+                                             dlna_ns,
+                                             recursive,
+                                             error)) {
+                                g_object_unref (object);
+
+                                return FALSE;
+                        }
                 } else if (GUPNP_IS_DIDL_LITE_ITEM (object)) {
-                        node = gupnp_didl_lite_object_get_xml_node(object);
-                        if (!verify_didl_attributes(node)) {
-                            g_object_unref (object);
-                            g_object_unref (xml_doc);
-                            g_set_error (error,
-                                         GUPNP_XML_ERROR,
-                                         GUPNP_XML_ERROR_INVALID_ATTRIBUTE,
-                                         "Could not parse DIDL-Lite XML");
-
-                            return FALSE;
+                        node = gupnp_didl_lite_object_get_xml_node (object);
+                        if (!verify_didl_attributes (node)) {
+                                g_object_unref (object);
+                                g_set_error (error,
+                                             GUPNP_XML_ERROR,
+                                             GUPNP_XML_ERROR_INVALID_ATTRIBUTE,
+                                             "Could not parse DIDL-Lite XML");
+
+                                return FALSE;
                         }
 
                         g_signal_emit (parser,
-                                        signals[ITEM_AVAILABLE],
-                                        0,
-                                        object);
+                                       signals[ITEM_AVAILABLE],
+                                       0,
+                                       object);
                 }
 
                 g_signal_emit (parser,
-                                signals[OBJECT_AVAILABLE],
-                                0,
-                                object);
+                               signals[OBJECT_AVAILABLE],
+                               0,
+                               object);
 
                 g_object_unref (object);
         }
 
-        g_object_unref (xml_doc);
-
         return TRUE;
 }
-
diff --git a/libgupnp-av/gupnp-media-collection.c b/libgupnp-av/gupnp-media-collection.c
index 69ce362..03feb28 100644
--- a/libgupnp-av/gupnp-media-collection.c
+++ b/libgupnp-av/gupnp-media-collection.c
@@ -123,8 +123,18 @@ parse_data (GUPnPMediaCollection *collection, const char *data)
                                                               TRUE,
                                                               &error);
         if (!result) {
+                GUPnPMediaCollectionPrivate *priv = collection->priv;
+
                 g_warning ("Failed to parse DIDL-Lite: %s", error->message);
                 g_error_free (error);
+                if (priv->container) {
+                        g_object_unref (priv->container);
+                        priv->container = NULL;
+                }
+                if (priv->items) {
+                        g_list_free_full (priv->items, g_object_unref);
+                        priv->items = NULL;
+                }
         }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]