First draft of inventory service connectors, and service implementation. No handlers yet, this is just the OUT part for now. It's not active and nothing in the simulator uses this yet. Just checking it in to start sharing with others. There are a couple of interesting software design points that could use other devs opinions.
Hopefully I added all needed files.0.6.6-post-fixes
parent
cda6b24668
commit
1ad237a8a7
|
@ -1,470 +1,466 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) Contributors, http://opensimulator.org/
|
* Copyright (c) Contributors, http://opensimulator.org/
|
||||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* * Neither the name of the OpenSimulator Project nor the
|
* * Neither the name of the OpenSimulator Project nor the
|
||||||
* names of its contributors may be used to endorse or promote products
|
* names of its contributors may be used to endorse or promote products
|
||||||
* derived from this software without specific prior written permission.
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* 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
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
|
|
||||||
//using System.Reflection;
|
namespace OpenSim.Framework
|
||||||
|
{
|
||||||
//using log4net;
|
public class InventoryFolderImpl : InventoryFolderBase
|
||||||
|
{
|
||||||
namespace OpenSim.Framework.Communications.Cache
|
//private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
{
|
|
||||||
public class InventoryFolderImpl : InventoryFolderBase
|
public static readonly string PATH_DELIMITER = "/";
|
||||||
{
|
|
||||||
//private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
/// <summary>
|
||||||
|
/// Items that are contained in this folder
|
||||||
public static readonly string PATH_DELIMITER = "/";
|
/// </summary>
|
||||||
|
public Dictionary<UUID, InventoryItemBase> Items = new Dictionary<UUID, InventoryItemBase>();
|
||||||
/// <summary>
|
|
||||||
/// Items that are contained in this folder
|
/// <summary>
|
||||||
/// </summary>
|
/// Child folders that are contained in this folder
|
||||||
public Dictionary<UUID, InventoryItemBase> Items = new Dictionary<UUID, InventoryItemBase>();
|
/// </summary>
|
||||||
|
protected Dictionary<UUID, InventoryFolderImpl> m_childFolders = new Dictionary<UUID, InventoryFolderImpl>();
|
||||||
/// <summary>
|
|
||||||
/// Child folders that are contained in this folder
|
// Constructors
|
||||||
/// </summary>
|
public InventoryFolderImpl(InventoryFolderBase folderbase)
|
||||||
protected Dictionary<UUID, InventoryFolderImpl> m_childFolders = new Dictionary<UUID, InventoryFolderImpl>();
|
{
|
||||||
|
Owner = folderbase.Owner;
|
||||||
// Constructors
|
ID = folderbase.ID;
|
||||||
public InventoryFolderImpl(InventoryFolderBase folderbase)
|
Name = folderbase.Name;
|
||||||
{
|
ParentID = folderbase.ParentID;
|
||||||
Owner = folderbase.Owner;
|
Type = folderbase.Type;
|
||||||
ID = folderbase.ID;
|
Version = folderbase.Version;
|
||||||
Name = folderbase.Name;
|
}
|
||||||
ParentID = folderbase.ParentID;
|
|
||||||
Type = folderbase.Type;
|
public InventoryFolderImpl()
|
||||||
Version = folderbase.Version;
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryFolderImpl()
|
/// <summary>
|
||||||
{
|
/// Create a new subfolder.
|
||||||
}
|
/// </summary>
|
||||||
|
/// <param name="folderID"></param>
|
||||||
/// <summary>
|
/// <param name="folderName"></param>
|
||||||
/// Create a new subfolder.
|
/// <param name="type"></param>
|
||||||
/// </summary>
|
/// <returns>The newly created subfolder. Returns null if the folder already exists</returns>
|
||||||
/// <param name="folderID"></param>
|
public InventoryFolderImpl CreateChildFolder(UUID folderID, string folderName, ushort type)
|
||||||
/// <param name="folderName"></param>
|
{
|
||||||
/// <param name="type"></param>
|
lock (m_childFolders)
|
||||||
/// <returns>The newly created subfolder. Returns null if the folder already exists</returns>
|
{
|
||||||
public InventoryFolderImpl CreateChildFolder(UUID folderID, string folderName, ushort type)
|
if (!m_childFolders.ContainsKey(folderID))
|
||||||
{
|
{
|
||||||
lock (m_childFolders)
|
InventoryFolderImpl subFold = new InventoryFolderImpl();
|
||||||
{
|
subFold.Name = folderName;
|
||||||
if (!m_childFolders.ContainsKey(folderID))
|
subFold.ID = folderID;
|
||||||
{
|
subFold.Type = (short)type;
|
||||||
InventoryFolderImpl subFold = new InventoryFolderImpl();
|
subFold.ParentID = this.ID;
|
||||||
subFold.Name = folderName;
|
subFold.Owner = Owner;
|
||||||
subFold.ID = folderID;
|
m_childFolders.Add(subFold.ID, subFold);
|
||||||
subFold.Type = (short) type;
|
|
||||||
subFold.ParentID = this.ID;
|
return subFold;
|
||||||
subFold.Owner = Owner;
|
}
|
||||||
m_childFolders.Add(subFold.ID, subFold);
|
}
|
||||||
|
|
||||||
return subFold;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
return null;
|
/// Add a folder that already exists.
|
||||||
}
|
/// </summary>
|
||||||
|
/// <param name="folder"></param>
|
||||||
/// <summary>
|
public void AddChildFolder(InventoryFolderImpl folder)
|
||||||
/// Add a folder that already exists.
|
{
|
||||||
/// </summary>
|
lock (m_childFolders)
|
||||||
/// <param name="folder"></param>
|
{
|
||||||
public void AddChildFolder(InventoryFolderImpl folder)
|
folder.ParentID = ID;
|
||||||
{
|
m_childFolders[folder.ID] = folder;
|
||||||
lock (m_childFolders)
|
}
|
||||||
{
|
}
|
||||||
folder.ParentID = ID;
|
|
||||||
m_childFolders[folder.ID] = folder;
|
/// <summary>
|
||||||
}
|
/// Does this folder contain the given child folder?
|
||||||
}
|
/// </summary>
|
||||||
|
/// <param name="folderID"></param>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
/// Does this folder contain the given child folder?
|
public bool ContainsChildFolder(UUID folderID)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="folderID"></param>
|
return m_childFolders.ContainsKey(folderID);
|
||||||
/// <returns></returns>
|
}
|
||||||
public bool ContainsChildFolder(UUID folderID)
|
|
||||||
{
|
/// <summary>
|
||||||
return m_childFolders.ContainsKey(folderID);
|
/// Get a child folder
|
||||||
}
|
/// </summary>
|
||||||
|
/// <param name="folderID"></param>
|
||||||
/// <summary>
|
/// <returns>The folder if it exists, null if it doesn't</returns>
|
||||||
/// Get a child folder
|
public InventoryFolderImpl GetChildFolder(UUID folderID)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="folderID"></param>
|
InventoryFolderImpl folder = null;
|
||||||
/// <returns>The folder if it exists, null if it doesn't</returns>
|
|
||||||
public InventoryFolderImpl GetChildFolder(UUID folderID)
|
lock (m_childFolders)
|
||||||
{
|
{
|
||||||
InventoryFolderImpl folder = null;
|
m_childFolders.TryGetValue(folderID, out folder);
|
||||||
|
}
|
||||||
lock (m_childFolders)
|
|
||||||
{
|
return folder;
|
||||||
m_childFolders.TryGetValue(folderID, out folder);
|
}
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
return folder;
|
/// Removes the given child subfolder.
|
||||||
}
|
/// </summary>
|
||||||
|
/// <param name="folderID"></param>
|
||||||
/// <summary>
|
/// <returns>
|
||||||
/// Removes the given child subfolder.
|
/// The folder removed, or null if the folder was not present.
|
||||||
/// </summary>
|
/// </returns>
|
||||||
/// <param name="folderID"></param>
|
public InventoryFolderImpl RemoveChildFolder(UUID folderID)
|
||||||
/// <returns>
|
{
|
||||||
/// The folder removed, or null if the folder was not present.
|
InventoryFolderImpl removedFolder = null;
|
||||||
/// </returns>
|
|
||||||
public InventoryFolderImpl RemoveChildFolder(UUID folderID)
|
lock (m_childFolders)
|
||||||
{
|
{
|
||||||
InventoryFolderImpl removedFolder = null;
|
if (m_childFolders.ContainsKey(folderID))
|
||||||
|
{
|
||||||
lock (m_childFolders)
|
removedFolder = m_childFolders[folderID];
|
||||||
{
|
m_childFolders.Remove(folderID);
|
||||||
if (m_childFolders.ContainsKey(folderID))
|
}
|
||||||
{
|
}
|
||||||
removedFolder = m_childFolders[folderID];
|
|
||||||
m_childFolders.Remove(folderID);
|
return removedFolder;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
return removedFolder;
|
/// Delete all the folders and items in this folder.
|
||||||
}
|
/// </summary>
|
||||||
|
public void Purge()
|
||||||
/// <summary>
|
{
|
||||||
/// Delete all the folders and items in this folder.
|
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
||||||
/// </summary>
|
{
|
||||||
public void Purge()
|
folder.Purge();
|
||||||
{
|
}
|
||||||
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
|
||||||
{
|
m_childFolders.Clear();
|
||||||
folder.Purge();
|
Items.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_childFolders.Clear();
|
/// <summary>
|
||||||
Items.Clear();
|
/// Returns the item if it exists in this folder or in any of this folder's descendant folders
|
||||||
}
|
/// </summary>
|
||||||
|
/// <param name="itemID"></param>
|
||||||
/// <summary>
|
/// <returns>null if the item is not found</returns>
|
||||||
/// Returns the item if it exists in this folder or in any of this folder's descendant folders
|
public InventoryItemBase FindItem(UUID itemID)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="itemID"></param>
|
lock (Items)
|
||||||
/// <returns>null if the item is not found</returns>
|
{
|
||||||
public InventoryItemBase FindItem(UUID itemID)
|
if (Items.ContainsKey(itemID))
|
||||||
{
|
{
|
||||||
lock (Items)
|
return Items[itemID];
|
||||||
{
|
}
|
||||||
if (Items.ContainsKey(itemID))
|
}
|
||||||
{
|
|
||||||
return Items[itemID];
|
lock (m_childFolders)
|
||||||
}
|
{
|
||||||
}
|
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
||||||
|
{
|
||||||
lock (m_childFolders)
|
InventoryItemBase item = folder.FindItem(itemID);
|
||||||
{
|
|
||||||
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
if (item != null)
|
||||||
{
|
{
|
||||||
InventoryItemBase item = folder.FindItem(itemID);
|
return item;
|
||||||
|
}
|
||||||
if (item != null)
|
}
|
||||||
{
|
}
|
||||||
return item;
|
|
||||||
}
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public InventoryItemBase FindAsset(UUID assetID)
|
||||||
return null;
|
{
|
||||||
}
|
lock (Items)
|
||||||
|
{
|
||||||
public InventoryItemBase FindAsset(UUID assetID)
|
foreach (InventoryItemBase item in Items.Values)
|
||||||
{
|
{
|
||||||
lock (Items)
|
if (item.AssetID == assetID)
|
||||||
{
|
return item;
|
||||||
foreach (InventoryItemBase item in Items.Values)
|
}
|
||||||
{
|
}
|
||||||
if (item.AssetID == assetID)
|
|
||||||
return item;
|
lock (m_childFolders)
|
||||||
}
|
{
|
||||||
}
|
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
||||||
|
{
|
||||||
lock (m_childFolders)
|
InventoryItemBase item = folder.FindAsset(assetID);
|
||||||
{
|
|
||||||
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
if (item != null)
|
||||||
{
|
{
|
||||||
InventoryItemBase item = folder.FindAsset(assetID);
|
return item;
|
||||||
|
}
|
||||||
if (item != null)
|
}
|
||||||
{
|
}
|
||||||
return item;
|
|
||||||
}
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
return null;
|
/// Deletes an item if it exists in this folder or any children
|
||||||
}
|
/// </summary>
|
||||||
|
/// <param name="folderID"></param>
|
||||||
/// <summary>
|
/// <returns></returns>
|
||||||
/// Deletes an item if it exists in this folder or any children
|
public bool DeleteItem(UUID itemID)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="folderID"></param>
|
bool found = false;
|
||||||
/// <returns></returns>
|
|
||||||
public bool DeleteItem(UUID itemID)
|
lock (Items)
|
||||||
{
|
{
|
||||||
bool found = false;
|
if (Items.ContainsKey(itemID))
|
||||||
|
{
|
||||||
lock (Items)
|
Items.Remove(itemID);
|
||||||
{
|
return true;
|
||||||
if (Items.ContainsKey(itemID))
|
}
|
||||||
{
|
}
|
||||||
Items.Remove(itemID);
|
|
||||||
return true;
|
lock (m_childFolders)
|
||||||
}
|
{
|
||||||
}
|
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
||||||
|
{
|
||||||
lock (m_childFolders)
|
found = folder.DeleteItem(itemID);
|
||||||
{
|
|
||||||
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
if (found == true)
|
||||||
{
|
{
|
||||||
found = folder.DeleteItem(itemID);
|
break;
|
||||||
|
}
|
||||||
if (found == true)
|
}
|
||||||
{
|
}
|
||||||
break;
|
|
||||||
}
|
return found;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
return found;
|
/// Returns the folder requested if it is this folder or is a descendent of this folder. The search is depth
|
||||||
}
|
/// first.
|
||||||
|
/// </summary>
|
||||||
/// <summary>
|
/// <returns>The requested folder if it exists, null if it does not.</returns>
|
||||||
/// Returns the folder requested if it is this folder or is a descendent of this folder. The search is depth
|
public InventoryFolderImpl FindFolder(UUID folderID)
|
||||||
/// first.
|
{
|
||||||
/// </summary>
|
if (folderID == ID)
|
||||||
/// <returns>The requested folder if it exists, null if it does not.</returns>
|
return this;
|
||||||
public InventoryFolderImpl FindFolder(UUID folderID)
|
|
||||||
{
|
lock (m_childFolders)
|
||||||
if (folderID == ID)
|
{
|
||||||
return this;
|
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
||||||
|
{
|
||||||
lock (m_childFolders)
|
InventoryFolderImpl returnFolder = folder.FindFolder(folderID);
|
||||||
{
|
|
||||||
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
if (returnFolder != null)
|
||||||
{
|
return returnFolder;
|
||||||
InventoryFolderImpl returnFolder = folder.FindFolder(folderID);
|
}
|
||||||
|
}
|
||||||
if (returnFolder != null)
|
|
||||||
return returnFolder;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
return null;
|
/// Look through all child subfolders for a folder marked as one for a particular asset type, and return it.
|
||||||
}
|
/// </summary>
|
||||||
|
/// <param name="type"></param>
|
||||||
/// <summary>
|
/// <returns>Returns null if no such folder is found</returns>
|
||||||
/// Look through all child subfolders for a folder marked as one for a particular asset type, and return it.
|
public InventoryFolderImpl FindFolderForType(int type)
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="type"></param>
|
lock (m_childFolders)
|
||||||
/// <returns>Returns null if no such folder is found</returns>
|
{
|
||||||
public InventoryFolderImpl FindFolderForType(int type)
|
foreach (InventoryFolderImpl f in m_childFolders.Values)
|
||||||
{
|
{
|
||||||
lock (m_childFolders)
|
if (f.Type == type)
|
||||||
{
|
return f;
|
||||||
foreach (InventoryFolderImpl f in m_childFolders.Values)
|
}
|
||||||
{
|
}
|
||||||
if (f.Type == type)
|
|
||||||
return f;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
return null;
|
/// Find a folder given a PATH_DELIMITER delimited path starting from this folder
|
||||||
}
|
/// </summary>
|
||||||
|
///
|
||||||
/// <summary>
|
/// This method does not handle paths that contain multiple delimitors
|
||||||
/// Find a folder given a PATH_DELIMITER delimited path starting from this folder
|
///
|
||||||
/// </summary>
|
/// FIXME: We do not yet handle situations where folders have the same name. We could handle this by some
|
||||||
///
|
/// XPath like expression
|
||||||
/// This method does not handle paths that contain multiple delimitors
|
///
|
||||||
///
|
/// FIXME: Delimitors which occur in names themselves are not currently escapable.
|
||||||
/// FIXME: We do not yet handle situations where folders have the same name. We could handle this by some
|
///
|
||||||
/// XPath like expression
|
/// <param name="path">
|
||||||
///
|
/// The path to the required folder.
|
||||||
/// FIXME: Delimitors which occur in names themselves are not currently escapable.
|
/// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned.
|
||||||
///
|
/// </param>
|
||||||
/// <param name="path">
|
/// <returns>null if the folder is not found</returns>
|
||||||
/// The path to the required folder.
|
public InventoryFolderImpl FindFolderByPath(string path)
|
||||||
/// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned.
|
{
|
||||||
/// </param>
|
if (path == string.Empty)
|
||||||
/// <returns>null if the folder is not found</returns>
|
return this;
|
||||||
public InventoryFolderImpl FindFolderByPath(string path)
|
|
||||||
{
|
path = path.Trim();
|
||||||
if (path == string.Empty)
|
|
||||||
return this;
|
if (path == PATH_DELIMITER)
|
||||||
|
return this;
|
||||||
path = path.Trim();
|
|
||||||
|
string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
|
||||||
if (path == PATH_DELIMITER)
|
|
||||||
return this;
|
lock (m_childFolders)
|
||||||
|
{
|
||||||
string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
|
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
||||||
|
{
|
||||||
lock (m_childFolders)
|
if (folder.Name == components[0])
|
||||||
{
|
if (components.Length > 1)
|
||||||
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
return folder.FindFolderByPath(components[1]);
|
||||||
{
|
else
|
||||||
if (folder.Name == components[0])
|
return folder;
|
||||||
if (components.Length > 1)
|
}
|
||||||
return folder.FindFolderByPath(components[1]);
|
}
|
||||||
else
|
|
||||||
return folder;
|
// We didn't find a folder with the given name
|
||||||
}
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We didn't find a folder with the given name
|
/// <summary>
|
||||||
return null;
|
/// Find an item given a PATH_DELIMITOR delimited path starting from this folder.
|
||||||
}
|
///
|
||||||
|
/// This method does not handle paths that contain multiple delimitors
|
||||||
/// <summary>
|
///
|
||||||
/// Find an item given a PATH_DELIMITOR delimited path starting from this folder.
|
/// FIXME: We do not yet handle situations where folders or items have the same name. We could handle this by some
|
||||||
///
|
/// XPath like expression
|
||||||
/// This method does not handle paths that contain multiple delimitors
|
///
|
||||||
///
|
/// FIXME: Delimitors which occur in names themselves are not currently escapable.
|
||||||
/// FIXME: We do not yet handle situations where folders or items have the same name. We could handle this by some
|
/// </summary>
|
||||||
/// XPath like expression
|
/// <param name="path">
|
||||||
///
|
/// The path to the required item.
|
||||||
/// FIXME: Delimitors which occur in names themselves are not currently escapable.
|
/// </param>
|
||||||
/// </summary>
|
/// <returns>null if the item is not found</returns>
|
||||||
/// <param name="path">
|
public InventoryItemBase FindItemByPath(string path)
|
||||||
/// The path to the required item.
|
{
|
||||||
/// </param>
|
string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
|
||||||
/// <returns>null if the item is not found</returns>
|
|
||||||
public InventoryItemBase FindItemByPath(string path)
|
if (components.Length == 1)
|
||||||
{
|
{
|
||||||
string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);
|
lock (Items)
|
||||||
|
{
|
||||||
if (components.Length == 1)
|
foreach (InventoryItemBase item in Items.Values)
|
||||||
{
|
{
|
||||||
lock (Items)
|
if (item.Name == components[0])
|
||||||
{
|
return item;
|
||||||
foreach (InventoryItemBase item in Items.Values)
|
}
|
||||||
{
|
}
|
||||||
if (item.Name == components[0])
|
}
|
||||||
return item;
|
else
|
||||||
}
|
{
|
||||||
}
|
lock (m_childFolders)
|
||||||
}
|
{
|
||||||
else
|
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
||||||
{
|
{
|
||||||
lock (m_childFolders)
|
if (folder.Name == components[0])
|
||||||
{
|
return folder.FindItemByPath(components[1]);
|
||||||
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
}
|
||||||
{
|
}
|
||||||
if (folder.Name == components[0])
|
}
|
||||||
return folder.FindItemByPath(components[1]);
|
|
||||||
}
|
// We didn't find an item or intermediate folder with the given name
|
||||||
}
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We didn't find an item or intermediate folder with the given name
|
/// <summary>
|
||||||
return null;
|
/// Return a copy of the list of child items in this folder. The items themselves are the originals.
|
||||||
}
|
/// </summary>
|
||||||
|
public List<InventoryItemBase> RequestListOfItems()
|
||||||
/// <summary>
|
{
|
||||||
/// Return a copy of the list of child items in this folder. The items themselves are the originals.
|
List<InventoryItemBase> itemList = new List<InventoryItemBase>();
|
||||||
/// </summary>
|
|
||||||
public List<InventoryItemBase> RequestListOfItems()
|
lock (Items)
|
||||||
{
|
{
|
||||||
List<InventoryItemBase> itemList = new List<InventoryItemBase>();
|
foreach (InventoryItemBase item in Items.Values)
|
||||||
|
{
|
||||||
lock (Items)
|
itemList.Add(item);
|
||||||
{
|
}
|
||||||
foreach (InventoryItemBase item in Items.Values)
|
}
|
||||||
{
|
|
||||||
itemList.Add(item);
|
//m_log.DebugFormat("[INVENTORY FOLDER IMPL]: Found {0} items", itemList.Count);
|
||||||
}
|
|
||||||
}
|
return itemList;
|
||||||
|
}
|
||||||
//m_log.DebugFormat("[INVENTORY FOLDER IMPL]: Found {0} items", itemList.Count);
|
|
||||||
|
/// <summary>
|
||||||
return itemList;
|
/// Return a copy of the list of child folders in this folder. The folders themselves are the originals.
|
||||||
}
|
/// </summary>
|
||||||
|
public List<InventoryFolderBase> RequestListOfFolders()
|
||||||
/// <summary>
|
{
|
||||||
/// Return a copy of the list of child folders in this folder. The folders themselves are the originals.
|
List<InventoryFolderBase> folderList = new List<InventoryFolderBase>();
|
||||||
/// </summary>
|
|
||||||
public List<InventoryFolderBase> RequestListOfFolders()
|
lock (m_childFolders)
|
||||||
{
|
{
|
||||||
List<InventoryFolderBase> folderList = new List<InventoryFolderBase>();
|
foreach (InventoryFolderBase folder in m_childFolders.Values)
|
||||||
|
{
|
||||||
lock (m_childFolders)
|
folderList.Add(folder);
|
||||||
{
|
}
|
||||||
foreach (InventoryFolderBase folder in m_childFolders.Values)
|
}
|
||||||
{
|
|
||||||
folderList.Add(folder);
|
return folderList;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public List<InventoryFolderImpl> RequestListOfFolderImpls()
|
||||||
return folderList;
|
{
|
||||||
}
|
List<InventoryFolderImpl> folderList = new List<InventoryFolderImpl>();
|
||||||
|
|
||||||
public List<InventoryFolderImpl> RequestListOfFolderImpls()
|
lock (m_childFolders)
|
||||||
{
|
{
|
||||||
List<InventoryFolderImpl> folderList = new List<InventoryFolderImpl>();
|
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
||||||
|
{
|
||||||
lock (m_childFolders)
|
folderList.Add(folder);
|
||||||
{
|
}
|
||||||
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
}
|
||||||
{
|
|
||||||
folderList.Add(folder);
|
return folderList;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/// <value>
|
||||||
return folderList;
|
/// The total number of items in this folder and in the immediate child folders (though not from other
|
||||||
}
|
/// descendants).
|
||||||
|
/// </value>
|
||||||
/// <value>
|
public int TotalCount
|
||||||
/// The total number of items in this folder and in the immediate child folders (though not from other
|
{
|
||||||
/// descendants).
|
get
|
||||||
/// </value>
|
{
|
||||||
public int TotalCount
|
int total = Items.Count;
|
||||||
{
|
|
||||||
get
|
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
||||||
{
|
{
|
||||||
int total = Items.Count;
|
total = total + folder.TotalCount;
|
||||||
|
}
|
||||||
foreach (InventoryFolderImpl folder in m_childFolders.Values)
|
|
||||||
{
|
return total;
|
||||||
total = total + folder.TotalCount;
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return total;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,366 @@
|
||||||
|
/*
|
||||||
|
* 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 log4net;
|
||||||
|
using Nini.Config;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using OpenSim.Framework;
|
||||||
|
using OpenSim.Framework.Communications.Cache;
|
||||||
|
using OpenSim.Server.Base;
|
||||||
|
using OpenSim.Region.Framework.Interfaces;
|
||||||
|
using OpenSim.Region.Framework.Scenes;
|
||||||
|
using OpenSim.Services.Interfaces;
|
||||||
|
using OpenSim.Services.Connectors;
|
||||||
|
using OpenMetaverse;
|
||||||
|
|
||||||
|
namespace OpenSim.Region.CoreModules.ServiceConnectors.Inventory
|
||||||
|
{
|
||||||
|
public class HGInventoryBroker : ISharedRegionModule, IInventoryService
|
||||||
|
{
|
||||||
|
private static readonly ILog m_log =
|
||||||
|
LogManager.GetLogger(
|
||||||
|
MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
private bool m_Enabled = false;
|
||||||
|
private bool m_Initialized = false;
|
||||||
|
private Scene m_Scene;
|
||||||
|
private UserProfileCacheService m_UserProfileService; // This should change to IUserProfileService
|
||||||
|
|
||||||
|
private IInventoryService m_GridService;
|
||||||
|
private ISessionAuthInventoryService m_HGService;
|
||||||
|
|
||||||
|
private string m_LocalGridInventoryURI = string.Empty;
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return "HGInventoryBroker"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialise(IConfigSource source)
|
||||||
|
{
|
||||||
|
IConfig moduleConfig = source.Configs["Modules"];
|
||||||
|
if (moduleConfig != null)
|
||||||
|
{
|
||||||
|
string name = moduleConfig.GetString("InventoryServices", "");
|
||||||
|
if (name == Name)
|
||||||
|
{
|
||||||
|
IConfig inventoryConfig = source.Configs["InventoryService"];
|
||||||
|
if (inventoryConfig == null)
|
||||||
|
{
|
||||||
|
m_log.Error("[HG INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string localDll = inventoryConfig.GetString("LocalGridInventoryService",
|
||||||
|
String.Empty);
|
||||||
|
string HGDll = inventoryConfig.GetString("HypergridInventoryService",
|
||||||
|
String.Empty);
|
||||||
|
|
||||||
|
if (localDll == String.Empty)
|
||||||
|
{
|
||||||
|
m_log.Error("[HG INVENTORY CONNECTOR]: No LocalGridInventoryService named in section InventoryService");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (HGDll == String.Empty)
|
||||||
|
{
|
||||||
|
m_log.Error("[HG INVENTORY CONNECTOR]: No HypergridInventoryService named in section InventoryService");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object[] args = new Object[] { source };
|
||||||
|
m_GridService =
|
||||||
|
ServerUtils.LoadPlugin<IInventoryService>(localDll,
|
||||||
|
args);
|
||||||
|
|
||||||
|
m_HGService =
|
||||||
|
ServerUtils.LoadPlugin<ISessionAuthInventoryService>(HGDll,
|
||||||
|
args);
|
||||||
|
|
||||||
|
if (m_GridService == null)
|
||||||
|
{
|
||||||
|
m_log.Error("[HG INVENTORY CONNECTOR]: Can't load local inventory service");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m_HGService == null)
|
||||||
|
{
|
||||||
|
m_log.Error("[HG INVENTORY CONNECTOR]: Can't load hypergrid inventory service");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_LocalGridInventoryURI = inventoryConfig.GetString("InventoryServerURI", string.Empty);
|
||||||
|
|
||||||
|
m_Enabled = true;
|
||||||
|
m_log.Info("[HG INVENTORY CONNECTOR]: HG asset broker enabled");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PostInitialise()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddRegion(Scene scene)
|
||||||
|
{
|
||||||
|
if (!m_Enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!m_Initialized)
|
||||||
|
{
|
||||||
|
m_Scene = scene;
|
||||||
|
// HACK for now. Ugh!
|
||||||
|
m_UserProfileService = m_Scene.CommsManager.UserProfileCacheService;
|
||||||
|
}
|
||||||
|
|
||||||
|
scene.RegisterModuleInterface<IInventoryService>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveRegion(Scene scene)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RegionLoaded(Scene scene)
|
||||||
|
{
|
||||||
|
if (!m_Enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_log.InfoFormat("[INVENTORY CONNECTOR]: Enabled remote inventory for region {0}", scene.RegionInfo.RegionName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IInventoryService
|
||||||
|
|
||||||
|
public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
|
||||||
|
{
|
||||||
|
if (IsLocalGridUser(userID))
|
||||||
|
m_GridService.GetUserInventory(userID, callback);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UUID sessionID = GetSessionID(userID);
|
||||||
|
string uri = "http://" + GetUserInventoryURI(userID) + "/" + userID.ToString();
|
||||||
|
m_HGService.GetUserInventory(uri, sessionID, callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
if (folder == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (IsLocalGridUser(folder.Owner))
|
||||||
|
return m_GridService.AddFolder(folder);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UUID sessionID = GetSessionID(folder.Owner);
|
||||||
|
string uri = "http://" + GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString();
|
||||||
|
return m_HGService.AddFolder(uri, folder, sessionID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
if (folder == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (IsLocalGridUser(folder.Owner))
|
||||||
|
return m_GridService.UpdateFolder(folder);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UUID sessionID = GetSessionID(folder.Owner);
|
||||||
|
string uri = "http://" + GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString();
|
||||||
|
return m_HGService.UpdateFolder(uri, folder, sessionID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MoveFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
if (folder == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (IsLocalGridUser(folder.Owner))
|
||||||
|
return m_GridService.MoveFolder(folder);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UUID sessionID = GetSessionID(folder.Owner);
|
||||||
|
string uri = "http://" + GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString();
|
||||||
|
return m_HGService.MoveFolder(uri, folder, sessionID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool PurgeFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
if (folder == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (IsLocalGridUser(folder.Owner))
|
||||||
|
return m_GridService.PurgeFolder(folder);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UUID sessionID = GetSessionID(folder.Owner);
|
||||||
|
string uri = "http://" + GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString();
|
||||||
|
return m_HGService.PurgeFolder(uri, folder, sessionID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
if (item == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (IsLocalGridUser(item.Owner))
|
||||||
|
return m_GridService.AddItem(item);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UUID sessionID = GetSessionID(item.Owner);
|
||||||
|
string uri = "http://" + GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString();
|
||||||
|
return m_HGService.AddItem(uri, item, sessionID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
if (item == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (IsLocalGridUser(item.Owner))
|
||||||
|
return m_GridService.UpdateItem(item);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UUID sessionID = GetSessionID(item.Owner);
|
||||||
|
string uri = "http://" + GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString();
|
||||||
|
return m_HGService.UpdateItem(uri, item, sessionID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeleteItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
if (item == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (IsLocalGridUser(item.Owner))
|
||||||
|
return m_GridService.DeleteItem(item);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UUID sessionID = GetSessionID(item.Owner);
|
||||||
|
string uri = "http://" + GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString();
|
||||||
|
return m_HGService.DeleteItem(uri, item, sessionID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryItemBase QueryItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
if (item == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (IsLocalGridUser(item.Owner))
|
||||||
|
return m_GridService.QueryItem(item);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UUID sessionID = GetSessionID(item.Owner);
|
||||||
|
string uri = "http://" + GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString();
|
||||||
|
return m_HGService.QueryItem(uri, item, sessionID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryFolderBase QueryFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
if (folder == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (IsLocalGridUser(folder.Owner))
|
||||||
|
return m_GridService.QueryFolder(folder);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UUID sessionID = GetSessionID(folder.Owner);
|
||||||
|
string uri = "http://" + GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString();
|
||||||
|
return m_HGService.QueryFolder(uri, folder, sessionID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasInventoryForUser(UUID userID)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryFolderBase RequestRootFolder(UUID userID)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private UUID GetSessionID(UUID userID)
|
||||||
|
{
|
||||||
|
ScenePresence sp = m_Scene.GetScenePresence(userID);
|
||||||
|
if (sp != null)
|
||||||
|
return sp.ControllingClient.SessionId;
|
||||||
|
|
||||||
|
return UUID.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsLocalGridUser(UUID userID)
|
||||||
|
{
|
||||||
|
if (m_UserProfileService == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CachedUserInfo uinfo = m_UserProfileService.GetUserDetails(userID);
|
||||||
|
if (uinfo == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
string userInventoryServerURI = HGNetworkServersInfo.ServerURI(uinfo.UserProfile.UserInventoryURI);
|
||||||
|
|
||||||
|
if ((userInventoryServerURI == m_LocalGridInventoryURI) || (userInventoryServerURI == ""))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetUserInventoryURI(UUID userID)
|
||||||
|
{
|
||||||
|
string invURI = m_LocalGridInventoryURI;
|
||||||
|
|
||||||
|
CachedUserInfo uinfo = m_UserProfileService.GetUserDetails(userID);
|
||||||
|
if ((uinfo == null) || (uinfo.UserProfile == null))
|
||||||
|
return invURI;
|
||||||
|
|
||||||
|
string userInventoryServerURI = HGNetworkServersInfo.ServerURI(uinfo.UserProfile.UserInventoryURI);
|
||||||
|
|
||||||
|
if ((userInventoryServerURI != null) &&
|
||||||
|
(userInventoryServerURI != ""))
|
||||||
|
invURI = userInventoryServerURI;
|
||||||
|
return invURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,246 @@
|
||||||
|
/*
|
||||||
|
* 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 log4net;
|
||||||
|
using Nini.Config;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using OpenSim.Framework;
|
||||||
|
using OpenSim.Data;
|
||||||
|
using OpenSim.Server.Base;
|
||||||
|
using OpenSim.Region.Framework.Interfaces;
|
||||||
|
using OpenSim.Region.Framework.Scenes;
|
||||||
|
using OpenSim.Services.Interfaces;
|
||||||
|
using OpenMetaverse;
|
||||||
|
|
||||||
|
namespace OpenSim.Region.CoreModules.ServiceConnectors.Inventory
|
||||||
|
{
|
||||||
|
public class LocalInventoryServicesConnector :
|
||||||
|
ISharedRegionModule, IInventoryService
|
||||||
|
{
|
||||||
|
private static readonly ILog m_log =
|
||||||
|
LogManager.GetLogger(
|
||||||
|
MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
private IInventoryService m_InventoryService;
|
||||||
|
|
||||||
|
private bool m_Enabled = false;
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return "LocalInventoryServicesConnector"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialise(IConfigSource source)
|
||||||
|
{
|
||||||
|
IConfig moduleConfig = source.Configs["Modules"];
|
||||||
|
if (moduleConfig != null)
|
||||||
|
{
|
||||||
|
string name = moduleConfig.GetString("InventoryServices", "");
|
||||||
|
if (name == Name)
|
||||||
|
{
|
||||||
|
IConfig assetConfig = source.Configs["InventoryService"];
|
||||||
|
if (assetConfig == null)
|
||||||
|
{
|
||||||
|
m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string serviceDll = assetConfig.GetString("LocalServiceModule",
|
||||||
|
String.Empty);
|
||||||
|
|
||||||
|
if (serviceDll == String.Empty)
|
||||||
|
{
|
||||||
|
m_log.Error("[INVENTORY CONNECTOR]: No LocalServiceModule named in section InventoryService");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object[] args = new Object[] { source };
|
||||||
|
m_InventoryService =
|
||||||
|
ServerUtils.LoadPlugin<IInventoryService>(serviceDll,
|
||||||
|
args);
|
||||||
|
|
||||||
|
if (m_InventoryService == null)
|
||||||
|
{
|
||||||
|
m_log.Error("[INVENTORY CONNECTOR]: Can't load asset service");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//List<IInventoryDataPlugin> plugins
|
||||||
|
// = DataPluginFactory.LoadDataPlugins<IInventoryDataPlugin>(
|
||||||
|
// configSettings.StandaloneInventoryPlugin,
|
||||||
|
// configSettings.StandaloneInventorySource);
|
||||||
|
|
||||||
|
//foreach (IInventoryDataPlugin plugin in plugins)
|
||||||
|
//{
|
||||||
|
// // Using the OSP wrapper plugin for database plugins should be made configurable at some point
|
||||||
|
// m_InventoryService.AddPlugin(new OspInventoryWrapperPlugin(plugin, this));
|
||||||
|
//}
|
||||||
|
|
||||||
|
m_Enabled = true;
|
||||||
|
m_log.Info("[INVENTORY CONNECTOR]: Local asset connector enabled");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PostInitialise()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddRegion(Scene scene)
|
||||||
|
{
|
||||||
|
if (!m_Enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
scene.RegisterModuleInterface<IInventoryService>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveRegion(Scene scene)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RegionLoaded(Scene scene)
|
||||||
|
{
|
||||||
|
if (!m_Enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_log.InfoFormat("[INVENTORY CONNECTOR]: Enabled local assets for region {0}", scene.RegionInfo.RegionName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
|
||||||
|
{
|
||||||
|
m_InventoryService.GetUserInventory(userID, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a new folder to the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder"></param>
|
||||||
|
/// <returns>true if the folder was successfully added</returns>
|
||||||
|
public bool AddFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
return m_InventoryService.AddFolder(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update a folder in the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder"></param>
|
||||||
|
/// <returns>true if the folder was successfully updated</returns>
|
||||||
|
public bool UpdateFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
return m_InventoryService.UpdateFolder(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Move an inventory folder to a new location
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder">A folder containing the details of the new location</param>
|
||||||
|
/// <returns>true if the folder was successfully moved</returns>
|
||||||
|
public bool MoveFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
return m_InventoryService.MoveFolder(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Purge an inventory folder of all its items and subfolders.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder"></param>
|
||||||
|
/// <returns>true if the folder was successfully purged</returns>
|
||||||
|
public bool PurgeFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
return m_InventoryService.PurgeFolder(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a new item to the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <returns>true if the item was successfully added</returns>
|
||||||
|
public bool AddItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
return m_InventoryService.AddItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update an item in the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <returns>true if the item was successfully updated</returns>
|
||||||
|
public bool UpdateItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
return m_InventoryService.UpdateItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete an item from the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <returns>true if the item was successfully deleted</returns>
|
||||||
|
public bool DeleteItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
return m_InventoryService.DeleteItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryItemBase QueryItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
return m_InventoryService.QueryItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryFolderBase QueryFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
return m_InventoryService.QueryFolder(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Does the given user have an inventory structure?
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userID"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool HasInventoryForUser(UUID userID)
|
||||||
|
{
|
||||||
|
return m_InventoryService.HasInventoryForUser(userID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve the root inventory folder for the given user.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userID"></param>
|
||||||
|
/// <returns>null if no root folder was found</returns>
|
||||||
|
public InventoryFolderBase RequestRootFolder(UUID userID)
|
||||||
|
{
|
||||||
|
return m_InventoryService.RequestRootFolder(userID);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,246 @@
|
||||||
|
/*
|
||||||
|
* 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 log4net;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using Nini.Config;
|
||||||
|
using OpenSim.Framework;
|
||||||
|
using OpenSim.Framework.Statistics;
|
||||||
|
using OpenSim.Services.Connectors;
|
||||||
|
using OpenSim.Region.Framework.Interfaces;
|
||||||
|
using OpenSim.Region.Framework.Scenes;
|
||||||
|
using OpenSim.Services.Interfaces;
|
||||||
|
using OpenMetaverse;
|
||||||
|
|
||||||
|
namespace OpenSim.Region.CoreModules.ServiceConnectors.Inventory
|
||||||
|
{
|
||||||
|
public class RemoteInventoryServicesConnector :
|
||||||
|
ISharedRegionModule, IInventoryService
|
||||||
|
{
|
||||||
|
private static readonly ILog m_log =
|
||||||
|
LogManager.GetLogger(
|
||||||
|
MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
private bool m_Enabled = false;
|
||||||
|
private bool m_Initialized = false;
|
||||||
|
private Scene m_Scene;
|
||||||
|
private InventoryServicesConnector m_RemoteConnector;
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return "RemoteInventoryServicesConnector"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public RemoteInventoryServicesConnector(IConfigSource source)
|
||||||
|
{
|
||||||
|
Init(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Init(IConfigSource source)
|
||||||
|
{
|
||||||
|
m_RemoteConnector = new InventoryServicesConnector(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region ISharedRegionModule
|
||||||
|
|
||||||
|
public void Initialise(IConfigSource source)
|
||||||
|
{
|
||||||
|
IConfig moduleConfig = source.Configs["Modules"];
|
||||||
|
if (moduleConfig != null)
|
||||||
|
{
|
||||||
|
string name = moduleConfig.GetString("InventoryServices", "");
|
||||||
|
if (name == Name)
|
||||||
|
{
|
||||||
|
Init(source);
|
||||||
|
m_Enabled = true;
|
||||||
|
|
||||||
|
m_log.Info("[INVENTORY CONNECTOR]: Remote inventory enabled");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PostInitialise()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddRegion(Scene scene)
|
||||||
|
{
|
||||||
|
if (!m_Enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!m_Initialized)
|
||||||
|
m_Scene = scene;
|
||||||
|
|
||||||
|
scene.RegisterModuleInterface<IInventoryService>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveRegion(Scene scene)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RegionLoaded(Scene scene)
|
||||||
|
{
|
||||||
|
if (!m_Enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_log.InfoFormat("[INVENTORY CONNECTOR]: Enabled remote inventory for region {0}", scene.RegionInfo.RegionName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion ISharedRegionModule
|
||||||
|
|
||||||
|
#region IInventoryService
|
||||||
|
|
||||||
|
public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
|
||||||
|
{
|
||||||
|
UUID sessionID = GetSessionID(userID);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_RemoteConnector.GetUserInventory(userID.ToString(), sessionID, callback);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
if (StatsManager.SimExtraStats != null)
|
||||||
|
StatsManager.SimExtraStats.AddInventoryServiceRetrievalFailure();
|
||||||
|
|
||||||
|
m_log.ErrorFormat("[INVENTORY CONNECTOR]: Request inventory operation failed, {0} {1}",
|
||||||
|
e.Source, e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
if (folder == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
UUID sessionID = GetSessionID(folder.Owner);
|
||||||
|
return m_RemoteConnector.AddFolder(folder.Owner.ToString(), folder, sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
if (folder == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
UUID sessionID = GetSessionID(folder.Owner);
|
||||||
|
return m_RemoteConnector.UpdateFolder(folder.Owner.ToString(), folder, sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MoveFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
if (folder == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
UUID sessionID = GetSessionID(folder.Owner);
|
||||||
|
return m_RemoteConnector.MoveFolder(folder.Owner.ToString(), folder, sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool PurgeFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
if (folder == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
UUID sessionID = GetSessionID(folder.Owner);
|
||||||
|
return m_RemoteConnector.PurgeFolder(folder.Owner.ToString(), folder, sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
if (item == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
UUID sessionID = GetSessionID(item.Owner);
|
||||||
|
return m_RemoteConnector.AddItem(item.Owner.ToString(), item, sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
if (item == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
UUID sessionID = GetSessionID(item.Owner);
|
||||||
|
return m_RemoteConnector.UpdateItem(item.Owner.ToString(), item, sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeleteItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
if (item == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
UUID sessionID = GetSessionID(item.Owner);
|
||||||
|
return m_RemoteConnector.DeleteItem(item.Owner.ToString(), item, sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryItemBase QueryItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
if (item == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
UUID sessionID = GetSessionID(item.Owner);
|
||||||
|
return m_RemoteConnector.QueryItem(item.Owner.ToString(), item, sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryFolderBase QueryFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
if (folder == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
UUID sessionID = GetSessionID(folder.Owner);
|
||||||
|
return m_RemoteConnector.QueryFolder(folder.Owner.ToString(), folder, sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasInventoryForUser(UUID userID)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryFolderBase RequestRootFolder(UUID userID)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private UUID GetSessionID(UUID userID)
|
||||||
|
{
|
||||||
|
ScenePresence sp = m_Scene.GetScenePresence(userID);
|
||||||
|
if (sp != null)
|
||||||
|
return sp.ControllingClient.SessionId;
|
||||||
|
|
||||||
|
return UUID.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,107 @@
|
||||||
|
/*
|
||||||
|
* 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 OpenSim.Framework;
|
||||||
|
using OpenSim.Services.Interfaces;
|
||||||
|
using OpenMetaverse;
|
||||||
|
|
||||||
|
namespace OpenSim.Services.Connectors
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Defines all operations to access a remote inventory service
|
||||||
|
/// using session authentication as a form of security.
|
||||||
|
/// </summary>
|
||||||
|
public interface ISessionAuthInventoryService
|
||||||
|
{
|
||||||
|
string Host
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request the inventory for a user. This is an asynchronous operation that will call the callback when the
|
||||||
|
/// inventory has been received
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userID"></param>
|
||||||
|
/// <param name="callback"></param>
|
||||||
|
void GetUserInventory(string userID, UUID session_id, InventoryReceiptCallback callback);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a new folder to the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder"></param>
|
||||||
|
/// <returns>true if the folder was successfully added</returns>
|
||||||
|
bool AddFolder(string userID, InventoryFolderBase folder, UUID session_id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update a folder in the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder"></param>
|
||||||
|
/// <returns>true if the folder was successfully updated</returns>
|
||||||
|
bool UpdateFolder(string userID, InventoryFolderBase folder, UUID session_id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Move an inventory folder to a new location
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder">A folder containing the details of the new location</param>
|
||||||
|
/// <returns>true if the folder was successfully moved</returns>
|
||||||
|
bool MoveFolder(string userID, InventoryFolderBase folder, UUID session_id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Purge an inventory folder of all its items and subfolders.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder"></param>
|
||||||
|
/// <returns>true if the folder was successfully purged</returns>
|
||||||
|
bool PurgeFolder(string userID, InventoryFolderBase folder, UUID session_id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a new item to the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <returns>true if the item was successfully added</returns>
|
||||||
|
bool AddItem(string userID, InventoryItemBase item, UUID session_id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update an item in the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <returns>true if the item was successfully updated</returns>
|
||||||
|
bool UpdateItem(string userID, InventoryItemBase item, UUID session_id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete an item from the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <returns>true if the item was successfully deleted</returns>
|
||||||
|
bool DeleteItem(string userID, InventoryItemBase item, UUID session_id);
|
||||||
|
|
||||||
|
InventoryItemBase QueryItem(string userID, InventoryItemBase item, UUID session_id);
|
||||||
|
|
||||||
|
InventoryFolderBase QueryFolder(string userID, InventoryFolderBase item, UUID session_id);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,343 @@
|
||||||
|
/*
|
||||||
|
* 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 log4net;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using Nini.Config;
|
||||||
|
using OpenSim.Framework;
|
||||||
|
using OpenSim.Framework.Servers.HttpServer;
|
||||||
|
using OpenSim.Services.Interfaces;
|
||||||
|
using OpenMetaverse;
|
||||||
|
|
||||||
|
namespace OpenSim.Services.Connectors
|
||||||
|
{
|
||||||
|
public class InventoryServicesConnector : ISessionAuthInventoryService
|
||||||
|
{
|
||||||
|
private static readonly ILog m_log =
|
||||||
|
LogManager.GetLogger(
|
||||||
|
MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
private string m_ServerURI = String.Empty;
|
||||||
|
|
||||||
|
private Dictionary<UUID, InventoryReceiptCallback> m_RequestingInventory = new Dictionary<UUID, InventoryReceiptCallback>();
|
||||||
|
|
||||||
|
public InventoryServicesConnector()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryServicesConnector(string serverURI)
|
||||||
|
{
|
||||||
|
m_ServerURI = serverURI.TrimEnd('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryServicesConnector(IConfigSource source)
|
||||||
|
{
|
||||||
|
Initialise(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Initialise(IConfigSource source)
|
||||||
|
{
|
||||||
|
IConfig inventoryConfig = source.Configs["InventoryService"];
|
||||||
|
if (inventoryConfig == null)
|
||||||
|
{
|
||||||
|
m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpanSim.ini");
|
||||||
|
throw new Exception("Inventory connector init error");
|
||||||
|
}
|
||||||
|
|
||||||
|
string serviceURI = inventoryConfig.GetString("InventoryServerURI",
|
||||||
|
String.Empty);
|
||||||
|
|
||||||
|
if (serviceURI == String.Empty)
|
||||||
|
{
|
||||||
|
m_log.Error("[INVENTORY CONNECTOR]: No Server URI named in section InventoryService");
|
||||||
|
throw new Exception("Inventory connector init error");
|
||||||
|
}
|
||||||
|
m_ServerURI = serviceURI.TrimEnd('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
#region ISessionAuthInventoryService
|
||||||
|
|
||||||
|
public string Host
|
||||||
|
{
|
||||||
|
get { return m_ServerURI; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Caller must catch eventual Exceptions.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userID"></param>
|
||||||
|
/// <param name="sessionID"></param>
|
||||||
|
/// <param name="callback"></param>
|
||||||
|
public void GetUserInventory(string userIDStr, UUID sessionID, InventoryReceiptCallback callback)
|
||||||
|
{
|
||||||
|
UUID userID = UUID.Zero;
|
||||||
|
if (UUID.TryParse(userIDStr, out userID))
|
||||||
|
{
|
||||||
|
lock (m_RequestingInventory)
|
||||||
|
{
|
||||||
|
if (!m_RequestingInventory.ContainsKey(userID))
|
||||||
|
m_RequestingInventory.Add(userID, callback);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetUserInventory - ignoring repeated request for user {0}", userID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_log.InfoFormat(
|
||||||
|
"[INVENTORY CONNECTOR]: Requesting inventory from {0}/GetInventory/ for user {1}",
|
||||||
|
m_ServerURI, userID);
|
||||||
|
|
||||||
|
RestSessionObjectPosterResponse<Guid, InventoryCollection> requester
|
||||||
|
= new RestSessionObjectPosterResponse<Guid, InventoryCollection>();
|
||||||
|
requester.ResponseCallback = InventoryResponse;
|
||||||
|
|
||||||
|
requester.BeginPostObject(m_ServerURI + "/GetInventory/", userID.Guid, sessionID.ToString(), userID.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddFolder(string userID, InventoryFolderBase folder, UUID sessionID)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
|
||||||
|
"POST", m_ServerURI + "/NewFolder/", folder, sessionID.ToString(), folder.Owner.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.ErrorFormat("[INVENTORY CONNECTOR]: Add new inventory folder operation failed, {0} {1}",
|
||||||
|
e.Source, e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateFolder(string userID, InventoryFolderBase folder, UUID sessionID)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
|
||||||
|
"POST", m_ServerURI + "/UpdateFolder/", folder, sessionID.ToString(), folder.Owner.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.ErrorFormat("[INVENTORY CONNECTOR]: Update inventory folder operation failed, {0} {1}",
|
||||||
|
e.Source, e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MoveFolder(string userID, InventoryFolderBase folder, UUID sessionID)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
|
||||||
|
"POST", m_ServerURI + "/MoveFolder/", folder, sessionID.ToString(), folder.Owner.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.ErrorFormat("[INVENTORY CONNECTOR]: Move inventory folder operation failed, {0} {1}",
|
||||||
|
e.Source, e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool PurgeFolder(string userID, InventoryFolderBase folder, UUID sessionID)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return SynchronousRestSessionObjectPoster<InventoryFolderBase, bool>.BeginPostObject(
|
||||||
|
"POST", m_ServerURI + "/PurgeFolder/", folder, sessionID.ToString(), folder.Owner.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.ErrorFormat("[INVENTORY CONNECTOR]: Move inventory folder operation failed, {0} {1}",
|
||||||
|
e.Source, e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddItem(string userID, InventoryItemBase item, UUID sessionID)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return SynchronousRestSessionObjectPoster<InventoryItemBase, bool>.BeginPostObject(
|
||||||
|
"POST", m_ServerURI + "/NewItem/", item, sessionID.ToString(), item.Owner.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.ErrorFormat("[INVENTORY CONNECTOR]: Add new inventory item operation failed, {0} {1}",
|
||||||
|
e.Source, e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateItem(string userID, InventoryItemBase item, UUID sessionID)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return SynchronousRestSessionObjectPoster<InventoryItemBase, bool>.BeginPostObject(
|
||||||
|
"POST", m_ServerURI + "/NewItem/", item, sessionID.ToString(), item.Owner.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.ErrorFormat("[INVENTORY CONNECTOR]: Update new inventory item operation failed, {0} {1}",
|
||||||
|
e.Source, e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeleteItem(string userID, InventoryItemBase item, UUID sessionID)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return SynchronousRestSessionObjectPoster<InventoryItemBase, bool>.BeginPostObject(
|
||||||
|
"POST", m_ServerURI + "/DeleteItem/", item, sessionID.ToString(), item.Owner.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.ErrorFormat("[INVENTORY CONNECTOR]: Delete inventory item operation failed, {0} {1}",
|
||||||
|
e.Source, e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryItemBase QueryItem(string userID, InventoryItemBase item, UUID sessionID)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return SynchronousRestSessionObjectPoster<InventoryItemBase, InventoryItemBase>.BeginPostObject(
|
||||||
|
"POST", m_ServerURI + "/QueryItem/", item, sessionID.ToString(), item.Owner.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.ErrorFormat("[INVENTORY CONNECTOR]: Query inventory item operation failed, {0} {1}",
|
||||||
|
e.Source, e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryFolderBase QueryFolder(string userID, InventoryFolderBase item, UUID sessionID)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return SynchronousRestSessionObjectPoster<InventoryFolderBase, InventoryFolderBase>.BeginPostObject(
|
||||||
|
"POST", m_ServerURI + "/QueryFolder/", item, sessionID.ToString(), item.Owner.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.ErrorFormat("[INVENTORY CONNECTOR]: Query inventory item operation failed, {0} {1}",
|
||||||
|
e.Source, e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Callback used by the inventory server GetInventory request
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userID"></param>
|
||||||
|
private void InventoryResponse(InventoryCollection response)
|
||||||
|
{
|
||||||
|
UUID userID = response.UserID;
|
||||||
|
InventoryReceiptCallback callback = null;
|
||||||
|
lock (m_RequestingInventory)
|
||||||
|
{
|
||||||
|
if (m_RequestingInventory.ContainsKey(userID))
|
||||||
|
{
|
||||||
|
callback = m_RequestingInventory[userID];
|
||||||
|
m_RequestingInventory.Remove(userID);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.WarnFormat(
|
||||||
|
"[INVENTORY CONNECTOR]: " +
|
||||||
|
"Received inventory response for {0} for which we do not have a record of requesting!",
|
||||||
|
userID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_log.InfoFormat("[INVENTORY CONNECTOR]: " +
|
||||||
|
"Received inventory response for user {0} containing {1} folders and {2} items",
|
||||||
|
userID, response.Folders.Count, response.Items.Count);
|
||||||
|
|
||||||
|
InventoryFolderImpl rootFolder = null;
|
||||||
|
|
||||||
|
ICollection<InventoryFolderImpl> folders = new List<InventoryFolderImpl>();
|
||||||
|
ICollection<InventoryItemBase> items = new List<InventoryItemBase>();
|
||||||
|
|
||||||
|
foreach (InventoryFolderBase folder in response.Folders)
|
||||||
|
{
|
||||||
|
if (folder.ParentID == UUID.Zero)
|
||||||
|
{
|
||||||
|
rootFolder = new InventoryFolderImpl(folder);
|
||||||
|
folders.Add(rootFolder);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rootFolder != null)
|
||||||
|
{
|
||||||
|
foreach (InventoryFolderBase folder in response.Folders)
|
||||||
|
{
|
||||||
|
if (folder.ID != rootFolder.ID)
|
||||||
|
{
|
||||||
|
folders.Add(new InventoryFolderImpl(folder));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (InventoryItemBase item in response.Items)
|
||||||
|
{
|
||||||
|
items.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.ErrorFormat("[INVENTORY CONNECTOR]: Did not get back an inventory containing a root folder for user {0}", userID);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(folders, items);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,118 @@
|
||||||
|
/*
|
||||||
|
* 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 OpenSim.Framework;
|
||||||
|
using OpenMetaverse;
|
||||||
|
|
||||||
|
namespace OpenSim.Services.Interfaces
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Callback used when a user's inventory is received from the inventory service
|
||||||
|
/// </summary>
|
||||||
|
public delegate void InventoryReceiptCallback(
|
||||||
|
ICollection<InventoryFolderImpl> folders, ICollection<InventoryItemBase> items);
|
||||||
|
|
||||||
|
public interface IInventoryService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Request the inventory for a user. This is an asynchronous operation that will call the callback when the
|
||||||
|
/// inventory has been received
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userID"></param>
|
||||||
|
/// <param name="callback"></param>
|
||||||
|
void GetUserInventory(UUID userID, InventoryReceiptCallback callback);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a new folder to the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder"></param>
|
||||||
|
/// <returns>true if the folder was successfully added</returns>
|
||||||
|
bool AddFolder(InventoryFolderBase folder);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update a folder in the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder"></param>
|
||||||
|
/// <returns>true if the folder was successfully updated</returns>
|
||||||
|
bool UpdateFolder(InventoryFolderBase folder);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Move an inventory folder to a new location
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder">A folder containing the details of the new location</param>
|
||||||
|
/// <returns>true if the folder was successfully moved</returns>
|
||||||
|
bool MoveFolder(InventoryFolderBase folder);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Purge an inventory folder of all its items and subfolders.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder"></param>
|
||||||
|
/// <returns>true if the folder was successfully purged</returns>
|
||||||
|
bool PurgeFolder(InventoryFolderBase folder);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a new item to the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <returns>true if the item was successfully added</returns>
|
||||||
|
bool AddItem(InventoryItemBase item);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update an item in the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <returns>true if the item was successfully updated</returns>
|
||||||
|
bool UpdateItem(InventoryItemBase item);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete an item from the user's inventory
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <returns>true if the item was successfully deleted</returns>
|
||||||
|
bool DeleteItem(InventoryItemBase item);
|
||||||
|
|
||||||
|
InventoryItemBase QueryItem(InventoryItemBase item);
|
||||||
|
|
||||||
|
InventoryFolderBase QueryFolder(InventoryFolderBase folder);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Does the given user have an inventory structure?
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userID"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool HasInventoryForUser(UUID userID);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve the root inventory folder for the given user.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userID"></param>
|
||||||
|
/// <returns>null if no root folder was found</returns>
|
||||||
|
InventoryFolderBase RequestRootFolder(UUID userID);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,178 @@
|
||||||
|
/*
|
||||||
|
* 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 log4net;
|
||||||
|
using Nini.Config;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using OpenSim.Framework;
|
||||||
|
using OpenSim.Services.Interfaces;
|
||||||
|
using OpenSim.Services.Connectors;
|
||||||
|
using OpenMetaverse;
|
||||||
|
|
||||||
|
namespace OpenSim.Services.InventoryService
|
||||||
|
{
|
||||||
|
public class HGInventoryService : ISessionAuthInventoryService
|
||||||
|
{
|
||||||
|
private static readonly ILog m_log =
|
||||||
|
LogManager.GetLogger(
|
||||||
|
MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
private Dictionary<string, InventoryServicesConnector> m_connectors = new Dictionary<string, InventoryServicesConnector>();
|
||||||
|
|
||||||
|
public HGInventoryService(IConfigSource source)
|
||||||
|
{
|
||||||
|
IConfig moduleConfig = source.Configs["Modules"];
|
||||||
|
if (moduleConfig != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
IConfig assetConfig = source.Configs["InventoryService"];
|
||||||
|
if (assetConfig == null)
|
||||||
|
{
|
||||||
|
m_log.Error("[HG INVENTORY SERVICE]: InventoryService missing from OpenSim.ini");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_log.Info("[HG INVENTORY SERVICE]: HG inventory service enabled");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool StringToUrlAndUserID(string id, out string url, out string userID)
|
||||||
|
{
|
||||||
|
url = String.Empty;
|
||||||
|
userID = String.Empty;
|
||||||
|
|
||||||
|
Uri assetUri;
|
||||||
|
|
||||||
|
if (Uri.TryCreate(id, UriKind.Absolute, out assetUri) &&
|
||||||
|
assetUri.Scheme == Uri.UriSchemeHttp)
|
||||||
|
{
|
||||||
|
url = "http://" + assetUri.Authority;
|
||||||
|
userID = assetUri.LocalPath.Trim(new char[] { '/' });
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private ISessionAuthInventoryService GetConnector(string url)
|
||||||
|
{
|
||||||
|
InventoryServicesConnector connector = null;
|
||||||
|
lock (m_connectors)
|
||||||
|
{
|
||||||
|
if (m_connectors.ContainsKey(url))
|
||||||
|
{
|
||||||
|
connector = m_connectors[url];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We're instantiating this class explicitly, but this won't
|
||||||
|
// work in general, because the remote grid may be running
|
||||||
|
// an inventory server that has a different protocol.
|
||||||
|
// Eventually we will want a piece of protocol asking
|
||||||
|
// the remote server about its kind. Definitely cool thing to do!
|
||||||
|
connector = new InventoryServicesConnector(url);
|
||||||
|
m_connectors.Add(url, connector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return connector;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Host
|
||||||
|
{
|
||||||
|
get { return string.Empty; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GetUserInventory(string id, UUID sessionID, InventoryReceiptCallback callback)
|
||||||
|
{
|
||||||
|
string url = string.Empty;
|
||||||
|
string userID = string.Empty;
|
||||||
|
|
||||||
|
if (StringToUrlAndUserID(id, out url, out userID))
|
||||||
|
{
|
||||||
|
ISessionAuthInventoryService connector = GetConnector(url);
|
||||||
|
connector.GetUserInventory(userID, sessionID, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddFolder(string userID, InventoryFolderBase folder, UUID sessionID)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateFolder(string userID, InventoryFolderBase folder, UUID sessionID)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MoveFolder(string userID, InventoryFolderBase folder, UUID sessionID)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool PurgeFolder(string userID, InventoryFolderBase folder, UUID sessionID)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddItem(string userID, InventoryItemBase item, UUID sessionID)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateItem(string userID, InventoryItemBase item, UUID sessionID)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeleteItem(string userID, InventoryItemBase item, UUID sessionID)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryItemBase QueryItem(string userID, InventoryItemBase item, UUID sessionID)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryFolderBase QueryFolder(string userID, InventoryFolderBase folder, UUID sessionID)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,544 @@
|
||||||
|
/*
|
||||||
|
* 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.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using log4net;
|
||||||
|
using Nini.Config;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using OpenSim.Data;
|
||||||
|
using OpenSim.Framework;
|
||||||
|
using OpenSim.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace OpenSim.Services.InventoryService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Inventory service reference implementation
|
||||||
|
/// </summary>
|
||||||
|
public class InventoryService : InventoryServiceBase, IInventoryService
|
||||||
|
{
|
||||||
|
private static readonly ILog m_log
|
||||||
|
= LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
public InventoryService(IConfigSource config) : base(config)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IInventoryServices methods
|
||||||
|
|
||||||
|
public string Host
|
||||||
|
{
|
||||||
|
get { return "default"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<InventoryFolderBase> GetInventorySkeleton(UUID userId)
|
||||||
|
{
|
||||||
|
// m_log.DebugFormat("[AGENT INVENTORY]: Getting inventory skeleton for {0}", userId);
|
||||||
|
|
||||||
|
InventoryFolderBase rootFolder = RequestRootFolder(userId);
|
||||||
|
|
||||||
|
// Agent has no inventory structure yet.
|
||||||
|
if (null == rootFolder)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<InventoryFolderBase> userFolders = new List<InventoryFolderBase>();
|
||||||
|
|
||||||
|
userFolders.Add(rootFolder);
|
||||||
|
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
IList<InventoryFolderBase> folders = plugin.getFolderHierarchy(rootFolder.ID);
|
||||||
|
userFolders.AddRange(folders);
|
||||||
|
}
|
||||||
|
|
||||||
|
// foreach (InventoryFolderBase folder in userFolders)
|
||||||
|
// {
|
||||||
|
// m_log.DebugFormat("[AGENT INVENTORY]: Got folder {0} {1}", folder.name, folder.folderID);
|
||||||
|
// }
|
||||||
|
|
||||||
|
return userFolders;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See IInventoryServices
|
||||||
|
public virtual bool HasInventoryForUser(UUID userID)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See IInventoryServices
|
||||||
|
public virtual InventoryFolderBase RequestRootFolder(UUID userID)
|
||||||
|
{
|
||||||
|
// Retrieve the first root folder we get from the list of plugins.
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
InventoryFolderBase rootFolder = plugin.getUserRootFolder(userID);
|
||||||
|
if (rootFolder != null)
|
||||||
|
return rootFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return nothing if no plugin was able to supply a root folder
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See IInventoryServices
|
||||||
|
public bool CreateNewUserInventory(UUID user)
|
||||||
|
{
|
||||||
|
InventoryFolderBase existingRootFolder = RequestRootFolder(user);
|
||||||
|
|
||||||
|
if (null != existingRootFolder)
|
||||||
|
{
|
||||||
|
m_log.WarnFormat(
|
||||||
|
"[AGENT INVENTORY]: Did not create a new inventory for user {0} since they already have "
|
||||||
|
+ "a root inventory folder with id {1}",
|
||||||
|
user, existingRootFolder.ID);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UsersInventory inven = new UsersInventory();
|
||||||
|
inven.CreateNewInventorySet(user);
|
||||||
|
AddNewInventorySet(inven);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See IInventoryServices
|
||||||
|
public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
|
||||||
|
{
|
||||||
|
m_log.InfoFormat("[LOCAL INVENTORY SERVICE]: Requesting inventory for user {0}", userID);
|
||||||
|
|
||||||
|
List<InventoryFolderImpl> folders = new List<InventoryFolderImpl>();
|
||||||
|
List<InventoryItemBase> items = new List<InventoryItemBase>();
|
||||||
|
|
||||||
|
List<InventoryFolderBase> skeletonFolders = GetInventorySkeleton(userID);
|
||||||
|
|
||||||
|
if (skeletonFolders != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
InventoryFolderImpl rootFolder = null;
|
||||||
|
|
||||||
|
// Need to retrieve the root folder on the first pass
|
||||||
|
foreach (InventoryFolderBase folder in skeletonFolders)
|
||||||
|
{
|
||||||
|
if (folder.ParentID == UUID.Zero)
|
||||||
|
{
|
||||||
|
rootFolder = new InventoryFolderImpl(folder);
|
||||||
|
folders.Add(rootFolder);
|
||||||
|
items.AddRange(RequestFolderItems(rootFolder.ID));
|
||||||
|
break; // Only 1 root folder per user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rootFolder != null)
|
||||||
|
{
|
||||||
|
foreach (InventoryFolderBase folder in skeletonFolders)
|
||||||
|
{
|
||||||
|
if (folder.ID != rootFolder.ID)
|
||||||
|
{
|
||||||
|
folders.Add(new InventoryFolderImpl(folder));
|
||||||
|
items.AddRange(RequestFolderItems(folder.ID));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_log.InfoFormat(
|
||||||
|
"[LOCAL INVENTORY SERVICE]: Received inventory response for user {0} containing {1} folders and {2} items",
|
||||||
|
userID, folders.Count, items.Count);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.WarnFormat("[LOCAL INVENTORY SERVICE]: User {0} inventory not available", userID);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(folders, items);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<InventoryItemBase> GetActiveGestures(UUID userId)
|
||||||
|
{
|
||||||
|
List<InventoryItemBase> activeGestures = new List<InventoryItemBase>();
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
activeGestures.AddRange(plugin.fetchActiveGestures(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
return activeGestures;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods used by GridInventoryService
|
||||||
|
|
||||||
|
public List<InventoryFolderBase> RequestSubFolders(UUID parentFolderID)
|
||||||
|
{
|
||||||
|
List<InventoryFolderBase> inventoryList = new List<InventoryFolderBase>();
|
||||||
|
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
inventoryList.AddRange(plugin.getInventoryFolders(parentFolderID));
|
||||||
|
}
|
||||||
|
|
||||||
|
return inventoryList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<InventoryItemBase> RequestFolderItems(UUID folderID)
|
||||||
|
{
|
||||||
|
List<InventoryItemBase> itemsList = new List<InventoryItemBase>();
|
||||||
|
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
itemsList.AddRange(plugin.getInventoryInFolder(folderID));
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// See IInventoryServices
|
||||||
|
public virtual bool AddFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat(
|
||||||
|
"[AGENT INVENTORY]: Adding folder {0} {1} to folder {2}", folder.Name, folder.ID, folder.ParentID);
|
||||||
|
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
plugin.addInventoryFolder(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Should return false on failure
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See IInventoryServices
|
||||||
|
public virtual bool UpdateFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat(
|
||||||
|
"[AGENT INVENTORY]: Updating folder {0} {1} to folder {2}", folder.Name, folder.ID, folder.ParentID);
|
||||||
|
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
plugin.updateInventoryFolder(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Should return false on failure
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See IInventoryServices
|
||||||
|
public virtual bool MoveFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat(
|
||||||
|
"[AGENT INVENTORY]: Moving folder {0} {1} to folder {2}", folder.Name, folder.ID, folder.ParentID);
|
||||||
|
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
plugin.moveInventoryFolder(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Should return false on failure
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See IInventoryServices
|
||||||
|
public virtual bool AddItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat(
|
||||||
|
"[AGENT INVENTORY]: Adding item {0} {1} to folder {2}", item.Name, item.ID, item.Folder);
|
||||||
|
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
plugin.addInventoryItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Should return false on failure
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See IInventoryServices
|
||||||
|
public virtual bool UpdateItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
m_log.InfoFormat(
|
||||||
|
"[AGENT INVENTORY]: Updating item {0} {1} in folder {2}", item.Name, item.ID, item.Folder);
|
||||||
|
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
plugin.updateInventoryItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Should return false on failure
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See IInventoryServices
|
||||||
|
public virtual bool DeleteItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
m_log.InfoFormat(
|
||||||
|
"[AGENT INVENTORY]: Deleting item {0} {1} from folder {2}", item.Name, item.ID, item.Folder);
|
||||||
|
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
plugin.deleteInventoryItem(item.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Should return false on failure
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual InventoryItemBase QueryItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
InventoryItemBase result = plugin.queryInventoryItem(item.ID);
|
||||||
|
if (result != null)
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual InventoryFolderBase QueryFolder(InventoryFolderBase item)
|
||||||
|
{
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
InventoryFolderBase result = plugin.queryInventoryFolder(item.ID);
|
||||||
|
if (result != null)
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Purge a folder of all items items and subfolders.
|
||||||
|
///
|
||||||
|
/// FIXME: Really nasty in a sense, because we have to query the database to get information we may
|
||||||
|
/// already know... Needs heavy refactoring.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folder"></param>
|
||||||
|
public virtual bool PurgeFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat(
|
||||||
|
"[AGENT INVENTORY]: Purging folder {0} {1} of its contents", folder.Name, folder.ID);
|
||||||
|
|
||||||
|
List<InventoryFolderBase> subFolders = RequestSubFolders(folder.ID);
|
||||||
|
|
||||||
|
foreach (InventoryFolderBase subFolder in subFolders)
|
||||||
|
{
|
||||||
|
// m_log.DebugFormat("[AGENT INVENTORY]: Deleting folder {0} {1}", subFolder.Name, subFolder.ID);
|
||||||
|
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
plugin.deleteInventoryFolder(subFolder.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<InventoryItemBase> items = RequestFolderItems(folder.ID);
|
||||||
|
|
||||||
|
foreach (InventoryItemBase item in items)
|
||||||
|
{
|
||||||
|
DeleteItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Should return false on failure
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddNewInventorySet(UsersInventory inventory)
|
||||||
|
{
|
||||||
|
foreach (InventoryFolderBase folder in inventory.Folders.Values)
|
||||||
|
{
|
||||||
|
AddFolder(folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryItemBase GetInventoryItem(UUID itemID)
|
||||||
|
{
|
||||||
|
foreach (IInventoryDataPlugin plugin in m_plugins)
|
||||||
|
{
|
||||||
|
InventoryItemBase item = plugin.getInventoryItem(itemID);
|
||||||
|
if (item != null)
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to create a new user inventory.
|
||||||
|
/// </summary>
|
||||||
|
private class UsersInventory
|
||||||
|
{
|
||||||
|
public Dictionary<UUID, InventoryFolderBase> Folders = new Dictionary<UUID, InventoryFolderBase>();
|
||||||
|
public Dictionary<UUID, InventoryItemBase> Items = new Dictionary<UUID, InventoryItemBase>();
|
||||||
|
|
||||||
|
public virtual void CreateNewInventorySet(UUID user)
|
||||||
|
{
|
||||||
|
InventoryFolderBase folder = new InventoryFolderBase();
|
||||||
|
|
||||||
|
folder.ParentID = UUID.Zero;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "My Inventory";
|
||||||
|
folder.Type = (short)AssetType.Folder;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
|
||||||
|
UUID rootFolder = folder.ID;
|
||||||
|
|
||||||
|
folder = new InventoryFolderBase();
|
||||||
|
folder.ParentID = rootFolder;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "Animations";
|
||||||
|
folder.Type = (short)AssetType.Animation;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
|
||||||
|
folder = new InventoryFolderBase();
|
||||||
|
folder.ParentID = rootFolder;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "Body Parts";
|
||||||
|
folder.Type = (short)AssetType.Bodypart;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
|
||||||
|
folder = new InventoryFolderBase();
|
||||||
|
folder.ParentID = rootFolder;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "Calling Cards";
|
||||||
|
folder.Type = (short)AssetType.CallingCard;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
|
||||||
|
folder = new InventoryFolderBase();
|
||||||
|
folder.ParentID = rootFolder;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "Clothing";
|
||||||
|
folder.Type = (short)AssetType.Clothing;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
|
||||||
|
folder = new InventoryFolderBase();
|
||||||
|
folder.ParentID = rootFolder;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "Gestures";
|
||||||
|
folder.Type = (short)AssetType.Gesture;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
|
||||||
|
folder = new InventoryFolderBase();
|
||||||
|
folder.ParentID = rootFolder;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "Landmarks";
|
||||||
|
folder.Type = (short)AssetType.Landmark;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
|
||||||
|
folder = new InventoryFolderBase();
|
||||||
|
folder.ParentID = rootFolder;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "Lost And Found";
|
||||||
|
folder.Type = (short)AssetType.LostAndFoundFolder;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
|
||||||
|
folder = new InventoryFolderBase();
|
||||||
|
folder.ParentID = rootFolder;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "Notecards";
|
||||||
|
folder.Type = (short)AssetType.Notecard;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
|
||||||
|
folder = new InventoryFolderBase();
|
||||||
|
folder.ParentID = rootFolder;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "Objects";
|
||||||
|
folder.Type = (short)AssetType.Object;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
|
||||||
|
folder = new InventoryFolderBase();
|
||||||
|
folder.ParentID = rootFolder;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "Photo Album";
|
||||||
|
folder.Type = (short)AssetType.SnapshotFolder;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
|
||||||
|
folder = new InventoryFolderBase();
|
||||||
|
folder.ParentID = rootFolder;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "Scripts";
|
||||||
|
folder.Type = (short)AssetType.LSLText;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
|
||||||
|
folder = new InventoryFolderBase();
|
||||||
|
folder.ParentID = rootFolder;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "Sounds";
|
||||||
|
folder.Type = (short)AssetType.Sound;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
|
||||||
|
folder = new InventoryFolderBase();
|
||||||
|
folder.ParentID = rootFolder;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "Textures";
|
||||||
|
folder.Type = (short)AssetType.Texture;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
|
||||||
|
folder = new InventoryFolderBase();
|
||||||
|
folder.ParentID = rootFolder;
|
||||||
|
folder.Owner = user;
|
||||||
|
folder.ID = UUID.Random();
|
||||||
|
folder.Name = "Trash";
|
||||||
|
folder.Type = (short)AssetType.TrashFolder;
|
||||||
|
folder.Version = 1;
|
||||||
|
Folders.Add(folder.ID, folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,98 @@
|
||||||
|
/*
|
||||||
|
* 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.Reflection;
|
||||||
|
using Nini.Config;
|
||||||
|
using OpenSim.Framework;
|
||||||
|
using OpenSim.Data;
|
||||||
|
using OpenSim.Services.Interfaces;
|
||||||
|
using OpenSim.Services.Base;
|
||||||
|
|
||||||
|
namespace OpenSim.Services.InventoryService
|
||||||
|
{
|
||||||
|
public class InventoryServiceBase : ServiceBase
|
||||||
|
{
|
||||||
|
protected IInventoryDataPlugin m_Database = null;
|
||||||
|
|
||||||
|
protected List<IInventoryDataPlugin> m_plugins = new List<IInventoryDataPlugin>();
|
||||||
|
|
||||||
|
public InventoryServiceBase(IConfigSource config) : base(config)
|
||||||
|
{
|
||||||
|
IConfig assetConfig = config.Configs["InventoryService"];
|
||||||
|
if (assetConfig == null)
|
||||||
|
throw new Exception("No InventoryService configuration");
|
||||||
|
|
||||||
|
string dllName = assetConfig.GetString("StorageProvider",
|
||||||
|
String.Empty);
|
||||||
|
|
||||||
|
if (dllName == String.Empty)
|
||||||
|
throw new Exception("No StorageProvider configured");
|
||||||
|
|
||||||
|
string connString = assetConfig.GetString("ConnectionString",
|
||||||
|
String.Empty);
|
||||||
|
|
||||||
|
m_Database = LoadPlugin<IInventoryDataPlugin>(dllName);
|
||||||
|
if (m_Database == null)
|
||||||
|
throw new Exception("Could not find a storage interface in the given module");
|
||||||
|
|
||||||
|
m_Database.Initialise(connString);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Plugin methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a new inventory data plugin - plugins will be requested in the order they were added.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plugin">The plugin that will provide data</param>
|
||||||
|
public void AddPlugin(IInventoryDataPlugin plugin)
|
||||||
|
{
|
||||||
|
m_plugins.Add(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a list of inventory data plugins, as described by `provider'
|
||||||
|
/// and `connect', to `m_plugins'.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="provider">
|
||||||
|
/// The filename of the inventory server plugin DLL.
|
||||||
|
/// </param>
|
||||||
|
/// <param name="connect">
|
||||||
|
/// The connection string for the storage backend.
|
||||||
|
/// </param>
|
||||||
|
public void AddPlugin(string provider, string connect)
|
||||||
|
{
|
||||||
|
m_plugins.AddRange(DataPluginFactory.LoadDataPlugins<IInventoryDataPlugin>(provider, connect));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
31
prebuild.xml
31
prebuild.xml
|
@ -1392,6 +1392,37 @@
|
||||||
</Files>
|
</Files>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
||||||
|
<Project name="OpenSim.Services.InventoryService" path="OpenSim/Services/InventoryService" type="Library">
|
||||||
|
<Configuration name="Debug">
|
||||||
|
<Options>
|
||||||
|
<OutputPath>../../../bin/</OutputPath>
|
||||||
|
</Options>
|
||||||
|
</Configuration>
|
||||||
|
<Configuration name="Release">
|
||||||
|
<Options>
|
||||||
|
<OutputPath>../../../bin/</OutputPath>
|
||||||
|
</Options>
|
||||||
|
</Configuration>
|
||||||
|
|
||||||
|
<ReferencePath>../../../bin/</ReferencePath>
|
||||||
|
<Reference name="System"/>
|
||||||
|
<Reference name="OpenMetaverseTypes.dll"/>
|
||||||
|
<Reference name="OpenMetaverse.dll"/>
|
||||||
|
<Reference name="OpenSim.Framework"/>
|
||||||
|
<Reference name="OpenSim.Framework.Console"/>
|
||||||
|
<Reference name="OpenSim.Framework.Servers.HttpServer"/>
|
||||||
|
<Reference name="OpenSim.Services.Interfaces"/>
|
||||||
|
<Reference name="OpenSim.Services.Base"/>
|
||||||
|
<Reference name="OpenSim.Services.Connectors"/>
|
||||||
|
<Reference name="OpenSim.Data"/>
|
||||||
|
<Reference name="Nini.dll" />
|
||||||
|
<Reference name="log4net.dll"/>
|
||||||
|
|
||||||
|
<Files>
|
||||||
|
<Match pattern="*.cs" recurse="true"/>
|
||||||
|
</Files>
|
||||||
|
</Project>
|
||||||
|
|
||||||
<Project name="OpenSim.Server.Base" path="OpenSim/Server/Base" type="Library">
|
<Project name="OpenSim.Server.Base" path="OpenSim/Server/Base" type="Library">
|
||||||
<Configuration name="Debug">
|
<Configuration name="Debug">
|
||||||
<Options>
|
<Options>
|
||||||
|
|
Loading…
Reference in New Issue