XInventoryService.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  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. protected string m_ConfigName = "InventoryService";
  47. public XInventoryService(IConfigSource config)
  48. : this(config, "InventoryService")
  49. {
  50. }
  51. public XInventoryService(IConfigSource config, string configName) : base(config)
  52. {
  53. if (configName != string.Empty)
  54. m_ConfigName = configName;
  55. string dllName = String.Empty;
  56. string connString = String.Empty;
  57. //string realm = "Inventory"; // OSG version doesn't use this
  58. //
  59. // Try reading the [InventoryService] section first, if it exists
  60. //
  61. IConfig authConfig = config.Configs[m_ConfigName];
  62. if (authConfig != null)
  63. {
  64. dllName = authConfig.GetString("StorageProvider", dllName);
  65. connString = authConfig.GetString("ConnectionString", connString);
  66. m_AllowDelete = authConfig.GetBoolean("AllowDelete", true);
  67. // realm = authConfig.GetString("Realm", realm);
  68. }
  69. //
  70. // Try reading the [DatabaseService] section, if it exists
  71. //
  72. IConfig dbConfig = config.Configs["DatabaseService"];
  73. if (dbConfig != null)
  74. {
  75. if (dllName == String.Empty)
  76. dllName = dbConfig.GetString("StorageProvider", String.Empty);
  77. if (connString == String.Empty)
  78. connString = dbConfig.GetString("ConnectionString", String.Empty);
  79. }
  80. //
  81. // We tried, but this doesn't exist. We can't proceed.
  82. //
  83. if (dllName == String.Empty)
  84. throw new Exception("No StorageProvider configured");
  85. m_Database = LoadPlugin<IXInventoryData>(dllName,
  86. new Object[] {connString, String.Empty});
  87. if (m_Database == null)
  88. throw new Exception("Could not find a storage interface in the given module");
  89. }
  90. public virtual bool CreateUserInventory(UUID principalID)
  91. {
  92. // This is braindeaad. We can't ever communicate that we fixed
  93. // an existing inventory. Well, just return root folder status,
  94. // but check sanity anyway.
  95. //
  96. bool result = false;
  97. InventoryFolderBase rootFolder = GetRootFolder(principalID);
  98. if (rootFolder == null)
  99. {
  100. rootFolder = ConvertToOpenSim(CreateFolder(principalID, UUID.Zero, (int)FolderType.Root, InventoryFolderBase.ROOT_FOLDER_NAME));
  101. result = true;
  102. }
  103. XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootFolder.ID);
  104. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Animation) return true; return false; }))
  105. CreateFolder(principalID, rootFolder.ID, (int)FolderType.Animation, "Animations");
  106. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.BodyPart) return true; return false; }))
  107. CreateFolder(principalID, rootFolder.ID, (int)FolderType.BodyPart, "Body Parts");
  108. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.CallingCard) return true; return false; }))
  109. {
  110. XInventoryFolder folder = CreateFolder(principalID, rootFolder.ID, (int)FolderType.CallingCard, "Calling Cards");
  111. folder = CreateFolder(principalID, folder.folderID, (int)FolderType.CallingCard, "Friends");
  112. CreateFolder(principalID, folder.folderID, (int)FolderType.CallingCard, "All");
  113. }
  114. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Clothing) return true; return false; }))
  115. CreateFolder(principalID, rootFolder.ID, (int)FolderType.Clothing, "Clothing");
  116. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.CurrentOutfit) return true; return false; }))
  117. CreateFolder(principalID, rootFolder.ID, (int)FolderType.CurrentOutfit, "Current Outfit");
  118. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Favorites) return true; return false; }))
  119. CreateFolder(principalID, rootFolder.ID, (int)FolderType.Favorites, "Favorites");
  120. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Gesture) return true; return false; }))
  121. CreateFolder(principalID, rootFolder.ID, (int)FolderType.Gesture, "Gestures");
  122. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Landmark) return true; return false; }))
  123. CreateFolder(principalID, rootFolder.ID, (int)FolderType.Landmark, "Landmarks");
  124. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.LostAndFound) return true; return false; }))
  125. CreateFolder(principalID, rootFolder.ID, (int)FolderType.LostAndFound, "Lost And Found");
  126. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Notecard) return true; return false; }))
  127. CreateFolder(principalID, rootFolder.ID, (int)FolderType.Notecard, "Notecards");
  128. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Object) return true; return false; }))
  129. CreateFolder(principalID, rootFolder.ID, (int)FolderType.Object, "Objects");
  130. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Snapshot) return true; return false; }))
  131. CreateFolder(principalID, rootFolder.ID, (int)FolderType.Snapshot, "Photo Album");
  132. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.LSLText) return true; return false; }))
  133. CreateFolder(principalID, rootFolder.ID, (int)FolderType.LSLText, "Scripts");
  134. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Sound) return true; return false; }))
  135. CreateFolder(principalID, rootFolder.ID, (int)FolderType.Sound, "Sounds");
  136. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Texture) return true; return false; }))
  137. CreateFolder(principalID, rootFolder.ID, (int)FolderType.Texture, "Textures");
  138. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Trash) return true; return false; }))
  139. CreateFolder(principalID, rootFolder.ID, (int)FolderType.Trash, "Trash");
  140. return result;
  141. }
  142. protected XInventoryFolder CreateFolder(UUID principalID, UUID parentID, int type, string name)
  143. {
  144. XInventoryFolder newFolder = new XInventoryFolder();
  145. newFolder.folderName = name;
  146. newFolder.type = type;
  147. newFolder.version = 1;
  148. newFolder.folderID = UUID.Random();
  149. newFolder.agentID = principalID;
  150. newFolder.parentFolderID = parentID;
  151. m_Database.StoreFolder(newFolder);
  152. return newFolder;
  153. }
  154. protected virtual XInventoryFolder[] GetSystemFolders(UUID principalID, UUID rootID)
  155. {
  156. // m_log.DebugFormat("[XINVENTORY SERVICE]: Getting system folders for {0}", principalID);
  157. XInventoryFolder[] allFolders = m_Database.GetFolders(
  158. new string[] { "agentID", "parentFolderID" },
  159. new string[] { principalID.ToString(), rootID.ToString() });
  160. XInventoryFolder[] sysFolders = Array.FindAll(
  161. allFolders,
  162. delegate (XInventoryFolder f)
  163. {
  164. if (f.type > 0)
  165. return true;
  166. return false;
  167. });
  168. // m_log.DebugFormat(
  169. // "[XINVENTORY SERVICE]: Found {0} system folders for {1}", sysFolders.Length, principalID);
  170. return sysFolders;
  171. }
  172. public virtual List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
  173. {
  174. XInventoryFolder[] allFolders = m_Database.GetFolders(
  175. new string[] { "agentID" },
  176. new string[] { principalID.ToString() });
  177. if (allFolders.Length == 0)
  178. return null;
  179. List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
  180. foreach (XInventoryFolder x in allFolders)
  181. {
  182. //m_log.DebugFormat("[XINVENTORY SERVICE]: Adding folder {0} to skeleton", x.folderName);
  183. folders.Add(ConvertToOpenSim(x));
  184. }
  185. return folders;
  186. }
  187. public virtual InventoryFolderBase GetRootFolder(UUID principalID)
  188. {
  189. XInventoryFolder[] folders = m_Database.GetFolders(
  190. new string[] { "agentID", "parentFolderID"},
  191. new string[] { principalID.ToString(), UUID.Zero.ToString() });
  192. if (folders.Length == 0)
  193. return null;
  194. XInventoryFolder root = null;
  195. foreach (XInventoryFolder folder in folders)
  196. {
  197. if (folder.folderName == InventoryFolderBase.ROOT_FOLDER_NAME)
  198. {
  199. root = folder;
  200. break;
  201. }
  202. }
  203. if (root == null) // oops
  204. root = folders[0];
  205. return ConvertToOpenSim(root);
  206. }
  207. public virtual InventoryFolderBase GetFolderForType(UUID principalID, FolderType type)
  208. {
  209. // m_log.DebugFormat("[XINVENTORY SERVICE]: Getting folder type {0} for user {1}", type, principalID);
  210. InventoryFolderBase rootFolder = GetRootFolder(principalID);
  211. if (rootFolder == null)
  212. {
  213. m_log.WarnFormat(
  214. "[XINVENTORY]: Found no root folder for {0} in GetFolderForType() when looking for {1}",
  215. principalID, type);
  216. return null;
  217. }
  218. return GetSystemFolderForType(rootFolder, type);
  219. }
  220. private InventoryFolderBase GetSystemFolderForType(InventoryFolderBase rootFolder, FolderType type)
  221. {
  222. //m_log.DebugFormat("[XINVENTORY SERVICE]: Getting folder type {0}", type);
  223. if (type == FolderType.Root)
  224. return rootFolder;
  225. XInventoryFolder[] folders = m_Database.GetFolders(
  226. new string[] { "agentID", "parentFolderID", "type"},
  227. new string[] { rootFolder.Owner.ToString(), rootFolder.ID.ToString(), ((int)type).ToString() });
  228. if (folders.Length == 0)
  229. {
  230. //m_log.WarnFormat("[XINVENTORY SERVICE]: Found no folder for type {0} ", type);
  231. return null;
  232. }
  233. //m_log.DebugFormat(
  234. // "[XINVENTORY SERVICE]: Found folder {0} {1} for type {2}",
  235. // folders[0].folderName, folders[0].folderID, type);
  236. return ConvertToOpenSim(folders[0]);
  237. }
  238. public virtual InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
  239. {
  240. // This method doesn't receive a valud principal id from the
  241. // connector. So we disregard the principal and look
  242. // by ID.
  243. //
  244. //m_log.DebugFormat("[XINVENTORY SERVICE]: Fetch contents for folder {0}", folderID.ToString());
  245. InventoryCollection inventory = new InventoryCollection();
  246. inventory.OwnerID = principalID;
  247. inventory.Folders = new List<InventoryFolderBase>();
  248. inventory.Items = new List<InventoryItemBase>();
  249. XInventoryFolder[] folders = m_Database.GetFolders(
  250. new string[] { "parentFolderID"},
  251. new string[] { folderID.ToString() });
  252. foreach (XInventoryFolder x in folders)
  253. {
  254. //m_log.DebugFormat("[XINVENTORY]: Adding folder {0} to response", x.folderName);
  255. inventory.Folders.Add(ConvertToOpenSim(x));
  256. }
  257. XInventoryItem[] items = m_Database.GetItems(
  258. new string[] { "parentFolderID"},
  259. new string[] { folderID.ToString() });
  260. foreach (XInventoryItem i in items)
  261. {
  262. //m_log.DebugFormat("[XINVENTORY]: Adding item {0} to response", i.inventoryName);
  263. inventory.Items.Add(ConvertToOpenSim(i));
  264. }
  265. InventoryFolderBase f = GetFolder(principalID, folderID);
  266. if (f != null)
  267. {
  268. inventory.Version = f.Version;
  269. inventory.OwnerID = f.Owner;
  270. }
  271. inventory.FolderID = folderID;
  272. return inventory;
  273. }
  274. public virtual InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderIDs)
  275. {
  276. InventoryCollection[] multiple = new InventoryCollection[folderIDs.Length];
  277. int i = 0;
  278. foreach (UUID fid in folderIDs)
  279. multiple[i++] = GetFolderContent(principalID, fid);
  280. return multiple;
  281. }
  282. public virtual List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
  283. {
  284. // m_log.DebugFormat("[XINVENTORY]: Fetch items for folder {0}", folderID);
  285. // Since we probably don't get a valid principal here, either ...
  286. //
  287. List<InventoryItemBase> invItems = new List<InventoryItemBase>();
  288. XInventoryItem[] items = m_Database.GetItems(
  289. new string[] { "parentFolderID" },
  290. new string[] { folderID.ToString() });
  291. foreach (XInventoryItem i in items)
  292. invItems.Add(ConvertToOpenSim(i));
  293. return invItems;
  294. }
  295. public virtual bool AddFolder(InventoryFolderBase folder)
  296. {
  297. // m_log.DebugFormat("[XINVENTORY]: Add folder {0} type {1} in parent {2}", folder.Name, folder.Type, folder.ParentID);
  298. InventoryFolderBase check = GetFolder(folder.Owner, folder.ID);
  299. if (check != null)
  300. return false;
  301. if (folder.Type != (short)FolderType.None)
  302. {
  303. InventoryFolderBase rootFolder = GetRootFolder(folder.Owner);
  304. if (rootFolder == null)
  305. {
  306. m_log.WarnFormat(
  307. "[XINVENTORY]: Found no root folder for {0} in AddFolder() when looking for {1}",
  308. folder.Owner, folder.Type);
  309. return false;
  310. }
  311. // Check we're not trying to add this as a system folder.
  312. if (folder.ParentID == rootFolder.ID)
  313. {
  314. InventoryFolderBase existingSystemFolder
  315. = GetSystemFolderForType(rootFolder, (FolderType)folder.Type);
  316. if (existingSystemFolder != null)
  317. {
  318. m_log.WarnFormat(
  319. "[XINVENTORY]: System folder of type {0} already exists when tried to add {1} to {2} for {3}",
  320. folder.Type, folder.Name, folder.ParentID, folder.Owner);
  321. return false;
  322. }
  323. }
  324. }
  325. XInventoryFolder xFolder = ConvertFromOpenSim(folder);
  326. return m_Database.StoreFolder(xFolder);
  327. }
  328. public virtual bool UpdateFolder(InventoryFolderBase folder)
  329. {
  330. // m_log.DebugFormat("[XINVENTORY]: Update folder {0} {1} ({2})", folder.Name, folder.Type, folder.ID);
  331. XInventoryFolder xFolder = ConvertFromOpenSim(folder);
  332. InventoryFolderBase check = GetFolder(folder.Owner, folder.ID);
  333. if (check == null)
  334. return AddFolder(folder);
  335. if ((check.Type != (short)FolderType.None || xFolder.type != (short)FolderType.None)
  336. && (check.Type != (short)FolderType.Outfit || xFolder.type != (short)FolderType.Outfit))
  337. {
  338. if (xFolder.version < check.Version)
  339. {
  340. // m_log.DebugFormat("[XINVENTORY]: {0} < {1} can't do", xFolder.version, check.Version);
  341. return false;
  342. }
  343. check.Version = (ushort)xFolder.version;
  344. xFolder = ConvertFromOpenSim(check);
  345. // m_log.DebugFormat(
  346. // "[XINVENTORY]: Storing version only update to system folder {0} {1} {2}",
  347. // xFolder.folderName, xFolder.version, xFolder.type);
  348. return m_Database.StoreFolder(xFolder);
  349. }
  350. if (xFolder.version < check.Version)
  351. xFolder.version = check.Version;
  352. xFolder.folderID = check.ID;
  353. return m_Database.StoreFolder(xFolder);
  354. }
  355. public virtual bool MoveFolder(InventoryFolderBase folder)
  356. {
  357. return m_Database.MoveFolder(folder.ID.ToString(), folder.ParentID.ToString());
  358. }
  359. // We don't check the principal's ID here
  360. //
  361. public virtual bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
  362. {
  363. return DeleteFolders(principalID, folderIDs, true);
  364. }
  365. public virtual bool DeleteFolders(UUID principalID, List<UUID> folderIDs, bool onlyIfTrash)
  366. {
  367. if (!m_AllowDelete)
  368. return false;
  369. // Ignore principal ID, it's bogus at connector level
  370. //
  371. foreach (UUID id in folderIDs)
  372. {
  373. if (onlyIfTrash && !ParentIsTrash(id))
  374. continue;
  375. //m_log.InfoFormat("[XINVENTORY SERVICE]: Delete folder {0}", id);
  376. InventoryFolderBase f = new InventoryFolderBase();
  377. f.ID = id;
  378. PurgeFolder(f, onlyIfTrash);
  379. m_Database.DeleteFolders("folderID", id.ToString());
  380. }
  381. return true;
  382. }
  383. public virtual bool PurgeFolder(InventoryFolderBase folder)
  384. {
  385. return PurgeFolder(folder, true);
  386. }
  387. public virtual bool PurgeFolder(InventoryFolderBase folder, bool onlyIfTrash)
  388. {
  389. if (!m_AllowDelete)
  390. return false;
  391. if (onlyIfTrash && !ParentIsTrash(folder.ID))
  392. return false;
  393. XInventoryFolder[] subFolders = m_Database.GetFolders(
  394. new string[] { "parentFolderID" },
  395. new string[] { folder.ID.ToString() });
  396. foreach (XInventoryFolder x in subFolders)
  397. {
  398. PurgeFolder(ConvertToOpenSim(x), onlyIfTrash);
  399. m_Database.DeleteFolders("folderID", x.folderID.ToString());
  400. }
  401. m_Database.DeleteItems("parentFolderID", folder.ID.ToString());
  402. return true;
  403. }
  404. public virtual bool AddItem(InventoryItemBase item)
  405. {
  406. // m_log.DebugFormat(
  407. // "[XINVENTORY SERVICE]: Adding item {0} {1} to folder {2} for {3}", item.Name, item.ID, item.Folder, item.Owner);
  408. return m_Database.StoreItem(ConvertFromOpenSim(item));
  409. }
  410. public virtual bool UpdateItem(InventoryItemBase item)
  411. {
  412. if (!m_AllowDelete)
  413. if (item.AssetType == (sbyte)AssetType.Link || item.AssetType == (sbyte)AssetType.LinkFolder)
  414. return false;
  415. // m_log.InfoFormat(
  416. // "[XINVENTORY SERVICE]: Updating item {0} {1} in folder {2}", item.Name, item.ID, item.Folder);
  417. InventoryItemBase retrievedItem = GetItem(item.Owner, item.ID);
  418. if (retrievedItem == null)
  419. {
  420. m_log.WarnFormat(
  421. "[XINVENTORY SERVICE]: Tried to update item {0} {1}, owner {2} but no existing item found.",
  422. item.Name, item.ID, item.Owner);
  423. return false;
  424. }
  425. // Do not allow invariants to change. Changes to folder ID occur in MoveItems()
  426. if (retrievedItem.InvType != item.InvType
  427. || retrievedItem.AssetType != item.AssetType
  428. || retrievedItem.Folder != item.Folder
  429. || retrievedItem.CreatorIdentification != item.CreatorIdentification
  430. || retrievedItem.Owner != item.Owner)
  431. {
  432. m_log.WarnFormat(
  433. "[XINVENTORY SERVICE]: Caller to UpdateItem() for {0} {1} tried to alter property(s) that should be invariant, (InvType, AssetType, Folder, CreatorIdentification, Owner), existing ({2}, {3}, {4}, {5}, {6}), update ({7}, {8}, {9}, {10}, {11})",
  434. retrievedItem.Name,
  435. retrievedItem.ID,
  436. retrievedItem.InvType,
  437. retrievedItem.AssetType,
  438. retrievedItem.Folder,
  439. retrievedItem.CreatorIdentification,
  440. retrievedItem.Owner,
  441. item.InvType,
  442. item.AssetType,
  443. item.Folder,
  444. item.CreatorIdentification,
  445. item.Owner);
  446. item.InvType = retrievedItem.InvType;
  447. item.AssetType = retrievedItem.AssetType;
  448. item.Folder = retrievedItem.Folder;
  449. item.CreatorIdentification = retrievedItem.CreatorIdentification;
  450. item.Owner = retrievedItem.Owner;
  451. }
  452. return m_Database.StoreItem(ConvertFromOpenSim(item));
  453. }
  454. public virtual bool MoveItems(UUID principalID, List<InventoryItemBase> items)
  455. {
  456. // Principal is b0rked. *sigh*
  457. //
  458. foreach (InventoryItemBase i in items)
  459. {
  460. m_Database.MoveItem(i.ID.ToString(), i.Folder.ToString());
  461. }
  462. return true;
  463. }
  464. public virtual bool DeleteItems(UUID principalID, List<UUID> itemIDs)
  465. {
  466. if (!m_AllowDelete)
  467. {
  468. // We must still allow links and links to folders to be deleted, otherwise they will build up
  469. // in the player's inventory until they can no longer log in. Deletions of links due to code bugs or
  470. // similar is inconvenient but on a par with accidental movement of items. The original item is never
  471. // touched.
  472. foreach (UUID id in itemIDs)
  473. {
  474. if (!m_Database.DeleteItems(
  475. new string[] { "inventoryID", "assetType" },
  476. new string[] { id.ToString(), ((sbyte)AssetType.Link).ToString() }))
  477. {
  478. m_Database.DeleteItems(
  479. new string[] { "inventoryID", "assetType" },
  480. new string[] { id.ToString(), ((sbyte)AssetType.LinkFolder).ToString() });
  481. }
  482. }
  483. }
  484. else
  485. {
  486. // Just use the ID... *facepalms*
  487. //
  488. foreach (UUID id in itemIDs)
  489. m_Database.DeleteItems("inventoryID", id.ToString());
  490. }
  491. return true;
  492. }
  493. public virtual InventoryItemBase GetItem(UUID principalID, UUID itemID)
  494. {
  495. XInventoryItem[] items = m_Database.GetItems(
  496. new string[] { "inventoryID" },
  497. new string[] { itemID.ToString() });
  498. if (items.Length == 0)
  499. return null;
  500. return ConvertToOpenSim(items[0]);
  501. }
  502. public virtual InventoryItemBase[] GetMultipleItems(UUID userID, UUID[] ids)
  503. {
  504. InventoryItemBase[] items = new InventoryItemBase[ids.Length];
  505. int i = 0;
  506. foreach (UUID id in ids)
  507. items[i++] = GetItem(userID, id);
  508. return items;
  509. }
  510. public virtual InventoryFolderBase GetFolder(UUID principalID, UUID folderID)
  511. {
  512. XInventoryFolder[] folders = m_Database.GetFolders(
  513. new string[] { "folderID"},
  514. new string[] { folderID.ToString() });
  515. if (folders.Length == 0)
  516. return null;
  517. return ConvertToOpenSim(folders[0]);
  518. }
  519. public virtual List<InventoryItemBase> GetActiveGestures(UUID principalID)
  520. {
  521. XInventoryItem[] items = m_Database.GetActiveGestures(principalID);
  522. if (items.Length == 0)
  523. return new List<InventoryItemBase>();
  524. List<InventoryItemBase> ret = new List<InventoryItemBase>();
  525. foreach (XInventoryItem x in items)
  526. ret.Add(ConvertToOpenSim(x));
  527. return ret;
  528. }
  529. public virtual int GetAssetPermissions(UUID principalID, UUID assetID)
  530. {
  531. return m_Database.GetAssetPermissions(principalID, assetID);
  532. }
  533. // Unused.
  534. //
  535. public bool HasInventoryForUser(UUID userID)
  536. {
  537. return false;
  538. }
  539. // CM Helpers
  540. //
  541. protected InventoryFolderBase ConvertToOpenSim(XInventoryFolder folder)
  542. {
  543. InventoryFolderBase newFolder = new InventoryFolderBase();
  544. newFolder.ParentID = folder.parentFolderID;
  545. newFolder.Type = (short)folder.type;
  546. //// Viewer can't understand anything that's not in it's LLFolderType enum
  547. //if (newFolder.Type == InventoryItemBase.SUITCASE_FOLDER_TYPE)
  548. // newFolder.Type = InventoryItemBase.SUITCASE_FOLDER_FAKE_TYPE;
  549. newFolder.Version = (ushort)folder.version;
  550. newFolder.Name = folder.folderName;
  551. newFolder.Owner = folder.agentID;
  552. newFolder.ID = folder.folderID;
  553. return newFolder;
  554. }
  555. protected XInventoryFolder ConvertFromOpenSim(InventoryFolderBase folder)
  556. {
  557. XInventoryFolder newFolder = new XInventoryFolder();
  558. newFolder.parentFolderID = folder.ParentID;
  559. newFolder.type = (int)folder.Type;
  560. newFolder.version = (int)folder.Version;
  561. newFolder.folderName = folder.Name;
  562. newFolder.agentID = folder.Owner;
  563. newFolder.folderID = folder.ID;
  564. return newFolder;
  565. }
  566. protected InventoryItemBase ConvertToOpenSim(XInventoryItem item)
  567. {
  568. InventoryItemBase newItem = new InventoryItemBase();
  569. newItem.AssetID = item.assetID;
  570. newItem.AssetType = item.assetType;
  571. newItem.Name = item.inventoryName;
  572. newItem.Owner = item.avatarID;
  573. newItem.ID = item.inventoryID;
  574. newItem.InvType = item.invType;
  575. newItem.Folder = item.parentFolderID;
  576. newItem.CreatorIdentification = item.creatorID;
  577. newItem.Description = item.inventoryDescription;
  578. newItem.NextPermissions = (uint)item.inventoryNextPermissions;
  579. newItem.CurrentPermissions = (uint)item.inventoryCurrentPermissions;
  580. newItem.BasePermissions = (uint)item.inventoryBasePermissions;
  581. newItem.EveryOnePermissions = (uint)item.inventoryEveryOnePermissions;
  582. newItem.GroupPermissions = (uint)item.inventoryGroupPermissions;
  583. newItem.GroupID = item.groupID;
  584. if (item.groupOwned == 0)
  585. newItem.GroupOwned = false;
  586. else
  587. newItem.GroupOwned = true;
  588. newItem.SalePrice = item.salePrice;
  589. newItem.SaleType = (byte)item.saleType;
  590. newItem.Flags = (uint)item.flags;
  591. newItem.CreationDate = item.creationDate;
  592. return newItem;
  593. }
  594. protected XInventoryItem ConvertFromOpenSim(InventoryItemBase item)
  595. {
  596. XInventoryItem newItem = new XInventoryItem();
  597. newItem.assetID = item.AssetID;
  598. newItem.assetType = item.AssetType;
  599. newItem.inventoryName = item.Name;
  600. newItem.avatarID = item.Owner;
  601. newItem.inventoryID = item.ID;
  602. newItem.invType = item.InvType;
  603. newItem.parentFolderID = item.Folder;
  604. newItem.creatorID = item.CreatorIdentification;
  605. newItem.inventoryDescription = item.Description;
  606. newItem.inventoryNextPermissions = (int)item.NextPermissions;
  607. newItem.inventoryCurrentPermissions = (int)item.CurrentPermissions;
  608. newItem.inventoryBasePermissions = (int)item.BasePermissions;
  609. newItem.inventoryEveryOnePermissions = (int)item.EveryOnePermissions;
  610. newItem.inventoryGroupPermissions = (int)item.GroupPermissions;
  611. newItem.groupID = item.GroupID;
  612. if (item.GroupOwned)
  613. newItem.groupOwned = 1;
  614. else
  615. newItem.groupOwned = 0;
  616. newItem.salePrice = item.SalePrice;
  617. newItem.saleType = (int)item.SaleType;
  618. newItem.flags = (int)item.Flags;
  619. newItem.creationDate = item.CreationDate;
  620. return newItem;
  621. }
  622. private bool ParentIsTrash(UUID folderID)
  623. {
  624. XInventoryFolder[] folder = m_Database.GetFolders(new string[] {"folderID"}, new string[] {folderID.ToString()});
  625. if (folder.Length < 1)
  626. return false;
  627. if (folder[0].type == (int)FolderType.Trash)
  628. return true;
  629. UUID parentFolder = folder[0].parentFolderID;
  630. while (parentFolder != UUID.Zero)
  631. {
  632. XInventoryFolder[] parent = m_Database.GetFolders(new string[] {"folderID"}, new string[] {parentFolder.ToString()});
  633. if (parent.Length < 1)
  634. return false;
  635. if (parent[0].type == (int)FolderType.Trash)
  636. return true;
  637. if (parent[0].type == (int)FolderType.Root)
  638. return false;
  639. parentFolder = parent[0].parentFolderID;
  640. }
  641. return false;
  642. }
  643. }
  644. }