[vlc-commits] Support for LG N1A1 UPnP server

Fabrizio Gennari git at videolan.org
Tue Jan 6 23:29:31 CET 2015


vlc | branch: master | Fabrizio Gennari <fabrizio.ge at tiscali.it> | Tue Jan  6 23:24:30 2015 +0100| [0ec04296a44bd29b973dc71a0a2d3f39aed798d5] | committer: Jean-Baptiste Kempf

Support for LG N1A1 UPnP server

Connecting to a LG N1A1 NAS device gave:
upnp services discovery error: browse() response parsing failed

There is a "ugly hack" ("The DIDL document is extracted from the Result tag,
then wrapped into a valid XML header and a new root tag") in the code now.
This actually break parsing the reply by the LG N1A1.

Now, we try parsing the reply as is, and uses the "ugly hack" as a fallback only.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0ec04296a44bd29b973dc71a0a2d3f39aed798d5
---

 modules/services_discovery/upnp.cpp |   47 +++++++++++++++++++----------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/modules/services_discovery/upnp.cpp b/modules/services_discovery/upnp.cpp
index 483f374..ab765aa 100644
--- a/modules/services_discovery/upnp.cpp
+++ b/modules/services_discovery/upnp.cpp
@@ -259,33 +259,36 @@ IXML_Document* parseBrowseResult( IXML_Document* p_doc )
 {
     assert( p_doc );
 
-    /* Missing namespaces confuse the ixml parser. This is a very ugly
-     * hack but it is needeed until devices start sending valid XML.
-     *
-     * It works that way:
-     *
-     * The DIDL document is extracted from the Result tag, then wrapped into
-     * a valid XML header and a new root tag which contains missing namespace
-     * definitions so the ixml parser understands it.
-     *
-     * If you know of a better workaround, please oh please fix it */
-    const char* psz_xml_result_fmt = "<?xml version=\"1.0\" ?>"
-        "<Result xmlns:sec=\"urn:samsung:metadata:2009\">%s</Result>";
-
-    char* psz_xml_result_string = NULL;
     const char* psz_raw_didl = xml_getChildElementValue( p_doc, "Result" );
 
     if( !psz_raw_didl )
         return NULL;
 
-    if( -1 == asprintf( &psz_xml_result_string,
-                         psz_xml_result_fmt,
-                         psz_raw_didl) )
-        return NULL;
-
-
-    IXML_Document* p_result_doc = ixmlParseBuffer( psz_xml_result_string );
-    free( psz_xml_result_string );
+    /* First, try parsing the buffer as is */
+    IXML_Document* p_result_doc = ixmlParseBuffer( psz_raw_didl );
+    if( !p_result_doc ) {
+        /* Missing namespaces confuse the ixml parser. This is a very ugly
+         * hack but it is needeed until devices start sending valid XML.
+         *
+         * It works that way:
+         *
+         * The DIDL document is extracted from the Result tag, then wrapped into
+         * a valid XML header and a new root tag which contains missing namespace
+         * definitions so the ixml parser understands it.
+         *
+         * If you know of a better workaround, please oh please fix it */
+        const char* psz_xml_result_fmt = "<?xml version=\"1.0\" ?>"
+            "<Result xmlns:sec=\"urn:samsung:metadata:2009\">%s</Result>";
+
+        char* psz_xml_result_string = NULL;
+        if( -1 == asprintf( &psz_xml_result_string,
+                             psz_xml_result_fmt,
+                             psz_raw_didl) )
+            return NULL;
+
+        p_result_doc = ixmlParseBuffer( psz_xml_result_string );
+        free( psz_xml_result_string );
+    }
 
     if( !p_result_doc )
         return NULL;



More information about the vlc-commits mailing list