aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/HypergridService/HGAssetService.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/HypergridService/HGAssetService.cs140
1 files changed, 140 insertions, 0 deletions
diff --git a/OpenSim/Services/HypergridService/HGAssetService.cs b/OpenSim/Services/HypergridService/HGAssetService.cs
new file mode 100644
index 0000000..584ab6f
--- /dev/null
+++ b/OpenSim/Services/HypergridService/HGAssetService.cs
@@ -0,0 +1,140 @@
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 public class HGAssetService : OpenSim.Services.AssetService.AssetService, IAssetService
46 {
47 private static readonly ILog m_log =
48 LogManager.GetLogger(
49 MethodBase.GetCurrentMethod().DeclaringType);
50
51 private string m_ProfileServiceURL;
52 private IUserAccountService m_UserAccountService;
53
54 private UserAccountCache m_Cache;
55
56 public HGAssetService(IConfigSource config) : base(config)
57 {
58 m_log.Debug("[HGAsset Service]: Starting");
59 IConfig assetConfig = config.Configs["HGAssetService"];
60 if (assetConfig == null)
61 throw new Exception("No HGAssetService configuration");
62
63 string userAccountsDll = assetConfig.GetString("UserAccountsService", string.Empty);
64 if (userAccountsDll == string.Empty)
65 throw new Exception("Please specify UserAccountsService in HGAssetService configuration");
66
67 Object[] args = new Object[] { config };
68 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
69 if (m_UserAccountService == null)
70 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
71
72 m_ProfileServiceURL = assetConfig.GetString("ProfileServerURI", string.Empty);
73
74 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
75 }
76
77 #region IAssetService overrides
78 public override AssetBase Get(string id)
79 {
80 AssetBase asset = base.Get(id);
81
82 if (asset == null)
83 return null;
84
85 if (asset.Metadata.Type == (sbyte)AssetType.Object)
86 asset.Data = AdjustIdentifiers(asset.Data); ;
87
88 AdjustIdentifiers(asset.Metadata);
89
90 return asset;
91 }
92
93 public override AssetMetadata GetMetadata(string id)
94 {
95 AssetMetadata meta = base.GetMetadata(id);
96
97 if (meta == null)
98 return null;
99
100 AdjustIdentifiers(meta);
101
102 return meta;
103 }
104
105 public override byte[] GetData(string id)
106 {
107 byte[] data = base.GetData(id);
108
109 if (data == null)
110 return null;
111
112 return AdjustIdentifiers(data);
113 }
114
115 //public virtual bool Get(string id, Object sender, AssetRetrieved handler)
116
117 public override bool Delete(string id)
118 {
119 // NOGO
120 return false;
121 }
122
123 #endregion
124
125 protected void AdjustIdentifiers(AssetMetadata meta)
126 {
127 UserAccount creator = m_Cache.GetUser(meta.CreatorID);
128 if (creator != null)
129 meta.CreatorID = m_ProfileServiceURL + "/" + meta.CreatorID + ";" + creator.FirstName + " " + creator.LastName;
130 }
131
132 protected byte[] AdjustIdentifiers(byte[] data)
133 {
134 string xml = Utils.BytesToString(data);
135 return Utils.StringToBytes(ExternalRepresentationUtils.RewriteSOP(xml, m_ProfileServiceURL, m_Cache, UUID.Zero));
136 }
137
138 }
139
140}