diff options
author | Justin Clarke Casey | 2009-04-28 17:47:09 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2009-04-28 17:47:09 +0000 |
commit | 52d56288060caca4f92fee9549090390d7053549 (patch) | |
tree | 48836efd21fb682658e12c1bdd785669eeeff84c /OpenSim | |
parent | Correctly handle group owned land in the Datasnapshot module. Will return (diff) | |
download | opensim-SC_OLD-52d56288060caca4f92fee9549090390d7053549.zip opensim-SC_OLD-52d56288060caca4f92fee9549090390d7053549.tar.gz opensim-SC_OLD-52d56288060caca4f92fee9549090390d7053549.tar.bz2 opensim-SC_OLD-52d56288060caca4f92fee9549090390d7053549.tar.xz |
* Add preliminary code for resolving iar profile names
* Not yet active
Diffstat (limited to 'OpenSim')
4 files changed, 152 insertions, 18 deletions
diff --git a/OpenSim/Framework/Communications/OspResolver.cs b/OpenSim/Framework/Communications/OspResolver.cs new file mode 100644 index 0000000..708bb84 --- /dev/null +++ b/OpenSim/Framework/Communications/OspResolver.cs | |||
@@ -0,0 +1,130 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Reflection; | ||
29 | using System.Text; | ||
30 | using log4net; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Framework.Communications.Cache; | ||
34 | |||
35 | namespace OpenSim.Framework.Communications | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Resolves OpenSim Profile Anchors (OSPA). An OSPA is a string used to provide information for | ||
39 | /// identifying user profiles or supplying a simple name if no profile is available. | ||
40 | /// </summary> | ||
41 | public class OspResolver | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | public const string OSPA_PREFIX = "ospi:"; | ||
46 | public const string OSPA_NAME_KEY = "n"; | ||
47 | public const string OSPA_NAME_VALUE_SEPARATOR = " "; | ||
48 | public const string OSPA_TUPLE_SEPARATOR = "|"; | ||
49 | public static readonly char[] OSPA_TUPLE_SEPARATOR_ARRAY = OSPA_TUPLE_SEPARATOR.ToCharArray(); | ||
50 | public const string OSPA_KEY_VALUE_PAIR_SEPARATOR = "="; | ||
51 | |||
52 | /// <summary> | ||
53 | /// Resolve an osp string into the most suitable internal OpenSim identifier. | ||
54 | /// </summary> | ||
55 | /// | ||
56 | /// In some cases this will be a UUID if a suitable profile exists on the system. In other cases, this may | ||
57 | /// just return the same identifier after creating a temporary profile. | ||
58 | /// | ||
59 | /// <param name="ospa"></param> | ||
60 | /// <param name="commsManager"></param> | ||
61 | /// <returns> | ||
62 | /// A suitable internal OpenSim identifier. If the input string wasn't ospi data, then we simply | ||
63 | /// return that same string. If the input string was ospi data but no valid profile information has been found, | ||
64 | /// then returns null. | ||
65 | /// </returns> | ||
66 | public static string Resolve(string ospa, CommunicationsManager commsManager) | ||
67 | { | ||
68 | if (!ospa.StartsWith(OSPA_PREFIX)) | ||
69 | return ospa; | ||
70 | |||
71 | string ospaMeat = ospa.Substring(OSPA_PREFIX.Length); | ||
72 | string[] ospaTuples = ospaMeat.Split(OSPA_TUPLE_SEPARATOR_ARRAY); | ||
73 | |||
74 | foreach (string tuple in ospaTuples) | ||
75 | { | ||
76 | int tupleSeparatorIndex = tuple.IndexOf(OSPA_TUPLE_SEPARATOR); | ||
77 | |||
78 | if (tupleSeparatorIndex < 0) | ||
79 | { | ||
80 | m_log.WarnFormat("[OSPA RESOLVER]: Ignoring non-tuple component {0} in OSPA {1}", tuple, ospa); | ||
81 | continue; | ||
82 | } | ||
83 | |||
84 | string key = tuple.Remove(tupleSeparatorIndex).Trim(); | ||
85 | string value = tuple.Substring(tupleSeparatorIndex + 1).Trim(); | ||
86 | |||
87 | if (OSPA_NAME_KEY == key) | ||
88 | return ResolveOspaName(value, commsManager); | ||
89 | } | ||
90 | |||
91 | return null; | ||
92 | } | ||
93 | |||
94 | /// <summary> | ||
95 | /// Resolve an OSPI name by querying existing persistent user profiles. If there is no persistent user profile | ||
96 | /// then a temporary user profile is inserted in the cache. | ||
97 | /// </summary> | ||
98 | /// <param name="name"></param> | ||
99 | /// <param name="commsManager"></param> | ||
100 | /// <returns> | ||
101 | /// An OpenSim internal identifier for the name given. Returns null if the name was not valid | ||
102 | /// </returns> | ||
103 | protected static string ResolveOspaName(string name, CommunicationsManager commsManager) | ||
104 | { | ||
105 | int nameSeparatorIndex = name.IndexOf(OSPA_NAME_VALUE_SEPARATOR); | ||
106 | |||
107 | if (nameSeparatorIndex < 0) | ||
108 | { | ||
109 | m_log.WarnFormat("[OSPA RESOLVER]: Ignoring unseparated name {0}", name); | ||
110 | return null; | ||
111 | } | ||
112 | |||
113 | string firstName = name.Remove(nameSeparatorIndex).TrimEnd(); | ||
114 | string lastName = name.Substring(nameSeparatorIndex + 1).TrimStart(); | ||
115 | |||
116 | CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(firstName, lastName); | ||
117 | if (userInfo != null) | ||
118 | return userInfo.UserProfile.ID.ToString(); | ||
119 | |||
120 | UserProfileData tempUserProfile = new UserProfileData(); | ||
121 | tempUserProfile.FirstName = firstName; | ||
122 | tempUserProfile.SurName = lastName; | ||
123 | tempUserProfile.ID = new UUID(Utils.MD5(Encoding.Unicode.GetBytes(tempUserProfile.Name)), 0); | ||
124 | |||
125 | commsManager.UserService.AddTemporaryUserProfile(tempUserProfile); | ||
126 | |||
127 | return tempUserProfile.ID.ToString(); | ||
128 | } | ||
129 | } | ||
130 | } | ||
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index f1993b2..cad259d 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -373,7 +373,6 @@ namespace OpenSim.Framework | |||
373 | return SHA1.ComputeHash(Encoding.Default.GetBytes(src)); | 373 | return SHA1.ComputeHash(Encoding.Default.GetBytes(src)); |
374 | } | 374 | } |
375 | 375 | ||
376 | |||
377 | public static int fast_distance2d(int x, int y) | 376 | public static int fast_distance2d(int x, int y) |
378 | { | 377 | { |
379 | x = Math.Abs(x); | 378 | x = Math.Abs(x); |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs index 2ecb7d4..75e39d1 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs | |||
@@ -57,7 +57,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
57 | /// </value> | 57 | /// </value> |
58 | private Stream m_loadStream; | 58 | private Stream m_loadStream; |
59 | 59 | ||
60 | CommunicationsManager commsManager; | 60 | protected CommunicationsManager m_commsManager; |
61 | 61 | ||
62 | public InventoryArchiveReadRequest( | 62 | public InventoryArchiveReadRequest( |
63 | CachedUserInfo userInfo, string invPath, string loadPath, CommunicationsManager commsManager) | 63 | CachedUserInfo userInfo, string invPath, string loadPath, CommunicationsManager commsManager) |
@@ -75,7 +75,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
75 | m_userInfo = userInfo; | 75 | m_userInfo = userInfo; |
76 | m_invPath = invPath; | 76 | m_invPath = invPath; |
77 | m_loadStream = loadStream; | 77 | m_loadStream = loadStream; |
78 | this.commsManager = commsManager; | 78 | m_commsManager = commsManager; |
79 | } | 79 | } |
80 | 80 | ||
81 | /// <summary> | 81 | /// <summary> |
@@ -101,7 +101,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
101 | // | 101 | // |
102 | // FIXME: FetchInventory should probably be assumed to by async anyway, since even standalones might | 102 | // FIXME: FetchInventory should probably be assumed to by async anyway, since even standalones might |
103 | // use a remote inventory service, though this is vanishingly rare at the moment. | 103 | // use a remote inventory service, though this is vanishingly rare at the moment. |
104 | if (null == commsManager.UserAdminService) | 104 | if (null == m_commsManager.UserAdminService) |
105 | { | 105 | { |
106 | m_log.ErrorFormat( | 106 | m_log.ErrorFormat( |
107 | "[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1}", | 107 | "[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1}", |
@@ -156,7 +156,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
156 | // Don't use the item ID that's in the file | 156 | // Don't use the item ID that's in the file |
157 | item.ID = UUID.Random(); | 157 | item.ID = UUID.Random(); |
158 | 158 | ||
159 | item.CreatorId = m_userInfo.UserProfile.ID.ToString(); | 159 | string ospResolvedId = OspResolver.Resolve(item.CreatorId, m_commsManager); |
160 | if (null != ospResolvedId) | ||
161 | item.CreatorId = ospResolvedId; | ||
162 | |||
160 | item.Owner = m_userInfo.UserProfile.ID; | 163 | item.Owner = m_userInfo.UserProfile.ID; |
161 | 164 | ||
162 | // Reset folder ID to the one in which we want to load it | 165 | // Reset folder ID to the one in which we want to load it |
@@ -352,7 +355,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
352 | asset.Type = assetType; | 355 | asset.Type = assetType; |
353 | asset.Data = data; | 356 | asset.Data = data; |
354 | 357 | ||
355 | commsManager.AssetCache.AddAsset(asset); | 358 | m_commsManager.AssetCache.AddAsset(asset); |
356 | 359 | ||
357 | return true; | 360 | return true; |
358 | } | 361 | } |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index 302d214..5ae1cbd 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs | |||
@@ -204,9 +204,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
204 | 204 | ||
205 | string userFirstName = "Mr"; | 205 | string userFirstName = "Mr"; |
206 | string userLastName = "Tiddles"; | 206 | string userLastName = "Tiddles"; |
207 | string folderName = "a"; | 207 | UUID userUuid = UUID.Parse("00000000-0000-0000-0000-000000000555"); |
208 | string archiveFolderName | ||
209 | = string.Format("{0}{1}{2}", folderName, ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, UUID.Random()); | ||
210 | string itemName = "b.lsl"; | 208 | string itemName = "b.lsl"; |
211 | string archiveItemName | 209 | string archiveItemName |
212 | = string.Format("{0}{1}{2}", itemName, "_", UUID.Random()); | 210 | = string.Format("{0}{1}{2}", itemName, "_", UUID.Random()); |
@@ -218,29 +216,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
218 | item1.Name = itemName; | 216 | item1.Name = itemName; |
219 | item1.AssetID = UUID.Random(); | 217 | item1.AssetID = UUID.Random(); |
220 | item1.GroupID = UUID.Random(); | 218 | item1.GroupID = UUID.Random(); |
219 | item1.CreatorId = userUuid.ToString(); | ||
220 | //item1.CreatorId = "00000000-0000-0000-0000-000000000444"; | ||
221 | item1.Owner = UUID.Parse(item1.CreatorId); | ||
221 | 222 | ||
222 | string item1FileName | 223 | string item1FileName |
223 | = string.Format("{0}{1}/{2}", ArchiveConstants.INVENTORY_PATH, archiveFolderName, archiveItemName); | 224 | = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); |
224 | tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1)); | 225 | tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1)); |
225 | tar.Close(); | 226 | tar.Close(); |
226 | 227 | ||
227 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | 228 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); |
228 | |||
229 | SerialiserModule serialiserModule = new SerialiserModule(); | 229 | SerialiserModule serialiserModule = new SerialiserModule(); |
230 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); | 230 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(); |
231 | 231 | ||
232 | // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene | 232 | // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene |
233 | Scene scene = SceneSetupHelpers.SetupScene(); | 233 | Scene scene = SceneSetupHelpers.SetupScene(); |
234 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | 234 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); |
235 | scene.CommsManager.UserAdminService.AddUser(userFirstName, userLastName, "meowfood", String.Empty, 1000, 1000); | 235 | scene.CommsManager.UserAdminService.AddUser( |
236 | userFirstName, userLastName, "meowfood", String.Empty, 1000, 1000, userUuid); | ||
236 | archiverModule.DearchiveInventory(userFirstName, userLastName, "/", archiveReadStream); | 237 | archiverModule.DearchiveInventory(userFirstName, userLastName, "/", archiveReadStream); |
237 | 238 | ||
238 | CachedUserInfo userInfo = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); | 239 | CachedUserInfo userInfo |
239 | InventoryFolderImpl foundFolder = userInfo.RootFolder.FindFolderByPath(folderName); | 240 | = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); |
240 | Assert.That(foundFolder, Is.Not.Null, string.Format("Folder {0} not found on load", folderName)); | 241 | InventoryItemBase foundItem = userInfo.RootFolder.FindItemByPath(itemName); |
241 | 242 | ||
242 | InventoryItemBase foundItem = foundFolder.FindItemByPath(itemName); | 243 | // Currently, creator and ownership both revert to the loader |
243 | Assert.That(foundItem, Is.Not.Null, string.Format("Item {0} not found on load", itemName)); | 244 | Assert.That(foundItem.CreatorId, Is.EqualTo(userUuid.ToString())); |
245 | Assert.That(foundItem.Owner, Is.EqualTo(userUuid)); | ||
244 | 246 | ||
245 | Console.WriteLine("Finished TestLoadIarV0p1()"); | 247 | Console.WriteLine("Finished TestLoadIarV0p1()"); |
246 | } | 248 | } |