aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/AgentCircuitData.cs35
-rw-r--r--OpenSim/Framework/AssetLandmark.cs12
-rw-r--r--OpenSim/Framework/AvatarAppearance.cs36
-rw-r--r--OpenSim/Framework/Capabilities/Caps.cs4
-rw-r--r--OpenSim/Framework/ChildAgentDataUpdate.cs10
-rw-r--r--OpenSim/Framework/Communications/Osp/OspInventoryWrapperPlugin.cs104
-rw-r--r--OpenSim/Framework/IScene.cs2
-rw-r--r--OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs99
-rw-r--r--OpenSim/Framework/Serialization/External/OspResolver.cs (renamed from OpenSim/Framework/Communications/Osp/OspResolver.cs)8
-rw-r--r--OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs225
-rw-r--r--OpenSim/Framework/Util.cs81
11 files changed, 438 insertions, 178 deletions
diff --git a/OpenSim/Framework/AgentCircuitData.cs b/OpenSim/Framework/AgentCircuitData.cs
index cc9fcea..1600bdc 100644
--- a/OpenSim/Framework/AgentCircuitData.cs
+++ b/OpenSim/Framework/AgentCircuitData.cs
@@ -302,31 +302,26 @@ namespace OpenSim.Framework
302 if (args["start_pos"] != null) 302 if (args["start_pos"] != null)
303 Vector3.TryParse(args["start_pos"].AsString(), out startpos); 303 Vector3.TryParse(args["start_pos"].AsString(), out startpos);
304 304
305// DEBUG ON 305 m_log.InfoFormat("[AGENTCIRCUITDATA] agentid={0}, child={1}, startpos={2}",AgentID,child,startpos.ToString());
306 m_log.WarnFormat("[AGENTCIRCUITDATA] agentid={0}, child={1}, startpos={2}",AgentID,child,startpos.ToString());
307// DEBUG OFF
308 306
309 try { 307 try {
310 // Unpack various appearance elements 308 // Unpack various appearance elements
311 Appearance = new AvatarAppearance(AgentID); 309 Appearance = new AvatarAppearance(AgentID);
312 310
313 // Eventually this code should be deprecated, use full appearance 311 // Eventually this code should be deprecated, use full appearance
314 // packing in packed_appearance 312 // packing in packed_appearance
315 if (args["appearance_serial"] != null) 313 if (args["appearance_serial"] != null)
316 Appearance.Serial = args["appearance_serial"].AsInteger(); 314 Appearance.Serial = args["appearance_serial"].AsInteger();
317 315
318 if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map)) 316 if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map))
319 { 317 {
320 Appearance.Unpack((OSDMap)args["packed_appearance"]); 318 Appearance.Unpack((OSDMap)args["packed_appearance"]);
321// DEBUG ON 319 m_log.InfoFormat("[AGENTCIRCUITDATA] unpacked appearance");
322 m_log.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance"); 320 }
323// DEBUG OFF 321 else
322 m_log.Warn("[AGENTCIRCUITDATA] failed to find a valid packed_appearance");
324 } 323 }
325// DEBUG ON 324 catch (Exception e)
326 else
327 m_log.Warn("[AGENTCIRCUITDATA] failed to find a valid packed_appearance");
328// DEBUG OFF
329 } catch (Exception e)
330 { 325 {
331 m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}",e.Message); 326 m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}",e.Message);
332 } 327 }
diff --git a/OpenSim/Framework/AssetLandmark.cs b/OpenSim/Framework/AssetLandmark.cs
index 7806c1f..f433235 100644
--- a/OpenSim/Framework/AssetLandmark.cs
+++ b/OpenSim/Framework/AssetLandmark.cs
@@ -51,8 +51,16 @@ namespace OpenSim.Framework
51 string[] parts = temp.Split('\n'); 51 string[] parts = temp.Split('\n');
52 int.TryParse(parts[0].Substring(17, 1), out Version); 52 int.TryParse(parts[0].Substring(17, 1), out Version);
53 UUID.TryParse(parts[1].Substring(10, 36), out RegionID); 53 UUID.TryParse(parts[1].Substring(10, 36), out RegionID);
54 // the vector is stored with spaces as separators, not with commas ("10.3 32.5 43" instead of "10.3, 32.5, 43") 54 // The position is a vector with spaces as separators ("10.3 32.5 43").
55 Vector3.TryParse(parts[2].Substring(10, parts[2].Length - 10).Replace(" ", ","), out Position); 55 // Parse each scalar separately to take into account the system's culture setting.
56 string[] scalars = parts[2].Substring(10, parts[2].Length - 10).Split(' ');
57 if (scalars.Length > 0)
58 System.Single.TryParse(scalars[0], out Position.X);
59 if (scalars.Length > 1)
60 System.Single.TryParse(scalars[1], out Position.Y);
61 if (scalars.Length > 2)
62 System.Single.TryParse(scalars[2], out Position.Z);
63
56 ulong.TryParse(parts[3].Substring(14, parts[3].Length - 14), out RegionHandle); 64 ulong.TryParse(parts[3].Substring(14, parts[3].Length - 14), out RegionHandle);
57 } 65 }
58 } 66 }
diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs
index 2906af8..18a5733 100644
--- a/OpenSim/Framework/AvatarAppearance.cs
+++ b/OpenSim/Framework/AvatarAppearance.cs
@@ -48,7 +48,7 @@ namespace OpenSim.Framework
48 public readonly static byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; 48 public readonly static byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
49 49
50 protected UUID m_owner; 50 protected UUID m_owner;
51 protected int m_serial = 1; 51 protected int m_serial = 0;
52 protected byte[] m_visualparams; 52 protected byte[] m_visualparams;
53 protected Primitive.TextureEntry m_texture; 53 protected Primitive.TextureEntry m_texture;
54 protected AvatarWearable[] m_wearables; 54 protected AvatarWearable[] m_wearables;
@@ -103,7 +103,7 @@ namespace OpenSim.Framework
103 { 103 {
104// m_log.WarnFormat("[AVATAR APPEARANCE]: create empty appearance for {0}",owner); 104// m_log.WarnFormat("[AVATAR APPEARANCE]: create empty appearance for {0}",owner);
105 105
106 m_serial = 1; 106 m_serial = 0;
107 m_owner = owner; 107 m_owner = owner;
108 108
109 SetDefaultWearables(); 109 SetDefaultWearables();
@@ -127,7 +127,7 @@ namespace OpenSim.Framework
127 { 127 {
128// m_log.WarnFormat("[AVATAR APPEARANCE] create initialized appearance for {0}",avatarID); 128// m_log.WarnFormat("[AVATAR APPEARANCE] create initialized appearance for {0}",avatarID);
129 129
130 m_serial = 1; 130 m_serial = 0;
131 m_owner = avatarID; 131 m_owner = avatarID;
132 132
133 if (wearables != null) 133 if (wearables != null)
@@ -160,7 +160,7 @@ namespace OpenSim.Framework
160 160
161 if (appearance == null) 161 if (appearance == null)
162 { 162 {
163 m_serial = 1; 163 m_serial = 0;
164 m_owner = UUID.Zero; 164 m_owner = UUID.Zero;
165 165
166 SetDefaultWearables(); 166 SetDefaultWearables();
@@ -229,6 +229,24 @@ namespace OpenSim.Framework
229 m_wearables = AvatarWearable.DefaultWearables; 229 m_wearables = AvatarWearable.DefaultWearables;
230 } 230 }
231 231
232 /// <summary>
233 /// Invalidate all of the baked textures in the appearance, useful
234 /// if you know that none are valid
235 /// </summary>
236 public virtual void ResetAppearance()
237 {
238 m_serial = 0;
239
240 SetDefaultParams();
241 SetDefaultTexture();
242
243 //for (int i = 0; i < BAKE_INDICES.Length; i++)
244 // {
245 // int idx = BAKE_INDICES[i];
246 // m_texture.FaceTextures[idx].TextureID = UUID.Zero;
247 // }
248 }
249
232 protected virtual void SetDefaultParams() 250 protected virtual void SetDefaultParams()
233 { 251 {
234 m_visualparams = new byte[] { 33,61,85,23,58,127,63,85,63,42,0,85,63,36,85,95,153,63,34,0,63,109,88,132,63,136,81,85,103,136,127,0,150,150,150,127,0,0,0,0,0,127,0,0,255,127,114,127,99,63,127,140,127,127,0,0,0,191,0,104,0,0,0,0,0,0,0,0,0,145,216,133,0,127,0,127,170,0,0,127,127,109,85,127,127,63,85,42,150,150,150,150,150,150,150,25,150,150,150,0,127,0,0,144,85,127,132,127,85,0,127,127,127,127,127,127,59,127,85,127,127,106,47,79,127,127,204,2,141,66,0,0,127,127,0,0,0,0,127,0,159,0,0,178,127,36,85,131,127,127,127,153,95,0,140,75,27,127,127,0,150,150,198,0,0,63,30,127,165,209,198,127,127,153,204,51,51,255,255,255,204,0,255,150,150,150,150,150,150,150,150,150,150,0,150,150,150,150,150,0,127,127,150,150,150,150,150,150,150,150,0,0,150,51,132,150,150,150 }; 252 m_visualparams = new byte[] { 33,61,85,23,58,127,63,85,63,42,0,85,63,36,85,95,153,63,34,0,63,109,88,132,63,136,81,85,103,136,127,0,150,150,150,127,0,0,0,0,0,127,0,0,255,127,114,127,99,63,127,140,127,127,0,0,0,191,0,104,0,0,0,0,0,0,0,0,0,145,216,133,0,127,0,127,170,0,0,127,127,109,85,127,127,63,85,42,150,150,150,150,150,150,150,25,150,150,150,0,127,0,0,144,85,127,132,127,85,0,127,127,127,127,127,127,59,127,85,127,127,106,47,79,127,127,204,2,141,66,0,0,127,127,0,0,0,0,127,0,159,0,0,178,127,36,85,131,127,127,127,153,95,0,140,75,27,127,127,0,150,150,198,0,0,63,30,127,165,209,198,127,127,153,204,51,51,255,255,255,204,0,255,150,150,150,150,150,150,150,150,150,150,0,150,150,150,150,150,0,127,127,150,150,150,150,150,150,150,150,0,0,150,51,132,150,150,150 };
@@ -240,9 +258,10 @@ namespace OpenSim.Framework
240 258
241 protected virtual void SetDefaultTexture() 259 protected virtual void SetDefaultTexture()
242 { 260 {
243 m_texture = new Primitive.TextureEntry(new UUID("C228D1CF-4B5D-4BA8-84F4-899A0796AA97")); 261 m_texture = new Primitive.TextureEntry(new UUID(AppearanceManager.DEFAULT_AVATAR_TEXTURE));
244 for (uint i = 0; i < TEXTURE_COUNT; i++) 262
245 m_texture.CreateFace(i).TextureID = new UUID(AppearanceManager.DEFAULT_AVATAR_TEXTURE); 263 // for (uint i = 0; i < TEXTURE_COUNT; i++)
264 // m_texture.CreateFace(i).TextureID = new UUID(AppearanceManager.DEFAULT_AVATAR_TEXTURE);
246 } 265 }
247 266
248 /// <summary> 267 /// <summary>
@@ -274,9 +293,6 @@ namespace OpenSim.Framework
274 } 293 }
275 294
276 changed = true; 295 changed = true;
277
278// if (newface != null)
279// m_log.WarnFormat("[AVATAR APPEARANCE]: index {0}, new texture id {1}",i,newface.TextureID);
280 } 296 }
281 297
282 m_texture = textureEntry; 298 m_texture = textureEntry;
diff --git a/OpenSim/Framework/Capabilities/Caps.cs b/OpenSim/Framework/Capabilities/Caps.cs
index e7f2e13..63e1e34 100644
--- a/OpenSim/Framework/Capabilities/Caps.cs
+++ b/OpenSim/Framework/Capabilities/Caps.cs
@@ -990,6 +990,7 @@ namespace OpenSim.Framework.Capabilities
990 public void BakedTextureUploaded(UUID assetID, byte[] data) 990 public void BakedTextureUploaded(UUID assetID, byte[] data)
991 { 991 {
992// m_log.WarnFormat("[CAPS]: Received baked texture {0}", assetID.ToString()); 992// m_log.WarnFormat("[CAPS]: Received baked texture {0}", assetID.ToString());
993
993 AssetBase asset; 994 AssetBase asset;
994 asset = new AssetBase(assetID, "Baked Texture", (sbyte)AssetType.Texture, m_agentID.ToString()); 995 asset = new AssetBase(assetID, "Baked Texture", (sbyte)AssetType.Texture, m_agentID.ToString());
995 asset.Data = data; 996 asset.Data = data;
@@ -1331,6 +1332,7 @@ namespace OpenSim.Framework.Capabilities
1331 newAssetID = UUID.Random(); 1332 newAssetID = UUID.Random();
1332 uploaderPath = path; 1333 uploaderPath = path;
1333 httpListener = httpServer; 1334 httpListener = httpServer;
1335 m_log.InfoFormat("[CAPS] baked texture upload starting for {0}",newAssetID);
1334 } 1336 }
1335 1337
1336 /// <summary> 1338 /// <summary>
@@ -1358,6 +1360,8 @@ namespace OpenSim.Framework.Capabilities
1358 handlerUpLoad(newAssetID, data); 1360 handlerUpLoad(newAssetID, data);
1359 } 1361 }
1360 1362
1363 m_log.InfoFormat("[CAPS] baked texture upload completed for {0}",newAssetID);
1364
1361 return res; 1365 return res;
1362 } 1366 }
1363 } 1367 }
diff --git a/OpenSim/Framework/ChildAgentDataUpdate.cs b/OpenSim/Framework/ChildAgentDataUpdate.cs
index a227338..ce0b2fb 100644
--- a/OpenSim/Framework/ChildAgentDataUpdate.cs
+++ b/OpenSim/Framework/ChildAgentDataUpdate.cs
@@ -331,9 +331,7 @@ namespace OpenSim.Framework
331 331
332 public virtual OSDMap Pack() 332 public virtual OSDMap Pack()
333 { 333 {
334// DEBUG ON 334 m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Pack data");
335 m_log.WarnFormat("[CHILDAGENTDATAUPDATE] Pack data");
336// DEBUG OFF
337 335
338 OSDMap args = new OSDMap(); 336 OSDMap args = new OSDMap();
339 args["message_type"] = OSD.FromString("AgentData"); 337 args["message_type"] = OSD.FromString("AgentData");
@@ -454,9 +452,7 @@ namespace OpenSim.Framework
454 /// <param name="hash"></param> 452 /// <param name="hash"></param>
455 public virtual void Unpack(OSDMap args) 453 public virtual void Unpack(OSDMap args)
456 { 454 {
457// DEBUG ON 455 m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Unpack data");
458 m_log.WarnFormat("[CHILDAGENTDATAUPDATE] Unpack data");
459// DEBUG OFF
460 456
461 if (args.ContainsKey("region_id")) 457 if (args.ContainsKey("region_id"))
462 UUID.TryParse(args["region_id"].AsString(), out RegionID); 458 UUID.TryParse(args["region_id"].AsString(), out RegionID);
@@ -613,10 +609,8 @@ namespace OpenSim.Framework
613 609
614 if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map) 610 if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
615 Appearance = new AvatarAppearance(AgentID,(OSDMap)args["packed_appearance"]); 611 Appearance = new AvatarAppearance(AgentID,(OSDMap)args["packed_appearance"]);
616// DEBUG ON
617 else 612 else
618 m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance"); 613 m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
619// DEBUG OFF
620 614
621 if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array) 615 if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
622 { 616 {
diff --git a/OpenSim/Framework/Communications/Osp/OspInventoryWrapperPlugin.cs b/OpenSim/Framework/Communications/Osp/OspInventoryWrapperPlugin.cs
deleted file mode 100644
index bcd1eee..0000000
--- a/OpenSim/Framework/Communications/Osp/OspInventoryWrapperPlugin.cs
+++ /dev/null
@@ -1,104 +0,0 @@
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.Collections.Generic;
29using OpenSim.Data;
30using OpenMetaverse;
31using OpenSim.Services.Interfaces;
32
33namespace OpenSim.Framework.Communications.Osp
34{
35 /// <summary>
36 /// Wrap other inventory data plugins so that we can perform OSP related post processing for items
37 /// </summary>
38 public class OspInventoryWrapperPlugin : IInventoryDataPlugin
39 {
40 protected IInventoryDataPlugin m_wrappedPlugin;
41 //protected CommunicationsManager m_commsManager;
42 protected IUserAccountService m_userAccountService;
43
44 public OspInventoryWrapperPlugin(IInventoryDataPlugin wrappedPlugin, IUserAccountService userService)
45 {
46 m_wrappedPlugin = wrappedPlugin;
47 m_userAccountService = userService;
48 }
49
50 public string Name { get { return "OspInventoryWrapperPlugin"; } }
51 public string Version { get { return "0.1"; } }
52 public void Initialise() {}
53 public void Initialise(string connect) {}
54 public void Dispose() {}
55
56 public InventoryItemBase getInventoryItem(UUID item)
57 {
58 return PostProcessItem(m_wrappedPlugin.getInventoryItem(item));
59 }
60
61 // XXX: Why on earth does this exist as it appears to duplicate getInventoryItem?
62 public InventoryItemBase queryInventoryItem(UUID item)
63 {
64 return PostProcessItem(m_wrappedPlugin.queryInventoryItem(item));
65 }
66
67 public List<InventoryItemBase> getInventoryInFolder(UUID folderID)
68 {
69 List<InventoryItemBase> items = m_wrappedPlugin.getInventoryInFolder(folderID);
70
71 foreach (InventoryItemBase item in items)
72 PostProcessItem(item);
73
74 return items;
75 }
76
77 public List<InventoryItemBase> fetchActiveGestures(UUID avatarID)
78 {
79 return m_wrappedPlugin.fetchActiveGestures(avatarID);
80
81 // Presuming that no post processing is needed here as gestures don't refer to creator information (?)
82 }
83
84 protected InventoryItemBase PostProcessItem(InventoryItemBase item)
85 {
86 item.CreatorIdAsUuid = OspResolver.ResolveOspa(item.CreatorId, m_userAccountService);
87 return item;
88 }
89
90 public List<InventoryFolderBase> getFolderHierarchy(UUID parentID) { return m_wrappedPlugin.getFolderHierarchy(parentID); }
91 public List<InventoryFolderBase> getUserRootFolders(UUID user) { return m_wrappedPlugin.getUserRootFolders(user); }
92 public InventoryFolderBase getUserRootFolder(UUID user) { return m_wrappedPlugin.getUserRootFolder(user); }
93 public List<InventoryFolderBase> getInventoryFolders(UUID parentID) { return m_wrappedPlugin.getInventoryFolders(parentID); }
94 public InventoryFolderBase getInventoryFolder(UUID folder) { return m_wrappedPlugin.getInventoryFolder(folder); }
95 public void addInventoryItem(InventoryItemBase item) { m_wrappedPlugin.addInventoryItem(item); }
96 public void updateInventoryItem(InventoryItemBase item) { m_wrappedPlugin.updateInventoryItem(item); }
97 public void deleteInventoryItem(UUID item) { m_wrappedPlugin.deleteInventoryItem(item); }
98 public InventoryFolderBase queryInventoryFolder(UUID folder) { return m_wrappedPlugin.queryInventoryFolder(folder); }
99 public void addInventoryFolder(InventoryFolderBase folder) { m_wrappedPlugin.addInventoryFolder(folder); }
100 public void updateInventoryFolder(InventoryFolderBase folder) { m_wrappedPlugin.updateInventoryFolder(folder); }
101 public void moveInventoryFolder(InventoryFolderBase folder) { m_wrappedPlugin.moveInventoryFolder(folder); }
102 public void deleteInventoryFolder(UUID folder) { m_wrappedPlugin.deleteInventoryFolder(folder); }
103 }
104}
diff --git a/OpenSim/Framework/IScene.cs b/OpenSim/Framework/IScene.cs
index 6798b7b..1298f26 100644
--- a/OpenSim/Framework/IScene.cs
+++ b/OpenSim/Framework/IScene.cs
@@ -73,7 +73,7 @@ namespace OpenSim.Framework
73 void AddNewClient(IClientAPI client); 73 void AddNewClient(IClientAPI client);
74 void RemoveClient(UUID agentID); 74 void RemoveClient(UUID agentID);
75 75
76 void Restart(int seconds); 76 void Restart();
77 //RegionInfo OtherRegionUp(RegionInfo thisRegion); 77 //RegionInfo OtherRegionUp(RegionInfo thisRegion);
78 78
79 string GetSimulatorVersion(); 79 string GetSimulatorVersion();
diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
new file mode 100644
index 0000000..6e8c2ee
--- /dev/null
+++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
@@ -0,0 +1,99 @@
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 /// <summary>
38 /// Utilities for manipulating external representations of data structures in OpenSim
39 /// </summary>
40 public class ExternalRepresentationUtils
41 {
42 /// <summary>
43 /// Takes a XML representation of a SceneObjectPart and returns another XML representation
44 /// with creator data added to it.
45 /// </summary>
46 /// <param name="xml">The SceneObjectPart represented in XML2</param>
47 /// <param name="profileURL">The URL of the profile service for the creator</param>
48 /// <param name="userService">The service for retrieving user account information</param>
49 /// <param name="scopeID">The scope of the user account information (Grid ID)</param>
50 /// <returns>The SceneObjectPart represented in XML2</returns>
51 public static string RewriteSOP(string xml, string profileURL, IUserAccountService userService, UUID scopeID)
52 {
53 if (xml == string.Empty || profileURL == string.Empty || userService == null)
54 return xml;
55
56 XmlDocument doc = new XmlDocument();
57 doc.LoadXml(xml);
58 XmlNodeList sops = doc.GetElementsByTagName("SceneObjectPart");
59
60 foreach (XmlNode sop in sops)
61 {
62 UserAccount creator = null;
63 bool hasCreatorData = false;
64 XmlNodeList nodes = sop.ChildNodes;
65 foreach (XmlNode node in nodes)
66 {
67 if (node.Name == "CreatorID")
68 {
69 UUID uuid = UUID.Zero;
70 UUID.TryParse(node.InnerText, out uuid);
71 creator = userService.GetUserAccount(scopeID, uuid);
72 }
73 if (node.Name == "CreatorData" && node.InnerText != null && node.InnerText != string.Empty)
74 hasCreatorData = true;
75
76 //if (node.Name == "OwnerID")
77 //{
78 // UserAccount owner = GetUser(node.InnerText);
79 // if (owner != null)
80 // node.InnerText = m_ProfileServiceURL + "/" + node.InnerText + "/" + owner.FirstName + " " + owner.LastName;
81 //}
82 }
83 if (!hasCreatorData && creator != null)
84 {
85 XmlElement creatorData = doc.CreateElement("CreatorData");
86 creatorData.InnerText = profileURL + "/" + creator.PrincipalID + ";" + creator.FirstName + " " + creator.LastName;
87 sop.AppendChild(creatorData);
88 }
89 }
90
91 using (StringWriter wr = new StringWriter())
92 {
93 doc.Save(wr);
94 return wr.ToString();
95 }
96
97 }
98 }
99}
diff --git a/OpenSim/Framework/Communications/Osp/OspResolver.cs b/OpenSim/Framework/Serialization/External/OspResolver.cs
index 24ea64d..7e3dd1b 100644
--- a/OpenSim/Framework/Communications/Osp/OspResolver.cs
+++ b/OpenSim/Framework/Serialization/External/OspResolver.cs
@@ -32,7 +32,7 @@ using OpenMetaverse;
32using OpenSim.Framework; 32using OpenSim.Framework;
33using OpenSim.Services.Interfaces; 33using OpenSim.Services.Interfaces;
34 34
35namespace OpenSim.Framework.Communications.Osp 35namespace OpenSim.Framework.Serialization
36{ 36{
37 /// <summary> 37 /// <summary>
38 /// Resolves OpenSim Profile Anchors (OSPA). An OSPA is a string used to provide information for 38 /// Resolves OpenSim Profile Anchors (OSPA). An OSPA is a string used to provide information for
@@ -57,6 +57,12 @@ namespace OpenSim.Framework.Communications.Osp
57 /// <returns>The OSPA. Null if a user with the given UUID could not be found.</returns> 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) 58 public static string MakeOspa(UUID userId, IUserAccountService userService)
59 { 59 {
60 if (userService == null)
61 {
62 m_log.Warn("[OSP RESOLVER]: UserService is null");
63 return userId.ToString();
64 }
65
60 UserAccount account = userService.GetUserAccount(UUID.Zero, userId); 66 UserAccount account = userService.GetUserAccount(UUID.Zero, userId);
61 if (account != null) 67 if (account != null)
62 return MakeOspa(account.FirstName, account.LastName); 68 return MakeOspa(account.FirstName, account.LastName);
diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
index 862cc72..d5e84c7 100644
--- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
@@ -26,11 +26,16 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
29using System.IO; 30using System.IO;
31using System.Reflection;
30using System.Text; 32using System.Text;
31using System.Xml; 33using System.Xml;
34
35using log4net;
32using OpenMetaverse; 36using OpenMetaverse;
33using OpenSim.Framework; 37using OpenSim.Framework;
38using OpenSim.Services.Interfaces;
34 39
35namespace OpenSim.Framework.Serialization.External 40namespace OpenSim.Framework.Serialization.External
36{ 41{
@@ -40,6 +45,141 @@ namespace OpenSim.Framework.Serialization.External
40 /// XXX: Please do not use yet. 45 /// XXX: Please do not use yet.
41 public class UserInventoryItemSerializer 46 public class UserInventoryItemSerializer
42 { 47 {
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49
50 private delegate void InventoryItemXmlProcessor(InventoryItemBase item, XmlTextReader reader);
51 private static Dictionary<string, InventoryItemXmlProcessor> m_InventoryItemXmlProcessors = new Dictionary<string, InventoryItemXmlProcessor>();
52
53 #region InventoryItemBase Processor initialization
54 static UserInventoryItemSerializer()
55 {
56 m_InventoryItemXmlProcessors.Add("Name", ProcessName);
57 m_InventoryItemXmlProcessors.Add("ID", ProcessID);
58 m_InventoryItemXmlProcessors.Add("InvType", ProcessInvType);
59 m_InventoryItemXmlProcessors.Add("CreatorUUID", ProcessCreatorUUID);
60 m_InventoryItemXmlProcessors.Add("CreatorID", ProcessCreatorID);
61 m_InventoryItemXmlProcessors.Add("CreatorData", ProcessCreatorData);
62 m_InventoryItemXmlProcessors.Add("CreationDate", ProcessCreationDate);
63 m_InventoryItemXmlProcessors.Add("Owner", ProcessOwner);
64 m_InventoryItemXmlProcessors.Add("Description", ProcessDescription);
65 m_InventoryItemXmlProcessors.Add("AssetType", ProcessAssetType);
66 m_InventoryItemXmlProcessors.Add("AssetID", ProcessAssetID);
67 m_InventoryItemXmlProcessors.Add("SaleType", ProcessSaleType);
68 m_InventoryItemXmlProcessors.Add("SalePrice", ProcessSalePrice);
69 m_InventoryItemXmlProcessors.Add("BasePermissions", ProcessBasePermissions);
70 m_InventoryItemXmlProcessors.Add("CurrentPermissions", ProcessCurrentPermissions);
71 m_InventoryItemXmlProcessors.Add("EveryOnePermissions", ProcessEveryOnePermissions);
72 m_InventoryItemXmlProcessors.Add("NextPermissions", ProcessNextPermissions);
73 m_InventoryItemXmlProcessors.Add("Flags", ProcessFlags);
74 m_InventoryItemXmlProcessors.Add("GroupID", ProcessGroupID);
75 m_InventoryItemXmlProcessors.Add("GroupOwned", ProcessGroupOwned);
76 }
77 #endregion
78
79 #region InventoryItemBase Processors
80 private static void ProcessName(InventoryItemBase item, XmlTextReader reader)
81 {
82 item.Name = reader.ReadElementContentAsString("Name", String.Empty);
83 }
84
85 private static void ProcessID(InventoryItemBase item, XmlTextReader reader)
86 {
87 item.ID = Util.ReadUUID(reader, "ID");
88 }
89
90 private static void ProcessInvType(InventoryItemBase item, XmlTextReader reader)
91 {
92 item.InvType = reader.ReadElementContentAsInt("InvType", String.Empty);
93 }
94
95 private static void ProcessCreatorUUID(InventoryItemBase item, XmlTextReader reader)
96 {
97 item.CreatorId = reader.ReadElementContentAsString("CreatorUUID", String.Empty);
98 }
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
106 private static void ProcessCreationDate(InventoryItemBase item, XmlTextReader reader)
107 {
108 item.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty);
109 }
110
111 private static void ProcessOwner(InventoryItemBase item, XmlTextReader reader)
112 {
113 item.Owner = Util.ReadUUID(reader, "Owner");
114 }
115
116 private static void ProcessDescription(InventoryItemBase item, XmlTextReader reader)
117 {
118 item.Description = reader.ReadElementContentAsString("Description", String.Empty);
119 }
120
121 private static void ProcessAssetType(InventoryItemBase item, XmlTextReader reader)
122 {
123 item.AssetType = reader.ReadElementContentAsInt("AssetType", String.Empty);
124 }
125
126 private static void ProcessAssetID(InventoryItemBase item, XmlTextReader reader)
127 {
128 item.AssetID = Util.ReadUUID(reader, "AssetID");
129 }
130
131 private static void ProcessSaleType(InventoryItemBase item, XmlTextReader reader)
132 {
133 item.SaleType = (byte)reader.ReadElementContentAsInt("SaleType", String.Empty);
134 }
135
136 private static void ProcessSalePrice(InventoryItemBase item, XmlTextReader reader)
137 {
138 item.SalePrice = reader.ReadElementContentAsInt("SalePrice", String.Empty);
139 }
140
141 private static void ProcessBasePermissions(InventoryItemBase item, XmlTextReader reader)
142 {
143 item.BasePermissions = (uint)reader.ReadElementContentAsInt("BasePermissions", String.Empty);
144 }
145
146 private static void ProcessCurrentPermissions(InventoryItemBase item, XmlTextReader reader)
147 {
148 item.CurrentPermissions = (uint)reader.ReadElementContentAsInt("CurrentPermissions", String.Empty);
149 }
150
151 private static void ProcessEveryOnePermissions(InventoryItemBase item, XmlTextReader reader)
152 {
153 item.EveryOnePermissions = (uint)reader.ReadElementContentAsInt("EveryOnePermissions", String.Empty);
154 }
155
156 private static void ProcessNextPermissions(InventoryItemBase item, XmlTextReader reader)
157 {
158 item.NextPermissions = (uint)reader.ReadElementContentAsInt("NextPermissions", String.Empty);
159 }
160
161 private static void ProcessFlags(InventoryItemBase item, XmlTextReader reader)
162 {
163 item.Flags = (uint)reader.ReadElementContentAsInt("Flags", String.Empty);
164 }
165
166 private static void ProcessGroupID(InventoryItemBase item, XmlTextReader reader)
167 {
168 item.GroupID = Util.ReadUUID(reader, "GroupID");
169 }
170
171 private static void ProcessGroupOwned(InventoryItemBase item, XmlTextReader reader)
172 {
173 item.GroupOwned = Util.ReadBoolean(reader);
174 }
175
176 private static void ProcessCreatorData(InventoryItemBase item, XmlTextReader reader)
177 {
178 item.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty);
179 }
180
181 #endregion
182
43 /// <summary> 183 /// <summary>
44 /// Deserialize item 184 /// Deserialize item
45 /// </summary> 185 /// </summary>
@@ -60,40 +200,47 @@ namespace OpenSim.Framework.Serialization.External
60 public static InventoryItemBase Deserialize(string serialization) 200 public static InventoryItemBase Deserialize(string serialization)
61 { 201 {
62 InventoryItemBase item = new InventoryItemBase(); 202 InventoryItemBase item = new InventoryItemBase();
63 203
64 StringReader sr = new StringReader(serialization); 204 using (XmlTextReader reader = new XmlTextReader(new StringReader(serialization)))
65 XmlTextReader xtr = new XmlTextReader(sr); 205 {
66 206 reader.ReadStartElement("InventoryItem");
67 xtr.ReadStartElement("InventoryItem"); 207
68 208 string nodeName = string.Empty;
69 item.Name = xtr.ReadElementString("Name"); 209 while (reader.NodeType != XmlNodeType.EndElement)
70 item.ID = UUID.Parse( xtr.ReadElementString("ID")); 210 {
71 item.InvType = Convert.ToInt32( xtr.ReadElementString("InvType")); 211 nodeName = reader.Name;
72 item.CreatorId = xtr.ReadElementString("CreatorUUID"); 212 InventoryItemXmlProcessor p = null;
73 item.CreationDate = Convert.ToInt32( xtr.ReadElementString("CreationDate")); 213 if (m_InventoryItemXmlProcessors.TryGetValue(reader.Name, out p))
74 item.Owner = UUID.Parse( xtr.ReadElementString("Owner")); 214 {
75 item.Description = xtr.ReadElementString("Description"); 215 //m_log.DebugFormat("[XXX] Processing: {0}", reader.Name);
76 item.AssetType = Convert.ToInt32( xtr.ReadElementString("AssetType")); 216 try
77 item.AssetID = UUID.Parse( xtr.ReadElementString("AssetID")); 217 {
78 item.SaleType = Convert.ToByte( xtr.ReadElementString("SaleType")); 218 p(item, reader);
79 item.SalePrice = Convert.ToInt32( xtr.ReadElementString("SalePrice")); 219 }
80 item.BasePermissions = Convert.ToUInt32( xtr.ReadElementString("BasePermissions")); 220 catch (Exception e)
81 item.CurrentPermissions = Convert.ToUInt32( xtr.ReadElementString("CurrentPermissions")); 221 {
82 item.EveryOnePermissions = Convert.ToUInt32( xtr.ReadElementString("EveryOnePermissions")); 222 m_log.DebugFormat("[InventoryItemSerializer]: exception while parsing {0}: {1}", nodeName, e);
83 item.NextPermissions = Convert.ToUInt32( xtr.ReadElementString("NextPermissions")); 223 if (reader.NodeType == XmlNodeType.EndElement)
84 item.Flags = Convert.ToUInt32( xtr.ReadElementString("Flags")); 224 reader.Read();
85 item.GroupID = UUID.Parse( xtr.ReadElementString("GroupID")); 225 }
86 item.GroupOwned = Convert.ToBoolean(xtr.ReadElementString("GroupOwned")); 226 }
87 227 else
88 xtr.ReadEndElement(); 228 {
89 229 // m_log.DebugFormat("[InventoryItemSerializer]: caught unknown element {0}", nodeName);
90 xtr.Close(); 230 reader.ReadOuterXml(); // ignore
91 sr.Close(); 231 }
92 232
233 }
234
235 reader.ReadEndElement(); // InventoryItem
236 }
237
238 //m_log.DebugFormat("[XXX]: parsed InventoryItemBase {0} - {1}", obj.Name, obj.UUID);
93 return item; 239 return item;
240
94 } 241 }
95 242
96 public static string Serialize(InventoryItemBase inventoryItem) 243 public static string Serialize(InventoryItemBase inventoryItem, Dictionary<string, object> options, IUserAccountService userAccountService)
97 { 244 {
98 StringWriter sw = new StringWriter(); 245 StringWriter sw = new StringWriter();
99 XmlTextWriter writer = new XmlTextWriter(sw); 246 XmlTextWriter writer = new XmlTextWriter(sw);
@@ -112,7 +259,7 @@ namespace OpenSim.Framework.Serialization.External
112 writer.WriteString(inventoryItem.InvType.ToString()); 259 writer.WriteString(inventoryItem.InvType.ToString());
113 writer.WriteEndElement(); 260 writer.WriteEndElement();
114 writer.WriteStartElement("CreatorUUID"); 261 writer.WriteStartElement("CreatorUUID");
115 writer.WriteString(inventoryItem.CreatorId); 262 writer.WriteString(OspResolver.MakeOspa(inventoryItem.CreatorIdAsUuid, userAccountService));
116 writer.WriteEndElement(); 263 writer.WriteEndElement();
117 writer.WriteStartElement("CreationDate"); 264 writer.WriteStartElement("CreationDate");
118 writer.WriteString(inventoryItem.CreationDate.ToString()); 265 writer.WriteString(inventoryItem.CreationDate.ToString());
@@ -156,6 +303,20 @@ namespace OpenSim.Framework.Serialization.External
156 writer.WriteStartElement("GroupOwned"); 303 writer.WriteStartElement("GroupOwned");
157 writer.WriteString(inventoryItem.GroupOwned.ToString()); 304 writer.WriteString(inventoryItem.GroupOwned.ToString());
158 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 }
159 320
160 writer.WriteEndElement(); 321 writer.WriteEndElement();
161 322
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index e8f8e01..8d1671a 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1558,5 +1558,86 @@ namespace OpenSim.Framework
1558 return string.Empty; 1558 return string.Empty;
1559 } 1559 }
1560 1560
1561 #region Xml Serialization Utilities
1562 public static bool ReadBoolean(XmlTextReader reader)
1563 {
1564 reader.ReadStartElement();
1565 bool result = Boolean.Parse(reader.ReadContentAsString().ToLower());
1566 reader.ReadEndElement();
1567
1568 return result;
1569 }
1570
1571 public static UUID ReadUUID(XmlTextReader reader, string name)
1572 {
1573 UUID id;
1574 string idStr;
1575
1576 reader.ReadStartElement(name);
1577
1578 if (reader.Name == "Guid")
1579 idStr = reader.ReadElementString("Guid");
1580 else if (reader.Name == "UUID")
1581 idStr = reader.ReadElementString("UUID");
1582 else // no leading tag
1583 idStr = reader.ReadContentAsString();
1584 UUID.TryParse(idStr, out id);
1585 reader.ReadEndElement();
1586
1587 return id;
1588 }
1589
1590 public static Vector3 ReadVector(XmlTextReader reader, string name)
1591 {
1592 Vector3 vec;
1593
1594 reader.ReadStartElement(name);
1595 vec.X = reader.ReadElementContentAsFloat(reader.Name, String.Empty); // X or x
1596 vec.Y = reader.ReadElementContentAsFloat(reader.Name, String.Empty); // Y or y
1597 vec.Z = reader.ReadElementContentAsFloat(reader.Name, String.Empty); // Z or z
1598 reader.ReadEndElement();
1599
1600 return vec;
1601 }
1602
1603 public static Quaternion ReadQuaternion(XmlTextReader reader, string name)
1604 {
1605 Quaternion quat = new Quaternion();
1606
1607 reader.ReadStartElement(name);
1608 while (reader.NodeType != XmlNodeType.EndElement)
1609 {
1610 switch (reader.Name.ToLower())
1611 {
1612 case "x":
1613 quat.X = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
1614 break;
1615 case "y":
1616 quat.Y = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
1617 break;
1618 case "z":
1619 quat.Z = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
1620 break;
1621 case "w":
1622 quat.W = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
1623 break;
1624 }
1625 }
1626
1627 reader.ReadEndElement();
1628
1629 return quat;
1630 }
1631
1632 public static T ReadEnum<T>(XmlTextReader reader, string name)
1633 {
1634 string value = reader.ReadElementContentAsString(name, String.Empty);
1635 // !!!!! to deal with flags without commas
1636 if (value.Contains(" ") && !value.Contains(","))
1637 value = value.Replace(" ", ", ");
1638
1639 return (T)Enum.Parse(typeof(T), value); ;
1640 }
1641 #endregion
1561 } 1642 }
1562} 1643}