From 60357d3778c95a47481f790803b7af39c70cde9c Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 9 May 2010 17:56:52 +0100 Subject: [PATCH 1/2] Implement the "delete" path for assets. Adds a new option to allow remote asset deletion in robust handler. --- OpenSim/Data/AssetDataBase.cs | 1 + OpenSim/Data/IAssetData.cs | 1 + OpenSim/Data/MSSQL/MSSQLAssetData.cs | 4 ++++ OpenSim/Data/MySQL/MySQLAssetData.cs | 18 ++++++++++++++++++ OpenSim/Data/SQLite/SQLiteAssetData.cs | 5 +++++ OpenSim/Data/SQLiteLegacy/SQLiteAssetData.cs | 6 +++++- .../Handlers/Asset/AssetServerConnector.cs | 4 +++- .../Handlers/Asset/AssetServerDeleteHandler.cs | 8 +++++--- OpenSim/Services/AssetService/AssetService.cs | 11 +++++++++++ .../Tests/Common/Mock/MockAssetDataPlugin.cs | 7 ++++++- bin/Robust.ini.example | 1 + 11 files changed, 60 insertions(+), 6 deletions(-) diff --git a/OpenSim/Data/AssetDataBase.cs b/OpenSim/Data/AssetDataBase.cs index 5deb44e61e..e1a810c9af 100644 --- a/OpenSim/Data/AssetDataBase.cs +++ b/OpenSim/Data/AssetDataBase.cs @@ -48,5 +48,6 @@ namespace OpenSim.Data public abstract void Initialise(string connect); public abstract void Initialise(); public abstract void Dispose(); + public abstract bool Delete(string id); } } diff --git a/OpenSim/Data/IAssetData.cs b/OpenSim/Data/IAssetData.cs index 2149bcac0a..90d5eeb489 100644 --- a/OpenSim/Data/IAssetData.cs +++ b/OpenSim/Data/IAssetData.cs @@ -38,6 +38,7 @@ namespace OpenSim.Data bool ExistsAsset(UUID uuid); List FetchAssetMetadataSet(int start, int count); void Initialise(string connect); + bool Delete(string id); } public class AssetDataInitialiser : PluginInitialiserBase diff --git a/OpenSim/Data/MSSQL/MSSQLAssetData.cs b/OpenSim/Data/MSSQL/MSSQLAssetData.cs index d6ea26254a..8475b22022 100644 --- a/OpenSim/Data/MSSQL/MSSQLAssetData.cs +++ b/OpenSim/Data/MSSQL/MSSQLAssetData.cs @@ -322,6 +322,10 @@ namespace OpenSim.Data.MSSQL return retList; } + public override bool Delete(string id) + { + return false; + } #endregion } } diff --git a/OpenSim/Data/MySQL/MySQLAssetData.cs b/OpenSim/Data/MySQL/MySQLAssetData.cs index 5a2af4f9ac..35eed56813 100644 --- a/OpenSim/Data/MySQL/MySQLAssetData.cs +++ b/OpenSim/Data/MySQL/MySQLAssetData.cs @@ -338,6 +338,24 @@ namespace OpenSim.Data.MySQL return retList; } + public override bool Delete(string id) + { + lock (m_dbLock) + { + using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) + { + dbcon.Open(); + MySqlCommand cmd = new MySqlCommand("delete from assets where id=?id"); + cmd.Parameters.AddWithValue("?id", id); + cmd.ExecuteNonQuery(); + + cmd.Dispose(); + } + } + + return true; + } + #endregion } } diff --git a/OpenSim/Data/SQLite/SQLiteAssetData.cs b/OpenSim/Data/SQLite/SQLiteAssetData.cs index 636bf8645b..9b938fab73 100644 --- a/OpenSim/Data/SQLite/SQLiteAssetData.cs +++ b/OpenSim/Data/SQLite/SQLiteAssetData.cs @@ -338,6 +338,11 @@ namespace OpenSim.Data.SQLite get { return "SQLite Asset storage engine"; } } + public override bool Delete(string id) + { + return false; + } + #endregion } } diff --git a/OpenSim/Data/SQLiteLegacy/SQLiteAssetData.cs b/OpenSim/Data/SQLiteLegacy/SQLiteAssetData.cs index 0d63deacd8..df509023eb 100644 --- a/OpenSim/Data/SQLiteLegacy/SQLiteAssetData.cs +++ b/OpenSim/Data/SQLiteLegacy/SQLiteAssetData.cs @@ -338,6 +338,10 @@ namespace OpenSim.Data.SQLiteLegacy get { return "SQLite Asset storage engine"; } } + public override bool Delete(string id) + { + return false; + } #endregion } -} \ No newline at end of file +} diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index f7eb292091..b6425f4c49 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -59,9 +59,11 @@ namespace OpenSim.Server.Handlers.Asset m_AssetService = ServerUtils.LoadPlugin(assetService, args); + bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false); + server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); - server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService)); + server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowDelete)); } } } diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs index f33bb90fde..8014fb5354 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs @@ -47,11 +47,13 @@ namespace OpenSim.Server.Handlers.Asset // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAssetService m_AssetService; + protected bool m_allowDelete; - public AssetServerDeleteHandler(IAssetService service) : + public AssetServerDeleteHandler(IAssetService service, bool allowDelete) : base("DELETE", "/assets") { m_AssetService = service; + m_allowDelete = allowDelete; } public override byte[] Handle(string path, Stream request, @@ -61,9 +63,9 @@ namespace OpenSim.Server.Handlers.Asset string[] p = SplitParams(path); - if (p.Length > 0) + if (p.Length > 0 && m_allowDelete) { - // result = m_AssetService.Delete(p[0]); + result = m_AssetService.Delete(p[0]); } XmlSerializer xs = new XmlSerializer(typeof(bool)); diff --git a/OpenSim/Services/AssetService/AssetService.cs b/OpenSim/Services/AssetService/AssetService.cs index 2114933ec7..4fc38f3173 100644 --- a/OpenSim/Services/AssetService/AssetService.cs +++ b/OpenSim/Services/AssetService/AssetService.cs @@ -156,6 +156,17 @@ namespace OpenSim.Services.AssetService public bool Delete(string id) { + UUID assetID; + if (!UUID.TryParse(id, out assetID)) + return false; + + AssetBase asset = m_Database.GetAsset(assetID); + if (asset == null) + return false; + + if ((int)(asset.Flags & AssetFlags.Maptile) != 0) + return m_Database.Delete(id); + return false; } diff --git a/OpenSim/Tests/Common/Mock/MockAssetDataPlugin.cs b/OpenSim/Tests/Common/Mock/MockAssetDataPlugin.cs index cc1dfbf02a..4a15cf2d64 100644 --- a/OpenSim/Tests/Common/Mock/MockAssetDataPlugin.cs +++ b/OpenSim/Tests/Common/Mock/MockAssetDataPlugin.cs @@ -60,5 +60,10 @@ namespace OpenSim.Tests.Common.Mock } public List FetchAssetMetadataSet(int start, int count) { return new List(count); } + + public bool Delete(string id) + { + return false; + } } -} \ No newline at end of file +} diff --git a/bin/Robust.ini.example b/bin/Robust.ini.example index 502a8e656a..f1b91269a7 100644 --- a/bin/Robust.ini.example +++ b/bin/Robust.ini.example @@ -40,6 +40,7 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003 LocalServiceModule = "OpenSim.Services.AssetService.dll:AssetService" DefaultAssetLoader = "OpenSim.Framework.AssetLoader.Filesystem.dll" AssetLoaderArgs = "assets/AssetSets.xml" + AllowRemoteDelete = "false" ; * This configuration loads the inventory server modules. It duplicates ; * the function of the legacy inventory server From bc6995f92123ff29fdfd6f811d3d252d99284527 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 9 May 2010 18:02:36 +0100 Subject: [PATCH 2/2] Add Delete handler to SQLite (NG) --- OpenSim/Data/SQLite/SQLiteAssetData.cs | 31 +++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/OpenSim/Data/SQLite/SQLiteAssetData.cs b/OpenSim/Data/SQLite/SQLiteAssetData.cs index 9b938fab73..2783ba1556 100644 --- a/OpenSim/Data/SQLite/SQLiteAssetData.cs +++ b/OpenSim/Data/SQLite/SQLiteAssetData.cs @@ -207,20 +207,6 @@ namespace OpenSim.Data.SQLite } } - /// - /// Delete an asset from database - /// - /// - public void DeleteAsset(UUID uuid) - { - using (SqliteCommand cmd = new SqliteCommand(DeleteAssetSQL, m_conn)) - { - cmd.Parameters.Add(new SqliteParameter(":UUID", uuid.ToString())); - - cmd.ExecuteNonQuery(); - } - } - /// /// /// @@ -340,7 +326,22 @@ namespace OpenSim.Data.SQLite public override bool Delete(string id) { - return false; + UUID assetID; + + if (!UUID.TryParse(id, out assetID)) + return false; + + lock (this) + { + using (SqliteCommand cmd = new SqliteCommand(DeleteAssetSQL, m_conn)) + { + cmd.Parameters.Add(new SqliteParameter(":UUID", assetID.ToString())); + + cmd.ExecuteNonQuery(); + } + } + + return true; } #endregion