aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Capabilities/CapsHandlers.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Framework/Communications/Capabilities/CapsHandlers.cs144
1 files changed, 144 insertions, 0 deletions
diff --git a/OpenSim/Framework/Communications/Capabilities/CapsHandlers.cs b/OpenSim/Framework/Communications/Capabilities/CapsHandlers.cs
new file mode 100755
index 0000000..a3d6b71
--- /dev/null
+++ b/OpenSim/Framework/Communications/Capabilities/CapsHandlers.cs
@@ -0,0 +1,144 @@
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 OpenSim 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 libsecondlife;
33using OpenSim.Framework;
34using OpenSim.Framework.Communications.Cache;
35using OpenSim.Framework.Console;
36using OpenSim.Framework.Servers;
37
38namespace OpenSim.Region.Capabilities
39{
40 /// <summary>
41 /// CapsHandlers is a cap handler container but also takes
42 /// care of adding and removing cap handlers to and from the
43 /// supplied BaseHttpServer.
44 /// </summary>
45 public class CapsHandlers
46 {
47 private Dictionary <string, IRequestHandler> m_capsHandlers = new Dictionary<string, IRequestHandler>();
48 private BaseHttpServer m_httpListener;
49 private string m_httpListenerHostName;
50 private uint m_httpListenerPort;
51
52 /// <summary></summary>
53 /// <param name="httpListener">base HTTP server</param>
54 /// <param name="httpListenerHostname">host name of the HTTP
55 /// server</param>
56 /// <param name="httpListenerPort">HTTP port</param>
57 public CapsHandlers(BaseHttpServer httpListener, string httpListenerHostname, uint httpListenerPort)
58 {
59 m_httpListener = httpListener;
60 m_httpListenerHostName = httpListenerHostname;
61 m_httpListenerPort = httpListenerPort;
62 }
63
64 /// <summary>
65 /// Remove the cap handler for a capability.
66 /// </summary>
67 /// <param name="capsName">name of the capability of the cap
68 /// handler to be removed</param>
69 public void Remove(string capsName)
70 {
71 m_capsHandlers.Remove(capsName);
72 }
73
74 public bool ContainsCap(string cap)
75 {
76 return m_capsHandlers.ContainsKey(cap);
77 }
78
79 /// <summary>
80 /// The indexer allows us to treat the CapsHandlers object
81 /// in an intuitive dictionary like way.
82 /// </summary>
83 /// <Remarks>
84 /// The indexer will throw an exception when you try to
85 /// retrieve a cap handler for a cap that is not contained in
86 /// CapsHandlers.
87 /// </Remarks>
88 public IRequestHandler this[string idx]
89 {
90 get
91 {
92 return m_capsHandlers[idx];
93 }
94
95 set
96 {
97 if (m_capsHandlers.ContainsKey(idx))
98 {
99 m_httpListener.RemoveStreamHandler("POST", m_capsHandlers[idx].Path);
100 m_capsHandlers.Remove(idx);
101 }
102
103 if (null == value) return;
104
105 m_capsHandlers[idx] = value;
106 m_httpListener.AddStreamHandler(value);
107 }
108 }
109
110 /// <summary>
111 /// Return the list of cap names for which this CapsHandlers
112 /// object contains cap handlers.
113 /// </summary>
114 public string[] Caps
115 {
116 get
117 {
118 string[] __keys = new string[m_capsHandlers.Keys.Count];
119 m_capsHandlers.Keys.CopyTo(__keys, 0);
120 return __keys;
121 }
122 }
123
124 /// <summary>
125 /// Return an LLSD-serializable Hashtable describing the
126 /// capabilities and their handler details.
127 /// </summary>
128 public Hashtable CapsDetails
129 {
130 get
131 {
132 Hashtable caps = new Hashtable();
133 string baseUrl = "http://" + m_httpListenerHostName + ":" + m_httpListenerPort.ToString();
134 foreach (string capsName in m_capsHandlers.Keys)
135 {
136 // skip SEED cap
137 if ("SEED" == capsName) continue;
138 caps[capsName] = baseUrl + m_capsHandlers[capsName].Path;
139 }
140 return caps;
141 }
142 }
143 }
144}