aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorDr Scofield2008-09-18 16:53:26 +0000
committerDr Scofield2008-09-18 16:53:26 +0000
commit0dff3f2383593dedee9c5b2e8d8668a8ad0ce6d0 (patch)
tree446e13c296397ea90bf3ba2ffabd8dcdfa6e2932 /OpenSim
parentUpdate svn properties, minor formatting cleanup. (diff)
downloadopensim-SC_OLD-0dff3f2383593dedee9c5b2e8d8668a8ad0ce6d0.zip
opensim-SC_OLD-0dff3f2383593dedee9c5b2e8d8668a8ad0ce6d0.tar.gz
opensim-SC_OLD-0dff3f2383593dedee9c5b2e8d8668a8ad0ce6d0.tar.bz2
opensim-SC_OLD-0dff3f2383593dedee9c5b2e8d8668a8ad0ce6d0.tar.xz
From: Robert Smart (SMARTROB@uk.ibm.com)
Patch for new scripting method osParseJSON. also, a couple of warning bugs killed.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs12
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs187
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs5
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs2
5 files changed, 202 insertions, 8 deletions
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
139 if (m_host.ParentGroup != null) 139 if (m_host.ParentGroup != null)
140 return new List<SceneObjectPart>(m_host.ParentGroup.Children.Values); 140 return new List<SceneObjectPart>(m_host.ParentGroup.Children.Values);
141 return ret; 141 return ret;
142 break; 142
143 case ScriptBaseClass.LINK_ROOT: 143 case ScriptBaseClass.LINK_ROOT:
144 if (m_host.ParentGroup != null) 144 if (m_host.ParentGroup != null)
145 { 145 {
@@ -148,7 +148,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
148 return ret; 148 return ret;
149 } 149 }
150 return ret; 150 return ret;
151 break; 151
152 case ScriptBaseClass.LINK_ALL_OTHERS: 152 case ScriptBaseClass.LINK_ALL_OTHERS:
153 if (m_host.ParentGroup == null) 153 if (m_host.ParentGroup == null)
154 return new List<SceneObjectPart>(); 154 return new List<SceneObjectPart>();
@@ -156,7 +156,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
156 if (ret.Contains(m_host)) 156 if (ret.Contains(m_host))
157 ret.Remove(m_host); 157 ret.Remove(m_host);
158 return ret; 158 return ret;
159 break; 159
160 case ScriptBaseClass.LINK_ALL_CHILDREN: 160 case ScriptBaseClass.LINK_ALL_CHILDREN:
161 if (m_host.ParentGroup == null) 161 if (m_host.ParentGroup == null)
162 return new List<SceneObjectPart>(); 162 return new List<SceneObjectPart>();
@@ -164,10 +164,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
164 if (ret.Contains(m_host.ParentGroup.RootPart)) 164 if (ret.Contains(m_host.ParentGroup.RootPart))
165 ret.Remove(m_host.ParentGroup.RootPart); 165 ret.Remove(m_host.ParentGroup.RootPart);
166 return ret; 166 return ret;
167 break; 167
168 case ScriptBaseClass.LINK_THIS: 168 case ScriptBaseClass.LINK_THIS:
169 return ret; 169 return ret;
170 break; 170
171 default: 171 default:
172 if (linkType < 0 || m_host.ParentGroup == null) 172 if (linkType < 0 || m_host.ParentGroup == null)
173 return new List<SceneObjectPart>(); 173 return new List<SceneObjectPart>();
@@ -177,7 +177,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
177 ret = new List<SceneObjectPart>(); 177 ret = new List<SceneObjectPart>();
178 ret.Add(target); 178 ret.Add(target);
179 return ret; 179 return ret;
180 break; 180
181 } 181 }
182 } 182 }
183 183
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 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27using System; 27using System;
28using System.Collections;
28using System.Collections.Generic; 29using System.Collections.Generic;
29using System.Runtime.Remoting.Lifetime; 30using System.Runtime.Remoting.Lifetime;
30using OpenMetaverse; 31using OpenMetaverse;
@@ -730,5 +731,191 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
730 731
731 World.ParcelMediaSetTime((float)time); 732 World.ParcelMediaSetTime((float)time);
732 } 733 }
734
735
736
737 public Hashtable osParseJSON(string JSON)
738 {
739 if (!m_OSFunctionsEnabled)
740 {
741 OSSLError("osParseJSON: permission denied");
742 return null;
743 }
744
745 CheckThreatLevel(ThreatLevel.None, "osParseJSON");
746
747 m_host.AddScriptLPS(1);
748
749 // see http://www.json.org/ for more details on JSON
750
751 string currentKey=null;
752 Stack objectStack = new Stack(); // objects in JSON can be nested so we need to keep a track of this
753 Hashtable jsondata = new Hashtable(); // the hashtable to be returned
754
755 try
756 {
757
758 // iterate through the serialised stream of tokens and store at the right depth in the hashtable
759 // the top level hashtable may contain more nested hashtables within it each containing an objects representation
760 for (int i=0;i<JSON.Length; i++)
761 {
762
763 // Console.WriteLine(""+JSON[i]);
764 switch(JSON[i])
765 {
766 case '{':
767 // create hashtable and add it to the stack or array if we are populating one, we can have a lot of nested objects in JSON
768
769 Hashtable currentObject = new Hashtable();
770 if(objectStack.Count==0) // the stack should only be empty for the first outer object
771 {
772
773 objectStack.Push(jsondata);
774 }
775 else if(objectStack.Peek().ToString()=="System.Collections.ArrayList")
776 {
777 // add it to the parent array
778 ((ArrayList)objectStack.Peek()).Add(currentObject);
779 objectStack.Push(currentObject);
780 }
781 else
782 {
783 // add it to the parent hashtable
784 ((Hashtable)objectStack.Peek()).Add(currentKey,currentObject);
785 objectStack.Push(currentObject);
786 }
787
788 // clear the key
789 currentKey=null;
790 break;
791 case '}':
792 // pop the hashtable off the stack
793 objectStack.Pop();
794 break;
795 case '"':// string boundary
796
797 string tokenValue="";
798 i++; // move to next char
799
800 // just loop through until the next quote mark storing the string
801 while(JSON[i]!='"')
802 {
803 tokenValue+=JSON[i++];
804 }
805
806 // ok we've got a string, if we've got an array on the top of the stack then we store it
807 if(objectStack.Peek().ToString()=="System.Collections.ArrayList")
808 {
809 ((ArrayList)objectStack.Peek()).Add(tokenValue);
810 }
811 else if(currentKey==null) // no key stored and its not an array this must be a key so store it
812 {
813 currentKey = tokenValue;
814 }
815 else
816 {
817 // we have a key so lets store this value
818 ((Hashtable)objectStack.Peek()).Add(currentKey,tokenValue);
819 // now lets clear the key, we're done with it and moving on
820 currentKey=null;
821 }
822
823 break;
824 case ':':// key : value separator
825 // just ignore
826 break;
827 case ' ':// spaces
828 // just ignore
829 break;
830 case '[': // array start
831 ArrayList currentArray = new ArrayList();
832
833 if(objectStack.Peek().ToString()=="System.Collections.ArrayList")
834 {
835 ((ArrayList)objectStack.Peek()).Add(currentArray);
836 }
837 else
838 {
839 ((Hashtable)objectStack.Peek()).Add(currentKey,currentArray);
840 // clear the key
841 currentKey=null;
842 }
843 objectStack.Push(currentArray);
844
845 break;
846 case ',':// seperator
847 // just ignore
848 break;
849 case ']'://Array end
850 // pop the array off the stack
851 objectStack.Pop();
852 break;
853 case 't': // we've found a character start not in quotes, it must be a boolean true
854
855 if(objectStack.Peek().ToString()=="System.Collections.ArrayList")
856 {
857 ((ArrayList)objectStack.Peek()).Add(true);
858 }
859 else
860 {
861 ((Hashtable)objectStack.Peek()).Add(currentKey,true);
862 }
863
864 //advance the counter to the letter 'e'
865 i = i+3;
866 break;
867 case 'f': // we've found a character start not in quotes, it must be a boolean false
868
869 if(objectStack.Peek().ToString()=="System.Collections.ArrayList")
870 {
871 ((ArrayList)objectStack.Peek()).Add(false);
872 }
873 else
874 {
875 ((Hashtable)objectStack.Peek()).Add(currentKey,false);
876 }
877 //advance the counter to the letter 'e'
878 i = i+4;
879 break;
880
881 default:
882 // ok here we're catching all numeric types int,double,long we might want to spit these up mr accurately
883 // but for now we'll just do them as strings
884
885 string numberValue="";
886
887 // just loop through until the next known marker quote mark storing the string
888 while(JSON[i] != '"' && JSON[i] != ',' && JSON[i] != ']' && JSON[i] != '}' && JSON[i] != ' ')
889 {
890 numberValue+=""+JSON[i++];
891 }
892
893 i--; // we want to process this caracter that marked the end of this string in the main loop
894
895 // ok we've got a string, if we've got an array on the top of the stack then we store it
896 if(objectStack.Peek().ToString()=="System.Collections.ArrayList")
897 {
898 ((ArrayList)objectStack.Peek()).Add(numberValue);
899 }
900 else
901 {
902 // we have a key so lets store this value
903 ((Hashtable)objectStack.Peek()).Add(currentKey,numberValue);
904 // now lets clear the key, we're done with it and moving on
905 currentKey=null;
906 }
907
908 break;
909 }
910 }
911 }
912 catch(Exception)
913 {
914 OSSLError("osParseJSON: The JSON string is not valid " + JSON);
915 }
916
917 return jsondata;
918 }
919
733 } 920 }
734} 921}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index d4bb8c3..9dd4a45 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -24,7 +24,7 @@
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27using System.Collections;
28namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces 28namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
29{ 29{
30 public interface IOSSL_Api 30 public interface IOSSL_Api
@@ -71,5 +71,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
71 71
72 string osGetScriptEngineName(); 72 string osGetScriptEngineName();
73 void osSetParcelMediaTime(double time); 73 void osSetParcelMediaTime(double time);
74 Hashtable osParseJSON(string JSON);
75
74 } 76 }
75} 77}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 3a7c14e..de11d06 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -219,5 +219,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
219 { 219 {
220 m_OSSL_Functions.osSetParcelMediaTime(time); 220 m_OSSL_Functions.osSetParcelMediaTime(time);
221 } 221 }
222
223 public Hashtable osParseJSON(string JSON)
224 {
225 return m_OSSL_Functions.osParseJSON(JSON);
226 }
222 } 227 }
223} 228}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index dd1bfaa..71bdd6e 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -474,7 +474,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
474 if (data.EventName == "control") 474 if (data.EventName == "control")
475 { 475 {
476 int held = ((LSL_Types.LSLInteger)data.Params[1]).value; 476 int held = ((LSL_Types.LSLInteger)data.Params[1]).value;
477 int changed= ((LSL_Types.LSLInteger)data.Params[2]).value; 477 // int changed = ((LSL_Types.LSLInteger)data.Params[2]).value;
478 478
479 // If the last message was a 0 (nothing held) 479 // If the last message was a 0 (nothing held)
480 // and this one is also nothing held, drop it 480 // and this one is also nothing held, drop it