From 07b8d51da8186e537da35c1d56d176b4843d8eaa Mon Sep 17 00:00:00 2001 From: Mike Mazur Date: Mon, 16 Feb 2009 02:27:17 +0000 Subject: AssetInventoryServer now compiles while using the standard OpenSim console and HttpServer. It doesn't work though. --- .../Plugins/BrowseFrontendPlugin.cs | 137 +++++++++++++-------- 1 file changed, 87 insertions(+), 50 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 f445b97..bb38d5d 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/BrowseFrontendPlugin.cs @@ -28,20 +28,21 @@ */ using System; +using System.IO; using System.Collections.Generic; using System.Collections.Specialized; using System.Net; using System.Text; using System.Web; using OpenMetaverse; -using HttpServer; using OpenSim.Framework; +using OpenSim.Framework.Servers; namespace OpenSim.Grid.AssetInventoryServer.Plugins { public class BrowseFrontendPlugin : IAssetInventoryServerPlugin { - AssetInventoryServer server; + AssetInventoryServer m_server; public BrowseFrontendPlugin() { @@ -51,10 +52,11 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins public void Initialise(AssetInventoryServer server) { - this.server = server; + m_server = server; // Request for / or /?... - server.HttpServer.AddHandler("get", null, @"(^/$)|(^/\?.*)", BrowseRequestHandler); + //server.HttpServer.AddHandler("get", null, @"(^/$)|(^/\?.*)", BrowseRequestHandler); + m_server.HttpServer.AddStreamHandler(new BrowseRequestHandler(server)); Logger.Log.Info("[ASSET] Browser Frontend loaded."); } @@ -85,67 +87,102 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins #endregion IPlugin implementation - bool BrowseRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) + public class BrowseRequestHandler : IStreamedRequestHandler { - const int ASSETS_PER_PAGE = 25; - const string HEADER = "Asset Server"; - const string TABLE_HEADER = - ""; - const string TABLE_FOOTER = "
NameDescriptionTypeIDTemporarySHA-1
"; - const string FOOTER = ""; + AssetInventoryServer m_server; + string m_contentType; + string m_httpMethod; + string m_path; - UUID authToken = Utils.GetAuthToken(request); + public BrowseRequestHandler(AssetInventoryServer server) + { + m_server = server; + m_contentType = null; + m_httpMethod = "GET"; + m_path = @"(^/$)|(^/\?.*)"; + } - StringBuilder html = new StringBuilder(); - int start = 0; - uint page = 0; + #region IStreamedRequestHandler implementation + + public string ContentType + { + get { return m_contentType; } + } + + public string HttpMethod + { + get { return m_httpMethod; } + } - if (!String.IsNullOrEmpty(request.Uri.Query)) + public string Path { - NameValueCollection query = HttpUtility.ParseQueryString(request.Uri.Query); - if (!String.IsNullOrEmpty(query["page"]) && UInt32.TryParse(query["page"], out page)) - start = (int)page * ASSETS_PER_PAGE; + get { return m_path; } } - html.AppendLine(HEADER); + 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 = ""; - html.AppendLine("

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

"); + UUID authToken = Utils.GetAuthToken(httpRequest); - html.AppendLine(TABLE_HEADER); + StringBuilder html = new StringBuilder(); + int start = 0; + uint page = 0; - server.StorageProvider.ForEach( - delegate(Metadata data) + if (!String.IsNullOrEmpty(httpRequest.Url.Query)) { - if (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 - ); + 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(TABLE_FOOTER); + html.AppendLine(HEADER); - html.AppendLine(FOOTER); + html.AppendLine("

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

"); - byte[] responseData = System.Text.Encoding.UTF8.GetBytes(html.ToString()); + 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; + } - response.Status = HttpStatusCode.OK; - response.Body.Write(responseData, 0, responseData.Length); - response.Body.Flush(); - return true; + #endregion IStreamedRequestHandler implementation } } } -- cgit v1.1