From a8faed6f76e5bb7936c1bc2b4711b5eeb143173d Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 5 May 2013 22:01:07 +0200 Subject: [PATCH] Implement llSetContentType using the new OpenID auth support for authentication --- .../Scripting/LSLHttp/UrlModule.cs | 51 ++++++++++++++++++- .../Shared/Api/Implementation/LSL_Api.cs | 12 +++++ .../Shared/Api/Interface/ILSL_Api.cs | 1 + .../Shared/Api/Runtime/LSL_Constants.cs | 3 ++ .../Shared/Api/Runtime/LSL_Stub.cs | 5 ++ 5 files changed, 71 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs index f2922d6792..2a4d4404e6 100644 --- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs @@ -51,6 +51,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp public UUID urlcode; public Dictionary requests; public bool isSsl; + public Scene scene; } public class RequestData @@ -66,6 +67,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp public int startTime; public bool responseSent; public string uri; + public bool allowResponseType = false; + public UUID hostID; + public Scene scene; } /// @@ -171,6 +175,17 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp public void RemoveRegion(Scene scene) { + // Drop references to that scene + foreach (KeyValuePair kvp in m_UrlMap) + { + if (kvp.Value.scene == scene) + kvp.Value.scene = null; + } + foreach (KeyValuePair kvp in m_RequestMap) + { + if (kvp.Value.scene == scene) + kvp.Value.scene = null; + } } public void Close() @@ -198,6 +213,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp urlData.urlcode = urlcode; urlData.isSsl = false; urlData.requests = new Dictionary(); + urlData.scene = host.ParentGroup.Scene; m_UrlMap[url] = urlData; @@ -316,6 +332,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp if (!urlData.requests[request].responseSent) { string responseBody = body; + + // If we have no OpenID from built-in browser, disable this + if (!urlData.requests[request].allowResponseType) + urlData.requests[request].responseType = "text/plain"; + if (urlData.requests[request].responseType.Equals("text/plain")) { string value; @@ -532,7 +553,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp //put response response["int_response_code"] = requestData.responseCode; response["str_response_string"] = requestData.responseBody; - response["content_type"] = "text/plain"; + response["content_type"] = requestData.responseType; response["keepalive"] = false; response["reusecontext"] = false; @@ -600,6 +621,8 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp requestData.requestDone = false; requestData.startTime = System.Environment.TickCount; requestData.uri = uri; + requestData.hostID = url.hostID; + requestData.scene = url.scene; if (requestData.headers == null) requestData.headers = new Dictionary(); @@ -608,6 +631,32 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp string key = (string)header.Key; string value = (string)header.Value; requestData.headers.Add(key, value); + if (key == "cookie") + { + string[] parts = value.Split(new char[] {'='}); + if (parts[0] == "agni_sl_session_id" && parts.Length > 1) + { + string cookie = Uri.UnescapeDataString(parts[1]); + string[] crumbs = cookie.Split(new char[] {':'}); + UUID owner; + if (crumbs.Length == 2 && UUID.TryParse(crumbs[0], out owner)) + { + if (crumbs[1].Length == 32) + { + Scene scene = requestData.scene; + if (scene != null) + { + SceneObjectPart host = scene.GetSceneObjectPart(requestData.hostID); + if (host != null) + { + if (host.OwnerID == owner) + requestData.allowResponseType = true; + } + } + } + } + } + } } foreach (DictionaryEntry de in request) { diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index bb89ac1190..6bcb361d17 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -13386,6 +13386,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return null; } + + public void llSetContentType(LSL_Key id, LSL_Integer content_type) + { + if (m_UrlModule != null) + { + string type = "text.plain"; + if (content_type == (int)ScriptBaseClass.CONTENT_TYPE_HTML) + type = "text/html"; + + m_UrlModule.HttpContentType(new UUID(id),type); + } + } } public class NotecardCache diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs index bc8d3210cc..daf89e575d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs @@ -434,5 +434,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces void llSetKeyframedMotion(LSL_List frames, LSL_List options); LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules); LSL_List llGetPhysicsMaterial(); + void llSetContentType(LSL_Key id, LSL_Integer content_type); } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index 2f8154da56..c664a84428 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs @@ -771,5 +771,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase /// process message parameter as regex /// public const int OS_LISTEN_REGEX_MESSAGE = 0x2; + + public const int CONTENT_TYPE_TEXT = 0; + public const int CONTENT_TYPE_HTML = 1; } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs index b6bb5d8217..6f3677c4be 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs @@ -2014,5 +2014,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase { return m_LSL_Functions.llGetPhysicsMaterial(); } + + public void llSetContentType(LSL_Key id, LSL_Integer content_type) + { + m_LSL_Functions.llSetContentType(id, content_type); + } } }