aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Capabilities/Caps.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Capabilities/Caps.cs')
-rw-r--r--OpenSim/Capabilities/Caps.cs278
1 files changed, 278 insertions, 0 deletions
diff --git a/OpenSim/Capabilities/Caps.cs b/OpenSim/Capabilities/Caps.cs
new file mode 100644
index 0000000..7492602
--- /dev/null
+++ b/OpenSim/Capabilities/Caps.cs
@@ -0,0 +1,278 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using System.Threading;
34using log4net;
35using Nini.Config;
36using OpenMetaverse;
37using OpenSim.Framework.Servers;
38using OpenSim.Framework.Servers.HttpServer;
39using OpenSim.Services.Interfaces;
40
41// using OpenSim.Region.Framework.Interfaces;
42
43namespace OpenSim.Framework.Capabilities
44{
45 /// <summary>
46 /// XXX Probably not a particularly nice way of allow us to get the scene presence from the scene (chiefly so that
47 /// we can popup a message on the user's client if the inventory service has permanently failed). But I didn't want
48 /// to just pass the whole Scene into CAPS.
49 /// </summary>
50 public delegate IClientAPI GetClientDelegate(UUID agentID);
51
52 public class Caps
53 {
54// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55
56 private string m_httpListenerHostName;
57 private uint m_httpListenPort;
58
59 /// <summary>
60 /// This is the uuid portion of every CAPS path. It is used to make capability urls private to the requester.
61 /// </summary>
62 private string m_capsObjectPath;
63 public string CapsObjectPath { get { return m_capsObjectPath; } }
64
65 private CapsHandlers m_capsHandlers;
66
67 private Dictionary<string, PollServiceEventArgs> m_pollServiceHandlers
68 = new Dictionary<string, PollServiceEventArgs>();
69
70 private Dictionary<string, string> m_externalCapsHandlers = new Dictionary<string, string>();
71
72 private IHttpServer m_httpListener;
73 private UUID m_agentID;
74 private string m_regionName;
75 private ManualResetEvent m_capsActive = new ManualResetEvent(false);
76
77 public UUID AgentID
78 {
79 get { return m_agentID; }
80 }
81
82 public string RegionName
83 {
84 get { return m_regionName; }
85 }
86
87 public string HostName
88 {
89 get { return m_httpListenerHostName; }
90 }
91
92 public uint Port
93 {
94 get { return m_httpListenPort; }
95 }
96
97 public IHttpServer HttpListener
98 {
99 get { return m_httpListener; }
100 }
101
102 public bool SSLCaps
103 {
104 get { return m_httpListener.UseSSL; }
105 }
106
107 public string SSLCommonName
108 {
109 get { return m_httpListener.SSLCommonName; }
110 }
111
112 public CapsHandlers CapsHandlers
113 {
114 get { return m_capsHandlers; }
115 }
116
117 public Dictionary<string, string> ExternalCapsHandlers
118 {
119 get { return m_externalCapsHandlers; }
120 }
121
122 public Caps(IHttpServer httpServer, string httpListen, uint httpPort, string capsPath,
123 UUID agent, string regionName)
124 {
125 m_capsObjectPath = capsPath;
126 m_httpListener = httpServer;
127 m_httpListenerHostName = httpListen;
128
129 m_httpListenPort = httpPort;
130
131 if (httpServer != null && httpServer.UseSSL)
132 {
133 m_httpListenPort = httpServer.SSLPort;
134 httpListen = httpServer.SSLCommonName;
135 httpPort = httpServer.SSLPort;
136 }
137
138 m_agentID = agent;
139 m_capsHandlers = new CapsHandlers(httpServer, httpListen, httpPort);
140 m_regionName = regionName;
141 m_capsActive.Reset();
142 }
143
144 ~Caps()
145 {
146 m_capsActive.Dispose();
147 }
148
149 /// <summary>
150 /// Register a handler. This allows modules to register handlers.
151 /// </summary>
152 /// <param name="capName"></param>
153 /// <param name="handler"></param>
154 public void RegisterHandler(string capName, IRequestHandler handler)
155 {
156 //m_log.DebugFormat("[CAPS]: Registering handler for \"{0}\": path {1}", capName, handler.Path);
157 m_capsHandlers[capName] = handler;
158 }
159
160 public void RegisterPollHandler(string capName, PollServiceEventArgs pollServiceHandler)
161 {
162// m_log.DebugFormat(
163// "[CAPS]: Registering handler with name {0}, url {1} for {2}",
164// capName, pollServiceHandler.Url, m_agentID, m_regionName);
165
166 m_pollServiceHandlers.Add(capName, pollServiceHandler);
167
168 m_httpListener.AddPollServiceHTTPHandler(pollServiceHandler.Url, pollServiceHandler);
169
170// uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port;
171// string protocol = "http";
172// string hostName = m_httpListenerHostName;
173//
174// if (MainServer.Instance.UseSSL)
175// {
176// hostName = MainServer.Instance.SSLCommonName;
177// port = MainServer.Instance.SSLPort;
178// protocol = "https";
179// }
180
181// RegisterHandler(
182// capName, String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, pollServiceHandler.Url));
183 }
184
185 /// <summary>
186 /// Register an external handler. The service for this capability is somewhere else
187 /// given by the URL.
188 /// </summary>
189 /// <param name="capsName"></param>
190 /// <param name="url"></param>
191 public void RegisterHandler(string capsName, string url)
192 {
193 m_externalCapsHandlers.Add(capsName, url);
194 }
195
196 /// <summary>
197 /// Remove all CAPS service handlers.
198 /// </summary>
199 public void DeregisterHandlers()
200 {
201 foreach (string capsName in m_capsHandlers.Caps)
202 {
203 m_capsHandlers.Remove(capsName);
204 }
205
206 foreach (PollServiceEventArgs handler in m_pollServiceHandlers.Values)
207 {
208 m_httpListener.RemovePollServiceHTTPHandler("", handler.Url);
209 }
210 }
211
212 public bool TryGetPollHandler(string name, out PollServiceEventArgs pollHandler)
213 {
214 return m_pollServiceHandlers.TryGetValue(name, out pollHandler);
215 }
216
217 public Dictionary<string, PollServiceEventArgs> GetPollHandlers()
218 {
219 return new Dictionary<string, PollServiceEventArgs>(m_pollServiceHandlers);
220 }
221
222 /// <summary>
223 /// Return an LLSD-serializable Hashtable describing the
224 /// capabilities and their handler details.
225 /// </summary>
226 /// <param name="excludeSeed">If true, then exclude the seed cap.</param>
227 public Hashtable GetCapsDetails(bool excludeSeed, List<string> requestedCaps)
228 {
229 Hashtable caps = CapsHandlers.GetCapsDetails(excludeSeed, requestedCaps);
230
231 lock (m_pollServiceHandlers)
232 {
233 foreach (KeyValuePair <string, PollServiceEventArgs> kvp in m_pollServiceHandlers)
234 {
235 if (!requestedCaps.Contains(kvp.Key))
236 continue;
237
238 string hostName = m_httpListenerHostName;
239 uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port;
240 string protocol = "http";
241
242 if (MainServer.Instance.UseSSL)
243 {
244 hostName = MainServer.Instance.SSLCommonName;
245 port = MainServer.Instance.SSLPort;
246 protocol = "https";
247 }
248 //
249 // caps.RegisterHandler("FetchInventoryDescendents2", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl));
250
251 caps[kvp.Key] = string.Format("{0}://{1}:{2}{3}", protocol, hostName, port, kvp.Value.Url);
252 }
253 }
254
255 // Add the external too
256 foreach (KeyValuePair<string, string> kvp in ExternalCapsHandlers)
257 {
258 if (!requestedCaps.Contains(kvp.Key))
259 continue;
260
261 caps[kvp.Key] = kvp.Value;
262 }
263
264 return caps;
265 }
266
267 public void Activate()
268 {
269 m_capsActive.Set();
270 }
271
272 public bool WaitForActivation()
273 {
274 // Wait for 30s. If that elapses, return false and run without caps
275 return m_capsActive.WaitOne(120000);
276 }
277 }
278} \ No newline at end of file