From a2f07ecd2e248966957a8ea70d772276359b02e8 Mon Sep 17 00:00:00 2001 From: Mike Mazur Date: Mon, 9 Mar 2009 07:29:34 +0000 Subject: Implemented FetchAssetMetadataSet in DB backends. This method fetches metadata for a subset of the entries in the assets database. This functionality is used in the ForEach calls in the asset storage providers in AssetInventoryServer. With this implemented, frontends such as the BrowseFrontend should now work. - MySQL: implemented, sanity tested - SQLite: implemented, sanity tested - MSSQL: implemented, not tested - NHibernate: not implemented --- .../Plugins/BrowseFrontendPlugin.cs | 185 ++++++++++----------- 1 file changed, 85 insertions(+), 100 deletions(-) (limited to 'OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs') diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs index 6e7519d..34b0565 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs @@ -42,7 +42,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins public class BrowseFrontendPlugin : IAssetInventoryServerPlugin { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - //private AssetInventoryServer m_server; + private AssetInventoryServer m_server; public BrowseFrontendPlugin() { @@ -52,10 +52,10 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins public void Initialise(AssetInventoryServer server) { - //m_server = server; + m_server = server; // Request for / or /?... - //m_server.HttpServer.AddStreamHandler(new BrowseRequestHandler(server)); + m_server.HttpServer.AddStreamHandler(new BrowseRequestHandler(server)); m_log.Info("[BROWSEFRONTEND]: Browser Frontend loaded."); } @@ -86,102 +86,87 @@ 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 : 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 + } } } -- cgit v1.1