aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-11-25 15:19:00 +0000
committerJustin Clarke Casey2008-11-25 15:19:00 +0000
commite187972377c19bdd85093677c4c54034e4f9196e (patch)
treecc1bb5f003628b018b823eafc9ee0a67f98df31c /OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs
parent* Adding some virtual hooks and making some privaets protected for great just... (diff)
downloadopensim-SC_OLD-e187972377c19bdd85093677c4c54034e4f9196e.zip
opensim-SC_OLD-e187972377c19bdd85093677c4c54034e4f9196e.tar.gz
opensim-SC_OLD-e187972377c19bdd85093677c4c54034e4f9196e.tar.bz2
opensim-SC_OLD-e187972377c19bdd85093677c4c54034e4f9196e.tar.xz
* Apply http://opensimulator.org/mantis/view.php?id=2640
* This is Diva's hypergrid patch, as perviously discussed on the opensim-dev mailing list * Applied some minor prebuild.xml jiggling to resolve a dependency issue * Thanks Diva!
Diffstat (limited to 'OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs')
-rw-r--r--OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs451
1 files changed, 451 insertions, 0 deletions
diff --git a/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs b/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs
new file mode 100644
index 0000000..9ef040b
--- /dev/null
+++ b/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs
@@ -0,0 +1,451 @@
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
28using System;
29using System.Collections.Generic;
30using System.Net;
31using System.Reflection;
32using OpenMetaverse;
33using log4net;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Communications.Cache;
37using OpenSim.Framework.Servers;
38using OpenSim.Framework.Statistics;
39using OpenSim.Region.Communications.Local;
40
41namespace OpenSim.Region.Communications.Hypergrid
42{
43 public class HGInventoryService : LocalInventoryService, ISecureInventoryService
44 {
45 private static readonly ILog m_log
46 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 private string _inventoryServerUrl;
49 private Uri m_Uri;
50 private UserProfileCacheService m_userProfileCache;
51 private bool m_gridmode = false;
52
53 private Dictionary<UUID, InventoryReceiptCallback> m_RequestingInventory
54 = new Dictionary<UUID, InventoryReceiptCallback>();
55
56 public UserProfileCacheService UserProfileCache
57 {
58 set { m_userProfileCache = value; }
59 }
60
61 public HGInventoryService(string inventoryServerUrl, UserProfileCacheService userProfileCacheService, bool gridmode)
62 {
63 _inventoryServerUrl = HGNetworkServersInfo.ServerURI(inventoryServerUrl);
64 m_Uri = new Uri(_inventoryServerUrl);
65 m_userProfileCache = userProfileCacheService;
66 m_gridmode = gridmode;
67 }
68
69 #region ISecureInventoryService Members
70
71 public void RequestInventoryForUser(UUID userID, UUID session_id, InventoryReceiptCallback callback)
72 {
73 if (IsLocalStandaloneUser(userID))
74 {
75 base.RequestInventoryForUser(userID, callback);
76 return;
77 }
78
79 // grid/hypergrid mode
80 if (!m_RequestingInventory.ContainsKey(userID))
81 {
82 m_RequestingInventory.Add(userID, callback);
83
84 try
85 {
86 string invServer = GetUserInventoryURI(userID);
87 m_log.InfoFormat(
88 "[HGrid INVENTORY SERVICE]: Requesting inventory from {0}/GetInventory/ for user {1} ({2})",
89 /*_inventoryServerUrl*/ invServer, userID, userID.Guid);
90
91
92 RestSessionObjectPosterResponse<Guid, InventoryCollection> requester
93 = new RestSessionObjectPosterResponse<Guid, InventoryCollection>();
94 requester.ResponseCallback = InventoryResponse;
95
96 requester.BeginPostObject(invServer + "/GetInventory/", userID.Guid, session_id.ToString(), userID.ToString());
97
98 //Test(userID.Guid);
99
100 //RestObjectPosterResponse<InventoryCollection> requester
101 // = new RestObjectPosterResponse<InventoryCollection>();
102 //requester.ResponseCallback = InventoryResponse;
103
104 //requester.BeginPostObject<Guid>(/*_inventoryServerUrl*/ invServer + "/GetInventory/", userID.Guid);
105
106 //RestClient cli = new RestClient(invServer + "/GetInventory/" + userID.Guid);
107 //Stream reply = cli.Request();
108 }
109 catch (WebException e)
110 {
111 if (StatsManager.SimExtraStats != null)
112 StatsManager.SimExtraStats.AddInventoryServiceRetrievalFailure();
113
114 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Request inventory operation failed, {0} {1}",
115 e.Source, e.Message);
116 }
117 }
118 else
119 {
120 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: RequestInventoryForUser() - could not find user profile for {0}", userID);
121 }
122
123 }
124
125 /// <summary>
126 /// Add a new folder to the user's inventory
127 /// </summary>
128 /// <param name="folder"></param>
129 /// <returns>true if the folder was successfully added</returns>
130 public bool AddFolder(InventoryFolderBase folder, UUID session_id)
131 {
132 if (IsLocalStandaloneUser(folder.Owner))
133 {
134 return base.AddFolder(folder);
135 }
136
137 try
138 {
139 string invServ = GetUserInventoryURI(folder.Owner);
140
141 return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
142 "POST", invServ + "/NewFolder/", folder, session_id.ToString(), folder.Owner.ToString());
143 }
144 catch (WebException e)
145 {
146 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Add new inventory folder operation failed, {0} {1}",
147 e.Source, e.Message);
148 }
149
150 return false;
151
152 }
153
154 /// <summary>
155 /// Update a folder in the user's inventory
156 /// </summary>
157 /// <param name="folder"></param>
158 /// <returns>true if the folder was successfully updated</returns>
159 public bool UpdateFolder(InventoryFolderBase folder, UUID session_id)
160 {
161 if (IsLocalStandaloneUser(folder.Owner))
162 {
163 return base.UpdateFolder(folder);
164 }
165 try
166 {
167 string invServ = GetUserInventoryURI(folder.Owner);
168
169 return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
170 "POST", invServ + "/UpdateFolder/", folder, session_id.ToString(), folder.Owner.ToString());
171 }
172 catch (WebException e)
173 {
174 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Update inventory folder operation failed, {0} {1}",
175 e.Source, e.Message);
176 }
177
178 return false;
179
180 }
181
182 /// <summary>
183 /// Move an inventory folder to a new location
184 /// </summary>
185 /// <param name="folder">A folder containing the details of the new location</param>
186 /// <returns>true if the folder was successfully moved</returns>
187 public bool MoveFolder(InventoryFolderBase folder, UUID session_id)
188 {
189 if (IsLocalStandaloneUser(folder.Owner))
190 {
191 return base.MoveFolder(folder);
192 }
193
194 try
195 {
196 string invServ = GetUserInventoryURI(folder.Owner);
197
198 return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
199 "POST", invServ + "/MoveFolder/", folder, session_id.ToString(), folder.Owner.ToString());
200 }
201 catch (WebException e)
202 {
203 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Move inventory folder operation failed, {0} {1}",
204 e.Source, e.Message);
205 }
206
207 return false;
208 }
209
210 /// <summary>
211 /// Purge an inventory folder of all its items and subfolders.
212 /// </summary>
213 /// <param name="folder"></param>
214 /// <returns>true if the folder was successfully purged</returns>
215 public bool PurgeFolder(InventoryFolderBase folder, UUID session_id)
216 {
217 if (IsLocalStandaloneUser(folder.Owner))
218 {
219 return base.PurgeFolder(folder);
220 }
221
222 try
223 {
224 string invServ = GetUserInventoryURI(folder.Owner);
225
226 return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
227 "POST", invServ + "/PurgeFolder/", folder, session_id.ToString(), folder.Owner.ToString());
228 }
229 catch (WebException e)
230 {
231 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Move inventory folder operation failed, {0} {1}",
232 e.Source, e.Message);
233 }
234
235 return false;
236 }
237
238 /// <summary>
239 /// Add a new item to the user's inventory
240 /// </summary>
241 /// <param name="item"></param>
242 /// <returns>true if the item was successfully added</returns>
243 public bool AddItem(InventoryItemBase item, UUID session_id)
244 {
245 if (IsLocalStandaloneUser(item.Owner))
246 {
247 return base.AddItem(item);
248 }
249
250 try
251 {
252 string invServ = GetUserInventoryURI(item.Owner);
253
254 return SynchronousRestSessionObjectPoster<InventoryItemBase, bool>.BeginPostObject(
255 "POST", invServ + "/NewItem/", item, session_id.ToString(), item.Owner.ToString());
256 }
257 catch (WebException e)
258 {
259 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Add new inventory item operation failed, {0} {1}",
260 e.Source, e.Message);
261 }
262
263 return false;
264 }
265
266 /// <summary>
267 /// Update an item in the user's inventory
268 /// </summary>
269 /// <param name="item"></param>
270 /// <returns>true if the item was successfully updated</returns>
271 public bool UpdateItem(InventoryItemBase item, UUID session_id)
272 {
273 if (IsLocalStandaloneUser(item.Owner))
274 {
275 return base.UpdateItem(item);
276 }
277
278 try
279 {
280 string invServ = GetUserInventoryURI(item.Owner);
281 return SynchronousRestSessionObjectPoster<InventoryItemBase, bool>.BeginPostObject(
282 "POST", invServ + "/NewItem/", item, session_id.ToString(), item.Owner.ToString());
283 }
284 catch (WebException e)
285 {
286 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Update new inventory item operation failed, {0} {1}",
287 e.Source, e.Message);
288 }
289
290 return false;
291 }
292
293 /// <summary>
294 /// Delete an item from the user's inventory
295 /// </summary>
296 /// <param name="item"></param>
297 /// <returns>true if the item was successfully deleted</returns>
298 public bool DeleteItem(InventoryItemBase item, UUID session_id)
299 {
300 if (IsLocalStandaloneUser(item.Owner))
301 {
302 return base.DeleteItem(item);
303 }
304
305 try
306 {
307 string invServ = GetUserInventoryURI(item.Owner);
308
309 return SynchronousRestSessionObjectPoster<InventoryItemBase, bool>.BeginPostObject(
310 "POST", invServ + "/DeleteItem/", item, session_id.ToString(), item.Owner.ToString());
311 }
312 catch (WebException e)
313 {
314 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Delete inventory item operation failed, {0} {1}",
315 e.Source, e.Message);
316 }
317
318 return false;
319 }
320 #endregion
321
322 #region Methods common to ISecureInventoryService and IInventoryService
323
324 /// <summary>
325 /// Does the given user have an inventory structure?
326 /// </summary>
327 /// <param name="userID"></param>
328 /// <returns></returns>
329 public override bool HasInventoryForUser(UUID userID)
330 {
331 if (IsLocalStandaloneUser(userID))
332 {
333 return base.HasInventoryForUser(userID);
334 }
335 return false;
336 }
337
338 /// <summary>
339 /// Retrieve the root inventory folder for the given user.
340 /// </summary>
341 /// <param name="userID"></param>
342 /// <returns>null if no root folder was found</returns>
343 public override InventoryFolderBase RequestRootFolder(UUID userID)
344 {
345 if (IsLocalStandaloneUser(userID))
346 {
347 return base.RequestRootFolder(userID);
348 }
349
350 return null;
351 }
352
353 #endregion
354
355
356 /// <summary>
357 /// Callback used by the inventory server GetInventory request
358 /// </summary>
359 /// <param name="userID"></param>
360 private void InventoryResponse(InventoryCollection response)
361 {
362 UUID userID = response.UserID;
363 if (m_RequestingInventory.ContainsKey(userID))
364 {
365 m_log.InfoFormat("[HGrid INVENTORY SERVICE]: " +
366 "Received inventory response for user {0} containing {1} folders and {2} items",
367 userID, response.Folders.Count, response.Items.Count);
368
369 InventoryFolderImpl rootFolder = null;
370 InventoryReceiptCallback callback = m_RequestingInventory[userID];
371
372 ICollection<InventoryFolderImpl> folders = new List<InventoryFolderImpl>();
373 ICollection<InventoryItemBase> items = new List<InventoryItemBase>();
374
375 foreach (InventoryFolderBase folder in response.Folders)
376 {
377 if (folder.ParentID == UUID.Zero)
378 {
379 rootFolder = new InventoryFolderImpl(folder);
380 folders.Add(rootFolder);
381
382 break;
383 }
384 }
385
386 if (rootFolder != null)
387 {
388 foreach (InventoryFolderBase folder in response.Folders)
389 {
390 if (folder.ID != rootFolder.ID)
391 {
392 folders.Add(new InventoryFolderImpl(folder));
393 }
394 }
395
396 foreach (InventoryItemBase item in response.Items)
397 {
398 items.Add(item);
399 }
400 }
401 else
402 {
403 m_log.ErrorFormat("[HGrid INVENTORY SERVICE]: Did not get back an inventory containing a root folder for user {0}", userID);
404 }
405
406 callback(folders, items);
407
408 m_RequestingInventory.Remove(userID);
409 }
410 else
411 {
412 m_log.WarnFormat(
413 "[HGrid INVENTORY SERVICE]: " +
414 "Received inventory response for {0} for which we do not have a record of requesting!",
415 userID);
416 }
417 }
418
419
420 private bool IsLocalStandaloneUser(UUID userID)
421 {
422 CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(userID);
423 if (uinfo == null)
424 return true;
425
426 string userInventoryServerURI = HGNetworkServersInfo.ServerURI(uinfo.UserProfile.UserInventoryURI);
427
428 if ((!m_gridmode) && ((userInventoryServerURI == _inventoryServerUrl)) || (userInventoryServerURI == ""))
429 {
430 return true;
431 }
432 return false;
433 }
434
435 private string GetUserInventoryURI(UUID userID)
436 {
437 string invURI = _inventoryServerUrl;
438 CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(userID);
439 if ((uinfo == null) || (uinfo.UserProfile == null))
440 return invURI;
441
442 string userInventoryServerURI = HGNetworkServersInfo.ServerURI(uinfo.UserProfile.UserInventoryURI);
443
444 if ((userInventoryServerURI != null) &&
445 (userInventoryServerURI != ""))
446 invURI = userInventoryServerURI;
447 return invURI;
448 }
449
450 }
451}