From f28886e26d32eaf97180d91dcd42fa045990bdd0 Mon Sep 17 00:00:00 2001 From: Mike Mazur Date: Mon, 16 Mar 2009 00:12:25 +0000 Subject: Rename OpenSim.Framework.Archive to OpenSim.Framework.Serialization Update using statements and prebuild.xml. Also trim trailing whitespace. --- .../Framework/Serialization/ArchiveConstants.cs | 133 +++++++++++++ .../Framework/Serialization/TarArchiveReader.cs | 218 +++++++++++++++++++++ .../Framework/Serialization/TarArchiveWriter.cs | 217 ++++++++++++++++++++ 3 files changed, 568 insertions(+) create mode 100644 OpenSim/Framework/Serialization/ArchiveConstants.cs create mode 100644 OpenSim/Framework/Serialization/TarArchiveReader.cs create mode 100644 OpenSim/Framework/Serialization/TarArchiveWriter.cs (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs new file mode 100644 index 0000000..d0a0985 --- /dev/null +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -0,0 +1,133 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System.Collections.Generic; +using OpenMetaverse; + +namespace OpenSim.Framework.Serialization +{ + /// + /// Constants for the archiving module + /// + public class ArchiveConstants + { + /// + /// The location of the archive control file + /// + public static readonly string CONTROL_FILE_PATH = "archive.xml"; + + /// + /// Path for the assets held in an archive + /// + public static readonly string ASSETS_PATH = "assets/"; + + /// + /// Path for the inventory data + /// + public static readonly string INVENTORY_PATH = "inventory/"; + + /// + /// Path for the prims file + /// + public static readonly string OBJECTS_PATH = "objects/"; + + /// + /// Path for terrains. Technically these may be assets, but I think it's quite nice to split them out. + /// + public static readonly string TERRAINS_PATH = "terrains/"; + + /// + /// Path for region settings. + /// + public static readonly string SETTINGS_PATH = "settings/"; + + /// + /// The character the separates the uuid from extension information in an archived asset filename + /// + public static readonly string ASSET_EXTENSION_SEPARATOR = "_"; + + /// + /// Used to separate components in an inventory node name + /// + public static readonly string INVENTORY_NODE_NAME_COMPONENT_SEPARATOR = "__"; + + /// + /// Extensions used for asset types in the archive + /// + public static readonly IDictionary ASSET_TYPE_TO_EXTENSION = new Dictionary(); + public static readonly IDictionary EXTENSION_TO_ASSET_TYPE = new Dictionary(); + + static ArchiveConstants() + { + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Animation] = ASSET_EXTENSION_SEPARATOR + "animation.bvh"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Bodypart] = ASSET_EXTENSION_SEPARATOR + "bodypart.txt"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.CallingCard] = ASSET_EXTENSION_SEPARATOR + "callingcard.txt"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Clothing] = ASSET_EXTENSION_SEPARATOR + "clothing.txt"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Folder] = ASSET_EXTENSION_SEPARATOR + "folder.txt"; // Not sure if we'll ever see this + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Gesture] = ASSET_EXTENSION_SEPARATOR + "gesture.txt"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.ImageJPEG] = ASSET_EXTENSION_SEPARATOR + "image.jpg"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.ImageTGA] = ASSET_EXTENSION_SEPARATOR + "image.tga"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Landmark] = ASSET_EXTENSION_SEPARATOR + "landmark.txt"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LostAndFoundFolder] = ASSET_EXTENSION_SEPARATOR + "lostandfoundfolder.txt"; // Not sure if we'll ever see this + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LSLBytecode] = ASSET_EXTENSION_SEPARATOR + "bytecode.lso"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LSLText] = ASSET_EXTENSION_SEPARATOR + "script.lsl"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Notecard] = ASSET_EXTENSION_SEPARATOR + "notecard.txt"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Object] = ASSET_EXTENSION_SEPARATOR + "object.xml"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.RootFolder] = ASSET_EXTENSION_SEPARATOR + "rootfolder.txt"; // Not sure if we'll ever see this + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Simstate] = ASSET_EXTENSION_SEPARATOR + "simstate.bin"; // Not sure if we'll ever see this + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SnapshotFolder] = ASSET_EXTENSION_SEPARATOR + "snapshotfolder.txt"; // Not sure if we'll ever see this + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Sound] = ASSET_EXTENSION_SEPARATOR + "sound.ogg"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SoundWAV] = ASSET_EXTENSION_SEPARATOR + "sound.wav"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Texture] = ASSET_EXTENSION_SEPARATOR + "texture.jp2"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TextureTGA] = ASSET_EXTENSION_SEPARATOR + "texture.tga"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TrashFolder] = ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"; // Not sure if we'll ever see this + + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "animation.bvh"] = (sbyte)AssetType.Animation; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "bodypart.txt"] = (sbyte)AssetType.Bodypart; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "callingcard.txt"] = (sbyte)AssetType.CallingCard; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "clothing.txt"] = (sbyte)AssetType.Clothing; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "folder.txt"] = (sbyte)AssetType.Folder; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "gesture.txt"] = (sbyte)AssetType.Gesture; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "image.jpg"] = (sbyte)AssetType.ImageJPEG; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "image.tga"] = (sbyte)AssetType.ImageTGA; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "landmark.txt"] = (sbyte)AssetType.Landmark; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "lostandfoundfolder.txt"] = (sbyte)AssetType.LostAndFoundFolder; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "bytecode.lso"] = (sbyte)AssetType.LSLBytecode; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "script.lsl"] = (sbyte)AssetType.LSLText; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "notecard.txt"] = (sbyte)AssetType.Notecard; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "object.xml"] = (sbyte)AssetType.Object; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "rootfolder.txt"] = (sbyte)AssetType.RootFolder; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "simstate.bin"] = (sbyte)AssetType.Simstate; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "snapshotfolder.txt"] = (sbyte)AssetType.SnapshotFolder; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "sound.ogg"] = (sbyte)AssetType.Sound; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "sound.wav"] = (sbyte)AssetType.SoundWAV; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.jp2"] = (sbyte)AssetType.Texture; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.tga"] = (sbyte)AssetType.TextureTGA; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"] = (sbyte)AssetType.TrashFolder; + } + } +} diff --git a/OpenSim/Framework/Serialization/TarArchiveReader.cs b/OpenSim/Framework/Serialization/TarArchiveReader.cs new file mode 100644 index 0000000..da5703f --- /dev/null +++ b/OpenSim/Framework/Serialization/TarArchiveReader.cs @@ -0,0 +1,218 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.IO; +using System.Reflection; +using System.Text; +using log4net; + +namespace OpenSim.Framework.Serialization +{ + /// + /// Temporary code to do the bare minimum required to read a tar archive for our purposes + /// + public class TarArchiveReader + { + //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + public enum TarEntryType + { + TYPE_UNKNOWN = 0, + TYPE_NORMAL_FILE = 1, + TYPE_HARD_LINK = 2, + TYPE_SYMBOLIC_LINK = 3, + TYPE_CHAR_SPECIAL = 4, + TYPE_BLOCK_SPECIAL = 5, + TYPE_DIRECTORY = 6, + TYPE_FIFO = 7, + TYPE_CONTIGUOUS_FILE = 8, + } + + protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); + + /// + /// Binary reader for the underlying stream + /// + protected BinaryReader m_br; + + /// + /// Used to trim off null chars + /// + protected char[] m_nullCharArray = new char[] { '\0' }; + + /// + /// Generate a tar reader which reads from the given stream. + /// + /// + public TarArchiveReader(Stream s) + { + m_br = new BinaryReader(s); + } + + /// + /// Read the next entry in the tar file. + /// + /// + /// the data for the entry. Returns null if there are no more entries + public byte[] ReadEntry(out string filePath, out TarEntryType entryType) + { + filePath = String.Empty; + entryType = TarEntryType.TYPE_UNKNOWN; + TarHeader header = ReadHeader(); + + if (null == header) + return null; + + entryType = header.EntryType; + filePath = header.FilePath; + return ReadData(header.FileSize); + } + + /// + /// Read the next 512 byte chunk of data as a tar header. + /// + /// A tar header struct. null if we have reached the end of the archive. + protected TarHeader ReadHeader() + { + byte[] header = m_br.ReadBytes(512); + + // If we've reached the end of the archive we'll be in null block territory, which means + // the next byte will be 0 + if (header[0] == 0) + return null; + + TarHeader tarHeader = new TarHeader(); + + // If we're looking at a GNU tar long link then extract the long name and pull up the next header + if (header[156] == (byte)'L') + { + int longNameLength = ConvertOctalBytesToDecimal(header, 124, 11); + tarHeader.FilePath = m_asciiEncoding.GetString(ReadData(longNameLength)); + //m_log.DebugFormat("[TAR ARCHIVE READER]: Got long file name {0}", tarHeader.FilePath); + header = m_br.ReadBytes(512); + } + else + { + tarHeader.FilePath = m_asciiEncoding.GetString(header, 0, 100); + tarHeader.FilePath = tarHeader.FilePath.Trim(m_nullCharArray); + //m_log.DebugFormat("[TAR ARCHIVE READER]: Got short file name {0}", tarHeader.FilePath); + } + + tarHeader.FileSize = ConvertOctalBytesToDecimal(header, 124, 11); + + switch (header[156]) + { + case 0: + tarHeader.EntryType = TarEntryType.TYPE_NORMAL_FILE; + break; + case (byte)'0': + tarHeader.EntryType = TarEntryType.TYPE_NORMAL_FILE; + break; + case (byte)'1': + tarHeader.EntryType = TarEntryType.TYPE_HARD_LINK; + break; + case (byte)'2': + tarHeader.EntryType = TarEntryType.TYPE_SYMBOLIC_LINK; + break; + case (byte)'3': + tarHeader.EntryType = TarEntryType.TYPE_CHAR_SPECIAL; + break; + case (byte)'4': + tarHeader.EntryType = TarEntryType.TYPE_BLOCK_SPECIAL; + break; + case (byte)'5': + tarHeader.EntryType = TarEntryType.TYPE_DIRECTORY; + break; + case (byte)'6': + tarHeader.EntryType = TarEntryType.TYPE_FIFO; + break; + case (byte)'7': + tarHeader.EntryType = TarEntryType.TYPE_CONTIGUOUS_FILE; + break; + } + + return tarHeader; + } + + /// + /// Read data following a header + /// + /// + /// + protected byte[] ReadData(int fileSize) + { + byte[] data = m_br.ReadBytes(fileSize); + + //m_log.DebugFormat("[TAR ARCHIVE READER]: fileSize {0}", fileSize); + + // Read the rest of the empty padding in the 512 byte block + if (fileSize % 512 != 0) + { + int paddingLeft = 512 - (fileSize % 512); + + //m_log.DebugFormat("[TAR ARCHIVE READER]: Reading {0} padding bytes", paddingLeft); + + m_br.ReadBytes(paddingLeft); + } + + return data; + } + + public void Close() + { + m_br.Close(); + } + + /// + /// Convert octal bytes to a decimal representation + /// + /// + /// + public static int ConvertOctalBytesToDecimal(byte[] bytes, int startIndex, int count) + { + string oString = m_asciiEncoding.GetString(bytes, startIndex, count); + + int d = 0; + + foreach (char c in oString) + { + d <<= 3; + d |= c - '0'; + } + + return d; + } + } + + public class TarHeader + { + public string FilePath; + public int FileSize; + public TarArchiveReader.TarEntryType EntryType; + } +} diff --git a/OpenSim/Framework/Serialization/TarArchiveWriter.cs b/OpenSim/Framework/Serialization/TarArchiveWriter.cs new file mode 100644 index 0000000..d319b0b --- /dev/null +++ b/OpenSim/Framework/Serialization/TarArchiveWriter.cs @@ -0,0 +1,217 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace OpenSim.Framework.Serialization +{ + /// + /// Temporary code to produce a tar archive in tar v7 format + /// + public class TarArchiveWriter + { + //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); + + /// + /// Binary writer for the underlying stream + /// + protected BinaryWriter m_bw; + + public TarArchiveWriter(Stream s) + { + m_bw = new BinaryWriter(s); + } + + /// + /// Write a directory entry to the tar archive. We can only handle one path level right now! + /// + /// + public void WriteDir(string dirName) + { + // Directories are signalled by a final / + if (!dirName.EndsWith("/")) + dirName += "/"; + + WriteFile(dirName, new byte[0]); + } + + /// + /// Write a file to the tar archive + /// + /// + /// + public void WriteFile(string filePath, string data) + { + WriteFile(filePath, m_asciiEncoding.GetBytes(data)); + } + + /// + /// Write a file to the tar archive + /// + /// + /// + public void WriteFile(string filePath, byte[] data) + { + if (filePath.Length > 100) + WriteEntry("././@LongLink", m_asciiEncoding.GetBytes(filePath), 'L'); + + char fileType; + + if (filePath.EndsWith("/")) + { + fileType = '5'; + } + else + { + fileType = '0'; + } + + WriteEntry(filePath, data, fileType); + } + + /// + /// Finish writing the raw tar archive data to a stream. The stream will be closed on completion. + /// + /// Stream to which to write the data + /// + public void Close() + { + //m_log.Debug("[TAR ARCHIVE WRITER]: Writing final consecutive 0 blocks"); + + // Write two consecutive 0 blocks to end the archive + byte[] finalZeroPadding = new byte[1024]; + m_bw.Write(finalZeroPadding); + + m_bw.Flush(); + m_bw.Close(); + } + + public static byte[] ConvertDecimalToPaddedOctalBytes(int d, int padding) + { + string oString = ""; + + while (d > 0) + { + oString = Convert.ToString((byte)'0' + d & 7) + oString; + d >>= 3; + } + + while (oString.Length < padding) + { + oString = "0" + oString; + } + + byte[] oBytes = m_asciiEncoding.GetBytes(oString); + + return oBytes; + } + + /// + /// Write a particular entry + /// + /// + /// + /// + protected void WriteEntry(string filePath, byte[] data, char fileType) + { + byte[] header = new byte[512]; + + // file path field (100) + byte[] nameBytes = m_asciiEncoding.GetBytes(filePath); + int nameSize = (nameBytes.Length >= 100) ? 100 : nameBytes.Length; + Array.Copy(nameBytes, header, nameSize); + + // file mode (8) + byte[] modeBytes = m_asciiEncoding.GetBytes("0000777"); + Array.Copy(modeBytes, 0, header, 100, 7); + + // owner user id (8) + byte[] ownerIdBytes = m_asciiEncoding.GetBytes("0000764"); + Array.Copy(ownerIdBytes, 0, header, 108, 7); + + // group user id (8) + byte[] groupIdBytes = m_asciiEncoding.GetBytes("0000764"); + Array.Copy(groupIdBytes, 0, header, 116, 7); + + // file size in bytes (12) + int fileSize = data.Length; + //m_log.DebugFormat("[TAR ARCHIVE WRITER]: File size of {0} is {1}", filePath, fileSize); + + byte[] fileSizeBytes = ConvertDecimalToPaddedOctalBytes(fileSize, 11); + + Array.Copy(fileSizeBytes, 0, header, 124, 11); + + // last modification time (12) + byte[] lastModTimeBytes = m_asciiEncoding.GetBytes("11017037332"); + Array.Copy(lastModTimeBytes, 0, header, 136, 11); + + // entry type indicator (1) + header[156] = m_asciiEncoding.GetBytes(new char[] { fileType })[0]; + + Array.Copy(m_asciiEncoding.GetBytes("0000000"), 0, header, 329, 7); + Array.Copy(m_asciiEncoding.GetBytes("0000000"), 0, header, 337, 7); + + // check sum for header block (8) [calculated last] + Array.Copy(m_asciiEncoding.GetBytes(" "), 0, header, 148, 8); + + int checksum = 0; + foreach (byte b in header) + { + checksum += b; + } + + //m_log.DebugFormat("[TAR ARCHIVE WRITER]: Decimal header checksum is {0}", checksum); + + byte[] checkSumBytes = ConvertDecimalToPaddedOctalBytes(checksum, 6); + + Array.Copy(checkSumBytes, 0, header, 148, 6); + + header[154] = 0; + + // Write out header + m_bw.Write(header); + + // Write out data + m_bw.Write(data); + + if (data.Length % 512 != 0) + { + int paddingRequired = 512 - (data.Length % 512); + + //m_log.DebugFormat("[TAR ARCHIVE WRITER]: Padding data with {0} bytes", paddingRequired); + + byte[] padding = new byte[paddingRequired]; + m_bw.Write(padding); + } + } + } +} -- cgit v1.1 From 93b26f89336d83f2eab43ced0081d60b1acf2d7f Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 26 Mar 2009 17:25:12 +0000 Subject: * iars: Serialize information about item creators to archive --- .../Framework/Serialization/ArchiveConstants.cs | 41 +++++++------ .../External/UserProfileSerializer.cs | 71 ++++++++++++++++++++++ 2 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 OpenSim/Framework/Serialization/External/UserProfileSerializer.cs (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index d0a0985..8ce7b56 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -35,49 +35,54 @@ namespace OpenSim.Framework.Serialization /// public class ArchiveConstants { - /// + /// /// The location of the archive control file - /// + /// public static readonly string CONTROL_FILE_PATH = "archive.xml"; - /// + /// /// Path for the assets held in an archive - /// + /// public static readonly string ASSETS_PATH = "assets/"; - /// + /// /// Path for the inventory data - /// + /// public static readonly string INVENTORY_PATH = "inventory/"; - /// + /// /// Path for the prims file - /// + /// public static readonly string OBJECTS_PATH = "objects/"; - /// + /// /// Path for terrains. Technically these may be assets, but I think it's quite nice to split them out. - /// + /// public static readonly string TERRAINS_PATH = "terrains/"; - /// + /// /// Path for region settings. - /// + /// public static readonly string SETTINGS_PATH = "settings/"; + + /// + /// Path for user profiles + /// + public const string USERS_PATH = "users/"; - /// + /// /// The character the separates the uuid from extension information in an archived asset filename - /// + /// public static readonly string ASSET_EXTENSION_SEPARATOR = "_"; - /// + /// /// Used to separate components in an inventory node name - /// + /// public static readonly string INVENTORY_NODE_NAME_COMPONENT_SEPARATOR = "__"; - /// + /// /// Extensions used for asset types in the archive - /// + /// public static readonly IDictionary ASSET_TYPE_TO_EXTENSION = new Dictionary(); public static readonly IDictionary EXTENSION_TO_ASSET_TYPE = new Dictionary(); diff --git a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs new file mode 100644 index 0000000..fc76fb6 --- /dev/null +++ b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs @@ -0,0 +1,71 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System.IO; +using System.Xml; +using OpenSim.Framework; + +namespace OpenSim.Framework.Serialization.External +{ + /// + /// Serialize and deserialize region settings for an archive file format. + /// + /// We didn't use automatic .NET serialization since this is really + /// a file format rather than an object serialization. + public class UserProfileSerializer + { + public const int MAJOR_VERSION = 0; + public const int MINOR_VERSION = 1; + + public static string Serialize(UserProfileData profile) + { + StringWriter sw = new StringWriter(); + XmlTextWriter xtw = new XmlTextWriter(sw); + xtw.Formatting = Formatting.Indented; + xtw.WriteStartDocument(); + + xtw.WriteStartElement("user_profile"); + xtw.WriteAttributeString("major_version", MAJOR_VERSION.ToString()); + xtw.WriteAttributeString("minor_version", MINOR_VERSION.ToString()); + + xtw.WriteElementString("name", profile.Name); + xtw.WriteElementString("id", profile.ID); + xtw.WriteElementString("about", profile.AboutText); + + // Not sure if we're storing this yet, need to take a look +// xtw.WriteElementString("Url", profile.Url); + // or, indeed, interests + + xtw.WriteEndElement(); + + xtw.Close(); + sw.Close(); + + return sw.ToString(); + } + } +} \ No newline at end of file -- cgit v1.1 From 3f1ec6334f59303d8223265dda97dc6b86b3fd3d Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 26 Mar 2009 17:30:43 +0000 Subject: * Fix build break from last commit --- OpenSim/Framework/Serialization/External/UserProfileSerializer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs index fc76fb6..544d13d 100644 --- a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs @@ -27,6 +27,7 @@ using System.IO; using System.Xml; +using OpenMetaverse; using OpenSim.Framework; namespace OpenSim.Framework.Serialization.External @@ -53,7 +54,7 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteAttributeString("minor_version", MINOR_VERSION.ToString()); xtw.WriteElementString("name", profile.Name); - xtw.WriteElementString("id", profile.ID); + xtw.WriteElementString("id", profile.ID.ToString()); xtw.WriteElementString("about", profile.AboutText); // Not sure if we're storing this yet, need to take a look -- cgit v1.1 From 7e40315d5d998826ebf3a613496f85e0fe6194af Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 26 Mar 2009 20:09:12 +0000 Subject: * minor: change some static readonlys to consts * adjust user profile iar saving path --- .../Framework/Serialization/ArchiveConstants.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index 8ce7b56..02b13be 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -38,53 +38,53 @@ namespace OpenSim.Framework.Serialization /// /// The location of the archive control file /// - public static readonly string CONTROL_FILE_PATH = "archive.xml"; + public const string CONTROL_FILE_PATH = "archive.xml"; /// /// Path for the assets held in an archive /// - public static readonly string ASSETS_PATH = "assets/"; + public const string ASSETS_PATH = "assets/"; /// /// Path for the inventory data /// - public static readonly string INVENTORY_PATH = "inventory/"; + public const string INVENTORY_PATH = "inventory/"; /// /// Path for the prims file /// - public static readonly string OBJECTS_PATH = "objects/"; + public const string OBJECTS_PATH = "objects/"; /// /// Path for terrains. Technically these may be assets, but I think it's quite nice to split them out. /// - public static readonly string TERRAINS_PATH = "terrains/"; + public const string TERRAINS_PATH = "terrains/"; /// /// Path for region settings. /// - public static readonly string SETTINGS_PATH = "settings/"; + public const string SETTINGS_PATH = "settings/"; /// /// Path for user profiles /// - public const string USERS_PATH = "users/"; + public const string USERS_PATH = "userprofiles/"; /// /// The character the separates the uuid from extension information in an archived asset filename /// - public static readonly string ASSET_EXTENSION_SEPARATOR = "_"; + public const string ASSET_EXTENSION_SEPARATOR = "_"; /// /// Used to separate components in an inventory node name /// - public static readonly string INVENTORY_NODE_NAME_COMPONENT_SEPARATOR = "__"; + public const string INVENTORY_NODE_NAME_COMPONENT_SEPARATOR = "__"; /// /// Extensions used for asset types in the archive /// - public static readonly IDictionary ASSET_TYPE_TO_EXTENSION = new Dictionary(); - public static readonly IDictionary EXTENSION_TO_ASSET_TYPE = new Dictionary(); + public const IDictionary ASSET_TYPE_TO_EXTENSION = new Dictionary(); + public const IDictionary EXTENSION_TO_ASSET_TYPE = new Dictionary(); static ArchiveConstants() { -- cgit v1.1 From 6ffed09682da5fd2d2e1e13e71ca3e317c6f2640 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 26 Mar 2009 20:15:36 +0000 Subject: * Fix build break - went a const or two too far --- OpenSim/Framework/Serialization/ArchiveConstants.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index 02b13be..7dd2db1 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -83,8 +83,8 @@ namespace OpenSim.Framework.Serialization /// /// Extensions used for asset types in the archive /// - public const IDictionary ASSET_TYPE_TO_EXTENSION = new Dictionary(); - public const IDictionary EXTENSION_TO_ASSET_TYPE = new Dictionary(); + public static readonly IDictionary ASSET_TYPE_TO_EXTENSION = new Dictionary(); + public static readonly IDictionary EXTENSION_TO_ASSET_TYPE = new Dictionary(); static ArchiveConstants() { -- cgit v1.1 From 561f24156476041bdcd2ef2fdccd296a4127d0b0 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 27 Mar 2009 18:13:34 +0000 Subject: * minor: move RegionSettingsSerializer into OpenSim.Framework.Serialization --- .../External/RegionSettingsSerializer.cs | 254 +++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs new file mode 100644 index 0000000..3ee9e1b --- /dev/null +++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs @@ -0,0 +1,254 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System.IO; +using System.Text; +using System.Xml; +using OpenMetaverse; +using OpenSim.Framework; + +namespace OpenSim.Framework.Serialization.External +{ + /// + /// Serialize and deserialize region settings for an archive file format. + /// + /// We didn't simply use automatic .NET serializagion for OpenSim.Framework.RegionSettings since this is really + /// a file format rather than an object serialization. + public class RegionSettingsSerializer + { + protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); + + /// + /// Deserialize region settings + /// + /// + /// + /// + public static RegionSettings Deserialize(byte[] serializedSettings) + { + return Deserialize(m_asciiEncoding.GetString(serializedSettings, 0, serializedSettings.Length)); + } + + /// + /// Deserialize region settings + /// + /// + /// + /// + public static RegionSettings Deserialize(string serializedSettings) + { + RegionSettings settings = new RegionSettings(); + + StringReader sr = new StringReader(serializedSettings); + XmlTextReader xtr = new XmlTextReader(sr); + + xtr.ReadStartElement("RegionSettings"); + + xtr.ReadStartElement("General"); + + while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) + { + switch (xtr.Name) + { + case "AllowDamage": + settings.AllowDamage = bool.Parse(xtr.ReadElementContentAsString()); + break; + case "AllowLandResell": + settings.AllowLandResell = bool.Parse(xtr.ReadElementContentAsString()); + break; + case "AllowLandJoinDivide": + settings.AllowLandJoinDivide = bool.Parse(xtr.ReadElementContentAsString()); + break; + case "BlockFly": + settings.BlockFly = bool.Parse(xtr.ReadElementContentAsString()); + break; + case "BlockLandShowInSearch": + settings.BlockShowInSearch = bool.Parse(xtr.ReadElementContentAsString()); + break; + case "BlockTerraform": + settings.BlockTerraform = bool.Parse(xtr.ReadElementContentAsString()); + break; + case "DisableCollisions": + settings.DisableCollisions = bool.Parse(xtr.ReadElementContentAsString()); + break; + case "DisablePhysics": + settings.DisablePhysics = bool.Parse(xtr.ReadElementContentAsString()); + break; + case "DisableScripts": + settings.DisableScripts = bool.Parse(xtr.ReadElementContentAsString()); + break; + case "MaturityRating": + settings.Maturity = int.Parse(xtr.ReadElementContentAsString()); + break; + case "RestrictPushing": + settings.RestrictPushing = bool.Parse(xtr.ReadElementContentAsString()); + break; + case "AgentLimit": + settings.AgentLimit = int.Parse(xtr.ReadElementContentAsString()); + break; + case "ObjectBonus": + settings.ObjectBonus = double.Parse(xtr.ReadElementContentAsString()); + break; + } + } + + xtr.ReadEndElement(); + xtr.ReadStartElement("GroundTextures"); + + while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) + { + switch (xtr.Name) + { + case "Texture1": + settings.TerrainTexture1 = UUID.Parse(xtr.ReadElementContentAsString()); + break; + case "Texture2": + settings.TerrainTexture2 = UUID.Parse(xtr.ReadElementContentAsString()); + break; + case "Texture3": + settings.TerrainTexture3 = UUID.Parse(xtr.ReadElementContentAsString()); + break; + case "Texture4": + settings.TerrainTexture4 = UUID.Parse(xtr.ReadElementContentAsString()); + break; + case "ElevationLowSW": + settings.Elevation1SW = double.Parse(xtr.ReadElementContentAsString()); + break; + case "ElevationLowNW": + settings.Elevation1NW = double.Parse(xtr.ReadElementContentAsString()); + break; + case "ElevationLowSE": + settings.Elevation1SE = double.Parse(xtr.ReadElementContentAsString()); + break; + case "ElevationLowNE": + settings.Elevation1NE = double.Parse(xtr.ReadElementContentAsString()); + break; + case "ElevationHighSW": + settings.Elevation2SW = double.Parse(xtr.ReadElementContentAsString()); + break; + case "ElevationHighNW": + settings.Elevation2NW = double.Parse(xtr.ReadElementContentAsString()); + break; + case "ElevationHighSE": + settings.Elevation2SE = double.Parse(xtr.ReadElementContentAsString()); + break; + case "ElevationHighNE": + settings.Elevation2NE = double.Parse(xtr.ReadElementContentAsString()); + break; + } + } + + xtr.ReadEndElement(); + xtr.ReadStartElement("Terrain"); + + while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) + { + switch (xtr.Name) + { + case "WaterHeight": + settings.WaterHeight = double.Parse(xtr.ReadElementContentAsString()); + break; + case "TerrainRaiseLimit": + settings.TerrainRaiseLimit = double.Parse(xtr.ReadElementContentAsString()); + break; + case "TerrainLowerLimit": + settings.TerrainLowerLimit = double.Parse(xtr.ReadElementContentAsString()); + break; + case "UseEstateSun": + settings.UseEstateSun = bool.Parse(xtr.ReadElementContentAsString()); + break; + case "FixedSun": + settings.FixedSun = bool.Parse(xtr.ReadElementContentAsString()); + break; + } + } + + xtr.Close(); + sr.Close(); + + return settings; + } + + public static string Serialize(RegionSettings settings) + { + StringWriter sw = new StringWriter(); + XmlTextWriter xtw = new XmlTextWriter(sw); + xtw.Formatting = Formatting.Indented; + xtw.WriteStartDocument(); + + xtw.WriteStartElement("RegionSettings"); + + xtw.WriteStartElement("General"); + xtw.WriteElementString("AllowDamage", settings.AllowDamage.ToString()); + xtw.WriteElementString("AllowLandResell", settings.AllowLandResell.ToString()); + xtw.WriteElementString("AllowLandJoinDivide", settings.AllowLandJoinDivide.ToString()); + xtw.WriteElementString("BlockFly", settings.BlockFly.ToString()); + xtw.WriteElementString("BlockLandShowInSearch", settings.BlockShowInSearch.ToString()); + xtw.WriteElementString("BlockTerraform", settings.BlockTerraform.ToString()); + xtw.WriteElementString("DisableCollisions", settings.DisableCollisions.ToString()); + xtw.WriteElementString("DisablePhysics", settings.DisablePhysics.ToString()); + xtw.WriteElementString("DisableScripts", settings.DisableScripts.ToString()); + xtw.WriteElementString("MaturityRating", settings.Maturity.ToString()); + xtw.WriteElementString("RestrictPushing", settings.RestrictPushing.ToString()); + xtw.WriteElementString("AgentLimit", settings.AgentLimit.ToString()); + xtw.WriteElementString("ObjectBonus", settings.ObjectBonus.ToString()); + xtw.WriteEndElement(); + + xtw.WriteStartElement("GroundTextures"); + xtw.WriteElementString("Texture1", settings.TerrainTexture1.ToString()); + xtw.WriteElementString("Texture2", settings.TerrainTexture2.ToString()); + xtw.WriteElementString("Texture3", settings.TerrainTexture3.ToString()); + xtw.WriteElementString("Texture4", settings.TerrainTexture4.ToString()); + xtw.WriteElementString("ElevationLowSW", settings.Elevation1SW.ToString()); + xtw.WriteElementString("ElevationLowNW", settings.Elevation1NW.ToString()); + xtw.WriteElementString("ElevationLowSE", settings.Elevation1SE.ToString()); + xtw.WriteElementString("ElevationLowNE", settings.Elevation1NE.ToString()); + xtw.WriteElementString("ElevationHighSW", settings.Elevation2SW.ToString()); + xtw.WriteElementString("ElevationHighNW", settings.Elevation2NW.ToString()); + xtw.WriteElementString("ElevationHighSE", settings.Elevation2SE.ToString()); + xtw.WriteElementString("ElevationHighNE", settings.Elevation2NE.ToString()); + xtw.WriteEndElement(); + + xtw.WriteStartElement("Terrain"); + xtw.WriteElementString("WaterHeight", settings.WaterHeight.ToString()); + xtw.WriteElementString("TerrainRaiseLimit", settings.TerrainRaiseLimit.ToString()); + xtw.WriteElementString("TerrainLowerLimit", settings.TerrainLowerLimit.ToString()); + xtw.WriteElementString("UseEstateSun", settings.UseEstateSun.ToString()); + xtw.WriteElementString("FixedSun", settings.FixedSun.ToString()); + // XXX: Need to expose interface to get sun phase information from sun module + // xtw.WriteStartElement("SunPhase", + xtw.WriteEndElement(); + + xtw.WriteEndElement(); + + xtw.Close(); + sw.Close(); + + return sw.ToString(); + } + } +} -- cgit v1.1 From 1ccc99a3f9d96fbdea478be7e7df427a9e5377a7 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 23 Apr 2009 20:15:05 +0000 Subject: * refactor: move archive user inventory item serialization out to a separate file --- .../External/RegionSettingsSerializer.cs | 8 +- .../External/UserInventoryItemSerializer.cs | 198 +++++++++++++++++++++ .../External/UserProfileSerializer.cs | 4 +- 3 files changed, 202 insertions(+), 8 deletions(-) create mode 100644 OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs index 3ee9e1b..232ad4e 100644 --- a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs +++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs @@ -34,16 +34,14 @@ using OpenSim.Framework; namespace OpenSim.Framework.Serialization.External { /// - /// Serialize and deserialize region settings for an archive file format. + /// Serialize and deserialize region settings as an external format. /// - /// We didn't simply use automatic .NET serializagion for OpenSim.Framework.RegionSettings since this is really - /// a file format rather than an object serialization. public class RegionSettingsSerializer { protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); /// - /// Deserialize region settings + /// Deserialize settings /// /// /// @@ -54,7 +52,7 @@ namespace OpenSim.Framework.Serialization.External } /// - /// Deserialize region settings + /// Deserialize settings /// /// /// diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs new file mode 100644 index 0000000..d51107d --- /dev/null +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -0,0 +1,198 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.IO; +using System.Text; +using System.Xml; +using OpenMetaverse; +using OpenSim.Framework; + +namespace OpenSim.Framework.Serialization.External +{ + /// + /// Serialize and deserialize user inventory items as an external format. + /// + /// XXX: Please do not use yet. + public class UserInventoryItemSerializer + { + protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); + + /// + /// Deserialize item + /// + /// + /// + /// + public static InventoryItemBase Deserialize(byte[] serialization) + { + return Deserialize(m_asciiEncoding.GetString(serialization, 0, serialization.Length)); + } + + /// + /// Deserialize settings + /// + /// + /// + /// + public static InventoryItemBase Deserialize(string serialization) + { + InventoryItemBase item = new InventoryItemBase(); + + StringReader sr = new StringReader(serialization); + XmlTextReader reader = new XmlTextReader(sr); + + reader.ReadStartElement("InventoryItem"); + reader.ReadStartElement("Name"); + item.Name = reader.ReadString(); + reader.ReadEndElement(); + reader.ReadStartElement("ID"); + item.ID = UUID.Parse(reader.ReadString()); + reader.ReadEndElement(); + reader.ReadStartElement("InvType"); + item.InvType = Convert.ToInt32(reader.ReadString()); + reader.ReadEndElement(); + reader.ReadStartElement("CreatorUUID"); + item.CreatorId = reader.ReadString(); + reader.ReadEndElement(); + reader.ReadStartElement("CreationDate"); + item.CreationDate = Convert.ToInt32(reader.ReadString()); + reader.ReadEndElement(); + reader.ReadStartElement("Owner"); + item.Owner = UUID.Parse(reader.ReadString()); + reader.ReadEndElement(); + reader.ReadElementString("Description"); + reader.ReadStartElement("AssetType"); + item.AssetType = Convert.ToInt32(reader.ReadString()); + reader.ReadEndElement(); + reader.ReadStartElement("AssetID"); + item.AssetID = UUID.Parse(reader.ReadString()); + reader.ReadEndElement(); + reader.ReadStartElement("SaleType"); + item.SaleType = Convert.ToByte(reader.ReadString()); + reader.ReadEndElement(); + reader.ReadStartElement("SalePrice"); + item.SalePrice = Convert.ToInt32(reader.ReadString()); + reader.ReadEndElement(); + reader.ReadStartElement("BasePermissions"); + item.BasePermissions = Convert.ToUInt32(reader.ReadString()); + reader.ReadEndElement(); + reader.ReadStartElement("CurrentPermissions"); + item.CurrentPermissions = Convert.ToUInt32(reader.ReadString()); + reader.ReadEndElement(); + reader.ReadStartElement("EveryOnePermssions"); + item.EveryOnePermissions = Convert.ToUInt32(reader.ReadString()); + reader.ReadEndElement(); + reader.ReadStartElement("NextPermissions"); + item.NextPermissions = Convert.ToUInt32(reader.ReadString()); + reader.ReadEndElement(); + reader.ReadStartElement("Flags"); + item.Flags = Convert.ToUInt32(reader.ReadString()); + reader.ReadEndElement(); + reader.ReadStartElement("GroupID"); + item.GroupID = UUID.Parse(reader.ReadString()); + reader.ReadEndElement(); + reader.ReadStartElement("GroupOwned"); + item.GroupOwned = Convert.ToBoolean(reader.ReadString()); + reader.ReadEndElement(); + + return item; + } + + public static string Serialize(InventoryItemBase inventoryItem) + { + StringWriter sw = new StringWriter(); + XmlTextWriter writer = new XmlTextWriter(sw); + writer.Formatting = Formatting.Indented; + writer.WriteStartDocument(); + + writer.WriteStartElement("InventoryItem"); + + writer.WriteStartElement("Name"); + writer.WriteString(inventoryItem.Name); + writer.WriteEndElement(); + writer.WriteStartElement("ID"); + writer.WriteString(inventoryItem.ID.ToString()); + writer.WriteEndElement(); + writer.WriteStartElement("InvType"); + writer.WriteString(inventoryItem.InvType.ToString()); + writer.WriteEndElement(); + writer.WriteStartElement("CreatorUUID"); + writer.WriteString(inventoryItem.CreatorId); + writer.WriteEndElement(); + writer.WriteStartElement("CreationDate"); + writer.WriteString(inventoryItem.CreationDate.ToString()); + writer.WriteEndElement(); + writer.WriteStartElement("Owner"); + writer.WriteString(inventoryItem.Owner.ToString()); + writer.WriteEndElement(); + writer.WriteStartElement("Description"); + writer.WriteString(inventoryItem.Description); + writer.WriteEndElement(); + writer.WriteStartElement("AssetType"); + writer.WriteString(inventoryItem.AssetType.ToString()); + writer.WriteEndElement(); + writer.WriteStartElement("AssetID"); + writer.WriteString(inventoryItem.AssetID.ToString()); + writer.WriteEndElement(); + writer.WriteStartElement("SaleType"); + writer.WriteString(inventoryItem.SaleType.ToString()); + writer.WriteEndElement(); + writer.WriteStartElement("SalePrice"); + writer.WriteString(inventoryItem.SalePrice.ToString()); + writer.WriteEndElement(); + writer.WriteStartElement("BasePermissions"); + writer.WriteString(inventoryItem.BasePermissions.ToString()); + writer.WriteEndElement(); + writer.WriteStartElement("CurrentPermissions"); + writer.WriteString(inventoryItem.CurrentPermissions.ToString()); + writer.WriteEndElement(); + writer.WriteStartElement("EveryOnePermssions"); + writer.WriteString(inventoryItem.EveryOnePermissions.ToString()); + writer.WriteEndElement(); + writer.WriteStartElement("NextPermissions"); + writer.WriteString(inventoryItem.NextPermissions.ToString()); + writer.WriteEndElement(); + writer.WriteStartElement("Flags"); + writer.WriteString(inventoryItem.Flags.ToString()); + writer.WriteEndElement(); + writer.WriteStartElement("GroupID"); + writer.WriteString(inventoryItem.GroupID.ToString()); + writer.WriteEndElement(); + writer.WriteStartElement("GroupOwned"); + writer.WriteString(inventoryItem.GroupOwned.ToString()); + writer.WriteEndElement(); + + writer.WriteEndElement(); + + writer.Close(); + sw.Close(); + + return sw.ToString(); + } + } +} diff --git a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs index 544d13d..6bf56c2 100644 --- a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs @@ -33,10 +33,8 @@ using OpenSim.Framework; namespace OpenSim.Framework.Serialization.External { /// - /// Serialize and deserialize region settings for an archive file format. + /// Serialize and deserialize region settings as an external format. /// - /// We didn't use automatic .NET serialization since this is really - /// a file format rather than an object serialization. public class UserProfileSerializer { public const int MAJOR_VERSION = 0; -- cgit v1.1 From d69a018ba84beede1f84f06eb17ab799133e006a Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 24 Apr 2009 15:02:48 +0000 Subject: * Write basic, incomplete load iar test --- .../Framework/Serialization/External/UserInventoryItemSerializer.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index d51107d..5fd5ab5 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -76,9 +76,7 @@ namespace OpenSim.Framework.Serialization.External reader.ReadStartElement("InvType"); item.InvType = Convert.ToInt32(reader.ReadString()); reader.ReadEndElement(); - reader.ReadStartElement("CreatorUUID"); - item.CreatorId = reader.ReadString(); - reader.ReadEndElement(); + item.CreatorId = reader.ReadElementString("CreatorUUID"); reader.ReadStartElement("CreationDate"); item.CreationDate = Convert.ToInt32(reader.ReadString()); reader.ReadEndElement(); -- cgit v1.1 From 170cea5088b393f33ac0e7447ff910b0d13c1bdb Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 24 Apr 2009 15:44:22 +0000 Subject: * minor: make inventory item deserialization code easier to read --- .../External/UserInventoryItemSerializer.cs | 78 ++++++++-------------- 1 file changed, 26 insertions(+), 52 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index 5fd5ab5..b9c6206 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -64,59 +64,33 @@ namespace OpenSim.Framework.Serialization.External InventoryItemBase item = new InventoryItemBase(); StringReader sr = new StringReader(serialization); - XmlTextReader reader = new XmlTextReader(sr); + XmlTextReader xtr = new XmlTextReader(sr); - reader.ReadStartElement("InventoryItem"); - reader.ReadStartElement("Name"); - item.Name = reader.ReadString(); - reader.ReadEndElement(); - reader.ReadStartElement("ID"); - item.ID = UUID.Parse(reader.ReadString()); - reader.ReadEndElement(); - reader.ReadStartElement("InvType"); - item.InvType = Convert.ToInt32(reader.ReadString()); - reader.ReadEndElement(); - item.CreatorId = reader.ReadElementString("CreatorUUID"); - reader.ReadStartElement("CreationDate"); - item.CreationDate = Convert.ToInt32(reader.ReadString()); - reader.ReadEndElement(); - reader.ReadStartElement("Owner"); - item.Owner = UUID.Parse(reader.ReadString()); - reader.ReadEndElement(); - reader.ReadElementString("Description"); - reader.ReadStartElement("AssetType"); - item.AssetType = Convert.ToInt32(reader.ReadString()); - reader.ReadEndElement(); - reader.ReadStartElement("AssetID"); - item.AssetID = UUID.Parse(reader.ReadString()); - reader.ReadEndElement(); - reader.ReadStartElement("SaleType"); - item.SaleType = Convert.ToByte(reader.ReadString()); - reader.ReadEndElement(); - reader.ReadStartElement("SalePrice"); - item.SalePrice = Convert.ToInt32(reader.ReadString()); - reader.ReadEndElement(); - reader.ReadStartElement("BasePermissions"); - item.BasePermissions = Convert.ToUInt32(reader.ReadString()); - reader.ReadEndElement(); - reader.ReadStartElement("CurrentPermissions"); - item.CurrentPermissions = Convert.ToUInt32(reader.ReadString()); - reader.ReadEndElement(); - reader.ReadStartElement("EveryOnePermssions"); - item.EveryOnePermissions = Convert.ToUInt32(reader.ReadString()); - reader.ReadEndElement(); - reader.ReadStartElement("NextPermissions"); - item.NextPermissions = Convert.ToUInt32(reader.ReadString()); - reader.ReadEndElement(); - reader.ReadStartElement("Flags"); - item.Flags = Convert.ToUInt32(reader.ReadString()); - reader.ReadEndElement(); - reader.ReadStartElement("GroupID"); - item.GroupID = UUID.Parse(reader.ReadString()); - reader.ReadEndElement(); - reader.ReadStartElement("GroupOwned"); - item.GroupOwned = Convert.ToBoolean(reader.ReadString()); - reader.ReadEndElement(); + xtr.ReadStartElement("InventoryItem"); + + item.Name = xtr.ReadElementString("Name"); + item.ID = UUID.Parse( xtr.ReadElementString("ID")); + item.InvType = Convert.ToInt32( xtr.ReadElementString("InvType")); + item.CreatorId = xtr.ReadElementString("CreatorUUID"); + item.CreationDate = Convert.ToInt32( xtr.ReadElementString("CreationDate")); + item.Owner = UUID.Parse( xtr.ReadElementString("Owner")); + item.Description = xtr.ReadElementString("Description"); + item.AssetType = Convert.ToInt32( xtr.ReadElementString("AssetType")); + item.AssetID = UUID.Parse( xtr.ReadElementString("AssetID")); + item.SaleType = Convert.ToByte( xtr.ReadElementString("SaleType")); + item.SalePrice = Convert.ToInt32( xtr.ReadElementString("SalePrice")); + item.BasePermissions = Convert.ToUInt32( xtr.ReadElementString("BasePermissions")); + item.CurrentPermissions = Convert.ToUInt32( xtr.ReadElementString("CurrentPermissions")); + item.EveryOnePermissions = Convert.ToUInt32( xtr.ReadElementString("EveryOnePermssions")); + item.NextPermissions = Convert.ToUInt32( xtr.ReadElementString("NextPermissions")); + item.Flags = Convert.ToUInt32( xtr.ReadElementString("Flags")); + item.GroupID = UUID.Parse( xtr.ReadElementString("GroupID")); + item.GroupOwned = Convert.ToBoolean(xtr.ReadElementString("GroupOwned")); + + xtr.ReadEndElement(); + + xtr.Close(); + sr.Close(); return item; } -- cgit v1.1 From 35c7aae455b110d99c578c1bd0dc0f21a7fc6fa3 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 24 Apr 2009 15:56:41 +0000 Subject: * correct spelling mistake in item seiralization --- .../Framework/Serialization/External/UserInventoryItemSerializer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index b9c6206..e0ddc96 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -81,7 +81,7 @@ namespace OpenSim.Framework.Serialization.External item.SalePrice = Convert.ToInt32( xtr.ReadElementString("SalePrice")); item.BasePermissions = Convert.ToUInt32( xtr.ReadElementString("BasePermissions")); item.CurrentPermissions = Convert.ToUInt32( xtr.ReadElementString("CurrentPermissions")); - item.EveryOnePermissions = Convert.ToUInt32( xtr.ReadElementString("EveryOnePermssions")); + item.EveryOnePermissions = Convert.ToUInt32( xtr.ReadElementString("EveryOnePermissions")); item.NextPermissions = Convert.ToUInt32( xtr.ReadElementString("NextPermissions")); item.Flags = Convert.ToUInt32( xtr.ReadElementString("Flags")); item.GroupID = UUID.Parse( xtr.ReadElementString("GroupID")); @@ -143,7 +143,7 @@ namespace OpenSim.Framework.Serialization.External writer.WriteStartElement("CurrentPermissions"); writer.WriteString(inventoryItem.CurrentPermissions.ToString()); writer.WriteEndElement(); - writer.WriteStartElement("EveryOnePermssions"); + writer.WriteStartElement("EveryOnePermissions"); writer.WriteString(inventoryItem.EveryOnePermissions.ToString()); writer.WriteEndElement(); writer.WriteStartElement("NextPermissions"); -- cgit v1.1 From aaad2fc8ffb48901e4c893811e82bf7754523d15 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 7 May 2009 19:27:38 +0000 Subject: * minor: use system ascii encoding rather than newing up our own object --- .../Framework/Serialization/External/UserInventoryItemSerializer.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index e0ddc96..b3fb7c3 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -40,8 +40,6 @@ namespace OpenSim.Framework.Serialization.External /// XXX: Please do not use yet. public class UserInventoryItemSerializer { - protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); - /// /// Deserialize item /// @@ -50,7 +48,7 @@ namespace OpenSim.Framework.Serialization.External /// public static InventoryItemBase Deserialize(byte[] serialization) { - return Deserialize(m_asciiEncoding.GetString(serialization, 0, serialization.Length)); + return Deserialize(Encoding.ASCII.GetString(serialization, 0, serialization.Length)); } /// -- cgit v1.1 From 62771560448edbc2112d427acd4b37780dfe2154 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 14 May 2009 20:37:54 +0000 Subject: * When saving an oar, save assets when immediately received rather than storing them all up in memory * Hopefully this will remove out of memory problems when saving large oars on machines without much memory * It may also speed up saving of large oars --- .../Framework/Serialization/TarArchiveWriter.cs | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/TarArchiveWriter.cs b/OpenSim/Framework/Serialization/TarArchiveWriter.cs index d319b0b..316a8de 100644 --- a/OpenSim/Framework/Serialization/TarArchiveWriter.cs +++ b/OpenSim/Framework/Serialization/TarArchiveWriter.cs @@ -109,10 +109,14 @@ namespace OpenSim.Framework.Serialization // Write two consecutive 0 blocks to end the archive byte[] finalZeroPadding = new byte[1024]; - m_bw.Write(finalZeroPadding); - m_bw.Flush(); - m_bw.Close(); + lock (m_bw) + { + m_bw.Write(finalZeroPadding); + + m_bw.Flush(); + m_bw.Close(); + } } public static byte[] ConvertDecimalToPaddedOctalBytes(int d, int padding) @@ -197,20 +201,23 @@ namespace OpenSim.Framework.Serialization header[154] = 0; - // Write out header - m_bw.Write(header); - - // Write out data - m_bw.Write(data); - - if (data.Length % 512 != 0) + lock (m_bw) { - int paddingRequired = 512 - (data.Length % 512); - - //m_log.DebugFormat("[TAR ARCHIVE WRITER]: Padding data with {0} bytes", paddingRequired); - - byte[] padding = new byte[paddingRequired]; - m_bw.Write(padding); + // Write out header + m_bw.Write(header); + + // Write out data + m_bw.Write(data); + + if (data.Length % 512 != 0) + { + int paddingRequired = 512 - (data.Length % 512); + + //m_log.DebugFormat("[TAR ARCHIVE WRITER]: Padding data with {0} bytes", paddingRequired); + + byte[] padding = new byte[paddingRequired]; + m_bw.Write(padding); + } } } } -- cgit v1.1 From 9e37e291b0cb8e88b1cd72d3644aec4159b6f3bd Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Wed, 27 May 2009 17:34:06 +0000 Subject: making TarArchiveReader more resilient when faced with OARs created by ancient tars. --- OpenSim/Framework/Serialization/TarArchiveReader.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/TarArchiveReader.cs b/OpenSim/Framework/Serialization/TarArchiveReader.cs index da5703f..1088870 100644 --- a/OpenSim/Framework/Serialization/TarArchiveReader.cs +++ b/OpenSim/Framework/Serialization/TarArchiveReader.cs @@ -63,7 +63,11 @@ namespace OpenSim.Framework.Serialization /// /// Used to trim off null chars /// - protected char[] m_nullCharArray = new char[] { '\0' }; + protected static char[] m_nullCharArray = new char[] { '\0' }; + /// + /// Used to trim off space chars + /// + protected static char[] m_spaceCharArray = new char[] { ' ' }; /// /// Generate a tar reader which reads from the given stream. @@ -195,7 +199,9 @@ namespace OpenSim.Framework.Serialization /// public static int ConvertOctalBytesToDecimal(byte[] bytes, int startIndex, int count) { - string oString = m_asciiEncoding.GetString(bytes, startIndex, count); + // Trim leading white space: ancient tars do that instead + // of leading 0s :-( don't ask. really. + string oString = m_asciiEncoding.GetString(bytes, startIndex, count).TrimStart(m_spaceCharArray); int d = 0; -- cgit v1.1 From 840de6c036570d559ec6924cd8405d3f34a99fdd Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Mon, 1 Jun 2009 06:37:14 +0000 Subject: Minor: Change OpenSim to OpenSimulator in older copyright headers and LICENSE.txt. --- OpenSim/Framework/Serialization/ArchiveConstants.cs | 2 +- OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs | 2 +- OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs | 2 +- OpenSim/Framework/Serialization/External/UserProfileSerializer.cs | 2 +- OpenSim/Framework/Serialization/TarArchiveReader.cs | 2 +- OpenSim/Framework/Serialization/TarArchiveWriter.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index 7dd2db1..f6dedec 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the + * * Neither the name of the OpenSimulator Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * diff --git a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs index 232ad4e..274f41f 100644 --- a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs +++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the + * * Neither the name of the OpenSimulator Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index b3fb7c3..862cc72 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the + * * Neither the name of the OpenSimulator Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * diff --git a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs index 6bf56c2..eb77e65 100644 --- a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the + * * Neither the name of the OpenSimulator Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * diff --git a/OpenSim/Framework/Serialization/TarArchiveReader.cs b/OpenSim/Framework/Serialization/TarArchiveReader.cs index 1088870..694ea70 100644 --- a/OpenSim/Framework/Serialization/TarArchiveReader.cs +++ b/OpenSim/Framework/Serialization/TarArchiveReader.cs @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the + * * Neither the name of the OpenSimulator Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * diff --git a/OpenSim/Framework/Serialization/TarArchiveWriter.cs b/OpenSim/Framework/Serialization/TarArchiveWriter.cs index 316a8de..7040870 100644 --- a/OpenSim/Framework/Serialization/TarArchiveWriter.cs +++ b/OpenSim/Framework/Serialization/TarArchiveWriter.cs @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the + * * Neither the name of the OpenSimulator Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * -- cgit v1.1 From acf7206f4ba31c7068d9d235c5bd36bb039eb72d Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Sun, 2 Aug 2009 19:30:25 +0000 Subject: Thank you kindly, dslake, for a patch that: The region dearchive module assumes extra null bytes will be appended to the end of every OAR file. This may be due to the block nature of storage but it seems like an unsafe assumption. When streaming region archives over a network or through a memory stream, no additional null bytes are added to the end and this an exception. --- OpenSim/Framework/Serialization/TarArchiveReader.cs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/TarArchiveReader.cs b/OpenSim/Framework/Serialization/TarArchiveReader.cs index 694ea70..77c29f8 100644 --- a/OpenSim/Framework/Serialization/TarArchiveReader.cs +++ b/OpenSim/Framework/Serialization/TarArchiveReader.cs @@ -105,6 +105,10 @@ namespace OpenSim.Framework.Serialization { byte[] header = m_br.ReadBytes(512); + // If there are no more bytes in the stream, return null header + if (header.Length == 0) + return null; + // If we've reached the end of the archive we'll be in null block territory, which means // the next byte will be 0 if (header[0] == 0) -- cgit v1.1 From 33515c75e44421df58a97058a6281eb96e0e50fd Mon Sep 17 00:00:00 2001 From: dr scofield (aka dirk husemann) Date: Tue, 29 Sep 2009 09:07:00 +0200 Subject: adding LandDataSerializer (not connected anywhere, work-in-progress) [hi, there, justin!] --- .../Serialization/External/LandDataSerializer.cs | 185 +++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 OpenSim/Framework/Serialization/External/LandDataSerializer.cs (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs new file mode 100644 index 0000000..6bfae41 --- /dev/null +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -0,0 +1,185 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Xml; +using OpenMetaverse; +using OpenSim.Framework; + +namespace OpenSim.Framework.Serialization.External +{ + /// + /// Serialize and deserialize LandData as an external format. + /// + public class LandDataSerializer + { + protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); + + /// + /// Reify/deserialize landData + /// + /// + /// + /// + public static LandData Deserialize(byte[] serializedLandData) + { + return Deserialize(m_utf8Encoding.GetString(serializedLandData, 0, serializedLandData.Length)); + } + + /// + /// Reify/deserialize landData + /// + /// + /// + /// + public static LandData Deserialize(string serializedLandData) + { + LandData landData = new LandData(); + + StringReader sr = new StringReader(serializedLandData); + XmlTextReader xtr = new XmlTextReader(sr); + + xtr.ReadStartElement("LandData"); + + landData.Area = Convert.ToInt32( xtr.ReadElementString("Area")); + landData.AuctionID = Convert.ToUInt32( xtr.ReadElementString("AuctionID")); + landData.AuthBuyerID = UUID.Parse( xtr.ReadElementString("AuthBuyerID")); + landData.Category = (ParcelCategory)Convert.ToSByte( xtr.ReadElementString("Category")); + landData.ClaimDate = Convert.ToInt32( xtr.ReadElementString("ClaimDate")); + landData.ClaimPrice = Convert.ToInt32( xtr.ReadElementString("ClaimPrice")); + landData.GlobalID = UUID.Parse( xtr.ReadElementString("GlobalID")); + landData.GroupID = UUID.Parse( xtr.ReadElementString("GroupID")); + landData.IsGroupOwned = Convert.ToBoolean( xtr.ReadElementString("IsGroupOwned")); + landData.Bitmap = Convert.FromBase64String( xtr.ReadElementString("Bitmap")); + landData.Description = xtr.ReadElementString("Description"); + landData.Flags = Convert.ToUInt32( xtr.ReadElementString("Flags")); + landData.LandingType = Convert.ToByte( xtr.ReadElementString("LandingType")); + landData.Name = xtr.ReadElementString("Name"); + landData.Status = (ParcelStatus)Convert.ToSByte( xtr.ReadElementString("Status")); + landData.LocalID = Convert.ToInt32( xtr.ReadElementString("LocalID")); + landData.MediaAutoScale = Convert.ToByte( xtr.ReadElementString("MediaAutoScale")); + landData.MediaID = UUID.Parse( xtr.ReadElementString("MediaID")); + landData.MediaURL = xtr.ReadElementString("MediaURL"); + landData.MusicURL = xtr.ReadElementString("MusicURL"); + landData.OwnerID = UUID.Parse( xtr.ReadElementString("OwnerID")); + + landData.ParcelAccessList = new List(); + xtr.ReadStartElement("ParcelAccessList"); + while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) + { + ParcelManager.ParcelAccessEntry pae; + + xtr.ReadStartElement("ParcelAccessEntry"); + pae.AgentID = UUID.Parse( xtr.ReadElementString("AgentID")); + pae.Time = Convert.ToDateTime( xtr.ReadElementString("Time")); + pae.Flags = (AccessList)Convert.ToUInt32( xtr.ReadElementString("AccessList")); + xtr.ReadEndElement(); + + landData.ParcelAccessList.Add(pae); + } + xtr.ReadEndElement(); + + landData.PassHours = Convert.ToSingle( xtr.ReadElementString("PassHours")); + landData.PassPrice = Convert.ToInt32( xtr.ReadElementString("PassPrice")); + landData.SalePrice = Convert.ToInt32( xtr.ReadElementString("SalePrice")); + landData.SnapshotID = UUID.Parse( xtr.ReadElementString("SnapshotID")); + landData.UserLocation = Vector3.Parse( xtr.ReadElementString("UserLocation")); + landData.UserLookAt = Vector3.Parse( xtr.ReadElementString("UserLookAt")); + landData.Dwell = Convert.ToInt32( xtr.ReadElementString("Dwell")); + landData.OtherCleanTime = Convert.ToInt32( xtr.ReadElementString("OtherCleanTime")); + + xtr.ReadEndElement(); + + xtr.Close(); + sr.Close(); + + return landData; + } + + public static string Serialize(LandData landData) + { + StringWriter sw = new StringWriter(); + XmlTextWriter xtw = new XmlTextWriter(sw); + xtw.Formatting = Formatting.Indented; + + xtw.WriteStartDocument(); + xtw.WriteStartElement("LandData"); + + xtw.WriteElementString("Area", landData.Area.ToString()); + xtw.WriteElementString("AuctionID", landData.AuctionID.ToString()); + xtw.WriteElementString("AuthBuyerID", landData.AuthBuyerID.ToString()); + xtw.WriteElementString("Category", landData.Category.ToString()); + xtw.WriteElementString("ClaimDate", landData.ClaimDate.ToString()); + xtw.WriteElementString("ClaimPrice", landData.ClaimPrice.ToString()); + xtw.WriteElementString("GlobalID", landData.GlobalID.ToString()); + xtw.WriteElementString("GroupID", landData.GroupID.ToString()); + xtw.WriteElementString("IsGroupOwned", landData.IsGroupOwned.ToString()); + xtw.WriteElementString("Bitmap", landData.Bitmap.ToString()); + xtw.WriteElementString("Description", landData.Description); + xtw.WriteElementString("Flags", landData.Flags.ToString()); + xtw.WriteElementString("LandingType", landData.LandingType.ToString()); + xtw.WriteElementString("Name", landData.Name); + xtw.WriteElementString("Status", landData.Status.ToString()); + xtw.WriteElementString("LocalID", landData.LocalID.ToString()); + xtw.WriteElementString("MediaAutoScale", landData.MediaAutoScale.ToString()); + xtw.WriteElementString("MediaID", landData.MediaID.ToString()); + xtw.WriteElementString("MediaURL", landData.MediaURL.ToString()); + xtw.WriteElementString("MusicURL", landData.MusicURL.ToString()); + xtw.WriteElementString("OwnerID", landData.OwnerID.ToString()); + + xtw.WriteStartElement("ParcelAccessList"); + foreach(ParcelManager.ParcelAccessEntry pal in landData.ParcelAccessList) + { + xtw.WriteStartElement("ParcelAccessEntry"); + xtw.WriteElementString("AgentID", pal.AgentID.ToString()); + xtw.WriteElementString("Time", pal.Time.ToString()); + xtw.WriteElementString("AccessList", pal.Flags.ToString()); + xtw.WriteEndElement(); + } + xtw.WriteEndElement(); + + xtw.WriteElementString("PassHours", landData.PassHours.ToString()); + xtw.WriteElementString("PassPrice", landData.PassPrice.ToString()); + xtw.WriteElementString("SalePrice", landData.SalePrice.ToString()); + xtw.WriteElementString("SnapshotID", landData.SnapshotID.ToString()); + xtw.WriteElementString("UserLocation", landData.UserLocation.ToString()); + xtw.WriteElementString("UserLookAt", landData.UserLookAt.ToString()); + xtw.WriteElementString("Dwell", landData.Dwell.ToString()); + xtw.WriteElementString("OtherCleanTime", landData.OtherCleanTime.ToString()); + + xtw.WriteEndElement(); + + xtw.Close(); + sw.Close(); + + return sw.ToString(); + } + } +} -- cgit v1.1 From ee205e7e812e170f670e690a4e0fa9caa652f226 Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Thu, 1 Oct 2009 01:00:09 +0900 Subject: Formatting cleanup. --- .../Framework/Serialization/External/RegionSettingsSerializer.cs | 6 +++--- OpenSim/Framework/Serialization/External/UserProfileSerializer.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs index 274f41f..b5901e1 100644 --- a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs +++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs @@ -158,7 +158,7 @@ namespace OpenSim.Framework.Serialization.External settings.Elevation2NE = double.Parse(xtr.ReadElementContentAsString()); break; } - } + } xtr.ReadEndElement(); xtr.ReadStartElement("Terrain"); @@ -200,8 +200,8 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteStartElement("RegionSettings"); - xtw.WriteStartElement("General"); - xtw.WriteElementString("AllowDamage", settings.AllowDamage.ToString()); + xtw.WriteStartElement("General"); + xtw.WriteElementString("AllowDamage", settings.AllowDamage.ToString()); xtw.WriteElementString("AllowLandResell", settings.AllowLandResell.ToString()); xtw.WriteElementString("AllowLandJoinDivide", settings.AllowLandJoinDivide.ToString()); xtw.WriteElementString("BlockFly", settings.BlockFly.ToString()); diff --git a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs index eb77e65..fb269b7 100644 --- a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs @@ -36,7 +36,7 @@ namespace OpenSim.Framework.Serialization.External /// Serialize and deserialize region settings as an external format. /// public class UserProfileSerializer - { + { public const int MAJOR_VERSION = 0; public const int MINOR_VERSION = 1; @@ -65,6 +65,6 @@ namespace OpenSim.Framework.Serialization.External sw.Close(); return sw.ToString(); - } + } } } \ No newline at end of file -- cgit v1.1 From 606e831ff5337fb5e94dcebf9d6852bd4c434d4b Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Thu, 1 Oct 2009 09:38:36 +0900 Subject: Formatting cleanup. --- OpenSim/Framework/Serialization/External/LandDataSerializer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index 6bfae41..4376249 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -155,7 +155,7 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("OwnerID", landData.OwnerID.ToString()); xtw.WriteStartElement("ParcelAccessList"); - foreach(ParcelManager.ParcelAccessEntry pal in landData.ParcelAccessList) + foreach (ParcelManager.ParcelAccessEntry pal in landData.ParcelAccessList) { xtw.WriteStartElement("ParcelAccessEntry"); xtw.WriteElementString("AgentID", pal.AgentID.ToString()); -- cgit v1.1 From 40cf840df26e66fca8ab81d602fd67ff1d2a6afa Mon Sep 17 00:00:00 2001 From: dr scofield (aka dirk husemann) Date: Thu, 1 Oct 2009 09:47:45 +0200 Subject: adding testcase for LandDataSerializer; fixing LandDataSerializer ;-) --- .../Serialization/External/LandDataSerializer.cs | 64 ++++++++-------- .../Serialization/Tests/LandDataSerializerTests.cs | 86 ++++++++++++++++++++++ 2 files changed, 118 insertions(+), 32 deletions(-) create mode 100644 OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index 6bfae41..0d91859 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -132,47 +132,47 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteStartDocument(); xtw.WriteStartElement("LandData"); - xtw.WriteElementString("Area", landData.Area.ToString()); - xtw.WriteElementString("AuctionID", landData.AuctionID.ToString()); - xtw.WriteElementString("AuthBuyerID", landData.AuthBuyerID.ToString()); - xtw.WriteElementString("Category", landData.Category.ToString()); - xtw.WriteElementString("ClaimDate", landData.ClaimDate.ToString()); - xtw.WriteElementString("ClaimPrice", landData.ClaimPrice.ToString()); - xtw.WriteElementString("GlobalID", landData.GlobalID.ToString()); - xtw.WriteElementString("GroupID", landData.GroupID.ToString()); - xtw.WriteElementString("IsGroupOwned", landData.IsGroupOwned.ToString()); - xtw.WriteElementString("Bitmap", landData.Bitmap.ToString()); - xtw.WriteElementString("Description", landData.Description); - xtw.WriteElementString("Flags", landData.Flags.ToString()); - xtw.WriteElementString("LandingType", landData.LandingType.ToString()); - xtw.WriteElementString("Name", landData.Name); - xtw.WriteElementString("Status", landData.Status.ToString()); - xtw.WriteElementString("LocalID", landData.LocalID.ToString()); - xtw.WriteElementString("MediaAutoScale", landData.MediaAutoScale.ToString()); - xtw.WriteElementString("MediaID", landData.MediaID.ToString()); - xtw.WriteElementString("MediaURL", landData.MediaURL.ToString()); - xtw.WriteElementString("MusicURL", landData.MusicURL.ToString()); - xtw.WriteElementString("OwnerID", landData.OwnerID.ToString()); + xtw.WriteElementString("Area", Convert.ToString(landData.Area)); + xtw.WriteElementString("AuctionID", Convert.ToString(landData.AuctionID)); + xtw.WriteElementString("AuthBuyerID", landData.AuthBuyerID.ToString()); + xtw.WriteElementString("Category", Convert.ToString(landData.Category)); + 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)); + xtw.WriteElementString("Bitmap", Convert.ToBase64String(landData.Bitmap)); + xtw.WriteElementString("Description", landData.Description); + xtw.WriteElementString("Flags", Convert.ToString(landData.Flags)); + xtw.WriteElementString("LandingType", Convert.ToString(landData.LandingType)); + xtw.WriteElementString("Name", landData.Name); + xtw.WriteElementString("Status", Convert.ToString(landData.Status)); + xtw.WriteElementString("LocalID", landData.LocalID.ToString()); + xtw.WriteElementString("MediaAutoScale", Convert.ToString(landData.MediaAutoScale)); + xtw.WriteElementString("MediaID", landData.MediaID.ToString()); + xtw.WriteElementString("MediaURL", landData.MediaURL); + xtw.WriteElementString("MusicURL", landData.MusicURL); + xtw.WriteElementString("OwnerID", landData.OwnerID.ToString()); xtw.WriteStartElement("ParcelAccessList"); foreach(ParcelManager.ParcelAccessEntry pal in landData.ParcelAccessList) { xtw.WriteStartElement("ParcelAccessEntry"); - xtw.WriteElementString("AgentID", pal.AgentID.ToString()); - xtw.WriteElementString("Time", pal.Time.ToString()); - xtw.WriteElementString("AccessList", pal.Flags.ToString()); + xtw.WriteElementString("AgentID", pal.AgentID.ToString()); + xtw.WriteElementString("Time", Convert.ToString(pal.Time)); + xtw.WriteElementString("AccessList", Convert.ToString(pal.Flags)); xtw.WriteEndElement(); } xtw.WriteEndElement(); - xtw.WriteElementString("PassHours", landData.PassHours.ToString()); - xtw.WriteElementString("PassPrice", landData.PassPrice.ToString()); - xtw.WriteElementString("SalePrice", landData.SalePrice.ToString()); - xtw.WriteElementString("SnapshotID", landData.SnapshotID.ToString()); - xtw.WriteElementString("UserLocation", landData.UserLocation.ToString()); - xtw.WriteElementString("UserLookAt", landData.UserLookAt.ToString()); - xtw.WriteElementString("Dwell", landData.Dwell.ToString()); - xtw.WriteElementString("OtherCleanTime", landData.OtherCleanTime.ToString()); + xtw.WriteElementString("PassHours", Convert.ToString(landData.PassHours)); + xtw.WriteElementString("PassPrice", Convert.ToString(landData.PassPrice)); + xtw.WriteElementString("SalePrice", Convert.ToString(landData.SalePrice)); + xtw.WriteElementString("SnapshotID", landData.SnapshotID.ToString()); + xtw.WriteElementString("UserLocation", landData.UserLocation.ToString()); + xtw.WriteElementString("UserLookAt", landData.UserLookAt.ToString()); + xtw.WriteElementString("Dwell", Convert.ToString(landData.Dwell)); + xtw.WriteElementString("OtherCleanTime", Convert.ToString(landData.OtherCleanTime)); xtw.WriteEndElement(); diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs new file mode 100644 index 0000000..f1881a1 --- /dev/null +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -0,0 +1,86 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System.Collections.Generic; +using OpenSim.Framework; +using OpenSim.Framework.Serialization.External; +using OpenMetaverse; +using OpenMetaverse.StructuredData; +using NUnit.Framework; + +namespace OpenSim.Framework.Serialization.Tests +{ + [TestFixture] + public class LandDataSerializerTest + { + private LandData land; + + [SetUp] + public void setup() + { + // setup LandData object + this.land = new LandData(); + this.land.AABBMax = new Vector3(0, 0, 0); + this.land.AABBMin = new Vector3(128, 128, 128); + this.land.Area = 128; + this.land.AuctionID = 0; + this.land.AuthBuyerID = new UUID(); + this.land.Category = ParcelCategory.Residential; + this.land.ClaimDate = 0; + this.land.ClaimPrice = 0; + this.land.GlobalID = new UUID("54ff9641-dd40-4a2c-b1f1-47dd3af24e50"); + this.land.GroupID = new UUID("d740204e-bbbf-44aa-949d-02c7d739f6a5"); + this.land.GroupPrims = 0; + this.land.Description = "land data to test LandDataSerializer"; + this.land.Flags = (uint)(ParcelFlags.AllowDamage | ParcelFlags.AllowVoiceChat); + this.land.LandingType = (byte)LandingType.Direct; + this.land.Name = "LandDataSerializerTest Land"; + this.land.Status = ParcelStatus.Leased; + this.land.LocalID = 0; + this.land.MediaAutoScale = (byte)0x01; + this.land.MediaID = new UUID("d4452578-2f25-4b97-a81b-819af559cfd7"); + this.land.MediaURL = "http://videos.opensimulator.org/bumblebee.mp4"; + this.land.OwnerID = new UUID("1b8eedf9-6d15-448b-8015-24286f1756bf"); + } + + /// + /// + [Test] + public void TestLandDataSerializerSerializeTest() + { + string serialized = LandDataSerializer.Serialize(this.land); + Assert.That(serialized.Length > 0); + } + + /// + /// + [Test] + public void TestLandDataSerializerDeserializeTest() + { + } + } +} -- cgit v1.1 From 77ed8e977a8664456f55533feafeaca913c3b1c6 Mon Sep 17 00:00:00 2001 From: dr scofield (aka dirk husemann) Date: Thu, 1 Oct 2009 10:30:26 +0200 Subject: adding meat to the LandDataSerializerTest cases. --- OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs index f1881a1..d0e3fc8 100644 --- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; using System.Collections.Generic; using OpenSim.Framework; using OpenSim.Framework.Serialization.External; @@ -38,6 +39,7 @@ namespace OpenSim.Framework.Serialization.Tests public class LandDataSerializerTest { private LandData land; + private string preSerialized = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n Residential\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n Leased\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; [SetUp] public void setup() @@ -70,10 +72,11 @@ namespace OpenSim.Framework.Serialization.Tests /// /// [Test] - public void TestLandDataSerializerSerializeTest() + public void LandDataSerializerSerializeTest() { string serialized = LandDataSerializer.Serialize(this.land); Assert.That(serialized.Length > 0); + Assert.That(serialized == this.preSerialized); } /// -- cgit v1.1 From 05da73c300b8ed2105febb8de8f2d302b8dbe599 Mon Sep 17 00:00:00 2001 From: dr scofield (aka dirk husemann) Date: Thu, 1 Oct 2009 12:01:41 +0200 Subject: fixing LandDataSerializer (yeah! for testcases) --- .../Serialization/External/LandDataSerializer.cs | 36 +++++++++++++--------- .../Serialization/Tests/LandDataSerializerTests.cs | 12 +++++--- 2 files changed, 29 insertions(+), 19 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index e9af2ca..e980945 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -91,20 +91,26 @@ namespace OpenSim.Framework.Serialization.External landData.OwnerID = UUID.Parse( xtr.ReadElementString("OwnerID")); landData.ParcelAccessList = new List(); - xtr.ReadStartElement("ParcelAccessList"); - while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) - { - ParcelManager.ParcelAccessEntry pae; + xtr.Read(); + if (xtr.Name != "ParcelAccessList") + throw new XmlException(String.Format("Expected \"ParcelAccessList\" element but got \"{0}\"", xtr.Name)); - xtr.ReadStartElement("ParcelAccessEntry"); - pae.AgentID = UUID.Parse( xtr.ReadElementString("AgentID")); - pae.Time = Convert.ToDateTime( xtr.ReadElementString("Time")); - pae.Flags = (AccessList)Convert.ToUInt32( xtr.ReadElementString("AccessList")); - xtr.ReadEndElement(); + if (!xtr.IsEmptyElement) + { + while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) + { + ParcelManager.ParcelAccessEntry pae; - landData.ParcelAccessList.Add(pae); + xtr.ReadStartElement("ParcelAccessEntry"); + pae.AgentID = UUID.Parse( xtr.ReadElementString("AgentID")); + pae.Time = Convert.ToDateTime( xtr.ReadElementString("Time")); + pae.Flags = (AccessList)Convert.ToUInt32( xtr.ReadElementString("AccessList")); + xtr.ReadEndElement(); + + landData.ParcelAccessList.Add(pae); + } } - xtr.ReadEndElement(); + xtr.Read(); landData.PassHours = Convert.ToSingle( xtr.ReadElementString("PassHours")); landData.PassPrice = Convert.ToInt32( xtr.ReadElementString("PassPrice")); @@ -135,7 +141,7 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("Area", Convert.ToString(landData.Area)); xtw.WriteElementString("AuctionID", Convert.ToString(landData.AuctionID)); xtw.WriteElementString("AuthBuyerID", landData.AuthBuyerID.ToString()); - xtw.WriteElementString("Category", Convert.ToString(landData.Category)); + xtw.WriteElementString("Category", Convert.ToString((sbyte)landData.Category)); xtw.WriteElementString("ClaimDate", Convert.ToString(landData.ClaimDate)); xtw.WriteElementString("ClaimPrice", Convert.ToString(landData.ClaimPrice)); xtw.WriteElementString("GlobalID", landData.GlobalID.ToString()); @@ -143,10 +149,10 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("IsGroupOwned", Convert.ToString(landData.IsGroupOwned)); xtw.WriteElementString("Bitmap", Convert.ToBase64String(landData.Bitmap)); xtw.WriteElementString("Description", landData.Description); - xtw.WriteElementString("Flags", Convert.ToString(landData.Flags)); - xtw.WriteElementString("LandingType", Convert.ToString(landData.LandingType)); + xtw.WriteElementString("Flags", Convert.ToString((uint)landData.Flags)); + xtw.WriteElementString("LandingType", Convert.ToString((byte)landData.LandingType)); xtw.WriteElementString("Name", landData.Name); - xtw.WriteElementString("Status", Convert.ToString(landData.Status)); + xtw.WriteElementString("Status", Convert.ToString((sbyte)landData.Status)); xtw.WriteElementString("LocalID", landData.LocalID.ToString()); xtw.WriteElementString("MediaAutoScale", Convert.ToString(landData.MediaAutoScale)); xtw.WriteElementString("MediaID", landData.MediaID.ToString()); diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs index d0e3fc8..06ec047 100644 --- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -39,7 +39,7 @@ namespace OpenSim.Framework.Serialization.Tests public class LandDataSerializerTest { private LandData land; - private string preSerialized = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n Residential\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n Leased\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; + private string preSerialized = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; [SetUp] public void setup() @@ -75,15 +75,19 @@ namespace OpenSim.Framework.Serialization.Tests public void LandDataSerializerSerializeTest() { string serialized = LandDataSerializer.Serialize(this.land); - Assert.That(serialized.Length > 0); - Assert.That(serialized == this.preSerialized); + Assert.That(serialized.Length > 0, "Serialize(LandData) returned empty string"); + Assert.That(serialized == this.preSerialized, "result of Serialize(LandData) does not match expected result"); } /// /// [Test] - public void TestLandDataSerializerDeserializeTest() + public void TestLandDataSerializerDeserializeFromStringTest() { + LandData reifiedLandData = LandDataSerializer.Deserialize(this.preSerialized); + Assert.That(reifiedLandData != null, "Deserialize(string) returned null"); + Assert.That(reifiedLandData.GlobalID == this.land.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID"); + Assert.That(reifiedLandData.Name == this.land.Name, "Reified LandData.Name != original LandData.Name"); } } } -- cgit v1.1 From 133a4a9906e55b20ff8780ebe5f59df87d5523ee Mon Sep 17 00:00:00 2001 From: dr scofield (aka dirk husemann) Date: Thu, 1 Oct 2009 15:03:16 +0200 Subject: - adding new LandDataSerializer testcase to "test-xml" target as well - adding another LandDataSerializer testcase --- .../Serialization/External/LandDataSerializer.cs | 22 +++++------ .../Serialization/Tests/LandDataSerializerTests.cs | 44 ++++++++++++++++++++-- 2 files changed, 52 insertions(+), 14 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index e980945..a3bc5d1 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -99,7 +99,7 @@ namespace OpenSim.Framework.Serialization.External { while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) { - ParcelManager.ParcelAccessEntry pae; + ParcelManager.ParcelAccessEntry pae = new ParcelManager.ParcelAccessEntry(); xtr.ReadStartElement("ParcelAccessEntry"); pae.AgentID = UUID.Parse( xtr.ReadElementString("AgentID")); @@ -112,14 +112,14 @@ namespace OpenSim.Framework.Serialization.External } xtr.Read(); - landData.PassHours = Convert.ToSingle( xtr.ReadElementString("PassHours")); - landData.PassPrice = Convert.ToInt32( xtr.ReadElementString("PassPrice")); - landData.SalePrice = Convert.ToInt32( xtr.ReadElementString("SalePrice")); - landData.SnapshotID = UUID.Parse( xtr.ReadElementString("SnapshotID")); - landData.UserLocation = Vector3.Parse( xtr.ReadElementString("UserLocation")); - landData.UserLookAt = Vector3.Parse( xtr.ReadElementString("UserLookAt")); - landData.Dwell = Convert.ToInt32( xtr.ReadElementString("Dwell")); - landData.OtherCleanTime = Convert.ToInt32( xtr.ReadElementString("OtherCleanTime")); + landData.PassHours = Convert.ToSingle( xtr.ReadElementString("PassHours")); + landData.PassPrice = Convert.ToInt32( xtr.ReadElementString("PassPrice")); + landData.SalePrice = Convert.ToInt32( xtr.ReadElementString("SalePrice")); + landData.SnapshotID = UUID.Parse( xtr.ReadElementString("SnapshotID")); + landData.UserLocation = Vector3.Parse( xtr.ReadElementString("UserLocation")); + landData.UserLookAt = Vector3.Parse( xtr.ReadElementString("UserLookAt")); + landData.Dwell = Convert.ToInt32( xtr.ReadElementString("Dwell")); + landData.OtherCleanTime = Convert.ToInt32( xtr.ReadElementString("OtherCleanTime")); xtr.ReadEndElement(); @@ -165,8 +165,8 @@ namespace OpenSim.Framework.Serialization.External { xtw.WriteStartElement("ParcelAccessEntry"); xtw.WriteElementString("AgentID", pal.AgentID.ToString()); - xtw.WriteElementString("Time", Convert.ToString(pal.Time)); - xtw.WriteElementString("AccessList", Convert.ToString(pal.Flags)); + xtw.WriteElementString("Time", pal.Time.ToString("s")); + xtw.WriteElementString("AccessList", Convert.ToString((uint)pal.Flags)); xtw.WriteEndElement(); } xtw.WriteEndElement(); diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs index 06ec047..14e0462 100644 --- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -39,7 +39,13 @@ namespace OpenSim.Framework.Serialization.Tests public class LandDataSerializerTest { private LandData land; - private string preSerialized = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; + private LandData landWithParcelAccessList; + + private static string preSerialized = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; + private static string preSerializedWithParcelAccessList = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n \n 62d65d45-c91a-4f77-862c-46557d978b6c\n \n 2\n \n \n ec2a8d18-2378-4fe0-8b68-2a31b57c481e\n \n 1\n \n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; + + + [SetUp] public void setup() @@ -67,27 +73,59 @@ namespace OpenSim.Framework.Serialization.Tests this.land.MediaID = new UUID("d4452578-2f25-4b97-a81b-819af559cfd7"); this.land.MediaURL = "http://videos.opensimulator.org/bumblebee.mp4"; this.land.OwnerID = new UUID("1b8eedf9-6d15-448b-8015-24286f1756bf"); + + this.landWithParcelAccessList = this.land.Copy(); + this.landWithParcelAccessList.ParcelAccessList.Clear(); + + ParcelManager.ParcelAccessEntry pae0 = new ParcelManager.ParcelAccessEntry(); + pae0.AgentID = new UUID("62d65d45-c91a-4f77-862c-46557d978b6c"); + pae0.Flags = AccessList.Ban; + pae0.Time = new DateTime(2009, 10, 01); + this.landWithParcelAccessList.ParcelAccessList.Add(pae0); + + ParcelManager.ParcelAccessEntry pae1 = new ParcelManager.ParcelAccessEntry(); + pae1.AgentID = new UUID("ec2a8d18-2378-4fe0-8b68-2a31b57c481e"); + pae1.Flags = AccessList.Access; + pae1.Time = new DateTime(2010, 10, 20); + this.landWithParcelAccessList.ParcelAccessList.Add(pae1); } /// + /// Test the LandDataSerializer.Serialize() method /// [Test] public void LandDataSerializerSerializeTest() { string serialized = LandDataSerializer.Serialize(this.land); Assert.That(serialized.Length > 0, "Serialize(LandData) returned empty string"); - Assert.That(serialized == this.preSerialized, "result of Serialize(LandData) does not match expected result"); + Assert.That(serialized == LandDataSerializerTest.preSerialized, + "result of Serialize(LandData) does not match expected result"); + + string serializedWithParcelAccessList = LandDataSerializer.Serialize(this.landWithParcelAccessList); + Assert.That(serializedWithParcelAccessList.Length > 0, + "Serialize(LandData) returned empty string for LandData object with ParcelAccessList"); + Assert.That(serializedWithParcelAccessList == LandDataSerializerTest.preSerializedWithParcelAccessList, + "result of Serialize(LandData) does not match expected result (pre-serialized with parcel access list"); } /// + /// Test the LandDataSerializer.Deserialize() method /// [Test] public void TestLandDataSerializerDeserializeFromStringTest() { - LandData reifiedLandData = LandDataSerializer.Deserialize(this.preSerialized); + LandData reifiedLandData = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerialized); Assert.That(reifiedLandData != null, "Deserialize(string) returned null"); Assert.That(reifiedLandData.GlobalID == this.land.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID"); Assert.That(reifiedLandData.Name == this.land.Name, "Reified LandData.Name != original LandData.Name"); + + LandData reifiedLandDataWithParcelAccessList = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerializedWithParcelAccessList); + Assert.That(reifiedLandDataWithParcelAccessList != null, + "Deserialize(string) returned null (pre-serialized with parcel access list)"); + Assert.That(reifiedLandDataWithParcelAccessList.GlobalID == this.landWithParcelAccessList.GlobalID, + "Reified LandData.GlobalID != original LandData.GlobalID (pre-serialized with parcel access list)"); + Assert.That(reifiedLandDataWithParcelAccessList.Name == this.landWithParcelAccessList.Name, + "Reified LandData.Name != original LandData.Name (pre-serialized with parcel access list)"); } } } -- cgit v1.1 From 2107b67f1b145f7718fdb1450be1a7b8dd1a0bf7 Mon Sep 17 00:00:00 2001 From: dr scofield (aka dirk husemann) Date: Fri, 2 Oct 2009 11:10:52 +0200 Subject: - cleaning up LandData/ILandObject capitalization issues - adding LandDataSerializer to OAR mechanics --- OpenSim/Framework/Serialization/ArchiveConstants.cs | 5 +++++ OpenSim/Framework/Serialization/TarArchiveWriter.cs | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index f6dedec..1cd80db 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -66,6 +66,11 @@ namespace OpenSim.Framework.Serialization public const string SETTINGS_PATH = "settings/"; /// + /// Path for region settings. + /// + public const string LANDDATA_PATH = "landdata/"; + + /// /// Path for user profiles /// public const string USERS_PATH = "userprofiles/"; diff --git a/OpenSim/Framework/Serialization/TarArchiveWriter.cs b/OpenSim/Framework/Serialization/TarArchiveWriter.cs index 7040870..20d0f7e 100644 --- a/OpenSim/Framework/Serialization/TarArchiveWriter.cs +++ b/OpenSim/Framework/Serialization/TarArchiveWriter.cs @@ -40,6 +40,7 @@ namespace OpenSim.Framework.Serialization //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); + protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); /// /// Binary writer for the underlying stream @@ -71,7 +72,7 @@ namespace OpenSim.Framework.Serialization /// public void WriteFile(string filePath, string data) { - WriteFile(filePath, m_asciiEncoding.GetBytes(data)); + WriteFile(filePath, m_utf8Encoding.GetBytes(data)); } /// -- cgit v1.1 From 0a259caeef6539867872b5abd17875487989900d Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Mon, 19 Oct 2009 15:48:07 +0900 Subject: Minor formatting cleanup. --- .../Serialization/External/LandDataSerializer.cs | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index a3bc5d1..ff0afc8 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -41,7 +41,7 @@ namespace OpenSim.Framework.Serialization.External public class LandDataSerializer { protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); - + /// /// Reify/deserialize landData /// @@ -52,7 +52,7 @@ namespace OpenSim.Framework.Serialization.External { return Deserialize(m_utf8Encoding.GetString(serializedLandData, 0, serializedLandData.Length)); } - + /// /// Reify/deserialize landData /// @@ -62,10 +62,10 @@ namespace OpenSim.Framework.Serialization.External public static LandData Deserialize(string serializedLandData) { LandData landData = new LandData(); - + StringReader sr = new StringReader(serializedLandData); XmlTextReader xtr = new XmlTextReader(sr); - + xtr.ReadStartElement("LandData"); landData.Area = Convert.ToInt32( xtr.ReadElementString("Area")); @@ -106,7 +106,7 @@ namespace OpenSim.Framework.Serialization.External pae.Time = Convert.ToDateTime( xtr.ReadElementString("Time")); pae.Flags = (AccessList)Convert.ToUInt32( xtr.ReadElementString("AccessList")); xtr.ReadEndElement(); - + landData.ParcelAccessList.Add(pae); } } @@ -122,13 +122,13 @@ namespace OpenSim.Framework.Serialization.External landData.OtherCleanTime = Convert.ToInt32( xtr.ReadElementString("OtherCleanTime")); xtr.ReadEndElement(); - + xtr.Close(); sr.Close(); - + return landData; } - + public static string Serialize(LandData landData) { StringWriter sw = new StringWriter(); @@ -137,8 +137,8 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteStartDocument(); xtw.WriteStartElement("LandData"); - - xtw.WriteElementString("Area", Convert.ToString(landData.Area)); + + xtw.WriteElementString("Area", Convert.ToString(landData.Area)); xtw.WriteElementString("AuctionID", Convert.ToString(landData.AuctionID)); xtw.WriteElementString("AuthBuyerID", landData.AuthBuyerID.ToString()); xtw.WriteElementString("Category", Convert.ToString((sbyte)landData.Category)); @@ -170,7 +170,7 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteEndElement(); } xtw.WriteEndElement(); - + xtw.WriteElementString("PassHours", Convert.ToString(landData.PassHours)); xtw.WriteElementString("PassPrice", Convert.ToString(landData.PassPrice)); xtw.WriteElementString("SalePrice", Convert.ToString(landData.SalePrice)); @@ -184,7 +184,7 @@ namespace OpenSim.Framework.Serialization.External xtw.Close(); sw.Close(); - + return sw.ToString(); } } -- cgit v1.1 From 1e1b2ab221851efc414678b7ea52ef2ca788ce9f Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 10 Jan 2010 10:40:07 -0800 Subject: * OMG! All but one references to UserProfileCacheService have been rerouted! * HG is seriously broken here * Compiles. Untested. --- .../Framework/Serialization/External/UserProfileSerializer.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs index fb269b7..de106b2 100644 --- a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs @@ -29,6 +29,7 @@ using System.IO; using System.Xml; using OpenMetaverse; using OpenSim.Framework; +using OpenSim.Services.Interfaces; namespace OpenSim.Framework.Serialization.External { @@ -40,7 +41,7 @@ namespace OpenSim.Framework.Serialization.External public const int MAJOR_VERSION = 0; public const int MINOR_VERSION = 1; - public static string Serialize(UserProfileData profile) + public static string Serialize(UserAccount profile) { StringWriter sw = new StringWriter(); XmlTextWriter xtw = new XmlTextWriter(sw); @@ -51,9 +52,9 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteAttributeString("major_version", MAJOR_VERSION.ToString()); xtw.WriteAttributeString("minor_version", MINOR_VERSION.ToString()); - xtw.WriteElementString("name", profile.Name); - xtw.WriteElementString("id", profile.ID.ToString()); - xtw.WriteElementString("about", profile.AboutText); + xtw.WriteElementString("name", profile.FirstName + " " + profile.LastName); + xtw.WriteElementString("id", profile.PrincipalID.ToString()); + xtw.WriteElementString("about", ""); // Not sure if we're storing this yet, need to take a look // xtw.WriteElementString("Url", profile.Url); -- cgit v1.1 From 53e83e5dbb3590cb9c858aa301665357d1511b30 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 10 Jan 2010 16:20:59 -0800 Subject: * Starting to clean the house... * Fixed circular dependency --- OpenSim/Framework/Serialization/External/UserProfileSerializer.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs index de106b2..a8ffa17 100644 --- a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs @@ -41,7 +41,7 @@ namespace OpenSim.Framework.Serialization.External public const int MAJOR_VERSION = 0; public const int MINOR_VERSION = 1; - public static string Serialize(UserAccount profile) + public static string Serialize(UUID userID, string firstName, string lastName) { StringWriter sw = new StringWriter(); XmlTextWriter xtw = new XmlTextWriter(sw); @@ -52,8 +52,8 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteAttributeString("major_version", MAJOR_VERSION.ToString()); xtw.WriteAttributeString("minor_version", MINOR_VERSION.ToString()); - xtw.WriteElementString("name", profile.FirstName + " " + profile.LastName); - xtw.WriteElementString("id", profile.PrincipalID.ToString()); + xtw.WriteElementString("name", firstName + " " + lastName); + xtw.WriteElementString("id", userID.ToString()); xtw.WriteElementString("about", ""); // Not sure if we're storing this yet, need to take a look -- cgit v1.1 From 68b7307f4f9c6390f4ad4326724247257409ab02 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 10 Jan 2010 16:34:01 -0800 Subject: Forgot to remove 'using' --- OpenSim/Framework/Serialization/External/UserProfileSerializer.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs index a8ffa17..f50b49a 100644 --- a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs @@ -29,7 +29,6 @@ using System.IO; using System.Xml; using OpenMetaverse; using OpenSim.Framework; -using OpenSim.Services.Interfaces; namespace OpenSim.Framework.Serialization.External { -- cgit v1.1 From 00800c59d35662d65aeb61a17de0d56fa6196509 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 12 Feb 2010 23:13:35 +0000 Subject: Apply last two patches from http://opensimulator.org/mantis/view.php?id=3522 These patch should allow people using systems that do not have their locale set to En_US or similar to use OpenSim without suffering effects such as being a million miles up in the air on login. The problem was caused by parsing strings without forcing that parse to be En_US (hence different decimal and digit group symbols were causing problems). Thanks very much to VikingErik for doing the legwork on this fix and phacelia for spotting it in the first place. --- .../External/RegionSettingsSerializer.cs | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs index b5901e1..6ba4c5a 100644 --- a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs +++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs @@ -109,7 +109,7 @@ namespace OpenSim.Framework.Serialization.External settings.AgentLimit = int.Parse(xtr.ReadElementContentAsString()); break; case "ObjectBonus": - settings.ObjectBonus = double.Parse(xtr.ReadElementContentAsString()); + settings.ObjectBonus = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); break; } } @@ -134,28 +134,28 @@ namespace OpenSim.Framework.Serialization.External settings.TerrainTexture4 = UUID.Parse(xtr.ReadElementContentAsString()); break; case "ElevationLowSW": - settings.Elevation1SW = double.Parse(xtr.ReadElementContentAsString()); + settings.Elevation1SW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); break; case "ElevationLowNW": - settings.Elevation1NW = double.Parse(xtr.ReadElementContentAsString()); + settings.Elevation1NW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); break; case "ElevationLowSE": - settings.Elevation1SE = double.Parse(xtr.ReadElementContentAsString()); + settings.Elevation1SE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); break; case "ElevationLowNE": - settings.Elevation1NE = double.Parse(xtr.ReadElementContentAsString()); + settings.Elevation1NE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); break; case "ElevationHighSW": - settings.Elevation2SW = double.Parse(xtr.ReadElementContentAsString()); + settings.Elevation2SW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); break; case "ElevationHighNW": - settings.Elevation2NW = double.Parse(xtr.ReadElementContentAsString()); + settings.Elevation2NW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); break; case "ElevationHighSE": - settings.Elevation2SE = double.Parse(xtr.ReadElementContentAsString()); + settings.Elevation2SE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); break; case "ElevationHighNE": - settings.Elevation2NE = double.Parse(xtr.ReadElementContentAsString()); + settings.Elevation2NE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); break; } } @@ -168,13 +168,13 @@ namespace OpenSim.Framework.Serialization.External switch (xtr.Name) { case "WaterHeight": - settings.WaterHeight = double.Parse(xtr.ReadElementContentAsString()); + settings.WaterHeight = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); break; case "TerrainRaiseLimit": - settings.TerrainRaiseLimit = double.Parse(xtr.ReadElementContentAsString()); + settings.TerrainRaiseLimit = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); break; case "TerrainLowerLimit": - settings.TerrainLowerLimit = double.Parse(xtr.ReadElementContentAsString()); + settings.TerrainLowerLimit = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); break; case "UseEstateSun": settings.UseEstateSun = bool.Parse(xtr.ReadElementContentAsString()); -- cgit v1.1 From 2bf1761ad8f7f4ea60fbcee65ae8782014672874 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 31 Mar 2010 19:51:17 +0100 Subject: When saving an oar/iar, don't attempt to write out the data byte array if it's empty On Mono 2.6 (and probably before) this causes a non-obvious IOException --- OpenSim/Framework/Serialization/TarArchiveWriter.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/TarArchiveWriter.cs b/OpenSim/Framework/Serialization/TarArchiveWriter.cs index 20d0f7e..0bd639f 100644 --- a/OpenSim/Framework/Serialization/TarArchiveWriter.cs +++ b/OpenSim/Framework/Serialization/TarArchiveWriter.cs @@ -208,7 +208,9 @@ namespace OpenSim.Framework.Serialization m_bw.Write(header); // Write out data - m_bw.Write(data); + // An IOException occurs if we try to write out an empty array in Mono 2.6 + if (data.Length > 0) + m_bw.Write(data); if (data.Length % 512 != 0) { -- cgit v1.1 From 4183cef4094364d28fd4497fdb4332ff4be34914 Mon Sep 17 00:00:00 2001 From: Teravus Ovares (Dan Olivares) Date: Wed, 5 May 2010 21:22:29 -0400 Subject: * Fixes LandDataSerializerTests on Windows by stripping CR from the serialization result since the reference serialization has LF only. * Added a bool result and then an Assert.That(result) because resharper was having a hard time with the equality compare in Assert.That. --- .../Serialization/Tests/LandDataSerializerTests.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs index 14e0462..70e87b3 100644 --- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -96,15 +96,19 @@ namespace OpenSim.Framework.Serialization.Tests [Test] public void LandDataSerializerSerializeTest() { - string serialized = LandDataSerializer.Serialize(this.land); + string serialized = LandDataSerializer.Serialize(this.land).Replace("\r\n", "\n"); Assert.That(serialized.Length > 0, "Serialize(LandData) returned empty string"); - Assert.That(serialized == LandDataSerializerTest.preSerialized, - "result of Serialize(LandData) does not match expected result"); - string serializedWithParcelAccessList = LandDataSerializer.Serialize(this.landWithParcelAccessList); - Assert.That(serializedWithParcelAccessList.Length > 0, + // adding a simple boolean variable because resharper nUnit integration doesn't like this + // XML data in the Assert.That statement. Not sure why. + bool result = (serialized == preSerialized); + Assert.That(result, "result of Serialize LandData does not match expected result"); + + string serializedWithParcelAccessList = LandDataSerializer.Serialize(this.landWithParcelAccessList).Replace("\r\n", "\n"); + Assert.That(serializedWithParcelAccessList.Length > 0, "Serialize(LandData) returned empty string for LandData object with ParcelAccessList"); - Assert.That(serializedWithParcelAccessList == LandDataSerializerTest.preSerializedWithParcelAccessList, + result = (serializedWithParcelAccessList == preSerializedWithParcelAccessList); + Assert.That(result, "result of Serialize(LandData) does not match expected result (pre-serialized with parcel access list"); } -- cgit v1.1 From 74ef1ed36f234d93aa3d58b1602344bcb3e00d6e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 21 May 2010 19:36:39 +0100 Subject: add prim item and test asset save in save oar unit test --- OpenSim/Framework/Serialization/TarArchiveWriter.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/TarArchiveWriter.cs b/OpenSim/Framework/Serialization/TarArchiveWriter.cs index 0bd639f..fca909f 100644 --- a/OpenSim/Framework/Serialization/TarArchiveWriter.cs +++ b/OpenSim/Framework/Serialization/TarArchiveWriter.cs @@ -28,7 +28,9 @@ using System; using System.Collections.Generic; using System.IO; +using System.Reflection; using System.Text; +using log4net; namespace OpenSim.Framework.Serialization { @@ -37,7 +39,7 @@ namespace OpenSim.Framework.Serialization /// public class TarArchiveWriter { - //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); @@ -148,6 +150,9 @@ namespace OpenSim.Framework.Serialization /// protected void WriteEntry(string filePath, byte[] data, char fileType) { +// m_log.DebugFormat( +// "[TAR ARCHIVE WRITER]: Data for {0} is {1} bytes", filePath, (null == data ? "null" : data.Length.ToString())); + byte[] header = new byte[512]; // file path field (100) -- cgit v1.1 From 721c1085da22229f4d40529dd2738a2cf62a91b7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 21 May 2010 20:43:11 +0100 Subject: make oar object filename/pathname creation a helper method reused in both tests and oar code reduction in checking is outweighed by greater test clarity --- .../Framework/Serialization/ArchiveConstants.cs | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index 1cd80db..475a9de 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; using System.Collections.Generic; using OpenMetaverse; @@ -85,6 +86,11 @@ namespace OpenSim.Framework.Serialization /// public const string INVENTORY_NODE_NAME_COMPONENT_SEPARATOR = "__"; + /// + /// Template used for creating filenames in OpenSim Archives. + /// + public const string OAR_OBJECT_FILENAME_TEMPLATE = "{0}_{1:000}-{2:000}-{3:000}__{4}.xml"; + /// /// Extensions used for asset types in the archive /// @@ -139,5 +145,32 @@ namespace OpenSim.Framework.Serialization EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.tga"] = (sbyte)AssetType.TextureTGA; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"] = (sbyte)AssetType.TrashFolder; } + + /// + /// Create the filename used to store an object in an OpenSim Archive. + /// + /// + /// + /// + /// + public static string CreateOarObjectFilename(string objectName, UUID uuid, Vector3 pos) + { + return string.Format( + OAR_OBJECT_FILENAME_TEMPLATE, objectName, + Math.Round(pos.X), Math.Round(pos.Y), Math.Round(pos.Z), + uuid); + } + + /// + /// Create the path used to store an object in an OpenSim Archives. + /// + /// + /// + /// + /// + public static string CreateOarObjectPath(string objectName, UUID uuid, Vector3 pos) + { + return OBJECTS_PATH + CreateOarObjectFilename(objectName, uuid, pos); + } } } -- cgit v1.1 From 5925aac859ee493fd7f6b10026c84a6a22626c79 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 30 Jun 2010 00:10:44 +0100 Subject: Add --merge switch to load iar. When this switch is used, iar folders are merged with existing same-name user inventory folders. This makes it a little easier to back and restore entire individual user inventories, among other things Added unit test to check behaviour --- .../Framework/Serialization/ArchiveConstants.cs | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index 475a9de..3143e3b 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.Text; using OpenMetaverse; namespace OpenSim.Framework.Serialization @@ -171,6 +172,30 @@ namespace OpenSim.Framework.Serialization public static string CreateOarObjectPath(string objectName, UUID uuid, Vector3 pos) { return OBJECTS_PATH + CreateOarObjectFilename(objectName, uuid, pos); - } + } + + /// + /// Extract a plain path from an IAR path + /// + /// + /// + public static string ExtractPlainPathFromIarPath(string iarPath) + { + List plainDirs = new List(); + + string[] iarDirs = iarPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); + + foreach (string iarDir in iarDirs) + { + if (!iarDir.Contains(ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR)) + plainDirs.Add(iarDir); + + int i = iarDir.LastIndexOf(ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR); + + plainDirs.Add(iarDir.Remove(i)); + } + + return string.Join("/", plainDirs.ToArray()); + } } -} +} \ No newline at end of file -- cgit v1.1 From 6a0a878f7c268c6f248588895e232e3d14eb6eb3 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sun, 5 Sep 2010 14:16:42 +0200 Subject: Remove "Dwell" support from core and replace it with calls to methods on IDwellModule --- OpenSim/Framework/Serialization/External/LandDataSerializer.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index ff0afc8..fc0387b 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -118,7 +118,8 @@ namespace OpenSim.Framework.Serialization.External landData.SnapshotID = UUID.Parse( xtr.ReadElementString("SnapshotID")); landData.UserLocation = Vector3.Parse( xtr.ReadElementString("UserLocation")); landData.UserLookAt = Vector3.Parse( xtr.ReadElementString("UserLookAt")); - landData.Dwell = Convert.ToInt32( xtr.ReadElementString("Dwell")); + // No longer used here + xtr.ReadElementString("Dwell"); landData.OtherCleanTime = Convert.ToInt32( xtr.ReadElementString("OtherCleanTime")); xtr.ReadEndElement(); @@ -177,7 +178,7 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("SnapshotID", landData.SnapshotID.ToString()); xtw.WriteElementString("UserLocation", landData.UserLocation.ToString()); xtw.WriteElementString("UserLookAt", landData.UserLookAt.ToString()); - xtw.WriteElementString("Dwell", Convert.ToString(landData.Dwell)); + xtw.WriteElementString("Dwell", "0"); xtw.WriteElementString("OtherCleanTime", Convert.ToString(landData.OtherCleanTime)); xtw.WriteEndElement(); -- cgit v1.1 From f1f0bc23f4501ba99035283d3407ddad2b21b785 Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Sun, 12 Sep 2010 13:43:49 -0400 Subject: Formatting cleanup. --- OpenSim/Framework/Serialization/ArchiveConstants.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index 3143e3b..7a9b33d 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -157,9 +157,9 @@ namespace OpenSim.Framework.Serialization public static string CreateOarObjectFilename(string objectName, UUID uuid, Vector3 pos) { return string.Format( - OAR_OBJECT_FILENAME_TEMPLATE, objectName, + OAR_OBJECT_FILENAME_TEMPLATE, objectName, Math.Round(pos.X), Math.Round(pos.Y), Math.Round(pos.Z), - uuid); + uuid); } /// @@ -171,9 +171,9 @@ namespace OpenSim.Framework.Serialization /// public static string CreateOarObjectPath(string objectName, UUID uuid, Vector3 pos) { - return OBJECTS_PATH + CreateOarObjectFilename(objectName, uuid, pos); - } - + return OBJECTS_PATH + CreateOarObjectFilename(objectName, uuid, pos); + } + /// /// Extract a plain path from an IAR path /// @@ -184,18 +184,18 @@ namespace OpenSim.Framework.Serialization List plainDirs = new List(); string[] iarDirs = iarPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); - + foreach (string iarDir in iarDirs) { if (!iarDir.Contains(ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR)) plainDirs.Add(iarDir); - + int i = iarDir.LastIndexOf(ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR); plainDirs.Add(iarDir.Remove(i)); } - - return string.Join("/", plainDirs.ToArray()); + + return string.Join("/", plainDirs.ToArray()); } } -} \ No newline at end of file +} -- cgit v1.1 From 1064e743beb3095dcfcfc22ae341f7efba48b648 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 22 Oct 2010 21:12:22 +0100 Subject: Allow OARs and IARs to save and load meshes. Save and reload appears okay for the duck mesh at https://collada.org/owl/download.php?sess=0&parent=126&expand=1&order=name&curview=0&binary=1&id=698/ However, one attempt at trying to load a more complicated scene failed (errors on console, only triangles appearing in mesh viewer). Not sure if this is really and OAR load problem. Needs more investigation. --- OpenSim/Framework/Serialization/ArchiveConstants.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index 7a9b33d..2c5e001 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -112,6 +112,7 @@ namespace OpenSim.Framework.Serialization ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LostAndFoundFolder] = ASSET_EXTENSION_SEPARATOR + "lostandfoundfolder.txt"; // Not sure if we'll ever see this ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LSLBytecode] = ASSET_EXTENSION_SEPARATOR + "bytecode.lso"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LSLText] = ASSET_EXTENSION_SEPARATOR + "script.lsl"; + ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Mesh] = ASSET_EXTENSION_SEPARATOR + "mesh.llmesh"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Notecard] = ASSET_EXTENSION_SEPARATOR + "notecard.txt"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Object] = ASSET_EXTENSION_SEPARATOR + "object.xml"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.RootFolder] = ASSET_EXTENSION_SEPARATOR + "rootfolder.txt"; // Not sure if we'll ever see this @@ -135,6 +136,7 @@ namespace OpenSim.Framework.Serialization EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "lostandfoundfolder.txt"] = (sbyte)AssetType.LostAndFoundFolder; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "bytecode.lso"] = (sbyte)AssetType.LSLBytecode; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "script.lsl"] = (sbyte)AssetType.LSLText; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "mesh.llmesh"] = (sbyte)AssetType.Mesh; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "notecard.txt"] = (sbyte)AssetType.Notecard; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "object.xml"] = (sbyte)AssetType.Object; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "rootfolder.txt"] = (sbyte)AssetType.RootFolder; -- cgit v1.1 From ca8d0157333823b549c7ae36b40ea3c05045fc25 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 27 Nov 2010 11:40:54 -0800 Subject: Changed the parser for InventoryItem deserialization. Moved some utility functions around. --- .../External/UserInventoryItemSerializer.cs | 198 +++++++++++++++++---- 1 file changed, 168 insertions(+), 30 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index 862cc72..df9af32 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -26,9 +26,13 @@ */ using System; +using System.Collections.Generic; using System.IO; +using System.Reflection; using System.Text; using System.Xml; + +using log4net; using OpenMetaverse; using OpenSim.Framework; @@ -40,6 +44,133 @@ namespace OpenSim.Framework.Serialization.External /// XXX: Please do not use yet. public class UserInventoryItemSerializer { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private delegate void InventoryItemXmlProcessor(InventoryItemBase item, XmlTextReader reader); + private static Dictionary m_InventoryItemXmlProcessors = new Dictionary(); + + #region InventoryItemBase Processor initialization + static UserInventoryItemSerializer() + { + m_InventoryItemXmlProcessors.Add("Name", ProcessName); + m_InventoryItemXmlProcessors.Add("ID", ProcessID); + m_InventoryItemXmlProcessors.Add("InvType", ProcessInvType); + m_InventoryItemXmlProcessors.Add("CreatorUUID", ProcessCreatorUUID); + m_InventoryItemXmlProcessors.Add("CreationDate", ProcessCreationDate); + m_InventoryItemXmlProcessors.Add("Owner", ProcessOwner); + m_InventoryItemXmlProcessors.Add("Description", ProcessDescription); + m_InventoryItemXmlProcessors.Add("AssetType", ProcessAssetType); + m_InventoryItemXmlProcessors.Add("AssetID", ProcessAssetID); + m_InventoryItemXmlProcessors.Add("SaleType", ProcessSaleType); + m_InventoryItemXmlProcessors.Add("SalePrice", ProcessSalePrice); + m_InventoryItemXmlProcessors.Add("BasePermissions", ProcessBasePermissions); + m_InventoryItemXmlProcessors.Add("CurrentPermissions", ProcessCurrentPermissions); + m_InventoryItemXmlProcessors.Add("EveryOnePermissions", ProcessEveryOnePermissions); + m_InventoryItemXmlProcessors.Add("NextPermissions", ProcessNextPermissions); + m_InventoryItemXmlProcessors.Add("Flags", ProcessFlags); + m_InventoryItemXmlProcessors.Add("GroupID", ProcessGroupID); + m_InventoryItemXmlProcessors.Add("GroupOwned", ProcessGroupOwned); + } + #endregion + + #region InventoryItemBase Processors + private static void ProcessName(InventoryItemBase item, XmlTextReader reader) + { + item.Name = reader.ReadElementContentAsString("Name", String.Empty); + } + + private static void ProcessID(InventoryItemBase item, XmlTextReader reader) + { + item.ID = Util.ReadUUID(reader, "ID"); + } + + private static void ProcessInvType(InventoryItemBase item, XmlTextReader reader) + { + item.InvType = reader.ReadElementContentAsInt("InvType", String.Empty); + } + + private static void ProcessCreatorUUID(InventoryItemBase item, XmlTextReader reader) + { + item.CreatorId = reader.ReadElementContentAsString("CreatorUUID", String.Empty); + } + + private static void ProcessCreationDate(InventoryItemBase item, XmlTextReader reader) + { + item.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty); + } + + private static void ProcessOwner(InventoryItemBase item, XmlTextReader reader) + { + item.Owner = Util.ReadUUID(reader, "Owner"); + } + + private static void ProcessDescription(InventoryItemBase item, XmlTextReader reader) + { + item.Description = reader.ReadElementContentAsString("Description", String.Empty); + } + + private static void ProcessAssetType(InventoryItemBase item, XmlTextReader reader) + { + item.AssetType = reader.ReadElementContentAsInt("AssetType", String.Empty); + } + + private static void ProcessAssetID(InventoryItemBase item, XmlTextReader reader) + { + item.AssetID = Util.ReadUUID(reader, "AssetID"); + } + + private static void ProcessSaleType(InventoryItemBase item, XmlTextReader reader) + { + item.SaleType = (byte)reader.ReadElementContentAsInt("SaleType", String.Empty); + } + + private static void ProcessSalePrice(InventoryItemBase item, XmlTextReader reader) + { + item.SalePrice = reader.ReadElementContentAsInt("SalePrice", String.Empty); + } + + private static void ProcessBasePermissions(InventoryItemBase item, XmlTextReader reader) + { + item.BasePermissions = (uint)reader.ReadElementContentAsInt("BasePermissions", String.Empty); + } + + private static void ProcessCurrentPermissions(InventoryItemBase item, XmlTextReader reader) + { + item.CurrentPermissions = (uint)reader.ReadElementContentAsInt("CurrentPermissions", String.Empty); + } + + private static void ProcessEveryOnePermissions(InventoryItemBase item, XmlTextReader reader) + { + item.EveryOnePermissions = (uint)reader.ReadElementContentAsInt("EveryOnePermissions", String.Empty); + } + + private static void ProcessNextPermissions(InventoryItemBase item, XmlTextReader reader) + { + item.NextPermissions = (uint)reader.ReadElementContentAsInt("NextPermissions", String.Empty); + } + + private static void ProcessFlags(InventoryItemBase item, XmlTextReader reader) + { + item.Flags = (uint)reader.ReadElementContentAsInt("Flags", String.Empty); + } + + private static void ProcessGroupID(InventoryItemBase item, XmlTextReader reader) + { + item.GroupID = Util.ReadUUID(reader, "GroupID"); + } + + private static void ProcessGroupOwned(InventoryItemBase item, XmlTextReader reader) + { + //item.GroupOwned = reader.ReadElementContentAsBoolean("GroupOwned", String.Empty); + // We don't do that, because ReadElementContentAsBoolean assumes lower case strings, + // and they may not be lower case + reader.ReadStartElement(); // GroupOwned + item.GroupOwned = Boolean.Parse(reader.ReadContentAsString().ToLower()); + reader.ReadEndElement(); + } + + #endregion + /// /// Deserialize item /// @@ -60,37 +191,44 @@ namespace OpenSim.Framework.Serialization.External public static InventoryItemBase Deserialize(string serialization) { InventoryItemBase item = new InventoryItemBase(); - - StringReader sr = new StringReader(serialization); - XmlTextReader xtr = new XmlTextReader(sr); - - xtr.ReadStartElement("InventoryItem"); - - item.Name = xtr.ReadElementString("Name"); - item.ID = UUID.Parse( xtr.ReadElementString("ID")); - item.InvType = Convert.ToInt32( xtr.ReadElementString("InvType")); - item.CreatorId = xtr.ReadElementString("CreatorUUID"); - item.CreationDate = Convert.ToInt32( xtr.ReadElementString("CreationDate")); - item.Owner = UUID.Parse( xtr.ReadElementString("Owner")); - item.Description = xtr.ReadElementString("Description"); - item.AssetType = Convert.ToInt32( xtr.ReadElementString("AssetType")); - item.AssetID = UUID.Parse( xtr.ReadElementString("AssetID")); - item.SaleType = Convert.ToByte( xtr.ReadElementString("SaleType")); - item.SalePrice = Convert.ToInt32( xtr.ReadElementString("SalePrice")); - item.BasePermissions = Convert.ToUInt32( xtr.ReadElementString("BasePermissions")); - item.CurrentPermissions = Convert.ToUInt32( xtr.ReadElementString("CurrentPermissions")); - item.EveryOnePermissions = Convert.ToUInt32( xtr.ReadElementString("EveryOnePermissions")); - item.NextPermissions = Convert.ToUInt32( xtr.ReadElementString("NextPermissions")); - item.Flags = Convert.ToUInt32( xtr.ReadElementString("Flags")); - item.GroupID = UUID.Parse( xtr.ReadElementString("GroupID")); - item.GroupOwned = Convert.ToBoolean(xtr.ReadElementString("GroupOwned")); - - xtr.ReadEndElement(); - - xtr.Close(); - sr.Close(); - + + using (XmlTextReader reader = new XmlTextReader(new StringReader(serialization))) + { + reader.ReadStartElement("InventoryItem"); + + string nodeName = string.Empty; + while (reader.NodeType != XmlNodeType.EndElement) + { + nodeName = reader.Name; + InventoryItemXmlProcessor p = null; + if (m_InventoryItemXmlProcessors.TryGetValue(reader.Name, out p)) + { + //m_log.DebugFormat("[XXX] Processing: {0}", reader.Name); + try + { + p(item, reader); + } + catch (Exception e) + { + m_log.DebugFormat("[InventoryItemSerializer]: exception while parsing {0}: {1}", nodeName, e); + if (reader.NodeType == XmlNodeType.EndElement) + reader.Read(); + } + } + else + { + // m_log.DebugFormat("[InventoryItemSerializer]: caught unknown element {0}", nodeName); + reader.ReadOuterXml(); // ignore + } + + } + + reader.ReadEndElement(); // InventoryItem + } + + //m_log.DebugFormat("[XXX]: parsed InventoryItemBase {0} - {1}", obj.Name, obj.UUID); return item; + } public static string Serialize(InventoryItemBase inventoryItem) -- cgit v1.1 From f86c438653fc3c8356a8f0c43a055b1928183f02 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 29 Nov 2010 08:43:33 -0800 Subject: Preservation of creator information now also working in IARs. Cleaned up usage help. Moved Osp around, deleted unnecessary OspInventoryWrapperPlugin, added manipulation of SOP's xml representation in a generic ExternalRepresentationUtils function. --- .../External/ExternalRepresentationUtils.cs | 87 ++++++++++ .../Serialization/External/OspResolver.cs | 177 +++++++++++++++++++++ .../External/UserInventoryItemSerializer.cs | 39 ++++- 3 files changed, 295 insertions(+), 8 deletions(-) create mode 100644 OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs create mode 100644 OpenSim/Framework/Serialization/External/OspResolver.cs (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs new file mode 100644 index 0000000..5c0630c --- /dev/null +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -0,0 +1,87 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml; + +using OpenMetaverse; +using OpenSim.Services.Interfaces; + +namespace OpenSim.Framework.Serialization.External +{ + public class ExternalRepresentationUtils + { + public static string RewriteSOP(string xml, string profileURL, IUserAccountService userService, UUID scopeID) + { + if (xml == string.Empty || profileURL == string.Empty || userService == null) + return xml; + + XmlDocument doc = new XmlDocument(); + doc.LoadXml(xml); + XmlNodeList sops = doc.GetElementsByTagName("SceneObjectPart"); + + foreach (XmlNode sop in sops) + { + UserAccount creator = null; + bool hasCreatorData = false; + XmlNodeList nodes = sop.ChildNodes; + foreach (XmlNode node in nodes) + { + if (node.Name == "CreatorID") + { + UUID uuid = UUID.Zero; + UUID.TryParse(node.InnerText, out uuid); + creator = userService.GetUserAccount(scopeID, uuid); + } + if (node.Name == "CreatorData" && node.InnerText != null && node.InnerText != string.Empty) + hasCreatorData = true; + + //if (node.Name == "OwnerID") + //{ + // UserAccount owner = GetUser(node.InnerText); + // if (owner != null) + // node.InnerText = m_ProfileServiceURL + "/" + node.InnerText + "/" + owner.FirstName + " " + owner.LastName; + //} + } + if (!hasCreatorData && creator != null) + { + XmlElement creatorData = doc.CreateElement("CreatorData"); + creatorData.InnerText = profileURL + "/" + creator.PrincipalID + ";" + creator.FirstName + " " + creator.LastName; + sop.AppendChild(creatorData); + } + } + + using (StringWriter wr = new StringWriter()) + { + doc.Save(wr); + return wr.ToString(); + } + + } + } +} diff --git a/OpenSim/Framework/Serialization/External/OspResolver.cs b/OpenSim/Framework/Serialization/External/OspResolver.cs new file mode 100644 index 0000000..53c35ff --- /dev/null +++ b/OpenSim/Framework/Serialization/External/OspResolver.cs @@ -0,0 +1,177 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System.Reflection; +using System.Text; +using log4net; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Services.Interfaces; + +namespace OpenSim.Framework.Serialization +{ + /// + /// Resolves OpenSim Profile Anchors (OSPA). An OSPA is a string used to provide information for + /// identifying user profiles or supplying a simple name if no profile is available. + /// + public class OspResolver + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + public const string OSPA_PREFIX = "ospa:"; + public const string OSPA_NAME_KEY = "n"; + public const string OSPA_NAME_VALUE_SEPARATOR = " "; + public const string OSPA_TUPLE_SEPARATOR = "|"; + public static readonly char[] OSPA_TUPLE_SEPARATOR_ARRAY = OSPA_TUPLE_SEPARATOR.ToCharArray(); + public const string OSPA_PAIR_SEPARATOR = "="; + + /// + /// Make an OSPA given a user UUID + /// + /// + /// + /// The OSPA. Null if a user with the given UUID could not be found. + public static string MakeOspa(UUID userId, IUserAccountService userService) + { + UserAccount account = userService.GetUserAccount(UUID.Zero, userId); + if (account != null) + return MakeOspa(account.FirstName, account.LastName); + + return null; + } + + /// + /// Make an OSPA given a user name + /// + /// + /// + public static string MakeOspa(string firstName, string lastName) + { + return + OSPA_PREFIX + OSPA_NAME_KEY + OSPA_PAIR_SEPARATOR + firstName + OSPA_NAME_VALUE_SEPARATOR + lastName; + } + + /// + /// Resolve an osp string into the most suitable internal OpenSim identifier. + /// + /// + /// In some cases this will be a UUID if a suitable profile exists on the system. In other cases, this may + /// just return the same identifier after creating a temporary profile. + /// + /// + /// + /// + /// A suitable UUID for use in Second Life client communication. If the string was not a valid ospa, then UUID.Zero + /// is returned. + /// + public static UUID ResolveOspa(string ospa, IUserAccountService userService) + { + if (!ospa.StartsWith(OSPA_PREFIX)) + return UUID.Zero; + +// m_log.DebugFormat("[OSP RESOLVER]: Resolving {0}", ospa); + + string ospaMeat = ospa.Substring(OSPA_PREFIX.Length); + string[] ospaTuples = ospaMeat.Split(OSPA_TUPLE_SEPARATOR_ARRAY); + + foreach (string tuple in ospaTuples) + { + int tupleSeparatorIndex = tuple.IndexOf(OSPA_PAIR_SEPARATOR); + + if (tupleSeparatorIndex < 0) + { + m_log.WarnFormat("[OSP RESOLVER]: Ignoring non-tuple component {0} in OSPA {1}", tuple, ospa); + continue; + } + + string key = tuple.Remove(tupleSeparatorIndex).Trim(); + string value = tuple.Substring(tupleSeparatorIndex + 1).Trim(); + + if (OSPA_NAME_KEY == key) + return ResolveOspaName(value, userService); + } + + return UUID.Zero; + } + + /// + /// Hash a profile name into a UUID + /// + /// + /// + public static UUID HashName(string name) + { + return new UUID(Utils.MD5(Encoding.Unicode.GetBytes(name)), 0); + } + + /// + /// Resolve an OSPI name by querying existing persistent user profiles. If there is no persistent user profile + /// then a temporary user profile is inserted in the cache. + /// + /// + /// + /// + /// An OpenSim internal identifier for the name given. Returns null if the name was not valid + /// + protected static UUID ResolveOspaName(string name, IUserAccountService userService) + { + if (userService == null) + return UUID.Zero; + + int nameSeparatorIndex = name.IndexOf(OSPA_NAME_VALUE_SEPARATOR); + + if (nameSeparatorIndex < 0) + { + m_log.WarnFormat("[OSP RESOLVER]: Ignoring unseparated name {0}", name); + return UUID.Zero; + } + + string firstName = name.Remove(nameSeparatorIndex).TrimEnd(); + string lastName = name.Substring(nameSeparatorIndex + 1).TrimStart(); + + UserAccount account = userService.GetUserAccount(UUID.Zero, firstName, lastName); + if (account != null) + return account.PrincipalID; + + // XXX: Disable temporary user profile creation for now as implementation is incomplete - justincc + /* + UserProfileData tempUserProfile = new UserProfileData(); + tempUserProfile.FirstName = firstName; + tempUserProfile.SurName = lastName; + tempUserProfile.ID = HashName(tempUserProfile.Name); + + m_log.DebugFormat( + "[OSP RESOLVER]: Adding temporary user profile for {0} {1}", tempUserProfile.Name, tempUserProfile.ID); + commsManager.UserService.AddTemporaryUserProfile(tempUserProfile); + + return tempUserProfile.ID; + */ + + return UUID.Zero; + } + } +} diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index df9af32..d5e84c7 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -35,6 +35,7 @@ using System.Xml; using log4net; using OpenMetaverse; using OpenSim.Framework; +using OpenSim.Services.Interfaces; namespace OpenSim.Framework.Serialization.External { @@ -56,6 +57,8 @@ namespace OpenSim.Framework.Serialization.External m_InventoryItemXmlProcessors.Add("ID", ProcessID); m_InventoryItemXmlProcessors.Add("InvType", ProcessInvType); m_InventoryItemXmlProcessors.Add("CreatorUUID", ProcessCreatorUUID); + m_InventoryItemXmlProcessors.Add("CreatorID", ProcessCreatorID); + m_InventoryItemXmlProcessors.Add("CreatorData", ProcessCreatorData); m_InventoryItemXmlProcessors.Add("CreationDate", ProcessCreationDate); m_InventoryItemXmlProcessors.Add("Owner", ProcessOwner); m_InventoryItemXmlProcessors.Add("Description", ProcessDescription); @@ -94,6 +97,12 @@ namespace OpenSim.Framework.Serialization.External item.CreatorId = reader.ReadElementContentAsString("CreatorUUID", String.Empty); } + private static void ProcessCreatorID(InventoryItemBase item, XmlTextReader reader) + { + // when it exists, this overrides the previous + item.CreatorId = reader.ReadElementContentAsString("CreatorID", String.Empty); + } + private static void ProcessCreationDate(InventoryItemBase item, XmlTextReader reader) { item.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty); @@ -161,12 +170,12 @@ namespace OpenSim.Framework.Serialization.External private static void ProcessGroupOwned(InventoryItemBase item, XmlTextReader reader) { - //item.GroupOwned = reader.ReadElementContentAsBoolean("GroupOwned", String.Empty); - // We don't do that, because ReadElementContentAsBoolean assumes lower case strings, - // and they may not be lower case - reader.ReadStartElement(); // GroupOwned - item.GroupOwned = Boolean.Parse(reader.ReadContentAsString().ToLower()); - reader.ReadEndElement(); + item.GroupOwned = Util.ReadBoolean(reader); + } + + private static void ProcessCreatorData(InventoryItemBase item, XmlTextReader reader) + { + item.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty); } #endregion @@ -231,7 +240,7 @@ namespace OpenSim.Framework.Serialization.External } - public static string Serialize(InventoryItemBase inventoryItem) + public static string Serialize(InventoryItemBase inventoryItem, Dictionary options, IUserAccountService userAccountService) { StringWriter sw = new StringWriter(); XmlTextWriter writer = new XmlTextWriter(sw); @@ -250,7 +259,7 @@ namespace OpenSim.Framework.Serialization.External writer.WriteString(inventoryItem.InvType.ToString()); writer.WriteEndElement(); writer.WriteStartElement("CreatorUUID"); - writer.WriteString(inventoryItem.CreatorId); + writer.WriteString(OspResolver.MakeOspa(inventoryItem.CreatorIdAsUuid, userAccountService)); writer.WriteEndElement(); writer.WriteStartElement("CreationDate"); writer.WriteString(inventoryItem.CreationDate.ToString()); @@ -294,6 +303,20 @@ namespace OpenSim.Framework.Serialization.External writer.WriteStartElement("GroupOwned"); writer.WriteString(inventoryItem.GroupOwned.ToString()); writer.WriteEndElement(); + if (inventoryItem.CreatorData != null && inventoryItem.CreatorData != string.Empty) + writer.WriteElementString("CreatorData", inventoryItem.CreatorData); + else if (options.ContainsKey("profile")) + { + if (userAccountService != null) + { + UserAccount account = userAccountService.GetUserAccount(UUID.Zero, inventoryItem.CreatorIdAsUuid); + if (account != null) + { + writer.WriteElementString("CreatorData", (string)options["profile"] + "/" + inventoryItem.CreatorIdAsUuid + ";" + account.FirstName + " " + account.LastName); + } + writer.WriteElementString("CreatorID", inventoryItem.CreatorId); + } + } writer.WriteEndElement(); -- cgit v1.1 From 49b59fffee54bb7aa7db2382ba564c99368945d4 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 29 Nov 2010 09:57:41 -0800 Subject: Fix unit test. --- OpenSim/Framework/Serialization/External/OspResolver.cs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/OspResolver.cs b/OpenSim/Framework/Serialization/External/OspResolver.cs index 53c35ff..7e3dd1b 100644 --- a/OpenSim/Framework/Serialization/External/OspResolver.cs +++ b/OpenSim/Framework/Serialization/External/OspResolver.cs @@ -57,6 +57,12 @@ namespace OpenSim.Framework.Serialization /// The OSPA. Null if a user with the given UUID could not be found. public static string MakeOspa(UUID userId, IUserAccountService userService) { + if (userService == null) + { + m_log.Warn("[OSP RESOLVER]: UserService is null"); + return userId.ToString(); + } + UserAccount account = userService.GetUserAccount(UUID.Zero, userId); if (account != null) return MakeOspa(account.FirstName, account.LastName); -- cgit v1.1 From 7d24dbca3c85cafe182648139ab132563e3e1cdd Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 1 Dec 2010 16:01:22 -0800 Subject: Added some comments. Better than listening to the boring speaker... --- .../Serialization/External/ExternalRepresentationUtils.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index 5c0630c..6e8c2ee 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -34,8 +34,20 @@ using OpenSim.Services.Interfaces; namespace OpenSim.Framework.Serialization.External { + /// + /// Utilities for manipulating external representations of data structures in OpenSim + /// public class ExternalRepresentationUtils { + /// + /// Takes a XML representation of a SceneObjectPart and returns another XML representation + /// with creator data added to it. + /// + /// The SceneObjectPart represented in XML2 + /// The URL of the profile service 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 xml, string profileURL, IUserAccountService userService, UUID scopeID) { if (xml == string.Empty || profileURL == string.Empty || userService == null) -- cgit v1.1 From 8fdc810a2329063d136458dff5a4c7d307db3feb Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 3 Feb 2011 04:07:36 -0800 Subject: Addresses mantis #5360: CreatorData was being written as long as it wasn't null. This made iars backwards incompatible when some items had non-null foreign creators. This patch adds an explicit option (-c) to preserve foreign creator information. --- OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index d5e84c7..f138437 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -303,7 +303,7 @@ namespace OpenSim.Framework.Serialization.External writer.WriteStartElement("GroupOwned"); writer.WriteString(inventoryItem.GroupOwned.ToString()); writer.WriteEndElement(); - if (inventoryItem.CreatorData != null && inventoryItem.CreatorData != string.Empty) + if (options.ContainsKey("creators") && inventoryItem.CreatorData != null && inventoryItem.CreatorData != string.Empty) writer.WriteElementString("CreatorData", inventoryItem.CreatorData); else if (options.ContainsKey("profile")) { -- cgit v1.1 From 8a2360bf815d4d78fcff34a69dec24782494bd2e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 9 Mar 2011 01:21:31 +0000 Subject: Simplify TestLoadIarV0_1AbsentUsers() to use common IAR test setup. Make static dictionaries on NullUserAccountData instance instead to stop user accounts being carried over between tests --- .../Framework/Serialization/External/OspResolver.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/OspResolver.cs b/OpenSim/Framework/Serialization/External/OspResolver.cs index 7e3dd1b..d31d27c 100644 --- a/OpenSim/Framework/Serialization/External/OspResolver.cs +++ b/OpenSim/Framework/Serialization/External/OspResolver.cs @@ -66,6 +66,8 @@ namespace OpenSim.Framework.Serialization UserAccount account = userService.GetUserAccount(UUID.Zero, userId); if (account != null) return MakeOspa(account.FirstName, account.LastName); +// else +// m_log.WarnFormat("[OSP RESOLVER]: No user account for {0}", userId); return null; } @@ -77,6 +79,8 @@ namespace OpenSim.Framework.Serialization /// public static string MakeOspa(string firstName, string lastName) { +// m_log.DebugFormat("[OSP RESOLVER]: Making OSPA for {0} {1}", firstName, lastName); + return OSPA_PREFIX + OSPA_NAME_KEY + OSPA_PAIR_SEPARATOR + firstName + OSPA_NAME_VALUE_SEPARATOR + lastName; } @@ -97,7 +101,10 @@ namespace OpenSim.Framework.Serialization public static UUID ResolveOspa(string ospa, IUserAccountService userService) { if (!ospa.StartsWith(OSPA_PREFIX)) - return UUID.Zero; + { +// m_log.DebugFormat("[OSP RESOLVER]: ResolveOspa() got unrecognized format [{0}]", ospa); + return UUID.Zero; + } // m_log.DebugFormat("[OSP RESOLVER]: Resolving {0}", ospa); @@ -161,7 +168,17 @@ namespace OpenSim.Framework.Serialization UserAccount account = userService.GetUserAccount(UUID.Zero, firstName, lastName); if (account != null) + { +// m_log.DebugFormat( +// "[OSP RESOLVER]: Found user account with uuid {0} for {1} {2}", +// account.PrincipalID, firstName, lastName); + return account.PrincipalID; + } +// else +// { +// m_log.DebugFormat("[OSP RESOLVER]: No resolved OSPA user account for {0}", name); +// } // XXX: Disable temporary user profile creation for now as implementation is incomplete - justincc /* -- cgit v1.1 From 0e465da187c93e7ff21f91742f75ee9f3b76b04e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 5 Apr 2011 21:25:54 +0100 Subject: remove now unused individual LandData prim counts. However, the calls to the land management module to record prims need to remain, since they were also being used to return owner object lists, etc. This is probably why prim counts were being done there in the first place. --- OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs index 70e87b3..c69c89d 100644 --- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -42,10 +42,7 @@ namespace OpenSim.Framework.Serialization.Tests private LandData landWithParcelAccessList; private static string preSerialized = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; - private static string preSerializedWithParcelAccessList = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n \n 62d65d45-c91a-4f77-862c-46557d978b6c\n \n 2\n \n \n ec2a8d18-2378-4fe0-8b68-2a31b57c481e\n \n 1\n \n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; - - - + private static string preSerializedWithParcelAccessList = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n \n 62d65d45-c91a-4f77-862c-46557d978b6c\n \n 2\n \n \n ec2a8d18-2378-4fe0-8b68-2a31b57c481e\n \n 1\n \n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; [SetUp] public void setup() @@ -62,7 +59,6 @@ namespace OpenSim.Framework.Serialization.Tests this.land.ClaimPrice = 0; this.land.GlobalID = new UUID("54ff9641-dd40-4a2c-b1f1-47dd3af24e50"); this.land.GroupID = new UUID("d740204e-bbbf-44aa-949d-02c7d739f6a5"); - this.land.GroupPrims = 0; this.land.Description = "land data to test LandDataSerializer"; this.land.Flags = (uint)(ParcelFlags.AllowDamage | ParcelFlags.AllowVoiceChat); this.land.LandingType = (byte)LandingType.Direct; @@ -132,4 +128,4 @@ namespace OpenSim.Framework.Serialization.Tests "Reified LandData.Name != original LandData.Name (pre-serialized with parcel access list)"); } } -} +} \ No newline at end of file -- cgit v1.1 From 804fe2d9b00e7e974600f17d64375fab8676ad11 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Fri, 20 May 2011 12:52:09 +0300 Subject: Save the sun's position in OARs --- .../Framework/Serialization/External/RegionSettingsSerializer.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs index 6ba4c5a..931898c 100644 --- a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs +++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs @@ -182,6 +182,9 @@ namespace OpenSim.Framework.Serialization.External case "FixedSun": settings.FixedSun = bool.Parse(xtr.ReadElementContentAsString()); break; + case "SunPosition": + settings.SunPosition = double.Parse(xtr.ReadElementContentAsString()); + break; } } @@ -237,8 +240,9 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("TerrainLowerLimit", settings.TerrainLowerLimit.ToString()); xtw.WriteElementString("UseEstateSun", settings.UseEstateSun.ToString()); xtw.WriteElementString("FixedSun", settings.FixedSun.ToString()); - // XXX: Need to expose interface to get sun phase information from sun module - // xtw.WriteStartElement("SunPhase", + xtw.WriteElementString("SunPosition", settings.SunPosition.ToString()); + // Note: 'SunVector' isn't saved because this value is owned by the Sun Module, which + // calculates it automatically according to the date and other factors. xtw.WriteEndElement(); xtw.WriteEndElement(); -- cgit v1.1 From 8bdd80abfa3830142b16615d97d555dad417e08d Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 12 Jan 2012 09:56:35 -0800 Subject: HG: normalize all externalized user ULRs to be the Home URL, i.e. the location of the user's UAS. This corrects an earlier design which had some cases pointing to the profile server. WARNING: CONFIGURATION CHANGES in both the sims (*Common.ini) and the Robust configs (Robust.HG.ini). Please check diff of the example files, but basically all vars that were pointing to profile should point to the UAS instead and should be called HomeURI. --- .../Serialization/External/ExternalRepresentationUtils.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index 6e8c2ee..7447ac2 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -44,13 +44,13 @@ namespace OpenSim.Framework.Serialization.External /// with creator data added to it. /// /// The SceneObjectPart represented in XML2 - /// The URL of the profile service for the creator + /// 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 xml, string profileURL, IUserAccountService userService, UUID scopeID) + public static string RewriteSOP(string xml, string homeURL, IUserAccountService userService, UUID scopeID) { - if (xml == string.Empty || profileURL == string.Empty || userService == null) + if (xml == string.Empty || homeURL == string.Empty || userService == null) return xml; XmlDocument doc = new XmlDocument(); @@ -83,7 +83,7 @@ namespace OpenSim.Framework.Serialization.External if (!hasCreatorData && creator != null) { XmlElement creatorData = doc.CreateElement("CreatorData"); - creatorData.InnerText = profileURL + "/" + creator.PrincipalID + ";" + creator.FirstName + " " + creator.LastName; + creatorData.InnerText = homeURL + ";" + creator.FirstName + " " + creator.LastName; sop.AppendChild(creatorData); } } -- cgit v1.1 From 447a66d66005c5ec54a786d1d0a532738729251c Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 2 Feb 2012 23:40:56 +0000 Subject: Replace ParcelAccessEntry with a new struct, LandAccessEntry, which more accurately reflects the data sent by the viewer. Add times bans and the expiration of timed bans. Warning: Contains a Migration (and nuts) --- .../Framework/Serialization/External/LandDataSerializer.cs | 12 +++++++----- .../Framework/Serialization/Tests/LandDataSerializerTests.cs | 12 ++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index fc0387b..c61b9e8 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -90,7 +90,7 @@ namespace OpenSim.Framework.Serialization.External landData.MusicURL = xtr.ReadElementString("MusicURL"); landData.OwnerID = UUID.Parse( xtr.ReadElementString("OwnerID")); - landData.ParcelAccessList = new List(); + landData.ParcelAccessList = new List(); xtr.Read(); if (xtr.Name != "ParcelAccessList") throw new XmlException(String.Format("Expected \"ParcelAccessList\" element but got \"{0}\"", xtr.Name)); @@ -99,11 +99,13 @@ namespace OpenSim.Framework.Serialization.External { while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) { - ParcelManager.ParcelAccessEntry pae = new ParcelManager.ParcelAccessEntry(); + LandAccessEntry pae = new LandAccessEntry(); xtr.ReadStartElement("ParcelAccessEntry"); pae.AgentID = UUID.Parse( xtr.ReadElementString("AgentID")); - pae.Time = Convert.ToDateTime( xtr.ReadElementString("Time")); + // We really don't care about temp vs perm here and this + // would break on old oars. Assume all bans are perm + pae.Expires = 0; // Convert.ToUint( xtr.ReadElementString("Time")); pae.Flags = (AccessList)Convert.ToUInt32( xtr.ReadElementString("AccessList")); xtr.ReadEndElement(); @@ -162,11 +164,11 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("OwnerID", landData.OwnerID.ToString()); xtw.WriteStartElement("ParcelAccessList"); - foreach (ParcelManager.ParcelAccessEntry pal in landData.ParcelAccessList) + foreach (LandAccessEntry pal in landData.ParcelAccessList) { xtw.WriteStartElement("ParcelAccessEntry"); xtw.WriteElementString("AgentID", pal.AgentID.ToString()); - xtw.WriteElementString("Time", pal.Time.ToString("s")); + xtw.WriteElementString("Time", pal.Expires.ToString()); xtw.WriteElementString("AccessList", Convert.ToString((uint)pal.Flags)); xtw.WriteEndElement(); } diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs index c69c89d..3607ce8 100644 --- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -42,7 +42,7 @@ namespace OpenSim.Framework.Serialization.Tests private LandData landWithParcelAccessList; private static string preSerialized = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; - private static string preSerializedWithParcelAccessList = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n \n 62d65d45-c91a-4f77-862c-46557d978b6c\n \n 2\n \n \n ec2a8d18-2378-4fe0-8b68-2a31b57c481e\n \n 1\n \n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; + private static string preSerializedWithParcelAccessList = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n \n 62d65d45-c91a-4f77-862c-46557d978b6c\n \n 2\n \n \n ec2a8d18-2378-4fe0-8b68-2a31b57c481e\n \n 1\n \n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; [SetUp] public void setup() @@ -73,16 +73,16 @@ namespace OpenSim.Framework.Serialization.Tests this.landWithParcelAccessList = this.land.Copy(); this.landWithParcelAccessList.ParcelAccessList.Clear(); - ParcelManager.ParcelAccessEntry pae0 = new ParcelManager.ParcelAccessEntry(); + LandAccessEntry pae0 = new LandAccessEntry(); pae0.AgentID = new UUID("62d65d45-c91a-4f77-862c-46557d978b6c"); pae0.Flags = AccessList.Ban; - pae0.Time = new DateTime(2009, 10, 01); + pae0.Expires = 0; this.landWithParcelAccessList.ParcelAccessList.Add(pae0); - ParcelManager.ParcelAccessEntry pae1 = new ParcelManager.ParcelAccessEntry(); + LandAccessEntry pae1 = new LandAccessEntry(); pae1.AgentID = new UUID("ec2a8d18-2378-4fe0-8b68-2a31b57c481e"); pae1.Flags = AccessList.Access; - pae1.Time = new DateTime(2010, 10, 20); + pae1.Expires = 0; this.landWithParcelAccessList.ParcelAccessList.Add(pae1); } @@ -128,4 +128,4 @@ namespace OpenSim.Framework.Serialization.Tests "Reified LandData.Name != original LandData.Name (pre-serialized with parcel access list)"); } } -} \ No newline at end of file +} -- cgit v1.1 From 574c24020284bf52349b9dd42c77ef90eae68500 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 3 Feb 2012 00:05:36 +0000 Subject: Fix test failure --- OpenSim/Framework/Serialization/External/LandDataSerializer.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index c61b9e8..3ae9a8e 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -105,6 +105,7 @@ namespace OpenSim.Framework.Serialization.External pae.AgentID = UUID.Parse( xtr.ReadElementString("AgentID")); // We really don't care about temp vs perm here and this // would break on old oars. Assume all bans are perm + xtr.ReadElementString("Time"); pae.Expires = 0; // Convert.ToUint( xtr.ReadElementString("Time")); pae.Flags = (AccessList)Convert.ToUInt32( xtr.ReadElementString("AccessList")); xtr.ReadEndElement(); -- cgit v1.1 From f17066b7bf27c22448d883e0af9d20a42f671b62 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 3 Feb 2012 22:21:54 +0000 Subject: Change LandDataSerializer deserialization so that in the future it won't care about extra elements or element order. This brings it into line with other deserializations such as object and will improve future backward compatibility. --- .../Serialization/External/LandDataSerializer.cs | 237 +++++++++++++++------ .../External/UserInventoryItemSerializer.cs | 3 +- .../External/UserProfileSerializer.cs | 5 +- .../Serialization/Tests/LandDataSerializerTests.cs | 37 +++- 4 files changed, 208 insertions(+), 74 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index 3ae9a8e..bf6c4e5 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -28,8 +28,10 @@ using System; using System.Collections.Generic; using System.IO; +using System.Reflection; using System.Text; using System.Xml; +using log4net; using OpenMetaverse; using OpenSim.Framework; @@ -40,8 +42,152 @@ namespace OpenSim.Framework.Serialization.External /// public class LandDataSerializer { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); + private delegate void LandDataProcessor(LandData landData, XmlTextReader reader); + private static Dictionary m_ldProcessors + = new Dictionary(); + + private delegate void LandAccessEntryProcessor(LandAccessEntry lae, XmlTextReader reader); + private static Dictionary m_laeProcessors + = new Dictionary(); + + static LandDataSerializer() + { + // LandData processors + m_ldProcessors.Add( + "Area", (ld, xtr) => ld.Area = Convert.ToInt32(xtr.ReadElementString("Area"))); + m_ldProcessors.Add( + "AuctionID", (ld, xtr) => ld.AuctionID = Convert.ToUInt32(xtr.ReadElementString("AuctionID"))); + m_ldProcessors.Add( + "AuthBuyerID", (ld, xtr) => ld.AuthBuyerID = UUID.Parse(xtr.ReadElementString("AuthBuyerID"))); + m_ldProcessors.Add( + "Category", (ld, xtr) => ld.Category = (ParcelCategory)Convert.ToSByte(xtr.ReadElementString("Category"))); + m_ldProcessors.Add( + "ClaimDate", (ld, xtr) => ld.ClaimDate = Convert.ToInt32(xtr.ReadElementString("ClaimDate"))); + m_ldProcessors.Add( + "ClaimPrice", (ld, xtr) => ld.ClaimPrice = Convert.ToInt32(xtr.ReadElementString("ClaimPrice"))); + m_ldProcessors.Add( + "GlobalID", (ld, xtr) => ld.GlobalID = UUID.Parse(xtr.ReadElementString("GlobalID"))); + m_ldProcessors.Add( + "GroupID", (ld, xtr) => ld.GroupID = UUID.Parse(xtr.ReadElementString("GroupID"))); + m_ldProcessors.Add( + "IsGroupOwned", (ld, xtr) => ld.IsGroupOwned = Convert.ToBoolean(xtr.ReadElementString("IsGroupOwned"))); + m_ldProcessors.Add( + "Bitmap", (ld, xtr) => ld.Bitmap = Convert.FromBase64String(xtr.ReadElementString("Bitmap"))); + m_ldProcessors.Add( + "Description", (ld, xtr) => ld.Description = xtr.ReadElementString("Description")); + m_ldProcessors.Add( + "Flags", (ld, xtr) => ld.Flags = Convert.ToUInt32(xtr.ReadElementString("Flags"))); + m_ldProcessors.Add( + "LandingType", (ld, xtr) => ld.LandingType = Convert.ToByte(xtr.ReadElementString("LandingType"))); + m_ldProcessors.Add( + "Name", (ld, xtr) => ld.Name = xtr.ReadElementString("Name")); + m_ldProcessors.Add( + "Status", (ld, xtr) => ld.Status = (ParcelStatus)Convert.ToSByte(xtr.ReadElementString("Status"))); + m_ldProcessors.Add( + "LocalID", (ld, xtr) => ld.LocalID = Convert.ToInt32(xtr.ReadElementString("LocalID"))); + m_ldProcessors.Add( + "MediaAutoScale", (ld, xtr) => ld.MediaAutoScale = Convert.ToByte(xtr.ReadElementString("MediaAutoScale"))); + m_ldProcessors.Add( + "MediaID", (ld, xtr) => ld.MediaID = UUID.Parse(xtr.ReadElementString("MediaID"))); + m_ldProcessors.Add( + "MediaURL", (ld, xtr) => ld.MediaURL = xtr.ReadElementString("MediaURL")); + m_ldProcessors.Add( + "MusicURL", (ld, xtr) => ld.MusicURL = xtr.ReadElementString("MusicURL")); + + m_ldProcessors.Add( + "ParcelAccessList", ProcessParcelAccessList); + + m_ldProcessors.Add( + "PassHours", (ld, xtr) => ld.PassHours = Convert.ToSingle(xtr.ReadElementString("PassHours"))); + m_ldProcessors.Add( + "PassPrice", (ld, xtr) => ld.PassPrice = Convert.ToInt32(xtr.ReadElementString("PassPrice"))); + m_ldProcessors.Add( + "SalePrice", (ld, xtr) => ld.SalePrice = Convert.ToInt32(xtr.ReadElementString("SalePrice"))); + m_ldProcessors.Add( + "SnapshotID", (ld, xtr) => ld.SnapshotID = UUID.Parse(xtr.ReadElementString("SnapshotID"))); + m_ldProcessors.Add( + "UserLocation", (ld, xtr) => ld.UserLocation = Vector3.Parse(xtr.ReadElementString("UserLocation"))); + m_ldProcessors.Add( + "UserLookAt", (ld, xtr) => ld.UserLookAt = Vector3.Parse(xtr.ReadElementString("UserLookAt"))); + + // No longer used here // + // m_ldProcessors.Add("Dwell", (landData, xtr) => return); + + m_ldProcessors.Add( + "OtherCleanTime", (ld, xtr) => ld.OtherCleanTime = Convert.ToInt32(xtr.ReadElementString("OtherCleanTime"))); + + // LandAccessEntryProcessors + m_laeProcessors.Add( + "AgentID", (lae, xtr) => lae.AgentID = UUID.Parse(xtr.ReadElementString("AgentID"))); + m_laeProcessors.Add( + "Time", (lae, xtr) => + { + // We really don't care about temp vs perm here and this + // would break on old oars. Assume all bans are perm + xtr.ReadElementString("Time"); + lae.Expires = 0; // Convert.ToUint( xtr.ReadElementString("Time")); + } + ); + m_laeProcessors.Add( + "AccessList", (lae, xtr) => lae.Flags = (AccessList)Convert.ToUInt32(xtr.ReadElementString("AccessList"))); + } + + public static void ProcessParcelAccessList(LandData ld, XmlTextReader xtr) + { + if (!xtr.IsEmptyElement) + { + while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) + { + LandAccessEntry lae = new LandAccessEntry(); + + xtr.ReadStartElement("ParcelAccessEntry"); + + string nodeName = string.Empty; + while (xtr.NodeType != XmlNodeType.EndElement) + { + nodeName = xtr.Name; + +// m_log.DebugFormat("[LandDataSerializer]: Processing: {0} in ParcelAccessEntry", nodeName); + + LandAccessEntryProcessor p = null; + if (m_laeProcessors.TryGetValue(xtr.Name, out p)) + { +// m_log.DebugFormat("[LandDataSerializer]: Found {0} processor in ParcelAccessEntry", nodeName); + + try + { + p(lae, xtr); + } + catch (Exception e) + { + m_log.ErrorFormat( + "[LandDataSerializer]: Exception while parsing element {0} in ParcelAccessEntry, continuing. Exception {1}{2}", + nodeName, e.Message, e.StackTrace); + + if (xtr.NodeType == XmlNodeType.EndElement) + xtr.Read(); + } + } + else + { + // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName); + xtr.ReadOuterXml(); // ignore + } + } + + xtr.ReadEndElement(); + + ld.ParcelAccessList.Add(lae); + } + } + + xtr.Read(); + } + /// /// Reify/deserialize landData /// @@ -63,72 +209,43 @@ namespace OpenSim.Framework.Serialization.External { LandData landData = new LandData(); - StringReader sr = new StringReader(serializedLandData); - XmlTextReader xtr = new XmlTextReader(sr); - - xtr.ReadStartElement("LandData"); - - landData.Area = Convert.ToInt32( xtr.ReadElementString("Area")); - landData.AuctionID = Convert.ToUInt32( xtr.ReadElementString("AuctionID")); - landData.AuthBuyerID = UUID.Parse( xtr.ReadElementString("AuthBuyerID")); - landData.Category = (ParcelCategory)Convert.ToSByte( xtr.ReadElementString("Category")); - landData.ClaimDate = Convert.ToInt32( xtr.ReadElementString("ClaimDate")); - landData.ClaimPrice = Convert.ToInt32( xtr.ReadElementString("ClaimPrice")); - landData.GlobalID = UUID.Parse( xtr.ReadElementString("GlobalID")); - landData.GroupID = UUID.Parse( xtr.ReadElementString("GroupID")); - landData.IsGroupOwned = Convert.ToBoolean( xtr.ReadElementString("IsGroupOwned")); - landData.Bitmap = Convert.FromBase64String( xtr.ReadElementString("Bitmap")); - landData.Description = xtr.ReadElementString("Description"); - landData.Flags = Convert.ToUInt32( xtr.ReadElementString("Flags")); - landData.LandingType = Convert.ToByte( xtr.ReadElementString("LandingType")); - landData.Name = xtr.ReadElementString("Name"); - landData.Status = (ParcelStatus)Convert.ToSByte( xtr.ReadElementString("Status")); - landData.LocalID = Convert.ToInt32( xtr.ReadElementString("LocalID")); - landData.MediaAutoScale = Convert.ToByte( xtr.ReadElementString("MediaAutoScale")); - landData.MediaID = UUID.Parse( xtr.ReadElementString("MediaID")); - landData.MediaURL = xtr.ReadElementString("MediaURL"); - landData.MusicURL = xtr.ReadElementString("MusicURL"); - landData.OwnerID = UUID.Parse( xtr.ReadElementString("OwnerID")); - - landData.ParcelAccessList = new List(); - xtr.Read(); - if (xtr.Name != "ParcelAccessList") - throw new XmlException(String.Format("Expected \"ParcelAccessList\" element but got \"{0}\"", xtr.Name)); - - if (!xtr.IsEmptyElement) + using (XmlTextReader reader = new XmlTextReader(new StringReader(serializedLandData))) { - while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) - { - LandAccessEntry pae = new LandAccessEntry(); + reader.ReadStartElement("LandData"); - xtr.ReadStartElement("ParcelAccessEntry"); - pae.AgentID = UUID.Parse( xtr.ReadElementString("AgentID")); - // We really don't care about temp vs perm here and this - // would break on old oars. Assume all bans are perm - xtr.ReadElementString("Time"); - pae.Expires = 0; // Convert.ToUint( xtr.ReadElementString("Time")); - pae.Flags = (AccessList)Convert.ToUInt32( xtr.ReadElementString("AccessList")); - xtr.ReadEndElement(); + string nodeName = string.Empty; + while (reader.NodeType != XmlNodeType.EndElement) + { + nodeName = reader.Name; - landData.ParcelAccessList.Add(pae); - } - } - xtr.Read(); +// m_log.DebugFormat("[LandDataSerializer]: Processing: {0}", nodeName); - landData.PassHours = Convert.ToSingle( xtr.ReadElementString("PassHours")); - landData.PassPrice = Convert.ToInt32( xtr.ReadElementString("PassPrice")); - landData.SalePrice = Convert.ToInt32( xtr.ReadElementString("SalePrice")); - landData.SnapshotID = UUID.Parse( xtr.ReadElementString("SnapshotID")); - landData.UserLocation = Vector3.Parse( xtr.ReadElementString("UserLocation")); - landData.UserLookAt = Vector3.Parse( xtr.ReadElementString("UserLookAt")); - // No longer used here - xtr.ReadElementString("Dwell"); - landData.OtherCleanTime = Convert.ToInt32( xtr.ReadElementString("OtherCleanTime")); + LandDataProcessor p = null; + if (m_ldProcessors.TryGetValue(reader.Name, out p)) + { + try + { + p(landData, reader); + } + catch (Exception e) + { + m_log.ErrorFormat( + "[LandDataSerializer]: exception while parsing element {0}, continuing. Exception {1}{2}", + nodeName, e.Message, e.StackTrace); - xtr.ReadEndElement(); + if (reader.NodeType == XmlNodeType.EndElement) + reader.Read(); + } + } + else + { + // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName); + reader.ReadOuterXml(); // ignore + } + } - xtr.Close(); - sr.Close(); + reader.ReadEndElement(); + } return landData; } diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index f138437..5d986d5 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -41,8 +41,7 @@ namespace OpenSim.Framework.Serialization.External { /// /// Serialize and deserialize user inventory items as an external format. - /// - /// XXX: Please do not use yet. + /// public class UserInventoryItemSerializer { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); diff --git a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs index f50b49a..c685a15 100644 --- a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs @@ -33,8 +33,11 @@ using OpenSim.Framework; namespace OpenSim.Framework.Serialization.External { /// - /// Serialize and deserialize region settings as an external format. + /// Serialize and deserialize user profiles as an external format. /// + /// + /// Currently UNUSED. + /// public class UserProfileSerializer { public const int MAJOR_VERSION = 0; diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs index 3607ce8..11a3a0a 100644 --- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -27,11 +27,12 @@ using System; using System.Collections.Generic; -using OpenSim.Framework; -using OpenSim.Framework.Serialization.External; using OpenMetaverse; using OpenMetaverse.StructuredData; using NUnit.Framework; +using OpenSim.Framework; +using OpenSim.Framework.Serialization.External; +using OpenSim.Tests.Common; namespace OpenSim.Framework.Serialization.Tests { @@ -92,6 +93,8 @@ namespace OpenSim.Framework.Serialization.Tests [Test] public void LandDataSerializerSerializeTest() { + TestHelpers.InMethod(); + string serialized = LandDataSerializer.Serialize(this.land).Replace("\r\n", "\n"); Assert.That(serialized.Length > 0, "Serialize(LandData) returned empty string"); @@ -112,20 +115,32 @@ namespace OpenSim.Framework.Serialization.Tests /// Test the LandDataSerializer.Deserialize() method /// [Test] - public void TestLandDataSerializerDeserializeFromStringTest() + public void TestLandDataDeserializeNoAccessLists() + { + TestHelpers.InMethod(); + log4net.Config.XmlConfigurator.Configure(); + + LandData ld = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerialized); + Assert.That(ld != null, "Deserialize(string) returned null"); + Assert.That(ld.GlobalID == this.land.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID"); + Assert.That(ld.Name == this.land.Name, "Reified LandData.Name != original LandData.Name"); + } + + [Test] + public void TestLandDataDeserializeWithAccessLists() { - LandData reifiedLandData = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerialized); - Assert.That(reifiedLandData != null, "Deserialize(string) returned null"); - Assert.That(reifiedLandData.GlobalID == this.land.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID"); - Assert.That(reifiedLandData.Name == this.land.Name, "Reified LandData.Name != original LandData.Name"); + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); - LandData reifiedLandDataWithParcelAccessList = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerializedWithParcelAccessList); - Assert.That(reifiedLandDataWithParcelAccessList != null, + LandData ld = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerializedWithParcelAccessList); + Assert.That(ld != null, "Deserialize(string) returned null (pre-serialized with parcel access list)"); - Assert.That(reifiedLandDataWithParcelAccessList.GlobalID == this.landWithParcelAccessList.GlobalID, + Assert.That(ld.GlobalID == this.landWithParcelAccessList.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID (pre-serialized with parcel access list)"); - Assert.That(reifiedLandDataWithParcelAccessList.Name == this.landWithParcelAccessList.Name, + Assert.That(ld.Name == this.landWithParcelAccessList.Name, "Reified LandData.Name != original LandData.Name (pre-serialized with parcel access list)"); + Assert.That(ld.ParcelAccessList.Count, Is.EqualTo(2)); + Assert.That(ld.ParcelAccessList[0].AgentID, Is.EqualTo(UUID.Parse("62d65d45-c91a-4f77-862c-46557d978b6c"))); } } } -- cgit v1.1 From 623426421132fdc41d9de006fb55aedc660d5362 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 3 Feb 2012 22:45:50 +0000 Subject: Refactor common deserialization processor code to generic method ExternalRepresentationUtils.ExecuteReadProcessors() --- .../External/ExternalRepresentationUtils.cs | 53 +++++++++++++++- .../Serialization/External/LandDataSerializer.cs | 74 ++-------------------- .../External/UserInventoryItemSerializer.cs | 33 ++-------- 3 files changed, 62 insertions(+), 98 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index 7447ac2..39a9f37 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -24,11 +24,13 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + using System; using System.Collections.Generic; using System.IO; +using System.Reflection; using System.Xml; - +using log4net; using OpenMetaverse; using OpenSim.Services.Interfaces; @@ -39,6 +41,55 @@ namespace OpenSim.Framework.Serialization.External /// public class ExternalRepresentationUtils { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + /// + /// Populate a node with data read from xml using a dictinoary of processors + /// + /// + /// + /// A + /// + /// + /// A + /// + public static void ExecuteReadProcessors( + NodeType nodeToFill, Dictionary> processors, XmlTextReader xtr) + { + string nodeName = string.Empty; + while (xtr.NodeType != XmlNodeType.EndElement) + { + nodeName = xtr.Name; + +// m_log.DebugFormat("[ExternalRepresentationUtils]: Processing: {0}", nodeName); + + Action p = null; + if (processors.TryGetValue(xtr.Name, out p)) + { +// m_log.DebugFormat("[ExternalRepresentationUtils]: Found {0} processor, nodeName); + + try + { + p(nodeToFill, xtr); + } + catch (Exception e) + { + m_log.ErrorFormat( + "[ExternalRepresentationUtils]: Exception while parsing element {0}, continuing. Exception {1}{2}", + nodeName, e.Message, e.StackTrace); + + if (xtr.NodeType == XmlNodeType.EndElement) + xtr.Read(); + } + } + else + { + // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName); + xtr.ReadOuterXml(); // ignore + } + } + } + /// /// Takes a XML representation of a SceneObjectPart and returns another XML representation /// with creator data added to it. diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index bf6c4e5..a12877a 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -46,13 +46,11 @@ namespace OpenSim.Framework.Serialization.External protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); - private delegate void LandDataProcessor(LandData landData, XmlTextReader reader); - private static Dictionary m_ldProcessors - = new Dictionary(); + private static Dictionary> m_ldProcessors + = new Dictionary>(); - private delegate void LandAccessEntryProcessor(LandAccessEntry lae, XmlTextReader reader); - private static Dictionary m_laeProcessors - = new Dictionary(); + private static Dictionary> m_laeProcessors + = new Dictionary>(); static LandDataSerializer() { @@ -146,38 +144,7 @@ namespace OpenSim.Framework.Serialization.External xtr.ReadStartElement("ParcelAccessEntry"); - string nodeName = string.Empty; - while (xtr.NodeType != XmlNodeType.EndElement) - { - nodeName = xtr.Name; - -// m_log.DebugFormat("[LandDataSerializer]: Processing: {0} in ParcelAccessEntry", nodeName); - - LandAccessEntryProcessor p = null; - if (m_laeProcessors.TryGetValue(xtr.Name, out p)) - { -// m_log.DebugFormat("[LandDataSerializer]: Found {0} processor in ParcelAccessEntry", nodeName); - - try - { - p(lae, xtr); - } - catch (Exception e) - { - m_log.ErrorFormat( - "[LandDataSerializer]: Exception while parsing element {0} in ParcelAccessEntry, continuing. Exception {1}{2}", - nodeName, e.Message, e.StackTrace); - - if (xtr.NodeType == XmlNodeType.EndElement) - xtr.Read(); - } - } - else - { - // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName); - xtr.ReadOuterXml(); // ignore - } - } + ExternalRepresentationUtils.ExecuteReadProcessors(lae, m_laeProcessors, xtr); xtr.ReadEndElement(); @@ -213,36 +180,7 @@ namespace OpenSim.Framework.Serialization.External { reader.ReadStartElement("LandData"); - string nodeName = string.Empty; - while (reader.NodeType != XmlNodeType.EndElement) - { - nodeName = reader.Name; - -// m_log.DebugFormat("[LandDataSerializer]: Processing: {0}", nodeName); - - LandDataProcessor p = null; - if (m_ldProcessors.TryGetValue(reader.Name, out p)) - { - try - { - p(landData, reader); - } - catch (Exception e) - { - m_log.ErrorFormat( - "[LandDataSerializer]: exception while parsing element {0}, continuing. Exception {1}{2}", - nodeName, e.Message, e.StackTrace); - - if (reader.NodeType == XmlNodeType.EndElement) - reader.Read(); - } - } - else - { - // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName); - reader.ReadOuterXml(); // ignore - } - } + ExternalRepresentationUtils.ExecuteReadProcessors(landData, m_ldProcessors, reader); reader.ReadEndElement(); } diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index 5d986d5..f6fdc4b 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 delegate void InventoryItemXmlProcessor(InventoryItemBase item, XmlTextReader reader); - private static Dictionary m_InventoryItemXmlProcessors = new Dictionary(); + private static Dictionary> m_InventoryItemXmlProcessors + = new Dictionary>(); #region InventoryItemBase Processor initialization static UserInventoryItemSerializer() @@ -204,39 +204,14 @@ namespace OpenSim.Framework.Serialization.External { reader.ReadStartElement("InventoryItem"); - string nodeName = string.Empty; - while (reader.NodeType != XmlNodeType.EndElement) - { - nodeName = reader.Name; - InventoryItemXmlProcessor p = null; - if (m_InventoryItemXmlProcessors.TryGetValue(reader.Name, out p)) - { - //m_log.DebugFormat("[XXX] Processing: {0}", reader.Name); - try - { - p(item, reader); - } - catch (Exception e) - { - m_log.DebugFormat("[InventoryItemSerializer]: exception while parsing {0}: {1}", nodeName, e); - if (reader.NodeType == XmlNodeType.EndElement) - reader.Read(); - } - } - else - { - // m_log.DebugFormat("[InventoryItemSerializer]: caught unknown element {0}", nodeName); - reader.ReadOuterXml(); // ignore - } - - } + ExternalRepresentationUtils.ExecuteReadProcessors( + item, m_InventoryItemXmlProcessors, reader); reader.ReadEndElement(); // InventoryItem } //m_log.DebugFormat("[XXX]: parsed InventoryItemBase {0} - {1}", obj.Name, obj.UUID); return item; - } public static string Serialize(InventoryItemBase inventoryItem, Dictionary options, IUserAccountService userAccountService) -- cgit v1.1 From 83ef13a79add392247ae8e36b419fdc8bc8c6b8b Mon Sep 17 00:00:00 2001 From: Snoopy Pfeffer Date: Fri, 3 Feb 2012 23:53:18 +0100 Subject: Changed save oar and save iar parameter -p|--profile to -h|--home, including corresponding RemoteAdmin parameter --- .../Framework/Serialization/External/UserInventoryItemSerializer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index f138437..b351703 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -305,14 +305,14 @@ namespace OpenSim.Framework.Serialization.External writer.WriteEndElement(); if (options.ContainsKey("creators") && inventoryItem.CreatorData != null && inventoryItem.CreatorData != string.Empty) writer.WriteElementString("CreatorData", inventoryItem.CreatorData); - else if (options.ContainsKey("profile")) + else if (options.ContainsKey("home")) { if (userAccountService != null) { UserAccount account = userAccountService.GetUserAccount(UUID.Zero, inventoryItem.CreatorIdAsUuid); if (account != null) { - writer.WriteElementString("CreatorData", (string)options["profile"] + "/" + inventoryItem.CreatorIdAsUuid + ";" + account.FirstName + " " + account.LastName); + writer.WriteElementString("CreatorData", (string)options["home"] + "/" + inventoryItem.CreatorIdAsUuid + ";" + account.FirstName + " " + account.LastName); } writer.WriteElementString("CreatorID", inventoryItem.CreatorId); } -- cgit v1.1 From 312e1457dd576bc61ac2fd2e104813dd86134c4d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 3 Feb 2012 23:47:01 +0000 Subject: Change SceneObjectSerializer to use common ExternalRepresentationUtils.ExecuteReadProcessors() methods. Adds ability to submit a customized exception message to match logging. --- .../External/ExternalRepresentationUtils.cs | 37 ++++++++++++++++------ 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index 39a9f37..a392af6 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -47,15 +47,36 @@ namespace OpenSim.Framework.Serialization.External /// Populate a node with data read from xml using a dictinoary of processors /// /// - /// - /// A - /// - /// - /// A - /// + /// /param> + /// public static void ExecuteReadProcessors( NodeType nodeToFill, Dictionary> processors, XmlTextReader xtr) { + ExecuteReadProcessors( + nodeToFill, + processors, + xtr, + (o, name, e) + => m_log.ErrorFormat( + "[ExternalRepresentationUtils]: Exception while parsing element {0}, continuing. Exception {1}{2}", + name, e.Message, e.StackTrace)); + } + + /// + /// Populate a node with data read from xml using a dictinoary of processors + /// + /// + /// + /// + /// + /// Action to take if there is a parsing problem. This will usually just be to log the exception + /// + public static void ExecuteReadProcessors( + NodeType nodeToFill, + Dictionary> processors, + XmlTextReader xtr, + Action parseExceptionAction) + { string nodeName = string.Empty; while (xtr.NodeType != XmlNodeType.EndElement) { @@ -74,9 +95,7 @@ namespace OpenSim.Framework.Serialization.External } catch (Exception e) { - m_log.ErrorFormat( - "[ExternalRepresentationUtils]: Exception while parsing element {0}, continuing. Exception {1}{2}", - nodeName, e.Message, e.StackTrace); + parseExceptionAction(nodeToFill, nodeName, e); if (xtr.NodeType == XmlNodeType.EndElement) xtr.Read(); -- cgit v1.1 From 6c252a0fa1342ea71bf7d2d0a417d9ff6ddea1b3 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 4 Feb 2012 00:55:03 +0000 Subject: Add TestRegionSettingsDeserialize --- .../Serialization/Tests/LandDataSerializerTests.cs | 2 +- .../Tests/RegionSettingsSerializerTests.cs | 134 +++++++++++++++++++++ 2 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs index 11a3a0a..b8ed9e1 100644 --- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -118,7 +118,7 @@ namespace OpenSim.Framework.Serialization.Tests public void TestLandDataDeserializeNoAccessLists() { TestHelpers.InMethod(); - log4net.Config.XmlConfigurator.Configure(); +// log4net.Config.XmlConfigurator.Configure(); LandData ld = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerialized); Assert.That(ld != null, "Deserialize(string) returned null"); diff --git a/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs new file mode 100644 index 0000000..a61e4af --- /dev/null +++ b/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs @@ -0,0 +1,134 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using OpenMetaverse; +using OpenMetaverse.StructuredData; +using NUnit.Framework; +using OpenSim.Framework; +using OpenSim.Framework.Serialization.External; +using OpenSim.Tests.Common; + +namespace OpenSim.Framework.Serialization.Tests +{ + [TestFixture] + public class RegionSettingsSerializerTests + { + private string m_serializedRs = @" + + + True + True + True + True + True + True + True + True + True + 1 + True + 40 + 1.4 + + + 00000000-0000-0000-0000-000000000020 + 00000000-0000-0000-0000-000000000040 + 00000000-0000-0000-0000-000000000060 + 00000000-0000-0000-0000-000000000080 + 1.9 + 15.9 + 49 + 45.3 + 2.1 + 4.5 + 9.2 + 19.2 + + + 23 + 17.9 + 0.4 + True + true + 12 + +"; + + private RegionSettings m_rs; + + [SetUp] + public void Setup() + { + m_rs = new RegionSettings(); + m_rs.AgentLimit = 17; + m_rs.AllowDamage = true; + m_rs.AllowLandJoinDivide = true; + m_rs.AllowLandResell = true; + m_rs.BlockFly = true; + m_rs.BlockShowInSearch = true; + m_rs.BlockTerraform = true; + m_rs.DisableCollisions = true; + m_rs.DisablePhysics = true; + m_rs.DisableScripts = true; + m_rs.Elevation1NW = 15.9; + m_rs.Elevation1NE = 45.3; + m_rs.Elevation1SE = 49; + m_rs.Elevation1SW = 1.9; + m_rs.Elevation2NW = 4.5; + m_rs.Elevation2NE = 19.2; + m_rs.Elevation2SE = 9.2; + m_rs.Elevation2SW = 2.1; + m_rs.FixedSun = true; + m_rs.SunPosition = 12.0; + m_rs.ObjectBonus = 1.4; + m_rs.RestrictPushing = true; + m_rs.TerrainLowerLimit = 0.4; + m_rs.TerrainRaiseLimit = 17.9; + m_rs.TerrainTexture1 = UUID.Parse("00000000-0000-0000-0000-000000000020"); + m_rs.TerrainTexture2 = UUID.Parse("00000000-0000-0000-0000-000000000040"); + m_rs.TerrainTexture3 = UUID.Parse("00000000-0000-0000-0000-000000000060"); + m_rs.TerrainTexture4 = UUID.Parse("00000000-0000-0000-0000-000000000080"); + m_rs.UseEstateSun = true; + m_rs.WaterHeight = 23; + } + + [Test] + public void TestRegionSettingsDeserialize() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + RegionSettings deserRs = RegionSettingsSerializer.Deserialize(m_serializedRs); + Assert.That(deserRs, Is.Not.Null); + Assert.That(deserRs.TerrainTexture2, Is.EqualTo(m_rs.TerrainTexture2)); + Assert.That(deserRs.DisablePhysics, Is.EqualTo(m_rs.DisablePhysics)); + Assert.That(deserRs.TerrainLowerLimit, Is.EqualTo(m_rs.TerrainLowerLimit)); + } + } +} -- cgit v1.1 From 189c67db957cadfe1bb5bd8aad0c86dec1ff295b Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 13 Feb 2012 20:43:26 +0000 Subject: On object deserialization, go back to logging errors at DEBUG level rather than ERROR. Restore extra log message if shape processing fails. Logging level was DEBUG before 312e145 (Fri Feb 3 2012). 312e145 also accidentally removed the 'general error' log message if any shape deserialization failed. This commit restores it, though this has no functional impact. --- .../External/ExternalRepresentationUtils.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index a392af6..c56f213 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -49,15 +49,16 @@ namespace OpenSim.Framework.Serialization.External /// /// /param> /// - public static void ExecuteReadProcessors( + /// true on successful, false if there were any processing failures + public static bool ExecuteReadProcessors( NodeType nodeToFill, Dictionary> processors, XmlTextReader xtr) { - ExecuteReadProcessors( + return ExecuteReadProcessors( nodeToFill, processors, xtr, (o, name, e) - => m_log.ErrorFormat( + => m_log.DebugFormat( "[ExternalRepresentationUtils]: Exception while parsing element {0}, continuing. Exception {1}{2}", name, e.Message, e.StackTrace)); } @@ -71,12 +72,15 @@ namespace OpenSim.Framework.Serialization.External /// /// Action to take if there is a parsing problem. This will usually just be to log the exception /// - public static void ExecuteReadProcessors( + /// true on successful, false if there were any processing failures + public static bool ExecuteReadProcessors( NodeType nodeToFill, Dictionary> processors, XmlTextReader xtr, Action parseExceptionAction) { + bool errors = false; + string nodeName = string.Empty; while (xtr.NodeType != XmlNodeType.EndElement) { @@ -95,6 +99,7 @@ namespace OpenSim.Framework.Serialization.External } catch (Exception e) { + errors = true; parseExceptionAction(nodeToFill, nodeName, e); if (xtr.NodeType == XmlNodeType.EndElement) @@ -107,6 +112,8 @@ namespace OpenSim.Framework.Serialization.External xtr.ReadOuterXml(); // ignore } } + + return errors; } /// @@ -140,6 +147,7 @@ namespace OpenSim.Framework.Serialization.External UUID.TryParse(node.InnerText, out uuid); creator = userService.GetUserAccount(scopeID, uuid); } + if (node.Name == "CreatorData" && node.InnerText != null && node.InnerText != string.Empty) hasCreatorData = true; @@ -163,7 +171,6 @@ namespace OpenSim.Framework.Serialization.External doc.Save(wr); return wr.ToString(); } - } } -} +} \ No newline at end of file -- cgit v1.1 From b0b7b45b943dd94546bcfcf5d3bb871cfe35b507 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Thu, 3 May 2012 19:38:35 +0300 Subject: Save the Telehub and its Spawn Points in the OAR Signed-off-by: BlueWall --- .../External/RegionSettingsSerializer.cs | 37 ++++++++++++++++++++-- .../Tests/RegionSettingsSerializerTests.cs | 8 +++++ 2 files changed, 43 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs index 931898c..f18435d 100644 --- a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs +++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs @@ -30,6 +30,8 @@ using System.Text; using System.Xml; using OpenMetaverse; using OpenSim.Framework; +using log4net; +using System.Reflection; namespace OpenSim.Framework.Serialization.External { @@ -187,7 +189,29 @@ namespace OpenSim.Framework.Serialization.External break; } } - + + xtr.ReadEndElement(); + + if (xtr.IsStartElement("Telehub")) + { + xtr.ReadStartElement("Telehub"); + + while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) + { + switch (xtr.Name) + { + case "TelehubObject": + settings.TelehubObject = UUID.Parse(xtr.ReadElementContentAsString()); + break; + case "SpawnPoint": + string str = xtr.ReadElementContentAsString(); + SpawnPoint sp = SpawnPoint.Parse(str); + settings.AddSpawnPoint(sp); + break; + } + } + } + xtr.Close(); sr.Close(); @@ -243,7 +267,16 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("SunPosition", settings.SunPosition.ToString()); // Note: 'SunVector' isn't saved because this value is owned by the Sun Module, which // calculates it automatically according to the date and other factors. - xtw.WriteEndElement(); + xtw.WriteEndElement(); + + xtw.WriteStartElement("Telehub"); + if (settings.TelehubObject != UUID.Zero) + { + xtw.WriteElementString("TelehubObject", settings.TelehubObject.ToString()); + foreach (SpawnPoint sp in settings.SpawnPoints()) + xtw.WriteElementString("SpawnPoint", sp.ToString()); + } + xtw.WriteEndElement(); xtw.WriteEndElement(); diff --git a/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs index a61e4af..09b6f6d 100644 --- a/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs @@ -78,6 +78,10 @@ namespace OpenSim.Framework.Serialization.Tests true 12 + + 00000000-0000-0000-0000-111111111111 + 1,-2,0.33 + "; private RegionSettings m_rs; @@ -116,6 +120,8 @@ namespace OpenSim.Framework.Serialization.Tests m_rs.TerrainTexture4 = UUID.Parse("00000000-0000-0000-0000-000000000080"); m_rs.UseEstateSun = true; m_rs.WaterHeight = 23; + m_rs.TelehubObject = UUID.Parse("00000000-0000-0000-0000-111111111111"); + m_rs.AddSpawnPoint(SpawnPoint.Parse("1,-2,0.33")); } [Test] @@ -129,6 +135,8 @@ namespace OpenSim.Framework.Serialization.Tests Assert.That(deserRs.TerrainTexture2, Is.EqualTo(m_rs.TerrainTexture2)); Assert.That(deserRs.DisablePhysics, Is.EqualTo(m_rs.DisablePhysics)); Assert.That(deserRs.TerrainLowerLimit, Is.EqualTo(m_rs.TerrainLowerLimit)); + Assert.That(deserRs.TelehubObject, Is.EqualTo(m_rs.TelehubObject)); + Assert.That(deserRs.SpawnPoints()[0].ToString(), Is.EqualTo(m_rs.SpawnPoints()[0].ToString())); } } } -- cgit v1.1 From 8b958e7e74d8e4b462c6a59c2854c5072ff8c746 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 12 May 2012 02:36:56 +0100 Subject: Revert "Save the Telehub and its Spawn Points in the OAR" This reverts commit b0b7b45b943dd94546bcfcf5d3bb871cfe35b507. Sorry BlueWall, I wanted to discuss an aspect of the data storage but I couldn't assign bugs in 'patch included' state to myself until I changed mantis just now and I forgot to mention it on irc. I wouldn't normally revert but thinks get tricky when it comes to data formats. Essentially, I would like to see the Yaw, Pitch and Distance values as separate XML entities (as used in other aspects such as vectors, quaternions) rather than as a . delimited string We can discuss this more with Oren in opensimulator.org/mantis/view.php?id=6008 --- .../External/RegionSettingsSerializer.cs | 37 ++-------------------- .../Tests/RegionSettingsSerializerTests.cs | 8 ----- 2 files changed, 2 insertions(+), 43 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs index f18435d..931898c 100644 --- a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs +++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs @@ -30,8 +30,6 @@ using System.Text; using System.Xml; using OpenMetaverse; using OpenSim.Framework; -using log4net; -using System.Reflection; namespace OpenSim.Framework.Serialization.External { @@ -189,29 +187,7 @@ namespace OpenSim.Framework.Serialization.External break; } } - - xtr.ReadEndElement(); - - if (xtr.IsStartElement("Telehub")) - { - xtr.ReadStartElement("Telehub"); - - while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) - { - switch (xtr.Name) - { - case "TelehubObject": - settings.TelehubObject = UUID.Parse(xtr.ReadElementContentAsString()); - break; - case "SpawnPoint": - string str = xtr.ReadElementContentAsString(); - SpawnPoint sp = SpawnPoint.Parse(str); - settings.AddSpawnPoint(sp); - break; - } - } - } - + xtr.Close(); sr.Close(); @@ -267,16 +243,7 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("SunPosition", settings.SunPosition.ToString()); // Note: 'SunVector' isn't saved because this value is owned by the Sun Module, which // calculates it automatically according to the date and other factors. - xtw.WriteEndElement(); - - xtw.WriteStartElement("Telehub"); - if (settings.TelehubObject != UUID.Zero) - { - xtw.WriteElementString("TelehubObject", settings.TelehubObject.ToString()); - foreach (SpawnPoint sp in settings.SpawnPoints()) - xtw.WriteElementString("SpawnPoint", sp.ToString()); - } - xtw.WriteEndElement(); + xtw.WriteEndElement(); xtw.WriteEndElement(); diff --git a/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs index 09b6f6d..a61e4af 100644 --- a/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs @@ -78,10 +78,6 @@ namespace OpenSim.Framework.Serialization.Tests true 12 - - 00000000-0000-0000-0000-111111111111 - 1,-2,0.33 - "; private RegionSettings m_rs; @@ -120,8 +116,6 @@ namespace OpenSim.Framework.Serialization.Tests m_rs.TerrainTexture4 = UUID.Parse("00000000-0000-0000-0000-000000000080"); m_rs.UseEstateSun = true; m_rs.WaterHeight = 23; - m_rs.TelehubObject = UUID.Parse("00000000-0000-0000-0000-111111111111"); - m_rs.AddSpawnPoint(SpawnPoint.Parse("1,-2,0.33")); } [Test] @@ -135,8 +129,6 @@ namespace OpenSim.Framework.Serialization.Tests Assert.That(deserRs.TerrainTexture2, Is.EqualTo(m_rs.TerrainTexture2)); Assert.That(deserRs.DisablePhysics, Is.EqualTo(m_rs.DisablePhysics)); Assert.That(deserRs.TerrainLowerLimit, Is.EqualTo(m_rs.TerrainLowerLimit)); - Assert.That(deserRs.TelehubObject, Is.EqualTo(m_rs.TelehubObject)); - Assert.That(deserRs.SpawnPoints()[0].ToString(), Is.EqualTo(m_rs.SpawnPoints()[0].ToString())); } } } -- cgit v1.1 From 52a32878a9573681e3b56d0151c4a0903719eadf Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Thu, 3 May 2012 19:38:35 +0300 Subject: Save the Telehub and its Spawn Points in the OAR --- .../External/RegionSettingsSerializer.cs | 37 ++++++++++++++++++++-- .../Tests/RegionSettingsSerializerTests.cs | 8 +++++ 2 files changed, 43 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs index 931898c..f18435d 100644 --- a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs +++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs @@ -30,6 +30,8 @@ using System.Text; using System.Xml; using OpenMetaverse; using OpenSim.Framework; +using log4net; +using System.Reflection; namespace OpenSim.Framework.Serialization.External { @@ -187,7 +189,29 @@ namespace OpenSim.Framework.Serialization.External break; } } - + + xtr.ReadEndElement(); + + if (xtr.IsStartElement("Telehub")) + { + xtr.ReadStartElement("Telehub"); + + while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) + { + switch (xtr.Name) + { + case "TelehubObject": + settings.TelehubObject = UUID.Parse(xtr.ReadElementContentAsString()); + break; + case "SpawnPoint": + string str = xtr.ReadElementContentAsString(); + SpawnPoint sp = SpawnPoint.Parse(str); + settings.AddSpawnPoint(sp); + break; + } + } + } + xtr.Close(); sr.Close(); @@ -243,7 +267,16 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("SunPosition", settings.SunPosition.ToString()); // Note: 'SunVector' isn't saved because this value is owned by the Sun Module, which // calculates it automatically according to the date and other factors. - xtw.WriteEndElement(); + xtw.WriteEndElement(); + + xtw.WriteStartElement("Telehub"); + if (settings.TelehubObject != UUID.Zero) + { + xtw.WriteElementString("TelehubObject", settings.TelehubObject.ToString()); + foreach (SpawnPoint sp in settings.SpawnPoints()) + xtw.WriteElementString("SpawnPoint", sp.ToString()); + } + xtw.WriteEndElement(); xtw.WriteEndElement(); diff --git a/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs index a61e4af..09b6f6d 100644 --- a/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs @@ -78,6 +78,10 @@ namespace OpenSim.Framework.Serialization.Tests true 12 + + 00000000-0000-0000-0000-111111111111 + 1,-2,0.33 + "; private RegionSettings m_rs; @@ -116,6 +120,8 @@ namespace OpenSim.Framework.Serialization.Tests m_rs.TerrainTexture4 = UUID.Parse("00000000-0000-0000-0000-000000000080"); m_rs.UseEstateSun = true; m_rs.WaterHeight = 23; + m_rs.TelehubObject = UUID.Parse("00000000-0000-0000-0000-111111111111"); + m_rs.AddSpawnPoint(SpawnPoint.Parse("1,-2,0.33")); } [Test] @@ -129,6 +135,8 @@ namespace OpenSim.Framework.Serialization.Tests Assert.That(deserRs.TerrainTexture2, Is.EqualTo(m_rs.TerrainTexture2)); Assert.That(deserRs.DisablePhysics, Is.EqualTo(m_rs.DisablePhysics)); Assert.That(deserRs.TerrainLowerLimit, Is.EqualTo(m_rs.TerrainLowerLimit)); + Assert.That(deserRs.TelehubObject, Is.EqualTo(m_rs.TelehubObject)); + Assert.That(deserRs.SpawnPoints()[0].ToString(), Is.EqualTo(m_rs.SpawnPoints()[0].ToString())); } } } -- cgit v1.1 From 1926de5a0599051c27c065fb06da3dc536e6784a Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 30 Jun 2012 01:25:27 +0100 Subject: Remove some mono compiler warnings --- OpenSim/Framework/Serialization/External/LandDataSerializer.cs | 2 +- OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index a12877a..e8d82d3 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -42,7 +42,7 @@ namespace OpenSim.Framework.Serialization.External /// public class LandDataSerializer { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index 57da7ca..88f9581 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -44,7 +44,7 @@ namespace OpenSim.Framework.Serialization.External /// public class UserInventoryItemSerializer { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static Dictionary> m_InventoryItemXmlProcessors = new Dictionary>(); -- cgit v1.1 From 916e3bf886ee622e2f18d6eb74f90fee8c630471 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 11 Jul 2012 22:54:22 +0100 Subject: Where possible, use the system Encoding.ASCII and Encoding.UTF8 rather than constructing fresh copies. The encodings are thread-safe and already used in such a manner in other places. This isn't done where Byte Order Mark output is suppressed, since Encoding.UTF8 is constructed to output the BOM. --- .../Serialization/External/LandDataSerializer.cs | 4 +--- .../External/RegionSettingsSerializer.cs | 4 +--- .../Framework/Serialization/TarArchiveReader.cs | 8 +++----- .../Framework/Serialization/TarArchiveWriter.cs | 23 +++++++++++----------- 4 files changed, 16 insertions(+), 23 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index e8d82d3..a64f01c 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -44,8 +44,6 @@ namespace OpenSim.Framework.Serialization.External { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); - private static Dictionary> m_ldProcessors = new Dictionary>(); @@ -163,7 +161,7 @@ namespace OpenSim.Framework.Serialization.External /// public static LandData Deserialize(byte[] serializedLandData) { - return Deserialize(m_utf8Encoding.GetString(serializedLandData, 0, serializedLandData.Length)); + return Deserialize(Encoding.UTF8.GetString(serializedLandData, 0, serializedLandData.Length)); } /// diff --git a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs index f18435d..19468c3 100644 --- a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs +++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs @@ -40,8 +40,6 @@ namespace OpenSim.Framework.Serialization.External /// public class RegionSettingsSerializer { - protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); - /// /// Deserialize settings /// @@ -50,7 +48,7 @@ namespace OpenSim.Framework.Serialization.External /// public static RegionSettings Deserialize(byte[] serializedSettings) { - return Deserialize(m_asciiEncoding.GetString(serializedSettings, 0, serializedSettings.Length)); + return Deserialize(Encoding.ASCII.GetString(serializedSettings, 0, serializedSettings.Length)); } /// diff --git a/OpenSim/Framework/Serialization/TarArchiveReader.cs b/OpenSim/Framework/Serialization/TarArchiveReader.cs index 77c29f8..339a37a 100644 --- a/OpenSim/Framework/Serialization/TarArchiveReader.cs +++ b/OpenSim/Framework/Serialization/TarArchiveReader.cs @@ -53,8 +53,6 @@ namespace OpenSim.Framework.Serialization TYPE_CONTIGUOUS_FILE = 8, } - protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); - /// /// Binary reader for the underlying stream /// @@ -120,13 +118,13 @@ namespace OpenSim.Framework.Serialization if (header[156] == (byte)'L') { int longNameLength = ConvertOctalBytesToDecimal(header, 124, 11); - tarHeader.FilePath = m_asciiEncoding.GetString(ReadData(longNameLength)); + tarHeader.FilePath = Encoding.ASCII.GetString(ReadData(longNameLength)); //m_log.DebugFormat("[TAR ARCHIVE READER]: Got long file name {0}", tarHeader.FilePath); header = m_br.ReadBytes(512); } else { - tarHeader.FilePath = m_asciiEncoding.GetString(header, 0, 100); + tarHeader.FilePath = Encoding.ASCII.GetString(header, 0, 100); tarHeader.FilePath = tarHeader.FilePath.Trim(m_nullCharArray); //m_log.DebugFormat("[TAR ARCHIVE READER]: Got short file name {0}", tarHeader.FilePath); } @@ -205,7 +203,7 @@ namespace OpenSim.Framework.Serialization { // Trim leading white space: ancient tars do that instead // of leading 0s :-( don't ask. really. - string oString = m_asciiEncoding.GetString(bytes, startIndex, count).TrimStart(m_spaceCharArray); + string oString = Encoding.ASCII.GetString(bytes, startIndex, count).TrimStart(m_spaceCharArray); int d = 0; diff --git a/OpenSim/Framework/Serialization/TarArchiveWriter.cs b/OpenSim/Framework/Serialization/TarArchiveWriter.cs index fca909f..122fa8e 100644 --- a/OpenSim/Framework/Serialization/TarArchiveWriter.cs +++ b/OpenSim/Framework/Serialization/TarArchiveWriter.cs @@ -41,7 +41,6 @@ namespace OpenSim.Framework.Serialization { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); /// @@ -85,7 +84,7 @@ namespace OpenSim.Framework.Serialization public void WriteFile(string filePath, byte[] data) { if (filePath.Length > 100) - WriteEntry("././@LongLink", m_asciiEncoding.GetBytes(filePath), 'L'); + WriteEntry("././@LongLink", Encoding.ASCII.GetBytes(filePath), 'L'); char fileType; @@ -137,7 +136,7 @@ namespace OpenSim.Framework.Serialization oString = "0" + oString; } - byte[] oBytes = m_asciiEncoding.GetBytes(oString); + byte[] oBytes = Encoding.ASCII.GetBytes(oString); return oBytes; } @@ -156,20 +155,20 @@ namespace OpenSim.Framework.Serialization byte[] header = new byte[512]; // file path field (100) - byte[] nameBytes = m_asciiEncoding.GetBytes(filePath); + byte[] nameBytes = Encoding.ASCII.GetBytes(filePath); int nameSize = (nameBytes.Length >= 100) ? 100 : nameBytes.Length; Array.Copy(nameBytes, header, nameSize); // file mode (8) - byte[] modeBytes = m_asciiEncoding.GetBytes("0000777"); + byte[] modeBytes = Encoding.ASCII.GetBytes("0000777"); Array.Copy(modeBytes, 0, header, 100, 7); // owner user id (8) - byte[] ownerIdBytes = m_asciiEncoding.GetBytes("0000764"); + byte[] ownerIdBytes = Encoding.ASCII.GetBytes("0000764"); Array.Copy(ownerIdBytes, 0, header, 108, 7); // group user id (8) - byte[] groupIdBytes = m_asciiEncoding.GetBytes("0000764"); + byte[] groupIdBytes = Encoding.ASCII.GetBytes("0000764"); Array.Copy(groupIdBytes, 0, header, 116, 7); // file size in bytes (12) @@ -181,17 +180,17 @@ namespace OpenSim.Framework.Serialization Array.Copy(fileSizeBytes, 0, header, 124, 11); // last modification time (12) - byte[] lastModTimeBytes = m_asciiEncoding.GetBytes("11017037332"); + byte[] lastModTimeBytes = Encoding.ASCII.GetBytes("11017037332"); Array.Copy(lastModTimeBytes, 0, header, 136, 11); // entry type indicator (1) - header[156] = m_asciiEncoding.GetBytes(new char[] { fileType })[0]; + header[156] = Encoding.ASCII.GetBytes(new char[] { fileType })[0]; - Array.Copy(m_asciiEncoding.GetBytes("0000000"), 0, header, 329, 7); - Array.Copy(m_asciiEncoding.GetBytes("0000000"), 0, header, 337, 7); + Array.Copy(Encoding.ASCII.GetBytes("0000000"), 0, header, 329, 7); + Array.Copy(Encoding.ASCII.GetBytes("0000000"), 0, header, 337, 7); // check sum for header block (8) [calculated last] - Array.Copy(m_asciiEncoding.GetBytes(" "), 0, header, 148, 8); + Array.Copy(Encoding.ASCII.GetBytes(" "), 0, header, 148, 8); int checksum = 0; foreach (byte b in header) -- cgit v1.1 From 884d603cac6c3fe0cdbd199e13e1514146ff82bc Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 13 Jul 2012 01:03:28 +0100 Subject: Rather than instantiating a UTF8 encoding everywhere when we want to supress the BOM, use a single Util.UTF8NoBomEncoding. This class is thread-safe (as evidenced by the provision of the system-wide Encoding.UTF8 which does not suppress BOM on output). --- OpenSim/Framework/Serialization/TarArchiveWriter.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/TarArchiveWriter.cs b/OpenSim/Framework/Serialization/TarArchiveWriter.cs index 122fa8e..2a3bc48 100644 --- a/OpenSim/Framework/Serialization/TarArchiveWriter.cs +++ b/OpenSim/Framework/Serialization/TarArchiveWriter.cs @@ -41,8 +41,6 @@ namespace OpenSim.Framework.Serialization { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); - /// /// Binary writer for the underlying stream /// @@ -73,7 +71,7 @@ namespace OpenSim.Framework.Serialization /// public void WriteFile(string filePath, string data) { - WriteFile(filePath, m_utf8Encoding.GetBytes(data)); + WriteFile(filePath, Util.UTF8NoBomEncoding.GetBytes(data)); } /// -- cgit v1.1 From fb91ca6f1d3e61444005175d0a0d55025d15ad5b Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 3 Aug 2012 23:49:34 +0100 Subject: Fix old regression that stopped saving parcel owner data in OARs. This was working in 0.7.2 but was accidentally removed from 0.7.3. The --publish option for "save oar" will now save oars stripped of parcel owner information as well as scene object info. Please use the --publish option if you want to publish oars that may be later loaded by others to the same grid from which they were saved. --- .../Serialization/External/LandDataSerializer.cs | 22 +++++- .../Serialization/Tests/LandDataSerializerTests.cs | 85 +++++++++++++--------- 2 files changed, 72 insertions(+), 35 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index a64f01c..709b516 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -93,6 +93,8 @@ namespace OpenSim.Framework.Serialization.External "MediaURL", (ld, xtr) => ld.MediaURL = xtr.ReadElementString("MediaURL")); m_ldProcessors.Add( "MusicURL", (ld, xtr) => ld.MusicURL = xtr.ReadElementString("MusicURL")); + m_ldProcessors.Add( + "OwnerID", (ld, xtr) => ld.OwnerID = UUID.Parse(xtr.ReadElementString("OwnerID"))); m_ldProcessors.Add( "ParcelAccessList", ProcessParcelAccessList); @@ -186,7 +188,16 @@ namespace OpenSim.Framework.Serialization.External return landData; } - public static string Serialize(LandData landData) + /// + /// Serialize land data + /// + /// + /// + /// Serialization options. + /// Can be null if there are no options. + /// "wipe-owners" will write UUID.Zero rather than the ownerID so that a later reload loads all parcels with the estate owner as the owner + /// + public static string Serialize(LandData landData, Dictionary options) { StringWriter sw = new StringWriter(); XmlTextWriter xtw = new XmlTextWriter(sw); @@ -215,7 +226,14 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("MediaID", landData.MediaID.ToString()); xtw.WriteElementString("MediaURL", landData.MediaURL); xtw.WriteElementString("MusicURL", landData.MusicURL); - xtw.WriteElementString("OwnerID", landData.OwnerID.ToString()); + + UUID ownerIdToWrite; + if (options != null && options.ContainsKey("wipe-owners")) + ownerIdToWrite = UUID.Zero; + else + ownerIdToWrite = landData.OwnerID; + + xtw.WriteElementString("OwnerID", ownerIdToWrite.ToString()); xtw.WriteStartElement("ParcelAccessList"); foreach (LandAccessEntry pal in landData.ParcelAccessList) diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs index b8ed9e1..8b9756b 100644 --- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -42,22 +42,23 @@ namespace OpenSim.Framework.Serialization.Tests private LandData land; private LandData landWithParcelAccessList; - private static string preSerialized = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; - private static string preSerializedWithParcelAccessList = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n \n 62d65d45-c91a-4f77-862c-46557d978b6c\n \n 2\n \n \n ec2a8d18-2378-4fe0-8b68-2a31b57c481e\n \n 1\n \n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; +// private static string preSerialized = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; + private static string preSerializedWithParcelAccessList + = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n \n 62d65d45-c91a-4f77-862c-46557d978b6c\n \n 2\n \n \n ec2a8d18-2378-4fe0-8b68-2a31b57c481e\n \n 1\n \n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; [SetUp] public void setup() { // setup LandData object this.land = new LandData(); - this.land.AABBMax = new Vector3(0, 0, 0); - this.land.AABBMin = new Vector3(128, 128, 128); + this.land.AABBMax = new Vector3(1, 2, 3); + this.land.AABBMin = new Vector3(129, 130, 131); this.land.Area = 128; - this.land.AuctionID = 0; - this.land.AuthBuyerID = new UUID(); + this.land.AuctionID = 4; + this.land.AuthBuyerID = new UUID("7176df0c-6c50-45db-8a37-5e78be56a0cd"); this.land.Category = ParcelCategory.Residential; - this.land.ClaimDate = 0; - this.land.ClaimPrice = 0; + this.land.ClaimDate = 1; + this.land.ClaimPrice = 2; this.land.GlobalID = new UUID("54ff9641-dd40-4a2c-b1f1-47dd3af24e50"); this.land.GroupID = new UUID("d740204e-bbbf-44aa-949d-02c7d739f6a5"); this.land.Description = "land data to test LandDataSerializer"; @@ -65,7 +66,7 @@ namespace OpenSim.Framework.Serialization.Tests this.land.LandingType = (byte)LandingType.Direct; this.land.Name = "LandDataSerializerTest Land"; this.land.Status = ParcelStatus.Leased; - this.land.LocalID = 0; + this.land.LocalID = 1; this.land.MediaAutoScale = (byte)0x01; this.land.MediaID = new UUID("d4452578-2f25-4b97-a81b-819af559cfd7"); this.land.MediaURL = "http://videos.opensimulator.org/bumblebee.mp4"; @@ -90,26 +91,26 @@ namespace OpenSim.Framework.Serialization.Tests /// /// Test the LandDataSerializer.Serialize() method /// - [Test] - public void LandDataSerializerSerializeTest() - { - TestHelpers.InMethod(); - - string serialized = LandDataSerializer.Serialize(this.land).Replace("\r\n", "\n"); - Assert.That(serialized.Length > 0, "Serialize(LandData) returned empty string"); - - // adding a simple boolean variable because resharper nUnit integration doesn't like this - // XML data in the Assert.That statement. Not sure why. - bool result = (serialized == preSerialized); - Assert.That(result, "result of Serialize LandData does not match expected result"); - - string serializedWithParcelAccessList = LandDataSerializer.Serialize(this.landWithParcelAccessList).Replace("\r\n", "\n"); - Assert.That(serializedWithParcelAccessList.Length > 0, - "Serialize(LandData) returned empty string for LandData object with ParcelAccessList"); - result = (serializedWithParcelAccessList == preSerializedWithParcelAccessList); - Assert.That(result, - "result of Serialize(LandData) does not match expected result (pre-serialized with parcel access list"); - } +// [Test] +// public void LandDataSerializerSerializeTest() +// { +// TestHelpers.InMethod(); +// +// string serialized = LandDataSerializer.Serialize(this.land).Replace("\r\n", "\n"); +// Assert.That(serialized.Length > 0, "Serialize(LandData) returned empty string"); +// +// // adding a simple boolean variable because resharper nUnit integration doesn't like this +// // XML data in the Assert.That statement. Not sure why. +// bool result = (serialized == preSerialized); +// Assert.That(result, "result of Serialize LandData does not match expected result"); +// +// string serializedWithParcelAccessList = LandDataSerializer.Serialize(this.landWithParcelAccessList).Replace("\r\n", "\n"); +// Assert.That(serializedWithParcelAccessList.Length > 0, +// "Serialize(LandData) returned empty string for LandData object with ParcelAccessList"); +// result = (serializedWithParcelAccessList == preSerializedWithParcelAccessList); +// Assert.That(result, +// "result of Serialize(LandData) does not match expected result (pre-serialized with parcel access list"); +// } /// /// Test the LandDataSerializer.Deserialize() method @@ -120,10 +121,28 @@ namespace OpenSim.Framework.Serialization.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); - LandData ld = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerialized); - Assert.That(ld != null, "Deserialize(string) returned null"); - Assert.That(ld.GlobalID == this.land.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID"); - Assert.That(ld.Name == this.land.Name, "Reified LandData.Name != original LandData.Name"); + LandData ld = LandDataSerializer.Deserialize(LandDataSerializer.Serialize(this.land, null)); + Assert.That(ld, Is.Not.Null, "Deserialize(string) returned null"); +// Assert.That(ld.AABBMax, Is.EqualTo(land.AABBMax)); +// Assert.That(ld.AABBMin, Is.EqualTo(land.AABBMin)); + Assert.That(ld.Area, Is.EqualTo(land.Area)); + Assert.That(ld.AuctionID, Is.EqualTo(land.AuctionID)); + Assert.That(ld.AuthBuyerID, Is.EqualTo(land.AuthBuyerID)); + Assert.That(ld.Category, Is.EqualTo(land.Category)); + Assert.That(ld.ClaimDate, Is.EqualTo(land.ClaimDate)); + Assert.That(ld.ClaimPrice, Is.EqualTo(land.ClaimPrice)); + Assert.That(ld.GlobalID, Is.EqualTo(land.GlobalID), "Reified LandData.GlobalID != original LandData.GlobalID"); + Assert.That(ld.GroupID, Is.EqualTo(land.GroupID)); + Assert.That(ld.Description, Is.EqualTo(land.Description)); + Assert.That(ld.Flags, Is.EqualTo(land.Flags)); + Assert.That(ld.LandingType, Is.EqualTo(land.LandingType)); + Assert.That(ld.Name, Is.EqualTo(land.Name), "Reified LandData.Name != original LandData.Name"); + Assert.That(ld.Status, Is.EqualTo(land.Status)); + Assert.That(ld.LocalID, Is.EqualTo(land.LocalID)); + Assert.That(ld.MediaAutoScale, Is.EqualTo(land.MediaAutoScale)); + Assert.That(ld.MediaID, Is.EqualTo(land.MediaID)); + Assert.That(ld.MediaURL, Is.EqualTo(land.MediaURL)); + Assert.That(ld.OwnerID, Is.EqualTo(land.OwnerID)); } [Test] -- cgit v1.1 From 7ea832d47c827ad9ef8eb0ce24702fbee585b1ee Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 29 Aug 2012 02:01:43 +0100 Subject: Fix regression introduced in a0d178b2 (Sat Aug 25 02:00:17 2012) where folders with asset type of 'Folder' and 'Unknown' were accidentally treated as system folders. This prevented more than one additional ordinary folder from being created in the base "My Inventory" user folder. Added regression test for this case. Switched tests to use XInventoryService with mostly implemented TestXInventoryDataPlugin rather than InventoryService Disabled TestLoadIarV0_1SameNameCreator() since this has not been working for a very long time (ever since XInventoryService) started being used since it doesnt' preserve creator data in the same way as InventoryService did and so effectively lost the OSPAs. However, nobody noticed/complained about this issue and OSPAs have been superseded by HG like creator information via the --home save oar/iar switch. --- OpenSim/Framework/Serialization/External/OspResolver.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/OspResolver.cs b/OpenSim/Framework/Serialization/External/OspResolver.cs index d31d27c..fa7160f 100644 --- a/OpenSim/Framework/Serialization/External/OspResolver.cs +++ b/OpenSim/Framework/Serialization/External/OspResolver.cs @@ -65,9 +65,14 @@ namespace OpenSim.Framework.Serialization UserAccount account = userService.GetUserAccount(UUID.Zero, userId); if (account != null) + { return MakeOspa(account.FirstName, account.LastName); + } // else +// { // m_log.WarnFormat("[OSP RESOLVER]: No user account for {0}", userId); +// System.Console.WriteLine("[OSP RESOLVER]: No user account for {0}", userId); +// } return null; } @@ -79,10 +84,13 @@ namespace OpenSim.Framework.Serialization /// public static string MakeOspa(string firstName, string lastName) { -// m_log.DebugFormat("[OSP RESOLVER]: Making OSPA for {0} {1}", firstName, lastName); + string ospa + = OSPA_PREFIX + OSPA_NAME_KEY + OSPA_PAIR_SEPARATOR + firstName + OSPA_NAME_VALUE_SEPARATOR + lastName; + +// m_log.DebugFormat("[OSP RESOLVER]: Made OSPA {0} for {1} {2}", ospa, firstName, lastName); +// System.Console.WriteLine("[OSP RESOLVER]: Made OSPA {0} for {1} {2}", ospa, firstName, lastName); - return - OSPA_PREFIX + OSPA_NAME_KEY + OSPA_PAIR_SEPARATOR + firstName + OSPA_NAME_VALUE_SEPARATOR + lastName; + return ospa; } /// -- cgit v1.1 From ce468215d576cc301a261d85bee9baa68a246ce6 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Tue, 24 Jul 2012 19:48:08 +0300 Subject: Support multi-region OAR files Merged ArchiveWriteRequestPreparation.cs and ArchiveWriteRequestExecution.cs. This simplifies the code, and it's faster to write each scene to the archive as it's found rather than all at once at the end. --- OpenSim/Framework/Serialization/ArchiveConstants.cs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index 2c5e001..48f1c4f 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -53,6 +53,11 @@ namespace OpenSim.Framework.Serialization public const string INVENTORY_PATH = "inventory/"; /// + /// Path for regions in a multi-region archive + /// + public const string REGIONS_PATH = "regions/"; + + /// /// Path for the prims file /// public const string OBJECTS_PATH = "objects/"; -- cgit v1.1 From 27b12cebbba8df2f03fe7918b9672be23bc41a09 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 14 Nov 2012 08:10:15 -0800 Subject: A few more AssemblyInfos in a few more dlls. --- .../Serialization/Properties/AssemblyInfo.cs | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs b/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..11efa4b --- /dev/null +++ b/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("OpenSim.Framework.Serialization")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("http://opensimulator.org")] +[assembly: AssemblyProduct("OpenSim")] +[assembly: AssemblyCopyright("OpenSimulator developers")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("919db41e-4ac0-4f24-9992-81d62c0ee183")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("0.7.5.*")] +[assembly: AssemblyFileVersion("1.0.0.0")] -- cgit v1.1 From 82690e138448ebac6456ab03dcca4b0a8a1cc57a Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 24 Nov 2012 02:43:31 +0000 Subject: Fix bug where loading an OAR with a deeded parcel would always set the parcel owner ID to the estate owner even if the group UUID was present. Aims to address http://opensimulator.org/mantis/view.php?id=6355 As part of this work, an incomplete IXGroupsData was added which currently only allows store/fetch/delete of group records (i.e. no membership data etc) This is subject to change and currently only an in-memory storage implementation exists for regression test purposes. --- OpenSim/Framework/Serialization/ArchiveConstants.cs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index 48f1c4f..0c12787 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -154,6 +154,11 @@ namespace OpenSim.Framework.Serialization EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"] = (sbyte)AssetType.TrashFolder; } + public static string CreateOarLandDataPath(LandData ld) + { + return string.Format("{0}{1}.xml", ArchiveConstants.LANDDATA_PATH, ld.GlobalID); + } + /// /// Create the filename used to store an object in an OpenSim Archive. /// -- cgit v1.1 From 22d4c52ffc374e167cb674e0e20815615d8a6927 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 24 Nov 2012 03:15:24 +0000 Subject: Consistenly make NUnit test cases inherit from OpenSimTestCase which automatically turns off any logging enabled between tests --- OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs | 2 +- OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs index 8b9756b..ea100ee 100644 --- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -37,7 +37,7 @@ using OpenSim.Tests.Common; namespace OpenSim.Framework.Serialization.Tests { [TestFixture] - public class LandDataSerializerTest + public class LandDataSerializerTest : OpenSimTestCase { private LandData land; private LandData landWithParcelAccessList; diff --git a/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs index 09b6f6d..142726b 100644 --- a/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/RegionSettingsSerializerTests.cs @@ -37,7 +37,7 @@ using OpenSim.Tests.Common; namespace OpenSim.Framework.Serialization.Tests { [TestFixture] - public class RegionSettingsSerializerTests + public class RegionSettingsSerializerTests : OpenSimTestCase { private string m_serializedRs = @" -- cgit v1.1 From 1f1da230976451d30d920c237d53c699ba96b9d9 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 5 Feb 2013 00:23:17 +0000 Subject: Bump version and assembly version numbers from 0.7.5 to 0.7.6 This is mostly Bluewall's work but I am also bumping the general version number OpenSimulator 0.7.5 remains in the release candidate stage. I'm doing this because master is significantly adding things that will not be in 0.7.5 This update should not cause issues with existing external binary DLLs because our DLLs do not have strong names and so the exact version match requirement is not in force. --- OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs b/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs index 11efa4b..7a122da 100644 --- a/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs +++ b/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("0.7.5.*")] +[assembly: AssemblyVersion("0.7.6.*")] [assembly: AssemblyFileVersion("1.0.0.0")] -- cgit v1.1 From 4779f7d7d5ce0e284d9ed15104389f8479b11545 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Tue, 19 Feb 2013 17:14:55 -0800 Subject: Deleted all AssemblyFileVersion directives --- OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs b/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs index 7a122da..a8dff93 100644 --- a/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs +++ b/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs @@ -30,4 +30,4 @@ using System.Runtime.InteropServices; // Revision // [assembly: AssemblyVersion("0.7.6.*")] -[assembly: AssemblyFileVersion("1.0.0.0")] + -- cgit v1.1 From 42bdf446585007029faf4cd21abd289487f0f797 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 4 Oct 2013 23:33:47 +0100 Subject: Bump OPenSimulator version and assembly versions up to 0.8.0 Dev --- OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs b/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs index a8dff93..3f04148 100644 --- a/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs +++ b/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("0.7.6.*")] +[assembly: AssemblyVersion("0.8.0.*")] -- cgit v1.1 From 7cab41f4223b7febd3fdd42fa7cfefef25e4a9c9 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 15 Nov 2013 21:45:08 +0000 Subject: refactor: replace verbose checks with String.IsNullOrEmpty where applicable. Thanks to Kira for this patch from http://opensimulator.org/mantis/view.php?id=6845 --- OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index 88f9581..f2a6b8b 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -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")) { -- cgit v1.1 From 3018b2c5d7c9de0e8da6d158f0848c840b7864ab Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Fri, 6 Dec 2013 16:21:11 +0200 Subject: Materials module: a) Store materials as assets; b) Finalized it (removed the "Demo" label; removed most of the logging); c) Enabled by default Changed UuidGatherer to use 'sbyte' to identify assets instead of 'AssetType'. This lets UuidGatherer handle Materials, which are defined in a different enum from 'AssetType'. --- OpenSim/Framework/Serialization/ArchiveConstants.cs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index 0c12787..73ebfae 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -29,6 +29,7 @@ using System; using System.Collections.Generic; using System.Text; using OpenMetaverse; +using OpenSimAssetType = OpenSim.Framework.SLUtil.OpenSimAssetType; namespace OpenSim.Framework.Serialization { @@ -128,6 +129,7 @@ namespace OpenSim.Framework.Serialization ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Texture] = ASSET_EXTENSION_SEPARATOR + "texture.jp2"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TextureTGA] = ASSET_EXTENSION_SEPARATOR + "texture.tga"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TrashFolder] = ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"; // Not sure if we'll ever see this + ASSET_TYPE_TO_EXTENSION[(sbyte)OpenSimAssetType.Material] = ASSET_EXTENSION_SEPARATOR + "material.xml"; // Not sure if we'll ever see this EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "animation.bvh"] = (sbyte)AssetType.Animation; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "bodypart.txt"] = (sbyte)AssetType.Bodypart; @@ -152,6 +154,7 @@ namespace OpenSim.Framework.Serialization EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.jp2"] = (sbyte)AssetType.Texture; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.tga"] = (sbyte)AssetType.TextureTGA; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"] = (sbyte)AssetType.TrashFolder; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "material.xml"] = (sbyte)OpenSimAssetType.Material; } public static string CreateOarLandDataPath(LandData ld) -- cgit v1.1 From 89945f8829dcc1ee889aad1bafd1d6c2938a6cc7 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Thu, 31 Oct 2013 13:02:57 +0200 Subject: Refactored: ExternalRepresentationUtils should be the only place where the "CreatorData" field is calculated, to ensure uniformity Resolves http://opensimulator.org/mantis/view.php?id=6933 --- .../External/ExternalRepresentationUtils.cs | 16 +++++++++++++--- .../External/UserInventoryItemSerializer.cs | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index c56f213..db46ea8 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. * @@ -161,7 +161,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 +172,15 @@ namespace OpenSim.Framework.Serialization.External return wr.ToString(); } } + + 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; + } } -} \ No newline at end of file +} diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index f2a6b8b..135cefb 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -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 From 33cc847c4ac78b890f8ac175c479ab1b1c56cbbf Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Mon, 26 May 2014 15:19:20 +0300 Subject: When saving an OAR in "Publish" mode, also discard Group information --- .../Serialization/External/LandDataSerializer.cs | 18 +++++++++--------- .../Serialization/Tests/LandDataSerializerTests.cs | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index 709b516..4b5326a 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -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/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs index ea100ee..e81cb78 100644 --- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -121,7 +121,8 @@ namespace OpenSim.Framework.Serialization.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); - LandData ld = LandDataSerializer.Deserialize(LandDataSerializer.Serialize(this.land, null)); + Dictionary options = new Dictionary(); + LandData ld = LandDataSerializer.Deserialize(LandDataSerializer.Serialize(this.land, options)); Assert.That(ld, Is.Not.Null, "Deserialize(string) returned null"); // Assert.That(ld.AABBMax, Is.EqualTo(land.AABBMax)); // Assert.That(ld.AABBMin, Is.EqualTo(land.AABBMin)); -- cgit v1.1 From 5450b1b0247bb3907f60f2b3f9b0582903de4f83 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 17 Jun 2014 18:37:15 +0100 Subject: Change assembly versions to 0.8.1 --- OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs b/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs index 3f04148..11573d2 100644 --- a/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs +++ b/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("0.8.0.*")] +[assembly: AssemblyVersion("0.8.1.*")] -- cgit v1.1 From 1b75ec5647afeb9fbdad78f70c0c90a829bba076 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 29 Aug 2014 19:08:23 +0100 Subject: Ignore whitespace when reading serialized XML objects. This was previously effectively being done by XmlDocument in the multiple passes through the XML. This change tells XmlReader to ignore whitespace. This also means changing arguments to use XmlReader instead of XmlTextReader (a descendent of XmlReader) directly. XmlReader.Create() has been the recommend way to create XML readers since .NET 2.0 as per MS SDK and is the only way to specific ignore whitespace settings. --- .../External/ExternalRepresentationUtils.cs | 8 ++-- .../Serialization/External/LandDataSerializer.cs | 10 ++--- .../External/UserInventoryItemSerializer.cs | 44 +++++++++++----------- 3 files changed, 31 insertions(+), 31 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index db46ea8..6debf65 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -51,7 +51,7 @@ 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) + NodeType nodeToFill, Dictionary> processors, XmlReader xtr) { return ExecuteReadProcessors( nodeToFill, @@ -75,8 +75,8 @@ 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; @@ -88,7 +88,7 @@ namespace OpenSim.Framework.Serialization.External // m_log.DebugFormat("[ExternalRepresentationUtils]: Processing: {0}", nodeName); - Action p = null; + Action p = null; if (processors.TryGetValue(xtr.Name, out p)) { // m_log.DebugFormat("[ExternalRepresentationUtils]: Found {0} processor, nodeName); diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index 4b5326a..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) { diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index 135cefb..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); } -- cgit v1.1 From da32512ea449c2de2d4a6069f899fbd4a8bb03fa Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 29 Apr 2015 18:47:17 -0700 Subject: Updated all occurrences of AssemblyVersion("0.8.1.*") to AssemblyVersion("0.8.2.*") --- OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs b/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs index 11573d2..0cce722 100644 --- a/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs +++ b/OpenSim/Framework/Serialization/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("0.8.1.*")] +[assembly: AssemblyVersion("0.8.2.*")] -- cgit v1.1 From 365f46bfa91245e6e277a180dc6bbf757ea2540f Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 2 May 2015 20:40:37 -0700 Subject: Mantis #7514 Mono bug introduces double xmlns attribute names when rewriting the asset in HGAssetService, e.g. . Solution: remove all attributes before saving. --- .../Framework/Serialization/External/ExternalRepresentationUtils.cs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index 6debf65..a293388 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -136,6 +136,9 @@ namespace OpenSim.Framework.Serialization.External foreach (XmlNode sop in sops) { + // Due to mono bug, we're removing all xmlns attributes + sop.Attributes.RemoveAll(); + UserAccount creator = null; bool hasCreatorData = false; XmlNodeList nodes = sop.ChildNodes; -- cgit v1.1 From 09edc9619af66b2705dbb4e28e3ffc1772d9adc0 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 2 May 2015 22:15:26 -0700 Subject: It wasn't that. Revert "Mantis #7514" This reverts commit 365f46bfa91245e6e277a180dc6bbf757ea2540f. --- .../Framework/Serialization/External/ExternalRepresentationUtils.cs | 3 --- 1 file changed, 3 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index a293388..6debf65 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -136,9 +136,6 @@ namespace OpenSim.Framework.Serialization.External foreach (XmlNode sop in sops) { - // Due to mono bug, we're removing all xmlns attributes - sop.Attributes.RemoveAll(); - UserAccount creator = null; bool hasCreatorData = false; XmlNodeList nodes = sop.ChildNodes; -- cgit v1.1 From 1abbad71b4603245e5481c11e3ce55f57b64935f Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Tue, 5 May 2015 20:59:09 -0700 Subject: Refactored some code that is used in two different dlls related to SOP rewriting. Also added some unit tests that relate to mantis #7514 --- .../External/ExternalRepresentationUtils.cs | 184 ++++++++++++++++++++- 1 file changed, 183 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index 6debf65..64de18b 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -125,7 +125,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; @@ -173,6 +174,187 @@ namespace OpenSim.Framework.Serialization.External } } + /// + /// 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; + + 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; -- cgit v1.1 From e5a1243abc04c3f6f62e94425fea25b2ad84b577 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 1 Aug 2015 18:58:05 -0700 Subject: Mantis #7657 and #7514. This should alleviate the problem of bad object assets being passed around via HG and archives. No guarantees that all the leaks have been found, but at least it detects and fixes these bad assets upon: (1) storing and getting assets over HG -- assuming the core HG asset service is being used (not the case with OSGrid!) (2) importing assets via OAR and IAR Instantiation of bad assets now should also work, instead of producing an exception, but the bad assets themselves aren't being fixed in the DB. That should be done with a cleaning tool -- see Perl script in Mantis #7657. Virus! --- .../External/ExternalRepresentationUtils.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index 64de18b..1254086 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -190,6 +190,9 @@ namespace OpenSim.Framework.Serialization.External 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)) @@ -364,5 +367,21 @@ namespace OpenSim.Framework.Serialization.External { 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; + } + } } -- cgit v1.1 From 959872315f67a1a33a2bae7330749f7dd74a4774 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 8 Aug 2015 12:12:50 -0700 Subject: WARNING: massive refactor to follow libomv's latest changes regarding inventory folders. The newest version of libomv itself is committed here. Basically, everything that was using the AssetType enum has been combed through; many of those uses were changed to the new FolderType enum. This means that from now on, [new] root folders have code 8 (FolderType.Root), as the viewers expect, as opposed to 9, which was what we had been doing. Normal folders are as they were, -1. Also now sending folder code 100 for Suitcase folders to viewers, with no filter. All tests pass, but fingers crossed! --- OpenSim/Framework/Serialization/ArchiveConstants.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/ArchiveConstants.cs b/OpenSim/Framework/Serialization/ArchiveConstants.cs index 73ebfae..ab3c285 100644 --- a/OpenSim/Framework/Serialization/ArchiveConstants.cs +++ b/OpenSim/Framework/Serialization/ArchiveConstants.cs @@ -115,20 +115,16 @@ namespace OpenSim.Framework.Serialization ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.ImageJPEG] = ASSET_EXTENSION_SEPARATOR + "image.jpg"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.ImageTGA] = ASSET_EXTENSION_SEPARATOR + "image.tga"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Landmark] = ASSET_EXTENSION_SEPARATOR + "landmark.txt"; - ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LostAndFoundFolder] = ASSET_EXTENSION_SEPARATOR + "lostandfoundfolder.txt"; // Not sure if we'll ever see this ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LSLBytecode] = ASSET_EXTENSION_SEPARATOR + "bytecode.lso"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.LSLText] = ASSET_EXTENSION_SEPARATOR + "script.lsl"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Mesh] = ASSET_EXTENSION_SEPARATOR + "mesh.llmesh"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Notecard] = ASSET_EXTENSION_SEPARATOR + "notecard.txt"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Object] = ASSET_EXTENSION_SEPARATOR + "object.xml"; - ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.RootFolder] = ASSET_EXTENSION_SEPARATOR + "rootfolder.txt"; // Not sure if we'll ever see this ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Simstate] = ASSET_EXTENSION_SEPARATOR + "simstate.bin"; // Not sure if we'll ever see this - ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SnapshotFolder] = ASSET_EXTENSION_SEPARATOR + "snapshotfolder.txt"; // Not sure if we'll ever see this ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Sound] = ASSET_EXTENSION_SEPARATOR + "sound.ogg"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SoundWAV] = ASSET_EXTENSION_SEPARATOR + "sound.wav"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.Texture] = ASSET_EXTENSION_SEPARATOR + "texture.jp2"; ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TextureTGA] = ASSET_EXTENSION_SEPARATOR + "texture.tga"; - ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.TrashFolder] = ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"; // Not sure if we'll ever see this ASSET_TYPE_TO_EXTENSION[(sbyte)OpenSimAssetType.Material] = ASSET_EXTENSION_SEPARATOR + "material.xml"; // Not sure if we'll ever see this EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "animation.bvh"] = (sbyte)AssetType.Animation; @@ -140,21 +136,17 @@ namespace OpenSim.Framework.Serialization EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "image.jpg"] = (sbyte)AssetType.ImageJPEG; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "image.tga"] = (sbyte)AssetType.ImageTGA; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "landmark.txt"] = (sbyte)AssetType.Landmark; - EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "lostandfoundfolder.txt"] = (sbyte)AssetType.LostAndFoundFolder; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "bytecode.lso"] = (sbyte)AssetType.LSLBytecode; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "script.lsl"] = (sbyte)AssetType.LSLText; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "mesh.llmesh"] = (sbyte)AssetType.Mesh; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "notecard.txt"] = (sbyte)AssetType.Notecard; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "object.xml"] = (sbyte)AssetType.Object; - EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "rootfolder.txt"] = (sbyte)AssetType.RootFolder; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "simstate.bin"] = (sbyte)AssetType.Simstate; - EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "snapshotfolder.txt"] = (sbyte)AssetType.SnapshotFolder; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "sound.ogg"] = (sbyte)AssetType.Sound; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "sound.wav"] = (sbyte)AssetType.SoundWAV; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.jp2"] = (sbyte)AssetType.Texture; EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "texture.tga"] = (sbyte)AssetType.TextureTGA; - EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "trashfolder.txt"] = (sbyte)AssetType.TrashFolder; - EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "material.xml"] = (sbyte)OpenSimAssetType.Material; + EXTENSION_TO_ASSET_TYPE[ASSET_EXTENSION_SEPARATOR + "material.xml"] = (sbyte)OpenSimAssetType.Material; } public static string CreateOarLandDataPath(LandData ld) -- cgit v1.1 From 4ad1468165b80f67439399e36688d36944996312 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Sun, 5 Jul 2015 16:05:01 +0300 Subject: Better handling of invalid XML: a) prevent infinite loop on EOF; b) better logging If the XML was truncated for some reason then ExecuteReadProcessors() would get into an infinite loop, using high CPU. Now it detects EOF (and several other error cases) and aborts. The rest of the changes just improve logging of XML in case of errors, so that we can see what the bad XML is. --- .../External/ExternalRepresentationUtils.cs | 40 +++++++++++++++++----- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'OpenSim/Framework/Serialization') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index 1254086..55640ac 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Reflection; using System.Xml; @@ -47,7 +48,7 @@ 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( @@ -57,10 +58,10 @@ namespace OpenSim.Framework.Serialization.External 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); + }); } /// @@ -80,18 +81,22 @@ namespace OpenSim.Framework.Serialization.External 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; 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; -- cgit v1.1