aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-02-03 22:21:54 +0000
committerJustin Clark-Casey (justincc)2012-02-03 22:21:54 +0000
commitf17066b7bf27c22448d883e0af9d20a42f671b62 (patch)
treec1b4fed29d33d2055dd990fd53c616a8fe1e8f60 /OpenSim/Framework
parentCorrected console help texts for "save iar" (diff)
downloadopensim-SC-f17066b7bf27c22448d883e0af9d20a42f671b62.zip
opensim-SC-f17066b7bf27c22448d883e0af9d20a42f671b62.tar.gz
opensim-SC-f17066b7bf27c22448d883e0af9d20a42f671b62.tar.bz2
opensim-SC-f17066b7bf27c22448d883e0af9d20a42f671b62.tar.xz
Change LandDataSerializer deserialization so that in the future it won't care about extra elements or element order.
This brings it into line with other deserializations such as object and will improve future backward compatibility.
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/LandData.cs2
-rw-r--r--OpenSim/Framework/Serialization/External/LandDataSerializer.cs237
-rw-r--r--OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs3
-rw-r--r--OpenSim/Framework/Serialization/External/UserProfileSerializer.cs5
-rw-r--r--OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs37
5 files changed, 209 insertions, 75 deletions
diff --git a/OpenSim/Framework/LandData.cs b/OpenSim/Framework/LandData.cs
index 58a80ef..f6271ef 100644
--- a/OpenSim/Framework/LandData.cs
+++ b/OpenSim/Framework/LandData.cs
@@ -34,7 +34,7 @@ using OpenMetaverse;
34 34
35namespace OpenSim.Framework 35namespace OpenSim.Framework
36{ 36{
37 public struct LandAccessEntry 37 public class LandAccessEntry
38 { 38 {
39 public UUID AgentID; 39 public UUID AgentID;
40 public int Expires; 40 public int Expires;
diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
index 3ae9a8e..bf6c4e5 100644
--- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
@@ -28,8 +28,10 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.Reflection;
31using System.Text; 32using System.Text;
32using System.Xml; 33using System.Xml;
34using log4net;
33using OpenMetaverse; 35using OpenMetaverse;
34using OpenSim.Framework; 36using OpenSim.Framework;
35 37
@@ -40,8 +42,152 @@ namespace OpenSim.Framework.Serialization.External
40 /// </summary> 42 /// </summary>
41 public class LandDataSerializer 43 public class LandDataSerializer
42 { 44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46
43 protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); 47 protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding();
44 48
49 private delegate void LandDataProcessor(LandData landData, XmlTextReader reader);
50 private static Dictionary<string, LandDataProcessor> m_ldProcessors
51 = new Dictionary<string, LandDataProcessor>();
52
53 private delegate void LandAccessEntryProcessor(LandAccessEntry lae, XmlTextReader reader);
54 private static Dictionary<string, LandAccessEntryProcessor> m_laeProcessors
55 = new Dictionary<string, LandAccessEntryProcessor>();
56
57 static LandDataSerializer()
58 {
59 // LandData processors
60 m_ldProcessors.Add(
61 "Area", (ld, xtr) => ld.Area = Convert.ToInt32(xtr.ReadElementString("Area")));
62 m_ldProcessors.Add(
63 "AuctionID", (ld, xtr) => ld.AuctionID = Convert.ToUInt32(xtr.ReadElementString("AuctionID")));
64 m_ldProcessors.Add(
65 "AuthBuyerID", (ld, xtr) => ld.AuthBuyerID = UUID.Parse(xtr.ReadElementString("AuthBuyerID")));
66 m_ldProcessors.Add(
67 "Category", (ld, xtr) => ld.Category = (ParcelCategory)Convert.ToSByte(xtr.ReadElementString("Category")));
68 m_ldProcessors.Add(
69 "ClaimDate", (ld, xtr) => ld.ClaimDate = Convert.ToInt32(xtr.ReadElementString("ClaimDate")));
70 m_ldProcessors.Add(
71 "ClaimPrice", (ld, xtr) => ld.ClaimPrice = Convert.ToInt32(xtr.ReadElementString("ClaimPrice")));
72 m_ldProcessors.Add(
73 "GlobalID", (ld, xtr) => ld.GlobalID = UUID.Parse(xtr.ReadElementString("GlobalID")));
74 m_ldProcessors.Add(
75 "GroupID", (ld, xtr) => ld.GroupID = UUID.Parse(xtr.ReadElementString("GroupID")));
76 m_ldProcessors.Add(
77 "IsGroupOwned", (ld, xtr) => ld.IsGroupOwned = Convert.ToBoolean(xtr.ReadElementString("IsGroupOwned")));
78 m_ldProcessors.Add(
79 "Bitmap", (ld, xtr) => ld.Bitmap = Convert.FromBase64String(xtr.ReadElementString("Bitmap")));
80 m_ldProcessors.Add(
81 "Description", (ld, xtr) => ld.Description = xtr.ReadElementString("Description"));
82 m_ldProcessors.Add(
83 "Flags", (ld, xtr) => ld.Flags = Convert.ToUInt32(xtr.ReadElementString("Flags")));
84 m_ldProcessors.Add(
85 "LandingType", (ld, xtr) => ld.LandingType = Convert.ToByte(xtr.ReadElementString("LandingType")));
86 m_ldProcessors.Add(
87 "Name", (ld, xtr) => ld.Name = xtr.ReadElementString("Name"));
88 m_ldProcessors.Add(
89 "Status", (ld, xtr) => ld.Status = (ParcelStatus)Convert.ToSByte(xtr.ReadElementString("Status")));
90 m_ldProcessors.Add(
91 "LocalID", (ld, xtr) => ld.LocalID = Convert.ToInt32(xtr.ReadElementString("LocalID")));
92 m_ldProcessors.Add(
93 "MediaAutoScale", (ld, xtr) => ld.MediaAutoScale = Convert.ToByte(xtr.ReadElementString("MediaAutoScale")));
94 m_ldProcessors.Add(
95 "MediaID", (ld, xtr) => ld.MediaID = UUID.Parse(xtr.ReadElementString("MediaID")));
96 m_ldProcessors.Add(
97 "MediaURL", (ld, xtr) => ld.MediaURL = xtr.ReadElementString("MediaURL"));
98 m_ldProcessors.Add(
99 "MusicURL", (ld, xtr) => ld.MusicURL = xtr.ReadElementString("MusicURL"));
100
101 m_ldProcessors.Add(
102 "ParcelAccessList", ProcessParcelAccessList);
103
104 m_ldProcessors.Add(
105 "PassHours", (ld, xtr) => ld.PassHours = Convert.ToSingle(xtr.ReadElementString("PassHours")));
106 m_ldProcessors.Add(
107 "PassPrice", (ld, xtr) => ld.PassPrice = Convert.ToInt32(xtr.ReadElementString("PassPrice")));
108 m_ldProcessors.Add(
109 "SalePrice", (ld, xtr) => ld.SalePrice = Convert.ToInt32(xtr.ReadElementString("SalePrice")));
110 m_ldProcessors.Add(
111 "SnapshotID", (ld, xtr) => ld.SnapshotID = UUID.Parse(xtr.ReadElementString("SnapshotID")));
112 m_ldProcessors.Add(
113 "UserLocation", (ld, xtr) => ld.UserLocation = Vector3.Parse(xtr.ReadElementString("UserLocation")));
114 m_ldProcessors.Add(
115 "UserLookAt", (ld, xtr) => ld.UserLookAt = Vector3.Parse(xtr.ReadElementString("UserLookAt")));
116
117 // No longer used here //
118 // m_ldProcessors.Add("Dwell", (landData, xtr) => return);
119
120 m_ldProcessors.Add(
121 "OtherCleanTime", (ld, xtr) => ld.OtherCleanTime = Convert.ToInt32(xtr.ReadElementString("OtherCleanTime")));
122
123 // LandAccessEntryProcessors
124 m_laeProcessors.Add(
125 "AgentID", (lae, xtr) => lae.AgentID = UUID.Parse(xtr.ReadElementString("AgentID")));
126 m_laeProcessors.Add(
127 "Time", (lae, xtr) =>
128 {
129 // We really don't care about temp vs perm here and this
130 // would break on old oars. Assume all bans are perm
131 xtr.ReadElementString("Time");
132 lae.Expires = 0; // Convert.ToUint( xtr.ReadElementString("Time"));
133 }
134 );
135 m_laeProcessors.Add(
136 "AccessList", (lae, xtr) => lae.Flags = (AccessList)Convert.ToUInt32(xtr.ReadElementString("AccessList")));
137 }
138
139 public static void ProcessParcelAccessList(LandData ld, XmlTextReader xtr)
140 {
141 if (!xtr.IsEmptyElement)
142 {
143 while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement)
144 {
145 LandAccessEntry lae = new LandAccessEntry();
146
147 xtr.ReadStartElement("ParcelAccessEntry");
148
149 string nodeName = string.Empty;
150 while (xtr.NodeType != XmlNodeType.EndElement)
151 {
152 nodeName = xtr.Name;
153
154// m_log.DebugFormat("[LandDataSerializer]: Processing: {0} in ParcelAccessEntry", nodeName);
155
156 LandAccessEntryProcessor p = null;
157 if (m_laeProcessors.TryGetValue(xtr.Name, out p))
158 {
159// m_log.DebugFormat("[LandDataSerializer]: Found {0} processor in ParcelAccessEntry", nodeName);
160
161 try
162 {
163 p(lae, xtr);
164 }
165 catch (Exception e)
166 {
167 m_log.ErrorFormat(
168 "[LandDataSerializer]: Exception while parsing element {0} in ParcelAccessEntry, continuing. Exception {1}{2}",
169 nodeName, e.Message, e.StackTrace);
170
171 if (xtr.NodeType == XmlNodeType.EndElement)
172 xtr.Read();
173 }
174 }
175 else
176 {
177 // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName);
178 xtr.ReadOuterXml(); // ignore
179 }
180 }
181
182 xtr.ReadEndElement();
183
184 ld.ParcelAccessList.Add(lae);
185 }
186 }
187
188 xtr.Read();
189 }
190
45 /// <summary> 191 /// <summary>
46 /// Reify/deserialize landData 192 /// Reify/deserialize landData
47 /// </summary> 193 /// </summary>
@@ -63,72 +209,43 @@ namespace OpenSim.Framework.Serialization.External
63 { 209 {
64 LandData landData = new LandData(); 210 LandData landData = new LandData();
65 211
66 StringReader sr = new StringReader(serializedLandData); 212 using (XmlTextReader reader = new XmlTextReader(new StringReader(serializedLandData)))
67 XmlTextReader xtr = new XmlTextReader(sr);
68
69 xtr.ReadStartElement("LandData");
70
71 landData.Area = Convert.ToInt32( xtr.ReadElementString("Area"));
72 landData.AuctionID = Convert.ToUInt32( xtr.ReadElementString("AuctionID"));
73 landData.AuthBuyerID = UUID.Parse( xtr.ReadElementString("AuthBuyerID"));
74 landData.Category = (ParcelCategory)Convert.ToSByte( xtr.ReadElementString("Category"));
75 landData.ClaimDate = Convert.ToInt32( xtr.ReadElementString("ClaimDate"));
76 landData.ClaimPrice = Convert.ToInt32( xtr.ReadElementString("ClaimPrice"));
77 landData.GlobalID = UUID.Parse( xtr.ReadElementString("GlobalID"));
78 landData.GroupID = UUID.Parse( xtr.ReadElementString("GroupID"));
79 landData.IsGroupOwned = Convert.ToBoolean( xtr.ReadElementString("IsGroupOwned"));
80 landData.Bitmap = Convert.FromBase64String( xtr.ReadElementString("Bitmap"));
81 landData.Description = xtr.ReadElementString("Description");
82 landData.Flags = Convert.ToUInt32( xtr.ReadElementString("Flags"));
83 landData.LandingType = Convert.ToByte( xtr.ReadElementString("LandingType"));
84 landData.Name = xtr.ReadElementString("Name");
85 landData.Status = (ParcelStatus)Convert.ToSByte( xtr.ReadElementString("Status"));
86 landData.LocalID = Convert.ToInt32( xtr.ReadElementString("LocalID"));
87 landData.MediaAutoScale = Convert.ToByte( xtr.ReadElementString("MediaAutoScale"));
88 landData.MediaID = UUID.Parse( xtr.ReadElementString("MediaID"));
89 landData.MediaURL = xtr.ReadElementString("MediaURL");
90 landData.MusicURL = xtr.ReadElementString("MusicURL");
91 landData.OwnerID = UUID.Parse( xtr.ReadElementString("OwnerID"));
92
93 landData.ParcelAccessList = new List<LandAccessEntry>();
94 xtr.Read();
95 if (xtr.Name != "ParcelAccessList")
96 throw new XmlException(String.Format("Expected \"ParcelAccessList\" element but got \"{0}\"", xtr.Name));
97
98 if (!xtr.IsEmptyElement)
99 { 213 {
100 while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) 214 reader.ReadStartElement("LandData");
101 {
102 LandAccessEntry pae = new LandAccessEntry();
103 215
104 xtr.ReadStartElement("ParcelAccessEntry"); 216 string nodeName = string.Empty;
105 pae.AgentID = UUID.Parse( xtr.ReadElementString("AgentID")); 217 while (reader.NodeType != XmlNodeType.EndElement)
106 // We really don't care about temp vs perm here and this 218 {
107 // would break on old oars. Assume all bans are perm 219 nodeName = reader.Name;
108 xtr.ReadElementString("Time");
109 pae.Expires = 0; // Convert.ToUint( xtr.ReadElementString("Time"));
110 pae.Flags = (AccessList)Convert.ToUInt32( xtr.ReadElementString("AccessList"));
111 xtr.ReadEndElement();
112 220
113 landData.ParcelAccessList.Add(pae); 221// m_log.DebugFormat("[LandDataSerializer]: Processing: {0}", nodeName);
114 }
115 }
116 xtr.Read();
117 222
118 landData.PassHours = Convert.ToSingle( xtr.ReadElementString("PassHours")); 223 LandDataProcessor p = null;
119 landData.PassPrice = Convert.ToInt32( xtr.ReadElementString("PassPrice")); 224 if (m_ldProcessors.TryGetValue(reader.Name, out p))
120 landData.SalePrice = Convert.ToInt32( xtr.ReadElementString("SalePrice")); 225 {
121 landData.SnapshotID = UUID.Parse( xtr.ReadElementString("SnapshotID")); 226 try
122 landData.UserLocation = Vector3.Parse( xtr.ReadElementString("UserLocation")); 227 {
123 landData.UserLookAt = Vector3.Parse( xtr.ReadElementString("UserLookAt")); 228 p(landData, reader);
124 // No longer used here 229 }
125 xtr.ReadElementString("Dwell"); 230 catch (Exception e)
126 landData.OtherCleanTime = Convert.ToInt32( xtr.ReadElementString("OtherCleanTime")); 231 {
232 m_log.ErrorFormat(
233 "[LandDataSerializer]: exception while parsing element {0}, continuing. Exception {1}{2}",
234 nodeName, e.Message, e.StackTrace);
127 235
128 xtr.ReadEndElement(); 236 if (reader.NodeType == XmlNodeType.EndElement)
237 reader.Read();
238 }
239 }
240 else
241 {
242 // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName);
243 reader.ReadOuterXml(); // ignore
244 }
245 }
129 246
130 xtr.Close(); 247 reader.ReadEndElement();
131 sr.Close(); 248 }
132 249
133 return landData; 250 return landData;
134 } 251 }
diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
index f138437..5d986d5 100644
--- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
@@ -41,8 +41,7 @@ namespace OpenSim.Framework.Serialization.External
41{ 41{
42 /// <summary> 42 /// <summary>
43 /// Serialize and deserialize user inventory items as an external format. 43 /// Serialize and deserialize user inventory items as an external format.
44 /// </summary> 44 /// </summary>
45 /// XXX: Please do not use yet.
46 public class UserInventoryItemSerializer 45 public class UserInventoryItemSerializer
47 { 46 {
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
diff --git a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs
index f50b49a..c685a15 100644
--- a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs
@@ -33,8 +33,11 @@ using OpenSim.Framework;
33namespace OpenSim.Framework.Serialization.External 33namespace OpenSim.Framework.Serialization.External
34{ 34{
35 /// <summary> 35 /// <summary>
36 /// Serialize and deserialize region settings as an external format. 36 /// Serialize and deserialize user profiles as an external format.
37 /// </summary> 37 /// </summary>
38 /// <remarks>
39 /// Currently UNUSED.
40 /// </remarks>
38 public class UserProfileSerializer 41 public class UserProfileSerializer
39 { 42 {
40 public const int MAJOR_VERSION = 0; 43 public const int MAJOR_VERSION = 0;
diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs
index 3607ce8..11a3a0a 100644
--- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs
+++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs
@@ -27,11 +27,12 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using OpenSim.Framework;
31using OpenSim.Framework.Serialization.External;
32using OpenMetaverse; 30using OpenMetaverse;
33using OpenMetaverse.StructuredData; 31using OpenMetaverse.StructuredData;
34using NUnit.Framework; 32using NUnit.Framework;
33using OpenSim.Framework;
34using OpenSim.Framework.Serialization.External;
35using OpenSim.Tests.Common;
35 36
36namespace OpenSim.Framework.Serialization.Tests 37namespace OpenSim.Framework.Serialization.Tests
37{ 38{
@@ -92,6 +93,8 @@ namespace OpenSim.Framework.Serialization.Tests
92 [Test] 93 [Test]
93 public void LandDataSerializerSerializeTest() 94 public void LandDataSerializerSerializeTest()
94 { 95 {
96 TestHelpers.InMethod();
97
95 string serialized = LandDataSerializer.Serialize(this.land).Replace("\r\n", "\n"); 98 string serialized = LandDataSerializer.Serialize(this.land).Replace("\r\n", "\n");
96 Assert.That(serialized.Length > 0, "Serialize(LandData) returned empty string"); 99 Assert.That(serialized.Length > 0, "Serialize(LandData) returned empty string");
97 100
@@ -112,20 +115,32 @@ namespace OpenSim.Framework.Serialization.Tests
112 /// Test the LandDataSerializer.Deserialize() method 115 /// Test the LandDataSerializer.Deserialize() method
113 /// </summary> 116 /// </summary>
114 [Test] 117 [Test]
115 public void TestLandDataSerializerDeserializeFromStringTest() 118 public void TestLandDataDeserializeNoAccessLists()
119 {
120 TestHelpers.InMethod();
121 log4net.Config.XmlConfigurator.Configure();
122
123 LandData ld = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerialized);
124 Assert.That(ld != null, "Deserialize(string) returned null");
125 Assert.That(ld.GlobalID == this.land.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID");
126 Assert.That(ld.Name == this.land.Name, "Reified LandData.Name != original LandData.Name");
127 }
128
129 [Test]
130 public void TestLandDataDeserializeWithAccessLists()
116 { 131 {
117 LandData reifiedLandData = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerialized); 132 TestHelpers.InMethod();
118 Assert.That(reifiedLandData != null, "Deserialize(string) returned null"); 133// log4net.Config.XmlConfigurator.Configure();
119 Assert.That(reifiedLandData.GlobalID == this.land.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID");
120 Assert.That(reifiedLandData.Name == this.land.Name, "Reified LandData.Name != original LandData.Name");
121 134
122 LandData reifiedLandDataWithParcelAccessList = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerializedWithParcelAccessList); 135 LandData ld = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerializedWithParcelAccessList);
123 Assert.That(reifiedLandDataWithParcelAccessList != null, 136 Assert.That(ld != null,
124 "Deserialize(string) returned null (pre-serialized with parcel access list)"); 137 "Deserialize(string) returned null (pre-serialized with parcel access list)");
125 Assert.That(reifiedLandDataWithParcelAccessList.GlobalID == this.landWithParcelAccessList.GlobalID, 138 Assert.That(ld.GlobalID == this.landWithParcelAccessList.GlobalID,
126 "Reified LandData.GlobalID != original LandData.GlobalID (pre-serialized with parcel access list)"); 139 "Reified LandData.GlobalID != original LandData.GlobalID (pre-serialized with parcel access list)");
127 Assert.That(reifiedLandDataWithParcelAccessList.Name == this.landWithParcelAccessList.Name, 140 Assert.That(ld.Name == this.landWithParcelAccessList.Name,
128 "Reified LandData.Name != original LandData.Name (pre-serialized with parcel access list)"); 141 "Reified LandData.Name != original LandData.Name (pre-serialized with parcel access list)");
142 Assert.That(ld.ParcelAccessList.Count, Is.EqualTo(2));
143 Assert.That(ld.ParcelAccessList[0].AgentID, Is.EqualTo(UUID.Parse("62d65d45-c91a-4f77-862c-46557d978b6c")));
129 } 144 }
130 } 145 }
131} 146}