aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/HypergridService
diff options
context:
space:
mode:
authorMelanie Thielker2017-01-02 19:30:40 +0000
committerMelanie Thielker2017-01-02 19:30:40 +0000
commit966e50d90c9ef9b5fde9830b6b0e90290eb2ea47 (patch)
treefbd2834542e3135644f486cfcaae121300d8ee61 /OpenSim/Services/HypergridService
parentReplaced OpenMetaverse libs/xmls with new ones. Also added a file in openmeta... (diff)
downloadopensim-SC_OLD-966e50d90c9ef9b5fde9830b6b0e90290eb2ea47.zip
opensim-SC_OLD-966e50d90c9ef9b5fde9830b6b0e90290eb2ea47.tar.gz
opensim-SC_OLD-966e50d90c9ef9b5fde9830b6b0e90290eb2ea47.tar.bz2
opensim-SC_OLD-966e50d90c9ef9b5fde9830b6b0e90290eb2ea47.tar.xz
Add the HGRemoteAssetService. Allows to use any asset service with HG
Diffstat (limited to 'OpenSim/Services/HypergridService')
-rw-r--r--OpenSim/Services/HypergridService/HGRemoteAssetService.cs240
1 files changed, 240 insertions, 0 deletions
diff --git a/OpenSim/Services/HypergridService/HGRemoteAssetService.cs b/OpenSim/Services/HypergridService/HGRemoteAssetService.cs
new file mode 100644
index 0000000..a53435b
--- /dev/null
+++ b/OpenSim/Services/HypergridService/HGRemoteAssetService.cs
@@ -0,0 +1,240 @@
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.Framework.Serialization.External;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenSim.Services.AssetService;
42
43namespace OpenSim.Services.HypergridService
44{
45 /// <summary>
46 /// Hypergrid asset service. It serves the IAssetService interface,
47 /// but implements it in ways that are appropriate for inter-grid
48 /// asset exchanges.
49 /// </summary>
50 public class HGRemoteAssetService : IAssetService
51 {
52 private static readonly ILog m_log =
53 LogManager.GetLogger(
54 MethodBase.GetCurrentMethod().DeclaringType);
55
56 private string m_HomeURL;
57 private IUserAccountService m_UserAccountService;
58 private IAssetService m_assetConnector;
59
60 private UserAccountCache m_Cache;
61
62 private AssetPermissions m_AssetPerms;
63
64 public HGRemoteAssetService(IConfigSource config, string configName)
65 {
66 m_log.Debug("[HGRemoteAsset Service]: Starting");
67 IConfig assetConfig = config.Configs[configName];
68 if (assetConfig == null)
69 throw new Exception("No HGAssetService configuration");
70
71 Object[] args = new Object[] { config };
72
73 string assetConnectorDll = assetConfig.GetString("AssetConnector", String.Empty);
74 if (assetConnectorDll == String.Empty)
75 throw new Exception("Please specify AssetConnector in HGAssetService configuration");
76
77 m_assetConnector = ServerUtils.LoadPlugin<IAssetService>(assetConnectorDll, args);
78 if (m_assetConnector == null)
79 throw new Exception(String.Format("Unable to create AssetConnector from {0}", assetConnectorDll));
80
81 string userAccountsDll = assetConfig.GetString("UserAccountsService", string.Empty);
82 if (userAccountsDll == string.Empty)
83 throw new Exception("Please specify UserAccountsService in HGAssetService configuration");
84
85 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
86 if (m_UserAccountService == null)
87 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
88
89 m_HomeURL = Util.GetConfigVarFromSections<string>(config, "HomeURI",
90 new string[] { "Startup", "Hypergrid", configName }, string.Empty);
91 if (m_HomeURL == string.Empty)
92 throw new Exception("[HGAssetService] No HomeURI specified");
93
94 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
95
96 // Permissions
97 m_AssetPerms = new AssetPermissions(assetConfig);
98
99 }
100
101 #region IAssetService overrides
102 public AssetBase Get(string id)
103 {
104 AssetBase asset = m_assetConnector.Get(id);
105
106 if (asset == null)
107 return null;
108
109 if (!m_AssetPerms.AllowedExport(asset.Type))
110 return null;
111
112 if (asset.Metadata.Type == (sbyte)AssetType.Object)
113 asset.Data = AdjustIdentifiers(asset.Data);
114
115 AdjustIdentifiers(asset.Metadata);
116
117 return asset;
118 }
119
120 public AssetMetadata GetMetadata(string id)
121 {
122 AssetMetadata meta = m_assetConnector.GetMetadata(id);
123
124 if (meta == null)
125 return null;
126
127 AdjustIdentifiers(meta);
128
129 return meta;
130 }
131
132 public byte[] GetData(string id)
133 {
134 AssetBase asset = Get(id);
135
136 if (asset == null)
137 return null;
138
139 if (!m_AssetPerms.AllowedExport(asset.Type))
140 return null;
141
142 // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
143 // Fix bad assets before sending them elsewhere
144 if (asset.Type == (int)AssetType.Object && asset.Data != null)
145 {
146 string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
147 asset.Data = Utils.StringToBytes(xml);
148 }
149
150 return asset.Data;
151 }
152
153 // public delegate void AssetRetrieved(string id, Object sender, AssetBase asset);
154 public virtual bool Get(string id, Object sender, AssetRetrieved handler)
155 {
156 return m_assetConnector.Get(id, sender, (i, s, asset) =>
157 {
158 if (asset != null)
159 {
160 if (!m_AssetPerms.AllowedExport(asset.Type))
161 {
162 asset = null;
163 }
164 else
165 {
166 if (asset.Metadata.Type == (sbyte)AssetType.Object)
167 asset.Data = AdjustIdentifiers(asset.Data);
168
169 AdjustIdentifiers(asset.Metadata);
170 }
171 }
172
173 handler(i, s, asset);
174 });
175 }
176
177 public string Store(AssetBase asset)
178 {
179 if (!m_AssetPerms.AllowedImport(asset.Type))
180 return string.Empty;
181
182 // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
183 // Fix bad assets before storing on this server
184 if (asset.Type == (int)AssetType.Object && asset.Data != null)
185 {
186 string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
187 asset.Data = Utils.StringToBytes(xml);
188 }
189
190 return m_assetConnector.Store(asset);
191 }
192
193 public bool Delete(string id)
194 {
195 // NOGO
196 return false;
197 }
198
199 #endregion
200
201 protected void AdjustIdentifiers(AssetMetadata meta)
202 {
203 if (meta == null || m_Cache == null)
204 return;
205
206 UserAccount creator = m_Cache.GetUser(meta.CreatorID);
207 if (creator != null)
208 meta.CreatorID = meta.CreatorID + ";" + m_HomeURL + "/" + creator.FirstName + " " + creator.LastName;
209 }
210
211 // Only for Object
212 protected byte[] AdjustIdentifiers(byte[] data)
213 {
214 string xml = Utils.BytesToString(data);
215
216 // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
217 // Fix bad assets before sending them elsewhere
218 xml = ExternalRepresentationUtils.SanitizeXml(xml);
219
220 return Utils.StringToBytes(ExternalRepresentationUtils.RewriteSOP(xml, "HGAssetService", m_HomeURL, m_Cache, UUID.Zero));
221 }
222
223 public AssetBase GetCached(string id)
224 {
225 return Get(id);
226 }
227
228 public bool[] AssetsExist(string[] ids)
229 {
230 return m_assetConnector.AssetsExist(ids);
231 }
232
233 public bool UpdateContent(string id, byte[] data)
234 {
235 // SO not happening!!
236 return false;
237 }
238 }
239
240}