From 4c65bb4196408bfb213496c2e52064d578ed0240 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 27 Jan 2018 18:09:44 +0000 Subject: [PATCH] a few more changes on inventory library and inv fetch --- .../FetchInventory/FetchInventory2Handler.cs | 98 ++++++++++--------- OpenSim/Framework/Util.cs | 1 + .../InventoryService/LibraryService.cs | 32 +++--- 3 files changed, 73 insertions(+), 58 deletions(-) diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs index e239a90dbf..66b46a697b 100644 --- a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs +++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs @@ -26,6 +26,7 @@ */ using System.Reflection; +using System.Text; using OpenMetaverse; using OpenMetaverse.StructuredData; using OpenSim.Framework; @@ -59,9 +60,6 @@ namespace OpenSim.Capabilities.Handlers OSDMap requestmap = (OSDMap)OSDParser.DeserializeLLSDXml(Utils.StringToBytes(request)); OSDArray itemsRequested = (OSDArray)requestmap["items"]; - string reply; - LLSDFetchInventory llsdReply = new LLSDFetchInventory(); - UUID[] itemIDs = new UUID[itemsRequested.Count]; int i = 0; @@ -92,55 +90,65 @@ namespace OpenSim.Capabilities.Handlers items[i++] = m_inventoryService.GetItem(UUID.Zero, id); } - foreach (InventoryItemBase item in items) + StringBuilder lsl = LLSDxmlEncode.Start(2048); + LLSDxmlEncode.AddMap(lsl); + + if(m_agentID == UUID.Zero && items.Length > 0) + LLSDxmlEncode.AddElem("agent_id", items[0].Owner, lsl); + else + LLSDxmlEncode.AddElem("agent_id", m_agentID, lsl); + + if(items == null || items.Length == 0) { - if (item != null) - { - // We don't know the agent that this request belongs to so we'll use the agent id of the item - // which will be the same for all items. - llsdReply.agent_id = item.Owner; - llsdReply.items.Array.Add(ConvertInventoryItem(item)); - } + LLSDxmlEncode.AddEmptyArray("items",lsl); } + else + { + LLSDxmlEncode.AddArray("items",lsl); + foreach (InventoryItemBase item in items) + { + if (item != null) + { + // this is as FecthLib, possible to move to a shared location later + LLSDxmlEncode.AddMap(lsl); + LLSDxmlEncode.AddElem("parent_id", item.Folder, lsl); + LLSDxmlEncode.AddElem("asset_id", item.AssetID, lsl); + LLSDxmlEncode.AddElem("item_id", item.ID, lsl); - reply = LLSDHelpers.SerialiseLLSDReply(llsdReply); + 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); - return reply; - } + 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); - /// - /// Convert an internal inventory item object into an LLSD object. - /// - /// - /// - private LLSDInventoryItem ConvertInventoryItem(InventoryItemBase invItem) - { - LLSDInventoryItem llsdItem = new LLSDInventoryItem(); - llsdItem.asset_id = invItem.AssetID; - llsdItem.created_at = invItem.CreationDate; - llsdItem.desc = invItem.Description; - llsdItem.flags = ((int)invItem.Flags) & 0xff; - llsdItem.item_id = invItem.ID; - llsdItem.name = invItem.Name; - llsdItem.parent_id = invItem.Folder; - llsdItem.type = invItem.AssetType; - llsdItem.inv_type = invItem.InvType; + LLSDxmlEncode.AddMap("sale_info",lsl); + LLSDxmlEncode.AddElem("sale_price", item.SalePrice, lsl); + LLSDxmlEncode.AddElem("sale_type", item.SaleType, lsl); + LLSDxmlEncode.AddEndMap(lsl); - llsdItem.permissions = new LLSDPermissions(); - llsdItem.permissions.creator_id = invItem.CreatorIdAsUuid; - llsdItem.permissions.base_mask = (int)invItem.CurrentPermissions; - llsdItem.permissions.everyone_mask = (int)invItem.EveryOnePermissions; - llsdItem.permissions.group_id = invItem.GroupID; - llsdItem.permissions.group_mask = (int)invItem.GroupPermissions; - llsdItem.permissions.is_owner_group = invItem.GroupOwned; - llsdItem.permissions.next_owner_mask = (int)invItem.NextPermissions; - llsdItem.permissions.owner_id = invItem.Owner; - llsdItem.permissions.owner_mask = (int)invItem.CurrentPermissions; - llsdItem.sale_info = new LLSDSaleInfo(); - llsdItem.sale_info.sale_price = invItem.SalePrice; - llsdItem.sale_info.sale_type = invItem.SaleType; + LLSDxmlEncode.AddElem("name", item.Name, lsl); + LLSDxmlEncode.AddElem("desc", item.Description, lsl); + LLSDxmlEncode.AddElem("created_at", item.CreationDate, lsl); - return llsdItem; + LLSDxmlEncode.AddEndMap(lsl); + } + } + LLSDxmlEncode.AddEndArray(lsl); + } + + LLSDxmlEncode.AddEndMap(lsl); + return LLSDxmlEncode.End(lsl);; } } } diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 0685fdcb49..8e4a953c98 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -92,6 +92,7 @@ namespace OpenSim.Framework // explicitly given All = 0x8e000, AllAndExport = 0x9e000, + AllAndExportNoMod = 0x9a000, AllEffective = 0x9e000, UnfoldedMask = 0x1e000 } diff --git a/OpenSim/Services/InventoryService/LibraryService.cs b/OpenSim/Services/InventoryService/LibraryService.cs index c71295dd4f..de1c78462a 100644 --- a/OpenSim/Services/InventoryService/LibraryService.cs +++ b/OpenSim/Services/InventoryService/LibraryService.cs @@ -69,6 +69,11 @@ namespace OpenSim.Services.InventoryService static protected Dictionary m_items = new Dictionary(256); static LibraryService m_root; static object m_rootLock = new object(); + static readonly uint m_BasePermissions = (uint)PermissionMask.AllAndExport; + static readonly uint m_EveryOnePermissions = (uint)PermissionMask.AllAndExportNoMod; + static readonly uint m_CurrentPermissions = (uint)PermissionMask.AllAndExport; + static readonly uint m_NextPermissions = (uint)PermissionMask.AllAndExport; + static readonly uint m_GroupPermissions = 0; public LibraryService(IConfigSource config):base(config) { @@ -96,8 +101,8 @@ namespace OpenSim.Services.InventoryService m_LibraryRootFolder.ID = new UUID("00000112-000f-0000-0000-000100bba000"); m_LibraryRootFolder.Name = pLibName; m_LibraryRootFolder.ParentID = UUID.Zero; - m_LibraryRootFolder.Type = (short)8; - m_LibraryRootFolder.Version = (ushort)1; + m_LibraryRootFolder.Type = 8; + m_LibraryRootFolder.Version = 1; libraryFolders.Add(m_LibraryRootFolder.ID, m_LibraryRootFolder); @@ -117,10 +122,11 @@ namespace OpenSim.Services.InventoryService item.AssetType = assetType; item.InvType = invType; item.Folder = parentFolderID; - item.BasePermissions = 0x7FFFFFFF; - item.EveryOnePermissions = 0x7FFFFFFF; - item.CurrentPermissions = 0x7FFFFFFF; - item.NextPermissions = 0x7FFFFFFF; + item.BasePermissions = m_BasePermissions; + item.EveryOnePermissions = m_EveryOnePermissions; + item.CurrentPermissions = m_CurrentPermissions; + item.NextPermissions = m_NextPermissions; + item.GroupPermissions = m_GroupPermissions; return item; } @@ -142,6 +148,7 @@ namespace OpenSim.Services.InventoryService protected void ReadLibraryFromConfig(IConfig config, string path) { string basePath = Path.GetDirectoryName(path); + m_LibraryRootFolder.Version = (ushort)config.GetInt("RootVersion", 1); string foldersPath = Path.Combine( basePath, config.GetString("foldersFile", String.Empty)); @@ -167,9 +174,8 @@ namespace OpenSim.Services.InventoryService folderInfo.Name = config.GetString("name", "unknown"); folderInfo.ParentID = new UUID(config.GetString("parentFolderID", m_LibraryRootFolder.ID.ToString())); folderInfo.Type = (short)config.GetInt("type", 8); - + folderInfo.Version = (ushort)config.GetInt("version", 1); folderInfo.Owner = libOwner; - folderInfo.Version = 1; if (libraryFolders.ContainsKey(folderInfo.ParentID)) { @@ -205,11 +211,11 @@ namespace OpenSim.Services.InventoryService item.Description = config.GetString("description", item.Name); item.InvType = config.GetInt("inventoryType", 0); item.AssetType = config.GetInt("assetType", item.InvType); - item.CurrentPermissions = (uint)config.GetLong("currentPermissions", (uint)PermissionMask.All); - item.NextPermissions = (uint)config.GetLong("nextPermissions", (uint)PermissionMask.All); - item.EveryOnePermissions - = (uint)config.GetLong("everyonePermissions", (uint)PermissionMask.All - (uint)PermissionMask.Modify); - item.BasePermissions = (uint)config.GetLong("basePermissions", (uint)PermissionMask.All); + item.CurrentPermissions = (uint)config.GetLong("currentPermissions", m_CurrentPermissions); + item.NextPermissions = (uint)config.GetLong("nextPermissions", m_NextPermissions); + item.EveryOnePermissions = (uint)config.GetLong("everyonePermissions", m_EveryOnePermissions); + item.BasePermissions = (uint)config.GetLong("basePermissions", m_BasePermissions); + item.GroupPermissions = (uint)config.GetLong("basePermissions", m_GroupPermissions);; item.Flags = (uint)config.GetInt("flags", 0); if (libraryFolders.ContainsKey(item.Folder))