add Cap_FetchLib2 note that this is still local to regions, not using grid as it possible should, but this needs more work, and issue with HG older grids/regions

httptests
UbitUmarov 2018-01-27 04:32:03 +00:00
parent 3dbdacf31f
commit 13b4ce8199
7 changed files with 228 additions and 20 deletions

View File

@ -0,0 +1,141 @@
/*
* 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.Reflection;
using System.Text;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using OpenSim.Framework;
using OpenSim.Framework.Capabilities;
using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Services.Interfaces;
using OSDArray = OpenMetaverse.StructuredData.OSDArray;
using OSDMap = OpenMetaverse.StructuredData.OSDMap;
using log4net;
namespace OpenSim.Capabilities.Handlers
{
public class FetchLib2Handler
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IInventoryService m_inventoryService;
private ILibraryService m_LibraryService;
private UUID m_agentID;
private UUID libOwner;
public FetchLib2Handler(IInventoryService invService, ILibraryService libraryService, UUID agentId)
{
m_inventoryService = invService;
m_agentID = agentId;
m_LibraryService = libraryService;
if(libraryService != null)
libOwner = m_LibraryService.LibraryRootFolder.Owner;
}
public string FetchLibRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
//m_log.DebugFormat("[FETCH INVENTORY HANDLER]: Received FetchInventory capability request {0}", request);
if (m_LibraryService == null)
return "<llsd><map><key><agent_id></key><uuid /><key>items</key><array /></map></llsd>";
OSDMap requestmap = (OSDMap)OSDParser.DeserializeLLSDXml(Utils.StringToBytes(request));
OSDArray itemsRequested = (OSDArray)requestmap["items"];
if (m_agentID == UUID.Zero)
return "<llsd><map><key><agent_id></key><uuid /><key>items</key><array /></map></llsd>";
UUID[] itemIDs = new UUID[itemsRequested.Count];
int i = 0;
foreach (OSDMap osdItemId in itemsRequested)
itemIDs[i++] = osdItemId["item_id"].AsUUID();
InventoryItemBase[] items = null;
// items = m_inventoryService.GetMultipleItems(libOwner, itemIDs);
items = m_LibraryService.GetMultipleItems(itemIDs);
StringBuilder lsl = LLSDxmlEncode.Start(2048);
LLSDxmlEncode.AddMap(lsl);
LLSDxmlEncode.AddElem("agent_id", m_agentID, lsl);
if(items == null || items.Length == 0)
{
LLSDxmlEncode.AddEmptyArray("items",lsl);
}
else
{
LLSDxmlEncode.AddArray("items",lsl);
foreach (InventoryItemBase item in items)
{
if (item != null)
{
LLSDxmlEncode.AddMap(lsl);
LLSDxmlEncode.AddElem("parent_id", item.Folder, lsl);
LLSDxmlEncode.AddElem("asset_id", item.AssetID, lsl);
LLSDxmlEncode.AddElem("item_id", item.ID, lsl);
LLSDxmlEncode.AddMap("permissions",lsl);
LLSDxmlEncode.AddElem("creator_id", item.CreatorIdAsUuid, lsl);
LLSDxmlEncode.AddElem("owner_id", item.Owner, lsl);
LLSDxmlEncode.AddElem("group_id", item.GroupID, lsl);
LLSDxmlEncode.AddElem("base_mask", (int)item.CurrentPermissions, lsl);
LLSDxmlEncode.AddElem("owner_mask", (int)item.CurrentPermissions, lsl);
LLSDxmlEncode.AddElem("group_mask", (int)item.GroupPermissions, lsl);
LLSDxmlEncode.AddElem("everyone_mask", (int)item.EveryOnePermissions, lsl);
LLSDxmlEncode.AddElem("next_owner_mask", (int)item.NextPermissions, lsl);
LLSDxmlEncode.AddElem("is_owner_group", item.GroupOwned, lsl);
LLSDxmlEncode.AddEndMap(lsl);
LLSDxmlEncode.AddElem("type", item.AssetType, lsl);
LLSDxmlEncode.AddElem("inv_type", item.InvType, lsl);
LLSDxmlEncode.AddElem("flags", ((int)item.Flags) & 0xff, lsl);
LLSDxmlEncode.AddElem("flags", ((int)item.Flags) & 0xff, lsl);
LLSDxmlEncode.AddMap("sale_info",lsl);
LLSDxmlEncode.AddElem("sale_price", item.SalePrice, lsl);
LLSDxmlEncode.AddElem("sale_type", item.SaleType, lsl);
LLSDxmlEncode.AddEndMap(lsl);
LLSDxmlEncode.AddElem("name", item.Name, lsl);
LLSDxmlEncode.AddElem("desc", item.Description, lsl);
LLSDxmlEncode.AddElem("created_at", item.CreationDate, lsl);
LLSDxmlEncode.AddEndMap(lsl);
}
}
LLSDxmlEncode.AddEndArray(lsl);
}
LLSDxmlEncode.AddEndMap(lsl);
return LLSDxmlEncode.End(lsl);;
}
}
}

View File

@ -81,7 +81,7 @@ namespace OpenSim.Framework
sb.Append("</map>");
}
public static void AddEmpyMap(StringBuilder sb)
public static void AddEmptyMap(StringBuilder sb)
{
sb.Append("<map />");
}
@ -97,7 +97,7 @@ namespace OpenSim.Framework
sb.Append("</array>");
}
public static void AddEmpyArray(StringBuilder sb)
public static void AddEmptyArray(StringBuilder sb)
{
sb.Append("<array />");
}
@ -254,7 +254,7 @@ namespace OpenSim.Framework
sb.Append("</key><map>");
}
public static void AddEmpyMap(string name, StringBuilder sb)
public static void AddEmptyMap(string name, StringBuilder sb)
{
sb.Append("<key>");
sb.Append(name);
@ -269,7 +269,7 @@ namespace OpenSim.Framework
sb.Append("</key><array>");
}
public static void AddEmpyArray(string name, StringBuilder sb)
public static void AddEmptyArray(string name, StringBuilder sb)
{
sb.Append("<key>");
sb.Append(name);

View File

@ -1381,7 +1381,7 @@ namespace OpenSim.Region.ClientStack.Linden
StringBuilder lsl = LLSDxmlEncode.Start();
if(object_ids.Count == 0)
LLSDxmlEncode.AddEmpyMap(lsl);
LLSDxmlEncode.AddEmptyMap(lsl);
else
{
LLSDxmlEncode.AddMap(lsl);
@ -1419,7 +1419,7 @@ namespace OpenSim.Region.ClientStack.Linden
StringBuilder lsl = LLSDxmlEncode.Start(512);
if(object_ids.Count == 0)
LLSDxmlEncode.AddEmpyMap(lsl);
LLSDxmlEncode.AddEmptyMap(lsl);
else
{
bool haveone = false;
@ -1854,7 +1854,7 @@ namespace OpenSim.Region.ClientStack.Linden
StringBuilder lsl = LLSDxmlEncode.Start(names.Count * 256 + 256);
LLSDxmlEncode.AddMap(lsl);
if(names.Count == 0)
LLSDxmlEncode.AddEmpyArray("agents", lsl);
LLSDxmlEncode.AddEmptyArray("agents", lsl);
else
{
LLSDxmlEncode.AddArray("agents", lsl);

View File

@ -51,8 +51,9 @@ namespace OpenSim.Region.ClientStack.Linden
private Scene m_scene;
private IInventoryService m_inventoryService;
private ILibraryService m_LibraryService;
private string m_fetchInventory2Url;
private string m_fetchLib2Url;
#region ISharedRegionModule Members
@ -63,6 +64,7 @@ namespace OpenSim.Region.ClientStack.Linden
return;
m_fetchInventory2Url = config.GetString("Cap_FetchInventory2", string.Empty);
m_fetchLib2Url = config.GetString("Cap_FetchLib2", "localhost");
if (m_fetchInventory2Url != string.Empty)
Enabled = true;
@ -91,7 +93,7 @@ namespace OpenSim.Region.ClientStack.Linden
return;
m_inventoryService = m_scene.InventoryService;
m_LibraryService = m_scene.LibraryService;
m_scene.EventManager.OnRegisterCaps += RegisterCaps;
}
@ -111,6 +113,7 @@ namespace OpenSim.Region.ClientStack.Linden
private void RegisterCaps(UUID agentID, Caps caps)
{
RegisterFetchCap(agentID, caps, "FetchInventory2", m_fetchInventory2Url);
RegisterFetchLibCap(agentID, caps, "FetchLib2", m_fetchLib2Url);
}
private void RegisterFetchCap(UUID agentID, Caps caps, string capName, string url)
@ -136,6 +139,34 @@ namespace OpenSim.Region.ClientStack.Linden
caps.RegisterHandler(capName, capUrl);
}
// m_log.DebugFormat(
// "[FETCH INVENTORY2 MODULE]: Registered capability {0} at {1} in region {2} for {3}",
// capName, capUrl, m_scene.RegionInfo.RegionName, agentID);
}
private void RegisterFetchLibCap(UUID agentID, Caps caps, string capName, string url)
{
string capUrl;
if (url == "localhost")
{
capUrl = "/CAPS/" + UUID.Random();
FetchLib2Handler fetchHandler = new FetchLib2Handler(m_inventoryService, m_LibraryService, agentID);
IRequestHandler reqHandler
= new RestStreamHandler(
"POST", capUrl, fetchHandler.FetchLibRequest, capName, agentID.ToString());
caps.RegisterHandler(capName, reqHandler);
}
else
{
capUrl = url;
caps.RegisterHandler(capName, capUrl);
}
// m_log.DebugFormat(
// "[FETCH INVENTORY2 MODULE]: Registered capability {0} at {1} in region {2} for {3}",
// capName, capUrl, m_scene.RegionInfo.RegionName, agentID);

View File

@ -38,6 +38,7 @@ namespace OpenSim.Services.Interfaces
InventoryFolderImpl LibraryRootFolder { get; }
Dictionary<UUID, InventoryFolderImpl> GetAllFolders();
InventoryItemBase GetItem(UUID itemID);
InventoryItemBase[] GetMultipleItems(UUID[] itemIDs);
}
}

View File

@ -50,25 +50,35 @@ namespace OpenSim.Services.InventoryService
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private InventoryFolderImpl m_LibraryRootFolder;
static private InventoryFolderImpl m_LibraryRootFolder;
public InventoryFolderImpl LibraryRootFolder
{
get { return m_LibraryRootFolder; }
}
private UUID libOwner = new UUID("11111111-1111-0000-0000-000100bba000");
static private UUID libOwner = new UUID("11111111-1111-0000-0000-000100bba000");
/// <summary>
/// Holds the root library folder and all its descendents. This is really only used during inventory
/// setup so that we don't have to repeatedly search the tree of library folders.
/// </summary>
protected Dictionary<UUID, InventoryFolderImpl> libraryFolders
= new Dictionary<UUID, InventoryFolderImpl>();
static protected Dictionary<UUID, InventoryFolderImpl> libraryFolders
= new Dictionary<UUID, InventoryFolderImpl>(32);
public LibraryService(IConfigSource config)
: base(config)
static protected Dictionary<UUID, InventoryItemBase> m_items = new Dictionary<UUID, InventoryItemBase>(256);
static LibraryService m_root;
static object m_rootLock = new object();
public LibraryService(IConfigSource config):base(config)
{
lock(m_rootLock)
{
if(m_root != null)
return;
m_root = this;
}
string pLibrariesLocation = Path.Combine("inventory", "Libraries.xml");
string pLibName = "OpenSim Library";
@ -187,7 +197,8 @@ namespace OpenSim.Services.InventoryService
InventoryItemBase item = new InventoryItemBase();
item.Owner = libOwner;
item.CreatorId = libOwner.ToString();
item.ID = new UUID(config.GetString("inventoryID", m_LibraryRootFolder.ID.ToString()));
UUID itID = new UUID(config.GetString("inventoryID", m_LibraryRootFolder.ID.ToString()));
item.ID = itID;
item.AssetID = new UUID(config.GetString("assetID", item.ID.ToString()));
item.Folder = new UUID(config.GetString("folderID", m_LibraryRootFolder.ID.ToString()));
item.Name = config.GetString("name", String.Empty);
@ -204,11 +215,12 @@ namespace OpenSim.Services.InventoryService
if (libraryFolders.ContainsKey(item.Folder))
{
InventoryFolderImpl parentFolder = libraryFolders[item.Folder];
try
if(!parentFolder.Items.ContainsKey(itID))
{
parentFolder.Items.Add(item.ID, item);
parentFolder.Items.Add(itID, item);
m_items[itID] = item;
}
catch (Exception)
else
{
m_log.WarnFormat("[LIBRARY INVENTORY] Item {1} [{0}] not added, duplicate item", item.ID, item.Name);
}
@ -281,5 +293,27 @@ namespace OpenSim.Services.InventoryService
folders.AddRange(subs);
return folders;
}
public InventoryItemBase GetItem(UUID itemID)
{
if(m_items.ContainsKey(itemID))
return m_items[itemID];
return null;
}
public InventoryItemBase[] GetMultipleItems(UUID[] ids)
{
List<InventoryItemBase> items = new List<InventoryItemBase>();
int i = 0;
foreach (UUID id in ids)
{
if(m_items.ContainsKey(id))
items.Add(m_items[id]);
}
if(items.Count == 0)
return null;
return items.ToArray();
}
}
}

View File

@ -843,6 +843,7 @@
Cap_WebFetchInventoryDescendents = ""
Cap_FetchInventoryDescendents2 = "localhost"
Cap_FetchInventory2 = "localhost"
Cap_FetchLib2 = "localhost"
; Capability for searching for people
Cap_AvatarPickerSearch = "localhost"