OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
FetchInventory2Handler.cs
Go to the documentation of this file.
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;
37 
38 using log4net;
39 
40 namespace OpenSim.Capabilities.Handlers
41 {
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 
68  foreach (OSDMap osdItemId in itemsRequested)
69  {
70  itemIDs[i++] = osdItemId["item_id"].AsUUID();
71  }
72 
73  InventoryItemBase[] items = null;
74 
75  if (m_agentID != UUID.Zero)
76  {
77  items = m_inventoryService.GetMultipleItems(m_agentID, itemIDs);
78 
79  if (items == null)
80  {
81  // OMG!!! One by one!!! This is fallback code, in case the backend isn't updated
82  m_log.WarnFormat("[FETCH INVENTORY HANDLER]: GetMultipleItems failed. Falling back to fetching inventory items one by one.");
83  items = new InventoryItemBase[itemsRequested.Count];
85  item.Owner = m_agentID;
86  foreach (UUID id in itemIDs)
87  {
88  item.ID = id;
89  items[i++] = m_inventoryService.GetItem(item);
90  }
91  }
92  }
93  else
94  {
95  items = new InventoryItemBase[itemsRequested.Count];
97  foreach (UUID id in itemIDs)
98  {
99  item.ID = id;
100  items[i++] = m_inventoryService.GetItem(item);
101  }
102  }
103 
104  foreach (InventoryItemBase item in items)
105  {
106  if (item != null)
107  {
108  // We don't know the agent that this request belongs to so we'll use the agent id of the item
109  // which will be the same for all items.
110  llsdReply.agent_id = item.Owner;
111  llsdReply.items.Array.Add(ConvertInventoryItem(item));
112  }
113  }
114 
115  reply = LLSDHelpers.SerialiseLLSDReply(llsdReply);
116 
117  return reply;
118  }
119 
125  private LLSDInventoryItem ConvertInventoryItem(InventoryItemBase invItem)
126  {
127  LLSDInventoryItem llsdItem = new LLSDInventoryItem();
128  llsdItem.asset_id = invItem.AssetID;
129  llsdItem.created_at = invItem.CreationDate;
130  llsdItem.desc = invItem.Description;
131  llsdItem.flags = ((int)invItem.Flags) & 0xff;
132  llsdItem.item_id = invItem.ID;
133  llsdItem.name = invItem.Name;
134  llsdItem.parent_id = invItem.Folder;
135  llsdItem.type = invItem.AssetType;
136  llsdItem.inv_type = invItem.InvType;
137 
138  llsdItem.permissions = new LLSDPermissions();
139  llsdItem.permissions.creator_id = invItem.CreatorIdAsUuid;
140  llsdItem.permissions.base_mask = (int)invItem.CurrentPermissions;
141  llsdItem.permissions.everyone_mask = (int)invItem.EveryOnePermissions;
142  llsdItem.permissions.group_id = invItem.GroupID;
143  llsdItem.permissions.group_mask = (int)invItem.GroupPermissions;
144  llsdItem.permissions.is_owner_group = invItem.GroupOwned;
145  llsdItem.permissions.next_owner_mask = (int)invItem.NextPermissions;
146  llsdItem.permissions.owner_id = invItem.Owner;
147  llsdItem.permissions.owner_mask = (int)invItem.CurrentPermissions;
148  llsdItem.sale_info = new LLSDSaleInfo();
149  llsdItem.sale_info.sale_price = invItem.SalePrice;
150  llsdItem.sale_info.sale_type = invItem.SaleType;
151 
152  return llsdItem;
153  }
154  }
155 }
FetchInventory2Handler(IInventoryService invService, UUID agentId)
OpenMetaverse.StructuredData.OSDArray OSDArray
OpenSim.Server.Handlers.Simulation.Utils Utils
OpenMetaverse.StructuredData.OSDMap OSDMap
string FetchInventoryRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
Inventory Item - contains all the properties associated with an individual inventory piece...