diff options
Diffstat (limited to 'OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs')
-rw-r--r-- | OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs | 141 |
1 files changed, 141 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..638e8bc --- /dev/null +++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs | |||
@@ -0,0 +1,141 @@ | |||
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 | |||
28 | using System.Reflection; | ||
29 | using OpenMetaverse; | ||
30 | using OpenMetaverse.StructuredData; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Framework.Capabilities; | ||
33 | using OpenSim.Framework.Servers.HttpServer; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using OSDArray = OpenMetaverse.StructuredData.OSDArray; | ||
36 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | ||
37 | |||
38 | using log4net; | ||
39 | |||
40 | namespace OpenSim.Capabilities.Handlers | ||
41 | { | ||
42 | public class FetchInventory2Handler | ||
43 | { | ||
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | private IInventoryService m_inventoryService; | ||
47 | private UUID m_agentID; | ||
48 | |||
49 | public FetchInventory2Handler(IInventoryService invService, UUID agentId) | ||
50 | { | ||
51 | m_inventoryService = invService; | ||
52 | m_agentID = agentId; | ||
53 | } | ||
54 | |||
55 | public string FetchInventoryRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
56 | { | ||
57 | //m_log.DebugFormat("[FETCH INVENTORY HANDLER]: Received FetchInventory capability request {0}", request); | ||
58 | |||
59 | OSDMap requestmap = (OSDMap)OSDParser.DeserializeLLSDXml(Utils.StringToBytes(request)); | ||
60 | OSDArray itemsRequested = (OSDArray)requestmap["items"]; | ||
61 | |||
62 | string reply; | ||
63 | LLSDFetchInventory llsdReply = new LLSDFetchInventory(); | ||
64 | |||
65 | UUID[] itemIDs = new UUID[itemsRequested.Count]; | ||
66 | int i = 0; | ||
67 | foreach (OSDMap osdItemId in itemsRequested) | ||
68 | { | ||
69 | itemIDs[i++] = osdItemId["item_id"].AsUUID(); | ||
70 | } | ||
71 | |||
72 | InventoryItemBase[] items = m_inventoryService.GetMultipleItems(m_agentID, itemIDs); | ||
73 | |||
74 | if (items == null) | ||
75 | { | ||
76 | // OMG!!! One by one!!! This is fallback code, in case the backend isn't updated | ||
77 | m_log.WarnFormat("[FETCH INVENTORY HANDLER]: GetMultipleItems failed. Falling back to fetching inventory items one by one."); | ||
78 | items = new InventoryItemBase[itemsRequested.Count]; | ||
79 | i = 0; | ||
80 | InventoryItemBase item = new InventoryItemBase(); | ||
81 | item.Owner = m_agentID; | ||
82 | foreach (UUID id in itemIDs) | ||
83 | { | ||
84 | item.ID = id; | ||
85 | items[i++] = m_inventoryService.GetItem(item); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | foreach (InventoryItemBase item in items) | ||
90 | { | ||
91 | if (item != null) | ||
92 | { | ||
93 | // We don't know the agent that this request belongs to so we'll use the agent id of the item | ||
94 | // which will be the same for all items. | ||
95 | llsdReply.agent_id = item.Owner; | ||
96 | |||
97 | llsdReply.items.Array.Add(ConvertInventoryItem(item)); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | reply = LLSDHelpers.SerialiseLLSDReply(llsdReply); | ||
102 | |||
103 | return reply; | ||
104 | } | ||
105 | |||
106 | /// <summary> | ||
107 | /// Convert an internal inventory item object into an LLSD object. | ||
108 | /// </summary> | ||
109 | /// <param name="invItem"></param> | ||
110 | /// <returns></returns> | ||
111 | private LLSDInventoryItem ConvertInventoryItem(InventoryItemBase invItem) | ||
112 | { | ||
113 | LLSDInventoryItem llsdItem = new LLSDInventoryItem(); | ||
114 | llsdItem.asset_id = invItem.AssetID; | ||
115 | llsdItem.created_at = invItem.CreationDate; | ||
116 | llsdItem.desc = invItem.Description; | ||
117 | llsdItem.flags = ((int)invItem.Flags) & 0xff; | ||
118 | llsdItem.item_id = invItem.ID; | ||
119 | llsdItem.name = invItem.Name; | ||
120 | llsdItem.parent_id = invItem.Folder; | ||
121 | llsdItem.type = invItem.AssetType; | ||
122 | llsdItem.inv_type = invItem.InvType; | ||
123 | |||
124 | llsdItem.permissions = new LLSDPermissions(); | ||
125 | llsdItem.permissions.creator_id = invItem.CreatorIdAsUuid; | ||
126 | llsdItem.permissions.base_mask = (int)invItem.CurrentPermissions; | ||
127 | llsdItem.permissions.everyone_mask = (int)invItem.EveryOnePermissions; | ||
128 | llsdItem.permissions.group_id = invItem.GroupID; | ||
129 | llsdItem.permissions.group_mask = (int)invItem.GroupPermissions; | ||
130 | llsdItem.permissions.is_owner_group = invItem.GroupOwned; | ||
131 | llsdItem.permissions.next_owner_mask = (int)invItem.NextPermissions; | ||
132 | llsdItem.permissions.owner_id = invItem.Owner; | ||
133 | llsdItem.permissions.owner_mask = (int)invItem.CurrentPermissions; | ||
134 | llsdItem.sale_info = new LLSDSaleInfo(); | ||
135 | llsdItem.sale_info.sale_price = invItem.SalePrice; | ||
136 | llsdItem.sale_info.sale_type = invItem.SaleType; | ||
137 | |||
138 | return llsdItem; | ||
139 | } | ||
140 | } | ||
141 | } \ No newline at end of file | ||