diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Services/HypergridService/HGAssetService.cs | 140 | ||||
-rw-r--r-- | OpenSim/Services/HypergridService/HGInventoryService.cs (renamed from OpenSim/Services/InventoryService/HGInventoryService.cs) | 47 | ||||
-rw-r--r-- | OpenSim/Services/HypergridService/UserAccountCache.cs | 105 |
3 files changed, 284 insertions, 8 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 | */ | ||
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 | 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 | } | ||
diff --git a/OpenSim/Services/InventoryService/HGInventoryService.cs b/OpenSim/Services/HypergridService/HGInventoryService.cs index d62c008..a04f0c4 100644 --- a/OpenSim/Services/InventoryService/HGInventoryService.cs +++ b/OpenSim/Services/HypergridService/HGInventoryService.cs | |||
@@ -33,10 +33,12 @@ using Nini.Config; | |||
33 | using System.Reflection; | 33 | using System.Reflection; |
34 | using OpenSim.Services.Base; | 34 | using OpenSim.Services.Base; |
35 | using OpenSim.Services.Interfaces; | 35 | using OpenSim.Services.Interfaces; |
36 | using OpenSim.Services.InventoryService; | ||
36 | using OpenSim.Data; | 37 | using OpenSim.Data; |
37 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
39 | using OpenSim.Server.Base; | ||
38 | 40 | ||
39 | namespace OpenSim.Services.InventoryService | 41 | namespace OpenSim.Services.HypergridService |
40 | { | 42 | { |
41 | public class HGInventoryService : XInventoryService, IInventoryService | 43 | public class HGInventoryService : XInventoryService, IInventoryService |
42 | { | 44 | { |
@@ -46,9 +48,16 @@ namespace OpenSim.Services.InventoryService | |||
46 | 48 | ||
47 | protected new IXInventoryData m_Database; | 49 | protected new IXInventoryData m_Database; |
48 | 50 | ||
51 | private string m_ProfileServiceURL; | ||
52 | private IUserAccountService m_UserAccountService; | ||
53 | |||
54 | private UserAccountCache m_Cache; | ||
55 | |||
49 | public HGInventoryService(IConfigSource config) | 56 | public HGInventoryService(IConfigSource config) |
50 | : base(config) | 57 | : base(config) |
51 | { | 58 | { |
59 | m_log.Debug("[HGInventory Service]: Starting"); | ||
60 | |||
52 | string dllName = String.Empty; | 61 | string dllName = String.Empty; |
53 | string connString = String.Empty; | 62 | string connString = String.Empty; |
54 | //string realm = "Inventory"; // OSG version doesn't use this | 63 | //string realm = "Inventory"; // OSG version doesn't use this |
@@ -68,12 +77,25 @@ namespace OpenSim.Services.InventoryService | |||
68 | // | 77 | // |
69 | // Try reading the [InventoryService] section, if it exists | 78 | // Try reading the [InventoryService] section, if it exists |
70 | // | 79 | // |
71 | IConfig authConfig = config.Configs["InventoryService"]; | 80 | IConfig invConfig = config.Configs["HGInventoryService"]; |
72 | if (authConfig != null) | 81 | if (invConfig != null) |
73 | { | 82 | { |
74 | dllName = authConfig.GetString("StorageProvider", dllName); | 83 | dllName = invConfig.GetString("StorageProvider", dllName); |
75 | connString = authConfig.GetString("ConnectionString", connString); | 84 | connString = invConfig.GetString("ConnectionString", connString); |
85 | |||
76 | // realm = authConfig.GetString("Realm", realm); | 86 | // realm = authConfig.GetString("Realm", realm); |
87 | string userAccountsDll = invConfig.GetString("UserAccountsService", string.Empty); | ||
88 | if (userAccountsDll == string.Empty) | ||
89 | throw new Exception("Please specify UserAccountsService in HGInventoryService configuration"); | ||
90 | |||
91 | Object[] args = new Object[] { config }; | ||
92 | m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args); | ||
93 | if (m_UserAccountService == null) | ||
94 | throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll)); | ||
95 | |||
96 | m_ProfileServiceURL = invConfig.GetString("ProfileServerURI", string.Empty); | ||
97 | |||
98 | m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService); | ||
77 | } | 99 | } |
78 | 100 | ||
79 | // | 101 | // |
@@ -282,9 +304,18 @@ namespace OpenSim.Services.InventoryService | |||
282 | //{ | 304 | //{ |
283 | //} | 305 | //} |
284 | 306 | ||
285 | //public InventoryItemBase GetItem(InventoryItemBase item) | 307 | public override InventoryItemBase GetItem(InventoryItemBase item) |
286 | //{ | 308 | { |
287 | //} | 309 | InventoryItemBase it = base.GetItem(item); |
310 | |||
311 | UserAccount user = m_Cache.GetUser(it.CreatorId); | ||
312 | |||
313 | // Adjust the creator data | ||
314 | if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty)) | ||
315 | it.CreatorData = m_ProfileServiceURL + "/" + it.CreatorId + ";" + user.FirstName + " " + user.LastName; | ||
316 | |||
317 | return it; | ||
318 | } | ||
288 | 319 | ||
289 | //public InventoryFolderBase GetFolder(InventoryFolderBase folder) | 320 | //public InventoryFolderBase GetFolder(InventoryFolderBase folder) |
290 | //{ | 321 | //{ |
diff --git a/OpenSim/Services/HypergridService/UserAccountCache.cs b/OpenSim/Services/HypergridService/UserAccountCache.cs new file mode 100644 index 0000000..3e9aea1 --- /dev/null +++ b/OpenSim/Services/HypergridService/UserAccountCache.cs | |||
@@ -0,0 +1,105 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Reflection; | ||
4 | |||
5 | using log4net; | ||
6 | using OpenMetaverse; | ||
7 | |||
8 | using OpenSim.Services.Interfaces; | ||
9 | |||
10 | namespace OpenSim.Services.HypergridService | ||
11 | { | ||
12 | public class UserAccountCache : IUserAccountService | ||
13 | { | ||
14 | private const double CACHE_EXPIRATION_SECONDS = 120000.0; // 33 hours! | ||
15 | |||
16 | private static readonly ILog m_log = | ||
17 | LogManager.GetLogger( | ||
18 | MethodBase.GetCurrentMethod().DeclaringType); | ||
19 | private ExpiringCache<UUID, UserAccount> m_UUIDCache; | ||
20 | |||
21 | private IUserAccountService m_UserAccountService; | ||
22 | |||
23 | private static UserAccountCache m_Singleton; | ||
24 | |||
25 | public static UserAccountCache CreateUserAccountCache(IUserAccountService u) | ||
26 | { | ||
27 | if (m_Singleton == null) | ||
28 | m_Singleton = new UserAccountCache(u); | ||
29 | |||
30 | return m_Singleton; | ||
31 | } | ||
32 | |||
33 | private UserAccountCache(IUserAccountService u) | ||
34 | { | ||
35 | m_UUIDCache = new ExpiringCache<UUID, UserAccount>(); | ||
36 | m_UserAccountService = u; | ||
37 | } | ||
38 | |||
39 | public void Cache(UUID userID, UserAccount account) | ||
40 | { | ||
41 | // Cache even null accounts | ||
42 | m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS); | ||
43 | |||
44 | //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID); | ||
45 | } | ||
46 | |||
47 | public UserAccount Get(UUID userID, out bool inCache) | ||
48 | { | ||
49 | UserAccount account = null; | ||
50 | inCache = false; | ||
51 | if (m_UUIDCache.TryGetValue(userID, out account)) | ||
52 | { | ||
53 | //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName); | ||
54 | inCache = true; | ||
55 | return account; | ||
56 | } | ||
57 | |||
58 | return null; | ||
59 | } | ||
60 | |||
61 | public UserAccount GetUser(string id) | ||
62 | { | ||
63 | UUID uuid = UUID.Zero; | ||
64 | UUID.TryParse(id, out uuid); | ||
65 | bool inCache = false; | ||
66 | UserAccount account = Get(uuid, out inCache); | ||
67 | if (!inCache) | ||
68 | { | ||
69 | account = m_UserAccountService.GetUserAccount(UUID.Zero, uuid); | ||
70 | Cache(uuid, account); | ||
71 | } | ||
72 | |||
73 | return account; | ||
74 | } | ||
75 | |||
76 | #region IUserAccountService | ||
77 | public UserAccount GetUserAccount(UUID scopeID, UUID userID) | ||
78 | { | ||
79 | return GetUser(userID.ToString()); | ||
80 | } | ||
81 | |||
82 | public UserAccount GetUserAccount(UUID scopeID, string FirstName, string LastName) | ||
83 | { | ||
84 | return null; | ||
85 | } | ||
86 | |||
87 | public UserAccount GetUserAccount(UUID scopeID, string Email) | ||
88 | { | ||
89 | return null; | ||
90 | } | ||
91 | |||
92 | public List<UserAccount> GetUserAccounts(UUID scopeID, string query) | ||
93 | { | ||
94 | return null; | ||
95 | } | ||
96 | |||
97 | public bool StoreUserAccount(UserAccount data) | ||
98 | { | ||
99 | return false; | ||
100 | } | ||
101 | #endregion | ||
102 | |||
103 | } | ||
104 | |||
105 | } | ||