From 1abc6149bb5494372dee67cb240931293d6bf1fe Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 28 Apr 2020 15:43:07 +0100 Subject: [PATCH] split file bunchofcaps a bit --- .../Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 194 +----------------- .../Caps/BunchOfCaps/UpdateItemAsset.cs | 184 +++++++++++++++++ 2 files changed, 189 insertions(+), 189 deletions(-) create mode 100644 OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/UpdateItemAsset.cs diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 8ab2ca318f..023451f401 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -65,16 +65,12 @@ namespace OpenSim.Region.ClientStack.Linden int cost, UUID texturesFolder, int nreqtextures, int nreqmeshs, int nreqinstances, bool IsAtestUpload, ref string error, ref int nextOwnerMask, ref int groupMask, ref int everyoneMask, int[] meshesSides); - public delegate UUID UpdateItem(UUID itemID, UUID objectID, byte[] data); - public delegate void UpdateTaskScript(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors); public delegate void NewInventoryItem(UUID userID, InventoryItemBase item, uint cost); public delegate void NewAsset(AssetBase asset); - public delegate UUID ItemUpdatedCallback(UUID userID, UUID itemID, UUID objectID, byte[] data); - public delegate ArrayList TaskScriptUpdatedCallback(UUID userID, UUID itemID, UUID primID, bool isScriptRunning, byte[] data); @@ -85,7 +81,7 @@ namespace OpenSim.Region.ClientStack.Linden /// public delegate IClientAPI GetClientDelegate(UUID agentID); - public class BunchOfCaps + public partial class BunchOfCaps { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -308,19 +304,10 @@ namespace OpenSim.Region.ClientStack.Linden new LLSDStreamhandler( "POST", GetNewCapPath(), NewAgentInventoryRequest, "NewFileAgentInventory", null)); - // we have a single "do it all" method - var oreq = new SimpleOSDMapHandler("POST", GetNewCapPath(), UpdateInventoryItemAsset); - - // first also sets the http handler, others only register the cap, using it - m_HostCapsObj.RegisterSimpleHandler("UpdateNotecardAgentInventory", oreq, true); - m_HostCapsObj.RegisterSimpleHandler("UpdateNotecardTaskInventory", oreq, false); // a object inv - m_HostCapsObj.RegisterSimpleHandler("UpdateAnimSetAgentInventory", oreq, false); - m_HostCapsObj.RegisterSimpleHandler("UpdateScriptAgentInventory", oreq, false); - m_HostCapsObj.RegisterSimpleHandler("UpdateScriptAgent", oreq, false); - m_HostCapsObj.RegisterSimpleHandler("UpdateSettingsAgentInventory", oreq, false); - m_HostCapsObj.RegisterSimpleHandler("UpdateSettingsTaskInventory", oreq, false); // a object inv - m_HostCapsObj.RegisterSimpleHandler("UpdateGestureAgentInventory", oreq, false); - m_HostCapsObj.RegisterSimpleHandler("UpdateGestureTaskInventory", oreq, false); + if(ItemUpdatedCall != null) + { + // we have a single "do it all" method + var oreq = new SimpleOSDMapHandler("POST", GetNewCapPath(), UpdateInventoryItemAsset); m_HostCapsObj.RegisterSimpleHandler("UpdateAgentInformation", @@ -1361,85 +1348,6 @@ namespace OpenSim.Region.ClientStack.Linden httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; } - /// - /// Called by the notecard update handler. Provides a URL to which the client can upload a new asset. - /// - /// - /// - /// - /// - public void UpdateInventoryItemAsset(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map) - { - m_log.Debug("[CAPS]: UpdateInventoryItemAsset Request in region: " + m_regionName + "\n"); - - httpResponse.StatusCode = (int)HttpStatusCode.OK; - - UUID itemID = UUID.Zero; - UUID objectID = UUID.Zero; - - try - { - if (map.TryGetValue("item_id", out OSD itmp)) - itemID = itmp; - if (map.TryGetValue("task_id", out OSD tmp)) - objectID = tmp; - } - catch { } - - if(itemID == UUID.Zero) - { - LLSDAssetUploadError error = new LLSDAssetUploadError(); - error.message = "failed to recode request"; - error.identifier = UUID.Zero; - httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(error)); - return; - } - - if (objectID != UUID.Zero) - { - SceneObjectPart sop = m_Scene.GetSceneObjectPart(objectID); - if (sop == null) - { - LLSDAssetUploadError error = new LLSDAssetUploadError(); - error.message = "object not found"; - error.identifier = UUID.Zero; - httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(error)); - return; - } - - if(!m_Scene.Permissions.CanEditObjectInventory(objectID, m_AgentID)) - { - LLSDAssetUploadError error = new LLSDAssetUploadError(); - error.message = "No permissions to edit objec"; - error.identifier = UUID.Zero; - httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(error)); - return; - } - } - - string uploaderPath = GetNewCapPath(); - - ItemUpdater uploader = new ItemUpdater(itemID, objectID, uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile); - uploader.OnUpLoad += ItemUpdated; - - m_HostCapsObj.HttpListener.AddStreamHandler( - new BinaryStreamHandler( - "POST", uploaderPath, uploader.uploaderCaps, "UpdateInventoryItemAsset", null)); - - string protocol = m_HostCapsObj.SSLCaps ? "https://" : "http://"; - - string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + uploaderPath; - - LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); - uploadResponse.uploader = uploaderURL; - uploadResponse.state = "upload"; - - // m_log.InfoFormat("[CAPS]: UpdateAgentInventoryAsset response: {0}", - // LLSDHelpers.SerialiseLLSDReply(uploadResponse))); - - httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(uploadResponse)); - } - private string CopyInventoryFromNotecardError(IOSHttpResponse response) { @@ -2374,99 +2282,7 @@ namespace OpenSim.Region.ClientStack.Linden } } - /// - /// This class is a callback invoked when a client sends asset data to - /// an agent inventory notecard update url - /// - public class ItemUpdater - { - public event UpdateItem OnUpLoad; - private UpdateItem handlerUpdateItem = null; - - private string uploaderPath = String.Empty; - private UUID inventoryItemID; - private UUID objectID; - private IHttpServer httpListener; - private bool m_dumpAssetToFile; - - public ItemUpdater(UUID inventoryItem, UUID objectid, string path, IHttpServer httpServer, bool dumpAssetToFile) - { - m_dumpAssetToFile = dumpAssetToFile; - - inventoryItemID = inventoryItem; - objectID = objectid; - uploaderPath = path; - httpListener = httpServer; - } - - /// - /// Handle raw uploaded asset data. - /// - /// - /// - /// - /// - public string uploaderCaps(byte[] data, string path, string param) - { - httpListener.RemoveStreamHandler("POST", uploaderPath); - - UUID inv = inventoryItemID; - string res = String.Empty; - - UUID assetID = UUID.Zero; - handlerUpdateItem = OnUpLoad; - if (handlerUpdateItem != null) - assetID = handlerUpdateItem(inv, objectID, data); - - if(assetID == UUID.Zero) - { - LLSDAssetUploadError uperror = new LLSDAssetUploadError(); - uperror.message ="Failed to update inventory item asset"; - uperror.identifier = inv; - res = LLSDHelpers.SerialiseLLSDReply(uperror); - } - else - { - LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); - uploadComplete.new_asset = assetID.ToString(); - uploadComplete.new_inventory_item = inv; - uploadComplete.state = "complete"; - res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); - } - - if (m_dumpAssetToFile) - { - SaveAssetToFile("updateditem" + Util.RandomClass.Next(1, 1000) + ".dat", data); - } - - return res; - } - - ///Left this in and commented in case there are unforseen issues - //private void SaveAssetToFile(string filename, byte[] data) - //{ - // FileStream fs = File.Create(filename); - // BinaryWriter bw = new BinaryWriter(fs); - // bw.Write(data); - // bw.Close(); - // fs.Close(); - //} - - private static void SaveAssetToFile(string filename, byte[] data) - { - string assetPath = "UserAssets"; - if (!Directory.Exists(assetPath)) - { - Directory.CreateDirectory(assetPath); - } - FileStream fs = File.Create(Path.Combine(assetPath, filename)); - BinaryWriter bw = new BinaryWriter(fs); - bw.Write(data); - bw.Close(); - fs.Close(); - } - } /// /// This class is a callback invoked when a client sends asset data to diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/UpdateItemAsset.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/UpdateItemAsset.cs new file mode 100644 index 0000000000..5f45a85093 --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/UpdateItemAsset.cs @@ -0,0 +1,184 @@ +using System; +using System.IO; +using System.Net; + +using OpenMetaverse; +using OpenMetaverse.StructuredData; + +using OpenSim.Framework; +using OpenSim.Framework.Capabilities; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Framework.Servers.HttpServer; +using OSDMap = OpenMetaverse.StructuredData.OSDMap; + +namespace OpenSim.Region.ClientStack.Linden +{ + public delegate UUID UpdateItem(UUID itemID, UUID objectID, byte[] data); + public delegate UUID ItemUpdatedCallback(UUID userID, UUID itemID, UUID objectID, byte[] data); + + public partial class BunchOfCaps + { + /// + /// Called by the items updates handler. Provides a URL to which the client can upload a new asset. + /// + /// + /// + /// + /// + public void UpdateInventoryItemAsset(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map) + { + m_log.Debug("[CAPS]: UpdateInventoryItemAsset Request in region: " + m_regionName + "\n"); + + httpResponse.StatusCode = (int)HttpStatusCode.OK; + + UUID itemID = UUID.Zero; + UUID objectID = UUID.Zero; + + try + { + if (map.TryGetValue("item_id", out OSD itmp)) + itemID = itmp; + if (map.TryGetValue("task_id", out OSD tmp)) + objectID = tmp; + } + catch { } + + if (itemID == UUID.Zero) + { + LLSDAssetUploadError error = new LLSDAssetUploadError(); + error.message = "failed to recode request"; + error.identifier = UUID.Zero; + httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(error)); + return; + } + + if (objectID != UUID.Zero) + { + SceneObjectPart sop = m_Scene.GetSceneObjectPart(objectID); + if (sop == null) + { + LLSDAssetUploadError error = new LLSDAssetUploadError(); + error.message = "object not found"; + error.identifier = UUID.Zero; + httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(error)); + return; + } + + if (!m_Scene.Permissions.CanEditObjectInventory(objectID, m_AgentID)) + { + LLSDAssetUploadError error = new LLSDAssetUploadError(); + error.message = "No permissions to edit objec"; + error.identifier = UUID.Zero; + httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(error)); + return; + } + } + + string uploaderPath = GetNewCapPath(); + + ItemUpdater uploader = new ItemUpdater(itemID, objectID, uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile); + uploader.OnUpLoad += ItemUpdated; + + m_HostCapsObj.HttpListener.AddStreamHandler( + new BinaryStreamHandler( + "POST", uploaderPath, uploader.uploaderCaps, "UpdateInventoryItemAsset", null)); + + string protocol = m_HostCapsObj.SSLCaps ? "https://" : "http://"; + + string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + uploaderPath; + + LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); + uploadResponse.uploader = uploaderURL; + uploadResponse.state = "upload"; + + // m_log.InfoFormat("[CAPS]: UpdateAgentInventoryAsset response: {0}", + // LLSDHelpers.SerialiseLLSDReply(uploadResponse))); + + httpResponse.RawBuffer = Util.UTF8.GetBytes(LLSDHelpers.SerialiseLLSDReply(uploadResponse)); + } + } + + /// + /// This class is a callback invoked when a client sends asset data to + /// an agent inventory notecard update url + /// + public class ItemUpdater + { + public event UpdateItem OnUpLoad; + + private UpdateItem handlerUpdateItem = null; + + private string uploaderPath = String.Empty; + private UUID inventoryItemID; + private UUID objectID; + private IHttpServer httpListener; + private bool m_dumpAssetToFile; + + public ItemUpdater(UUID inventoryItem, UUID objectid, string path, IHttpServer httpServer, bool dumpAssetToFile) + { + m_dumpAssetToFile = dumpAssetToFile; + + inventoryItemID = inventoryItem; + objectID = objectid; + uploaderPath = path; + httpListener = httpServer; + } + + /// + /// Handle raw uploaded asset data. + /// + /// + /// + /// + /// + public string uploaderCaps(byte[] data, string path, string param) + { + httpListener.RemoveStreamHandler("POST", uploaderPath); + + UUID inv = inventoryItemID; + string res = String.Empty; + + UUID assetID = UUID.Zero; + handlerUpdateItem = OnUpLoad; + if (handlerUpdateItem != null) + assetID = handlerUpdateItem(inv, objectID, data); + + if (assetID == UUID.Zero) + { + LLSDAssetUploadError uperror = new LLSDAssetUploadError(); + uperror.message = "Failed to update inventory item asset"; + uperror.identifier = inv; + res = LLSDHelpers.SerialiseLLSDReply(uperror); + } + else + { + LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); + uploadComplete.new_asset = assetID.ToString(); + uploadComplete.new_inventory_item = inv; + uploadComplete.state = "complete"; + res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); + } + + if (m_dumpAssetToFile) + { + SaveAssetToFile("updateditem" + Util.RandomClass.Next(1, 1000) + ".dat", data); + } + + return res; + } + + private static void SaveAssetToFile(string filename, byte[] data) + { + string assetPath = "UserAssets"; + if (!Directory.Exists(assetPath)) + { + Directory.CreateDirectory(assetPath); + } + FileStream fs = File.Create(Path.Combine(assetPath, filename)); + BinaryWriter bw = new BinaryWriter(fs); + bw.Write(data); + bw.Close(); + fs.Close(); + } + } +} \ No newline at end of file