From afef1ac191d32e9c1514c294b17e404b1d4ae217 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 5 Nov 2009 13:10:58 -0800 Subject: Changing the AssetBase constructors to avoid initializing assets with an unknown asset type, and log an error if it ever does happen --- OpenSim/Framework/AssetBase.cs | 42 ++++++++++++++++++---- OpenSim/Framework/AssetLandmark.cs | 4 +-- .../Filesystem/AssetLoaderFileSystem.cs | 21 ++++++----- OpenSim/Framework/Capabilities/Caps.cs | 5 +-- OpenSim/Framework/Tests/AssetBaseTest.cs | 3 +- 5 files changed, 50 insertions(+), 25 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/AssetBase.cs b/OpenSim/Framework/AssetBase.cs index 9679ff2..eed9703 100644 --- a/OpenSim/Framework/AssetBase.cs +++ b/OpenSim/Framework/AssetBase.cs @@ -27,6 +27,8 @@ using System; using System.Xml.Serialization; +using System.Reflection; +using log4net; using OpenMetaverse; namespace OpenSim.Framework @@ -37,6 +39,8 @@ namespace OpenSim.Framework [Serializable] public class AssetBase { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + /// /// Data of the Asset /// @@ -47,16 +51,34 @@ namespace OpenSim.Framework /// private AssetMetadata m_metadata; - public AssetBase() + public AssetBase(UUID assetID, string name, sbyte assetType) { + if (assetType == (sbyte)AssetType.Unknown) + { + System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true); + m_log.ErrorFormat("[ASSETBASE]: Creating asset '{0}' ({1}) with an unknown asset type\n{2}", + name, assetID, trace.ToString()); + } + m_metadata = new AssetMetadata(); + m_metadata.FullID = assetID; + m_metadata.Name = name; + m_metadata.Type = assetType; } - public AssetBase(UUID assetId, string name) + public AssetBase(string assetID, string name, sbyte assetType) { + if (assetType == (sbyte)AssetType.Unknown) + { + System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true); + m_log.ErrorFormat("[ASSETBASE]: Creating asset '{0}' ({1}) with an unknown asset type\n{2}", + name, assetID, trace.ToString()); + } + m_metadata = new AssetMetadata(); - m_metadata.FullID = assetId; + m_metadata.ID = assetID; m_metadata.Name = name; + m_metadata.Type = assetType; } public bool ContainsReferences @@ -193,11 +215,11 @@ namespace OpenSim.Framework private string m_name = String.Empty; private string m_description = String.Empty; private DateTime m_creation_date; - private sbyte m_type; + private sbyte m_type = (sbyte)AssetType.Unknown; private string m_content_type; private byte[] m_sha1; - private bool m_local = false; - private bool m_temporary = false; + private bool m_local; + private bool m_temporary; //private Dictionary m_methods = new Dictionary(); //private OSDMap m_extra_data; @@ -211,7 +233,13 @@ namespace OpenSim.Framework { //get { return m_fullid.ToString(); } //set { m_fullid = new UUID(value); } - get { return m_id; } + get + { + if (String.IsNullOrEmpty(m_id)) + m_id = m_fullid.ToString(); + + return m_id; + } set { UUID uuid = UUID.Zero; diff --git a/OpenSim/Framework/AssetLandmark.cs b/OpenSim/Framework/AssetLandmark.cs index fd7a2cd..058b442 100644 --- a/OpenSim/Framework/AssetLandmark.cs +++ b/OpenSim/Framework/AssetLandmark.cs @@ -38,11 +38,9 @@ namespace OpenSim.Framework public int Version; public AssetLandmark(AssetBase a) + : base(a.FullID, a.Name, a.Type) { Data = a.Data; - FullID = a.FullID; - Type = a.Type; - Name = a.Name; Description = a.Description; InternData(); } diff --git a/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs index a394b1a..9497a2e 100644 --- a/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs +++ b/OpenSim/Framework/AssetLoader/Filesystem/AssetLoaderFileSystem.cs @@ -43,18 +43,15 @@ namespace OpenSim.Framework.AssetLoader.Filesystem { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - protected static AssetBase CreateAsset(string assetIdStr, string name, string path, bool isImage) + protected static AssetBase CreateAsset(string assetIdStr, string name, string path, sbyte type) { - AssetBase asset = new AssetBase( - new UUID(assetIdStr), - name - ); + AssetBase asset = new AssetBase(new UUID(assetIdStr), name, type); if (!String.IsNullOrEmpty(path)) { //m_log.InfoFormat("[ASSETS]: Loading: [{0}][{1}]", name, path); - LoadAsset(asset, isImage, path); + LoadAsset(asset, path); } else { @@ -64,8 +61,14 @@ namespace OpenSim.Framework.AssetLoader.Filesystem return asset; } - protected static void LoadAsset(AssetBase info, bool image, string path) + protected static void LoadAsset(AssetBase info, string path) { + bool image = + (info.Type == (sbyte)AssetType.Texture || + info.Type == (sbyte)AssetType.TextureTGA || + info.Type == (sbyte)AssetType.ImageJPEG || + info.Type == (sbyte)AssetType.ImageTGA); + FileInfo fInfo = new FileInfo(path); long numBytes = fInfo.Length; if (fInfo.Exists) @@ -138,10 +141,10 @@ namespace OpenSim.Framework.AssetLoader.Filesystem { string assetIdStr = source.Configs[i].GetString("assetID", UUID.Random().ToString()); string name = source.Configs[i].GetString("name", String.Empty); - sbyte type = (sbyte) source.Configs[i].GetInt("assetType", 0); + sbyte type = (sbyte)source.Configs[i].GetInt("assetType", 0); string assetPath = Path.Combine(dir, source.Configs[i].GetString("fileName", String.Empty)); - AssetBase newAsset = CreateAsset(assetIdStr, name, assetPath, false); + AssetBase newAsset = CreateAsset(assetIdStr, name, assetPath, type); newAsset.Type = type; assets.Add(newAsset); diff --git a/OpenSim/Framework/Capabilities/Caps.cs b/OpenSim/Framework/Capabilities/Caps.cs index ccfe800..72231ca 100644 --- a/OpenSim/Framework/Capabilities/Caps.cs +++ b/OpenSim/Framework/Capabilities/Caps.cs @@ -888,10 +888,7 @@ namespace OpenSim.Framework.Capabilities } AssetBase asset; - asset = new AssetBase(); - asset.FullID = assetID; - asset.Type = assType; - asset.Name = assetName; + asset = new AssetBase(assetID, assetName, assType); asset.Data = data; if (AddNewAsset != null) AddNewAsset(asset); diff --git a/OpenSim/Framework/Tests/AssetBaseTest.cs b/OpenSim/Framework/Tests/AssetBaseTest.cs index 3dc6b4e..18a3e01 100644 --- a/OpenSim/Framework/Tests/AssetBaseTest.cs +++ b/OpenSim/Framework/Tests/AssetBaseTest.cs @@ -67,8 +67,7 @@ namespace OpenSim.Framework.Tests private void CheckContainsReferences(AssetType assetType, bool expected) { - AssetBase asset = new AssetBase(); - asset.Type = (sbyte)assetType; + AssetBase asset = new AssetBase(UUID.Zero, String.Empty, (sbyte)assetType); bool actual = asset.ContainsReferences; Assert.AreEqual(expected, actual, "Expected "+assetType+".ContainsReferences to be "+expected+" but was "+actual+"."); } -- cgit v1.1 From 5300e8506da657118dbde8c9edc9a00db28bc4ac Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 6 Nov 2009 10:33:49 +0000 Subject: Reintroduce AssetBase's old behavior. A Parameterless constructor is required for .NET serialization and removing it breaks the OpenSim asset server protocol. --- OpenSim/Framework/AssetBase.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/AssetBase.cs b/OpenSim/Framework/AssetBase.cs index eed9703..212f41d 100644 --- a/OpenSim/Framework/AssetBase.cs +++ b/OpenSim/Framework/AssetBase.cs @@ -51,6 +51,16 @@ namespace OpenSim.Framework /// private AssetMetadata m_metadata; + // This is needed for .NET serialization!!! + // Do NOT "Optimize" away! + public AssetBase() + { + m_metadata = new AssetMetadata(); + m_metadata.FullID = UUID.Zero; + m_metadata.ID = UUID.Zero.ToString(); + m_metadata.Type = (sbyte)AssetType.Unknown; + } + public AssetBase(UUID assetID, string name, sbyte assetType) { if (assetType == (sbyte)AssetType.Unknown) -- cgit v1.1