XInventoryService.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  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.Generic;
  29. using OpenMetaverse;
  30. using log4net;
  31. using Nini.Config;
  32. using System.Reflection;
  33. using OpenSim.Services.Base;
  34. using OpenSim.Services.Interfaces;
  35. using OpenSim.Data;
  36. using OpenSim.Framework;
  37. namespace OpenSim.Services.InventoryService
  38. {
  39. public class XInventoryService : ServiceBase, IInventoryService
  40. {
  41. //private static readonly ILog m_log =
  42. // LogManager.GetLogger(
  43. // MethodBase.GetCurrentMethod().DeclaringType);
  44. protected IXInventoryData m_Database;
  45. protected bool m_AllowDelete = true;
  46. public XInventoryService(IConfigSource config) : base(config)
  47. {
  48. string dllName = String.Empty;
  49. string connString = String.Empty;
  50. //string realm = "Inventory"; // OSG version doesn't use this
  51. //
  52. // Try reading the [InventoryService] section first, if it exists
  53. //
  54. IConfig authConfig = config.Configs["InventoryService"];
  55. if (authConfig != null)
  56. {
  57. dllName = authConfig.GetString("StorageProvider", dllName);
  58. connString = authConfig.GetString("ConnectionString", connString);
  59. m_AllowDelete = authConfig.GetBoolean("AllowDelete", true);
  60. // realm = authConfig.GetString("Realm", realm);
  61. }
  62. //
  63. // Try reading the [DatabaseService] section, if it exists
  64. //
  65. IConfig dbConfig = config.Configs["DatabaseService"];
  66. if (dbConfig != null)
  67. {
  68. if (dllName == String.Empty)
  69. dllName = dbConfig.GetString("StorageProvider", String.Empty);
  70. if (connString == String.Empty)
  71. connString = dbConfig.GetString("ConnectionString", String.Empty);
  72. }
  73. //
  74. // We tried, but this doesn't exist. We can't proceed.
  75. //
  76. if (dllName == String.Empty)
  77. throw new Exception("No StorageProvider configured");
  78. m_Database = LoadPlugin<IXInventoryData>(dllName,
  79. new Object[] {connString, String.Empty});
  80. if (m_Database == null)
  81. throw new Exception("Could not find a storage interface in the given module");
  82. }
  83. public virtual bool CreateUserInventory(UUID principalID)
  84. {
  85. // This is braindeaad. We can't ever communicate that we fixed
  86. // an existing inventory. Well, just return root folder status,
  87. // but check sanity anyway.
  88. //
  89. bool result = false;
  90. InventoryFolderBase rootFolder = GetRootFolder(principalID);
  91. if (rootFolder == null)
  92. {
  93. rootFolder = ConvertToOpenSim(CreateFolder(principalID, UUID.Zero, (int)AssetType.RootFolder, "My Inventory"));
  94. result = true;
  95. }
  96. XInventoryFolder[] sysFolders = GetSystemFolders(principalID);
  97. if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; }))
  98. CreateFolder(principalID, rootFolder.ID, (int)AssetType.Animation, "Animations");
  99. if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Bodypart) return true; return false; }))
  100. CreateFolder(principalID, rootFolder.ID, (int)AssetType.Bodypart, "Body Parts");
  101. if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.CallingCard) return true; return false; }))
  102. CreateFolder(principalID, rootFolder.ID, (int)AssetType.CallingCard, "Calling Cards");
  103. if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Clothing) return true; return false; }))
  104. CreateFolder(principalID, rootFolder.ID, (int)AssetType.Clothing, "Clothing");
  105. if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Gesture) return true; return false; }))
  106. CreateFolder(principalID, rootFolder.ID, (int)AssetType.Gesture, "Gestures");
  107. if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Landmark) return true; return false; }))
  108. CreateFolder(principalID, rootFolder.ID, (int)AssetType.Landmark, "Landmarks");
  109. if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.LostAndFoundFolder) return true; return false; }))
  110. CreateFolder(principalID, rootFolder.ID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
  111. if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Notecard) return true; return false; }))
  112. CreateFolder(principalID, rootFolder.ID, (int)AssetType.Notecard, "Notecards");
  113. if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Object) return true; return false; }))
  114. CreateFolder(principalID, rootFolder.ID, (int)AssetType.Object, "Objects");
  115. if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.SnapshotFolder) return true; return false; }))
  116. CreateFolder(principalID, rootFolder.ID, (int)AssetType.SnapshotFolder, "Photo Album");
  117. if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.LSLText) return true; return false; }))
  118. CreateFolder(principalID, rootFolder.ID, (int)AssetType.LSLText, "Scripts");
  119. if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Sound) return true; return false; }))
  120. CreateFolder(principalID, rootFolder.ID, (int)AssetType.Sound, "Sounds");
  121. if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Texture) return true; return false; }))
  122. CreateFolder(principalID, rootFolder.ID, (int)AssetType.Texture, "Textures");
  123. if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.TrashFolder) return true; return false; }))
  124. CreateFolder(principalID, rootFolder.ID, (int)AssetType.TrashFolder, "Trash");
  125. return result;
  126. }
  127. protected XInventoryFolder CreateFolder(UUID principalID, UUID parentID, int type, string name)
  128. {
  129. XInventoryFolder newFolder = new XInventoryFolder();
  130. newFolder.folderName = name;
  131. newFolder.type = type;
  132. newFolder.version = 1;
  133. newFolder.folderID = UUID.Random();
  134. newFolder.agentID = principalID;
  135. newFolder.parentFolderID = parentID;
  136. m_Database.StoreFolder(newFolder);
  137. return newFolder;
  138. }
  139. protected virtual XInventoryFolder[] GetSystemFolders(UUID principalID)
  140. {
  141. // m_log.DebugFormat("[XINVENTORY SERVICE]: Getting system folders for {0}", principalID);
  142. XInventoryFolder[] allFolders = m_Database.GetFolders(
  143. new string[] { "agentID" },
  144. new string[] { principalID.ToString() });
  145. XInventoryFolder[] sysFolders = Array.FindAll(
  146. allFolders,
  147. delegate (XInventoryFolder f)
  148. {
  149. if (f.type > 0)
  150. return true;
  151. return false;
  152. });
  153. // m_log.DebugFormat(
  154. // "[XINVENTORY SERVICE]: Found {0} system folders for {1}", sysFolders.Length, principalID);
  155. return sysFolders;
  156. }
  157. public virtual List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
  158. {
  159. XInventoryFolder[] allFolders = m_Database.GetFolders(
  160. new string[] { "agentID" },
  161. new string[] { principalID.ToString() });
  162. if (allFolders.Length == 0)
  163. return null;
  164. List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
  165. foreach (XInventoryFolder x in allFolders)
  166. {
  167. //m_log.DebugFormat("[XINVENTORY SERVICE]: Adding folder {0} to skeleton", x.folderName);
  168. folders.Add(ConvertToOpenSim(x));
  169. }
  170. return folders;
  171. }
  172. public virtual InventoryFolderBase GetRootFolder(UUID principalID)
  173. {
  174. XInventoryFolder[] folders = m_Database.GetFolders(
  175. new string[] { "agentID", "parentFolderID"},
  176. new string[] { principalID.ToString(), UUID.Zero.ToString() });
  177. if (folders.Length == 0)
  178. return null;
  179. XInventoryFolder root = null;
  180. foreach (XInventoryFolder folder in folders)
  181. if (folder.folderName == "My Inventory")
  182. root = folder;
  183. if (folders == null) // oops
  184. root = folders[0];
  185. return ConvertToOpenSim(root);
  186. }
  187. public virtual InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
  188. {
  189. // m_log.DebugFormat("[XINVENTORY SERVICE]: Getting folder type {0} for user {1}", type, principalID);
  190. XInventoryFolder[] folders = m_Database.GetFolders(
  191. new string[] { "agentID", "type"},
  192. new string[] { principalID.ToString(), ((int)type).ToString() });
  193. if (folders.Length == 0)
  194. {
  195. // m_log.WarnFormat("[XINVENTORY SERVICE]: Found no folder for type {0} for user {1}", type, principalID);
  196. return null;
  197. }
  198. // m_log.DebugFormat(
  199. // "[XINVENTORY SERVICE]: Found folder {0} {1} for type {2} for user {3}",
  200. // folders[0].folderName, folders[0].folderID, type, principalID);
  201. return ConvertToOpenSim(folders[0]);
  202. }
  203. public virtual InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
  204. {
  205. // This method doesn't receive a valud principal id from the
  206. // connector. So we disregard the principal and look
  207. // by ID.
  208. //
  209. //m_log.DebugFormat("[XINVENTORY SERVICE]: Fetch contents for folder {0}", folderID.ToString());
  210. InventoryCollection inventory = new InventoryCollection();
  211. inventory.UserID = principalID;
  212. inventory.Folders = new List<InventoryFolderBase>();
  213. inventory.Items = new List<InventoryItemBase>();
  214. XInventoryFolder[] folders = m_Database.GetFolders(
  215. new string[] { "parentFolderID"},
  216. new string[] { folderID.ToString() });
  217. foreach (XInventoryFolder x in folders)
  218. {
  219. //m_log.DebugFormat("[XINVENTORY]: Adding folder {0} to response", x.folderName);
  220. inventory.Folders.Add(ConvertToOpenSim(x));
  221. }
  222. XInventoryItem[] items = m_Database.GetItems(
  223. new string[] { "parentFolderID"},
  224. new string[] { folderID.ToString() });
  225. foreach (XInventoryItem i in items)
  226. {
  227. //m_log.DebugFormat("[XINVENTORY]: Adding item {0} to response", i.inventoryName);
  228. inventory.Items.Add(ConvertToOpenSim(i));
  229. }
  230. return inventory;
  231. }
  232. public virtual List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
  233. {
  234. // m_log.DebugFormat("[XINVENTORY]: Fetch items for folder {0}", folderID);
  235. // Since we probably don't get a valid principal here, either ...
  236. //
  237. List<InventoryItemBase> invItems = new List<InventoryItemBase>();
  238. XInventoryItem[] items = m_Database.GetItems(
  239. new string[] { "parentFolderID" },
  240. new string[] { folderID.ToString() });
  241. foreach (XInventoryItem i in items)
  242. invItems.Add(ConvertToOpenSim(i));
  243. return invItems;
  244. }
  245. public virtual bool AddFolder(InventoryFolderBase folder)
  246. {
  247. InventoryFolderBase check = GetFolder(folder);
  248. if (check != null)
  249. return false;
  250. XInventoryFolder xFolder = ConvertFromOpenSim(folder);
  251. return m_Database.StoreFolder(xFolder);
  252. }
  253. public virtual bool UpdateFolder(InventoryFolderBase folder)
  254. {
  255. XInventoryFolder xFolder = ConvertFromOpenSim(folder);
  256. InventoryFolderBase check = GetFolder(folder);
  257. if (check == null)
  258. return AddFolder(folder);
  259. if (check.Type != -1 || xFolder.type != -1)
  260. {
  261. if (xFolder.version > check.Version)
  262. return false;
  263. check.Version = (ushort)xFolder.version;
  264. xFolder = ConvertFromOpenSim(check);
  265. return m_Database.StoreFolder(xFolder);
  266. }
  267. if (xFolder.version < check.Version)
  268. xFolder.version = check.Version;
  269. xFolder.folderID = check.ID;
  270. return m_Database.StoreFolder(xFolder);
  271. }
  272. public virtual bool MoveFolder(InventoryFolderBase folder)
  273. {
  274. XInventoryFolder[] x = m_Database.GetFolders(
  275. new string[] { "folderID" },
  276. new string[] { folder.ID.ToString() });
  277. if (x.Length == 0)
  278. return false;
  279. x[0].parentFolderID = folder.ParentID;
  280. return m_Database.StoreFolder(x[0]);
  281. }
  282. // We don't check the principal's ID here
  283. //
  284. public virtual bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
  285. {
  286. if (!m_AllowDelete)
  287. return false;
  288. // Ignore principal ID, it's bogus at connector level
  289. //
  290. foreach (UUID id in folderIDs)
  291. {
  292. if (!ParentIsTrash(id))
  293. continue;
  294. InventoryFolderBase f = new InventoryFolderBase();
  295. f.ID = id;
  296. PurgeFolder(f);
  297. m_Database.DeleteFolders("folderID", id.ToString());
  298. }
  299. return true;
  300. }
  301. public virtual bool PurgeFolder(InventoryFolderBase folder)
  302. {
  303. if (!m_AllowDelete)
  304. return false;
  305. if (!ParentIsTrash(folder.ID))
  306. return false;
  307. XInventoryFolder[] subFolders = m_Database.GetFolders(
  308. new string[] { "parentFolderID" },
  309. new string[] { folder.ID.ToString() });
  310. foreach (XInventoryFolder x in subFolders)
  311. {
  312. PurgeFolder(ConvertToOpenSim(x));
  313. m_Database.DeleteFolders("folderID", x.folderID.ToString());
  314. }
  315. m_Database.DeleteItems("parentFolderID", folder.ID.ToString());
  316. return true;
  317. }
  318. public virtual bool AddItem(InventoryItemBase item)
  319. {
  320. //m_log.DebugFormat(
  321. // "[XINVENTORY SERVICE]: Adding item {0} to folder {1} for {2}", item.ID, item.Folder, item.Owner);
  322. return m_Database.StoreItem(ConvertFromOpenSim(item));
  323. }
  324. public virtual bool UpdateItem(InventoryItemBase item)
  325. {
  326. if (!m_AllowDelete)
  327. if (item.AssetType == (sbyte)AssetType.Link || item.AssetType == (sbyte)AssetType.LinkFolder)
  328. return false;
  329. return m_Database.StoreItem(ConvertFromOpenSim(item));
  330. }
  331. public virtual bool MoveItems(UUID principalID, List<InventoryItemBase> items)
  332. {
  333. // Principal is b0rked. *sigh*
  334. //
  335. foreach (InventoryItemBase i in items)
  336. {
  337. m_Database.MoveItem(i.ID.ToString(), i.Folder.ToString());
  338. }
  339. return true;
  340. }
  341. public virtual bool DeleteItems(UUID principalID, List<UUID> itemIDs)
  342. {
  343. if (!m_AllowDelete)
  344. {
  345. // We must still allow links and links to folders to be deleted, otherwise they will build up
  346. // in the player's inventory until they can no longer log in. Deletions of links due to code bugs or
  347. // similar is inconvenient but on a par with accidental movement of items. The original item is never
  348. // touched.
  349. foreach (UUID id in itemIDs)
  350. {
  351. if (!m_Database.DeleteItems(
  352. new string[] { "inventoryID", "assetType" },
  353. new string[] { id.ToString(), ((sbyte)AssetType.Link).ToString() }))
  354. {
  355. m_Database.DeleteItems(
  356. new string[] { "inventoryID", "assetType" },
  357. new string[] { id.ToString(), ((sbyte)AssetType.LinkFolder).ToString() });
  358. }
  359. }
  360. }
  361. else
  362. {
  363. // Just use the ID... *facepalms*
  364. //
  365. foreach (UUID id in itemIDs)
  366. m_Database.DeleteItems("inventoryID", id.ToString());
  367. }
  368. return true;
  369. }
  370. public virtual InventoryItemBase GetItem(InventoryItemBase item)
  371. {
  372. XInventoryItem[] items = m_Database.GetItems(
  373. new string[] { "inventoryID" },
  374. new string[] { item.ID.ToString() });
  375. if (items.Length == 0)
  376. return null;
  377. return ConvertToOpenSim(items[0]);
  378. }
  379. public virtual InventoryFolderBase GetFolder(InventoryFolderBase folder)
  380. {
  381. XInventoryFolder[] folders = m_Database.GetFolders(
  382. new string[] { "folderID"},
  383. new string[] { folder.ID.ToString() });
  384. if (folders.Length == 0)
  385. return null;
  386. return ConvertToOpenSim(folders[0]);
  387. }
  388. public virtual List<InventoryItemBase> GetActiveGestures(UUID principalID)
  389. {
  390. XInventoryItem[] items = m_Database.GetActiveGestures(principalID);
  391. if (items.Length == 0)
  392. return new List<InventoryItemBase>();
  393. List<InventoryItemBase> ret = new List<InventoryItemBase>();
  394. foreach (XInventoryItem x in items)
  395. ret.Add(ConvertToOpenSim(x));
  396. return ret;
  397. }
  398. public virtual int GetAssetPermissions(UUID principalID, UUID assetID)
  399. {
  400. return m_Database.GetAssetPermissions(principalID, assetID);
  401. }
  402. // CM never needed those. Left unimplemented.
  403. // Obsolete in core
  404. //
  405. public InventoryCollection GetUserInventory(UUID userID)
  406. {
  407. return null;
  408. }
  409. public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
  410. {
  411. }
  412. // Unused.
  413. //
  414. public bool HasInventoryForUser(UUID userID)
  415. {
  416. return false;
  417. }
  418. // CM Helpers
  419. //
  420. protected InventoryFolderBase ConvertToOpenSim(XInventoryFolder folder)
  421. {
  422. InventoryFolderBase newFolder = new InventoryFolderBase();
  423. newFolder.ParentID = folder.parentFolderID;
  424. newFolder.Type = (short)folder.type;
  425. newFolder.Version = (ushort)folder.version;
  426. newFolder.Name = folder.folderName;
  427. newFolder.Owner = folder.agentID;
  428. newFolder.ID = folder.folderID;
  429. return newFolder;
  430. }
  431. protected XInventoryFolder ConvertFromOpenSim(InventoryFolderBase folder)
  432. {
  433. XInventoryFolder newFolder = new XInventoryFolder();
  434. newFolder.parentFolderID = folder.ParentID;
  435. newFolder.type = (int)folder.Type;
  436. newFolder.version = (int)folder.Version;
  437. newFolder.folderName = folder.Name;
  438. newFolder.agentID = folder.Owner;
  439. newFolder.folderID = folder.ID;
  440. return newFolder;
  441. }
  442. protected InventoryItemBase ConvertToOpenSim(XInventoryItem item)
  443. {
  444. InventoryItemBase newItem = new InventoryItemBase();
  445. newItem.AssetID = item.assetID;
  446. newItem.AssetType = item.assetType;
  447. newItem.Name = item.inventoryName;
  448. newItem.Owner = item.avatarID;
  449. newItem.ID = item.inventoryID;
  450. newItem.InvType = item.invType;
  451. newItem.Folder = item.parentFolderID;
  452. newItem.CreatorIdentification = item.creatorID;
  453. newItem.Description = item.inventoryDescription;
  454. newItem.NextPermissions = (uint)item.inventoryNextPermissions;
  455. newItem.CurrentPermissions = (uint)item.inventoryCurrentPermissions;
  456. newItem.BasePermissions = (uint)item.inventoryBasePermissions;
  457. newItem.EveryOnePermissions = (uint)item.inventoryEveryOnePermissions;
  458. newItem.GroupPermissions = (uint)item.inventoryGroupPermissions;
  459. newItem.GroupID = item.groupID;
  460. if (item.groupOwned == 0)
  461. newItem.GroupOwned = false;
  462. else
  463. newItem.GroupOwned = true;
  464. newItem.SalePrice = item.salePrice;
  465. newItem.SaleType = (byte)item.saleType;
  466. newItem.Flags = (uint)item.flags;
  467. newItem.CreationDate = item.creationDate;
  468. return newItem;
  469. }
  470. protected XInventoryItem ConvertFromOpenSim(InventoryItemBase item)
  471. {
  472. XInventoryItem newItem = new XInventoryItem();
  473. newItem.assetID = item.AssetID;
  474. newItem.assetType = item.AssetType;
  475. newItem.inventoryName = item.Name;
  476. newItem.avatarID = item.Owner;
  477. newItem.inventoryID = item.ID;
  478. newItem.invType = item.InvType;
  479. newItem.parentFolderID = item.Folder;
  480. newItem.creatorID = item.CreatorIdentification;
  481. newItem.inventoryDescription = item.Description;
  482. newItem.inventoryNextPermissions = (int)item.NextPermissions;
  483. newItem.inventoryCurrentPermissions = (int)item.CurrentPermissions;
  484. newItem.inventoryBasePermissions = (int)item.BasePermissions;
  485. newItem.inventoryEveryOnePermissions = (int)item.EveryOnePermissions;
  486. newItem.inventoryGroupPermissions = (int)item.GroupPermissions;
  487. newItem.groupID = item.GroupID;
  488. if (item.GroupOwned)
  489. newItem.groupOwned = 1;
  490. else
  491. newItem.groupOwned = 0;
  492. newItem.salePrice = item.SalePrice;
  493. newItem.saleType = (int)item.SaleType;
  494. newItem.flags = (int)item.Flags;
  495. newItem.creationDate = item.CreationDate;
  496. return newItem;
  497. }
  498. private bool ParentIsTrash(UUID folderID)
  499. {
  500. XInventoryFolder[] folder = m_Database.GetFolders(new string[] {"folderID"}, new string[] {folderID.ToString()});
  501. if (folder.Length < 1)
  502. return false;
  503. if (folder[0].type == (int)AssetType.TrashFolder)
  504. return true;
  505. UUID parentFolder = folder[0].parentFolderID;
  506. while (parentFolder != UUID.Zero)
  507. {
  508. XInventoryFolder[] parent = m_Database.GetFolders(new string[] {"folderID"}, new string[] {parentFolder.ToString()});
  509. if (parent.Length < 1)
  510. return false;
  511. if (parent[0].type == (int)AssetType.TrashFolder)
  512. return true;
  513. if (parent[0].type == (int)AssetType.RootFolder)
  514. return false;
  515. parentFolder = parent[0].parentFolderID;
  516. }
  517. return false;
  518. }
  519. }
  520. }