From 134f86e8d5c414409631b25b8c6f0ee45fbd8631 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Thu, 3 Nov 2016 21:44:39 +1000 Subject: Initial update to OpenSim 0.8.2.1 source code. --- .../External/ExternalRepresentationUtils.cs | 267 +++++++++++++++++++-- .../Serialization/External/LandDataSerializer.cs | 28 +-- .../External/UserInventoryItemSerializer.cs | 49 ++-- 3 files changed, 290 insertions(+), 54 deletions(-) (limited to 'OpenSim/Framework/Serialization/External') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index c56f213..55640ac 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) Contributors, http://opensimulator.org/ * See CONTRIBUTORS.TXT for a full list of copyright holders. * @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Reflection; using System.Xml; @@ -47,20 +48,20 @@ namespace OpenSim.Framework.Serialization.External /// Populate a node with data read from xml using a dictinoary of processors /// /// - /// /param> + /// /// /// true on successful, false if there were any processing failures public static bool ExecuteReadProcessors( - NodeType nodeToFill, Dictionary> processors, XmlTextReader xtr) + NodeType nodeToFill, Dictionary> processors, XmlReader xtr) { return ExecuteReadProcessors( nodeToFill, processors, xtr, - (o, name, e) - => m_log.DebugFormat( - "[ExternalRepresentationUtils]: Exception while parsing element {0}, continuing. Exception {1}{2}", - name, e.Message, e.StackTrace)); + (o, nodeName, e) => { + m_log.Debug(string.Format("[ExternalRepresentationUtils]: Error while parsing element {0} ", + nodeName), e); + }); } /// @@ -75,23 +76,27 @@ namespace OpenSim.Framework.Serialization.External /// true on successful, false if there were any processing failures public static bool ExecuteReadProcessors( NodeType nodeToFill, - Dictionary> processors, - XmlTextReader xtr, + Dictionary> processors, + XmlReader xtr, Action parseExceptionAction) { bool errors = false; + int numErrors = 0; + + Stopwatch timer = new Stopwatch(); + timer.Start(); string nodeName = string.Empty; while (xtr.NodeType != XmlNodeType.EndElement) { nodeName = xtr.Name; -// m_log.DebugFormat("[ExternalRepresentationUtils]: Processing: {0}", nodeName); + // m_log.DebugFormat("[ExternalRepresentationUtils]: Processing node: {0}", nodeName); - Action p = null; + Action p = null; if (processors.TryGetValue(xtr.Name, out p)) { -// m_log.DebugFormat("[ExternalRepresentationUtils]: Found {0} processor, nodeName); + // m_log.DebugFormat("[ExternalRepresentationUtils]: Found processor for {0}", nodeName); try { @@ -101,6 +106,18 @@ namespace OpenSim.Framework.Serialization.External { errors = true; parseExceptionAction(nodeToFill, nodeName, e); + + if (xtr.EOF) + { + m_log.Debug("[ExternalRepresentationUtils]: Aborting ExecuteReadProcessors due to unexpected end of XML"); + break; + } + + if (++numErrors == 10) + { + m_log.Debug("[ExternalRepresentationUtils]: Aborting ExecuteReadProcessors due to too many parsing errors"); + break; + } if (xtr.NodeType == XmlNodeType.EndElement) xtr.Read(); @@ -108,9 +125,16 @@ namespace OpenSim.Framework.Serialization.External } else { - // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName); + // m_log.DebugFormat("[ExternalRepresentationUtils]: found unknown element \"{0}\"", nodeName); xtr.ReadOuterXml(); // ignore } + + if (timer.Elapsed.TotalSeconds >= 60) + { + m_log.Debug("[ExternalRepresentationUtils]: Aborting ExecuteReadProcessors due to timeout"); + errors = true; + break; + } } return errors; @@ -125,7 +149,8 @@ namespace OpenSim.Framework.Serialization.External /// The service for retrieving user account information /// The scope of the user account information (Grid ID) /// The SceneObjectPart represented in XML2 - public static string RewriteSOP(string xml, string homeURL, IUserAccountService userService, UUID scopeID) + [Obsolete("This method is deprecated. Use RewriteSOP instead.")] + public static string RewriteSOP_Old(string xml, string homeURL, IUserAccountService userService, UUID scopeID) { if (xml == string.Empty || homeURL == string.Empty || userService == null) return xml; @@ -161,7 +186,7 @@ namespace OpenSim.Framework.Serialization.External if (!hasCreatorData && creator != null) { XmlElement creatorData = doc.CreateElement("CreatorData"); - creatorData.InnerText = homeURL + ";" + creator.FirstName + " " + creator.LastName; + creatorData.InnerText = CalcCreatorData(homeURL, creator.FirstName + " " + creator.LastName); sop.AppendChild(creatorData); } } @@ -172,5 +197,215 @@ namespace OpenSim.Framework.Serialization.External return wr.ToString(); } } + + /// + /// Takes a XML representation of a SceneObjectPart and returns another XML representation + /// with creator data added to it. + /// + /// The SceneObjectPart represented in XML2 + /// An identifier for the component that's calling this function + /// The URL of the user agents service (home) for the creator + /// The service for retrieving user account information + /// The scope of the user account information (Grid ID) + /// The SceneObjectPart represented in XML2 + public static string RewriteSOP(string xmlData, string sceneName, string homeURL, IUserAccountService userService, UUID scopeID) + { + // Console.WriteLine("Input XML [{0}]", xmlData); + if (xmlData == string.Empty || homeURL == string.Empty || userService == null) + return xmlData; + + // Deal with bug + xmlData = ExternalRepresentationUtils.SanitizeXml(xmlData); + + using (StringWriter sw = new StringWriter()) + using (XmlTextWriter writer = new XmlTextWriter(sw)) + using (XmlTextReader wrappedReader = new XmlTextReader(xmlData, XmlNodeType.Element, null)) + using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment })) + { + TransformXml(reader, writer, sceneName, homeURL, userService, scopeID); + + // Console.WriteLine("Output: [{0}]", sw.ToString()); + + return sw.ToString(); + } + } + + protected static void TransformXml(XmlReader reader, XmlWriter writer, string sceneName, string homeURI, IUserAccountService userAccountService, UUID scopeID) + { + // m_log.DebugFormat("[HG ASSET MAPPER]: Transforming XML"); + + int sopDepth = -1; + UserAccount creator = null; + bool hasCreatorData = false; + + while (reader.Read()) + { + // Console.WriteLine("Depth: {0}, name {1}", reader.Depth, reader.Name); + + switch (reader.NodeType) + { + case XmlNodeType.Attribute: + // Console.WriteLine("FOUND ATTRIBUTE {0}", reader.Name); + writer.WriteAttributeString(reader.Name, reader.Value); + break; + + case XmlNodeType.CDATA: + writer.WriteCData(reader.Value); + break; + + case XmlNodeType.Comment: + writer.WriteComment(reader.Value); + break; + + case XmlNodeType.DocumentType: + writer.WriteDocType(reader.Name, reader.Value, null, null); + break; + + case XmlNodeType.Element: + // m_log.DebugFormat("Depth {0} at element {1}", reader.Depth, reader.Name); + + writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); + + if (reader.HasAttributes) + { + while (reader.MoveToNextAttribute()) + writer.WriteAttributeString(reader.Name, reader.Value); + + reader.MoveToElement(); + } + + if (reader.LocalName == "SceneObjectPart") + { + if (sopDepth < 0) + { + sopDepth = reader.Depth; + // m_log.DebugFormat("[HG ASSET MAPPER]: Set sopDepth to {0}", sopDepth); + } + } + else + { + if (sopDepth >= 0 && reader.Depth == sopDepth + 1) + { + if (reader.Name == "CreatorID") + { + reader.Read(); + if (reader.NodeType == XmlNodeType.Element && reader.Name == "Guid" || reader.Name == "UUID") + { + reader.Read(); + + if (reader.NodeType == XmlNodeType.Text) + { + UUID uuid = UUID.Zero; + UUID.TryParse(reader.Value, out uuid); + creator = userAccountService.GetUserAccount(scopeID, uuid); + writer.WriteElementString("UUID", reader.Value); + reader.Read(); + } + else + { + // If we unexpected run across mixed content in this node, still carry on + // transforming the subtree (this replicates earlier behaviour). + TransformXml(reader, writer, sceneName, homeURI, userAccountService, scopeID); + } + } + else + { + // If we unexpected run across mixed content in this node, still carry on + // transforming the subtree (this replicates earlier behaviour). + TransformXml(reader, writer, sceneName, homeURI, userAccountService, scopeID); + } + } + else if (reader.Name == "CreatorData") + { + reader.Read(); + if (reader.NodeType == XmlNodeType.Text) + { + hasCreatorData = true; + writer.WriteString(reader.Value); + } + else + { + // If we unexpected run across mixed content in this node, still carry on + // transforming the subtree (this replicates earlier behaviour). + TransformXml(reader, writer, sceneName, homeURI, userAccountService, scopeID); + } + } + } + } + + if (reader.IsEmptyElement) + { + // m_log.DebugFormat("[HG ASSET MAPPER]: Writing end for empty element {0}", reader.Name); + writer.WriteEndElement(); + } + + break; + + case XmlNodeType.EndElement: + // m_log.DebugFormat("Depth {0} at EndElement", reader.Depth); + if (sopDepth == reader.Depth) + { + if (!hasCreatorData && creator != null) + writer.WriteElementString(reader.Prefix, "CreatorData", reader.NamespaceURI, string.Format("{0};{1} {2}", homeURI, creator.FirstName, creator.LastName)); + + // m_log.DebugFormat("[HG ASSET MAPPER]: Reset sopDepth"); + sopDepth = -1; + creator = null; + hasCreatorData = false; + } + writer.WriteEndElement(); + break; + + case XmlNodeType.EntityReference: + writer.WriteEntityRef(reader.Name); + break; + + case XmlNodeType.ProcessingInstruction: + writer.WriteProcessingInstruction(reader.Name, reader.Value); + break; + + case XmlNodeType.Text: + writer.WriteString(reader.Value); + break; + + case XmlNodeType.XmlDeclaration: + // For various reasons, not all serializations have xml declarations (or consistent ones) + // and as it's embedded inside a byte stream we don't need it anyway, so ignore. + break; + + default: + m_log.WarnFormat( + "[HG ASSET MAPPER]: Unrecognized node {0} in asset XML transform in {1}", + reader.NodeType, sceneName); + break; + } + } + } + + public static string CalcCreatorData(string homeURL, string name) + { + return homeURL + ";" + name; + } + + internal static string CalcCreatorData(string homeURL, UUID uuid, string name) + { + return homeURL + "/" + uuid + ";" + name; + } + + /// + /// Sanitation for bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8) + /// + /// + /// + public static string SanitizeXml(string xmlData) + { + string fixedData = xmlData; + if (fixedData != null) + // Loop, because it may contain multiple + while (fixedData.Contains("xmlns:xmlns:")) + fixedData = fixedData.Replace("xmlns:xmlns:", "xmlns:"); + return fixedData; + } + } -} \ No newline at end of file +} diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index 709b516..e42d56f 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -44,11 +44,11 @@ namespace OpenSim.Framework.Serialization.External { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private static Dictionary> m_ldProcessors - = new Dictionary>(); + private static Dictionary> m_ldProcessors + = new Dictionary>(); - private static Dictionary> m_laeProcessors - = new Dictionary>(); + private static Dictionary> m_laeProcessors + = new Dictionary>(); static LandDataSerializer() { @@ -134,7 +134,7 @@ namespace OpenSim.Framework.Serialization.External "AccessList", (lae, xtr) => lae.Flags = (AccessList)Convert.ToUInt32(xtr.ReadElementString("AccessList"))); } - public static void ProcessParcelAccessList(LandData ld, XmlTextReader xtr) + public static void ProcessParcelAccessList(LandData ld, XmlReader xtr) { if (!xtr.IsEmptyElement) { @@ -213,8 +213,13 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("ClaimDate", Convert.ToString(landData.ClaimDate)); xtw.WriteElementString("ClaimPrice", Convert.ToString(landData.ClaimPrice)); xtw.WriteElementString("GlobalID", landData.GlobalID.ToString()); - xtw.WriteElementString("GroupID", landData.GroupID.ToString()); - xtw.WriteElementString("IsGroupOwned", Convert.ToString(landData.IsGroupOwned)); + + UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : landData.GroupID; + xtw.WriteElementString("GroupID", groupID.ToString()); + + bool isGroupOwned = options.ContainsKey("wipe-owners") ? false : landData.IsGroupOwned; + xtw.WriteElementString("IsGroupOwned", Convert.ToString(isGroupOwned)); + xtw.WriteElementString("Bitmap", Convert.ToBase64String(landData.Bitmap)); xtw.WriteElementString("Description", landData.Description); xtw.WriteElementString("Flags", Convert.ToString((uint)landData.Flags)); @@ -227,13 +232,8 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("MediaURL", landData.MediaURL); xtw.WriteElementString("MusicURL", landData.MusicURL); - UUID ownerIdToWrite; - if (options != null && options.ContainsKey("wipe-owners")) - ownerIdToWrite = UUID.Zero; - else - ownerIdToWrite = landData.OwnerID; - - xtw.WriteElementString("OwnerID", ownerIdToWrite.ToString()); + UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : landData.OwnerID; + xtw.WriteElementString("OwnerID", ownerID.ToString()); xtw.WriteStartElement("ParcelAccessList"); foreach (LandAccessEntry pal in landData.ParcelAccessList) diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index 88f9581..994cede 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -46,8 +46,8 @@ namespace OpenSim.Framework.Serialization.External { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private static Dictionary> m_InventoryItemXmlProcessors - = new Dictionary>(); + private static Dictionary> m_InventoryItemXmlProcessors + = new Dictionary>(); #region InventoryItemBase Processor initialization static UserInventoryItemSerializer() @@ -76,103 +76,103 @@ namespace OpenSim.Framework.Serialization.External #endregion #region InventoryItemBase Processors - private static void ProcessName(InventoryItemBase item, XmlTextReader reader) + private static void ProcessName(InventoryItemBase item, XmlReader reader) { item.Name = reader.ReadElementContentAsString("Name", String.Empty); } - private static void ProcessID(InventoryItemBase item, XmlTextReader reader) + private static void ProcessID(InventoryItemBase item, XmlReader reader) { item.ID = Util.ReadUUID(reader, "ID"); } - private static void ProcessInvType(InventoryItemBase item, XmlTextReader reader) + private static void ProcessInvType(InventoryItemBase item, XmlReader reader) { item.InvType = reader.ReadElementContentAsInt("InvType", String.Empty); } - private static void ProcessCreatorUUID(InventoryItemBase item, XmlTextReader reader) + private static void ProcessCreatorUUID(InventoryItemBase item, XmlReader reader) { item.CreatorId = reader.ReadElementContentAsString("CreatorUUID", String.Empty); } - private static void ProcessCreatorID(InventoryItemBase item, XmlTextReader reader) + private static void ProcessCreatorID(InventoryItemBase item, XmlReader reader) { // when it exists, this overrides the previous item.CreatorId = reader.ReadElementContentAsString("CreatorID", String.Empty); } - private static void ProcessCreationDate(InventoryItemBase item, XmlTextReader reader) + private static void ProcessCreationDate(InventoryItemBase item, XmlReader reader) { item.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty); } - private static void ProcessOwner(InventoryItemBase item, XmlTextReader reader) + private static void ProcessOwner(InventoryItemBase item, XmlReader reader) { item.Owner = Util.ReadUUID(reader, "Owner"); } - private static void ProcessDescription(InventoryItemBase item, XmlTextReader reader) + private static void ProcessDescription(InventoryItemBase item, XmlReader reader) { item.Description = reader.ReadElementContentAsString("Description", String.Empty); } - private static void ProcessAssetType(InventoryItemBase item, XmlTextReader reader) + private static void ProcessAssetType(InventoryItemBase item, XmlReader reader) { item.AssetType = reader.ReadElementContentAsInt("AssetType", String.Empty); } - private static void ProcessAssetID(InventoryItemBase item, XmlTextReader reader) + private static void ProcessAssetID(InventoryItemBase item, XmlReader reader) { item.AssetID = Util.ReadUUID(reader, "AssetID"); } - private static void ProcessSaleType(InventoryItemBase item, XmlTextReader reader) + private static void ProcessSaleType(InventoryItemBase item, XmlReader reader) { item.SaleType = (byte)reader.ReadElementContentAsInt("SaleType", String.Empty); } - private static void ProcessSalePrice(InventoryItemBase item, XmlTextReader reader) + private static void ProcessSalePrice(InventoryItemBase item, XmlReader reader) { item.SalePrice = reader.ReadElementContentAsInt("SalePrice", String.Empty); } - private static void ProcessBasePermissions(InventoryItemBase item, XmlTextReader reader) + private static void ProcessBasePermissions(InventoryItemBase item, XmlReader reader) { item.BasePermissions = (uint)reader.ReadElementContentAsInt("BasePermissions", String.Empty); } - private static void ProcessCurrentPermissions(InventoryItemBase item, XmlTextReader reader) + private static void ProcessCurrentPermissions(InventoryItemBase item, XmlReader reader) { item.CurrentPermissions = (uint)reader.ReadElementContentAsInt("CurrentPermissions", String.Empty); } - private static void ProcessEveryOnePermissions(InventoryItemBase item, XmlTextReader reader) + private static void ProcessEveryOnePermissions(InventoryItemBase item, XmlReader reader) { item.EveryOnePermissions = (uint)reader.ReadElementContentAsInt("EveryOnePermissions", String.Empty); } - private static void ProcessNextPermissions(InventoryItemBase item, XmlTextReader reader) + private static void ProcessNextPermissions(InventoryItemBase item, XmlReader reader) { item.NextPermissions = (uint)reader.ReadElementContentAsInt("NextPermissions", String.Empty); } - private static void ProcessFlags(InventoryItemBase item, XmlTextReader reader) + private static void ProcessFlags(InventoryItemBase item, XmlReader reader) { item.Flags = (uint)reader.ReadElementContentAsInt("Flags", String.Empty); } - private static void ProcessGroupID(InventoryItemBase item, XmlTextReader reader) + private static void ProcessGroupID(InventoryItemBase item, XmlReader reader) { item.GroupID = Util.ReadUUID(reader, "GroupID"); } - private static void ProcessGroupOwned(InventoryItemBase item, XmlTextReader reader) + private static void ProcessGroupOwned(InventoryItemBase item, XmlReader reader) { item.GroupOwned = Util.ReadBoolean(reader); } - private static void ProcessCreatorData(InventoryItemBase item, XmlTextReader reader) + private static void ProcessCreatorData(InventoryItemBase item, XmlReader reader) { item.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty); } @@ -277,7 +277,7 @@ namespace OpenSim.Framework.Serialization.External writer.WriteStartElement("GroupOwned"); writer.WriteString(inventoryItem.GroupOwned.ToString()); writer.WriteEndElement(); - if (options.ContainsKey("creators") && inventoryItem.CreatorData != null && inventoryItem.CreatorData != string.Empty) + if (options.ContainsKey("creators") && !string.IsNullOrEmpty(inventoryItem.CreatorData)) writer.WriteElementString("CreatorData", inventoryItem.CreatorData); else if (options.ContainsKey("home")) { @@ -286,7 +286,8 @@ namespace OpenSim.Framework.Serialization.External UserAccount account = userAccountService.GetUserAccount(UUID.Zero, inventoryItem.CreatorIdAsUuid); if (account != null) { - writer.WriteElementString("CreatorData", (string)options["home"] + "/" + inventoryItem.CreatorIdAsUuid + ";" + account.FirstName + " " + account.LastName); + string creatorData = ExternalRepresentationUtils.CalcCreatorData((string)options["home"], inventoryItem.CreatorIdAsUuid, account.FirstName + " " + account.LastName); + writer.WriteElementString("CreatorData", creatorData); } writer.WriteElementString("CreatorID", inventoryItem.CreatorId); } -- cgit v1.1