From b8a7c8b26f3005eed5b161c37509b06b1d604967 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 26 Feb 2013 23:36:36 +0000
Subject: Add regression test for llRequestUrl()
---
.../CoreModules/Scripting/LSLHttp/UrlModule.cs | 37 ++++++++------
.../Region/Framework/Interfaces/IScriptModule.cs | 11 +++++
.../Shared/Api/Implementation/LSL_Api.cs | 1 +
OpenSim/Tests/Common/Mock/MockScriptEngine.cs | 57 +++++++++++++++++++---
prebuild.xml | 2 +
5 files changed, 86 insertions(+), 22 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
index be617a5..79e633f 100644
--- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
@@ -122,15 +122,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
///
private int m_TotalUrls = 100;
- private uint https_port = 0;
+ private uint m_HttpsPort = 0;
private IHttpServer m_HttpServer = null;
private IHttpServer m_HttpsServer = null;
- private string m_ExternalHostNameForLSL = "";
- public string ExternalHostNameForLSL
- {
- get { return m_ExternalHostNameForLSL; }
- }
+ public string ExternalHostNameForLSL { get; private set; }
public Type ReplaceableInterface
{
@@ -144,11 +140,20 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
public void Initialise(IConfigSource config)
{
- m_ExternalHostNameForLSL = config.Configs["Network"].GetString("ExternalHostNameForLSL", System.Environment.MachineName);
- bool ssl_enabled = config.Configs["Network"].GetBoolean("https_listener",false);
+ IConfig networkConfig = config.Configs["Network"];
+
+ if (networkConfig != null)
+ {
+ ExternalHostNameForLSL = config.Configs["Network"].GetString("ExternalHostNameForLSL", null);
+
+ bool ssl_enabled = config.Configs["Network"].GetBoolean("https_listener", false);
+
+ if (ssl_enabled)
+ m_HttpsPort = (uint)config.Configs["Network"].GetInt("https_port", (int)m_HttpsPort);
+ }
- if (ssl_enabled)
- https_port = (uint) config.Configs["Network"].GetInt("https_port",0);
+ if (ExternalHostNameForLSL == null)
+ ExternalHostNameForLSL = System.Environment.MachineName;
IConfig llFunctionsConfig = config.Configs["LL-Functions"];
@@ -169,9 +174,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
m_HttpServer = MainServer.Instance;
//
// We can use the https if it is enabled
- if (https_port > 0)
+ if (m_HttpsPort > 0)
{
- m_HttpsServer = MainServer.GetHttpServer(https_port);
+ m_HttpsServer = MainServer.GetHttpServer(m_HttpsPort);
}
}
@@ -209,7 +214,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
return urlcode;
}
- string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/";
+ string url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/";
UrlData urlData = new UrlData();
urlData.hostID = host.UUID;
@@ -254,7 +259,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
return urlcode;
}
- string url = "https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/";
+ string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/";
UrlData urlData = new UrlData();
urlData.hostID = host.UUID;
@@ -579,9 +584,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
string url;
if (is_ssl)
- url = "https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp;
+ url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp;
else
- url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp;
+ url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp;
// Avoid a race - the request URL may have been released via llRequestUrl() whilst this
// request was being processed.
diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs
index 143af48..ced4e91 100644
--- a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs
@@ -52,7 +52,18 @@ namespace OpenSim.Region.Framework.Interfaces
string GetXMLState(UUID itemID);
bool SetXMLState(UUID itemID, string xml);
+ ///
+ /// Post a script event to a single script.
+ ///
+ /// true if the post suceeded, false if it did not
+ /// The item ID of the script.
+ /// The name of the event.
+ ///
+ /// The arguments of the event. These are in the order in which they appear.
+ /// e.g. for http_request this will be an object array of key request_id, string method, string body
+ ///
bool PostScriptEvent(UUID itemID, string name, Object[] args);
+
bool PostObjectEvent(UUID itemID, string name, Object[] args);
///
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 96f650e..6a31568 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -9423,6 +9423,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return UUID.Zero.ToString();
}
}
+
public LSL_String llRequestURL()
{
m_host.AddScriptLPS(1);
diff --git a/OpenSim/Tests/Common/Mock/MockScriptEngine.cs b/OpenSim/Tests/Common/Mock/MockScriptEngine.cs
index 78bab5b..6a53fe7 100644
--- a/OpenSim/Tests/Common/Mock/MockScriptEngine.cs
+++ b/OpenSim/Tests/Common/Mock/MockScriptEngine.cs
@@ -40,10 +40,33 @@ namespace OpenSim.Tests.Common
{
public class MockScriptEngine : INonSharedRegionModule, IScriptModule, IScriptEngine
{
+ public IConfigSource ConfigSource { get; private set; }
+
+ public IConfig Config { get; private set; }
+
private Scene m_scene;
+ ///
+ /// Expose posted events to tests.
+ ///
+ public Dictionary> PostedEvents { get; private set; }
+
+ ///
+ /// A very primitive way of hooking text cose to a posed event.
+ ///
+ ///
+ /// May be replaced with something that uses more original code in the future.
+ ///
+ public event Action PostEventHook;
+
public void Initialise(IConfigSource source)
{
+ ConfigSource = source;
+
+ // Can set later on if required
+ Config = new IniConfig("MockScriptEngine", ConfigSource);
+
+ PostedEvents = new Dictionary>();
}
public void Close()
@@ -85,7 +108,28 @@ namespace OpenSim.Tests.Common
public bool PostScriptEvent(UUID itemID, string name, object[] args)
{
- return false;
+// Console.WriteLine("Posting event {0} for {1}", name, itemID);
+
+ EventParams evParams = new EventParams(name, args, null);
+
+ List eventsForItem;
+
+ if (!PostedEvents.ContainsKey(itemID))
+ {
+ eventsForItem = new List();
+ PostedEvents.Add(itemID, eventsForItem);
+ }
+ else
+ {
+ eventsForItem = PostedEvents[itemID];
+ }
+
+ eventsForItem.Add(evParams);
+
+ if (PostEventHook != null)
+ PostEventHook(itemID, evParams);
+
+ return true;
}
public bool PostObjectEvent(UUID itemID, string name, object[] args)
@@ -195,11 +239,7 @@ namespace OpenSim.Tests.Common
public Scene World { get { return m_scene; } }
- public IScriptModule ScriptModule { get { throw new System.NotImplementedException(); } }
-
- public IConfig Config { get { throw new System.NotImplementedException (); } }
-
- public IConfigSource ConfigSource { get { throw new System.NotImplementedException (); } }
+ public IScriptModule ScriptModule { get { return this; } }
public string ScriptEnginePath { get { throw new System.NotImplementedException (); }}
@@ -210,5 +250,10 @@ namespace OpenSim.Tests.Common
public string[] ScriptReferencedAssemblies { get { throw new System.NotImplementedException (); } }
public ParameterInfo[] ScriptBaseClassParameters { get { throw new System.NotImplementedException (); } }
+
+ public void ClearPostedEvents()
+ {
+ PostedEvents.Clear();
+ }
}
}
\ No newline at end of file
diff --git a/prebuild.xml b/prebuild.xml
index 7b28085..1e68f67 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -3391,6 +3391,8 @@
+
+
--
cgit v1.1