clockwerk-opensim-stable – Blame information for rev 1
?pathlinks?
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.Collections; |
||
29 | using System.Collections.Generic; |
||
30 | using OpenSim.Framework.Servers; |
||
31 | using OpenSim.Framework.Servers.HttpServer; |
||
32 | |||
33 | namespace OpenSim.Framework.Capabilities |
||
34 | { |
||
35 | /// <summary> |
||
36 | /// CapsHandlers is a cap handler container but also takes |
||
37 | /// care of adding and removing cap handlers to and from the |
||
38 | /// supplied BaseHttpServer. |
||
39 | /// </summary> |
||
40 | public class CapsHandlers |
||
41 | { |
||
42 | private Dictionary<string, IRequestHandler> m_capsHandlers = new Dictionary<string, IRequestHandler>(); |
||
43 | private IHttpServer m_httpListener; |
||
44 | private string m_httpListenerHostName; |
||
45 | private uint m_httpListenerPort; |
||
46 | private bool m_useSSL = false; |
||
47 | |||
48 | /// <summary></summary> |
||
49 | /// CapsHandlers is a cap handler container but also takes |
||
50 | /// care of adding and removing cap handlers to and from the |
||
51 | /// supplied BaseHttpServer. |
||
52 | /// </summary> |
||
53 | /// <param name="httpListener">base HTTP server</param> |
||
54 | /// <param name="httpListenerHostname">host name of the HTTP server</param> |
||
55 | /// <param name="httpListenerPort">HTTP port</param> |
||
56 | public CapsHandlers(BaseHttpServer httpListener, string httpListenerHostname, uint httpListenerPort) |
||
57 | : this(httpListener,httpListenerHostname,httpListenerPort, false) |
||
58 | { |
||
59 | } |
||
60 | |||
61 | /// <summary></summary> |
||
62 | /// CapsHandlers is a cap handler container but also takes |
||
63 | /// care of adding and removing cap handlers to and from the |
||
64 | /// supplied BaseHttpServer. |
||
65 | /// </summary> |
||
66 | /// <param name="httpListener">base HTTP server</param> |
||
67 | /// <param name="httpListenerHostname">host name of the HTTP |
||
68 | /// server</param> |
||
69 | /// <param name="httpListenerPort">HTTP port</param> |
||
70 | public CapsHandlers(IHttpServer httpListener, string httpListenerHostname, uint httpListenerPort, bool https) |
||
71 | { |
||
72 | m_httpListener = httpListener; |
||
73 | m_httpListenerHostName = httpListenerHostname; |
||
74 | m_httpListenerPort = httpListenerPort; |
||
75 | m_useSSL = https; |
||
76 | if (httpListener != null && m_useSSL) |
||
77 | { |
||
78 | m_httpListenerHostName = httpListener.SSLCommonName; |
||
79 | m_httpListenerPort = httpListener.SSLPort; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | /// <summary> |
||
84 | /// Remove the cap handler for a capability. |
||
85 | /// </summary> |
||
86 | /// <param name="capsName">name of the capability of the cap |
||
87 | /// handler to be removed</param> |
||
88 | public void Remove(string capsName) |
||
89 | { |
||
90 | lock (m_capsHandlers) |
||
91 | { |
||
92 | m_httpListener.RemoveStreamHandler("POST", m_capsHandlers[capsName].Path); |
||
93 | m_httpListener.RemoveStreamHandler("GET", m_capsHandlers[capsName].Path); |
||
94 | m_capsHandlers.Remove(capsName); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | public bool ContainsCap(string cap) |
||
99 | { |
||
100 | lock (m_capsHandlers) |
||
101 | return m_capsHandlers.ContainsKey(cap); |
||
102 | } |
||
103 | |||
104 | /// <summary> |
||
105 | /// The indexer allows us to treat the CapsHandlers object |
||
106 | /// in an intuitive dictionary like way. |
||
107 | /// </summary> |
||
108 | /// <remarks> |
||
109 | /// The indexer will throw an exception when you try to |
||
110 | /// retrieve a cap handler for a cap that is not contained in |
||
111 | /// CapsHandlers. |
||
112 | /// </remarks> |
||
113 | public IRequestHandler this[string idx] |
||
114 | { |
||
115 | get |
||
116 | { |
||
117 | lock (m_capsHandlers) |
||
118 | return m_capsHandlers[idx]; |
||
119 | } |
||
120 | |||
121 | set |
||
122 | { |
||
123 | lock (m_capsHandlers) |
||
124 | { |
||
125 | if (m_capsHandlers.ContainsKey(idx)) |
||
126 | { |
||
127 | m_httpListener.RemoveStreamHandler("POST", m_capsHandlers[idx].Path); |
||
128 | m_capsHandlers.Remove(idx); |
||
129 | } |
||
130 | |||
131 | if (null == value) return; |
||
132 | |||
133 | m_capsHandlers[idx] = value; |
||
134 | m_httpListener.AddStreamHandler(value); |
||
135 | } |
||
136 | } |
||
137 | } |
||
138 | |||
139 | /// <summary> |
||
140 | /// Return the list of cap names for which this CapsHandlers |
||
141 | /// object contains cap handlers. |
||
142 | /// </summary> |
||
143 | public string[] Caps |
||
144 | { |
||
145 | get |
||
146 | { |
||
147 | lock (m_capsHandlers) |
||
148 | { |
||
149 | string[] __keys = new string[m_capsHandlers.Keys.Count]; |
||
150 | m_capsHandlers.Keys.CopyTo(__keys, 0); |
||
151 | return __keys; |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | |||
156 | /// <summary> |
||
157 | /// Return an LLSD-serializable Hashtable describing the |
||
158 | /// capabilities and their handler details. |
||
159 | /// </summary> |
||
160 | /// <param name="excludeSeed">If true, then exclude the seed cap.</param> |
||
161 | public Hashtable GetCapsDetails(bool excludeSeed, List<string> requestedCaps) |
||
162 | { |
||
163 | Hashtable caps = new Hashtable(); |
||
164 | string protocol = "http://"; |
||
165 | |||
166 | if (m_useSSL) |
||
167 | protocol = "https://"; |
||
168 | |||
169 | string baseUrl = protocol + m_httpListenerHostName + ":" + m_httpListenerPort.ToString(); |
||
170 | |||
171 | lock (m_capsHandlers) |
||
172 | { |
||
173 | foreach (string capsName in m_capsHandlers.Keys) |
||
174 | { |
||
175 | if (excludeSeed && "SEED" == capsName) |
||
176 | continue; |
||
177 | |||
178 | if (requestedCaps != null && !requestedCaps.Contains(capsName)) |
||
179 | continue; |
||
180 | |||
181 | caps[capsName] = baseUrl + m_capsHandlers[capsName].Path; |
||
182 | } |
||
183 | } |
||
184 | |||
185 | return caps; |
||
186 | } |
||
187 | |||
188 | /// <summary> |
||
189 | /// Returns a copy of the dictionary of all the HTTP cap handlers |
||
190 | /// </summary> |
||
191 | /// <returns> |
||
192 | /// The dictionary copy. The key is the capability name, the value is the HTTP handler. |
||
193 | /// </returns> |
||
194 | public Dictionary<string, IRequestHandler> GetCapsHandlers() |
||
195 | { |
||
196 | lock (m_capsHandlers) |
||
197 | return new Dictionary<string, IRequestHandler>(m_capsHandlers); |
||
198 | } |
||
199 | } |
||
200 | } |