aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs556
1 files changed, 556 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
new file mode 100644
index 0000000..e09db15
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
@@ -0,0 +1,556 @@
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 OpenSimulator 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 log4net;
29using Nini.Config;
30using System;
31using System.Collections.Generic;
32using System.Reflection;
33using OpenSim.Framework;
34
35using OpenSim.Server.Base;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Services.Interfaces;
39using OpenSim.Services.Connectors;
40using OpenMetaverse;
41
42namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
43{
44 public class HGInventoryBroker : ISharedRegionModule, IInventoryService
45 {
46 private static readonly ILog m_log =
47 LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType);
49
50 private static bool m_Enabled = false;
51
52 private static IInventoryService m_LocalGridInventoryService;
53 private Dictionary<string, IInventoryService> m_connectors = new Dictionary<string, IInventoryService>();
54
55 // A cache of userIDs --> ServiceURLs, for HGBroker only
56 protected Dictionary<UUID, string> m_InventoryURLs = new Dictionary<UUID,string>();
57
58 private List<Scene> m_Scenes = new List<Scene>();
59
60 public Type ReplaceableInterface
61 {
62 get { return null; }
63 }
64
65 public string Name
66 {
67 get { return "HGInventoryBroker"; }
68 }
69
70 public void Initialise(IConfigSource source)
71 {
72 IConfig moduleConfig = source.Configs["Modules"];
73 if (moduleConfig != null)
74 {
75 string name = moduleConfig.GetString("InventoryServices", "");
76 if (name == Name)
77 {
78 IConfig inventoryConfig = source.Configs["InventoryService"];
79 if (inventoryConfig == null)
80 {
81 m_log.Error("[HG INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini");
82 return;
83 }
84
85 string localDll = inventoryConfig.GetString("LocalGridInventoryService",
86 String.Empty);
87 //string HGDll = inventoryConfig.GetString("HypergridInventoryService",
88 // String.Empty);
89
90 if (localDll == String.Empty)
91 {
92 m_log.Error("[HG INVENTORY CONNECTOR]: No LocalGridInventoryService named in section InventoryService");
93 //return;
94 throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
95 }
96
97 Object[] args = new Object[] { source };
98 m_LocalGridInventoryService =
99 ServerUtils.LoadPlugin<IInventoryService>(localDll,
100 args);
101
102 if (m_LocalGridInventoryService == null)
103 {
104 m_log.Error("[HG INVENTORY CONNECTOR]: Can't load local inventory service");
105 return;
106 }
107
108 m_Enabled = true;
109 m_log.InfoFormat("[HG INVENTORY CONNECTOR]: HG inventory broker enabled with inner connector of type {0}", m_LocalGridInventoryService.GetType());
110 }
111 }
112 }
113
114 public void PostInitialise()
115 {
116 }
117
118 public void Close()
119 {
120 }
121
122 public void AddRegion(Scene scene)
123 {
124 if (!m_Enabled)
125 return;
126
127 m_Scenes.Add(scene);
128
129 scene.RegisterModuleInterface<IInventoryService>(this);
130
131 scene.EventManager.OnClientClosed += OnClientClosed;
132
133 }
134
135 public void RemoveRegion(Scene scene)
136 {
137 if (!m_Enabled)
138 return;
139
140 m_Scenes.Remove(scene);
141 }
142
143 public void RegionLoaded(Scene scene)
144 {
145 if (!m_Enabled)
146 return;
147
148 m_log.InfoFormat("[HG INVENTORY CONNECTOR]: Enabled HG inventory for region {0}", scene.RegionInfo.RegionName);
149
150 }
151
152 #region URL Cache
153
154 void OnClientClosed(UUID clientID, Scene scene)
155 {
156 if (m_InventoryURLs.ContainsKey(clientID)) // if it's in cache
157 {
158 ScenePresence sp = null;
159 foreach (Scene s in m_Scenes)
160 {
161 s.TryGetScenePresence(clientID, out sp);
162 if ((sp != null) && !sp.IsChildAgent && (s != scene))
163 {
164 m_log.DebugFormat("[INVENTORY CACHE]: OnClientClosed in {0}, but user {1} still in sim. Keeping inventoryURL in cache",
165 scene.RegionInfo.RegionName, clientID);
166 return;
167 }
168 }
169 DropInventoryServiceURL(clientID);
170 }
171 }
172
173 /// <summary>
174 /// Gets the user's inventory URL from its serviceURLs, if the user is foreign,
175 /// and sticks it in the cache
176 /// </summary>
177 /// <param name="userID"></param>
178 private void CacheInventoryServiceURL(UUID userID)
179 {
180 if (m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, userID) == null)
181 {
182 // The user does not have a local account; let's cache its service URL
183 string inventoryURL = string.Empty;
184 ScenePresence sp = null;
185 foreach (Scene scene in m_Scenes)
186 {
187 scene.TryGetScenePresence(userID, out sp);
188 if (sp != null)
189 {
190 AgentCircuitData aCircuit = scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
191 if (aCircuit.ServiceURLs.ContainsKey("InventoryServerURI"))
192 {
193 inventoryURL = aCircuit.ServiceURLs["InventoryServerURI"].ToString();
194 if (inventoryURL != null && inventoryURL != string.Empty)
195 {
196 inventoryURL = inventoryURL.Trim(new char[] { '/' });
197 m_InventoryURLs.Add(userID, inventoryURL);
198 m_log.DebugFormat("[HG INVENTORY CONNECTOR]: Added {0} to the cache of inventory URLs", inventoryURL);
199 return;
200 }
201 }
202 }
203 }
204 }
205
206 // else put a null; it means that the methods should forward to local grid's inventory
207 m_InventoryURLs.Add(userID, null);
208 }
209
210 private void DropInventoryServiceURL(UUID userID)
211 {
212 lock (m_InventoryURLs)
213 if (m_InventoryURLs.ContainsKey(userID))
214 {
215 string url = m_InventoryURLs[userID];
216 m_InventoryURLs.Remove(userID);
217 m_log.DebugFormat("[HG INVENTORY CONNECTOR]: Removed {0} from the cache of inventory URLs", url);
218 }
219 }
220
221 public string GetInventoryServiceURL(UUID userID)
222 {
223 if (m_InventoryURLs.ContainsKey(userID))
224 return m_InventoryURLs[userID];
225
226 else
227 CacheInventoryServiceURL(userID);
228
229 return m_InventoryURLs[userID];
230 }
231 #endregion
232
233 #region IInventoryService
234
235 public bool CreateUserInventory(UUID userID)
236 {
237 return m_LocalGridInventoryService.CreateUserInventory(userID);
238 }
239
240 public List<InventoryFolderBase> GetInventorySkeleton(UUID userId)
241 {
242 return m_LocalGridInventoryService.GetInventorySkeleton(userId);
243 }
244
245 public InventoryCollection GetUserInventory(UUID userID)
246 {
247 return null;
248 }
249
250 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
251 {
252 }
253
254 public InventoryFolderBase GetRootFolder(UUID userID)
255 {
256 m_log.DebugFormat("[HG INVENTORY CONNECTOR]: GetRootFolder for {0}", userID);
257
258 string invURL = GetInventoryServiceURL(userID);
259
260 if (invURL == null) // not there, forward to local inventory connector to resolve
261 return m_LocalGridInventoryService.GetRootFolder(userID);
262
263 IInventoryService connector = GetConnector(invURL);
264
265 return connector.GetRootFolder(userID);
266 }
267
268 public InventoryFolderBase GetFolderForType(UUID userID, AssetType type)
269 {
270 m_log.DebugFormat("[HG INVENTORY CONNECTOR]: GetFolderForType {0} type {1}", userID, type);
271
272 string invURL = GetInventoryServiceURL(userID);
273
274 if (invURL == null) // not there, forward to local inventory connector to resolve
275 return m_LocalGridInventoryService.GetFolderForType(userID, type);
276
277 IInventoryService connector = GetConnector(invURL);
278
279 return connector.GetFolderForType(userID, type);
280 }
281
282 public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
283 {
284 m_log.Debug("[HG INVENTORY CONNECTOR]: GetFolderContent " + folderID);
285
286 string invURL = GetInventoryServiceURL(userID);
287
288 if (invURL == null) // not there, forward to local inventory connector to resolve
289 return m_LocalGridInventoryService.GetFolderContent(userID, folderID);
290
291 IInventoryService connector = GetConnector(invURL);
292
293 return connector.GetFolderContent(userID, folderID);
294
295 }
296
297 public List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID)
298 {
299 m_log.Debug("[HG INVENTORY CONNECTOR]: GetFolderItems " + folderID);
300
301 string invURL = GetInventoryServiceURL(userID);
302
303 if (invURL == null) // not there, forward to local inventory connector to resolve
304 return m_LocalGridInventoryService.GetFolderItems(userID, folderID);
305
306 IInventoryService connector = GetConnector(invURL);
307
308 return connector.GetFolderItems(userID, folderID);
309
310 }
311
312 public bool AddFolder(InventoryFolderBase folder)
313 {
314 if (folder == null)
315 return false;
316
317 m_log.Debug("[HG INVENTORY CONNECTOR]: AddFolder " + folder.ID);
318
319 string invURL = GetInventoryServiceURL(folder.Owner);
320
321 if (invURL == null) // not there, forward to local inventory connector to resolve
322 return m_LocalGridInventoryService.AddFolder(folder);
323
324 IInventoryService connector = GetConnector(invURL);
325
326 return connector.AddFolder(folder);
327 }
328
329 public bool UpdateFolder(InventoryFolderBase folder)
330 {
331 if (folder == null)
332 return false;
333
334 m_log.Debug("[HG INVENTORY CONNECTOR]: UpdateFolder " + folder.ID);
335
336 string invURL = GetInventoryServiceURL(folder.Owner);
337
338 if (invURL == null) // not there, forward to local inventory connector to resolve
339 return m_LocalGridInventoryService.UpdateFolder(folder);
340
341 IInventoryService connector = GetConnector(invURL);
342
343 return connector.UpdateFolder(folder);
344 }
345
346 public bool DeleteFolders(UUID ownerID, List<UUID> folderIDs)
347 {
348 if (folderIDs == null)
349 return false;
350 if (folderIDs.Count == 0)
351 return false;
352
353 m_log.Debug("[HG INVENTORY CONNECTOR]: DeleteFolders for " + ownerID);
354
355 string invURL = GetInventoryServiceURL(ownerID);
356
357 if (invURL == null) // not there, forward to local inventory connector to resolve
358 return m_LocalGridInventoryService.DeleteFolders(ownerID, folderIDs);
359
360 IInventoryService connector = GetConnector(invURL);
361
362 return connector.DeleteFolders(ownerID, folderIDs);
363 }
364
365 public bool MoveFolder(InventoryFolderBase folder)
366 {
367 if (folder == null)
368 return false;
369
370 m_log.Debug("[HG INVENTORY CONNECTOR]: MoveFolder for " + folder.Owner);
371
372 string invURL = GetInventoryServiceURL(folder.Owner);
373
374 if (invURL == null) // not there, forward to local inventory connector to resolve
375 return m_LocalGridInventoryService.MoveFolder(folder);
376
377 IInventoryService connector = GetConnector(invURL);
378
379 return connector.MoveFolder(folder);
380 }
381
382 public bool PurgeFolder(InventoryFolderBase folder)
383 {
384 if (folder == null)
385 return false;
386
387 m_log.Debug("[HG INVENTORY CONNECTOR]: PurgeFolder for " + folder.Owner);
388
389 string invURL = GetInventoryServiceURL(folder.Owner);
390
391 if (invURL == null) // not there, forward to local inventory connector to resolve
392 return m_LocalGridInventoryService.PurgeFolder(folder);
393
394 IInventoryService connector = GetConnector(invURL);
395
396 return connector.PurgeFolder(folder);
397 }
398
399 public bool AddItem(InventoryItemBase item)
400 {
401 if (item == null)
402 return false;
403
404 m_log.Debug("[HG INVENTORY CONNECTOR]: AddItem " + item.ID);
405
406 string invURL = GetInventoryServiceURL(item.Owner);
407
408 if (invURL == null) // not there, forward to local inventory connector to resolve
409 return m_LocalGridInventoryService.AddItem(item);
410
411 IInventoryService connector = GetConnector(invURL);
412
413 return connector.AddItem(item);
414 }
415
416 public bool UpdateItem(InventoryItemBase item)
417 {
418 if (item == null)
419 return false;
420
421 m_log.Debug("[HG INVENTORY CONNECTOR]: UpdateItem " + item.ID);
422
423 string invURL = GetInventoryServiceURL(item.Owner);
424
425 if (invURL == null) // not there, forward to local inventory connector to resolve
426 return m_LocalGridInventoryService.UpdateItem(item);
427
428 IInventoryService connector = GetConnector(invURL);
429
430 return connector.UpdateItem(item);
431 }
432
433 public bool MoveItems(UUID ownerID, List<InventoryItemBase> items)
434 {
435 if (items == null)
436 return false;
437 if (items.Count == 0)
438 return true;
439
440 m_log.Debug("[HG INVENTORY CONNECTOR]: MoveItems for " + ownerID);
441
442 string invURL = GetInventoryServiceURL(ownerID);
443
444 if (invURL == null) // not there, forward to local inventory connector to resolve
445 return m_LocalGridInventoryService.MoveItems(ownerID, items);
446
447 IInventoryService connector = GetConnector(invURL);
448
449 return connector.MoveItems(ownerID, items);
450 }
451
452 public bool DeleteItems(UUID ownerID, List<UUID> itemIDs)
453 {
454 m_log.DebugFormat("[HG INVENTORY CONNECTOR]: Delete {0} items for user {1}", itemIDs.Count, ownerID);
455
456 if (itemIDs == null)
457 return false;
458 if (itemIDs.Count == 0)
459 return true;
460
461 m_log.Debug("[HG INVENTORY CONNECTOR]: DeleteItems for " + ownerID);
462
463 string invURL = GetInventoryServiceURL(ownerID);
464
465 if (invURL == null) // not there, forward to local inventory connector to resolve
466 return m_LocalGridInventoryService.DeleteItems(ownerID, itemIDs);
467
468 IInventoryService connector = GetConnector(invURL);
469
470 return connector.DeleteItems(ownerID, itemIDs);
471 }
472
473 public InventoryItemBase GetItem(InventoryItemBase item)
474 {
475 if (item == null)
476 return null;
477 m_log.Debug("[HG INVENTORY CONNECTOR]: GetItem " + item.ID);
478
479 string invURL = GetInventoryServiceURL(item.Owner);
480
481 if (invURL == null) // not there, forward to local inventory connector to resolve
482 return m_LocalGridInventoryService.GetItem(item);
483
484 IInventoryService connector = GetConnector(invURL);
485
486 return connector.GetItem(item);
487 }
488
489 public InventoryFolderBase GetFolder(InventoryFolderBase folder)
490 {
491 if (folder == null)
492 return null;
493
494 m_log.Debug("[HG INVENTORY CONNECTOR]: GetFolder " + folder.ID);
495
496 string invURL = GetInventoryServiceURL(folder.Owner);
497
498 if (invURL == null) // not there, forward to local inventory connector to resolve
499 return m_LocalGridInventoryService.GetFolder(folder);
500
501 IInventoryService connector = GetConnector(invURL);
502
503 return connector.GetFolder(folder);
504 }
505
506 public bool HasInventoryForUser(UUID userID)
507 {
508 return false;
509 }
510
511 public List<InventoryItemBase> GetActiveGestures(UUID userId)
512 {
513 return new List<InventoryItemBase>();
514 }
515
516 public int GetAssetPermissions(UUID userID, UUID assetID)
517 {
518 m_log.Debug("[HG INVENTORY CONNECTOR]: GetAssetPermissions " + assetID);
519
520 string invURL = GetInventoryServiceURL(userID);
521
522 if (invURL == null) // not there, forward to local inventory connector to resolve
523 return m_LocalGridInventoryService.GetAssetPermissions(userID, assetID);
524
525 IInventoryService connector = GetConnector(invURL);
526
527 return connector.GetAssetPermissions(userID, assetID);
528 }
529
530 #endregion
531
532 private IInventoryService GetConnector(string url)
533 {
534 IInventoryService connector = null;
535 lock (m_connectors)
536 {
537 if (m_connectors.ContainsKey(url))
538 {
539 connector = m_connectors[url];
540 }
541 else
542 {
543 // We're instantiating this class explicitly, but this won't
544 // work in general, because the remote grid may be running
545 // an inventory server that has a different protocol.
546 // Eventually we will want a piece of protocol asking
547 // the remote server about its kind. Definitely cool thing to do!
548 connector = new RemoteXInventoryServicesConnector(url);
549 m_connectors.Add(url, connector);
550 }
551 }
552 return connector;
553 }
554
555 }
556}