From 0dff3f2383593dedee9c5b2e8d8668a8ad0ce6d0 Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Thu, 18 Sep 2008 16:53:26 +0000 Subject: From: Robert Smart (SMARTROB@uk.ibm.com) Patch for new scripting method osParseJSON. also, a couple of warning bugs killed. --- .../Shared/Api/Implementation/LSL_Api.cs | 12 +- .../Shared/Api/Implementation/OSSL_Api.cs | 187 +++++++++++++++++++++ 2 files changed, 193 insertions(+), 6 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index b77676c..1c108b7 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -139,7 +139,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (m_host.ParentGroup != null) return new List(m_host.ParentGroup.Children.Values); return ret; - break; + case ScriptBaseClass.LINK_ROOT: if (m_host.ParentGroup != null) { @@ -148,7 +148,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return ret; } return ret; - break; + case ScriptBaseClass.LINK_ALL_OTHERS: if (m_host.ParentGroup == null) return new List(); @@ -156,7 +156,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (ret.Contains(m_host)) ret.Remove(m_host); return ret; - break; + case ScriptBaseClass.LINK_ALL_CHILDREN: if (m_host.ParentGroup == null) return new List(); @@ -164,10 +164,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (ret.Contains(m_host.ParentGroup.RootPart)) ret.Remove(m_host.ParentGroup.RootPart); return ret; - break; + case ScriptBaseClass.LINK_THIS: return ret; - break; + default: if (linkType < 0 || m_host.ParentGroup == null) return new List(); @@ -177,7 +177,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api ret = new List(); ret.Add(target); return ret; - break; + } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 5cc58e7..7404640 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ using System; +using System.Collections; using System.Collections.Generic; using System.Runtime.Remoting.Lifetime; using OpenMetaverse; @@ -730,5 +731,191 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api World.ParcelMediaSetTime((float)time); } + + + + public Hashtable osParseJSON(string JSON) + { + if (!m_OSFunctionsEnabled) + { + OSSLError("osParseJSON: permission denied"); + return null; + } + + CheckThreatLevel(ThreatLevel.None, "osParseJSON"); + + m_host.AddScriptLPS(1); + + // see http://www.json.org/ for more details on JSON + + string currentKey=null; + Stack objectStack = new Stack(); // objects in JSON can be nested so we need to keep a track of this + Hashtable jsondata = new Hashtable(); // the hashtable to be returned + + try + { + + // iterate through the serialised stream of tokens and store at the right depth in the hashtable + // the top level hashtable may contain more nested hashtables within it each containing an objects representation + for (int i=0;i