diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut')
3 files changed, 974 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 | |||
28 | using log4net; | ||
29 | using Nini.Config; | ||
30 | using System; | ||
31 | using System.Collections.Generic; | ||
32 | using System.Reflection; | ||
33 | using OpenSim.Framework; | ||
34 | |||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Region.Framework.Interfaces; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenSim.Services.Connectors; | ||
40 | using OpenMetaverse; | ||
41 | |||
42 | namespace 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 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs index 5e06580..9c6e1cd 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs | |||
@@ -51,6 +51,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
51 | // The cache proper | 51 | // The cache proper |
52 | protected Dictionary<UUID, Dictionary<AssetType, InventoryFolderBase>> m_InventoryCache; | 52 | protected Dictionary<UUID, Dictionary<AssetType, InventoryFolderBase>> m_InventoryCache; |
53 | 53 | ||
54 | // A cache of userIDs --> ServiceURLs, for HGBroker only | ||
55 | protected Dictionary<UUID, string> m_InventoryURLs; | ||
56 | |||
54 | public virtual void Init(IConfigSource source, BaseInventoryConnector connector) | 57 | public virtual void Init(IConfigSource source, BaseInventoryConnector connector) |
55 | { | 58 | { |
56 | m_Scenes = new List<Scene>(); | 59 | m_Scenes = new List<Scene>(); |
@@ -89,8 +92,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
89 | 92 | ||
90 | // If not, go get them and place them in the cache | 93 | // If not, go get them and place them in the cache |
91 | Dictionary<AssetType, InventoryFolderBase> folders = CacheSystemFolders(presence.UUID); | 94 | Dictionary<AssetType, InventoryFolderBase> folders = CacheSystemFolders(presence.UUID); |
95 | CacheInventoryServiceURL(presence.Scene, presence.UUID); | ||
96 | |||
92 | m_log.DebugFormat("[INVENTORY CACHE]: OnMakeRootAgent in {0}, fetched system folders for {1} {2}: count {3}", | 97 | m_log.DebugFormat("[INVENTORY CACHE]: OnMakeRootAgent in {0}, fetched system folders for {1} {2}: count {3}", |
93 | presence.Scene.RegionInfo.RegionName, presence.Firstname, presence.Lastname, folders.Count); | 98 | presence.Scene.RegionInfo.RegionName, presence.Firstname, presence.Lastname, folders.Count); |
99 | |||
94 | } | 100 | } |
95 | 101 | ||
96 | void OnClientClosed(UUID clientID, Scene scene) | 102 | void OnClientClosed(UUID clientID, Scene scene) |
@@ -113,6 +119,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
113 | "[INVENTORY CACHE]: OnClientClosed in {0}, user {1} out of sim. Dropping system folders", | 119 | "[INVENTORY CACHE]: OnClientClosed in {0}, user {1} out of sim. Dropping system folders", |
114 | scene.RegionInfo.RegionName, clientID); | 120 | scene.RegionInfo.RegionName, clientID); |
115 | DropCachedSystemFolders(clientID); | 121 | DropCachedSystemFolders(clientID); |
122 | DropInventoryServiceURL(clientID); | ||
116 | } | 123 | } |
117 | } | 124 | } |
118 | 125 | ||
@@ -174,5 +181,49 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
174 | 181 | ||
175 | return null; | 182 | return null; |
176 | } | 183 | } |
184 | |||
185 | /// <summary> | ||
186 | /// Gets the user's inventory URL from its serviceURLs, if the user is foreign, | ||
187 | /// and sticks it in the cache | ||
188 | /// </summary> | ||
189 | /// <param name="userID"></param> | ||
190 | private void CacheInventoryServiceURL(Scene scene, UUID userID) | ||
191 | { | ||
192 | if (scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, userID) == null) | ||
193 | { | ||
194 | // The user does not have a local account; let's cache its service URL | ||
195 | string inventoryURL = string.Empty; | ||
196 | ScenePresence sp = null; | ||
197 | scene.TryGetScenePresence(userID, out sp); | ||
198 | if (sp != null) | ||
199 | { | ||
200 | AgentCircuitData aCircuit = scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); | ||
201 | if (aCircuit.ServiceURLs.ContainsKey("InventoryServerURI")) | ||
202 | { | ||
203 | inventoryURL = aCircuit.ServiceURLs["InventoryServerURI"].ToString(); | ||
204 | if (inventoryURL != null && inventoryURL != string.Empty) | ||
205 | { | ||
206 | inventoryURL = inventoryURL.Trim(new char[] { '/' }); | ||
207 | m_InventoryURLs.Add(userID, inventoryURL); | ||
208 | } | ||
209 | } | ||
210 | } | ||
211 | } | ||
212 | } | ||
213 | |||
214 | private void DropInventoryServiceURL(UUID userID) | ||
215 | { | ||
216 | lock (m_InventoryURLs) | ||
217 | if (m_InventoryURLs.ContainsKey(userID)) | ||
218 | m_InventoryURLs.Remove(userID); | ||
219 | } | ||
220 | |||
221 | public string GetInventoryServiceURL(UUID userID) | ||
222 | { | ||
223 | if (m_InventoryURLs.ContainsKey(userID)) | ||
224 | return m_InventoryURLs[userID]; | ||
225 | |||
226 | return null; | ||
227 | } | ||
177 | } | 228 | } |
178 | } | 229 | } |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteXInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteXInventoryServiceConnector.cs new file mode 100644 index 0000000..ac9e792 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteXInventoryServiceConnector.cs | |||
@@ -0,0 +1,305 @@ | |||
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 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Statistics; | ||
35 | |||
36 | using OpenSim.Services.Connectors; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using OpenMetaverse; | ||
41 | |||
42 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | ||
43 | { | ||
44 | public class RemoteXInventoryServicesConnector : ISharedRegionModule, IInventoryService | ||
45 | { | ||
46 | private static readonly ILog m_log = | ||
47 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private bool m_Enabled = false; | ||
50 | private bool m_Initialized = false; | ||
51 | private Scene m_Scene; | ||
52 | private XInventoryServicesConnector m_RemoteConnector; | ||
53 | |||
54 | public Type ReplaceableInterface | ||
55 | { | ||
56 | get { return null; } | ||
57 | } | ||
58 | |||
59 | public string Name | ||
60 | { | ||
61 | get { return "RemoteXInventoryServicesConnector"; } | ||
62 | } | ||
63 | |||
64 | public RemoteXInventoryServicesConnector() | ||
65 | { | ||
66 | } | ||
67 | |||
68 | public RemoteXInventoryServicesConnector(string url) | ||
69 | { | ||
70 | m_RemoteConnector = new XInventoryServicesConnector(url); | ||
71 | } | ||
72 | |||
73 | public RemoteXInventoryServicesConnector(IConfigSource source) | ||
74 | { | ||
75 | Init(source); | ||
76 | } | ||
77 | |||
78 | protected void Init(IConfigSource source) | ||
79 | { | ||
80 | m_RemoteConnector = new XInventoryServicesConnector(source); | ||
81 | } | ||
82 | |||
83 | |||
84 | #region ISharedRegionModule | ||
85 | |||
86 | public void Initialise(IConfigSource source) | ||
87 | { | ||
88 | IConfig moduleConfig = source.Configs["Modules"]; | ||
89 | if (moduleConfig != null) | ||
90 | { | ||
91 | string name = moduleConfig.GetString("InventoryServices", ""); | ||
92 | if (name == Name) | ||
93 | { | ||
94 | Init(source); | ||
95 | m_Enabled = true; | ||
96 | |||
97 | m_log.Info("[XINVENTORY CONNECTOR]: Remote XInventory enabled"); | ||
98 | } | ||
99 | } | ||
100 | } | ||
101 | |||
102 | public void PostInitialise() | ||
103 | { | ||
104 | } | ||
105 | |||
106 | public void Close() | ||
107 | { | ||
108 | } | ||
109 | |||
110 | public void AddRegion(Scene scene) | ||
111 | { | ||
112 | m_Scene = scene; | ||
113 | //m_log.Debug("[XXXX] Adding scene " + m_Scene.RegionInfo.RegionName); | ||
114 | |||
115 | if (!m_Enabled) | ||
116 | return; | ||
117 | |||
118 | if (!m_Initialized) | ||
119 | { | ||
120 | m_Initialized = true; | ||
121 | } | ||
122 | |||
123 | scene.RegisterModuleInterface<IInventoryService>(this); | ||
124 | } | ||
125 | |||
126 | public void RemoveRegion(Scene scene) | ||
127 | { | ||
128 | if (!m_Enabled) | ||
129 | return; | ||
130 | |||
131 | } | ||
132 | |||
133 | public void RegionLoaded(Scene scene) | ||
134 | { | ||
135 | if (!m_Enabled) | ||
136 | return; | ||
137 | |||
138 | m_log.InfoFormat("[XINVENTORY CONNECTOR]: Enabled remote XInventory for region {0}", scene.RegionInfo.RegionName); | ||
139 | |||
140 | } | ||
141 | |||
142 | #endregion ISharedRegionModule | ||
143 | |||
144 | #region IInventoryService | ||
145 | |||
146 | public bool CreateUserInventory(UUID user) | ||
147 | { | ||
148 | return false; | ||
149 | } | ||
150 | |||
151 | public List<InventoryFolderBase> GetInventorySkeleton(UUID userId) | ||
152 | { | ||
153 | return new List<InventoryFolderBase>(); | ||
154 | } | ||
155 | |||
156 | public InventoryCollection GetUserInventory(UUID userID) | ||
157 | { | ||
158 | return null; | ||
159 | } | ||
160 | |||
161 | public void GetUserInventory(UUID userID, InventoryReceiptCallback callback) | ||
162 | { | ||
163 | } | ||
164 | |||
165 | public InventoryFolderBase GetRootFolder(UUID userID) | ||
166 | { | ||
167 | return m_RemoteConnector.GetRootFolder(userID); | ||
168 | } | ||
169 | |||
170 | public InventoryFolderBase GetFolderForType(UUID userID, AssetType type) | ||
171 | { | ||
172 | return m_RemoteConnector.GetFolderForType(userID, type); | ||
173 | } | ||
174 | |||
175 | public Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(UUID userID) | ||
176 | { | ||
177 | return m_RemoteConnector.GetSystemFolders(userID); | ||
178 | } | ||
179 | |||
180 | public InventoryCollection GetFolderContent(UUID userID, UUID folderID) | ||
181 | { | ||
182 | return m_RemoteConnector.GetFolderContent(userID, folderID); | ||
183 | } | ||
184 | |||
185 | public List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID) | ||
186 | { | ||
187 | return m_RemoteConnector.GetFolderItems(userID, folderID); | ||
188 | } | ||
189 | |||
190 | public bool AddFolder(InventoryFolderBase folder) | ||
191 | { | ||
192 | if (folder == null) | ||
193 | return false; | ||
194 | |||
195 | return m_RemoteConnector.AddFolder(folder); | ||
196 | } | ||
197 | |||
198 | public bool UpdateFolder(InventoryFolderBase folder) | ||
199 | { | ||
200 | if (folder == null) | ||
201 | return false; | ||
202 | |||
203 | return m_RemoteConnector.UpdateFolder(folder); | ||
204 | } | ||
205 | |||
206 | public bool MoveFolder(InventoryFolderBase folder) | ||
207 | { | ||
208 | if (folder == null) | ||
209 | return false; | ||
210 | |||
211 | return m_RemoteConnector.MoveFolder(folder); | ||
212 | } | ||
213 | |||
214 | public bool DeleteFolders(UUID ownerID, List<UUID> folderIDs) | ||
215 | { | ||
216 | if (folderIDs == null) | ||
217 | return false; | ||
218 | if (folderIDs.Count == 0) | ||
219 | return false; | ||
220 | |||
221 | return m_RemoteConnector.DeleteFolders(ownerID, folderIDs); | ||
222 | } | ||
223 | |||
224 | |||
225 | public bool PurgeFolder(InventoryFolderBase folder) | ||
226 | { | ||
227 | if (folder == null) | ||
228 | return false; | ||
229 | |||
230 | return m_RemoteConnector.PurgeFolder(folder); | ||
231 | } | ||
232 | |||
233 | public bool AddItem(InventoryItemBase item) | ||
234 | { | ||
235 | if (item == null) | ||
236 | return false; | ||
237 | |||
238 | return m_RemoteConnector.AddItem(item); | ||
239 | } | ||
240 | |||
241 | public bool UpdateItem(InventoryItemBase item) | ||
242 | { | ||
243 | if (item == null) | ||
244 | return false; | ||
245 | |||
246 | return m_RemoteConnector.UpdateItem(item); | ||
247 | } | ||
248 | |||
249 | public bool MoveItems(UUID ownerID, List<InventoryItemBase> items) | ||
250 | { | ||
251 | if (items == null) | ||
252 | return false; | ||
253 | |||
254 | return m_RemoteConnector.MoveItems(ownerID, items); | ||
255 | } | ||
256 | |||
257 | |||
258 | public bool DeleteItems(UUID ownerID, List<UUID> itemIDs) | ||
259 | { | ||
260 | if (itemIDs == null) | ||
261 | return false; | ||
262 | if (itemIDs.Count == 0) | ||
263 | return true; | ||
264 | |||
265 | return m_RemoteConnector.DeleteItems(ownerID, itemIDs); | ||
266 | } | ||
267 | |||
268 | public InventoryItemBase GetItem(InventoryItemBase item) | ||
269 | { | ||
270 | if (item == null) | ||
271 | return null; | ||
272 | |||
273 | return m_RemoteConnector.GetItem(item); | ||
274 | } | ||
275 | |||
276 | public InventoryFolderBase GetFolder(InventoryFolderBase folder) | ||
277 | { | ||
278 | m_log.DebugFormat("[XINVENTORY CONNECTOR]: GetFolder {0}", folder.ID); | ||
279 | if (folder == null) | ||
280 | return null; | ||
281 | |||
282 | return m_RemoteConnector.GetFolder(folder); | ||
283 | } | ||
284 | |||
285 | public bool HasInventoryForUser(UUID userID) | ||
286 | { | ||
287 | return false; | ||
288 | } | ||
289 | |||
290 | public List<InventoryItemBase> GetActiveGestures(UUID userId) | ||
291 | { | ||
292 | return new List<InventoryItemBase>(); | ||
293 | } | ||
294 | |||
295 | public int GetAssetPermissions(UUID userID, UUID assetID) | ||
296 | { | ||
297 | return m_RemoteConnector.GetAssetPermissions(userID, assetID); | ||
298 | } | ||
299 | |||
300 | |||
301 | #endregion | ||
302 | |||
303 | |||
304 | } | ||
305 | } | ||