diff options
author | AliciaRaven | 2015-08-02 20:02:36 +0100 |
---|---|---|
committer | AliciaRaven | 2015-08-02 20:02:36 +0100 |
commit | ce62824b1f57308ca463386783c907d4d8c5696f (patch) | |
tree | 1795e4d3efd78580b9292c6e66863bd2075b5e34 /OpenSim | |
parent | osKey2Name returns now correct values for HG users who are not on the region. (diff) | |
download | opensim-SC_OLD-ce62824b1f57308ca463386783c907d4d8c5696f.zip opensim-SC_OLD-ce62824b1f57308ca463386783c907d4d8c5696f.tar.gz opensim-SC_OLD-ce62824b1f57308ca463386783c907d4d8c5696f.tar.bz2 opensim-SC_OLD-ce62824b1f57308ca463386783c907d4d8c5696f.tar.xz |
Add HGFSAssetService to the HypergridService to provide HG support for FSAssets.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Services/FSAssetService/FSAssetService.cs | 10 | ||||
-rw-r--r-- | OpenSim/Services/HypergridService/HGFSAssetService.cs | 189 |
2 files changed, 194 insertions, 5 deletions
diff --git a/OpenSim/Services/FSAssetService/FSAssetService.cs b/OpenSim/Services/FSAssetService/FSAssetService.cs index c2e379b..1bab687 100644 --- a/OpenSim/Services/FSAssetService/FSAssetService.cs +++ b/OpenSim/Services/FSAssetService/FSAssetService.cs | |||
@@ -330,7 +330,7 @@ namespace OpenSim.Services.FSAssetService | |||
330 | return Path.Combine(HashToPath(hash), hash); | 330 | return Path.Combine(HashToPath(hash), hash); |
331 | } | 331 | } |
332 | 332 | ||
333 | public AssetBase Get(string id) | 333 | public virtual AssetBase Get(string id) |
334 | { | 334 | { |
335 | string hash; | 335 | string hash; |
336 | 336 | ||
@@ -434,13 +434,13 @@ namespace OpenSim.Services.FSAssetService | |||
434 | } | 434 | } |
435 | } | 435 | } |
436 | 436 | ||
437 | public AssetMetadata GetMetadata(string id) | 437 | public virtual AssetMetadata GetMetadata(string id) |
438 | { | 438 | { |
439 | string hash; | 439 | string hash; |
440 | return m_DataConnector.Get(id, out hash); | 440 | return m_DataConnector.Get(id, out hash); |
441 | } | 441 | } |
442 | 442 | ||
443 | public byte[] GetData(string id) | 443 | public virtual byte[] GetData(string id) |
444 | { | 444 | { |
445 | string hash; | 445 | string hash; |
446 | if (m_DataConnector.Get(id, out hash) == null) | 446 | if (m_DataConnector.Get(id, out hash) == null) |
@@ -521,7 +521,7 @@ namespace OpenSim.Services.FSAssetService | |||
521 | 521 | ||
522 | } | 522 | } |
523 | 523 | ||
524 | public string Store(AssetBase asset) | 524 | public virtual string Store(AssetBase asset) |
525 | { | 525 | { |
526 | return Store(asset, false); | 526 | return Store(asset, false); |
527 | } | 527 | } |
@@ -606,7 +606,7 @@ namespace OpenSim.Services.FSAssetService | |||
606 | // return true; | 606 | // return true; |
607 | } | 607 | } |
608 | 608 | ||
609 | public bool Delete(string id) | 609 | public virtual bool Delete(string id) |
610 | { | 610 | { |
611 | m_DataConnector.Delete(id); | 611 | m_DataConnector.Delete(id); |
612 | 612 | ||
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 | */ | ||
27 | using System; | ||
28 | using System.Reflection; | ||
29 | |||
30 | using Nini.Config; | ||
31 | using log4net; | ||
32 | using OpenMetaverse; | ||
33 | |||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Serialization.External; | ||
36 | using OpenSim.Server.Base; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using OpenSim.Services.FSAssetService; | ||
39 | |||
40 | namespace 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 | } | ||