aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs')
-rw-r--r--OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs118
1 files changed, 118 insertions, 0 deletions
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs
new file mode 100644
index 0000000..b67b326
--- /dev/null
+++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs
@@ -0,0 +1,118 @@
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
28using OpenMetaverse;
29using OpenMetaverse.StructuredData;
30using OpenSim.Framework;
31using OpenSim.Framework.Capabilities;
32using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Services.Interfaces;
34using OSDArray = OpenMetaverse.StructuredData.OSDArray;
35using OSDMap = OpenMetaverse.StructuredData.OSDMap;
36
37namespace OpenSim.Capabilities.Handlers
38{
39 public class FetchInventory2Handler
40 {
41// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42
43 private IInventoryService m_inventoryService;
44 private UUID m_agentID;
45
46 public FetchInventory2Handler(IInventoryService invService, UUID agentId)
47 {
48 m_inventoryService = invService;
49 m_agentID = agentId;
50 }
51
52 public string FetchInventoryRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
53 {
54// m_log.DebugFormat("[FETCH INVENTORY HANDLER]: Received FetchInventory capabilty request");
55
56 OSDMap requestmap = (OSDMap)OSDParser.DeserializeLLSDXml(Utils.StringToBytes(request));
57 OSDArray itemsRequested = (OSDArray)requestmap["items"];
58
59 string reply;
60 LLSDFetchInventory llsdReply = new LLSDFetchInventory();
61
62 foreach (OSDMap osdItemId in itemsRequested)
63 {
64 UUID itemId = osdItemId["item_id"].AsUUID();
65
66 InventoryItemBase item = m_inventoryService.GetItem(new InventoryItemBase(itemId, m_agentID));
67
68 if (item != null)
69 {
70 // We don't know the agent that this request belongs to so we'll use the agent id of the item
71 // which will be the same for all items.
72 llsdReply.agent_id = item.Owner;
73
74 llsdReply.items.Array.Add(ConvertInventoryItem(item));
75 }
76 }
77
78 reply = LLSDHelpers.SerialiseLLSDReply(llsdReply);
79
80 return reply;
81 }
82
83 /// <summary>
84 /// Convert an internal inventory item object into an LLSD object.
85 /// </summary>
86 /// <param name="invItem"></param>
87 /// <returns></returns>
88 private LLSDInventoryItem ConvertInventoryItem(InventoryItemBase invItem)
89 {
90 LLSDInventoryItem llsdItem = new LLSDInventoryItem();
91 llsdItem.asset_id = invItem.AssetID;
92 llsdItem.created_at = invItem.CreationDate;
93 llsdItem.desc = invItem.Description;
94 llsdItem.flags = (int)invItem.Flags;
95 llsdItem.item_id = invItem.ID;
96 llsdItem.name = invItem.Name;
97 llsdItem.parent_id = invItem.Folder;
98 llsdItem.type = invItem.AssetType;
99 llsdItem.inv_type = invItem.InvType;
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 llsdItem.sale_info.sale_type = invItem.SaleType;
114
115 return llsdItem;
116 }
117 }
118} \ No newline at end of file