diff options
author | Jonathan Freedman | 2010-12-05 11:49:15 -0800 |
---|---|---|
committer | Jonathan Freedman | 2010-12-05 11:49:15 -0800 |
commit | 45cd2e3ef93cc8ab880cb5b1742e33d441e7d01a (patch) | |
tree | 0351fb2c756a46d522fe41798c3969e020a3258d /OpenSim/Services/HypergridService/HGAssetService.cs | |
parent | Merge branch 'master-core' into mantis5110 (diff) | |
parent | Merge branch 'master' of /var/git/opensim/ (diff) | |
download | opensim-SC_OLD-45cd2e3ef93cc8ab880cb5b1742e33d441e7d01a.zip opensim-SC_OLD-45cd2e3ef93cc8ab880cb5b1742e33d441e7d01a.tar.gz opensim-SC_OLD-45cd2e3ef93cc8ab880cb5b1742e33d441e7d01a.tar.bz2 opensim-SC_OLD-45cd2e3ef93cc8ab880cb5b1742e33d441e7d01a.tar.xz |
Merge branch 'master-core' into mantis5110
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Services/HypergridService/HGAssetService.cs | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/OpenSim/Services/HypergridService/HGAssetService.cs b/OpenSim/Services/HypergridService/HGAssetService.cs new file mode 100644 index 0000000..a82d0d1 --- /dev/null +++ b/OpenSim/Services/HypergridService/HGAssetService.cs | |||
@@ -0,0 +1,145 @@ | |||
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.Collections.Generic; | ||
29 | using System.IO; | ||
30 | using System.Reflection; | ||
31 | using System.Xml; | ||
32 | |||
33 | using Nini.Config; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | |||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Serialization.External; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Services.AssetService; | ||
42 | |||
43 | namespace 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 HGAssetService : OpenSim.Services.AssetService.AssetService, IAssetService | ||
51 | { | ||
52 | private static readonly ILog m_log = | ||
53 | LogManager.GetLogger( | ||
54 | MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | |||
56 | private string m_ProfileServiceURL; | ||
57 | private IUserAccountService m_UserAccountService; | ||
58 | |||
59 | private UserAccountCache m_Cache; | ||
60 | |||
61 | public HGAssetService(IConfigSource config) : base(config) | ||
62 | { | ||
63 | m_log.Debug("[HGAsset Service]: Starting"); | ||
64 | IConfig assetConfig = config.Configs["HGAssetService"]; | ||
65 | if (assetConfig == null) | ||
66 | throw new Exception("No HGAssetService configuration"); | ||
67 | |||
68 | string userAccountsDll = assetConfig.GetString("UserAccountsService", string.Empty); | ||
69 | if (userAccountsDll == string.Empty) | ||
70 | throw new Exception("Please specify UserAccountsService in HGAssetService configuration"); | ||
71 | |||
72 | Object[] args = new Object[] { config }; | ||
73 | m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args); | ||
74 | if (m_UserAccountService == null) | ||
75 | throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll)); | ||
76 | |||
77 | m_ProfileServiceURL = assetConfig.GetString("ProfileServerURI", string.Empty); | ||
78 | |||
79 | m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService); | ||
80 | } | ||
81 | |||
82 | #region IAssetService overrides | ||
83 | public override AssetBase Get(string id) | ||
84 | { | ||
85 | AssetBase asset = base.Get(id); | ||
86 | |||
87 | if (asset == null) | ||
88 | return null; | ||
89 | |||
90 | if (asset.Metadata.Type == (sbyte)AssetType.Object) | ||
91 | asset.Data = AdjustIdentifiers(asset.Data); ; | ||
92 | |||
93 | AdjustIdentifiers(asset.Metadata); | ||
94 | |||
95 | return asset; | ||
96 | } | ||
97 | |||
98 | public override AssetMetadata GetMetadata(string id) | ||
99 | { | ||
100 | AssetMetadata meta = base.GetMetadata(id); | ||
101 | |||
102 | if (meta == null) | ||
103 | return null; | ||
104 | |||
105 | AdjustIdentifiers(meta); | ||
106 | |||
107 | return meta; | ||
108 | } | ||
109 | |||
110 | public override byte[] GetData(string id) | ||
111 | { | ||
112 | byte[] data = base.GetData(id); | ||
113 | |||
114 | if (data == null) | ||
115 | return null; | ||
116 | |||
117 | return AdjustIdentifiers(data); | ||
118 | } | ||
119 | |||
120 | //public virtual bool Get(string id, Object sender, AssetRetrieved handler) | ||
121 | |||
122 | public override bool Delete(string id) | ||
123 | { | ||
124 | // NOGO | ||
125 | return false; | ||
126 | } | ||
127 | |||
128 | #endregion | ||
129 | |||
130 | protected void AdjustIdentifiers(AssetMetadata meta) | ||
131 | { | ||
132 | UserAccount creator = m_Cache.GetUser(meta.CreatorID); | ||
133 | if (creator != null) | ||
134 | meta.CreatorID = m_ProfileServiceURL + "/" + meta.CreatorID + ";" + creator.FirstName + " " + creator.LastName; | ||
135 | } | ||
136 | |||
137 | protected byte[] AdjustIdentifiers(byte[] data) | ||
138 | { | ||
139 | string xml = Utils.BytesToString(data); | ||
140 | return Utils.StringToBytes(ExternalRepresentationUtils.RewriteSOP(xml, m_ProfileServiceURL, m_Cache, UUID.Zero)); | ||
141 | } | ||
142 | |||
143 | } | ||
144 | |||
145 | } | ||