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 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);
|
||||
//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.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);
|
||||
//HttpServer.Set404Handler(
|
||||
// delegate(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
// {
|
||||
// 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>";
|
||||
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(notFoundString);
|
||||
response.Body.Write(buffer, 0, buffer.Length);
|
||||
response.Status = HttpStatusCode.NotFound;
|
||||
return true;
|
||||
}
|
||||
);
|
||||
// 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);
|
||||
// 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 class log4netLogWriter : ILogWriter
|
||||
//{
|
||||
// ILog Log;
|
||||
|
||||
public log4netLogWriter(ILog log)
|
||||
{
|
||||
Log = 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 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;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
|
|
@ -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() };
|
||||
|
|
|
@ -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,7 +87,39 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
|||
|
||||
#endregion IPlugin implementation
|
||||
|
||||
bool BrowseRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
public class BrowseRequestHandler : IStreamedRequestHandler
|
||||
{
|
||||
AssetInventoryServer m_server;
|
||||
string m_contentType;
|
||||
string m_httpMethod;
|
||||
string m_path;
|
||||
|
||||
public BrowseRequestHandler(AssetInventoryServer server)
|
||||
{
|
||||
m_server = server;
|
||||
m_contentType = null;
|
||||
m_httpMethod = "GET";
|
||||
m_path = @"(^/$)|(^/\?.*)";
|
||||
}
|
||||
|
||||
#region IStreamedRequestHandler implementation
|
||||
|
||||
public string ContentType
|
||||
{
|
||||
get { return m_contentType; }
|
||||
}
|
||||
|
||||
public string HttpMethod
|
||||
{
|
||||
get { return m_httpMethod; }
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get { return m_path; }
|
||||
}
|
||||
|
||||
public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
||||
{
|
||||
const int ASSETS_PER_PAGE = 25;
|
||||
const string HEADER = "<html><head><title>Asset Server</title></head><body>";
|
||||
|
@ -94,15 +128,15 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
|||
const string TABLE_FOOTER = "</table>";
|
||||
const string FOOTER = "</body></html>";
|
||||
|
||||
UUID authToken = Utils.GetAuthToken(request);
|
||||
UUID authToken = Utils.GetAuthToken(httpRequest);
|
||||
|
||||
StringBuilder html = new StringBuilder();
|
||||
int start = 0;
|
||||
uint page = 0;
|
||||
|
||||
if (!String.IsNullOrEmpty(request.Uri.Query))
|
||||
if (!String.IsNullOrEmpty(httpRequest.Url.Query))
|
||||
{
|
||||
NameValueCollection query = HttpUtility.ParseQueryString(request.Uri.Query);
|
||||
NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query);
|
||||
if (!String.IsNullOrEmpty(query["page"]) && UInt32.TryParse(query["page"], out page))
|
||||
start = (int)page * ASSETS_PER_PAGE;
|
||||
}
|
||||
|
@ -111,16 +145,16 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
|||
|
||||
html.AppendLine("<p>");
|
||||
if (page > 0)
|
||||
html.AppendFormat("<a href=\"{0}?page={1}\">< Previous Page</a> | ", request.Uri.AbsolutePath, page - 1);
|
||||
html.AppendFormat("<a href=\"{0}?page={1}\">Next Page ></a>", request.Uri.AbsolutePath, page + 1);
|
||||
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);
|
||||
|
||||
server.StorageProvider.ForEach(
|
||||
m_server.StorageProvider.ForEach(
|
||||
delegate(Metadata data)
|
||||
{
|
||||
if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.ID))
|
||||
if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.ID))
|
||||
{
|
||||
html.AppendLine(String.Format(
|
||||
"<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>",
|
||||
|
@ -142,10 +176,13 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
|||
|
||||
byte[] responseData = System.Text.Encoding.UTF8.GetBytes(html.ToString());
|
||||
|
||||
response.Status = HttpStatusCode.OK;
|
||||
response.Body.Write(responseData, 0, responseData.Length);
|
||||
response.Body.Flush();
|
||||
return true;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.OK;
|
||||
httpResponse.Body.Write(responseData, 0, responseData.Length);
|
||||
httpResponse.Body.Flush();
|
||||
return responseData;
|
||||
}
|
||||
|
||||
#endregion IStreamedRequestHandler implementation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,11 +90,44 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
|||
|
||||
#endregion IPlugin implementation
|
||||
|
||||
bool AssetRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
public class AssetRequestHandler : IStreamedRequestHandler
|
||||
{
|
||||
AssetInventoryServer m_server;
|
||||
string m_contentType;
|
||||
string m_httpMethod;
|
||||
string m_path;
|
||||
|
||||
public AssetRequestHandler(AssetInventoryServer server)
|
||||
{
|
||||
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 = request.Uri.PathAndQuery.Split('/');
|
||||
string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
|
||||
|
||||
if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out assetID))
|
||||
{
|
||||
|
@ -101,7 +135,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
|||
byte[] assetData;
|
||||
BackendResponse dataResponse;
|
||||
|
||||
if ((dataResponse = server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success)
|
||||
if ((dataResponse = m_server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success)
|
||||
{
|
||||
AssetBase asset = new AssetBase();
|
||||
asset.Data = assetData;
|
||||
|
@ -120,35 +154,71 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
|||
xw.Flush();
|
||||
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
byte[] buffer = ms.GetBuffer();
|
||||
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();
|
||||
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);
|
||||
response.Status = HttpStatusCode.NotFound;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Log.Warn("Unrecognized OpenSim asset request: " + request.Uri.PathAndQuery);
|
||||
Logger.Log.Warn("Unrecognized OpenSim asset request: " + httpRequest.Url.PathAndQuery);
|
||||
}
|
||||
|
||||
return true;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
#endregion IStreamedRequestHandler implementation
|
||||
}
|
||||
|
||||
public class AssetPostHandler : IStreamedRequestHandler
|
||||
{
|
||||
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
|
||||
|
||||
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
|
||||
{
|
||||
AssetBase asset = (AssetBase) new XmlSerializer(typeof (AssetBase)).Deserialize(request.Body);
|
||||
AssetBase asset = (AssetBase) new XmlSerializer(typeof (AssetBase)).Deserialize(httpRequest.InputStream);
|
||||
|
||||
if (asset.Data != null && asset.Data.Length > 0)
|
||||
{
|
||||
|
@ -161,28 +231,31 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
|||
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;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.Created;
|
||||
else if (storageResponse == BackendResponse.NotFound)
|
||||
response.Status = HttpStatusCode.NotFound;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
|
||||
else
|
||||
response.Status = HttpStatusCode.InternalServerError;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Log.Warn("AssetPostHandler called with no asset data");
|
||||
response.Status = HttpStatusCode.BadRequest;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log.Warn("Failed to parse POST data (expecting AssetBase): " + ex.Message);
|
||||
response.Status = HttpStatusCode.BadRequest;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
|
||||
}
|
||||
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion IStreamedRequestHandler implementation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
//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");
|
||||
// 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);
|
||||
// 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<UUID, InventoryFolder>();
|
||||
inventory.Items = new Dictionary<UUID, InventoryItem>();
|
||||
collectionSerializer.Serialize(response.Body, inventory);
|
||||
response.Body.Flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Status = HttpStatusCode.InternalServerError;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Status = HttpStatusCode.BadRequest;
|
||||
}
|
||||
// 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<UUID, InventoryFolder>();
|
||||
// inventory.Items = new Dictionary<UUID, InventoryItem>();
|
||||
// collectionSerializer.Serialize(response.Body, inventory);
|
||||
// response.Body.Flush();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// response.Status = HttpStatusCode.InternalServerError;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// response.Status = HttpStatusCode.BadRequest;
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
// return true;
|
||||
//}
|
||||
|
||||
bool CreateInventoryHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
{
|
||||
UUID ownerID = DeserializeUUID(request.Body);
|
||||
//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);
|
||||
// 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);
|
||||
// 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, true);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
SerializeBool(response.Body, false);
|
||||
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);
|
||||
//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);
|
||||
// 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;
|
||||
}
|
||||
// // 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);
|
||||
// BackendResponse storageResponse = server.InventoryProvider.TryCreateFolder(owner, folder);
|
||||
|
||||
if (storageResponse == BackendResponse.Success)
|
||||
{
|
||||
SerializeBool(response.Body, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// if (storageResponse == BackendResponse.Success)
|
||||
// {
|
||||
// SerializeBool(response.Body, true);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
SerializeBool(response.Body, false);
|
||||
return true;
|
||||
}
|
||||
// SerializeBool(response.Body, false);
|
||||
// return true;
|
||||
//}
|
||||
|
||||
bool UpdateFolderHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
{
|
||||
return NewFolderHandler(client, request, response);
|
||||
}
|
||||
//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 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);
|
||||
//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 (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;
|
||||
}
|
||||
}
|
||||
// if (storageResponse == BackendResponse.Success)
|
||||
// {
|
||||
// SerializeBool(response.Body, true);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
SerializeBool(response.Body, false);
|
||||
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);
|
||||
//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 (item != null)
|
||||
// {
|
||||
// Uri owner = Utils.GetOpenSimUri(agentID);
|
||||
// BackendResponse storageResponse = server.InventoryProvider.TryCreateItem(owner, item);
|
||||
|
||||
if (storageResponse == BackendResponse.Success)
|
||||
{
|
||||
SerializeBool(response.Body, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// if (storageResponse == BackendResponse.Success)
|
||||
// {
|
||||
// SerializeBool(response.Body, true);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
SerializeBool(response.Body, false);
|
||||
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);
|
||||
//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 (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;
|
||||
}
|
||||
}
|
||||
// if (storageResponse == BackendResponse.Success)
|
||||
// {
|
||||
// SerializeBool(response.Body, true);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
SerializeBool(response.Body, false);
|
||||
return true;
|
||||
}
|
||||
// SerializeBool(response.Body, false);
|
||||
// return true;
|
||||
//}
|
||||
|
||||
bool RootFoldersHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
{
|
||||
UUID ownerID = DeserializeUUID(request.Body);
|
||||
//bool RootFoldersHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
//{
|
||||
// UUID ownerID = DeserializeUUID(request.Body);
|
||||
|
||||
if (ownerID != UUID.Zero)
|
||||
{
|
||||
Uri owner = Utils.GetOpenSimUri(ownerID);
|
||||
List<InventoryFolder> skeleton;
|
||||
BackendResponse storageResponse = server.InventoryProvider.TryFetchFolderList(owner, out skeleton);
|
||||
// if (ownerID != UUID.Zero)
|
||||
// {
|
||||
// Uri owner = Utils.GetOpenSimUri(ownerID);
|
||||
// List<InventoryFolder> 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<InventoryFolder>(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Status = HttpStatusCode.InternalServerError;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Status = HttpStatusCode.BadRequest;
|
||||
}
|
||||
// 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<InventoryFolder>(0));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// response.Status = HttpStatusCode.InternalServerError;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// response.Status = HttpStatusCode.BadRequest;
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
// return true;
|
||||
//}
|
||||
|
||||
bool ActiveGesturesHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
{
|
||||
UUID ownerID = DeserializeUUID(request.Body);
|
||||
//bool ActiveGesturesHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
//{
|
||||
// UUID ownerID = DeserializeUUID(request.Body);
|
||||
|
||||
if (ownerID != UUID.Zero)
|
||||
{
|
||||
Uri owner = Utils.GetOpenSimUri(ownerID);
|
||||
List<InventoryItem> gestures;
|
||||
BackendResponse storageResponse = server.InventoryProvider.TryFetchActiveGestures(owner, out gestures);
|
||||
// if (ownerID != UUID.Zero)
|
||||
// {
|
||||
// Uri owner = Utils.GetOpenSimUri(ownerID);
|
||||
// List<InventoryItem> 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<InventoryItem>(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Status = HttpStatusCode.InternalServerError;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Status = HttpStatusCode.BadRequest;
|
||||
}
|
||||
// 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<InventoryItem>(0));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// response.Status = HttpStatusCode.InternalServerError;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// response.Status = HttpStatusCode.BadRequest;
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
// return true;
|
||||
//}
|
||||
|
||||
BackendResponse CreateFolder(string name, UUID ownerID, UUID parentID, AssetType assetType)
|
||||
{
|
||||
|
|
|
@ -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,20 +92,53 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
|||
|
||||
#endregion IPlugin implementation
|
||||
|
||||
bool MetadataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
public class MetadataRequestHandler : IStreamedRequestHandler
|
||||
{
|
||||
AssetInventoryServer m_server;
|
||||
string m_contentType;
|
||||
string m_httpMethod;
|
||||
string m_path;
|
||||
|
||||
public MetadataRequestHandler(AssetInventoryServer server)
|
||||
{
|
||||
m_server = server;
|
||||
m_contentType = null;
|
||||
m_httpMethod = "GET";
|
||||
m_path = @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/metadata";
|
||||
}
|
||||
|
||||
#region IStreamedRequestHandler implementation
|
||||
|
||||
public string ContentType
|
||||
{
|
||||
get { return m_contentType; }
|
||||
}
|
||||
|
||||
public string HttpMethod
|
||||
{
|
||||
get { return m_httpMethod; }
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get { return m_path; }
|
||||
}
|
||||
|
||||
public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
||||
{
|
||||
byte[] serializedData = null;
|
||||
UUID assetID;
|
||||
// Split the URL up into an AssetID and a method
|
||||
string[] rawUrl = request.Uri.PathAndQuery.Split('/');
|
||||
string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
|
||||
|
||||
if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
|
||||
{
|
||||
UUID authToken = Utils.GetAuthToken(request);
|
||||
UUID authToken = Utils.GetAuthToken(httpRequest);
|
||||
|
||||
if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID))
|
||||
if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID))
|
||||
{
|
||||
Metadata metadata;
|
||||
BackendResponse storageResponse = server.StorageProvider.TryFetchMetadata(assetID, out metadata);
|
||||
BackendResponse storageResponse = m_server.StorageProvider.TryFetchMetadata(assetID, out metadata);
|
||||
|
||||
if (storageResponse == BackendResponse.Success)
|
||||
{
|
||||
|
@ -114,93 +147,162 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
|||
if (!metadata.Methods.ContainsKey("data"))
|
||||
{
|
||||
metadata.Methods["data"] = new Uri(String.Format("{0}://{1}/{2}/data",
|
||||
request.Uri.Scheme, request.Uri.Authority, assetID));
|
||||
httpRequest.Url.Scheme, httpRequest.Url.Authority, assetID));
|
||||
}
|
||||
|
||||
byte[] serializedData = metadata.SerializeToBytes();
|
||||
|
||||
response.Status = HttpStatusCode.OK;
|
||||
response.ContentType = "application/json";
|
||||
response.ContentLength = serializedData.Length;
|
||||
response.Body.Write(serializedData, 0, serializedData.Length);
|
||||
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)
|
||||
{
|
||||
Logger.Log.Warn("Could not find metadata for asset " + assetID.ToString());
|
||||
response.Status = HttpStatusCode.NotFound;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Status = HttpStatusCode.InternalServerError;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Status = HttpStatusCode.Forbidden;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
|
||||
}
|
||||
|
||||
return true;
|
||||
return serializedData;
|
||||
}
|
||||
|
||||
response.Status = HttpStatusCode.NotFound;
|
||||
return true;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
|
||||
return serializedData;
|
||||
}
|
||||
|
||||
bool DataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
#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 = request.Uri.PathAndQuery.Split('/');
|
||||
string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
|
||||
|
||||
if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
|
||||
{
|
||||
UUID authToken = Utils.GetAuthToken(request);
|
||||
UUID authToken = Utils.GetAuthToken(httpRequest);
|
||||
|
||||
if (server.AuthorizationProvider.IsDataAuthorized(authToken, assetID))
|
||||
if (m_server.AuthorizationProvider.IsDataAuthorized(authToken, assetID))
|
||||
{
|
||||
byte[] assetData;
|
||||
BackendResponse storageResponse = server.StorageProvider.TryFetchData(assetID, out assetData);
|
||||
BackendResponse storageResponse = m_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);
|
||||
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)
|
||||
{
|
||||
response.Status = HttpStatusCode.NotFound;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Status = HttpStatusCode.InternalServerError;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Status = HttpStatusCode.Forbidden;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
|
||||
}
|
||||
|
||||
return true;
|
||||
return assetData;
|
||||
}
|
||||
|
||||
response.Status = HttpStatusCode.BadRequest;
|
||||
return true;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
|
||||
return assetData;
|
||||
}
|
||||
|
||||
bool CreateRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
#endregion IStreamedRequestHandler implementation
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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(request.Body);
|
||||
OSD osdata = OSDParser.DeserializeJson(httpRequest.InputStream);
|
||||
|
||||
if (osdata.Type == OSDType.Map)
|
||||
{
|
||||
|
@ -215,51 +317,54 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
|
|||
BackendResponse storageResponse;
|
||||
|
||||
if (metadata.ID != UUID.Zero)
|
||||
storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData);
|
||||
storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData);
|
||||
else
|
||||
storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID);
|
||||
storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID);
|
||||
|
||||
if (storageResponse == BackendResponse.Success)
|
||||
{
|
||||
response.Status = HttpStatusCode.Created;
|
||||
httpResponse.StatusCode = (int) 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();
|
||||
responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson());
|
||||
httpResponse.Body.Write(responseData, 0, responseData.Length);
|
||||
httpResponse.Body.Flush();
|
||||
}
|
||||
else if (storageResponse == BackendResponse.NotFound)
|
||||
{
|
||||
response.Status = HttpStatusCode.NotFound;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Status = HttpStatusCode.InternalServerError;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Status = HttpStatusCode.BadRequest;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Status = HttpStatusCode.BadRequest;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
response.Status = HttpStatusCode.InternalServerError;
|
||||
response.Reason = ex.Message;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
|
||||
httpResponse.StatusDescription = ex.Message;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Status = HttpStatusCode.Forbidden;
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
|
||||
}
|
||||
|
||||
return true;
|
||||
return responseData;
|
||||
}
|
||||
|
||||
#endregion IStreamedRequestHandler implementation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -764,10 +764,11 @@
|
|||
<Reference name="System.Web"/>
|
||||
<Reference name="System.Xml"/>
|
||||
<Reference name="OpenSim.Framework"/>
|
||||
<Reference name="OpenSim.Framework.Console"/>
|
||||
<Reference name="OpenSim.Framework.Servers"/>
|
||||
<Reference name="log4net2"/>
|
||||
<Reference name="OpenMetaverseTypes"/>
|
||||
<Reference name="OpenMetaverse.StructuredData2"/>
|
||||
<Reference name="OpenMetaverse.Http"/>
|
||||
<Reference name="ExtensionLoader"/>
|
||||
<Reference name="HttpServer2"/>
|
||||
|
||||
|
@ -800,6 +801,7 @@
|
|||
<Reference name="System.Web"/>
|
||||
<Reference name="OpenSim.Grid.AssetInventoryServer" />
|
||||
<Reference name="OpenSim.Framework"/>
|
||||
<Reference name="OpenSim.Framework.Servers"/>
|
||||
<Reference name="OpenMetaverse"/>
|
||||
<Reference name="OpenMetaverseTypes"/>
|
||||
<Reference name="OpenMetaverse.StructuredData2"/>
|
||||
|
@ -859,6 +861,7 @@
|
|||
<Reference name="System" />
|
||||
<Reference name="System.Data" />
|
||||
<Reference name="OpenSim.Framework" />
|
||||
<Reference name="OpenSim.Framework.Servers"/>
|
||||
<Reference name="OpenSim.Data" />
|
||||
<Reference name="OpenSim.Grid.AssetInventoryServer" />
|
||||
<Reference name="OpenMetaverseTypes"/>
|
||||
|
|
Loading…
Reference in New Issue