aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid
diff options
context:
space:
mode:
authorDiva Canto2009-08-21 21:31:18 -0700
committerDiva Canto2009-08-22 09:03:59 -0700
commit75021b5309c5e74c08feea5d508b69ce05491375 (patch)
treec498f2171eee953a452633762ac119af0487a5ca /OpenSim/Grid
parentMerge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-75021b5309c5e74c08feea5d508b69ce05491375.zip
opensim-SC_OLD-75021b5309c5e74c08feea5d508b69ce05491375.tar.gz
opensim-SC_OLD-75021b5309c5e74c08feea5d508b69ce05491375.tar.bz2
opensim-SC_OLD-75021b5309c5e74c08feea5d508b69ce05491375.tar.xz
Moved AuthedSessionCache to where it is used -- Grid/InventoryServer.
Diffstat (limited to 'OpenSim/Grid')
-rw-r--r--OpenSim/Grid/InventoryServer/AuthedSessionCache.cs133
-rw-r--r--OpenSim/Grid/InventoryServer/InventoryServiceBase.cs517
2 files changed, 650 insertions, 0 deletions
diff --git a/OpenSim/Grid/InventoryServer/AuthedSessionCache.cs b/OpenSim/Grid/InventoryServer/AuthedSessionCache.cs
new file mode 100644
index 0000000..d56e48a
--- /dev/null
+++ b/OpenSim/Grid/InventoryServer/AuthedSessionCache.cs
@@ -0,0 +1,133 @@
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
28using System;
29using System.Collections.Generic;
30
31namespace OpenSim.Framework.Communications.Cache
32{
33 public class AuthedSessionCache
34 {
35 public class CacheData
36 {
37 private static readonly DateTime UNIX_EPOCH = new DateTime(1970, 1, 1);
38 private string m_session_id;
39 private string m_agent_id;
40 private int m_expire;
41
42 private int get_current_unix_time()
43 {
44 return (int)(DateTime.UtcNow - UNIX_EPOCH).TotalSeconds;
45 }
46
47 public CacheData(string sid, string aid)
48 {
49 m_session_id = sid;
50 m_agent_id = aid;
51 m_expire = get_current_unix_time() + DEFAULT_LIFETIME;
52 }
53
54 public CacheData(string sid, string aid, int time_now)
55 {
56 m_session_id = sid;
57 m_agent_id = aid;
58 m_expire = time_now + DEFAULT_LIFETIME;
59 }
60
61 public string SessionID
62 {
63 get { return m_session_id; }
64 set { m_session_id = value; }
65 }
66
67 public string AgentID
68 {
69 get { return m_agent_id; }
70 set { m_agent_id = value; }
71 }
72
73 public bool isExpired
74 {
75 get { return m_expire < get_current_unix_time(); }
76 }
77
78 public void Renew()
79 {
80 m_expire = get_current_unix_time() + DEFAULT_LIFETIME;
81 }
82 }
83
84 private static readonly int DEFAULT_LIFETIME = 30;
85 private Dictionary<string, CacheData> m_authed_sessions = new Dictionary<string,CacheData>();
86 // private int m_session_lifetime = DEFAULT_LIFETIME;
87
88 public AuthedSessionCache()
89 {
90 // m_session_lifetime = DEFAULT_LIFETIME;
91 }
92
93 public AuthedSessionCache(int timeout)
94 {
95 // m_session_lifetime = timeout;
96 }
97
98 public CacheData getCachedSession(string session_id, string agent_id)
99 {
100 CacheData ret = null;
101 lock (m_authed_sessions)
102 {
103 if (m_authed_sessions.ContainsKey(session_id))
104 {
105 CacheData cached_session = m_authed_sessions[session_id];
106 if (!cached_session.isExpired && cached_session.AgentID == agent_id)
107 {
108 ret = m_authed_sessions[session_id];
109 // auto renew
110 m_authed_sessions[session_id].Renew();
111 }
112 }
113 }
114 return ret;
115 }
116
117 public void Add(string session_id, string agent_id)
118 {
119 CacheData data = new CacheData(session_id, agent_id);
120 lock (m_authed_sessions)
121 {
122 if (m_authed_sessions.ContainsKey(session_id))
123 {
124 m_authed_sessions[session_id] = data;
125 }
126 else
127 {
128 m_authed_sessions.Add(session_id, data);
129 }
130 }
131 }
132 }
133}
diff --git a/OpenSim/Grid/InventoryServer/InventoryServiceBase.cs b/OpenSim/Grid/InventoryServer/InventoryServiceBase.cs
new file mode 100644
index 0000000..309c415
--- /dev/null
+++ b/OpenSim/Grid/InventoryServer/InventoryServiceBase.cs
@@ -0,0 +1,517 @@
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
28using System.Collections.Generic;
29using System.Reflection;
30using log4net;
31using OpenMetaverse;
32using OpenSim.Data;
33
34namespace OpenSim.Framework.Communications
35{
36 /// <summary>
37 /// Abstract base class used by local and grid implementations of an inventory service.
38 /// </summary>
39 public abstract class InventoryServiceBase : IInterServiceInventoryServices
40 {
41
42 private static readonly ILog m_log
43 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44
45 protected List<IInventoryDataPlugin> m_plugins = new List<IInventoryDataPlugin>();
46
47 #region Plugin methods
48
49 /// <summary>
50 /// Add a new inventory data plugin - plugins will be requested in the order they were added.
51 /// </summary>
52 /// <param name="plugin">The plugin that will provide data</param>
53 public void AddPlugin(IInventoryDataPlugin plugin)
54 {
55 m_plugins.Add(plugin);
56 }
57
58 /// <summary>
59 /// Adds a list of inventory data plugins, as described by `provider'
60 /// and `connect', to `m_plugins'.
61 /// </summary>
62 /// <param name="provider">
63 /// The filename of the inventory server plugin DLL.
64 /// </param>
65 /// <param name="connect">
66 /// The connection string for the storage backend.
67 /// </param>
68 public void AddPlugin(string provider, string connect)
69 {
70 m_plugins.AddRange(DataPluginFactory.LoadDataPlugins<IInventoryDataPlugin>(provider, connect));
71 }
72
73 #endregion
74
75 #region IInventoryServices methods
76
77 public string Host
78 {
79 get { return "default"; }
80 }
81
82 public List<InventoryFolderBase> GetInventorySkeleton(UUID userId)
83 {
84// m_log.DebugFormat("[AGENT INVENTORY]: Getting inventory skeleton for {0}", userId);
85
86 InventoryFolderBase rootFolder = RequestRootFolder(userId);
87
88 // Agent has no inventory structure yet.
89 if (null == rootFolder)
90 {
91 return null;
92 }
93
94 List<InventoryFolderBase> userFolders = new List<InventoryFolderBase>();
95
96 userFolders.Add(rootFolder);
97
98 foreach (IInventoryDataPlugin plugin in m_plugins)
99 {
100 IList<InventoryFolderBase> folders = plugin.getFolderHierarchy(rootFolder.ID);
101 userFolders.AddRange(folders);
102 }
103
104// foreach (InventoryFolderBase folder in userFolders)
105// {
106// m_log.DebugFormat("[AGENT INVENTORY]: Got folder {0} {1}", folder.name, folder.folderID);
107// }
108
109 return userFolders;
110 }
111
112 // See IInventoryServices
113 public virtual bool HasInventoryForUser(UUID userID)
114 {
115 return false;
116 }
117
118 // See IInventoryServices
119 public virtual InventoryFolderBase RequestRootFolder(UUID userID)
120 {
121 // Retrieve the first root folder we get from the list of plugins.
122 foreach (IInventoryDataPlugin plugin in m_plugins)
123 {
124 InventoryFolderBase rootFolder = plugin.getUserRootFolder(userID);
125 if (rootFolder != null)
126 return rootFolder;
127 }
128
129 // Return nothing if no plugin was able to supply a root folder
130 return null;
131 }
132
133 // See IInventoryServices
134 public bool CreateNewUserInventory(UUID user)
135 {
136 InventoryFolderBase existingRootFolder = RequestRootFolder(user);
137
138 if (null != existingRootFolder)
139 {
140 m_log.WarnFormat(
141 "[AGENT INVENTORY]: Did not create a new inventory for user {0} since they already have "
142 + "a root inventory folder with id {1}",
143 user, existingRootFolder.ID);
144 }
145 else
146 {
147 UsersInventory inven = new UsersInventory();
148 inven.CreateNewInventorySet(user);
149 AddNewInventorySet(inven);
150
151 return true;
152 }
153
154 return false;
155 }
156
157 public List<InventoryItemBase> GetActiveGestures(UUID userId)
158 {
159 List<InventoryItemBase> activeGestures = new List<InventoryItemBase>();
160 foreach (IInventoryDataPlugin plugin in m_plugins)
161 {
162 activeGestures.AddRange(plugin.fetchActiveGestures(userId));
163 }
164
165 return activeGestures;
166 }
167
168 #endregion
169
170 #region Methods used by GridInventoryService
171
172 public List<InventoryFolderBase> RequestSubFolders(UUID parentFolderID)
173 {
174 List<InventoryFolderBase> inventoryList = new List<InventoryFolderBase>();
175
176 foreach (IInventoryDataPlugin plugin in m_plugins)
177 {
178 inventoryList.AddRange(plugin.getInventoryFolders(parentFolderID));
179 }
180
181 return inventoryList;
182 }
183
184 public List<InventoryItemBase> RequestFolderItems(UUID folderID)
185 {
186 List<InventoryItemBase> itemsList = new List<InventoryItemBase>();
187
188 foreach (IInventoryDataPlugin plugin in m_plugins)
189 {
190 itemsList.AddRange(plugin.getInventoryInFolder(folderID));
191 }
192
193 return itemsList;
194 }
195
196 #endregion
197
198 // See IInventoryServices
199 public virtual bool AddFolder(InventoryFolderBase folder)
200 {
201 m_log.DebugFormat(
202 "[AGENT INVENTORY]: Adding folder {0} {1} to folder {2}", folder.Name, folder.ID, folder.ParentID);
203
204 foreach (IInventoryDataPlugin plugin in m_plugins)
205 {
206 plugin.addInventoryFolder(folder);
207 }
208
209 // FIXME: Should return false on failure
210 return true;
211 }
212
213 // See IInventoryServices
214 public virtual bool UpdateFolder(InventoryFolderBase folder)
215 {
216 m_log.DebugFormat(
217 "[AGENT INVENTORY]: Updating folder {0} {1} to folder {2}", folder.Name, folder.ID, folder.ParentID);
218
219 foreach (IInventoryDataPlugin plugin in m_plugins)
220 {
221 plugin.updateInventoryFolder(folder);
222 }
223
224 // FIXME: Should return false on failure
225 return true;
226 }
227
228 // See IInventoryServices
229 public virtual bool MoveFolder(InventoryFolderBase folder)
230 {
231 m_log.DebugFormat(
232 "[AGENT INVENTORY]: Moving folder {0} {1} to folder {2}", folder.Name, folder.ID, folder.ParentID);
233
234 foreach (IInventoryDataPlugin plugin in m_plugins)
235 {
236 plugin.moveInventoryFolder(folder);
237 }
238
239 // FIXME: Should return false on failure
240 return true;
241 }
242
243 // See IInventoryServices
244 public virtual bool AddItem(InventoryItemBase item)
245 {
246 m_log.DebugFormat(
247 "[AGENT INVENTORY]: Adding item {0} {1} to folder {2}", item.Name, item.ID, item.Folder);
248
249 foreach (IInventoryDataPlugin plugin in m_plugins)
250 {
251 plugin.addInventoryItem(item);
252 }
253
254 // FIXME: Should return false on failure
255 return true;
256 }
257
258 // See IInventoryServices
259 public virtual bool UpdateItem(InventoryItemBase item)
260 {
261 m_log.InfoFormat(
262 "[AGENT INVENTORY]: Updating item {0} {1} in folder {2}", item.Name, item.ID, item.Folder);
263
264 foreach (IInventoryDataPlugin plugin in m_plugins)
265 {
266 plugin.updateInventoryItem(item);
267 }
268
269 // FIXME: Should return false on failure
270 return true;
271 }
272
273 // See IInventoryServices
274 public virtual bool DeleteItem(InventoryItemBase item)
275 {
276 m_log.InfoFormat(
277 "[AGENT INVENTORY]: Deleting item {0} {1} from folder {2}", item.Name, item.ID, item.Folder);
278
279 foreach (IInventoryDataPlugin plugin in m_plugins)
280 {
281 plugin.deleteInventoryItem(item.ID);
282 }
283
284 // FIXME: Should return false on failure
285 return true;
286 }
287
288 public virtual InventoryItemBase QueryItem(InventoryItemBase item)
289 {
290 foreach (IInventoryDataPlugin plugin in m_plugins)
291 {
292 InventoryItemBase result = plugin.queryInventoryItem(item.ID);
293 if (result != null)
294 return result;
295 }
296
297 return null;
298 }
299
300 public virtual InventoryFolderBase QueryFolder(InventoryFolderBase item)
301 {
302 foreach (IInventoryDataPlugin plugin in m_plugins)
303 {
304 InventoryFolderBase result = plugin.queryInventoryFolder(item.ID);
305 if (result != null)
306 return result;
307 }
308
309 return null;
310 }
311
312 /// <summary>
313 /// Purge a folder of all items items and subfolders.
314 ///
315 /// FIXME: Really nasty in a sense, because we have to query the database to get information we may
316 /// already know... Needs heavy refactoring.
317 /// </summary>
318 /// <param name="folder"></param>
319 public virtual bool PurgeFolder(InventoryFolderBase folder)
320 {
321 m_log.DebugFormat(
322 "[AGENT INVENTORY]: Purging folder {0} {1} of its contents", folder.Name, folder.ID);
323
324 List<InventoryFolderBase> subFolders = RequestSubFolders(folder.ID);
325
326 foreach (InventoryFolderBase subFolder in subFolders)
327 {
328// m_log.DebugFormat("[AGENT INVENTORY]: Deleting folder {0} {1}", subFolder.Name, subFolder.ID);
329
330 foreach (IInventoryDataPlugin plugin in m_plugins)
331 {
332 plugin.deleteInventoryFolder(subFolder.ID);
333 }
334 }
335
336 List<InventoryItemBase> items = RequestFolderItems(folder.ID);
337
338 foreach (InventoryItemBase item in items)
339 {
340 DeleteItem(item);
341 }
342
343 // FIXME: Should return false on failure
344 return true;
345 }
346
347 private void AddNewInventorySet(UsersInventory inventory)
348 {
349 foreach (InventoryFolderBase folder in inventory.Folders.Values)
350 {
351 AddFolder(folder);
352 }
353 }
354
355 public InventoryItemBase GetInventoryItem(UUID itemID)
356 {
357 foreach (IInventoryDataPlugin plugin in m_plugins)
358 {
359 InventoryItemBase item = plugin.getInventoryItem(itemID);
360 if (item != null)
361 return item;
362 }
363
364 return null;
365 }
366
367 /// <summary>
368 /// Used to create a new user inventory.
369 /// </summary>
370 private class UsersInventory
371 {
372 public Dictionary<UUID, InventoryFolderBase> Folders = new Dictionary<UUID, InventoryFolderBase>();
373 public Dictionary<UUID, InventoryItemBase> Items = new Dictionary<UUID, InventoryItemBase>();
374
375 public virtual void CreateNewInventorySet(UUID user)
376 {
377 InventoryFolderBase folder = new InventoryFolderBase();
378
379 folder.ParentID = UUID.Zero;
380 folder.Owner = user;
381 folder.ID = UUID.Random();
382 folder.Name = "My Inventory";
383 folder.Type = (short)AssetType.Folder;
384 folder.Version = 1;
385 Folders.Add(folder.ID, folder);
386
387 UUID rootFolder = folder.ID;
388
389 folder = new InventoryFolderBase();
390 folder.ParentID = rootFolder;
391 folder.Owner = user;
392 folder.ID = UUID.Random();
393 folder.Name = "Animations";
394 folder.Type = (short)AssetType.Animation;
395 folder.Version = 1;
396 Folders.Add(folder.ID, folder);
397
398 folder = new InventoryFolderBase();
399 folder.ParentID = rootFolder;
400 folder.Owner = user;
401 folder.ID = UUID.Random();
402 folder.Name = "Body Parts";
403 folder.Type = (short)AssetType.Bodypart;
404 folder.Version = 1;
405 Folders.Add(folder.ID, folder);
406
407 folder = new InventoryFolderBase();
408 folder.ParentID = rootFolder;
409 folder.Owner = user;
410 folder.ID = UUID.Random();
411 folder.Name = "Calling Cards";
412 folder.Type = (short)AssetType.CallingCard;
413 folder.Version = 1;
414 Folders.Add(folder.ID, folder);
415
416 folder = new InventoryFolderBase();
417 folder.ParentID = rootFolder;
418 folder.Owner = user;
419 folder.ID = UUID.Random();
420 folder.Name = "Clothing";
421 folder.Type = (short)AssetType.Clothing;
422 folder.Version = 1;
423 Folders.Add(folder.ID, folder);
424
425 folder = new InventoryFolderBase();
426 folder.ParentID = rootFolder;
427 folder.Owner = user;
428 folder.ID = UUID.Random();
429 folder.Name = "Gestures";
430 folder.Type = (short)AssetType.Gesture;
431 folder.Version = 1;
432 Folders.Add(folder.ID, folder);
433
434 folder = new InventoryFolderBase();
435 folder.ParentID = rootFolder;
436 folder.Owner = user;
437 folder.ID = UUID.Random();
438 folder.Name = "Landmarks";
439 folder.Type = (short)AssetType.Landmark;
440 folder.Version = 1;
441 Folders.Add(folder.ID, folder);
442
443 folder = new InventoryFolderBase();
444 folder.ParentID = rootFolder;
445 folder.Owner = user;
446 folder.ID = UUID.Random();
447 folder.Name = "Lost And Found";
448 folder.Type = (short)AssetType.LostAndFoundFolder;
449 folder.Version = 1;
450 Folders.Add(folder.ID, folder);
451
452 folder = new InventoryFolderBase();
453 folder.ParentID = rootFolder;
454 folder.Owner = user;
455 folder.ID = UUID.Random();
456 folder.Name = "Notecards";
457 folder.Type = (short)AssetType.Notecard;
458 folder.Version = 1;
459 Folders.Add(folder.ID, folder);
460
461 folder = new InventoryFolderBase();
462 folder.ParentID = rootFolder;
463 folder.Owner = user;
464 folder.ID = UUID.Random();
465 folder.Name = "Objects";
466 folder.Type = (short)AssetType.Object;
467 folder.Version = 1;
468 Folders.Add(folder.ID, folder);
469
470 folder = new InventoryFolderBase();
471 folder.ParentID = rootFolder;
472 folder.Owner = user;
473 folder.ID = UUID.Random();
474 folder.Name = "Photo Album";
475 folder.Type = (short)AssetType.SnapshotFolder;
476 folder.Version = 1;
477 Folders.Add(folder.ID, folder);
478
479 folder = new InventoryFolderBase();
480 folder.ParentID = rootFolder;
481 folder.Owner = user;
482 folder.ID = UUID.Random();
483 folder.Name = "Scripts";
484 folder.Type = (short)AssetType.LSLText;
485 folder.Version = 1;
486 Folders.Add(folder.ID, folder);
487
488 folder = new InventoryFolderBase();
489 folder.ParentID = rootFolder;
490 folder.Owner = user;
491 folder.ID = UUID.Random();
492 folder.Name = "Sounds";
493 folder.Type = (short)AssetType.Sound;
494 folder.Version = 1;
495 Folders.Add(folder.ID, folder);
496
497 folder = new InventoryFolderBase();
498 folder.ParentID = rootFolder;
499 folder.Owner = user;
500 folder.ID = UUID.Random();
501 folder.Name = "Textures";
502 folder.Type = (short)AssetType.Texture;
503 folder.Version = 1;
504 Folders.Add(folder.ID, folder);
505
506 folder = new InventoryFolderBase();
507 folder.ParentID = rootFolder;
508 folder.Owner = user;
509 folder.ID = UUID.Random();
510 folder.Name = "Trash";
511 folder.Type = (short)AssetType.TrashFolder;
512 folder.Version = 1;
513 Folders.Add(folder.ID, folder);
514 }
515 }
516 }
517}