mirror of
https://github.com/opensim/opensim.git
synced 2026-08-08 18:25:33 +08:00
* Added some more experimental code; nothing wired in so far.
This commit is contained in:
@@ -49,6 +49,19 @@ namespace OpenSim.Framework
|
||||
m_metadata.Name = name;
|
||||
}
|
||||
|
||||
public bool ContainsReferences
|
||||
{
|
||||
get
|
||||
{
|
||||
return
|
||||
IsTextualAsset && (
|
||||
Type != (sbyte)AssetType.Notecard
|
||||
&& Type != (sbyte)AssetType.CallingCard
|
||||
&& Type != (sbyte)AssetType.LSLText
|
||||
&& Type != (sbyte)AssetType.Landmark);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsTextualAsset
|
||||
{
|
||||
get
|
||||
@@ -62,10 +75,22 @@ namespace OpenSim.Framework
|
||||
{
|
||||
get
|
||||
{
|
||||
return
|
||||
return
|
||||
(Type == (sbyte) AssetType.Animation ||
|
||||
Type == (sbyte) AssetType.Gesture ||
|
||||
Type == (sbyte) AssetType.ImageJPEG ||
|
||||
Type == (sbyte)AssetType.Gesture ||
|
||||
Type == (sbyte)AssetType.Simstate ||
|
||||
Type == (sbyte)AssetType.Unknown ||
|
||||
Type == (sbyte)AssetType.Object ||
|
||||
Type == (sbyte)AssetType.Sound ||
|
||||
Type == (sbyte)AssetType.SoundWAV ||
|
||||
Type == (sbyte)AssetType.Texture ||
|
||||
Type == (sbyte)AssetType.TextureTGA ||
|
||||
Type == (sbyte)AssetType.Folder ||
|
||||
Type == (sbyte)AssetType.RootFolder ||
|
||||
Type == (sbyte)AssetType.LostAndFoundFolder ||
|
||||
Type == (sbyte)AssetType.SnapshotFolder ||
|
||||
Type == (sbyte)AssetType.TrashFolder ||
|
||||
Type == (sbyte)AssetType.ImageJPEG ||
|
||||
Type == (sbyte) AssetType.ImageTGA ||
|
||||
Type == (sbyte) AssetType.LSLBytecode);
|
||||
}
|
||||
|
||||
@@ -393,22 +393,26 @@ namespace OpenSim.Framework.Communications.Cache
|
||||
|
||||
protected void ProcessReceivedAsset(bool IsTexture, AssetInfo assetInf)
|
||||
{
|
||||
if(!IsTexture && assetInf.ContainsReferences && false )
|
||||
{
|
||||
assetInf.Data = ProcessAssetData(assetInf.Data);
|
||||
}
|
||||
}
|
||||
|
||||
// See IAssetReceiver
|
||||
public virtual void AssetNotFound(UUID assetID, bool IsTexture)
|
||||
public virtual void AssetNotFound(UUID assetId, bool isTexture)
|
||||
{
|
||||
// m_log.WarnFormat("[ASSET CACHE]: AssetNotFound for {0}", assetID);
|
||||
// m_log.WarnFormat("[ASSET CACHE]: AssetNotFound for {0}", assetId);
|
||||
|
||||
// Remember the fact that this asset could not be found to prevent delays from repeated requests
|
||||
m_memcache.Add(assetID, null, TimeSpan.FromHours(24));
|
||||
m_memcache.Add(assetId, null, TimeSpan.FromHours(24));
|
||||
|
||||
// Notify requesters for this asset
|
||||
AssetRequestsList reqList;
|
||||
lock (RequestLists)
|
||||
{
|
||||
if (RequestLists.TryGetValue(assetID, out reqList))
|
||||
RequestLists.Remove(assetID);
|
||||
if (RequestLists.TryGetValue(assetId, out reqList))
|
||||
RequestLists.Remove(assetId);
|
||||
}
|
||||
|
||||
if (reqList != null)
|
||||
@@ -418,7 +422,7 @@ namespace OpenSim.Framework.Communications.Cache
|
||||
|
||||
foreach (NewAssetRequest req in reqList.Requests)
|
||||
{
|
||||
req.Callback(assetID, null);
|
||||
req.Callback(assetId, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -554,12 +558,12 @@ namespace OpenSim.Framework.Communications.Cache
|
||||
{
|
||||
string data = Encoding.ASCII.GetString(assetData);
|
||||
|
||||
data = ProcessAssetDataString(data);
|
||||
data = ProcessAssetDataString(data, null);
|
||||
|
||||
return Encoding.ASCII.GetBytes( data );
|
||||
}
|
||||
|
||||
public string ProcessAssetDataString(string data)
|
||||
public string ProcessAssetDataString(string data, IUserService userService)
|
||||
{
|
||||
Regex regex = new Regex("(creator_url|owner_url)\\s+(\\S+)");
|
||||
|
||||
@@ -571,16 +575,18 @@ namespace OpenSim.Framework.Communications.Cache
|
||||
|
||||
string value = m.Groups[2].Captures[0].Value;
|
||||
|
||||
Guid id = Util.GetHashGuid(value, AssetInfo.Secret);
|
||||
Uri userUri;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case "creator_url":
|
||||
result = "creator_id " + id;
|
||||
userUri = new Uri(value);
|
||||
result = "creator_id " + ResolveUserUri(userService, userUri);
|
||||
break;
|
||||
|
||||
case "owner_url":
|
||||
result = "owner_id " + id;
|
||||
userUri = new Uri(value);
|
||||
result = "owner_id " + ResolveUserUri(userService, userUri);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -590,6 +596,21 @@ namespace OpenSim.Framework.Communications.Cache
|
||||
return data;
|
||||
}
|
||||
|
||||
private Guid ResolveUserUri(IUserService userService, Uri userUri)
|
||||
{
|
||||
Guid id;
|
||||
UserProfileData userProfile = userService.GetUserProfile(userUri);
|
||||
if( userProfile == null )
|
||||
{
|
||||
id = Guid.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
id = userProfile.ID.Guid;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public class AssetRequest
|
||||
{
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.SyntaxHelpers;
|
||||
@@ -85,15 +87,105 @@ namespace OpenSim.Framework.Communications.Tests
|
||||
}
|
||||
}
|
||||
|
||||
private class FakeUserService : IUserService
|
||||
{
|
||||
public UserProfileData GetUserProfile(string firstName, string lastName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public UserProfileData GetUserProfile(UUID userId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public UserProfileData GetUserProfile(Uri uri)
|
||||
{
|
||||
UserProfileData userProfile = new UserProfileData();
|
||||
|
||||
userProfile.ID = new UUID( Util.GetHashGuid( uri.ToString(), AssetCache.AssetInfo.Secret ));
|
||||
|
||||
return userProfile;
|
||||
}
|
||||
|
||||
public UserAgentData GetAgentByUUID(UUID userId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ClearUserAgent(UUID avatarID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(UUID QueryID, string Query)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public UserProfileData SetupMasterUser(string firstName, string lastName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public UserProfileData SetupMasterUser(string firstName, string lastName, string password)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public UserProfileData SetupMasterUser(UUID userId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool UpdateUserProfile(UserProfileData data)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RemoveUserFriend(UUID friendlistowner, UUID friend)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessAssetDataTest()
|
||||
public void TestProcessAssetData()
|
||||
{
|
||||
string url = "http://host/dir/";
|
||||
string data = " creator_url " + url + " ";
|
||||
string creatorData = " creator_url " + url + " ";
|
||||
string ownerData = " owner_url " + url + " ";
|
||||
|
||||
AssetCache assetCache = new AssetCache();
|
||||
FakeUserService fakeUserService = new FakeUserService();
|
||||
|
||||
Assert.AreEqual(" creator_id "+Util.GetHashGuid( url, AssetCache.AssetInfo.Secret )+" ", assetCache.ProcessAssetDataString( data ));
|
||||
Assert.AreEqual(" creator_id " + Util.GetHashGuid(url, AssetCache.AssetInfo.Secret) + " ", assetCache.ProcessAssetDataString(creatorData, fakeUserService));
|
||||
Assert.AreEqual(" owner_id " + Util.GetHashGuid(url, AssetCache.AssetInfo.Secret) + " ", assetCache.ProcessAssetDataString(ownerData, fakeUserService));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
49
OpenSim/Framework/Tests/AssetBaseTest.cs
Normal file
49
OpenSim/Framework/Tests/AssetBaseTest.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using OpenMetaverse;
|
||||
|
||||
namespace OpenSim.Framework.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class AssetBaseTest
|
||||
{
|
||||
[Test]
|
||||
public void TestContainsReferences()
|
||||
{
|
||||
TestContainsReferences(AssetType.Bodypart, true);
|
||||
TestContainsReferences(AssetType.Clothing, true);
|
||||
|
||||
TestContainsReferences(AssetType.Animation, false);
|
||||
TestContainsReferences(AssetType.CallingCard, false);
|
||||
TestContainsReferences(AssetType.Folder , false);
|
||||
TestContainsReferences(AssetType.Gesture , false);
|
||||
TestContainsReferences(AssetType.ImageJPEG , false);
|
||||
TestContainsReferences(AssetType.ImageTGA , false);
|
||||
TestContainsReferences(AssetType.Landmark , false);
|
||||
TestContainsReferences(AssetType.LostAndFoundFolder, false);
|
||||
TestContainsReferences(AssetType.LSLBytecode, false);
|
||||
TestContainsReferences(AssetType.LSLText, false);
|
||||
TestContainsReferences(AssetType.Notecard, false);
|
||||
TestContainsReferences(AssetType.Object, false);
|
||||
TestContainsReferences(AssetType.RootFolder, false);
|
||||
TestContainsReferences(AssetType.Simstate, false);
|
||||
TestContainsReferences(AssetType.SnapshotFolder, false);
|
||||
TestContainsReferences(AssetType.Sound, false);
|
||||
TestContainsReferences(AssetType.SoundWAV, false);
|
||||
TestContainsReferences(AssetType.Texture, false);
|
||||
TestContainsReferences(AssetType.TextureTGA, false);
|
||||
TestContainsReferences(AssetType.TrashFolder, false);
|
||||
TestContainsReferences(AssetType.Unknown, false);
|
||||
}
|
||||
|
||||
private void TestContainsReferences(AssetType assetType, bool expected)
|
||||
{
|
||||
AssetBase asset = new AssetBase();
|
||||
asset.Type = (sbyte)assetType;
|
||||
bool actual = asset.ContainsReferences;
|
||||
Assert.AreEqual(expected, actual, "Expected "+assetType+".ContainsReferences to be "+expected+" but was "+actual+".");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user