OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
XInventoryServicesConnector.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 log4net;
29 using System;
30 using System.Collections.Generic;
31 using System.IO;
32 using System.Reflection;
33 using Nini.Config;
34 using OpenSim.Framework;
35 using OpenSim.Framework.Console;
36 
37 using OpenSim.Framework.Monitoring;
38 using OpenSim.Services.Interfaces;
39 using OpenSim.Server.Base;
40 using OpenMetaverse;
41 
42 namespace OpenSim.Services.Connectors
43 {
45  {
46  private static readonly ILog m_log =
47  LogManager.GetLogger(
48  MethodBase.GetCurrentMethod().DeclaringType);
49 
53  public int RequestsMade { get; private set; }
54 
55  private string m_ServerURI = String.Empty;
56 
63  private int m_requestTimeoutSecs = -1;
64 
65  private const double CACHE_EXPIRATION_SECONDS = 20.0;
66  private static ExpiringCache<UUID, InventoryItemBase> m_ItemCache = new ExpiringCache<UUID,InventoryItemBase>();
67 
69  {
70  }
71 
72  public XInventoryServicesConnector(string serverURI)
73  {
74  m_ServerURI = serverURI.TrimEnd('/');
75  }
76 
77  public XInventoryServicesConnector(IConfigSource source)
78  : base(source, "InventoryService")
79  {
80  Initialise(source);
81  }
82 
83  public virtual void Initialise(IConfigSource source)
84  {
85  IConfig config = source.Configs["InventoryService"];
86  if (config == null)
87  {
88  m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini");
89  throw new Exception("Inventory connector init error");
90  }
91 
92  string serviceURI = config.GetString("InventoryServerURI",
93  String.Empty);
94 
95  if (serviceURI == String.Empty)
96  {
97  m_log.Error("[INVENTORY CONNECTOR]: No Server URI named in section InventoryService");
98  throw new Exception("Inventory connector init error");
99  }
100  m_ServerURI = serviceURI;
101 
102  m_requestTimeoutSecs = config.GetInt("RemoteRequestTimeout", m_requestTimeoutSecs);
103 
104  StatsManager.RegisterStat(
105  new Stat(
106  "RequestsMade",
107  "Requests made",
108  "Number of requests made to the remove inventory service",
109  "requests",
110  "inventory",
111  serviceURI,
112  StatType.Pull,
113  MeasuresOfInterest.AverageChangeOverTime,
114  s => s.Value = RequestsMade,
115  StatVerbosity.Debug));
116  }
117 
118  private bool CheckReturn(Dictionary<string, object> ret)
119  {
120  if (ret == null)
121  return false;
122 
123  if (ret.Count == 0)
124  return false;
125 
126  if (ret.ContainsKey("RESULT"))
127  {
128  if (ret["RESULT"] is string)
129  {
130  bool result;
131 
132  if (bool.TryParse((string)ret["RESULT"], out result))
133  return result;
134 
135  return false;
136  }
137  }
138 
139  return true;
140  }
141 
142  public bool CreateUserInventory(UUID principalID)
143  {
144  Dictionary<string,object> ret = MakeRequest("CREATEUSERINVENTORY",
145  new Dictionary<string,object> {
146  { "PRINCIPAL", principalID.ToString() }
147  });
148 
149  return CheckReturn(ret);
150  }
151 
152  public List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
153  {
154  Dictionary<string,object> ret = MakeRequest("GETINVENTORYSKELETON",
155  new Dictionary<string,object> {
156  { "PRINCIPAL", principalID.ToString() }
157  });
158 
159  if (!CheckReturn(ret))
160  return null;
161 
162  Dictionary<string, object> folders = (Dictionary<string, object>)ret["FOLDERS"];
163 
164  List<InventoryFolderBase> fldrs = new List<InventoryFolderBase>();
165 
166  try
167  {
168  foreach (Object o in folders.Values)
169  fldrs.Add(BuildFolder((Dictionary<string, object>)o));
170  }
171  catch (Exception e)
172  {
173  m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception unwrapping folder list: ", e);
174  }
175 
176  return fldrs;
177  }
178 
179  public InventoryFolderBase GetRootFolder(UUID principalID)
180  {
181  Dictionary<string,object> ret = MakeRequest("GETROOTFOLDER",
182  new Dictionary<string,object> {
183  { "PRINCIPAL", principalID.ToString() }
184  });
185 
186  if (!CheckReturn(ret))
187  return null;
188 
189  return BuildFolder((Dictionary<string, object>)ret["folder"]);
190  }
191 
192  public InventoryFolderBase GetFolderForType(UUID principalID, FolderType type)
193  {
194  Dictionary<string,object> ret = MakeRequest("GETFOLDERFORTYPE",
195  new Dictionary<string,object> {
196  { "PRINCIPAL", principalID.ToString() },
197  { "TYPE", ((int)type).ToString() }
198  });
199 
200  if (!CheckReturn(ret))
201  return null;
202 
203  return BuildFolder((Dictionary<string, object>)ret["folder"]);
204  }
205 
206  public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
207  {
208  InventoryCollection inventory = new InventoryCollection();
209  inventory.Folders = new List<InventoryFolderBase>();
210  inventory.Items = new List<InventoryItemBase>();
211  inventory.OwnerID = principalID;
212 
213  try
214  {
215  Dictionary<string,object> ret = MakeRequest("GETFOLDERCONTENT",
216  new Dictionary<string,object> {
217  { "PRINCIPAL", principalID.ToString() },
218  { "FOLDER", folderID.ToString() }
219  });
220 
221  if (!CheckReturn(ret))
222  return null;
223 
224  Dictionary<string,object> folders = ret.ContainsKey("FOLDERS") ?
225  (Dictionary<string,object>)ret["FOLDERS"] : null;
226  Dictionary<string,object> items = ret.ContainsKey("ITEMS") ?
227  (Dictionary<string, object>)ret["ITEMS"] : null;
228 
229  if (folders != null)
230  foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
231  inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o));
232  if (items != null)
233  foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
234  inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
235  }
236  catch (Exception e)
237  {
238  m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetFolderContent: {0}", e.Message);
239  }
240 
241  return inventory;
242  }
243 
244  public virtual InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderIDs)
245  {
246  InventoryCollection[] inventoryArr = new InventoryCollection[folderIDs.Length];
247  // m_log.DebugFormat("[XXX]: In GetMultipleFoldersContent {0}", String.Join(",", folderIDs));
248  try
249  {
250  Dictionary<string, object> resultSet = MakeRequest("GETMULTIPLEFOLDERSCONTENT",
251  new Dictionary<string, object> {
252  { "PRINCIPAL", principalID.ToString() },
253  { "FOLDERS", String.Join(",", folderIDs) },
254  { "COUNT", folderIDs.Length.ToString() }
255  });
256 
257  if (!CheckReturn(resultSet))
258  return null;
259 
260  int i = 0;
261  foreach (KeyValuePair<string, object> kvp in resultSet)
262  {
263  InventoryCollection inventory = new InventoryCollection();
264  if (kvp.Key.StartsWith("F_"))
265  {
266  UUID fid = UUID.Zero;
267  if (UUID.TryParse(kvp.Key.Substring(2), out fid) && fid == folderIDs[i])
268  {
269  inventory.Folders = new List<InventoryFolderBase>();
270  inventory.Items = new List<InventoryItemBase>();
271 
272  Dictionary<string, object> ret = (Dictionary<string, object>)kvp.Value;
273 
274  if (ret.ContainsKey("FID"))
275  {
276  if (!UUID.TryParse(ret["FID"].ToString(), out inventory.FolderID))
277  m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Could not parse folder id {0}", ret["FID"].ToString());
278  }
279  else
280  m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: FID key not present in response");
281 
282  inventory.Version = -1;
283  if (ret.ContainsKey("VERSION"))
284  Int32.TryParse(ret["VERSION"].ToString(), out inventory.Version);
285  if (ret.ContainsKey("OWNER"))
286  UUID.TryParse(ret["OWNER"].ToString(), out inventory.OwnerID);
287 
288  //m_log.DebugFormat("[XXX]: Received {0} ({1}) {2} {3}", inventory.FolderID, fid, inventory.Version, inventory.OwnerID);
289 
290  Dictionary<string, object> folders =
291  (Dictionary<string, object>)ret["FOLDERS"];
292  Dictionary<string, object> items =
293  (Dictionary<string, object>)ret["ITEMS"];
294 
295  foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
296  {
297  inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o));
298  }
299  foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
300  {
301  inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
302  }
303 
304  inventoryArr[i] = inventory;
305  }
306  else
307  {
308  m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Folder id does not match. Expected {0} got {1}",
309  folderIDs[i], fid);
310  m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: {0} {1}", String.Join(",", folderIDs), String.Join(",", resultSet.Keys));
311  }
312 
313  i += 1;
314  }
315  }
316  }
317  catch (Exception e)
318  {
319  m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetMultipleFoldersContent: {0}", e.Message);
320  }
321 
322  return inventoryArr;
323  }
324 
325  public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
326  {
327  Dictionary<string,object> ret = MakeRequest("GETFOLDERITEMS",
328  new Dictionary<string,object> {
329  { "PRINCIPAL", principalID.ToString() },
330  { "FOLDER", folderID.ToString() }
331  });
332 
333  if (!CheckReturn(ret))
334  return null;
335 
336  Dictionary<string, object> items = (Dictionary<string, object>)ret["ITEMS"];
337  List<InventoryItemBase> fitems = new List<InventoryItemBase>();
338  foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
339  fitems.Add(BuildItem((Dictionary<string, object>)o));
340 
341  return fitems;
342  }
343 
344  public bool AddFolder(InventoryFolderBase folder)
345  {
346  Dictionary<string,object> ret = MakeRequest("ADDFOLDER",
347  new Dictionary<string,object> {
348  { "ParentID", folder.ParentID.ToString() },
349  { "Type", folder.Type.ToString() },
350  { "Version", folder.Version.ToString() },
351  { "Name", folder.Name.ToString() },
352  { "Owner", folder.Owner.ToString() },
353  { "ID", folder.ID.ToString() }
354  });
355 
356  return CheckReturn(ret);
357  }
358 
359  public bool UpdateFolder(InventoryFolderBase folder)
360  {
361  Dictionary<string,object> ret = MakeRequest("UPDATEFOLDER",
362  new Dictionary<string,object> {
363  { "ParentID", folder.ParentID.ToString() },
364  { "Type", folder.Type.ToString() },
365  { "Version", folder.Version.ToString() },
366  { "Name", folder.Name.ToString() },
367  { "Owner", folder.Owner.ToString() },
368  { "ID", folder.ID.ToString() }
369  });
370 
371  return CheckReturn(ret);
372  }
373 
374  public bool MoveFolder(InventoryFolderBase folder)
375  {
376  Dictionary<string,object> ret = MakeRequest("MOVEFOLDER",
377  new Dictionary<string,object> {
378  { "ParentID", folder.ParentID.ToString() },
379  { "ID", folder.ID.ToString() },
380  { "PRINCIPAL", folder.Owner.ToString() }
381  });
382 
383  return CheckReturn(ret);
384  }
385 
386  public bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
387  {
388  List<string> slist = new List<string>();
389 
390  foreach (UUID f in folderIDs)
391  slist.Add(f.ToString());
392 
393  Dictionary<string,object> ret = MakeRequest("DELETEFOLDERS",
394  new Dictionary<string,object> {
395  { "PRINCIPAL", principalID.ToString() },
396  { "FOLDERS", slist }
397  });
398 
399  return CheckReturn(ret);
400  }
401 
402  public bool PurgeFolder(InventoryFolderBase folder)
403  {
404  Dictionary<string,object> ret = MakeRequest("PURGEFOLDER",
405  new Dictionary<string,object> {
406  { "ID", folder.ID.ToString() }
407  });
408 
409  return CheckReturn(ret);
410  }
411 
412  public bool AddItem(InventoryItemBase item)
413  {
414  if (item.Description == null)
415  item.Description = String.Empty;
416  if (item.CreatorData == null)
417  item.CreatorData = String.Empty;
418  if (item.CreatorId == null)
419  item.CreatorId = String.Empty;
420  Dictionary<string, object> ret = MakeRequest("ADDITEM",
421  new Dictionary<string,object> {
422  { "AssetID", item.AssetID.ToString() },
423  { "AssetType", item.AssetType.ToString() },
424  { "Name", item.Name.ToString() },
425  { "Owner", item.Owner.ToString() },
426  { "ID", item.ID.ToString() },
427  { "InvType", item.InvType.ToString() },
428  { "Folder", item.Folder.ToString() },
429  { "CreatorId", item.CreatorId.ToString() },
430  { "CreatorData", item.CreatorData.ToString() },
431  { "Description", item.Description.ToString() },
432  { "NextPermissions", item.NextPermissions.ToString() },
433  { "CurrentPermissions", item.CurrentPermissions.ToString() },
434  { "BasePermissions", item.BasePermissions.ToString() },
435  { "EveryOnePermissions", item.EveryOnePermissions.ToString() },
436  { "GroupPermissions", item.GroupPermissions.ToString() },
437  { "GroupID", item.GroupID.ToString() },
438  { "GroupOwned", item.GroupOwned.ToString() },
439  { "SalePrice", item.SalePrice.ToString() },
440  { "SaleType", item.SaleType.ToString() },
441  { "Flags", item.Flags.ToString() },
442  { "CreationDate", item.CreationDate.ToString() }
443  });
444 
445  return CheckReturn(ret);
446  }
447 
448  public bool UpdateItem(InventoryItemBase item)
449  {
450  if (item.CreatorData == null)
451  item.CreatorData = String.Empty;
452  Dictionary<string,object> ret = MakeRequest("UPDATEITEM",
453  new Dictionary<string,object> {
454  { "AssetID", item.AssetID.ToString() },
455  { "AssetType", item.AssetType.ToString() },
456  { "Name", item.Name.ToString() },
457  { "Owner", item.Owner.ToString() },
458  { "ID", item.ID.ToString() },
459  { "InvType", item.InvType.ToString() },
460  { "Folder", item.Folder.ToString() },
461  { "CreatorId", item.CreatorId.ToString() },
462  { "CreatorData", item.CreatorData.ToString() },
463  { "Description", item.Description.ToString() },
464  { "NextPermissions", item.NextPermissions.ToString() },
465  { "CurrentPermissions", item.CurrentPermissions.ToString() },
466  { "BasePermissions", item.BasePermissions.ToString() },
467  { "EveryOnePermissions", item.EveryOnePermissions.ToString() },
468  { "GroupPermissions", item.GroupPermissions.ToString() },
469  { "GroupID", item.GroupID.ToString() },
470  { "GroupOwned", item.GroupOwned.ToString() },
471  { "SalePrice", item.SalePrice.ToString() },
472  { "SaleType", item.SaleType.ToString() },
473  { "Flags", item.Flags.ToString() },
474  { "CreationDate", item.CreationDate.ToString() }
475  });
476 
477  bool result = CheckReturn(ret);
478  if (result)
479  {
480  m_ItemCache.AddOrUpdate(item.ID, item, CACHE_EXPIRATION_SECONDS);
481  }
482 
483  return result;
484  }
485 
486  public bool MoveItems(UUID principalID, List<InventoryItemBase> items)
487  {
488  List<string> idlist = new List<string>();
489  List<string> destlist = new List<string>();
490 
491  foreach (InventoryItemBase item in items)
492  {
493  idlist.Add(item.ID.ToString());
494  destlist.Add(item.Folder.ToString());
495  }
496 
497  Dictionary<string,object> ret = MakeRequest("MOVEITEMS",
498  new Dictionary<string,object> {
499  { "PRINCIPAL", principalID.ToString() },
500  { "IDLIST", idlist },
501  { "DESTLIST", destlist }
502  });
503 
504  return CheckReturn(ret);
505  }
506 
507  public bool DeleteItems(UUID principalID, List<UUID> itemIDs)
508  {
509  List<string> slist = new List<string>();
510 
511  foreach (UUID f in itemIDs)
512  slist.Add(f.ToString());
513 
514  Dictionary<string,object> ret = MakeRequest("DELETEITEMS",
515  new Dictionary<string,object> {
516  { "PRINCIPAL", principalID.ToString() },
517  { "ITEMS", slist }
518  });
519 
520  return CheckReturn(ret);
521  }
522 
524  {
525  InventoryItemBase retrieved = null;
526  if (m_ItemCache.TryGetValue(item.ID, out retrieved))
527  {
528  return retrieved;
529  }
530 
531  try
532  {
533  Dictionary<string, object> ret = MakeRequest("GETITEM",
534  new Dictionary<string, object> {
535  { "ID", item.ID.ToString() }
536  });
537 
538  if (!CheckReturn(ret))
539  return null;
540 
541  retrieved = BuildItem((Dictionary<string, object>)ret["item"]);
542  }
543  catch (Exception e)
544  {
545  m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetItem: ", e);
546  }
547 
548  m_ItemCache.AddOrUpdate(item.ID, retrieved, CACHE_EXPIRATION_SECONDS);
549 
550  return retrieved;
551  }
552 
553  public virtual InventoryItemBase[] GetMultipleItems(UUID principalID, UUID[] itemIDs)
554  {
555  //m_log.DebugFormat("[XXX]: In GetMultipleItems {0}", String.Join(",", itemIDs));
556 
557  InventoryItemBase[] itemArr = new InventoryItemBase[itemIDs.Length];
558  // Try to get them from the cache
559  List<UUID> pending = new List<UUID>();
560  InventoryItemBase item = null;
561  int i = 0;
562 
563  foreach (UUID id in itemIDs)
564  {
565  if (m_ItemCache.TryGetValue(id, out item))
566  itemArr[i++] = item;
567  else
568  pending.Add(id);
569  }
570 
571  if (pending.Count == 0) // we're done, everything was in the cache
572  return itemArr;
573 
574  try
575  {
576  Dictionary<string, object> resultSet = MakeRequest("GETMULTIPLEITEMS",
577  new Dictionary<string, object> {
578  { "PRINCIPAL", principalID.ToString() },
579  { "ITEMS", String.Join(",", pending.ToArray()) },
580  { "COUNT", pending.Count.ToString() }
581  });
582 
583  if (!CheckReturn(resultSet))
584  {
585  if (i == 0)
586  return null;
587  else
588  return itemArr;
589  }
590 
591  // carry over index i where we left above
592  foreach (KeyValuePair<string, object> kvp in resultSet)
593  {
594  InventoryCollection inventory = new InventoryCollection();
595  if (kvp.Key.StartsWith("item_"))
596  {
597  if (kvp.Value is Dictionary<string, object>)
598  {
599  item = BuildItem((Dictionary<string, object>)kvp.Value);
600  m_ItemCache.AddOrUpdate(item.ID, item, CACHE_EXPIRATION_SECONDS);
601  itemArr[i++] = item;
602  }
603  else
604  itemArr[i++] = null;
605  }
606  }
607  }
608  catch (Exception e)
609  {
610  m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetMultipleItems: {0}", e.Message);
611  }
612 
613  return itemArr;
614  }
615 
617  {
618  try
619  {
620  Dictionary<string, object> ret = MakeRequest("GETFOLDER",
621  new Dictionary<string, object> {
622  { "ID", folder.ID.ToString() }
623  });
624 
625  if (!CheckReturn(ret))
626  return null;
627 
628  return BuildFolder((Dictionary<string, object>)ret["folder"]);
629  }
630  catch (Exception e)
631  {
632  m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetFolder: ", e);
633  }
634 
635  return null;
636  }
637 
638  public List<InventoryItemBase> GetActiveGestures(UUID principalID)
639  {
640  Dictionary<string,object> ret = MakeRequest("GETACTIVEGESTURES",
641  new Dictionary<string,object> {
642  { "PRINCIPAL", principalID.ToString() }
643  });
644 
645  if (!CheckReturn(ret))
646  return null;
647 
648  List<InventoryItemBase> items = new List<InventoryItemBase>();
649 
650  foreach (Object o in ((Dictionary<string,object>)ret["ITEMS"]).Values)
651  items.Add(BuildItem((Dictionary<string, object>)o));
652 
653  return items;
654  }
655 
656  public int GetAssetPermissions(UUID principalID, UUID assetID)
657  {
658  Dictionary<string,object> ret = MakeRequest("GETASSETPERMISSIONS",
659  new Dictionary<string,object> {
660  { "PRINCIPAL", principalID.ToString() },
661  { "ASSET", assetID.ToString() }
662  });
663 
664  // We cannot use CheckReturn() here because valid values for RESULT are "false" (in the case of request failure) or an int
665  if (ret == null)
666  return 0;
667 
668  if (ret.ContainsKey("RESULT"))
669  {
670  if (ret["RESULT"] is string)
671  {
672  int intResult;
673 
674  if (int.TryParse ((string)ret["RESULT"], out intResult))
675  return intResult;
676  }
677  }
678 
679  return 0;
680  }
681 
682  public bool HasInventoryForUser(UUID principalID)
683  {
684  return false;
685  }
686 
687  // Helpers
688  //
689  private Dictionary<string,object> MakeRequest(string method,
690  Dictionary<string,object> sendData)
691  {
692  // Add "METHOD" as the first key in the dictionary. This ensures that it will be
693  // visible even when using partial logging ("debug http all 5").
694  Dictionary<string, object> temp = sendData;
695  sendData = new Dictionary<string,object>{ { "METHOD", method } };
696  foreach (KeyValuePair<string, object> kvp in temp)
697  sendData.Add(kvp.Key, kvp.Value);
698 
699  RequestsMade++;
700 
701  string reply
702  = SynchronousRestFormsRequester.MakeRequest(
703  "POST", m_ServerURI + "/xinventory",
704  ServerUtils.BuildQueryString(sendData), m_requestTimeoutSecs, m_Auth);
705 
706  Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
707  reply);
708 
709  return replyData;
710  }
711 
712  private InventoryFolderBase BuildFolder(Dictionary<string,object> data)
713  {
715 
716  try
717  {
718  folder.ParentID = new UUID(data["ParentID"].ToString());
719  folder.Type = short.Parse(data["Type"].ToString());
720  folder.Version = ushort.Parse(data["Version"].ToString());
721  folder.Name = data["Name"].ToString();
722  folder.Owner = new UUID(data["Owner"].ToString());
723  folder.ID = new UUID(data["ID"].ToString());
724  }
725  catch (Exception e)
726  {
727  m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception building folder: ", e);
728  }
729 
730  return folder;
731  }
732 
733  private InventoryItemBase BuildItem(Dictionary<string,object> data)
734  {
736 
737  try
738  {
739  item.AssetID = new UUID(data["AssetID"].ToString());
740  item.AssetType = int.Parse(data["AssetType"].ToString());
741  item.Name = data["Name"].ToString();
742  item.Owner = new UUID(data["Owner"].ToString());
743  item.ID = new UUID(data["ID"].ToString());
744  item.InvType = int.Parse(data["InvType"].ToString());
745  item.Folder = new UUID(data["Folder"].ToString());
746  item.CreatorId = data["CreatorId"].ToString();
747  if (data.ContainsKey("CreatorData"))
748  item.CreatorData = data["CreatorData"].ToString();
749  else
750  item.CreatorData = String.Empty;
751  item.Description = data["Description"].ToString();
752  item.NextPermissions = uint.Parse(data["NextPermissions"].ToString());
753  item.CurrentPermissions = uint.Parse(data["CurrentPermissions"].ToString());
754  item.BasePermissions = uint.Parse(data["BasePermissions"].ToString());
755  item.EveryOnePermissions = uint.Parse(data["EveryOnePermissions"].ToString());
756  item.GroupPermissions = uint.Parse(data["GroupPermissions"].ToString());
757  item.GroupID = new UUID(data["GroupID"].ToString());
758  item.GroupOwned = bool.Parse(data["GroupOwned"].ToString());
759  item.SalePrice = int.Parse(data["SalePrice"].ToString());
760  item.SaleType = byte.Parse(data["SaleType"].ToString());
761  item.Flags = uint.Parse(data["Flags"].ToString());
762  item.CreationDate = int.Parse(data["CreationDate"].ToString());
763  }
764  catch (Exception e)
765  {
766  m_log.Error("[XINVENTORY CONNECTOR]: Exception building item: ", e);
767  }
768 
769  return item;
770  }
771  }
772 }
InventoryItemBase GetItem(InventoryItemBase item)
Get an item, given by its UUID
InventoryFolderBase GetRootFolder(UUID principalID)
Retrieve the root inventory folder for the given user.
bool DeleteItems(UUID principalID, List< UUID > itemIDs)
Delete an item from the user's inventory
virtual InventoryItemBase[] GetMultipleItems(UUID principalID, UUID[] itemIDs)
Get multiple items, given by their UUIDs
Holds individual statistic details
Definition: Stat.cs:41
bool UpdateFolder(InventoryFolderBase folder)
Update a folder in the user's inventory
bool AddFolder(InventoryFolderBase folder)
Add a new folder to the user's inventory
List< InventoryItemBase > GetFolderItems(UUID principalID, UUID folderID)
Gets the items inside a folder
bool MoveFolder(InventoryFolderBase folder)
Move an inventory folder to a new location
bool AddItem(InventoryItemBase item)
Add a new item to the user's inventory
virtual InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderIDs)
Gets everything (folders and items) inside a folder
bool CreateUserInventory(UUID principalID)
Create the entire inventory for a given user
bool PurgeFolder(InventoryFolderBase folder)
Purge an inventory folder of all its items and subfolders.
bool UpdateItem(InventoryItemBase item)
Update an item in the user's inventory
Inventory Item - contains all the properties associated with an individual inventory piece...
bool DeleteFolders(UUID principalID, List< UUID > folderIDs)
Delete an item from the user's inventory
InventoryFolderBase GetFolder(InventoryFolderBase folder)
Get a folder, given by its UUID
StatVerbosity
Verbosity of stat.
bool HasInventoryForUser(UUID principalID)
Does the given user have an inventory structure?
List< InventoryItemBase > GetActiveGestures(UUID principalID)
Get the active gestures of the agent.
string CreatorData
Extended creator information of the form <profile url>="">;<name>
InventoryFolderBase GetFolderForType(UUID principalID, FolderType type)
Gets the user folder for the given folder-type
UUID ID
A UUID containing the ID for the inventory node itself
bool MoveItems(UUID principalID, List< InventoryItemBase > items)
MeasuresOfInterest
Measures of interest for this stat.
List< InventoryFolderBase > GetInventorySkeleton(UUID principalID)
Gets the skeleton of the inventory – folders only
int GetAssetPermissions(UUID principalID, UUID assetID)
Get the union of permissions of all inventory items that hold the given assetID.
InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
Gets everything (folders and items) inside a folder
Used to serialize a whole inventory for transfer over the network.