diff options
| author | Joshua M. Boniface <joshua@boniface.me> | 2019-02-19 21:31:16 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-19 21:31:16 -0500 |
| commit | 6c6e9ca9f22d4c4bd1175d4abae846d09d2f074d (patch) | |
| tree | b00da54bdf21dcb9fb205ffbb75d6d22cab28960 /Emby.Dlna | |
| parent | 89d4ce309dfd63546d032e19bb1c186af7871af6 (diff) | |
| parent | a82303ccd146ce3093ccb29115aacc26b44bfbc4 (diff) | |
Merge pull request #889 from Bond-009/xmlex
Fix uncaught xml error
Diffstat (limited to 'Emby.Dlna')
| -rw-r--r-- | Emby.Dlna/PlayTo/Device.cs | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/Emby.Dlna/PlayTo/Device.cs b/Emby.Dlna/PlayTo/Device.cs index 037cdd8aa..b62c5e1d4 100644 --- a/Emby.Dlna/PlayTo/Device.cs +++ b/Emby.Dlna/PlayTo/Device.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; +using System.Xml; using System.Xml.Linq; using Emby.Dlna.Common; using Emby.Dlna.Server; @@ -733,26 +734,21 @@ namespace Emby.Dlna.PlayTo return (true, null); } - XElement uPnpResponse; + XElement uPnpResponse = null; - // Handle different variations sent back by devices try { - uPnpResponse = XElement.Parse(trackString); + uPnpResponse = ParseResponse(trackString); } - catch (Exception) + catch (Exception ex) { - // first try to add a root node with a dlna namesapce - try - { - uPnpResponse = XElement.Parse("<data xmlns:dlna=\"urn:schemas-dlna-org:device-1-0\">" + trackString + "</data>"); - uPnpResponse = uPnpResponse.Descendants().First(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Unable to parse xml {0}", trackString); - return (true, null); - } + _logger.LogError(ex, "Uncaught exception while parsing xml"); + } + + if (uPnpResponse == null) + { + _logger.LogError("Failed to parse xml: \n {Xml}", trackString); + return (true, null); } var e = uPnpResponse.Element(uPnpNamespaces.items); @@ -762,6 +758,43 @@ namespace Emby.Dlna.PlayTo return (true, uTrack); } + private XElement ParseResponse(string xml) + { + // Handle different variations sent back by devices + try + { + return XElement.Parse(xml); + } + catch (XmlException) + { + + } + + // first try to add a root node with a dlna namesapce + try + { + return XElement.Parse("<data xmlns:dlna=\"urn:schemas-dlna-org:device-1-0\">" + xml + "</data>") + .Descendants() + .First(); + } + catch (XmlException) + { + + } + + // some devices send back invalid xml + try + { + return XElement.Parse(xml.Replace("&", "&")); + } + catch (XmlException) + { + + } + + return null; + } + private static uBaseObject CreateUBaseObject(XElement container, string trackUri) { if (container == null) |
