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.
---
.../AssetInventoryServer/AssetInventoryServer.cs | 147 +++---
OpenSim/Grid/AssetInventoryServer/Main.cs | 5 +-
.../Plugins/BrowseFrontendPlugin.cs | 137 ++++--
.../Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs | 211 ++++++---
.../OpenSim/OpenSimInventoryFrontendPlugin.cs | 514 ++++++++++-----------
.../Plugins/ReferenceFrontendPlugin.cs | 329 ++++++++-----
OpenSim/Grid/AssetInventoryServer/Utils.cs | 17 +-
prebuild.xml | 5 +-
8 files changed, 800 insertions(+), 565 deletions(-)
diff --git a/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs b/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs
index 19f2081..bd05d59 100644
--- a/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs
+++ b/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs
@@ -36,17 +36,19 @@ using System.Security.Cryptography.X509Certificates;
using System.ServiceProcess;
using ExtensionLoader;
using ExtensionLoader.Config;
-using HttpServer;
+//using HttpServer;
using log4net;
using OpenSim.Framework;
+using OpenSim.Framework.Servers;
+using OpenSim.Framework.Console;
namespace OpenSim.Grid.AssetInventoryServer
{
- public class AssetInventoryServer : ServiceBase
+ public class AssetInventoryServer : BaseOpenSimServer//ServiceBase
{
public const string CONFIG_FILE = "AssetInventoryServer.ini";
- public WebServer HttpServer;
+ //public WebServer HttpServer;
public IniConfigSource ConfigFile;
public IAssetStorageProvider StorageProvider;
@@ -60,7 +62,9 @@ namespace OpenSim.Grid.AssetInventoryServer
public AssetInventoryServer()
{
- this.ServiceName = "OpenSimAssetInventoryServer";
+ m_console = new ConsoleBase("Asset");
+ MainConsole.Instance = m_console;
+ //this.ServiceName = "OpenSimAssetInventoryServer";
}
public bool Start()
@@ -123,7 +127,7 @@ namespace OpenSim.Grid.AssetInventoryServer
catch (Exception ex)
{
Logger.Log.Error("Initializing the HTTP server failed, shutting down: " + ex.Message);
- Stop();
+ Shutdown();
return false;
}
@@ -138,7 +142,17 @@ namespace OpenSim.Grid.AssetInventoryServer
return true;
}
- public void Shutdown()
+ public void Work()
+ {
+ m_console.Notice("Enter help for a list of commands");
+
+ while (true)
+ {
+ m_console.Prompt();
+ }
+ }
+
+ public override void ShutdownSpecific()
{
foreach (IAssetInventoryServerPlugin plugin in frontends)
{
@@ -162,26 +176,27 @@ namespace OpenSim.Grid.AssetInventoryServer
void InitHttpServer(int port, X509Certificate serverCert)
{
- if (serverCert != null)
- HttpServer = new WebServer(IPAddress.Any, port, serverCert, null, false);
- else
- HttpServer = new WebServer(IPAddress.Any, port);
-
- HttpServer.LogWriter = new log4netLogWriter(Logger.Log);
-
- HttpServer.Set404Handler(
- delegate(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
- {
- Logger.Log.Warn("Requested page was not found: " + request.Uri.PathAndQuery);
-
- string notFoundString = "
Page Not FoundThe requested page or method was not found";
- byte[] buffer = System.Text.Encoding.UTF8.GetBytes(notFoundString);
- response.Body.Write(buffer, 0, buffer.Length);
- response.Status = HttpStatusCode.NotFound;
- return true;
- }
- );
-
+ //if (serverCert != null)
+ // HttpServer = new WebServer(IPAddress.Any, port, serverCert, null, false);
+ //else
+ // HttpServer = new WebServer(IPAddress.Any, port);
+
+ //HttpServer.LogWriter = new log4netLogWriter(Logger.Log);
+
+ //HttpServer.Set404Handler(
+ // delegate(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ // {
+ // Logger.Log.Warn("Requested page was not found: " + request.Uri.PathAndQuery);
+
+ // string notFoundString = "Page Not FoundThe requested page or method was not found";
+ // byte[] buffer = System.Text.Encoding.UTF8.GetBytes(notFoundString);
+ // response.Body.Write(buffer, 0, buffer.Length);
+ // response.Status = HttpStatusCode.NotFound;
+ // return true;
+ // }
+ //);
+
+ m_httpServer = new BaseHttpServer(8003);
HttpServer.Start();
Logger.Log.Info("Asset server is listening on port " + port);
@@ -189,14 +204,14 @@ namespace OpenSim.Grid.AssetInventoryServer
#region ServiceBase Overrides
- protected override void OnStart(string[] args)
- {
- Start();
- }
- protected override void OnStop()
- {
- Shutdown();
- }
+ //protected override void OnStart(string[] args)
+ //{
+ // Start();
+ //}
+ //protected override void OnStop()
+ //{
+ // Shutdown();
+ //}
#endregion
@@ -231,36 +246,36 @@ namespace OpenSim.Grid.AssetInventoryServer
}
}
- public class log4netLogWriter : ILogWriter
- {
- ILog Log;
-
- public log4netLogWriter(ILog log)
- {
- Log = log;
- }
-
- public void Write(object source, LogPrio prio, string message)
- {
- switch (prio)
- {
- case LogPrio.Trace:
- case LogPrio.Debug:
- Log.DebugFormat("{0}: {1}", source, message);
- break;
- case LogPrio.Info:
- Log.InfoFormat("{0}: {1}", source, message);
- break;
- case LogPrio.Warning:
- Log.WarnFormat("{0}: {1}", source, message);
- break;
- case LogPrio.Error:
- Log.ErrorFormat("{0}: {1}", source, message);
- break;
- case LogPrio.Fatal:
- Log.FatalFormat("{0}: {1}", source, message);
- break;
- }
- }
- }
+ //public class log4netLogWriter : ILogWriter
+ //{
+ // ILog Log;
+
+ // public log4netLogWriter(ILog log)
+ // {
+ // Log = log;
+ // }
+
+ // public void Write(object source, LogPrio prio, string message)
+ // {
+ // switch (prio)
+ // {
+ // case LogPrio.Trace:
+ // case LogPrio.Debug:
+ // Log.DebugFormat("{0}: {1}", source, message);
+ // break;
+ // case LogPrio.Info:
+ // Log.InfoFormat("{0}: {1}", source, message);
+ // break;
+ // case LogPrio.Warning:
+ // Log.WarnFormat("{0}: {1}", source, message);
+ // break;
+ // case LogPrio.Error:
+ // Log.ErrorFormat("{0}: {1}", source, message);
+ // break;
+ // case LogPrio.Fatal:
+ // Log.FatalFormat("{0}: {1}", source, message);
+ // break;
+ // }
+ // }
+ //}
}
diff --git a/OpenSim/Grid/AssetInventoryServer/Main.cs b/OpenSim/Grid/AssetInventoryServer/Main.cs
index 894a32a..2f01281 100644
--- a/OpenSim/Grid/AssetInventoryServer/Main.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Main.cs
@@ -50,8 +50,9 @@ namespace OpenSim.Grid.AssetInventoryServer
Environment.Exit(0);
};
- while (true)
- Console.ReadLine();
+ server.Work();
+ //while (true)
+ // Console.ReadLine();
}
#else
ServiceBase[] servicesToRun = new ServiceBase[] { new AssetInventoryServer() };
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 =
- "Name | Description | Type | ID | Temporary | SHA-1 |
";
- const string TABLE_FOOTER = "
";
- 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 =
+ "Name | Description | Type | ID | Temporary | SHA-1 |
";
+ const string TABLE_FOOTER = "
";
+ 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
}
}
}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
index f831e24..3431ff3 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetFrontendPlugin.cs
@@ -37,6 +37,7 @@ using System.Xml.Serialization;
using OpenMetaverse;
using HttpServer;
using OpenSim.Framework;
+using OpenSim.Framework.Servers;
namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
{
@@ -55,10 +56,10 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
this.server = server;
// Asset request
- server.HttpServer.AddHandler("get", null, @"^/assets/", AssetRequestHandler);
+ server.HttpServer.AddStreamHandler(new AssetRequestHandler(server));
// Asset creation
- server.HttpServer.AddHandler("post", null, @"^/assets/", AssetPostHandler);
+ server.HttpServer.AddStreamHandler(new AssetPostHandler(server));
Logger.Log.Info("[ASSET] OpenSim Asset Frontend loaded.");
}
@@ -89,100 +90,172 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
#endregion IPlugin implementation
- bool AssetRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ public class AssetRequestHandler : IStreamedRequestHandler
{
- UUID assetID;
- // Split the URL up to get the asset ID out
- string[] rawUrl = request.Uri.PathAndQuery.Split('/');
+ AssetInventoryServer m_server;
+ string m_contentType;
+ string m_httpMethod;
+ string m_path;
- if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out assetID))
+ public AssetRequestHandler(AssetInventoryServer server)
{
- Metadata metadata;
- byte[] assetData;
- BackendResponse dataResponse;
+ m_server = server;
+ m_contentType = null;
+ m_httpMethod = "GET";
+ m_path = @"^/assets/";
+ }
+
+ #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[] buffer = null;
+ UUID assetID;
+ // Split the URL up to get the asset ID out
+ string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
- if ((dataResponse = server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success)
+ if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out assetID))
{
- AssetBase 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;
-
- XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
- MemoryStream ms = new MemoryStream();
- XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
- xs.Serialize(xw, asset);
- xw.Flush();
-
- ms.Seek(0, SeekOrigin.Begin);
- byte[] buffer = ms.GetBuffer();
-
- response.Status = HttpStatusCode.OK;
- response.ContentType = "application/xml";
- response.ContentLength = ms.Length;
- response.Body.Write(buffer, 0, (int) ms.Length);
- response.Body.Flush();
+ Metadata metadata;
+ byte[] assetData;
+ BackendResponse dataResponse;
+
+ if ((dataResponse = m_server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success)
+ {
+ AssetBase 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;
+
+ XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
+ MemoryStream ms = new MemoryStream();
+ XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
+ xs.Serialize(xw, asset);
+ xw.Flush();
+
+ ms.Seek(0, SeekOrigin.Begin);
+ buffer = ms.GetBuffer();
+
+ httpResponse.StatusCode = (int) HttpStatusCode.OK;
+ httpResponse.ContentType = "application/xml";
+ httpResponse.ContentLength = ms.Length;
+ httpResponse.Body.Write(buffer, 0, (int) ms.Length);
+ httpResponse.Body.Flush();
+ }
+ else
+ {
+ Logger.Log.WarnFormat("Failed to fetch asset data or metadata for {0}: {1}", assetID, dataResponse);
+ httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
+ }
}
else
{
- Logger.Log.WarnFormat("Failed to fetch asset data or metadata for {0}: {1}", assetID, dataResponse);
- response.Status = HttpStatusCode.NotFound;
+ Logger.Log.Warn("Unrecognized OpenSim asset request: " + httpRequest.Url.PathAndQuery);
}
- }
- else
- {
- Logger.Log.Warn("Unrecognized OpenSim asset request: " + request.Uri.PathAndQuery);
+
+ return buffer;
}
- return true;
+ #endregion IStreamedRequestHandler implementation
}
- bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ public class AssetPostHandler : IStreamedRequestHandler
{
- Metadata metadata = new Metadata();
+ AssetInventoryServer m_server;
+ string m_contentType;
+ string m_httpMethod;
+ string m_path;
+
+ public AssetPostHandler(AssetInventoryServer server)
+ {
+ m_server = server;
+ m_contentType = null;
+ m_httpMethod = "POST";
+ m_path = @"^/assets/";
+ }
+
+ #region IStreamedRequestHandler implementation
- try
+ public string ContentType
{
- AssetBase asset = (AssetBase) new XmlSerializer(typeof (AssetBase)).Deserialize(request.Body);
+ get { return m_contentType; }
+ }
- if (asset.Data != null && asset.Data.Length > 0)
+ 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)
+ //bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ {
+ Metadata metadata = new Metadata();
+
+ try
{
- 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;
+ 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;
+ metadata.SHA1 = OpenMetaverse.Utils.SHA1(asset.Data);
+ metadata.CreationDate = DateTime.Now;
- BackendResponse storageResponse = server.StorageProvider.TryCreateAsset(metadata, asset.Data);
+ BackendResponse storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, asset.Data);
- if (storageResponse == BackendResponse.Success)
- response.Status = HttpStatusCode.Created;
- else if (storageResponse == BackendResponse.NotFound)
- response.Status = HttpStatusCode.NotFound;
+ 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
- response.Status = HttpStatusCode.InternalServerError;
+ {
+ Logger.Log.Warn("AssetPostHandler called with no asset data");
+ httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
+ }
}
- else
+ catch (Exception ex)
{
- Logger.Log.Warn("AssetPostHandler called with no asset data");
- response.Status = HttpStatusCode.BadRequest;
+ Logger.Log.Warn("Failed to parse POST data (expecting AssetBase): " + ex.Message);
+ httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
}
- }
- catch (Exception ex)
- {
- Logger.Log.Warn("Failed to parse POST data (expecting AssetBase): " + ex.Message);
- response.Status = HttpStatusCode.BadRequest;
+
+ return null;
}
- return true;
+ #endregion IStreamedRequestHandler implementation
}
}
}
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs
index 0f3867a..ac67159 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimInventoryFrontendPlugin.cs
@@ -56,16 +56,16 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
{
this.server = server;
- server.HttpServer.AddHandler("post", null, @"^/GetInventory/", GetInventoryHandler);
- server.HttpServer.AddHandler("post", null, @"^/CreateInventory/", CreateInventoryHandler);
- server.HttpServer.AddHandler("post", null, @"^/NewFolder/", NewFolderHandler);
- server.HttpServer.AddHandler("post", null, @"^/UpdateFolder/", UpdateFolderHandler);
- server.HttpServer.AddHandler("post", null, @"^/MoveFolder/", MoveFolderHandler);
- server.HttpServer.AddHandler("post", null, @"^/PurgeFolder/", PurgeFolderHandler);
- server.HttpServer.AddHandler("post", null, @"^/NewItem/", NewItemHandler);
- server.HttpServer.AddHandler("post", null, @"^/DeleteItem/", DeleteItemHandler);
- server.HttpServer.AddHandler("post", null, @"^/RootFolders/", RootFoldersHandler);
- server.HttpServer.AddHandler("post", null, @"^/ActiveGestures/", ActiveGesturesHandler);
+ //server.HttpServer.AddHandler("post", null, @"^/GetInventory/", GetInventoryHandler);
+ //server.HttpServer.AddHandler("post", null, @"^/CreateInventory/", CreateInventoryHandler);
+ //server.HttpServer.AddHandler("post", null, @"^/NewFolder/", NewFolderHandler);
+ //server.HttpServer.AddHandler("post", null, @"^/UpdateFolder/", UpdateFolderHandler);
+ //server.HttpServer.AddHandler("post", null, @"^/MoveFolder/", MoveFolderHandler);
+ //server.HttpServer.AddHandler("post", null, @"^/PurgeFolder/", PurgeFolderHandler);
+ //server.HttpServer.AddHandler("post", null, @"^/NewItem/", NewItemHandler);
+ //server.HttpServer.AddHandler("post", null, @"^/DeleteItem/", DeleteItemHandler);
+ //server.HttpServer.AddHandler("post", null, @"^/RootFolders/", RootFoldersHandler);
+ //server.HttpServer.AddHandler("post", null, @"^/ActiveGestures/", ActiveGesturesHandler);
Logger.Log.Info("[INVENTORY] OpenSim Inventory Frontend loaded.");
}
@@ -96,253 +96,253 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
#endregion IPlugin implementation
- bool GetInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
- {
- UUID sessionID, agentID;
- UUID ownerID = DeserializeUUID(request.Body, out agentID, out sessionID);
-
- if (ownerID != UUID.Zero)
- {
- Logger.Log.Warn("GetInventory is not scalable on some inventory backends, avoid calling it wherever possible");
-
- Uri owner = Utils.GetOpenSimUri(ownerID);
- InventoryCollection inventory;
- BackendResponse storageResponse = server.InventoryProvider.TryFetchInventory(owner, out inventory);
-
- if (storageResponse == BackendResponse.Success)
- {
- collectionSerializer.Serialize(response.Body, inventory);
- response.Body.Flush();
- }
- else if (storageResponse == BackendResponse.NotFound)
- {
- // Return an empty inventory set to mimic OpenSim.Grid.InventoryServer.exe
- inventory = new InventoryCollection();
- inventory.UserID = ownerID;
- inventory.Folders = new Dictionary();
- inventory.Items = new Dictionary();
- collectionSerializer.Serialize(response.Body, inventory);
- response.Body.Flush();
- }
- else
- {
- response.Status = HttpStatusCode.InternalServerError;
- }
- }
- else
- {
- response.Status = HttpStatusCode.BadRequest;
- }
-
- return true;
- }
-
- bool CreateInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
- {
- UUID ownerID = DeserializeUUID(request.Body);
-
- if (ownerID != UUID.Zero)
- {
- Uri owner = Utils.GetOpenSimUri(ownerID);
- Logger.Log.DebugFormat("Created URI {0} for inventory creation", owner);
-
- InventoryFolder rootFolder = new InventoryFolder("My Inventory", ownerID, UUID.Zero, (short)AssetType.Folder);
- BackendResponse storageResponse = server.InventoryProvider.TryCreateInventory(owner, rootFolder);
- if (storageResponse == BackendResponse.Success)
- {
- CreateFolder("Animations", ownerID, rootFolder.ID, AssetType.Animation);
- CreateFolder("Body Parts", ownerID, rootFolder.ID, AssetType.Bodypart);
- CreateFolder("Calling Cards", ownerID, rootFolder.ID, AssetType.CallingCard);
- CreateFolder("Clothing", ownerID, rootFolder.ID, AssetType.Clothing);
- CreateFolder("Gestures", ownerID, rootFolder.ID, AssetType.Gesture);
- CreateFolder("Landmarks", ownerID, rootFolder.ID, AssetType.Landmark);
- CreateFolder("Lost and Found", ownerID, rootFolder.ID, AssetType.LostAndFoundFolder);
- CreateFolder("Notecards", ownerID, rootFolder.ID, AssetType.Notecard);
- CreateFolder("Objects", ownerID, rootFolder.ID, AssetType.Object);
- CreateFolder("Photo Album", ownerID, rootFolder.ID, AssetType.SnapshotFolder);
- CreateFolder("Scripts", ownerID, rootFolder.ID, AssetType.LSLText);
- CreateFolder("Sounds", ownerID, rootFolder.ID, AssetType.Sound);
- CreateFolder("Textures", ownerID, rootFolder.ID, AssetType.Texture);
- CreateFolder("Trash", ownerID, rootFolder.ID, AssetType.TrashFolder);
-
- SerializeBool(response.Body, true);
- return true;
- }
- }
-
- SerializeBool(response.Body, false);
- return true;
- }
-
- bool NewFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
- {
- UUID agentID, sessionID;
- InventoryFolder folder = DeserializeFolder(request.Body, out agentID, out sessionID);
-
- if (folder != null)
- {
- Uri owner = Utils.GetOpenSimUri(folder.Owner);
-
- // Some calls that are moving or updating a folder instead of creating a new one
- // will pass in an InventoryFolder without the name set. If this is the case we
- // need to look up the name first
- if (String.IsNullOrEmpty(folder.Name))
- {
- InventoryFolder oldFolder;
- if (server.InventoryProvider.TryFetchFolder(owner, folder.ID, out oldFolder) == BackendResponse.Success)
- folder.Name = oldFolder.Name;
- }
-
- BackendResponse storageResponse = server.InventoryProvider.TryCreateFolder(owner, folder);
-
- if (storageResponse == BackendResponse.Success)
- {
- SerializeBool(response.Body, true);
- return true;
- }
- }
-
- SerializeBool(response.Body, false);
- return true;
- }
-
- bool UpdateFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
- {
- return NewFolderHandler(client, request, response);
- }
-
- bool MoveFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
- {
- return NewFolderHandler(client, request, response);
- }
-
- bool PurgeFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
- {
- UUID agentID, sessionID;
- InventoryFolder folder = DeserializeFolder(request.Body, out agentID, out sessionID);
-
- if (folder != null)
- {
- Uri owner = Utils.GetOpenSimUri(folder.Owner);
- BackendResponse storageResponse = server.InventoryProvider.TryPurgeFolder(owner, folder.ID);
-
- if (storageResponse == BackendResponse.Success)
- {
- SerializeBool(response.Body, true);
- return true;
- }
- }
-
- SerializeBool(response.Body, false);
- return true;
- }
-
- bool NewItemHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
- {
- UUID agentID, sessionID;
- InventoryItem item = DeserializeItem(request.Body, out agentID, out sessionID);
-
- if (item != null)
- {
- Uri owner = Utils.GetOpenSimUri(agentID);
- BackendResponse storageResponse = server.InventoryProvider.TryCreateItem(owner, item);
-
- if (storageResponse == BackendResponse.Success)
- {
- SerializeBool(response.Body, true);
- return true;
- }
- }
-
- SerializeBool(response.Body, false);
- return true;
- }
-
- bool DeleteItemHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
- {
- UUID agentID, sessionID;
- InventoryItem item = DeserializeItem(request.Body, out agentID, out sessionID);
-
- if (item != null)
- {
- Uri owner = Utils.GetOpenSimUri(item.Owner);
- BackendResponse storageResponse = server.InventoryProvider.TryDeleteItem(owner, item.ID);
-
- if (storageResponse == BackendResponse.Success)
- {
- SerializeBool(response.Body, true);
- return true;
- }
- }
-
- SerializeBool(response.Body, false);
- return true;
- }
-
- bool RootFoldersHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
- {
- UUID ownerID = DeserializeUUID(request.Body);
-
- if (ownerID != UUID.Zero)
- {
- Uri owner = Utils.GetOpenSimUri(ownerID);
- List skeleton;
- BackendResponse storageResponse = server.InventoryProvider.TryFetchFolderList(owner, out skeleton);
-
- if (storageResponse == BackendResponse.Success)
- {
- SerializeFolderList(response.Body, skeleton);
- }
- else if (storageResponse == BackendResponse.NotFound)
- {
- // Return an empty set of inventory so the requester knows that
- // an inventory needs to be created for this agent
- SerializeFolderList(response.Body, new List(0));
- }
- else
- {
- response.Status = HttpStatusCode.InternalServerError;
- }
- }
- else
- {
- response.Status = HttpStatusCode.BadRequest;
- }
-
- return true;
- }
-
- bool ActiveGesturesHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
- {
- UUID ownerID = DeserializeUUID(request.Body);
-
- if (ownerID != UUID.Zero)
- {
- Uri owner = Utils.GetOpenSimUri(ownerID);
- List gestures;
- BackendResponse storageResponse = server.InventoryProvider.TryFetchActiveGestures(owner, out gestures);
-
- if (storageResponse == BackendResponse.Success)
- {
- SerializeItemList(response.Body, gestures);
- }
- else if (storageResponse == BackendResponse.NotFound)
- {
- // Return an empty set of gestures to match OpenSim.Grid.InventoryServer.exe behavior
- SerializeItemList(response.Body, new List(0));
- }
- else
- {
- response.Status = HttpStatusCode.InternalServerError;
- }
- }
- else
- {
- response.Status = HttpStatusCode.BadRequest;
- }
-
- return true;
- }
+ //bool GetInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ //{
+ // UUID sessionID, agentID;
+ // UUID ownerID = DeserializeUUID(request.Body, out agentID, out sessionID);
+
+ // if (ownerID != UUID.Zero)
+ // {
+ // Logger.Log.Warn("GetInventory is not scalable on some inventory backends, avoid calling it wherever possible");
+
+ // Uri owner = Utils.GetOpenSimUri(ownerID);
+ // InventoryCollection inventory;
+ // BackendResponse storageResponse = server.InventoryProvider.TryFetchInventory(owner, out inventory);
+
+ // if (storageResponse == BackendResponse.Success)
+ // {
+ // collectionSerializer.Serialize(response.Body, inventory);
+ // response.Body.Flush();
+ // }
+ // else if (storageResponse == BackendResponse.NotFound)
+ // {
+ // // Return an empty inventory set to mimic OpenSim.Grid.InventoryServer.exe
+ // inventory = new InventoryCollection();
+ // inventory.UserID = ownerID;
+ // inventory.Folders = new Dictionary();
+ // inventory.Items = new Dictionary();
+ // collectionSerializer.Serialize(response.Body, inventory);
+ // response.Body.Flush();
+ // }
+ // else
+ // {
+ // response.Status = HttpStatusCode.InternalServerError;
+ // }
+ // }
+ // else
+ // {
+ // response.Status = HttpStatusCode.BadRequest;
+ // }
+
+ // return true;
+ //}
+
+ //bool CreateInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ //{
+ // UUID ownerID = DeserializeUUID(request.Body);
+
+ // if (ownerID != UUID.Zero)
+ // {
+ // Uri owner = Utils.GetOpenSimUri(ownerID);
+ // Logger.Log.DebugFormat("Created URI {0} for inventory creation", owner);
+
+ // InventoryFolder rootFolder = new InventoryFolder("My Inventory", ownerID, UUID.Zero, (short)AssetType.Folder);
+ // BackendResponse storageResponse = server.InventoryProvider.TryCreateInventory(owner, rootFolder);
+ // if (storageResponse == BackendResponse.Success)
+ // {
+ // CreateFolder("Animations", ownerID, rootFolder.ID, AssetType.Animation);
+ // CreateFolder("Body Parts", ownerID, rootFolder.ID, AssetType.Bodypart);
+ // CreateFolder("Calling Cards", ownerID, rootFolder.ID, AssetType.CallingCard);
+ // CreateFolder("Clothing", ownerID, rootFolder.ID, AssetType.Clothing);
+ // CreateFolder("Gestures", ownerID, rootFolder.ID, AssetType.Gesture);
+ // CreateFolder("Landmarks", ownerID, rootFolder.ID, AssetType.Landmark);
+ // CreateFolder("Lost and Found", ownerID, rootFolder.ID, AssetType.LostAndFoundFolder);
+ // CreateFolder("Notecards", ownerID, rootFolder.ID, AssetType.Notecard);
+ // CreateFolder("Objects", ownerID, rootFolder.ID, AssetType.Object);
+ // CreateFolder("Photo Album", ownerID, rootFolder.ID, AssetType.SnapshotFolder);
+ // CreateFolder("Scripts", ownerID, rootFolder.ID, AssetType.LSLText);
+ // CreateFolder("Sounds", ownerID, rootFolder.ID, AssetType.Sound);
+ // CreateFolder("Textures", ownerID, rootFolder.ID, AssetType.Texture);
+ // CreateFolder("Trash", ownerID, rootFolder.ID, AssetType.TrashFolder);
+
+ // SerializeBool(response.Body, true);
+ // return true;
+ // }
+ // }
+
+ // SerializeBool(response.Body, false);
+ // return true;
+ //}
+
+ //bool NewFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ //{
+ // UUID agentID, sessionID;
+ // InventoryFolder folder = DeserializeFolder(request.Body, out agentID, out sessionID);
+
+ // if (folder != null)
+ // {
+ // Uri owner = Utils.GetOpenSimUri(folder.Owner);
+
+ // // Some calls that are moving or updating a folder instead of creating a new one
+ // // will pass in an InventoryFolder without the name set. If this is the case we
+ // // need to look up the name first
+ // if (String.IsNullOrEmpty(folder.Name))
+ // {
+ // InventoryFolder oldFolder;
+ // if (server.InventoryProvider.TryFetchFolder(owner, folder.ID, out oldFolder) == BackendResponse.Success)
+ // folder.Name = oldFolder.Name;
+ // }
+
+ // BackendResponse storageResponse = server.InventoryProvider.TryCreateFolder(owner, folder);
+
+ // if (storageResponse == BackendResponse.Success)
+ // {
+ // SerializeBool(response.Body, true);
+ // return true;
+ // }
+ // }
+
+ // SerializeBool(response.Body, false);
+ // return true;
+ //}
+
+ //bool UpdateFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ //{
+ // return NewFolderHandler(client, request, response);
+ //}
+
+ //bool MoveFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ //{
+ // return NewFolderHandler(client, request, response);
+ //}
+
+ //bool PurgeFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ //{
+ // UUID agentID, sessionID;
+ // InventoryFolder folder = DeserializeFolder(request.Body, out agentID, out sessionID);
+
+ // if (folder != null)
+ // {
+ // Uri owner = Utils.GetOpenSimUri(folder.Owner);
+ // BackendResponse storageResponse = server.InventoryProvider.TryPurgeFolder(owner, folder.ID);
+
+ // if (storageResponse == BackendResponse.Success)
+ // {
+ // SerializeBool(response.Body, true);
+ // return true;
+ // }
+ // }
+
+ // SerializeBool(response.Body, false);
+ // return true;
+ //}
+
+ //bool NewItemHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ //{
+ // UUID agentID, sessionID;
+ // InventoryItem item = DeserializeItem(request.Body, out agentID, out sessionID);
+
+ // if (item != null)
+ // {
+ // Uri owner = Utils.GetOpenSimUri(agentID);
+ // BackendResponse storageResponse = server.InventoryProvider.TryCreateItem(owner, item);
+
+ // if (storageResponse == BackendResponse.Success)
+ // {
+ // SerializeBool(response.Body, true);
+ // return true;
+ // }
+ // }
+
+ // SerializeBool(response.Body, false);
+ // return true;
+ //}
+
+ //bool DeleteItemHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ //{
+ // UUID agentID, sessionID;
+ // InventoryItem item = DeserializeItem(request.Body, out agentID, out sessionID);
+
+ // if (item != null)
+ // {
+ // Uri owner = Utils.GetOpenSimUri(item.Owner);
+ // BackendResponse storageResponse = server.InventoryProvider.TryDeleteItem(owner, item.ID);
+
+ // if (storageResponse == BackendResponse.Success)
+ // {
+ // SerializeBool(response.Body, true);
+ // return true;
+ // }
+ // }
+
+ // SerializeBool(response.Body, false);
+ // return true;
+ //}
+
+ //bool RootFoldersHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ //{
+ // UUID ownerID = DeserializeUUID(request.Body);
+
+ // if (ownerID != UUID.Zero)
+ // {
+ // Uri owner = Utils.GetOpenSimUri(ownerID);
+ // List skeleton;
+ // BackendResponse storageResponse = server.InventoryProvider.TryFetchFolderList(owner, out skeleton);
+
+ // if (storageResponse == BackendResponse.Success)
+ // {
+ // SerializeFolderList(response.Body, skeleton);
+ // }
+ // else if (storageResponse == BackendResponse.NotFound)
+ // {
+ // // Return an empty set of inventory so the requester knows that
+ // // an inventory needs to be created for this agent
+ // SerializeFolderList(response.Body, new List(0));
+ // }
+ // else
+ // {
+ // response.Status = HttpStatusCode.InternalServerError;
+ // }
+ // }
+ // else
+ // {
+ // response.Status = HttpStatusCode.BadRequest;
+ // }
+
+ // return true;
+ //}
+
+ //bool ActiveGesturesHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ //{
+ // UUID ownerID = DeserializeUUID(request.Body);
+
+ // if (ownerID != UUID.Zero)
+ // {
+ // Uri owner = Utils.GetOpenSimUri(ownerID);
+ // List gestures;
+ // BackendResponse storageResponse = server.InventoryProvider.TryFetchActiveGestures(owner, out gestures);
+
+ // if (storageResponse == BackendResponse.Success)
+ // {
+ // SerializeItemList(response.Body, gestures);
+ // }
+ // else if (storageResponse == BackendResponse.NotFound)
+ // {
+ // // Return an empty set of gestures to match OpenSim.Grid.InventoryServer.exe behavior
+ // SerializeItemList(response.Body, new List(0));
+ // }
+ // else
+ // {
+ // response.Status = HttpStatusCode.InternalServerError;
+ // }
+ // }
+ // else
+ // {
+ // response.Status = HttpStatusCode.BadRequest;
+ // }
+
+ // return true;
+ //}
BackendResponse CreateFolder(string name, UUID ownerID, UUID parentID, AssetType assetType)
{
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
index fddc385..d1ea201 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
@@ -28,6 +28,7 @@
*/
using System;
+using System.IO;
using System.Collections.Generic;
using System.Net;
using System.Xml;
@@ -35,12 +36,13 @@ using OpenMetaverse;
using OpenMetaverse.StructuredData;
using HttpServer;
using OpenSim.Framework;
+using OpenSim.Framework.Servers;
namespace OpenSim.Grid.AssetInventoryServer.Plugins
{
public class ReferenceFrontendPlugin : IAssetInventoryServerPlugin
{
- AssetInventoryServer server;
+ AssetInventoryServer m_server;
public ReferenceFrontendPlugin()
{
@@ -50,18 +52,16 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
public void Initialise(AssetInventoryServer server)
{
- this.server = server;
+ m_server = server;
// Asset metadata request
- server.HttpServer.AddHandler("get", null, @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/metadata",
- MetadataRequestHandler);
+ m_server.HttpServer.AddStreamHandler(new MetadataRequestHandler(server));
// Asset data request
- server.HttpServer.AddHandler("get", null, @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/data",
- DataRequestHandler);
+ m_server.HttpServer.AddStreamHandler(new DataRequestHandler(server));
// Asset creation
- server.HttpServer.AddHandler("post", null, "^/createasset", CreateRequestHandler);
+ m_server.HttpServer.AddStreamHandler(new CreateRequestHandler(server));
Logger.Log.Info("[ASSET] Reference Frontend loaded.");
}
@@ -92,174 +92,279 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
#endregion IPlugin implementation
- bool MetadataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ public class MetadataRequestHandler : IStreamedRequestHandler
{
- UUID assetID;
- // Split the URL up into an AssetID and a method
- string[] rawUrl = request.Uri.PathAndQuery.Split('/');
+ AssetInventoryServer m_server;
+ string m_contentType;
+ string m_httpMethod;
+ string m_path;
- if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
+ public MetadataRequestHandler(AssetInventoryServer server)
{
- UUID authToken = Utils.GetAuthToken(request);
+ 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; }
+ }
- if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID))
+ 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))
{
- Metadata metadata;
- BackendResponse storageResponse = server.StorageProvider.TryFetchMetadata(assetID, out metadata);
+ UUID authToken = Utils.GetAuthToken(httpRequest);
- if (storageResponse == BackendResponse.Success)
+ if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID))
{
- // 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",
- request.Uri.Scheme, request.Uri.Authority, assetID));
- }
+ Metadata metadata;
+ BackendResponse storageResponse = m_server.StorageProvider.TryFetchMetadata(assetID, out metadata);
- byte[] serializedData = metadata.SerializeToBytes();
+ 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));
+ }
- response.Status = HttpStatusCode.OK;
- response.ContentType = "application/json";
- response.ContentLength = serializedData.Length;
- response.Body.Write(serializedData, 0, serializedData.Length);
+ serializedData = metadata.SerializeToBytes();
- }
- else if (storageResponse == BackendResponse.NotFound)
- {
- Logger.Log.Warn("Could not find metadata for asset " + assetID.ToString());
- response.Status = HttpStatusCode.NotFound;
+ 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)
+ {
+ Logger.Log.Warn("Could not find metadata for asset " + assetID.ToString());
+ httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
+ }
+ else
+ {
+ httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
+ }
}
else
{
- response.Status = HttpStatusCode.InternalServerError;
+ httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
}
- }
- else
- {
- response.Status = HttpStatusCode.Forbidden;
+
+ return serializedData;
}
- return true;
+ httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
+ return serializedData;
}
- response.Status = HttpStatusCode.NotFound;
- return true;
+ #endregion IStreamedRequestHandler implementation
}
- bool DataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ public class DataRequestHandler : IStreamedRequestHandler
{
- UUID assetID;
- // Split the URL up into an AssetID and a method
- string[] rawUrl = request.Uri.PathAndQuery.Split('/');
+ AssetInventoryServer m_server;
+ string m_contentType;
+ string m_httpMethod;
+ string m_path;
+
+ public DataRequestHandler(AssetInventoryServer server)
+ {
+ m_server = server;
+ m_contentType = null;
+ m_httpMethod = "GET";
+ m_path = @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/data";
+ }
+
+ #region IStreamedRequestHandler implementation
+
+ public string ContentType
+ {
+ get { return m_contentType; }
+ }
- if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
+ public string HttpMethod
{
- UUID authToken = Utils.GetAuthToken(request);
+ get { return m_httpMethod; }
+ }
+
+ public string Path
+ {
+ get { return m_path; }
+ }
- if (server.AuthorizationProvider.IsDataAuthorized(authToken, assetID))
+ public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
+ {
+ byte[] assetData = null;
+ UUID assetID;
+ // Split the URL up into an AssetID and a method
+ string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
+
+ if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
{
- byte[] assetData;
- BackendResponse storageResponse = server.StorageProvider.TryFetchData(assetID, out assetData);
+ UUID authToken = Utils.GetAuthToken(httpRequest);
- if (storageResponse == BackendResponse.Success)
+ if (m_server.AuthorizationProvider.IsDataAuthorized(authToken, assetID))
{
- response.Status = HttpStatusCode.OK;
- response.Status = HttpStatusCode.OK;
- response.ContentType = "application/octet-stream";
- response.AddHeader("Content-Disposition", "attachment; filename=" + assetID.ToString());
- response.ContentLength = assetData.Length;
- response.Body.Write(assetData, 0, assetData.Length);
- }
- else if (storageResponse == BackendResponse.NotFound)
- {
- response.Status = HttpStatusCode.NotFound;
+ BackendResponse storageResponse = m_server.StorageProvider.TryFetchData(assetID, out assetData);
+
+ if (storageResponse == BackendResponse.Success)
+ {
+ httpResponse.StatusCode = (int) HttpStatusCode.OK;
+ httpResponse.ContentType = "application/octet-stream";
+ httpResponse.AddHeader("Content-Disposition", "attachment; filename=" + assetID.ToString());
+ httpResponse.ContentLength = assetData.Length;
+ httpResponse.Body.Write(assetData, 0, assetData.Length);
+ }
+ else if (storageResponse == BackendResponse.NotFound)
+ {
+ httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
+ }
+ else
+ {
+ httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
+ }
}
else
{
- response.Status = HttpStatusCode.InternalServerError;
+ httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
}
- }
- else
- {
- response.Status = HttpStatusCode.Forbidden;
+
+ return assetData;
}
- return true;
+ httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
+ return assetData;
}
- response.Status = HttpStatusCode.BadRequest;
- return true;
+ #endregion IStreamedRequestHandler implementation
}
- bool CreateRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
+ public class CreateRequestHandler : IStreamedRequestHandler
{
- UUID authToken = Utils.GetAuthToken(request);
+ AssetInventoryServer m_server;
+ string m_contentType;
+ string m_httpMethod;
+ string m_path;
- if (server.AuthorizationProvider.IsCreateAuthorized(authToken))
+ public CreateRequestHandler(AssetInventoryServer server)
{
- try
- {
- OSD osdata = OSDParser.DeserializeJson(request.Body);
+ m_server = server;
+ m_contentType = null;
+ m_httpMethod = "POST";
+ m_path = "^/createasset";
+ }
- if (osdata.Type == OSDType.Map)
- {
- OSDMap map = (OSDMap)osdata;
- Metadata metadata = new Metadata();
- metadata.Deserialize(map);
+ #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);
- byte[] assetData = map["data"].AsBinary();
+ if (m_server.AuthorizationProvider.IsCreateAuthorized(authToken))
+ {
+ try
+ {
+ OSD osdata = OSDParser.DeserializeJson(httpRequest.InputStream);
- if (assetData != null && assetData.Length > 0)
+ if (osdata.Type == OSDType.Map)
{
- BackendResponse storageResponse;
+ OSDMap map = (OSDMap)osdata;
+ Metadata metadata = new Metadata();
+ metadata.Deserialize(map);
- if (metadata.ID != UUID.Zero)
- storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData);
- else
- storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID);
+ byte[] assetData = map["data"].AsBinary();
- if (storageResponse == BackendResponse.Success)
- {
- response.Status = HttpStatusCode.Created;
- OSDMap responseMap = new OSDMap(1);
- responseMap["id"] = OSD.FromUUID(metadata.ID);
- LitJson.JsonData jsonData = OSDParser.SerializeJson(responseMap);
- byte[] responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson());
- response.Body.Write(responseData, 0, responseData.Length);
- response.Body.Flush();
- }
- else if (storageResponse == BackendResponse.NotFound)
+ if (assetData != null && assetData.Length > 0)
{
- response.Status = HttpStatusCode.NotFound;
+ 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
{
- response.Status = HttpStatusCode.InternalServerError;
+ httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
}
}
else
{
- response.Status = HttpStatusCode.BadRequest;
+ httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
}
}
- else
+ catch (Exception ex)
{
- response.Status = HttpStatusCode.BadRequest;
+ httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
+ httpResponse.StatusDescription = ex.Message;
}
}
- catch (Exception ex)
+ else
{
- response.Status = HttpStatusCode.InternalServerError;
- response.Reason = ex.Message;
+ httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
}
- }
- else
- {
- response.Status = HttpStatusCode.Forbidden;
+
+ return responseData;
}
- return true;
+ #endregion IStreamedRequestHandler implementation
}
}
}
diff --git a/OpenSim/Grid/AssetInventoryServer/Utils.cs b/OpenSim/Grid/AssetInventoryServer/Utils.cs
index e1b62a4..52e2370 100644
--- a/OpenSim/Grid/AssetInventoryServer/Utils.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Utils.cs
@@ -36,12 +36,13 @@ using System.Xml.Serialization;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using HttpServer;
+using OpenSim.Framework.Servers;
namespace OpenSim.Grid.AssetInventoryServer
{
public static class Utils
{
- public static UUID GetAuthToken(IHttpRequest request)
+ public static UUID GetAuthToken(OSHttpRequest request)
{
UUID authToken = UUID.Zero;
@@ -55,13 +56,13 @@ namespace OpenSim.Grid.AssetInventoryServer
UUID.TryParse(authHeaderParts[1], out authToken);
}
- if (authToken == UUID.Zero && request.Cookies != null)
- {
- // Check for an authToken cookie to make logins browser-compatible
- RequestCookie authCookie = request.Cookies["authToken"];
- if (authCookie != null)
- UUID.TryParse(authCookie.Value, out authToken);
- }
+ //if (authToken == UUID.Zero && request.Cookies != null)
+ //{
+ // // Check for an authToken cookie to make logins browser-compatible
+ // RequestCookie authCookie = request.Cookies["authToken"];
+ // if (authCookie != null)
+ // UUID.TryParse(authCookie.Value, out authToken);
+ //}
return authToken;
}
diff --git a/prebuild.xml b/prebuild.xml
index a284f72..81832dd 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -764,10 +764,11 @@
+
+
-
@@ -800,6 +801,7 @@
+
@@ -859,6 +861,7 @@
+
--
cgit v1.1