clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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  
28 using System;
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.IO;
32 using System.Reflection;
33 using log4net;
34 using Nini.Config;
35 using OpenMetaverse;
36 using OpenSim.Framework.Servers;
37 using OpenSim.Framework.Servers.HttpServer;
38 using OpenSim.Services.Interfaces;
39  
40 // using OpenSim.Region.Framework.Interfaces;
41  
42 namespace 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 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54  
55 private string m_httpListenerHostName;
56 private uint m_httpListenPort;
57  
58 /// <summary>
59 /// This is the uuid portion of every CAPS path. It is used to make capability urls private to the requester.
60 /// </summary>
61 private string m_capsObjectPath;
62 public string CapsObjectPath { get { return m_capsObjectPath; } }
63  
64 private CapsHandlers m_capsHandlers;
65  
66 private Dictionary<string, PollServiceEventArgs> m_pollServiceHandlers
67 = new Dictionary<string, PollServiceEventArgs>();
68  
69 private Dictionary<string, string> m_externalCapsHandlers = new Dictionary<string, string>();
70  
71 private IHttpServer m_httpListener;
72 private UUID m_agentID;
73 private string m_regionName;
74  
75 public UUID AgentID
76 {
77 get { return m_agentID; }
78 }
79  
80 public string RegionName
81 {
82 get { return m_regionName; }
83 }
84  
85 public string HostName
86 {
87 get { return m_httpListenerHostName; }
88 }
89  
90 public uint Port
91 {
92 get { return m_httpListenPort; }
93 }
94  
95 public IHttpServer HttpListener
96 {
97 get { return m_httpListener; }
98 }
99  
100 public bool SSLCaps
101 {
102 get { return m_httpListener.UseSSL; }
103 }
104  
105 public string SSLCommonName
106 {
107 get { return m_httpListener.SSLCommonName; }
108 }
109  
110 public CapsHandlers CapsHandlers
111 {
112 get { return m_capsHandlers; }
113 }
114  
115 public Dictionary<string, string> ExternalCapsHandlers
116 {
117 get { return m_externalCapsHandlers; }
118 }
119  
120 public Caps(IHttpServer httpServer, string httpListen, uint httpPort, string capsPath,
121 UUID agent, string regionName)
122 {
123 m_capsObjectPath = capsPath;
124 m_httpListener = httpServer;
125 m_httpListenerHostName = httpListen;
126  
127 m_httpListenPort = httpPort;
128  
129 if (httpServer != null && httpServer.UseSSL)
130 {
131 m_httpListenPort = httpServer.SSLPort;
132 httpListen = httpServer.SSLCommonName;
133 httpPort = httpServer.SSLPort;
134 }
135  
136 m_agentID = agent;
137 m_capsHandlers = new CapsHandlers(httpServer, httpListen, httpPort, (httpServer == null) ? false : httpServer.UseSSL);
138 m_regionName = regionName;
139 }
140  
141 /// <summary>
142 /// Register a handler. This allows modules to register handlers.
143 /// </summary>
144 /// <param name="capName"></param>
145 /// <param name="handler"></param>
146 public void RegisterHandler(string capName, IRequestHandler handler)
147 {
148 //m_log.DebugFormat("[CAPS]: Registering handler for \"{0}\": path {1}", capName, handler.Path);
149 m_capsHandlers[capName] = handler;
150 }
151  
152 public void RegisterPollHandler(string capName, PollServiceEventArgs pollServiceHandler)
153 {
154 // m_log.DebugFormat(
155 // "[CAPS]: Registering handler with name {0}, url {1} for {2}",
156 // capName, pollServiceHandler.Url, m_agentID, m_regionName);
157  
158 m_pollServiceHandlers.Add(capName, pollServiceHandler);
159  
160 m_httpListener.AddPollServiceHTTPHandler(pollServiceHandler.Url, pollServiceHandler);
161  
162 // uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port;
163 // string protocol = "http";
164 // string hostName = m_httpListenerHostName;
165 //
166 // if (MainServer.Instance.UseSSL)
167 // {
168 // hostName = MainServer.Instance.SSLCommonName;
169 // port = MainServer.Instance.SSLPort;
170 // protocol = "https";
171 // }
172  
173 // RegisterHandler(
174 // capName, String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, pollServiceHandler.Url));
175 }
176  
177 /// <summary>
178 /// Register an external handler. The service for this capability is somewhere else
179 /// given by the URL.
180 /// </summary>
181 /// <param name="capsName"></param>
182 /// <param name="url"></param>
183 public void RegisterHandler(string capsName, string url)
184 {
185 m_externalCapsHandlers.Add(capsName, url);
186 }
187  
188 /// <summary>
189 /// Remove all CAPS service handlers.
190 /// </summary>
191 public void DeregisterHandlers()
192 {
193 foreach (string capsName in m_capsHandlers.Caps)
194 {
195 m_capsHandlers.Remove(capsName);
196 }
197  
198 foreach (PollServiceEventArgs handler in m_pollServiceHandlers.Values)
199 {
200 m_httpListener.RemovePollServiceHTTPHandler("", handler.Url);
201 }
202 }
203  
204 public bool TryGetPollHandler(string name, out PollServiceEventArgs pollHandler)
205 {
206 return m_pollServiceHandlers.TryGetValue(name, out pollHandler);
207 }
208  
209 public Dictionary<string, PollServiceEventArgs> GetPollHandlers()
210 {
211 return new Dictionary<string, PollServiceEventArgs>(m_pollServiceHandlers);
212 }
213  
214 /// <summary>
215 /// Return an LLSD-serializable Hashtable describing the
216 /// capabilities and their handler details.
217 /// </summary>
218 /// <param name="excludeSeed">If true, then exclude the seed cap.</param>
219 public Hashtable GetCapsDetails(bool excludeSeed, List<string> requestedCaps)
220 {
221 Hashtable caps = CapsHandlers.GetCapsDetails(excludeSeed, requestedCaps);
222  
223 lock (m_pollServiceHandlers)
224 {
225 foreach (KeyValuePair <string, PollServiceEventArgs> kvp in m_pollServiceHandlers)
226 {
227 if (!requestedCaps.Contains(kvp.Key))
228 continue;
229  
230 string hostName = m_httpListenerHostName;
231 uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port;
232 string protocol = "http";
233  
234 if (MainServer.Instance.UseSSL)
235 {
236 hostName = MainServer.Instance.SSLCommonName;
237 port = MainServer.Instance.SSLPort;
238 protocol = "https";
239 }
240 //
241 // caps.RegisterHandler("FetchInventoryDescendents2", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl));
242  
243 caps[kvp.Key] = string.Format("{0}://{1}:{2}{3}", protocol, hostName, port, kvp.Value.Url);
244 }
245 }
246  
247 // Add the external too
248 foreach (KeyValuePair<string, string> kvp in ExternalCapsHandlers)
249 {
250 if (!requestedCaps.Contains(kvp.Key))
251 continue;
252  
253 caps[kvp.Key] = kvp.Value;
254 }
255  
256 return caps;
257 }
258 }
259 }