aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/HypergridService/HGFSAssetService.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/HypergridService/HGFSAssetService.cs189
1 files changed, 189 insertions, 0 deletions
diff --git a/OpenSim/Services/HypergridService/HGFSAssetService.cs b/OpenSim/Services/HypergridService/HGFSAssetService.cs
new file mode 100644
index 0000000..54e8ccb
--- /dev/null
+++ b/OpenSim/Services/HypergridService/HGFSAssetService.cs
@@ -0,0 +1,189 @@
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.Reflection;
29
30using Nini.Config;
31using log4net;
32using OpenMetaverse;
33
34using OpenSim.Framework;
35using OpenSim.Framework.Serialization.External;
36using OpenSim.Server.Base;
37using OpenSim.Services.Interfaces;
38using OpenSim.Services.FSAssetService;
39
40namespace OpenSim.Services.HypergridService
41{
42 /// <summary>
43 /// Hypergrid asset service. It serves the IAssetService interface,
44 /// but implements it in ways that are appropriate for inter-grid
45 /// asset exchanges. This version is for FSAssets.
46 /// </summary>
47 public class HGFSAssetService : FSAssetConnector, IAssetService
48 {
49 private static readonly ILog m_log =
50 LogManager.GetLogger(
51 MethodBase.GetCurrentMethod().DeclaringType);
52
53 private string m_HomeURL;
54 private IUserAccountService m_UserAccountService;
55
56 private UserAccountCache m_Cache;
57
58 private AssetPermissions m_AssetPerms;
59
60 public HGFSAssetService(IConfigSource config, string configName) : base(config, "AssetService")
61 {
62 m_log.Debug("[HGAsset Service]: Starting in FSAsset mode");
63 IConfig assetConfig = config.Configs[configName];
64 if (assetConfig == null)
65 throw new Exception("No HGAssetService configuration");
66
67 string userAccountsDll = assetConfig.GetString("UserAccountsService", string.Empty);
68 if (userAccountsDll == string.Empty)
69 throw new Exception("Please specify UserAccountsService in HGAssetService configuration");
70
71 Object[] args = new Object[] { config };
72 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
73 if (m_UserAccountService == null)
74 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
75
76 m_HomeURL = Util.GetConfigVarFromSections<string>(config, "HomeURI",
77 new string[] { "Startup", "Hypergrid", configName }, string.Empty);
78 if (m_HomeURL == string.Empty)
79 throw new Exception("[HGAssetService] No HomeURI specified");
80
81 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
82
83 // Permissions
84 m_AssetPerms = new AssetPermissions(assetConfig);
85 }
86
87 #region IAssetService overrides
88 public override AssetBase Get(string id)
89 {
90 AssetBase asset = base.Get(id);
91
92 if (asset == null)
93 return null;
94
95 if (!m_AssetPerms.AllowedExport(asset.Type))
96 return null;
97
98 if (asset.Metadata.Type == (sbyte)AssetType.Object)
99 asset.Data = AdjustIdentifiers(asset.Data);
100
101 AdjustIdentifiers(asset.Metadata);
102
103 return asset;
104 }
105
106 public override AssetMetadata GetMetadata(string id)
107 {
108 AssetMetadata meta = base.GetMetadata(id);
109
110 if (meta == null)
111 return null;
112
113 AdjustIdentifiers(meta);
114
115 return meta;
116 }
117
118 public override byte[] GetData(string id)
119 {
120 AssetBase asset = Get(id);
121
122 if (asset == null)
123 return null;
124
125 if (!m_AssetPerms.AllowedExport(asset.Type))
126 return null;
127
128 // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
129 // Fix bad assets before sending them elsewhere
130 if (asset.Type == (int)AssetType.Object && asset.Data != null)
131 {
132 string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
133 asset.Data = Utils.StringToBytes(xml);
134 }
135
136 return asset.Data;
137 }
138
139 //public virtual bool Get(string id, Object sender, AssetRetrieved handler)
140
141 public override string Store(AssetBase asset)
142 {
143 if (!m_AssetPerms.AllowedImport(asset.Type))
144 return string.Empty;
145
146 // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
147 // Fix bad assets before storing on this server
148 if (asset.Type == (int)AssetType.Object && asset.Data != null)
149 {
150 string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
151 asset.Data = Utils.StringToBytes(xml);
152 }
153
154 return base.Store(asset);
155 }
156
157 public override bool Delete(string id)
158 {
159 // NOGO
160 return false;
161 }
162
163 #endregion
164
165 protected void AdjustIdentifiers(AssetMetadata meta)
166 {
167 if (meta == null || m_Cache == null)
168 return;
169
170 UserAccount creator = m_Cache.GetUser(meta.CreatorID);
171 if (creator != null)
172 meta.CreatorID = meta.CreatorID + ";" + m_HomeURL + "/" + creator.FirstName + " " + creator.LastName;
173 }
174
175 // Only for Object
176 protected byte[] AdjustIdentifiers(byte[] data)
177 {
178 string xml = Utils.BytesToString(data);
179
180 // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
181 // Fix bad assets before sending them elsewhere
182 xml = ExternalRepresentationUtils.SanitizeXml(xml);
183
184 return Utils.StringToBytes(ExternalRepresentationUtils.RewriteSOP(xml, "HGAssetService", m_HomeURL, m_Cache, UUID.Zero));
185 }
186
187 }
188
189}