aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/BaseHttpServer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Servers/BaseHttpServer.cs')
-rw-r--r--OpenSim/Framework/Servers/BaseHttpServer.cs75
1 files changed, 72 insertions, 3 deletions
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs
index af2b27c..b36cc8a 100644
--- a/OpenSim/Framework/Servers/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/BaseHttpServer.cs
@@ -34,6 +34,7 @@ using System.Text;
34using System.Threading; 34using System.Threading;
35using System.Xml; 35using System.Xml;
36using Nwc.XmlRpc; 36using Nwc.XmlRpc;
37using libsecondlife.StructuredData;
37using OpenSim.Framework.Console; 38using OpenSim.Framework.Console;
38 39
39namespace OpenSim.Framework.Servers 40namespace OpenSim.Framework.Servers
@@ -43,6 +44,7 @@ namespace OpenSim.Framework.Servers
43 protected Thread m_workerThread; 44 protected Thread m_workerThread;
44 protected HttpListener m_httpListener; 45 protected HttpListener m_httpListener;
45 protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>(); 46 protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>();
47 protected LLSDMethod m_llsdHandler = null;
46 protected Dictionary<string, IRequestHandler> m_streamHandlers = new Dictionary<string, IRequestHandler>(); 48 protected Dictionary<string, IRequestHandler> m_streamHandlers = new Dictionary<string, IRequestHandler>();
47 protected uint m_port; 49 protected uint m_port;
48 protected bool m_ssl = false; 50 protected bool m_ssl = false;
@@ -90,6 +92,11 @@ namespace OpenSim.Framework.Servers
90 return false; 92 return false;
91 } 93 }
92 94
95 public bool SetLLSDHandler(LLSDMethod handler)
96 {
97 m_llsdHandler = handler;
98 return true;
99 }
93 100
94 public virtual void HandleRequest(Object stateinfo) 101 public virtual void HandleRequest(Object stateinfo)
95 { 102 {
@@ -136,7 +143,17 @@ namespace OpenSim.Framework.Servers
136 } 143 }
137 else 144 else
138 { 145 {
139 HandleXmlRpcRequests(request, response); 146 switch (request.ContentType)
147 {
148 //case "application/xml+llsd":
149 //HandleLLSDRequests(request, response);
150 //break;
151 case "text/xml":
152 case "application/xml":
153 default:
154 HandleXmlRpcRequests(request, response);
155 break;
156 }
140 } 157 }
141 } 158 }
142 159
@@ -242,7 +259,7 @@ namespace OpenSim.Framework.Servers
242 } 259 }
243 } 260 }
244 261
245 response.AddHeader("Content-type", "text/xml"); 262 response.ContentType = "text/xml";
246 263
247 byte[] buffer = Encoding.UTF8.GetBytes(responseString); 264 byte[] buffer = Encoding.UTF8.GetBytes(responseString);
248 265
@@ -263,6 +280,58 @@ namespace OpenSim.Framework.Servers
263 } 280 }
264 } 281 }
265 282
283 private void HandleLLSDRequests(HttpListenerRequest request, HttpListenerResponse response)
284 {
285 Stream requestStream = request.InputStream;
286
287 Encoding encoding = Encoding.UTF8;
288 StreamReader reader = new StreamReader(requestStream, encoding);
289
290 string requestBody = reader.ReadToEnd();
291 reader.Close();
292 requestStream.Close();
293
294 LLSD llsdRequest = null;
295 LLSD llsdResponse = null;
296
297 try { llsdRequest = LLSDParser.DeserializeXml(requestBody); }
298 catch (Exception ex) { MainLog.Instance.Warn("HTTPD", "Error - " + ex.Message); }
299
300 if (llsdRequest != null && m_llsdHandler != null)
301 {
302 llsdResponse = m_llsdHandler(llsdRequest);
303 }
304 else
305 {
306 LLSDMap map = new LLSDMap();
307 map["reason"] = LLSD.FromString("LLSDRequest");
308 map["message"] = LLSD.FromString("No handler registered for LLSD Requests");
309 map["login"] = LLSD.FromString("false");
310 llsdResponse = map;
311 }
312
313 response.ContentType = "application/xml+llsd";
314
315 byte[] buffer = LLSDParser.SerializeXmlBytes(llsdResponse);
316
317 response.SendChunked = false;
318 response.ContentLength64 = buffer.Length;
319 response.ContentEncoding = Encoding.UTF8;
320
321 try
322 {
323 response.OutputStream.Write(buffer, 0, buffer.Length);
324 }
325 catch (Exception ex)
326 {
327 MainLog.Instance.Warn("HTTPD", "Error - " + ex.Message);
328 }
329 finally
330 {
331 response.OutputStream.Close();
332 }
333 }
334
266 public void HandleHTTPRequest(Hashtable keysvals, HttpListenerRequest request, HttpListenerResponse response) 335 public void HandleHTTPRequest(Hashtable keysvals, HttpListenerRequest request, HttpListenerResponse response)
267 { 336 {
268 // This is a test. There's a workable alternative.. as this way sucks. 337 // This is a test. There's a workable alternative.. as this way sucks.
@@ -436,4 +505,4 @@ namespace OpenSim.Framework.Servers
436 m_streamHandlers.Remove(GetHandlerKey(httpMethod, path)); 505 m_streamHandlers.Remove(GetHandlerKey(httpMethod, path));
437 } 506 }
438 } 507 }
439} \ No newline at end of file 508}