1
0

Caps.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Reflection;
  32. using log4net;
  33. using Nini.Config;
  34. using OpenMetaverse;
  35. using OpenSim.Framework.Servers;
  36. using OpenSim.Framework.Servers.HttpServer;
  37. using OpenSim.Services.Interfaces;
  38. // using OpenSim.Region.Framework.Interfaces;
  39. namespace OpenSim.Framework.Capabilities
  40. {
  41. /// <summary>
  42. /// XXX Probably not a particularly nice way of allow us to get the scene presence from the scene (chiefly so that
  43. /// we can popup a message on the user's client if the inventory service has permanently failed). But I didn't want
  44. /// to just pass the whole Scene into CAPS.
  45. /// </summary>
  46. public delegate IClientAPI GetClientDelegate(UUID agentID);
  47. public class Caps
  48. {
  49. // private static readonly ILog m_log =
  50. // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  51. private string m_httpListenerHostName;
  52. private uint m_httpListenPort;
  53. /// <summary>
  54. /// This is the uuid portion of every CAPS path. It is used to make capability urls private to the requester.
  55. /// </summary>
  56. private string m_capsObjectPath;
  57. public string CapsObjectPath { get { return m_capsObjectPath; } }
  58. private CapsHandlers m_capsHandlers;
  59. private Dictionary<string, string> m_externalCapsHandlers;
  60. private IHttpServer m_httpListener;
  61. private UUID m_agentID;
  62. private string m_regionName;
  63. public UUID AgentID
  64. {
  65. get { return m_agentID; }
  66. }
  67. public string RegionName
  68. {
  69. get { return m_regionName; }
  70. }
  71. public string HostName
  72. {
  73. get { return m_httpListenerHostName; }
  74. }
  75. public uint Port
  76. {
  77. get { return m_httpListenPort; }
  78. }
  79. public IHttpServer HttpListener
  80. {
  81. get { return m_httpListener; }
  82. }
  83. public bool SSLCaps
  84. {
  85. get { return m_httpListener.UseSSL; }
  86. }
  87. public string SSLCommonName
  88. {
  89. get { return m_httpListener.SSLCommonName; }
  90. }
  91. public CapsHandlers CapsHandlers
  92. {
  93. get { return m_capsHandlers; }
  94. }
  95. public Dictionary<string, string> ExternalCapsHandlers
  96. {
  97. get { return m_externalCapsHandlers; }
  98. }
  99. public Caps(IHttpServer httpServer, string httpListen, uint httpPort, string capsPath,
  100. UUID agent, string regionName)
  101. {
  102. m_capsObjectPath = capsPath;
  103. m_httpListener = httpServer;
  104. m_httpListenerHostName = httpListen;
  105. m_httpListenPort = httpPort;
  106. if (httpServer != null && httpServer.UseSSL)
  107. {
  108. m_httpListenPort = httpServer.SSLPort;
  109. httpListen = httpServer.SSLCommonName;
  110. httpPort = httpServer.SSLPort;
  111. }
  112. m_agentID = agent;
  113. m_capsHandlers = new CapsHandlers(httpServer, httpListen, httpPort, (httpServer == null) ? false : httpServer.UseSSL);
  114. m_externalCapsHandlers = new Dictionary<string, string>();
  115. m_regionName = regionName;
  116. }
  117. /// <summary>
  118. /// Register a handler. This allows modules to register handlers.
  119. /// </summary>
  120. /// <param name="capName"></param>
  121. /// <param name="handler"></param>
  122. public void RegisterHandler(string capName, IRequestHandler handler)
  123. {
  124. m_capsHandlers[capName] = handler;
  125. //m_log.DebugFormat("[CAPS]: Registering handler for \"{0}\": path {1}", capName, handler.Path);
  126. }
  127. /// <summary>
  128. /// Register an external handler. The service for this capability is somewhere else
  129. /// given by the URL.
  130. /// </summary>
  131. /// <param name="capsName"></param>
  132. /// <param name="url"></param>
  133. public void RegisterHandler(string capsName, string url)
  134. {
  135. m_externalCapsHandlers.Add(capsName, url);
  136. }
  137. /// <summary>
  138. /// Remove all CAPS service handlers.
  139. ///
  140. /// </summary>
  141. /// <param name="httpListener"></param>
  142. /// <param name="path"></param>
  143. /// <param name="restMethod"></param>
  144. public void DeregisterHandlers()
  145. {
  146. if (m_capsHandlers != null)
  147. {
  148. foreach (string capsName in m_capsHandlers.Caps)
  149. {
  150. m_capsHandlers.Remove(capsName);
  151. }
  152. }
  153. }
  154. }
  155. }