FetchInventory2Handler.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using log4net;
  32. using Nini.Config;
  33. using OpenMetaverse;
  34. using OpenMetaverse.StructuredData;
  35. using OpenSim.Framework;
  36. using OpenSim.Framework.Capabilities;
  37. using OpenSim.Region.Framework.Interfaces;
  38. using OpenSim.Framework.Servers.HttpServer;
  39. using OpenSim.Services.Interfaces;
  40. using Caps = OpenSim.Framework.Capabilities.Caps;
  41. using OSDArray = OpenMetaverse.StructuredData.OSDArray;
  42. using OSDMap = OpenMetaverse.StructuredData.OSDMap;
  43. namespace OpenSim.Capabilities.Handlers
  44. {
  45. public class FetchInventory2Handler
  46. {
  47. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. private IInventoryService m_inventoryService;
  49. public FetchInventory2Handler(IInventoryService invService)
  50. {
  51. m_inventoryService = invService;
  52. }
  53. public string FetchInventoryRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  54. {
  55. // m_log.DebugFormat("[FETCH INVENTORY HANDLER]: Received FetchInventory capabilty request");
  56. OSDMap requestmap = (OSDMap)OSDParser.DeserializeLLSDXml(Utils.StringToBytes(request));
  57. OSDArray itemsRequested = (OSDArray)requestmap["items"];
  58. string reply;
  59. LLSDFetchInventory llsdReply = new LLSDFetchInventory();
  60. foreach (OSDMap osdItemId in itemsRequested)
  61. {
  62. UUID itemId = osdItemId["item_id"].AsUUID();
  63. InventoryItemBase item = m_inventoryService.GetItem(new InventoryItemBase(itemId));
  64. if (item != null)
  65. {
  66. // We don't know the agent that this request belongs to so we'll use the agent id of the item
  67. // which will be the same for all items.
  68. llsdReply.agent_id = item.Owner;
  69. llsdReply.items.Array.Add(ConvertInventoryItem(item));
  70. }
  71. }
  72. reply = LLSDHelpers.SerialiseLLSDReply(llsdReply);
  73. return reply;
  74. }
  75. /// <summary>
  76. /// Convert an internal inventory item object into an LLSD object.
  77. /// </summary>
  78. /// <param name="invItem"></param>
  79. /// <returns></returns>
  80. private LLSDInventoryItem ConvertInventoryItem(InventoryItemBase invItem)
  81. {
  82. LLSDInventoryItem llsdItem = new LLSDInventoryItem();
  83. llsdItem.asset_id = invItem.AssetID;
  84. llsdItem.created_at = invItem.CreationDate;
  85. llsdItem.desc = invItem.Description;
  86. llsdItem.flags = (int)invItem.Flags;
  87. llsdItem.item_id = invItem.ID;
  88. llsdItem.name = invItem.Name;
  89. llsdItem.parent_id = invItem.Folder;
  90. try
  91. {
  92. llsdItem.type = Utils.AssetTypeToString((AssetType)invItem.AssetType);
  93. llsdItem.inv_type = Utils.InventoryTypeToString((InventoryType)invItem.InvType);
  94. }
  95. catch (Exception e)
  96. {
  97. m_log.ErrorFormat(
  98. "[WEB FETCH INV DESC HANDLER]: Problem setting asset {0} inventory {1} types while converting inventory item {2}: {3}",
  99. invItem.AssetType, invItem.InvType, invItem.Name, e.Message);
  100. }
  101. llsdItem.permissions = new LLSDPermissions();
  102. llsdItem.permissions.creator_id = invItem.CreatorIdAsUuid;
  103. llsdItem.permissions.base_mask = (int)invItem.CurrentPermissions;
  104. llsdItem.permissions.everyone_mask = (int)invItem.EveryOnePermissions;
  105. llsdItem.permissions.group_id = invItem.GroupID;
  106. llsdItem.permissions.group_mask = (int)invItem.GroupPermissions;
  107. llsdItem.permissions.is_owner_group = invItem.GroupOwned;
  108. llsdItem.permissions.next_owner_mask = (int)invItem.NextPermissions;
  109. llsdItem.permissions.owner_id = invItem.Owner;
  110. llsdItem.permissions.owner_mask = (int)invItem.CurrentPermissions;
  111. llsdItem.sale_info = new LLSDSaleInfo();
  112. llsdItem.sale_info.sale_price = invItem.SalePrice;
  113. switch (invItem.SaleType)
  114. {
  115. default:
  116. llsdItem.sale_info.sale_type = "not";
  117. break;
  118. case 1:
  119. llsdItem.sale_info.sale_type = "original";
  120. break;
  121. case 2:
  122. llsdItem.sale_info.sale_type = "copy";
  123. break;
  124. case 3:
  125. llsdItem.sale_info.sale_type = "contents";
  126. break;
  127. }
  128. return llsdItem;
  129. }
  130. }
  131. }