From 6abffedab5646c0c9d76a308cb9d7a722613fe14 Mon Sep 17 00:00:00 2001 From: diva Date: Sun, 14 Jun 2009 19:44:56 +0000 Subject: Renamed Region/CoreModules/ServiceConnectors to Region/CoreModules/ServiceConnectorsOut. No functional changes. --- .../ServiceConnectorsOut/Asset/HGAssetBroker.cs | 343 +++++++++ .../Asset/LocalAssetServiceConnector.cs | 256 +++++++ .../Asset/RemoteAssetServiceConnector.cs | 127 ++++ .../Interregion/LocalInterregionComms.cs | 286 ++++++++ .../Interregion/RESTInterregionComms.cs | 811 +++++++++++++++++++++ .../Inventory/HGInventoryBroker.cs | 401 ++++++++++ .../Inventory/LocalInventoryServiceConnector.cs | 286 ++++++++ .../Inventory/RemoteInventoryServiceConnector.cs | 279 +++++++ .../Neighbour/LocalNeighbourServiceConnector.cs | 135 ++++ .../Neighbour/RemoteNeighourServiceConnector.cs | 148 ++++ .../User/LocalUserServiceConnector.cs | 126 ++++ .../User/RemoteUserServiceConnector.cs | 87 +++ 12 files changed, 3285 insertions(+) create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/RemoteAssetServiceConnector.cs create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/LocalInterregionComms.cs create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/RESTInterregionComms.cs create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/LocalNeighbourServiceConnector.cs create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/RemoteNeighourServiceConnector.cs create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/User/LocalUserServiceConnector.cs create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/User/RemoteUserServiceConnector.cs (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs new file mode 100644 index 0000000..a9e9dc2 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs @@ -0,0 +1,343 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using log4net; +using Nini.Config; +using System; +using System.Collections.Generic; +using System.Reflection; +using OpenSim.Framework; +using OpenSim.Server.Base; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; +using OpenMetaverse; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset +{ + public class HGAssetBroker : + ISharedRegionModule, IAssetService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private IImprovedAssetCache m_Cache = null; + private IAssetService m_GridService; + private IAssetService m_HGService; + + private bool m_Enabled = false; + + public string Name + { + get { return "HGAssetBroker"; } + } + + public void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("AssetServices", ""); + if (name == Name) + { + IConfig assetConfig = source.Configs["AssetService"]; + if (assetConfig == null) + { + m_log.Error("[HG ASSET CONNECTOR]: AssetService missing from OpenSim.ini"); + return; + } + + string localDll = assetConfig.GetString("LocalGridAssetService", + String.Empty); + string HGDll = assetConfig.GetString("HypergridAssetService", + String.Empty); + + if (localDll == String.Empty) + { + m_log.Error("[HG ASSET CONNECTOR]: No LocalGridAssetService named in section AssetService"); + return; + } + + if (HGDll == String.Empty) + { + m_log.Error("[HG ASSET CONNECTOR]: No HypergridAssetService named in section AssetService"); + return; + } + + Object[] args = new Object[] { source }; + m_GridService = + ServerUtils.LoadPlugin(localDll, + args); + + m_HGService = + ServerUtils.LoadPlugin(HGDll, + args); + + if (m_GridService == null) + { + m_log.Error("[HG ASSET CONNECTOR]: Can't load local asset service"); + return; + } + if (m_HGService == null) + { + m_log.Error("[HG ASSET CONNECTOR]: Can't load hypergrid asset service"); + return; + } + + m_Enabled = true; + m_log.Info("[HG ASSET CONNECTOR]: HG asset broker enabled"); + } + } + } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + scene.RegisterModuleInterface(this); + } + + public void RemoveRegion(Scene scene) + { + } + + public void RegionLoaded(Scene scene) + { + if (!m_Enabled) + return; + + if (m_Cache == null) + { + m_Cache = scene.RequestModuleInterface(); + + if (!(m_Cache is ISharedRegionModule)) + m_Cache = null; + } + + m_log.InfoFormat("[HG ASSET CONNECTOR]: Enabled hypergrid asset broker for region {0}", scene.RegionInfo.RegionName); + + if (m_Cache != null) + { + m_log.InfoFormat("[HG ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName); + } + } + + private bool IsHG(string id) + { + Uri assetUri; + + if (Uri.TryCreate(id, UriKind.Absolute, out assetUri) && + assetUri.Scheme == Uri.UriSchemeHttp) + return true; + + return false; + } + + public AssetBase Get(string id) + { + //m_log.DebugFormat("[HG ASSET CONNECTOR]: Get {0}", id); + AssetBase asset = null; + + if (m_Cache != null) + { + asset = m_Cache.Get(id); + + if (asset != null) + return asset; + } + + if (IsHG(id)) + { + asset = m_HGService.Get(id); + if (asset != null) + { + // Now store it locally + // For now, let me just do it for textures and scripts + if (((AssetType)asset.Type == AssetType.Texture) || + ((AssetType)asset.Type == AssetType.LSLBytecode) || + ((AssetType)asset.Type == AssetType.LSLText)) + { + m_GridService.Store(asset); + } + } + } + else + asset = m_GridService.Get(id); + + if (asset != null) + { + if (m_Cache != null) + m_Cache.Cache(asset); + } + + return asset; + } + + public AssetMetadata GetMetadata(string id) + { + AssetBase asset = null; + + if (m_Cache != null) + { + if (m_Cache != null) + m_Cache.Get(id); + + if (asset != null) + return asset.Metadata; + } + + AssetMetadata metadata; + + if (IsHG(id)) + metadata = m_HGService.GetMetadata(id); + else + metadata = m_GridService.GetMetadata(id); + + return metadata; + } + + public byte[] GetData(string id) + { + AssetBase asset = null; + + if (m_Cache != null) + { + if (m_Cache != null) + m_Cache.Get(id); + + if (asset != null) + return asset.Data; + } + + if (IsHG(id)) + asset = m_HGService.Get(id); + else + asset = m_GridService.Get(id); + + if (asset != null) + { + if (m_Cache != null) + m_Cache.Cache(asset); + return asset.Data; + } + + return null; + } + + public bool Get(string id, Object sender, AssetRetrieved handler) + { + AssetBase asset = null; + + if (m_Cache != null) + asset = m_Cache.Get(id); + + if (asset != null) + { + handler.BeginInvoke(id, sender, asset, null, null); + return true; + } + + if (IsHG(id)) + { + return m_HGService.Get(id, sender, delegate (string assetID, Object s, AssetBase a) + { + if (a != null && m_Cache != null) + m_Cache.Cache(a); + handler(assetID, s, a); + }); + } + else + { + return m_GridService.Get(id, sender, delegate (string assetID, Object s, AssetBase a) + { + if (a != null && m_Cache != null) + m_Cache.Cache(a); + handler(assetID, s, a); + }); + } + } + + public string Store(AssetBase asset) + { + bool isHG = IsHG(asset.ID); + + if ((m_Cache != null) && !isHG) + // Don't store it in the cache if the asset is to + // be sent to the other grid, because this is already + // a copy of the local asset. + m_Cache.Cache(asset); + + if (asset.Temporary || asset.Local) + return asset.ID; + + if (IsHG(asset.ID)) + return m_HGService.Store(asset); + else + return m_GridService.Store(asset); + } + + public bool UpdateContent(string id, byte[] data) + { + AssetBase asset = null; + + if (m_Cache != null) + asset = m_Cache.Get(id); + + if (asset != null) + { + asset.Data = data; + m_Cache.Cache(asset); + } + + if (IsHG(id)) + return m_HGService.UpdateContent(id, data); + else + return m_GridService.UpdateContent(id, data); + } + + public bool Delete(string id) + { + if (m_Cache != null) + m_Cache.Expire(id); + + if (IsHG(id)) + return m_HGService.Delete(id); + else + return m_GridService.Delete(id); + } + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs new file mode 100644 index 0000000..13c4b52 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs @@ -0,0 +1,256 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using log4net; +using Nini.Config; +using System; +using System.Collections.Generic; +using System.Reflection; +using OpenSim.Framework; +using OpenSim.Server.Base; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset +{ + public class LocalAssetServicesConnector : + ISharedRegionModule, IAssetService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private IImprovedAssetCache m_Cache = null; + + private IAssetService m_AssetService; + + private bool m_Enabled = false; + + public string Name + { + get { return "LocalAssetServicesConnector"; } + } + + public void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("AssetServices", ""); + if (name == Name) + { + IConfig assetConfig = source.Configs["AssetService"]; + if (assetConfig == null) + { + m_log.Error("[ASSET CONNECTOR]: AssetService missing from OpenSim.ini"); + return; + } + + string serviceDll = assetConfig.GetString("LocalServiceModule", + String.Empty); + + if (serviceDll == String.Empty) + { + m_log.Error("[ASSET CONNECTOR]: No LocalServiceModule named in section AssetService"); + return; + } + + Object[] args = new Object[] { source }; + m_AssetService = + ServerUtils.LoadPlugin(serviceDll, + args); + + if (m_AssetService == null) + { + m_log.Error("[ASSET CONNECTOR]: Can't load asset service"); + return; + } + m_Enabled = true; + m_log.Info("[ASSET CONNECTOR]: Local asset connector enabled"); + } + } + } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + scene.RegisterModuleInterface(this); + } + + public void RemoveRegion(Scene scene) + { + } + + public void RegionLoaded(Scene scene) + { + if (!m_Enabled) + return; + + if (m_Cache == null) + { + m_Cache = scene.RequestModuleInterface(); + + if (!(m_Cache is ISharedRegionModule)) + m_Cache = null; + } + + m_log.InfoFormat("[ASSET CONNECTOR]: Enabled local assets for region {0}", scene.RegionInfo.RegionName); + + if (m_Cache != null) + { + m_log.InfoFormat("[ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName); + } + else + { + // Short-circuit directly to storage layer + // + scene.UnregisterModuleInterface(this); + scene.RegisterModuleInterface(m_AssetService); + } + } + + public AssetBase Get(string id) + { + AssetBase asset = null; + if (m_Cache != null) + asset = m_Cache.Get(id); + + if (asset == null) + { + asset = m_AssetService.Get(id); + if ((m_Cache != null) && (asset != null)) + m_Cache.Cache(asset); + } + return asset; + } + + public AssetMetadata GetMetadata(string id) + { + AssetBase asset = null; + if (m_Cache != null) + asset = m_Cache.Get(id); + + if (asset != null) + return asset.Metadata; + + asset = m_AssetService.Get(id); + if (asset != null) + { + if (m_Cache != null) + m_Cache.Cache(asset); + return asset.Metadata; + } + + return null; + } + + public byte[] GetData(string id) + { + AssetBase asset = m_Cache.Get(id); + + if (asset != null) + return asset.Data; + + asset = m_AssetService.Get(id); + if (asset != null) + { + if (m_Cache != null) + m_Cache.Cache(asset); + return asset.Data; + } + + return null; + } + + public bool Get(string id, Object sender, AssetRetrieved handler) + { + AssetBase asset = null; + + if (m_Cache != null) + m_Cache.Get(id); + + if (asset != null) + { + handler.BeginInvoke(id, sender, asset, null, null); + return true; + } + + return m_AssetService.Get(id, sender, delegate (string assetID, Object s, AssetBase a) + { + if ((a != null) && (m_Cache != null)) + m_Cache.Cache(a); + + handler.BeginInvoke(assetID, s, a, null, null); + }); + } + + public string Store(AssetBase asset) + { + if (m_Cache != null) + m_Cache.Cache(asset); + + if (asset.Temporary || asset.Local) + return asset.ID; + + return m_AssetService.Store(asset); + } + + public bool UpdateContent(string id, byte[] data) + { + AssetBase asset = null; + if (m_Cache != null) + m_Cache.Get(id); + if (asset != null) + { + asset.Data = data; + if (m_Cache != null) + m_Cache.Cache(asset); + } + + return m_AssetService.UpdateContent(id, data); + } + + public bool Delete(string id) + { + if (m_Cache != null) + m_Cache.Expire(id); + + return m_AssetService.Delete(id); + } + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/RemoteAssetServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/RemoteAssetServiceConnector.cs new file mode 100644 index 0000000..e554c68 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/RemoteAssetServiceConnector.cs @@ -0,0 +1,127 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using log4net; +using System; +using System.Collections.Generic; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Services.Connectors; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset +{ + public class RemoteAssetServicesConnector : + AssetServicesConnector, ISharedRegionModule, IAssetService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private bool m_Enabled = false; + private IImprovedAssetCache m_Cache; + + public string Name + { + get { return "RemoteAssetServicesConnector"; } + } + + public override void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("AssetServices", ""); + if (name == Name) + { + IConfig assetConfig = source.Configs["AssetService"]; + if (assetConfig == null) + { + m_log.Error("[ASSET CONNECTOR]: AssetService missing from OpanSim.ini"); + return; + } + + m_Enabled = true; + + base.Initialise(source); + + m_log.Info("[ASSET CONNECTOR]: Remote assets enabled"); + } + } + } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + scene.RegisterModuleInterface(this); + } + + public void RemoveRegion(Scene scene) + { + } + + public void RegionLoaded(Scene scene) + { + if (!m_Enabled) + return; + + if (m_Cache == null) + { + m_Cache = scene.RequestModuleInterface(); + + // Since we are a shared module and scene data is not + // available for every method, the cache must be shared, too + // + if (!(m_Cache is ISharedRegionModule)) + m_Cache = null; + else + SetCache(m_Cache); + + } + + m_log.InfoFormat("[ASSET CONNECTOR]: Enabled remote assets for region {0}", scene.RegionInfo.RegionName); + + if (m_Cache != null) + { + m_log.InfoFormat("[ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName); + } + } + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/LocalInterregionComms.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/LocalInterregionComms.cs new file mode 100644 index 0000000..9c3751d --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/LocalInterregionComms.cs @@ -0,0 +1,286 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +using System; +using System.Collections.Generic; +using System.Reflection; +using log4net; +using Nini.Config; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion +{ + public class LocalInterregionComms : IRegionModule, IInterregionCommsOut, IInterregionCommsIn + { + private bool m_enabled = false; + + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private List m_sceneList = new List(); + + #region Events + public event ChildAgentUpdateReceived OnChildAgentUpdate; + + #endregion /* Events */ + + #region IRegionModule + + public void Initialise(Scene scene, IConfigSource config) + { + if (m_sceneList.Count == 0) + { + IConfig startupConfig = config.Configs["Communications"]; + + if ((startupConfig != null) && (startupConfig.GetString("InterregionComms", "RESTComms") == "LocalComms")) + { + m_log.Debug("[LOCAL COMMS]: Enabling InterregionComms LocalComms module"); + m_enabled = true; + } + } + + if (!m_enabled) + return; + + Init(scene); + } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public string Name + { + get { return "LocalInterregionCommsModule"; } + } + + public bool IsSharedModule + { + get { return true; } + } + /// + /// Can be called from other modules. + /// + /// + public void Init(Scene scene) + { + if (!m_sceneList.Contains(scene)) + { + lock (m_sceneList) + { + m_sceneList.Add(scene); + if (m_enabled) + scene.RegisterModuleInterface(this); + scene.RegisterModuleInterface(this); + } + + } + } + + #endregion /* IRegionModule */ + + #region IInterregionComms + + /** + * Agent-related communications + */ + + public bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit, out string reason) + { + foreach (Scene s in m_sceneList) + { + if (s.RegionInfo.RegionHandle == regionHandle) + { +// m_log.DebugFormat("[LOCAL COMMS]: Found region {0} to send SendCreateChildAgent", regionHandle); + return s.NewUserConnection(aCircuit, out reason); + } + } + +// m_log.DebugFormat("[LOCAL COMMS]: Did not find region {0} for SendCreateChildAgent", regionHandle); + reason = "Did not find region."; + return false; + } + + public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData) + { + foreach (Scene s in m_sceneList) + { + if (s.RegionInfo.RegionHandle == regionHandle) + { + //m_log.DebugFormat( + // "[LOCAL COMMS]: Found region {0} {1} to send ChildAgentUpdate", + // s.RegionInfo.RegionName, regionHandle); + + s.IncomingChildAgentDataUpdate(cAgentData); + return true; + } + } + +// m_log.DebugFormat("[LOCAL COMMS]: Did not find region {0} for ChildAgentUpdate", regionHandle); + return false; + } + + public bool SendChildAgentUpdate(ulong regionHandle, AgentPosition cAgentData) + { + foreach (Scene s in m_sceneList) + { + if (s.RegionInfo.RegionHandle == regionHandle) + { + //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate"); + s.IncomingChildAgentDataUpdate(cAgentData); + return true; + } + } + //m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate"); + return false; + } + + public bool SendRetrieveRootAgent(ulong regionHandle, UUID id, out IAgentData agent) + { + agent = null; + foreach (Scene s in m_sceneList) + { + if (s.RegionInfo.RegionHandle == regionHandle) + { + //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate"); + return s.IncomingRetrieveRootAgent(id, out agent); + } + } + //m_log.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate"); + return false; + } + + public bool SendReleaseAgent(ulong regionHandle, UUID id, string uri) + { + //uint x, y; + //Utils.LongToUInts(regionHandle, out x, out y); + //x = x / Constants.RegionSize; + //y = y / Constants.RegionSize; + //m_log.Debug("\n >>> Local SendReleaseAgent " + x + "-" + y); + foreach (Scene s in m_sceneList) + { + if (s.RegionInfo.RegionHandle == regionHandle) + { + //m_log.Debug("[LOCAL COMMS]: Found region to SendReleaseAgent"); + return s.IncomingReleaseAgent(id); + } + } + //m_log.Debug("[LOCAL COMMS]: region not found in SendReleaseAgent"); + return false; + } + + public bool SendCloseAgent(ulong regionHandle, UUID id) + { + //uint x, y; + //Utils.LongToUInts(regionHandle, out x, out y); + //x = x / Constants.RegionSize; + //y = y / Constants.RegionSize; + //m_log.Debug("\n >>> Local SendCloseAgent " + x + "-" + y); + foreach (Scene s in m_sceneList) + { + if (s.RegionInfo.RegionHandle == regionHandle) + { + //m_log.Debug("[LOCAL COMMS]: Found region to SendCloseAgent"); + return s.IncomingCloseAgent(id); + } + } + //m_log.Debug("[LOCAL COMMS]: region not found in SendCloseAgent"); + return false; + } + + /** + * Object-related communications + */ + + public bool SendCreateObject(ulong regionHandle, SceneObjectGroup sog, bool isLocalCall) + { + foreach (Scene s in m_sceneList) + { + if (s.RegionInfo.RegionHandle == regionHandle) + { + //m_log.Debug("[LOCAL COMMS]: Found region to SendCreateObject"); + if (isLocalCall) + { + // We need to make a local copy of the object + ISceneObject sogClone = sog.CloneForNewScene(); + sogClone.SetState(sog.GetStateSnapshot(), + s.RegionInfo.RegionID); + return s.IncomingCreateObject(sogClone); + } + else + { + // Use the object as it came through the wire + return s.IncomingCreateObject(sog); + } + } + } + return false; + } + + public bool SendCreateObject(ulong regionHandle, UUID userID, UUID itemID) + { + foreach (Scene s in m_sceneList) + { + if (s.RegionInfo.RegionHandle == regionHandle) + { + return s.IncomingCreateObject(userID, itemID); + } + } + return false; + } + + + #endregion /* IInterregionComms */ + + #region Misc + + public UUID GetRegionID(ulong regionhandle) + { + foreach (Scene s in m_sceneList) + { + if (s.RegionInfo.RegionHandle == regionhandle) + return s.RegionInfo.RegionID; + } + // ? weird. should not happen + return m_sceneList[0].RegionInfo.RegionID; + } + + public bool IsLocalRegion(ulong regionhandle) + { + foreach (Scene s in m_sceneList) + if (s.RegionInfo.RegionHandle == regionhandle) + return true; + return false; + } + + #endregion + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/RESTInterregionComms.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/RESTInterregionComms.cs new file mode 100644 index 0000000..05cc824 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/RESTInterregionComms.cs @@ -0,0 +1,811 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.IO; +using System.Net; +using System.Reflection; +using System.Text; +using log4net; +using Nini.Config; +using OpenMetaverse; +using OpenMetaverse.StructuredData; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Framework.Communications.Clients; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.Framework.Scenes.Hypergrid; +using OpenSim.Region.Framework.Scenes.Serialization; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion +{ + public class RESTInterregionComms : IRegionModule, IInterregionCommsOut + { + private bool initialized = false; + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + protected bool m_enabled = false; + protected Scene m_aScene; + // RESTInterregionComms does not care about local regions; it delegates that to the Local module + protected LocalInterregionComms m_localBackend; + + protected CommunicationsManager m_commsManager; + + protected RegionToRegionClient m_regionClient; + + protected bool m_safemode; + protected IPAddress m_thisIP; + + #region IRegionModule + + public virtual void Initialise(Scene scene, IConfigSource config) + { + if (!initialized) + { + initialized = true; + IConfig startupConfig = config.Configs["Communications"]; + + if ((startupConfig == null) + || (startupConfig != null) + && (startupConfig.GetString("InterregionComms", "RESTComms") == "RESTComms")) + { + m_log.Info("[REST COMMS]: Enabling InterregionComms RESTComms module"); + m_enabled = true; + if (config.Configs["Hypergrid"] != null) + m_safemode = config.Configs["Hypergrid"].GetBoolean("safemode", false); + + InitOnce(scene); + } + } + + if (!m_enabled) + return; + + InitEach(scene); + + } + + public virtual void PostInitialise() + { + if (m_enabled) + AddHTTPHandlers(); + } + + public virtual void Close() + { + } + + public virtual string Name + { + get { return "RESTInterregionCommsModule"; } + } + + public virtual bool IsSharedModule + { + get { return true; } + } + + protected virtual void InitEach(Scene scene) + { + m_localBackend.Init(scene); + scene.RegisterModuleInterface(this); + } + + protected virtual void InitOnce(Scene scene) + { + m_localBackend = new LocalInterregionComms(); + m_commsManager = scene.CommsManager; + m_aScene = scene; + m_regionClient = new RegionToRegionClient(m_aScene); + m_thisIP = Util.GetHostFromDNS(scene.RegionInfo.ExternalHostName); + } + + protected virtual void AddHTTPHandlers() + { + m_aScene.CommsManager.HttpServer.AddHTTPHandler("/agent/", AgentHandler); + m_aScene.CommsManager.HttpServer.AddHTTPHandler("/object/", ObjectHandler); + } + + #endregion /* IRegionModule */ + + #region IInterregionComms + + /** + * Agent-related communications + */ + + public bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit, out string reason) + { + // Try local first + if (m_localBackend.SendCreateChildAgent(regionHandle, aCircuit, out reason)) + return true; + + // else do the remote thing + if (!m_localBackend.IsLocalRegion(regionHandle)) + { + RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); + if (regInfo != null) + { + m_regionClient.SendUserInformation(regInfo, aCircuit); + + return m_regionClient.DoCreateChildAgentCall(regInfo, aCircuit, "None", out reason); + } + //else + // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); + } + return false; + } + + public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData) + { + // Try local first + if (m_localBackend.SendChildAgentUpdate(regionHandle, cAgentData)) + return true; + + // else do the remote thing + if (!m_localBackend.IsLocalRegion(regionHandle)) + { + RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); + if (regInfo != null) + { + return m_regionClient.DoChildAgentUpdateCall(regInfo, cAgentData); + } + //else + // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); + } + return false; + + } + + public bool SendChildAgentUpdate(ulong regionHandle, AgentPosition cAgentData) + { + // Try local first + if (m_localBackend.SendChildAgentUpdate(regionHandle, cAgentData)) + return true; + + // else do the remote thing + if (!m_localBackend.IsLocalRegion(regionHandle)) + { + RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); + if (regInfo != null) + { + return m_regionClient.DoChildAgentUpdateCall(regInfo, cAgentData); + } + //else + // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); + } + return false; + + } + + public bool SendRetrieveRootAgent(ulong regionHandle, UUID id, out IAgentData agent) + { + // Try local first + if (m_localBackend.SendRetrieveRootAgent(regionHandle, id, out agent)) + return true; + + // else do the remote thing + if (!m_localBackend.IsLocalRegion(regionHandle)) + { + RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); + if (regInfo != null) + { + return m_regionClient.DoRetrieveRootAgentCall(regInfo, id, out agent); + } + //else + // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); + } + return false; + + } + + public bool SendReleaseAgent(ulong regionHandle, UUID id, string uri) + { + // Try local first + if (m_localBackend.SendReleaseAgent(regionHandle, id, uri)) + return true; + + // else do the remote thing + return m_regionClient.DoReleaseAgentCall(regionHandle, id, uri); + } + + + public bool SendCloseAgent(ulong regionHandle, UUID id) + { + // Try local first + if (m_localBackend.SendCloseAgent(regionHandle, id)) + return true; + + // else do the remote thing + if (!m_localBackend.IsLocalRegion(regionHandle)) + { + RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); + if (regInfo != null) + { + return m_regionClient.DoCloseAgentCall(regInfo, id); + } + //else + // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); + } + return false; + } + + /** + * Object-related communications + */ + + public bool SendCreateObject(ulong regionHandle, SceneObjectGroup sog, bool isLocalCall) + { + // Try local first + if (m_localBackend.SendCreateObject(regionHandle, sog, true)) + { + //m_log.Debug("[REST COMMS]: LocalBackEnd SendCreateObject succeeded"); + return true; + } + + // else do the remote thing + if (!m_localBackend.IsLocalRegion(regionHandle)) + { + RegionInfo regInfo = m_commsManager.GridService.RequestNeighbourInfo(regionHandle); + if (regInfo != null) + { + return m_regionClient.DoCreateObjectCall( + regInfo, sog, SceneObjectSerializer.ToXml2Format(sog), m_aScene.m_allowScriptCrossings); + } + //else + // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); + } + return false; + } + + public bool SendCreateObject(ulong regionHandle, UUID userID, UUID itemID) + { + // Not Implemented + return false; + } + + #endregion /* IInterregionComms */ + + #region Incoming calls from remote instances + + /** + * Agent-related incoming calls + */ + + public Hashtable AgentHandler(Hashtable request) + { + //m_log.Debug("[CONNECTION DEBUGGING]: AgentHandler Called"); + + m_log.Debug("---------------------------"); + m_log.Debug(" >> uri=" + request["uri"]); + m_log.Debug(" >> content-type=" + request["content-type"]); + m_log.Debug(" >> http-method=" + request["http-method"]); + m_log.Debug("---------------------------\n"); + + Hashtable responsedata = new Hashtable(); + responsedata["content_type"] = "text/html"; + responsedata["keepalive"] = false; + + + UUID agentID; + string action; + ulong regionHandle; + if (!GetParams((string)request["uri"], out agentID, out regionHandle, out action)) + { + m_log.InfoFormat("[REST COMMS]: Invalid parameters for agent message {0}", request["uri"]); + responsedata["int_response_code"] = 404; + responsedata["str_response_string"] = "false"; + + return responsedata; + } + + // Next, let's parse the verb + string method = (string)request["http-method"]; + if (method.Equals("PUT")) + { + DoAgentPut(request, responsedata); + return responsedata; + } + else if (method.Equals("POST")) + { + DoAgentPost(request, responsedata, agentID); + return responsedata; + } + else if (method.Equals("GET")) + { + DoAgentGet(request, responsedata, agentID, regionHandle); + return responsedata; + } + else if (method.Equals("DELETE")) + { + DoAgentDelete(request, responsedata, agentID, action, regionHandle); + return responsedata; + } + else + { + m_log.InfoFormat("[REST COMMS]: method {0} not supported in agent message", method); + responsedata["int_response_code"] = 404; + responsedata["str_response_string"] = "false"; + + return responsedata; + } + + } + + protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) + { + if (m_safemode) + { + // Authentication + string authority = string.Empty; + string authToken = string.Empty; + if (!GetAuthentication(request, out authority, out authToken)) + { + m_log.InfoFormat("[REST COMMS]: Authentication failed for agent message {0}", request["uri"]); + responsedata["int_response_code"] = 403; + responsedata["str_response_string"] = "Forbidden"; + return ; + } + if (!VerifyKey(id, authority, authToken)) + { + m_log.InfoFormat("[REST COMMS]: Authentication failed for agent message {0}", request["uri"]); + responsedata["int_response_code"] = 403; + responsedata["str_response_string"] = "Forbidden"; + return ; + } + m_log.DebugFormat("[REST COMMS]: Authentication succeeded for {0}", id); + } + + OSDMap args = RegionClient.GetOSDMap((string)request["body"]); + if (args == null) + { + responsedata["int_response_code"] = 400; + responsedata["str_response_string"] = "false"; + return; + } + + // retrieve the regionhandle + ulong regionhandle = 0; + if (args["destination_handle"] != null) + UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); + + AgentCircuitData aCircuit = new AgentCircuitData(); + try + { + aCircuit.UnpackAgentCircuitData(args); + } + catch (Exception ex) + { + m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildCreate message {0}", ex.Message); + return; + } + + OSDMap resp = new OSDMap(2); + string reason = String.Empty; + + // This is the meaning of POST agent + m_regionClient.AdjustUserInformation(aCircuit); + bool result = m_localBackend.SendCreateChildAgent(regionhandle, aCircuit, out reason); + + resp["reason"] = OSD.FromString(reason); + resp["success"] = OSD.FromBoolean(result); + + // TODO: add reason if not String.Empty? + responsedata["int_response_code"] = 200; + responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); + } + + protected virtual void DoAgentPut(Hashtable request, Hashtable responsedata) + { + OSDMap args = RegionClient.GetOSDMap((string)request["body"]); + if (args == null) + { + responsedata["int_response_code"] = 400; + responsedata["str_response_string"] = "false"; + return; + } + + // retrieve the regionhandle + ulong regionhandle = 0; + if (args["destination_handle"] != null) + UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); + + string messageType; + if (args["message_type"] != null) + messageType = args["message_type"].AsString(); + else + { + m_log.Warn("[REST COMMS]: Agent Put Message Type not found. "); + messageType = "AgentData"; + } + + bool result = true; + if ("AgentData".Equals(messageType)) + { + AgentData agent = new AgentData(); + try + { + agent.Unpack(args); + } + catch (Exception ex) + { + m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); + return; + } + + //agent.Dump(); + // This is one of the meanings of PUT agent + result = m_localBackend.SendChildAgentUpdate(regionhandle, agent); + + } + else if ("AgentPosition".Equals(messageType)) + { + AgentPosition agent = new AgentPosition(); + try + { + agent.Unpack(args); + } + catch (Exception ex) + { + m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); + return; + } + //agent.Dump(); + // This is one of the meanings of PUT agent + result = m_localBackend.SendChildAgentUpdate(regionhandle, agent); + + } + + responsedata["int_response_code"] = 200; + responsedata["str_response_string"] = result.ToString(); + } + + protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, ulong regionHandle) + { + IAgentData agent = null; + bool result = m_localBackend.SendRetrieveRootAgent(regionHandle, id, out agent); + OSDMap map = null; + if (result) + { + if (agent != null) // just to make sure + { + map = agent.Pack(); + string strBuffer = ""; + try + { + strBuffer = OSDParser.SerializeJsonString(map); + } + catch (Exception e) + { + m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of CreateObject: {0}", e.Message); + // ignore. buffer will be empty, caller should check. + } + + responsedata["content_type"] = "application/json"; + responsedata["int_response_code"] = 200; + responsedata["str_response_string"] = strBuffer; + } + else + { + responsedata["int_response_code"] = 500; + responsedata["str_response_string"] = "Internal error"; + } + } + else + { + responsedata["int_response_code"] = 404; + responsedata["str_response_string"] = "Not Found"; + } + } + + protected virtual void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, ulong regionHandle) + { + //m_log.Debug(" >>> DoDelete action:" + action + "; regionHandle:" + regionHandle); + + if (action.Equals("release")) + m_localBackend.SendReleaseAgent(regionHandle, id, ""); + else + m_localBackend.SendCloseAgent(regionHandle, id); + + responsedata["int_response_code"] = 200; + responsedata["str_response_string"] = "OpenSim agent " + id.ToString(); + + m_log.Debug("[REST COMMS]: Agent Deleted."); + } + + /** + * Object-related incoming calls + */ + + public Hashtable ObjectHandler(Hashtable request) + { + m_log.Debug("[CONNECTION DEBUGGING]: ObjectHandler Called"); + + m_log.Debug("---------------------------"); + m_log.Debug(" >> uri=" + request["uri"]); + m_log.Debug(" >> content-type=" + request["content-type"]); + m_log.Debug(" >> http-method=" + request["http-method"]); + m_log.Debug("---------------------------\n"); + + Hashtable responsedata = new Hashtable(); + responsedata["content_type"] = "text/html"; + + UUID objectID; + string action; + ulong regionHandle; + if (!GetParams((string)request["uri"], out objectID, out regionHandle, out action)) + { + m_log.InfoFormat("[REST COMMS]: Invalid parameters for object message {0}", request["uri"]); + responsedata["int_response_code"] = 404; + responsedata["str_response_string"] = "false"; + + return responsedata; + } + + // Next, let's parse the verb + string method = (string)request["http-method"]; + if (method.Equals("POST")) + { + DoObjectPost(request, responsedata, regionHandle); + return responsedata; + } + else if (method.Equals("PUT")) + { + DoObjectPut(request, responsedata, regionHandle); + return responsedata; + } + //else if (method.Equals("DELETE")) + //{ + // DoObjectDelete(request, responsedata, agentID, action, regionHandle); + // return responsedata; + //} + else + { + m_log.InfoFormat("[REST COMMS]: method {0} not supported in object message", method); + responsedata["int_response_code"] = 404; + responsedata["str_response_string"] = "false"; + + return responsedata; + } + + } + + protected virtual void DoObjectPost(Hashtable request, Hashtable responsedata, ulong regionhandle) + { + OSDMap args = RegionClient.GetOSDMap((string)request["body"]); + if (args == null) + { + responsedata["int_response_code"] = 400; + responsedata["str_response_string"] = "false"; + return; + } + + string sogXmlStr = "", extraStr = "", stateXmlStr = ""; + if (args["sog"] != null) + sogXmlStr = args["sog"].AsString(); + if (args["extra"] != null) + extraStr = args["extra"].AsString(); + + UUID regionID = m_localBackend.GetRegionID(regionhandle); + SceneObjectGroup sog = null; + try + { + sog = SceneObjectSerializer.FromXml2Format(sogXmlStr); + sog.ExtraFromXmlString(extraStr); + } + catch (Exception ex) + { + m_log.InfoFormat("[REST COMMS]: exception on deserializing scene object {0}", ex.Message); + responsedata["int_response_code"] = 400; + responsedata["str_response_string"] = "false"; + return; + } + + if ((args["state"] != null) && m_aScene.m_allowScriptCrossings) + { + stateXmlStr = args["state"].AsString(); + if (stateXmlStr != "") + { + try + { + sog.SetState(stateXmlStr, regionID); + } + catch (Exception ex) + { + m_log.InfoFormat("[REST COMMS]: exception on setting state for scene object {0}", ex.Message); + + } + } + } + // This is the meaning of POST object + bool result = m_localBackend.SendCreateObject(regionhandle, sog, false); + + responsedata["int_response_code"] = 200; + responsedata["str_response_string"] = result.ToString(); + } + + protected virtual void DoObjectPut(Hashtable request, Hashtable responsedata, ulong regionhandle) + { + OSDMap args = RegionClient.GetOSDMap((string)request["body"]); + if (args == null) + { + responsedata["int_response_code"] = 400; + responsedata["str_response_string"] = "false"; + return; + } + + UUID userID = UUID.Zero, itemID = UUID.Zero; + if (args["userid"] != null) + userID = args["userid"].AsUUID(); + if (args["itemid"] != null) + itemID = args["itemid"].AsUUID(); + + //UUID regionID = m_localBackend.GetRegionID(regionhandle); + + // This is the meaning of PUT object + bool result = m_localBackend.SendCreateObject(regionhandle, userID, itemID); + + responsedata["int_response_code"] = 200; + responsedata["str_response_string"] = result.ToString(); + } + + #endregion + + #region Misc + + + /// + /// Extract the param from an uri. + /// + /// Something like this: /agent/uuid/ or /agent/uuid/handle/release + /// uuid on uuid field + /// optional action + public static bool GetParams(string uri, out UUID uuid, out ulong regionHandle, out string action) + { + uuid = UUID.Zero; + action = ""; + regionHandle = 0; + + uri = uri.Trim(new char[] { '/' }); + string[] parts = uri.Split('/'); + if (parts.Length <= 1) + { + return false; + } + else + { + if (!UUID.TryParse(parts[1], out uuid)) + return false; + + if (parts.Length >= 3) + UInt64.TryParse(parts[2], out regionHandle); + if (parts.Length >= 4) + action = parts[3]; + + return true; + } + } + + public static bool GetAuthentication(Hashtable request, out string authority, out string authKey) + { + authority = string.Empty; + authKey = string.Empty; + + Uri authUri; + Hashtable headers = (Hashtable)request["headers"]; + + // Authorization keys look like this: + // http://orgrid.org:8002/ + if (headers.ContainsKey("authorization") && (string)headers["authorization"] != "None") + { + if (Uri.TryCreate((string)headers["authorization"], UriKind.Absolute, out authUri)) + { + authority = authUri.Authority; + authKey = authUri.PathAndQuery.Trim('/'); + m_log.DebugFormat("[REST COMMS]: Got authority {0} and key {1}", authority, authKey); + return true; + } + else + m_log.Debug("[REST COMMS]: Wrong format for Authorization header: " + (string)headers["authorization"]); + } + else + m_log.Debug("[REST COMMS]: Authorization header not found"); + + return false; + } + + bool VerifyKey(UUID userID, string authority, string key) + { + string[] parts = authority.Split(':'); + IPAddress ipaddr = IPAddress.None; + uint port = 0; + if (parts.Length <= 2) + ipaddr = Util.GetHostFromDNS(parts[0]); + if (parts.Length == 2) + UInt32.TryParse(parts[1], out port); + + // local authority (standalone), local call + if (m_thisIP.Equals(ipaddr) && (m_aScene.RegionInfo.HttpPort == port)) + return ((IAuthentication)m_aScene.CommsManager.UserAdminService).VerifyKey(userID, key); + // remote call + else + return AuthClient.VerifyKey("http://" + authority, userID, key); + } + + + #endregion Misc + + protected class RegionToRegionClient : RegionClient + { + Scene m_aScene = null; + + public RegionToRegionClient(Scene s) + { + m_aScene = s; + } + + public override ulong GetRegionHandle(ulong handle) + { + if (m_aScene.SceneGridService is HGSceneCommunicationService) + return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.FindRegionHandle(handle); + + return handle; + } + + public override bool IsHyperlink(ulong handle) + { + if (m_aScene.SceneGridService is HGSceneCommunicationService) + return ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.IsHyperlinkRegion(handle); + + return false; + } + + public override void SendUserInformation(RegionInfo regInfo, AgentCircuitData aCircuit) + { + try + { + if (m_aScene.SceneGridService is HGSceneCommunicationService) + { + ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.SendUserInformation(regInfo, aCircuit); + } + } + catch // Bad cast + { } + + } + + public override void AdjustUserInformation(AgentCircuitData aCircuit) + { + if (m_aScene.SceneGridService is HGSceneCommunicationService) + ((HGSceneCommunicationService)(m_aScene.SceneGridService)).m_hg.AdjustUserInformation(aCircuit); + } + } + + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs new file mode 100644 index 0000000..9f6c1a2 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs @@ -0,0 +1,401 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using log4net; +using Nini.Config; +using System; +using System.Collections.Generic; +using System.Reflection; +using OpenSim.Framework; +using OpenSim.Framework.Communications.Cache; +using OpenSim.Server.Base; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; +using OpenSim.Services.Connectors; +using OpenMetaverse; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory +{ + public class HGInventoryBroker : ISharedRegionModule, IInventoryService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private bool m_Enabled = false; + private bool m_Initialized = false; + private Scene m_Scene; + private UserProfileCacheService m_UserProfileService; // This should change to IUserProfileService + + private IInventoryService m_GridService; + private ISessionAuthInventoryService m_HGService; + + private string m_LocalGridInventoryURI = string.Empty; + public string Name + { + get { return "HGInventoryBroker"; } + } + + public void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("InventoryServices", ""); + if (name == Name) + { + IConfig inventoryConfig = source.Configs["InventoryService"]; + if (inventoryConfig == null) + { + m_log.Error("[HG INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini"); + return; + } + + string localDll = inventoryConfig.GetString("LocalGridInventoryService", + String.Empty); + string HGDll = inventoryConfig.GetString("HypergridInventoryService", + String.Empty); + + if (localDll == String.Empty) + { + m_log.Error("[HG INVENTORY CONNECTOR]: No LocalGridInventoryService named in section InventoryService"); + //return; + throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's"); + } + + if (HGDll == String.Empty) + { + m_log.Error("[HG INVENTORY CONNECTOR]: No HypergridInventoryService named in section InventoryService"); + //return; + throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's"); + } + + Object[] args = new Object[] { source }; + m_GridService = + ServerUtils.LoadPlugin(localDll, + args); + + m_HGService = + ServerUtils.LoadPlugin(HGDll, + args); + + if (m_GridService == null) + { + m_log.Error("[HG INVENTORY CONNECTOR]: Can't load local inventory service"); + return; + } + if (m_HGService == null) + { + m_log.Error("[HG INVENTORY CONNECTOR]: Can't load hypergrid inventory service"); + return; + } + + m_LocalGridInventoryURI = inventoryConfig.GetString("InventoryServerURI", string.Empty); + + m_Enabled = true; + m_log.Info("[HG INVENTORY CONNECTOR]: HG inventory broker enabled"); + } + } + } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + if (!m_Initialized) + { + m_Scene = scene; + // HACK for now. Ugh! + m_UserProfileService = m_Scene.CommsManager.UserProfileCacheService; + // ugh! + m_UserProfileService.SetInventoryService(this); + scene.CommsManager.UserService.SetInventoryService(this); + + m_Initialized = true; + } + + scene.RegisterModuleInterface(this); + } + + public void RemoveRegion(Scene scene) + { + } + + public void RegionLoaded(Scene scene) + { + if (!m_Enabled) + return; + + m_log.InfoFormat("[INVENTORY CONNECTOR]: Enabled HG inventory for region {0}", scene.RegionInfo.RegionName); + + } + + #region IInventoryService + + public bool CreateUserInventory(UUID userID) + { + return m_GridService.CreateUserInventory(userID); + } + + public List GetInventorySkeleton(UUID userId) + { + return m_GridService.GetInventorySkeleton(userId); + } + + public InventoryCollection GetUserInventory(UUID userID) + { + if (IsLocalGridUser(userID)) + return m_GridService.GetUserInventory(userID); + else + return null; + } + + public void GetUserInventory(UUID userID, InventoryReceiptCallback callback) + { + if (IsLocalGridUser(userID)) + m_GridService.GetUserInventory(userID, callback); + else + { + UUID sessionID = GetSessionID(userID); + string uri = GetUserInventoryURI(userID) + "/" + userID.ToString(); + m_HGService.GetUserInventory(uri, sessionID, callback); + } + } + + public List GetFolderItems(UUID userID, UUID folderID) + { + return new List(); + } + + public bool AddFolder(InventoryFolderBase folder) + { + if (folder == null) + return false; + + if (IsLocalGridUser(folder.Owner)) + return m_GridService.AddFolder(folder); + else + { + UUID sessionID = GetSessionID(folder.Owner); + string uri = GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString(); + return m_HGService.AddFolder(uri, folder, sessionID); + } + } + + public bool UpdateFolder(InventoryFolderBase folder) + { + if (folder == null) + return false; + + if (IsLocalGridUser(folder.Owner)) + return m_GridService.UpdateFolder(folder); + else + { + UUID sessionID = GetSessionID(folder.Owner); + string uri = GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString(); + return m_HGService.UpdateFolder(uri, folder, sessionID); + } + } + + public bool MoveFolder(InventoryFolderBase folder) + { + if (folder == null) + return false; + + if (IsLocalGridUser(folder.Owner)) + return m_GridService.MoveFolder(folder); + else + { + UUID sessionID = GetSessionID(folder.Owner); + string uri = GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString(); + return m_HGService.MoveFolder(uri, folder, sessionID); + } + } + + public bool PurgeFolder(InventoryFolderBase folder) + { + if (folder == null) + return false; + + if (IsLocalGridUser(folder.Owner)) + return m_GridService.PurgeFolder(folder); + else + { + UUID sessionID = GetSessionID(folder.Owner); + string uri = GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString(); + return m_HGService.PurgeFolder(uri, folder, sessionID); + } + } + + public bool AddItem(InventoryItemBase item) + { + if (item == null) + return false; + + if (IsLocalGridUser(item.Owner)) + return m_GridService.AddItem(item); + else + { + UUID sessionID = GetSessionID(item.Owner); + string uri = GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString(); + return m_HGService.AddItem(uri, item, sessionID); + } + } + + public bool UpdateItem(InventoryItemBase item) + { + if (item == null) + return false; + + if (IsLocalGridUser(item.Owner)) + return m_GridService.UpdateItem(item); + else + { + UUID sessionID = GetSessionID(item.Owner); + string uri = GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString(); + return m_HGService.UpdateItem(uri, item, sessionID); + } + } + + public bool DeleteItem(InventoryItemBase item) + { + if (item == null) + return false; + + if (IsLocalGridUser(item.Owner)) + return m_GridService.DeleteItem(item); + else + { + UUID sessionID = GetSessionID(item.Owner); + string uri = GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString(); + return m_HGService.DeleteItem(uri, item, sessionID); + } + } + + public InventoryItemBase QueryItem(InventoryItemBase item) + { + if (item == null) + return null; + + if (IsLocalGridUser(item.Owner)) + return m_GridService.QueryItem(item); + else + { + UUID sessionID = GetSessionID(item.Owner); + string uri = GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString(); + return m_HGService.QueryItem(uri, item, sessionID); + } + } + + public InventoryFolderBase QueryFolder(InventoryFolderBase folder) + { + if (folder == null) + return null; + + if (IsLocalGridUser(folder.Owner)) + return m_GridService.QueryFolder(folder); + else + { + UUID sessionID = GetSessionID(folder.Owner); + string uri = GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString(); + return m_HGService.QueryFolder(uri, folder, sessionID); + } + } + + public bool HasInventoryForUser(UUID userID) + { + return false; + } + + public InventoryFolderBase RequestRootFolder(UUID userID) + { + return null; + } + + public List GetActiveGestures(UUID userId) + { + return new List(); + } + + #endregion + + private UUID GetSessionID(UUID userID) + { + ScenePresence sp = m_Scene.GetScenePresence(userID); + if (sp != null) + return sp.ControllingClient.SessionId; + + return UUID.Zero; + } + + private bool IsLocalGridUser(UUID userID) + { + if (m_UserProfileService == null) + return false; + + CachedUserInfo uinfo = m_UserProfileService.GetUserDetails(userID); + if (uinfo == null) + return true; + + string userInventoryServerURI = HGNetworkServersInfo.ServerURI(uinfo.UserProfile.UserInventoryURI); + + if ((userInventoryServerURI == m_LocalGridInventoryURI) || (userInventoryServerURI == "")) + { + return true; + } + return false; + } + + private string GetUserInventoryURI(UUID userID) + { + string invURI = m_LocalGridInventoryURI; + + CachedUserInfo uinfo = m_UserProfileService.GetUserDetails(userID); + if ((uinfo == null) || (uinfo.UserProfile == null)) + return invURI; + + string userInventoryServerURI = HGNetworkServersInfo.ServerURI(uinfo.UserProfile.UserInventoryURI); + + if ((userInventoryServerURI != null) && + (userInventoryServerURI != "")) + invURI = userInventoryServerURI; + return invURI; + } + + + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs new file mode 100644 index 0000000..8f04025 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs @@ -0,0 +1,286 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using log4net; +using Nini.Config; + +using System; +using System.Collections.Generic; +using System.Reflection; +using OpenSim.Framework; +using OpenSim.Data; +using OpenSim.Server.Base; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; +using OpenMetaverse; + + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory +{ + public class LocalInventoryServicesConnector : ISharedRegionModule, IInventoryService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private IInventoryService m_InventoryService; + + private bool m_Enabled = false; + private bool m_Initialized = false; + + public string Name + { + get { return "LocalInventoryServicesConnector"; } + } + + public void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("InventoryServices", ""); + if (name == Name) + { + IConfig inventoryConfig = source.Configs["InventoryService"]; + if (inventoryConfig == null) + { + m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini"); + return; + } + + string serviceDll = inventoryConfig.GetString("LocalServiceModule", String.Empty); + + if (serviceDll == String.Empty) + { + m_log.Error("[INVENTORY CONNECTOR]: No LocalServiceModule named in section InventoryService"); + return; + } + + Object[] args = new Object[] { source }; + m_log.DebugFormat("[INVENTORY CONNECTOR]: Service dll = {0}", serviceDll); + + m_InventoryService = ServerUtils.LoadPlugin(serviceDll, args); + + if (m_InventoryService == null) + { + m_log.Error("[INVENTORY CONNECTOR]: Can't load inventory service"); + //return; + throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's"); + } + + //List plugins + // = DataPluginFactory.LoadDataPlugins( + // configSettings.StandaloneInventoryPlugin, + // configSettings.StandaloneInventorySource); + + //foreach (IInventoryDataPlugin plugin in plugins) + //{ + // // Using the OSP wrapper plugin for database plugins should be made configurable at some point + // m_InventoryService.AddPlugin(new OspInventoryWrapperPlugin(plugin, this)); + //} + + m_Enabled = true; + m_log.Info("[INVENTORY CONNECTOR]: Local inventory connector enabled"); + } + } + } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + if (!m_Initialized) + { + // ugh! + scene.CommsManager.UserProfileCacheService.SetInventoryService(this); + scene.CommsManager.UserService.SetInventoryService(this); + m_Initialized = true; + } + +// m_log.DebugFormat( +// "[INVENTORY CONNECTOR]: Registering IInventoryService to scene {0}", scene.RegionInfo.RegionName); + + scene.RegisterModuleInterface(this); + } + + public void RemoveRegion(Scene scene) + { + } + + public void RegionLoaded(Scene scene) + { + if (!m_Enabled) + return; + + m_log.InfoFormat( + "[INVENTORY CONNECTOR]: Enabled local invnetory for region {0}", scene.RegionInfo.RegionName); + } + + #region IInventoryService + + public bool CreateUserInventory(UUID user) + { + return m_InventoryService.CreateUserInventory(user); + } + + public List GetInventorySkeleton(UUID userId) + { + return m_InventoryService.GetInventorySkeleton(userId); + } + + public InventoryCollection GetUserInventory(UUID id) + { + return m_InventoryService.GetUserInventory(id); + } + + public void GetUserInventory(UUID userID, InventoryReceiptCallback callback) + { + m_InventoryService.GetUserInventory(userID, callback); + } + + public List GetFolderItems(UUID userID, UUID folderID) + { + return m_InventoryService.GetFolderItems(userID, folderID); + } + + /// + /// Add a new folder to the user's inventory + /// + /// + /// true if the folder was successfully added + public bool AddFolder(InventoryFolderBase folder) + { + return m_InventoryService.AddFolder(folder); + } + + /// + /// Update a folder in the user's inventory + /// + /// + /// true if the folder was successfully updated + public bool UpdateFolder(InventoryFolderBase folder) + { + return m_InventoryService.UpdateFolder(folder); + } + + /// + /// Move an inventory folder to a new location + /// + /// A folder containing the details of the new location + /// true if the folder was successfully moved + public bool MoveFolder(InventoryFolderBase folder) + { + return m_InventoryService.MoveFolder(folder); + } + + /// + /// Purge an inventory folder of all its items and subfolders. + /// + /// + /// true if the folder was successfully purged + public bool PurgeFolder(InventoryFolderBase folder) + { + return m_InventoryService.PurgeFolder(folder); + } + + /// + /// Add a new item to the user's inventory + /// + /// + /// true if the item was successfully added + public bool AddItem(InventoryItemBase item) + { + return m_InventoryService.AddItem(item); + } + + /// + /// Update an item in the user's inventory + /// + /// + /// true if the item was successfully updated + public bool UpdateItem(InventoryItemBase item) + { + return m_InventoryService.UpdateItem(item); + } + + /// + /// Delete an item from the user's inventory + /// + /// + /// true if the item was successfully deleted + public bool DeleteItem(InventoryItemBase item) + { + return m_InventoryService.DeleteItem(item); + } + + public InventoryItemBase QueryItem(InventoryItemBase item) + { + return m_InventoryService.QueryItem(item); + } + + public InventoryFolderBase QueryFolder(InventoryFolderBase folder) + { + return m_InventoryService.QueryFolder(folder); + } + + /// + /// Does the given user have an inventory structure? + /// + /// + /// + public bool HasInventoryForUser(UUID userID) + { + return m_InventoryService.HasInventoryForUser(userID); + } + + /// + /// Retrieve the root inventory folder for the given user. + /// + /// + /// null if no root folder was found + public InventoryFolderBase RequestRootFolder(UUID userID) + { + return m_InventoryService.RequestRootFolder(userID); + } + + public List GetActiveGestures(UUID userId) + { + return m_InventoryService.GetActiveGestures(userId); + } + #endregion IInventoryService + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs new file mode 100644 index 0000000..9b51da7 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs @@ -0,0 +1,279 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using log4net; +using System; +using System.Collections.Generic; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Statistics; +using OpenSim.Services.Connectors; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; +using OpenMetaverse; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory +{ + public class RemoteInventoryServicesConnector : ISharedRegionModule, IInventoryService + { + private static readonly ILog m_log = + LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private bool m_Enabled = false; + private bool m_Initialized = false; + private Scene m_Scene; + private InventoryServicesConnector m_RemoteConnector; + + public string Name + { + get { return "RemoteInventoryServicesConnector"; } + } + + public RemoteInventoryServicesConnector() + { + } + + public RemoteInventoryServicesConnector(IConfigSource source) + { + Init(source); + } + + private void Init(IConfigSource source) + { + m_RemoteConnector = new InventoryServicesConnector(source); + } + + + #region ISharedRegionModule + + public void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("InventoryServices", ""); + if (name == Name) + { + Init(source); + m_Enabled = true; + + m_log.Info("[INVENTORY CONNECTOR]: Remote inventory enabled"); + } + } + } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + if (!m_Initialized) + { + m_Scene = scene; + // ugh! + scene.CommsManager.UserProfileCacheService.SetInventoryService(this); + scene.CommsManager.UserService.SetInventoryService(this); + m_Initialized = true; + } + + scene.RegisterModuleInterface(this); + } + + public void RemoveRegion(Scene scene) + { + } + + public void RegionLoaded(Scene scene) + { + if (!m_Enabled) + return; + + m_log.InfoFormat("[INVENTORY CONNECTOR]: Enabled remote inventory for region {0}", scene.RegionInfo.RegionName); + + } + + #endregion ISharedRegionModule + + #region IInventoryService + + public bool CreateUserInventory(UUID user) + { + return false; + } + + public List GetInventorySkeleton(UUID userId) + { + return new List(); + } + + public InventoryCollection GetUserInventory(UUID userID) + { + return null; + } + + public void GetUserInventory(UUID userID, InventoryReceiptCallback callback) + { + UUID sessionID = GetSessionID(userID); + try + { + m_RemoteConnector.GetUserInventory(userID.ToString(), sessionID, callback); + } + catch (Exception e) + { + if (StatsManager.SimExtraStats != null) + StatsManager.SimExtraStats.AddInventoryServiceRetrievalFailure(); + + m_log.ErrorFormat("[INVENTORY CONNECTOR]: Request inventory operation failed, {0} {1}", + e.Source, e.Message); + } + + } + + public List GetFolderItems(UUID userID, UUID folderID) + { + return new List(); + } + + public bool AddFolder(InventoryFolderBase folder) + { + if (folder == null) + return false; + + UUID sessionID = GetSessionID(folder.Owner); + return m_RemoteConnector.AddFolder(folder.Owner.ToString(), folder, sessionID); + } + + public bool UpdateFolder(InventoryFolderBase folder) + { + if (folder == null) + return false; + + UUID sessionID = GetSessionID(folder.Owner); + return m_RemoteConnector.UpdateFolder(folder.Owner.ToString(), folder, sessionID); + } + + public bool MoveFolder(InventoryFolderBase folder) + { + if (folder == null) + return false; + + UUID sessionID = GetSessionID(folder.Owner); + return m_RemoteConnector.MoveFolder(folder.Owner.ToString(), folder, sessionID); + } + + public bool PurgeFolder(InventoryFolderBase folder) + { + if (folder == null) + return false; + + UUID sessionID = GetSessionID(folder.Owner); + return m_RemoteConnector.PurgeFolder(folder.Owner.ToString(), folder, sessionID); + } + + public bool AddItem(InventoryItemBase item) + { + if (item == null) + return false; + + UUID sessionID = GetSessionID(item.Owner); + return m_RemoteConnector.AddItem(item.Owner.ToString(), item, sessionID); + } + + public bool UpdateItem(InventoryItemBase item) + { + if (item == null) + return false; + + UUID sessionID = GetSessionID(item.Owner); + return m_RemoteConnector.UpdateItem(item.Owner.ToString(), item, sessionID); + } + + public bool DeleteItem(InventoryItemBase item) + { + if (item == null) + return false; + + UUID sessionID = GetSessionID(item.Owner); + return m_RemoteConnector.DeleteItem(item.Owner.ToString(), item, sessionID); + } + + public InventoryItemBase QueryItem(InventoryItemBase item) + { + if (item == null) + return null; + + UUID sessionID = GetSessionID(item.Owner); + return m_RemoteConnector.QueryItem(item.Owner.ToString(), item, sessionID); + } + + public InventoryFolderBase QueryFolder(InventoryFolderBase folder) + { + if (folder == null) + return null; + + UUID sessionID = GetSessionID(folder.Owner); + return m_RemoteConnector.QueryFolder(folder.Owner.ToString(), folder, sessionID); + } + + public bool HasInventoryForUser(UUID userID) + { + return false; + } + + public InventoryFolderBase RequestRootFolder(UUID userID) + { + return null; + } + + public List GetActiveGestures(UUID userId) + { + return new List(); + } + + #endregion + + private UUID GetSessionID(UUID userID) + { + ScenePresence sp = m_Scene.GetScenePresence(userID); + if (sp != null) + return sp.ControllingClient.SessionId; + + return UUID.Zero; + } + + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/LocalNeighbourServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/LocalNeighbourServiceConnector.cs new file mode 100644 index 0000000..6f2b354 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/LocalNeighbourServiceConnector.cs @@ -0,0 +1,135 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using log4net; +using Nini.Config; +using System; +using System.Collections.Generic; +using System.Reflection; +using OpenSim.Framework; +using OpenSim.Server.Base; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Neighbour +{ + public class LocalNeighbourServicesConnector : + ISharedRegionModule, INeighbourService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private List m_Scenes = new List(); + + private bool m_Enabled = false; + + public LocalNeighbourServicesConnector() + { + } + + public LocalNeighbourServicesConnector(List scenes) + { + m_Scenes = scenes; + } + + #region ISharedRegionModule + + public string Name + { + get { return "LocalNeighbourServicesConnector"; } + } + + public void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("NeighbourServices", this.Name); + if (name == Name) + { + // m_Enabled rules whether this module registers as INeighbourService or not + m_Enabled = true; + m_log.Info("[NEIGHBOUR CONNECTOR]: Local neighbour connector enabled"); + } + } + } + + public void Close() + { + } + + public void AddRegion(Scene scene) + { + m_Scenes.Add(scene); + + if (!m_Enabled) + return; + + scene.RegisterModuleInterface(this); + } + + public void RegionLoaded(Scene scene) + { + m_log.Info("[NEIGHBOUR CONNECTOR]: Local neighbour connector enabled for region " + scene.RegionInfo.RegionName); + } + + public void PostInitialise() + { + } + + public void RemoveRegion(Scene scene) + { + // Always remove + if (m_Scenes.Contains(scene)) + m_Scenes.Remove(scene); + } + + #endregion ISharedRegionModule + + #region INeighbourService + + public bool HelloNeighbour(ulong regionHandle, RegionInfo thisRegion) + { + m_log.DebugFormat("[NEIGHBOUR CONNECTOR]: HelloNeighbour from {0}, to {1}. Count = {2}", + thisRegion.RegionName, regionHandle, m_Scenes.Count); + foreach (Scene s in m_Scenes) + { + if (s.RegionInfo.RegionHandle == regionHandle) + { + m_log.Debug("[NEIGHBOUR CONNECTOR]: Found region to SendHelloNeighbour"); + return s.IncomingHelloNeighbour(thisRegion); + } + } + m_log.DebugFormat("[NEIGHBOUR CONNECTOR]: region handle {0} not found", regionHandle); + return false; + } + + #endregion INeighbourService + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/RemoteNeighourServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/RemoteNeighourServiceConnector.cs new file mode 100644 index 0000000..9145d11 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/RemoteNeighourServiceConnector.cs @@ -0,0 +1,148 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using log4net; +using System; +using System.Collections.Generic; +using System.Reflection; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Services.Connectors; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; +using OpenSim.Server.Base; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Neighbour +{ + public class RemoteNeighbourServicesConnector : + NeighbourServicesConnector, ISharedRegionModule, INeighbourService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private bool m_Enabled = false; + private LocalNeighbourServicesConnector m_LocalService; + private string serviceDll; + private List m_Scenes = new List(); + + public string Name + { + get { return "RemoteNeighbourServicesConnector"; } + } + + public void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("NeighbourServices"); + if (name == Name) + { + m_LocalService = new LocalNeighbourServicesConnector(); + + //IConfig neighbourConfig = source.Configs["NeighbourService"]; + //if (neighbourConfig == null) + //{ + // m_log.Error("[NEIGHBOUR CONNECTOR]: NeighbourService missing from OpenSim.ini"); + // return; + //} + //serviceDll = neighbourConfig.GetString("LocalServiceModule", String.Empty); + //if (serviceDll == String.Empty) + //{ + // m_log.Error("[NEIGHBOUR CONNECTOR]: No LocalServiceModule named in section NeighbourService"); + // return; + //} + + m_Enabled = true; + + m_log.Info("[NEIGHBOUR CONNECTOR]: Remote Neighbour connector enabled"); + } + } + } + + public void PostInitialise() + { + //if (m_Enabled) + //{ + // Object[] args = new Object[] { m_Scenes }; + // m_LocalService = + // ServerUtils.LoadPlugin(serviceDll, + // args); + + // if (m_LocalService == null) + // { + // m_log.Error("[NEIGHBOUR CONNECTOR]: Can't load neighbour service"); + // Unregister(); + // return; + // } + //} + } + + public void Close() + { + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + m_MapService = scene.CommsManager.GridService; + m_LocalService.AddRegion(scene); + scene.RegisterModuleInterface(this); + } + + public void RemoveRegion(Scene scene) + { + if (m_Enabled && m_Scenes.Contains(scene)) + m_LocalService.RemoveRegion(scene); + } + + public void RegionLoaded(Scene scene) + { + if (!m_Enabled) + return; + + m_log.InfoFormat("[NEIGHBOUR CONNECTOR]: Enabled remote neighbours for region {0}", scene.RegionInfo.RegionName); + + } + + #region INeighbourService + + public override bool HelloNeighbour(ulong regionHandle, RegionInfo thisRegion) + { + if (m_LocalService.HelloNeighbour(regionHandle, thisRegion)) + return true; + + return base.HelloNeighbour(regionHandle, thisRegion); + } + + #endregion INeighbourService + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/LocalUserServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/LocalUserServiceConnector.cs new file mode 100644 index 0000000..f364999 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/LocalUserServiceConnector.cs @@ -0,0 +1,126 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Reflection; +using log4net; +using Nini.Config; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User +{ + public class LocalUserServicesConnector : ISharedRegionModule + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private IUserService m_UserService; + + private bool m_Enabled = false; + + public string Name + { + get { return "LocalUserServicesConnector"; } + } + + public void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("UserServices", ""); + if (name == Name) + { + IConfig userConfig = source.Configs["UserService"]; + if (userConfig == null) + { + m_log.Error("[USER CONNECTOR]: UserService missing from OpenSim.ini"); + return; + } + + string serviceDll = userConfig.GetString("LocalServiceModule", + String.Empty); + + if (serviceDll == String.Empty) + { + m_log.Error("[USER CONNECTOR]: No LocalServiceModule named in section UserService"); + return; + } + + Object[] args = new Object[] { source }; + m_UserService = + ServerUtils.LoadPlugin(serviceDll, + args); + + if (m_UserService == null) + { + m_log.Error("[USER CONNECTOR]: Can't load user service"); + return; + } + m_Enabled = true; + m_log.Info("[USER CONNECTOR]: Local user connector enabled"); + } + } + } + + public void PostInitialise() + { + if (!m_Enabled) + return; + } + + public void Close() + { + if (!m_Enabled) + return; + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + scene.RegisterModuleInterface(m_UserService); + } + + public void RemoveRegion(Scene scene) + { + if (!m_Enabled) + return; + } + + public void RegionLoaded(Scene scene) + { + if (!m_Enabled) + return; + } + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/RemoteUserServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/RemoteUserServiceConnector.cs new file mode 100644 index 0000000..00a2478 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/RemoteUserServiceConnector.cs @@ -0,0 +1,87 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using Nini.Config; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User +{ + public class RemoteUserServicesConnector : ISharedRegionModule + { + private bool m_Enabled = false; + + public string Name + { + get { return "RemoteUserServicesConnector"; } + } + + public void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("UserServices", ""); + if (name == Name) + { + m_Enabled = true; + } + } + } + + public void PostInitialise() + { + if (!m_Enabled) + return; + } + + public void Close() + { + if (!m_Enabled) + return; + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + } + + public void RemoveRegion(Scene scene) + { + if (!m_Enabled) + return; + } + + public void RegionLoaded(Scene scene) + { + if (!m_Enabled) + return; + } + } +} -- cgit v1.1