From 85b280385fd7400da8bc721131d25eee9fd7f8da Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Sat, 27 Sep 2008 09:42:31 +0000 Subject: [PATCH] * This is the very very early beginnings of an EventQueue:get module. * This won't function yet as far as the client can tell.. because it doesn't respond to the first query with a 200 message. * We have to figure out how to encode those binary values in the example code in the module... * Committing this so we have a start point. Will continue to work on this more today. --- OpenSim/Framework/Servers/BaseHTTPHandler.cs | 42 +++++ OpenSim/Framework/Servers/BaseHttpServer.cs | 61 ++++++- OpenSim/Framework/Servers/RestHTTPHandler.cs | 57 ++++++ .../Modules/Framework/EventQueueGetModule.cs | 164 ++++++++++++++++++ OpenSim/Region/Interfaces/IEventQueue.cs | 40 +++++ 5 files changed, 359 insertions(+), 5 deletions(-) create mode 100644 OpenSim/Framework/Servers/BaseHTTPHandler.cs create mode 100644 OpenSim/Framework/Servers/RestHTTPHandler.cs create mode 100644 OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs create mode 100644 OpenSim/Region/Interfaces/IEventQueue.cs diff --git a/OpenSim/Framework/Servers/BaseHTTPHandler.cs b/OpenSim/Framework/Servers/BaseHTTPHandler.cs new file mode 100644 index 0000000000..a7c3562f2e --- /dev/null +++ b/OpenSim/Framework/Servers/BaseHTTPHandler.cs @@ -0,0 +1,42 @@ +/* + * 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 System; +using System.Collections; + +namespace OpenSim.Framework.Servers +{ + public abstract class BaseHTTPHandler : BaseRequestHandler, IGenericHTTPHandler + { + public abstract Hashtable Handle(string path, Hashtable Request); + + protected BaseHTTPHandler(string httpMethod, string path) + : base(httpMethod, path) + { + } + } +} \ No newline at end of file diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs index ae07895dc7..24bba2bc9f 100644 --- a/OpenSim/Framework/Servers/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/BaseHttpServer.cs @@ -361,9 +361,57 @@ namespace OpenSim.Framework.Servers buffer = streamedRequestHandler.Handle(path, request.InputStream, request, response); } + else if (requestHandler is IGenericHTTPHandler) + { + IGenericHTTPHandler HTTPRequestHandler = requestHandler as IGenericHTTPHandler; + Stream requestStream = request.InputStream; + + Encoding encoding = Encoding.UTF8; + StreamReader reader = new StreamReader(requestStream, encoding); + + string requestBody = reader.ReadToEnd(); + + + reader.Close(); + requestStream.Close(); + + Hashtable keysvals = new Hashtable(); + Hashtable headervals = new Hashtable(); + string host = String.Empty; + + string[] querystringkeys = request.QueryString.AllKeys; + string[] rHeaders = request.Headers.AllKeys; + + + foreach (string queryname in querystringkeys) + { + keysvals.Add(queryname, request.QueryString[queryname]); + } + + foreach (string headername in rHeaders) + { + //m_log.Warn("[HEADER]: " + headername + "=" + request.Headers[headername]); + headervals[headername] = request.Headers[headername]; + } + + if (headervals.Contains("Host")) + { + host = (string)headervals["Host"]; + } + keysvals.Add("requestbody",requestBody); + if (keysvals.Contains("method")) + { + //m_log.Warn("[HTTP]: Contains Method"); + string method = (string)keysvals["method"]; + //m_log.Warn("[HTTP]: " + requestBody); + + } + DoHTTPGruntWork(HTTPRequestHandler.Handle(path,keysvals), response); + return; + } else { - IStreamHandler streamHandler = (IStreamHandler) requestHandler; + IStreamHandler streamHandler = (IStreamHandler)requestHandler; using (MemoryStream memoryStream = new MemoryStream()) { @@ -943,6 +991,9 @@ namespace OpenSim.Framework.Servers string responseString = (string)responsedata["str_response_string"]; string contentType = (string)responsedata["content_type"]; + if (responsedata.ContainsKey("keepalive")) + response.KeepAlive = true; + //Even though only one other part of the entire code uses HTTPHandlers, we shouldn't expect this //and should check for NullReferenceExceptions @@ -951,10 +1002,9 @@ namespace OpenSim.Framework.Servers contentType = "text/html"; } - // We're forgoing the usual error status codes here because the client - // ignores anything but 200 and 301 - - response.StatusCode = (int)OSHttpStatusCode.SuccessOk; + // The client ignores anything but 200 here for web login, so ensure that this is 200 for that + + response.StatusCode = responsecode; if (responsecode == (int)OSHttpStatusCode.RedirectMovedPermanently) { @@ -978,6 +1028,7 @@ namespace OpenSim.Framework.Servers response.SendChunked = false; response.ContentLength64 = buffer.Length; response.ContentEncoding = Encoding.UTF8; + try { diff --git a/OpenSim/Framework/Servers/RestHTTPHandler.cs b/OpenSim/Framework/Servers/RestHTTPHandler.cs new file mode 100644 index 0000000000..2974c56ad8 --- /dev/null +++ b/OpenSim/Framework/Servers/RestHTTPHandler.cs @@ -0,0 +1,57 @@ +/* + * 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 System; +using System.Collections; + +namespace OpenSim.Framework.Servers +{ + public class RestHTTPHandler : BaseHTTPHandler + { + private GenericHTTPMethod m_dhttpMethod; + + public GenericHTTPMethod Method + { + get { return m_dhttpMethod; } + } + + public override Hashtable Handle(string path, Hashtable request) + { + + string param = GetParam(path); + request.Add("param", param); + request.Add("path", path); + return m_dhttpMethod(request); + } + + public RestHTTPHandler(string httpMethod, string path, GenericHTTPMethod dhttpMethod) + : base(httpMethod, path) + { + m_dhttpMethod = dhttpMethod; + } + } +} diff --git a/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs b/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs new file mode 100644 index 0000000000..ea6c6632f2 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs @@ -0,0 +1,164 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using System.Reflection; +using System.Xml; +using OpenMetaverse; +using OpenMetaverse.StructuredData; +using log4net; +using Nini.Config; +using Nwc.XmlRpc; +using OpenSim.Framework; +using OpenSim.Framework.Communications.Cache; +using OpenSim.Framework.Communications.Capabilities; +using OpenSim.Framework.Servers; +using OpenSim.Region.Environment.Interfaces; +using OpenSim.Region.Interfaces; +using OpenSim.Region.Environment.Scenes; + +using LLSD = OpenMetaverse.StructuredData.LLSD; +using LLSDMap = OpenMetaverse.StructuredData.LLSDMap; +using LLSDArray = OpenMetaverse.StructuredData.LLSDArray; +using Caps = OpenSim.Framework.Communications.Capabilities.Caps; + +namespace OpenSim.Region.Environment.Modules.Framework +{ + public class EventQueueGetModule : IEventQueue, IRegionModule + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + Scene m_scene = null; + IConfigSource m_gConfig; + + #region IRegionModule methods + public void Initialise(Scene scene, IConfigSource config) + { + m_gConfig = config; + m_scene = scene; + + + IConfig startupConfig = m_gConfig.Configs["Startup"]; + + ReadConfigAndPopulate(scene, startupConfig, "Startup"); + + scene.RegisterModuleInterface(this); + + scene.EventManager.OnNewClient += OnNewClient; + scene.EventManager.OnClientClosed += ClientClosed; + scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; + scene.EventManager.OnMakeChildAgent += MakeChildAgent; + scene.EventManager.OnClientClosed += ClientLoggedOut; + scene.EventManager.OnRegisterCaps += OnRegisterCaps; + + } + + private void ReadConfigAndPopulate(Scene scene, IConfig startupConfig, string p) + { + + } + + + + + + public void PostInitialise() + { + } + + public void Close() + { + } + + public string Name + { + get { return "EventQueueGetModule"; } + } + + public bool IsSharedModule + { + get { return false; } + } + #endregion + + #region IEventQueue Members + public bool Enqueue(object o, UUID avatarID) + { + + return false; + } + #endregion + + private void OnNewClient(IClientAPI client) + { + + client.OnLogout += ClientClosed; + } + + + public void ClientClosed(IClientAPI client) + { + ClientClosed(client.AgentId); + } + + private void ClientLoggedOut(UUID AgentId) + { + + } + + private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID) + { + + } + + public void ClientClosed(UUID AgentID) + { + + } + private void MakeChildAgent(ScenePresence avatar) + { + } + public void OnRegisterCaps(UUID agentID, Caps caps) + { + m_log.DebugFormat("[EVENTQUEUE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps); + string capsBase = "/CAPS/"; + caps.RegisterHandler("EventQueueGet", + new RestHTTPHandler("POST", capsBase + UUID.Random().ToString(), + delegate(Hashtable m_dhttpMethod) + { + return ProcessQueue(m_dhttpMethod,agentID, caps); + })); + } + public Hashtable ProcessQueue(Hashtable request,UUID agentID, Caps caps) + { + + Hashtable responsedata = new Hashtable(); + responsedata["int_response_code"] = 502; + responsedata["str_response_string"] = "Upstream error:"; + responsedata["content_type"] = "text/plain"; + responsedata["keepalive"] = true; + + /* + responsedata["int_response_code"] = 200; + responsedata["content_type"] = "application/xml"; + responsedata["keepalive"] = true; + + responsedata["str_response_string"] = @"eventsbodyAgentDataAgentID + 0fd0e798-a54f-40b1-0000-000000000000SessionIDcc91f1fe-9d52-435d-0000-000000000000 + InfoLookAt0.9869639873504638671875 + -0.16094399988651275634765620Position1.43747997283935546875 + 95.3056030273437557.3480987548828125RegionData + RegionHandleAAPnAAAD8AA=SeedCapability + https://sim7.aditi.lindenlab.com:12043/cap/64015fb3-6fee-9205-0000-000000000000SimIPyA8FSA==SimPort13005message + CrossedRegionid1"; + + */ + //string requestbody = (string)request["requestbody"]; + //LLSD llsdRequest = LLSDParser.DeserializeXml(request); + //System.Console.WriteLine(requestbody); + return responsedata; + + } + } +} diff --git a/OpenSim/Region/Interfaces/IEventQueue.cs b/OpenSim/Region/Interfaces/IEventQueue.cs new file mode 100644 index 0000000000..a11eebe36c --- /dev/null +++ b/OpenSim/Region/Interfaces/IEventQueue.cs @@ -0,0 +1,40 @@ +/* + * 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 System; +using OpenSim.Framework; +using OpenMetaverse; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Region.Interfaces +{ + public interface IEventQueue + { + bool Enqueue(object o, UUID avatarID); + } +}