aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Servers')
-rw-r--r--OpenSim/Framework/Servers/BaseHttpServer.cs55
-rw-r--r--OpenSim/Framework/Servers/Interfaces/IHttpServer.cs127
2 files changed, 130 insertions, 52 deletions
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs
index 1b34209..28fb9df 100644
--- a/OpenSim/Framework/Servers/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/BaseHttpServer.cs
@@ -41,10 +41,11 @@ using Nwc.XmlRpc;
41using OpenMetaverse.StructuredData; 41using OpenMetaverse.StructuredData;
42using CoolHTTPListener = HttpServer.HttpListener; 42using CoolHTTPListener = HttpServer.HttpListener;
43using HttpListener=System.Net.HttpListener; 43using HttpListener=System.Net.HttpListener;
44using OpenSim.Framework.Servers.Interfaces;
44 45
45namespace OpenSim.Framework.Servers 46namespace OpenSim.Framework.Servers
46{ 47{
47 public class BaseHttpServer 48 public class BaseHttpServer : IHttpServer
48 { 49 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50 private HttpServerLogWriter httpserverlog = new HttpServerLogWriter(); 51 private HttpServerLogWriter httpserverlog = new HttpServerLogWriter();
@@ -148,11 +149,6 @@ namespace OpenSim.Framework.Servers
148 return true; 149 return true;
149 } 150 }
150 151
151 /// <summary>
152 /// Gets the XML RPC handler for given method name
153 /// </summary>
154 /// <param name="method">Name of the method</param>
155 /// <returns>Returns null if not found</returns>
156 public XmlRpcMethod GetXmlRPCHandler(string method) 152 public XmlRpcMethod GetXmlRPCHandler(string method)
157 { 153 {
158 lock (m_rpcHandlers) 154 lock (m_rpcHandlers)
@@ -168,32 +164,6 @@ namespace OpenSim.Framework.Servers
168 } 164 }
169 } 165 }
170 166
171 /// <summary>
172 /// Add a handler for an HTTP request
173 /// </summary>
174 ///
175 /// This handler can actually be invoked either as
176 ///
177 /// http://<hostname>:<port>/?method=<methodName>
178 ///
179 /// or
180 ///
181 /// http://<hostname>:<port><method>
182 ///
183 /// if the method name starts with a slash. For example, AddHTTPHandler("/object/", ...) on a standalone region
184 /// server will register a handler that can be invoked with either
185 ///
186 /// http://localhost:9000/?method=/object/
187 ///
188 /// or
189 ///
190 /// http://localhost:9000/object/
191 ///
192 /// <param name="methodName"></param>
193 /// <param name="handler"></param>
194 /// <returns>
195 /// true if the handler was successfully registered, false if a handler with the same name already existed.
196 /// </returns>
197 public bool AddHTTPHandler(string methodName, GenericHTTPMethod handler) 167 public bool AddHTTPHandler(string methodName, GenericHTTPMethod handler)
198 { 168 {
199 //m_log.DebugFormat("[BASE HTTP SERVER]: Registering {0}", methodName); 169 //m_log.DebugFormat("[BASE HTTP SERVER]: Registering {0}", methodName);
@@ -229,12 +199,6 @@ namespace OpenSim.Framework.Servers
229 return false; 199 return false;
230 } 200 }
231 201
232 /// <summary>
233 /// Adds a LLSD handler, yay.
234 /// </summary>
235 /// <param name="path">/resource/ path</param>
236 /// <param name="handler">handle the LLSD response</param>
237 /// <returns></returns>
238 public bool AddLLSDHandler(string path, LLSDMethod handler) 202 public bool AddLLSDHandler(string path, LLSDMethod handler)
239 { 203 {
240 lock (m_llsdHandlers) 204 lock (m_llsdHandlers)
@@ -1313,7 +1277,6 @@ namespace OpenSim.Framework.Servers
1313 response.ContentLength64 = buffer.Length; 1277 response.ContentLength64 = buffer.Length;
1314 response.ContentEncoding = Encoding.UTF8; 1278 response.ContentEncoding = Encoding.UTF8;
1315 1279
1316
1317 try 1280 try
1318 { 1281 {
1319 response.OutputStream.Write(buffer, 0, buffer.Length); 1282 response.OutputStream.Write(buffer, 0, buffer.Length);
@@ -1334,8 +1297,7 @@ namespace OpenSim.Framework.Servers
1334 // This has to be here to prevent a Linux/Mono crash 1297 // This has to be here to prevent a Linux/Mono crash
1335 m_log.WarnFormat("[BASE HTTP SERVER] XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e); 1298 m_log.WarnFormat("[BASE HTTP SERVER] XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
1336 } 1299 }
1337 } 1300 }
1338
1339 } 1301 }
1340 1302
1341 public void SendHTML404(OSHttpResponse response, string host) 1303 public void SendHTML404(OSHttpResponse response, string host)
@@ -1513,11 +1475,6 @@ namespace OpenSim.Framework.Servers
1513 lock (m_streamHandlers) m_streamHandlers.Remove(handlerKey); 1475 lock (m_streamHandlers) m_streamHandlers.Remove(handlerKey);
1514 } 1476 }
1515 1477
1516 /// <summary>
1517 /// Remove an HTTP handler
1518 /// </summary>
1519 /// <param name="httpMethod"></param>
1520 /// <param name="path"></param>
1521 public void RemoveHTTPHandler(string httpMethod, string path) 1478 public void RemoveHTTPHandler(string httpMethod, string path)
1522 { 1479 {
1523 lock (m_HTTPHandlers) 1480 lock (m_HTTPHandlers)
@@ -1532,12 +1489,6 @@ namespace OpenSim.Framework.Servers
1532 } 1489 }
1533 } 1490 }
1534 1491
1535 /// <summary>
1536 /// Remove the agent IF it is registered. Intercept the possible exception.
1537 /// </summary>
1538 /// <param name="agent"></param>
1539 /// <param name="handler"></param>
1540 /// <returns></returns>
1541 public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler) 1492 public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler)
1542 { 1493 {
1543 try 1494 try
diff --git a/OpenSim/Framework/Servers/Interfaces/IHttpServer.cs b/OpenSim/Framework/Servers/Interfaces/IHttpServer.cs
new file mode 100644
index 0000000..ea2c8f1
--- /dev/null
+++ b/OpenSim/Framework/Servers/Interfaces/IHttpServer.cs
@@ -0,0 +1,127 @@
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 Nwc.XmlRpc;
29using OpenSim.Framework.Servers;
30
31namespace OpenSim.Framework.Servers.Interfaces
32{
33 /// <summary>
34 /// Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.)
35 /// for given URLs.
36 /// </summary>
37 public interface IHttpServer
38 {
39 uint SSLPort { get; }
40 string SSLCommonName { get; }
41
42 uint Port { get; }
43 bool UseSSL { get; }
44
45 // Note that the agent string is provided simply to differentiate
46 // the handlers - it is NOT required to be an actual agent header
47 // value.
48 bool AddAgentHandler(string agent, IHttpAgentHandler handler);
49
50 /// <summary>
51 /// Add a handler for an HTTP request
52 /// </summary>
53 ///
54 /// This handler can actually be invoked either as
55 ///
56 /// http://<hostname>:<port>/?method=<methodName>
57 ///
58 /// or
59 ///
60 /// http://<hostname>:<port><method>
61 ///
62 /// if the method name starts with a slash. For example, AddHTTPHandler("/object/", ...) on a standalone region
63 /// server will register a handler that can be invoked with either
64 ///
65 /// http://localhost:9000/?method=/object/
66 ///
67 /// or
68 ///
69 /// http://localhost:9000/object/
70 ///
71 /// <param name="methodName"></param>
72 /// <param name="handler"></param>
73 /// <returns>
74 /// true if the handler was successfully registered, false if a handler with the same name already existed.
75 /// </returns>
76 bool AddHTTPHandler(string methodName, GenericHTTPMethod handler);
77
78 /// <summary>
79 /// Adds a LLSD handler, yay.
80 /// </summary>
81 /// <param name="path">/resource/ path</param>
82 /// <param name="handler">handle the LLSD response</param>
83 /// <returns></returns>
84 bool AddLLSDHandler(string path, LLSDMethod handler);
85
86 /// <summary>
87 /// Add a stream handler to the http server. If the handler already exists, then nothing happens.
88 /// </summary>
89 /// <param name="handler"></param>
90 void AddStreamHandler(IRequestHandler handler);
91
92 bool AddXmlRPCHandler(string method, XmlRpcMethod handler);
93 bool AddXmlRPCHandler(string method, XmlRpcMethod handler, bool keepAlive);
94
95 /// <summary>
96 /// Gets the XML RPC handler for given method name
97 /// </summary>
98 /// <param name="method">Name of the method</param>
99 /// <returns>Returns null if not found</returns>
100 XmlRpcMethod GetXmlRPCHandler(string method);
101
102 bool SetDefaultLLSDHandler(DefaultLLSDMethod handler);
103
104 /// <summary>
105 /// Remove the agent if it is registered.
106 /// </summary>
107 /// <param name="agent"></param>
108 /// <param name="handler"></param>
109 /// <returns></returns>
110 bool RemoveAgentHandler(string agent, IHttpAgentHandler handler);
111
112 /// <summary>
113 /// Remove an HTTP handler
114 /// </summary>
115 /// <param name="httpMethod"></param>
116 /// <param name="path"></param>
117 void RemoveHTTPHandler(string httpMethod, string path);
118
119 bool RemoveLLSDHandler(string path, LLSDMethod handler);
120
121 void RemoveStreamHandler(string httpMethod, string path);
122
123 string GetHTTP404(string host);
124
125 string GetHTTP500();
126 }
127} \ No newline at end of file