opensim-development – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 | |||
28 | using System; |
||
29 | using System.Collections; |
||
30 | using System.Collections.Generic; |
||
31 | using System.Net; |
||
32 | using System.Reflection; |
||
33 | using log4net; |
||
34 | using Nini.Config; |
||
35 | using Nwc.XmlRpc; |
||
36 | using OpenSim.Server.Base; |
||
37 | using OpenSim.Services.Interfaces; |
||
38 | using OpenSim.Framework; |
||
39 | using OpenSim.Framework.Servers.HttpServer; |
||
40 | using OpenSim.Server.Handlers.Base; |
||
41 | using OpenMetaverse; |
||
42 | |||
43 | namespace OpenSim.Server.Handlers.Inventory |
||
44 | { |
||
45 | public class InventoryServiceInConnector : ServiceConnector |
||
46 | { |
||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
48 | |||
49 | protected IInventoryService m_InventoryService; |
||
50 | |||
51 | private bool m_doLookup = false; |
||
52 | |||
53 | //private static readonly int INVENTORY_DEFAULT_SESSION_TIME = 30; // secs |
||
54 | //private AuthedSessionCache m_session_cache = new AuthedSessionCache(INVENTORY_DEFAULT_SESSION_TIME); |
||
55 | |||
56 | private string m_userserver_url; |
||
57 | protected string m_ConfigName = "InventoryService"; |
||
58 | |||
59 | public InventoryServiceInConnector(IConfigSource config, IHttpServer server, string configName) : |
||
60 | base(config, server, configName) |
||
61 | { |
||
62 | if (configName != string.Empty) |
||
63 | m_ConfigName = configName; |
||
64 | |||
65 | IConfig serverConfig = config.Configs[m_ConfigName]; |
||
66 | if (serverConfig == null) |
||
67 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); |
||
68 | |||
69 | string inventoryService = serverConfig.GetString("LocalServiceModule", |
||
70 | String.Empty); |
||
71 | |||
72 | if (inventoryService == String.Empty) |
||
73 | throw new Exception("No LocalServiceModule in config file"); |
||
74 | |||
75 | Object[] args = new Object[] { config }; |
||
76 | m_InventoryService = |
||
77 | ServerUtils.LoadPlugin<IInventoryService>(inventoryService, args); |
||
78 | |||
79 | m_userserver_url = serverConfig.GetString("UserServerURI", String.Empty); |
||
80 | m_doLookup = serverConfig.GetBoolean("SessionAuthentication", false); |
||
81 | |||
82 | AddHttpHandlers(server); |
||
83 | m_log.Debug("[INVENTORY HANDLER]: handlers initialized"); |
||
84 | } |
||
85 | |||
86 | protected virtual void AddHttpHandlers(IHttpServer m_httpServer) |
||
87 | { |
||
88 | m_httpServer.AddStreamHandler( |
||
89 | new RestDeserialiseSecureHandler<Guid, InventoryCollection>( |
||
90 | "POST", "/GetInventory/", GetUserInventory, CheckAuthSession)); |
||
91 | |||
92 | m_httpServer.AddStreamHandler( |
||
93 | new RestDeserialiseSecureHandler<Guid, List<InventoryFolderBase>>( |
||
94 | "POST", "/SystemFolders/", GetSystemFolders, CheckAuthSession)); |
||
95 | |||
96 | m_httpServer.AddStreamHandler( |
||
97 | new RestDeserialiseSecureHandler<Guid, InventoryCollection>( |
||
98 | "POST", "/GetFolderContent/", GetFolderContent, CheckAuthSession)); |
||
99 | |||
100 | m_httpServer.AddStreamHandler( |
||
101 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( |
||
102 | "POST", "/UpdateFolder/", m_InventoryService.UpdateFolder, CheckAuthSession)); |
||
103 | |||
104 | m_httpServer.AddStreamHandler( |
||
105 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( |
||
106 | "POST", "/MoveFolder/", m_InventoryService.MoveFolder, CheckAuthSession)); |
||
107 | |||
108 | m_httpServer.AddStreamHandler( |
||
109 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( |
||
110 | "POST", "/PurgeFolder/", m_InventoryService.PurgeFolder, CheckAuthSession)); |
||
111 | |||
112 | m_httpServer.AddStreamHandler( |
||
113 | new RestDeserialiseSecureHandler<List<Guid>, bool>( |
||
114 | "POST", "/DeleteFolders/", DeleteFolders, CheckAuthSession)); |
||
115 | |||
116 | m_httpServer.AddStreamHandler( |
||
117 | new RestDeserialiseSecureHandler<List<Guid>, bool>( |
||
118 | "POST", "/DeleteItem/", DeleteItems, CheckAuthSession)); |
||
119 | |||
120 | m_httpServer.AddStreamHandler( |
||
121 | new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>( |
||
122 | "POST", "/QueryItem/", m_InventoryService.GetItem, CheckAuthSession)); |
||
123 | |||
124 | m_httpServer.AddStreamHandler( |
||
125 | new RestDeserialiseSecureHandler<InventoryFolderBase, InventoryFolderBase>( |
||
126 | "POST", "/QueryFolder/", m_InventoryService.GetFolder, CheckAuthSession)); |
||
127 | |||
128 | m_httpServer.AddStreamHandler( |
||
129 | new RestDeserialiseTrustedHandler<Guid, bool>( |
||
130 | "POST", "/CreateInventory/", CreateUsersInventory, CheckTrustSource)); |
||
131 | |||
132 | m_httpServer.AddStreamHandler( |
||
133 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( |
||
134 | "POST", "/NewFolder/", m_InventoryService.AddFolder, CheckAuthSession)); |
||
135 | |||
136 | m_httpServer.AddStreamHandler( |
||
137 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( |
||
138 | "POST", "/CreateFolder/", m_InventoryService.AddFolder, CheckAuthSession)); |
||
139 | |||
140 | m_httpServer.AddStreamHandler( |
||
141 | new RestDeserialiseSecureHandler<InventoryItemBase, bool>( |
||
142 | "POST", "/NewItem/", m_InventoryService.AddItem, CheckAuthSession)); |
||
143 | |||
144 | m_httpServer.AddStreamHandler( |
||
145 | new RestDeserialiseTrustedHandler<InventoryItemBase, bool>( |
||
146 | "POST", "/AddNewItem/", m_InventoryService.AddItem, CheckTrustSource)); |
||
147 | |||
148 | m_httpServer.AddStreamHandler( |
||
149 | new RestDeserialiseSecureHandler<Guid, List<InventoryItemBase>>( |
||
150 | "POST", "/GetItems/", GetFolderItems, CheckAuthSession)); |
||
151 | |||
152 | m_httpServer.AddStreamHandler( |
||
153 | new RestDeserialiseSecureHandler<List<InventoryItemBase>, bool>( |
||
154 | "POST", "/MoveItems/", MoveItems, CheckAuthSession)); |
||
155 | |||
156 | m_httpServer.AddStreamHandler(new InventoryServerMoveItemsHandler(m_InventoryService)); |
||
157 | |||
158 | |||
159 | // for persistent active gestures |
||
160 | m_httpServer.AddStreamHandler( |
||
161 | new RestDeserialiseTrustedHandler<Guid, List<InventoryItemBase>> |
||
162 | ("POST", "/ActiveGestures/", GetActiveGestures, CheckTrustSource)); |
||
163 | |||
164 | // WARNING: Root folders no longer just delivers the root and immediate child folders (e.g |
||
165 | // system folders such as Objects, Textures), but it now returns the entire inventory skeleton. |
||
166 | // It would have been better to rename this request, but complexities in the BaseHttpServer |
||
167 | // (e.g. any http request not found is automatically treated as an xmlrpc request) make it easier |
||
168 | // to do this for now. |
||
169 | m_httpServer.AddStreamHandler( |
||
170 | new RestDeserialiseTrustedHandler<Guid, List<InventoryFolderBase>> |
||
171 | ("POST", "/RootFolders/", GetInventorySkeleton, CheckTrustSource)); |
||
172 | |||
173 | m_httpServer.AddStreamHandler( |
||
174 | new RestDeserialiseTrustedHandler<InventoryItemBase, int> |
||
175 | ("POST", "/AssetPermissions/", GetAssetPermissions, CheckTrustSource)); |
||
176 | |||
177 | } |
||
178 | |||
179 | #region Wrappers for converting the Guid parameter |
||
180 | |||
181 | public InventoryCollection GetUserInventory(Guid guid) |
||
182 | { |
||
183 | UUID userID = new UUID(guid); |
||
184 | return m_InventoryService.GetUserInventory(userID); |
||
185 | } |
||
186 | |||
187 | public List<InventoryFolderBase> GetSystemFolders(Guid guid) |
||
188 | { |
||
189 | UUID userID = new UUID(guid); |
||
190 | return new List<InventoryFolderBase>(GetSystemFolders(userID).Values); |
||
191 | } |
||
192 | |||
193 | // This shouldn't be here, it should be in the inventory service. |
||
194 | // But I don't want to deal with types and dependencies for now. |
||
195 | private Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(UUID userID) |
||
196 | { |
||
197 | InventoryFolderBase root = m_InventoryService.GetRootFolder(userID); |
||
198 | if (root != null) |
||
199 | { |
||
200 | InventoryCollection content = m_InventoryService.GetFolderContent(userID, root.ID); |
||
201 | if (content != null) |
||
202 | { |
||
203 | Dictionary<AssetType, InventoryFolderBase> folders = new Dictionary<AssetType, InventoryFolderBase>(); |
||
204 | foreach (InventoryFolderBase folder in content.Folders) |
||
205 | { |
||
206 | if ((folder.Type != (short)AssetType.Folder) && (folder.Type != (short)AssetType.Unknown)) |
||
207 | folders[(AssetType)folder.Type] = folder; |
||
208 | } |
||
209 | // Put the root folder there, as type Folder |
||
210 | folders[AssetType.Folder] = root; |
||
211 | return folders; |
||
212 | } |
||
213 | } |
||
214 | m_log.WarnFormat("[INVENTORY SERVICE]: System folders for {0} not found", userID); |
||
215 | return new Dictionary<AssetType, InventoryFolderBase>(); |
||
216 | } |
||
217 | |||
218 | public InventoryCollection GetFolderContent(Guid guid) |
||
219 | { |
||
220 | return m_InventoryService.GetFolderContent(UUID.Zero, new UUID(guid)); |
||
221 | } |
||
222 | |||
223 | public List<InventoryItemBase> GetFolderItems(Guid folderID) |
||
224 | { |
||
225 | List<InventoryItemBase> allItems = new List<InventoryItemBase>(); |
||
226 | |||
227 | // TODO: UUID.Zero is passed as the userID here, making the old assumption that the OpenSim |
||
228 | // inventory server only has a single inventory database and not per-user inventory databases. |
||
229 | // This could be changed but it requirs a bit of hackery to pass another parameter into this |
||
230 | // callback |
||
231 | List<InventoryItemBase> items = m_InventoryService.GetFolderItems(UUID.Zero, new UUID(folderID)); |
||
232 | |||
233 | if (items != null) |
||
234 | { |
||
235 | allItems.InsertRange(0, items); |
||
236 | } |
||
237 | return allItems; |
||
238 | } |
||
239 | |||
240 | public bool CreateUsersInventory(Guid rawUserID) |
||
241 | { |
||
242 | UUID userID = new UUID(rawUserID); |
||
243 | |||
244 | |||
245 | return m_InventoryService.CreateUserInventory(userID); |
||
246 | } |
||
247 | |||
248 | public List<InventoryItemBase> GetActiveGestures(Guid rawUserID) |
||
249 | { |
||
250 | UUID userID = new UUID(rawUserID); |
||
251 | |||
252 | return m_InventoryService.GetActiveGestures(userID); |
||
253 | } |
||
254 | |||
255 | public List<InventoryFolderBase> GetInventorySkeleton(Guid rawUserID) |
||
256 | { |
||
257 | UUID userID = new UUID(rawUserID); |
||
258 | return m_InventoryService.GetInventorySkeleton(userID); |
||
259 | } |
||
260 | |||
261 | public int GetAssetPermissions(InventoryItemBase item) |
||
262 | { |
||
263 | return m_InventoryService.GetAssetPermissions(item.Owner, item.AssetID); |
||
264 | } |
||
265 | |||
266 | public bool DeleteFolders(List<Guid> items) |
||
267 | { |
||
268 | List<UUID> uuids = new List<UUID>(); |
||
269 | foreach (Guid g in items) |
||
270 | uuids.Add(new UUID(g)); |
||
271 | // oops we lost the user info here. Bad bad handlers |
||
272 | return m_InventoryService.DeleteFolders(UUID.Zero, uuids); |
||
273 | } |
||
274 | |||
275 | public bool DeleteItems(List<Guid> items) |
||
276 | { |
||
277 | List<UUID> uuids = new List<UUID>(); |
||
278 | foreach (Guid g in items) |
||
279 | uuids.Add(new UUID(g)); |
||
280 | // oops we lost the user info here. Bad bad handlers |
||
281 | return m_InventoryService.DeleteItems(UUID.Zero, uuids); |
||
282 | } |
||
283 | |||
284 | public bool MoveItems(List<InventoryItemBase> items) |
||
285 | { |
||
286 | // oops we lost the user info here. Bad bad handlers |
||
287 | // let's peek at one item |
||
288 | UUID ownerID = UUID.Zero; |
||
289 | if (items.Count > 0) |
||
290 | ownerID = items[0].Owner; |
||
291 | return m_InventoryService.MoveItems(ownerID, items); |
||
292 | } |
||
293 | #endregion |
||
294 | |||
295 | /// <summary> |
||
296 | /// Check that the source of an inventory request is one that we trust. |
||
297 | /// </summary> |
||
298 | /// <param name="peer"></param> |
||
299 | /// <returns></returns> |
||
300 | public bool CheckTrustSource(IPEndPoint peer) |
||
301 | { |
||
302 | if (m_doLookup) |
||
303 | { |
||
304 | m_log.InfoFormat("[INVENTORY IN CONNECTOR]: Checking trusted source {0}", peer); |
||
305 | UriBuilder ub = new UriBuilder(m_userserver_url); |
||
306 | IPAddress[] uaddrs = Dns.GetHostAddresses(ub.Host); |
||
307 | foreach (IPAddress uaddr in uaddrs) |
||
308 | { |
||
309 | if (uaddr.Equals(peer.Address)) |
||
310 | { |
||
311 | return true; |
||
312 | } |
||
313 | } |
||
314 | |||
315 | m_log.WarnFormat( |
||
316 | "[INVENTORY IN CONNECTOR]: Rejecting request since source {0} was not in the list of trusted sources", |
||
317 | peer); |
||
318 | |||
319 | return false; |
||
320 | } |
||
321 | else |
||
322 | { |
||
323 | return true; |
||
324 | } |
||
325 | } |
||
326 | |||
327 | /// <summary> |
||
328 | /// Check that the source of an inventory request for a particular agent is a current session belonging to |
||
329 | /// that agent. |
||
330 | /// </summary> |
||
331 | /// <param name="session_id"></param> |
||
332 | /// <param name="avatar_id"></param> |
||
333 | /// <returns></returns> |
||
334 | public virtual bool CheckAuthSession(string session_id, string avatar_id) |
||
335 | { |
||
336 | return true; |
||
337 | } |
||
338 | |||
339 | } |
||
340 | } |