29 using System.Collections.Generic;
33 using System.Reflection;
34 using OpenSim.Services.Base;
35 using OpenSim.Services.Interfaces;
37 using OpenSim.Framework;
39 namespace OpenSim.Services.InventoryService
43 private static readonly ILog m_log =
45 MethodBase.GetCurrentMethod().DeclaringType);
48 protected bool m_AllowDelete =
true;
49 protected string m_ConfigName =
"InventoryService";
52 : this(config,
"InventoryService")
58 if (configName !=
string.Empty)
59 m_ConfigName = configName;
61 string dllName = String.Empty;
62 string connString = String.Empty;
68 IConfig authConfig = config.Configs[m_ConfigName];
69 if (authConfig != null)
71 dllName = authConfig.GetString(
"StorageProvider", dllName);
72 connString = authConfig.GetString(
"ConnectionString", connString);
73 m_AllowDelete = authConfig.GetBoolean(
"AllowDelete",
true);
80 IConfig dbConfig = config.Configs[
"DatabaseService"];
83 if (dllName == String.Empty)
84 dllName = dbConfig.GetString(
"StorageProvider", String.Empty);
85 if (connString == String.Empty)
86 connString = dbConfig.GetString(
"ConnectionString", String.Empty);
92 if (dllName == String.Empty)
93 throw new Exception(
"No StorageProvider configured");
95 m_Database = LoadPlugin<IXInventoryData>(dllName,
96 new Object[] {connString, String.Empty});
98 if (m_Database == null)
99 throw new Exception(
"Could not find a storage interface in the given module");
112 if (rootFolder == null)
120 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.Animation)
return true;
return false; }))
121 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.Animation,
"Animations");
122 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.BodyPart)
return true;
return false; }))
123 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.BodyPart,
"Body Parts");
124 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.CallingCard)
return true;
return false; }))
126 XInventoryFolder folder = CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.CallingCard,
"Calling Cards");
127 folder = CreateFolder(principalID, folder.
folderID, (
int)FolderType.CallingCard,
"Friends");
128 CreateFolder(principalID, folder.
folderID, (
int)FolderType.CallingCard,
"All");
130 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.Clothing)
return true;
return false; }))
131 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.Clothing,
"Clothing");
132 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.CurrentOutfit)
return true;
return false; }))
133 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.CurrentOutfit,
"Current Outfit");
134 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.Favorites)
return true;
return false; }))
135 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.Favorites,
"Favorites");
136 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.Gesture)
return true;
return false; }))
137 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.Gesture,
"Gestures");
138 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.Landmark)
return true;
return false; }))
139 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.Landmark,
"Landmarks");
140 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.LostAndFound)
return true;
return false; }))
141 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.LostAndFound,
"Lost And Found");
142 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.Notecard)
return true;
return false; }))
143 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.Notecard,
"Notecards");
144 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.Object)
return true;
return false; }))
145 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.Object,
"Objects");
146 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.Snapshot)
return true;
return false; }))
147 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.Snapshot,
"Photo Album");
148 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.LSLText)
return true;
return false; }))
149 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.LSLText,
"Scripts");
150 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.Sound)
return true;
return false; }))
151 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.Sound,
"Sounds");
152 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.Texture)
return true;
return false; }))
153 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.Texture,
"Textures");
154 if (!Array.Exists(sysFolders, delegate(
XInventoryFolder f) {
if (f.
type == (
int)FolderType.Trash)
return true;
return false; }))
155 CreateFolder(principalID, rootFolder.
ID, (
int)FolderType.Trash,
"Trash");
164 newFolder.folderName = name;
165 newFolder.type = type;
166 newFolder.version = 1;
167 newFolder.folderID = UUID.Random();
168 newFolder.agentID = principalID;
169 newFolder.parentFolderID = parentID;
171 m_Database.StoreFolder(newFolder);
181 new string[] {
"agentID",
"parentFolderID" },
182 new string[] { principalID.ToString(), rootID.ToString() });
202 new string[] {
"agentID" },
203 new string[] { principalID.ToString() });
205 if (allFolders.Length == 0)
208 List<InventoryFolderBase> folders =
new List<InventoryFolderBase>();
213 folders.Add(ConvertToOpenSim(x));
222 new string[] {
"agentID",
"parentFolderID"},
223 new string[] { principalID.ToString(), UUID.Zero.ToString() });
225 if (folders.Length == 0)
241 return ConvertToOpenSim(root);
250 if (rootFolder == null)
253 "[XINVENTORY]: Found no root folder for {0} in GetFolderForType() when looking for {1}",
259 return GetSystemFolderForType(rootFolder, type);
266 if (type == FolderType.Root)
270 new string[] {
"agentID",
"parentFolderID",
"type"},
271 new string[] { rootFolder.Owner.ToString(), rootFolder.
ID.ToString(), ((int)type).ToString() });
273 if (folders.Length == 0)
283 return ConvertToOpenSim(folders[0]);
294 inventory.OwnerID = principalID;
295 inventory.Folders =
new List<InventoryFolderBase>();
296 inventory.Items =
new List<InventoryItemBase>();
299 new string[] {
"parentFolderID"},
300 new string[] { folderID.ToString() });
305 inventory.Folders.Add(ConvertToOpenSim(x));
309 new string[] {
"parentFolderID"},
310 new string[] { folderID.ToString() });
315 inventory.Items.Add(ConvertToOpenSim(i));
322 inventory.Version = f.Version;
323 inventory.OwnerID = f.Owner;
325 inventory.FolderID = folderID;
334 foreach (UUID fid
in folderIDs)
335 multiple[i++] = GetFolderContent(principalID, fid);
340 public virtual List<InventoryItemBase>
GetFolderItems(UUID principalID, UUID folderID)
346 List<InventoryItemBase> invItems =
new List<InventoryItemBase>();
349 new string[] {
"parentFolderID" },
350 new string[] { folderID.ToString() });
353 invItems.Add(ConvertToOpenSim(i));
366 if (folder.
Type != (
short)FolderType.None)
370 if (rootFolder == null)
373 "[XINVENTORY]: Found no root folder for {0} in AddFolder() when looking for {1}",
374 folder.Owner, folder.Type);
383 = GetSystemFolderForType(rootFolder, (FolderType)folder.
Type);
385 if (existingSystemFolder != null)
388 "[XINVENTORY]: System folder of type {0} already exists when tried to add {1} to {2} for {3}",
389 folder.Type, folder.Name, folder.ParentID, folder.Owner);
397 return m_Database.StoreFolder(xFolder);
408 return AddFolder(folder);
410 if ((check.
Type != (
short)FolderType.None || xFolder.
type != (
short)FolderType.None)
411 && (check.
Type != (
short)FolderType.Outfit || xFolder.
type != (
short)FolderType.Outfit))
419 check.Version = (ushort)xFolder.
version;
420 xFolder = ConvertFromOpenSim(check);
426 return m_Database.StoreFolder(xFolder);
430 xFolder.version = check.Version;
432 xFolder.folderID = check.ID;
434 return m_Database.StoreFolder(xFolder);
439 return m_Database.MoveFolder(folder.ID.ToString(), folder.
ParentID.ToString());
446 return DeleteFolders(principalID, folderIDs,
true);
449 public virtual bool DeleteFolders(UUID principalID, List<UUID> folderIDs,
bool onlyIfTrash)
456 foreach (UUID
id in folderIDs)
458 if (onlyIfTrash && !ParentIsTrash(
id))
463 PurgeFolder(f, onlyIfTrash);
464 m_Database.DeleteFolders(
"folderID", id.ToString());
472 return PurgeFolder(folder,
true);
480 if (onlyIfTrash && !ParentIsTrash(folder.
ID))
484 new string[] {
"parentFolderID" },
485 new string[] { folder.ID.ToString() });
489 PurgeFolder(ConvertToOpenSim(x), onlyIfTrash);
490 m_Database.DeleteFolders(
"folderID", x.folderID.ToString());
493 m_Database.DeleteItems(
"parentFolderID", folder.ID.ToString());
503 return m_Database.StoreItem(ConvertFromOpenSim(item));
509 if (item.
AssetType == (sbyte)AssetType.Link || item.
AssetType == (sbyte)AssetType.LinkFolder)
517 if (retrievedItem == null)
520 "[XINVENTORY SERVICE]: Tried to update item {0} {1}, owner {2} but no existing item found.",
521 item.Name, item.ID, item.Owner);
534 "[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})",
537 retrievedItem.InvType,
538 retrievedItem.AssetType,
539 retrievedItem.Folder,
540 retrievedItem.CreatorIdentification,
545 item.CreatorIdentification,
548 item.InvType = retrievedItem.InvType;
549 item.AssetType = retrievedItem.AssetType;
550 item.Folder = retrievedItem.Folder;
551 item.CreatorIdentification = retrievedItem.CreatorIdentification;
552 item.Owner = retrievedItem.Owner;
555 return m_Database.StoreItem(ConvertFromOpenSim(item));
558 public virtual bool MoveItems(UUID principalID, List<InventoryItemBase> items)
564 m_Database.MoveItem(i.ID.ToString(), i.
Folder.ToString());
570 public virtual bool DeleteItems(UUID principalID, List<UUID> itemIDs)
578 foreach (UUID
id in itemIDs)
580 if (!m_Database.DeleteItems(
581 new string[] {
"inventoryID",
"assetType" },
582 new string[] { id.ToString(), ((sbyte)AssetType.Link).ToString() }))
584 m_Database.DeleteItems(
585 new string[] {
"inventoryID",
"assetType" },
586 new string[] { id.ToString(), ((sbyte)AssetType.LinkFolder).ToString() });
594 foreach (UUID
id in itemIDs)
595 m_Database.DeleteItems(
"inventoryID", id.ToString());
604 new string[] {
"inventoryID" },
605 new string[] { item.ID.ToString() });
607 if (items.Length == 0)
610 return ConvertToOpenSim(items[0]);
619 foreach (UUID
id in ids)
622 items[i++] = GetItem(item);
631 new string[] {
"folderID"},
632 new string[] { folder.ID.ToString() });
634 if (folders.Length == 0)
637 return ConvertToOpenSim(folders[0]);
642 XInventoryItem[] items = m_Database.GetActiveGestures(principalID);
644 if (items.Length == 0)
645 return new List<InventoryItemBase>();
647 List<InventoryItemBase> ret =
new List<InventoryItemBase>();
650 ret.Add(ConvertToOpenSim(x));
657 return m_Database.GetAssetPermissions(principalID, assetID);
673 newFolder.ParentID = folder.parentFolderID;
674 newFolder.Type = (short)folder.
type;
678 newFolder.
Version = (ushort)folder.version;
679 newFolder.Name = folder.folderName;
680 newFolder.Owner = folder.agentID;
681 newFolder.ID = folder.folderID;
690 newFolder.parentFolderID = folder.ParentID;
691 newFolder.type = (int)folder.
Type;
692 newFolder.
version = (
int)folder.Version;
693 newFolder.folderName = folder.Name;
694 newFolder.agentID = folder.Owner;
695 newFolder.folderID = folder.ID;
704 newItem.AssetID = item.assetID;
705 newItem.AssetType = item.assetType;
706 newItem.Name = item.inventoryName;
707 newItem.Owner = item.avatarID;
708 newItem.ID = item.inventoryID;
709 newItem.InvType = item.invType;
710 newItem.Folder = item.parentFolderID;
711 newItem.CreatorIdentification = item.creatorID;
712 newItem.Description = item.inventoryDescription;
720 newItem.GroupOwned =
false;
722 newItem.GroupOwned =
true;
723 newItem.SalePrice = item.salePrice;
724 newItem.SaleType = (byte)item.
saleType;
725 newItem.
Flags = (uint)item.flags;
726 newItem.CreationDate = item.creationDate;
735 newItem.assetID = item.AssetID;
736 newItem.assetType = item.AssetType;
737 newItem.inventoryName = item.Name;
738 newItem.avatarID = item.Owner;
739 newItem.inventoryID = item.ID;
740 newItem.invType = item.InvType;
741 newItem.parentFolderID = item.Folder;
742 newItem.creatorID = item.CreatorIdentification;
743 newItem.inventoryDescription = item.Description;
751 newItem.groupOwned = 1;
753 newItem.groupOwned = 0;
754 newItem.salePrice = item.SalePrice;
755 newItem.saleType = (int)item.
SaleType;
756 newItem.
flags = (
int)item.Flags;
757 newItem.creationDate = item.CreationDate;
762 private bool ParentIsTrash(UUID folderID)
764 XInventoryFolder[] folder = m_Database.GetFolders(
new string[] {
"folderID"},
new string[] {folderID.ToString()});
765 if (folder.Length < 1)
768 if (folder[0].type == (
int)FolderType.Trash)
771 UUID parentFolder = folder[0].parentFolderID;
773 while (parentFolder != UUID.Zero)
775 XInventoryFolder[] parent = m_Database.GetFolders(
new string[] {
"folderID"},
new string[] {parentFolder.ToString()});
776 if (parent.Length < 1)
779 if (parent[0].type == (
int)FolderType.Trash)
781 if (parent[0].type == (
int)FolderType.Root)
784 parentFolder = parent[0].parentFolderID;
virtual XInventoryFolder[] GetSystemFolders(UUID principalID, UUID rootID)
int inventoryNextPermissions
IXInventoryData m_Database
virtual bool AddItem(InventoryItemBase item)
Add a new item to the user's inventory
virtual InventoryFolderBase GetFolder(InventoryFolderBase folder)
Get a folder, given by its UUID
virtual bool AddFolder(InventoryFolderBase folder)
Add a new folder to the user's inventory
InventoryFolderBase ConvertToOpenSim(XInventoryFolder folder)
virtual bool UpdateItem(InventoryItemBase item)
Update an item in the user's inventory
int inventoryGroupPermissions
virtual bool MoveItems(UUID principalID, List< InventoryItemBase > items)
bool HasInventoryForUser(UUID userID)
Does the given user have an inventory structure?
int inventoryBasePermissions
XInventoryService(IConfigSource config)
virtual List< InventoryFolderBase > GetInventorySkeleton(UUID principalID)
Gets the skeleton of the inventory – folders only
XInventoryFolder CreateFolder(UUID principalID, UUID parentID, int type, string name)
virtual UUID Owner
The agent who's inventory this is contained by
virtual bool UpdateFolder(InventoryFolderBase folder)
Update a folder in the user's inventory
virtual InventoryFolderBase GetRootFolder(UUID principalID)
Retrieve the root inventory folder for the given user.
virtual InventoryItemBase[] GetMultipleItems(UUID userID, UUID[] ids)
Get multiple items, given by their UUIDs
virtual bool MoveFolder(InventoryFolderBase folder)
Move an inventory folder to a new location
virtual bool DeleteFolders(UUID principalID, List< UUID > folderIDs, bool onlyIfTrash)
virtual InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderIDs)
Gets everything (folders and items) inside a folder
virtual List< InventoryItemBase > GetActiveGestures(UUID principalID)
Get the active gestures of the agent.
Inventory Item - contains all the properties associated with an individual inventory piece...
virtual InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
Gets everything (folders and items) inside a folder
virtual bool CreateUserInventory(UUID principalID)
Create the entire inventory for a given user
XInventoryFolder ConvertFromOpenSim(InventoryFolderBase folder)
virtual int GetAssetPermissions(UUID principalID, UUID assetID)
Get the union of permissions of all inventory items that hold the given assetID.
int inventoryEveryOnePermissions
UUID ID
A UUID containing the ID for the inventory node itself
XInventoryItem ConvertFromOpenSim(InventoryItemBase item)
virtual bool DeleteItems(UUID principalID, List< UUID > itemIDs)
Delete an item from the user's inventory
virtual InventoryItemBase GetItem(InventoryItemBase item)
Get an item, given by its UUID
XInventoryService(IConfigSource config, string configName)
virtual bool PurgeFolder(InventoryFolderBase folder)
Purge an inventory folder of all its items and subfolders.
virtual List< InventoryItemBase > GetFolderItems(UUID principalID, UUID folderID)
Gets the items inside a folder
InventoryItemBase ConvertToOpenSim(XInventoryItem item)
static readonly string ROOT_FOLDER_NAME
virtual InventoryFolderBase GetFolderForType(UUID principalID, FolderType type)
Gets the user folder for the given folder-type
virtual bool PurgeFolder(InventoryFolderBase folder, bool onlyIfTrash)
Used to serialize a whole inventory for transfer over the network.
int inventoryCurrentPermissions
virtual bool DeleteFolders(UUID principalID, List< UUID > folderIDs)
Delete an item from the user's inventory
string CreatorIdentification
Used by the DB layer to retrieve / store the entire user identification. The identification can eithe...