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