[vlc-commits] upnp sd: work around missing XML namespaces in DIDL documents
Mirsal Ennaime
git at videolan.org
Fri Dec 28 00:32:07 CET 2012
vlc | branch: master | Mirsal Ennaime <mirsal at videolan.org> | Wed Dec 26 06:59:00 2012 +0100| [5aa6adb6b282d072bbf68bd0c6f50836a0e09c5b] | committer: Mirsal Ennaime
upnp sd: work around missing XML namespaces in DIDL documents
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5aa6adb6b282d072bbf68bd0c6f50836a0e09c5b
---
modules/services_discovery/upnp.cpp | 38 +++++++++++++++++++++++++++++++----
1 file changed, 34 insertions(+), 4 deletions(-)
diff --git a/modules/services_discovery/upnp.cpp b/modules/services_discovery/upnp.cpp
index e934956..66223fa 100644
--- a/modules/services_discovery/upnp.cpp
+++ b/modules/services_discovery/upnp.cpp
@@ -259,14 +259,44 @@ IXML_Document* parseBrowseResult( IXML_Document* p_doc )
{
assert( p_doc );
- const char* psz_result_string = xml_getChildElementValue( p_doc, "Result" );
+ /* 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;
- if( !psz_result_string )
+
+ IXML_Document* p_result_doc = ixmlParseBuffer( psz_xml_result_string );
+ free( psz_xml_result_string );
+
+ if( !p_result_doc )
return NULL;
- IXML_Document* p_browse_doc = ixmlParseBuffer( psz_result_string );
+ IXML_NodeList *p_elems = ixmlDocument_getElementsByTagName( p_result_doc,
+ "DIDL-Lite" );
+
+ IXML_Node *p_node = ixmlNodeList_item( p_elems, 0 );
+ ixmlNodeList_free( p_elems );
- return p_browse_doc;
+ return (IXML_Document*)p_node;
}
/*
More information about the vlc-commits
mailing list