XInventoryService.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. // throw new Exception("urrgh");
  327. if (!m_AllowDelete)
  328. if (item.AssetType == (sbyte)AssetType.Link || item.AssetType == (sbyte)AssetType.LinkFolder)
  329. return false;
  330. // m_log.InfoFormat(
  331. // "[XINVENTORY SERVICE]: Updating item {0} {1} in folder {2}", item.Name, item.ID, item.Folder);
  332. return m_Database.StoreItem(ConvertFromOpenSim(item));
  333. }
  334. public virtual bool MoveItems(UUID principalID, List<InventoryItemBase> items)
  335. {
  336. // Principal is b0rked. *sigh*
  337. //
  338. foreach (InventoryItemBase i in items)
  339. {
  340. m_Database.MoveItem(i.ID.ToString(), i.Folder.ToString());
  341. }
  342. return true;
  343. }
  344. public virtual bool DeleteItems(UUID principalID, List<UUID> itemIDs)
  345. {
  346. if (!m_AllowDelete)
  347. {
  348. // We must still allow links and links to folders to be deleted, otherwise they will build up
  349. // in the player's inventory until they can no longer log in. Deletions of links due to code bugs or
  350. // similar is inconvenient but on a par with accidental movement of items. The original item is never
  351. // touched.
  352. foreach (UUID id in itemIDs)
  353. {
  354. if (!m_Database.DeleteItems(
  355. new string[] { "inventoryID", "assetType" },
  356. new string[] { id.ToString(), ((sbyte)AssetType.Link).ToString() }))
  357. {
  358. m_Database.DeleteItems(
  359. new string[] { "inventoryID", "assetType" },
  360. new string[] { id.ToString(), ((sbyte)AssetType.LinkFolder).ToString() });
  361. }
  362. }
  363. }
  364. else
  365. {
  366. // Just use the ID... *facepalms*
  367. //
  368. foreach (UUID id in itemIDs)
  369. m_Database.DeleteItems("inventoryID", id.ToString());
  370. }
  371. return true;
  372. }
  373. public virtual InventoryItemBase GetItem(InventoryItemBase item)
  374. {
  375. XInventoryItem[] items = m_Database.GetItems(
  376. new string[] { "inventoryID" },
  377. new string[] { item.ID.ToString() });
  378. if (items.Length == 0)
  379. return null;
  380. return ConvertToOpenSim(items[0]);
  381. }
  382. public virtual InventoryFolderBase GetFolder(InventoryFolderBase folder)
  383. {
  384. XInventoryFolder[] folders = m_Database.GetFolders(
  385. new string[] { "folderID"},
  386. new string[] { folder.ID.ToString() });
  387. if (folders.Length == 0)
  388. return null;
  389. return ConvertToOpenSim(folders[0]);
  390. }
  391. public virtual List<InventoryItemBase> GetActiveGestures(UUID principalID)
  392. {
  393. XInventoryItem[] items = m_Database.GetActiveGestures(principalID);
  394. if (items.Length == 0)
  395. return new List<InventoryItemBase>();
  396. List<InventoryItemBase> ret = new List<InventoryItemBase>();
  397. foreach (XInventoryItem x in items)
  398. ret.Add(ConvertToOpenSim(x));
  399. return ret;
  400. }
  401. public virtual int GetAssetPermissions(UUID principalID, UUID assetID)
  402. {
  403. return m_Database.GetAssetPermissions(principalID, assetID);
  404. }
  405. // CM never needed those. Left unimplemented.
  406. // Obsolete in core
  407. //
  408. public InventoryCollection GetUserInventory(UUID userID)
  409. {
  410. return null;
  411. }
  412. public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
  413. {
  414. }
  415. // Unused.
  416. //
  417. public bool HasInventoryForUser(UUID userID)
  418. {
  419. return false;
  420. }
  421. // CM Helpers
  422. //
  423. protected InventoryFolderBase ConvertToOpenSim(XInventoryFolder folder)
  424. {
  425. InventoryFolderBase newFolder = new InventoryFolderBase();
  426. newFolder.ParentID = folder.parentFolderID;
  427. newFolder.Type = (short)folder.type;
  428. newFolder.Version = (ushort)folder.version;
  429. newFolder.Name = folder.folderName;
  430. newFolder.Owner = folder.agentID;
  431. newFolder.ID = folder.folderID;
  432. return newFolder;
  433. }
  434. protected XInventoryFolder ConvertFromOpenSim(InventoryFolderBase folder)
  435. {
  436. XInventoryFolder newFolder = new XInventoryFolder();
  437. newFolder.parentFolderID = folder.ParentID;
  438. newFolder.type = (int)folder.Type;
  439. newFolder.version = (int)folder.Version;
  440. newFolder.folderName = folder.Name;
  441. newFolder.agentID = folder.Owner;
  442. newFolder.folderID = folder.ID;
  443. return newFolder;
  444. }
  445. protected InventoryItemBase ConvertToOpenSim(XInventoryItem item)
  446. {
  447. InventoryItemBase newItem = new InventoryItemBase();
  448. newItem.AssetID = item.assetID;
  449. newItem.AssetType = item.assetType;
  450. newItem.Name = item.inventoryName;
  451. newItem.Owner = item.avatarID;
  452. newItem.ID = item.inventoryID;
  453. newItem.InvType = item.invType;
  454. newItem.Folder = item.parentFolderID;
  455. newItem.CreatorIdentification = item.creatorID;
  456. newItem.Description = item.inventoryDescription;
  457. newItem.NextPermissions = (uint)item.inventoryNextPermissions;
  458. newItem.CurrentPermissions = (uint)item.inventoryCurrentPermissions;
  459. newItem.BasePermissions = (uint)item.inventoryBasePermissions;
  460. newItem.EveryOnePermissions = (uint)item.inventoryEveryOnePermissions;
  461. newItem.GroupPermissions = (uint)item.inventoryGroupPermissions;
  462. newItem.GroupID = item.groupID;
  463. if (item.groupOwned == 0)
  464. newItem.GroupOwned = false;
  465. else
  466. newItem.GroupOwned = true;
  467. newItem.SalePrice = item.salePrice;
  468. newItem.SaleType = (byte)item.saleType;
  469. newItem.Flags = (uint)item.flags;
  470. newItem.CreationDate = item.creationDate;
  471. return newItem;
  472. }
  473. protected XInventoryItem ConvertFromOpenSim(InventoryItemBase item)
  474. {
  475. XInventoryItem newItem = new XInventoryItem();
  476. newItem.assetID = item.AssetID;
  477. newItem.assetType = item.AssetType;
  478. newItem.inventoryName = item.Name;
  479. newItem.avatarID = item.Owner;
  480. newItem.inventoryID = item.ID;
  481. newItem.invType = item.InvType;
  482. newItem.parentFolderID = item.Folder;
  483. newItem.creatorID = item.CreatorIdentification;
  484. newItem.inventoryDescription = item.Description;
  485. newItem.inventoryNextPermissions = (int)item.NextPermissions;
  486. newItem.inventoryCurrentPermissions = (int)item.CurrentPermissions;
  487. newItem.inventoryBasePermissions = (int)item.BasePermissions;
  488. newItem.inventoryEveryOnePermissions = (int)item.EveryOnePermissions;
  489. newItem.inventoryGroupPermissions = (int)item.GroupPermissions;
  490. newItem.groupID = item.GroupID;
  491. if (item.GroupOwned)
  492. newItem.groupOwned = 1;
  493. else
  494. newItem.groupOwned = 0;
  495. newItem.salePrice = item.SalePrice;
  496. newItem.saleType = (int)item.SaleType;
  497. newItem.flags = (int)item.Flags;
  498. newItem.creationDate = item.CreationDate;
  499. return newItem;
  500. }
  501. private bool ParentIsTrash(UUID folderID)
  502. {
  503. XInventoryFolder[] folder = m_Database.GetFolders(new string[] {"folderID"}, new string[] {folderID.ToString()});
  504. if (folder.Length < 1)
  505. return false;
  506. if (folder[0].type == (int)AssetType.TrashFolder)
  507. return true;
  508. UUID parentFolder = folder[0].parentFolderID;
  509. while (parentFolder != UUID.Zero)
  510. {
  511. XInventoryFolder[] parent = m_Database.GetFolders(new string[] {"folderID"}, new string[] {parentFolder.ToString()});
  512. if (parent.Length < 1)
  513. return false;
  514. if (parent[0].type == (int)AssetType.TrashFolder)
  515. return true;
  516. if (parent[0].type == (int)AssetType.RootFolder)
  517. return false;
  518. parentFolder = parent[0].parentFolderID;
  519. }
  520. return false;
  521. }
  522. }
  523. }