From 8a9677a5319793ff630d0761e204ae8961f375aa Mon Sep 17 00:00:00 2001
From: Diva Canto
Date: Fri, 1 Jan 2010 21:12:46 -0800
Subject: The Library Service is now working.
UserProfileCacheService.LibraryRoot is obsolete. Didn't delete it yet to
avoid merge conflicts later -- want to stay out of core as much as possible.
---
.../Services/InventoryService/LibraryService.cs | 283 +++++++++++++++++++++
OpenSim/Services/LLLoginService/LLLoginResponse.cs | 34 +--
OpenSim/Services/LLLoginService/LLLoginService.cs | 24 +-
3 files changed, 321 insertions(+), 20 deletions(-)
create mode 100644 OpenSim/Services/InventoryService/LibraryService.cs
(limited to 'OpenSim/Services')
diff --git a/OpenSim/Services/InventoryService/LibraryService.cs b/OpenSim/Services/InventoryService/LibraryService.cs
new file mode 100644
index 0000000..383f311
--- /dev/null
+++ b/OpenSim/Services/InventoryService/LibraryService.cs
@@ -0,0 +1,283 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
+using System.Xml;
+
+using OpenSim.Framework;
+using OpenSim.Services.Base;
+using OpenSim.Services.Interfaces;
+
+using log4net;
+using Nini.Config;
+using OpenMetaverse;
+
+namespace OpenSim.Services.InventoryService
+{
+ ///
+ /// Basically a hack to give us a Inventory library while we don't have a inventory server
+ /// once the server is fully implemented then should read the data from that
+ ///
+ public class LibraryService : ServiceBase, ILibraryService
+ {
+ private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
+ private InventoryFolderImpl m_LibraryRootFolder;
+
+ public InventoryFolderImpl LibraryRootFolder
+ {
+ get { return m_LibraryRootFolder; }
+ }
+
+ private UUID libOwner = new UUID("11111111-1111-0000-0000-000100bba000");
+
+ ///
+ /// Holds the root library folder and all its descendents. This is really only used during inventory
+ /// setup so that we don't have to repeatedly search the tree of library folders.
+ ///
+ protected Dictionary libraryFolders
+ = new Dictionary();
+
+ public LibraryService(IConfigSource config)
+ : base(config)
+ {
+ string pLibrariesLocation = Path.Combine("inventory", "Libraries.xml");
+ string pLibName = "OpenSim Library";
+
+ IConfig libConfig = config.Configs["LibraryService"];
+ if (libConfig != null)
+ {
+ pLibrariesLocation = libConfig.GetString("DefaultLibrary", pLibrariesLocation);
+ pLibName = libConfig.GetString("LibraryName", pLibName);
+ }
+
+ m_log.Debug("[LIBRARY]: Starting library service...");
+
+ m_LibraryRootFolder = new InventoryFolderImpl();
+ m_LibraryRootFolder.Owner = libOwner;
+ m_LibraryRootFolder.ID = new UUID("00000112-000f-0000-0000-000100bba000");
+ m_LibraryRootFolder.Name = pLibName;
+ m_LibraryRootFolder.ParentID = UUID.Zero;
+ m_LibraryRootFolder.Type = (short)8;
+ m_LibraryRootFolder.Version = (ushort)1;
+
+ libraryFolders.Add(m_LibraryRootFolder.ID, m_LibraryRootFolder);
+
+ LoadLibraries(pLibrariesLocation);
+ }
+
+ public InventoryItemBase CreateItem(UUID inventoryID, UUID assetID, string name, string description,
+ int assetType, int invType, UUID parentFolderID)
+ {
+ InventoryItemBase item = new InventoryItemBase();
+ item.Owner = libOwner;
+ item.CreatorId = libOwner.ToString();
+ item.ID = inventoryID;
+ item.AssetID = assetID;
+ item.Description = description;
+ item.Name = name;
+ item.AssetType = assetType;
+ item.InvType = invType;
+ item.Folder = parentFolderID;
+ item.BasePermissions = 0x7FFFFFFF;
+ item.EveryOnePermissions = 0x7FFFFFFF;
+ item.CurrentPermissions = 0x7FFFFFFF;
+ item.NextPermissions = 0x7FFFFFFF;
+ return item;
+ }
+
+ ///
+ /// Use the asset set information at path to load assets
+ ///
+ ///
+ ///
+ protected void LoadLibraries(string librariesControlPath)
+ {
+ m_log.InfoFormat("[LIBRARY INVENTORY]: Loading library control file {0}", librariesControlPath);
+ LoadFromFile(librariesControlPath, "Libraries control", ReadLibraryFromConfig);
+ }
+
+ ///
+ /// Read a library set from config
+ ///
+ ///
+ protected void ReadLibraryFromConfig(IConfig config, string path)
+ {
+ string basePath = Path.GetDirectoryName(path);
+ string foldersPath
+ = Path.Combine(
+ basePath, config.GetString("foldersFile", String.Empty));
+
+ LoadFromFile(foldersPath, "Library folders", ReadFolderFromConfig);
+
+ string itemsPath
+ = Path.Combine(
+ basePath, config.GetString("itemsFile", String.Empty));
+
+ LoadFromFile(itemsPath, "Library items", ReadItemFromConfig);
+ }
+
+ ///
+ /// Read a library inventory folder from a loaded configuration
+ ///
+ ///
+ private void ReadFolderFromConfig(IConfig config, string path)
+ {
+ InventoryFolderImpl folderInfo = new InventoryFolderImpl();
+
+ folderInfo.ID = new UUID(config.GetString("folderID", m_LibraryRootFolder.ID.ToString()));
+ folderInfo.Name = config.GetString("name", "unknown");
+ folderInfo.ParentID = new UUID(config.GetString("parentFolderID", m_LibraryRootFolder.ID.ToString()));
+ folderInfo.Type = (short)config.GetInt("type", 8);
+
+ folderInfo.Owner = libOwner;
+ folderInfo.Version = 1;
+
+ if (libraryFolders.ContainsKey(folderInfo.ParentID))
+ {
+ InventoryFolderImpl parentFolder = libraryFolders[folderInfo.ParentID];
+
+ libraryFolders.Add(folderInfo.ID, folderInfo);
+ parentFolder.AddChildFolder(folderInfo);
+
+// m_log.InfoFormat("[LIBRARY INVENTORY]: Adding folder {0} ({1})", folderInfo.name, folderInfo.folderID);
+ }
+ else
+ {
+ m_log.WarnFormat(
+ "[LIBRARY INVENTORY]: Couldn't add folder {0} ({1}) since parent folder with ID {2} does not exist!",
+ folderInfo.Name, folderInfo.ID, folderInfo.ParentID);
+ }
+ }
+
+ ///
+ /// Read a library inventory item metadata from a loaded configuration
+ ///
+ ///
+ private void ReadItemFromConfig(IConfig config, string path)
+ {
+ InventoryItemBase item = new InventoryItemBase();
+ item.Owner = libOwner;
+ item.CreatorId = libOwner.ToString();
+ item.ID = new UUID(config.GetString("inventoryID", m_LibraryRootFolder.ID.ToString()));
+ item.AssetID = new UUID(config.GetString("assetID", item.ID.ToString()));
+ item.Folder = new UUID(config.GetString("folderID", m_LibraryRootFolder.ID.ToString()));
+ item.Name = config.GetString("name", String.Empty);
+ item.Description = config.GetString("description", item.Name);
+ item.InvType = config.GetInt("inventoryType", 0);
+ item.AssetType = config.GetInt("assetType", item.InvType);
+ item.CurrentPermissions = (uint)config.GetLong("currentPermissions", 0x7FFFFFFF);
+ item.NextPermissions = (uint)config.GetLong("nextPermissions", 0x7FFFFFFF);
+ item.EveryOnePermissions = (uint)config.GetLong("everyonePermissions", 0x7FFFFFFF);
+ item.BasePermissions = (uint)config.GetLong("basePermissions", 0x7FFFFFFF);
+ item.Flags = (uint)config.GetInt("flags", 0);
+
+ if (libraryFolders.ContainsKey(item.Folder))
+ {
+ InventoryFolderImpl parentFolder = libraryFolders[item.Folder];
+ try
+ {
+ parentFolder.Items.Add(item.ID, item);
+ }
+ catch (Exception)
+ {
+ m_log.WarnFormat("[LIBRARY INVENTORY] Item {1} [{0}] not added, duplicate item", item.ID, item.Name);
+ }
+ }
+ else
+ {
+ m_log.WarnFormat(
+ "[LIBRARY INVENTORY]: Couldn't add item {0} ({1}) since parent folder with ID {2} does not exist!",
+ item.Name, item.ID, item.Folder);
+ }
+ }
+
+ private delegate void ConfigAction(IConfig config, string path);
+
+ ///
+ /// Load the given configuration at a path and perform an action on each Config contained within it
+ ///
+ ///
+ ///
+ ///
+ private static void LoadFromFile(string path, string fileDescription, ConfigAction action)
+ {
+ if (File.Exists(path))
+ {
+ try
+ {
+ XmlConfigSource source = new XmlConfigSource(path);
+
+ for (int i = 0; i < source.Configs.Count; i++)
+ {
+ action(source.Configs[i], path);
+ }
+ }
+ catch (XmlException e)
+ {
+ m_log.ErrorFormat("[LIBRARY INVENTORY]: Error loading {0} : {1}", path, e);
+ }
+ }
+ else
+ {
+ m_log.ErrorFormat("[LIBRARY INVENTORY]: {0} file {1} does not exist!", fileDescription, path);
+ }
+ }
+
+ ///
+ /// Looks like a simple getter, but is written like this for some consistency with the other Request
+ /// methods in the superclass
+ ///
+ ///
+ public Dictionary GetAllFolders()
+ {
+ Dictionary fs = new Dictionary();
+ fs.Add(m_LibraryRootFolder.ID, m_LibraryRootFolder);
+ List fis = TraverseFolder(m_LibraryRootFolder);
+ foreach (InventoryFolderImpl f in fis)
+ {
+ fs.Add(f.ID, f);
+ }
+ //return libraryFolders;
+ return fs;
+ }
+
+ private List TraverseFolder(InventoryFolderImpl node)
+ {
+ List folders = node.RequestListOfFolderImpls();
+ List subs = new List();
+ foreach (InventoryFolderImpl f in folders)
+ subs.AddRange(TraverseFolder(f));
+
+ folders.AddRange(subs);
+ return folders;
+ }
+ }
+}
diff --git a/OpenSim/Services/LLLoginService/LLLoginResponse.cs b/OpenSim/Services/LLLoginService/LLLoginResponse.cs
index c80ab7f..4db6a05 100644
--- a/OpenSim/Services/LLLoginService/LLLoginResponse.cs
+++ b/OpenSim/Services/LLLoginService/LLLoginResponse.cs
@@ -215,12 +215,12 @@ namespace OpenSim.Services.LLLoginService
}
public LLLoginResponse(UserAccount account, AgentCircuitData aCircuit, PresenceInfo pinfo,
- GridRegion destination, List invSkel,
+ GridRegion destination, List invSkel, ILibraryService libService,
string where, string startlocation, Vector3 position, Vector3 lookAt, string message,
GridRegion home, IPEndPoint clientIP)
: this()
{
- FillOutInventoryData(invSkel);
+ FillOutInventoryData(invSkel, libService);
CircuitCode = (int)aCircuit.circuitcode;
Lastname = account.LastName;
@@ -243,7 +243,7 @@ namespace OpenSim.Services.LLLoginService
}
- private void FillOutInventoryData(List invSkel)
+ private void FillOutInventoryData(List invSkel, ILibraryService libService)
{
InventoryData inventData = null;
@@ -272,13 +272,16 @@ namespace OpenSim.Services.LLLoginService
}
// Inventory Library Section
- Hashtable InventoryLibRootHash = new Hashtable();
- InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
- InventoryLibRoot = new ArrayList();
- InventoryLibRoot.Add(InventoryLibRootHash);
+ if (libService != null && libService.LibraryRootFolder != null)
+ {
+ Hashtable InventoryLibRootHash = new Hashtable();
+ InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
+ InventoryLibRoot = new ArrayList();
+ InventoryLibRoot.Add(InventoryLibRootHash);
- InventoryLibraryOwner = GetLibraryOwner();
- InventoryLibrary = GetInventoryLibrary();
+ InventoryLibraryOwner = GetLibraryOwner(libService.LibraryRootFolder);
+ InventoryLibrary = GetInventoryLibrary(libService);
+ }
}
private void FillOutHomeData(PresenceInfo pinfo, GridRegion home)
@@ -646,12 +649,11 @@ namespace OpenSim.Services.LLLoginService
/// Converts the inventory library skeleton into the form required by the rpc request.
///
///
- protected virtual ArrayList GetInventoryLibrary()
+ protected virtual ArrayList GetInventoryLibrary(ILibraryService library)
{
- // While we don't have library...
- //Dictionary rootFolders
- // = m_libraryRootFolder.RequestSelfAndDescendentFolders();
- Dictionary rootFolders = new Dictionary();
+ Dictionary rootFolders = library.GetAllFolders();
+ m_log.DebugFormat("[LLOGIN]: Library has {0} folders", rootFolders.Count);
+ //Dictionary rootFolders = new Dictionary();
ArrayList folderHashes = new ArrayList();
foreach (InventoryFolderBase folder in rootFolders.Values)
@@ -672,11 +674,11 @@ namespace OpenSim.Services.LLLoginService
///
///
///
- protected virtual ArrayList GetLibraryOwner()
+ protected virtual ArrayList GetLibraryOwner(InventoryFolderImpl libFolder)
{
//for now create random inventory library owner
Hashtable TempHash = new Hashtable();
- TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000";
+ TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000"; // libFolder.Owner
ArrayList inventoryLibOwner = new ArrayList();
inventoryLibOwner.Add(TempHash);
return inventoryLibOwner;
diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs
index 58038cb..2b74539 100644
--- a/OpenSim/Services/LLLoginService/LLLoginService.cs
+++ b/OpenSim/Services/LLLoginService/LLLoginService.cs
@@ -26,13 +26,14 @@ namespace OpenSim.Services.LLLoginService
private IGridService m_GridService;
private IPresenceService m_PresenceService;
private ISimulationService m_LocalSimulationService;
+ private ILibraryService m_LibraryService;
private string m_DefaultRegionName;
private string m_RemoteSimulationDll;
private string m_WelcomeMessage;
private bool m_RequireInventory;
- public LLLoginService(IConfigSource config, ISimulationService simService)
+ public LLLoginService(IConfigSource config, ISimulationService simService, ILibraryService libraryService)
{
IConfig serverConfig = config.Configs["LoginService"];
if (serverConfig == null)
@@ -43,13 +44,14 @@ namespace OpenSim.Services.LLLoginService
string invService = serverConfig.GetString("InventoryService", String.Empty);
string gridService = serverConfig.GetString("GridService", String.Empty);
string presenceService = serverConfig.GetString("PresenceService", String.Empty);
+ string libService = serverConfig.GetString("LibraryService", String.Empty);
m_DefaultRegionName = serverConfig.GetString("DefaultRegion", String.Empty);
m_RemoteSimulationDll = serverConfig.GetString("RemoteSimulationService", String.Empty);
m_WelcomeMessage = serverConfig.GetString("WelcomeMessage", "Welcome to OpenSim!");
m_RequireInventory = serverConfig.GetBoolean("RequireInventory", true);
- // These 3 are required; the other 2 aren't
+ // These 3 are required; the others aren't
if (accountService == string.Empty || authService == string.Empty ||
invService == string.Empty)
throw new Exception("LoginService is missing service specifications");
@@ -62,13 +64,27 @@ namespace OpenSim.Services.LLLoginService
m_GridService = ServerUtils.LoadPlugin(gridService, args);
if (presenceService != string.Empty)
m_PresenceService = ServerUtils.LoadPlugin(presenceService, args);
+
+ //
+ // deal with the services given as argument
+ //
m_LocalSimulationService = simService;
+ if (libraryService != null)
+ {
+ m_log.DebugFormat("[LLOGIN SERVICE]: Using LibraryService given as argument");
+ m_LibraryService = libraryService;
+ }
+ else if (libService != string.Empty)
+ {
+ m_log.DebugFormat("[LLOGIN SERVICE]: Using instantiated LibraryService");
+ m_LibraryService = ServerUtils.LoadPlugin(libService, args);
+ }
m_log.DebugFormat("[LLOGIN SERVICE]: Starting...");
}
- public LLLoginService(IConfigSource config) : this(config, null)
+ public LLLoginService(IConfigSource config) : this(config, null, null)
{
}
@@ -171,7 +187,7 @@ namespace OpenSim.Services.LLLoginService
// TODO: Get Friends list...
// Finally, fill out the response and return it
- LLLoginResponse response = new LLLoginResponse(account, aCircuit, presence, destination, inventorySkel,
+ LLLoginResponse response = new LLLoginResponse(account, aCircuit, presence, destination, inventorySkel, m_LibraryService,
where, startLocation, position, lookAt, m_WelcomeMessage, home, clientIP);
return response;
--
cgit v1.1