From 51e487a172d97d17e3a02f8f3479af24a1d1ae41 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 19 Aug 2009 12:02:57 -0700 Subject: Makes the inventory connectors fully compatible with the old Grid.InventoryServer. WARNING: interacting with the old server is _much_ slower than interacting with the new one. Grids with the old server will not see any improvements on crossings and TPs, because inventory needs to be fetched from it in its entirety. --- .../Inventory/InventoryServiceConnector.cs | 64 ++++++++++++---------- 1 file changed, 35 insertions(+), 29 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs b/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs index bcf9d87..b573a06 100644 --- a/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs +++ b/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs @@ -178,30 +178,36 @@ namespace OpenSim.Services.Connectors catch (Exception e) { // Maybe we're talking to an old inventory server. Try this other thing. - m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetSystemFolders operation failed, {0} {1}. Trying RootFolders.", + m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetSystemFolders operation failed, {0} {1} (old sever?). Trying GetInventory.", e.Source, e.Message); try { - folders = SynchronousRestSessionObjectPoster>.BeginPostObject( - "POST", m_ServerURI + "/RootFolders/", new Guid(userID), sessionID.ToString(), userID.ToString()); + InventoryCollection inventory = SynchronousRestSessionObjectPoster.BeginPostObject( + "POST", m_ServerURI + "/GetInventory/", new Guid(userID), sessionID.ToString(), userID.ToString()); + folders = inventory.Folders; } catch (Exception ex) { - m_log.ErrorFormat("[INVENTORY CONNECTOR]: RootFolders operation also failed, {0} {1}. Give up.", + m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetInventory operation also failed, {0} {1}. Giving up.", e.Source, ex.Message); } if ((folders != null) && (folders.Count > 0)) { - dFolders[AssetType.Folder] = folders[0]; // Root folder is the first one - folders.RemoveAt(0); + m_log.DebugFormat("[INVENTORY CONNECTOR]: Received entire inventory ({0} folders) for user {1}", + folders.Count, userID); foreach (InventoryFolderBase f in folders) { if ((f.Type != (short)AssetType.Folder) && (f.Type != (short)AssetType.Unknown)) dFolders[(AssetType)f.Type] = f; } + UUID rootFolderID = dFolders[AssetType.Animation].ParentID; + InventoryFolderBase rootFolder = new InventoryFolderBase(rootFolderID, new UUID(userID)); + rootFolder = QueryFolder(userID, rootFolder, sessionID); + dFolders[AssetType.Folder] = rootFolder; + m_log.DebugFormat("[INVENTORY CONNECTOR]: {0} system folders for user {1}", dFolders.Count, userID); return dFolders; } } @@ -226,48 +232,48 @@ namespace OpenSim.Services.Connectors catch (Exception e) { // Maybe we're talking to an old inventory server. Try this other thing. - m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetFolderForType operation failed, {0} {1}. Trying RootFolders and GetItems.", + m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetFolderContent operation failed, {0} {1} (old server?). Trying GetInventory.", e.Source, e.Message); + InventoryCollection inventory; List folders = null; try { - folders = SynchronousRestSessionObjectPoster>.BeginPostObject( - "POST", m_ServerURI + "/RootFolders/", new Guid(userID), sessionID.ToString(), userID.ToString()); + inventory = SynchronousRestSessionObjectPoster.BeginPostObject( + "POST", m_ServerURI + "/GetInventory/", new Guid(userID), sessionID.ToString(), userID.ToString()); + if (inventory != null) + folders = inventory.Folders; } catch (Exception ex) { - m_log.ErrorFormat("[INVENTORY CONNECTOR]: RootFolders operation also failed, {0} {1}. Give up.", + m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetInventory operation also failed, {0} {1}. Giving up.", e.Source, ex.Message); + return new InventoryCollection(); } if ((folders != null) && (folders.Count > 0)) { - folders = folders.FindAll(delegate (InventoryFolderBase f) { return f.ParentID == folderID ; }); + m_log.DebugFormat("[INVENTORY CONNECTOR]: Received entire inventory ({0} folders) for user {1}", + folders.Count, userID); - try + folders = folders.FindAll(delegate(InventoryFolderBase f) { return f.ParentID == folderID; }); + List items = inventory.Items; + if (items != null) { - List items = SynchronousRestSessionObjectPoster>.BeginPostObject( - "POST", m_ServerURI + "/GetItems/", folderID.Guid, sessionID.ToString(), userID.ToString()); - - if (items != null) - { - InventoryCollection result = new InventoryCollection(); - result.Folders = folders; - result.Items = items; - result.UserID = new UUID(userID); - return result; - } - } - catch (Exception ex) - { - m_log.ErrorFormat("[INVENTORY CONNECTOR]: QueryFolder and GetItems operation failed, {0} {1}. Give up.", - e.Source, ex.Message); + items = items.FindAll(delegate(InventoryItemBase i) { return i.Folder == folderID; }); } + + inventory.Items = items; + inventory.Folders = folders; + return inventory; } } - return null; + InventoryCollection nullCollection = new InventoryCollection(); + nullCollection.Folders = new List(); + nullCollection.Items = new List(); + nullCollection.UserID = new UUID(userID); + return nullCollection; } public bool AddFolder(string userID, InventoryFolderBase folder, UUID sessionID) -- cgit v1.1 From c295354ea035c7e62f8a2c58868d2303a3ede883 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 19 Aug 2009 16:15:04 -0700 Subject: Fixes GetRootFolder for normal standalone, which was being incorrectly redirected to the wrong object. Probably fixes most grief in http://opensimulator.org/mantis/view.php?id=4035 http://opensimulator.org/mantis/view.php?id=4027 --- .../Inventory/LocalInventoryServiceConnector.cs | 6 +++--- OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs index 562c5dd..e6edcf2 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs @@ -191,7 +191,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory public override Dictionary GetSystemFolders(UUID userID) { - InventoryFolderBase root = GetRootFolder(userID); + InventoryFolderBase root = m_InventoryService.GetRootFolder(userID); if (root != null) { InventoryCollection content = GetFolderContent(userID, root.ID); @@ -202,13 +202,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory { if ((folder.Type != (short)AssetType.Folder) && (folder.Type != (short)AssetType.Unknown)) { - m_log.InfoFormat("[INVENTORY CONNECTOR]: folder type {0} ", folder.Type); + //m_log.InfoFormat("[INVENTORY CONNECTOR]: folder type {0} ", folder.Type); folders[(AssetType)folder.Type] = folder; } } // Put the root folder there, as type Folder folders[AssetType.Folder] = root; - m_log.InfoFormat("[INVENTORY CONNECTOR]: root folder is type {0} ", root.Type); + //m_log.InfoFormat("[INVENTORY CONNECTOR]: root folder is type {0} ", root.Type); return folders; } diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index a119efc..a9d361b 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -179,8 +179,8 @@ namespace OpenSim.Region.Framework.Scenes else { m_log.ErrorFormat( - "[AGENT INVENTORY]: Could not resolve user {0} for caps inventory update", - remoteClient.AgentId); + "[AGENT INVENTORY]: Could not find item {0} for caps inventory update", + itemID); } return UUID.Zero; -- cgit v1.1 From f1287cc7af7da26910c5cba456a8c35b6454d815 Mon Sep 17 00:00:00 2001 From: Kunnis Date: Sun, 16 Aug 2009 18:54:20 -0500 Subject: * Switching IAssetData to follow the new naming schema, removing the separate insert and update methods. --- OpenSim/Data/AssetDataBase.cs | 10 +---- OpenSim/Data/IAssetData.cs | 5 +-- OpenSim/Data/MSSQL/MSSQLAssetData.cs | 19 ++++++--- OpenSim/Data/MySQL/MySQLAssetData.cs | 13 +----- OpenSim/Data/NHibernate/NHibernateAssetData.cs | 24 +++++------ OpenSim/Data/SQLite/SQLiteAssetData.cs | 47 +++++++++------------- OpenSim/Data/Tests/BasicAssetTest.cs | 24 +++++------ OpenSim/Framework/Servers/GetAssetStreamHandler.cs | 2 +- .../Framework/Servers/PostAssetStreamHandler.cs | 2 +- .../Servers/Tests/GetAssetStreamHandlerTests.cs | 2 +- .../Plugins/OpenSim/OpenSimAssetStoragePlugin.cs | 8 ++-- OpenSim/Grid/AssetServer/Main.cs | 2 +- OpenSim/Services/AssetService/AssetService.cs | 10 ++--- 13 files changed, 73 insertions(+), 95 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Data/AssetDataBase.cs b/OpenSim/Data/AssetDataBase.cs index f723ebf..5deb44e 100644 --- a/OpenSim/Data/AssetDataBase.cs +++ b/OpenSim/Data/AssetDataBase.cs @@ -36,15 +36,9 @@ namespace OpenSim.Data { public abstract class AssetDataBase : IAssetDataPlugin { - public virtual AssetBase FetchAsset(UUID uuid) - { - return FetchStoredAsset(uuid); - } - - protected abstract AssetBase FetchStoredAsset(UUID uuid); + public abstract AssetBase GetAsset(UUID uuid); - public abstract void CreateAsset(AssetBase asset); - public abstract void UpdateAsset(AssetBase asset); + public abstract void StoreAsset(AssetBase asset); public abstract bool ExistsAsset(UUID uuid); public abstract List FetchAssetMetadataSet(int start, int count); diff --git a/OpenSim/Data/IAssetData.cs b/OpenSim/Data/IAssetData.cs index d13732b..2149bca 100644 --- a/OpenSim/Data/IAssetData.cs +++ b/OpenSim/Data/IAssetData.cs @@ -33,9 +33,8 @@ namespace OpenSim.Data { public interface IAssetDataPlugin : IPlugin { - AssetBase FetchAsset(UUID uuid); - void CreateAsset(AssetBase asset); - void UpdateAsset(AssetBase asset); + AssetBase GetAsset(UUID uuid); + void StoreAsset(AssetBase asset); bool ExistsAsset(UUID uuid); List FetchAssetMetadataSet(int start, int count); void Initialise(string connect); diff --git a/OpenSim/Data/MSSQL/MSSQLAssetData.cs b/OpenSim/Data/MSSQL/MSSQLAssetData.cs index a542584..d193cf5 100644 --- a/OpenSim/Data/MSSQL/MSSQLAssetData.cs +++ b/OpenSim/Data/MSSQL/MSSQLAssetData.cs @@ -122,7 +122,7 @@ namespace OpenSim.Data.MSSQL /// /// the asset UUID /// - override protected AssetBase FetchStoredAsset(UUID assetID) + override public AssetBase GetAsset(UUID assetID) { string sql = "SELECT * FROM assets WHERE id = @id"; using (AutoClosingSqlCommand command = m_database.Query(sql)) @@ -152,7 +152,16 @@ namespace OpenSim.Data.MSSQL /// Create asset in m_database /// /// the asset - override public void CreateAsset(AssetBase asset) + override public void StoreAsset(AssetBase asset) + { + if (ExistsAsset(asset.FullID)) + UpdateAsset(asset); + else + InsertAsset(asset); + } + + + private void InsertAsset(AssetBase asset) { if (ExistsAsset(asset.FullID)) { @@ -208,7 +217,7 @@ namespace OpenSim.Data.MSSQL /// Update asset in m_database /// /// the asset - override public void UpdateAsset(AssetBase asset) + private void UpdateAsset(AssetBase asset) { string sql = @"UPDATE assets set id = @id, name = @name, description = @description, assetType = @assetType, local = @local, temporary = @temporary, data = @data @@ -250,7 +259,7 @@ namespace OpenSim.Data.MSSQL } } -// Commented out since currently unused - this probably should be called in FetchAsset() +// Commented out since currently unused - this probably should be called in GetAsset() // private void UpdateAccessTime(AssetBase asset) // { // using (AutoClosingSqlCommand cmd = m_database.Query("UPDATE assets SET access_time = @access_time WHERE id=@id")) @@ -276,7 +285,7 @@ namespace OpenSim.Data.MSSQL /// true if exist. override public bool ExistsAsset(UUID uuid) { - if (FetchAsset(uuid) != null) + if (GetAsset(uuid) != null) { return true; } diff --git a/OpenSim/Data/MySQL/MySQLAssetData.cs b/OpenSim/Data/MySQL/MySQLAssetData.cs index 0865083..1b4377a 100644 --- a/OpenSim/Data/MySQL/MySQLAssetData.cs +++ b/OpenSim/Data/MySQL/MySQLAssetData.cs @@ -135,7 +135,7 @@ namespace OpenSim.Data.MySQL /// Asset UUID to fetch /// Return the asset /// On failure : throw an exception and attempt to reconnect to database - override protected AssetBase FetchStoredAsset(UUID assetID) + override public AssetBase GetAsset(UUID assetID) { AssetBase asset = null; lock (_dbConnection) @@ -192,7 +192,7 @@ namespace OpenSim.Data.MySQL /// /// Asset UUID to create /// On failure : Throw an exception and attempt to reconnect to database - override public void CreateAsset(AssetBase asset) + override public void StoreAsset(AssetBase asset) { lock (_dbConnection) { @@ -285,15 +285,6 @@ namespace OpenSim.Data.MySQL } /// - /// Update a asset in database, see - /// - /// Asset UUID to update - override public void UpdateAsset(AssetBase asset) - { - CreateAsset(asset); - } - - /// /// check if the asset UUID exist in database /// /// The asset UUID diff --git a/OpenSim/Data/NHibernate/NHibernateAssetData.cs b/OpenSim/Data/NHibernate/NHibernateAssetData.cs index 9d8cec5..aaba15c 100644 --- a/OpenSim/Data/NHibernate/NHibernateAssetData.cs +++ b/OpenSim/Data/NHibernate/NHibernateAssetData.cs @@ -65,30 +65,24 @@ namespace OpenSim.Data.NHibernate } - override protected AssetBase FetchStoredAsset(UUID uuid) + override public AssetBase GetAsset(UUID uuid) { return (AssetBase)manager.Get(typeof(AssetBase), uuid); } - private void Save(AssetBase asset) + override public void StoreAsset(AssetBase asset) { AssetBase temp = (AssetBase)manager.Get(typeof(AssetBase), asset.FullID); if (temp == null) { + m_log.InfoFormat("[NHIBERNATE] inserting asset {0}", asset.FullID); manager.Insert(asset); } - } - - override public void CreateAsset(AssetBase asset) - { - m_log.InfoFormat("[NHIBERNATE] inserting asset {0}", asset.FullID); - Save(asset); - } - - override public void UpdateAsset(AssetBase asset) - { - m_log.InfoFormat("[NHIBERNATE] updating asset {0}", asset.FullID); - manager.Update(asset); + else + { + m_log.InfoFormat("[NHIBERNATE] updating asset {0}", asset.FullID); + manager.Update(asset); + } } // private void LogAssetLoad(AssetBase asset) @@ -107,7 +101,7 @@ namespace OpenSim.Data.NHibernate override public bool ExistsAsset(UUID uuid) { m_log.InfoFormat("[NHIBERNATE] ExistsAsset: {0}", uuid); - return (FetchAsset(uuid) != null); + return (GetAsset(uuid) != null); } /// diff --git a/OpenSim/Data/SQLite/SQLiteAssetData.cs b/OpenSim/Data/SQLite/SQLiteAssetData.cs index 72af7a0..3831467 100644 --- a/OpenSim/Data/SQLite/SQLiteAssetData.cs +++ b/OpenSim/Data/SQLite/SQLiteAssetData.cs @@ -90,7 +90,7 @@ namespace OpenSim.Data.SQLite /// /// UUID of ... ? /// Asset base - override protected AssetBase FetchStoredAsset(UUID uuid) + override public AssetBase GetAsset(UUID uuid) { lock (this) { @@ -119,18 +119,16 @@ namespace OpenSim.Data.SQLite /// Create an asset /// /// Asset Base - override public void CreateAsset(AssetBase asset) + override public void StoreAsset(AssetBase asset) { //m_log.Info("[ASSET DB]: Creating Asset " + asset.FullID.ToString()); if (ExistsAsset(asset.FullID)) { - //m_log.Info("[ASSET DB]: Asset exists already, ignoring."); - } - else - { + LogAssetLoad(asset); + lock (this) { - using (SqliteCommand cmd = new SqliteCommand(InsertAssetSQL, m_conn)) + using (SqliteCommand cmd = new SqliteCommand(UpdateAssetSQL, m_conn)) { cmd.Parameters.Add(new SqliteParameter(":UUID", asset.FullID.ToString())); cmd.Parameters.Add(new SqliteParameter(":Name", asset.Name)); @@ -144,29 +142,22 @@ namespace OpenSim.Data.SQLite } } } - } - - /// - /// Update an asset - /// - /// - override public void UpdateAsset(AssetBase asset) - { - LogAssetLoad(asset); - - lock (this) + else { - using (SqliteCommand cmd = new SqliteCommand(UpdateAssetSQL, m_conn)) + lock (this) { - cmd.Parameters.Add(new SqliteParameter(":UUID", asset.FullID.ToString())); - cmd.Parameters.Add(new SqliteParameter(":Name", asset.Name)); - cmd.Parameters.Add(new SqliteParameter(":Description", asset.Description)); - cmd.Parameters.Add(new SqliteParameter(":Type", asset.Type)); - cmd.Parameters.Add(new SqliteParameter(":Local", asset.Local)); - cmd.Parameters.Add(new SqliteParameter(":Temporary", asset.Temporary)); - cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data)); - - cmd.ExecuteNonQuery(); + using (SqliteCommand cmd = new SqliteCommand(InsertAssetSQL, m_conn)) + { + cmd.Parameters.Add(new SqliteParameter(":UUID", asset.FullID.ToString())); + cmd.Parameters.Add(new SqliteParameter(":Name", asset.Name)); + cmd.Parameters.Add(new SqliteParameter(":Description", asset.Description)); + cmd.Parameters.Add(new SqliteParameter(":Type", asset.Type)); + cmd.Parameters.Add(new SqliteParameter(":Local", asset.Local)); + cmd.Parameters.Add(new SqliteParameter(":Temporary", asset.Temporary)); + cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data)); + + cmd.ExecuteNonQuery(); + } } } } diff --git a/OpenSim/Data/Tests/BasicAssetTest.cs b/OpenSim/Data/Tests/BasicAssetTest.cs index 09131c1..1969d76 100644 --- a/OpenSim/Data/Tests/BasicAssetTest.cs +++ b/OpenSim/Data/Tests/BasicAssetTest.cs @@ -84,34 +84,34 @@ namespace OpenSim.Data.Tests scrambler.Scramble(a2); scrambler.Scramble(a3); - db.CreateAsset(a1); - db.CreateAsset(a2); - db.CreateAsset(a3); + db.StoreAsset(a1); + db.StoreAsset(a2); + db.StoreAsset(a3); - AssetBase a1a = db.FetchAsset(uuid1); + AssetBase a1a = db.GetAsset(uuid1); Assert.That(a1a, Constraints.PropertyCompareConstraint(a1)); - AssetBase a2a = db.FetchAsset(uuid2); + AssetBase a2a = db.GetAsset(uuid2); Assert.That(a2a, Constraints.PropertyCompareConstraint(a2)); - AssetBase a3a = db.FetchAsset(uuid3); + AssetBase a3a = db.GetAsset(uuid3); Assert.That(a3a, Constraints.PropertyCompareConstraint(a3)); scrambler.Scramble(a1a); scrambler.Scramble(a2a); scrambler.Scramble(a3a); - db.UpdateAsset(a1a); - db.UpdateAsset(a2a); - db.UpdateAsset(a3a); + db.StoreAsset(a1a); + db.StoreAsset(a2a); + db.StoreAsset(a3a); - AssetBase a1b = db.FetchAsset(uuid1); + AssetBase a1b = db.GetAsset(uuid1); Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a)); - AssetBase a2b = db.FetchAsset(uuid2); + AssetBase a2b = db.GetAsset(uuid2); Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a)); - AssetBase a3b = db.FetchAsset(uuid3); + AssetBase a3b = db.GetAsset(uuid3); Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a)); Assert.That(db.ExistsAsset(uuid1), Is.True); diff --git a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs index bc046cf..c6958de 100644 --- a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs +++ b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs @@ -57,7 +57,7 @@ namespace OpenSim.Framework.Servers protected override AssetBase GetAsset(UUID assetID) { - return m_assetProvider.FetchAsset(assetID); + return m_assetProvider.GetAsset(assetID); } } } diff --git a/OpenSim/Framework/Servers/PostAssetStreamHandler.cs b/OpenSim/Framework/Servers/PostAssetStreamHandler.cs index 419b408..8bf406c 100644 --- a/OpenSim/Framework/Servers/PostAssetStreamHandler.cs +++ b/OpenSim/Framework/Servers/PostAssetStreamHandler.cs @@ -57,7 +57,7 @@ namespace OpenSim.Framework.Servers AssetBase asset = (AssetBase) xs.Deserialize(request); m_log.InfoFormat("[REST]: Creating asset {0}", asset.FullID); - m_assetProvider.CreateAsset(asset); + m_assetProvider.StoreAsset(asset); return new byte[] {}; } diff --git a/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs b/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs index 35da73f..be3f518 100644 --- a/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs +++ b/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs @@ -128,7 +128,7 @@ namespace OpenSim.Framework.Servers.Tests IAssetDataPlugin assetDataPlugin = new TestAssetDataPlugin(); handler = new GetAssetStreamHandler(assetDataPlugin); - assetDataPlugin.CreateAsset(asset); + assetDataPlugin.StoreAsset(asset); return asset; } } diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs index 0631ee7..92ac84f 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs @@ -57,7 +57,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim metadata = null; BackendResponse ret; - AssetBase asset = m_assetProvider.FetchAsset(assetID); + AssetBase asset = m_assetProvider.GetAsset(assetID); if (asset == null) ret = BackendResponse.NotFound; else @@ -75,7 +75,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim assetData = null; BackendResponse ret; - AssetBase asset = m_assetProvider.FetchAsset(assetID); + AssetBase asset = m_assetProvider.GetAsset(assetID); if (asset == null) ret = BackendResponse.NotFound; else @@ -90,7 +90,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim public BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset) { - asset = m_assetProvider.FetchAsset(assetID); + asset = m_assetProvider.GetAsset(assetID); if (asset == null) return BackendResponse.NotFound; @@ -107,7 +107,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim { BackendResponse ret; - m_assetProvider.CreateAsset(asset); + m_assetProvider.StoreAsset(asset); ret = BackendResponse.Success; m_server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, asset.FullID, asset.Data.Length, DateTime.Now); diff --git a/OpenSim/Grid/AssetServer/Main.cs b/OpenSim/Grid/AssetServer/Main.cs index f25e847..ac8f888 100644 --- a/OpenSim/Grid/AssetServer/Main.cs +++ b/OpenSim/Grid/AssetServer/Main.cs @@ -140,7 +140,7 @@ namespace OpenSim.Grid.AssetServer protected void StoreAsset(AssetBase asset) { - m_assetProvider.CreateAsset(asset); + m_assetProvider.StoreAsset(asset); } } } diff --git a/OpenSim/Services/AssetService/AssetService.cs b/OpenSim/Services/AssetService/AssetService.cs index fe663eb..88a905c 100644 --- a/OpenSim/Services/AssetService/AssetService.cs +++ b/OpenSim/Services/AssetService/AssetService.cs @@ -83,7 +83,7 @@ namespace OpenSim.Services.AssetService if (!UUID.TryParse(id, out assetID)) return null; - return m_Database.FetchAsset(assetID); + return m_Database.GetAsset(assetID); } public AssetMetadata GetMetadata(string id) @@ -93,7 +93,7 @@ namespace OpenSim.Services.AssetService if (!UUID.TryParse(id, out assetID)) return null; - AssetBase asset = m_Database.FetchAsset(assetID); + AssetBase asset = m_Database.GetAsset(assetID); return asset.Metadata; } @@ -104,7 +104,7 @@ namespace OpenSim.Services.AssetService if (!UUID.TryParse(id, out assetID)) return null; - AssetBase asset = m_Database.FetchAsset(assetID); + AssetBase asset = m_Database.GetAsset(assetID); return asset.Data; } @@ -117,7 +117,7 @@ namespace OpenSim.Services.AssetService if (!UUID.TryParse(id, out assetID)) return false; - AssetBase asset = m_Database.FetchAsset(assetID); + AssetBase asset = m_Database.GetAsset(assetID); //m_log.DebugFormat("[AssetService]: Got asset {0}", asset); @@ -129,7 +129,7 @@ namespace OpenSim.Services.AssetService public string Store(AssetBase asset) { //m_log.DebugFormat("[ASSET SERVICE]: Store asset {0} {1}", asset.Name, asset.ID); - m_Database.CreateAsset(asset); + m_Database.StoreAsset(asset); return asset.ID; } -- cgit v1.1 From b1853d9f265fb32cf51d65fdcf2d5b4741911f00 Mon Sep 17 00:00:00 2001 From: Kunnis Date: Sun, 16 Aug 2009 23:25:12 -0500 Subject: Fixing a spot I missed in assets. Switching Grid to the new naming schema with Store/Get --- OpenSim/Data/GridDataBase.cs | 3 +-- OpenSim/Data/IGridData.cs | 11 ++------- OpenSim/Data/MSSQL/MSSQLGridData.cs | 27 ++++++++++------------ OpenSim/Data/MySQL/MySQLGridData.cs | 13 +---------- OpenSim/Data/NHibernate/NHibernateGridData.cs | 14 +---------- OpenSim/Data/SQLite/SQLiteGridData.cs | 10 ++------ OpenSim/Data/Tests/BasicGridTest.cs | 8 +++---- .../Cache/UserProfileCacheService.cs | 2 +- .../Tests/Cache/UserProfileCacheServiceTests.cs | 4 ++-- OpenSim/Grid/GridServer.Modules/GridDBService.cs | 6 ++--- OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs | 13 +++++++++++ 11 files changed, 42 insertions(+), 69 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Data/GridDataBase.cs b/OpenSim/Data/GridDataBase.cs index 5a30455..a03488b 100644 --- a/OpenSim/Data/GridDataBase.cs +++ b/OpenSim/Data/GridDataBase.cs @@ -38,9 +38,8 @@ namespace OpenSim.Data public abstract RegionProfileData[] GetProfilesInRange(uint Xmin, uint Ymin, uint Xmax, uint Ymax); public abstract List GetRegionsByName(string namePrefix, uint maxNum); public abstract bool AuthenticateSim(UUID UUID, ulong regionHandle, string simrecvkey); - public abstract DataResponse AddProfile(RegionProfileData profile); + public abstract DataResponse StoreProfile(RegionProfileData profile); public abstract ReservationData GetReservationAtPoint(uint x, uint y); - public abstract DataResponse UpdateProfile(RegionProfileData profile); public abstract DataResponse DeleteProfile(string uuid); public abstract void Initialise(); diff --git a/OpenSim/Data/IGridData.cs b/OpenSim/Data/IGridData.cs index 4bf8646..8bd3811 100644 --- a/OpenSim/Data/IGridData.cs +++ b/OpenSim/Data/IGridData.cs @@ -99,18 +99,11 @@ namespace OpenSim.Data bool AuthenticateSim(UUID UUID, ulong regionHandle, string simrecvkey); /// - /// Adds a new profile to the database + /// Adds or updates a profile in the database /// /// The profile to add /// RESPONSE_OK if successful, error if not. - DataResponse AddProfile(RegionProfileData profile); - - /// - /// Updates a profile in the database - /// - /// - /// - DataResponse UpdateProfile(RegionProfileData profile); + DataResponse StoreProfile(RegionProfileData profile); /// /// Remove a profile from the database diff --git a/OpenSim/Data/MSSQL/MSSQLGridData.cs b/OpenSim/Data/MSSQL/MSSQLGridData.cs index 0ebbf4e..8a3d332 100644 --- a/OpenSim/Data/MSSQL/MSSQLGridData.cs +++ b/OpenSim/Data/MSSQL/MSSQLGridData.cs @@ -272,26 +272,23 @@ namespace OpenSim.Data.MSSQL /// /// The profile to add /// A dataresponse enum indicating success - override public DataResponse AddProfile(RegionProfileData profile) + override public DataResponse StoreProfile(RegionProfileData profile) { - if (InsertRegionRow(profile)) + if (GetProfileByUUID(profile.UUID) == null) { - return DataResponse.RESPONSE_OK; + if (InsertRegionRow(profile)) + { + return DataResponse.RESPONSE_OK; + } } - return DataResponse.RESPONSE_ERROR; - } - - /// - /// Update the specified region in the database - /// - /// The profile to update - /// A dataresponse enum indicating success - override public DataResponse UpdateProfile(RegionProfileData profile) - { - if (UpdateRegionRow(profile)) + else { - return DataResponse.RESPONSE_OK; + if (UpdateRegionRow(profile)) + { + return DataResponse.RESPONSE_OK; + } } + return DataResponse.RESPONSE_ERROR; } diff --git a/OpenSim/Data/MySQL/MySQLGridData.cs b/OpenSim/Data/MySQL/MySQLGridData.cs index 0a5800b..1ec2609 100644 --- a/OpenSim/Data/MySQL/MySQLGridData.cs +++ b/OpenSim/Data/MySQL/MySQLGridData.cs @@ -391,7 +391,7 @@ namespace OpenSim.Data.MySQL /// /// The profile to add /// Successful? - override public DataResponse AddProfile(RegionProfileData profile) + override public DataResponse StoreProfile(RegionProfileData profile) { MySQLSuperManager dbm = GetLockedConnection(); try { @@ -408,17 +408,6 @@ namespace OpenSim.Data.MySQL } /// - /// Update a sim profile - /// - /// The profile to update - /// Sucessful? - /// Same as AddProfile - override public DataResponse UpdateProfile(RegionProfileData profile) - { - return AddProfile(profile); - } - - /// /// Deletes a sim profile from the database /// /// the sim UUID diff --git a/OpenSim/Data/NHibernate/NHibernateGridData.cs b/OpenSim/Data/NHibernate/NHibernateGridData.cs index fe8da59..018af62 100644 --- a/OpenSim/Data/NHibernate/NHibernateGridData.cs +++ b/OpenSim/Data/NHibernate/NHibernateGridData.cs @@ -117,7 +117,7 @@ namespace OpenSim.Data.NHibernate throw new NotImplementedException(); } - public override DataResponse AddProfile(RegionProfileData profile) + public override DataResponse StoreProfile(RegionProfileData profile) { if (manager.Get(typeof(RegionProfileData), profile.Uuid) == null) { @@ -126,21 +126,9 @@ namespace OpenSim.Data.NHibernate } else { - return DataResponse.RESPONSE_ERROR; - } - } - - public override DataResponse UpdateProfile(RegionProfileData profile) - { - if (manager.Get(typeof(RegionProfileData), profile.Uuid) != null) - { manager.Update(profile); return DataResponse.RESPONSE_OK; } - else - { - return DataResponse.RESPONSE_ERROR; - } } public override DataResponse DeleteProfile(string uuid) diff --git a/OpenSim/Data/SQLite/SQLiteGridData.cs b/OpenSim/Data/SQLite/SQLiteGridData.cs index 4107594..18abb88 100644 --- a/OpenSim/Data/SQLite/SQLiteGridData.cs +++ b/OpenSim/Data/SQLite/SQLiteGridData.cs @@ -203,7 +203,7 @@ namespace OpenSim.Data.SQLite /// /// The profile to add /// A dataresponse enum indicating success - override public DataResponse AddProfile(RegionProfileData profile) + override public DataResponse StoreProfile(RegionProfileData profile) { if (database.insertRow(profile)) { @@ -215,17 +215,11 @@ namespace OpenSim.Data.SQLite } } - override public DataResponse UpdateProfile(RegionProfileData profile) - { - return AddProfile(profile); - } - - /// + /// /// Deletes a sim profile from the database /// /// the sim UUID /// Successful? - //public DataResponse DeleteProfile(RegionProfileData profile) override public DataResponse DeleteProfile(string uuid) { Dictionary param = new Dictionary(); diff --git a/OpenSim/Data/Tests/BasicGridTest.cs b/OpenSim/Data/Tests/BasicGridTest.cs index de8fb48..df6c669 100644 --- a/OpenSim/Data/Tests/BasicGridTest.cs +++ b/OpenSim/Data/Tests/BasicGridTest.cs @@ -70,7 +70,7 @@ namespace OpenSim.Data.Tests reg.Uuid = regionUUID; reg.RegionName = regionName; - db.AddProfile(reg); + db.StoreProfile(reg); return reg; } @@ -120,7 +120,7 @@ namespace OpenSim.Data.Tests RegionProfileData retreg = db.GetProfileByUUID(region2); retreg.regionName = "Gotham City"; - db.UpdateProfile(retreg); + db.StoreProfile(retreg); retreg = db.GetProfileByUUID(region2); Assert.That(retreg.RegionName, Is.EqualTo("Gotham City"), "Assert.That(retreg.RegionName, Is.EqualTo(\"Gotham City\"))"); @@ -135,13 +135,13 @@ namespace OpenSim.Data.Tests retreg.RegionName = "Gotham Town"; retreg.Uuid = region1; - db.AddProfile(retreg); + db.StoreProfile(retreg); retreg = db.GetProfileByUUID(region2); retreg.RegionName = "Gothan Town"; retreg.Uuid = region3; - db.AddProfile(retreg); + db.StoreProfile(retreg); List listreg = db.GetRegionsByName("Gotham",10); diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs index c9f5236..7f1c7e9 100644 --- a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs +++ b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs @@ -184,7 +184,7 @@ namespace OpenSim.Framework.Communications.Cache // Commented out for now. The implementation needs to be improved by protecting against race conditions, // probably by making sure that the update doesn't use the UserCacheInfo.UserProfile directly (possibly via // returning a read only class from the cache). -// public bool UpdateProfile(UserProfileData userProfile) +// public bool StoreProfile(UserProfileData userProfile) // { // lock (m_userProfilesById) // { diff --git a/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs b/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs index 670c9ff..933fa12 100644 --- a/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs +++ b/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs @@ -110,14 +110,14 @@ namespace OpenSim.Framework.Communications.Tests IUserDataPlugin userDataPlugin = commsManager.UserDataPlugin; // Check that we can't update info before it exists - Assert.That(userCacheService.UpdateProfile(newProfile), Is.False); + Assert.That(userCacheService.StoreProfile(newProfile), Is.False); Assert.That(userDataPlugin.GetUserByUUID(userId), Is.Null); // Check that we can update a profile once it exists LocalUserServices lus = (LocalUserServices)commsManager.UserService; lus.AddUser(firstName, originalLastName, "pingu", "ted@excellentadventure.com", 1000, 1000, userId); - Assert.That(userCacheService.UpdateProfile(newProfile), Is.True); + Assert.That(userCacheService.StoreProfile(newProfile), Is.True); UserProfileData retrievedProfile = userCacheService.GetUserDetails(userId).UserProfile; Assert.That(retrievedProfile.SurName, Is.EqualTo(newLastName)); Assert.That(userDataPlugin.GetUserByUUID(userId).SurName, Is.EqualTo(newLastName)); diff --git a/OpenSim/Grid/GridServer.Modules/GridDBService.cs b/OpenSim/Grid/GridServer.Modules/GridDBService.cs index caa2c10..fd5a09a 100644 --- a/OpenSim/Grid/GridServer.Modules/GridDBService.cs +++ b/OpenSim/Grid/GridServer.Modules/GridDBService.cs @@ -206,11 +206,11 @@ namespace OpenSim.Grid.GridServer.Modules { if (existingSim == null) { - insertResponse = plugin.AddProfile(sim); + insertResponse = plugin.StoreProfile(sim); } else { - insertResponse = plugin.UpdateProfile(sim); + insertResponse = plugin.StoreProfile(sim); } } catch (Exception e) @@ -259,7 +259,7 @@ namespace OpenSim.Grid.GridServer.Modules if ((reserveData != null && reserveData.gridRecvKey == theSim.regionRecvKey) || (reserveData == null && authkeynode.InnerText != theSim.regionRecvKey)) { - plugin.AddProfile(theSim); + plugin.StoreProfile(theSim); m_log.Info("[grid]: New sim added to grid (" + theSim.regionName + ")"); logToDB(theSim.ToString(), "RestSetSimMethod", String.Empty, 5, "Region successfully updated and connected to grid."); diff --git a/OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs b/OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs index 8ab72dc..3981fe9 100644 --- a/OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs +++ b/OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; using System.Collections.Generic; using OpenMetaverse; using OpenSim.Framework; @@ -46,6 +47,18 @@ namespace OpenSim.Tests.Common.Mock public void Initialise(string connect) {} public void Dispose() {} + private readonly List assets = new List(); + + public AssetBase GetAsset(UUID uuid) + { + return assets.Find(x=>x.FullID == uuid); + } + + public void StoreAsset(AssetBase asset) + { + assets.Add(asset); + } + public List FetchAssetMetadataSet(int start, int count) { return new List(count); } } } \ No newline at end of file -- cgit v1.1 From 6e35ddb0e9642e6719d5043da99d45f8885d13f0 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 19 Aug 2009 16:15:04 -0700 Subject: Fixes GetItem and GetFolder for SQLite. Turns out some methods were no-op in SQlite. Fixes most grief in http://opensimulator.org/mantis/view.php?id=4035 http://opensimulator.org/mantis/view.php?id=4027 --- OpenSim/Data/SQLite/SQLiteInventoryStore.cs | 4 ++-- .../Inventory/LocalInventoryServiceConnector.cs | 6 +++--- OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 4 ++-- OpenSim/Services/InventoryService/InventoryService.cs | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs index e5f7a50..64591fd 100644 --- a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs +++ b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs @@ -628,12 +628,12 @@ namespace OpenSim.Data.SQLite public InventoryItemBase queryInventoryItem(UUID itemID) { - return null; + return getInventoryItem(itemID); } public InventoryFolderBase queryInventoryFolder(UUID folderID) { - return null; + return getInventoryFolder(folderID); } /// diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs index 562c5dd..e6edcf2 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs @@ -191,7 +191,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory public override Dictionary GetSystemFolders(UUID userID) { - InventoryFolderBase root = GetRootFolder(userID); + InventoryFolderBase root = m_InventoryService.GetRootFolder(userID); if (root != null) { InventoryCollection content = GetFolderContent(userID, root.ID); @@ -202,13 +202,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory { if ((folder.Type != (short)AssetType.Folder) && (folder.Type != (short)AssetType.Unknown)) { - m_log.InfoFormat("[INVENTORY CONNECTOR]: folder type {0} ", folder.Type); + //m_log.InfoFormat("[INVENTORY CONNECTOR]: folder type {0} ", folder.Type); folders[(AssetType)folder.Type] = folder; } } // Put the root folder there, as type Folder folders[AssetType.Folder] = root; - m_log.InfoFormat("[INVENTORY CONNECTOR]: root folder is type {0} ", root.Type); + //m_log.InfoFormat("[INVENTORY CONNECTOR]: root folder is type {0} ", root.Type); return folders; } diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index a119efc..a9d361b 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -179,8 +179,8 @@ namespace OpenSim.Region.Framework.Scenes else { m_log.ErrorFormat( - "[AGENT INVENTORY]: Could not resolve user {0} for caps inventory update", - remoteClient.AgentId); + "[AGENT INVENTORY]: Could not find item {0} for caps inventory update", + itemID); } return UUID.Zero; diff --git a/OpenSim/Services/InventoryService/InventoryService.cs b/OpenSim/Services/InventoryService/InventoryService.cs index e0217f6..6310254 100644 --- a/OpenSim/Services/InventoryService/InventoryService.cs +++ b/OpenSim/Services/InventoryService/InventoryService.cs @@ -420,16 +420,16 @@ namespace OpenSim.Services.InventoryService public virtual InventoryItemBase GetItem(InventoryItemBase item) { - InventoryItemBase result = m_Database.queryInventoryItem(item.ID); + InventoryItemBase result = m_Database.getInventoryItem(item.ID); if (result != null) return result; - + m_log.DebugFormat("[INVENTORY SERVICE]: GetItem failed to find item {0}", item.ID); return null; } public virtual InventoryFolderBase GetFolder(InventoryFolderBase item) { - InventoryFolderBase result = m_Database.queryInventoryFolder(item.ID); + InventoryFolderBase result = m_Database.getInventoryFolder(item.ID); if (result != null) return result; -- cgit v1.1 From 948c7ea20b1e33ee3f3aceb87fff731ddbb3bf0e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 19 Aug 2009 18:08:20 -0700 Subject: Commented T021_TestCrossToNewRegion because (1) it can fail on panda, and (2) it is not a meaningful representation of region crossing. --- OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs index ce6f3d6..3ee6007 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs @@ -225,7 +225,14 @@ namespace OpenSim.Region.Framework.Scenes.Tests Assert.That(presence.AbsolutePosition, Is.EqualTo(pos), "Position is not the same one entered"); } - [Test] + // I'm commenting this test because it does not represent + // crossings. The Thread.Sleep's in here are not meaningful mocks, + // and they sometimes fail in panda. + // We need to talk in order to develop a test + // that really tests region crossings. There are 3 async components, + // but things are synchronous among them. So there should be + // 3 threads in here. + //[Test] public void T021_TestCrossToNewRegion() { TestHelper.InMethod(); -- cgit v1.1 From 1604c9d19e12602608dbb402382cde8302185efd Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 20 Aug 2009 10:14:53 -0700 Subject: One more place fixed for setting the inventory folder owner. Thanks jhurliman. --- OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs index 77b980c..d722e23 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs @@ -519,7 +519,7 @@ namespace OpenSim.Region.Framework.Scenes // m_log.DebugFormat( // "[AGENT INVENTORY]: Updating inventory folder {0} {1} for {2} {3}", folderID, name, remoteClient.Name, remoteClient.AgentId); - InventoryFolderBase folder = new InventoryFolderBase(folderID); + InventoryFolderBase folder = new InventoryFolderBase(folderID, remoteClient.AgentId); folder = InventoryService.GetFolder(folder); if (folder != null) { -- cgit v1.1 From ae2ceda479a2b223189b5eecedc46798e1152fcd Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Wed, 19 Aug 2009 12:41:57 -0700 Subject: * Only update TextureEntry in AvatarAppearance if the incoming XML-RPC has a valid TextureEntry. About half the time update_avatar_appearance calls are made, the TextureEntry is empty --- OpenSim/Framework/AvatarAppearance.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs index 7270f32..1fb01ba 100644 --- a/OpenSim/Framework/AvatarAppearance.cs +++ b/OpenSim/Framework/AvatarAppearance.cs @@ -503,7 +503,14 @@ namespace OpenSim.Framework Owner = new UUID((string)h["owner"]); Serial = Convert.ToInt32((string)h["serial"]); VisualParams = (byte[])h["visual_params"]; - Texture = new Primitive.TextureEntry((byte[])h["texture"], 0, ((byte[])h["texture"]).Length); + + if (h.Contains("texture")) + { + byte[] te = h["texture"] as byte[]; + if (te != null && te.Length > 0) + Texture = new Primitive.TextureEntry(te, 0, te.Length); + } + AvatarHeight = (float)Convert.ToDouble((string)h["avatar_height"]); m_wearables = new AvatarWearable[MAX_WEARABLES]; -- cgit v1.1 From 4c8bcd2ff63cfbc38f6c1df4f22c0c019da5af1d Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 20 Aug 2009 20:19:08 +0100 Subject: Add some output (at DEBUG level) to the message transfer module to aid in tracking down an initialization failure. --- .../Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs index 5e7cf4b..4495303 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs @@ -56,7 +56,10 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage if (cnf != null && cnf.GetString( "MessageTransferModule", "MessageTransferModule") != "MessageTransferModule") + { + m_log.Debug("[MESSAGE TRANSFER]: Disabled by configuration"); return; + } cnf = config.Configs["Startup"]; if (cnf != null) @@ -72,6 +75,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage "grid_instant_message", processXMLRPCGridInstantMessage); } + m_log.Debug("[MESSAGE TRANSFER]: Message transfer module active"); scene.RegisterModuleInterface(this); m_Scenes.Add(scene); } -- cgit v1.1 From 297393f349d6529549f78142f426d95f2fdf0b90 Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 20 Aug 2009 21:05:00 +0100 Subject: Remove a load-order dependency in inventory transfer that was biting Windows users --- .../Avatar/Inventory/Transfer/InventoryTransferModule.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs index 5afbf68..75976e2 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs @@ -67,13 +67,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer if (!m_Scenelist.Contains(scene)) { - if (m_Scenelist.Count == 0) - { - m_TransferModule = scene.RequestModuleInterface(); - if (m_TransferModule == null) - m_log.Error("[INVENTORY TRANSFER] No Message transfer module found, transfers will be local only"); - } - m_Scenelist.Add(scene); scene.RegisterModuleInterface(this); @@ -86,6 +79,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer public void PostInitialise() { + if (m_Scenelist.Count > 0) + { + m_TransferModule = m_Scenelist[0].RequestModuleInterface(); + if (m_TransferModule == null) + m_log.Error("[INVENTORY TRANSFER] No Message transfer module found, transfers will be local only"); + } } public void Close() -- cgit v1.1 From b23160a871fe6a28105d39c9602c35cda75efe4a Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 20 Aug 2009 21:45:49 +0100 Subject: Remove the AssetInventory server from core. It has fallen behind both upstream and the reference implementation to the point where it is no longer usable. It has no known users, and sinnce it doesn't work anymore, it is safe to assume that no one has used it in a long time. --- .../AssetInventoryServer/AssetInventoryConfig.cs | 98 -- .../AssetInventoryServer/AssetInventoryServer.cs | 216 ---- OpenSim/Grid/AssetInventoryServer/Interfaces.cs | 143 --- .../Grid/AssetInventoryServer/InventoryObjects.cs | 139 --- OpenSim/Grid/AssetInventoryServer/Main.cs | 62 -- .../Plugins/AuthorizeAllPlugin.cs | 105 -- .../Plugins/BrowseFrontendPlugin.cs | 173 ---- .../Plugins/InventoryArchivePlugin.cs | 211 ---- .../Plugins/NullAuthenticationPlugin.cs | 95 -- .../Plugins/NullMetricsPlugin.cs | 151 --- .../Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs | 198 ---- .../Plugins/OpenSim/OpenSimAssetStoragePlugin.cs | 189 ---- .../OpenSim/OpenSimInventoryFrontendPlugin.cs | 867 ---------------- .../Plugins/OpenSim/OpenSimInventoryService.cs | 56 -- .../OpenSim/OpenSimInventoryStoragePlugin.cs | 547 ----------- .../AssetInventoryServerOpenSimPlugins.addin.xml | 27 - .../Plugins/ReferenceFrontendPlugin.cs | 369 ------- .../AssetInventoryServerPlugins.addin.xml | 28 - .../AssetInventoryServerSimplePlugins.addin.xml | 16 - .../Plugins/Simple/SimpleAssetStoragePlugin.cs | 290 ------ .../Plugins/Simple/SimpleInventoryStoragePlugin.cs | 625 ------------ .../Plugins/Simple/SimpleUtils.cs | 71 -- OpenSim/Grid/AssetInventoryServer/Utils.cs | 1031 -------------------- 23 files changed, 5707 deletions(-) delete mode 100644 OpenSim/Grid/AssetInventoryServer/AssetInventoryConfig.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Interfaces.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/InventoryObjects.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Main.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/AuthorizeAllPlugin.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/InventoryArchivePlugin.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/NullAuthenticationPlugin.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/NullMetricsPlugin.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryService.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/Resources/AssetInventoryServerOpenSimPlugins.addin.xml delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/Simple/Resources/AssetInventoryServerSimplePlugins.addin.xml delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleInventoryStoragePlugin.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleUtils.cs delete mode 100644 OpenSim/Grid/AssetInventoryServer/Utils.cs (limited to 'OpenSim') diff --git a/OpenSim/Grid/AssetInventoryServer/AssetInventoryConfig.cs b/OpenSim/Grid/AssetInventoryServer/AssetInventoryConfig.cs deleted file mode 100644 index 79b6c73..0000000 --- a/OpenSim/Grid/AssetInventoryServer/AssetInventoryConfig.cs +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.IO; -using System.Reflection; -using OpenSim.Framework; -using log4net; -using Nini.Config; - -namespace OpenSim.Grid.AssetInventoryServer -{ - public static class AssetInventoryConfig - { - public const string CONFIG_FILE = "AssetInventoryServer.ini"; - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - public static IConfigSource LoadConfig() - { - IConfigSource configSource = new IniConfigSource(); - configSource.AddConfig("Startup"); - return LoadConfig(configSource); - } - - public static IConfigSource LoadConfig(IConfigSource source) - { - string iniFileName = source.Configs["Startup"].GetString("inifile", CONFIG_FILE); - string iniFilePath = Path.Combine(Util.configDir(), iniFileName); - - source.Merge(DefaultConfig()); - - if (!File.Exists(iniFilePath)) - { - m_log.FatalFormat("[CONFIG]: File {0} not found, could not load any configuration.", iniFilePath); - m_log.FatalFormat("[CONFIG]: Did you copy the AssetInventoryServer.ini.example file to AssetInventoryServer.ini?"); - Environment.Exit(1); - } - - source.Merge(new IniConfigSource(iniFilePath)); - return source; - } - - private static IConfigSource DefaultConfig() - { - IConfigSource result = new IniConfigSource(); - - { - IConfig config = result.AddConfig("Config"); - config.Set("listen_port", 8003); - config.Set("assetset_location", String.Format(".{0}assets{0}AssetSets.xml", Path.DirectorySeparatorChar)); - } - - { - IConfig config = result.AddConfig("Plugins"); - config.Set("asset_storage_provider", "OpenSimAssetStorage"); - config.Set("inventory_storage_provider", "OpenSimInventoryStorage"); - config.Set("authentication_provider", "NullAuthentication"); - config.Set("authorization_provider", "AuthorizeAll"); - config.Set("metrics_provider", "NullMetrics"); - config.Set("frontends", "ReferenceFrontend,OpenSimAssetFrontend,OpenSimInventoryFrontend,BrowseFrontend"); - } - - { - IConfig config = result.AddConfig("OpenSim"); - config.Set("asset_database_provider", "OpenSim.Data.MySQL.dll"); - config.Set("inventory_database_provider", "OpenSim.Data.MySQL.dll"); - config.Set("asset_database_connect", String.Empty); - config.Set("inventory_database_connect", String.Empty); - } - - return result; - } - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs b/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs deleted file mode 100644 index 16b9d9e..0000000 --- a/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections.Generic; -using System.Reflection; -using OpenSim.Framework; -using OpenSim.Framework.Servers; -using OpenSim.Framework.Servers.HttpServer; -using OpenSim.Framework.Console; -using OpenSim.Framework.AssetLoader.Filesystem; -using Nini.Config; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer -{ - public class AssetInventoryServer : BaseOpenSimServer - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - public IConfigSource ConfigFile; - - public IAssetStorageProvider StorageProvider; - public IInventoryStorageProvider InventoryProvider; - public IAuthenticationProvider AuthenticationProvider; - public IAuthorizationProvider AuthorizationProvider; - public IMetricsProvider MetricsProvider; - - private List m_frontends = new List(); - private List m_backends = new List(); - - public AssetInventoryServer(IConfigSource config) - { - ConfigFile = config; - - m_console = new LocalConsole("AssetInventory"); - MainConsole.Instance = m_console; - } - - public bool Start() - { - Startup(); - m_log.Info("[ASSETINVENTORY]: Starting AssetInventory Server"); - - try - { - ConfigFile = AssetInventoryConfig.LoadConfig(ConfigFile); - } - catch (Exception) - { - m_log.Error("[ASSETINVENTORY]: Failed to load the config."); - return false; - } - - StorageProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/AssetStorageProvider", - "asset_storage_provider", false) as IAssetStorageProvider; - m_backends.Add(StorageProvider); - - InventoryProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/InventoryStorageProvider", - "inventory_storage_provider", false) as IInventoryStorageProvider; - m_backends.Add(InventoryProvider); - - MetricsProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/MetricsProvider", - "metrics_provider", false) as IMetricsProvider; - m_backends.Add(MetricsProvider); - - try - { - InitHttpServer((uint) ConfigFile.Configs["Config"].GetInt("listen_port")); - } - catch (Exception ex) - { - m_log.Error("[ASSETINVENTORY]: Initializing the HTTP server failed, shutting down: " + ex.Message); - Shutdown(); - return false; - } - - LoadDefaultAssets(); - - AuthenticationProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/AuthenticationProvider", - "authentication_provider", false) as IAuthenticationProvider; - m_backends.Add(AuthenticationProvider); - - AuthorizationProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/AuthorizationProvider", - "authorization_provider", false) as IAuthorizationProvider; - m_backends.Add(AuthorizationProvider); - - m_frontends.AddRange(LoadAssetInventoryServerPlugins("/OpenSim/AssetInventoryServer/Frontend", "frontends")); - - // Inform the user if we don't have any frontends at this point. - if (m_frontends.Count == 0) - m_log.Info("[ASSETINVENTORY]: Starting with no frontends loaded, which isn't extremely useful. Did you set the 'frontends' configuration parameter?"); - - return true; - } - - public void Work() - { - m_console.Output("Enter help for a list of commands"); - - while (true) - { - m_console.Prompt(); - } - } - - public override void ShutdownSpecific() - { - foreach (IAssetInventoryServerPlugin plugin in m_frontends) - { - m_log.Debug("[ASSETINVENTORY]: Disposing plugin " + plugin.Name); - try { plugin.Dispose(); } - catch (Exception ex) - { m_log.ErrorFormat("[ASSETINVENTORY]: Failure shutting down plugin {0}: {1}", plugin.Name, ex.Message); } - } - - foreach (IAssetInventoryServerPlugin plugin in m_backends) - { - m_log.Debug("[ASSETINVENTORY]: Disposing plugin " + plugin.Name); - try { plugin.Dispose(); } - catch (Exception ex) - { m_log.ErrorFormat("[ASSETINVENTORY]: Failure shutting down plugin {0}: {1}", plugin.Name, ex.Message); } - } - - if (HttpServer != null) - HttpServer.Stop(); - } - - void InitHttpServer(uint port) - { - m_httpServer = new BaseHttpServer(port); - m_httpServer.Start(); - - m_log.Info("[ASSETINVENTORY]: AssetInventory server is listening on port " + port); - } - - private IAssetInventoryServerPlugin LoadAssetInventoryServerPlugin(string addinPath, string configParam, bool optional) - { - IAssetInventoryServerPlugin result = null; - List plugins = LoadAssetInventoryServerPlugins(addinPath, configParam); - - if (plugins.Count == 1) - { - result = plugins[0]; - } - else if (plugins.Count > 1) - { - m_log.ErrorFormat("[ASSETINVENTORY]: Only 1 plugin expected for extension point '{0}', {1} plugins loaded. Check the '{2}' parameter in the config file.", - addinPath, plugins.Count, configParam); - Shutdown(); - Environment.Exit(0); - } - else if (!optional) - { - m_log.ErrorFormat("[ASSETINVENTORY]: The extension point '{0}' is not optional. Check the '{1}' parameter in the config file.", addinPath, configParam); - Shutdown(); - Environment.Exit(0); - } - - return result; - } - - private List LoadAssetInventoryServerPlugins(string addinPath, string configParam) - { - PluginLoader loader = new PluginLoader(new AssetInventoryServerPluginInitialiser(this)); - loader.Add(addinPath, new PluginIdFilter(ConfigFile.Configs["Plugins"].GetString(configParam))); - - try - { - loader.Load(); - } - catch (PluginNotInitialisedException e) - { - m_log.ErrorFormat("[ASSETINVENTORY]: Error initialising plugin '{0}' for extension point '{1}'.", e.Message, addinPath); - Shutdown(); - Environment.Exit(0); - } - - return loader.Plugins; - } - - private void LoadDefaultAssets() - { - AssetLoaderFileSystem assetLoader = new AssetLoaderFileSystem(); - assetLoader.ForEachDefaultXmlAsset(ConfigFile.Configs["Config"].GetString("assetset_location"), StoreAsset); - } - - private void StoreAsset(AssetBase asset) - { - StorageProvider.TryCreateAsset(asset); - } - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Interfaces.cs b/OpenSim/Grid/AssetInventoryServer/Interfaces.cs deleted file mode 100644 index e808dd3..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Interfaces.cs +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections.Generic; -using OpenMetaverse; -using OpenSim.Framework; - -namespace OpenSim.Grid.AssetInventoryServer -{ - /// - /// Response from a call to a backend provider - /// - public enum BackendResponse - { - /// The call succeeded - Success, - /// The resource requested was not found - NotFound, - /// A server failure prevented the call from - /// completing - Failure - } - - public class AssetInventoryServerPluginInitialiser : PluginInitialiserBase - { - private AssetInventoryServer server; - - public AssetInventoryServerPluginInitialiser(AssetInventoryServer server) - { - this.server = server; - } - - public override void Initialise(IPlugin plugin) - { - IAssetInventoryServerPlugin p = plugin as IAssetInventoryServerPlugin; - p.Initialise (server); - } - } - - #region Interfaces - - public interface IAssetInventoryServerPlugin : IPlugin - { - void Initialise(AssetInventoryServer server); - } - - public interface IAssetStorageProvider : IAssetInventoryServerPlugin - { - BackendResponse TryFetchMetadata(UUID assetID, out AssetMetadata metadata); - BackendResponse TryFetchData(UUID assetID, out byte[] assetData); - BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset); - BackendResponse TryCreateAsset(AssetBase asset); - BackendResponse TryCreateAsset(AssetBase asset, out UUID assetID); - int ForEach(Action action, int start, int count); - } - - public interface IInventoryStorageProvider : IAssetInventoryServerPlugin - { - BackendResponse TryFetchItem(Uri owner, UUID itemID, out InventoryItemBase item); - BackendResponse TryFetchFolder(Uri owner, UUID folderID, out InventoryFolderWithChildren folder); - BackendResponse TryFetchFolderContents(Uri owner, UUID folderID, out InventoryCollection contents); - BackendResponse TryFetchFolderList(Uri owner, out List folders); - BackendResponse TryFetchInventory(Uri owner, out InventoryCollection inventory); - - BackendResponse TryFetchActiveGestures(Uri owner, out List gestures); - - BackendResponse TryCreateItem(Uri owner, InventoryItemBase item); - BackendResponse TryCreateFolder(Uri owner, InventoryFolderWithChildren folder); - BackendResponse TryCreateInventory(Uri owner, InventoryFolderWithChildren rootFolder); - - BackendResponse TryDeleteItem(Uri owner, UUID itemID); - BackendResponse TryDeleteFolder(Uri owner, UUID folderID); - BackendResponse TryPurgeFolder(Uri owner, UUID folderID); - } - - public interface IAuthenticationProvider : IAssetInventoryServerPlugin - { - void AddIdentifier(UUID authToken, Uri identifier); - bool RemoveIdentifier(UUID authToken); - bool TryGetIdentifier(UUID authToken, out Uri identifier); - } - - public interface IAuthorizationProvider : IAssetInventoryServerPlugin - { - bool IsMetadataAuthorized(UUID authToken, UUID assetID); - /// - /// Authorizes access to the data for an asset. Access to asset data - /// also implies access to the metadata for that asset - /// - /// Authentication token to check for access - /// ID of the requested asset - /// True if access is granted, otherwise false - bool IsDataAuthorized(UUID authToken, UUID assetID); - bool IsCreateAuthorized(UUID authToken); - - bool IsInventoryReadAuthorized(UUID authToken, Uri owner); - bool IsInventoryWriteAuthorized(UUID authToken, Uri owner); - } - - public interface IMetricsProvider : IAssetInventoryServerPlugin - { - void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time); - void LogAssetDataFetch(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time); - void LogAssetCreate(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time); - - void LogInventoryFetch(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time); - void LogInventoryFetchFolderContents(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time); - void LogInventoryFetchFolderList(string extension, BackendResponse response, Uri owner, DateTime time); - void LogInventoryFetchInventory(string extension, BackendResponse response, Uri owner, DateTime time); - void LogInventoryFetchActiveGestures(string extension, BackendResponse response, Uri owner, DateTime time); - void LogInventoryCreate(string extension, BackendResponse response, Uri owner, bool folder, DateTime time); - void LogInventoryCreateInventory(string extension, BackendResponse response, DateTime time); - void LogInventoryDelete(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time); - void LogInventoryPurgeFolder(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time); - } - - #endregion Interfaces -} diff --git a/OpenSim/Grid/AssetInventoryServer/InventoryObjects.cs b/OpenSim/Grid/AssetInventoryServer/InventoryObjects.cs deleted file mode 100644 index 4f42a20..0000000 --- a/OpenSim/Grid/AssetInventoryServer/InventoryObjects.cs +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections.Generic; -using OpenMetaverse; -using OpenSim.Framework; - -namespace OpenSim.Grid.AssetInventoryServer -{ - //public class InventoryBase - //{ - //} - - //public class InventoryFolder : InventoryBase - //{ - // public string Name; - // public UUID Owner; - // public UUID ParentID; - // public UUID ID; - // public short Type; - // public ushort Version; - - // [NonSerialized] - // public Dictionary Children = new Dictionary(); - - // public InventoryFolder() - // { - // } - - // public InventoryFolder(string name, UUID ownerID, UUID parentID, short assetType) - // { - // ID = UUID.Random(); - // Name = name; - // Owner = ownerID; - // ParentID = parentID; - // Type = assetType; - // Version = 1; - // } - - // public override string ToString() - // { - // return String.Format("{0} ({1})", Name, ID); - // } - //} - - //public class InventoryItem : InventoryBase - //{ - // public UUID ID; - // public int InvType; - // public UUID Folder; - // public UUID Owner; - // public UUID Creator; - // public string Name; - // public string Description; - // public uint NextPermissions; - // public uint CurrentPermissions; - // public uint BasePermissions; - // public uint EveryOnePermissions; - // public uint GroupPermissions; - // public int AssetType; - // public UUID AssetID; - // public UUID GroupID; - // public bool GroupOwned; - // public int SalePrice; - // public byte SaleType; - // public uint Flags; - // public int CreationDate; - - // public override string ToString() - // { - // return String.Format("{0} ({1})", Name, ID); - // } - //} - - public class InventoryFolderWithChildren : InventoryFolderBase - { - public InventoryFolderWithChildren() - { - } - - public InventoryFolderWithChildren(InventoryFolderBase folder) - { - // from InventoryNodeBase - Name = folder.Name; - ID = folder.ID; - Owner = folder.Owner; - - // from InventoryFolderBase - ParentID = folder.ParentID; - Type = folder.Type; - Version = folder.Version; - } - - public InventoryFolderWithChildren(string name, UUID ownerID, UUID parentID, short assetType) - { - ID = UUID.Random(); - Name = name; - Owner = ownerID; - ParentID = parentID; - Type = assetType; - Version = 1; - } - - [NonSerialized] - public Dictionary Children = new Dictionary(); - } - - public class InventoryCollection - { - public Dictionary Folders; - public Dictionary Items; - public UUID UserID; - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Main.cs b/OpenSim/Grid/AssetInventoryServer/Main.cs deleted file mode 100644 index 598b754..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Main.cs +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using Nini.Config; -using log4net.Config; -using log4net; -using System.Reflection; - -namespace OpenSim.Grid.AssetInventoryServer -{ - class MainEntry - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - static void Main(string[] args) - { - XmlConfigurator.Configure(); - - ArgvConfigSource configSource = new ArgvConfigSource(args); - configSource.AddSwitch("Startup", "inifile"); - - AssetInventoryServer server = new AssetInventoryServer(configSource); - if (server.Start()) - { - Console.CancelKeyPress += - delegate(object sender, ConsoleCancelEventArgs e) - { - m_log.Info("AssetInventory server is shutting down..."); - server.Shutdown(); - Environment.Exit(0); - }; - - server.Work(); - } - } - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/AuthorizeAllPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/AuthorizeAllPlugin.cs deleted file mode 100644 index 3d0a283..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/AuthorizeAllPlugin.cs +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Reflection; -using OpenMetaverse; -using OpenSim.Framework; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins -{ - public class AuthorizeAllPlugin : IAuthorizationProvider - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - //private AssetInventoryServer m_server; - - public AuthorizeAllPlugin() - { - } - - #region IPlugin implementation - - public void Initialise(AssetInventoryServer server) - { - //m_server = server; - - m_log.Info("[AUTHORIZEALL]: Authorize All loaded."); - } - - /// - /// Initialises asset interface - /// - public void Initialise() - { - m_log.InfoFormat("[AUTHORIZEALL]: {0} cannot be default-initialized!", Name); - throw new PluginNotInitialisedException(Name); - } - - public void Dispose() - { - } - - public string Version - { - // TODO: this should be something meaningful and not hardcoded? - get { return "0.1"; } - } - - public string Name - { - get { return "AuthorizeAll"; } - } - - #endregion IPlugin implementation - - public bool IsMetadataAuthorized(UUID authToken, UUID assetID) - { - return true; - } - - public bool IsDataAuthorized(UUID authToken, UUID assetID) - { - return true; - } - - public bool IsCreateAuthorized(UUID authToken) - { - return true; - } - - public bool IsInventoryReadAuthorized(UUID authToken, Uri owner) - { - return true; - } - - public bool IsInventoryWriteAuthorized(UUID authToken, Uri owner) - { - return true; - } - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs deleted file mode 100644 index 90ea2e0..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.IO; -using System.Reflection; -using System.Collections.Specialized; -using System.Net; -using System.Text; -using System.Web; -using OpenMetaverse; -using OpenSim.Framework; -using OpenSim.Framework.Servers; -using OpenSim.Framework.Servers.HttpServer; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins -{ - public class BrowseFrontendPlugin : IAssetInventoryServerPlugin - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private AssetInventoryServer m_server; - - public BrowseFrontendPlugin() - { - } - - #region IPlugin implementation - - public void Initialise(AssetInventoryServer server) - { - m_server = server; - - // Request for / or /?... - m_server.HttpServer.AddStreamHandler(new BrowseRequestHandler(server)); - - m_log.Info("[BROWSEFRONTEND]: Browser Frontend loaded."); - } - - /// - /// Initialises asset interface - /// - public void Initialise() - { - m_log.InfoFormat("[BROWSEFRONTEND]: {0} cannot be default-initialized!", Name); - throw new PluginNotInitialisedException(Name); - } - - public void Dispose() - { - } - - public string Version - { - // TODO: this should be something meaningful and not hardcoded? - get { return "0.1"; } - } - - public string Name - { - get { return "BrowseFrontend"; } - } - - #endregion IPlugin implementation - - public class BrowseRequestHandler : BaseStreamHandler - { - AssetInventoryServer m_server; - - //public BrowseRequestHandler(AssetInventoryServer server) : base("GET", "(^/$|(^/\?.*)") - public BrowseRequestHandler(AssetInventoryServer server) : base("GET", "/") - { - m_server = server; - } - - public override string ContentType - { - get { return "text/html"; } - } - - #region IStreamedRequestHandler implementation - - public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - const int ASSETS_PER_PAGE = 25; - const string HEADER = "Asset Server"; - const string TABLE_HEADER = - ""; - const string TABLE_FOOTER = "
NameDescriptionTypeIDTemporarySHA-1
"; - const string FOOTER = ""; - - UUID authToken = Utils.GetAuthToken(httpRequest); - - StringBuilder html = new StringBuilder(); - int start = 0; - uint page = 0; - - if (!String.IsNullOrEmpty(httpRequest.Url.Query)) - { - NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); - if (!String.IsNullOrEmpty(query["page"]) && UInt32.TryParse(query["page"], out page)) - start = (int)page * ASSETS_PER_PAGE; - } - - html.AppendLine(HEADER); - - html.AppendLine("

"); - if (page > 0) - html.AppendFormat("< Previous Page | ", httpRequest.RawUrl, page - 1); - html.AppendFormat("Next Page >", httpRequest.RawUrl, page + 1); - html.AppendLine("

"); - - html.AppendLine(TABLE_HEADER); - - m_server.StorageProvider.ForEach( - delegate(AssetMetadata data) - { - if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.FullID)) - { - html.AppendLine(String.Format( - "{0}{1}{2}{3}{4}{5}", - data.Name, data.Description, data.ContentType, data.ID, data.Temporary, - BitConverter.ToString(data.SHA1).Replace("-", String.Empty))); - } - else - { - html.AppendLine(String.Format( - "[Protected Asset]  {0}{1} ", - data.ID, data.Temporary)); - } - }, start, ASSETS_PER_PAGE - ); - - html.AppendLine(TABLE_FOOTER); - - html.AppendLine(FOOTER); - - byte[] responseData = System.Text.Encoding.UTF8.GetBytes(html.ToString()); - - httpResponse.StatusCode = (int) HttpStatusCode.OK; - //httpResponse.Body.Write(responseData, 0, responseData.Length); - //httpResponse.Body.Flush(); - return responseData; - } - - #endregion IStreamedRequestHandler implementation - } - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/InventoryArchivePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/InventoryArchivePlugin.cs deleted file mode 100644 index 8323450..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/InventoryArchivePlugin.cs +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Net; -using System.IO; -using System.IO.Compression; -using System.Xml; -using System.Reflection; -using OpenMetaverse; -using OpenSim.Framework; -using OpenSim.Framework.Serialization; -using OpenSim.Framework.Serialization.External; -using OpenSim.Framework.Servers; -using OpenSim.Framework.Servers.HttpServer; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins -{ - public class InventoryArchivePlugin : IAssetInventoryServerPlugin - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private AssetInventoryServer m_server; - - public InventoryArchivePlugin() - { - } - - #region IPlugin implementation - - public void Initialise(AssetInventoryServer server) - { - m_server = server; - - m_server.HttpServer.AddStreamHandler(new GetInventoryArchive(server)); - - m_log.Info("[INVENTORYARCHIVE]: Inventory Archive loaded."); - } - - /// - /// Initialises asset interface - /// - public void Initialise() - { - m_log.InfoFormat("[INVENTORYARCHIVE]: {0} cannot be default-initialized!", Name); - throw new PluginNotInitialisedException(Name); - } - - public void Dispose() - { - } - - public string Version - { - // TODO: this should be something meaningful and not hardcoded? - get { return "0.1"; } - } - - public string Name - { - get { return "InventoryArchive"; } - } - - #endregion IPlugin implementation - - public class GetInventoryArchive : BaseStreamHandler - { - AssetInventoryServer m_server; - - //public GetInventoryArchive(AssetInventoryServer server) : base("GET", @"^/inventoryarchive/") - public GetInventoryArchive(AssetInventoryServer server) : base("GET", "/inventoryarchive") - { - m_server = server; - } - - public override string ContentType - { - get { return "application/x-compressed"; } - } - - public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - byte[] buffer = new byte[] {}; - UUID ownerID; - // Split the URL up to get the asset ID out - string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/'); - - if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out ownerID)) - { - Uri owner = Utils.GetOpenSimUri(ownerID); - InventoryCollection inventory; - BackendResponse storageResponse = m_server.InventoryProvider.TryFetchInventory(owner, out inventory); - - if (storageResponse == BackendResponse.Success) - { - m_log.DebugFormat("[INVENTORYARCHIVE]: Archiving inventory for user UUID {0}", ownerID); - buffer = ArchiveInventoryCollection(inventory); - httpResponse.StatusCode = (int) HttpStatusCode.OK; - } - else - { - httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; - } - } - else - { - m_log.Warn("[INVENTORYARCHIVE]: Unrecognized inventory archive request: " + httpRequest.Url.PathAndQuery); - } - - return buffer; - } - } - - private static byte[] ArchiveInventoryCollection(InventoryCollection inventory) - { - byte[] buffer = new byte[] {}; - - // Fill in each folder's Children dictionary. - InventoryFolderWithChildren rootFolder = BuildInventoryHierarchy(ref inventory); - - // TODO: It's probably a bad idea to tar to memory for large - // inventories. - MemoryStream ms = new MemoryStream(); - GZipStream gzs = new GZipStream(ms, CompressionMode.Compress, true); - TarArchiveWriter archive = new TarArchiveWriter(gzs); - WriteInventoryFolderToArchive(archive, rootFolder, ArchiveConstants.INVENTORY_PATH); - - archive.Close(); - - ms.Seek(0, SeekOrigin.Begin); - buffer = ms.GetBuffer(); - Array.Resize(ref buffer, (int) ms.Length); - ms.Close(); - return buffer; - } - - private static InventoryFolderWithChildren BuildInventoryHierarchy(ref InventoryCollection inventory) - { - m_log.DebugFormat("[INVENTORYARCHIVE]: Building inventory hierarchy"); - InventoryFolderWithChildren rootFolder = null; - - foreach (InventoryFolderWithChildren parentFolder in inventory.Folders.Values) - { - // Grab the root folder, it has no parents. - if (UUID.Zero == parentFolder.ParentID) rootFolder = parentFolder; - - foreach (InventoryFolderWithChildren folder in inventory.Folders.Values) - if (parentFolder.ID == folder.ParentID) - parentFolder.Children.Add(folder.ID, folder); - - foreach (InventoryItemBase item in inventory.Items.Values) - if (parentFolder.ID == item.Folder) - parentFolder.Children.Add(item.ID, item); - } - - return rootFolder; - } - - private static void WriteInventoryFolderToArchive( - TarArchiveWriter archive, InventoryFolderWithChildren folder, string path) - { - path += string.Format("{0}{1}{2}/", folder.Name, ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, folder.ID); - archive.WriteDir(path); - - foreach (InventoryNodeBase inventoryNode in folder.Children.Values) - { - if (inventoryNode is InventoryFolderWithChildren) - { - WriteInventoryFolderToArchive(archive, (InventoryFolderWithChildren) inventoryNode, path); - } - else if (inventoryNode is InventoryItemBase) - { - WriteInventoryItemToArchive(archive, (InventoryItemBase) inventoryNode, path); - } - } - } - - private static void WriteInventoryItemToArchive(TarArchiveWriter archive, InventoryItemBase item, string path) - { - string filename = string.Format("{0}{1}_{2}.xml", path, item.Name, item.ID); - string serialization = UserInventoryItemSerializer.Serialize(item); - archive.WriteFile(filename, serialization); - - //m_assetGatherer.GatherAssetUuids(item.AssetID, (AssetType) item.AssetType, assetUuids); - } - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/NullAuthenticationPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/NullAuthenticationPlugin.cs deleted file mode 100644 index 026b3c8..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/NullAuthenticationPlugin.cs +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Reflection; -using OpenMetaverse; -using OpenSim.Framework; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins -{ - public class NullAuthenticationPlugin : IAuthenticationProvider - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - //private AssetInventoryServer m_server; - - public NullAuthenticationPlugin() - { - } - - #region IPlugin implementation - - public void Initialise(AssetInventoryServer server) - { - //m_server = server; - - m_log.Info("[NULLAUTHENTICATION]: Null Authentication loaded."); - } - - /// - /// Initialises asset interface - /// - public void Initialise() - { - m_log.InfoFormat("[NULLAUTHENTICATION]: {0} cannot be default-initialized!", Name); - throw new PluginNotInitialisedException(Name); - } - - public void Dispose() - { - } - - public string Version - { - // TODO: this should be something meaningful and not hardcoded? - get { return "0.1"; } - } - - public string Name - { - get { return "NullAuthentication"; } - } - - #endregion IPlugin implementation - - public void AddIdentifier(UUID authToken, Uri identifier) - { - } - - public bool RemoveIdentifier(UUID authToken) - { - return true; - } - - public bool TryGetIdentifier(UUID authToken, out Uri identifier) - { - identifier = null; - return true; - } - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/NullMetricsPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/NullMetricsPlugin.cs deleted file mode 100644 index 8cde8f4..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/NullMetricsPlugin.cs +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Reflection; -using OpenMetaverse; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins -{ - public class NullMetricsPlugin : IMetricsProvider - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - //private AssetInventoryServer m_server; - - public NullMetricsPlugin() - { - } - - #region IMetricsProvider implementation - - public void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time) - { - m_log.DebugFormat("[{0}]: AssetMetadataFetch(): AssetID: {1}, Response: {2}", extension, assetID, response); - } - - public void LogAssetDataFetch(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time) - { - m_log.DebugFormat("[{0}]: AssetDataFetch(): AssetID: {1}, DataSize: {2}, Response: {3}", extension, assetID, - dataSize, response); - } - - public void LogAssetCreate(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time) - { - m_log.DebugFormat("[{0}]: AssetCreate(): AssetID: {1}, DataSize: {2}, Response: {3}", extension, assetID, - dataSize, response); - } - - public void LogInventoryFetch(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time) - { - m_log.DebugFormat("[{0}]: InventoryFetch(): ObjID: {1}, Folder: {2}, OwnerID: {3}, Response: {4}", extension, - objID, folder, owner, response); - } - - public void LogInventoryFetchFolderContents(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time) - { - m_log.DebugFormat("[{0}]: InventoryFetchFolderContents(): FolderID: {1}, OwnerID: {2}, Response: {3}", extension, - folderID, owner, response); - } - - public void LogInventoryFetchFolderList(string extension, BackendResponse response, Uri owner, DateTime time) - { - m_log.DebugFormat("[{0}]: InventoryFetchFolderList(): OwnerID: {1}, Response: {2}", extension, - owner, response); - } - - public void LogInventoryFetchInventory(string extension, BackendResponse response, Uri owner, DateTime time) - { - m_log.DebugFormat("[{0}]: InventoryFetchInventory(): OwnerID: {1}, Response: {2}", extension, - owner, response); - } - - public void LogInventoryFetchActiveGestures(string extension, BackendResponse response, Uri owner, DateTime time) - { - m_log.DebugFormat("[{0}]: InventoryFetchActiveGestures(): OwnerID: {1}, Response: {2}", extension, - owner, response); - } - - public void LogInventoryCreate(string extension, BackendResponse response, Uri owner, bool folder, DateTime time) - { - m_log.DebugFormat("[{0}]: InventoryCreate(): OwnerID: {1}, Response: {2}", extension, - owner, response); - } - - public void LogInventoryCreateInventory(string extension, BackendResponse response, DateTime time) - { - m_log.DebugFormat("[{0}]: InventoryCreateInventory(): Response: {1}", extension, - response); - } - - public void LogInventoryDelete(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time) - { - m_log.DebugFormat("[{0}]: InventoryDelete(): OwnerID: {1}, Folder: {2}, Response: {3}", extension, - owner, folder, response); - } - - public void LogInventoryPurgeFolder(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time) - { - m_log.DebugFormat("[{0}]: InventoryPurgeFolder(): OwnerID: {1}, FolderID: {2}, Response: {3}", extension, - owner, folderID, response); - } - - #endregion IMetricsProvider implementation - - #region IPlugin implementation - - public void Initialise(AssetInventoryServer server) - { - //m_server = server; - } - - /// - /// Initialises metrics interface - /// - public void Initialise() - { - m_log.Info("[NULLMETRICS]: Null metrics loaded."); - } - - public void Dispose() - { - } - - public string Version - { - // TODO: this should be something meaningful and not hardcoded? - get { return "0.1"; } - } - - public string Name - { - get { return "NullMetrics"; } - } - - #endregion IPlugin implementation - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs deleted file mode 100644 index e4be55e..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Reflection; -using System.Net; -using System.IO; -using System.Text; -using System.Xml; -using System.Xml.Serialization; -using OpenMetaverse; -using OpenSim.Framework; -using OpenSim.Framework.Servers; -using OpenSim.Framework.Servers.HttpServer; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim -{ - public class OpenSimAssetFrontendPlugin : IAssetInventoryServerPlugin - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private AssetInventoryServer m_server; - - public OpenSimAssetFrontendPlugin() - { - } - - #region IPlugin implementation - - public void Initialise(AssetInventoryServer server) - { - m_server = server; - - // Asset request - m_server.HttpServer.AddStreamHandler(new AssetRequestHandler(server)); - - // Asset creation - m_server.HttpServer.AddStreamHandler(new AssetPostHandler(server)); - - m_log.Info("[OPENSIMASSETFRONTEND]: OpenSim Asset Frontend loaded."); - } - - /// - /// Initialises asset interface - /// - public void Initialise() - { - m_log.InfoFormat("[OPENSIMASSETFRONTEND]: {0} cannot be default-initialized!", Name); - throw new PluginNotInitialisedException(Name); - } - - public void Dispose() - { - } - - public string Version - { - // TODO: this should be something meaningful and not hardcoded? - get { return "0.1"; } - } - - public string Name - { - get { return "OpenSimAssetFrontend"; } - } - - #endregion IPlugin implementation - - public class AssetRequestHandler : BaseStreamHandler - { - AssetInventoryServer m_server; - - //public AssetRequestHandler(AssetInventoryServer server) : base("GET", "^/assets") - public AssetRequestHandler(AssetInventoryServer server) : base("GET", "/assets") - { - m_server = server; - } - - public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - byte[] buffer = new byte[] {}; - UUID assetID; - // Split the URL up to get the asset ID out - string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/'); - - if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out assetID)) - { - BackendResponse dataResponse; - - AssetBase asset = new AssetBase(); - if ((dataResponse = m_server.StorageProvider.TryFetchDataMetadata(assetID, out asset)) == BackendResponse.Success) - { - if (rawUrl.Length >= 4 && rawUrl[3] == "data") - { - httpResponse.StatusCode = (int)HttpStatusCode.OK; - httpResponse.ContentType = Utils.SLAssetTypeToContentType(asset.Type); - buffer=asset.Data; - } - else - { - XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); - MemoryStream ms = new MemoryStream(); - XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8); - xs.Serialize(xw, asset); - xw.Flush(); - - ms.Seek(0, SeekOrigin.Begin); - buffer = ms.GetBuffer(); - Array.Resize(ref buffer, (int)ms.Length); - ms.Close(); - httpResponse.StatusCode = (int)HttpStatusCode.OK; - } - } - else - { - m_log.WarnFormat("[OPENSIMASSETFRONTEND]: Failed to fetch asset data or metadata for {0}: {1}", assetID, dataResponse); - httpResponse.StatusCode = (int) HttpStatusCode.NotFound; - } - } - else - { - m_log.Warn("[OPENSIMASSETFRONTEND]: Unrecognized OpenSim asset request: " + httpRequest.Url.PathAndQuery); - } - - return buffer; - } - } - - public class AssetPostHandler : BaseStreamHandler - { - AssetInventoryServer m_server; - - //public AssetPostHandler(AssetInventoryServer server) : base("POST", "/^assets") - public AssetPostHandler(AssetInventoryServer server) : base("POST", "/assets") - { - m_server = server; - } - - public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - AssetBase asset = null; - - try - { - asset = (AssetBase) new XmlSerializer(typeof (AssetBase)).Deserialize(httpRequest.InputStream); - } - catch (Exception ex) - { - m_log.Warn("[OPENSIMASSETFRONTEND]: Failed to parse POST data (expecting AssetBase): " + ex.Message); - httpResponse.StatusCode = (int) HttpStatusCode.BadRequest; - } - - if (asset != null && asset.Data != null && asset.Data.Length > 0) - { - BackendResponse storageResponse = m_server.StorageProvider.TryCreateAsset(asset); - - if (storageResponse == BackendResponse.Success) - httpResponse.StatusCode = (int) HttpStatusCode.Created; - else if (storageResponse == BackendResponse.NotFound) - httpResponse.StatusCode = (int) HttpStatusCode.NotFound; - else - httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; - } - else - { - m_log.Warn("[OPENSIMASSETFRONTEND]: AssetPostHandler called with no asset data"); - httpResponse.StatusCode = (int) HttpStatusCode.BadRequest; - } - - return new byte[] {}; - } - } - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs deleted file mode 100644 index 92ac84f..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Reflection; -using System.Data; -using System.Collections.Generic; -using OpenMetaverse; -using OpenSim.Framework; -using OpenSim.Data; -using Nini.Config; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim -{ - public class OpenSimAssetStoragePlugin : IAssetStorageProvider - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - const string EXTENSION_NAME = "OpenSimAssetStorage"; // Used in metrics reporting - - private AssetInventoryServer m_server; - private IAssetDataPlugin m_assetProvider; - private IConfig m_openSimConfig; - - public OpenSimAssetStoragePlugin() - { - } - - #region IAssetStorageProvider implementation - - public BackendResponse TryFetchMetadata(UUID assetID, out AssetMetadata metadata) - { - metadata = null; - BackendResponse ret; - - AssetBase asset = m_assetProvider.GetAsset(assetID); - - if (asset == null) ret = BackendResponse.NotFound; - else - { - metadata = asset.Metadata; - ret = BackendResponse.Success; - } - - m_server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchData(UUID assetID, out byte[] assetData) - { - assetData = null; - BackendResponse ret; - - AssetBase asset = m_assetProvider.GetAsset(assetID); - - if (asset == null) ret = BackendResponse.NotFound; - else - { - assetData = asset.Data; - ret = BackendResponse.Success; - } - - m_server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now); - return ret; - } - - public BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset) - { - asset = m_assetProvider.GetAsset(assetID); - - if (asset == null) return BackendResponse.NotFound; - - return BackendResponse.Success; - } - - public BackendResponse TryCreateAsset(AssetBase asset, out UUID assetID) - { - assetID = asset.FullID = UUID.Random(); - return TryCreateAsset(asset); - } - - public BackendResponse TryCreateAsset(AssetBase asset) - { - BackendResponse ret; - - m_assetProvider.StoreAsset(asset); - ret = BackendResponse.Success; - - m_server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, asset.FullID, asset.Data.Length, DateTime.Now); - return ret; - } - - public int ForEach(Action action, int start, int count) - { - int rowCount = 0; - - foreach (AssetMetadata metadata in m_assetProvider.FetchAssetMetadataSet(start, count)) - { - // We set the ContentType here because Utils is only in - // AssetInventoryServer. This should be moved to the DB - // backends when the equivalent of SLAssetTypeToContentType is - // in OpenSim.Framework or similar. - metadata.ContentType = Utils.SLAssetTypeToContentType(metadata.Type); - - action(metadata); - ++rowCount; - } - - return rowCount; - } - - #endregion IAssetStorageProvider implementation - - #region IPlugin implementation - - public void Initialise(AssetInventoryServer server) - { - m_server = server; - m_openSimConfig = server.ConfigFile.Configs["OpenSim"]; - - try - { - m_assetProvider = DataPluginFactory.LoadDataPlugin(m_openSimConfig.GetString("asset_database_provider"), - m_openSimConfig.GetString("asset_database_connect")); - if (m_assetProvider == null) - { - m_log.Error("[OPENSIMASSETSTORAGE]: Failed to load a database plugin, server halting."); - Environment.Exit(-1); - } - else - m_log.InfoFormat("[OPENSIMASSETSTORAGE]: Loaded storage backend: {0}", Version); - } - catch (Exception e) - { - m_log.WarnFormat("[OPENSIMASSETSTORAGE]: Failure loading data plugin: {0}", e.ToString()); - throw new PluginNotInitialisedException(Name); - } - } - - /// - /// Initialises asset interface - /// - public void Initialise() - { - m_log.InfoFormat("[OPENSIMASSETSTORAGE]: {0} cannot be default-initialized!", Name); - throw new PluginNotInitialisedException(Name); - } - - public void Dispose() - { - } - - public string Version - { - get { return m_assetProvider.Version; } - } - - public string Name - { - get { return "OpenSimAssetStorage"; } - } - - #endregion IPlugin implementation - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs deleted file mode 100644 index c83e911..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs +++ /dev/null @@ -1,867 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Net; -using System.Reflection; -using System.Collections.Generic; -using System.IO; -using System.Xml; -using OpenMetaverse; -using OpenSim.Framework; -using OpenSim.Framework.Servers; -using OpenSim.Framework.Servers.HttpServer; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim -{ - public class OpenSimInventoryFrontendPlugin : IAssetInventoryServerPlugin - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private AssetInventoryServer m_server; - private Utils.InventoryCollectionSerializer collectionSerializer = new Utils.InventoryCollectionSerializer(); - - public OpenSimInventoryFrontendPlugin() - { - } - - #region IPlugin implementation - - public void Initialise(AssetInventoryServer server) - { - m_server = server; - - m_server.HttpServer.AddStreamHandler(new GetInventoryHandler(server, collectionSerializer)); - m_server.HttpServer.AddStreamHandler(new CreateInventoryHandler(server)); - m_server.HttpServer.AddStreamHandler(new NewFolderHandler(server)); - m_server.HttpServer.AddStreamHandler(new UpdateFolderHandler(server)); - m_server.HttpServer.AddStreamHandler(new MoveFolderHandler(server)); - m_server.HttpServer.AddStreamHandler(new PurgeFolderHandler(server)); - m_server.HttpServer.AddStreamHandler(new NewItemHandler(server)); - m_server.HttpServer.AddStreamHandler(new DeleteItemHandler(server)); - m_server.HttpServer.AddStreamHandler(new RootFoldersHandler(server)); - m_server.HttpServer.AddStreamHandler(new ActiveGesturesHandler(server)); - - m_log.Info("[OPENSIMINVENTORYFRONTEND]: OpenSim Inventory Frontend loaded."); - } - - /// - /// Initialises asset interface - /// - public void Initialise() - { - m_log.InfoFormat("[OPENSIMINVENTORYFRONTEND]: {0} cannot be default-initialized!", Name); - throw new PluginNotInitialisedException(Name); - } - - public void Dispose() - { - } - - public string Version - { - // TODO: this should be something meaningful and not hardcoded? - get { return "0.1"; } - } - - public string Name - { - get { return "OpenSimInventoryFrontend"; } - } - - #endregion IPlugin implementation - - public class GetInventoryHandler : BaseStreamHandler - { - AssetInventoryServer m_server; - Utils.InventoryCollectionSerializer m_collectionSerializer; - - //public GetInventoryHandler(AssetInventoryServer server, Utils.InventoryCollectionSerializer collectionSerializer) : base("POST", @"^/GetInventory/") - public GetInventoryHandler(AssetInventoryServer server, Utils.InventoryCollectionSerializer collectionSerializer) : base("POST", "/GetInventory") - { - m_server = server; - m_collectionSerializer = collectionSerializer; - } - - public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - byte[] buffer = new byte[] {}; - UUID sessionID, agentID; - UUID ownerID = DeserializeUUID(httpRequest.InputStream, out agentID, out sessionID); - - if (ownerID != UUID.Zero) - { - m_log.Warn("[OPENSIMINVENTORYFRONTEND]: GetInventory is not scalable on some inventory backends, avoid calling it wherever possible"); - - Uri owner = Utils.GetOpenSimUri(ownerID); - InventoryCollection inventory; - BackendResponse storageResponse = m_server.InventoryProvider.TryFetchInventory(owner, out inventory); - - if (storageResponse == BackendResponse.Success) - { - //collectionSerializer.Serialize(httpResponse.Body, inventory); - //httpResponse.Body.Flush(); - MemoryStream ms = new MemoryStream(); - m_collectionSerializer.Serialize(ms, inventory); - ms.Seek(0, SeekOrigin.Begin); - buffer = ms.GetBuffer(); - Array.Resize(ref buffer, (int) ms.Length); - ms.Close(); - httpResponse.StatusCode = (int) HttpStatusCode.OK; - } - else if (storageResponse == BackendResponse.NotFound) - { - // Return an empty inventory set to mimic OpenSim.Grid.InventoryServer.exe - inventory = new InventoryCollection(); - inventory.UserID = ownerID; - inventory.Folders = new Dictionary(); - inventory.Items = new Dictionary(); - //collectionSerializer.Serialize(httpResponse.Body, inventory); - //httpResponse.Body.Flush(); - MemoryStream ms = new MemoryStream(); - m_collectionSerializer.Serialize(ms, inventory); - ms.Seek(0, SeekOrigin.Begin); - buffer = ms.GetBuffer(); - Array.Resize(ref buffer, (int) ms.Length); - ms.Close(); - httpResponse.StatusCode = (int) HttpStatusCode.OK; - } - else - { - httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; - } - } - else - { - httpResponse.StatusCode = (int) HttpStatusCode.BadRequest; - } - - return buffer; - } - } - - public class CreateInventoryHandler : BaseStreamHandler - { - AssetInventoryServer m_server; - - //public CreateInventoryHandler(AssetInventoryServer server) : base("POST", @"^/CreateInventory/") - public CreateInventoryHandler(AssetInventoryServer server) : base("POST", "/CreateInventory") - { - m_server = server; - } - - public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - UUID ownerID = DeserializeUUID(httpRequest.InputStream); - - if (ownerID != UUID.Zero) - { - Uri owner = Utils.GetOpenSimUri(ownerID); - m_log.DebugFormat("[OPENSIMINVENTORYFRONTEND]: Created URI {0} for inventory creation", owner); - - InventoryFolderWithChildren rootFolder = new InventoryFolderWithChildren("My Inventory", ownerID, UUID.Zero, (short)AssetType.Folder); - BackendResponse storageResponse = m_server.InventoryProvider.TryCreateInventory(owner, rootFolder); - if (storageResponse == BackendResponse.Success) - { - // TODO: The CreateFolder calls need to be executed in SimpleStorage. - //CreateFolder("Animations", ownerID, rootFolder.ID, AssetType.Animation); - //CreateFolder("Body Parts", ownerID, rootFolder.ID, AssetType.Bodypart); - //CreateFolder("Calling Cards", ownerID, rootFolder.ID, AssetType.CallingCard); - //CreateFolder("Clothing", ownerID, rootFolder.ID, AssetType.Clothing); - //CreateFolder("Gestures", ownerID, rootFolder.ID, AssetType.Gesture); - //CreateFolder("Landmarks", ownerID, rootFolder.ID, AssetType.Landmark); - //CreateFolder("Lost and Found", ownerID, rootFolder.ID, AssetType.LostAndFoundFolder); - //CreateFolder("Notecards", ownerID, rootFolder.ID, AssetType.Notecard); - //CreateFolder("Objects", ownerID, rootFolder.ID, AssetType.Object); - //CreateFolder("Photo Album", ownerID, rootFolder.ID, AssetType.SnapshotFolder); - //CreateFolder("Scripts", ownerID, rootFolder.ID, AssetType.LSLText); - //CreateFolder("Sounds", ownerID, rootFolder.ID, AssetType.Sound); - //CreateFolder("Textures", ownerID, rootFolder.ID, AssetType.Texture); - //CreateFolder("Trash", ownerID, rootFolder.ID, AssetType.TrashFolder); - - return SerializeBool(true); - } - } - - return SerializeBool(false); - } - } - - public class NewFolderHandler : BaseStreamHandler - { - AssetInventoryServer m_server; - - //public NewFolderHandler(AssetInventoryServer server) : base("POST", @"^/NewFolder/") - public NewFolderHandler(AssetInventoryServer server) : base("POST", "/NewFolder") - { - m_server = server; - } - - public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - UUID agentID, sessionID; - InventoryFolderWithChildren folder = DeserializeFolder(httpRequest.InputStream, out agentID, out sessionID); - - if (folder != null) - { - Uri owner = Utils.GetOpenSimUri(folder.Owner); - - // Some calls that are moving or updating a folder instead - // of creating a new one will pass in an InventoryFolder - // without the name set and type set to 0. If this is the - // case we need to look up the name first and preserver - // it's type. - if (String.IsNullOrEmpty(folder.Name)) - { - InventoryFolderWithChildren oldFolder; - if (m_server.InventoryProvider.TryFetchFolder(owner, folder.ID, out oldFolder) == BackendResponse.Success) - { - folder.Name = oldFolder.Name; - folder.Type = oldFolder.Type; - } - } - - BackendResponse storageResponse = m_server.InventoryProvider.TryCreateFolder(owner, folder); - - if (storageResponse == BackendResponse.Success) - { - return SerializeBool(true); - } - } - - return SerializeBool(false); - } - } - - public class UpdateFolderHandler : BaseStreamHandler - { - AssetInventoryServer m_server; - - //public UpdateFolderHandler(AssetInventoryServer server) : base("POST", @"^/UpdateFolder/") - public UpdateFolderHandler(AssetInventoryServer server) : base("POST", "/UpdateFolder") - { - m_server = server; - } - - public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - return new NewFolderHandler(m_server).Handle(path, request, httpRequest, httpResponse); - } - } - - public class MoveFolderHandler : BaseStreamHandler - { - AssetInventoryServer m_server; - - //public MoveFolderHandler(AssetInventoryServer server) : base("POST", @"^/MoveFolder/") - public MoveFolderHandler(AssetInventoryServer server) : base("POST", "/MoveFolder") - { - m_server = server; - } - - public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - return new NewFolderHandler(m_server).Handle(path, request, httpRequest, httpResponse); - } - } - - public class PurgeFolderHandler : BaseStreamHandler - { - AssetInventoryServer m_server; - - //public PurgeFolderHandler(AssetInventoryServer server) : base("POST", @"^/PurgeFolder/") - public PurgeFolderHandler(AssetInventoryServer server) : base("POST", "/PurgeFolder") - { - m_server = server; - } - - public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - UUID agentID, sessionID; - InventoryFolderWithChildren folder = DeserializeFolder(httpRequest.InputStream, out agentID, out sessionID); - - if (folder != null) - { - Uri owner = Utils.GetOpenSimUri(folder.Owner); - BackendResponse storageResponse = m_server.InventoryProvider.TryPurgeFolder(owner, folder.ID); - - if (storageResponse == BackendResponse.Success) - { - return SerializeBool(true); - } - } - - return SerializeBool(false); - } - } - - public class NewItemHandler : BaseStreamHandler - { - AssetInventoryServer m_server; - - //public NewItemHandler(AssetInventoryServer server) : base("POST", @"^/NewItem/") - public NewItemHandler(AssetInventoryServer server) : base("POST", "/NewItem") - { - m_server = server; - } - - public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - UUID agentID, sessionID; - InventoryItemBase item = DeserializeItem(httpRequest.InputStream, out agentID, out sessionID); - - if (item != null) - { - Uri owner = Utils.GetOpenSimUri(agentID); - BackendResponse storageResponse = m_server.InventoryProvider.TryCreateItem(owner, item); - - if (storageResponse == BackendResponse.Success) - { - return SerializeBool(true); - } - } - - return SerializeBool(false); - } - } - - public class DeleteItemHandler : BaseStreamHandler - { - AssetInventoryServer m_server; - - //public DeleteItemHandler(AssetInventoryServer server) : base("POST", @"^/DeleteItem/") - public DeleteItemHandler(AssetInventoryServer server) : base("POST", "/DeleteItem") - { - m_server = server; - } - - public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - UUID agentID, sessionID; - InventoryItemBase item = DeserializeItem(httpRequest.InputStream, out agentID, out sessionID); - - if (item != null) - { - Uri owner = Utils.GetOpenSimUri(item.Owner); - BackendResponse storageResponse = m_server.InventoryProvider.TryDeleteItem(owner, item.ID); - - if (storageResponse == BackendResponse.Success) - { - return SerializeBool(true); - } - } - - return SerializeBool(false); - } - } - - public class RootFoldersHandler : BaseStreamHandler - { - AssetInventoryServer m_server; - - //public RootFoldersHandler(AssetInventoryServer server) : base("POST", @"^/RootFolders/") - public RootFoldersHandler(AssetInventoryServer server) : base("POST", "/RootFolders") - { - m_server = server; - } - - public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - byte[] buffer = new byte[] {}; - UUID ownerID = DeserializeUUID(httpRequest.InputStream); - - if (ownerID != UUID.Zero) - { - Uri owner = Utils.GetOpenSimUri(ownerID); - List skeleton; - BackendResponse storageResponse = m_server.InventoryProvider.TryFetchFolderList(owner, out skeleton); - - if (storageResponse == BackendResponse.Success) - { - MemoryStream ms = new MemoryStream(); - SerializeFolderList(ms, skeleton); - ms.Seek(0, SeekOrigin.Begin); - buffer = ms.GetBuffer(); - Array.Resize(ref buffer, (int) ms.Length); - ms.Close(); - httpResponse.StatusCode = (int) HttpStatusCode.OK; - } - else if (storageResponse == BackendResponse.NotFound) - { - // Return an empty set of inventory so the requester knows that - // an inventory needs to be created for this agent - MemoryStream ms = new MemoryStream(); - SerializeFolderList(ms, new List(0)); - ms.Seek(0, SeekOrigin.Begin); - buffer = ms.GetBuffer(); - Array.Resize(ref buffer, (int) ms.Length); - ms.Close(); - httpResponse.StatusCode = (int) HttpStatusCode.OK; - } - else - { - httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; - } - } - else - { - httpResponse.StatusCode = (int) HttpStatusCode.BadRequest; - } - - return buffer; - } - } - - public class ActiveGesturesHandler : BaseStreamHandler - { - AssetInventoryServer m_server; - - //public ActiveGesturesHandler(AssetInventoryServer server) : base("POST", @"^/ActiveGestures/") - public ActiveGesturesHandler(AssetInventoryServer server) : base("POST", "/ActiveGestures") - { - m_server = server; - } - - public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - byte[] buffer = new byte[] {}; - UUID ownerID = DeserializeUUID(httpRequest.InputStream); - - if (ownerID != UUID.Zero) - { - Uri owner = Utils.GetOpenSimUri(ownerID); - List gestures; - BackendResponse storageResponse = m_server.InventoryProvider.TryFetchActiveGestures(owner, out gestures); - - if (storageResponse == BackendResponse.Success) - { - MemoryStream ms = new MemoryStream(); - SerializeItemList(ms, gestures); - ms.Seek(0, SeekOrigin.Begin); - buffer = ms.GetBuffer(); - Array.Resize(ref buffer, (int) ms.Length); - ms.Close(); - httpResponse.StatusCode = (int) HttpStatusCode.OK; - } - else if (storageResponse == BackendResponse.NotFound) - { - // Return an empty set of gestures to match OpenSim.Grid.InventoryServer.exe behavior - MemoryStream ms = new MemoryStream(); - SerializeItemList(ms, new List(0)); - ms.Seek(0, SeekOrigin.Begin); - buffer = ms.GetBuffer(); - Array.Resize(ref buffer, (int) ms.Length); - ms.Close(); - httpResponse.StatusCode = (int) HttpStatusCode.OK; - } - else - { - httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; - } - } - else - { - httpResponse.StatusCode = (int) HttpStatusCode.BadRequest; - } - - return buffer; - } - } - - //BackendResponse CreateFolder(string name, UUID ownerID, UUID parentID, AssetType assetType) - //{ - // InventoryFolder folder = new InventoryFolder(name, ownerID, parentID, (short)assetType); - // Uri owner = Utils.GetOpenSimUri(ownerID); - // return m_server.InventoryProvider.TryCreateFolder(owner, folder); - //} - - private static UUID DeserializeUUID(Stream stream) - { - UUID id = UUID.Zero; - - try - { - using (XmlReader reader = XmlReader.Create(stream)) - { - reader.MoveToContent(); - UUID.TryParse(reader.ReadElementContentAsString("guid", String.Empty), out id); - } - } - catch (Exception ex) - { - m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse POST data (expecting guid): " + ex.Message); - } - - return id; - } - - private static UUID DeserializeUUID(Stream stream, out UUID agentID, out UUID sessionID) - { - UUID id; - - try - { - using (XmlReader reader = XmlReader.Create(stream)) - { - reader.MoveToContent(); - reader.ReadStartElement("RestSessionObjectOfGuid"); - UUID.TryParse(reader.ReadElementContentAsString("SessionID", String.Empty), out sessionID); - UUID.TryParse(reader.ReadElementContentAsString("AvatarID", String.Empty), out agentID); - UUID.TryParse(reader.ReadElementContentAsString("Body", String.Empty), out id); - reader.ReadEndElement(); - } - } - catch (Exception ex) - { - m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse GetInventory POST data: " + ex.Message); - agentID = UUID.Zero; - sessionID = UUID.Zero; - return UUID.Zero; - } - - return id; - } - - private static InventoryFolderWithChildren DeserializeFolder(Stream stream, out UUID agentID, out UUID sessionID) - { - InventoryFolderWithChildren folder = new InventoryFolderWithChildren(); - - try - { - using (XmlReader reader = XmlReader.Create(stream)) - { - reader.MoveToContent(); - reader.ReadStartElement("RestSessionObjectOfInventoryFolderBase"); - UUID.TryParse(reader.ReadElementContentAsString("SessionID", String.Empty), out sessionID); - UUID.TryParse(reader.ReadElementContentAsString("AvatarID", String.Empty), out agentID); - reader.ReadStartElement("Body"); - if (reader.Name == "Name") - folder.Name = reader.ReadElementContentAsString("Name", String.Empty); - else - folder.Name = String.Empty; - - UUID dummyUUID; - ReadUUID(reader, "ID", out dummyUUID); - folder.ID = dummyUUID; - ReadUUID(reader, "Owner", out dummyUUID); - folder.Owner = dummyUUID; - ReadUUID(reader, "ParentID", out dummyUUID); - folder.ParentID = dummyUUID; - - short dummyType; - Int16.TryParse(reader.ReadElementContentAsString("Type", String.Empty), out dummyType); - folder.Type = dummyType; - - ushort dummyVersion; - UInt16.TryParse(reader.ReadElementContentAsString("Version", String.Empty), out dummyVersion); - folder.Version = dummyVersion; - - reader.ReadEndElement(); - reader.ReadEndElement(); - } - } - catch (Exception ex) - { - m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse POST data (expecting InventoryFolderBase): " + ex.Message); - agentID = UUID.Zero; - sessionID = UUID.Zero; - return null; - } - - return folder; - } - - private static InventoryItemBase DeserializeItem(Stream stream, out UUID agentID, out UUID sessionID) - { - InventoryItemBase item = new InventoryItemBase(); - - try - { - using (XmlReader reader = XmlReader.Create(stream)) - { - reader.MoveToContent(); - reader.ReadStartElement("RestSessionObjectOfInventoryItemBase"); - UUID.TryParse(reader.ReadElementContentAsString("SessionID", String.Empty), out sessionID); - UUID.TryParse(reader.ReadElementContentAsString("AvatarID", String.Empty), out agentID); - reader.ReadStartElement("Body"); - - item.Name = reader.ReadElementContentAsString("Name", String.Empty); - - UUID dummyUUID; - ReadUUID(reader, "ID", out dummyUUID); - item.ID = dummyUUID; - - ReadUUID(reader, "Owner", out dummyUUID); - item.Owner = dummyUUID; - - int dummyInt; - Int32.TryParse(reader.ReadElementContentAsString("InvType", String.Empty), out dummyInt); - item.InvType = dummyInt; - - ReadUUID(reader, "Folder", out dummyUUID); - item.Folder = dummyUUID; - - item.CreatorId = reader.ReadElementContentAsString("CreatorId", String.Empty); - item.Description = reader.ReadElementContentAsString("Description", String.Empty); - - uint dummyUInt; - UInt32.TryParse(reader.ReadElementContentAsString("NextPermissions", String.Empty), out dummyUInt); - item.NextPermissions = dummyUInt; - UInt32.TryParse(reader.ReadElementContentAsString("CurrentPermissions", String.Empty), out dummyUInt); - item.CurrentPermissions = dummyUInt; - UInt32.TryParse(reader.ReadElementContentAsString("BasePermissions", String.Empty), out dummyUInt); - item.BasePermissions = dummyUInt; - UInt32.TryParse(reader.ReadElementContentAsString("EveryOnePermissions", String.Empty), out dummyUInt); - item.EveryOnePermissions = dummyUInt; - UInt32.TryParse(reader.ReadElementContentAsString("GroupPermissions", String.Empty), out dummyUInt); - item.GroupPermissions = dummyUInt; - - Int32.TryParse(reader.ReadElementContentAsString("AssetType", String.Empty), out dummyInt); - item.AssetType = dummyInt; - - ReadUUID(reader, "AssetID", out dummyUUID); - item.AssetID = dummyUUID; - ReadUUID(reader, "GroupID", out dummyUUID); - item.GroupID = dummyUUID; - - bool dummyBool; - Boolean.TryParse(reader.ReadElementContentAsString("GroupOwned", String.Empty), out dummyBool); - item.GroupOwned = dummyBool; - - Int32.TryParse(reader.ReadElementContentAsString("SalePrice", String.Empty), out dummyInt); - item.SalePrice = dummyInt; - - byte dummyByte; - Byte.TryParse(reader.ReadElementContentAsString("SaleType", String.Empty), out dummyByte); - item.SaleType = dummyByte; - - UInt32.TryParse(reader.ReadElementContentAsString("Flags", String.Empty), out dummyUInt); - item.Flags = dummyUInt; - - Int32.TryParse(reader.ReadElementContentAsString("CreationDate", String.Empty), out dummyInt); - item.CreationDate = dummyInt; - - reader.ReadEndElement(); - reader.ReadEndElement(); - } - } - catch (Exception ex) - { - m_log.Warn("[OPENSIMINVENTORYFRONTEND]: Failed to parse POST data (expecting InventoryItemBase): " + ex.Message); - agentID = UUID.Zero; - sessionID = UUID.Zero; - return null; - } - - return item; - } - - private static byte[] SerializeBool(bool value) - { - byte[] buffer; - MemoryStream ms = new MemoryStream(); - - using (XmlWriter writer = XmlWriter.Create(ms)) - { - writer.WriteStartDocument(); - writer.WriteStartElement("boolean"); - writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); - writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); - writer.WriteString(value.ToString().ToLower()); - writer.WriteEndElement(); - writer.WriteEndDocument(); - writer.Flush(); - } - - ms.Seek(0, SeekOrigin.Begin); - buffer = ms.GetBuffer(); - Array.Resize(ref buffer, (int) ms.Length); - ms.Close(); - - return buffer; - } - - private static void SerializeFolderList(Stream stream, List folders) - { - using (XmlWriter writer = XmlWriter.Create(stream)) - { - writer.WriteStartDocument(); - writer.WriteStartElement("ArrayOfInventoryFolderBase"); - writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); - writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); - - if (folders != null) - { - foreach (InventoryFolderWithChildren folder in folders) - { - writer.WriteStartElement("InventoryFolderBase"); - writer.WriteElementString("Name", folder.Name); - WriteUUID(writer, "Owner", folder.Owner); - WriteUUID(writer, "ParentID", folder.ParentID); - WriteUUID(writer, "ID", folder.ID); - writer.WriteElementString("Type", XmlConvert.ToString(folder.Type)); - writer.WriteElementString("Version", XmlConvert.ToString(folder.Version)); - writer.WriteEndElement(); - } - } - - writer.WriteEndElement(); - writer.WriteEndDocument(); - - writer.Flush(); - } - - stream.Flush(); - } - - private static void SerializeItemList(Stream stream, List items) - { - using (XmlWriter writer = XmlWriter.Create(stream)) - { - writer.WriteStartDocument(); - writer.WriteStartElement("ArrayOfInventoryItemBase"); - writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); - writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); - - if (items != null) - { - foreach (InventoryItemBase item in items) - { - writer.WriteStartElement("InventoryItemBase"); - WriteUUID(writer, "ID", item.ID); - writer.WriteElementString("InvType", XmlConvert.ToString(item.InvType)); - WriteUUID(writer, "Folder", item.Folder); - WriteUUID(writer, "Owner", item.Owner); - writer.WriteElementString("Creator", item.CreatorId); - writer.WriteElementString("Name", item.Name); - writer.WriteElementString("Description", item.Description); - writer.WriteElementString("NextPermissions", XmlConvert.ToString(item.NextPermissions)); - writer.WriteElementString("CurrentPermissions", XmlConvert.ToString(item.CurrentPermissions)); - writer.WriteElementString("BasePermissions", XmlConvert.ToString(item.BasePermissions)); - writer.WriteElementString("EveryOnePermissions", XmlConvert.ToString(item.EveryOnePermissions)); - writer.WriteElementString("GroupPermissions", XmlConvert.ToString(item.GroupPermissions)); - writer.WriteElementString("AssetType", XmlConvert.ToString(item.AssetType)); - WriteUUID(writer, "AssetID", item.AssetID); - WriteUUID(writer, "GroupID", item.GroupID); - writer.WriteElementString("GroupOwned", XmlConvert.ToString(item.GroupOwned)); - writer.WriteElementString("SalePrice", XmlConvert.ToString(item.SalePrice)); - writer.WriteElementString("SaleType", XmlConvert.ToString(item.SaleType)); - writer.WriteElementString("Flags", XmlConvert.ToString(item.Flags)); - writer.WriteElementString("CreationDate", XmlConvert.ToString(item.CreationDate)); - writer.WriteEndElement(); - } - } - - writer.WriteEndElement(); - writer.WriteEndDocument(); - - writer.Flush(); - } - - stream.Flush(); - } - - private static void WriteUUID(XmlWriter writer, string name, UUID id) - { - writer.WriteStartElement(name); - writer.WriteElementString("Guid", XmlConvert.ToString(id.Guid)); - writer.WriteEndElement(); - } - - private static void ReadUUID(XmlReader reader, string name, out UUID id) - { - reader.ReadStartElement(name); - UUID.TryParse(reader.ReadElementContentAsString("Guid", String.Empty), out id); - reader.ReadEndElement(); - } - } - - #region OpenSim AssetType - - /// - /// The different types of grid assets - /// - public enum AssetType : sbyte - { - /// Unknown asset type - Unknown = -1, - /// Texture asset, stores in JPEG2000 J2C stream format - Texture = 0, - /// Sound asset - Sound = 1, - /// Calling card for another avatar - CallingCard = 2, - /// Link to a location in world - Landmark = 3, - // Legacy script asset, you should never see one of these - //[Obsolete] - //Script = 4, - /// Collection of textures and parameters that can be - /// worn by an avatar - Clothing = 5, - /// Primitive that can contain textures, sounds, - /// scripts and more - Object = 6, - /// Notecard asset - Notecard = 7, - /// Holds a collection of inventory items - Folder = 8, - /// Root inventory folder - RootFolder = 9, - /// Linden scripting language script - LSLText = 10, - /// LSO bytecode for a script - LSLBytecode = 11, - /// Uncompressed TGA texture - TextureTGA = 12, - /// Collection of textures and shape parameters that can - /// be worn - Bodypart = 13, - /// Trash folder - TrashFolder = 14, - /// Snapshot folder - SnapshotFolder = 15, - /// Lost and found folder - LostAndFoundFolder = 16, - /// Uncompressed sound - SoundWAV = 17, - /// Uncompressed TGA non-square image, not to be used as a - /// texture - ImageTGA = 18, - /// Compressed JPEG non-square image, not to be used as a - /// texture - ImageJPEG = 19, - /// Animation - Animation = 20, - /// Sequence of animations, sounds, chat, and pauses - Gesture = 21, - /// Simstate file - Simstate = 22, - } - - #endregion OpenSim AssetType -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryService.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryService.cs deleted file mode 100644 index 0effa9f..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryService.cs +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using OpenMetaverse; -using OpenSim.Framework; -using OpenSim.Framework.Communications; -using OpenSim.Data; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim -{ - public class OpenSimInventoryService : InventoryServiceBase - { - public InventoryFolderWithChildren GetInventoryFolder(UUID folderID) - { - InventoryFolderBase baseFolder = null; - InventoryFolderWithChildren folder = null; - - foreach (IInventoryDataPlugin plugin in m_plugins) - { - baseFolder = plugin.getInventoryFolder(folderID); - } - - if (null != baseFolder) - { - folder = new InventoryFolderWithChildren(baseFolder); - folder.Children = null; // This call only returns data for the folder itself, no children data - } - - return folder; - } - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs deleted file mode 100644 index 2239b87..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs +++ /dev/null @@ -1,547 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Reflection; -using System.Collections.Generic; -using System.Data; -using OpenMetaverse; -using OpenSim.Framework; -using OpenSim.Data; -using Nini.Config; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim -{ - public class OpenSimInventoryStoragePlugin : IInventoryStorageProvider - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - const string EXTENSION_NAME = "OpenSimInventoryStorage"; // Used in metrics reporting - - private AssetInventoryServer m_server; - private IConfig m_openSimConfig; - private OpenSimInventoryService m_inventoryService; - - public OpenSimInventoryStoragePlugin() - { - } - - #region IInventoryStorageProvider implementation - - public BackendResponse TryFetchItem(Uri owner, UUID itemID, out InventoryItemBase item) - { - item = null; - //BackendResponse ret; - - //using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect"))) - //{ - // IDataReader reader; - - // try - // { - // dbConnection.Open(); - - // IDbCommand command = dbConnection.CreateCommand(); - // command.CommandText = String.Format("SELECT assetID,assetType,inventoryName,inventoryDescription,inventoryNextPermissions," + - // "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + - // "creationDate,groupID,groupOwned,flags,avatarID,parentFolderID,inventoryGroupPermissions FROM inventoryitems WHERE inventoryID='{0}'", - // itemID.ToString()); - // reader = command.ExecuteReader(); - - // if (reader.Read()) - // { - // item = new InventoryItemBase(); - // item.ID = itemID; - // item.AssetID = UUID.Parse(reader.GetString(0)); - // item.AssetType = reader.GetInt32(1); - // item.Name = reader.GetString(2); - // item.Description = reader.GetString(3); - // item.NextPermissions = (uint)reader.GetInt32(4); - // item.CurrentPermissions = (uint)reader.GetInt32(5); - // item.InvType = reader.GetInt32(6); - // item.Creator = UUID.Parse(reader.GetString(7)); - // item.BasePermissions = (uint)reader.GetInt32(8); - // item.EveryOnePermissions = (uint)reader.GetInt32(9); - // item.SalePrice = reader.GetInt32(10); - // item.SaleType = reader.GetByte(11); - // item.CreationDate = reader.GetInt32(12); - // item.GroupID = UUID.Parse(reader.GetString(13)); - // item.GroupOwned = reader.GetBoolean(14); - // item.Flags = (uint)reader.GetInt32(15); - // item.Owner = UUID.Parse(reader.GetString(16)); - // item.Folder = UUID.Parse(reader.GetString(17)); - // item.GroupPermissions = (uint)reader.GetInt32(18); - - // ret = BackendResponse.Success; - // } - // else - // { - // ret = BackendResponse.NotFound; - // } - // } - // catch (MySqlException ex) - // { - // m_log.Error("[OPENSIMINVENTORYSTORAGE]: Connection to MySQL backend failed: " + ex.Message); - // ret = BackendResponse.Failure; - // } - //} - - //m_server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now); - //return ret; - m_log.Warn("[OPENSIMINVENTORYSTORAGE]: Called TryFetchItem which is not implemented."); - return BackendResponse.Success; - } - - public BackendResponse TryFetchFolder(Uri owner, UUID folderID, out InventoryFolderWithChildren folder) - { - BackendResponse ret; - - // TODO: implement some logic for "folder not found" - folder = m_inventoryService.GetInventoryFolder(folderID); - ret = BackendResponse.Success; - - m_server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchFolderContents(Uri owner, UUID folderID, out InventoryCollection contents) - { - contents = null; - //BackendResponse ret; - - //using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect"))) - //{ - // IDataReader reader; - - // try - // { - // dbConnection.Open(); - - // contents = new InventoryCollection(); - - // #region Folder retrieval - - // IDbCommand command = dbConnection.CreateCommand(); - // command.CommandText = String.Format("SELECT folderName,type,version,agentID,folderID FROM inventoryfolders WHERE parentFolderID='{0}'", - // folderID.ToString()); - // reader = command.ExecuteReader(); - - // contents.Folders = new Dictionary(); - - // while (reader.Read()) - // { - // InventoryFolderWithChildren folder = new InventoryFolderWithChildren(); - // folder.ParentID = folderID; - // folder.Children = null; // This call doesn't do recursion - // folder.Name = reader.GetString(0); - // folder.Type = reader.GetInt16(1); - // folder.Version = (ushort)reader.GetInt16(2); - // folder.Owner = UUID.Parse(reader.GetString(3)); - // folder.ID = UUID.Parse(reader.GetString(4)); - - // contents.Folders.Add(folder.ID, folder); - // contents.UserID = folder.Owner; - // } - - // reader.Close(); - - // #endregion Folder retrieval - - // #region Item retrieval - - // command = dbConnection.CreateCommand(); - // command.CommandText = String.Format("SELECT assetID,assetType,inventoryName,inventoryDescription,inventoryNextPermissions," + - // "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + - // "creationDate,groupID,groupOwned,flags,avatarID,inventoryID,inventoryGroupPermissions FROM inventoryitems WHERE parentFolderID='{0}'", - // folderID.ToString()); - // reader = command.ExecuteReader(); - - // contents.Items = new Dictionary(); - - // while (reader.Read()) - // { - // InventoryItemBase item = new InventoryItemBase(); - // item.Folder = folderID; - // item.AssetID = UUID.Parse(reader.GetString(0)); - // item.AssetType = reader.GetInt32(1); - // item.Name = reader.GetString(2); - // item.Description = reader.GetString(3); - // item.NextPermissions = (uint)reader.GetInt32(4); - // item.CurrentPermissions = (uint)reader.GetInt32(5); - // item.InvType = reader.GetInt32(6); - // item.Creator = UUID.Parse(reader.GetString(7)); - // item.BasePermissions = (uint)reader.GetInt32(8); - // item.EveryOnePermissions = (uint)reader.GetInt32(9); - // item.SalePrice = reader.GetInt32(10); - // item.SaleType = reader.GetByte(11); - // item.CreationDate = reader.GetInt32(12); - // item.GroupID = UUID.Parse(reader.GetString(13)); - // item.GroupOwned = reader.GetBoolean(14); - // item.Flags = (uint)reader.GetInt32(15); - // item.Owner = UUID.Parse(reader.GetString(16)); - // item.ID = UUID.Parse(reader.GetString(17)); - // item.GroupPermissions = (uint)reader.GetInt32(18); - - // contents.Items.Add(item.ID, item); - // contents.UserID = item.Owner; - // } - - // #endregion Item retrieval - - // ret = BackendResponse.Success; - // } - // catch (MySqlException ex) - // { - // m_log.Error("[OPENSIMINVENTORYSTORAGE]: Connection to MySQL backend failed: " + ex.Message); - // ret = BackendResponse.Failure; - // } - //} - - //m_server.MetricsProvider.LogInventoryFetchFolderContents(EXTENSION_NAME, ret, owner, folderID, DateTime.Now); - //return ret; - m_log.Warn("[OPENSIMINVENTORYSTORAGE]: Called TryFetchFolderContents which is not implemented."); - return BackendResponse.Success; - } - - public BackendResponse TryFetchFolderList(Uri owner, out List folders) - { - folders = new List(); - BackendResponse ret; - UUID ownerID; - - if (Utils.TryGetOpenSimUUID(owner, out ownerID)) - { - List baseFolders = m_inventoryService.GetInventorySkeleton(ownerID); - foreach (InventoryFolderBase baseFolder in baseFolders) - { - InventoryFolderWithChildren folder = new InventoryFolderWithChildren(baseFolder); - //folder.Children = null; // This call does not create a folder hierarchy - folders.Add(folder); - } - - ret = BackendResponse.Success; - } - else - { - folders = null; - ret = BackendResponse.NotFound; - } - - m_server.MetricsProvider.LogInventoryFetchFolderList(EXTENSION_NAME, ret, owner, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchInventory(Uri owner, out InventoryCollection inventory) - { - inventory = null; - BackendResponse ret; - List folders; - - ret = TryFetchFolderList(owner, out folders); - - if (ret == BackendResponse.Success) - { - // Add the retrieved folders to the inventory collection - inventory = new InventoryCollection(); - inventory.Folders = new Dictionary(folders.Count); - foreach (InventoryFolderWithChildren folder in folders) - inventory.Folders[folder.ID] = folder; - - // Fetch inventory items - UUID ownerID; - if (Utils.TryGetOpenSimUUID(owner, out ownerID)) - { - inventory.UserID = ownerID; - inventory.Items = new Dictionary(); - - foreach (InventoryFolderWithChildren folder in folders) - { - foreach (InventoryItemBase item in m_inventoryService.RequestFolderItems(folder.ID)) - { - inventory.Items.Add(item.ID, item); - } - } - - ret = BackendResponse.Success; - - } - else - { - ret = BackendResponse.NotFound; - } - } - - m_server.MetricsProvider.LogInventoryFetchInventory(EXTENSION_NAME, ret, owner, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchActiveGestures(Uri owner, out List gestures) - { - gestures = null; - BackendResponse ret; - UUID ownerID; - - if (Utils.TryGetOpenSimUUID(owner, out ownerID)) - { - gestures = m_inventoryService.GetActiveGestures(ownerID); - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.NotFound; - } - - m_server.MetricsProvider.LogInventoryFetchActiveGestures(EXTENSION_NAME, ret, owner, DateTime.Now); - return ret; - } - - public BackendResponse TryCreateItem(Uri owner, InventoryItemBase item) - { - BackendResponse ret; - - if (m_inventoryService.AddItem(item)) - { - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.Failure; - } - - m_server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, false, DateTime.Now); - return ret; - } - - public BackendResponse TryCreateFolder(Uri owner, InventoryFolderWithChildren folder) - { - BackendResponse ret; - - if (m_inventoryService.AddFolder(folder)) - { - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.Failure; - } - - m_server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, true, DateTime.Now); - return ret; - } - - public BackendResponse TryCreateInventory(Uri owner, InventoryFolderWithChildren rootFolder) - { - BackendResponse ret; - UUID ownerID; - - if (Utils.TryGetOpenSimUUID(owner, out ownerID)) - { - if (m_inventoryService.CreateNewUserInventory(ownerID)) - { - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.Failure; - } - } - else - { - ret = BackendResponse.Failure; - } - - return ret; - } - - public BackendResponse TryDeleteItem(Uri owner, UUID itemID) - { - BackendResponse ret; - - if (m_inventoryService.DeleteItem(m_inventoryService.GetInventoryItem(itemID))) - { - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.Failure; - } - - m_server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now); - return ret; - } - - public BackendResponse TryDeleteFolder(Uri owner, UUID folderID) - { - //BackendResponse ret; - //UUID ownerID; - - //if (Utils.TryGetOpenSimUUID(owner, out ownerID)) - //{ - // using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect"))) - // { - // try - // { - // dbConnection.Open(); - - // MySqlCommand command = new MySqlCommand( - // "DELETE FROM inventoryfolders WHERE folderID=?folderID AND agentID=?agentID", dbConnection); - - // command.Parameters.AddWithValue("?folderID", folderID.ToString()); - // command.Parameters.AddWithValue("?agentID", ownerID.ToString()); - - // int rowsAffected = command.ExecuteNonQuery(); - // if (rowsAffected == 1) - // { - // ret = BackendResponse.Success; - // } - // else - // { - // m_log.ErrorFormat("[OPENSIMINVENTORYSTORAGE]: MySQL DELETE query affected {0} rows", rowsAffected); - // ret = BackendResponse.NotFound; - // } - // } - // catch (MySqlException ex) - // { - // m_log.Error("[OPENSIMINVENTORYSTORAGE]: Connection to MySQL backend failed: " + ex.Message); - // ret = BackendResponse.Failure; - // } - // } - //} - //else - //{ - // ret = BackendResponse.NotFound; - //} - - //m_server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now); - //return ret; - m_log.Warn("[OPENSIMINVENTORYSTORAGE]: Called TryDeleteFolder which is not implemented."); - return BackendResponse.Success; - } - - public BackendResponse TryPurgeFolder(Uri owner, UUID folderID) - { - BackendResponse ret; - - if (m_inventoryService.PurgeFolder(m_inventoryService.GetInventoryFolder(folderID))) - { - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.Failure; - } - - m_server.MetricsProvider.LogInventoryPurgeFolder(EXTENSION_NAME, ret, owner, folderID, DateTime.Now); - return ret; - } - - public int ForEach(Action action, int start, int count) - { - int rowCount = 0; - - //using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect"))) - //{ - // MySqlDataReader reader; - - // try - // { - // dbConnection.Open(); - - // MySqlCommand command = dbConnection.CreateCommand(); - // command.CommandText = String.Format("SELECT name,description,assetType,temporary,data,id FROM assets LIMIT {0}, {1}", - // start, count); - // reader = command.ExecuteReader(); - // } - // catch (MySqlException ex) - // { - // m_log.Error("[OPENSIMINVENTORYSTORAGE]: Connection to MySQL backend failed: " + ex.Message); - // return 0; - // } - - // while (reader.Read()) - // { - // Metadata metadata = new Metadata(); - // metadata.CreationDate = OpenMetaverse.Utils.Epoch; - // metadata.Description = reader.GetString(1); - // metadata.ID = UUID.Parse(reader.GetString(5)); - // metadata.Name = reader.GetString(0); - // metadata.SHA1 = OpenMetaverse.Utils.SHA1((byte[])reader.GetValue(4)); - // metadata.Temporary = reader.GetBoolean(3); - // metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); - - // action(metadata); - // ++rowCount; - // } - - // reader.Close(); - //} - - return rowCount; - } - - #endregion IInventoryStorageProvider implementation - - #region IPlugin implementation - - public void Initialise(AssetInventoryServer server) - { - m_server = server; - m_openSimConfig = server.ConfigFile.Configs["OpenSim"]; - - m_inventoryService = new OpenSimInventoryService(); - m_inventoryService.AddPlugin(m_openSimConfig.GetString("inventory_database_provider"), - m_openSimConfig.GetString("inventory_database_connect")); - } - - public void Stop() - { - } - - public void Initialise() - { - m_log.InfoFormat("[OPENSIMINVENTORYSTORAGE]: {0} cannot be default-initialized!", Name); - throw new PluginNotInitialisedException(Name); - } - - public void Dispose() - { - } - - public string Version - { - // TODO: this should be something meaningful and not hardcoded? - get { return "0.1"; } - } - - public string Name - { - get { return "OpenSimInventoryStorage"; } - } - - #endregion IPlugin implementation - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/Resources/AssetInventoryServerOpenSimPlugins.addin.xml b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/Resources/AssetInventoryServerOpenSimPlugins.addin.xml deleted file mode 100644 index 8cd7585..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/Resources/AssetInventoryServerOpenSimPlugins.addin.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs deleted file mode 100644 index b5ad1a1..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs +++ /dev/null @@ -1,369 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.IO; -using System.Reflection; -using System.Net; -using OpenMetaverse; -using OpenMetaverse.StructuredData; -using OpenSim.Framework; -using OpenSim.Framework.Servers; -using OpenSim.Framework.Servers.HttpServer; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins -{ - public class ReferenceFrontendPlugin : IAssetInventoryServerPlugin - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - AssetInventoryServer m_server; - - public ReferenceFrontendPlugin() - { - } - - #region IPlugin implementation - - public void Initialise(AssetInventoryServer server) - { - m_server = server; - - // Asset metadata request - //m_server.HttpServer.AddStreamHandler(new MetadataRequestHandler(server)); - - // Asset data request - m_server.HttpServer.AddStreamHandler(new DataRequestHandler(server)); - - // Asset creation - //m_server.HttpServer.AddStreamHandler(new CreateRequestHandler(server)); - - m_log.Info("[REFERENCEFRONTEND]: Reference Frontend loaded."); - } - - /// - /// Initialises asset interface - /// - public void Initialise() - { - m_log.InfoFormat("[REFERENCEFRONTEND]: {0} cannot be default-initialized!", Name); - throw new PluginNotInitialisedException(Name); - } - - public void Dispose() - { - } - - public string Version - { - // TODO: this should be something meaningful and not hardcoded? - get { return "0.1"; } - } - - public string Name - { - get { return "ReferenceFrontend"; } - } - - #endregion IPlugin implementation - - //public class MetadataRequestHandler : IStreamedRequestHandler - //{ - // AssetInventoryServer m_server; - // string m_contentType; - // string m_httpMethod; - // string m_path; - - // public MetadataRequestHandler(AssetInventoryServer server) - // { - // m_server = server; - // m_contentType = null; - // m_httpMethod = "GET"; - // m_path = @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/metadata"; - // } - - // #region IStreamedRequestHandler implementation - - // public string ContentType - // { - // get { return m_contentType; } - // } - - // public string HttpMethod - // { - // get { return m_httpMethod; } - // } - - // public string Path - // { - // get { return m_path; } - // } - - // public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - // { - // byte[] serializedData = null; - // UUID assetID; - // // Split the URL up into an AssetID and a method - // string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/'); - - // if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID)) - // { - // UUID authToken = Utils.GetAuthToken(httpRequest); - - // if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID)) - // { - // AssetMetadata metadata; - // BackendResponse storageResponse = m_server.StorageProvider.TryFetchMetadata(assetID, out metadata); - - // if (storageResponse == BackendResponse.Success) - // { - // // If the asset data location wasn't specified in the metadata, specify it - // // manually here by pointing back to this asset server - // if (!metadata.Methods.ContainsKey("data")) - // { - // metadata.Methods["data"] = new Uri(String.Format("{0}://{1}/{2}/data", - // httpRequest.Url.Scheme, httpRequest.Url.Authority, assetID)); - // } - - // serializedData = metadata.SerializeToBytes(); - - // httpResponse.StatusCode = (int) HttpStatusCode.OK; - // httpResponse.ContentType = "application/json"; - // httpResponse.ContentLength = serializedData.Length; - // httpResponse.Body.Write(serializedData, 0, serializedData.Length); - // } - // else if (storageResponse == BackendResponse.NotFound) - // { - // m_log.Warn("[REFERENCEFRONTEND]: Could not find metadata for asset " + assetID.ToString()); - // httpResponse.StatusCode = (int) HttpStatusCode.NotFound; - // } - // else - // { - // httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; - // } - // } - // else - // { - // httpResponse.StatusCode = (int) HttpStatusCode.Forbidden; - // } - - // return serializedData; - // } - - // httpResponse.StatusCode = (int) HttpStatusCode.NotFound; - // return serializedData; - // } - - // #endregion IStreamedRequestHandler implementation - //} - - public class DataRequestHandler : IStreamedRequestHandler - { - AssetInventoryServer m_server; - string m_contentType; - string m_httpMethod; - string m_path; - - public DataRequestHandler(AssetInventoryServer server) - { - m_server = server; - m_contentType = null; - m_httpMethod = "GET"; - m_path = @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/data"; - } - - #region IStreamedRequestHandler implementation - - public string ContentType - { - get { return m_contentType; } - } - - public string HttpMethod - { - get { return m_httpMethod; } - } - - public string Path - { - get { return m_path; } - } - - public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - byte[] assetData = null; - UUID assetID; - // Split the URL up into an AssetID and a method - string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/'); - - if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID)) - { - UUID authToken = Utils.GetAuthToken(httpRequest); - - if (m_server.AuthorizationProvider.IsDataAuthorized(authToken, assetID)) - { - BackendResponse storageResponse = m_server.StorageProvider.TryFetchData(assetID, out assetData); - - if (storageResponse == BackendResponse.Success) - { - httpResponse.StatusCode = (int) HttpStatusCode.OK; - httpResponse.ContentType = "application/octet-stream"; - httpResponse.AddHeader("Content-Disposition", "attachment; filename=" + assetID.ToString()); - httpResponse.ContentLength = assetData.Length; - httpResponse.Body.Write(assetData, 0, assetData.Length); - } - else if (storageResponse == BackendResponse.NotFound) - { - httpResponse.StatusCode = (int) HttpStatusCode.NotFound; - } - else - { - httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; - } - } - else - { - httpResponse.StatusCode = (int) HttpStatusCode.Forbidden; - } - - return assetData; - } - - httpResponse.StatusCode = (int) HttpStatusCode.BadRequest; - return assetData; - } - - #endregion IStreamedRequestHandler implementation - } - - //public class CreateRequestHandler : IStreamedRequestHandler - //{ - // AssetInventoryServer m_server; - // string m_contentType; - // string m_httpMethod; - // string m_path; - - // public CreateRequestHandler(AssetInventoryServer server) - // { - // m_server = server; - // m_contentType = null; - // m_httpMethod = "POST"; - // m_path = "^/createasset"; - // } - - // #region IStreamedRequestHandler implementation - - // public string ContentType - // { - // get { return m_contentType; } - // } - - // public string HttpMethod - // { - // get { return m_httpMethod; } - // } - - // public string Path - // { - // get { return m_path; } - // } - - // public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) - // { - // byte[] responseData = null; - // UUID authToken = Utils.GetAuthToken(httpRequest); - - // if (m_server.AuthorizationProvider.IsCreateAuthorized(authToken)) - // { - // try - // { - // OSD osdata = OSDParser.DeserializeJson(new StreamReader(httpRequest.InputStream).ReadToEnd()); - - // if (osdata.Type == OSDType.Map) - // { - // OSDMap map = (OSDMap)osdata; - // Metadata metadata = new Metadata(); - // metadata.Deserialize(map); - - // byte[] assetData = map["data"].AsBinary(); - - // if (assetData != null && assetData.Length > 0) - // { - // BackendResponse storageResponse; - - // if (metadata.ID != UUID.Zero) - // storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData); - // else - // storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID); - - // if (storageResponse == BackendResponse.Success) - // { - // httpResponse.StatusCode = (int) HttpStatusCode.Created; - // OSDMap responseMap = new OSDMap(1); - // responseMap["id"] = OSD.FromUUID(metadata.ID); - // LitJson.JsonData jsonData = OSDParser.SerializeJson(responseMap); - // responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson()); - // httpResponse.Body.Write(responseData, 0, responseData.Length); - // httpResponse.Body.Flush(); - // } - // else if (storageResponse == BackendResponse.NotFound) - // { - // httpResponse.StatusCode = (int) HttpStatusCode.NotFound; - // } - // else - // { - // httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; - // } - // } - // else - // { - // httpResponse.StatusCode = (int) HttpStatusCode.BadRequest; - // } - // } - // else - // { - // httpResponse.StatusCode = (int) HttpStatusCode.BadRequest; - // } - // } - // catch (Exception ex) - // { - // httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; - // httpResponse.StatusDescription = ex.Message; - // } - // } - // else - // { - // httpResponse.StatusCode = (int) HttpStatusCode.Forbidden; - // } - - // return responseData; - // } - - // #endregion IStreamedRequestHandler implementation - //} - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml b/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml deleted file mode 100644 index 42a279d..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/Resources/AssetInventoryServerPlugins.addin.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/Resources/AssetInventoryServerSimplePlugins.addin.xml b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/Resources/AssetInventoryServerSimplePlugins.addin.xml deleted file mode 100644 index cb6959e..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/Resources/AssetInventoryServerSimplePlugins.addin.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs deleted file mode 100644 index 4ec2d96..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Reflection; -using System.Collections.Generic; -using System.IO; -using OpenMetaverse; -using OpenSim.Framework; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple -{ - public class SimpleAssetStoragePlugin : IAssetStorageProvider - { - const string EXTENSION_NAME = "SimpleAssetStorage"; // Used in metrics reporting - const string DEFAULT_DATA_DIR = "SimpleAssets"; - const string TEMP_DATA_DIR = "SimpleAssetsTemp"; - - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - AssetInventoryServer server; - Dictionary metadataStorage; - Dictionary filenames; - - public SimpleAssetStoragePlugin() - { - } - - #region Required Interfaces - - public BackendResponse TryFetchMetadata(UUID assetID, out AssetMetadata metadata) - { - metadata = null; - BackendResponse ret; - - if (metadataStorage.TryGetValue(assetID, out metadata)) - ret = BackendResponse.Success; - else - ret = BackendResponse.NotFound; - - server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchData(UUID assetID, out byte[] assetData) - { - assetData = null; - string filename; - BackendResponse ret; - - if (filenames.TryGetValue(assetID, out filename)) - { - try - { - assetData = File.ReadAllBytes(filename); - ret = BackendResponse.Success; - } - catch (Exception ex) - { - m_log.ErrorFormat("[SIMPLEASSETSTORAGE]: Failed reading data for asset {0} from {1}: {2}", assetID, filename, ex.Message); - ret = BackendResponse.Failure; - } - } - else - { - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now); - return ret; - } - - public BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset) - { - asset = new AssetBase(); - AssetMetadata metadata = asset.Metadata; - - string filename; - BackendResponse ret; - - if (metadataStorage.TryGetValue(assetID, out metadata) && - filenames.TryGetValue(assetID, out filename)) - { - try - { - asset.Data = File.ReadAllBytes(filename); - ret = BackendResponse.Success; - } - catch (Exception ex) - { - m_log.ErrorFormat("[SIMPLEASSETSTORAGE]: Failed reading data for asset {0} from {1}: {2}", assetID, filename, ex.Message); - ret = BackendResponse.Failure; - } - - asset.Type = (sbyte) Utils.ContentTypeToSLAssetType(metadata.ContentType); - asset.Local = false; - } - else - { - asset = null; - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); - server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (asset != null && asset.Data != null ? asset.Data.Length : 0), DateTime.Now); - return ret; - } - - public BackendResponse TryCreateAsset(AssetBase asset, out UUID assetID) - { - assetID = asset.FullID = UUID.Random(); - return TryCreateAsset(asset); - } - - public BackendResponse TryCreateAsset(AssetBase asset) - { - BackendResponse ret; - AssetMetadata metadata = asset.Metadata; - - string path; - string filename = String.Format("{0}.{1}", asset.FullID, Utils.ContentTypeToExtension(metadata.ContentType)); - - if (asset.Temporary) - path = Path.Combine(TEMP_DATA_DIR, filename); - else - path = Path.Combine(DEFAULT_DATA_DIR, filename); - - try - { - File.WriteAllBytes(path, asset.Data); - lock (filenames) filenames[asset.FullID] = path; - - // Set the creation date to right now - metadata.CreationDate = DateTime.Now; - - lock (metadataStorage) - metadataStorage[asset.FullID] = metadata; - - ret = BackendResponse.Success; - } - catch (Exception ex) - { - m_log.ErrorFormat("[SIMPLEASSETSTORAGE]: Failed writing data for asset {0} to {1}: {2}", asset.FullID, filename, ex.Message); - ret = BackendResponse.Failure; - } - - server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, asset.FullID, asset.Data.Length, DateTime.Now); - return ret; - } - - public int ForEach(Action action, int start, int count) - { - int rowCount = 0; - - //lock (metadataStorage) - //{ - // foreach (Metadata metadata in metadataStorage.Values) - // { - // action(metadata); - // ++rowCount; - // } - //} - - return rowCount; - } - - #endregion Required Interfaces - - #region IPlugin implementation - - public void Initialise(AssetInventoryServer server) - { - this.server = server; - - metadataStorage = new Dictionary(); - filenames = new Dictionary(); - - LoadFiles(DEFAULT_DATA_DIR, false); - LoadFiles(TEMP_DATA_DIR, true); - - m_log.InfoFormat("[SIMPLEASSETSTORAGE]: Initialized the store index with metadata for {0} assets", - metadataStorage.Count); - } - - /// - /// Initialises asset interface - /// - public void Initialise() - { - m_log.InfoFormat("[SIMPLEASSETSTORAGE]: {0} cannot be default-initialized!", Name); - throw new PluginNotInitialisedException(Name); - } - - public void Dispose() - { - WipeTemporary(); - } - - public string Version - { - // TODO: this should be something meaningful and not hardcoded? - get { return "0.1"; } - } - - public string Name - { - get { return "SimpleAssetStorage"; } - } - - #endregion IPlugin implementation - - public void WipeTemporary() - { - if (Directory.Exists(TEMP_DATA_DIR)) - { - try { Directory.Delete(TEMP_DATA_DIR); } - catch (Exception ex) { m_log.Error("[SIMPLEASSETSTORAGE]: " + ex.Message); } - } - } - - void LoadFiles(string folder, bool temporary) - { - // Try to create the directory if it doesn't already exist - if (!Directory.Exists(folder)) - { - try { Directory.CreateDirectory(folder); } - catch (Exception ex) - { - m_log.Warn("[SIMPLEASSETSTORAGE]: " + ex.Message); - return; - } - } - - lock (metadataStorage) - { - try - { - string[] assets = Directory.GetFiles(folder); - - for (int i = 0; i < assets.Length; i++) - { - string filename = assets[i]; - byte[] data = File.ReadAllBytes(filename); - - AssetMetadata metadata = new AssetMetadata(); - metadata.CreationDate = File.GetCreationTime(filename); - metadata.Description = String.Empty; - metadata.FullID = SimpleUtils.ParseUUIDFromFilename(filename); - metadata.Name = SimpleUtils.ParseNameFromFilename(filename); - metadata.SHA1 = OpenMetaverse.Utils.SHA1(data); - metadata.Temporary = false; - metadata.ContentType = Utils.ExtensionToContentType(Path.GetExtension(filename).TrimStart('.')); - - // Store the loaded data - metadataStorage[metadata.FullID] = metadata; - filenames[metadata.FullID] = filename; - } - } - catch (Exception ex) - { - m_log.Warn("[SIMPLEASSETSTORAGE]: " + ex.Message); - } - } - } - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleInventoryStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleInventoryStoragePlugin.cs deleted file mode 100644 index 4010818..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleInventoryStoragePlugin.cs +++ /dev/null @@ -1,625 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Reflection; -using System.Collections.Generic; -using System.IO; -using System.Text; -using OpenMetaverse; -using OpenSim.Framework; -using log4net; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple -{ - public class SimpleInventoryStoragePlugin : IInventoryStorageProvider - { - const string EXTENSION_NAME = "SimpleInventoryStorage"; // Used for metrics reporting - const string DEFAULT_INVENTORY_DIR = "SimpleInventory"; - - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - AssetInventoryServer server; - Dictionary inventories = new Dictionary(); - Dictionary> activeGestures = new Dictionary>(); - Utils.InventoryItemSerializer itemSerializer = new Utils.InventoryItemSerializer(); - Utils.InventoryFolderSerializer folderSerializer = new Utils.InventoryFolderSerializer(); - - public SimpleInventoryStoragePlugin() - { - } - - #region Required Interfaces - - public BackendResponse TryFetchItem(Uri owner, UUID itemID, out InventoryItemBase item) - { - item = null; - BackendResponse ret; - - InventoryCollection collection; - if (inventories.TryGetValue(owner, out collection) && collection.Items.TryGetValue(itemID, out item)) - ret = BackendResponse.Success; - else - ret = BackendResponse.NotFound; - - server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchFolder(Uri owner, UUID folderID, out InventoryFolderWithChildren folder) - { - folder = null; - BackendResponse ret; - - InventoryCollection collection; - if (inventories.TryGetValue(owner, out collection) && collection.Folders.TryGetValue(folderID, out folder)) - ret = BackendResponse.Success; - else - ret = BackendResponse.NotFound; - - server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchFolderContents(Uri owner, UUID folderID, out InventoryCollection contents) - { - contents = null; - BackendResponse ret; - - InventoryCollection collection; - InventoryFolderWithChildren folder; - - if (inventories.TryGetValue(owner, out collection) && collection.Folders.TryGetValue(folderID, out folder)) - { - contents = new InventoryCollection(); - contents.UserID = collection.UserID; - contents.Folders = new Dictionary(); - contents.Items = new Dictionary(); - - foreach (InventoryNodeBase invBase in folder.Children.Values) - { - if (invBase is InventoryItemBase) - { - InventoryItemBase invItem = invBase as InventoryItemBase; - contents.Items.Add(invItem.ID, invItem); - } - else - { - InventoryFolderWithChildren invFolder = invBase as InventoryFolderWithChildren; - contents.Folders.Add(invFolder.ID, invFolder); - } - } - - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogInventoryFetchFolderContents(EXTENSION_NAME, ret, owner, folderID, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchFolderList(Uri owner, out List folders) - { - folders = null; - BackendResponse ret; - - InventoryCollection collection; - if (inventories.TryGetValue(owner, out collection)) - { - folders = new List(collection.Folders.Values); - return BackendResponse.Success; - } - else - { - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogInventoryFetchFolderList(EXTENSION_NAME, ret, owner, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchInventory(Uri owner, out InventoryCollection inventory) - { - inventory = null; - BackendResponse ret; - - if (inventories.TryGetValue(owner, out inventory)) - ret = BackendResponse.Success; - else - ret = BackendResponse.NotFound; - - server.MetricsProvider.LogInventoryFetchInventory(EXTENSION_NAME, ret, owner, DateTime.Now); - return ret; - } - - public BackendResponse TryFetchActiveGestures(Uri owner, out List gestures) - { - gestures = null; - BackendResponse ret; - - if (activeGestures.TryGetValue(owner, out gestures)) - ret = BackendResponse.Success; - else - ret = BackendResponse.NotFound; - - server.MetricsProvider.LogInventoryFetchActiveGestures(EXTENSION_NAME, ret, owner, DateTime.Now); - return ret; - } - - public BackendResponse TryCreateItem(Uri owner, InventoryItemBase item) - { - BackendResponse ret; - - InventoryCollection collection; - if (inventories.TryGetValue(owner, out collection)) - { - // Delete this item first if it already exists - InventoryItemBase oldItem; - if (collection.Items.TryGetValue(item.ID, out oldItem)) - TryDeleteItem(owner, item.ID); - - try - { - // Create the file - SaveItem(item); - - // Add the item to the collection - lock (collection) collection.Items[item.ID] = item; - - // Add the item to its parent folder - InventoryFolderWithChildren parent; - if (collection.Folders.TryGetValue(item.Folder, out parent)) - lock (parent.Children) parent.Children.Add(item.ID, item); - - // Add active gestures to our list - if (item.InvType == (int)InventoryType.Gesture && item.Flags == 1) - { - lock (activeGestures) - activeGestures[owner].Add(item); - } - - ret = BackendResponse.Success; - } - catch (Exception ex) - { - m_log.Error("[SIMPLEINVENTORYSTORAGE]: " + ex.Message); - ret = BackendResponse.Failure; - } - } - else - { - return BackendResponse.NotFound; - } - - server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, false, DateTime.Now); - return ret; - } - - public BackendResponse TryCreateFolder(Uri owner, InventoryFolderWithChildren folder) - { - BackendResponse ret; - - InventoryCollection collection; - if (inventories.TryGetValue(owner, out collection)) - { - // Delete this folder first if it already exists - InventoryFolderWithChildren oldFolder; - if (collection.Folders.TryGetValue(folder.ID, out oldFolder)) - TryDeleteFolder(owner, folder.ID); - - try - { - // Create the file - SaveFolder(folder); - - // Add the folder to the collection - lock (collection) collection.Folders[folder.ID] = folder; - - // Add the folder to its parent folder - InventoryFolderWithChildren parent; - if (collection.Folders.TryGetValue(folder.ParentID, out parent)) - lock (parent.Children) parent.Children.Add(folder.ID, folder); - - ret = BackendResponse.Success; - } - catch (Exception ex) - { - m_log.Error("[SIMPLEINVENTORYSTORAGE]: " + ex.Message); - ret = BackendResponse.Failure; - } - } - else - { - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, true, DateTime.Now); - return ret; - } - - public BackendResponse TryCreateInventory(Uri owner, InventoryFolderWithChildren rootFolder) - { - BackendResponse ret; - - lock (inventories) - { - if (!inventories.ContainsKey(owner)) - { - InventoryCollection collection = new InventoryCollection(); - collection.UserID = rootFolder.Owner; - collection.Folders = new Dictionary(); - collection.Folders.Add(rootFolder.ID, rootFolder); - collection.Items = new Dictionary(); - - inventories.Add(owner, collection); - - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.Failure; - } - } - - if (ret == BackendResponse.Success) - { - string path = Path.Combine(DEFAULT_INVENTORY_DIR, rootFolder.Owner.ToString()); - try - { - // Create the directory for this agent - Directory.CreateDirectory(path); - - // Create an index.txt containing the UUID and URI for this agent - string[] index = new string[] { rootFolder.Owner.ToString(), owner.ToString() }; - File.WriteAllLines(Path.Combine(path, "index.txt"), index); - - // Create the root folder file - SaveFolder(rootFolder); - } - catch (Exception ex) - { - m_log.Error("[SIMPLEINVENTORYSTORAGE]: " + ex.Message); - ret = BackendResponse.Failure; - } - } - - server.MetricsProvider.LogInventoryCreateInventory(EXTENSION_NAME, ret, DateTime.Now); - return ret; - } - - public BackendResponse TryDeleteItem(Uri owner, UUID itemID) - { - BackendResponse ret; - - InventoryCollection collection; - InventoryItemBase item; - if (inventories.TryGetValue(owner, out collection) && collection.Items.TryGetValue(itemID, out item)) - { - // Remove the item from its parent folder - InventoryFolderWithChildren parent; - if (collection.Folders.TryGetValue(item.Folder, out parent)) - lock (parent.Children) parent.Children.Remove(itemID); - - // Remove the item from the collection - lock (collection) collection.Items.Remove(itemID); - - // Remove from the active gestures list if applicable - if (item.InvType == (int)InventoryType.Gesture) - { - lock (activeGestures) - { - for (int i = 0; i < activeGestures[owner].Count; i++) - { - if (activeGestures[owner][i].ID == itemID) - { - activeGestures[owner].RemoveAt(i); - break; - } - } - } - } - - // Delete the file. We don't know exactly what the file name is, - // so search for it - string path = PathFromURI(owner); - string[] matches = Directory.GetFiles(path, String.Format("*{0}.item", itemID), SearchOption.TopDirectoryOnly); - foreach (string match in matches) - { - try { File.Delete(match); } - catch (Exception ex) { m_log.ErrorFormat("[SIMPLEINVENTORYSTORAGE]: Failed to delete file {0}: {1}", match, ex.Message); } - } - - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now); - return ret; - } - - public BackendResponse TryDeleteFolder(Uri owner, UUID folderID) - { - BackendResponse ret; - - InventoryCollection collection; - InventoryFolderWithChildren folder; - if (inventories.TryGetValue(owner, out collection) && collection.Folders.TryGetValue(folderID, out folder)) - { - // Remove the folder from its parent folder - InventoryFolderWithChildren parent; - if (collection.Folders.TryGetValue(folder.ParentID, out parent)) - lock (parent.Children) parent.Children.Remove(folderID); - - // Remove the folder from the collection - lock (collection) collection.Items.Remove(folderID); - - // Delete the folder file. We don't know exactly what the file name is, - // so search for it - string path = PathFromURI(owner); - string[] matches = Directory.GetFiles(path, String.Format("*{0}.folder", folderID), SearchOption.TopDirectoryOnly); - foreach (string match in matches) - { - try { File.Delete(match); } - catch (Exception ex) { m_log.ErrorFormat("[SIMPLEINVENTORYSTORAGE]: Failed to delete folder file {0}: {1}", match, ex.Message); } - } - - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now); - return ret; - } - - public BackendResponse TryPurgeFolder(Uri owner, UUID folderID) - { - BackendResponse ret; - - InventoryCollection collection; - InventoryFolderWithChildren folder; - if (inventories.TryGetValue(owner, out collection) && collection.Folders.TryGetValue(folderID, out folder)) - { - // Delete all of the folder children - foreach (InventoryNodeBase obj in new List(folder.Children.Values)) - { - if (obj is InventoryItemBase) - { - TryDeleteItem(owner, (obj as InventoryItemBase).ID); - } - else - { - InventoryFolderWithChildren childFolder = obj as InventoryFolderWithChildren; - TryPurgeFolder(owner, childFolder.ID); - TryDeleteFolder(owner, childFolder.ID); - } - } - - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.NotFound; - } - - server.MetricsProvider.LogInventoryPurgeFolder(EXTENSION_NAME, ret, owner, folderID, DateTime.Now); - return ret; - } - - #endregion Required Interfaces - - void SaveItem(InventoryItemBase item) - { - string filename = String.Format("{0}-{1}.item", SanitizeFilename(item.Name), item.ID); - - string path = Path.Combine(DEFAULT_INVENTORY_DIR, item.Owner.ToString()); - path = Path.Combine(path, filename); - - using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write)) - { - itemSerializer.Serialize(stream, item); - stream.Flush(); - } - } - - void SaveFolder(InventoryFolderWithChildren folder) - { - string filename = String.Format("{0}-{1}.folder", SanitizeFilename(folder.Name), folder.ID); - - string path = Path.Combine(DEFAULT_INVENTORY_DIR, folder.Owner.ToString()); - path = Path.Combine(path, filename); - - using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write)) - { - folderSerializer.Serialize(stream, folder); - stream.Flush(); - } - } - - string SanitizeFilename(string filename) - { - string output = filename; - - if (output.Length > 64) - output = output.Substring(0, 64); - - foreach (char i in Path.GetInvalidFileNameChars()) - output = output.Replace(i, '_'); - - return output; - } - - static string PathFromURI(Uri uri) - { - byte[] hash = OpenMetaverse.Utils.SHA1(Encoding.UTF8.GetBytes(uri.ToString())); - StringBuilder digest = new StringBuilder(40); - - // Convert the hash to a hex string - foreach (byte b in hash) - digest.AppendFormat(OpenMetaverse.Utils.EnUsCulture, "{0:x2}", b); - - return Path.Combine(DEFAULT_INVENTORY_DIR, digest.ToString()); - } - - void LoadFiles(string folder) - { - // Try to create the directory if it doesn't already exist - if (!Directory.Exists(folder)) - { - try { Directory.CreateDirectory(folder); } - catch (Exception ex) - { - m_log.Warn("[SIMPLEINVENTORYSTORAGE]: " + ex.Message); - return; - } - } - - try - { - string[] agentFolders = Directory.GetDirectories(DEFAULT_INVENTORY_DIR); - - for (int i = 0; i < agentFolders.Length; i++) - { - string foldername = agentFolders[i]; - string indexPath = Path.Combine(foldername, "index.txt"); - UUID ownerID = UUID.Zero; - Uri owner = null; - - try - { - string[] index = File.ReadAllLines(indexPath); - ownerID = UUID.Parse(index[0]); - owner = new Uri(index[1]); - } - catch (Exception ex) - { - m_log.WarnFormat("[SIMPLEINVENTORYSTORAGE]: Failed loading the index file {0}: {1}", indexPath, ex.Message); - } - - if (ownerID != UUID.Zero && owner != null) - { - // Initialize the active gestures list for this agent - activeGestures.Add(owner, new List()); - - InventoryCollection collection = new InventoryCollection(); - collection.UserID = ownerID; - - // Load all of the folders for this agent - string[] folders = Directory.GetFiles(foldername, "*.folder", SearchOption.TopDirectoryOnly); - collection.Folders = new Dictionary(folders.Length); - - for (int j = 0; j < folders.Length; j++) - { - InventoryFolderWithChildren invFolder = (InventoryFolderWithChildren)folderSerializer.Deserialize( - new FileStream(folders[j], FileMode.Open, FileAccess.Read)); - collection.Folders[invFolder.ID] = invFolder; - } - - // Iterate over the folders collection, adding children to their parents - foreach (InventoryFolderWithChildren invFolder in collection.Folders.Values) - { - InventoryFolderWithChildren parent; - if (collection.Folders.TryGetValue(invFolder.ParentID, out parent)) - parent.Children[invFolder.ID] = invFolder; - } - - // Load all of the items for this agent - string[] files = Directory.GetFiles(foldername, "*.item", SearchOption.TopDirectoryOnly); - collection.Items = new Dictionary(files.Length); - - for (int j = 0; j < files.Length; j++) - { - InventoryItemBase invItem = (InventoryItemBase)itemSerializer.Deserialize( - new FileStream(files[j], FileMode.Open, FileAccess.Read)); - collection.Items[invItem.ID] = invItem; - - // Add items to their parent folders - InventoryFolderWithChildren parent; - if (collection.Folders.TryGetValue(invItem.Folder, out parent)) - parent.Children[invItem.ID] = invItem; - - // Add active gestures to our list - if (invItem.InvType == (int)InventoryType.Gesture && invItem.Flags != 0) - activeGestures[owner].Add(invItem); - } - - inventories.Add(owner, collection); - } - } - } - catch (Exception ex) - { - m_log.ErrorFormat("[SIMPLEINVENTORYSTORAGE]: Failed loading inventory from {0}: {1}", folder, ex.Message); - } - } - - #region IPlugin implementation - - public void Initialise(AssetInventoryServer server) - { - this.server = server; - - LoadFiles(DEFAULT_INVENTORY_DIR); - - m_log.InfoFormat("[SIMPLEINVENTORYSTORAGE]: Initialized the inventory index with data for {0} avatars", - inventories.Count); - } - - /// - /// Initialises asset interface - /// - public void Initialise() - { - m_log.InfoFormat("[SIMPLEINVENTORYSTORAGE]: {0} cannot be default-initialized!", Name); - throw new PluginNotInitialisedException(Name); - } - - public void Dispose() - { - } - - public string Version - { - // TODO: this should be something meaningful and not hardcoded? - get { return "0.1"; } - } - - public string Name - { - get { return "SimpleInventoryStorage"; } - } - - #endregion IPlugin implementation - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleUtils.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleUtils.cs deleted file mode 100644 index 0d5c53a..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleUtils.cs +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.IO; -using OpenMetaverse; - -namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple -{ - public static class SimpleUtils - { - public static string ParseNameFromFilename(string filename) - { - filename = Path.GetFileName(filename); - - int dot = filename.LastIndexOf('.'); - int firstDash = filename.IndexOf('-'); - - if (dot - 37 > 0 && firstDash > 0) - return filename.Substring(0, firstDash); - else - return String.Empty; - } - - public static UUID ParseUUIDFromFilename(string filename) - { - int dot = filename.LastIndexOf('.'); - - if (dot > 35) - { - // Grab the last 36 characters of the filename - string uuidString = filename.Substring(dot - 36, 36); - UUID uuid; - UUID.TryParse(uuidString, out uuid); - return uuid; - } - else - { - UUID uuid; - if (UUID.TryParse(Path.GetFileName(filename), out uuid)) - return uuid; - else - return UUID.Zero; - } - } - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Utils.cs b/OpenSim/Grid/AssetInventoryServer/Utils.cs deleted file mode 100644 index 9bbc0bc..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Utils.cs +++ /dev/null @@ -1,1031 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Globalization; -using System.Xml; -using System.Xml.Serialization; -using OpenMetaverse; -using OpenSim.Framework; -using OpenSim.Framework.Servers; -using OpenSim.Framework.Servers.HttpServer; - -namespace OpenSim.Grid.AssetInventoryServer -{ - public static class Utils - { - public static UUID GetAuthToken(OSHttpRequest request) - { - UUID authToken = UUID.Zero; - - string[] authHeader = request.Headers.GetValues("Authorization"); - if (authHeader != null && authHeader.Length == 1) - { - // Example header: - // Authorization: OpenGrid 65fda0b5-4446-42f5-b828-aaf644293646 - string[] authHeaderParts = authHeader[0].Split(' '); - if (authHeaderParts.Length == 2 && authHeaderParts[0] == "OpenGrid") - UUID.TryParse(authHeaderParts[1], out authToken); - } - - //if (authToken == UUID.Zero && request.Cookies != null) - //{ - // // Check for an authToken cookie to make logins browser-compatible - // RequestCookie authCookie = request.Cookies["authToken"]; - // if (authCookie != null) - // UUID.TryParse(authCookie.Value, out authToken); - //} - - return authToken; - } - - public static Uri GetOpenSimUri(UUID avatarID) - { - return new Uri("http://opensim/" + avatarID.ToString()); - } - - public static bool TryGetOpenSimUUID(Uri avatarUri, out UUID avatarID) - { - string[] parts = avatarUri.Segments; - return UUID.TryParse(parts[parts.Length - 1], out avatarID); - } - - #region SL / file extension / content-type conversions - - public static string SLAssetTypeToContentType(int assetType) - { - switch (assetType) - { - case 0: - return "image/jp2"; - case 1: - return "application/ogg"; - case 2: - return "application/x-metaverse-callingcard"; - case 3: - return "application/x-metaverse-landmark"; - case 5: - return "application/x-metaverse-clothing"; - case 6: - return "application/x-metaverse-primitive"; - case 7: - return "application/x-metaverse-notecard"; - case 8: - return "application/x-metaverse-folder"; - case 10: - return "application/x-metaverse-lsl"; - case 11: - return "application/x-metaverse-lso"; - case 12: - return "image/tga"; - case 13: - return "application/x-metaverse-bodypart"; - case 17: - return "audio/x-wav"; - case 19: - return "image/jpeg"; - case 20: - return "application/x-metaverse-animation"; - case 21: - return "application/x-metaverse-gesture"; - case 22: - return "application/x-metaverse-simstate"; - default: - return "application/octet-stream"; - } - } - - public static int ContentTypeToSLAssetType(string contentType) - { - switch (contentType) - { - case "image/jp2": - return 0; - case "application/ogg": - return 1; - case "application/x-metaverse-callingcard": - return 2; - case "application/x-metaverse-landmark": - return 3; - case "application/x-metaverse-clothing": - return 5; - case "application/x-metaverse-primitive": - return 6; - case "application/x-metaverse-notecard": - return 7; - case "application/x-metaverse-lsl": - return 10; - case "application/x-metaverse-lso": - return 11; - case "image/tga": - return 12; - case "application/x-metaverse-bodypart": - return 13; - case "audio/x-wav": - return 17; - case "image/jpeg": - return 19; - case "application/x-metaverse-animation": - return 20; - case "application/x-metaverse-gesture": - return 21; - case "application/x-metaverse-simstate": - return 22; - default: - return -1; - } - } - - public static string ContentTypeToExtension(string contentType) - { - switch (contentType) - { - case "image/jp2": - return "texture"; - case "application/ogg": - return "ogg"; - case "application/x-metaverse-callingcard": - return "callingcard"; - case "application/x-metaverse-landmark": - return "landmark"; - case "application/x-metaverse-clothing": - return "clothing"; - case "application/x-metaverse-primitive": - return "primitive"; - case "application/x-metaverse-notecard": - return "notecard"; - case "application/x-metaverse-lsl": - return "lsl"; - case "application/x-metaverse-lso": - return "lso"; - case "image/tga": - return "tga"; - case "application/x-metaverse-bodypart": - return "bodypart"; - case "audio/x-wav": - return "wav"; - case "image/jpeg": - return "jpg"; - case "application/x-metaverse-animation": - return "animation"; - case "application/x-metaverse-gesture": - return "gesture"; - case "application/x-metaverse-simstate": - return "simstate"; - default: - return "bin"; - } - } - - public static string ExtensionToContentType(string extension) - { - switch (extension) - { - case "texture": - case "jp2": - case "j2c": - return "image/jp2"; - case "sound": - case "ogg": - return "application/ogg"; - case "callingcard": - return "application/x-metaverse-callingcard"; - case "landmark": - return "application/x-metaverse-landmark"; - case "clothing": - return "application/x-metaverse-clothing"; - case "primitive": - return "application/x-metaverse-primitive"; - case "notecard": - return "application/x-metaverse-notecard"; - case "lsl": - return "application/x-metaverse-lsl"; - case "lso": - return "application/x-metaverse-lso"; - case "tga": - return "image/tga"; - case "bodypart": - return "application/x-metaverse-bodypart"; - case "wav": - return "audio/x-wav"; - case "jpg": - case "jpeg": - return "image/jpeg"; - case "animation": - return "application/x-metaverse-animation"; - case "gesture": - return "application/x-metaverse-gesture"; - case "simstate": - return "application/x-metaverse-simstate"; - case "txt": - return "text/plain"; - case "xml": - return "application/xml"; - default: - return "application/octet-stream"; - } - } - - #endregion SL / file extension / content-type conversions - - #region XML Serialization - - public class GeneratedReader : XmlSerializationReader - { - public object ReadRoot_InventoryFolderBase() - { - Reader.MoveToContent(); - if (Reader.LocalName != "InventoryFolderBase" || Reader.NamespaceURI != "") - throw CreateUnknownNodeException(); - return ReadObject_InventoryFolder(true, true); - } - - public object ReadRoot_InventoryItemBase() - { - Reader.MoveToContent(); - if (Reader.LocalName != "InventoryItemBase" || Reader.NamespaceURI != "") - throw CreateUnknownNodeException(); - return ReadObject_InventoryItem(true, true); - } - - public object ReadRoot_InventoryCollection() - { - Reader.MoveToContent(); - if (Reader.LocalName != "InventoryCollection" || Reader.NamespaceURI != "") - throw CreateUnknownNodeException(); - return ReadObject_InventoryCollection(true, true); - } - - public InventoryFolderWithChildren ReadObject_InventoryFolder(bool isNullable, bool checkType) - { - InventoryFolderWithChildren ob = null; - if (isNullable && ReadNull()) return null; - - if (checkType) - { - System.Xml.XmlQualifiedName t = GetXsiType(); - if (t == null) - { } - else if (t.Name != "InventoryFolderBase" || t.Namespace != "") - throw CreateUnknownTypeException(t); - } - - ob = (InventoryFolderWithChildren)Activator.CreateInstance(typeof(InventoryFolderWithChildren), true); - - Reader.MoveToElement(); - - while (Reader.MoveToNextAttribute()) - { - if (IsXmlnsAttribute(Reader.Name)) - { - } - else - { - UnknownNode(ob); - } - } - - Reader.MoveToElement(); - Reader.MoveToElement(); - if (Reader.IsEmptyElement) - { - Reader.Skip(); - return ob; - } - - Reader.ReadStartElement(); - Reader.MoveToContent(); - - bool b0 = false, b1 = false, b2 = false, b3 = false, b4 = false, b5 = false; - - while (Reader.NodeType != System.Xml.XmlNodeType.EndElement) - { - if (Reader.NodeType == System.Xml.XmlNodeType.Element) - { - if (Reader.LocalName == "Owner" && Reader.NamespaceURI == "" && !b1) - { - b1 = true; - ob.@Owner = ReadObject_UUID(false, true); - } - else if (Reader.LocalName == "Version" && Reader.NamespaceURI == "" && !b5) - { - b5 = true; - string s6 = Reader.ReadElementString(); - ob.@Version = UInt16.Parse(s6, CultureInfo.InvariantCulture); - } - else if (Reader.LocalName == "ID" && Reader.NamespaceURI == "" && !b3) - { - b3 = true; - ob.@ID = ReadObject_UUID(false, true); - } - else if (Reader.LocalName == "Type" && Reader.NamespaceURI == "" && !b4) - { - b4 = true; - string s7 = Reader.ReadElementString(); - ob.@Type = Int16.Parse(s7, CultureInfo.InvariantCulture); - } - else if (Reader.LocalName == "Name" && Reader.NamespaceURI == "" && !b0) - { - b0 = true; - string s8 = Reader.ReadElementString(); - ob.@Name = s8; - } - else if (Reader.LocalName == "ParentID" && Reader.NamespaceURI == "" && !b2) - { - b2 = true; - ob.@ParentID = ReadObject_UUID(false, true); - } - else - { - UnknownNode(ob); - } - } - else - UnknownNode(ob); - - Reader.MoveToContent(); - } - - ReadEndElement(); - - return ob; - } - - public InventoryItemBase ReadObject_InventoryItem(bool isNullable, bool checkType) - { - InventoryItemBase ob = null; - if (isNullable && ReadNull()) return null; - - if (checkType) - { - System.Xml.XmlQualifiedName t = GetXsiType(); - if (t == null) - { } - else if (t.Name != "InventoryItemBase" || t.Namespace != "") - throw CreateUnknownTypeException(t); - } - - ob = (InventoryItemBase)Activator.CreateInstance(typeof(InventoryItemBase), true); - - Reader.MoveToElement(); - - while (Reader.MoveToNextAttribute()) - { - if (IsXmlnsAttribute(Reader.Name)) - { - } - else - { - UnknownNode(ob); - } - } - - Reader.MoveToElement(); - Reader.MoveToElement(); - if (Reader.IsEmptyElement) - { - Reader.Skip(); - return ob; - } - - Reader.ReadStartElement(); - Reader.MoveToContent(); - - bool b9 = false, b10 = false, b11 = false, b12 = false, b13 = false, b14 = false, b15 = false, b16 = false, b17 = false, b18 = false, b19 = false, b20 = false, b21 = false, b22 = false, b23 = false, b24 = false, b25 = false, b26 = false, b27 = false, b28 = false; - - while (Reader.NodeType != System.Xml.XmlNodeType.EndElement) - { - if (Reader.NodeType == System.Xml.XmlNodeType.Element) - { - if (Reader.LocalName == "GroupPermissions" && Reader.NamespaceURI == "" && !b20) - { - b20 = true; - string s29 = Reader.ReadElementString(); - ob.@GroupPermissions = UInt32.Parse(s29, CultureInfo.InvariantCulture); - } - else if (Reader.LocalName == "AssetType" && Reader.NamespaceURI == "" && !b21) - { - b21 = true; - string s30 = Reader.ReadElementString(); - ob.@AssetType = Int32.Parse(s30, CultureInfo.InvariantCulture); - } - else if (Reader.LocalName == "SalePrice" && Reader.NamespaceURI == "" && !b25) - { - b25 = true; - string s31 = Reader.ReadElementString(); - ob.@SalePrice = Int32.Parse(s31, CultureInfo.InvariantCulture); - } - else if (Reader.LocalName == "AssetID" && Reader.NamespaceURI == "" && !b22) - { - b22 = true; - ob.@AssetID = ReadObject_UUID(false, true); - } - else if (Reader.LocalName == "Folder" && Reader.NamespaceURI == "" && !b11) - { - b11 = true; - ob.@Folder = ReadObject_UUID(false, true); - } - else if (Reader.LocalName == "Name" && Reader.NamespaceURI == "" && !b14) - { - b14 = true; - string s32 = Reader.ReadElementString(); - ob.@Name = s32; - } - else if (Reader.LocalName == "NextPermissions" && Reader.NamespaceURI == "" && !b16) - { - b16 = true; - string s33 = Reader.ReadElementString(); - ob.@NextPermissions = UInt32.Parse(s33, CultureInfo.InvariantCulture); - } - else if (Reader.LocalName == "BasePermissions" && Reader.NamespaceURI == "" && !b18) - { - b18 = true; - string s34 = Reader.ReadElementString(); - ob.@BasePermissions = UInt32.Parse(s34, CultureInfo.InvariantCulture); - } - else if (Reader.LocalName == "ID" && Reader.NamespaceURI == "" && !b9) - { - b9 = true; - ob.@ID = ReadObject_UUID(false, true); - } - else if (Reader.LocalName == "Flags" && Reader.NamespaceURI == "" && !b27) - { - b27 = true; - string s35 = Reader.ReadElementString(); - ob.@Flags = UInt32.Parse(s35, CultureInfo.InvariantCulture); - } - else if (Reader.LocalName == "GroupOwned" && Reader.NamespaceURI == "" && !b24) - { - b24 = true; - string s36 = Reader.ReadElementString(); - ob.@GroupOwned = XmlConvert.ToBoolean(s36); - } - else if (Reader.LocalName == "InvType" && Reader.NamespaceURI == "" && !b10) - { - b10 = true; - string s37 = Reader.ReadElementString(); - ob.@InvType = Int32.Parse(s37, CultureInfo.InvariantCulture); - } - else if (Reader.LocalName == "GroupID" && Reader.NamespaceURI == "" && !b23) - { - b23 = true; - ob.@GroupID = ReadObject_UUID(false, true); - } - else if (Reader.LocalName == "Description" && Reader.NamespaceURI == "" && !b15) - { - b15 = true; - string s38 = Reader.ReadElementString(); - ob.@Description = s38; - } - else if (Reader.LocalName == "CreationDate" && Reader.NamespaceURI == "" && !b28) - { - b28 = true; - string s39 = Reader.ReadElementString(); - ob.@CreationDate = Int32.Parse(s39, CultureInfo.InvariantCulture); - } - else if (Reader.LocalName == "EveryOnePermissions" && Reader.NamespaceURI == "" && !b19) - { - b19 = true; - string s40 = Reader.ReadElementString(); - ob.@EveryOnePermissions = UInt32.Parse(s40, CultureInfo.InvariantCulture); - } - else if (Reader.LocalName == "Creator" && Reader.NamespaceURI == "" && !b13) - { - b13 = true; - ob.@CreatorId = Reader.ReadElementString(); - } - else if (Reader.LocalName == "Owner" && Reader.NamespaceURI == "" && !b12) - { - b12 = true; - ob.@Owner = ReadObject_UUID(false, true); - } - else if (Reader.LocalName == "SaleType" && Reader.NamespaceURI == "" && !b26) - { - b26 = true; - string s41 = Reader.ReadElementString(); - ob.@SaleType = byte.Parse(s41, CultureInfo.InvariantCulture); - } - else if (Reader.LocalName == "CurrentPermissions" && Reader.NamespaceURI == "" && !b17) - { - b17 = true; - string s42 = Reader.ReadElementString(); - ob.@CurrentPermissions = UInt32.Parse(s42, CultureInfo.InvariantCulture); - } - else - { - UnknownNode(ob); - } - } - else - UnknownNode(ob); - - Reader.MoveToContent(); - } - - ReadEndElement(); - - return ob; - } - - public InventoryCollection ReadObject_InventoryCollection(bool isNullable, bool checkType) - { - InventoryCollection ob = null; - if (isNullable && ReadNull()) return null; - - if (checkType) - { - System.Xml.XmlQualifiedName t = GetXsiType(); - if (t == null) - { } - else if (t.Name != "InventoryCollection" || t.Namespace != "") - throw CreateUnknownTypeException(t); - } - - ob = (InventoryCollection)Activator.CreateInstance(typeof(InventoryCollection), true); - - Reader.MoveToElement(); - - while (Reader.MoveToNextAttribute()) - { - if (IsXmlnsAttribute(Reader.Name)) - { - } - else - { - UnknownNode(ob); - } - } - - Reader.MoveToElement(); - Reader.MoveToElement(); - if (Reader.IsEmptyElement) - { - Reader.Skip(); - if (ob.@Folders == null) - { - ob.@Folders = new System.Collections.Generic.Dictionary(); - } - if (ob.@Items == null) - { - ob.@Items = new System.Collections.Generic.Dictionary(); - } - return ob; - } - - Reader.ReadStartElement(); - Reader.MoveToContent(); - - bool b43 = false, b44 = false, b45 = false; - - while (Reader.NodeType != System.Xml.XmlNodeType.EndElement) - { - if (Reader.NodeType == System.Xml.XmlNodeType.Element) - { - if (Reader.LocalName == "UserID" && Reader.NamespaceURI == "" && !b45) - { - b45 = true; - ob.@UserID = ReadObject_UUID(false, true); - } - else if (Reader.LocalName == "Items" && Reader.NamespaceURI == "" && !b44) - { - System.Collections.Generic.Dictionary o46 = ob.@Items; - if (((object)o46) == null) - { - o46 = new System.Collections.Generic.Dictionary(); - ob.@Items = o46; - } - if (Reader.IsEmptyElement) - { - Reader.Skip(); - } - else - { - int n47 = 0; - Reader.ReadStartElement(); - Reader.MoveToContent(); - - while (Reader.NodeType != System.Xml.XmlNodeType.EndElement) - { - if (Reader.NodeType == System.Xml.XmlNodeType.Element) - { - if (Reader.LocalName == "InventoryItemBase" && Reader.NamespaceURI == "") - { - if (((object)o46) == null) - throw CreateReadOnlyCollectionException("System.Collections.Generic.List"); - InventoryItemBase item = ReadObject_InventoryItem(true, true); - o46.Add(item.ID, item); - n47++; - } - else UnknownNode(null); - } - else UnknownNode(null); - - Reader.MoveToContent(); - } - ReadEndElement(); - } - b44 = true; - } - else if (Reader.LocalName == "Folders" && Reader.NamespaceURI == "" && !b43) - { - System.Collections.Generic.Dictionary o48 = ob.@Folders; - if (((object)o48) == null) - { - o48 = new System.Collections.Generic.Dictionary(); - ob.@Folders = o48; - } - if (Reader.IsEmptyElement) - { - Reader.Skip(); - } - else - { - int n49 = 0; - Reader.ReadStartElement(); - Reader.MoveToContent(); - - while (Reader.NodeType != System.Xml.XmlNodeType.EndElement) - { - if (Reader.NodeType == System.Xml.XmlNodeType.Element) - { - if (Reader.LocalName == "InventoryFolderBase" && Reader.NamespaceURI == "") - { - if (((object)o48) == null) - throw CreateReadOnlyCollectionException("System.Collections.Generic.List"); - InventoryFolderWithChildren folder = ReadObject_InventoryFolder(true, true); - o48.Add(folder.ID, folder); - n49++; - } - else UnknownNode(null); - } - else UnknownNode(null); - - Reader.MoveToContent(); - } - ReadEndElement(); - } - b43 = true; - } - else - { - UnknownNode(ob); - } - } - else - UnknownNode(ob); - - Reader.MoveToContent(); - } - if (ob.@Folders == null) - { - ob.@Folders = new System.Collections.Generic.Dictionary(); - } - if (ob.@Items == null) - { - ob.@Items = new System.Collections.Generic.Dictionary(); - } - - ReadEndElement(); - - return ob; - } - - public OpenMetaverse.UUID ReadObject_UUID(bool isNullable, bool checkType) - { - OpenMetaverse.UUID ob = (OpenMetaverse.UUID)Activator.CreateInstance(typeof(OpenMetaverse.UUID), true); - System.Xml.XmlQualifiedName t = GetXsiType(); - if (t == null) - { } - else if (t.Name != "UUID" || t.Namespace != "") - throw CreateUnknownTypeException(t); - - Reader.MoveToElement(); - - while (Reader.MoveToNextAttribute()) - { - if (IsXmlnsAttribute(Reader.Name)) - { - } - else - { - UnknownNode(ob); - } - } - - Reader.MoveToElement(); - Reader.MoveToElement(); - if (Reader.IsEmptyElement) - { - Reader.Skip(); - return ob; - } - - Reader.ReadStartElement(); - Reader.MoveToContent(); - - bool b52 = false; - - while (Reader.NodeType != System.Xml.XmlNodeType.EndElement) - { - if (Reader.NodeType == System.Xml.XmlNodeType.Element) - { - if (Reader.LocalName == "Guid" && Reader.NamespaceURI == "" && !b52) - { - b52 = true; - string s53 = Reader.ReadElementString(); - ob.@Guid = XmlConvert.ToGuid(s53); - } - else - { - UnknownNode(ob); - } - } - else - UnknownNode(ob); - - Reader.MoveToContent(); - } - - ReadEndElement(); - - return ob; - } - - protected override void InitCallbacks() - { - } - - protected override void InitIDs() - { - } - } - - public class GeneratedWriter : XmlSerializationWriter - { - const string xmlNamespace = "http://www.w3.org/2000/xmlns/"; - //static readonly System.Reflection.MethodInfo toBinHexStringMethod = typeof(XmlConvert).GetMethod("ToBinHexString", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic, null, new Type[] { typeof(byte[]) }, null); - //static string ToBinHexString(byte[] input) - //{ - // return input == null ? null : (string)toBinHexStringMethod.Invoke(null, new object[] { input }); - //} - public void WriteRoot_InventoryFolder(object o) - { - WriteStartDocument(); - InventoryFolderWithChildren ob = (InventoryFolderWithChildren)o; - TopLevelElement(); - WriteObject_InventoryFolder(ob, "InventoryFolderBase", "", true, false, true); - } - - public void WriteRoot_InventoryItem(object o) - { - WriteStartDocument(); - InventoryItemBase ob = (InventoryItemBase)o; - TopLevelElement(); - WriteObject_InventoryItem(ob, "InventoryItemBase", "", true, false, true); - } - - public void WriteRoot_InventoryCollection(object o) - { - WriteStartDocument(); - InventoryCollection ob = (InventoryCollection)o; - TopLevelElement(); - WriteObject_InventoryCollection(ob, "InventoryCollection", "", true, false, true); - } - - void WriteObject_InventoryFolder(InventoryFolderWithChildren ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem) - { - if (((object)ob) == null) - { - if (isNullable) - WriteNullTagLiteral(element, namesp); - return; - } - - System.Type type = ob.GetType(); - if (type == typeof(InventoryFolderWithChildren)) - { } - else - { - throw CreateUnknownTypeException(ob); - } - - if (writeWrappingElem) - { - WriteStartElement(element, namesp, ob); - } - - if (needType) WriteXsiType("InventoryFolderBase", ""); - - WriteElementString("Name", "", ob.@Name); - WriteObject_UUID(ob.@Owner, "Owner", "", false, false, true); - WriteObject_UUID(ob.@ParentID, "ParentID", "", false, false, true); - WriteObject_UUID(ob.@ID, "ID", "", false, false, true); - WriteElementString("Type", "", ob.@Type.ToString(CultureInfo.InvariantCulture)); - WriteElementString("Version", "", ob.@Version.ToString(CultureInfo.InvariantCulture)); - if (writeWrappingElem) WriteEndElement(ob); - } - - void WriteObject_InventoryItem(InventoryItemBase ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem) - { - if (((object)ob) == null) - { - if (isNullable) - WriteNullTagLiteral(element, namesp); - return; - } - - System.Type type = ob.GetType(); - if (type == typeof(InventoryItemBase)) - { } - else - { - throw CreateUnknownTypeException(ob); - } - - if (writeWrappingElem) - { - WriteStartElement(element, namesp, ob); - } - - if (needType) WriteXsiType("InventoryItemBase", ""); - - WriteObject_UUID(ob.@ID, "ID", "", false, false, true); - WriteElementString("InvType", "", ob.@InvType.ToString(CultureInfo.InvariantCulture)); - WriteObject_UUID(ob.@Folder, "Folder", "", false, false, true); - WriteObject_UUID(ob.@Owner, "Owner", "", false, false, true); - WriteElementString("Creator", "", ob.@CreatorId); - WriteElementString("Name", "", ob.@Name); - WriteElementString("Description", "", ob.@Description); - WriteElementString("NextPermissions", "", ob.@NextPermissions.ToString(CultureInfo.InvariantCulture)); - WriteElementString("CurrentPermissions", "", ob.@CurrentPermissions.ToString(CultureInfo.InvariantCulture)); - WriteElementString("BasePermissions", "", ob.@BasePermissions.ToString(CultureInfo.InvariantCulture)); - WriteElementString("EveryOnePermissions", "", ob.@EveryOnePermissions.ToString(CultureInfo.InvariantCulture)); - WriteElementString("GroupPermissions", "", ob.@GroupPermissions.ToString(CultureInfo.InvariantCulture)); - WriteElementString("AssetType", "", ob.@AssetType.ToString(CultureInfo.InvariantCulture)); - WriteObject_UUID(ob.@AssetID, "AssetID", "", false, false, true); - WriteObject_UUID(ob.@GroupID, "GroupID", "", false, false, true); - WriteElementString("GroupOwned", "", (ob.@GroupOwned ? "true" : "false")); - WriteElementString("SalePrice", "", ob.@SalePrice.ToString(CultureInfo.InvariantCulture)); - WriteElementString("SaleType", "", ob.@SaleType.ToString(CultureInfo.InvariantCulture)); - WriteElementString("Flags", "", ob.@Flags.ToString(CultureInfo.InvariantCulture)); - WriteElementString("CreationDate", "", ob.@CreationDate.ToString(CultureInfo.InvariantCulture)); - if (writeWrappingElem) WriteEndElement(ob); - } - - void WriteObject_InventoryCollection(InventoryCollection ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem) - { - if (((object)ob) == null) - { - if (isNullable) - WriteNullTagLiteral(element, namesp); - return; - } - - System.Type type = ob.GetType(); - if (type == typeof(InventoryCollection)) - { } - else - { - throw CreateUnknownTypeException(ob); - } - - if (writeWrappingElem) - { - WriteStartElement(element, namesp, ob); - } - - if (needType) WriteXsiType("InventoryCollection", ""); - - if (ob.@Folders != null) - { - WriteStartElement("Folders", "", ob.@Folders); - foreach (InventoryFolderWithChildren folder in ob.Folders.Values) - { - WriteObject_InventoryFolder(folder, "InventoryFolderBase", "", true, false, true); - } - WriteEndElement(ob.@Folders); - } - if (ob.@Items != null) - { - WriteStartElement("Items", "", ob.@Items); - foreach (InventoryItemBase item in ob.Items.Values) - { - WriteObject_InventoryItem(item, "InventoryItemBase", "", true, false, true); - } - WriteEndElement(ob.@Items); - } - WriteObject_UUID(ob.@UserID, "UserID", "", false, false, true); - if (writeWrappingElem) WriteEndElement(ob); - } - - void WriteObject_UUID(OpenMetaverse.UUID ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem) - { - System.Type type = ob.GetType(); - if (type == typeof(OpenMetaverse.UUID)) - { } - else - { - throw CreateUnknownTypeException(ob); - } - - if (writeWrappingElem) - { - WriteStartElement(element, namesp, ob); - } - - if (needType) WriteXsiType("UUID", ""); - - WriteElementString("Guid", "", XmlConvert.ToString(ob.@Guid)); - if (writeWrappingElem) WriteEndElement(ob); - } - - protected override void InitCallbacks() - { - } - - } - - public class BaseXmlSerializer : System.Xml.Serialization.XmlSerializer - { - protected override System.Xml.Serialization.XmlSerializationReader CreateReader() - { - return new GeneratedReader(); - } - - protected override System.Xml.Serialization.XmlSerializationWriter CreateWriter() - { - return new GeneratedWriter(); - } - - public override bool CanDeserialize(System.Xml.XmlReader xmlReader) - { - return true; - } - } - - public sealed class InventoryFolderSerializer : BaseXmlSerializer - { - protected override void Serialize(object obj, System.Xml.Serialization.XmlSerializationWriter writer) - { - ((GeneratedWriter)writer).WriteRoot_InventoryFolder(obj); - } - - protected override object Deserialize(System.Xml.Serialization.XmlSerializationReader reader) - { - return ((GeneratedReader)reader).ReadRoot_InventoryFolderBase(); - } - } - - public sealed class InventoryItemSerializer : BaseXmlSerializer - { - protected override void Serialize(object obj, System.Xml.Serialization.XmlSerializationWriter writer) - { - ((GeneratedWriter)writer).WriteRoot_InventoryItem(obj); - } - - protected override object Deserialize(System.Xml.Serialization.XmlSerializationReader reader) - { - return ((GeneratedReader)reader).ReadRoot_InventoryItemBase(); - } - } - - public sealed class InventoryCollectionSerializer : BaseXmlSerializer - { - protected override void Serialize(object obj, System.Xml.Serialization.XmlSerializationWriter writer) - { - ((GeneratedWriter)writer).WriteRoot_InventoryCollection(obj); - } - - protected override object Deserialize(System.Xml.Serialization.XmlSerializationReader reader) - { - return ((GeneratedReader)reader).ReadRoot_InventoryCollection(); - } - } - - #endregion XML Serialization - } -} -- cgit v1.1 From e83b00a3dfc5410f5ca6bd2eed3d8565ebbffecf Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Fri, 21 Aug 2009 08:51:43 +1000 Subject: * Implements a bunch of stuff in NPCModule --- .../Region/OptionalModules/World/NPC/NPCModule.cs | 64 +++++++++++++++++++--- .../Shared/Api/Implementation/LSL_Api.cs | 48 ++++++++-------- 2 files changed, 80 insertions(+), 32 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 8c9717c..a3cefc9 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -25,26 +25,74 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System.Collections.Generic; using OpenMetaverse; using Nini.Config; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; +using OpenSim.Framework; namespace OpenSim.Region.OptionalModules.World.NPC { - public class NPCModule : IRegionModule + public interface INPCModule + { + UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom); + void Autopilot(UUID agentID, Scene scene, Vector3 pos); + void Say(UUID agentID, Scene scene, string text); + void DeleteNPC(UUID agentID, Scene scene); + } + + public class NPCModule : IRegionModule, INPCModule { // private const bool m_enabled = false; + private Dictionary m_avatars = new Dictionary(); + + public UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom) + { + NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, scene); + scene.AddNewClient(npcAvatar); + + ScenePresence sp; + if(scene.TryGetAvatar(npcAvatar.AgentId, out sp)) + { + AvatarAppearance x = scene.CommsManager.AvatarService.GetUserAppearance(cloneAppearanceFrom); + + List wearbyte = new List(); + for (int i = 0; i < x.VisualParams.Length; i++) + { + wearbyte.Add(x.VisualParams[i]); + } + + sp.SetAppearance(x.Texture.GetBytes(), wearbyte); + } + + m_avatars.Add(npcAvatar.AgentId, npcAvatar); + + return npcAvatar.AgentId; + } + + public void Autopilot(UUID agentID, Scene scene, Vector3 pos) + { + ScenePresence sp; + scene.TryGetAvatar(agentID, out sp); + sp.DoAutoPilot(0,pos,m_avatars[agentID]); + } + + public void Say(UUID agentID, Scene scene, string text) + { + m_avatars[agentID].Say(text); + } + + public void DeleteNPC(UUID agentID, Scene scene) + { + scene.RemoveClient(agentID); + } + + public void Initialise(Scene scene, IConfigSource source) { - // if (m_enabled) - // { - // NPCAvatar testAvatar = new NPCAvatar("Jack", "NPC", new Vector3(128, 128, 40), scene); - // NPCAvatar testAvatar2 = new NPCAvatar("Jill", "NPC", new Vector3(136, 128, 40), scene); - // scene.AddNewClient(testAvatar); - // scene.AddNewClient(testAvatar2); - // } + scene.RegisterModuleInterface(this); } public void PostInitialise() diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 4e665e9..972e71c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -1978,30 +1978,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return new LSL_Rotation(q.X, q.Y, q.Z, q.W); } - private LSL_Rotation GetPartRot( SceneObjectPart part ) - { - Quaternion q; - if (part.LinkNum == 0 || part.LinkNum == 1) // unlinked or root prim - { - if (part.ParentGroup.RootPart.AttachmentPoint != 0) - { - ScenePresence avatar = World.GetScenePresence(part.AttachedAvatar); - if (avatar != null) - if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0) - q = avatar.CameraRotation; // Mouselook - else - q = avatar.Rotation; // Currently infrequently updated so may be inaccurate - else - q = part.ParentGroup.GroupRotation; // Likely never get here but just in case - } - else - q = part.ParentGroup.GroupRotation; // just the group rotation - return new LSL_Rotation(q.X, q.Y, q.Z, q.W); - } - q = part.GetWorldRotation(); - return new LSL_Rotation(q.X, q.Y, q.Z, q.W); - } - + private LSL_Rotation GetPartRot( SceneObjectPart part ) + { + Quaternion q; + if (part.LinkNum == 0 || part.LinkNum == 1) // unlinked or root prim + { + if (part.ParentGroup.RootPart.AttachmentPoint != 0) + { + ScenePresence avatar = World.GetScenePresence(part.AttachedAvatar); + if (avatar != null) + if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0) + q = avatar.CameraRotation; // Mouselook + else + q = avatar.Rotation; // Currently infrequently updated so may be inaccurate + else + q = part.ParentGroup.GroupRotation; // Likely never get here but just in case + } + else + q = part.ParentGroup.GroupRotation; // just the group rotation + return new LSL_Rotation(q.X, q.Y, q.Z, q.W); + } + q = part.GetWorldRotation(); + return new LSL_Rotation(q.X, q.Y, q.Z, q.W); + } + public LSL_Rotation llGetLocalRot() { m_host.AddScriptLPS(1); -- cgit v1.1 From 118f710a79c68da04861941a3304b1dba2c847bb Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 20 Aug 2009 16:18:32 -0700 Subject: Fixed a missing field in SendBulkInventoryFolderUpdate. --- OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 6969a3d..a7a5aa3 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -2177,7 +2177,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP bulkUpdate.AgentData.AgentID = AgentId; bulkUpdate.AgentData.TransactionID = transactionId; bulkUpdate.FolderData = folderDataBlocks.ToArray(); - + List foo = new List(); + bulkUpdate.ItemData = foo.ToArray(); + //m_log.Debug("SendBulkUpdateInventory :" + bulkUpdate); OutPacket(bulkUpdate, ThrottleOutPacketType.Asset); } -- cgit v1.1