AssetInventoryServer now compiles while using the standard OpenSim
console and HttpServer. It doesn't work though.0.6.3-post-fixes
parent
1778f799ba
commit
07b8d51da8
|
@ -36,17 +36,19 @@ using System.Security.Cryptography.X509Certificates;
|
||||||
using System.ServiceProcess;
|
using System.ServiceProcess;
|
||||||
using ExtensionLoader;
|
using ExtensionLoader;
|
||||||
using ExtensionLoader.Config;
|
using ExtensionLoader.Config;
|
||||||
using HttpServer;
|
//using HttpServer;
|
||||||
using log4net;
|
using log4net;
|
||||||
using OpenSim.Framework;
|
using OpenSim.Framework;
|
||||||
|
using OpenSim.Framework.Servers;
|
||||||
|
using OpenSim.Framework.Console;
|
||||||
|
|
||||||
namespace OpenSim.Grid.AssetInventoryServer
|
namespace OpenSim.Grid.AssetInventoryServer
|
||||||
{
|
{
|
||||||
public class AssetInventoryServer : ServiceBase
|
public class AssetInventoryServer : BaseOpenSimServer//ServiceBase
|
||||||
{
|
{
|
||||||
public const string CONFIG_FILE = "AssetInventoryServer.ini";
|
public const string CONFIG_FILE = "AssetInventoryServer.ini";
|
||||||
|
|
||||||
public WebServer HttpServer;
|
//public WebServer HttpServer;
|
||||||
public IniConfigSource ConfigFile;
|
public IniConfigSource ConfigFile;
|
||||||
|
|
||||||
public IAssetStorageProvider StorageProvider;
|
public IAssetStorageProvider StorageProvider;
|
||||||
|
@ -60,7 +62,9 @@ namespace OpenSim.Grid.AssetInventoryServer
|
||||||
|
|
||||||
public AssetInventoryServer()
|
public AssetInventoryServer()
|
||||||
{
|
{
|
||||||
this.ServiceName = "OpenSimAssetInventoryServer";
|
m_console = new ConsoleBase("Asset");
|
||||||
|
MainConsole.Instance = m_console;
|
||||||
|
//this.ServiceName = "OpenSimAssetInventoryServer";
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Start()
|
public bool Start()
|
||||||
|
@ -123,7 +127,7 @@ namespace OpenSim.Grid.AssetInventoryServer
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.Log.Error("Initializing the HTTP server failed, shutting down: " + ex.Message);
|
Logger.Log.Error("Initializing the HTTP server failed, shutting down: " + ex.Message);
|
||||||
Stop();
|
Shutdown();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +142,17 @@ namespace OpenSim.Grid.AssetInventoryServer
|
||||||
return true;
|
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)
|
foreach (IAssetInventoryServerPlugin plugin in frontends)
|
||||||
{
|
{
|
||||||
|
@ -162,26 +176,27 @@ namespace OpenSim.Grid.AssetInventoryServer
|
||||||
|
|
||||||
void InitHttpServer(int port, X509Certificate serverCert)
|
void InitHttpServer(int port, X509Certificate serverCert)
|
||||||
{
|
{
|
||||||
if (serverCert != null)
|
//if (serverCert != null)
|
||||||
HttpServer = new WebServer(IPAddress.Any, port, serverCert, null, false);
|
// HttpServer = new WebServer(IPAddress.Any, port, serverCert, null, false);
|
||||||
else
|
//else
|
||||||
HttpServer = new WebServer(IPAddress.Any, port);
|
// HttpServer = new WebServer(IPAddress.Any, port);
|
||||||
|
|
||||||
HttpServer.LogWriter = new log4netLogWriter(Logger.Log);
|
//HttpServer.LogWriter = new log4netLogWriter(Logger.Log);
|
||||||
|
|
||||||
HttpServer.Set404Handler(
|
//HttpServer.Set404Handler(
|
||||||
delegate(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
// delegate(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||||
{
|
// {
|
||||||
Logger.Log.Warn("Requested page was not found: " + request.Uri.PathAndQuery);
|
// Logger.Log.Warn("Requested page was not found: " + request.Uri.PathAndQuery);
|
||||||
|
|
||||||
string notFoundString = "<html><head><title>Page Not Found</title></head><body>The requested page or method was not found</body></html>";
|
// string notFoundString = "<html><head><title>Page Not Found</title></head><body>The requested page or method was not found</body></html>";
|
||||||
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(notFoundString);
|
// byte[] buffer = System.Text.Encoding.UTF8.GetBytes(notFoundString);
|
||||||
response.Body.Write(buffer, 0, buffer.Length);
|
// response.Body.Write(buffer, 0, buffer.Length);
|
||||||
response.Status = HttpStatusCode.NotFound;
|
// response.Status = HttpStatusCode.NotFound;
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
);
|
//);
|
||||||
|
|
||||||
|
m_httpServer = new BaseHttpServer(8003);
|
||||||
HttpServer.Start();
|
HttpServer.Start();
|
||||||
|
|
||||||
Logger.Log.Info("Asset server is listening on port " + port);
|
Logger.Log.Info("Asset server is listening on port " + port);
|
||||||
|
@ -189,14 +204,14 @@ namespace OpenSim.Grid.AssetInventoryServer
|
||||||
|
|
||||||
#region ServiceBase Overrides
|
#region ServiceBase Overrides
|
||||||
|
|
||||||
protected override void OnStart(string[] args)
|
//protected override void OnStart(string[] args)
|
||||||
{
|
//{
|
||||||
Start();
|
// Start();
|
||||||
}
|
//}
|
||||||
protected override void OnStop()
|
//protected override void OnStop()
|
||||||
{
|
//{
|
||||||
Shutdown();
|
// Shutdown();
|
||||||
}
|
//}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -231,36 +246,36 @@ namespace OpenSim.Grid.AssetInventoryServer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class log4netLogWriter : ILogWriter
|
//public class log4netLogWriter : ILogWriter
|
||||||
{
|
//{
|
||||||
ILog Log;
|
// ILog Log;
|
||||||
|
|
||||||
public log4netLogWriter(ILog log)
|
// public log4netLogWriter(ILog log)
|
||||||
{
|
// {
|
||||||
Log = log;
|
// Log = log;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void Write(object source, LogPrio prio, string message)
|
// public void Write(object source, LogPrio prio, string message)
|
||||||
{
|
// {
|
||||||
switch (prio)
|
// switch (prio)
|
||||||
{
|
// {
|
||||||
case LogPrio.Trace:
|
// case LogPrio.Trace:
|
||||||
case LogPrio.Debug:
|
// case LogPrio.Debug:
|
||||||
Log.DebugFormat("{0}: {1}", source, message);
|
// Log.DebugFormat("{0}: {1}", source, message);
|
||||||
break;
|
// break;
|
||||||
case LogPrio.Info:
|
// case LogPrio.Info:
|
||||||
Log.InfoFormat("{0}: {1}", source, message);
|
// Log.InfoFormat("{0}: {1}", source, message);
|
||||||
break;
|
// break;
|
||||||
case LogPrio.Warning:
|
// case LogPrio.Warning:
|
||||||
Log.WarnFormat("{0}: {1}", source, message);
|
// Log.WarnFormat("{0}: {1}", source, message);
|
||||||
break;
|
// break;
|
||||||
case LogPrio.Error:
|
// case LogPrio.Error:
|
||||||
Log.ErrorFormat("{0}: {1}", source, message);
|
// Log.ErrorFormat("{0}: {1}", source, message);
|
||||||
break;
|
// break;
|
||||||
case LogPrio.Fatal:
|
// case LogPrio.Fatal:
|
||||||
Log.FatalFormat("{0}: {1}", source, message);
|
// Log.FatalFormat("{0}: {1}", source, message);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,8 +50,9 @@ namespace OpenSim.Grid.AssetInventoryServer
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
while (true)
|
server.Work();
|
||||||
Console.ReadLine();
|
//while (true)
|
||||||
|
// Console.ReadLine();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
ServiceBase[] servicesToRun = new ServiceBase[] { new AssetInventoryServer() };
|
ServiceBase[] servicesToRun = new ServiceBase[] { new AssetInventoryServer() };
|
||||||
|
|
|
@ -28,20 +28,21 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
using HttpServer;
|
|
||||||
using OpenSim.Framework;
|
using OpenSim.Framework;
|
||||||
|
using OpenSim.Framework.Servers;
|
||||||
|
|
||||||
namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
||||||
{
|
{
|
||||||
public class BrowseFrontendPlugin : IAssetInventoryServerPlugin
|
public class BrowseFrontendPlugin : IAssetInventoryServerPlugin
|
||||||
{
|
{
|
||||||
AssetInventoryServer server;
|
AssetInventoryServer m_server;
|
||||||
|
|
||||||
public BrowseFrontendPlugin()
|
public BrowseFrontendPlugin()
|
||||||
{
|
{
|
||||||
|
@ -51,10 +52,11 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
||||||
|
|
||||||
public void Initialise(AssetInventoryServer server)
|
public void Initialise(AssetInventoryServer server)
|
||||||
{
|
{
|
||||||
this.server = server;
|
m_server = server;
|
||||||
|
|
||||||
// Request for / or /?...
|
// 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.");
|
Logger.Log.Info("[ASSET] Browser Frontend loaded.");
|
||||||
}
|
}
|
||||||
|
@ -85,67 +87,102 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
||||||
|
|
||||||
#endregion IPlugin implementation
|
#endregion IPlugin implementation
|
||||||
|
|
||||||
bool BrowseRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
public class BrowseRequestHandler : IStreamedRequestHandler
|
||||||
{
|
{
|
||||||
const int ASSETS_PER_PAGE = 25;
|
AssetInventoryServer m_server;
|
||||||
const string HEADER = "<html><head><title>Asset Server</title></head><body>";
|
string m_contentType;
|
||||||
const string TABLE_HEADER =
|
string m_httpMethod;
|
||||||
"<table><tr><th>Name</th><th>Description</th><th>Type</th><th>ID</th><th>Temporary</th><th>SHA-1</th></tr>";
|
string m_path;
|
||||||
const string TABLE_FOOTER = "</table>";
|
|
||||||
const string FOOTER = "</body></html>";
|
|
||||||
|
|
||||||
UUID authToken = Utils.GetAuthToken(request);
|
public BrowseRequestHandler(AssetInventoryServer server)
|
||||||
|
|
||||||
StringBuilder html = new StringBuilder();
|
|
||||||
int start = 0;
|
|
||||||
uint page = 0;
|
|
||||||
|
|
||||||
if (!String.IsNullOrEmpty(request.Uri.Query))
|
|
||||||
{
|
{
|
||||||
NameValueCollection query = HttpUtility.ParseQueryString(request.Uri.Query);
|
m_server = server;
|
||||||
if (!String.IsNullOrEmpty(query["page"]) && UInt32.TryParse(query["page"], out page))
|
m_contentType = null;
|
||||||
start = (int)page * ASSETS_PER_PAGE;
|
m_httpMethod = "GET";
|
||||||
|
m_path = @"(^/$)|(^/\?.*)";
|
||||||
}
|
}
|
||||||
|
|
||||||
html.AppendLine(HEADER);
|
#region IStreamedRequestHandler implementation
|
||||||
|
|
||||||
html.AppendLine("<p>");
|
public string ContentType
|
||||||
if (page > 0)
|
{
|
||||||
html.AppendFormat("<a href=\"{0}?page={1}\">< Previous Page</a> | ", request.Uri.AbsolutePath, page - 1);
|
get { return m_contentType; }
|
||||||
html.AppendFormat("<a href=\"{0}?page={1}\">Next Page ></a>", request.Uri.AbsolutePath, page + 1);
|
}
|
||||||
html.AppendLine("</p>");
|
|
||||||
|
|
||||||
html.AppendLine(TABLE_HEADER);
|
public string HttpMethod
|
||||||
|
{
|
||||||
|
get { return m_httpMethod; }
|
||||||
|
}
|
||||||
|
|
||||||
server.StorageProvider.ForEach(
|
public string Path
|
||||||
delegate(Metadata data)
|
{
|
||||||
|
get { return m_path; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
||||||
|
{
|
||||||
|
const int ASSETS_PER_PAGE = 25;
|
||||||
|
const string HEADER = "<html><head><title>Asset Server</title></head><body>";
|
||||||
|
const string TABLE_HEADER =
|
||||||
|
"<table><tr><th>Name</th><th>Description</th><th>Type</th><th>ID</th><th>Temporary</th><th>SHA-1</th></tr>";
|
||||||
|
const string TABLE_FOOTER = "</table>";
|
||||||
|
const string FOOTER = "</body></html>";
|
||||||
|
|
||||||
|
UUID authToken = Utils.GetAuthToken(httpRequest);
|
||||||
|
|
||||||
|
StringBuilder html = new StringBuilder();
|
||||||
|
int start = 0;
|
||||||
|
uint page = 0;
|
||||||
|
|
||||||
|
if (!String.IsNullOrEmpty(httpRequest.Url.Query))
|
||||||
{
|
{
|
||||||
if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.ID))
|
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("<p>");
|
||||||
|
if (page > 0)
|
||||||
|
html.AppendFormat("<a href=\"{0}?page={1}\">< Previous Page</a> | ", httpRequest.RawUrl, page - 1);
|
||||||
|
html.AppendFormat("<a href=\"{0}?page={1}\">Next Page ></a>", httpRequest.RawUrl, page + 1);
|
||||||
|
html.AppendLine("</p>");
|
||||||
|
|
||||||
|
html.AppendLine(TABLE_HEADER);
|
||||||
|
|
||||||
|
m_server.StorageProvider.ForEach(
|
||||||
|
delegate(Metadata data)
|
||||||
{
|
{
|
||||||
html.AppendLine(String.Format(
|
if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.ID))
|
||||||
"<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>",
|
{
|
||||||
data.Name, data.Description, data.ContentType, data.ID, data.Temporary,
|
html.AppendLine(String.Format(
|
||||||
BitConverter.ToString(data.SHA1).Replace("-", String.Empty)));
|
"<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>",
|
||||||
}
|
data.Name, data.Description, data.ContentType, data.ID, data.Temporary,
|
||||||
else
|
BitConverter.ToString(data.SHA1).Replace("-", String.Empty)));
|
||||||
{
|
}
|
||||||
html.AppendLine(String.Format(
|
else
|
||||||
"<tr><td>[Protected Asset]</td><td> </td><td> </td><td>{0}</td><td>{1}</td><td> </td></tr>",
|
{
|
||||||
data.ID, data.Temporary));
|
html.AppendLine(String.Format(
|
||||||
}
|
"<tr><td>[Protected Asset]</td><td> </td><td> </td><td>{0}</td><td>{1}</td><td> </td></tr>",
|
||||||
}, start, ASSETS_PER_PAGE
|
data.ID, data.Temporary));
|
||||||
);
|
}
|
||||||
|
}, start, ASSETS_PER_PAGE
|
||||||
|
);
|
||||||
|
|
||||||
html.AppendLine(TABLE_FOOTER);
|
html.AppendLine(TABLE_FOOTER);
|
||||||
|
|
||||||
html.AppendLine(FOOTER);
|
html.AppendLine(FOOTER);
|
||||||
|
|
||||||
byte[] responseData = System.Text.Encoding.UTF8.GetBytes(html.ToString());
|
byte[] responseData = System.Text.Encoding.UTF8.GetBytes(html.ToString());
|
||||||
|
|
||||||
response.Status = HttpStatusCode.OK;
|
httpResponse.StatusCode = (int) HttpStatusCode.OK;
|
||||||
response.Body.Write(responseData, 0, responseData.Length);
|
httpResponse.Body.Write(responseData, 0, responseData.Length);
|
||||||
response.Body.Flush();
|
httpResponse.Body.Flush();
|
||||||
return true;
|
return responseData;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion IStreamedRequestHandler implementation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ using System.Xml.Serialization;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
using HttpServer;
|
using HttpServer;
|
||||||
using OpenSim.Framework;
|
using OpenSim.Framework;
|
||||||
|
using OpenSim.Framework.Servers;
|
||||||
|
|
||||||
namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
||||||
{
|
{
|
||||||
|
@ -55,10 +56,10 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
|
||||||
// Asset request
|
// Asset request
|
||||||
server.HttpServer.AddHandler("get", null, @"^/assets/", AssetRequestHandler);
|
server.HttpServer.AddStreamHandler(new AssetRequestHandler(server));
|
||||||
|
|
||||||
// Asset creation
|
// Asset creation
|
||||||
server.HttpServer.AddHandler("post", null, @"^/assets/", AssetPostHandler);
|
server.HttpServer.AddStreamHandler(new AssetPostHandler(server));
|
||||||
|
|
||||||
Logger.Log.Info("[ASSET] OpenSim Asset Frontend loaded.");
|
Logger.Log.Info("[ASSET] OpenSim Asset Frontend loaded.");
|
||||||
}
|
}
|
||||||
|
@ -89,100 +90,172 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
||||||
|
|
||||||
#endregion IPlugin implementation
|
#endregion IPlugin implementation
|
||||||
|
|
||||||
bool AssetRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
public class AssetRequestHandler : IStreamedRequestHandler
|
||||||
{
|
{
|
||||||
UUID assetID;
|
AssetInventoryServer m_server;
|
||||||
// Split the URL up to get the asset ID out
|
string m_contentType;
|
||||||
string[] rawUrl = request.Uri.PathAndQuery.Split('/');
|
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;
|
m_server = server;
|
||||||
byte[] assetData;
|
m_contentType = null;
|
||||||
BackendResponse dataResponse;
|
m_httpMethod = "GET";
|
||||||
|
m_path = @"^/assets/";
|
||||||
|
}
|
||||||
|
|
||||||
if ((dataResponse = server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success)
|
#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 (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out assetID))
|
||||||
{
|
{
|
||||||
AssetBase asset = new AssetBase();
|
Metadata metadata;
|
||||||
asset.Data = assetData;
|
byte[] assetData;
|
||||||
asset.Metadata.FullID = metadata.ID;
|
BackendResponse dataResponse;
|
||||||
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));
|
if ((dataResponse = m_server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success)
|
||||||
MemoryStream ms = new MemoryStream();
|
{
|
||||||
XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
|
AssetBase asset = new AssetBase();
|
||||||
xs.Serialize(xw, asset);
|
asset.Data = assetData;
|
||||||
xw.Flush();
|
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;
|
||||||
|
|
||||||
ms.Seek(0, SeekOrigin.Begin);
|
XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
|
||||||
byte[] buffer = ms.GetBuffer();
|
MemoryStream ms = new MemoryStream();
|
||||||
|
XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
|
||||||
|
xs.Serialize(xw, asset);
|
||||||
|
xw.Flush();
|
||||||
|
|
||||||
response.Status = HttpStatusCode.OK;
|
ms.Seek(0, SeekOrigin.Begin);
|
||||||
response.ContentType = "application/xml";
|
buffer = ms.GetBuffer();
|
||||||
response.ContentLength = ms.Length;
|
|
||||||
response.Body.Write(buffer, 0, (int) ms.Length);
|
httpResponse.StatusCode = (int) HttpStatusCode.OK;
|
||||||
response.Body.Flush();
|
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
|
else
|
||||||
{
|
{
|
||||||
Logger.Log.WarnFormat("Failed to fetch asset data or metadata for {0}: {1}", assetID, dataResponse);
|
Logger.Log.Warn("Unrecognized OpenSim asset request: " + httpRequest.Url.PathAndQuery);
|
||||||
response.Status = HttpStatusCode.NotFound;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
return buffer;
|
||||||
{
|
|
||||||
Logger.Log.Warn("Unrecognized OpenSim asset request: " + request.Uri.PathAndQuery);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
try
|
public AssetPostHandler(AssetInventoryServer server)
|
||||||
{
|
{
|
||||||
AssetBase asset = (AssetBase) new XmlSerializer(typeof (AssetBase)).Deserialize(request.Body);
|
m_server = server;
|
||||||
|
m_contentType = null;
|
||||||
|
m_httpMethod = "POST";
|
||||||
|
m_path = @"^/assets/";
|
||||||
|
}
|
||||||
|
|
||||||
if (asset.Data != null && asset.Data.Length > 0)
|
#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)
|
||||||
|
//bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||||
|
{
|
||||||
|
Metadata metadata = new Metadata();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
metadata.ID = asset.Metadata.FullID;
|
AssetBase asset = (AssetBase) new XmlSerializer(typeof (AssetBase)).Deserialize(httpRequest.InputStream);
|
||||||
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);
|
if (asset.Data != null && asset.Data.Length > 0)
|
||||||
metadata.CreationDate = DateTime.Now;
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
BackendResponse storageResponse = server.StorageProvider.TryCreateAsset(metadata, asset.Data);
|
metadata.SHA1 = OpenMetaverse.Utils.SHA1(asset.Data);
|
||||||
|
metadata.CreationDate = DateTime.Now;
|
||||||
|
|
||||||
if (storageResponse == BackendResponse.Success)
|
BackendResponse storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, asset.Data);
|
||||||
response.Status = HttpStatusCode.Created;
|
|
||||||
else if (storageResponse == BackendResponse.NotFound)
|
if (storageResponse == BackendResponse.Success)
|
||||||
response.Status = HttpStatusCode.NotFound;
|
httpResponse.StatusCode = (int) HttpStatusCode.Created;
|
||||||
|
else if (storageResponse == BackendResponse.NotFound)
|
||||||
|
httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
|
||||||
|
else
|
||||||
|
httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
|
||||||
|
}
|
||||||
else
|
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");
|
Logger.Log.Warn("Failed to parse POST data (expecting AssetBase): " + ex.Message);
|
||||||
response.Status = HttpStatusCode.BadRequest;
|
httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
return null;
|
||||||
{
|
|
||||||
Logger.Log.Warn("Failed to parse POST data (expecting AssetBase): " + ex.Message);
|
|
||||||
response.Status = HttpStatusCode.BadRequest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
#endregion IStreamedRequestHandler implementation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,16 +56,16 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
||||||
{
|
{
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
|
||||||
server.HttpServer.AddHandler("post", null, @"^/GetInventory/", GetInventoryHandler);
|
//server.HttpServer.AddHandler("post", null, @"^/GetInventory/", GetInventoryHandler);
|
||||||
server.HttpServer.AddHandler("post", null, @"^/CreateInventory/", CreateInventoryHandler);
|
//server.HttpServer.AddHandler("post", null, @"^/CreateInventory/", CreateInventoryHandler);
|
||||||
server.HttpServer.AddHandler("post", null, @"^/NewFolder/", NewFolderHandler);
|
//server.HttpServer.AddHandler("post", null, @"^/NewFolder/", NewFolderHandler);
|
||||||
server.HttpServer.AddHandler("post", null, @"^/UpdateFolder/", UpdateFolderHandler);
|
//server.HttpServer.AddHandler("post", null, @"^/UpdateFolder/", UpdateFolderHandler);
|
||||||
server.HttpServer.AddHandler("post", null, @"^/MoveFolder/", MoveFolderHandler);
|
//server.HttpServer.AddHandler("post", null, @"^/MoveFolder/", MoveFolderHandler);
|
||||||
server.HttpServer.AddHandler("post", null, @"^/PurgeFolder/", PurgeFolderHandler);
|
//server.HttpServer.AddHandler("post", null, @"^/PurgeFolder/", PurgeFolderHandler);
|
||||||
server.HttpServer.AddHandler("post", null, @"^/NewItem/", NewItemHandler);
|
//server.HttpServer.AddHandler("post", null, @"^/NewItem/", NewItemHandler);
|
||||||
server.HttpServer.AddHandler("post", null, @"^/DeleteItem/", DeleteItemHandler);
|
//server.HttpServer.AddHandler("post", null, @"^/DeleteItem/", DeleteItemHandler);
|
||||||
server.HttpServer.AddHandler("post", null, @"^/RootFolders/", RootFoldersHandler);
|
//server.HttpServer.AddHandler("post", null, @"^/RootFolders/", RootFoldersHandler);
|
||||||
server.HttpServer.AddHandler("post", null, @"^/ActiveGestures/", ActiveGesturesHandler);
|
//server.HttpServer.AddHandler("post", null, @"^/ActiveGestures/", ActiveGesturesHandler);
|
||||||
|
|
||||||
Logger.Log.Info("[INVENTORY] OpenSim Inventory Frontend loaded.");
|
Logger.Log.Info("[INVENTORY] OpenSim Inventory Frontend loaded.");
|
||||||
}
|
}
|
||||||
|
@ -96,253 +96,253 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
||||||
|
|
||||||
#endregion IPlugin implementation
|
#endregion IPlugin implementation
|
||||||
|
|
||||||
bool GetInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
//bool GetInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||||
{
|
//{
|
||||||
UUID sessionID, agentID;
|
// UUID sessionID, agentID;
|
||||||
UUID ownerID = DeserializeUUID(request.Body, out agentID, out sessionID);
|
// UUID ownerID = DeserializeUUID(request.Body, out agentID, out sessionID);
|
||||||
|
|
||||||
if (ownerID != UUID.Zero)
|
// if (ownerID != UUID.Zero)
|
||||||
{
|
// {
|
||||||
Logger.Log.Warn("GetInventory is not scalable on some inventory backends, avoid calling it wherever possible");
|
// Logger.Log.Warn("GetInventory is not scalable on some inventory backends, avoid calling it wherever possible");
|
||||||
|
|
||||||
Uri owner = Utils.GetOpenSimUri(ownerID);
|
// Uri owner = Utils.GetOpenSimUri(ownerID);
|
||||||
InventoryCollection inventory;
|
// InventoryCollection inventory;
|
||||||
BackendResponse storageResponse = server.InventoryProvider.TryFetchInventory(owner, out inventory);
|
// BackendResponse storageResponse = server.InventoryProvider.TryFetchInventory(owner, out inventory);
|
||||||
|
|
||||||
if (storageResponse == BackendResponse.Success)
|
// if (storageResponse == BackendResponse.Success)
|
||||||
{
|
// {
|
||||||
collectionSerializer.Serialize(response.Body, inventory);
|
// collectionSerializer.Serialize(response.Body, inventory);
|
||||||
response.Body.Flush();
|
// response.Body.Flush();
|
||||||
}
|
// }
|
||||||
else if (storageResponse == BackendResponse.NotFound)
|
// else if (storageResponse == BackendResponse.NotFound)
|
||||||
{
|
// {
|
||||||
// Return an empty inventory set to mimic OpenSim.Grid.InventoryServer.exe
|
// // Return an empty inventory set to mimic OpenSim.Grid.InventoryServer.exe
|
||||||
inventory = new InventoryCollection();
|
// inventory = new InventoryCollection();
|
||||||
inventory.UserID = ownerID;
|
// inventory.UserID = ownerID;
|
||||||
inventory.Folders = new Dictionary<UUID, InventoryFolder>();
|
// inventory.Folders = new Dictionary<UUID, InventoryFolder>();
|
||||||
inventory.Items = new Dictionary<UUID, InventoryItem>();
|
// inventory.Items = new Dictionary<UUID, InventoryItem>();
|
||||||
collectionSerializer.Serialize(response.Body, inventory);
|
// collectionSerializer.Serialize(response.Body, inventory);
|
||||||
response.Body.Flush();
|
// response.Body.Flush();
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
response.Status = HttpStatusCode.InternalServerError;
|
// response.Status = HttpStatusCode.InternalServerError;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
response.Status = HttpStatusCode.BadRequest;
|
// response.Status = HttpStatusCode.BadRequest;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return true;
|
// return true;
|
||||||
}
|
//}
|
||||||
|
|
||||||
bool CreateInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
//bool CreateInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||||
{
|
//{
|
||||||
UUID ownerID = DeserializeUUID(request.Body);
|
// UUID ownerID = DeserializeUUID(request.Body);
|
||||||
|
|
||||||
if (ownerID != UUID.Zero)
|
// if (ownerID != UUID.Zero)
|
||||||
{
|
// {
|
||||||
Uri owner = Utils.GetOpenSimUri(ownerID);
|
// Uri owner = Utils.GetOpenSimUri(ownerID);
|
||||||
Logger.Log.DebugFormat("Created URI {0} for inventory creation", owner);
|
// Logger.Log.DebugFormat("Created URI {0} for inventory creation", owner);
|
||||||
|
|
||||||
InventoryFolder rootFolder = new InventoryFolder("My Inventory", ownerID, UUID.Zero, (short)AssetType.Folder);
|
// InventoryFolder rootFolder = new InventoryFolder("My Inventory", ownerID, UUID.Zero, (short)AssetType.Folder);
|
||||||
BackendResponse storageResponse = server.InventoryProvider.TryCreateInventory(owner, rootFolder);
|
// BackendResponse storageResponse = server.InventoryProvider.TryCreateInventory(owner, rootFolder);
|
||||||
if (storageResponse == BackendResponse.Success)
|
// if (storageResponse == BackendResponse.Success)
|
||||||
{
|
// {
|
||||||
CreateFolder("Animations", ownerID, rootFolder.ID, AssetType.Animation);
|
// CreateFolder("Animations", ownerID, rootFolder.ID, AssetType.Animation);
|
||||||
CreateFolder("Body Parts", ownerID, rootFolder.ID, AssetType.Bodypart);
|
// CreateFolder("Body Parts", ownerID, rootFolder.ID, AssetType.Bodypart);
|
||||||
CreateFolder("Calling Cards", ownerID, rootFolder.ID, AssetType.CallingCard);
|
// CreateFolder("Calling Cards", ownerID, rootFolder.ID, AssetType.CallingCard);
|
||||||
CreateFolder("Clothing", ownerID, rootFolder.ID, AssetType.Clothing);
|
// CreateFolder("Clothing", ownerID, rootFolder.ID, AssetType.Clothing);
|
||||||
CreateFolder("Gestures", ownerID, rootFolder.ID, AssetType.Gesture);
|
// CreateFolder("Gestures", ownerID, rootFolder.ID, AssetType.Gesture);
|
||||||
CreateFolder("Landmarks", ownerID, rootFolder.ID, AssetType.Landmark);
|
// CreateFolder("Landmarks", ownerID, rootFolder.ID, AssetType.Landmark);
|
||||||
CreateFolder("Lost and Found", ownerID, rootFolder.ID, AssetType.LostAndFoundFolder);
|
// CreateFolder("Lost and Found", ownerID, rootFolder.ID, AssetType.LostAndFoundFolder);
|
||||||
CreateFolder("Notecards", ownerID, rootFolder.ID, AssetType.Notecard);
|
// CreateFolder("Notecards", ownerID, rootFolder.ID, AssetType.Notecard);
|
||||||
CreateFolder("Objects", ownerID, rootFolder.ID, AssetType.Object);
|
// CreateFolder("Objects", ownerID, rootFolder.ID, AssetType.Object);
|
||||||
CreateFolder("Photo Album", ownerID, rootFolder.ID, AssetType.SnapshotFolder);
|
// CreateFolder("Photo Album", ownerID, rootFolder.ID, AssetType.SnapshotFolder);
|
||||||
CreateFolder("Scripts", ownerID, rootFolder.ID, AssetType.LSLText);
|
// CreateFolder("Scripts", ownerID, rootFolder.ID, AssetType.LSLText);
|
||||||
CreateFolder("Sounds", ownerID, rootFolder.ID, AssetType.Sound);
|
// CreateFolder("Sounds", ownerID, rootFolder.ID, AssetType.Sound);
|
||||||
CreateFolder("Textures", ownerID, rootFolder.ID, AssetType.Texture);
|
// CreateFolder("Textures", ownerID, rootFolder.ID, AssetType.Texture);
|
||||||
CreateFolder("Trash", ownerID, rootFolder.ID, AssetType.TrashFolder);
|
// CreateFolder("Trash", ownerID, rootFolder.ID, AssetType.TrashFolder);
|
||||||
|
|
||||||
SerializeBool(response.Body, true);
|
// SerializeBool(response.Body, true);
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
SerializeBool(response.Body, false);
|
// SerializeBool(response.Body, false);
|
||||||
return true;
|
// return true;
|
||||||
}
|
//}
|
||||||
|
|
||||||
bool NewFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
//bool NewFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||||
{
|
//{
|
||||||
UUID agentID, sessionID;
|
// UUID agentID, sessionID;
|
||||||
InventoryFolder folder = DeserializeFolder(request.Body, out agentID, out sessionID);
|
// InventoryFolder folder = DeserializeFolder(request.Body, out agentID, out sessionID);
|
||||||
|
|
||||||
if (folder != null)
|
// if (folder != null)
|
||||||
{
|
// {
|
||||||
Uri owner = Utils.GetOpenSimUri(folder.Owner);
|
// Uri owner = Utils.GetOpenSimUri(folder.Owner);
|
||||||
|
|
||||||
// Some calls that are moving or updating a folder instead of creating a new one
|
// // 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
|
// // will pass in an InventoryFolder without the name set. If this is the case we
|
||||||
// need to look up the name first
|
// // need to look up the name first
|
||||||
if (String.IsNullOrEmpty(folder.Name))
|
// if (String.IsNullOrEmpty(folder.Name))
|
||||||
{
|
// {
|
||||||
InventoryFolder oldFolder;
|
// InventoryFolder oldFolder;
|
||||||
if (server.InventoryProvider.TryFetchFolder(owner, folder.ID, out oldFolder) == BackendResponse.Success)
|
// if (server.InventoryProvider.TryFetchFolder(owner, folder.ID, out oldFolder) == BackendResponse.Success)
|
||||||
folder.Name = oldFolder.Name;
|
// folder.Name = oldFolder.Name;
|
||||||
}
|
// }
|
||||||
|
|
||||||
BackendResponse storageResponse = server.InventoryProvider.TryCreateFolder(owner, folder);
|
// BackendResponse storageResponse = server.InventoryProvider.TryCreateFolder(owner, folder);
|
||||||
|
|
||||||
if (storageResponse == BackendResponse.Success)
|
// if (storageResponse == BackendResponse.Success)
|
||||||
{
|
// {
|
||||||
SerializeBool(response.Body, true);
|
// SerializeBool(response.Body, true);
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
SerializeBool(response.Body, false);
|
// SerializeBool(response.Body, false);
|
||||||
return true;
|
// return true;
|
||||||
}
|
//}
|
||||||
|
|
||||||
bool UpdateFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
//bool UpdateFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||||
{
|
//{
|
||||||
return NewFolderHandler(client, request, response);
|
// return NewFolderHandler(client, request, response);
|
||||||
}
|
//}
|
||||||
|
|
||||||
bool MoveFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
//bool MoveFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||||
{
|
//{
|
||||||
return NewFolderHandler(client, request, response);
|
// return NewFolderHandler(client, request, response);
|
||||||
}
|
//}
|
||||||
|
|
||||||
bool PurgeFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
//bool PurgeFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||||
{
|
//{
|
||||||
UUID agentID, sessionID;
|
// UUID agentID, sessionID;
|
||||||
InventoryFolder folder = DeserializeFolder(request.Body, out agentID, out sessionID);
|
// InventoryFolder folder = DeserializeFolder(request.Body, out agentID, out sessionID);
|
||||||
|
|
||||||
if (folder != null)
|
// if (folder != null)
|
||||||
{
|
// {
|
||||||
Uri owner = Utils.GetOpenSimUri(folder.Owner);
|
// Uri owner = Utils.GetOpenSimUri(folder.Owner);
|
||||||
BackendResponse storageResponse = server.InventoryProvider.TryPurgeFolder(owner, folder.ID);
|
// BackendResponse storageResponse = server.InventoryProvider.TryPurgeFolder(owner, folder.ID);
|
||||||
|
|
||||||
if (storageResponse == BackendResponse.Success)
|
// if (storageResponse == BackendResponse.Success)
|
||||||
{
|
// {
|
||||||
SerializeBool(response.Body, true);
|
// SerializeBool(response.Body, true);
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
SerializeBool(response.Body, false);
|
// SerializeBool(response.Body, false);
|
||||||
return true;
|
// return true;
|
||||||
}
|
//}
|
||||||
|
|
||||||
bool NewItemHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
//bool NewItemHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||||
{
|
//{
|
||||||
UUID agentID, sessionID;
|
// UUID agentID, sessionID;
|
||||||
InventoryItem item = DeserializeItem(request.Body, out agentID, out sessionID);
|
// InventoryItem item = DeserializeItem(request.Body, out agentID, out sessionID);
|
||||||
|
|
||||||
if (item != null)
|
// if (item != null)
|
||||||
{
|
// {
|
||||||
Uri owner = Utils.GetOpenSimUri(agentID);
|
// Uri owner = Utils.GetOpenSimUri(agentID);
|
||||||
BackendResponse storageResponse = server.InventoryProvider.TryCreateItem(owner, item);
|
// BackendResponse storageResponse = server.InventoryProvider.TryCreateItem(owner, item);
|
||||||
|
|
||||||
if (storageResponse == BackendResponse.Success)
|
// if (storageResponse == BackendResponse.Success)
|
||||||
{
|
// {
|
||||||
SerializeBool(response.Body, true);
|
// SerializeBool(response.Body, true);
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
SerializeBool(response.Body, false);
|
// SerializeBool(response.Body, false);
|
||||||
return true;
|
// return true;
|
||||||
}
|
//}
|
||||||
|
|
||||||
bool DeleteItemHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
//bool DeleteItemHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||||
{
|
//{
|
||||||
UUID agentID, sessionID;
|
// UUID agentID, sessionID;
|
||||||
InventoryItem item = DeserializeItem(request.Body, out agentID, out sessionID);
|
// InventoryItem item = DeserializeItem(request.Body, out agentID, out sessionID);
|
||||||
|
|
||||||
if (item != null)
|
// if (item != null)
|
||||||
{
|
// {
|
||||||
Uri owner = Utils.GetOpenSimUri(item.Owner);
|
// Uri owner = Utils.GetOpenSimUri(item.Owner);
|
||||||
BackendResponse storageResponse = server.InventoryProvider.TryDeleteItem(owner, item.ID);
|
// BackendResponse storageResponse = server.InventoryProvider.TryDeleteItem(owner, item.ID);
|
||||||
|
|
||||||
if (storageResponse == BackendResponse.Success)
|
// if (storageResponse == BackendResponse.Success)
|
||||||
{
|
// {
|
||||||
SerializeBool(response.Body, true);
|
// SerializeBool(response.Body, true);
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
SerializeBool(response.Body, false);
|
// SerializeBool(response.Body, false);
|
||||||
return true;
|
// return true;
|
||||||
}
|
//}
|
||||||
|
|
||||||
bool RootFoldersHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
//bool RootFoldersHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||||
{
|
//{
|
||||||
UUID ownerID = DeserializeUUID(request.Body);
|
// UUID ownerID = DeserializeUUID(request.Body);
|
||||||
|
|
||||||
if (ownerID != UUID.Zero)
|
// if (ownerID != UUID.Zero)
|
||||||
{
|
// {
|
||||||
Uri owner = Utils.GetOpenSimUri(ownerID);
|
// Uri owner = Utils.GetOpenSimUri(ownerID);
|
||||||
List<InventoryFolder> skeleton;
|
// List<InventoryFolder> skeleton;
|
||||||
BackendResponse storageResponse = server.InventoryProvider.TryFetchFolderList(owner, out skeleton);
|
// BackendResponse storageResponse = server.InventoryProvider.TryFetchFolderList(owner, out skeleton);
|
||||||
|
|
||||||
if (storageResponse == BackendResponse.Success)
|
// if (storageResponse == BackendResponse.Success)
|
||||||
{
|
// {
|
||||||
SerializeFolderList(response.Body, skeleton);
|
// SerializeFolderList(response.Body, skeleton);
|
||||||
}
|
// }
|
||||||
else if (storageResponse == BackendResponse.NotFound)
|
// else if (storageResponse == BackendResponse.NotFound)
|
||||||
{
|
// {
|
||||||
// Return an empty set of inventory so the requester knows that
|
// // Return an empty set of inventory so the requester knows that
|
||||||
// an inventory needs to be created for this agent
|
// // an inventory needs to be created for this agent
|
||||||
SerializeFolderList(response.Body, new List<InventoryFolder>(0));
|
// SerializeFolderList(response.Body, new List<InventoryFolder>(0));
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
response.Status = HttpStatusCode.InternalServerError;
|
// response.Status = HttpStatusCode.InternalServerError;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
response.Status = HttpStatusCode.BadRequest;
|
// response.Status = HttpStatusCode.BadRequest;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return true;
|
// return true;
|
||||||
}
|
//}
|
||||||
|
|
||||||
bool ActiveGesturesHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
//bool ActiveGesturesHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||||
{
|
//{
|
||||||
UUID ownerID = DeserializeUUID(request.Body);
|
// UUID ownerID = DeserializeUUID(request.Body);
|
||||||
|
|
||||||
if (ownerID != UUID.Zero)
|
// if (ownerID != UUID.Zero)
|
||||||
{
|
// {
|
||||||
Uri owner = Utils.GetOpenSimUri(ownerID);
|
// Uri owner = Utils.GetOpenSimUri(ownerID);
|
||||||
List<InventoryItem> gestures;
|
// List<InventoryItem> gestures;
|
||||||
BackendResponse storageResponse = server.InventoryProvider.TryFetchActiveGestures(owner, out gestures);
|
// BackendResponse storageResponse = server.InventoryProvider.TryFetchActiveGestures(owner, out gestures);
|
||||||
|
|
||||||
if (storageResponse == BackendResponse.Success)
|
// if (storageResponse == BackendResponse.Success)
|
||||||
{
|
// {
|
||||||
SerializeItemList(response.Body, gestures);
|
// SerializeItemList(response.Body, gestures);
|
||||||
}
|
// }
|
||||||
else if (storageResponse == BackendResponse.NotFound)
|
// else if (storageResponse == BackendResponse.NotFound)
|
||||||
{
|
// {
|
||||||
// Return an empty set of gestures to match OpenSim.Grid.InventoryServer.exe behavior
|
// // Return an empty set of gestures to match OpenSim.Grid.InventoryServer.exe behavior
|
||||||
SerializeItemList(response.Body, new List<InventoryItem>(0));
|
// SerializeItemList(response.Body, new List<InventoryItem>(0));
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
response.Status = HttpStatusCode.InternalServerError;
|
// response.Status = HttpStatusCode.InternalServerError;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
response.Status = HttpStatusCode.BadRequest;
|
// response.Status = HttpStatusCode.BadRequest;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return true;
|
// return true;
|
||||||
}
|
//}
|
||||||
|
|
||||||
BackendResponse CreateFolder(string name, UUID ownerID, UUID parentID, AssetType assetType)
|
BackendResponse CreateFolder(string name, UUID ownerID, UUID parentID, AssetType assetType)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
@ -35,12 +36,13 @@ using OpenMetaverse;
|
||||||
using OpenMetaverse.StructuredData;
|
using OpenMetaverse.StructuredData;
|
||||||
using HttpServer;
|
using HttpServer;
|
||||||
using OpenSim.Framework;
|
using OpenSim.Framework;
|
||||||
|
using OpenSim.Framework.Servers;
|
||||||
|
|
||||||
namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
||||||
{
|
{
|
||||||
public class ReferenceFrontendPlugin : IAssetInventoryServerPlugin
|
public class ReferenceFrontendPlugin : IAssetInventoryServerPlugin
|
||||||
{
|
{
|
||||||
AssetInventoryServer server;
|
AssetInventoryServer m_server;
|
||||||
|
|
||||||
public ReferenceFrontendPlugin()
|
public ReferenceFrontendPlugin()
|
||||||
{
|
{
|
||||||
|
@ -50,18 +52,16 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
||||||
|
|
||||||
public void Initialise(AssetInventoryServer server)
|
public void Initialise(AssetInventoryServer server)
|
||||||
{
|
{
|
||||||
this.server = server;
|
m_server = server;
|
||||||
|
|
||||||
// Asset metadata request
|
// 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",
|
m_server.HttpServer.AddStreamHandler(new MetadataRequestHandler(server));
|
||||||
MetadataRequestHandler);
|
|
||||||
|
|
||||||
// Asset data request
|
// 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",
|
m_server.HttpServer.AddStreamHandler(new DataRequestHandler(server));
|
||||||
DataRequestHandler);
|
|
||||||
|
|
||||||
// Asset creation
|
// Asset creation
|
||||||
server.HttpServer.AddHandler("post", null, "^/createasset", CreateRequestHandler);
|
m_server.HttpServer.AddStreamHandler(new CreateRequestHandler(server));
|
||||||
|
|
||||||
Logger.Log.Info("[ASSET] Reference Frontend loaded.");
|
Logger.Log.Info("[ASSET] Reference Frontend loaded.");
|
||||||
}
|
}
|
||||||
|
@ -92,174 +92,279 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
||||||
|
|
||||||
#endregion IPlugin implementation
|
#endregion IPlugin implementation
|
||||||
|
|
||||||
bool MetadataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
public class MetadataRequestHandler : IStreamedRequestHandler
|
||||||
{
|
{
|
||||||
UUID assetID;
|
AssetInventoryServer m_server;
|
||||||
// Split the URL up into an AssetID and a method
|
string m_contentType;
|
||||||
string[] rawUrl = request.Uri.PathAndQuery.Split('/');
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID))
|
#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))
|
||||||
{
|
{
|
||||||
Metadata metadata;
|
UUID authToken = Utils.GetAuthToken(httpRequest);
|
||||||
BackendResponse storageResponse = server.StorageProvider.TryFetchMetadata(assetID, out metadata);
|
|
||||||
|
|
||||||
if (storageResponse == BackendResponse.Success)
|
if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID))
|
||||||
{
|
{
|
||||||
// If the asset data location wasn't specified in the metadata, specify it
|
Metadata metadata;
|
||||||
// manually here by pointing back to this asset server
|
BackendResponse storageResponse = m_server.StorageProvider.TryFetchMetadata(assetID, out metadata);
|
||||||
if (!metadata.Methods.ContainsKey("data"))
|
|
||||||
|
if (storageResponse == BackendResponse.Success)
|
||||||
{
|
{
|
||||||
metadata.Methods["data"] = new Uri(String.Format("{0}://{1}/{2}/data",
|
// If the asset data location wasn't specified in the metadata, specify it
|
||||||
request.Uri.Scheme, request.Uri.Authority, assetID));
|
// 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)
|
||||||
byte[] serializedData = metadata.SerializeToBytes();
|
|
||||||
|
|
||||||
response.Status = HttpStatusCode.OK;
|
|
||||||
response.ContentType = "application/json";
|
|
||||||
response.ContentLength = serializedData.Length;
|
|
||||||
response.Body.Write(serializedData, 0, serializedData.Length);
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (storageResponse == BackendResponse.NotFound)
|
|
||||||
{
|
|
||||||
Logger.Log.Warn("Could not find metadata for asset " + assetID.ToString());
|
|
||||||
response.Status = HttpStatusCode.NotFound;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
response.Status = HttpStatusCode.InternalServerError;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
response.Status = HttpStatusCode.Forbidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Status = HttpStatusCode.NotFound;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
|
||||||
{
|
|
||||||
UUID assetID;
|
|
||||||
// Split the URL up into an AssetID and a method
|
|
||||||
string[] rawUrl = request.Uri.PathAndQuery.Split('/');
|
|
||||||
|
|
||||||
if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
|
|
||||||
{
|
|
||||||
UUID authToken = Utils.GetAuthToken(request);
|
|
||||||
|
|
||||||
if (server.AuthorizationProvider.IsDataAuthorized(authToken, assetID))
|
|
||||||
{
|
|
||||||
byte[] assetData;
|
|
||||||
BackendResponse storageResponse = server.StorageProvider.TryFetchData(assetID, out assetData);
|
|
||||||
|
|
||||||
if (storageResponse == BackendResponse.Success)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
response.Status = HttpStatusCode.InternalServerError;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
response.Status = HttpStatusCode.Forbidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Status = HttpStatusCode.BadRequest;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CreateRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
|
||||||
{
|
|
||||||
UUID authToken = Utils.GetAuthToken(request);
|
|
||||||
|
|
||||||
if (server.AuthorizationProvider.IsCreateAuthorized(authToken))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
OSD osdata = OSDParser.DeserializeJson(request.Body);
|
|
||||||
|
|
||||||
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;
|
Logger.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;
|
||||||
|
}
|
||||||
|
|
||||||
if (metadata.ID != UUID.Zero)
|
return serializedData;
|
||||||
storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData);
|
}
|
||||||
else
|
|
||||||
storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID);
|
|
||||||
|
|
||||||
if (storageResponse == BackendResponse.Success)
|
httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
|
||||||
|
return serializedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion IStreamedRequestHandler implementation
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DataRequestHandler : IStreamedRequestHandler
|
||||||
|
{
|
||||||
|
AssetInventoryServer m_server;
|
||||||
|
string m_contentType;
|
||||||
|
string m_httpMethod;
|
||||||
|
string m_path;
|
||||||
|
|
||||||
|
public DataRequestHandler(AssetInventoryServer server)
|
||||||
|
{
|
||||||
|
m_server = server;
|
||||||
|
m_contentType = null;
|
||||||
|
m_httpMethod = "GET";
|
||||||
|
m_path = @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/data";
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IStreamedRequestHandler implementation
|
||||||
|
|
||||||
|
public string ContentType
|
||||||
|
{
|
||||||
|
get { return m_contentType; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string HttpMethod
|
||||||
|
{
|
||||||
|
get { return m_httpMethod; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Path
|
||||||
|
{
|
||||||
|
get { return m_path; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
||||||
|
{
|
||||||
|
byte[] assetData = null;
|
||||||
|
UUID assetID;
|
||||||
|
// Split the URL up into an AssetID and a method
|
||||||
|
string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
|
||||||
|
|
||||||
|
if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
|
||||||
|
{
|
||||||
|
UUID authToken = Utils.GetAuthToken(httpRequest);
|
||||||
|
|
||||||
|
if (m_server.AuthorizationProvider.IsDataAuthorized(authToken, assetID))
|
||||||
|
{
|
||||||
|
BackendResponse storageResponse = m_server.StorageProvider.TryFetchData(assetID, out assetData);
|
||||||
|
|
||||||
|
if (storageResponse == BackendResponse.Success)
|
||||||
|
{
|
||||||
|
httpResponse.StatusCode = (int) HttpStatusCode.OK;
|
||||||
|
httpResponse.ContentType = "application/octet-stream";
|
||||||
|
httpResponse.AddHeader("Content-Disposition", "attachment; filename=" + assetID.ToString());
|
||||||
|
httpResponse.ContentLength = assetData.Length;
|
||||||
|
httpResponse.Body.Write(assetData, 0, assetData.Length);
|
||||||
|
}
|
||||||
|
else if (storageResponse == BackendResponse.NotFound)
|
||||||
|
{
|
||||||
|
httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
return assetData;
|
||||||
|
}
|
||||||
|
|
||||||
|
httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
|
||||||
|
return assetData;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion IStreamedRequestHandler implementation
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CreateRequestHandler : IStreamedRequestHandler
|
||||||
|
{
|
||||||
|
AssetInventoryServer m_server;
|
||||||
|
string m_contentType;
|
||||||
|
string m_httpMethod;
|
||||||
|
string m_path;
|
||||||
|
|
||||||
|
public CreateRequestHandler(AssetInventoryServer server)
|
||||||
|
{
|
||||||
|
m_server = server;
|
||||||
|
m_contentType = null;
|
||||||
|
m_httpMethod = "POST";
|
||||||
|
m_path = "^/createasset";
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IStreamedRequestHandler implementation
|
||||||
|
|
||||||
|
public string ContentType
|
||||||
|
{
|
||||||
|
get { return m_contentType; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string HttpMethod
|
||||||
|
{
|
||||||
|
get { return m_httpMethod; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Path
|
||||||
|
{
|
||||||
|
get { return m_path; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
||||||
|
{
|
||||||
|
byte[] responseData = null;
|
||||||
|
UUID authToken = Utils.GetAuthToken(httpRequest);
|
||||||
|
|
||||||
|
if (m_server.AuthorizationProvider.IsCreateAuthorized(authToken))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
OSD osdata = OSDParser.DeserializeJson(httpRequest.InputStream);
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
response.Status = HttpStatusCode.Created;
|
BackendResponse storageResponse;
|
||||||
OSDMap responseMap = new OSDMap(1);
|
|
||||||
responseMap["id"] = OSD.FromUUID(metadata.ID);
|
if (metadata.ID != UUID.Zero)
|
||||||
LitJson.JsonData jsonData = OSDParser.SerializeJson(responseMap);
|
storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData);
|
||||||
byte[] responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson());
|
else
|
||||||
response.Body.Write(responseData, 0, responseData.Length);
|
storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID);
|
||||||
response.Body.Flush();
|
|
||||||
}
|
if (storageResponse == BackendResponse.Success)
|
||||||
else if (storageResponse == BackendResponse.NotFound)
|
{
|
||||||
{
|
httpResponse.StatusCode = (int) HttpStatusCode.Created;
|
||||||
response.Status = HttpStatusCode.NotFound;
|
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
|
else
|
||||||
{
|
{
|
||||||
response.Status = HttpStatusCode.InternalServerError;
|
httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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;
|
httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
|
||||||
response.Reason = ex.Message;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
return responseData;
|
||||||
{
|
|
||||||
response.Status = HttpStatusCode.Forbidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
#endregion IStreamedRequestHandler implementation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,12 +36,13 @@ using System.Xml.Serialization;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
using OpenMetaverse.StructuredData;
|
using OpenMetaverse.StructuredData;
|
||||||
using HttpServer;
|
using HttpServer;
|
||||||
|
using OpenSim.Framework.Servers;
|
||||||
|
|
||||||
namespace OpenSim.Grid.AssetInventoryServer
|
namespace OpenSim.Grid.AssetInventoryServer
|
||||||
{
|
{
|
||||||
public static class Utils
|
public static class Utils
|
||||||
{
|
{
|
||||||
public static UUID GetAuthToken(IHttpRequest request)
|
public static UUID GetAuthToken(OSHttpRequest request)
|
||||||
{
|
{
|
||||||
UUID authToken = UUID.Zero;
|
UUID authToken = UUID.Zero;
|
||||||
|
|
||||||
|
@ -55,13 +56,13 @@ namespace OpenSim.Grid.AssetInventoryServer
|
||||||
UUID.TryParse(authHeaderParts[1], out authToken);
|
UUID.TryParse(authHeaderParts[1], out authToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authToken == UUID.Zero && request.Cookies != null)
|
//if (authToken == UUID.Zero && request.Cookies != null)
|
||||||
{
|
//{
|
||||||
// Check for an authToken cookie to make logins browser-compatible
|
// // Check for an authToken cookie to make logins browser-compatible
|
||||||
RequestCookie authCookie = request.Cookies["authToken"];
|
// RequestCookie authCookie = request.Cookies["authToken"];
|
||||||
if (authCookie != null)
|
// if (authCookie != null)
|
||||||
UUID.TryParse(authCookie.Value, out authToken);
|
// UUID.TryParse(authCookie.Value, out authToken);
|
||||||
}
|
//}
|
||||||
|
|
||||||
return authToken;
|
return authToken;
|
||||||
}
|
}
|
||||||
|
|
|
@ -764,10 +764,11 @@
|
||||||
<Reference name="System.Web"/>
|
<Reference name="System.Web"/>
|
||||||
<Reference name="System.Xml"/>
|
<Reference name="System.Xml"/>
|
||||||
<Reference name="OpenSim.Framework"/>
|
<Reference name="OpenSim.Framework"/>
|
||||||
|
<Reference name="OpenSim.Framework.Console"/>
|
||||||
|
<Reference name="OpenSim.Framework.Servers"/>
|
||||||
<Reference name="log4net2"/>
|
<Reference name="log4net2"/>
|
||||||
<Reference name="OpenMetaverseTypes"/>
|
<Reference name="OpenMetaverseTypes"/>
|
||||||
<Reference name="OpenMetaverse.StructuredData2"/>
|
<Reference name="OpenMetaverse.StructuredData2"/>
|
||||||
<Reference name="OpenMetaverse.Http"/>
|
|
||||||
<Reference name="ExtensionLoader"/>
|
<Reference name="ExtensionLoader"/>
|
||||||
<Reference name="HttpServer2"/>
|
<Reference name="HttpServer2"/>
|
||||||
|
|
||||||
|
@ -800,6 +801,7 @@
|
||||||
<Reference name="System.Web"/>
|
<Reference name="System.Web"/>
|
||||||
<Reference name="OpenSim.Grid.AssetInventoryServer" />
|
<Reference name="OpenSim.Grid.AssetInventoryServer" />
|
||||||
<Reference name="OpenSim.Framework"/>
|
<Reference name="OpenSim.Framework"/>
|
||||||
|
<Reference name="OpenSim.Framework.Servers"/>
|
||||||
<Reference name="OpenMetaverse"/>
|
<Reference name="OpenMetaverse"/>
|
||||||
<Reference name="OpenMetaverseTypes"/>
|
<Reference name="OpenMetaverseTypes"/>
|
||||||
<Reference name="OpenMetaverse.StructuredData2"/>
|
<Reference name="OpenMetaverse.StructuredData2"/>
|
||||||
|
@ -859,6 +861,7 @@
|
||||||
<Reference name="System" />
|
<Reference name="System" />
|
||||||
<Reference name="System.Data" />
|
<Reference name="System.Data" />
|
||||||
<Reference name="OpenSim.Framework" />
|
<Reference name="OpenSim.Framework" />
|
||||||
|
<Reference name="OpenSim.Framework.Servers"/>
|
||||||
<Reference name="OpenSim.Data" />
|
<Reference name="OpenSim.Data" />
|
||||||
<Reference name="OpenSim.Grid.AssetInventoryServer" />
|
<Reference name="OpenSim.Grid.AssetInventoryServer" />
|
||||||
<Reference name="OpenMetaverseTypes"/>
|
<Reference name="OpenMetaverseTypes"/>
|
||||||
|
|
Loading…
Reference in New Issue