diff --git a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs index ccaf5c44ed..a944972d0a 100644 --- a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs +++ b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs @@ -158,6 +158,16 @@ namespace OpenSim.Server.Handlers.Asset } private byte[] FailureResult() + { + return BoolResult(false); + } + + private byte[] SuccessResult() + { + return BoolResult(true); + } + + private byte[] BoolResult(bool value) { XmlDocument doc = new XmlDocument(); @@ -172,7 +182,7 @@ namespace OpenSim.Server.Handlers.Asset doc.AppendChild(rootElement); XmlElement result = doc.CreateElement("", "RESULT", ""); - result.AppendChild(doc.CreateTextNode("False")); + result.AppendChild(doc.CreateTextNode(value.ToString())); rootElement.AppendChild(result); @@ -218,8 +228,9 @@ namespace OpenSim.Server.Handlers.Asset List folders = m_InventoryService.GetInventorySkeleton(new UUID(request["PRINCIPAL"].ToString())); - foreach (InventoryFolderBase f in folders) - result[f.ID.ToString()] = EncodeFolder(f); + if (folders != null) + foreach (InventoryFolderBase f in folders) + result[f.ID.ToString()] = EncodeFolder(f); string xmlString = ServerUtils.BuildXmlResponse(result); m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); @@ -234,10 +245,9 @@ namespace OpenSim.Server.Handlers.Asset UUID principal = UUID.Zero; UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); InventoryFolderBase rfolder = m_InventoryService.GetRootFolder(principal); - if (rfolder == null) - return FailureResult(); + if (rfolder != null) + result[rfolder.ID.ToString()] = EncodeFolder(rfolder); - result[rfolder.ID.ToString()] = EncodeFolder(rfolder); string xmlString = ServerUtils.BuildXmlResponse(result); m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); UTF8Encoding encoding = new UTF8Encoding(); @@ -252,10 +262,9 @@ namespace OpenSim.Server.Handlers.Asset int type = 0; Int32.TryParse(request["TYPE"].ToString(), out type); InventoryFolderBase folder = m_InventoryService.GetFolderForType(principal, (AssetType)type); - if (folder == null) - return FailureResult(); + if (folder != null) + result[folder.ID.ToString()] = EncodeFolder(folder); - result[folder.ID.ToString()] = EncodeFolder(folder); string xmlString = ServerUtils.BuildXmlResponse(result); m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); UTF8Encoding encoding = new UTF8Encoding(); @@ -271,19 +280,19 @@ namespace OpenSim.Server.Handlers.Asset UUID.TryParse(request["FOLDER"].ToString(), out folderID); InventoryCollection icoll = m_InventoryService.GetFolderContent(principal, folderID); - if (icoll == null) - return FailureResult(); + if (icoll != null) + { + Dictionary folders = new Dictionary(); + foreach (InventoryFolderBase f in icoll.Folders) + folders[f.ID.ToString()] = EncodeFolder(f); + result["FOLDERS"] = folders; - Dictionary folders = new Dictionary(); - foreach (InventoryFolderBase f in icoll.Folders) - folders[f.ID.ToString()] = EncodeFolder(f); - result["FOLDERS"] = folders; + Dictionary items = new Dictionary(); + foreach (InventoryItemBase i in icoll.Items) + items[i.ID.ToString()] = EncodeItem(i); + result["ITEMS"] = items; + } - Dictionary items = new Dictionary(); - foreach (InventoryItemBase i in icoll.Items) - items[i.ID.ToString()] = EncodeItem(i); - result["ITEMS"] = folders; - string xmlString = ServerUtils.BuildXmlResponse(result); m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); UTF8Encoding encoding = new UTF8Encoding(); @@ -293,7 +302,16 @@ namespace OpenSim.Server.Handlers.Asset byte[] HandleGetFolderItems(Dictionary request) { Dictionary result = new Dictionary(); + UUID principal = UUID.Zero; + UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); + UUID folderID = UUID.Zero; + UUID.TryParse(request["FOLDER"].ToString(), out folderID); + List items = m_InventoryService.GetFolderItems(principal, folderID); + if (items != null) + foreach (InventoryItemBase item in items) + result[item.ID.ToString()] = EncodeItem(item); + string xmlString = ServerUtils.BuildXmlResponse(result); m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); UTF8Encoding encoding = new UTF8Encoding(); @@ -303,96 +321,169 @@ namespace OpenSim.Server.Handlers.Asset byte[] HandleAddFolder(Dictionary request) { Dictionary result = new Dictionary(); + InventoryFolderBase folder = BuildFolder(request); - string xmlString = ServerUtils.BuildXmlResponse(result); - m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); - UTF8Encoding encoding = new UTF8Encoding(); - return encoding.GetBytes(xmlString); + if (m_InventoryService.AddFolder(folder)) + return SuccessResult(); + else + return FailureResult(); } byte[] HandleUpdateFolder(Dictionary request) { - Dictionary result = new Dictionary(); + Dictionary result = new Dictionary(); + InventoryFolderBase folder = BuildFolder(request); - string xmlString = ServerUtils.BuildXmlResponse(result); - m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); - UTF8Encoding encoding = new UTF8Encoding(); - return encoding.GetBytes(xmlString); + if (m_InventoryService.UpdateFolder(folder)) + return SuccessResult(); + else + return FailureResult(); } byte[] HandleMoveFolder(Dictionary request) { - Dictionary result = new Dictionary(); + Dictionary result = new Dictionary(); + UUID parentID = UUID.Zero; + UUID.TryParse(request["ParentID"].ToString(), out parentID); + UUID folderID = UUID.Zero; + UUID.TryParse(request["ID"].ToString(), out folderID); + UUID principal = UUID.Zero; + UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); + + InventoryFolderBase folder = new InventoryFolderBase(folderID, "", principal, parentID); + if (m_InventoryService.MoveFolder(folder)) + return SuccessResult(); + else + return FailureResult(); - string xmlString = ServerUtils.BuildXmlResponse(result); - m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); - UTF8Encoding encoding = new UTF8Encoding(); - return encoding.GetBytes(xmlString); } byte[] HandleDeleteFolders(Dictionary request) { Dictionary result = new Dictionary(); + UUID principal = UUID.Zero; + UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); + List slist = (List)request["FOLDERS"]; + List uuids = new List(); + foreach (string s in slist) + { + UUID u = UUID.Zero; + if (UUID.TryParse(s, out u)) + uuids.Add(u); + } - string xmlString = ServerUtils.BuildXmlResponse(result); - m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); - UTF8Encoding encoding = new UTF8Encoding(); - return encoding.GetBytes(xmlString); + if (m_InventoryService.DeleteFolders(principal, uuids)) + return SuccessResult(); + else + return + FailureResult(); } byte[] HandlePurgeFolder(Dictionary request) { Dictionary result = new Dictionary(); + UUID folderID = UUID.Zero; + UUID.TryParse(request["ID"].ToString(), out folderID); - string xmlString = ServerUtils.BuildXmlResponse(result); - m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); - UTF8Encoding encoding = new UTF8Encoding(); - return encoding.GetBytes(xmlString); + InventoryFolderBase folder = new InventoryFolderBase(folderID); + if (m_InventoryService.PurgeFolder(folder)) + return SuccessResult(); + else + return FailureResult(); } byte[] HandleAddItem(Dictionary request) { - Dictionary result = new Dictionary(); + Dictionary result = new Dictionary(); + InventoryItemBase item = BuildItem(request); - string xmlString = ServerUtils.BuildXmlResponse(result); - m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); - UTF8Encoding encoding = new UTF8Encoding(); - return encoding.GetBytes(xmlString); + if (m_InventoryService.AddItem(item)) + return SuccessResult(); + else + return FailureResult(); } byte[] HandleUpdateItem(Dictionary request) { - Dictionary result = new Dictionary(); + Dictionary result = new Dictionary(); + InventoryItemBase item = BuildItem(request); - string xmlString = ServerUtils.BuildXmlResponse(result); - m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); - UTF8Encoding encoding = new UTF8Encoding(); - return encoding.GetBytes(xmlString); + if (m_InventoryService.UpdateItem(item)) + return SuccessResult(); + else + return FailureResult(); } byte[] HandleMoveItems(Dictionary request) { Dictionary result = new Dictionary(); + List idlist = (List)request["IDLIST"]; + List destlist = (List)request["DESTLIST"]; + UUID principal = UUID.Zero; + UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); - string xmlString = ServerUtils.BuildXmlResponse(result); - m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); - UTF8Encoding encoding = new UTF8Encoding(); - return encoding.GetBytes(xmlString); + List items = new List(); + int n = 0; + try + { + foreach (string s in idlist) + { + UUID u = UUID.Zero; + if (UUID.TryParse(s, out u)) + { + UUID fid = UUID.Zero; + if (UUID.TryParse(destlist[n++], out fid)) + { + InventoryItemBase item = new InventoryItemBase(u, principal); + item.Folder = fid; + items.Add(item); + } + } + } + } + catch (Exception e) + { + m_log.DebugFormat("[XINVENTORY IN CONNECTOR]: Exception in HandleMoveItems: {0}", e.Message); + return FailureResult(); + } + + if (m_InventoryService.MoveItems(principal, items)) + return SuccessResult(); + else + return FailureResult(); } byte[] HandleDeleteItems(Dictionary request) { - Dictionary result = new Dictionary(); + Dictionary result = new Dictionary(); + UUID principal = UUID.Zero; + UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); + List slist = (List)request["ITEMS"]; + List uuids = new List(); + foreach (string s in slist) + { + UUID u = UUID.Zero; + if (UUID.TryParse(s, out u)) + uuids.Add(u); + } - string xmlString = ServerUtils.BuildXmlResponse(result); - m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); - UTF8Encoding encoding = new UTF8Encoding(); - return encoding.GetBytes(xmlString); + if (m_InventoryService.DeleteItems(principal, uuids)) + return SuccessResult(); + else + return + FailureResult(); } byte[] HandleGetItem(Dictionary request) { Dictionary result = new Dictionary(); + UUID id = UUID.Zero; + UUID.TryParse(request["ID"].ToString(), out id); + + InventoryItemBase item = new InventoryItemBase(id); + item = m_InventoryService.GetItem(item); + if (item != null) + result[item.ID.ToString()] = EncodeItem(item); string xmlString = ServerUtils.BuildXmlResponse(result); m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); @@ -402,7 +493,14 @@ namespace OpenSim.Server.Handlers.Asset byte[] HandleGetFolder(Dictionary request) { - Dictionary result = new Dictionary(); + Dictionary result = new Dictionary(); + UUID id = UUID.Zero; + UUID.TryParse(request["ID"].ToString(), out id); + + InventoryFolderBase folder = new InventoryFolderBase(id); + folder = m_InventoryService.GetFolder(folder); + if (folder != null) + result[folder.ID.ToString()] = EncodeFolder(folder); string xmlString = ServerUtils.BuildXmlResponse(result); m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); @@ -413,6 +511,13 @@ namespace OpenSim.Server.Handlers.Asset byte[] HandleGetActiveGestures(Dictionary request) { Dictionary result = new Dictionary(); + UUID principal = UUID.Zero; + UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); + + List gestures = m_InventoryService.GetActiveGestures(principal); + if (gestures != null) + foreach (InventoryItemBase item in gestures) + result[item.ID.ToString()] = EncodeItem(item); string xmlString = ServerUtils.BuildXmlResponse(result); m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); @@ -423,7 +528,14 @@ namespace OpenSim.Server.Handlers.Asset byte[] HandleGetAssetPermissions(Dictionary request) { Dictionary result = new Dictionary(); + UUID principal = UUID.Zero; + UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); + UUID assetID = UUID.Zero; + UUID.TryParse(request["ASSET"].ToString(), out assetID); + int perms = m_InventoryService.GetAssetPermissions(principal, assetID); + + result["RESULT"] = perms.ToString(); string xmlString = ServerUtils.BuildXmlResponse(result); m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); UTF8Encoding encoding = new UTF8Encoding(); diff --git a/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs b/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs index b9ccd7ea12..3309d169dd 100644 --- a/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs +++ b/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs @@ -92,6 +92,8 @@ namespace OpenSim.Services.Connectors if (ret == null) return false; + if (ret.Count == 0) + return false; return bool.Parse(ret["RESULT"].ToString()); } @@ -105,6 +107,8 @@ namespace OpenSim.Services.Connectors if (ret == null) return null; + if (ret.Count == 0) + return null; List folders = new List(); @@ -122,8 +126,7 @@ namespace OpenSim.Services.Connectors }); if (ret == null) - return null; - + return null; if (ret.Count == 0) return null; @@ -140,7 +143,6 @@ namespace OpenSim.Services.Connectors if (ret == null) return null; - if (ret.Count == 0) return null; @@ -157,7 +159,6 @@ namespace OpenSim.Services.Connectors if (ret == null) return null; - if (ret.Count == 0) return null; @@ -182,7 +183,7 @@ namespace OpenSim.Services.Connectors public List GetFolderItems(UUID principalID, UUID folderID) { - Dictionary ret = MakeRequest("GETFOLDERCONTENT", + Dictionary ret = MakeRequest("GETFOLDERITEMS", new Dictionary { { "PRINCIPAL", principalID.ToString() }, { "FOLDER", folderID.ToString() } @@ -190,7 +191,6 @@ namespace OpenSim.Services.Connectors if (ret == null) return null; - if (ret.Count == 0) return null; @@ -244,7 +244,8 @@ namespace OpenSim.Services.Connectors Dictionary ret = MakeRequest("MOVEFOLDER", new Dictionary { { "ParentID", folder.ParentID.ToString() }, - { "ID", folder.ID.ToString() } + { "ID", folder.ID.ToString() }, + { "PRINCIPAL", folder.Owner.ToString() } }); if (ret == null) @@ -362,7 +363,7 @@ namespace OpenSim.Services.Connectors Dictionary ret = MakeRequest("MOVEITEMS", new Dictionary { - { "PrincipalID", principalID.ToString() }, + { "PRINCIPAL", principalID.ToString() }, { "IDLIST", idlist }, { "DESTLIST", destlist } }); @@ -401,7 +402,6 @@ namespace OpenSim.Services.Connectors if (ret == null) return null; - if (ret.Count == 0) return null; @@ -417,7 +417,6 @@ namespace OpenSim.Services.Connectors if (ret == null) return null; - if (ret.Count == 0) return null; @@ -531,5 +530,6 @@ namespace OpenSim.Services.Connectors return item; } + } }