From db3edff5d5f1c9a31f377db77d1ac4e1fa685623 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Sat, 5 Jan 2008 06:05:25 +0000 Subject: * Applying jhurliman's LLSD login enablement patch. * I'm keeping it deactivated until some issues are resolved. * I'm patching it in deactivated so the patch doesn't get outdated * I've deactivated it by commenting out the handler for the application/xml+llsd content type. * While I've tested this as much as possible on my setup and found the deactivated code doesn't cause any problems, consider this update experimental (event though it's deactivated) --- OpenSim/Framework/Servers/BaseHttpServer.cs | 75 +++++++++++++++++++++++++++-- OpenSim/Framework/Servers/LLSDMethod.cs | 33 +++++++++++++ 2 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 OpenSim/Framework/Servers/LLSDMethod.cs (limited to 'OpenSim/Framework/Servers') 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; using System.Threading; using System.Xml; using Nwc.XmlRpc; +using libsecondlife.StructuredData; using OpenSim.Framework.Console; namespace OpenSim.Framework.Servers @@ -43,6 +44,7 @@ namespace OpenSim.Framework.Servers protected Thread m_workerThread; protected HttpListener m_httpListener; protected Dictionary m_rpcHandlers = new Dictionary(); + protected LLSDMethod m_llsdHandler = null; protected Dictionary m_streamHandlers = new Dictionary(); protected uint m_port; protected bool m_ssl = false; @@ -90,6 +92,11 @@ namespace OpenSim.Framework.Servers return false; } + public bool SetLLSDHandler(LLSDMethod handler) + { + m_llsdHandler = handler; + return true; + } public virtual void HandleRequest(Object stateinfo) { @@ -136,7 +143,17 @@ namespace OpenSim.Framework.Servers } else { - HandleXmlRpcRequests(request, response); + switch (request.ContentType) + { + //case "application/xml+llsd": + //HandleLLSDRequests(request, response); + //break; + case "text/xml": + case "application/xml": + default: + HandleXmlRpcRequests(request, response); + break; + } } } @@ -242,7 +259,7 @@ namespace OpenSim.Framework.Servers } } - response.AddHeader("Content-type", "text/xml"); + response.ContentType = "text/xml"; byte[] buffer = Encoding.UTF8.GetBytes(responseString); @@ -263,6 +280,58 @@ namespace OpenSim.Framework.Servers } } + private void HandleLLSDRequests(HttpListenerRequest request, HttpListenerResponse response) + { + Stream requestStream = request.InputStream; + + Encoding encoding = Encoding.UTF8; + StreamReader reader = new StreamReader(requestStream, encoding); + + string requestBody = reader.ReadToEnd(); + reader.Close(); + requestStream.Close(); + + LLSD llsdRequest = null; + LLSD llsdResponse = null; + + try { llsdRequest = LLSDParser.DeserializeXml(requestBody); } + catch (Exception ex) { MainLog.Instance.Warn("HTTPD", "Error - " + ex.Message); } + + if (llsdRequest != null && m_llsdHandler != null) + { + llsdResponse = m_llsdHandler(llsdRequest); + } + else + { + LLSDMap map = new LLSDMap(); + map["reason"] = LLSD.FromString("LLSDRequest"); + map["message"] = LLSD.FromString("No handler registered for LLSD Requests"); + map["login"] = LLSD.FromString("false"); + llsdResponse = map; + } + + response.ContentType = "application/xml+llsd"; + + byte[] buffer = LLSDParser.SerializeXmlBytes(llsdResponse); + + response.SendChunked = false; + response.ContentLength64 = buffer.Length; + response.ContentEncoding = Encoding.UTF8; + + try + { + response.OutputStream.Write(buffer, 0, buffer.Length); + } + catch (Exception ex) + { + MainLog.Instance.Warn("HTTPD", "Error - " + ex.Message); + } + finally + { + response.OutputStream.Close(); + } + } + public void HandleHTTPRequest(Hashtable keysvals, HttpListenerRequest request, HttpListenerResponse response) { // This is a test. There's a workable alternative.. as this way sucks. @@ -436,4 +505,4 @@ namespace OpenSim.Framework.Servers m_streamHandlers.Remove(GetHandlerKey(httpMethod, path)); } } -} \ No newline at end of file +} diff --git a/OpenSim/Framework/Servers/LLSDMethod.cs b/OpenSim/Framework/Servers/LLSDMethod.cs new file mode 100644 index 0000000..5cd225b --- /dev/null +++ b/OpenSim/Framework/Servers/LLSDMethod.cs @@ -0,0 +1,33 @@ +/* +* Copyright (c) Contributors, http://opensimulator.org/ +* See CONTRIBUTORS.TXT for a full list of copyright holders. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the OpenSim Project nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ +using libsecondlife.StructuredData; + +namespace OpenSim.Framework.Servers +{ + public delegate LLSD LLSDMethod(LLSD request); +} -- cgit v1.1