From 29355de6ee01b1f44f32ea45b9c06f636ae9a241 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Mon, 13 Apr 2009 20:04:18 +0000 Subject: * Some more experimental work on distributed assets. Nothing hotwired yet. * Introduced preprocess step in FetchAsset (Might revert this later) * Some minor CCC * Added actual implementation of GetUserProfile( uri ) and the corresponding handler to OGS1. * Introduced non-functioning GetUserUri( userProfile) awaiting user server wireup (this might move elsewhere) --- .../Framework/Communications/Cache/AssetCache.cs | 10 ++-- OpenSim/Framework/Communications/IUserService.cs | 2 + .../Communications/Tests/Cache/AssetCacheTests.cs | 5 ++ .../Framework/Communications/UserManagerBase.cs | 8 ++- OpenSim/Framework/Servers/GetAssetStreamHandler.cs | 67 ++++++++++++++++++---- 5 files changed, 73 insertions(+), 19 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs index cbb2a5a..4d2db17 100644 --- a/OpenSim/Framework/Communications/Cache/AssetCache.cs +++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs @@ -336,7 +336,7 @@ namespace OpenSim.Framework.Communications.Cache { AssetInfo assetInf = new AssetInfo(asset); - ProcessReceivedAsset(IsTexture, assetInf); + ProcessReceivedAsset(IsTexture, assetInf, null); if (!m_memcache.Contains(assetInf.FullID)) { @@ -391,11 +391,11 @@ namespace OpenSim.Framework.Communications.Cache } } - protected void ProcessReceivedAsset(bool IsTexture, AssetInfo assetInf) + protected void ProcessReceivedAsset(bool IsTexture, AssetInfo assetInf, IUserService userService) { if(!IsTexture && assetInf.ContainsReferences && false ) { - assetInf.Data = ProcessAssetData(assetInf.Data); + assetInf.Data = ProcessAssetData(assetInf.Data, userService ); } } @@ -554,11 +554,11 @@ namespace OpenSim.Framework.Communications.Cache } } - public byte[] ProcessAssetData(byte[] assetData) + public byte[] ProcessAssetData(byte[] assetData, IUserService userService) { string data = Encoding.ASCII.GetString(assetData); - data = ProcessAssetDataString(data, null); + data = ProcessAssetDataString(data, userService ); return Encoding.ASCII.GetBytes( data ); } diff --git a/OpenSim/Framework/Communications/IUserService.cs b/OpenSim/Framework/Communications/IUserService.cs index 38c360a..3c09b40 100644 --- a/OpenSim/Framework/Communications/IUserService.cs +++ b/OpenSim/Framework/Communications/IUserService.cs @@ -50,6 +50,8 @@ namespace OpenSim.Framework.Communications UserProfileData GetUserProfile(Uri uri); + Uri GetUserUri(UserProfileData userProfile); + UserAgentData GetAgentByUUID(UUID userId); void ClearUserAgent(UUID avatarID); diff --git a/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs b/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs index 3779f55..9d9810b 100644 --- a/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs +++ b/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs @@ -108,6 +108,11 @@ namespace OpenSim.Framework.Communications.Tests return userProfile; } + public Uri GetUserUri(UserProfileData userProfile) + { + throw new NotImplementedException(); + } + public UserAgentData GetAgentByUUID(UUID userId) { throw new NotImplementedException(); diff --git a/OpenSim/Framework/Communications/UserManagerBase.cs b/OpenSim/Framework/Communications/UserManagerBase.cs index b7280d3..155f5cd 100644 --- a/OpenSim/Framework/Communications/UserManagerBase.cs +++ b/OpenSim/Framework/Communications/UserManagerBase.cs @@ -124,7 +124,7 @@ namespace OpenSim.Framework.Communications public UserProfileData GetUserProfile(Uri uri) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public UserAgentData GetAgentByUUID(UUID userId) @@ -142,6 +142,11 @@ namespace OpenSim.Framework.Communications return null; } + public Uri GetUserUri(UserProfileData userProfile) + { + throw new NotImplementedException(); + } + // see IUserService public virtual UserProfileData GetUserProfile(UUID uuid) { @@ -835,6 +840,5 @@ namespace OpenSim.Framework.Communications } #endregion - } } diff --git a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs index 91d1a28..ffd7ef4 100644 --- a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs +++ b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs @@ -29,6 +29,7 @@ using System; using System.IO; using System.Reflection; using System.Text; +using System.Text.RegularExpressions; using System.Xml; using System.Xml.Serialization; using log4net; @@ -64,9 +65,9 @@ namespace OpenSim.Framework.Servers OSHttpRequest httpRequest, OSHttpResponse httpResponse) { string param = GetParam(path); - byte[] result = new byte[] {}; + byte[] result = new byte[] { }; - string[] p = param.Split(new char[] {'/', '?', '&'}, StringSplitOptions.RemoveEmptyEntries); + string[] p = param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries); if (p.Length > 0) { @@ -85,7 +86,12 @@ namespace OpenSim.Framework.Servers AssetBase asset = m_assetProvider.FetchAsset(assetID); if (asset != null) { - XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); + if (asset.ContainsReferences && false) + { + asset.Data = ProcessOutgoingAssetData(asset.Data); + } + + XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); MemoryStream ms = new MemoryStream(); XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8); xw.Formatting = Formatting.Indented; @@ -97,15 +103,7 @@ namespace OpenSim.Framework.Servers result = ms.GetBuffer(); -//Ckrinke 1/11/09 Commenting out the succesful REST message as under heavy use there -//are multiple messages in a second and that is usually (in my experience) meaning -//the logging itself is slowing down the program. Leaving the unsuccesful message -//as we need to know about that path. -// m_log.InfoFormat( -// "[REST]: GET:/asset found {0} with name {1}, size {2} bytes", -// assetID, asset.Name, result.Length); - - Array.Resize(ref result, (int) ms.Length); + Array.Resize(ref result, (int)ms.Length); } else { @@ -118,5 +116,50 @@ namespace OpenSim.Framework.Servers return result; } + + private byte[] ProcessOutgoingAssetData(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_id|owner_id)\\s+(\\S+)"); + + // IUserService userService = null; + + 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 userUri; + + switch (key) + { + case "creator_id": + userUri = new Guid(value); + // result = "creator_url " + userService(userService, userUri); + break; + + case "owner_id": + userUri = new Guid(value); + // result = "owner_url " + ResolveUserUri(userService, userUri); + break; + } + + return result; + }); + + return data; + } + } } \ No newline at end of file -- cgit v1.1