From ab5e3328323a66028bfd47562d9d515dbec433be Mon Sep 17 00:00:00 2001 From: Mike Mazur Date: Mon, 16 Feb 2009 02:28:34 +0000 Subject: - removed OpenSim.Grid.AssetInventoryServer.Metadata class in favor of OpenSim.Framework.AssetMetadata and related updates in AssetInventory server - removed dependency on MySql.Data.MySqlClient - commented out the bulk of OpenSimInventoryStorage due to missing MySql.Data dependency - refactor asset creation in OpenSimAssetFrontend - commented out ForEach implementation, which also depended on MySql.Data, until it's supported by OpenSim backends - commented out some handlers in BrowseFrontend and ReferenceFrontend as they relied on either ForEach or the removed Metadata class --- OpenSim/Grid/AssetInventoryServer/Interfaces.cs | 8 +- OpenSim/Grid/AssetInventoryServer/Metadata.cs | 84 -- .../Plugins/BrowseFrontendPlugin.cs | 197 ++- .../Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs | 47 +- .../Plugins/OpenSim/OpenSimAssetStoragePlugin.cs | 201 +-- .../OpenSim/OpenSimInventoryStoragePlugin.cs | 1316 ++++++++++---------- .../Plugins/ReferenceFrontendPlugin.cs | 392 +++--- .../Plugins/Simple/SimpleAssetStoragePlugin.cs | 79 +- 8 files changed, 1074 insertions(+), 1250 deletions(-) delete mode 100644 OpenSim/Grid/AssetInventoryServer/Metadata.cs (limited to 'OpenSim') diff --git a/OpenSim/Grid/AssetInventoryServer/Interfaces.cs b/OpenSim/Grid/AssetInventoryServer/Interfaces.cs index 29428d4..053cacf 100644 --- a/OpenSim/Grid/AssetInventoryServer/Interfaces.cs +++ b/OpenSim/Grid/AssetInventoryServer/Interfaces.cs @@ -73,12 +73,12 @@ namespace OpenSim.Grid.AssetInventoryServer public interface IAssetStorageProvider : IAssetInventoryServerPlugin { - BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata); + BackendResponse TryFetchMetadata(UUID assetID, out AssetMetadata metadata); BackendResponse TryFetchData(UUID assetID, out byte[] assetData); BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset); - BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData); - BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID); - int ForEach(Action action, int start, int count); + BackendResponse TryCreateAsset(AssetBase asset); + BackendResponse TryCreateAsset(AssetBase asset, out UUID assetID); + int ForEach(Action action, int start, int count); } public interface IInventoryStorageProvider : IAssetInventoryServerPlugin diff --git a/OpenSim/Grid/AssetInventoryServer/Metadata.cs b/OpenSim/Grid/AssetInventoryServer/Metadata.cs deleted file mode 100644 index ebd379d..0000000 --- a/OpenSim/Grid/AssetInventoryServer/Metadata.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.Collections.Generic; -using OpenMetaverse; -using OpenMetaverse.StructuredData; - -namespace OpenSim.Grid.AssetInventoryServer -{ - public class Metadata - { - public UUID ID; - public string Name; - public string Description; - public DateTime CreationDate; - public string ContentType; - public byte[] SHA1; - public bool Temporary; - public Dictionary Methods = new Dictionary(); - public OSDMap ExtraData; - - public OSDMap SerializeToOSD() - { - OSDMap osdata = new OSDMap(); - - if (ID != UUID.Zero) osdata["id"] = OSD.FromUUID(ID); - osdata["name"] = OSD.FromString(Name); - osdata["description"] = OSD.FromString(Description); - osdata["creation_date"] = OSD.FromDate(CreationDate); - osdata["type"] = OSD.FromString(ContentType); - osdata["sha1"] = OSD.FromBinary(SHA1); - osdata["temporary"] = OSD.FromBoolean(Temporary); - - OSDMap methods = new OSDMap(Methods.Count); - foreach (KeyValuePair kvp in Methods) - methods.Add(kvp.Key, OSD.FromUri(kvp.Value)); - osdata["methods"] = methods; - - if (ExtraData != null) osdata["extra_data"] = ExtraData; - - return osdata; - } - - public byte[] SerializeToBytes() - { - LitJson.JsonData jsonData = OSDParser.SerializeJson(SerializeToOSD()); - return System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson()); - } - - public void Deserialize(byte[] data) - { - OSD osdata = OSDParser.DeserializeJson(System.Text.Encoding.UTF8.GetString(data)); - Deserialize(osdata); - } - - public void Deserialize(string data) - { - OSD osdata = OSDParser.DeserializeJson(data); - Deserialize(osdata); - } - - public void Deserialize(OSD osdata) - { - if (osdata.Type == OSDType.Map) - { - OSDMap map = (OSDMap)osdata; - ID = map["id"].AsUUID(); - Name = map["name"].AsString(); - Description = map["description"].AsString(); - CreationDate = map["creation_date"].AsDate(); - ContentType = map["type"].AsString(); - SHA1 = map["sha1"].AsBinary(); - Temporary = map["temporary"].AsBoolean(); - - OSDMap methods = map["methods"] as OSDMap; - if (methods != null) - { - foreach (KeyValuePair kvp in methods) - Methods.Add(kvp.Key, kvp.Value.AsUri()); - } - - ExtraData = map["extra_data"] as OSDMap; - } - } - } -} diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs index 6afda79..3b6e99e 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs @@ -57,8 +57,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins m_server = server; // Request for / or /?... - //server.HttpServer.AddHandler("get", null, @"(^/$)|(^/\?.*)", BrowseRequestHandler); - m_server.HttpServer.AddStreamHandler(new BrowseRequestHandler(server)); + //m_server.HttpServer.AddStreamHandler(new BrowseRequestHandler(server)); m_log.Info("[ASSET] Browser Frontend loaded."); } @@ -89,102 +88,102 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins #endregion IPlugin implementation - public class BrowseRequestHandler : IStreamedRequestHandler - { - AssetInventoryServer m_server; - string m_contentType; - string m_httpMethod; - string m_path; - - public BrowseRequestHandler(AssetInventoryServer server) - { - m_server = server; - m_contentType = null; - m_httpMethod = "GET"; - m_path = @"(^/$)|(^/\?.*)"; - } - - #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) - { - 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(Metadata data) - { - if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.ID)) - { - 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 - } + //public class BrowseRequestHandler : IStreamedRequestHandler + //{ + // AssetInventoryServer m_server; + // string m_contentType; + // string m_httpMethod; + // string m_path; + + // public BrowseRequestHandler(AssetInventoryServer server) + // { + // m_server = server; + // m_contentType = null; + // m_httpMethod = "GET"; + // m_path = @"(^/$)|(^/\?.*)"; + // } + + // #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) + // { + // 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(Metadata data) + // { + // if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.ID)) + // { + // 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/OpenSim/OpenSimAssetFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs index afb836d..f8f4cce 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs @@ -153,37 +153,11 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { - Metadata metadata = new Metadata(); + AssetBase asset = null; try { - AssetBase asset = (AssetBase) new XmlSerializer(typeof (AssetBase)).Deserialize(httpRequest.InputStream); - - if (asset.Data != null && asset.Data.Length > 0) - { - metadata.ID = asset.Metadata.FullID; - metadata.ContentType = Utils.SLAssetTypeToContentType((int) asset.Metadata.Type); - metadata.Name = asset.Metadata.Name; - metadata.Description = asset.Metadata.Description; - metadata.Temporary = asset.Metadata.Temporary; - - metadata.SHA1 = OpenMetaverse.Utils.SHA1(asset.Data); - metadata.CreationDate = DateTime.Now; - - BackendResponse storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, asset.Data); - - 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("AssetPostHandler called with no asset data"); - httpResponse.StatusCode = (int) HttpStatusCode.BadRequest; - } + asset = (AssetBase) new XmlSerializer(typeof (AssetBase)).Deserialize(httpRequest.InputStream); } catch (Exception ex) { @@ -191,6 +165,23 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim 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("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 index bcd1900..fccf50d 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs @@ -30,7 +30,6 @@ using System; using System.Reflection; using System.Data; -using MySql.Data.MySqlClient; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Data; @@ -54,46 +53,18 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim #region IAssetStorageProvider implementation - public BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata) + public BackendResponse TryFetchMetadata(UUID assetID, out AssetMetadata metadata) { metadata = null; BackendResponse ret; - using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("asset_database_connect"))) - { - IDataReader reader; + AssetBase asset = m_assetProvider.FetchAsset(assetID); - try - { - dbConnection.Open(); - - IDbCommand command = dbConnection.CreateCommand(); - command.CommandText = String.Format("SELECT name,description,assetType,temporary FROM assets WHERE id='{0}'", assetID.ToString()); - reader = command.ExecuteReader(); - - if (reader.Read()) - { - metadata = new Metadata(); - metadata.CreationDate = OpenMetaverse.Utils.Epoch; - metadata.SHA1 = null; - metadata.ID = assetID; - metadata.Name = reader.GetString(0); - metadata.Description = reader.GetString(1); - metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); - metadata.Temporary = reader.GetBoolean(3); - - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.NotFound; - } - } - catch (MySqlException ex) - { - m_log.Error("Connection to MySQL backend failed: " + ex.Message); - ret = BackendResponse.Failure; - } + if (asset == null) ret = BackendResponse.NotFound; + else + { + metadata = asset.Metadata; + ret = BackendResponse.Success; } m_server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); @@ -105,33 +76,13 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim assetData = null; BackendResponse ret; - using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("asset_database_connect"))) - { - IDataReader reader; + AssetBase asset = m_assetProvider.FetchAsset(assetID); - try - { - dbConnection.Open(); - - IDbCommand command = dbConnection.CreateCommand(); - command.CommandText = String.Format("SELECT data FROM assets WHERE id='{0}'", assetID.ToString()); - reader = command.ExecuteReader(); - - if (reader.Read()) - { - assetData = (byte[])reader.GetValue(0); - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.NotFound; - } - } - catch (MySqlException ex) - { - m_log.Error("Connection to MySQL backend failed: " + ex.Message); - ret = BackendResponse.Failure; - } + 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); @@ -147,101 +98,63 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim return BackendResponse.Success; } - public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID) + public BackendResponse TryCreateAsset(AssetBase asset, out UUID assetID) { - assetID = metadata.ID = UUID.Random(); - return TryCreateAsset(metadata, assetData); + assetID = asset.FullID = UUID.Random(); + return TryCreateAsset(asset); } - public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData) + public BackendResponse TryCreateAsset(AssetBase asset) { BackendResponse ret; - using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("asset_database_connect"))) - { - try - { - dbConnection.Open(); - - MySqlCommand command = new MySqlCommand( - "REPLACE INTO assets (name,description,assetType,local,temporary,data,id) VALUES " + - "(?name,?description,?assetType,?local,?temporary,?data,?id)", dbConnection); - - command.Parameters.AddWithValue("?name", metadata.Name); - command.Parameters.AddWithValue("?description", metadata.Description); - command.Parameters.AddWithValue("?assetType", Utils.ContentTypeToSLAssetType(metadata.ContentType)); - command.Parameters.AddWithValue("?local", 0); - command.Parameters.AddWithValue("?temporary", metadata.Temporary); - command.Parameters.AddWithValue("?data", assetData); - command.Parameters.AddWithValue("?id", metadata.ID.ToString()); - - int rowsAffected = command.ExecuteNonQuery(); - if (rowsAffected == 1) - { - ret = BackendResponse.Success; - } - else if (rowsAffected == 2) - { - m_log.Info("Replaced asset " + metadata.ID.ToString()); - ret = BackendResponse.Success; - } - else - { - m_log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected); - ret = BackendResponse.Failure; - } - } - catch (MySqlException ex) - { - m_log.Error("Connection to MySQL backend failed: " + ex.Message); - ret = BackendResponse.Failure; - } - } + m_assetProvider.CreateAsset(asset); + ret = BackendResponse.Success; - m_server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, metadata.ID, assetData.Length, DateTime.Now); + 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) + public int ForEach(Action action, int start, int count) { int rowCount = 0; - using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("asset_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("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(); - } + //using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("asset_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("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; } diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs index 86cf1de..69b8497 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryStoragePlugin.cs @@ -31,7 +31,6 @@ using System; using System.Reflection; using System.Collections.Generic; using System.Data; -using MySql.Data.MySqlClient; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Data; @@ -45,7 +44,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim 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 AssetInventoryServer m_server; private IInventoryDataPlugin m_inventoryProvider; private IConfig m_openSimConfig; @@ -58,529 +57,537 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim public BackendResponse TryFetchItem(Uri owner, UUID itemID, out InventoryItem 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 InventoryItem(); - 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("Connection to MySQL backend failed: " + ex.Message); - ret = BackendResponse.Failure; - } - } - - m_server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now); - return ret; + //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 InventoryItem(); + // 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("Connection to MySQL backend failed: " + ex.Message); + // ret = BackendResponse.Failure; + // } + //} + + //m_server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now); + //return ret; + return BackendResponse.Success; } public BackendResponse TryFetchFolder(Uri owner, UUID folderID, out InventoryFolder folder) { folder = 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 folderName,type,version,agentID,parentFolderID FROM inventoryfolders WHERE folderID='{0}'", - folderID.ToString()); - reader = command.ExecuteReader(); - - if (reader.Read()) - { - folder = new InventoryFolder(); - folder.Children = null; // This call only returns data for the folder itself, no children data - folder.ID = folderID; - folder.Name = reader.GetString(0); - folder.Type = reader.GetInt16(1); - folder.Version = (ushort)reader.GetInt16(2); - folder.Owner = UUID.Parse(reader.GetString(3)); - folder.ParentID = UUID.Parse(reader.GetString(4)); - - ret = BackendResponse.Success; - } - else - { - ret = BackendResponse.NotFound; - } - } - catch (MySqlException ex) - { - m_log.Error("Connection to MySQL backend failed: " + ex.Message); - ret = BackendResponse.Failure; - } - } - - m_server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now); - return ret; + //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 folderName,type,version,agentID,parentFolderID FROM inventoryfolders WHERE folderID='{0}'", + // folderID.ToString()); + // reader = command.ExecuteReader(); + + // if (reader.Read()) + // { + // folder = new InventoryFolder(); + // folder.Children = null; // This call only returns data for the folder itself, no children data + // folder.ID = folderID; + // folder.Name = reader.GetString(0); + // folder.Type = reader.GetInt16(1); + // folder.Version = (ushort)reader.GetInt16(2); + // folder.Owner = UUID.Parse(reader.GetString(3)); + // folder.ParentID = UUID.Parse(reader.GetString(4)); + + // ret = BackendResponse.Success; + // } + // else + // { + // ret = BackendResponse.NotFound; + // } + // } + // catch (MySqlException ex) + // { + // m_log.Error("Connection to MySQL backend failed: " + ex.Message); + // ret = BackendResponse.Failure; + // } + //} + + //m_server.MetricsProvider.LogInventoryFetch(EXTENSION_NAME, ret, owner, folderID, true, DateTime.Now); + //return ret; + return BackendResponse.Success; } 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()) - { - InventoryFolder folder = new InventoryFolder(); - 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()) - { - InventoryItem item = new InventoryItem(); - 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("Connection to MySQL backend failed: " + ex.Message); - ret = BackendResponse.Failure; - } - } - - m_server.MetricsProvider.LogInventoryFetchFolderContents(EXTENSION_NAME, ret, owner, folderID, DateTime.Now); - return ret; + //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()) + // { + // InventoryFolder folder = new InventoryFolder(); + // 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()) + // { + // InventoryItem item = new InventoryItem(); + // 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("Connection to MySQL backend failed: " + ex.Message); + // ret = BackendResponse.Failure; + // } + //} + + //m_server.MetricsProvider.LogInventoryFetchFolderContents(EXTENSION_NAME, ret, owner, folderID, DateTime.Now); + //return ret; + return BackendResponse.Success; } public BackendResponse TryFetchFolderList(Uri owner, out List folders) { folders = null; - BackendResponse ret; - UUID ownerID; - - if (Utils.TryGetOpenSimUUID(owner, out ownerID)) - { - using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect"))) - { - IDataReader reader; - - try - { - dbConnection.Open(); - folders = new List(); - - IDbCommand command = dbConnection.CreateCommand(); - command.CommandText = String.Format("SELECT folderName,type,version,folderID,parentFolderID FROM inventoryfolders WHERE agentID='{0}'", - ownerID.ToString()); - reader = command.ExecuteReader(); - - while (reader.Read()) - { - InventoryFolder folder = new InventoryFolder(); - folder.Owner = ownerID; - folder.Children = null; // This call does not create a folder hierarchy - folder.Name = reader.GetString(0); - folder.Type = reader.GetInt16(1); - folder.Version = (ushort)reader.GetInt16(2); - folder.ID = UUID.Parse(reader.GetString(3)); - folder.ParentID = UUID.Parse(reader.GetString(4)); - - folders.Add(folder); - } - - ret = BackendResponse.Success; - } - catch (MySqlException ex) - { - m_log.Error("Connection to MySQL backend failed: " + ex.Message); - ret = BackendResponse.Failure; - } - } - } - else - { - ret = BackendResponse.NotFound; - } - - m_server.MetricsProvider.LogInventoryFetchFolderList(EXTENSION_NAME, ret, owner, DateTime.Now); - return ret; + //BackendResponse ret; + //UUID ownerID; + + //if (Utils.TryGetOpenSimUUID(owner, out ownerID)) + //{ + // using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect"))) + // { + // IDataReader reader; + + // try + // { + // dbConnection.Open(); + // folders = new List(); + + // IDbCommand command = dbConnection.CreateCommand(); + // command.CommandText = String.Format("SELECT folderName,type,version,folderID,parentFolderID FROM inventoryfolders WHERE agentID='{0}'", + // ownerID.ToString()); + // reader = command.ExecuteReader(); + + // while (reader.Read()) + // { + // InventoryFolder folder = new InventoryFolder(); + // folder.Owner = ownerID; + // folder.Children = null; // This call does not create a folder hierarchy + // folder.Name = reader.GetString(0); + // folder.Type = reader.GetInt16(1); + // folder.Version = (ushort)reader.GetInt16(2); + // folder.ID = UUID.Parse(reader.GetString(3)); + // folder.ParentID = UUID.Parse(reader.GetString(4)); + + // folders.Add(folder); + // } + + // ret = BackendResponse.Success; + // } + // catch (MySqlException ex) + // { + // m_log.Error("Connection to MySQL backend failed: " + ex.Message); + // ret = BackendResponse.Failure; + // } + // } + //} + //else + //{ + // ret = BackendResponse.NotFound; + //} + + //m_server.MetricsProvider.LogInventoryFetchFolderList(EXTENSION_NAME, ret, owner, DateTime.Now); + //return ret; + return BackendResponse.Success; } public BackendResponse TryFetchInventory(Uri owner, out InventoryCollection inventory) { inventory = null; - BackendResponse ret; - List folders; - UUID ownerID; - - 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 (InventoryFolder folder in folders) - inventory.Folders[folder.ID] = folder; - - // Fetch inventory items - if (Utils.TryGetOpenSimUUID(owner, out ownerID)) - { - 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,inventoryID,parentFolderID,inventoryGroupPermissions FROM inventoryitems WHERE " + - "avatarID='{0}'", ownerID.ToString()); - reader = command.ExecuteReader(); - - inventory.UserID = ownerID; - inventory.Items = new Dictionary(); - - while (reader.Read()) - { - InventoryItem item = new InventoryItem(); - item.Owner = ownerID; - 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.ID = UUID.Parse(reader.GetString(16)); - item.Folder = UUID.Parse(reader.GetString(17)); - item.GroupPermissions = (uint)reader.GetInt32(18); - - inventory.Items.Add(item.ID, item); - } - - ret = BackendResponse.Success; - } - catch (MySqlException ex) - { - m_log.Error("Connection to MySQL backend failed: " + ex.Message); - ret = BackendResponse.Failure; - } - } - } - else - { - ret = BackendResponse.NotFound; - } - } - - m_server.MetricsProvider.LogInventoryFetchInventory(EXTENSION_NAME, ret, owner, DateTime.Now); - return ret; + //BackendResponse ret; + //List folders; + //UUID ownerID; + + //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 (InventoryFolder folder in folders) + // inventory.Folders[folder.ID] = folder; + + // // Fetch inventory items + // if (Utils.TryGetOpenSimUUID(owner, out ownerID)) + // { + // 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,inventoryID,parentFolderID,inventoryGroupPermissions FROM inventoryitems WHERE " + + // "avatarID='{0}'", ownerID.ToString()); + // reader = command.ExecuteReader(); + + // inventory.UserID = ownerID; + // inventory.Items = new Dictionary(); + + // while (reader.Read()) + // { + // InventoryItem item = new InventoryItem(); + // item.Owner = ownerID; + // 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.ID = UUID.Parse(reader.GetString(16)); + // item.Folder = UUID.Parse(reader.GetString(17)); + // item.GroupPermissions = (uint)reader.GetInt32(18); + + // inventory.Items.Add(item.ID, item); + // } + + // ret = BackendResponse.Success; + // } + // catch (MySqlException ex) + // { + // m_log.Error("Connection to MySQL backend failed: " + ex.Message); + // ret = BackendResponse.Failure; + // } + // } + // } + // else + // { + // ret = BackendResponse.NotFound; + // } + //} + + //m_server.MetricsProvider.LogInventoryFetchInventory(EXTENSION_NAME, ret, owner, DateTime.Now); + //return ret; + return BackendResponse.Success; } public BackendResponse TryFetchActiveGestures(Uri owner, out List gestures) { gestures = null; - BackendResponse ret; - UUID ownerID; - - if (Utils.TryGetOpenSimUUID(owner, out ownerID)) - { - using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect"))) - { - IDataReader reader; - - try - { - dbConnection.Open(); - - MySqlCommand command = new MySqlCommand("SELECT assetID,inventoryName,inventoryDescription,inventoryNextPermissions," + - "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + - "creationDate,groupID,groupOwned,inventoryID,parentFolderID,inventoryGroupPermissions FROM inventoryitems WHERE " + - "avatarId=?uuid AND assetType=?type AND flags=1", dbConnection); - command.Parameters.AddWithValue("?uuid", ownerID.ToString()); - command.Parameters.AddWithValue("?type", (int)AssetType.Gesture); - reader = command.ExecuteReader(); - - while (reader.Read()) - { - InventoryItem item = new InventoryItem(); - item.Owner = ownerID; - item.AssetType = (int)AssetType.Gesture; - item.Flags = (uint)1; - item.AssetID = UUID.Parse(reader.GetString(0)); - item.Name = reader.GetString(1); - item.Description = reader.GetString(2); - item.NextPermissions = (uint)reader.GetInt32(3); - item.CurrentPermissions = (uint)reader.GetInt32(4); - item.InvType = reader.GetInt32(5); - item.Creator = UUID.Parse(reader.GetString(6)); - item.BasePermissions = (uint)reader.GetInt32(7); - item.EveryOnePermissions = (uint)reader.GetInt32(8); - item.SalePrice = reader.GetInt32(9); - item.SaleType = reader.GetByte(10); - item.CreationDate = reader.GetInt32(11); - item.GroupID = UUID.Parse(reader.GetString(12)); - item.GroupOwned = reader.GetBoolean(13); - item.ID = UUID.Parse(reader.GetString(14)); - item.Folder = UUID.Parse(reader.GetString(15)); - item.GroupPermissions = (uint)reader.GetInt32(16); - - gestures.Add(item); - } - - ret = BackendResponse.Success; - } - catch (MySqlException ex) - { - m_log.Error("Connection to MySQL backend failed: " + ex.Message); - ret = BackendResponse.Failure; - } - } - } - else - { - ret = BackendResponse.NotFound; - } - - m_server.MetricsProvider.LogInventoryFetchActiveGestures(EXTENSION_NAME, ret, owner, DateTime.Now); - return ret; + //BackendResponse ret; + //UUID ownerID; + + //if (Utils.TryGetOpenSimUUID(owner, out ownerID)) + //{ + // using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect"))) + // { + // IDataReader reader; + + // try + // { + // dbConnection.Open(); + + // MySqlCommand command = new MySqlCommand("SELECT assetID,inventoryName,inventoryDescription,inventoryNextPermissions," + + // "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + + // "creationDate,groupID,groupOwned,inventoryID,parentFolderID,inventoryGroupPermissions FROM inventoryitems WHERE " + + // "avatarId=?uuid AND assetType=?type AND flags=1", dbConnection); + // command.Parameters.AddWithValue("?uuid", ownerID.ToString()); + // command.Parameters.AddWithValue("?type", (int)AssetType.Gesture); + // reader = command.ExecuteReader(); + + // while (reader.Read()) + // { + // InventoryItem item = new InventoryItem(); + // item.Owner = ownerID; + // item.AssetType = (int)AssetType.Gesture; + // item.Flags = (uint)1; + // item.AssetID = UUID.Parse(reader.GetString(0)); + // item.Name = reader.GetString(1); + // item.Description = reader.GetString(2); + // item.NextPermissions = (uint)reader.GetInt32(3); + // item.CurrentPermissions = (uint)reader.GetInt32(4); + // item.InvType = reader.GetInt32(5); + // item.Creator = UUID.Parse(reader.GetString(6)); + // item.BasePermissions = (uint)reader.GetInt32(7); + // item.EveryOnePermissions = (uint)reader.GetInt32(8); + // item.SalePrice = reader.GetInt32(9); + // item.SaleType = reader.GetByte(10); + // item.CreationDate = reader.GetInt32(11); + // item.GroupID = UUID.Parse(reader.GetString(12)); + // item.GroupOwned = reader.GetBoolean(13); + // item.ID = UUID.Parse(reader.GetString(14)); + // item.Folder = UUID.Parse(reader.GetString(15)); + // item.GroupPermissions = (uint)reader.GetInt32(16); + + // gestures.Add(item); + // } + + // ret = BackendResponse.Success; + // } + // catch (MySqlException ex) + // { + // m_log.Error("Connection to MySQL backend failed: " + ex.Message); + // ret = BackendResponse.Failure; + // } + // } + //} + //else + //{ + // ret = BackendResponse.NotFound; + //} + + //m_server.MetricsProvider.LogInventoryFetchActiveGestures(EXTENSION_NAME, ret, owner, DateTime.Now); + //return ret; + return BackendResponse.Success; } public BackendResponse TryCreateItem(Uri owner, InventoryItem item) { - BackendResponse ret; - - using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect"))) - { - try - { - dbConnection.Open(); - - MySqlCommand command = new MySqlCommand( - "REPLACE INTO inventoryitems (assetID,assetType,inventoryName,inventoryDescription,inventoryNextPermissions," + - "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + - "creationDate,groupID,groupOwned,flags,inventoryID,avatarID,parentFolderID,inventoryGroupPermissions) VALUES " + - - "(?assetID,?assetType,?inventoryName,?inventoryDescription,?inventoryNextPermissions,?inventoryCurrentPermissions,?invType," + - "?creatorID,?inventoryBasePermissions,?inventoryEveryOnePermissions,?salePrice,?saleType,?creationDate,?groupID,?groupOwned," + - "?flags,?inventoryID,?avatarID,?parentFolderID,?inventoryGroupPermissions)", dbConnection); - - command.Parameters.AddWithValue("?assetID", item.AssetID.ToString()); - command.Parameters.AddWithValue("?assetType", item.AssetType); - command.Parameters.AddWithValue("?inventoryName", item.Name); - command.Parameters.AddWithValue("?inventoryDescription", item.Description); - command.Parameters.AddWithValue("?inventoryNextPermissions", item.NextPermissions); - command.Parameters.AddWithValue("?inventoryCurrentPermissions", item.CurrentPermissions); - command.Parameters.AddWithValue("?invType", item.InvType); - command.Parameters.AddWithValue("?creatorID", item.Creator.ToString()); - command.Parameters.AddWithValue("?inventoryBasePermissions", item.BasePermissions); - command.Parameters.AddWithValue("?inventoryEveryOnePermissions", item.EveryOnePermissions); - command.Parameters.AddWithValue("?salePrice", item.SalePrice); - command.Parameters.AddWithValue("?saleType", item.SaleType); - command.Parameters.AddWithValue("?creationDate", item.CreationDate); - command.Parameters.AddWithValue("?groupID", item.GroupID.ToString()); - command.Parameters.AddWithValue("?groupOwned", item.GroupOwned); - command.Parameters.AddWithValue("?flags", item.Flags); - command.Parameters.AddWithValue("?inventoryID", item.ID); - command.Parameters.AddWithValue("?avatarID", item.Owner); - command.Parameters.AddWithValue("?parentFolderID", item.Folder); - command.Parameters.AddWithValue("?inventoryGroupPermissions", item.GroupPermissions); - - int rowsAffected = command.ExecuteNonQuery(); - if (rowsAffected == 1) - { - ret = BackendResponse.Success; - } - else if (rowsAffected == 2) - { - m_log.Info("Replaced inventory item " + item.ID.ToString()); - ret = BackendResponse.Success; - } - else - { - m_log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected); - ret = BackendResponse.Failure; - } - } - catch (MySqlException ex) - { - m_log.Error("Connection to MySQL backend failed: " + ex.Message); - ret = BackendResponse.Failure; - } - } - - m_server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, false, DateTime.Now); - return ret; + //BackendResponse ret; + + //using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect"))) + //{ + // try + // { + // dbConnection.Open(); + + // MySqlCommand command = new MySqlCommand( + // "REPLACE INTO inventoryitems (assetID,assetType,inventoryName,inventoryDescription,inventoryNextPermissions," + + // "inventoryCurrentPermissions,invType,creatorID,inventoryBasePermissions,inventoryEveryOnePermissions,salePrice,saleType," + + // "creationDate,groupID,groupOwned,flags,inventoryID,avatarID,parentFolderID,inventoryGroupPermissions) VALUES " + + + // "(?assetID,?assetType,?inventoryName,?inventoryDescription,?inventoryNextPermissions,?inventoryCurrentPermissions,?invType," + + // "?creatorID,?inventoryBasePermissions,?inventoryEveryOnePermissions,?salePrice,?saleType,?creationDate,?groupID,?groupOwned," + + // "?flags,?inventoryID,?avatarID,?parentFolderID,?inventoryGroupPermissions)", dbConnection); + + // command.Parameters.AddWithValue("?assetID", item.AssetID.ToString()); + // command.Parameters.AddWithValue("?assetType", item.AssetType); + // command.Parameters.AddWithValue("?inventoryName", item.Name); + // command.Parameters.AddWithValue("?inventoryDescription", item.Description); + // command.Parameters.AddWithValue("?inventoryNextPermissions", item.NextPermissions); + // command.Parameters.AddWithValue("?inventoryCurrentPermissions", item.CurrentPermissions); + // command.Parameters.AddWithValue("?invType", item.InvType); + // command.Parameters.AddWithValue("?creatorID", item.Creator.ToString()); + // command.Parameters.AddWithValue("?inventoryBasePermissions", item.BasePermissions); + // command.Parameters.AddWithValue("?inventoryEveryOnePermissions", item.EveryOnePermissions); + // command.Parameters.AddWithValue("?salePrice", item.SalePrice); + // command.Parameters.AddWithValue("?saleType", item.SaleType); + // command.Parameters.AddWithValue("?creationDate", item.CreationDate); + // command.Parameters.AddWithValue("?groupID", item.GroupID.ToString()); + // command.Parameters.AddWithValue("?groupOwned", item.GroupOwned); + // command.Parameters.AddWithValue("?flags", item.Flags); + // command.Parameters.AddWithValue("?inventoryID", item.ID); + // command.Parameters.AddWithValue("?avatarID", item.Owner); + // command.Parameters.AddWithValue("?parentFolderID", item.Folder); + // command.Parameters.AddWithValue("?inventoryGroupPermissions", item.GroupPermissions); + + // int rowsAffected = command.ExecuteNonQuery(); + // if (rowsAffected == 1) + // { + // ret = BackendResponse.Success; + // } + // else if (rowsAffected == 2) + // { + // m_log.Info("Replaced inventory item " + item.ID.ToString()); + // ret = BackendResponse.Success; + // } + // else + // { + // m_log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected); + // ret = BackendResponse.Failure; + // } + // } + // catch (MySqlException ex) + // { + // m_log.Error("Connection to MySQL backend failed: " + ex.Message); + // ret = BackendResponse.Failure; + // } + //} + + //m_server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, false, DateTime.Now); + //return ret; + return BackendResponse.Success; } public BackendResponse TryCreateFolder(Uri owner, InventoryFolder folder) { - BackendResponse ret; - - using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect"))) - { - try - { - dbConnection.Open(); - - MySqlCommand command = new MySqlCommand( - "REPLACE INTO inventoryfolders (folderName,type,version,folderID,agentID,parentFolderID) VALUES " + - "(?folderName,?type,?version,?folderID,?agentID,?parentFolderID)", dbConnection); - - command.Parameters.AddWithValue("?folderName", folder.Name); - command.Parameters.AddWithValue("?type", folder.Type); - command.Parameters.AddWithValue("?version", folder.Version); - command.Parameters.AddWithValue("?folderID", folder.ID); - command.Parameters.AddWithValue("?agentID", folder.Owner); - command.Parameters.AddWithValue("?parentFolderID", folder.ParentID); - - int rowsAffected = command.ExecuteNonQuery(); - if (rowsAffected == 1) - { - ret = BackendResponse.Success; - } - else if (rowsAffected == 2) - { - m_log.Info("Replaced inventory folder " + folder.ID.ToString()); - ret = BackendResponse.Success; - } - else - { - m_log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected); - ret = BackendResponse.Failure; - } - } - catch (MySqlException ex) - { - m_log.Error("Connection to MySQL backend failed: " + ex.Message); - ret = BackendResponse.Failure; - } - } - - m_server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, true, DateTime.Now); - return ret; + //BackendResponse ret; + + //using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect"))) + //{ + // try + // { + // dbConnection.Open(); + + // MySqlCommand command = new MySqlCommand( + // "REPLACE INTO inventoryfolders (folderName,type,version,folderID,agentID,parentFolderID) VALUES " + + // "(?folderName,?type,?version,?folderID,?agentID,?parentFolderID)", dbConnection); + + // command.Parameters.AddWithValue("?folderName", folder.Name); + // command.Parameters.AddWithValue("?type", folder.Type); + // command.Parameters.AddWithValue("?version", folder.Version); + // command.Parameters.AddWithValue("?folderID", folder.ID); + // command.Parameters.AddWithValue("?agentID", folder.Owner); + // command.Parameters.AddWithValue("?parentFolderID", folder.ParentID); + + // int rowsAffected = command.ExecuteNonQuery(); + // if (rowsAffected == 1) + // { + // ret = BackendResponse.Success; + // } + // else if (rowsAffected == 2) + // { + // m_log.Info("Replaced inventory folder " + folder.ID.ToString()); + // ret = BackendResponse.Success; + // } + // else + // { + // m_log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected); + // ret = BackendResponse.Failure; + // } + // } + // catch (MySqlException ex) + // { + // m_log.Error("Connection to MySQL backend failed: " + ex.Message); + // ret = BackendResponse.Failure; + // } + //} + + //m_server.MetricsProvider.LogInventoryCreate(EXTENSION_NAME, ret, owner, true, DateTime.Now); + //return ret; + return BackendResponse.Success; } public BackendResponse TryCreateInventory(Uri owner, InventoryFolder rootFolder) @@ -590,193 +597,196 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim public BackendResponse TryDeleteItem(Uri owner, UUID itemID) { - 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 inventoryitems WHERE inventoryID=?inventoryID AND avatarID=?avatarID", dbConnection); - - command.Parameters.AddWithValue("?inventoryID", itemID.ToString()); - command.Parameters.AddWithValue("?avatarID", ownerID.ToString()); - - int rowsAffected = command.ExecuteNonQuery(); - if (rowsAffected == 1) - { - ret = BackendResponse.Success; - } - else - { - m_log.ErrorFormat("MySQL DELETE query affected {0} rows", rowsAffected); - ret = BackendResponse.NotFound; - } - } - catch (MySqlException ex) - { - m_log.Error("Connection to MySQL backend failed: " + ex.Message); - ret = BackendResponse.Failure; - } - } - } - else - { - ret = BackendResponse.NotFound; - } - - m_server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now); - return ret; + //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 inventoryitems WHERE inventoryID=?inventoryID AND avatarID=?avatarID", dbConnection); + + // command.Parameters.AddWithValue("?inventoryID", itemID.ToString()); + // command.Parameters.AddWithValue("?avatarID", ownerID.ToString()); + + // int rowsAffected = command.ExecuteNonQuery(); + // if (rowsAffected == 1) + // { + // ret = BackendResponse.Success; + // } + // else + // { + // m_log.ErrorFormat("MySQL DELETE query affected {0} rows", rowsAffected); + // ret = BackendResponse.NotFound; + // } + // } + // catch (MySqlException ex) + // { + // m_log.Error("Connection to MySQL backend failed: " + ex.Message); + // ret = BackendResponse.Failure; + // } + // } + //} + //else + //{ + // ret = BackendResponse.NotFound; + //} + + //m_server.MetricsProvider.LogInventoryDelete(EXTENSION_NAME, ret, owner, itemID, false, DateTime.Now); + //return ret; + return BackendResponse.Success; } 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("MySQL DELETE query affected {0} rows", rowsAffected); - ret = BackendResponse.NotFound; - } - } - catch (MySqlException ex) - { - m_log.Error("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; + //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("MySQL DELETE query affected {0} rows", rowsAffected); + // ret = BackendResponse.NotFound; + // } + // } + // catch (MySqlException ex) + // { + // m_log.Error("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; + return BackendResponse.Success; } public BackendResponse TryPurgeFolder(Uri owner, UUID folderID) { - BackendResponse ret; - UUID ownerID; + //BackendResponse ret; + //UUID ownerID; - if (Utils.TryGetOpenSimUUID(owner, out ownerID)) - { - using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect"))) - { - try - { - dbConnection.Open(); + //if (Utils.TryGetOpenSimUUID(owner, out ownerID)) + //{ + // using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("inventory_database_connect"))) + // { + // try + // { + // dbConnection.Open(); - #region Delete items + // #region Delete items - MySqlCommand command = new MySqlCommand( - "DELETE FROM inventoryitems WHERE parentFolderID=?parentFolderID AND avatarID=?avatarID", dbConnection); + // MySqlCommand command = new MySqlCommand( + // "DELETE FROM inventoryitems WHERE parentFolderID=?parentFolderID AND avatarID=?avatarID", dbConnection); - command.Parameters.AddWithValue("?parentFolderID", folderID.ToString()); - command.Parameters.AddWithValue("?avatarID", ownerID.ToString()); + // command.Parameters.AddWithValue("?parentFolderID", folderID.ToString()); + // command.Parameters.AddWithValue("?avatarID", ownerID.ToString()); - int rowsAffected = command.ExecuteNonQuery(); + // int rowsAffected = command.ExecuteNonQuery(); - #endregion Delete items + // #endregion Delete items - #region Delete folders + // #region Delete folders - command = new MySqlCommand( - "DELETE FROM inventoryfolders WHERE parentFolderID=?parentFolderID AND agentID=?agentID", dbConnection); + // command = new MySqlCommand( + // "DELETE FROM inventoryfolders WHERE parentFolderID=?parentFolderID AND agentID=?agentID", dbConnection); - command.Parameters.AddWithValue("?parentFolderID", folderID.ToString()); - command.Parameters.AddWithValue("?agentID", ownerID.ToString()); + // command.Parameters.AddWithValue("?parentFolderID", folderID.ToString()); + // command.Parameters.AddWithValue("?agentID", ownerID.ToString()); - rowsAffected += command.ExecuteNonQuery(); + // rowsAffected += command.ExecuteNonQuery(); - #endregion Delete folders + // #endregion Delete folders - m_log.DebugFormat("Deleted {0} inventory objects from MySQL in a folder purge", rowsAffected); + // m_log.DebugFormat("Deleted {0} inventory objects from MySQL in a folder purge", rowsAffected); - ret = BackendResponse.Success; - } - catch (MySqlException ex) - { - m_log.Error("Connection to MySQL backend failed: " + ex.Message); - ret = BackendResponse.Failure; - } - } - } - else - { - ret = BackendResponse.NotFound; - } + // ret = BackendResponse.Success; + // } + // catch (MySqlException ex) + // { + // m_log.Error("Connection to MySQL backend failed: " + ex.Message); + // ret = BackendResponse.Failure; + // } + // } + //} + //else + //{ + // ret = BackendResponse.NotFound; + //} - m_server.MetricsProvider.LogInventoryPurgeFolder(EXTENSION_NAME, ret, owner, folderID, DateTime.Now); - return ret; + //m_server.MetricsProvider.LogInventoryPurgeFolder(EXTENSION_NAME, ret, owner, folderID, DateTime.Now); + //return ret; + return BackendResponse.Success; } - public int ForEach(Action action, int start, int count) + 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("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(); - } + //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("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; } @@ -787,7 +797,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim public void Initialise(AssetInventoryServer server) { - m_server = server; + //m_server = server; m_openSimConfig = server.ConfigFile.Configs["OpenSim"]; try diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs index 7ff5dfa..f19be08 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs @@ -55,13 +55,13 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins m_server = server; // Asset metadata request - m_server.HttpServer.AddStreamHandler(new MetadataRequestHandler(server)); + //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_server.HttpServer.AddStreamHandler(new CreateRequestHandler(server)); m_log.Info("[ASSET] Reference Frontend loaded."); } @@ -92,95 +92,95 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins #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)) - { - Metadata 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("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 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("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 { @@ -261,110 +261,110 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins #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 - } + //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/Simple/SimpleAssetStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs index cd0a454..384f5f0 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/Simple/SimpleAssetStoragePlugin.cs @@ -45,7 +45,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); AssetInventoryServer server; - Dictionary metadataStorage; + Dictionary metadataStorage; Dictionary filenames; public SimpleAssetStoragePlugin() @@ -54,7 +54,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple #region Required Interfaces - public BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata) + public BackendResponse TryFetchMetadata(UUID assetID, out AssetMetadata metadata) { metadata = null; BackendResponse ret; @@ -98,8 +98,9 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple public BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset) { - Metadata metadata = null; - byte[] assetData = null; + asset = new AssetBase(); + AssetMetadata metadata = asset.Metadata; + string filename; BackendResponse ret; @@ -108,7 +109,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple { try { - assetData = File.ReadAllBytes(filename); + asset.Data = File.ReadAllBytes(filename); ret = BackendResponse.Success; } catch (Exception ex) @@ -116,80 +117,74 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple m_log.ErrorFormat("Failed reading data for asset {0} from {1}: {2}", assetID, filename, ex.Message); ret = BackendResponse.Failure; } + + asset.Metadata.Type = (sbyte) Utils.ContentTypeToSLAssetType(asset.Metadata.ContentType); + asset.Metadata.Local = false; } else { + asset = null; ret = BackendResponse.NotFound; } - asset = new AssetBase(); - asset.Data = assetData; - asset.Metadata.FullID = metadata.ID; - asset.Metadata.Name = metadata.Name; - asset.Metadata.Description = metadata.Description; - asset.Metadata.CreationDate = metadata.CreationDate; - asset.Metadata.Type = (sbyte) Utils.ContentTypeToSLAssetType(metadata.ContentType); - asset.Metadata.Local = false; - asset.Metadata.Temporary = metadata.Temporary; - server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); - server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), 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(Metadata metadata, byte[] assetData, out UUID assetID) + public BackendResponse TryCreateAsset(AssetBase asset, out UUID assetID) { - assetID = metadata.ID = UUID.Random(); - return TryCreateAsset(metadata, assetData); + assetID = asset.FullID = UUID.Random(); + return TryCreateAsset(asset); } - public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData) + public BackendResponse TryCreateAsset(AssetBase asset) { BackendResponse ret; string path; - string filename = String.Format("{0}.{1}", metadata.ID, Utils.ContentTypeToExtension(metadata.ContentType)); + string filename = String.Format("{0}.{1}", asset.FullID, Utils.ContentTypeToExtension(asset.Metadata.ContentType)); - if (metadata.Temporary) + if (asset.Metadata.Temporary) path = Path.Combine(TEMP_DATA_DIR, filename); else path = Path.Combine(DEFAULT_DATA_DIR, filename); try { - File.WriteAllBytes(path, assetData); - lock (filenames) filenames[metadata.ID] = path; + File.WriteAllBytes(path, asset.Data); + lock (filenames) filenames[asset.FullID] = path; // Set the creation date to right now - metadata.CreationDate = DateTime.Now; + asset.Metadata.CreationDate = DateTime.Now; lock (metadataStorage) - metadataStorage[metadata.ID] = metadata; + metadataStorage[asset.FullID] = asset.Metadata; ret = BackendResponse.Success; } catch (Exception ex) { - m_log.ErrorFormat("Failed writing data for asset {0} to {1}: {2}", metadata.ID, filename, ex.Message); + m_log.ErrorFormat("Failed writing data for asset {0} to {1}: {2}", asset.FullID, filename, ex.Message); ret = BackendResponse.Failure; } - server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, metadata.ID, assetData.Length, DateTime.Now); + server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, asset.FullID, asset.Data.Length, DateTime.Now); return ret; } - public int ForEach(Action action, int start, int count) + public int ForEach(Action action, int start, int count) { int rowCount = 0; - lock (metadataStorage) - { - foreach (Metadata metadata in metadataStorage.Values) - { - action(metadata); - ++rowCount; - } - } + //lock (metadataStorage) + //{ + // foreach (Metadata metadata in metadataStorage.Values) + // { + // action(metadata); + // ++rowCount; + // } + //} return rowCount; } @@ -202,7 +197,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple { this.server = server; - metadataStorage = new Dictionary(); + metadataStorage = new Dictionary(); filenames = new Dictionary(); LoadFiles(DEFAULT_DATA_DIR, false); @@ -272,18 +267,18 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple string filename = assets[i]; byte[] data = File.ReadAllBytes(filename); - Metadata metadata = new Metadata(); + AssetMetadata metadata = new AssetMetadata(); metadata.CreationDate = File.GetCreationTime(filename); metadata.Description = String.Empty; - metadata.ID = SimpleUtils.ParseUUIDFromFilename(filename); + 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.ID] = metadata; - filenames[metadata.ID] = filename; + metadataStorage[metadata.FullID] = metadata; + filenames[metadata.FullID] = filename; } } catch (Exception ex) -- cgit v1.1