From e93b782f9d86e4049a28d7f90c691dc5d242f234 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Wed, 8 Apr 2009 19:59:37 +0000 Subject: * Introduced some experimental code with regards to asset data substitution --- OpenSim/Framework/AssetBase.cs | 22 +++++++++++ .../Framework/Communications/Cache/AssetCache.cs | 43 ++++++++++++++++++++++ OpenSim/Framework/Communications/IUserService.cs | 3 ++ .../Communications/Tests/Cache/AssetCacheTests.cs | 17 +++++++-- .../Framework/Communications/UserManagerBase.cs | 5 +++ .../Communications/Hypergrid/HGUserServices.cs | 6 +++ .../Region/Communications/OGS1/OGS1UserServices.cs | 5 +++ 7 files changed, 98 insertions(+), 3 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/AssetBase.cs b/OpenSim/Framework/AssetBase.cs index 5c311c0..03b6ea8 100644 --- a/OpenSim/Framework/AssetBase.cs +++ b/OpenSim/Framework/AssetBase.cs @@ -49,6 +49,28 @@ namespace OpenSim.Framework m_metadata.Name = name; } + public bool IsTextualAsset + { + get + { + return !IsBinaryAsset; + } + + } + + public bool IsBinaryAsset + { + get + { + return + Type == (sbyte) AssetType.Animation || + Type == (sbyte) AssetType.Gesture || + Type == (sbyte) AssetType.ImageJPEG || + Type == (sbyte) AssetType.ImageTGA || + Type == (sbyte) AssetType.LSLBytecode ||; + } + } + public virtual byte[] Data { get { return m_data; } diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs index e0d0bd7..b571c0b 100644 --- a/OpenSim/Framework/Communications/Cache/AssetCache.cs +++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs @@ -28,6 +28,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using System.Text.RegularExpressions; using System.Threading; using GlynnTucker.Cache; using log4net; @@ -547,9 +548,49 @@ namespace OpenSim.Framework.Communications.Cache req.RequestUser.SendAsset(req2); } + } + + public byte[] ProcessAssetData(byte[] assetData) + { + string data = Encoding.ASCII.GetString(assetData); + + data = ProcessAssetDataString(data); + + return Encoding.ASCII.GetBytes( data ); + } + + public string ProcessAssetDataString(string data) + { + Regex regex = new Regex("(creator_url|owner_url)\\s+(\\S+)"); + + data = regex.Replace(data, delegate(Match m) + { + string result = String.Empty; + string key = m.Groups[1].Captures[0].Value; + + string value = m.Groups[2].Captures[0].Value; + + Guid id = Util.GetHashGuid(value, AssetInfo.Secret); + + switch (key) + { + case "creator_url": + result = "creator_id " + id; + break; + + case "owner_url": + result = "owner_id " + id; + break; + } + + return result; + }); + + return data; } + public class AssetRequest { public IClientAPI RequestUser; @@ -578,6 +619,8 @@ namespace OpenSim.Framework.Communications.Cache Name = aBase.Name; Description = aBase.Description; } + + public const string Secret = "secret"; } public class TextureImage : AssetBase diff --git a/OpenSim/Framework/Communications/IUserService.cs b/OpenSim/Framework/Communications/IUserService.cs index 0846024..38c360a 100644 --- a/OpenSim/Framework/Communications/IUserService.cs +++ b/OpenSim/Framework/Communications/IUserService.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; using System.Collections.Generic; using OpenMetaverse; @@ -46,6 +47,8 @@ namespace OpenSim.Framework.Communications /// The target UUID /// A user profile. Returns null if no user profile is found. UserProfileData GetUserProfile(UUID userId); + + UserProfileData GetUserProfile(Uri uri); UserAgentData GetAgentByUUID(UUID userId); diff --git a/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs b/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs index 18ae9a7..70a398e 100644 --- a/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs +++ b/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs @@ -73,16 +73,27 @@ namespace OpenSim.Framework.Communications.Tests Assert.That( assetData, Is.EqualTo(m_assetReceived.Data), "Asset data stored differs from asset data received"); } - + private void AssetRequestCallback(UUID assetId, AssetBase asset) { m_assetIdReceived = assetId; m_assetReceived = asset; - + lock (this) { Monitor.PulseAll(this); - } + } + } + + [Test] + public void ProcessAssetDataTest() + { + string url = "http://host/dir/"; + string data = " creator_url " + url + " "; + + AssetCache assetCache = new AssetCache(); + + Assert.AreEqual(" creator_id "+Util.GetHashGuid( url, AssetCache.AssetInfo.Secret )+" ", assetCache.ProcessAssetDataString( data )); } } } diff --git a/OpenSim/Framework/Communications/UserManagerBase.cs b/OpenSim/Framework/Communications/UserManagerBase.cs index c177d4f..b7280d3 100644 --- a/OpenSim/Framework/Communications/UserManagerBase.cs +++ b/OpenSim/Framework/Communications/UserManagerBase.cs @@ -122,6 +122,11 @@ namespace OpenSim.Framework.Communications } } + public UserProfileData GetUserProfile(Uri uri) + { + throw new System.NotImplementedException(); + } + public UserAgentData GetAgentByUUID(UUID userId) { foreach (IUserDataPlugin plugin in _plugins) diff --git a/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs b/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs index e9eb18c..6a39876 100644 --- a/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs +++ b/OpenSim/Region/Communications/Hypergrid/HGUserServices.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; using System.Collections; using System.Collections.Generic; using OpenMetaverse; @@ -57,6 +58,11 @@ namespace OpenSim.Region.Communications.Hypergrid return m_remoteUserServices.ConvertXMLRPCDataToUserProfile(data); } + public UserProfileData GetUserProfile(Uri uri) + { + throw new System.NotImplementedException(); + } + /// /// Get a user agent from the user server /// diff --git a/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs b/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs index 6235565..09c1d6a 100644 --- a/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs +++ b/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs @@ -108,6 +108,11 @@ namespace OpenSim.Region.Communications.OGS1 return userData; } + public UserProfileData GetUserProfile(Uri uri) + { + throw new System.NotImplementedException(); + } + /// /// Get a user agent from the user server /// -- cgit v1.1