* Added a sanity check for missing asset data in LLClientView

* Moved the SL asset type to content type conversion methods from ServerUtils to OpenSim.Framework.SLUtil
* Linked content type to asset type in AssetMetadata
slimupdates
John Hurliman 2010-02-20 16:21:13 -08:00
parent eb22fde96c
commit 845a390e93
5 changed files with 212 additions and 181 deletions

View File

@ -289,8 +289,21 @@ namespace OpenSim.Framework
public string ContentType public string ContentType
{ {
get { return m_content_type; } get
set { m_content_type = value; } {
if (!String.IsNullOrEmpty(m_content_type))
return m_content_type;
else
return SLUtil.SLAssetTypeToContentType(m_type);
}
set
{
m_content_type = value;
sbyte type = (sbyte)SLUtil.ContentTypeToSLAssetType(value);
if (type != -1)
m_type = type;
}
} }
public byte[] SHA1 public byte[] SHA1

185
OpenSim/Framework/SLUtil.cs Normal file
View File

@ -0,0 +1,185 @@
using System;
using OpenMetaverse;
namespace OpenSim.Framework
{
public static class SLUtil
{
#region SL / file extension / content-type conversions
public static string SLAssetTypeToContentType(int assetType)
{
switch ((AssetType)assetType)
{
case AssetType.Texture:
return "image/x-j2c";
case AssetType.Sound:
return "application/ogg";
case AssetType.CallingCard:
return "application/vnd.ll.callingcard";
case AssetType.Landmark:
return "application/vnd.ll.landmark";
case AssetType.Clothing:
return "application/vnd.ll.clothing";
case AssetType.Object:
return "application/vnd.ll.primitive";
case AssetType.Notecard:
return "application/vnd.ll.notecard";
case AssetType.Folder:
return "application/vnd.ll.folder";
case AssetType.RootFolder:
return "application/vnd.ll.rootfolder";
case AssetType.LSLText:
return "application/vnd.ll.lsltext";
case AssetType.LSLBytecode:
return "application/vnd.ll.lslbyte";
case AssetType.TextureTGA:
case AssetType.ImageTGA:
return "image/tga";
case AssetType.Bodypart:
return "application/vnd.ll.bodypart";
case AssetType.TrashFolder:
return "application/vnd.ll.trashfolder";
case AssetType.SnapshotFolder:
return "application/vnd.ll.snapshotfolder";
case AssetType.LostAndFoundFolder:
return "application/vnd.ll.lostandfoundfolder";
case AssetType.SoundWAV:
return "audio/x-wav";
case AssetType.ImageJPEG:
return "image/jpeg";
case AssetType.Animation:
return "application/vnd.ll.animation";
case AssetType.Gesture:
return "application/vnd.ll.gesture";
case AssetType.Simstate:
return "application/x-metaverse-simstate";
case AssetType.Unknown:
default:
return "application/octet-stream";
}
}
public static sbyte ContentTypeToSLAssetType(string contentType)
{
switch (contentType)
{
case "image/x-j2c":
case "image/jp2":
return (sbyte)AssetType.Texture;
case "application/ogg":
return (sbyte)AssetType.Sound;
case "application/vnd.ll.callingcard":
case "application/x-metaverse-callingcard":
return (sbyte)AssetType.CallingCard;
case "application/vnd.ll.landmark":
case "application/x-metaverse-landmark":
return (sbyte)AssetType.Landmark;
case "application/vnd.ll.clothing":
case "application/x-metaverse-clothing":
return (sbyte)AssetType.Clothing;
case "application/vnd.ll.primitive":
case "application/x-metaverse-primitive":
return (sbyte)AssetType.Object;
case "application/vnd.ll.notecard":
case "application/x-metaverse-notecard":
return (sbyte)AssetType.Notecard;
case "application/vnd.ll.folder":
return (sbyte)AssetType.Folder;
case "application/vnd.ll.rootfolder":
return (sbyte)AssetType.RootFolder;
case "application/vnd.ll.lsltext":
case "application/x-metaverse-lsl":
return (sbyte)AssetType.LSLText;
case "application/vnd.ll.lslbyte":
case "application/x-metaverse-lso":
return (sbyte)AssetType.LSLBytecode;
case "image/tga":
// Note that AssetType.TextureTGA will be converted to AssetType.ImageTGA
return (sbyte)AssetType.ImageTGA;
case "application/vnd.ll.bodypart":
case "application/x-metaverse-bodypart":
return (sbyte)AssetType.Bodypart;
case "application/vnd.ll.trashfolder":
return (sbyte)AssetType.TrashFolder;
case "application/vnd.ll.snapshotfolder":
return (sbyte)AssetType.SnapshotFolder;
case "application/vnd.ll.lostandfoundfolder":
return (sbyte)AssetType.LostAndFoundFolder;
case "audio/x-wav":
return (sbyte)AssetType.SoundWAV;
case "image/jpeg":
return (sbyte)AssetType.ImageJPEG;
case "application/vnd.ll.animation":
case "application/x-metaverse-animation":
return (sbyte)AssetType.Animation;
case "application/vnd.ll.gesture":
case "application/x-metaverse-gesture":
return (sbyte)AssetType.Gesture;
case "application/x-metaverse-simstate":
return (sbyte)AssetType.Simstate;
case "application/octet-stream":
default:
return (sbyte)AssetType.Unknown;
}
}
public static sbyte ContentTypeToSLInvType(string contentType)
{
switch (contentType)
{
case "image/x-j2c":
case "image/jp2":
case "image/tga":
case "image/jpeg":
return (sbyte)InventoryType.Texture;
case "application/ogg":
case "audio/x-wav":
return (sbyte)InventoryType.Sound;
case "application/vnd.ll.callingcard":
case "application/x-metaverse-callingcard":
return (sbyte)InventoryType.CallingCard;
case "application/vnd.ll.landmark":
case "application/x-metaverse-landmark":
return (sbyte)InventoryType.Landmark;
case "application/vnd.ll.clothing":
case "application/x-metaverse-clothing":
case "application/vnd.ll.bodypart":
case "application/x-metaverse-bodypart":
return (sbyte)InventoryType.Wearable;
case "application/vnd.ll.primitive":
case "application/x-metaverse-primitive":
return (sbyte)InventoryType.Object;
case "application/vnd.ll.notecard":
case "application/x-metaverse-notecard":
return (sbyte)InventoryType.Notecard;
case "application/vnd.ll.folder":
return (sbyte)InventoryType.Folder;
case "application/vnd.ll.rootfolder":
return (sbyte)InventoryType.RootCategory;
case "application/vnd.ll.lsltext":
case "application/x-metaverse-lsl":
case "application/vnd.ll.lslbyte":
case "application/x-metaverse-lso":
return (sbyte)InventoryType.LSL;
case "application/vnd.ll.trashfolder":
case "application/vnd.ll.snapshotfolder":
case "application/vnd.ll.lostandfoundfolder":
return (sbyte)InventoryType.Folder;
case "application/vnd.ll.animation":
case "application/x-metaverse-animation":
return (sbyte)InventoryType.Animation;
case "application/vnd.ll.gesture":
case "application/x-metaverse-gesture":
return (sbyte)InventoryType.Gesture;
case "application/x-metaverse-simstate":
return (sbyte)InventoryType.Snapshot;
case "application/octet-stream":
default:
return (sbyte)InventoryType.Unknown;
}
}
#endregion SL / file extension / content-type conversions
}
}

View File

@ -2533,6 +2533,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public void SendAsset(AssetRequestToClient req) public void SendAsset(AssetRequestToClient req)
{ {
if (req.AssetInf.Data == null)
{
m_log.ErrorFormat("Cannot send asset {0} ({1}), asset data is null",
req.AssetInf.ID, req.AssetInf.Metadata.ContentType);
return;
}
//m_log.Debug("sending asset " + req.RequestAssetID); //m_log.Debug("sending asset " + req.RequestAssetID);
TransferInfoPacket Transfer = new TransferInfoPacket(); TransferInfoPacket Transfer = new TransferInfoPacket();
Transfer.TransferInfo.ChannelType = 2; Transfer.TransferInfo.ChannelType = 2;
@ -16193,6 +16200,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
const uint m_maxPacketSize = 600; const uint m_maxPacketSize = 600;
int numPackets = 1; int numPackets = 1;
if (data == null)
return 0;
if (data.LongLength > m_maxPacketSize) if (data.LongLength > m_maxPacketSize)
{ {
// over max number of bytes so split up file // over max number of bytes so split up file

View File

@ -42,183 +42,6 @@ namespace OpenSim.Server.Base
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
#region SL / file extension / content-type conversions
public static string SLAssetTypeToContentType(int assetType)
{
switch ((AssetType)assetType)
{
case AssetType.Texture:
return "image/x-j2c";
case AssetType.Sound:
return "application/ogg";
case AssetType.CallingCard:
return "application/vnd.ll.callingcard";
case AssetType.Landmark:
return "application/vnd.ll.landmark";
case AssetType.Clothing:
return "application/vnd.ll.clothing";
case AssetType.Object:
return "application/vnd.ll.primitive";
case AssetType.Notecard:
return "application/vnd.ll.notecard";
case AssetType.Folder:
return "application/vnd.ll.folder";
case AssetType.RootFolder:
return "application/vnd.ll.rootfolder";
case AssetType.LSLText:
return "application/vnd.ll.lsltext";
case AssetType.LSLBytecode:
return "application/vnd.ll.lslbyte";
case AssetType.TextureTGA:
case AssetType.ImageTGA:
return "image/tga";
case AssetType.Bodypart:
return "application/vnd.ll.bodypart";
case AssetType.TrashFolder:
return "application/vnd.ll.trashfolder";
case AssetType.SnapshotFolder:
return "application/vnd.ll.snapshotfolder";
case AssetType.LostAndFoundFolder:
return "application/vnd.ll.lostandfoundfolder";
case AssetType.SoundWAV:
return "audio/x-wav";
case AssetType.ImageJPEG:
return "image/jpeg";
case AssetType.Animation:
return "application/vnd.ll.animation";
case AssetType.Gesture:
return "application/vnd.ll.gesture";
case AssetType.Simstate:
return "application/x-metaverse-simstate";
case AssetType.Unknown:
default:
return "application/octet-stream";
}
}
public static sbyte ContentTypeToSLAssetType(string contentType)
{
switch (contentType)
{
case "image/x-j2c":
case "image/jp2":
return (sbyte)AssetType.Texture;
case "application/ogg":
return (sbyte)AssetType.Sound;
case "application/vnd.ll.callingcard":
case "application/x-metaverse-callingcard":
return (sbyte)AssetType.CallingCard;
case "application/vnd.ll.landmark":
case "application/x-metaverse-landmark":
return (sbyte)AssetType.Landmark;
case "application/vnd.ll.clothing":
case "application/x-metaverse-clothing":
return (sbyte)AssetType.Clothing;
case "application/vnd.ll.primitive":
case "application/x-metaverse-primitive":
return (sbyte)AssetType.Object;
case "application/vnd.ll.notecard":
case "application/x-metaverse-notecard":
return (sbyte)AssetType.Notecard;
case "application/vnd.ll.folder":
return (sbyte)AssetType.Folder;
case "application/vnd.ll.rootfolder":
return (sbyte)AssetType.RootFolder;
case "application/vnd.ll.lsltext":
case "application/x-metaverse-lsl":
return (sbyte)AssetType.LSLText;
case "application/vnd.ll.lslbyte":
case "application/x-metaverse-lso":
return (sbyte)AssetType.LSLBytecode;
case "image/tga":
// Note that AssetType.TextureTGA will be converted to AssetType.ImageTGA
return (sbyte)AssetType.ImageTGA;
case "application/vnd.ll.bodypart":
case "application/x-metaverse-bodypart":
return (sbyte)AssetType.Bodypart;
case "application/vnd.ll.trashfolder":
return (sbyte)AssetType.TrashFolder;
case "application/vnd.ll.snapshotfolder":
return (sbyte)AssetType.SnapshotFolder;
case "application/vnd.ll.lostandfoundfolder":
return (sbyte)AssetType.LostAndFoundFolder;
case "audio/x-wav":
return (sbyte)AssetType.SoundWAV;
case "image/jpeg":
return (sbyte)AssetType.ImageJPEG;
case "application/vnd.ll.animation":
case "application/x-metaverse-animation":
return (sbyte)AssetType.Animation;
case "application/vnd.ll.gesture":
case "application/x-metaverse-gesture":
return (sbyte)AssetType.Gesture;
case "application/x-metaverse-simstate":
return (sbyte)AssetType.Simstate;
case "application/octet-stream":
default:
return (sbyte)AssetType.Unknown;
}
}
public static sbyte ContentTypeToSLInvType(string contentType)
{
switch (contentType)
{
case "image/x-j2c":
case "image/jp2":
case "image/tga":
case "image/jpeg":
return (sbyte)InventoryType.Texture;
case "application/ogg":
case "audio/x-wav":
return (sbyte)InventoryType.Sound;
case "application/vnd.ll.callingcard":
case "application/x-metaverse-callingcard":
return (sbyte)InventoryType.CallingCard;
case "application/vnd.ll.landmark":
case "application/x-metaverse-landmark":
return (sbyte)InventoryType.Landmark;
case "application/vnd.ll.clothing":
case "application/x-metaverse-clothing":
case "application/vnd.ll.bodypart":
case "application/x-metaverse-bodypart":
return (sbyte)InventoryType.Wearable;
case "application/vnd.ll.primitive":
case "application/x-metaverse-primitive":
return (sbyte)InventoryType.Object;
case "application/vnd.ll.notecard":
case "application/x-metaverse-notecard":
return (sbyte)InventoryType.Notecard;
case "application/vnd.ll.folder":
return (sbyte)InventoryType.Folder;
case "application/vnd.ll.rootfolder":
return (sbyte)InventoryType.RootCategory;
case "application/vnd.ll.lsltext":
case "application/x-metaverse-lsl":
case "application/vnd.ll.lslbyte":
case "application/x-metaverse-lso":
return (sbyte)InventoryType.LSL;
case "application/vnd.ll.trashfolder":
case "application/vnd.ll.snapshotfolder":
case "application/vnd.ll.lostandfoundfolder":
return (sbyte)InventoryType.Folder;
case "application/vnd.ll.animation":
case "application/x-metaverse-animation":
return (sbyte)InventoryType.Animation;
case "application/vnd.ll.gesture":
case "application/x-metaverse-gesture":
return (sbyte)InventoryType.Gesture;
case "application/x-metaverse-simstate":
return (sbyte)InventoryType.Snapshot;
case "application/octet-stream":
default:
return (sbyte)InventoryType.Unknown;
}
}
#endregion SL / file extension / content-type conversions
public static byte[] SerializeResult(XmlSerializer xs, object data) public static byte[] SerializeResult(XmlSerializer xs, object data)
{ {
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();

View File

@ -91,7 +91,7 @@ namespace OpenSim.Server.Handlers.Asset
httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.StatusCode = (int)HttpStatusCode.OK;
httpResponse.ContentType = httpResponse.ContentType =
ServerUtils.SLAssetTypeToContentType(metadata.Type); SLUtil.SLAssetTypeToContentType(metadata.Type);
} }
else else
{ {
@ -111,7 +111,7 @@ namespace OpenSim.Server.Handlers.Asset
httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.StatusCode = (int)HttpStatusCode.OK;
httpResponse.ContentType = httpResponse.ContentType =
ServerUtils.SLAssetTypeToContentType(asset.Type); SLUtil.SLAssetTypeToContentType(asset.Type);
} }
else else
{ {