From 49b99132106d0553dae6edf13c89f7b66604d133 Mon Sep 17 00:00:00 2001 From: MW Date: Mon, 25 Jun 2007 18:31:47 +0000 Subject: Some work in progress LLSD serialise / de-serialise functions. --- Common/OpenSim.Framework/LLSDHelpers.cs | 173 +++++++++++++++++++++ Common/OpenSim.Framework/OpenSim.Framework.csproj | 39 +++-- .../OpenSim.Framework/OpenSim.Framework.dll.build | 1 + OpenSim/OpenSim.Region/Caps.cs | 26 ++-- 4 files changed, 215 insertions(+), 24 deletions(-) create mode 100644 Common/OpenSim.Framework/LLSDHelpers.cs diff --git a/Common/OpenSim.Framework/LLSDHelpers.cs b/Common/OpenSim.Framework/LLSDHelpers.cs new file mode 100644 index 0000000..5b73483 --- /dev/null +++ b/Common/OpenSim.Framework/LLSDHelpers.cs @@ -0,0 +1,173 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using System.IO; +using System.Xml; +using libsecondlife; + +namespace OpenSim.Framework +{ + public class LLSDHelpers + { + public static string SerialiseLLSDReply(object obj) + { + StringWriter sw = new StringWriter(); + XmlTextWriter writer = new XmlTextWriter(sw); + writer.Formatting = Formatting.None; + writer.WriteStartElement(String.Empty, "llsd", String.Empty); + LLSDHelpers.SerializeLLSDType(writer, obj); + writer.WriteEndElement(); + writer.Close(); + return sw.ToString(); + } + + public static void SerializeLLSDType(XmlTextWriter writer, object obj) + { + Type myType = obj.GetType(); + LLSDType[] llsdattributes = (LLSDType[])myType.GetCustomAttributes(typeof(LLSDType), false); + if (llsdattributes.Length > 0) + { + switch (llsdattributes[0].ObjectType) + { + case "MAP": + writer.WriteStartElement(String.Empty, "map", String.Empty); + System.Reflection.FieldInfo[] fields = myType.GetFields(); + for (int i = 0; i < fields.Length; i++) + { + object fieldValue = fields[i].GetValue(obj); + LLSDType[] fieldAttributes = (LLSDType[])fieldValue.GetType().GetCustomAttributes(typeof(LLSDType), false); + if (fieldAttributes.Length > 0) + { + writer.WriteStartElement(String.Empty, "key", String.Empty); + writer.WriteString(fields[i].Name); + writer.WriteEndElement(); + SerializeLLSDType(writer, fieldValue); + } + else + { + //Console.WriteLine("LLSD field name" + fields[i].Name + " , " + fields[i].GetValue(obj).GetType()); + writer.WriteStartElement(String.Empty, "key", String.Empty); + writer.WriteString(fields[i].Name); + writer.WriteEndElement(); + LLSD.LLSDWriteOne(writer, fieldValue); + } + } + writer.WriteEndElement(); + break; + case "ARRAY": + // LLSDArray arrayObject = obj as LLSDArray; + // ArrayList a = arrayObject.Array; + ArrayList a = (ArrayList)obj.GetType().GetField("Array").GetValue(obj); + writer.WriteStartElement(String.Empty, "array", String.Empty); + foreach (object item in a) + { + SerializeLLSDType(writer, item); + } + writer.WriteEndElement(); + break; + } + } + else + { + LLSD.LLSDWriteOne(writer, obj); + } + } + + public static object DeserialiseLLSDMap(Hashtable llsd, object obj) + { + Type myType = obj.GetType(); + LLSDType[] llsdattributes = (LLSDType[])myType.GetCustomAttributes(typeof(LLSDType), false); + if (llsdattributes.Length > 0) + { + switch (llsdattributes[0].ObjectType) + { + case "MAP": + IDictionaryEnumerator enumerator = llsd.GetEnumerator(); + while (enumerator.MoveNext()) + { + System.Reflection.FieldInfo field = myType.GetField((string)enumerator.Key); + if (field != null) + { + field.SetValue(obj, enumerator.Value); + } + } + break; + } + } + return obj; + } + } + + [LLSDType("MAP")] + public class LLSDMapLayer + { + public int Left = 0; + public int Right = 0; + public int Top = 0; + public int Bottom = 0; + public LLUUID ImageID = LLUUID.Zero; + + public LLSDArray TestArray = new LLSDArray(); + public LLSDMapLayer() + { + + } + } + + [LLSDType("ARRAY")] + public class LLSDArray + { + public ArrayList Array = new ArrayList(); + + public LLSDArray() + { + + } + } + + [LLSDType("MAP")] + public class LLSDMapRequest + { + public int Flags = 0; + + public LLSDMapRequest() + { + + } + } + + [LLSDType("MAP")] + public class LLSDTest + { + public int Test1 = 20; + public int Test2 = 10; + + public LLSDTest() + { + + } + } + + + [AttributeUsage(AttributeTargets.Class)] + public class LLSDType : Attribute + { + private string myHandler; + + + public LLSDType(string type) + { + myHandler = type; + + } + + public string ObjectType + { + get + { + return myHandler; + } + } + } +} diff --git a/Common/OpenSim.Framework/OpenSim.Framework.csproj b/Common/OpenSim.Framework/OpenSim.Framework.csproj index f9a4f2d..f12ffcb 100644 --- a/Common/OpenSim.Framework/OpenSim.Framework.csproj +++ b/Common/OpenSim.Framework/OpenSim.Framework.csproj @@ -1,4 +1,4 @@ - + Local 8.0.50727 @@ -6,7 +6,8 @@ {8ACA2445-0000-0000-0000-000000000000} Debug AnyCPU - + + OpenSim.Framework @@ -15,9 +16,11 @@ IE50 false Library - + + OpenSim.Framework - + + @@ -28,7 +31,8 @@ TRACE;DEBUG - + + True 4096 False @@ -37,7 +41,8 @@ False False 4 - + + False @@ -46,7 +51,8 @@ TRACE - + + False 4096 True @@ -55,22 +61,24 @@ False False 4 - + + - + ..\..\bin\Db4objects.Db4o.dll False - + ..\..\bin\libsecondlife.dll False - + System.dll False - + + System.Xml.dll False @@ -80,13 +88,13 @@ OpenSim.Framework.Console {A7CD0630-0000-0000-0000-000000000000} {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - False + False XMLRPC {8E81D43C-0000-0000-0000-000000000000} {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - False + False @@ -102,6 +110,7 @@ Code + Code @@ -215,4 +224,4 @@ - + \ No newline at end of file diff --git a/Common/OpenSim.Framework/OpenSim.Framework.dll.build b/Common/OpenSim.Framework/OpenSim.Framework.dll.build index ab511f2..afe1aea 100644 --- a/Common/OpenSim.Framework/OpenSim.Framework.dll.build +++ b/Common/OpenSim.Framework/OpenSim.Framework.dll.build @@ -15,6 +15,7 @@ + diff --git a/OpenSim/OpenSim.Region/Caps.cs b/OpenSim/OpenSim.Region/Caps.cs index 11b1b4d..319e027 100644 --- a/OpenSim/OpenSim.Region/Caps.cs +++ b/OpenSim/OpenSim.Region/Caps.cs @@ -1,8 +1,11 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Text; using System.IO; +using System.Xml; using OpenSim.Servers; +using OpenSim.Framework; using OpenSim.Framework.Utilities; using OpenSim.Framework.Types; using OpenSim.Caches; @@ -91,6 +94,11 @@ namespace OpenSim.Region /// public string MapLayer(string request, string path, string param) { + Encoding _enc = System.Text.Encoding.UTF8; + Hashtable hash =(Hashtable) LLSD.LLSDDeserialize(_enc.GetBytes(request)); + LLSDMapRequest mapReq = new LLSDMapRequest(); + LLSDHelpers.DeserialiseLLSDMap(hash, mapReq ); + string res = "AgentDataFlags0LayerData"; res += this.BuildLLSDMapLayerResponse(); res += ""; @@ -123,14 +131,14 @@ namespace OpenSim.Region public string ProcessEventQueue(string request, string path, string param) { - // Console.WriteLine("event queue request " + request); + // Console.WriteLine("event queue request " + request); string res = ""; int timer = 0; - /*while ((timer < 200) || (this.CapsEventQueue.Count < 1)) - { - timer++; - }*/ + /*while ((timer < 200) || (this.CapsEventQueue.Count < 1)) + { + timer++; + }*/ if (this.CapsEventQueue.Count > 0) { lock (this.CapsEventQueue) @@ -152,9 +160,9 @@ namespace OpenSim.Region res += "events"; res += "messageEstablishAgentCommunication"; res += "body"; - res += "sim-ip-and-port"+ipAddressPort +""; - res += "seed-capability"+caps+""; - res += "agent-id"+this.agentID.ToStringHyphenated()+""; + res += "sim-ip-and-port" + ipAddressPort + ""; + res += "seed-capability" + caps + ""; + res += "agent-id" + this.agentID.ToStringHyphenated() + ""; res += ""; res += ""; res += ""; @@ -195,7 +203,7 @@ namespace OpenSim.Region public void UploadHandler(LLUUID assetID, LLUUID inventoryItem, byte[] data) { - // Console.WriteLine("upload handler called"); + // Console.WriteLine("upload handler called"); AssetBase asset; asset = new AssetBase(); asset.FullID = assetID; -- cgit v1.1