aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/HypergridService
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/HypergridService/HGAssetService.cs181
-rw-r--r--OpenSim/Services/HypergridService/HGInventoryService.cs (renamed from OpenSim/Services/InventoryService/HGInventoryService.cs)47
2 files changed, 220 insertions, 8 deletions
diff --git a/OpenSim/Services/HypergridService/HGAssetService.cs b/OpenSim/Services/HypergridService/HGAssetService.cs
new file mode 100644
index 0000000..6e0d4cd
--- /dev/null
+++ b/OpenSim/Services/HypergridService/HGAssetService.cs
@@ -0,0 +1,181 @@
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.Reflection;
31using System.Xml;
32
33using Nini.Config;
34using log4net;
35using OpenMetaverse;
36
37using OpenSim.Framework;
38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces;
40using OpenSim.Services.AssetService;
41
42namespace OpenSim.Services.HypergridService
43{
44 public class HGAssetService : OpenSim.Services.AssetService.AssetService, IAssetService
45 {
46 private static readonly ILog m_log =
47 LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType);
49
50 private string m_ProfileServiceURL;
51 private IUserAccountService m_UserAccountService;
52
53 private UserAccountCache m_Cache;
54
55 public HGAssetService(IConfigSource config) : base(config)
56 {
57 m_log.Debug("[HGAsset Service]: Starting");
58 IConfig assetConfig = config.Configs["HGAssetService"];
59 if (assetConfig == null)
60 throw new Exception("No HGAssetService configuration");
61
62 string userAccountsDll = assetConfig.GetString("UserAccountsService", string.Empty);
63 if (userAccountsDll == string.Empty)
64 throw new Exception("Please specify UserAccountsService in HGAssetService configuration");
65
66 Object[] args = new Object[] { config };
67 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
68 if (m_UserAccountService == null)
69 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
70
71 m_ProfileServiceURL = assetConfig.GetString("ProfileServerURI", string.Empty);
72
73 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
74 }
75
76 #region IAssetService overrides
77 public override AssetBase Get(string id)
78 {
79 AssetBase asset = base.Get(id);
80
81 if (asset == null)
82 return null;
83
84 if (asset.Metadata.Type == (sbyte)AssetType.Object)
85 asset.Data = AdjustIdentifiers(asset.Data); ;
86
87 AdjustIdentifiers(asset.Metadata);
88
89 return asset;
90 }
91
92 public override AssetMetadata GetMetadata(string id)
93 {
94 AssetMetadata meta = base.GetMetadata(id);
95
96 if (meta == null)
97 return null;
98
99 AdjustIdentifiers(meta);
100
101 return meta;
102 }
103
104 public override byte[] GetData(string id)
105 {
106 byte[] data = base.GetData(id);
107
108 if (data == null)
109 return null;
110
111 return AdjustIdentifiers(data);
112 }
113
114 //public virtual bool Get(string id, Object sender, AssetRetrieved handler)
115
116 public override bool Delete(string id)
117 {
118 // NOGO
119 return false;
120 }
121
122 #endregion
123
124 protected void AdjustIdentifiers(AssetMetadata meta)
125 {
126 UserAccount creator = m_Cache.GetUser(meta.CreatorID);
127 if (creator != null)
128 meta.CreatorID = m_ProfileServiceURL + "/" + meta.CreatorID + ";" + creator.FirstName + " " + creator.LastName;
129
130 }
131
132 protected byte[] AdjustIdentifiers(byte[] data)
133 {
134 string xml = Utils.BytesToString(data);
135 return Utils.StringToBytes(RewriteSOP(xml));
136 }
137
138 protected string RewriteSOP(string xml)
139 {
140 XmlDocument doc = new XmlDocument();
141 doc.LoadXml(xml);
142 XmlNodeList sops = doc.GetElementsByTagName("SceneObjectPart");
143
144 foreach (XmlNode sop in sops)
145 {
146 UserAccount creator = null;
147 bool hasCreatorData = false;
148 XmlNodeList nodes = sop.ChildNodes;
149 foreach (XmlNode node in nodes)
150 {
151 if (node.Name == "CreatorID")
152 creator = m_Cache.GetUser(node.InnerText);
153 if (node.Name == "CreatorData" && node.InnerText != null && node.InnerText != string.Empty)
154 hasCreatorData = true;
155
156 //if (node.Name == "OwnerID")
157 //{
158 // UserAccount owner = GetUser(node.InnerText);
159 // if (owner != null)
160 // node.InnerText = m_ProfileServiceURL + "/" + node.InnerText + "/" + owner.FirstName + " " + owner.LastName;
161 //}
162 }
163 if (!hasCreatorData && creator != null)
164 {
165 XmlElement creatorData = doc.CreateElement("CreatorData");
166 creatorData.InnerText = m_ProfileServiceURL + "/" + creator.PrincipalID + ";" + creator.FirstName + " " + creator.LastName;
167 sop.AppendChild(creatorData);
168 }
169 }
170
171 using (StringWriter wr = new StringWriter())
172 {
173 doc.Save(wr);
174 return wr.ToString();
175 }
176
177 }
178
179 }
180
181}
diff --git a/OpenSim/Services/InventoryService/HGInventoryService.cs b/OpenSim/Services/HypergridService/HGInventoryService.cs
index d62c008..a04f0c4 100644
--- a/OpenSim/Services/InventoryService/HGInventoryService.cs
+++ b/OpenSim/Services/HypergridService/HGInventoryService.cs
@@ -33,10 +33,12 @@ using Nini.Config;
33using System.Reflection; 33using System.Reflection;
34using OpenSim.Services.Base; 34using OpenSim.Services.Base;
35using OpenSim.Services.Interfaces; 35using OpenSim.Services.Interfaces;
36using OpenSim.Services.InventoryService;
36using OpenSim.Data; 37using OpenSim.Data;
37using OpenSim.Framework; 38using OpenSim.Framework;
39using OpenSim.Server.Base;
38 40
39namespace OpenSim.Services.InventoryService 41namespace OpenSim.Services.HypergridService
40{ 42{
41 public class HGInventoryService : XInventoryService, IInventoryService 43 public class HGInventoryService : XInventoryService, IInventoryService
42 { 44 {
@@ -46,9 +48,16 @@ namespace OpenSim.Services.InventoryService
46 48
47 protected new IXInventoryData m_Database; 49 protected new IXInventoryData m_Database;
48 50
51 private string m_ProfileServiceURL;
52 private IUserAccountService m_UserAccountService;
53
54 private UserAccountCache m_Cache;
55
49 public HGInventoryService(IConfigSource config) 56 public HGInventoryService(IConfigSource config)
50 : base(config) 57 : base(config)
51 { 58 {
59 m_log.Debug("[HGInventory Service]: Starting");
60
52 string dllName = String.Empty; 61 string dllName = String.Empty;
53 string connString = String.Empty; 62 string connString = String.Empty;
54 //string realm = "Inventory"; // OSG version doesn't use this 63 //string realm = "Inventory"; // OSG version doesn't use this
@@ -68,12 +77,25 @@ namespace OpenSim.Services.InventoryService
68 // 77 //
69 // Try reading the [InventoryService] section, if it exists 78 // Try reading the [InventoryService] section, if it exists
70 // 79 //
71 IConfig authConfig = config.Configs["InventoryService"]; 80 IConfig invConfig = config.Configs["HGInventoryService"];
72 if (authConfig != null) 81 if (invConfig != null)
73 { 82 {
74 dllName = authConfig.GetString("StorageProvider", dllName); 83 dllName = invConfig.GetString("StorageProvider", dllName);
75 connString = authConfig.GetString("ConnectionString", connString); 84 connString = invConfig.GetString("ConnectionString", connString);
85
76 // realm = authConfig.GetString("Realm", realm); 86 // realm = authConfig.GetString("Realm", realm);
87 string userAccountsDll = invConfig.GetString("UserAccountsService", string.Empty);
88 if (userAccountsDll == string.Empty)
89 throw new Exception("Please specify UserAccountsService in HGInventoryService configuration");
90
91 Object[] args = new Object[] { config };
92 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
93 if (m_UserAccountService == null)
94 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
95
96 m_ProfileServiceURL = invConfig.GetString("ProfileServerURI", string.Empty);
97
98 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
77 } 99 }
78 100
79 // 101 //
@@ -282,9 +304,18 @@ namespace OpenSim.Services.InventoryService
282 //{ 304 //{
283 //} 305 //}
284 306
285 //public InventoryItemBase GetItem(InventoryItemBase item) 307 public override InventoryItemBase GetItem(InventoryItemBase item)
286 //{ 308 {
287 //} 309 InventoryItemBase it = base.GetItem(item);
310
311 UserAccount user = m_Cache.GetUser(it.CreatorId);
312
313 // Adjust the creator data
314 if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty))
315 it.CreatorData = m_ProfileServiceURL + "/" + it.CreatorId + ";" + user.FirstName + " " + user.LastName;
316
317 return it;
318 }
288 319
289 //public InventoryFolderBase GetFolder(InventoryFolderBase folder) 320 //public InventoryFolderBase GetFolder(InventoryFolderBase folder)
290 //{ 321 //{