From 7625438adeb2211ee9c3f6532819eea2a0673c5d Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Wed, 12 Dec 2007 22:14:43 +0000 Subject: From Michael Osias (IBM) This patch implements the llHttpRequest function via a region module, HttpScriptsRequest. There were bits and peices in LSLLong_cmd_handler, which I moved into the region module, and just check for completed requests and dispatch the http_response callback event instead. works for me as of r2674 --- .../DotNetEngine/Compiler/LSL/LSL_BaseClass.cs | 4 +- .../Compiler/Server_API/LSL_BuiltIn_Commands.cs | 13 +- .../ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs | 160 ++++++--------------- 3 files changed, 59 insertions(+), 118 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine') diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs index deabec3..99f8d3b 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs @@ -1759,9 +1759,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL return m_LSL_Functions.llXorBase64StringsCorrect(str1, str2); } - public void llHTTPRequest(string url, List parameters, string body) + public string llHTTPRequest(string url, List parameters, string body) { - m_LSL_Functions.llHTTPRequest(url, parameters, body); + return m_LSL_Functions.llHTTPRequest(url, parameters, body); } public void llResetLandBanList() diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs index 94479a0..aaac294 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs @@ -2451,9 +2451,18 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler return llStringToBase64(ret); } - public void llHTTPRequest(string url, List parameters, string body) + public string llHTTPRequest(string url, List parameters, string body) { - m_ScriptEngine.m_LSLLongCmdHandler.StartHttpRequest(m_localID, m_itemID, url, parameters, body); + IHttpRequests httpScriptMod = + m_ScriptEngine.World.RequestModuleInterface(); + + LLUUID reqID = httpScriptMod. + StartHttpRequest(m_localID, m_itemID, url, parameters, body); + + if( reqID != null ) + return reqID.ToString(); + else + return null; } public void llResetLandBanList() diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs index 5061629..ddc0c62 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/LSLLongCmdHandler.cs @@ -110,7 +110,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine // Remove from: Timers UnSetTimerEvents(localID, itemID); // Remove from: HttpRequest - StopHttpRequest(localID, itemID); + IHttpRequests iHttpReq = + m_ScriptEngine.World.RequestModuleInterface(); + iHttpReq.StopHttpRequest(localID, itemID); } #region TIMER @@ -198,136 +200,67 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine #region HTTP REQUEST - // - // HTTP REAQUEST - // - private class HttpClass + public void CheckHttpRequests() { - public uint localID; - public LLUUID itemID; - public string url; - public List parameters; - public string body; - public DateTime next; + IHttpRequests iHttpReq = + m_ScriptEngine.World.RequestModuleInterface(); - public string response_request_id; - public int response_status; - public List response_metadata; - public string response_body; + HttpRequestClass httpInfo = null; - public void SendRequest() - { - // TODO: SEND REQUEST!!! - } - - public void Stop() - { - // TODO: Cancel any ongoing request - } + if( iHttpReq != null ) + httpInfo = iHttpReq.GetNextCompletedRequest(); - public bool CheckResponse() + while ( httpInfo != null ) { - // TODO: Check if we got a response yet, return true if so -- false if not - return true; - - // TODO: If we got a response, set the following then return true - //response_request_id - //response_status - //response_metadata - //response_body - } - } + + Console.WriteLine("PICKED HTTP REQ:" + httpInfo.response_body + httpInfo.status); + + // Deliver data to prim's remote_data handler + // + // TODO: Returning null for metadata, since the lsl function + // only returns the byte for HTTP_BODY_TRUNCATED, which is not + // implemented here yet anyway. Should be fixed if/when maxsize + // is supported + + object[] resobj = new object[] + { + httpInfo.reqID.ToString(), httpInfo.status, null, httpInfo.response_body + }; - private List HttpRequests = new List(); - private object HttpListLock = new object(); + m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( + httpInfo.localID, httpInfo.itemID, "http_response", resobj + ); - public void StartHttpRequest(uint localID, LLUUID itemID, string url, List parameters, string body) - { - Console.WriteLine("StartHttpRequest"); - - HttpClass htc = new HttpClass(); - htc.localID = localID; - htc.itemID = itemID; - htc.url = url; - htc.parameters = parameters; - htc.body = body; - lock (HttpListLock) - { - //ADD REQUEST - HttpRequests.Add(htc); - } - } + httpInfo.Stop(); + httpInfo = null; - public void StopHttpRequest(uint m_localID, LLUUID m_itemID) - { - // Remove from list - lock (HttpListLock) - { - List NewHttpList = new List(); - foreach (HttpClass ts in HttpRequests) - { - if (ts.localID != m_localID && ts.itemID != m_itemID) - { - // Keeping this one - NewHttpList.Add(ts); - } - else - { - // Shutting this one down - ts.Stop(); - } - } - HttpRequests.Clear(); - HttpRequests = NewHttpList; + httpInfo = iHttpReq.GetNextCompletedRequest(); } } - public void CheckHttpRequests() - { - // Nothing to do here? - if (HttpRequests.Count == 0) - return; - - lock (HttpListLock) - { - foreach (HttpClass ts in HttpRequests) - { - if (ts.CheckResponse() == true) - { - // Add it to event queue - //key request_id, integer status, list metadata, string body - object[] resobj = - new object[] - {ts.response_request_id, ts.response_status, ts.response_metadata, ts.response_body}; - m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "http_response", - resobj); - // Now stop it - StopHttpRequest(ts.localID, ts.itemID); - } - } - } // lock - } - #endregion public void CheckXMLRPCRequests() { IXMLRPC xmlrpc = m_ScriptEngine.World.RequestModuleInterface(); - while (xmlrpc.hasRequests()) + if (xmlrpc != null) { - RPCRequestInfo rInfo = xmlrpc.GetNextRequest(); - Console.WriteLine("PICKED REQUEST"); - - //Deliver data to prim's remote_data handler - object[] resobj = new object[] - { - 2, rInfo.GetChannelKey().ToString(), rInfo.GetMessageID().ToString(), "", rInfo.GetIntValue(), - rInfo.GetStrVal() - }; - m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( - rInfo.GetLocalID(), rInfo.GetItemID(), "remote_data", resobj - ); + while (xmlrpc.hasRequests()) + { + RPCRequestInfo rInfo = xmlrpc.GetNextRequest(); + Console.WriteLine("PICKED REQUEST"); + + //Deliver data to prim's remote_data handler + object[] resobj = new object[] + { + 2, rInfo.GetChannelKey().ToString(), rInfo.GetMessageID().ToString(), "", rInfo.GetIntValue(), + rInfo.GetStrVal() + }; + m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( + rInfo.GetLocalID(), rInfo.GetItemID(), "remote_data", resobj + ); + } } } @@ -338,7 +271,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine while (comms.HasMessages()) { ListenerInfo lInfo = comms.GetNextMessage(); - Console.WriteLine("PICKED LISTENER"); //Deliver data to prim's listen handler object[] resobj = new object[] -- cgit v1.1