diff options
author | lbsa71 | 2009-04-09 16:45:22 +0000 |
---|---|---|
committer | lbsa71 | 2009-04-09 16:45:22 +0000 |
commit | d2a412e94bf3ef1e332d44b7106c606f26b1636b (patch) | |
tree | ba7535b2a55edf538e067d7ac72a1ee55943215e /OpenSim/Framework | |
parent | * Moved the DatabaseTestAttribute to Test.Common, and thus included ref to th... (diff) | |
download | opensim-SC-d2a412e94bf3ef1e332d44b7106c606f26b1636b.zip opensim-SC-d2a412e94bf3ef1e332d44b7106c606f26b1636b.tar.gz opensim-SC-d2a412e94bf3ef1e332d44b7106c606f26b1636b.tar.bz2 opensim-SC-d2a412e94bf3ef1e332d44b7106c606f26b1636b.tar.xz |
* Added some more experimental code; nothing wired in so far.
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/AssetBase.cs | 31 | ||||
-rw-r--r-- | OpenSim/Framework/Communications/Cache/AssetCache.cs | 43 | ||||
-rw-r--r-- | OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs | 98 | ||||
-rw-r--r-- | OpenSim/Framework/Tests/AssetBaseTest.cs | 49 |
4 files changed, 204 insertions, 17 deletions
diff --git a/OpenSim/Framework/AssetBase.cs b/OpenSim/Framework/AssetBase.cs index 8e7e059..4e43cb7 100644 --- a/OpenSim/Framework/AssetBase.cs +++ b/OpenSim/Framework/AssetBase.cs | |||
@@ -49,6 +49,19 @@ namespace OpenSim.Framework | |||
49 | m_metadata.Name = name; | 49 | m_metadata.Name = name; |
50 | } | 50 | } |
51 | 51 | ||
52 | public bool ContainsReferences | ||
53 | { | ||
54 | get | ||
55 | { | ||
56 | return | ||
57 | IsTextualAsset && ( | ||
58 | Type != (sbyte)AssetType.Notecard | ||
59 | && Type != (sbyte)AssetType.CallingCard | ||
60 | && Type != (sbyte)AssetType.LSLText | ||
61 | && Type != (sbyte)AssetType.Landmark); | ||
62 | } | ||
63 | } | ||
64 | |||
52 | public bool IsTextualAsset | 65 | public bool IsTextualAsset |
53 | { | 66 | { |
54 | get | 67 | get |
@@ -62,10 +75,22 @@ namespace OpenSim.Framework | |||
62 | { | 75 | { |
63 | get | 76 | get |
64 | { | 77 | { |
65 | return | 78 | return |
66 | (Type == (sbyte) AssetType.Animation || | 79 | (Type == (sbyte) AssetType.Animation || |
67 | Type == (sbyte) AssetType.Gesture || | 80 | Type == (sbyte)AssetType.Gesture || |
68 | Type == (sbyte) AssetType.ImageJPEG || | 81 | Type == (sbyte)AssetType.Simstate || |
82 | Type == (sbyte)AssetType.Unknown || | ||
83 | Type == (sbyte)AssetType.Object || | ||
84 | Type == (sbyte)AssetType.Sound || | ||
85 | Type == (sbyte)AssetType.SoundWAV || | ||
86 | Type == (sbyte)AssetType.Texture || | ||
87 | Type == (sbyte)AssetType.TextureTGA || | ||
88 | Type == (sbyte)AssetType.Folder || | ||
89 | Type == (sbyte)AssetType.RootFolder || | ||
90 | Type == (sbyte)AssetType.LostAndFoundFolder || | ||
91 | Type == (sbyte)AssetType.SnapshotFolder || | ||
92 | Type == (sbyte)AssetType.TrashFolder || | ||
93 | Type == (sbyte)AssetType.ImageJPEG || | ||
69 | Type == (sbyte) AssetType.ImageTGA || | 94 | Type == (sbyte) AssetType.ImageTGA || |
70 | Type == (sbyte) AssetType.LSLBytecode); | 95 | Type == (sbyte) AssetType.LSLBytecode); |
71 | } | 96 | } |
diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs index b571c0b..cbb2a5a 100644 --- a/OpenSim/Framework/Communications/Cache/AssetCache.cs +++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs | |||
@@ -393,22 +393,26 @@ namespace OpenSim.Framework.Communications.Cache | |||
393 | 393 | ||
394 | protected void ProcessReceivedAsset(bool IsTexture, AssetInfo assetInf) | 394 | protected void ProcessReceivedAsset(bool IsTexture, AssetInfo assetInf) |
395 | { | 395 | { |
396 | if(!IsTexture && assetInf.ContainsReferences && false ) | ||
397 | { | ||
398 | assetInf.Data = ProcessAssetData(assetInf.Data); | ||
399 | } | ||
396 | } | 400 | } |
397 | 401 | ||
398 | // See IAssetReceiver | 402 | // See IAssetReceiver |
399 | public virtual void AssetNotFound(UUID assetID, bool IsTexture) | 403 | public virtual void AssetNotFound(UUID assetId, bool isTexture) |
400 | { | 404 | { |
401 | // m_log.WarnFormat("[ASSET CACHE]: AssetNotFound for {0}", assetID); | 405 | // m_log.WarnFormat("[ASSET CACHE]: AssetNotFound for {0}", assetId); |
402 | 406 | ||
403 | // Remember the fact that this asset could not be found to prevent delays from repeated requests | 407 | // Remember the fact that this asset could not be found to prevent delays from repeated requests |
404 | m_memcache.Add(assetID, null, TimeSpan.FromHours(24)); | 408 | m_memcache.Add(assetId, null, TimeSpan.FromHours(24)); |
405 | 409 | ||
406 | // Notify requesters for this asset | 410 | // Notify requesters for this asset |
407 | AssetRequestsList reqList; | 411 | AssetRequestsList reqList; |
408 | lock (RequestLists) | 412 | lock (RequestLists) |
409 | { | 413 | { |
410 | if (RequestLists.TryGetValue(assetID, out reqList)) | 414 | if (RequestLists.TryGetValue(assetId, out reqList)) |
411 | RequestLists.Remove(assetID); | 415 | RequestLists.Remove(assetId); |
412 | } | 416 | } |
413 | 417 | ||
414 | if (reqList != null) | 418 | if (reqList != null) |
@@ -418,7 +422,7 @@ namespace OpenSim.Framework.Communications.Cache | |||
418 | 422 | ||
419 | foreach (NewAssetRequest req in reqList.Requests) | 423 | foreach (NewAssetRequest req in reqList.Requests) |
420 | { | 424 | { |
421 | req.Callback(assetID, null); | 425 | req.Callback(assetId, null); |
422 | } | 426 | } |
423 | } | 427 | } |
424 | } | 428 | } |
@@ -554,12 +558,12 @@ namespace OpenSim.Framework.Communications.Cache | |||
554 | { | 558 | { |
555 | string data = Encoding.ASCII.GetString(assetData); | 559 | string data = Encoding.ASCII.GetString(assetData); |
556 | 560 | ||
557 | data = ProcessAssetDataString(data); | 561 | data = ProcessAssetDataString(data, null); |
558 | 562 | ||
559 | return Encoding.ASCII.GetBytes( data ); | 563 | return Encoding.ASCII.GetBytes( data ); |
560 | } | 564 | } |
561 | 565 | ||
562 | public string ProcessAssetDataString(string data) | 566 | public string ProcessAssetDataString(string data, IUserService userService) |
563 | { | 567 | { |
564 | Regex regex = new Regex("(creator_url|owner_url)\\s+(\\S+)"); | 568 | Regex regex = new Regex("(creator_url|owner_url)\\s+(\\S+)"); |
565 | 569 | ||
@@ -571,16 +575,18 @@ namespace OpenSim.Framework.Communications.Cache | |||
571 | 575 | ||
572 | string value = m.Groups[2].Captures[0].Value; | 576 | string value = m.Groups[2].Captures[0].Value; |
573 | 577 | ||
574 | Guid id = Util.GetHashGuid(value, AssetInfo.Secret); | 578 | Uri userUri; |
575 | 579 | ||
576 | switch (key) | 580 | switch (key) |
577 | { | 581 | { |
578 | case "creator_url": | 582 | case "creator_url": |
579 | result = "creator_id " + id; | 583 | userUri = new Uri(value); |
584 | result = "creator_id " + ResolveUserUri(userService, userUri); | ||
580 | break; | 585 | break; |
581 | 586 | ||
582 | case "owner_url": | 587 | case "owner_url": |
583 | result = "owner_id " + id; | 588 | userUri = new Uri(value); |
589 | result = "owner_id " + ResolveUserUri(userService, userUri); | ||
584 | break; | 590 | break; |
585 | } | 591 | } |
586 | 592 | ||
@@ -590,6 +596,21 @@ namespace OpenSim.Framework.Communications.Cache | |||
590 | return data; | 596 | return data; |
591 | } | 597 | } |
592 | 598 | ||
599 | private Guid ResolveUserUri(IUserService userService, Uri userUri) | ||
600 | { | ||
601 | Guid id; | ||
602 | UserProfileData userProfile = userService.GetUserProfile(userUri); | ||
603 | if( userProfile == null ) | ||
604 | { | ||
605 | id = Guid.Empty; | ||
606 | } | ||
607 | else | ||
608 | { | ||
609 | id = userProfile.ID.Guid; | ||
610 | } | ||
611 | return id; | ||
612 | } | ||
613 | |||
593 | 614 | ||
594 | public class AssetRequest | 615 | public class AssetRequest |
595 | { | 616 | { |
diff --git a/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs b/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs index 70a398e..3779f55 100644 --- a/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs +++ b/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs | |||
@@ -25,6 +25,8 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
28 | using System.Threading; | 30 | using System.Threading; |
29 | using NUnit.Framework; | 31 | using NUnit.Framework; |
30 | using NUnit.Framework.SyntaxHelpers; | 32 | using NUnit.Framework.SyntaxHelpers; |
@@ -85,15 +87,105 @@ namespace OpenSim.Framework.Communications.Tests | |||
85 | } | 87 | } |
86 | } | 88 | } |
87 | 89 | ||
90 | private class FakeUserService : IUserService | ||
91 | { | ||
92 | public UserProfileData GetUserProfile(string firstName, string lastName) | ||
93 | { | ||
94 | throw new NotImplementedException(); | ||
95 | } | ||
96 | |||
97 | public UserProfileData GetUserProfile(UUID userId) | ||
98 | { | ||
99 | throw new NotImplementedException(); | ||
100 | } | ||
101 | |||
102 | public UserProfileData GetUserProfile(Uri uri) | ||
103 | { | ||
104 | UserProfileData userProfile = new UserProfileData(); | ||
105 | |||
106 | userProfile.ID = new UUID( Util.GetHashGuid( uri.ToString(), AssetCache.AssetInfo.Secret )); | ||
107 | |||
108 | return userProfile; | ||
109 | } | ||
110 | |||
111 | public UserAgentData GetAgentByUUID(UUID userId) | ||
112 | { | ||
113 | throw new NotImplementedException(); | ||
114 | } | ||
115 | |||
116 | public void ClearUserAgent(UUID avatarID) | ||
117 | { | ||
118 | throw new NotImplementedException(); | ||
119 | } | ||
120 | |||
121 | public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(UUID QueryID, string Query) | ||
122 | { | ||
123 | throw new NotImplementedException(); | ||
124 | } | ||
125 | |||
126 | public UserProfileData SetupMasterUser(string firstName, string lastName) | ||
127 | { | ||
128 | throw new NotImplementedException(); | ||
129 | } | ||
130 | |||
131 | public UserProfileData SetupMasterUser(string firstName, string lastName, string password) | ||
132 | { | ||
133 | throw new NotImplementedException(); | ||
134 | } | ||
135 | |||
136 | public UserProfileData SetupMasterUser(UUID userId) | ||
137 | { | ||
138 | throw new NotImplementedException(); | ||
139 | } | ||
140 | |||
141 | public bool UpdateUserProfile(UserProfileData data) | ||
142 | { | ||
143 | throw new NotImplementedException(); | ||
144 | } | ||
145 | |||
146 | public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms) | ||
147 | { | ||
148 | throw new NotImplementedException(); | ||
149 | } | ||
150 | |||
151 | public void RemoveUserFriend(UUID friendlistowner, UUID friend) | ||
152 | { | ||
153 | throw new NotImplementedException(); | ||
154 | } | ||
155 | |||
156 | public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms) | ||
157 | { | ||
158 | throw new NotImplementedException(); | ||
159 | } | ||
160 | |||
161 | public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat) | ||
162 | { | ||
163 | throw new NotImplementedException(); | ||
164 | } | ||
165 | |||
166 | public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz) | ||
167 | { | ||
168 | throw new NotImplementedException(); | ||
169 | } | ||
170 | |||
171 | public List<FriendListItem> GetUserFriendList(UUID friendlistowner) | ||
172 | { | ||
173 | throw new NotImplementedException(); | ||
174 | } | ||
175 | } | ||
176 | |||
88 | [Test] | 177 | [Test] |
89 | public void ProcessAssetDataTest() | 178 | public void TestProcessAssetData() |
90 | { | 179 | { |
91 | string url = "http://host/dir/"; | 180 | string url = "http://host/dir/"; |
92 | string data = " creator_url " + url + " "; | 181 | string creatorData = " creator_url " + url + " "; |
182 | string ownerData = " owner_url " + url + " "; | ||
93 | 183 | ||
94 | AssetCache assetCache = new AssetCache(); | 184 | AssetCache assetCache = new AssetCache(); |
185 | FakeUserService fakeUserService = new FakeUserService(); | ||
95 | 186 | ||
96 | Assert.AreEqual(" creator_id "+Util.GetHashGuid( url, AssetCache.AssetInfo.Secret )+" ", assetCache.ProcessAssetDataString( data )); | 187 | Assert.AreEqual(" creator_id " + Util.GetHashGuid(url, AssetCache.AssetInfo.Secret) + " ", assetCache.ProcessAssetDataString(creatorData, fakeUserService)); |
188 | Assert.AreEqual(" owner_id " + Util.GetHashGuid(url, AssetCache.AssetInfo.Secret) + " ", assetCache.ProcessAssetDataString(ownerData, fakeUserService)); | ||
97 | } | 189 | } |
98 | } | 190 | } |
99 | } | 191 | } |
diff --git a/OpenSim/Framework/Tests/AssetBaseTest.cs b/OpenSim/Framework/Tests/AssetBaseTest.cs new file mode 100644 index 0000000..800b41b --- /dev/null +++ b/OpenSim/Framework/Tests/AssetBaseTest.cs | |||
@@ -0,0 +1,49 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using NUnit.Framework; | ||
5 | using OpenMetaverse; | ||
6 | |||
7 | namespace OpenSim.Framework.Tests | ||
8 | { | ||
9 | [TestFixture] | ||
10 | public class AssetBaseTest | ||
11 | { | ||
12 | [Test] | ||
13 | public void TestContainsReferences() | ||
14 | { | ||
15 | TestContainsReferences(AssetType.Bodypart, true); | ||
16 | TestContainsReferences(AssetType.Clothing, true); | ||
17 | |||
18 | TestContainsReferences(AssetType.Animation, false); | ||
19 | TestContainsReferences(AssetType.CallingCard, false); | ||
20 | TestContainsReferences(AssetType.Folder , false); | ||
21 | TestContainsReferences(AssetType.Gesture , false); | ||
22 | TestContainsReferences(AssetType.ImageJPEG , false); | ||
23 | TestContainsReferences(AssetType.ImageTGA , false); | ||
24 | TestContainsReferences(AssetType.Landmark , false); | ||
25 | TestContainsReferences(AssetType.LostAndFoundFolder, false); | ||
26 | TestContainsReferences(AssetType.LSLBytecode, false); | ||
27 | TestContainsReferences(AssetType.LSLText, false); | ||
28 | TestContainsReferences(AssetType.Notecard, false); | ||
29 | TestContainsReferences(AssetType.Object, false); | ||
30 | TestContainsReferences(AssetType.RootFolder, false); | ||
31 | TestContainsReferences(AssetType.Simstate, false); | ||
32 | TestContainsReferences(AssetType.SnapshotFolder, false); | ||
33 | TestContainsReferences(AssetType.Sound, false); | ||
34 | TestContainsReferences(AssetType.SoundWAV, false); | ||
35 | TestContainsReferences(AssetType.Texture, false); | ||
36 | TestContainsReferences(AssetType.TextureTGA, false); | ||
37 | TestContainsReferences(AssetType.TrashFolder, false); | ||
38 | TestContainsReferences(AssetType.Unknown, false); | ||
39 | } | ||
40 | |||
41 | private void TestContainsReferences(AssetType assetType, bool expected) | ||
42 | { | ||
43 | AssetBase asset = new AssetBase(); | ||
44 | asset.Type = (sbyte)assetType; | ||
45 | bool actual = asset.ContainsReferences; | ||
46 | Assert.AreEqual(expected, actual, "Expected "+assetType+".ContainsReferences to be "+expected+" but was "+actual+"."); | ||
47 | } | ||
48 | } | ||
49 | } | ||