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