diff options
Diffstat (limited to '')
6 files changed, 1549 insertions, 0 deletions
diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs new file mode 100644 index 0000000..55640ac --- /dev/null +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs | |||
@@ -0,0 +1,411 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Diagnostics; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using System.Xml; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | |||
38 | namespace OpenSim.Framework.Serialization.External | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Utilities for manipulating external representations of data structures in OpenSim | ||
42 | /// </summary> | ||
43 | public class ExternalRepresentationUtils | ||
44 | { | ||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | /// <summary> | ||
48 | /// Populate a node with data read from xml using a dictinoary of processors | ||
49 | /// </summary> | ||
50 | /// <param name="nodeToFill"></param> | ||
51 | /// <param name="processors"></param> | ||
52 | /// <param name="xtr"></param> | ||
53 | /// <returns>true on successful, false if there were any processing failures</returns> | ||
54 | public static bool ExecuteReadProcessors<NodeType>( | ||
55 | NodeType nodeToFill, Dictionary<string, Action<NodeType, XmlReader>> processors, XmlReader xtr) | ||
56 | { | ||
57 | return ExecuteReadProcessors( | ||
58 | nodeToFill, | ||
59 | processors, | ||
60 | xtr, | ||
61 | (o, nodeName, e) => { | ||
62 | m_log.Debug(string.Format("[ExternalRepresentationUtils]: Error while parsing element {0} ", | ||
63 | nodeName), e); | ||
64 | }); | ||
65 | } | ||
66 | |||
67 | /// <summary> | ||
68 | /// Populate a node with data read from xml using a dictinoary of processors | ||
69 | /// </summary> | ||
70 | /// <param name="nodeToFill"></param> | ||
71 | /// <param name="processors"></param> | ||
72 | /// <param name="xtr"></param> | ||
73 | /// <param name="parseExceptionAction"> | ||
74 | /// Action to take if there is a parsing problem. This will usually just be to log the exception | ||
75 | /// </param> | ||
76 | /// <returns>true on successful, false if there were any processing failures</returns> | ||
77 | public static bool ExecuteReadProcessors<NodeType>( | ||
78 | NodeType nodeToFill, | ||
79 | Dictionary<string, Action<NodeType, XmlReader>> processors, | ||
80 | XmlReader xtr, | ||
81 | Action<NodeType, string, Exception> parseExceptionAction) | ||
82 | { | ||
83 | bool errors = false; | ||
84 | int numErrors = 0; | ||
85 | |||
86 | Stopwatch timer = new Stopwatch(); | ||
87 | timer.Start(); | ||
88 | |||
89 | string nodeName = string.Empty; | ||
90 | while (xtr.NodeType != XmlNodeType.EndElement) | ||
91 | { | ||
92 | nodeName = xtr.Name; | ||
93 | |||
94 | // m_log.DebugFormat("[ExternalRepresentationUtils]: Processing node: {0}", nodeName); | ||
95 | |||
96 | Action<NodeType, XmlReader> p = null; | ||
97 | if (processors.TryGetValue(xtr.Name, out p)) | ||
98 | { | ||
99 | // m_log.DebugFormat("[ExternalRepresentationUtils]: Found processor for {0}", nodeName); | ||
100 | |||
101 | try | ||
102 | { | ||
103 | p(nodeToFill, xtr); | ||
104 | } | ||
105 | catch (Exception e) | ||
106 | { | ||
107 | errors = true; | ||
108 | parseExceptionAction(nodeToFill, nodeName, e); | ||
109 | |||
110 | if (xtr.EOF) | ||
111 | { | ||
112 | m_log.Debug("[ExternalRepresentationUtils]: Aborting ExecuteReadProcessors due to unexpected end of XML"); | ||
113 | break; | ||
114 | } | ||
115 | |||
116 | if (++numErrors == 10) | ||
117 | { | ||
118 | m_log.Debug("[ExternalRepresentationUtils]: Aborting ExecuteReadProcessors due to too many parsing errors"); | ||
119 | break; | ||
120 | } | ||
121 | |||
122 | if (xtr.NodeType == XmlNodeType.EndElement) | ||
123 | xtr.Read(); | ||
124 | } | ||
125 | } | ||
126 | else | ||
127 | { | ||
128 | // m_log.DebugFormat("[ExternalRepresentationUtils]: found unknown element \"{0}\"", nodeName); | ||
129 | xtr.ReadOuterXml(); // ignore | ||
130 | } | ||
131 | |||
132 | if (timer.Elapsed.TotalSeconds >= 60) | ||
133 | { | ||
134 | m_log.Debug("[ExternalRepresentationUtils]: Aborting ExecuteReadProcessors due to timeout"); | ||
135 | errors = true; | ||
136 | break; | ||
137 | } | ||
138 | } | ||
139 | |||
140 | return errors; | ||
141 | } | ||
142 | |||
143 | /// <summary> | ||
144 | /// Takes a XML representation of a SceneObjectPart and returns another XML representation | ||
145 | /// with creator data added to it. | ||
146 | /// </summary> | ||
147 | /// <param name="xml">The SceneObjectPart represented in XML2</param> | ||
148 | /// <param name="homeURL">The URL of the user agents service (home) for the creator</param> | ||
149 | /// <param name="userService">The service for retrieving user account information</param> | ||
150 | /// <param name="scopeID">The scope of the user account information (Grid ID)</param> | ||
151 | /// <returns>The SceneObjectPart represented in XML2</returns> | ||
152 | [Obsolete("This method is deprecated. Use RewriteSOP instead.")] | ||
153 | public static string RewriteSOP_Old(string xml, string homeURL, IUserAccountService userService, UUID scopeID) | ||
154 | { | ||
155 | if (xml == string.Empty || homeURL == string.Empty || userService == null) | ||
156 | return xml; | ||
157 | |||
158 | XmlDocument doc = new XmlDocument(); | ||
159 | doc.LoadXml(xml); | ||
160 | XmlNodeList sops = doc.GetElementsByTagName("SceneObjectPart"); | ||
161 | |||
162 | foreach (XmlNode sop in sops) | ||
163 | { | ||
164 | UserAccount creator = null; | ||
165 | bool hasCreatorData = false; | ||
166 | XmlNodeList nodes = sop.ChildNodes; | ||
167 | foreach (XmlNode node in nodes) | ||
168 | { | ||
169 | if (node.Name == "CreatorID") | ||
170 | { | ||
171 | UUID uuid = UUID.Zero; | ||
172 | UUID.TryParse(node.InnerText, out uuid); | ||
173 | creator = userService.GetUserAccount(scopeID, uuid); | ||
174 | } | ||
175 | |||
176 | if (node.Name == "CreatorData" && node.InnerText != null && node.InnerText != string.Empty) | ||
177 | hasCreatorData = true; | ||
178 | |||
179 | //if (node.Name == "OwnerID") | ||
180 | //{ | ||
181 | // UserAccount owner = GetUser(node.InnerText); | ||
182 | // if (owner != null) | ||
183 | // node.InnerText = m_ProfileServiceURL + "/" + node.InnerText + "/" + owner.FirstName + " " + owner.LastName; | ||
184 | //} | ||
185 | } | ||
186 | if (!hasCreatorData && creator != null) | ||
187 | { | ||
188 | XmlElement creatorData = doc.CreateElement("CreatorData"); | ||
189 | creatorData.InnerText = CalcCreatorData(homeURL, creator.FirstName + " " + creator.LastName); | ||
190 | sop.AppendChild(creatorData); | ||
191 | } | ||
192 | } | ||
193 | |||
194 | using (StringWriter wr = new StringWriter()) | ||
195 | { | ||
196 | doc.Save(wr); | ||
197 | return wr.ToString(); | ||
198 | } | ||
199 | } | ||
200 | |||
201 | /// <summary> | ||
202 | /// Takes a XML representation of a SceneObjectPart and returns another XML representation | ||
203 | /// with creator data added to it. | ||
204 | /// </summary> | ||
205 | /// <param name="xml">The SceneObjectPart represented in XML2</param> | ||
206 | /// <param name="sceneName">An identifier for the component that's calling this function</param> | ||
207 | /// <param name="homeURL">The URL of the user agents service (home) for the creator</param> | ||
208 | /// <param name="userService">The service for retrieving user account information</param> | ||
209 | /// <param name="scopeID">The scope of the user account information (Grid ID)</param> | ||
210 | /// <returns>The SceneObjectPart represented in XML2</returns> | ||
211 | public static string RewriteSOP(string xmlData, string sceneName, string homeURL, IUserAccountService userService, UUID scopeID) | ||
212 | { | ||
213 | // Console.WriteLine("Input XML [{0}]", xmlData); | ||
214 | if (xmlData == string.Empty || homeURL == string.Empty || userService == null) | ||
215 | return xmlData; | ||
216 | |||
217 | // Deal with bug | ||
218 | xmlData = ExternalRepresentationUtils.SanitizeXml(xmlData); | ||
219 | |||
220 | using (StringWriter sw = new StringWriter()) | ||
221 | using (XmlTextWriter writer = new XmlTextWriter(sw)) | ||
222 | using (XmlTextReader wrappedReader = new XmlTextReader(xmlData, XmlNodeType.Element, null)) | ||
223 | using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment })) | ||
224 | { | ||
225 | TransformXml(reader, writer, sceneName, homeURL, userService, scopeID); | ||
226 | |||
227 | // Console.WriteLine("Output: [{0}]", sw.ToString()); | ||
228 | |||
229 | return sw.ToString(); | ||
230 | } | ||
231 | } | ||
232 | |||
233 | protected static void TransformXml(XmlReader reader, XmlWriter writer, string sceneName, string homeURI, IUserAccountService userAccountService, UUID scopeID) | ||
234 | { | ||
235 | // m_log.DebugFormat("[HG ASSET MAPPER]: Transforming XML"); | ||
236 | |||
237 | int sopDepth = -1; | ||
238 | UserAccount creator = null; | ||
239 | bool hasCreatorData = false; | ||
240 | |||
241 | while (reader.Read()) | ||
242 | { | ||
243 | // Console.WriteLine("Depth: {0}, name {1}", reader.Depth, reader.Name); | ||
244 | |||
245 | switch (reader.NodeType) | ||
246 | { | ||
247 | case XmlNodeType.Attribute: | ||
248 | // Console.WriteLine("FOUND ATTRIBUTE {0}", reader.Name); | ||
249 | writer.WriteAttributeString(reader.Name, reader.Value); | ||
250 | break; | ||
251 | |||
252 | case XmlNodeType.CDATA: | ||
253 | writer.WriteCData(reader.Value); | ||
254 | break; | ||
255 | |||
256 | case XmlNodeType.Comment: | ||
257 | writer.WriteComment(reader.Value); | ||
258 | break; | ||
259 | |||
260 | case XmlNodeType.DocumentType: | ||
261 | writer.WriteDocType(reader.Name, reader.Value, null, null); | ||
262 | break; | ||
263 | |||
264 | case XmlNodeType.Element: | ||
265 | // m_log.DebugFormat("Depth {0} at element {1}", reader.Depth, reader.Name); | ||
266 | |||
267 | writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); | ||
268 | |||
269 | if (reader.HasAttributes) | ||
270 | { | ||
271 | while (reader.MoveToNextAttribute()) | ||
272 | writer.WriteAttributeString(reader.Name, reader.Value); | ||
273 | |||
274 | reader.MoveToElement(); | ||
275 | } | ||
276 | |||
277 | if (reader.LocalName == "SceneObjectPart") | ||
278 | { | ||
279 | if (sopDepth < 0) | ||
280 | { | ||
281 | sopDepth = reader.Depth; | ||
282 | // m_log.DebugFormat("[HG ASSET MAPPER]: Set sopDepth to {0}", sopDepth); | ||
283 | } | ||
284 | } | ||
285 | else | ||
286 | { | ||
287 | if (sopDepth >= 0 && reader.Depth == sopDepth + 1) | ||
288 | { | ||
289 | if (reader.Name == "CreatorID") | ||
290 | { | ||
291 | reader.Read(); | ||
292 | if (reader.NodeType == XmlNodeType.Element && reader.Name == "Guid" || reader.Name == "UUID") | ||
293 | { | ||
294 | reader.Read(); | ||
295 | |||
296 | if (reader.NodeType == XmlNodeType.Text) | ||
297 | { | ||
298 | UUID uuid = UUID.Zero; | ||
299 | UUID.TryParse(reader.Value, out uuid); | ||
300 | creator = userAccountService.GetUserAccount(scopeID, uuid); | ||
301 | writer.WriteElementString("UUID", reader.Value); | ||
302 | reader.Read(); | ||
303 | } | ||
304 | else | ||
305 | { | ||
306 | // If we unexpected run across mixed content in this node, still carry on | ||
307 | // transforming the subtree (this replicates earlier behaviour). | ||
308 | TransformXml(reader, writer, sceneName, homeURI, userAccountService, scopeID); | ||
309 | } | ||
310 | } | ||
311 | else | ||
312 | { | ||
313 | // If we unexpected run across mixed content in this node, still carry on | ||
314 | // transforming the subtree (this replicates earlier behaviour). | ||
315 | TransformXml(reader, writer, sceneName, homeURI, userAccountService, scopeID); | ||
316 | } | ||
317 | } | ||
318 | else if (reader.Name == "CreatorData") | ||
319 | { | ||
320 | reader.Read(); | ||
321 | if (reader.NodeType == XmlNodeType.Text) | ||
322 | { | ||
323 | hasCreatorData = true; | ||
324 | writer.WriteString(reader.Value); | ||
325 | } | ||
326 | else | ||
327 | { | ||
328 | // If we unexpected run across mixed content in this node, still carry on | ||
329 | // transforming the subtree (this replicates earlier behaviour). | ||
330 | TransformXml(reader, writer, sceneName, homeURI, userAccountService, scopeID); | ||
331 | } | ||
332 | } | ||
333 | } | ||
334 | } | ||
335 | |||
336 | if (reader.IsEmptyElement) | ||
337 | { | ||
338 | // m_log.DebugFormat("[HG ASSET MAPPER]: Writing end for empty element {0}", reader.Name); | ||
339 | writer.WriteEndElement(); | ||
340 | } | ||
341 | |||
342 | break; | ||
343 | |||
344 | case XmlNodeType.EndElement: | ||
345 | // m_log.DebugFormat("Depth {0} at EndElement", reader.Depth); | ||
346 | if (sopDepth == reader.Depth) | ||
347 | { | ||
348 | if (!hasCreatorData && creator != null) | ||
349 | writer.WriteElementString(reader.Prefix, "CreatorData", reader.NamespaceURI, string.Format("{0};{1} {2}", homeURI, creator.FirstName, creator.LastName)); | ||
350 | |||
351 | // m_log.DebugFormat("[HG ASSET MAPPER]: Reset sopDepth"); | ||
352 | sopDepth = -1; | ||
353 | creator = null; | ||
354 | hasCreatorData = false; | ||
355 | } | ||
356 | writer.WriteEndElement(); | ||
357 | break; | ||
358 | |||
359 | case XmlNodeType.EntityReference: | ||
360 | writer.WriteEntityRef(reader.Name); | ||
361 | break; | ||
362 | |||
363 | case XmlNodeType.ProcessingInstruction: | ||
364 | writer.WriteProcessingInstruction(reader.Name, reader.Value); | ||
365 | break; | ||
366 | |||
367 | case XmlNodeType.Text: | ||
368 | writer.WriteString(reader.Value); | ||
369 | break; | ||
370 | |||
371 | case XmlNodeType.XmlDeclaration: | ||
372 | // For various reasons, not all serializations have xml declarations (or consistent ones) | ||
373 | // and as it's embedded inside a byte stream we don't need it anyway, so ignore. | ||
374 | break; | ||
375 | |||
376 | default: | ||
377 | m_log.WarnFormat( | ||
378 | "[HG ASSET MAPPER]: Unrecognized node {0} in asset XML transform in {1}", | ||
379 | reader.NodeType, sceneName); | ||
380 | break; | ||
381 | } | ||
382 | } | ||
383 | } | ||
384 | |||
385 | public static string CalcCreatorData(string homeURL, string name) | ||
386 | { | ||
387 | return homeURL + ";" + name; | ||
388 | } | ||
389 | |||
390 | internal static string CalcCreatorData(string homeURL, UUID uuid, string name) | ||
391 | { | ||
392 | return homeURL + "/" + uuid + ";" + name; | ||
393 | } | ||
394 | |||
395 | /// <summary> | ||
396 | /// Sanitation for bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8) | ||
397 | /// </summary> | ||
398 | /// <param name="xmlData"></param> | ||
399 | /// <returns></returns> | ||
400 | public static string SanitizeXml(string xmlData) | ||
401 | { | ||
402 | string fixedData = xmlData; | ||
403 | if (fixedData != null) | ||
404 | // Loop, because it may contain multiple | ||
405 | while (fixedData.Contains("xmlns:xmlns:")) | ||
406 | fixedData = fixedData.Replace("xmlns:xmlns:", "xmlns:"); | ||
407 | return fixedData; | ||
408 | } | ||
409 | |||
410 | } | ||
411 | } | ||
diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs new file mode 100644 index 0000000..e42d56f --- /dev/null +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs | |||
@@ -0,0 +1,266 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using System.Xml; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | |||
38 | namespace OpenSim.Framework.Serialization.External | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Serialize and deserialize LandData as an external format. | ||
42 | /// </summary> | ||
43 | public class LandDataSerializer | ||
44 | { | ||
45 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | private static Dictionary<string, Action<LandData, XmlReader>> m_ldProcessors | ||
48 | = new Dictionary<string, Action<LandData, XmlReader>>(); | ||
49 | |||
50 | private static Dictionary<string, Action<LandAccessEntry, XmlReader>> m_laeProcessors | ||
51 | = new Dictionary<string, Action<LandAccessEntry, XmlReader>>(); | ||
52 | |||
53 | static LandDataSerializer() | ||
54 | { | ||
55 | // LandData processors | ||
56 | m_ldProcessors.Add( | ||
57 | "Area", (ld, xtr) => ld.Area = Convert.ToInt32(xtr.ReadElementString("Area"))); | ||
58 | m_ldProcessors.Add( | ||
59 | "AuctionID", (ld, xtr) => ld.AuctionID = Convert.ToUInt32(xtr.ReadElementString("AuctionID"))); | ||
60 | m_ldProcessors.Add( | ||
61 | "AuthBuyerID", (ld, xtr) => ld.AuthBuyerID = UUID.Parse(xtr.ReadElementString("AuthBuyerID"))); | ||
62 | m_ldProcessors.Add( | ||
63 | "Category", (ld, xtr) => ld.Category = (ParcelCategory)Convert.ToSByte(xtr.ReadElementString("Category"))); | ||
64 | m_ldProcessors.Add( | ||
65 | "ClaimDate", (ld, xtr) => ld.ClaimDate = Convert.ToInt32(xtr.ReadElementString("ClaimDate"))); | ||
66 | m_ldProcessors.Add( | ||
67 | "ClaimPrice", (ld, xtr) => ld.ClaimPrice = Convert.ToInt32(xtr.ReadElementString("ClaimPrice"))); | ||
68 | m_ldProcessors.Add( | ||
69 | "GlobalID", (ld, xtr) => ld.GlobalID = UUID.Parse(xtr.ReadElementString("GlobalID"))); | ||
70 | m_ldProcessors.Add( | ||
71 | "GroupID", (ld, xtr) => ld.GroupID = UUID.Parse(xtr.ReadElementString("GroupID"))); | ||
72 | m_ldProcessors.Add( | ||
73 | "IsGroupOwned", (ld, xtr) => ld.IsGroupOwned = Convert.ToBoolean(xtr.ReadElementString("IsGroupOwned"))); | ||
74 | m_ldProcessors.Add( | ||
75 | "Bitmap", (ld, xtr) => ld.Bitmap = Convert.FromBase64String(xtr.ReadElementString("Bitmap"))); | ||
76 | m_ldProcessors.Add( | ||
77 | "Description", (ld, xtr) => ld.Description = xtr.ReadElementString("Description")); | ||
78 | m_ldProcessors.Add( | ||
79 | "Flags", (ld, xtr) => ld.Flags = Convert.ToUInt32(xtr.ReadElementString("Flags"))); | ||
80 | m_ldProcessors.Add( | ||
81 | "LandingType", (ld, xtr) => ld.LandingType = Convert.ToByte(xtr.ReadElementString("LandingType"))); | ||
82 | m_ldProcessors.Add( | ||
83 | "Name", (ld, xtr) => ld.Name = xtr.ReadElementString("Name")); | ||
84 | m_ldProcessors.Add( | ||
85 | "Status", (ld, xtr) => ld.Status = (ParcelStatus)Convert.ToSByte(xtr.ReadElementString("Status"))); | ||
86 | m_ldProcessors.Add( | ||
87 | "LocalID", (ld, xtr) => ld.LocalID = Convert.ToInt32(xtr.ReadElementString("LocalID"))); | ||
88 | m_ldProcessors.Add( | ||
89 | "MediaAutoScale", (ld, xtr) => ld.MediaAutoScale = Convert.ToByte(xtr.ReadElementString("MediaAutoScale"))); | ||
90 | m_ldProcessors.Add( | ||
91 | "MediaID", (ld, xtr) => ld.MediaID = UUID.Parse(xtr.ReadElementString("MediaID"))); | ||
92 | m_ldProcessors.Add( | ||
93 | "MediaURL", (ld, xtr) => ld.MediaURL = xtr.ReadElementString("MediaURL")); | ||
94 | m_ldProcessors.Add( | ||
95 | "MusicURL", (ld, xtr) => ld.MusicURL = xtr.ReadElementString("MusicURL")); | ||
96 | m_ldProcessors.Add( | ||
97 | "OwnerID", (ld, xtr) => ld.OwnerID = UUID.Parse(xtr.ReadElementString("OwnerID"))); | ||
98 | |||
99 | m_ldProcessors.Add( | ||
100 | "ParcelAccessList", ProcessParcelAccessList); | ||
101 | |||
102 | m_ldProcessors.Add( | ||
103 | "PassHours", (ld, xtr) => ld.PassHours = Convert.ToSingle(xtr.ReadElementString("PassHours"))); | ||
104 | m_ldProcessors.Add( | ||
105 | "PassPrice", (ld, xtr) => ld.PassPrice = Convert.ToInt32(xtr.ReadElementString("PassPrice"))); | ||
106 | m_ldProcessors.Add( | ||
107 | "SalePrice", (ld, xtr) => ld.SalePrice = Convert.ToInt32(xtr.ReadElementString("SalePrice"))); | ||
108 | m_ldProcessors.Add( | ||
109 | "SnapshotID", (ld, xtr) => ld.SnapshotID = UUID.Parse(xtr.ReadElementString("SnapshotID"))); | ||
110 | m_ldProcessors.Add( | ||
111 | "UserLocation", (ld, xtr) => ld.UserLocation = Vector3.Parse(xtr.ReadElementString("UserLocation"))); | ||
112 | m_ldProcessors.Add( | ||
113 | "UserLookAt", (ld, xtr) => ld.UserLookAt = Vector3.Parse(xtr.ReadElementString("UserLookAt"))); | ||
114 | |||
115 | // No longer used here // | ||
116 | // m_ldProcessors.Add("Dwell", (landData, xtr) => return); | ||
117 | |||
118 | m_ldProcessors.Add( | ||
119 | "OtherCleanTime", (ld, xtr) => ld.OtherCleanTime = Convert.ToInt32(xtr.ReadElementString("OtherCleanTime"))); | ||
120 | |||
121 | // LandAccessEntryProcessors | ||
122 | m_laeProcessors.Add( | ||
123 | "AgentID", (lae, xtr) => lae.AgentID = UUID.Parse(xtr.ReadElementString("AgentID"))); | ||
124 | m_laeProcessors.Add( | ||
125 | "Time", (lae, xtr) => | ||
126 | { | ||
127 | // We really don't care about temp vs perm here and this | ||
128 | // would break on old oars. Assume all bans are perm | ||
129 | xtr.ReadElementString("Time"); | ||
130 | lae.Expires = 0; // Convert.ToUint( xtr.ReadElementString("Time")); | ||
131 | } | ||
132 | ); | ||
133 | m_laeProcessors.Add( | ||
134 | "AccessList", (lae, xtr) => lae.Flags = (AccessList)Convert.ToUInt32(xtr.ReadElementString("AccessList"))); | ||
135 | } | ||
136 | |||
137 | public static void ProcessParcelAccessList(LandData ld, XmlReader xtr) | ||
138 | { | ||
139 | if (!xtr.IsEmptyElement) | ||
140 | { | ||
141 | while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) | ||
142 | { | ||
143 | LandAccessEntry lae = new LandAccessEntry(); | ||
144 | |||
145 | xtr.ReadStartElement("ParcelAccessEntry"); | ||
146 | |||
147 | ExternalRepresentationUtils.ExecuteReadProcessors<LandAccessEntry>(lae, m_laeProcessors, xtr); | ||
148 | |||
149 | xtr.ReadEndElement(); | ||
150 | |||
151 | ld.ParcelAccessList.Add(lae); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | xtr.Read(); | ||
156 | } | ||
157 | |||
158 | /// <summary> | ||
159 | /// Reify/deserialize landData | ||
160 | /// </summary> | ||
161 | /// <param name="serializedLandData"></param> | ||
162 | /// <returns></returns> | ||
163 | /// <exception cref="System.Xml.XmlException"></exception> | ||
164 | public static LandData Deserialize(byte[] serializedLandData) | ||
165 | { | ||
166 | return Deserialize(Encoding.UTF8.GetString(serializedLandData, 0, serializedLandData.Length)); | ||
167 | } | ||
168 | |||
169 | /// <summary> | ||
170 | /// Reify/deserialize landData | ||
171 | /// </summary> | ||
172 | /// <param name="serializedLandData"></param> | ||
173 | /// <returns></returns> | ||
174 | /// <exception cref="System.Xml.XmlException"></exception> | ||
175 | public static LandData Deserialize(string serializedLandData) | ||
176 | { | ||
177 | LandData landData = new LandData(); | ||
178 | |||
179 | using (XmlTextReader reader = new XmlTextReader(new StringReader(serializedLandData))) | ||
180 | { | ||
181 | reader.ReadStartElement("LandData"); | ||
182 | |||
183 | ExternalRepresentationUtils.ExecuteReadProcessors<LandData>(landData, m_ldProcessors, reader); | ||
184 | |||
185 | reader.ReadEndElement(); | ||
186 | } | ||
187 | |||
188 | return landData; | ||
189 | } | ||
190 | |||
191 | /// <summary> | ||
192 | /// Serialize land data | ||
193 | /// </summary> | ||
194 | /// <param name='landData'></param> | ||
195 | /// <param name='options'> | ||
196 | /// Serialization options. | ||
197 | /// Can be null if there are no options. | ||
198 | /// "wipe-owners" will write UUID.Zero rather than the ownerID so that a later reload loads all parcels with the estate owner as the owner | ||
199 | /// </param> | ||
200 | public static string Serialize(LandData landData, Dictionary<string, object> options) | ||
201 | { | ||
202 | StringWriter sw = new StringWriter(); | ||
203 | XmlTextWriter xtw = new XmlTextWriter(sw); | ||
204 | xtw.Formatting = Formatting.Indented; | ||
205 | |||
206 | xtw.WriteStartDocument(); | ||
207 | xtw.WriteStartElement("LandData"); | ||
208 | |||
209 | xtw.WriteElementString("Area", Convert.ToString(landData.Area)); | ||
210 | xtw.WriteElementString("AuctionID", Convert.ToString(landData.AuctionID)); | ||
211 | xtw.WriteElementString("AuthBuyerID", landData.AuthBuyerID.ToString()); | ||
212 | xtw.WriteElementString("Category", Convert.ToString((sbyte)landData.Category)); | ||
213 | xtw.WriteElementString("ClaimDate", Convert.ToString(landData.ClaimDate)); | ||
214 | xtw.WriteElementString("ClaimPrice", Convert.ToString(landData.ClaimPrice)); | ||
215 | xtw.WriteElementString("GlobalID", landData.GlobalID.ToString()); | ||
216 | |||
217 | UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : landData.GroupID; | ||
218 | xtw.WriteElementString("GroupID", groupID.ToString()); | ||
219 | |||
220 | bool isGroupOwned = options.ContainsKey("wipe-owners") ? false : landData.IsGroupOwned; | ||
221 | xtw.WriteElementString("IsGroupOwned", Convert.ToString(isGroupOwned)); | ||
222 | |||
223 | xtw.WriteElementString("Bitmap", Convert.ToBase64String(landData.Bitmap)); | ||
224 | xtw.WriteElementString("Description", landData.Description); | ||
225 | xtw.WriteElementString("Flags", Convert.ToString((uint)landData.Flags)); | ||
226 | xtw.WriteElementString("LandingType", Convert.ToString((byte)landData.LandingType)); | ||
227 | xtw.WriteElementString("Name", landData.Name); | ||
228 | xtw.WriteElementString("Status", Convert.ToString((sbyte)landData.Status)); | ||
229 | xtw.WriteElementString("LocalID", landData.LocalID.ToString()); | ||
230 | xtw.WriteElementString("MediaAutoScale", Convert.ToString(landData.MediaAutoScale)); | ||
231 | xtw.WriteElementString("MediaID", landData.MediaID.ToString()); | ||
232 | xtw.WriteElementString("MediaURL", landData.MediaURL); | ||
233 | xtw.WriteElementString("MusicURL", landData.MusicURL); | ||
234 | |||
235 | UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : landData.OwnerID; | ||
236 | xtw.WriteElementString("OwnerID", ownerID.ToString()); | ||
237 | |||
238 | xtw.WriteStartElement("ParcelAccessList"); | ||
239 | foreach (LandAccessEntry pal in landData.ParcelAccessList) | ||
240 | { | ||
241 | xtw.WriteStartElement("ParcelAccessEntry"); | ||
242 | xtw.WriteElementString("AgentID", pal.AgentID.ToString()); | ||
243 | xtw.WriteElementString("Time", pal.Expires.ToString()); | ||
244 | xtw.WriteElementString("AccessList", Convert.ToString((uint)pal.Flags)); | ||
245 | xtw.WriteEndElement(); | ||
246 | } | ||
247 | xtw.WriteEndElement(); | ||
248 | |||
249 | xtw.WriteElementString("PassHours", Convert.ToString(landData.PassHours)); | ||
250 | xtw.WriteElementString("PassPrice", Convert.ToString(landData.PassPrice)); | ||
251 | xtw.WriteElementString("SalePrice", Convert.ToString(landData.SalePrice)); | ||
252 | xtw.WriteElementString("SnapshotID", landData.SnapshotID.ToString()); | ||
253 | xtw.WriteElementString("UserLocation", landData.UserLocation.ToString()); | ||
254 | xtw.WriteElementString("UserLookAt", landData.UserLookAt.ToString()); | ||
255 | xtw.WriteElementString("Dwell", "0"); | ||
256 | xtw.WriteElementString("OtherCleanTime", Convert.ToString(landData.OtherCleanTime)); | ||
257 | |||
258 | xtw.WriteEndElement(); | ||
259 | |||
260 | xtw.Close(); | ||
261 | sw.Close(); | ||
262 | |||
263 | return sw.ToString(); | ||
264 | } | ||
265 | } | ||
266 | } | ||
diff --git a/OpenSim/Framework/Serialization/External/OspResolver.cs b/OpenSim/Framework/Serialization/External/OspResolver.cs new file mode 100644 index 0000000..fa7160f --- /dev/null +++ b/OpenSim/Framework/Serialization/External/OspResolver.cs | |||
@@ -0,0 +1,208 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Reflection; | ||
29 | using System.Text; | ||
30 | using log4net; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | |||
35 | namespace OpenSim.Framework.Serialization | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Resolves OpenSim Profile Anchors (OSPA). An OSPA is a string used to provide information for | ||
39 | /// identifying user profiles or supplying a simple name if no profile is available. | ||
40 | /// </summary> | ||
41 | public class OspResolver | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | public const string OSPA_PREFIX = "ospa:"; | ||
46 | public const string OSPA_NAME_KEY = "n"; | ||
47 | public const string OSPA_NAME_VALUE_SEPARATOR = " "; | ||
48 | public const string OSPA_TUPLE_SEPARATOR = "|"; | ||
49 | public static readonly char[] OSPA_TUPLE_SEPARATOR_ARRAY = OSPA_TUPLE_SEPARATOR.ToCharArray(); | ||
50 | public const string OSPA_PAIR_SEPARATOR = "="; | ||
51 | |||
52 | /// <summary> | ||
53 | /// Make an OSPA given a user UUID | ||
54 | /// </summary> | ||
55 | /// <param name="userId"></param> | ||
56 | /// <param name="commsManager"></param> | ||
57 | /// <returns>The OSPA. Null if a user with the given UUID could not be found.</returns> | ||
58 | public static string MakeOspa(UUID userId, IUserAccountService userService) | ||
59 | { | ||
60 | if (userService == null) | ||
61 | { | ||
62 | m_log.Warn("[OSP RESOLVER]: UserService is null"); | ||
63 | return userId.ToString(); | ||
64 | } | ||
65 | |||
66 | UserAccount account = userService.GetUserAccount(UUID.Zero, userId); | ||
67 | if (account != null) | ||
68 | { | ||
69 | return MakeOspa(account.FirstName, account.LastName); | ||
70 | } | ||
71 | // else | ||
72 | // { | ||
73 | // m_log.WarnFormat("[OSP RESOLVER]: No user account for {0}", userId); | ||
74 | // System.Console.WriteLine("[OSP RESOLVER]: No user account for {0}", userId); | ||
75 | // } | ||
76 | |||
77 | return null; | ||
78 | } | ||
79 | |||
80 | /// <summary> | ||
81 | /// Make an OSPA given a user name | ||
82 | /// </summary> | ||
83 | /// <param name="name"></param> | ||
84 | /// <returns></returns> | ||
85 | public static string MakeOspa(string firstName, string lastName) | ||
86 | { | ||
87 | string ospa | ||
88 | = OSPA_PREFIX + OSPA_NAME_KEY + OSPA_PAIR_SEPARATOR + firstName + OSPA_NAME_VALUE_SEPARATOR + lastName; | ||
89 | |||
90 | // m_log.DebugFormat("[OSP RESOLVER]: Made OSPA {0} for {1} {2}", ospa, firstName, lastName); | ||
91 | // System.Console.WriteLine("[OSP RESOLVER]: Made OSPA {0} for {1} {2}", ospa, firstName, lastName); | ||
92 | |||
93 | return ospa; | ||
94 | } | ||
95 | |||
96 | /// <summary> | ||
97 | /// Resolve an osp string into the most suitable internal OpenSim identifier. | ||
98 | /// </summary> | ||
99 | /// | ||
100 | /// In some cases this will be a UUID if a suitable profile exists on the system. In other cases, this may | ||
101 | /// just return the same identifier after creating a temporary profile. | ||
102 | /// | ||
103 | /// <param name="ospa"></param> | ||
104 | /// <param name="commsManager"></param> | ||
105 | /// <returns> | ||
106 | /// A suitable UUID for use in Second Life client communication. If the string was not a valid ospa, then UUID.Zero | ||
107 | /// is returned. | ||
108 | /// </returns> | ||
109 | public static UUID ResolveOspa(string ospa, IUserAccountService userService) | ||
110 | { | ||
111 | if (!ospa.StartsWith(OSPA_PREFIX)) | ||
112 | { | ||
113 | // m_log.DebugFormat("[OSP RESOLVER]: ResolveOspa() got unrecognized format [{0}]", ospa); | ||
114 | return UUID.Zero; | ||
115 | } | ||
116 | |||
117 | // m_log.DebugFormat("[OSP RESOLVER]: Resolving {0}", ospa); | ||
118 | |||
119 | string ospaMeat = ospa.Substring(OSPA_PREFIX.Length); | ||
120 | string[] ospaTuples = ospaMeat.Split(OSPA_TUPLE_SEPARATOR_ARRAY); | ||
121 | |||
122 | foreach (string tuple in ospaTuples) | ||
123 | { | ||
124 | int tupleSeparatorIndex = tuple.IndexOf(OSPA_PAIR_SEPARATOR); | ||
125 | |||
126 | if (tupleSeparatorIndex < 0) | ||
127 | { | ||
128 | m_log.WarnFormat("[OSP RESOLVER]: Ignoring non-tuple component {0} in OSPA {1}", tuple, ospa); | ||
129 | continue; | ||
130 | } | ||
131 | |||
132 | string key = tuple.Remove(tupleSeparatorIndex).Trim(); | ||
133 | string value = tuple.Substring(tupleSeparatorIndex + 1).Trim(); | ||
134 | |||
135 | if (OSPA_NAME_KEY == key) | ||
136 | return ResolveOspaName(value, userService); | ||
137 | } | ||
138 | |||
139 | return UUID.Zero; | ||
140 | } | ||
141 | |||
142 | /// <summary> | ||
143 | /// Hash a profile name into a UUID | ||
144 | /// </summary> | ||
145 | /// <param name="name"></param> | ||
146 | /// <returns></returns> | ||
147 | public static UUID HashName(string name) | ||
148 | { | ||
149 | return new UUID(Utils.MD5(Encoding.Unicode.GetBytes(name)), 0); | ||
150 | } | ||
151 | |||
152 | /// <summary> | ||
153 | /// Resolve an OSPI name by querying existing persistent user profiles. If there is no persistent user profile | ||
154 | /// then a temporary user profile is inserted in the cache. | ||
155 | /// </summary> | ||
156 | /// <param name="name"></param> | ||
157 | /// <param name="commsManager"></param> | ||
158 | /// <returns> | ||
159 | /// An OpenSim internal identifier for the name given. Returns null if the name was not valid | ||
160 | /// </returns> | ||
161 | protected static UUID ResolveOspaName(string name, IUserAccountService userService) | ||
162 | { | ||
163 | if (userService == null) | ||
164 | return UUID.Zero; | ||
165 | |||
166 | int nameSeparatorIndex = name.IndexOf(OSPA_NAME_VALUE_SEPARATOR); | ||
167 | |||
168 | if (nameSeparatorIndex < 0) | ||
169 | { | ||
170 | m_log.WarnFormat("[OSP RESOLVER]: Ignoring unseparated name {0}", name); | ||
171 | return UUID.Zero; | ||
172 | } | ||
173 | |||
174 | string firstName = name.Remove(nameSeparatorIndex).TrimEnd(); | ||
175 | string lastName = name.Substring(nameSeparatorIndex + 1).TrimStart(); | ||
176 | |||
177 | UserAccount account = userService.GetUserAccount(UUID.Zero, firstName, lastName); | ||
178 | if (account != null) | ||
179 | { | ||
180 | // m_log.DebugFormat( | ||
181 | // "[OSP RESOLVER]: Found user account with uuid {0} for {1} {2}", | ||
182 | // account.PrincipalID, firstName, lastName); | ||
183 | |||
184 | return account.PrincipalID; | ||
185 | } | ||
186 | // else | ||
187 | // { | ||
188 | // m_log.DebugFormat("[OSP RESOLVER]: No resolved OSPA user account for {0}", name); | ||
189 | // } | ||
190 | |||
191 | // XXX: Disable temporary user profile creation for now as implementation is incomplete - justincc | ||
192 | /* | ||
193 | UserProfileData tempUserProfile = new UserProfileData(); | ||
194 | tempUserProfile.FirstName = firstName; | ||
195 | tempUserProfile.SurName = lastName; | ||
196 | tempUserProfile.ID = HashName(tempUserProfile.Name); | ||
197 | |||
198 | m_log.DebugFormat( | ||
199 | "[OSP RESOLVER]: Adding temporary user profile for {0} {1}", tempUserProfile.Name, tempUserProfile.ID); | ||
200 | commsManager.UserService.AddTemporaryUserProfile(tempUserProfile); | ||
201 | |||
202 | return tempUserProfile.ID; | ||
203 | */ | ||
204 | |||
205 | return UUID.Zero; | ||
206 | } | ||
207 | } | ||
208 | } | ||
diff --git a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs new file mode 100644 index 0000000..19468c3 --- /dev/null +++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs | |||
@@ -0,0 +1,287 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.IO; | ||
29 | using System.Text; | ||
30 | using System.Xml; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using log4net; | ||
34 | using System.Reflection; | ||
35 | |||
36 | namespace OpenSim.Framework.Serialization.External | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// Serialize and deserialize region settings as an external format. | ||
40 | /// </summary> | ||
41 | public class RegionSettingsSerializer | ||
42 | { | ||
43 | /// <summary> | ||
44 | /// Deserialize settings | ||
45 | /// </summary> | ||
46 | /// <param name="serializedSettings"></param> | ||
47 | /// <returns></returns> | ||
48 | /// <exception cref="System.Xml.XmlException"></exception> | ||
49 | public static RegionSettings Deserialize(byte[] serializedSettings) | ||
50 | { | ||
51 | return Deserialize(Encoding.ASCII.GetString(serializedSettings, 0, serializedSettings.Length)); | ||
52 | } | ||
53 | |||
54 | /// <summary> | ||
55 | /// Deserialize settings | ||
56 | /// </summary> | ||
57 | /// <param name="serializedSettings"></param> | ||
58 | /// <returns></returns> | ||
59 | /// <exception cref="System.Xml.XmlException"></exception> | ||
60 | public static RegionSettings Deserialize(string serializedSettings) | ||
61 | { | ||
62 | RegionSettings settings = new RegionSettings(); | ||
63 | |||
64 | StringReader sr = new StringReader(serializedSettings); | ||
65 | XmlTextReader xtr = new XmlTextReader(sr); | ||
66 | |||
67 | xtr.ReadStartElement("RegionSettings"); | ||
68 | |||
69 | xtr.ReadStartElement("General"); | ||
70 | |||
71 | while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) | ||
72 | { | ||
73 | switch (xtr.Name) | ||
74 | { | ||
75 | case "AllowDamage": | ||
76 | settings.AllowDamage = bool.Parse(xtr.ReadElementContentAsString()); | ||
77 | break; | ||
78 | case "AllowLandResell": | ||
79 | settings.AllowLandResell = bool.Parse(xtr.ReadElementContentAsString()); | ||
80 | break; | ||
81 | case "AllowLandJoinDivide": | ||
82 | settings.AllowLandJoinDivide = bool.Parse(xtr.ReadElementContentAsString()); | ||
83 | break; | ||
84 | case "BlockFly": | ||
85 | settings.BlockFly = bool.Parse(xtr.ReadElementContentAsString()); | ||
86 | break; | ||
87 | case "BlockLandShowInSearch": | ||
88 | settings.BlockShowInSearch = bool.Parse(xtr.ReadElementContentAsString()); | ||
89 | break; | ||
90 | case "BlockTerraform": | ||
91 | settings.BlockTerraform = bool.Parse(xtr.ReadElementContentAsString()); | ||
92 | break; | ||
93 | case "DisableCollisions": | ||
94 | settings.DisableCollisions = bool.Parse(xtr.ReadElementContentAsString()); | ||
95 | break; | ||
96 | case "DisablePhysics": | ||
97 | settings.DisablePhysics = bool.Parse(xtr.ReadElementContentAsString()); | ||
98 | break; | ||
99 | case "DisableScripts": | ||
100 | settings.DisableScripts = bool.Parse(xtr.ReadElementContentAsString()); | ||
101 | break; | ||
102 | case "MaturityRating": | ||
103 | settings.Maturity = int.Parse(xtr.ReadElementContentAsString()); | ||
104 | break; | ||
105 | case "RestrictPushing": | ||
106 | settings.RestrictPushing = bool.Parse(xtr.ReadElementContentAsString()); | ||
107 | break; | ||
108 | case "AgentLimit": | ||
109 | settings.AgentLimit = int.Parse(xtr.ReadElementContentAsString()); | ||
110 | break; | ||
111 | case "ObjectBonus": | ||
112 | settings.ObjectBonus = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); | ||
113 | break; | ||
114 | } | ||
115 | } | ||
116 | |||
117 | xtr.ReadEndElement(); | ||
118 | xtr.ReadStartElement("GroundTextures"); | ||
119 | |||
120 | while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) | ||
121 | { | ||
122 | switch (xtr.Name) | ||
123 | { | ||
124 | case "Texture1": | ||
125 | settings.TerrainTexture1 = UUID.Parse(xtr.ReadElementContentAsString()); | ||
126 | break; | ||
127 | case "Texture2": | ||
128 | settings.TerrainTexture2 = UUID.Parse(xtr.ReadElementContentAsString()); | ||
129 | break; | ||
130 | case "Texture3": | ||
131 | settings.TerrainTexture3 = UUID.Parse(xtr.ReadElementContentAsString()); | ||
132 | break; | ||
133 | case "Texture4": | ||
134 | settings.TerrainTexture4 = UUID.Parse(xtr.ReadElementContentAsString()); | ||
135 | break; | ||
136 | case "ElevationLowSW": | ||
137 | settings.Elevation1SW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); | ||
138 | break; | ||
139 | case "ElevationLowNW": | ||
140 | settings.Elevation1NW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); | ||
141 | break; | ||
142 | case "ElevationLowSE": | ||
143 | settings.Elevation1SE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); | ||
144 | break; | ||
145 | case "ElevationLowNE": | ||
146 | settings.Elevation1NE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); | ||
147 | break; | ||
148 | case "ElevationHighSW": | ||
149 | settings.Elevation2SW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); | ||
150 | break; | ||
151 | case "ElevationHighNW": | ||
152 | settings.Elevation2NW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); | ||
153 | break; | ||
154 | case "ElevationHighSE": | ||
155 | settings.Elevation2SE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); | ||
156 | break; | ||
157 | case "ElevationHighNE": | ||
158 | settings.Elevation2NE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); | ||
159 | break; | ||
160 | } | ||
161 | } | ||
162 | |||
163 | xtr.ReadEndElement(); | ||
164 | xtr.ReadStartElement("Terrain"); | ||
165 | |||
166 | while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) | ||
167 | { | ||
168 | switch (xtr.Name) | ||
169 | { | ||
170 | case "WaterHeight": | ||
171 | settings.WaterHeight = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); | ||
172 | break; | ||
173 | case "TerrainRaiseLimit": | ||
174 | settings.TerrainRaiseLimit = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); | ||
175 | break; | ||
176 | case "TerrainLowerLimit": | ||
177 | settings.TerrainLowerLimit = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo); | ||
178 | break; | ||
179 | case "UseEstateSun": | ||
180 | settings.UseEstateSun = bool.Parse(xtr.ReadElementContentAsString()); | ||
181 | break; | ||
182 | case "FixedSun": | ||
183 | settings.FixedSun = bool.Parse(xtr.ReadElementContentAsString()); | ||
184 | break; | ||
185 | case "SunPosition": | ||
186 | settings.SunPosition = double.Parse(xtr.ReadElementContentAsString()); | ||
187 | break; | ||
188 | } | ||
189 | } | ||
190 | |||
191 | xtr.ReadEndElement(); | ||
192 | |||
193 | if (xtr.IsStartElement("Telehub")) | ||
194 | { | ||
195 | xtr.ReadStartElement("Telehub"); | ||
196 | |||
197 | while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) | ||
198 | { | ||
199 | switch (xtr.Name) | ||
200 | { | ||
201 | case "TelehubObject": | ||
202 | settings.TelehubObject = UUID.Parse(xtr.ReadElementContentAsString()); | ||
203 | break; | ||
204 | case "SpawnPoint": | ||
205 | string str = xtr.ReadElementContentAsString(); | ||
206 | SpawnPoint sp = SpawnPoint.Parse(str); | ||
207 | settings.AddSpawnPoint(sp); | ||
208 | break; | ||
209 | } | ||
210 | } | ||
211 | } | ||
212 | |||
213 | xtr.Close(); | ||
214 | sr.Close(); | ||
215 | |||
216 | return settings; | ||
217 | } | ||
218 | |||
219 | public static string Serialize(RegionSettings settings) | ||
220 | { | ||
221 | StringWriter sw = new StringWriter(); | ||
222 | XmlTextWriter xtw = new XmlTextWriter(sw); | ||
223 | xtw.Formatting = Formatting.Indented; | ||
224 | xtw.WriteStartDocument(); | ||
225 | |||
226 | xtw.WriteStartElement("RegionSettings"); | ||
227 | |||
228 | xtw.WriteStartElement("General"); | ||
229 | xtw.WriteElementString("AllowDamage", settings.AllowDamage.ToString()); | ||
230 | xtw.WriteElementString("AllowLandResell", settings.AllowLandResell.ToString()); | ||
231 | xtw.WriteElementString("AllowLandJoinDivide", settings.AllowLandJoinDivide.ToString()); | ||
232 | xtw.WriteElementString("BlockFly", settings.BlockFly.ToString()); | ||
233 | xtw.WriteElementString("BlockLandShowInSearch", settings.BlockShowInSearch.ToString()); | ||
234 | xtw.WriteElementString("BlockTerraform", settings.BlockTerraform.ToString()); | ||
235 | xtw.WriteElementString("DisableCollisions", settings.DisableCollisions.ToString()); | ||
236 | xtw.WriteElementString("DisablePhysics", settings.DisablePhysics.ToString()); | ||
237 | xtw.WriteElementString("DisableScripts", settings.DisableScripts.ToString()); | ||
238 | xtw.WriteElementString("MaturityRating", settings.Maturity.ToString()); | ||
239 | xtw.WriteElementString("RestrictPushing", settings.RestrictPushing.ToString()); | ||
240 | xtw.WriteElementString("AgentLimit", settings.AgentLimit.ToString()); | ||
241 | xtw.WriteElementString("ObjectBonus", settings.ObjectBonus.ToString()); | ||
242 | xtw.WriteEndElement(); | ||
243 | |||
244 | xtw.WriteStartElement("GroundTextures"); | ||
245 | xtw.WriteElementString("Texture1", settings.TerrainTexture1.ToString()); | ||
246 | xtw.WriteElementString("Texture2", settings.TerrainTexture2.ToString()); | ||
247 | xtw.WriteElementString("Texture3", settings.TerrainTexture3.ToString()); | ||
248 | xtw.WriteElementString("Texture4", settings.TerrainTexture4.ToString()); | ||
249 | xtw.WriteElementString("ElevationLowSW", settings.Elevation1SW.ToString()); | ||
250 | xtw.WriteElementString("ElevationLowNW", settings.Elevation1NW.ToString()); | ||
251 | xtw.WriteElementString("ElevationLowSE", settings.Elevation1SE.ToString()); | ||
252 | xtw.WriteElementString("ElevationLowNE", settings.Elevation1NE.ToString()); | ||
253 | xtw.WriteElementString("ElevationHighSW", settings.Elevation2SW.ToString()); | ||
254 | xtw.WriteElementString("ElevationHighNW", settings.Elevation2NW.ToString()); | ||
255 | xtw.WriteElementString("ElevationHighSE", settings.Elevation2SE.ToString()); | ||
256 | xtw.WriteElementString("ElevationHighNE", settings.Elevation2NE.ToString()); | ||
257 | xtw.WriteEndElement(); | ||
258 | |||
259 | xtw.WriteStartElement("Terrain"); | ||
260 | xtw.WriteElementString("WaterHeight", settings.WaterHeight.ToString()); | ||
261 | xtw.WriteElementString("TerrainRaiseLimit", settings.TerrainRaiseLimit.ToString()); | ||
262 | xtw.WriteElementString("TerrainLowerLimit", settings.TerrainLowerLimit.ToString()); | ||
263 | xtw.WriteElementString("UseEstateSun", settings.UseEstateSun.ToString()); | ||
264 | xtw.WriteElementString("FixedSun", settings.FixedSun.ToString()); | ||
265 | xtw.WriteElementString("SunPosition", settings.SunPosition.ToString()); | ||
266 | // Note: 'SunVector' isn't saved because this value is owned by the Sun Module, which | ||
267 | // calculates it automatically according to the date and other factors. | ||
268 | xtw.WriteEndElement(); | ||
269 | |||
270 | xtw.WriteStartElement("Telehub"); | ||
271 | if (settings.TelehubObject != UUID.Zero) | ||
272 | { | ||
273 | xtw.WriteElementString("TelehubObject", settings.TelehubObject.ToString()); | ||
274 | foreach (SpawnPoint sp in settings.SpawnPoints()) | ||
275 | xtw.WriteElementString("SpawnPoint", sp.ToString()); | ||
276 | } | ||
277 | xtw.WriteEndElement(); | ||
278 | |||
279 | xtw.WriteEndElement(); | ||
280 | |||
281 | xtw.Close(); | ||
282 | sw.Close(); | ||
283 | |||
284 | return sw.ToString(); | ||
285 | } | ||
286 | } | ||
287 | } | ||
diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs new file mode 100644 index 0000000..994cede --- /dev/null +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs | |||
@@ -0,0 +1,304 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using System.Xml; | ||
34 | |||
35 | using log4net; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | |||
40 | namespace OpenSim.Framework.Serialization.External | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// Serialize and deserialize user inventory items as an external format. | ||
44 | /// </summary> | ||
45 | public class UserInventoryItemSerializer | ||
46 | { | ||
47 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private static Dictionary<string, Action<InventoryItemBase, XmlReader>> m_InventoryItemXmlProcessors | ||
50 | = new Dictionary<string, Action<InventoryItemBase, XmlReader>>(); | ||
51 | |||
52 | #region InventoryItemBase Processor initialization | ||
53 | static UserInventoryItemSerializer() | ||
54 | { | ||
55 | m_InventoryItemXmlProcessors.Add("Name", ProcessName); | ||
56 | m_InventoryItemXmlProcessors.Add("ID", ProcessID); | ||
57 | m_InventoryItemXmlProcessors.Add("InvType", ProcessInvType); | ||
58 | m_InventoryItemXmlProcessors.Add("CreatorUUID", ProcessCreatorUUID); | ||
59 | m_InventoryItemXmlProcessors.Add("CreatorID", ProcessCreatorID); | ||
60 | m_InventoryItemXmlProcessors.Add("CreatorData", ProcessCreatorData); | ||
61 | m_InventoryItemXmlProcessors.Add("CreationDate", ProcessCreationDate); | ||
62 | m_InventoryItemXmlProcessors.Add("Owner", ProcessOwner); | ||
63 | m_InventoryItemXmlProcessors.Add("Description", ProcessDescription); | ||
64 | m_InventoryItemXmlProcessors.Add("AssetType", ProcessAssetType); | ||
65 | m_InventoryItemXmlProcessors.Add("AssetID", ProcessAssetID); | ||
66 | m_InventoryItemXmlProcessors.Add("SaleType", ProcessSaleType); | ||
67 | m_InventoryItemXmlProcessors.Add("SalePrice", ProcessSalePrice); | ||
68 | m_InventoryItemXmlProcessors.Add("BasePermissions", ProcessBasePermissions); | ||
69 | m_InventoryItemXmlProcessors.Add("CurrentPermissions", ProcessCurrentPermissions); | ||
70 | m_InventoryItemXmlProcessors.Add("EveryOnePermissions", ProcessEveryOnePermissions); | ||
71 | m_InventoryItemXmlProcessors.Add("NextPermissions", ProcessNextPermissions); | ||
72 | m_InventoryItemXmlProcessors.Add("Flags", ProcessFlags); | ||
73 | m_InventoryItemXmlProcessors.Add("GroupID", ProcessGroupID); | ||
74 | m_InventoryItemXmlProcessors.Add("GroupOwned", ProcessGroupOwned); | ||
75 | } | ||
76 | #endregion | ||
77 | |||
78 | #region InventoryItemBase Processors | ||
79 | private static void ProcessName(InventoryItemBase item, XmlReader reader) | ||
80 | { | ||
81 | item.Name = reader.ReadElementContentAsString("Name", String.Empty); | ||
82 | } | ||
83 | |||
84 | private static void ProcessID(InventoryItemBase item, XmlReader reader) | ||
85 | { | ||
86 | item.ID = Util.ReadUUID(reader, "ID"); | ||
87 | } | ||
88 | |||
89 | private static void ProcessInvType(InventoryItemBase item, XmlReader reader) | ||
90 | { | ||
91 | item.InvType = reader.ReadElementContentAsInt("InvType", String.Empty); | ||
92 | } | ||
93 | |||
94 | private static void ProcessCreatorUUID(InventoryItemBase item, XmlReader reader) | ||
95 | { | ||
96 | item.CreatorId = reader.ReadElementContentAsString("CreatorUUID", String.Empty); | ||
97 | } | ||
98 | |||
99 | private static void ProcessCreatorID(InventoryItemBase item, XmlReader reader) | ||
100 | { | ||
101 | // when it exists, this overrides the previous | ||
102 | item.CreatorId = reader.ReadElementContentAsString("CreatorID", String.Empty); | ||
103 | } | ||
104 | |||
105 | private static void ProcessCreationDate(InventoryItemBase item, XmlReader reader) | ||
106 | { | ||
107 | item.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty); | ||
108 | } | ||
109 | |||
110 | private static void ProcessOwner(InventoryItemBase item, XmlReader reader) | ||
111 | { | ||
112 | item.Owner = Util.ReadUUID(reader, "Owner"); | ||
113 | } | ||
114 | |||
115 | private static void ProcessDescription(InventoryItemBase item, XmlReader reader) | ||
116 | { | ||
117 | item.Description = reader.ReadElementContentAsString("Description", String.Empty); | ||
118 | } | ||
119 | |||
120 | private static void ProcessAssetType(InventoryItemBase item, XmlReader reader) | ||
121 | { | ||
122 | item.AssetType = reader.ReadElementContentAsInt("AssetType", String.Empty); | ||
123 | } | ||
124 | |||
125 | private static void ProcessAssetID(InventoryItemBase item, XmlReader reader) | ||
126 | { | ||
127 | item.AssetID = Util.ReadUUID(reader, "AssetID"); | ||
128 | } | ||
129 | |||
130 | private static void ProcessSaleType(InventoryItemBase item, XmlReader reader) | ||
131 | { | ||
132 | item.SaleType = (byte)reader.ReadElementContentAsInt("SaleType", String.Empty); | ||
133 | } | ||
134 | |||
135 | private static void ProcessSalePrice(InventoryItemBase item, XmlReader reader) | ||
136 | { | ||
137 | item.SalePrice = reader.ReadElementContentAsInt("SalePrice", String.Empty); | ||
138 | } | ||
139 | |||
140 | private static void ProcessBasePermissions(InventoryItemBase item, XmlReader reader) | ||
141 | { | ||
142 | item.BasePermissions = (uint)reader.ReadElementContentAsInt("BasePermissions", String.Empty); | ||
143 | } | ||
144 | |||
145 | private static void ProcessCurrentPermissions(InventoryItemBase item, XmlReader reader) | ||
146 | { | ||
147 | item.CurrentPermissions = (uint)reader.ReadElementContentAsInt("CurrentPermissions", String.Empty); | ||
148 | } | ||
149 | |||
150 | private static void ProcessEveryOnePermissions(InventoryItemBase item, XmlReader reader) | ||
151 | { | ||
152 | item.EveryOnePermissions = (uint)reader.ReadElementContentAsInt("EveryOnePermissions", String.Empty); | ||
153 | } | ||
154 | |||
155 | private static void ProcessNextPermissions(InventoryItemBase item, XmlReader reader) | ||
156 | { | ||
157 | item.NextPermissions = (uint)reader.ReadElementContentAsInt("NextPermissions", String.Empty); | ||
158 | } | ||
159 | |||
160 | private static void ProcessFlags(InventoryItemBase item, XmlReader reader) | ||
161 | { | ||
162 | item.Flags = (uint)reader.ReadElementContentAsInt("Flags", String.Empty); | ||
163 | } | ||
164 | |||
165 | private static void ProcessGroupID(InventoryItemBase item, XmlReader reader) | ||
166 | { | ||
167 | item.GroupID = Util.ReadUUID(reader, "GroupID"); | ||
168 | } | ||
169 | |||
170 | private static void ProcessGroupOwned(InventoryItemBase item, XmlReader reader) | ||
171 | { | ||
172 | item.GroupOwned = Util.ReadBoolean(reader); | ||
173 | } | ||
174 | |||
175 | private static void ProcessCreatorData(InventoryItemBase item, XmlReader reader) | ||
176 | { | ||
177 | item.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty); | ||
178 | } | ||
179 | |||
180 | #endregion | ||
181 | |||
182 | /// <summary> | ||
183 | /// Deserialize item | ||
184 | /// </summary> | ||
185 | /// <param name="serializedSettings"></param> | ||
186 | /// <returns></returns> | ||
187 | /// <exception cref="System.Xml.XmlException"></exception> | ||
188 | public static InventoryItemBase Deserialize(byte[] serialization) | ||
189 | { | ||
190 | return Deserialize(Encoding.ASCII.GetString(serialization, 0, serialization.Length)); | ||
191 | } | ||
192 | |||
193 | /// <summary> | ||
194 | /// Deserialize settings | ||
195 | /// </summary> | ||
196 | /// <param name="serializedSettings"></param> | ||
197 | /// <returns></returns> | ||
198 | /// <exception cref="System.Xml.XmlException"></exception> | ||
199 | public static InventoryItemBase Deserialize(string serialization) | ||
200 | { | ||
201 | InventoryItemBase item = new InventoryItemBase(); | ||
202 | |||
203 | using (XmlTextReader reader = new XmlTextReader(new StringReader(serialization))) | ||
204 | { | ||
205 | reader.ReadStartElement("InventoryItem"); | ||
206 | |||
207 | ExternalRepresentationUtils.ExecuteReadProcessors<InventoryItemBase>( | ||
208 | item, m_InventoryItemXmlProcessors, reader); | ||
209 | |||
210 | reader.ReadEndElement(); // InventoryItem | ||
211 | } | ||
212 | |||
213 | //m_log.DebugFormat("[XXX]: parsed InventoryItemBase {0} - {1}", obj.Name, obj.UUID); | ||
214 | return item; | ||
215 | } | ||
216 | |||
217 | public static string Serialize(InventoryItemBase inventoryItem, Dictionary<string, object> options, IUserAccountService userAccountService) | ||
218 | { | ||
219 | StringWriter sw = new StringWriter(); | ||
220 | XmlTextWriter writer = new XmlTextWriter(sw); | ||
221 | writer.Formatting = Formatting.Indented; | ||
222 | writer.WriteStartDocument(); | ||
223 | |||
224 | writer.WriteStartElement("InventoryItem"); | ||
225 | |||
226 | writer.WriteStartElement("Name"); | ||
227 | writer.WriteString(inventoryItem.Name); | ||
228 | writer.WriteEndElement(); | ||
229 | writer.WriteStartElement("ID"); | ||
230 | writer.WriteString(inventoryItem.ID.ToString()); | ||
231 | writer.WriteEndElement(); | ||
232 | writer.WriteStartElement("InvType"); | ||
233 | writer.WriteString(inventoryItem.InvType.ToString()); | ||
234 | writer.WriteEndElement(); | ||
235 | writer.WriteStartElement("CreatorUUID"); | ||
236 | writer.WriteString(OspResolver.MakeOspa(inventoryItem.CreatorIdAsUuid, userAccountService)); | ||
237 | writer.WriteEndElement(); | ||
238 | writer.WriteStartElement("CreationDate"); | ||
239 | writer.WriteString(inventoryItem.CreationDate.ToString()); | ||
240 | writer.WriteEndElement(); | ||
241 | writer.WriteStartElement("Owner"); | ||
242 | writer.WriteString(inventoryItem.Owner.ToString()); | ||
243 | writer.WriteEndElement(); | ||
244 | writer.WriteStartElement("Description"); | ||
245 | writer.WriteString(inventoryItem.Description); | ||
246 | writer.WriteEndElement(); | ||
247 | writer.WriteStartElement("AssetType"); | ||
248 | writer.WriteString(inventoryItem.AssetType.ToString()); | ||
249 | writer.WriteEndElement(); | ||
250 | writer.WriteStartElement("AssetID"); | ||
251 | writer.WriteString(inventoryItem.AssetID.ToString()); | ||
252 | writer.WriteEndElement(); | ||
253 | writer.WriteStartElement("SaleType"); | ||
254 | writer.WriteString(inventoryItem.SaleType.ToString()); | ||
255 | writer.WriteEndElement(); | ||
256 | writer.WriteStartElement("SalePrice"); | ||
257 | writer.WriteString(inventoryItem.SalePrice.ToString()); | ||
258 | writer.WriteEndElement(); | ||
259 | writer.WriteStartElement("BasePermissions"); | ||
260 | writer.WriteString(inventoryItem.BasePermissions.ToString()); | ||
261 | writer.WriteEndElement(); | ||
262 | writer.WriteStartElement("CurrentPermissions"); | ||
263 | writer.WriteString(inventoryItem.CurrentPermissions.ToString()); | ||
264 | writer.WriteEndElement(); | ||
265 | writer.WriteStartElement("EveryOnePermissions"); | ||
266 | writer.WriteString(inventoryItem.EveryOnePermissions.ToString()); | ||
267 | writer.WriteEndElement(); | ||
268 | writer.WriteStartElement("NextPermissions"); | ||
269 | writer.WriteString(inventoryItem.NextPermissions.ToString()); | ||
270 | writer.WriteEndElement(); | ||
271 | writer.WriteStartElement("Flags"); | ||
272 | writer.WriteString(inventoryItem.Flags.ToString()); | ||
273 | writer.WriteEndElement(); | ||
274 | writer.WriteStartElement("GroupID"); | ||
275 | writer.WriteString(inventoryItem.GroupID.ToString()); | ||
276 | writer.WriteEndElement(); | ||
277 | writer.WriteStartElement("GroupOwned"); | ||
278 | writer.WriteString(inventoryItem.GroupOwned.ToString()); | ||
279 | writer.WriteEndElement(); | ||
280 | if (options.ContainsKey("creators") && !string.IsNullOrEmpty(inventoryItem.CreatorData)) | ||
281 | writer.WriteElementString("CreatorData", inventoryItem.CreatorData); | ||
282 | else if (options.ContainsKey("home")) | ||
283 | { | ||
284 | if (userAccountService != null) | ||
285 | { | ||
286 | UserAccount account = userAccountService.GetUserAccount(UUID.Zero, inventoryItem.CreatorIdAsUuid); | ||
287 | if (account != null) | ||
288 | { | ||
289 | string creatorData = ExternalRepresentationUtils.CalcCreatorData((string)options["home"], inventoryItem.CreatorIdAsUuid, account.FirstName + " " + account.LastName); | ||
290 | writer.WriteElementString("CreatorData", creatorData); | ||
291 | } | ||
292 | writer.WriteElementString("CreatorID", inventoryItem.CreatorId); | ||
293 | } | ||
294 | } | ||
295 | |||
296 | writer.WriteEndElement(); | ||
297 | |||
298 | writer.Close(); | ||
299 | sw.Close(); | ||
300 | |||
301 | return sw.ToString(); | ||
302 | } | ||
303 | } | ||
304 | } | ||
diff --git a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs new file mode 100644 index 0000000..c685a15 --- /dev/null +++ b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs | |||
@@ -0,0 +1,73 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.IO; | ||
29 | using System.Xml; | ||
30 | using OpenMetaverse; | ||
31 | using OpenSim.Framework; | ||
32 | |||
33 | namespace OpenSim.Framework.Serialization.External | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// Serialize and deserialize user profiles as an external format. | ||
37 | /// </summary> | ||
38 | /// <remarks> | ||
39 | /// Currently UNUSED. | ||
40 | /// </remarks> | ||
41 | public class UserProfileSerializer | ||
42 | { | ||
43 | public const int MAJOR_VERSION = 0; | ||
44 | public const int MINOR_VERSION = 1; | ||
45 | |||
46 | public static string Serialize(UUID userID, string firstName, string lastName) | ||
47 | { | ||
48 | StringWriter sw = new StringWriter(); | ||
49 | XmlTextWriter xtw = new XmlTextWriter(sw); | ||
50 | xtw.Formatting = Formatting.Indented; | ||
51 | xtw.WriteStartDocument(); | ||
52 | |||
53 | xtw.WriteStartElement("user_profile"); | ||
54 | xtw.WriteAttributeString("major_version", MAJOR_VERSION.ToString()); | ||
55 | xtw.WriteAttributeString("minor_version", MINOR_VERSION.ToString()); | ||
56 | |||
57 | xtw.WriteElementString("name", firstName + " " + lastName); | ||
58 | xtw.WriteElementString("id", userID.ToString()); | ||
59 | xtw.WriteElementString("about", ""); | ||
60 | |||
61 | // Not sure if we're storing this yet, need to take a look | ||
62 | // xtw.WriteElementString("Url", profile.Url); | ||
63 | // or, indeed, interests | ||
64 | |||
65 | xtw.WriteEndElement(); | ||
66 | |||
67 | xtw.Close(); | ||
68 | sw.Close(); | ||
69 | |||
70 | return sw.ToString(); | ||
71 | } | ||
72 | } | ||
73 | } \ No newline at end of file | ||