From aca5728ab2a86e5753afdafacf5180984a73b409 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 18 May 2020 02:37:03 +0100 Subject: [PATCH] try to work around missing BOM --- .../CoalescedSceneObjectsSerializer.cs | 96 +++++++++---------- .../Serialization/SceneObjectSerializer.cs | 7 +- 2 files changed, 51 insertions(+), 52 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs index 4a32b22793..e57e0bb173 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs @@ -30,6 +30,7 @@ using System.Collections.Generic; using System.Drawing; using System.IO; using System.Reflection; +using System.Text; using System.Xml; using log4net; using OpenMetaverse; @@ -129,20 +130,17 @@ namespace OpenSim.Region.Framework.Scenes.Serialization try { // Quickly check if this is a coalesced object, without fully parsing the XML - using (StringReader sr = new StringReader(xml)) + using (XmlTextReader reader = new XmlTextReader(new StringReader(xml))) { - using (XmlTextReader reader = new XmlTextReader(sr)) + reader.MoveToContent(); // skip possible xml declaration + + if (reader.Name != "CoalescedObject") { - reader.MoveToContent(); // skip possible xml declaration + // m_log.DebugFormat( + // "[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() root element was {0} so returning false", + // reader.Name); - if (reader.Name != "CoalescedObject") - { - // m_log.DebugFormat( - // "[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() root element was {0} so returning false", - // reader.Name); - - return false; - } + return false; } } @@ -199,49 +197,49 @@ namespace OpenSim.Region.Framework.Scenes.Serialization if (data[len - 1] == 0) --len; // Quickly check if this is a coalesced object, without fully parsing the XML - using (MemoryStream ms = new MemoryStream(data, 0, len, false)) + MemoryStream ms = new MemoryStream(data, 0, len, false); + StreamReader sr = new StreamReader(ms, Encoding.UTF8); + using (XmlTextReader reader = new XmlTextReader(sr)) { - using (XmlTextReader reader = new XmlTextReader(ms)) + reader.MoveToContent(); // skip possible xml declaration + + if (reader.Name != "CoalescedObject") { - reader.MoveToContent(); // skip possible xml declaration - - if (reader.Name != "CoalescedObject") - { - return false; - } - } - - ms.Seek(0, SeekOrigin.Begin); - XmlDocument doc = new XmlDocument(); - doc.Load(ms); - XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject"); - if (e == null) return false; - - coa = new CoalescedSceneObjects(UUID.Zero); - - XmlNodeList groups = e.SelectNodes("SceneObjectGroup"); - int i = 0; - - foreach (XmlNode n in groups) - { - SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(n.OuterXml); - if (so != null) - { - coa.Add(so); - } - else - { - // XXX: Possibly we should fail outright here rather than continuing if a particular component of the - // coalesced object fails to load. - m_log.WarnFormat( - "[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml for component {0} failed. Continuing.", - i); - } - - i++; } } + + XmlDocument doc = new XmlDocument(); + using (ms = new MemoryStream(data, 0, len, false)) + doc.Load(ms); + + XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject"); + if (e == null) + return false; + + coa = new CoalescedSceneObjects(UUID.Zero); + + XmlNodeList groups = e.SelectNodes("SceneObjectGroup"); + int i = 0; + + foreach (XmlNode n in groups) + { + SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(n.OuterXml); + if (so != null) + { + coa.Add(so); + } + else + { + // XXX: Possibly we should fail outright here rather than continuing if a particular component of the + // coalesced object fails to load. + m_log.WarnFormat( + "[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml for component {0} failed. Continuing.", + i); + } + + i++; + } } catch (Exception e) { diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs index d4552b2e4c..ea662e6074 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs @@ -29,8 +29,8 @@ using System; using System.Collections.Generic; using System.Drawing; using System.IO; -using System.Linq; using System.Reflection; +using System.Text; using System.Xml; using log4net; using OpenMetaverse; @@ -86,7 +86,9 @@ namespace OpenSim.Region.Framework.Scenes.Serialization return null; if(data[len -1 ] == 0) --len; - using (MemoryStream ms = new MemoryStream(data,0, len, false)) + + MemoryStream ms = new MemoryStream(data,0, len, false); + using(StreamReader sr = new StreamReader(ms, Encoding.UTF8)) { using (XmlReader reader = XmlReader.Create(ms, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment })) { @@ -97,7 +99,6 @@ namespace OpenSim.Region.Framework.Scenes.Serialization catch (Exception e) { m_log.Error("[SERIALIZER]: Deserialization of xml data failed ", e); - string s = Utils.BytesToString(data); return null; } }