aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Serialization/External
diff options
context:
space:
mode:
authorDiva Canto2010-11-29 08:43:33 -0800
committerDiva Canto2010-11-29 08:43:33 -0800
commitf86c438653fc3c8356a8f0c43a055b1928183f02 (patch)
treeb8ad05db04efde6385eeaed48dcbe4e896133ad5 /OpenSim/Framework/Serialization/External
parentChanged the parser for InventoryItem deserialization. Moved some utility func... (diff)
downloadopensim-SC_OLD-f86c438653fc3c8356a8f0c43a055b1928183f02.zip
opensim-SC_OLD-f86c438653fc3c8356a8f0c43a055b1928183f02.tar.gz
opensim-SC_OLD-f86c438653fc3c8356a8f0c43a055b1928183f02.tar.bz2
opensim-SC_OLD-f86c438653fc3c8356a8f0c43a055b1928183f02.tar.xz
Preservation of creator information now also working in IARs. Cleaned up usage help. Moved Osp around, deleted unnecessary OspInventoryWrapperPlugin, added manipulation of SOP's xml representation in a generic ExternalRepresentationUtils function.
Diffstat (limited to 'OpenSim/Framework/Serialization/External')
-rw-r--r--OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs87
-rw-r--r--OpenSim/Framework/Serialization/External/OspResolver.cs177
-rw-r--r--OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs39
3 files changed, 295 insertions, 8 deletions
diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
new file mode 100644
index 0000000..5c0630c
--- /dev/null
+++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
@@ -0,0 +1,87 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.IO;
30using System.Xml;
31
32using OpenMetaverse;
33using OpenSim.Services.Interfaces;
34
35namespace OpenSim.Framework.Serialization.External
36{
37 public class ExternalRepresentationUtils
38 {
39 public static string RewriteSOP(string xml, string profileURL, IUserAccountService userService, UUID scopeID)
40 {
41 if (xml == string.Empty || profileURL == string.Empty || userService == null)
42 return xml;
43
44 XmlDocument doc = new XmlDocument();
45 doc.LoadXml(xml);
46 XmlNodeList sops = doc.GetElementsByTagName("SceneObjectPart");
47
48 foreach (XmlNode sop in sops)
49 {
50 UserAccount creator = null;
51 bool hasCreatorData = false;
52 XmlNodeList nodes = sop.ChildNodes;
53 foreach (XmlNode node in nodes)
54 {
55 if (node.Name == "CreatorID")
56 {
57 UUID uuid = UUID.Zero;
58 UUID.TryParse(node.InnerText, out uuid);
59 creator = userService.GetUserAccount(scopeID, uuid);
60 }
61 if (node.Name == "CreatorData" && node.InnerText != null && node.InnerText != string.Empty)
62 hasCreatorData = true;
63
64 //if (node.Name == "OwnerID")
65 //{
66 // UserAccount owner = GetUser(node.InnerText);
67 // if (owner != null)
68 // node.InnerText = m_ProfileServiceURL + "/" + node.InnerText + "/" + owner.FirstName + " " + owner.LastName;
69 //}
70 }
71 if (!hasCreatorData && creator != null)
72 {
73 XmlElement creatorData = doc.CreateElement("CreatorData");
74 creatorData.InnerText = profileURL + "/" + creator.PrincipalID + ";" + creator.FirstName + " " + creator.LastName;
75 sop.AppendChild(creatorData);
76 }
77 }
78
79 using (StringWriter wr = new StringWriter())
80 {
81 doc.Save(wr);
82 return wr.ToString();
83 }
84
85 }
86 }
87}
diff --git a/OpenSim/Framework/Serialization/External/OspResolver.cs b/OpenSim/Framework/Serialization/External/OspResolver.cs
new file mode 100644
index 0000000..53c35ff
--- /dev/null
+++ b/OpenSim/Framework/Serialization/External/OspResolver.cs
@@ -0,0 +1,177 @@
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
28using System.Reflection;
29using System.Text;
30using log4net;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Services.Interfaces;
34
35namespace 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 UserAccount account = userService.GetUserAccount(UUID.Zero, userId);
61 if (account != null)
62 return MakeOspa(account.FirstName, account.LastName);
63
64 return null;
65 }
66
67 /// <summary>
68 /// Make an OSPA given a user name
69 /// </summary>
70 /// <param name="name"></param>
71 /// <returns></returns>
72 public static string MakeOspa(string firstName, string lastName)
73 {
74 return
75 OSPA_PREFIX + OSPA_NAME_KEY + OSPA_PAIR_SEPARATOR + firstName + OSPA_NAME_VALUE_SEPARATOR + lastName;
76 }
77
78 /// <summary>
79 /// Resolve an osp string into the most suitable internal OpenSim identifier.
80 /// </summary>
81 ///
82 /// In some cases this will be a UUID if a suitable profile exists on the system. In other cases, this may
83 /// just return the same identifier after creating a temporary profile.
84 ///
85 /// <param name="ospa"></param>
86 /// <param name="commsManager"></param>
87 /// <returns>
88 /// A suitable UUID for use in Second Life client communication. If the string was not a valid ospa, then UUID.Zero
89 /// is returned.
90 /// </returns>
91 public static UUID ResolveOspa(string ospa, IUserAccountService userService)
92 {
93 if (!ospa.StartsWith(OSPA_PREFIX))
94 return UUID.Zero;
95
96// m_log.DebugFormat("[OSP RESOLVER]: Resolving {0}", ospa);
97
98 string ospaMeat = ospa.Substring(OSPA_PREFIX.Length);
99 string[] ospaTuples = ospaMeat.Split(OSPA_TUPLE_SEPARATOR_ARRAY);
100
101 foreach (string tuple in ospaTuples)
102 {
103 int tupleSeparatorIndex = tuple.IndexOf(OSPA_PAIR_SEPARATOR);
104
105 if (tupleSeparatorIndex < 0)
106 {
107 m_log.WarnFormat("[OSP RESOLVER]: Ignoring non-tuple component {0} in OSPA {1}", tuple, ospa);
108 continue;
109 }
110
111 string key = tuple.Remove(tupleSeparatorIndex).Trim();
112 string value = tuple.Substring(tupleSeparatorIndex + 1).Trim();
113
114 if (OSPA_NAME_KEY == key)
115 return ResolveOspaName(value, userService);
116 }
117
118 return UUID.Zero;
119 }
120
121 /// <summary>
122 /// Hash a profile name into a UUID
123 /// </summary>
124 /// <param name="name"></param>
125 /// <returns></returns>
126 public static UUID HashName(string name)
127 {
128 return new UUID(Utils.MD5(Encoding.Unicode.GetBytes(name)), 0);
129 }
130
131 /// <summary>
132 /// Resolve an OSPI name by querying existing persistent user profiles. If there is no persistent user profile
133 /// then a temporary user profile is inserted in the cache.
134 /// </summary>
135 /// <param name="name"></param>
136 /// <param name="commsManager"></param>
137 /// <returns>
138 /// An OpenSim internal identifier for the name given. Returns null if the name was not valid
139 /// </returns>
140 protected static UUID ResolveOspaName(string name, IUserAccountService userService)
141 {
142 if (userService == null)
143 return UUID.Zero;
144
145 int nameSeparatorIndex = name.IndexOf(OSPA_NAME_VALUE_SEPARATOR);
146
147 if (nameSeparatorIndex < 0)
148 {
149 m_log.WarnFormat("[OSP RESOLVER]: Ignoring unseparated name {0}", name);
150 return UUID.Zero;
151 }
152
153 string firstName = name.Remove(nameSeparatorIndex).TrimEnd();
154 string lastName = name.Substring(nameSeparatorIndex + 1).TrimStart();
155
156 UserAccount account = userService.GetUserAccount(UUID.Zero, firstName, lastName);
157 if (account != null)
158 return account.PrincipalID;
159
160 // XXX: Disable temporary user profile creation for now as implementation is incomplete - justincc
161 /*
162 UserProfileData tempUserProfile = new UserProfileData();
163 tempUserProfile.FirstName = firstName;
164 tempUserProfile.SurName = lastName;
165 tempUserProfile.ID = HashName(tempUserProfile.Name);
166
167 m_log.DebugFormat(
168 "[OSP RESOLVER]: Adding temporary user profile for {0} {1}", tempUserProfile.Name, tempUserProfile.ID);
169 commsManager.UserService.AddTemporaryUserProfile(tempUserProfile);
170
171 return tempUserProfile.ID;
172 */
173
174 return UUID.Zero;
175 }
176 }
177}
diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
index df9af32..d5e84c7 100644
--- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
@@ -35,6 +35,7 @@ using System.Xml;
35using log4net; 35using log4net;
36using OpenMetaverse; 36using OpenMetaverse;
37using OpenSim.Framework; 37using OpenSim.Framework;
38using OpenSim.Services.Interfaces;
38 39
39namespace OpenSim.Framework.Serialization.External 40namespace OpenSim.Framework.Serialization.External
40{ 41{
@@ -56,6 +57,8 @@ namespace OpenSim.Framework.Serialization.External
56 m_InventoryItemXmlProcessors.Add("ID", ProcessID); 57 m_InventoryItemXmlProcessors.Add("ID", ProcessID);
57 m_InventoryItemXmlProcessors.Add("InvType", ProcessInvType); 58 m_InventoryItemXmlProcessors.Add("InvType", ProcessInvType);
58 m_InventoryItemXmlProcessors.Add("CreatorUUID", ProcessCreatorUUID); 59 m_InventoryItemXmlProcessors.Add("CreatorUUID", ProcessCreatorUUID);
60 m_InventoryItemXmlProcessors.Add("CreatorID", ProcessCreatorID);
61 m_InventoryItemXmlProcessors.Add("CreatorData", ProcessCreatorData);
59 m_InventoryItemXmlProcessors.Add("CreationDate", ProcessCreationDate); 62 m_InventoryItemXmlProcessors.Add("CreationDate", ProcessCreationDate);
60 m_InventoryItemXmlProcessors.Add("Owner", ProcessOwner); 63 m_InventoryItemXmlProcessors.Add("Owner", ProcessOwner);
61 m_InventoryItemXmlProcessors.Add("Description", ProcessDescription); 64 m_InventoryItemXmlProcessors.Add("Description", ProcessDescription);
@@ -94,6 +97,12 @@ namespace OpenSim.Framework.Serialization.External
94 item.CreatorId = reader.ReadElementContentAsString("CreatorUUID", String.Empty); 97 item.CreatorId = reader.ReadElementContentAsString("CreatorUUID", String.Empty);
95 } 98 }
96 99
100 private static void ProcessCreatorID(InventoryItemBase item, XmlTextReader reader)
101 {
102 // when it exists, this overrides the previous
103 item.CreatorId = reader.ReadElementContentAsString("CreatorID", String.Empty);
104 }
105
97 private static void ProcessCreationDate(InventoryItemBase item, XmlTextReader reader) 106 private static void ProcessCreationDate(InventoryItemBase item, XmlTextReader reader)
98 { 107 {
99 item.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty); 108 item.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty);
@@ -161,12 +170,12 @@ namespace OpenSim.Framework.Serialization.External
161 170
162 private static void ProcessGroupOwned(InventoryItemBase item, XmlTextReader reader) 171 private static void ProcessGroupOwned(InventoryItemBase item, XmlTextReader reader)
163 { 172 {
164 //item.GroupOwned = reader.ReadElementContentAsBoolean("GroupOwned", String.Empty); 173 item.GroupOwned = Util.ReadBoolean(reader);
165 // We don't do that, because ReadElementContentAsBoolean assumes lower case strings, 174 }
166 // and they may not be lower case 175
167 reader.ReadStartElement(); // GroupOwned 176 private static void ProcessCreatorData(InventoryItemBase item, XmlTextReader reader)
168 item.GroupOwned = Boolean.Parse(reader.ReadContentAsString().ToLower()); 177 {
169 reader.ReadEndElement(); 178 item.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty);
170 } 179 }
171 180
172 #endregion 181 #endregion
@@ -231,7 +240,7 @@ namespace OpenSim.Framework.Serialization.External
231 240
232 } 241 }
233 242
234 public static string Serialize(InventoryItemBase inventoryItem) 243 public static string Serialize(InventoryItemBase inventoryItem, Dictionary<string, object> options, IUserAccountService userAccountService)
235 { 244 {
236 StringWriter sw = new StringWriter(); 245 StringWriter sw = new StringWriter();
237 XmlTextWriter writer = new XmlTextWriter(sw); 246 XmlTextWriter writer = new XmlTextWriter(sw);
@@ -250,7 +259,7 @@ namespace OpenSim.Framework.Serialization.External
250 writer.WriteString(inventoryItem.InvType.ToString()); 259 writer.WriteString(inventoryItem.InvType.ToString());
251 writer.WriteEndElement(); 260 writer.WriteEndElement();
252 writer.WriteStartElement("CreatorUUID"); 261 writer.WriteStartElement("CreatorUUID");
253 writer.WriteString(inventoryItem.CreatorId); 262 writer.WriteString(OspResolver.MakeOspa(inventoryItem.CreatorIdAsUuid, userAccountService));
254 writer.WriteEndElement(); 263 writer.WriteEndElement();
255 writer.WriteStartElement("CreationDate"); 264 writer.WriteStartElement("CreationDate");
256 writer.WriteString(inventoryItem.CreationDate.ToString()); 265 writer.WriteString(inventoryItem.CreationDate.ToString());
@@ -294,6 +303,20 @@ namespace OpenSim.Framework.Serialization.External
294 writer.WriteStartElement("GroupOwned"); 303 writer.WriteStartElement("GroupOwned");
295 writer.WriteString(inventoryItem.GroupOwned.ToString()); 304 writer.WriteString(inventoryItem.GroupOwned.ToString());
296 writer.WriteEndElement(); 305 writer.WriteEndElement();
306 if (inventoryItem.CreatorData != null && inventoryItem.CreatorData != string.Empty)
307 writer.WriteElementString("CreatorData", inventoryItem.CreatorData);
308 else if (options.ContainsKey("profile"))
309 {
310 if (userAccountService != null)
311 {
312 UserAccount account = userAccountService.GetUserAccount(UUID.Zero, inventoryItem.CreatorIdAsUuid);
313 if (account != null)
314 {
315 writer.WriteElementString("CreatorData", (string)options["profile"] + "/" + inventoryItem.CreatorIdAsUuid + ";" + account.FirstName + " " + account.LastName);
316 }
317 writer.WriteElementString("CreatorID", inventoryItem.CreatorId);
318 }
319 }
297 320
298 writer.WriteEndElement(); 321 writer.WriteEndElement();
299 322