* Added some more experimental code; nothing wired in so far.

0.6.5-rc1
lbsa71 2009-04-09 16:45:22 +00:00
parent 5572a00295
commit d2a412e94b
5 changed files with 272 additions and 57 deletions

View File

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

View File

@ -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
{

View File

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

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

View File

@ -41,7 +41,7 @@ namespace OpenSim.Grid.UserServer.Modules
{
public delegate void logOffUser(UUID AgentID);
public class UserManager
public class UserManager
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -50,12 +50,12 @@ namespace OpenSim.Grid.UserServer.Modules
private UserDataBaseService m_userDataBaseService;
private BaseHttpServer m_httpServer;
/// <summary>
///
/// </summary>
/// <param name="userDataBaseService"></param>
public UserManager( UserDataBaseService userDataBaseService)
public UserManager(UserDataBaseService userDataBaseService)
{
m_userDataBaseService = userDataBaseService;
}
@ -70,10 +70,38 @@ namespace OpenSim.Grid.UserServer.Modules
}
private string RESTGetUserProfile(string request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
{
UUID id;
UserProfileData userProfile;
try
{
id = new UUID(param);
}
catch (Exception)
{
httpResponse.StatusCode = 500;
return "Malformed Param [" + param + "]";
}
userProfile = m_userDataBaseService.GetUserProfile(id);
if (userProfile == null)
{
httpResponse.StatusCode = 404;
return "Not Found.";
}
return ProfileToXmlRPCResponse(userProfile).ToString();
}
public void RegisterHandlers(BaseHttpServer httpServer)
{
m_httpServer = httpServer;
m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/users/", RESTGetUserProfile));
m_httpServer.AddXmlRPCHandler("get_user_by_name", XmlRPCGetUserMethodName);
m_httpServer.AddXmlRPCHandler("get_user_by_uuid", XmlRPCGetUserMethodUUID);
m_httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", XmlRPCGetAvatarPickerAvatar);
@ -191,24 +219,24 @@ namespace OpenSim.Grid.UserServer.Modules
public XmlRpcResponse XmlRPCGetAvatarPickerAvatar(XmlRpcRequest request)
{
// XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable) request.Params[0];
Hashtable requestData = (Hashtable)request.Params[0];
List<AvatarPickerAvatar> returnAvatar = new List<AvatarPickerAvatar>();
UUID queryID = new UUID(UUID.Zero.ToString());
if (requestData.Contains("avquery") && requestData.Contains("queryid"))
{
queryID = new UUID((string) requestData["queryid"]);
returnAvatar = m_userDataBaseService.GenerateAgentPickerRequestResponse(queryID, (string) requestData["avquery"]);
queryID = new UUID((string)requestData["queryid"]);
returnAvatar = m_userDataBaseService.GenerateAgentPickerRequestResponse(queryID, (string)requestData["avquery"]);
}
m_log.InfoFormat("[AVATARINFO]: Servicing Avatar Query: " + (string) requestData["avquery"]);
m_log.InfoFormat("[AVATARINFO]: Servicing Avatar Query: " + (string)requestData["avquery"]);
return AvatarPickerListtoXmlRPCResponse(queryID, returnAvatar);
}
public XmlRpcResponse XmlRPCAtRegion(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable) request.Params[0];
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable responseData = new Hashtable();
string returnstring = "FALSE";
@ -219,14 +247,14 @@ namespace OpenSim.Grid.UserServer.Modules
UUID regionUUID;
UUID avatarUUID;
UUID.TryParse((string) requestData["avatar_id"], out avatarUUID);
UUID.TryParse((string) requestData["region_uuid"], out regionUUID);
UUID.TryParse((string)requestData["avatar_id"], out avatarUUID);
UUID.TryParse((string)requestData["region_uuid"], out regionUUID);
if (avatarUUID != UUID.Zero)
{
UserProfileData userProfile = m_userDataBaseService.GetUserProfile(avatarUUID);
userProfile.CurrentAgent.Region = regionUUID;
userProfile.CurrentAgent.Handle = (ulong) Convert.ToInt64((string) requestData["region_handle"]);
userProfile.CurrentAgent.Handle = (ulong)Convert.ToInt64((string)requestData["region_handle"]);
//userProfile.CurrentAgent.
m_userDataBaseService.CommitAgent(ref userProfile);
//setUserProfile(userProfile);
@ -243,11 +271,11 @@ namespace OpenSim.Grid.UserServer.Modules
public XmlRpcResponse XmlRPCGetUserMethodName(XmlRpcRequest request)
{
// XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable) request.Params[0];
Hashtable requestData = (Hashtable)request.Params[0];
UserProfileData userProfile;
if (requestData.Contains("avatar_name"))
{
string query = (string) requestData["avatar_name"];
string query = (string)requestData["avatar_name"];
if (null == query)
return CreateUnknownUserErrorResponse();
@ -280,7 +308,7 @@ namespace OpenSim.Grid.UserServer.Modules
public XmlRpcResponse XmlRPCGetUserMethodUUID(XmlRpcRequest request)
{
// XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable) request.Params[0];
Hashtable requestData = (Hashtable)request.Params[0];
UserProfileData userProfile;
//CFK: this clogs the UserServer log and is not necessary at this time.
//CFK: m_log.Debug("METHOD BY UUID CALLED");
@ -288,7 +316,7 @@ namespace OpenSim.Grid.UserServer.Modules
{
try
{
UUID guess = new UUID((string) requestData["avatar_uuid"]);
UUID guess = new UUID((string)requestData["avatar_uuid"]);
userProfile = m_userDataBaseService.GetUserProfile(guess);
}
@ -313,7 +341,7 @@ namespace OpenSim.Grid.UserServer.Modules
public XmlRpcResponse XmlRPCGetAgentMethodUUID(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable) request.Params[0];
Hashtable requestData = (Hashtable)request.Params[0];
UserProfileData userProfile;
//CFK: this clogs the UserServer log and is not necessary at this time.
//CFK: m_log.Debug("METHOD BY UUID CALLED");
@ -321,7 +349,7 @@ namespace OpenSim.Grid.UserServer.Modules
{
UUID guess;
UUID.TryParse((string) requestData["avatar_uuid"], out guess);
UUID.TryParse((string)requestData["avatar_uuid"], out guess);
if (guess == UUID.Zero)
{
@ -362,7 +390,7 @@ namespace OpenSim.Grid.UserServer.Modules
public XmlRpcResponse XmlRPCCheckAuthSession(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable) request.Params[0];
Hashtable requestData = (Hashtable)request.Params[0];
UserProfileData userProfile;
string authed = "FALSE";
@ -371,12 +399,12 @@ namespace OpenSim.Grid.UserServer.Modules
UUID guess_aid;
UUID guess_sid;
UUID.TryParse((string) requestData["avatar_uuid"], out guess_aid);
UUID.TryParse((string)requestData["avatar_uuid"], out guess_aid);
if (guess_aid == UUID.Zero)
{
return CreateUnknownUserErrorResponse();
}
UUID.TryParse((string) requestData["session_id"], out guess_sid);
UUID.TryParse((string)requestData["session_id"], out guess_sid);
if (guess_sid == UUID.Zero)
{
return CreateUnknownUserErrorResponse();
@ -404,7 +432,7 @@ namespace OpenSim.Grid.UserServer.Modules
{
m_log.Debug("[UserManager]: Got request to update user profile");
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable) request.Params[0];
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable responseData = new Hashtable();
if (!requestData.Contains("avatar_uuid"))
@ -412,7 +440,7 @@ namespace OpenSim.Grid.UserServer.Modules
return CreateUnknownUserErrorResponse();
}
UUID UserUUID = new UUID((string) requestData["avatar_uuid"]);
UUID UserUUID = new UUID((string)requestData["avatar_uuid"]);
UserProfileData userProfile = m_userDataBaseService.GetUserProfile(UserUUID);
if (null == userProfile)
{
@ -424,11 +452,11 @@ namespace OpenSim.Grid.UserServer.Modules
}
if (requestData.Contains("FLImageID"))
{
userProfile.FirstLifeImage = new UUID((string) requestData["FLImageID"]);
userProfile.FirstLifeImage = new UUID((string)requestData["FLImageID"]);
}
if (requestData.Contains("ImageID"))
{
userProfile.Image = new UUID((string) requestData["ImageID"]);
userProfile.Image = new UUID((string)requestData["ImageID"]);
}
// dont' know how yet
if (requestData.Contains("MaturePublish"))
@ -436,11 +464,11 @@ namespace OpenSim.Grid.UserServer.Modules
}
if (requestData.Contains("AboutText"))
{
userProfile.AboutText = (string) requestData["AboutText"];
userProfile.AboutText = (string)requestData["AboutText"];
}
if (requestData.Contains("FLAboutText"))
{
userProfile.FirstLifeAboutText = (string) requestData["FLAboutText"];
userProfile.FirstLifeAboutText = (string)requestData["FLAboutText"];
}
// not in DB yet.
if (requestData.Contains("ProfileURL"))
@ -450,7 +478,7 @@ namespace OpenSim.Grid.UserServer.Modules
{
try
{
userProfile.HomeRegion = Convert.ToUInt64((string) requestData["home_region"]);
userProfile.HomeRegion = Convert.ToUInt64((string)requestData["home_region"]);
}
catch (ArgumentException)
{
@ -468,14 +496,14 @@ namespace OpenSim.Grid.UserServer.Modules
if (requestData.Contains("home_region_id"))
{
UUID regionID;
UUID.TryParse((string) requestData["home_region_id"], out regionID);
UUID.TryParse((string)requestData["home_region_id"], out regionID);
userProfile.HomeRegionID = regionID;
}
if (requestData.Contains("home_pos_x"))
{
try
{
userProfile.HomeLocationX = (float) Convert.ToDecimal((string) requestData["home_pos_x"]);
userProfile.HomeLocationX = (float)Convert.ToDecimal((string)requestData["home_pos_x"]);
}
catch (InvalidCastException)
{
@ -486,7 +514,7 @@ namespace OpenSim.Grid.UserServer.Modules
{
try
{
userProfile.HomeLocationY = (float) Convert.ToDecimal((string) requestData["home_pos_y"]);
userProfile.HomeLocationY = (float)Convert.ToDecimal((string)requestData["home_pos_y"]);
}
catch (InvalidCastException)
{
@ -497,7 +525,7 @@ namespace OpenSim.Grid.UserServer.Modules
{
try
{
userProfile.HomeLocationZ = (float) Convert.ToDecimal((string) requestData["home_pos_z"]);
userProfile.HomeLocationZ = (float)Convert.ToDecimal((string)requestData["home_pos_z"]);
}
catch (InvalidCastException)
{
@ -508,7 +536,7 @@ namespace OpenSim.Grid.UserServer.Modules
{
try
{
userProfile.HomeLookAtX = (float) Convert.ToDecimal((string) requestData["home_look_x"]);
userProfile.HomeLookAtX = (float)Convert.ToDecimal((string)requestData["home_look_x"]);
}
catch (InvalidCastException)
{
@ -519,7 +547,7 @@ namespace OpenSim.Grid.UserServer.Modules
{
try
{
userProfile.HomeLookAtY = (float) Convert.ToDecimal((string) requestData["home_look_y"]);
userProfile.HomeLookAtY = (float)Convert.ToDecimal((string)requestData["home_look_y"]);
}
catch (InvalidCastException)
{
@ -530,7 +558,7 @@ namespace OpenSim.Grid.UserServer.Modules
{
try
{
userProfile.HomeLookAtZ = (float) Convert.ToDecimal((string) requestData["home_look_z"]);
userProfile.HomeLookAtZ = (float)Convert.ToDecimal((string)requestData["home_look_z"]);
}
catch (InvalidCastException)
{
@ -541,7 +569,7 @@ namespace OpenSim.Grid.UserServer.Modules
{
try
{
userProfile.UserFlags = Convert.ToInt32((string) requestData["user_flags"]);
userProfile.UserFlags = Convert.ToInt32((string)requestData["user_flags"]);
}
catch (InvalidCastException)
{
@ -552,7 +580,7 @@ namespace OpenSim.Grid.UserServer.Modules
{
try
{
userProfile.GodLevel = Convert.ToInt32((string) requestData["god_level"]);
userProfile.GodLevel = Convert.ToInt32((string)requestData["god_level"]);
}
catch (InvalidCastException)
{
@ -563,7 +591,7 @@ namespace OpenSim.Grid.UserServer.Modules
{
try
{
userProfile.CustomType = (string) requestData["custom_type"];
userProfile.CustomType = (string)requestData["custom_type"];
}
catch (InvalidCastException)
{
@ -574,7 +602,7 @@ namespace OpenSim.Grid.UserServer.Modules
{
try
{
userProfile.Partner = new UUID((string) requestData["partner"]);
userProfile.Partner = new UUID((string)requestData["partner"]);
}
catch (InvalidCastException)
{
@ -596,7 +624,7 @@ namespace OpenSim.Grid.UserServer.Modules
public XmlRpcResponse XmlRPCLogOffUserMethodUUID(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable) request.Params[0];
Hashtable requestData = (Hashtable)request.Params[0];
if (requestData.Contains("avatar_uuid"))
{
@ -685,6 +713,6 @@ namespace OpenSim.Grid.UserServer.Modules
public void HandleRegionShutdown(UUID regionID)
{
m_userDataBaseService.LogoutUsers(regionID);
}
}
}
}