Changing the AssetBase constructors to avoid initializing assets with an unknown asset type, and log an error if it ever does happen

0.6.8-post-fixes
John Hurliman 2009-11-05 13:10:58 -08:00
parent e6d7303b29
commit afef1ac191
31 changed files with 105 additions and 122 deletions

View File

@ -1562,11 +1562,8 @@ namespace OpenSim.ApplicationPlugins.RemoteController
assets = doc.GetElementsByTagName("RequiredAsset");
foreach (XmlNode asset in assets)
{
AssetBase rass = new AssetBase();
rass.FullID = UUID.Random();
rass.Name = GetStringAttribute(asset,"name","");
AssetBase rass = new AssetBase(UUID.Random(), GetStringAttribute(asset,"name",""), SByte.Parse(GetStringAttribute(asset,"type","")));
rass.Description = GetStringAttribute(asset,"desc","");
rass.Type = SByte.Parse(GetStringAttribute(asset,"type",""));
rass.Local = Boolean.Parse(GetStringAttribute(asset,"local",""));
rass.Temporary = Boolean.Parse(GetStringAttribute(asset,"temporary",""));
rass.Data = Convert.FromBase64String(asset.InnerText);

View File

@ -261,11 +261,8 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
modified = (asset != null);
created = !modified;
asset = new AssetBase();
asset.FullID = uuid;
asset.Name = xml.GetAttribute("name");
asset = new AssetBase(uuid, xml.GetAttribute("name"), SByte.Parse(xml.GetAttribute("type")));
asset.Description = xml.GetAttribute("desc");
asset.Type = SByte.Parse(xml.GetAttribute("type"));
asset.Local = Int32.Parse(xml.GetAttribute("local")) != 0;
asset.Temporary = Int32.Parse(xml.GetAttribute("temporary")) != 0;
asset.Data = Convert.FromBase64String(xml.ReadElementContentAsString("Asset", ""));
@ -341,11 +338,8 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
modified = (asset != null);
created = !modified;
asset = new AssetBase();
asset.FullID = uuid;
asset.Name = xml.GetAttribute("name");
asset = new AssetBase(uuid, xml.GetAttribute("name"), SByte.Parse(xml.GetAttribute("type")));
asset.Description = xml.GetAttribute("desc");
asset.Type = SByte.Parse(xml.GetAttribute("type"));
asset.Local = Int32.Parse(xml.GetAttribute("local")) != 0;
asset.Temporary = Int32.Parse(xml.GetAttribute("temporary")) != 0;
asset.Data = Convert.FromBase64String(xml.ReadElementContentAsString("Asset", ""));

View File

@ -1869,10 +1869,9 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
// Create AssetBase entity to hold the inlined asset
asset = new AssetBase(uuid, name);
asset = new AssetBase(uuid, name, type);
asset.Description = desc;
asset.Type = type; // type == 0 == texture
asset.Local = local;
asset.Temporary = temp;

View File

@ -132,12 +132,13 @@ namespace OpenSim.Data.MSSQL
{
if (reader.Read())
{
AssetBase asset = new AssetBase();
AssetBase asset = new AssetBase(
new UUID((Guid)reader["id"]),
(string)reader["name"],
Convert.ToSByte(reader["assetType"])
);
// Region Main
asset.FullID = new UUID((Guid)reader["id"]);
asset.Name = (string)reader["name"];
asset.Description = (string)reader["description"];
asset.Type = Convert.ToSByte(reader["assetType"]);
asset.Local = Convert.ToBoolean(reader["local"]);
asset.Temporary = Convert.ToBoolean(reader["temporary"]);
asset.Data = (byte[])reader["data"];

View File

@ -151,10 +151,9 @@ namespace OpenSim.Data.MySQL
{
if (dbReader.Read())
{
asset = new AssetBase();
asset = new AssetBase(assetID, (string)dbReader["name"], (sbyte)dbReader["assetType"]);
asset.Data = (byte[]) dbReader["data"];
asset.Description = (string) dbReader["description"];
asset.FullID = assetID;
string local = dbReader["local"].ToString();
if (local.Equals("1") || local.Equals("true", StringComparison.InvariantCultureIgnoreCase))
@ -162,8 +161,6 @@ namespace OpenSim.Data.MySQL
else
asset.Local = false;
asset.Name = (string) dbReader["name"];
asset.Type = (sbyte) dbReader["assetType"];
asset.Temporary = Convert.ToBoolean(dbReader["temporary"]);
}
dbReader.Close();

View File

@ -231,12 +231,13 @@ namespace OpenSim.Data.SQLite
// TODO: this doesn't work yet because something more
// interesting has to be done to actually get these values
// back out. Not enough time to figure it out yet.
AssetBase asset = new AssetBase();
AssetBase asset = new AssetBase(
new UUID((String)row["UUID"]),
(String)row["Name"],
Convert.ToSByte(row["Type"])
);
asset.FullID = new UUID((String) row["UUID"]);
asset.Name = (String) row["Name"];
asset.Description = (String) row["Description"];
asset.Type = Convert.ToSByte(row["Type"]);
asset.Local = Convert.ToBoolean(row["Local"]);
asset.Temporary = Convert.ToBoolean(row["Temporary"]);
asset.Data = (byte[]) row["Data"];

View File

@ -66,9 +66,9 @@ namespace OpenSim.Data.Tests
[Test]
public void T010_StoreSimpleAsset()
{
AssetBase a1 = new AssetBase(uuid1, "asset one");
AssetBase a2 = new AssetBase(uuid2, "asset two");
AssetBase a3 = new AssetBase(uuid3, "asset three");
AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture);
AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture);
AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture);
a1.Data = asset1;
a2.Data = asset1;
a3.Data = asset1;

View File

@ -297,8 +297,8 @@ namespace OpenSim.Data.Tests
public void AssetShouldMatch()
{
UUID uuid1 = UUID.Random();
AssetBase actual = new AssetBase(uuid1, "asset one");
AssetBase expected = new AssetBase(uuid1, "asset one");
AssetBase actual = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture);
AssetBase expected = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture);
var constraint = Constraints.PropertyCompareConstraint(expected);
@ -309,8 +309,8 @@ namespace OpenSim.Data.Tests
public void AssetShouldNotMatch()
{
UUID uuid1 = UUID.Random();
AssetBase actual = new AssetBase(uuid1, "asset one");
AssetBase expected = new AssetBase(UUID.Random(), "asset one");
AssetBase actual = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture);
AssetBase expected = new AssetBase(UUID.Random(), "asset one", (sbyte)AssetType.Texture);
var constraint = Constraints.PropertyCompareConstraint(expected);
@ -321,8 +321,8 @@ namespace OpenSim.Data.Tests
public void AssetShouldNotMatch2()
{
UUID uuid1 = UUID.Random();
AssetBase actual = new AssetBase(uuid1, "asset one");
AssetBase expected = new AssetBase(uuid1, "asset two");
AssetBase actual = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture);
AssetBase expected = new AssetBase(uuid1, "asset two", (sbyte)AssetType.Texture);
var constraint = Constraints.PropertyCompareConstraint(expected);

View File

@ -165,7 +165,7 @@ namespace OpenSim.Data.Tests
[Test]
public void TestScramble()
{
AssetBase actual = new AssetBase(UUID.Random(), "asset one");
AssetBase actual = new AssetBase(UUID.Random(), "asset one", (sbyte)AssetType.Texture);
new PropertyScrambler<AssetBase>().Scramble(actual);
}
@ -173,8 +173,7 @@ namespace OpenSim.Data.Tests
public void DontScramble()
{
UUID uuid = UUID.Random();
AssetBase asset = new AssetBase();
asset.FullID = uuid;
AssetBase asset = new AssetBase(uuid, "asset", (sbyte)AssetType.Texture);
new PropertyScrambler<AssetBase>()
.DontScramble(x => x.Metadata)
.DontScramble(x => x.FullID)

View File

@ -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);
/// <summary>
/// Data of the Asset
/// </summary>
@ -47,16 +51,34 @@ namespace OpenSim.Framework
/// </summary>
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<string, Uri> m_methods = new Dictionary<string, Uri>();
//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;

View File

@ -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();
}

View File

@ -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);

View File

@ -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);

View File

@ -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+".");
}

View File

@ -197,11 +197,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
private void Initialise(UUID fileID, string fileName)
{
m_asset = new AssetBase();
m_asset.FullID = fileID;
m_asset.Type = type;
m_asset = new AssetBase(fileID, fileName, type);
m_asset.Data = new byte[0];
m_asset.Name = fileName;
m_asset.Description = "empty";
m_asset.Local = true;
m_asset.Temporary = true;

View File

@ -112,11 +112,8 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
bool storeLocal, bool tempFile)
{
ourClient = remoteClient;
m_asset = new AssetBase();
m_asset.FullID = assetID;
m_asset.Type = type;
m_asset = new AssetBase(assetID, "blank", type);
m_asset.Data = data;
m_asset.Name = "blank";
m_asset.Description = "empty";
m_asset.Local = storeLocal;
m_asset.Temporary = tempFile;

View File

@ -238,12 +238,11 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
if (m_cache != null)
{
AssetBase layerDecodeAsset = new AssetBase();
layerDecodeAsset.ID = "j2kCache_" + AssetId.ToString();
string assetID = "j2kCache_" + AssetId.ToString();
AssetBase layerDecodeAsset = new AssetBase(assetID, assetID, (sbyte)AssetType.Notecard);
layerDecodeAsset.Local = true;
layerDecodeAsset.Name = layerDecodeAsset.ID;
layerDecodeAsset.Temporary = true;
layerDecodeAsset.Type = (sbyte)AssetType.Notecard;
#region Serialize Layer Data

View File

@ -389,11 +389,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
{
sbyte assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension];
if (assetType == (sbyte)AssetType.Unknown)
m_log.WarnFormat("[INVENTORY ARCHIVER]: Importing {0} byte asset {1} with unknown type", data.Length, uuid);
//m_log.DebugFormat("[INVENTORY ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType);
AssetBase asset = new AssetBase(new UUID(uuid), "RandomName");
asset.Type = assetType;
AssetBase asset = new AssetBase(new UUID(uuid), "RandomName", assetType);
asset.Data = data;
m_scene.AssetService.Store(asset);

View File

@ -122,8 +122,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
}
UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
AssetBase asset1 = new AssetBase();
asset1.FullID = asset1Id;
AssetBase asset1 = new AssetBase(asset1Id, asset1Id.ToString(), (sbyte)AssetType.Object);
asset1.Data = Encoding.ASCII.GetBytes(SceneObjectSerializer.ToXml2Format(object1));
scene.AssetService.Store(asset1);

View File

@ -311,11 +311,8 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
}
// Create a new asset for user
AssetBase asset = new AssetBase();
asset.FullID = UUID.Random();
AssetBase asset = new AssetBase(UUID.Random(), "DynamicImage" + Util.RandomClass.Next(1, 10000), (sbyte)AssetType.Texture);
asset.Data = assetData;
asset.Name = "DynamicImage" + Util.RandomClass.Next(1, 10000);
asset.Type = 0;
asset.Description = String.Format("URL image : {0}", Url);
asset.Local = false;
asset.Temporary = ((Disp & DISP_TEMP) != 0);

View File

@ -332,10 +332,12 @@ namespace OpenSim.Region.CoreModules.World.Archiver
{
sbyte assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension];
if (assetType == (sbyte)AssetType.Unknown)
m_log.WarnFormat("[ARCHIVER]: Importing {0} byte asset {1} with unknown type", data.Length, uuid);
//m_log.DebugFormat("[ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType);
AssetBase asset = new AssetBase(new UUID(uuid), String.Empty);
asset.Type = assetType;
AssetBase asset = new AssetBase(new UUID(uuid), String.Empty, assetType);
asset.Data = data;
// We're relying on the asset service to do the sensible thing and not store the asset if it already

View File

@ -158,9 +158,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
m_log.DebugFormat("[ARCHIVER]: Importing asset {0}", filename);
AssetBase asset = new AssetBase(new UUID(filename), metadata.Name);
AssetBase asset = new AssetBase(new UUID(filename), metadata.Name, metadata.AssetType);
asset.Description = metadata.Description;
asset.Type = metadata.AssetType;
asset.Data = data;
m_cache.Store(asset);

View File

@ -52,16 +52,11 @@ namespace OpenSim.Region.CoreModules.World.Estate
public EstateTerrainXferHandler(IClientAPI pRemoteClient, string pClientFilename)
{
m_asset = new AssetBase();
m_asset.FullID = UUID.Zero;
m_asset.Type = type;
m_asset = new AssetBase(UUID.Zero, pClientFilename, type);
m_asset.Data = new byte[0];
m_asset.Name = pClientFilename;
m_asset.Description = "empty";
m_asset.Local = true;
m_asset.Temporary = true;
}
public ulong XferID

View File

@ -1077,14 +1077,12 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
m_scene.RegionInfo.RegionSettings.TerrainImageID = TerrainImageUUID;
AssetBase asset = new AssetBase();
asset.FullID = m_scene.RegionInfo.RegionSettings.TerrainImageID;
AssetBase asset = new AssetBase(
m_scene.RegionInfo.RegionSettings.TerrainImageID,
"terrainImage_" + m_scene.RegionInfo.RegionID.ToString() + "_" + lastMapRefresh.ToString(),
(sbyte)AssetType.Texture);
asset.Data = data;
asset.Name
= "terrainImage_" + m_scene.RegionInfo.RegionID.ToString() + "_" + lastMapRefresh.ToString();
asset.Description = m_scene.RegionInfo.RegionName;
asset.Type = 0;
asset.Temporary = temporary;
m_scene.AssetService.Store(asset);
}

View File

@ -118,7 +118,7 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid
// HGAssetService dispatches it to the remote grid.
// It's not pretty, but the best that can be done while
// not having a global naming infrastructure
AssetBase asset1 = new AssetBase();
AssetBase asset1 = new AssetBase(asset.FullID, asset.Name, asset.Type);
Copy(asset, asset1);
try
{

View File

@ -627,11 +627,8 @@ namespace OpenSim.Region.Framework.Scenes
/// <returns></returns>
private AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data)
{
AssetBase asset = new AssetBase();
asset.Name = name;
AssetBase asset = new AssetBase(UUID.Random(), name, assetType);
asset.Description = description;
asset.Type = assetType;
asset.FullID = UUID.Random();
asset.Data = (data == null) ? new byte[1] : data;
return asset;

View File

@ -1918,14 +1918,10 @@ namespace OpenSim.Region.Framework.Scenes
}
AssetBase Animasset = new AssetBase();
AssetBase Animasset = new AssetBase(UUID.Random(), "Random Animation", (sbyte)AssetType.Animation);
Animasset.Data = anim.ToBytes();
Animasset.Temporary = true;
Animasset.Local = true;
Animasset.FullID = UUID.Random();
Animasset.ID = Animasset.FullID.ToString();
Animasset.Name = "Random Animation";
Animasset.Type = (sbyte)AssetType.Animation;
Animasset.Description = "dance";
//BinBVHAnimation bbvhanim = new BinBVHAnimation(Animasset.Data);

View File

@ -49,11 +49,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
public UUID SaveBitmap(Bitmap data, bool lossless, bool temporary)
{
AssetBase asset = new AssetBase();
asset.FullID = UUID.Random();
AssetBase asset = new AssetBase(UUID.Random(), "MRMDynamicImage", (sbyte)AssetType.Texture);
asset.Data = OpenJPEG.EncodeFromImage(data, lossless);
asset.Name = "MRMDynamicImage";
asset.Type = 0;
asset.Description = "MRM Image";
asset.Local = false;
asset.Temporary = temporary;

View File

@ -1483,12 +1483,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_host.AddScriptLPS(1);
// Create new asset
AssetBase asset = new AssetBase();
asset.Name = notecardName;
AssetBase asset = new AssetBase(UUID.Random(), notecardName, (sbyte)AssetType.Notecard);
asset.Description = "Script Generated Notecard";
asset.Type = 7;
asset.FullID = UUID.Random();
string notecardData = "";
string notecardData = String.Empty;
for (int i = 0; i < contents.Length; i++) {
notecardData += contents.GetLSLStringItem(i) + "\n";

View File

@ -243,7 +243,7 @@ namespace OpenSim.Services.Connectors
if (metadata == null)
return false;
asset = new AssetBase();
asset = new AssetBase(metadata.FullID, metadata.Name, metadata.Type);
asset.Metadata = metadata;
}
asset.Data = data;

View File

@ -140,12 +140,11 @@ namespace OpenSim.Services.Connectors.Grid
Bitmap m = new Bitmap(info.RegionID.ToString() + ".jpg");
//m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width);
byte[] imageData = OpenJPEG.EncodeFromImage(m, true);
AssetBase ass = new AssetBase(UUID.Random(), "region " + info.RegionID.ToString());
AssetBase ass = new AssetBase(UUID.Random(), "region " + info.RegionID.ToString(), (sbyte)AssetType.Texture);
// !!! for now
//info.RegionSettings.TerrainImageID = ass.FullID;
ass.Type = (int)AssetType.Texture;
ass.Temporary = true;
ass.Local = true;
ass.Data = imageData;