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.cs176
1 files changed, 176 insertions, 0 deletions
diff --git a/OpenSim/Capabilities/Caps.cs b/OpenSim/Capabilities/Caps.cs
new file mode 100644
index 0000000..e188896
--- /dev/null
+++ b/OpenSim/Capabilities/Caps.cs
@@ -0,0 +1,176 @@
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 log4net;
34using Nini.Config;
35using OpenMetaverse;
36using OpenSim.Framework.Servers;
37using OpenSim.Framework.Servers.HttpServer;
38using OpenSim.Services.Interfaces;
39
40// using OpenSim.Region.Framework.Interfaces;
41
42namespace OpenSim.Framework.Capabilities
43{
44 /// <summary>
45 /// XXX Probably not a particularly nice way of allow us to get the scene presence from the scene (chiefly so that
46 /// we can popup a message on the user's client if the inventory service has permanently failed). But I didn't want
47 /// to just pass the whole Scene into CAPS.
48 /// </summary>
49 public delegate IClientAPI GetClientDelegate(UUID agentID);
50
51 public class Caps
52 {
53 private static readonly ILog m_log =
54 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 private Dictionary<string, string> m_externalCapsHandlers;
67
68 private IHttpServer m_httpListener;
69 private UUID m_agentID;
70 private string m_regionName;
71
72 public UUID AgentID
73 {
74 get { return m_agentID; }
75 }
76
77 public string RegionName
78 {
79 get { return m_regionName; }
80 }
81
82 public string HostName
83 {
84 get { return m_httpListenerHostName; }
85 }
86
87 public uint Port
88 {
89 get { return m_httpListenPort; }
90 }
91
92 public IHttpServer HttpListener
93 {
94 get { return m_httpListener; }
95 }
96
97 public bool SSLCaps
98 {
99 get { return m_httpListener.UseSSL; }
100 }
101 public string SSLCommonName
102 {
103 get { return m_httpListener.SSLCommonName; }
104 }
105 public CapsHandlers CapsHandlers
106 {
107 get { return m_capsHandlers; }
108 }
109 public Dictionary<string, string> ExternalCapsHandlers
110 {
111 get { return m_externalCapsHandlers; }
112 }
113
114 public Caps(IHttpServer httpServer, string httpListen, uint httpPort, string capsPath,
115 UUID agent, string regionName)
116 {
117 m_capsObjectPath = capsPath;
118 m_httpListener = httpServer;
119 m_httpListenerHostName = httpListen;
120
121 m_httpListenPort = httpPort;
122
123 if (httpServer != null && httpServer.UseSSL)
124 {
125 m_httpListenPort = httpServer.SSLPort;
126 httpListen = httpServer.SSLCommonName;
127 httpPort = httpServer.SSLPort;
128 }
129
130 m_agentID = agent;
131 m_capsHandlers = new CapsHandlers(httpServer, httpListen, httpPort, (httpServer == null) ? false : httpServer.UseSSL);
132 m_externalCapsHandlers = new Dictionary<string, string>();
133 m_regionName = regionName;
134 }
135
136 /// <summary>
137 /// Register a handler. This allows modules to register handlers.
138 /// </summary>
139 /// <param name="capName"></param>
140 /// <param name="handler"></param>
141 public void RegisterHandler(string capName, IRequestHandler handler)
142 {
143 m_capsHandlers[capName] = handler;
144 //m_log.DebugFormat("[CAPS]: Registering handler for \"{0}\": path {1}", capName, handler.Path);
145 }
146
147 /// <summary>
148 /// Register an external handler. The service for this capability is somewhere else
149 /// given by the URL.
150 /// </summary>
151 /// <param name="capsName"></param>
152 /// <param name="url"></param>
153 public void RegisterHandler(string capsName, string url)
154 {
155 m_externalCapsHandlers.Add(capsName, url);
156 }
157
158 /// <summary>
159 /// Remove all CAPS service handlers.
160 ///
161 /// </summary>
162 /// <param name="httpListener"></param>
163 /// <param name="path"></param>
164 /// <param name="restMethod"></param>
165 public void DeregisterHandlers()
166 {
167 if (m_capsHandlers != null)
168 {
169 foreach (string capsName in m_capsHandlers.Caps)
170 {
171 m_capsHandlers.Remove(capsName);
172 }
173 }
174 }
175 }
176}