diff options
author | Sean Dague | 2007-07-30 20:11:40 +0000 |
---|---|---|
committer | Sean Dague | 2007-07-30 20:11:40 +0000 |
commit | 74bb5282a09ec095a7ff810c62f79cc64e187686 (patch) | |
tree | e0a9b703bfcbbab59b04351dd71508fa913e741a /OpenSim/Framework/Communications/Capabilities/LLSDHelpers.cs | |
parent | added OnDisconnectUser event to required classes (diff) | |
download | opensim-SC_OLD-74bb5282a09ec095a7ff810c62f79cc64e187686.zip opensim-SC_OLD-74bb5282a09ec095a7ff810c62f79cc64e187686.tar.gz opensim-SC_OLD-74bb5282a09ec095a7ff810c62f79cc64e187686.tar.bz2 opensim-SC_OLD-74bb5282a09ec095a7ff810c62f79cc64e187686.tar.xz |
mass update of files to have native line endings
Diffstat (limited to 'OpenSim/Framework/Communications/Capabilities/LLSDHelpers.cs')
-rw-r--r-- | OpenSim/Framework/Communications/Capabilities/LLSDHelpers.cs | 328 |
1 files changed, 164 insertions, 164 deletions
diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDHelpers.cs b/OpenSim/Framework/Communications/Capabilities/LLSDHelpers.cs index 19ef0c9..efeb9b1 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDHelpers.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDHelpers.cs | |||
@@ -1,164 +1,164 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | 2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 | */ | 27 | */ |
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.IO; | 30 | using System.IO; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Xml; | 32 | using System.Xml; |
33 | using libsecondlife; | 33 | using libsecondlife; |
34 | 34 | ||
35 | namespace OpenSim.Region.Capabilities | 35 | namespace OpenSim.Region.Capabilities |
36 | { | 36 | { |
37 | public class LLSDHelpers | 37 | public class LLSDHelpers |
38 | { | 38 | { |
39 | public static string SerialiseLLSDReply(object obj) | 39 | public static string SerialiseLLSDReply(object obj) |
40 | { | 40 | { |
41 | StringWriter sw = new StringWriter(); | 41 | StringWriter sw = new StringWriter(); |
42 | XmlTextWriter writer = new XmlTextWriter(sw); | 42 | XmlTextWriter writer = new XmlTextWriter(sw); |
43 | writer.Formatting = Formatting.None; | 43 | writer.Formatting = Formatting.None; |
44 | writer.WriteStartElement(String.Empty, "llsd", String.Empty); | 44 | writer.WriteStartElement(String.Empty, "llsd", String.Empty); |
45 | SerializeLLSDType(writer, obj); | 45 | SerializeLLSDType(writer, obj); |
46 | writer.WriteEndElement(); | 46 | writer.WriteEndElement(); |
47 | writer.Close(); | 47 | writer.Close(); |
48 | return sw.ToString(); | 48 | return sw.ToString(); |
49 | } | 49 | } |
50 | 50 | ||
51 | public static void SerializeLLSDType(XmlTextWriter writer, object obj) | 51 | public static void SerializeLLSDType(XmlTextWriter writer, object obj) |
52 | { | 52 | { |
53 | Type myType = obj.GetType(); | 53 | Type myType = obj.GetType(); |
54 | LLSDType[] llsdattributes = (LLSDType[])myType.GetCustomAttributes(typeof(LLSDType), false); | 54 | LLSDType[] llsdattributes = (LLSDType[])myType.GetCustomAttributes(typeof(LLSDType), false); |
55 | if (llsdattributes.Length > 0) | 55 | if (llsdattributes.Length > 0) |
56 | { | 56 | { |
57 | switch (llsdattributes[0].ObjectType) | 57 | switch (llsdattributes[0].ObjectType) |
58 | { | 58 | { |
59 | case "MAP": | 59 | case "MAP": |
60 | writer.WriteStartElement(String.Empty, "map", String.Empty); | 60 | writer.WriteStartElement(String.Empty, "map", String.Empty); |
61 | FieldInfo[] fields = myType.GetFields(); | 61 | FieldInfo[] fields = myType.GetFields(); |
62 | for (int i = 0; i < fields.Length; i++) | 62 | for (int i = 0; i < fields.Length; i++) |
63 | { | 63 | { |
64 | object fieldValue = fields[i].GetValue(obj); | 64 | object fieldValue = fields[i].GetValue(obj); |
65 | LLSDType[] fieldAttributes = (LLSDType[])fieldValue.GetType().GetCustomAttributes(typeof(LLSDType), false); | 65 | LLSDType[] fieldAttributes = (LLSDType[])fieldValue.GetType().GetCustomAttributes(typeof(LLSDType), false); |
66 | if (fieldAttributes.Length > 0) | 66 | if (fieldAttributes.Length > 0) |
67 | { | 67 | { |
68 | writer.WriteStartElement(String.Empty, "key", String.Empty); | 68 | writer.WriteStartElement(String.Empty, "key", String.Empty); |
69 | writer.WriteString(fields[i].Name); | 69 | writer.WriteString(fields[i].Name); |
70 | writer.WriteEndElement(); | 70 | writer.WriteEndElement(); |
71 | SerializeLLSDType(writer, fieldValue); | 71 | SerializeLLSDType(writer, fieldValue); |
72 | } | 72 | } |
73 | else | 73 | else |
74 | { | 74 | { |
75 | writer.WriteStartElement(String.Empty, "key", String.Empty); | 75 | writer.WriteStartElement(String.Empty, "key", String.Empty); |
76 | writer.WriteString(fields[i].Name); | 76 | writer.WriteString(fields[i].Name); |
77 | writer.WriteEndElement(); | 77 | writer.WriteEndElement(); |
78 | LLSD.LLSDWriteOne(writer, fieldValue); | 78 | LLSD.LLSDWriteOne(writer, fieldValue); |
79 | } | 79 | } |
80 | } | 80 | } |
81 | writer.WriteEndElement(); | 81 | writer.WriteEndElement(); |
82 | break; | 82 | break; |
83 | case "ARRAY": | 83 | case "ARRAY": |
84 | // LLSDArray arrayObject = obj as LLSDArray; | 84 | // LLSDArray arrayObject = obj as LLSDArray; |
85 | // ArrayList a = arrayObject.Array; | 85 | // ArrayList a = arrayObject.Array; |
86 | ArrayList a = (ArrayList)obj.GetType().GetField("Array").GetValue(obj); | 86 | ArrayList a = (ArrayList)obj.GetType().GetField("Array").GetValue(obj); |
87 | if (a != null) | 87 | if (a != null) |
88 | { | 88 | { |
89 | writer.WriteStartElement(String.Empty, "array", String.Empty); | 89 | writer.WriteStartElement(String.Empty, "array", String.Empty); |
90 | foreach (object item in a) | 90 | foreach (object item in a) |
91 | { | 91 | { |
92 | SerializeLLSDType(writer, item); | 92 | SerializeLLSDType(writer, item); |
93 | } | 93 | } |
94 | writer.WriteEndElement(); | 94 | writer.WriteEndElement(); |
95 | } | 95 | } |
96 | break; | 96 | break; |
97 | } | 97 | } |
98 | } | 98 | } |
99 | else | 99 | else |
100 | { | 100 | { |
101 | LLSD.LLSDWriteOne(writer, obj); | 101 | LLSD.LLSDWriteOne(writer, obj); |
102 | } | 102 | } |
103 | } | 103 | } |
104 | 104 | ||
105 | public static object DeserialiseLLSDMap(Hashtable llsd, object obj) | 105 | public static object DeserialiseLLSDMap(Hashtable llsd, object obj) |
106 | { | 106 | { |
107 | Type myType = obj.GetType(); | 107 | Type myType = obj.GetType(); |
108 | LLSDType[] llsdattributes = (LLSDType[])myType.GetCustomAttributes(typeof(LLSDType), false); | 108 | LLSDType[] llsdattributes = (LLSDType[])myType.GetCustomAttributes(typeof(LLSDType), false); |
109 | if (llsdattributes.Length > 0) | 109 | if (llsdattributes.Length > 0) |
110 | { | 110 | { |
111 | switch (llsdattributes[0].ObjectType) | 111 | switch (llsdattributes[0].ObjectType) |
112 | { | 112 | { |
113 | case "MAP": | 113 | case "MAP": |
114 | IDictionaryEnumerator enumerator = llsd.GetEnumerator(); | 114 | IDictionaryEnumerator enumerator = llsd.GetEnumerator(); |
115 | while (enumerator.MoveNext()) | 115 | while (enumerator.MoveNext()) |
116 | { | 116 | { |
117 | FieldInfo field = myType.GetField((string)enumerator.Key); | 117 | FieldInfo field = myType.GetField((string)enumerator.Key); |
118 | if (field != null) | 118 | if (field != null) |
119 | { | 119 | { |
120 | if (enumerator.Value is Hashtable) | 120 | if (enumerator.Value is Hashtable) |
121 | { | 121 | { |
122 | object fieldValue = field.GetValue(obj); | 122 | object fieldValue = field.GetValue(obj); |
123 | DeserialiseLLSDMap((Hashtable) enumerator.Value, fieldValue); | 123 | DeserialiseLLSDMap((Hashtable) enumerator.Value, fieldValue); |
124 | } | 124 | } |
125 | else if (enumerator.Value is ArrayList) | 125 | else if (enumerator.Value is ArrayList) |
126 | { | 126 | { |
127 | object fieldValue = field.GetValue(obj); | 127 | object fieldValue = field.GetValue(obj); |
128 | fieldValue.GetType().GetField("Array").SetValue(fieldValue, enumerator.Value); | 128 | fieldValue.GetType().GetField("Array").SetValue(fieldValue, enumerator.Value); |
129 | //TODO | 129 | //TODO |
130 | // the LLSD map/array types in the array need to be deserialised | 130 | // the LLSD map/array types in the array need to be deserialised |
131 | // but first we need to know the right class to deserialise them into. | 131 | // but first we need to know the right class to deserialise them into. |
132 | } | 132 | } |
133 | else | 133 | else |
134 | { | 134 | { |
135 | field.SetValue(obj, enumerator.Value); | 135 | field.SetValue(obj, enumerator.Value); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | } | 138 | } |
139 | break; | 139 | break; |
140 | } | 140 | } |
141 | } | 141 | } |
142 | return obj; | 142 | return obj; |
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | 147 | ||
148 | 148 | ||
149 | 149 | ||
150 | 150 | ||
151 | 151 | ||
152 | 152 | ||
153 | 153 | ||
154 | 154 | ||
155 | 155 | ||
156 | 156 | ||
157 | 157 | ||
158 | 158 | ||
159 | 159 | ||
160 | 160 | ||
161 | 161 | ||
162 | 162 | ||
163 | 163 | ||
164 | } | 164 | } |