From 2eee87fea3a5353e24ce2a6279400e4b5da292e6 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 29 Nov 2018 18:57:20 +0000 Subject: mantis 8414: add cap CreateInventoryCategory handler --- .../Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 71 +++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index dd410a7..0289513 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -312,9 +312,13 @@ namespace OpenSim.Region.ClientStack.Linden m_HostCapsObj.RegisterHandler("UpdateAgentInformation", UpdateAgentInformationHandler); IRequestHandler CopyInventoryFromNotecardHandler = new RestStreamHandler( - "POST", GetNewCapPath(), CopyInventoryFromNotecard, "CopyInventoryFromNotecard", null); + "POST", GetNewCapPath(), CopyInventoryFromNotecard, "CopyInventoryFromNotecard", null); m_HostCapsObj.RegisterHandler("CopyInventoryFromNotecard", CopyInventoryFromNotecardHandler); + IRequestHandler CreateInventoryCategoryHandler = new RestStreamHandler( + "POST", GetNewCapPath(), CreateInventoryCategory, "CreateInventoryCategory", null); + m_HostCapsObj.RegisterHandler("CreateInventoryCategory", CreateInventoryCategoryHandler); + } catch (Exception e) { @@ -1260,6 +1264,71 @@ namespace OpenSim.Region.ClientStack.Linden return String.Empty; } + public string CreateInventoryCategory(string request, string path, string param, + IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) + { + if (m_Scene.InventoryService == null) + { + httpResponse.StatusCode = (int)System.Net.HttpStatusCode.ServiceUnavailable; + httpResponse.StatusDescription = "Service not avaiable"; + return ""; + } + + ScenePresence sp = m_Scene.GetScenePresence(m_AgentID); + if (sp == null || sp.IsDeleted) + { + httpResponse.StatusCode = (int)System.Net.HttpStatusCode.ServiceUnavailable; + httpResponse.StatusDescription = "Retry later"; + httpResponse.AddHeader("Retry-After", "30"); + return ""; + } + + Hashtable hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request)); + + while (true) // kinda goto + { + if (!hash.Contains("folder_id") || !(hash["folder_id"] is UUID)) + break; + UUID folderID = (UUID)hash["folder_id"]; + + if (!hash.Contains("parent_id") || !(hash["parent_id"] is UUID)) + break; + UUID parentID = (UUID)hash["parent_id"]; + + if (!hash.Contains("name") || !(hash["name"] is string)) + break; + string folderName = (string)hash["name"]; + + if (!hash.Contains("type") || !(hash["type"] is int)) + break; + int folderType = (int)hash["type"]; + + InventoryFolderBase folder = new InventoryFolderBase(folderID, folderName, m_AgentID, (short)folderType, parentID, 1); + if (!m_Scene.InventoryService.AddFolder(folder)) + break; + + // costly double check plus possible service changes + folder = m_Scene.InventoryService.GetFolder(m_AgentID, folderID); + if(folder == null) + break; + + StringBuilder sb = LLSDxmlEncode.Start(256); + LLSDxmlEncode.AddMap(sb); + LLSDxmlEncode.AddElem("folder_id", folder.ID, sb); + LLSDxmlEncode.AddElem("name", folder.Name, sb); + LLSDxmlEncode.AddElem("parent_id", folder.ParentID, sb); + LLSDxmlEncode.AddElem("type", folder.Type, sb); + LLSDxmlEncode.AddEndMap(sb); + string resp = LLSDxmlEncode.End(sb); + + return resp; + } + + httpResponse.StatusCode = (int)OSHttpStatusCode.ClientErrorBadRequest; + httpResponse.StatusDescription = "Error"; + httpResponse.KeepAlive = false; + return ""; + } /// /// Called by the notecard update handler. Provides a URL to which the client can upload a new asset. -- cgit v1.1