From 042cd57e948f6e3695d1d5b2b2a473ee77a1e9c4 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 3 Apr 2008 15:44:20 +0000 Subject: * From: Dr Scofield * This patch removes voice code into a region module. This required the implementation of events and other code to allow region modules to register their own caps handlers, and should allow different voice module implementations. * CAVEAT: This does not provide complete voice support, it merely provides the hooks so that it can be plugged in. --- .../Framework/Communications/Capabilities/Caps.cs | 189 ++++++--------------- .../Communications/Capabilities/CapsHandlers.cs | 144 ++++++++++++++++ .../Communications/Capabilities/LLSDCapsDetails.cs | 52 ------ 3 files changed, 192 insertions(+), 193 deletions(-) create mode 100755 OpenSim/Framework/Communications/Capabilities/CapsHandlers.cs delete mode 100644 OpenSim/Framework/Communications/Capabilities/LLSDCapsDetails.cs (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Communications/Capabilities/Caps.cs b/OpenSim/Framework/Communications/Capabilities/Caps.cs index 53cad66..886ca49 100644 --- a/OpenSim/Framework/Communications/Capabilities/Caps.cs +++ b/OpenSim/Framework/Communications/Capabilities/Caps.cs @@ -55,25 +55,22 @@ namespace OpenSim.Region.Capabilities public delegate List FetchInventoryDescendentsCAPS(LLUUID agentID, LLUUID folderID, LLUUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder); - /// - /// FIXME This is a temporary delegate, and should disappear once the voice code is fleshed out and moved into its - /// own region module. - /// - public delegate CachedUserInfo GetUserDetailsCAPS(LLUUID agentID); - public class Caps { - private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - + private static readonly log4net.ILog m_log = + log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + private string m_httpListenerHostName; private uint m_httpListenPort; - + /// /// This is the uuid portion of every CAPS path. It is used to make capability urls private to the requester. /// private string m_capsObjectPath; public string CapsObjectPath { get { return m_capsObjectPath; } } + private CapsHandlers m_capsHandlers; + private static readonly string m_requestPath = "0000/"; private static readonly string m_mapLayerPath = "0001/"; private static readonly string m_newInventory = "0002/"; @@ -99,7 +96,6 @@ namespace OpenSim.Region.Capabilities public TaskScriptUpdatedCallback TaskScriptUpdatedCall = null; // public FetchInventoryDescendentsCAPS CAPSFetchInventoryDescendents = null; - public GetUserDetailsCAPS CAPSGetUserDetails = null; public Caps(AssetCache assetCache, BaseHttpServer httpServer, string httpListen, uint httpPort, string capsPath, LLUUID agent, bool dumpAssetsToFile) @@ -111,6 +107,7 @@ namespace OpenSim.Region.Capabilities m_httpListenPort = httpPort; m_agentID = agent; m_dumpAssetsToFile = dumpAssetsToFile; + m_capsHandlers = new CapsHandlers(httpServer, httpListen, httpPort); } /// @@ -123,27 +120,31 @@ namespace OpenSim.Region.Capabilities string capsBase = "/CAPS/" + m_capsObjectPath; try - { - m_httpListener.AddStreamHandler( - new LLSDStreamhandler("POST", capsBase + m_mapLayerPath, GetMapLayer)); - m_httpListener.AddStreamHandler( + { + // the root of all evil + m_capsHandlers["SEED"] = new RestStreamHandler("POST", capsBase + m_requestPath, CapsRequest); + m_capsHandlers["MapLayer"] = + new LLSDStreamhandler("POST", + capsBase + m_mapLayerPath, + GetMapLayer); + m_capsHandlers["NewFileAgentInventory"] = new LLSDStreamhandler("POST", capsBase + m_newInventory, - NewAgentInventoryRequest)); - - // m_httpListener.AddStreamHandler( - // new LLSDStreamhandler("POST", - // capsBase + m_fetchInventory, - // FetchInventory)); - - - AddLegacyCapsHandler(m_httpListener, m_requestPath, CapsRequest); - //AddLegacyCapsHandler(m_httpListener, m_requestTexture , RequestTexture); - AddLegacyCapsHandler(m_httpListener, m_parcelVoiceInfoRequestPath, ParcelVoiceInfoRequest); - AddLegacyCapsHandler(m_httpListener, m_provisionVoiceAccountRequestPath, ProvisionVoiceAccountRequest); - AddLegacyCapsHandler(m_httpListener, m_notecardUpdatePath, NoteCardAgentInventory); - AddLegacyCapsHandler(m_httpListener, m_notecardTaskUpdatePath, ScriptTaskInventory); - AddLegacyCapsHandler(m_httpListener, m_fetchInventoryPath, FetchInventoryRequest); + NewAgentInventoryRequest); + m_capsHandlers["UpdateNotecardAgentInventory"] = + new RestStreamHandler("POST", capsBase + m_notecardUpdatePath, NoteCardAgentInventory); + m_capsHandlers["UpdateScriptAgentInventory"] = m_capsHandlers["UpdateNotecardAgentInventory"]; + m_capsHandlers["UpdateScriptTaskInventory"] = + new RestStreamHandler("POST", capsBase + m_notecardTaskUpdatePath, ScriptTaskInventory); + m_capsHandlers["FetchInventoryDescendents"] = + new RestStreamHandler("POST", capsBase + m_fetchInventoryPath, FetchInventoryRequest); + // m_capsHandlers["FetchInventoryDescendents"] = + // new LLSDStreamhandler("POST", + // capsBase + m_fetchInventory, + // FetchInventory)); + // m_capsHandlers["RequestTextureDownload"] = new RestStreamHandler("POST", + // capsBase + m_requestTexture, + // RequestTexture); } catch (Exception e) { @@ -152,35 +153,29 @@ namespace OpenSim.Region.Capabilities } /// + /// Register a handler. This allows modules to register handlers. + /// + /// + /// + public void RegisterHandler(string capName, IRequestHandler handler) + { + m_capsHandlers[capName] = handler; + m_log.DebugFormat("[CAPS]: Registering handler for \"{0}\": path {1}", capName, handler.Path); + } + + /// /// Remove all CAPS service handlers. /// - /// FIXME: Would be much nicer to remove and all paths to a single list. However, this is a little awkward - /// than it could be as we set up some handlers differently (legacy and non-legacy) /// /// /// /// public void DeregisterHandlers() { - string capsBase = "/CAPS/" + m_capsObjectPath; - - m_httpListener.RemoveStreamHandler("POST", capsBase + m_mapLayerPath); - m_httpListener.RemoveStreamHandler("POST", capsBase + m_newInventory); - m_httpListener.RemoveStreamHandler("POST", capsBase + m_requestPath); - m_httpListener.RemoveStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath); - m_httpListener.RemoveStreamHandler("POST", capsBase + m_provisionVoiceAccountRequestPath); - m_httpListener.RemoveStreamHandler("POST", capsBase + m_notecardUpdatePath); - m_httpListener.RemoveStreamHandler("POST", capsBase + m_notecardTaskUpdatePath); - m_httpListener.RemoveStreamHandler("POST", capsBase + m_fetchInventoryPath); - } - - //[Obsolete("Use BaseHttpServer.AddStreamHandler(new LLSDStreamHandler( LLSDMethod delegate )) instead.")] - //Commented out the obsolete as at this time the first caps request can not use the new Caps method - //as the sent type is a array and not a map and the deserialising doesn't deal properly with arrays. - private void AddLegacyCapsHandler(BaseHttpServer httpListener, string path, RestMethod restMethod) - { - string capsBase = "/CAPS/" + m_capsObjectPath; - httpListener.AddStreamHandler(new RestStreamHandler("POST", capsBase + path, restMethod)); + foreach(string capsName in m_capsHandlers.Caps) + { + m_capsHandlers.Remove(capsName); + } } /// @@ -193,31 +188,12 @@ namespace OpenSim.Region.Capabilities public string CapsRequest(string request, string path, string param) { //Console.WriteLine("caps request " + request); - string result = LLSDHelpers.SerialiseLLSDReply(GetCapabilities()); + string result = LLSDHelpers.SerialiseLLSDReply(m_capsHandlers.CapsDetails); return result; } - /// - /// Return an LLSDCapsDetails listing all the capabilities this server can provide - /// - /// - protected LLSDCapsDetails GetCapabilities() - { - LLSDCapsDetails caps = new LLSDCapsDetails(); - string capsBaseUrl = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + "/CAPS/" + - m_capsObjectPath; - caps.MapLayer = capsBaseUrl + m_mapLayerPath; - // caps.RequestTextureDownload = capsBaseUrl + m_requestTexture; - caps.NewFileAgentInventory = capsBaseUrl + m_newInventory; - caps.UpdateNotecardAgentInventory = capsBaseUrl + m_notecardUpdatePath; - caps.UpdateScriptAgentInventory = capsBaseUrl + m_notecardUpdatePath; - caps.UpdateScriptTaskInventory = capsBaseUrl + m_notecardTaskUpdatePath; - caps.FetchInventoryDescendents = capsBaseUrl + m_fetchInventoryPath; - caps.ParcelVoiceInfoRequest = capsBaseUrl + m_parcelVoiceInfoRequestPath; - caps.ProvisionVoiceAccountRequest = capsBaseUrl + m_provisionVoiceAccountRequestPath; - - return caps; - } + // FIXME: these all should probably go into the respective region + // modules public string FetchInventoryRequest(string request, string path, string param) { @@ -443,75 +419,6 @@ namespace OpenSim.Region.Capabilities return null; } - /// - /// Callback for a client request for ParcelVoiceInfo - /// - /// - /// - /// - /// - public string ParcelVoiceInfoRequest(string request, string path, string param) { - try - { - m_log.DebugFormat("[CAPS][PARCELVOICE]: request: {0}, path: {1}, param: {2}", request, path, param); - - // XXX brutal hack, we need to get channel_uri, region - // name, and parcel_local_id from somewhere - Hashtable creds = new Hashtable(); - - creds["channel_uri"] = "sip:testroom@testserver.com"; - - LLSDParcelVoiceInfoResponse parcelVoiceInfo = - new LLSDParcelVoiceInfoResponse("OpenSim Test", 1, creds); - - // XXX for debugging purposes: - string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo); - m_log.DebugFormat("[CAPS][PARCELVOICE]: {0}", r); - - return r; - } - catch (Exception e) - { - m_log.Error("[CAPS]: " + e.ToString()); - } - - return null; - } - - /// - /// Callback for a client request for Voice Account Details - /// - /// - /// - /// - /// - public string ProvisionVoiceAccountRequest(string request, string path, string param) { - try - { - m_log.DebugFormat("[CAPS][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}", request, path, param); - - if (null == CAPSGetUserDetails) throw new Exception("CAPSGetUserDetails null"); - - string voiceUser = "x" + Convert.ToBase64String(m_agentID.GetBytes()); - voiceUser = voiceUser.Replace('+', '-').Replace('/', '_'); - - CachedUserInfo userInfo = CAPSGetUserDetails(m_agentID); - if (null == userInfo) throw new Exception("CAPSGetUserDetails returned null"); - - LLSDVoiceAccountResponse voiceAccountResponse = - new LLSDVoiceAccountResponse(voiceUser, "$1$" + userInfo.UserProfile.passwordHash); - string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse); - m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r); - return r; - } - catch (Exception e) - { - m_log.Error("[CAPS][PROVISIONVOICE]: " + e.ToString()); - } - - return null; - } - /// /// Called by the notecard update handler. Provides a URL to which the client can upload a new asset. /// diff --git a/OpenSim/Framework/Communications/Capabilities/CapsHandlers.cs b/OpenSim/Framework/Communications/Capabilities/CapsHandlers.cs new file mode 100755 index 0000000..a3d6b71 --- /dev/null +++ b/OpenSim/Framework/Communications/Capabilities/CapsHandlers.cs @@ -0,0 +1,144 @@ +/* + * 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 OpenSim 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.Collections.Generic; +using System.IO; +using libsecondlife; +using OpenSim.Framework; +using OpenSim.Framework.Communications.Cache; +using OpenSim.Framework.Console; +using OpenSim.Framework.Servers; + +namespace OpenSim.Region.Capabilities +{ + /// + /// CapsHandlers is a cap handler container but also takes + /// care of adding and removing cap handlers to and from the + /// supplied BaseHttpServer. + /// + public class CapsHandlers + { + private Dictionary m_capsHandlers = new Dictionary(); + private BaseHttpServer m_httpListener; + private string m_httpListenerHostName; + private uint m_httpListenerPort; + + /// + /// base HTTP server + /// host name of the HTTP + /// server + /// HTTP port + public CapsHandlers(BaseHttpServer httpListener, string httpListenerHostname, uint httpListenerPort) + { + m_httpListener = httpListener; + m_httpListenerHostName = httpListenerHostname; + m_httpListenerPort = httpListenerPort; + } + + /// + /// Remove the cap handler for a capability. + /// + /// name of the capability of the cap + /// handler to be removed + public void Remove(string capsName) + { + m_capsHandlers.Remove(capsName); + } + + public bool ContainsCap(string cap) + { + return m_capsHandlers.ContainsKey(cap); + } + + /// + /// The indexer allows us to treat the CapsHandlers object + /// in an intuitive dictionary like way. + /// + /// + /// The indexer will throw an exception when you try to + /// retrieve a cap handler for a cap that is not contained in + /// CapsHandlers. + /// + public IRequestHandler this[string idx] + { + get + { + return m_capsHandlers[idx]; + } + + set + { + if (m_capsHandlers.ContainsKey(idx)) + { + m_httpListener.RemoveStreamHandler("POST", m_capsHandlers[idx].Path); + m_capsHandlers.Remove(idx); + } + + if (null == value) return; + + m_capsHandlers[idx] = value; + m_httpListener.AddStreamHandler(value); + } + } + + /// + /// Return the list of cap names for which this CapsHandlers + /// object contains cap handlers. + /// + public string[] Caps + { + get + { + string[] __keys = new string[m_capsHandlers.Keys.Count]; + m_capsHandlers.Keys.CopyTo(__keys, 0); + return __keys; + } + } + + /// + /// Return an LLSD-serializable Hashtable describing the + /// capabilities and their handler details. + /// + public Hashtable CapsDetails + { + get + { + Hashtable caps = new Hashtable(); + string baseUrl = "http://" + m_httpListenerHostName + ":" + m_httpListenerPort.ToString(); + foreach (string capsName in m_capsHandlers.Keys) + { + // skip SEED cap + if ("SEED" == capsName) continue; + caps[capsName] = baseUrl + m_capsHandlers[capsName].Path; + } + return caps; + } + } + } +} diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDCapsDetails.cs b/OpenSim/Framework/Communications/Capabilities/LLSDCapsDetails.cs deleted file mode 100644 index bd1c9da..0000000 --- a/OpenSim/Framework/Communications/Capabilities/LLSDCapsDetails.cs +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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 OpenSim 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; - -namespace OpenSim.Region.Capabilities -{ - [LLSDType("MAP")] - public class LLSDCapsDetails - { - public string MapLayer = String.Empty; - public string NewFileAgentInventory = String.Empty; - //public string EventQueueGet = String.Empty; - // public string RequestTextureDownload = String.Empty; - // public string ChatSessionRequest = String.Empty; - public string UpdateNotecardAgentInventory = String.Empty; - public string UpdateScriptAgentInventory = String.Empty; - public string UpdateScriptTaskInventory = String.Empty; - public string ParcelVoiceInfoRequest = String.Empty; - public string FetchInventoryDescendents = String.Empty; - public string ProvisionVoiceAccountRequest = String.Empty; - - - public LLSDCapsDetails() - { - } - } -} -- cgit v1.1