Converted to Linux newlines.

0.6.3-post-fixes
Mike Mazur 2009-02-16 02:25:44 +00:00
parent 617016fa68
commit 16fa7f516a
22 changed files with 5968 additions and 5968 deletions

View File

@ -1,267 +1,267 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using System.Security.Cryptography.X509Certificates; 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;
namespace OpenSim.Grid.AssetInventoryServer namespace OpenSim.Grid.AssetInventoryServer
{ {
public class AssetInventoryServer : ServiceBase public class AssetInventoryServer : 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;
public IInventoryProvider InventoryProvider; public IInventoryProvider InventoryProvider;
public IAuthenticationProvider AuthenticationProvider; public IAuthenticationProvider AuthenticationProvider;
public IAuthorizationProvider AuthorizationProvider; public IAuthorizationProvider AuthorizationProvider;
public IMetricsProvider MetricsProvider; public IMetricsProvider MetricsProvider;
private IAssetInventoryServerPlugin frontend; private IAssetInventoryServerPlugin frontend;
public AssetInventoryServer() public AssetInventoryServer()
{ {
this.ServiceName = "OpenSimAssetInventoryServer"; this.ServiceName = "OpenSimAssetInventoryServer";
} }
public bool Start() public bool Start()
{ {
Logger.Log.Info("Starting Asset Server"); Logger.Log.Info("Starting Asset Server");
List<string> extensionList = null; List<string> extensionList = null;
int port = 0; int port = 0;
X509Certificate2 serverCert = null; X509Certificate2 serverCert = null;
try { ConfigFile = new IniConfigSource(CONFIG_FILE); } try { ConfigFile = new IniConfigSource(CONFIG_FILE); }
catch (Exception) catch (Exception)
{ {
Logger.Log.Error("Failed to load the config file " + CONFIG_FILE); Logger.Log.Error("Failed to load the config file " + CONFIG_FILE);
return false; return false;
} }
try try
{ {
IConfig extensionConfig = ConfigFile.Configs["Config"]; IConfig extensionConfig = ConfigFile.Configs["Config"];
// Load the port number to listen on // Load the port number to listen on
port = extensionConfig.GetInt("ListenPort"); port = extensionConfig.GetInt("ListenPort");
// Load the server certificate file // Load the server certificate file
string certFile = extensionConfig.GetString("SSLCertFile"); string certFile = extensionConfig.GetString("SSLCertFile");
if (!String.IsNullOrEmpty(certFile)) if (!String.IsNullOrEmpty(certFile))
serverCert = new X509Certificate2(certFile); serverCert = new X509Certificate2(certFile);
} }
catch (Exception) catch (Exception)
{ {
Logger.Log.Error("Failed to load [Config] section from " + CONFIG_FILE); Logger.Log.Error("Failed to load [Config] section from " + CONFIG_FILE);
return false; return false;
} }
try try
{ {
// Load the extension list (and ordering) from our config file // Load the extension list (and ordering) from our config file
IConfig extensionConfig = ConfigFile.Configs["Extensions"]; IConfig extensionConfig = ConfigFile.Configs["Extensions"];
extensionList = new List<string>(extensionConfig.GetKeys()); extensionList = new List<string>(extensionConfig.GetKeys());
} }
catch (Exception) catch (Exception)
{ {
Logger.Log.Error("Failed to load [Extensions] section from " + CONFIG_FILE); Logger.Log.Error("Failed to load [Extensions] section from " + CONFIG_FILE);
return false; return false;
} }
//try //try
//{ //{
// // Create a reference list for C# extensions compiled at runtime // // Create a reference list for C# extensions compiled at runtime
// List<string> references = new List<string>(); // List<string> references = new List<string>();
// references.Add("OpenMetaverseTypes.dll"); // references.Add("OpenMetaverseTypes.dll");
// references.Add("OpenMetaverse.dll"); // references.Add("OpenMetaverse.dll");
// references.Add("OpenMetaverse.StructuredData.dll"); // references.Add("OpenMetaverse.StructuredData.dll");
// references.Add("OpenMetaverse.Http.dll"); // references.Add("OpenMetaverse.Http.dll");
// references.Add("ExtensionLoader.dll"); // references.Add("ExtensionLoader.dll");
// references.Add("AssetServer.exe"); // references.Add("AssetServer.exe");
// // Get a list of all of the members of AssetServer that are interfaces // // Get a list of all of the members of AssetServer that are interfaces
// List<FieldInfo> assignables = ExtensionLoader<AssetServer>.GetInterfaces(this); // List<FieldInfo> assignables = ExtensionLoader<AssetServer>.GetInterfaces(this);
// // Load all of the extensions // // Load all of the extensions
// ExtensionLoader<AssetServer>.LoadAllExtensions( // ExtensionLoader<AssetServer>.LoadAllExtensions(
// Assembly.GetExecutingAssembly(), // Assembly.GetExecutingAssembly(),
// Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), // Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
// extensionList, // extensionList,
// references, // references,
// "AssetServer.*.dll", // "AssetServer.*.dll",
// "AssetServer.*.cs", // "AssetServer.*.cs",
// this, // this,
// assignables); // assignables);
//} //}
//catch (ExtensionException ex) //catch (ExtensionException ex)
//{ //{
// Logger.Log.Error("Interface loading failed, shutting down: " + ex.Message); // Logger.Log.Error("Interface loading failed, shutting down: " + ex.Message);
// if (ex.InnerException != null) // if (ex.InnerException != null)
// Logger.Log.Error(ex.InnerException.Message, ex.InnerException); // Logger.Log.Error(ex.InnerException.Message, ex.InnerException);
// Stop(); // Stop();
// return false; // return false;
//} //}
StorageProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/StorageProvider") as IAssetStorageProvider; StorageProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/StorageProvider") as IAssetStorageProvider;
try try
{ {
InitHttpServer(port, serverCert); InitHttpServer(port, serverCert);
} }
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(); Stop();
return false; return false;
} }
frontend = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/Frontend"); frontend = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/Frontend");
// Start all of the extensions // Start all of the extensions
//foreach (IExtension<AssetServer> extension in ExtensionLoader<AssetServer>.Extensions) //foreach (IExtension<AssetServer> extension in ExtensionLoader<AssetServer>.Extensions)
//{ //{
// Logger.Log.Info("Starting extension " + extension.GetType().Name); // Logger.Log.Info("Starting extension " + extension.GetType().Name);
// extension.Start(this); // extension.Start(this);
//} //}
return true; return true;
} }
public void Shutdown() public void Shutdown()
{ {
foreach (IExtension<AssetInventoryServer> extension in ExtensionLoader<AssetInventoryServer>.Extensions) foreach (IExtension<AssetInventoryServer> extension in ExtensionLoader<AssetInventoryServer>.Extensions)
{ {
Logger.Log.Debug("Disposing extension " + extension.GetType().Name); Logger.Log.Debug("Disposing extension " + extension.GetType().Name);
try { extension.Stop(); } try { extension.Stop(); }
catch (Exception ex) catch (Exception ex)
{ Logger.Log.ErrorFormat("Failure shutting down extension {0}: {1}", extension.GetType().Name, ex.Message); } { Logger.Log.ErrorFormat("Failure shutting down extension {0}: {1}", extension.GetType().Name, ex.Message); }
} }
if (HttpServer != null) if (HttpServer != null)
HttpServer.Stop(); HttpServer.Stop();
} }
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;
} }
); );
HttpServer.Start(); HttpServer.Start();
Logger.Log.Info("Asset server is listening on port " + port); Logger.Log.Info("Asset server is listening on port " + port);
} }
#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
private IAssetInventoryServerPlugin LoadAssetInventoryServerPlugin(string addinPath) private IAssetInventoryServerPlugin LoadAssetInventoryServerPlugin(string addinPath)
{ {
PluginLoader<IAssetInventoryServerPlugin> loader = new PluginLoader<IAssetInventoryServerPlugin>(new AssetInventoryServerPluginInitialiser(this)); PluginLoader<IAssetInventoryServerPlugin> loader = new PluginLoader<IAssetInventoryServerPlugin>(new AssetInventoryServerPluginInitialiser(this));
//loader.Add ("/OpenSim/AssetInventoryServer/StorageProvider", new PluginProviderFilter (provider)); //loader.Add ("/OpenSim/AssetInventoryServer/StorageProvider", new PluginProviderFilter (provider));
//loader.Add("/OpenSim/AssetInventoryServer/StorageProvider", new PluginCountConstraint(1)); //loader.Add("/OpenSim/AssetInventoryServer/StorageProvider", new PluginCountConstraint(1));
loader.Add(addinPath); loader.Add(addinPath);
loader.Load(); loader.Load();
return loader.Plugin; return loader.Plugin;
} }
} }
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;
} }
} }
} }
} }

View File

@ -1,78 +1,78 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using ExtensionLoader; using ExtensionLoader;
using OpenMetaverse; using OpenMetaverse;
namespace OpenSim.Grid.AssetInventoryServer.Extensions namespace OpenSim.Grid.AssetInventoryServer.Extensions
{ {
public class AuthorizeAll : IExtension<AssetInventoryServer>, IAuthorizationProvider public class AuthorizeAll : IExtension<AssetInventoryServer>, IAuthorizationProvider
{ {
AssetInventoryServer server; AssetInventoryServer server;
public AuthorizeAll() public AuthorizeAll()
{ {
} }
public void Start(AssetInventoryServer server) public void Start(AssetInventoryServer server)
{ {
this.server = server; this.server = server;
} }
public void Stop() public void Stop()
{ {
} }
public bool IsMetadataAuthorized(UUID authToken, UUID assetID) public bool IsMetadataAuthorized(UUID authToken, UUID assetID)
{ {
return true; return true;
} }
public bool IsDataAuthorized(UUID authToken, UUID assetID) public bool IsDataAuthorized(UUID authToken, UUID assetID)
{ {
return true; return true;
} }
public bool IsCreateAuthorized(UUID authToken) public bool IsCreateAuthorized(UUID authToken)
{ {
return true; return true;
} }
public bool IsInventoryReadAuthorized(UUID authToken, Uri owner) public bool IsInventoryReadAuthorized(UUID authToken, Uri owner)
{ {
return true; return true;
} }
public bool IsInventoryWriteAuthorized(UUID authToken, Uri owner) public bool IsInventoryWriteAuthorized(UUID authToken, Uri owner)
{ {
return true; return true;
} }
} }
} }

View File

@ -1,125 +1,125 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
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 ExtensionLoader; using ExtensionLoader;
using OpenMetaverse; using OpenMetaverse;
using HttpServer; using HttpServer;
namespace OpenSim.Grid.AssetInventoryServer.Extensions namespace OpenSim.Grid.AssetInventoryServer.Extensions
{ {
public class BrowseFrontend : IExtension<AssetInventoryServer> public class BrowseFrontend : IExtension<AssetInventoryServer>
{ {
AssetInventoryServer server; AssetInventoryServer server;
public BrowseFrontend() public BrowseFrontend()
{ {
} }
public void Start(AssetInventoryServer server) public void Start(AssetInventoryServer server)
{ {
this.server = server; this.server = server;
// Request for / or /?... // Request for / or /?...
server.HttpServer.AddHandler("get", null, @"(^/$)|(^/\?.*)", BrowseRequestHandler); server.HttpServer.AddHandler("get", null, @"(^/$)|(^/\?.*)", BrowseRequestHandler);
} }
public void Stop() public void Stop()
{ {
} }
bool BrowseRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) bool BrowseRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
{ {
const int ASSETS_PER_PAGE = 25; const int ASSETS_PER_PAGE = 25;
const string HEADER = "<html><head><title>Asset Server</title></head><body>"; const string HEADER = "<html><head><title>Asset Server</title></head><body>";
const string TABLE_HEADER = 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>"; "<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 TABLE_FOOTER = "</table>";
const string FOOTER = "</body></html>"; const string FOOTER = "</body></html>";
UUID authToken = Utils.GetAuthToken(request); UUID authToken = Utils.GetAuthToken(request);
StringBuilder html = new StringBuilder(); StringBuilder html = new StringBuilder();
int start = 0; int start = 0;
uint page = 0; uint page = 0;
if (!String.IsNullOrEmpty(request.Uri.Query)) if (!String.IsNullOrEmpty(request.Uri.Query))
{ {
NameValueCollection query = HttpUtility.ParseQueryString(request.Uri.Query); NameValueCollection query = HttpUtility.ParseQueryString(request.Uri.Query);
if (!String.IsNullOrEmpty(query["page"]) && UInt32.TryParse(query["page"], out page)) if (!String.IsNullOrEmpty(query["page"]) && UInt32.TryParse(query["page"], out page))
start = (int)page * ASSETS_PER_PAGE; start = (int)page * ASSETS_PER_PAGE;
} }
html.AppendLine(HEADER); html.AppendLine(HEADER);
html.AppendLine("<p>"); html.AppendLine("<p>");
if (page > 0) if (page > 0)
html.AppendFormat("<a href=\"{0}?page={1}\">&lt; Previous Page</a> | ", request.Uri.AbsolutePath, page - 1); html.AppendFormat("<a href=\"{0}?page={1}\">&lt; Previous Page</a> | ", request.Uri.AbsolutePath, page - 1);
html.AppendFormat("<a href=\"{0}?page={1}\">Next Page &gt;</a>", request.Uri.AbsolutePath, page + 1); html.AppendFormat("<a href=\"{0}?page={1}\">Next Page &gt;</a>", request.Uri.AbsolutePath, page + 1);
html.AppendLine("</p>"); html.AppendLine("</p>");
html.AppendLine(TABLE_HEADER); html.AppendLine(TABLE_HEADER);
server.StorageProvider.ForEach( server.StorageProvider.ForEach(
delegate(Metadata data) delegate(Metadata data)
{ {
if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.ID)) if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, data.ID))
{ {
html.AppendLine(String.Format( html.AppendLine(String.Format(
"<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>", "<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, data.Name, data.Description, data.ContentType, data.ID, data.Temporary,
BitConverter.ToString(data.SHA1).Replace("-", String.Empty))); BitConverter.ToString(data.SHA1).Replace("-", String.Empty)));
} }
else else
{ {
html.AppendLine(String.Format( html.AppendLine(String.Format(
"<tr><td>[Protected Asset]</td><td>&nbsp;</td><td>&nbsp;</td><td>{0}</td><td>{1}</td><td>&nbsp;</td></tr>", "<tr><td>[Protected Asset]</td><td>&nbsp;</td><td>&nbsp;</td><td>{0}</td><td>{1}</td><td>&nbsp;</td></tr>",
data.ID, data.Temporary)); data.ID, data.Temporary));
} }
}, start, ASSETS_PER_PAGE }, 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; response.Status = HttpStatusCode.OK;
response.Body.Write(responseData, 0, responseData.Length); response.Body.Write(responseData, 0, responseData.Length);
response.Body.Flush(); response.Body.Flush();
return true; return true;
} }
} }
} }

View File

@ -1,78 +1,78 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Xml; using System.Xml;
using ExtensionLoader.Config; using ExtensionLoader.Config;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
namespace OpenSim.Grid.AssetInventoryServer.Extensions namespace OpenSim.Grid.AssetInventoryServer.Extensions
{ {
public static class DBConnString public static class DBConnString
{ {
private static string connectionString; private static string connectionString;
/// <summary> /// <summary>
/// Parses the MySQL connection string out of either the asset server /// Parses the MySQL connection string out of either the asset server
/// .ini or a OpenSim-style .xml file and caches the result for future /// .ini or a OpenSim-style .xml file and caches the result for future
/// requests /// requests
/// </summary> /// </summary>
public static string GetConnectionString(IniConfigSource configFile) public static string GetConnectionString(IniConfigSource configFile)
{ {
if (connectionString == null) if (connectionString == null)
{ {
// Try parsing from the ini file // Try parsing from the ini file
try try
{ {
// Load the extension list (and ordering) from our config file // Load the extension list (and ordering) from our config file
IConfig extensionConfig = configFile.Configs["MySQL"]; IConfig extensionConfig = configFile.Configs["MySQL"];
connectionString = extensionConfig.GetString("database_connect", null); connectionString = extensionConfig.GetString("database_connect", null);
} }
catch (Exception) { } catch (Exception) { }
if (connectionString != null) if (connectionString != null)
{ {
// Force MySQL's broken connection pooling off // Force MySQL's broken connection pooling off
MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(connectionString); MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(connectionString);
builder.Pooling = false; builder.Pooling = false;
if (String.IsNullOrEmpty(builder.Database)) if (String.IsNullOrEmpty(builder.Database))
Logger.Log.Error("No database selected in the connectionString: " + connectionString); Logger.Log.Error("No database selected in the connectionString: " + connectionString);
connectionString = builder.ToString(); connectionString = builder.ToString();
} }
else else
{ {
Logger.Log.Error("Database connection string is missing, check that the database_connect line is " + Logger.Log.Error("Database connection string is missing, check that the database_connect line is " +
"correct and uncommented in AssetInventoryServer.ini"); "correct and uncommented in AssetInventoryServer.ini");
} }
} }
return connectionString; return connectionString;
} }
} }
} }

View File

@ -1,68 +1,68 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using ExtensionLoader; using ExtensionLoader;
using OpenMetaverse; using OpenMetaverse;
namespace OpenSim.Grid.AssetInventoryServer.Extensions namespace OpenSim.Grid.AssetInventoryServer.Extensions
{ {
public class NullAuthentication : IExtension<AssetInventoryServer>, IAuthenticationProvider public class NullAuthentication : IExtension<AssetInventoryServer>, IAuthenticationProvider
{ {
AssetInventoryServer server; AssetInventoryServer server;
public NullAuthentication() public NullAuthentication()
{ {
} }
public void Start(AssetInventoryServer server) public void Start(AssetInventoryServer server)
{ {
this.server = server; this.server = server;
} }
public void Stop() public void Stop()
{ {
} }
public void AddIdentifier(UUID authToken, Uri identifier) public void AddIdentifier(UUID authToken, Uri identifier)
{ {
} }
public bool RemoveIdentifier(UUID authToken) public bool RemoveIdentifier(UUID authToken)
{ {
return true; return true;
} }
public bool TryGetIdentifier(UUID authToken, out Uri identifier) public bool TryGetIdentifier(UUID authToken, out Uri identifier)
{ {
identifier = null; identifier = null;
return true; return true;
} }
} }
} }

View File

@ -1,124 +1,124 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using ExtensionLoader; using ExtensionLoader;
using OpenMetaverse; using OpenMetaverse;
namespace OpenSim.Grid.AssetInventoryServer.Extensions namespace OpenSim.Grid.AssetInventoryServer.Extensions
{ {
public class NullMetrics : IExtension<AssetInventoryServer>, IMetricsProvider public class NullMetrics : IExtension<AssetInventoryServer>, IMetricsProvider
{ {
AssetInventoryServer server; AssetInventoryServer server;
public NullMetrics() public NullMetrics()
{ {
} }
public void Start(AssetInventoryServer server) public void Start(AssetInventoryServer server)
{ {
this.server = server; this.server = server;
} }
public void Stop() public void Stop()
{ {
} }
public void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time) public void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time)
{ {
Logger.Log.DebugFormat("[{0}] AssetMetadataFetch(): AssetID: {1}, Response: {2}", extension, assetID, response); Logger.Log.DebugFormat("[{0}] AssetMetadataFetch(): AssetID: {1}, Response: {2}", extension, assetID, response);
} }
public void LogAssetDataFetch(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time) public void LogAssetDataFetch(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time)
{ {
Logger.Log.DebugFormat("[{0}] AssetDataFetch(): AssetID: {1}, DataSize: {2}, Response: {3}", extension, assetID, Logger.Log.DebugFormat("[{0}] AssetDataFetch(): AssetID: {1}, DataSize: {2}, Response: {3}", extension, assetID,
dataSize, response); dataSize, response);
} }
public void LogAssetCreate(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time) public void LogAssetCreate(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time)
{ {
Logger.Log.DebugFormat("[{0}] AssetCreate(): AssetID: {1}, DataSize: {2}, Response: {3}", extension, assetID, Logger.Log.DebugFormat("[{0}] AssetCreate(): AssetID: {1}, DataSize: {2}, Response: {3}", extension, assetID,
dataSize, response); dataSize, response);
} }
public void LogInventoryFetch(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time) public void LogInventoryFetch(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time)
{ {
Logger.Log.DebugFormat("[{0}] InventoryFetch(): ObjID: {1}, Folder: {2}, OwnerID: {3}, Response: {4}", extension, Logger.Log.DebugFormat("[{0}] InventoryFetch(): ObjID: {1}, Folder: {2}, OwnerID: {3}, Response: {4}", extension,
objID, folder, owner, response); objID, folder, owner, response);
} }
public void LogInventoryFetchFolderContents(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time) public void LogInventoryFetchFolderContents(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time)
{ {
Logger.Log.DebugFormat("[{0}] InventoryFetchFolderContents(): FolderID: {1}, OwnerID: {2}, Response: {3}", extension, Logger.Log.DebugFormat("[{0}] InventoryFetchFolderContents(): FolderID: {1}, OwnerID: {2}, Response: {3}", extension,
folderID, owner, response); folderID, owner, response);
} }
public void LogInventoryFetchFolderList(string extension, BackendResponse response, Uri owner, DateTime time) public void LogInventoryFetchFolderList(string extension, BackendResponse response, Uri owner, DateTime time)
{ {
Logger.Log.DebugFormat("[{0}] InventoryFetchFolderList(): OwnerID: {1}, Response: {2}", extension, Logger.Log.DebugFormat("[{0}] InventoryFetchFolderList(): OwnerID: {1}, Response: {2}", extension,
owner, response); owner, response);
} }
public void LogInventoryFetchInventory(string extension, BackendResponse response, Uri owner, DateTime time) public void LogInventoryFetchInventory(string extension, BackendResponse response, Uri owner, DateTime time)
{ {
Logger.Log.DebugFormat("[{0}] InventoryFetchInventory(): OwnerID: {1}, Response: {2}", extension, Logger.Log.DebugFormat("[{0}] InventoryFetchInventory(): OwnerID: {1}, Response: {2}", extension,
owner, response); owner, response);
} }
public void LogInventoryFetchActiveGestures(string extension, BackendResponse response, Uri owner, DateTime time) public void LogInventoryFetchActiveGestures(string extension, BackendResponse response, Uri owner, DateTime time)
{ {
Logger.Log.DebugFormat("[{0}] InventoryFetchActiveGestures(): OwnerID: {1}, Response: {2}", extension, Logger.Log.DebugFormat("[{0}] InventoryFetchActiveGestures(): OwnerID: {1}, Response: {2}", extension,
owner, response); owner, response);
} }
public void LogInventoryCreate(string extension, BackendResponse response, Uri owner, bool folder, DateTime time) public void LogInventoryCreate(string extension, BackendResponse response, Uri owner, bool folder, DateTime time)
{ {
Logger.Log.DebugFormat("[{0}] InventoryCreate(): OwnerID: {1}, Response: {2}", extension, Logger.Log.DebugFormat("[{0}] InventoryCreate(): OwnerID: {1}, Response: {2}", extension,
owner, response); owner, response);
} }
public void LogInventoryCreateInventory(string extension, BackendResponse response, DateTime time) public void LogInventoryCreateInventory(string extension, BackendResponse response, DateTime time)
{ {
Logger.Log.DebugFormat("[{0}] InventoryCreateInventory(): Response: {1}", extension, Logger.Log.DebugFormat("[{0}] InventoryCreateInventory(): Response: {1}", extension,
response); response);
} }
public void LogInventoryDelete(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time) public void LogInventoryDelete(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time)
{ {
Logger.Log.DebugFormat("[{0}] InventoryDelete(): OwnerID: {1}, Folder: {2}, Response: {3}", extension, Logger.Log.DebugFormat("[{0}] InventoryDelete(): OwnerID: {1}, Folder: {2}, Response: {3}", extension,
owner, folder, response); owner, folder, response);
} }
public void LogInventoryPurgeFolder(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time) public void LogInventoryPurgeFolder(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time)
{ {
Logger.Log.DebugFormat("[{0}] InventoryPurgeFolder(): OwnerID: {1}, FolderID: {2}, Response: {3}", extension, Logger.Log.DebugFormat("[{0}] InventoryPurgeFolder(): OwnerID: {1}, FolderID: {2}, Response: {3}", extension,
owner, response); owner, response);
} }
} }
} }

View File

@ -1,215 +1,215 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.IO; using System.IO;
using System.Xml; using System.Xml;
using ExtensionLoader; using ExtensionLoader;
using OpenMetaverse; using OpenMetaverse;
using HttpServer; using HttpServer;
namespace OpenSim.Grid.AssetInventoryServer.Extensions namespace OpenSim.Grid.AssetInventoryServer.Extensions
{ {
public class OpenSimFrontend : IExtension<AssetInventoryServer> public class OpenSimFrontend : IExtension<AssetInventoryServer>
{ {
AssetInventoryServer server; AssetInventoryServer server;
public OpenSimFrontend() public OpenSimFrontend()
{ {
} }
public void Start(AssetInventoryServer server) public void Start(AssetInventoryServer server)
{ {
this.server = server; this.server = server;
// Asset request // Asset request
server.HttpServer.AddHandler("get", null, @"^/assets/", AssetRequestHandler); server.HttpServer.AddHandler("get", null, @"^/assets/", AssetRequestHandler);
// Asset creation // Asset creation
server.HttpServer.AddHandler("post", null, @"^/assets/", AssetPostHandler); server.HttpServer.AddHandler("post", null, @"^/assets/", AssetPostHandler);
} }
public void Stop() public void Stop()
{ {
} }
bool AssetRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) bool AssetRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
{ {
UUID assetID; UUID assetID;
// Split the URL up to get the asset ID out // Split the URL up to get the asset ID out
string[] rawUrl = request.Uri.PathAndQuery.Split('/'); string[] rawUrl = request.Uri.PathAndQuery.Split('/');
if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out assetID)) if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out assetID))
{ {
Metadata metadata; Metadata metadata;
byte[] assetData; byte[] assetData;
BackendResponse dataResponse; BackendResponse dataResponse;
if ((dataResponse = server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success) if ((dataResponse = server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success)
{ {
MemoryStream stream = new MemoryStream(); MemoryStream stream = new MemoryStream();
XmlWriterSettings settings = new XmlWriterSettings(); XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true; settings.Indent = true;
XmlWriter writer = XmlWriter.Create(stream, settings); XmlWriter writer = XmlWriter.Create(stream, settings);
writer.WriteStartDocument(); writer.WriteStartDocument();
writer.WriteStartElement("AssetBase"); writer.WriteStartElement("AssetBase");
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
writer.WriteStartElement("FullID"); writer.WriteStartElement("FullID");
writer.WriteStartElement("Guid"); writer.WriteStartElement("Guid");
writer.WriteString(assetID.ToString()); writer.WriteString(assetID.ToString());
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteStartElement("ID"); writer.WriteStartElement("ID");
writer.WriteString(assetID.ToString()); writer.WriteString(assetID.ToString());
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteStartElement("Data"); writer.WriteStartElement("Data");
writer.WriteBase64(assetData, 0, assetData.Length); writer.WriteBase64(assetData, 0, assetData.Length);
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteStartElement("Type"); writer.WriteStartElement("Type");
writer.WriteValue(Utils.ContentTypeToSLAssetType(metadata.ContentType)); writer.WriteValue(Utils.ContentTypeToSLAssetType(metadata.ContentType));
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteStartElement("Name"); writer.WriteStartElement("Name");
writer.WriteString(metadata.Name); writer.WriteString(metadata.Name);
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteStartElement("Description"); writer.WriteStartElement("Description");
writer.WriteString(metadata.Description); writer.WriteString(metadata.Description);
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteStartElement("Local"); writer.WriteStartElement("Local");
writer.WriteValue(false); writer.WriteValue(false);
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteStartElement("Temporary"); writer.WriteStartElement("Temporary");
writer.WriteValue(metadata.Temporary); writer.WriteValue(metadata.Temporary);
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteEndDocument(); writer.WriteEndDocument();
writer.Flush(); writer.Flush();
byte[] buffer = stream.GetBuffer(); byte[] buffer = stream.GetBuffer();
response.Status = HttpStatusCode.OK; response.Status = HttpStatusCode.OK;
response.ContentType = "application/xml"; response.ContentType = "application/xml";
response.ContentLength = stream.Length; response.ContentLength = stream.Length;
response.Body.Write(buffer, 0, (int)stream.Length); response.Body.Write(buffer, 0, (int)stream.Length);
response.Body.Flush(); response.Body.Flush();
} }
else else
{ {
Logger.Log.WarnFormat("Failed to fetch asset data or metadata for {0}: {1}", assetID, dataResponse); Logger.Log.WarnFormat("Failed to fetch asset data or metadata for {0}: {1}", assetID, dataResponse);
response.Status = HttpStatusCode.NotFound; response.Status = HttpStatusCode.NotFound;
} }
} }
else else
{ {
Logger.Log.Warn("Unrecognized OpenSim asset request: " + request.Uri.PathAndQuery); Logger.Log.Warn("Unrecognized OpenSim asset request: " + request.Uri.PathAndQuery);
} }
return true; return true;
} }
bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
{ {
byte[] assetData = null; byte[] assetData = null;
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
Logger.Log.Debug("Handling OpenSim asset upload"); Logger.Log.Debug("Handling OpenSim asset upload");
try try
{ {
using (XmlReader reader = XmlReader.Create(request.Body)) using (XmlReader reader = XmlReader.Create(request.Body))
{ {
reader.MoveToContent(); reader.MoveToContent();
reader.ReadStartElement("AssetBase"); reader.ReadStartElement("AssetBase");
reader.ReadStartElement("FullID"); reader.ReadStartElement("FullID");
UUID.TryParse(reader.ReadElementContentAsString("Guid", String.Empty), out metadata.ID); UUID.TryParse(reader.ReadElementContentAsString("Guid", String.Empty), out metadata.ID);
reader.ReadEndElement(); reader.ReadEndElement();
reader.ReadStartElement("ID"); reader.ReadStartElement("ID");
reader.Skip(); reader.Skip();
reader.ReadEndElement(); reader.ReadEndElement();
// HACK: Broken on Mono. https://bugzilla.novell.com/show_bug.cgi?id=464229 // HACK: Broken on Mono. https://bugzilla.novell.com/show_bug.cgi?id=464229
//int readBytes = 0; //int readBytes = 0;
//byte[] buffer = new byte[1024]; //byte[] buffer = new byte[1024];
//MemoryStream stream = new MemoryStream(); //MemoryStream stream = new MemoryStream();
//BinaryWriter writer = new BinaryWriter(stream); //BinaryWriter writer = new BinaryWriter(stream);
//while ((readBytes = reader.ReadElementContentAsBase64(buffer, 0, buffer.Length)) > 0) //while ((readBytes = reader.ReadElementContentAsBase64(buffer, 0, buffer.Length)) > 0)
// writer.Write(buffer, 0, readBytes); // writer.Write(buffer, 0, readBytes);
//writer.Flush(); //writer.Flush();
//assetData = stream.GetBuffer(); //assetData = stream.GetBuffer();
//Array.Resize<byte>(ref assetData, (int)stream.Length); //Array.Resize<byte>(ref assetData, (int)stream.Length);
assetData = Convert.FromBase64String(reader.ReadElementContentAsString()); assetData = Convert.FromBase64String(reader.ReadElementContentAsString());
int type; int type;
Int32.TryParse(reader.ReadElementContentAsString("Type", String.Empty), out type); Int32.TryParse(reader.ReadElementContentAsString("Type", String.Empty), out type);
metadata.ContentType = Utils.SLAssetTypeToContentType(type); metadata.ContentType = Utils.SLAssetTypeToContentType(type);
metadata.Name = reader.ReadElementContentAsString("Name", String.Empty); metadata.Name = reader.ReadElementContentAsString("Name", String.Empty);
metadata.Description = reader.ReadElementContentAsString("Description", String.Empty); metadata.Description = reader.ReadElementContentAsString("Description", String.Empty);
Boolean.TryParse(reader.ReadElementContentAsString("Local", String.Empty), out metadata.Temporary); Boolean.TryParse(reader.ReadElementContentAsString("Local", String.Empty), out metadata.Temporary);
Boolean.TryParse(reader.ReadElementContentAsString("Temporary", String.Empty), out metadata.Temporary); Boolean.TryParse(reader.ReadElementContentAsString("Temporary", String.Empty), out metadata.Temporary);
reader.ReadEndElement(); reader.ReadEndElement();
} }
if (assetData != null && assetData.Length > 0) if (assetData != null && assetData.Length > 0)
{ {
metadata.SHA1 = OpenMetaverse.Utils.SHA1(assetData); metadata.SHA1 = OpenMetaverse.Utils.SHA1(assetData);
metadata.CreationDate = DateTime.Now; metadata.CreationDate = DateTime.Now;
BackendResponse storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData); BackendResponse storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData);
if (storageResponse == BackendResponse.Success) if (storageResponse == BackendResponse.Success)
response.Status = HttpStatusCode.Created; response.Status = HttpStatusCode.Created;
else if (storageResponse == BackendResponse.NotFound) else if (storageResponse == BackendResponse.NotFound)
response.Status = HttpStatusCode.NotFound; response.Status = HttpStatusCode.NotFound;
else else
response.Status = HttpStatusCode.InternalServerError; response.Status = HttpStatusCode.InternalServerError;
} }
else else
{ {
Logger.Log.Warn("AssetPostHandler called with no asset data"); Logger.Log.Warn("AssetPostHandler called with no asset data");
response.Status = HttpStatusCode.BadRequest; response.Status = HttpStatusCode.BadRequest;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Log.Warn("Failed to parse POST data (expecting AssetBase): " + ex.Message); Logger.Log.Warn("Failed to parse POST data (expecting AssetBase): " + ex.Message);
response.Status = HttpStatusCode.BadRequest; response.Status = HttpStatusCode.BadRequest;
} }
Logger.Log.Debug("Finished handling OpenSim asset upload, Status: " + response.Status.ToString()); Logger.Log.Debug("Finished handling OpenSim asset upload, Status: " + response.Status.ToString());
return true; return true;
} }
} }
} }

View File

@ -1,311 +1,311 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Data; using System.Data;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using ExtensionLoader; using ExtensionLoader;
using ExtensionLoader.Config; using ExtensionLoader.Config;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.StructuredData; using OpenMetaverse.StructuredData;
namespace OpenSim.Grid.AssetInventoryServer.Extensions namespace OpenSim.Grid.AssetInventoryServer.Extensions
{ {
public class OpenSimMySQLStorage : IExtension<AssetInventoryServer>, IStorageProvider public class OpenSimMySQLStorage : IExtension<AssetInventoryServer>, IStorageProvider
{ {
const string EXTENSION_NAME = "OpenSimMySQLStorage"; // Used in metrics reporting const string EXTENSION_NAME = "OpenSimMySQLStorage"; // Used in metrics reporting
AssetInventoryServer server; AssetInventoryServer server;
public OpenSimMySQLStorage() public OpenSimMySQLStorage()
{ {
} }
#region Required Interfaces #region Required Interfaces
public void Start(AssetInventoryServer server) public void Start(AssetInventoryServer server)
{ {
this.server = server; this.server = server;
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
{ {
try try
{ {
dbConnection.Open(); dbConnection.Open();
Logger.Log.Info("Connected to MySQL storage backend: " + dbConnection.ServerVersion); Logger.Log.Info("Connected to MySQL storage backend: " + dbConnection.ServerVersion);
} }
catch (MySqlException ex) catch (MySqlException ex)
{ {
Logger.Log.Error("Connection to MySQL storage backend failed: " + ex.Message); Logger.Log.Error("Connection to MySQL storage backend failed: " + ex.Message);
} }
} }
} }
public void Stop() public void Stop()
{ {
} }
public BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata) public BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata)
{ {
metadata = null; metadata = null;
BackendResponse ret; BackendResponse ret;
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
{ {
IDataReader reader; IDataReader reader;
try try
{ {
dbConnection.Open(); dbConnection.Open();
IDbCommand command = dbConnection.CreateCommand(); IDbCommand command = dbConnection.CreateCommand();
command.CommandText = String.Format("SELECT name,description,assetType,temporary FROM assets WHERE id='{0}'", assetID.ToString()); command.CommandText = String.Format("SELECT name,description,assetType,temporary FROM assets WHERE id='{0}'", assetID.ToString());
reader = command.ExecuteReader(); reader = command.ExecuteReader();
if (reader.Read()) if (reader.Read())
{ {
metadata = new Metadata(); metadata = new Metadata();
metadata.CreationDate = OpenMetaverse.Utils.Epoch; metadata.CreationDate = OpenMetaverse.Utils.Epoch;
metadata.SHA1 = null; metadata.SHA1 = null;
metadata.ID = assetID; metadata.ID = assetID;
metadata.Name = reader.GetString(0); metadata.Name = reader.GetString(0);
metadata.Description = reader.GetString(1); metadata.Description = reader.GetString(1);
metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2));
metadata.Temporary = reader.GetBoolean(3); metadata.Temporary = reader.GetBoolean(3);
ret = BackendResponse.Success; ret = BackendResponse.Success;
} }
else else
{ {
ret = BackendResponse.NotFound; ret = BackendResponse.NotFound;
} }
} }
catch (MySqlException ex) catch (MySqlException ex)
{ {
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message);
ret = BackendResponse.Failure; ret = BackendResponse.Failure;
} }
} }
server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
return ret; return ret;
} }
public BackendResponse TryFetchData(UUID assetID, out byte[] assetData) public BackendResponse TryFetchData(UUID assetID, out byte[] assetData)
{ {
assetData = null; assetData = null;
BackendResponse ret; BackendResponse ret;
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
{ {
IDataReader reader; IDataReader reader;
try try
{ {
dbConnection.Open(); dbConnection.Open();
IDbCommand command = dbConnection.CreateCommand(); IDbCommand command = dbConnection.CreateCommand();
command.CommandText = String.Format("SELECT data FROM assets WHERE id='{0}'", assetID.ToString()); command.CommandText = String.Format("SELECT data FROM assets WHERE id='{0}'", assetID.ToString());
reader = command.ExecuteReader(); reader = command.ExecuteReader();
if (reader.Read()) if (reader.Read())
{ {
assetData = (byte[])reader.GetValue(0); assetData = (byte[])reader.GetValue(0);
ret = BackendResponse.Success; ret = BackendResponse.Success;
} }
else else
{ {
ret = BackendResponse.NotFound; ret = BackendResponse.NotFound;
} }
} }
catch (MySqlException ex) catch (MySqlException ex)
{ {
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message);
ret = BackendResponse.Failure; ret = BackendResponse.Failure;
} }
} }
server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now); server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now);
return ret; return ret;
} }
public BackendResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData) public BackendResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData)
{ {
metadata = null; metadata = null;
assetData = null; assetData = null;
BackendResponse ret; BackendResponse ret;
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
{ {
IDataReader reader; IDataReader reader;
try try
{ {
dbConnection.Open(); dbConnection.Open();
IDbCommand command = dbConnection.CreateCommand(); IDbCommand command = dbConnection.CreateCommand();
command.CommandText = String.Format("SELECT name,description,assetType,temporary,data FROM assets WHERE id='{0}'", assetID.ToString()); command.CommandText = String.Format("SELECT name,description,assetType,temporary,data FROM assets WHERE id='{0}'", assetID.ToString());
reader = command.ExecuteReader(); reader = command.ExecuteReader();
if (reader.Read()) if (reader.Read())
{ {
metadata = new Metadata(); metadata = new Metadata();
metadata.CreationDate = OpenMetaverse.Utils.Epoch; metadata.CreationDate = OpenMetaverse.Utils.Epoch;
metadata.SHA1 = null; metadata.SHA1 = null;
metadata.ID = assetID; metadata.ID = assetID;
metadata.Name = reader.GetString(0); metadata.Name = reader.GetString(0);
metadata.Description = reader.GetString(1); metadata.Description = reader.GetString(1);
metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2));
metadata.Temporary = reader.GetBoolean(3); metadata.Temporary = reader.GetBoolean(3);
assetData = (byte[])reader.GetValue(4); assetData = (byte[])reader.GetValue(4);
ret = BackendResponse.Success; ret = BackendResponse.Success;
} }
else else
{ {
ret = BackendResponse.NotFound; ret = BackendResponse.NotFound;
} }
} }
catch (MySqlException ex) catch (MySqlException ex)
{ {
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message);
ret = BackendResponse.Failure; ret = BackendResponse.Failure;
} }
} }
server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now); server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now);
return ret; return ret;
} }
public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID) public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID)
{ {
assetID = metadata.ID = UUID.Random(); assetID = metadata.ID = UUID.Random();
return TryCreateAsset(metadata, assetData); return TryCreateAsset(metadata, assetData);
} }
public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData) public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData)
{ {
BackendResponse ret; BackendResponse ret;
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
{ {
try try
{ {
dbConnection.Open(); dbConnection.Open();
MySqlCommand command = new MySqlCommand( MySqlCommand command = new MySqlCommand(
"REPLACE INTO assets (name,description,assetType,local,temporary,data,id) VALUES " + "REPLACE INTO assets (name,description,assetType,local,temporary,data,id) VALUES " +
"(?name,?description,?assetType,?local,?temporary,?data,?id)", dbConnection); "(?name,?description,?assetType,?local,?temporary,?data,?id)", dbConnection);
command.Parameters.AddWithValue("?name", metadata.Name); command.Parameters.AddWithValue("?name", metadata.Name);
command.Parameters.AddWithValue("?description", metadata.Description); command.Parameters.AddWithValue("?description", metadata.Description);
command.Parameters.AddWithValue("?assetType", Utils.ContentTypeToSLAssetType(metadata.ContentType)); command.Parameters.AddWithValue("?assetType", Utils.ContentTypeToSLAssetType(metadata.ContentType));
command.Parameters.AddWithValue("?local", 0); command.Parameters.AddWithValue("?local", 0);
command.Parameters.AddWithValue("?temporary", metadata.Temporary); command.Parameters.AddWithValue("?temporary", metadata.Temporary);
command.Parameters.AddWithValue("?data", assetData); command.Parameters.AddWithValue("?data", assetData);
command.Parameters.AddWithValue("?id", metadata.ID.ToString()); command.Parameters.AddWithValue("?id", metadata.ID.ToString());
int rowsAffected = command.ExecuteNonQuery(); int rowsAffected = command.ExecuteNonQuery();
if (rowsAffected == 1) if (rowsAffected == 1)
{ {
ret = BackendResponse.Success; ret = BackendResponse.Success;
} }
else if (rowsAffected == 2) else if (rowsAffected == 2)
{ {
Logger.Log.Info("Replaced asset " + metadata.ID.ToString()); Logger.Log.Info("Replaced asset " + metadata.ID.ToString());
ret = BackendResponse.Success; ret = BackendResponse.Success;
} }
else else
{ {
Logger.Log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected); Logger.Log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected);
ret = BackendResponse.Failure; ret = BackendResponse.Failure;
} }
} }
catch (MySqlException ex) catch (MySqlException ex)
{ {
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message);
ret = BackendResponse.Failure; ret = BackendResponse.Failure;
} }
} }
server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, metadata.ID, assetData.Length, DateTime.Now); server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, metadata.ID, assetData.Length, DateTime.Now);
return ret; return ret;
} }
public int ForEach(Action<Metadata> action, int start, int count) public int ForEach(Action<Metadata> action, int start, int count)
{ {
int rowCount = 0; int rowCount = 0;
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
{ {
MySqlDataReader reader; MySqlDataReader reader;
try try
{ {
dbConnection.Open(); dbConnection.Open();
MySqlCommand command = dbConnection.CreateCommand(); MySqlCommand command = dbConnection.CreateCommand();
command.CommandText = String.Format("SELECT name,description,assetType,temporary,data,id FROM assets LIMIT {0}, {1}", command.CommandText = String.Format("SELECT name,description,assetType,temporary,data,id FROM assets LIMIT {0}, {1}",
start, count); start, count);
reader = command.ExecuteReader(); reader = command.ExecuteReader();
} }
catch (MySqlException ex) catch (MySqlException ex)
{ {
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message);
return 0; return 0;
} }
while (reader.Read()) while (reader.Read())
{ {
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
metadata.CreationDate = OpenMetaverse.Utils.Epoch; metadata.CreationDate = OpenMetaverse.Utils.Epoch;
metadata.Description = reader.GetString(1); metadata.Description = reader.GetString(1);
metadata.ID = UUID.Parse(reader.GetString(5)); metadata.ID = UUID.Parse(reader.GetString(5));
metadata.Name = reader.GetString(0); metadata.Name = reader.GetString(0);
metadata.SHA1 = OpenMetaverse.Utils.SHA1((byte[])reader.GetValue(4)); metadata.SHA1 = OpenMetaverse.Utils.SHA1((byte[])reader.GetValue(4));
metadata.Temporary = reader.GetBoolean(3); metadata.Temporary = reader.GetBoolean(3);
metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2));
action(metadata); action(metadata);
++rowCount; ++rowCount;
} }
reader.Close(); reader.Close();
} }
return rowCount; return rowCount;
} }
#endregion Required Interfaces #endregion Required Interfaces
} }
} }

View File

@ -1,239 +1,239 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Xml; using System.Xml;
using ExtensionLoader; using ExtensionLoader;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.StructuredData; using OpenMetaverse.StructuredData;
using HttpServer; using HttpServer;
namespace OpenSim.Grid.AssetInventoryServer.Extensions namespace OpenSim.Grid.AssetInventoryServer.Extensions
{ {
public class ReferenceFrontend : IExtension<AssetInventoryServer> public class ReferenceFrontend : IExtension<AssetInventoryServer>
{ {
AssetInventoryServer server; AssetInventoryServer server;
public ReferenceFrontend() public ReferenceFrontend()
{ {
} }
public void Start(AssetInventoryServer server) public void Start(AssetInventoryServer server)
{ {
this.server = server; this.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", 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); 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", 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); DataRequestHandler);
// Asset creation // Asset creation
server.HttpServer.AddHandler("post", null, "^/createasset", CreateRequestHandler); server.HttpServer.AddHandler("post", null, "^/createasset", CreateRequestHandler);
} }
public void Stop() public void Stop()
{ {
} }
bool MetadataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) bool MetadataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
{ {
UUID assetID; UUID assetID;
// Split the URL up into an AssetID and a method // Split the URL up into an AssetID and a method
string[] rawUrl = request.Uri.PathAndQuery.Split('/'); string[] rawUrl = request.Uri.PathAndQuery.Split('/');
if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID)) if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
{ {
UUID authToken = Utils.GetAuthToken(request); UUID authToken = Utils.GetAuthToken(request);
if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID)) if (server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID))
{ {
Metadata metadata; Metadata metadata;
BackendResponse storageResponse = server.StorageProvider.TryFetchMetadata(assetID, out metadata); BackendResponse storageResponse = server.StorageProvider.TryFetchMetadata(assetID, out metadata);
if (storageResponse == BackendResponse.Success) if (storageResponse == BackendResponse.Success)
{ {
// If the asset data location wasn't specified in the metadata, specify it // If the asset data location wasn't specified in the metadata, specify it
// manually here by pointing back to this asset server // manually here by pointing back to this asset server
if (!metadata.Methods.ContainsKey("data")) if (!metadata.Methods.ContainsKey("data"))
{ {
metadata.Methods["data"] = new Uri(String.Format("{0}://{1}/{2}/data", metadata.Methods["data"] = new Uri(String.Format("{0}://{1}/{2}/data",
request.Uri.Scheme, request.Uri.Authority, assetID)); request.Uri.Scheme, request.Uri.Authority, assetID));
} }
byte[] serializedData = metadata.SerializeToBytes(); byte[] serializedData = metadata.SerializeToBytes();
response.Status = HttpStatusCode.OK; response.Status = HttpStatusCode.OK;
response.ContentType = "application/json"; response.ContentType = "application/json";
response.ContentLength = serializedData.Length; response.ContentLength = serializedData.Length;
response.Body.Write(serializedData, 0, serializedData.Length); response.Body.Write(serializedData, 0, serializedData.Length);
} }
else if (storageResponse == BackendResponse.NotFound) else if (storageResponse == BackendResponse.NotFound)
{ {
Logger.Log.Warn("Could not find metadata for asset " + assetID.ToString()); Logger.Log.Warn("Could not find metadata for asset " + assetID.ToString());
response.Status = HttpStatusCode.NotFound; response.Status = HttpStatusCode.NotFound;
} }
else else
{ {
response.Status = HttpStatusCode.InternalServerError; response.Status = HttpStatusCode.InternalServerError;
} }
} }
else else
{ {
response.Status = HttpStatusCode.Forbidden; response.Status = HttpStatusCode.Forbidden;
} }
return true; return true;
} }
response.Status = HttpStatusCode.NotFound; response.Status = HttpStatusCode.NotFound;
return true; return true;
} }
bool DataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) bool DataRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
{ {
UUID assetID; UUID assetID;
// Split the URL up into an AssetID and a method // Split the URL up into an AssetID and a method
string[] rawUrl = request.Uri.PathAndQuery.Split('/'); string[] rawUrl = request.Uri.PathAndQuery.Split('/');
if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID)) if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
{ {
UUID authToken = Utils.GetAuthToken(request); UUID authToken = Utils.GetAuthToken(request);
if (server.AuthorizationProvider.IsDataAuthorized(authToken, assetID)) if (server.AuthorizationProvider.IsDataAuthorized(authToken, assetID))
{ {
byte[] assetData; byte[] assetData;
BackendResponse storageResponse = server.StorageProvider.TryFetchData(assetID, out assetData); BackendResponse storageResponse = server.StorageProvider.TryFetchData(assetID, out assetData);
if (storageResponse == BackendResponse.Success) if (storageResponse == BackendResponse.Success)
{ {
response.Status = HttpStatusCode.OK; response.Status = HttpStatusCode.OK;
response.Status = HttpStatusCode.OK; response.Status = HttpStatusCode.OK;
response.ContentType = "application/octet-stream"; response.ContentType = "application/octet-stream";
response.AddHeader("Content-Disposition", "attachment; filename=" + assetID.ToString()); response.AddHeader("Content-Disposition", "attachment; filename=" + assetID.ToString());
response.ContentLength = assetData.Length; response.ContentLength = assetData.Length;
response.Body.Write(assetData, 0, assetData.Length); response.Body.Write(assetData, 0, assetData.Length);
} }
else if (storageResponse == BackendResponse.NotFound) else if (storageResponse == BackendResponse.NotFound)
{ {
response.Status = HttpStatusCode.NotFound; response.Status = HttpStatusCode.NotFound;
} }
else else
{ {
response.Status = HttpStatusCode.InternalServerError; response.Status = HttpStatusCode.InternalServerError;
} }
} }
else else
{ {
response.Status = HttpStatusCode.Forbidden; response.Status = HttpStatusCode.Forbidden;
} }
return true; return true;
} }
response.Status = HttpStatusCode.BadRequest; response.Status = HttpStatusCode.BadRequest;
return true; return true;
} }
bool CreateRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) bool CreateRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
{ {
UUID authToken = Utils.GetAuthToken(request); UUID authToken = Utils.GetAuthToken(request);
if (server.AuthorizationProvider.IsCreateAuthorized(authToken)) if (server.AuthorizationProvider.IsCreateAuthorized(authToken))
{ {
try try
{ {
OSD osdata = OSDParser.DeserializeJson(request.Body); OSD osdata = OSDParser.DeserializeJson(request.Body);
if (osdata.Type == OSDType.Map) if (osdata.Type == OSDType.Map)
{ {
OSDMap map = (OSDMap)osdata; OSDMap map = (OSDMap)osdata;
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
metadata.Deserialize(map); metadata.Deserialize(map);
byte[] assetData = map["data"].AsBinary(); byte[] assetData = map["data"].AsBinary();
if (assetData != null && assetData.Length > 0) if (assetData != null && assetData.Length > 0)
{ {
BackendResponse storageResponse; BackendResponse storageResponse;
if (metadata.ID != UUID.Zero) if (metadata.ID != UUID.Zero)
storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData); storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData);
else else
storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID); storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID);
if (storageResponse == BackendResponse.Success) if (storageResponse == BackendResponse.Success)
{ {
response.Status = HttpStatusCode.Created; response.Status = HttpStatusCode.Created;
OSDMap responseMap = new OSDMap(1); OSDMap responseMap = new OSDMap(1);
responseMap["id"] = OSD.FromUUID(metadata.ID); responseMap["id"] = OSD.FromUUID(metadata.ID);
LitJson.JsonData jsonData = OSDParser.SerializeJson(responseMap); LitJson.JsonData jsonData = OSDParser.SerializeJson(responseMap);
byte[] responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson()); byte[] responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson());
response.Body.Write(responseData, 0, responseData.Length); response.Body.Write(responseData, 0, responseData.Length);
response.Body.Flush(); response.Body.Flush();
} }
else if (storageResponse == BackendResponse.NotFound) else if (storageResponse == BackendResponse.NotFound)
{ {
response.Status = HttpStatusCode.NotFound; response.Status = HttpStatusCode.NotFound;
} }
else else
{ {
response.Status = HttpStatusCode.InternalServerError; response.Status = HttpStatusCode.InternalServerError;
} }
} }
else else
{ {
response.Status = HttpStatusCode.BadRequest; response.Status = HttpStatusCode.BadRequest;
} }
} }
else else
{ {
response.Status = HttpStatusCode.BadRequest; response.Status = HttpStatusCode.BadRequest;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
response.Status = HttpStatusCode.InternalServerError; response.Status = HttpStatusCode.InternalServerError;
response.Reason = ex.Message; response.Reason = ex.Message;
} }
} }
else else
{ {
response.Status = HttpStatusCode.Forbidden; response.Status = HttpStatusCode.Forbidden;
} }
return true; return true;
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,260 +1,260 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.IO; using System.IO;
using ExtensionLoader; using ExtensionLoader;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.StructuredData; using OpenMetaverse.StructuredData;
namespace OpenSim.Grid.AssetInventoryServer.Extensions namespace OpenSim.Grid.AssetInventoryServer.Extensions
{ {
public class SimpleStorage : IExtension<AssetInventoryServer>, IStorageProvider public class SimpleStorage : IExtension<AssetInventoryServer>, IStorageProvider
{ {
const string EXTENSION_NAME = ""; // Used in metrics reporting const string EXTENSION_NAME = ""; // Used in metrics reporting
const string DEFAULT_DATA_DIR = "SimpleAssets"; const string DEFAULT_DATA_DIR = "SimpleAssets";
const string TEMP_DATA_DIR = "SimpleAssetsTemp"; const string TEMP_DATA_DIR = "SimpleAssetsTemp";
AssetInventoryServer server; AssetInventoryServer server;
Dictionary<UUID, Metadata> metadataStorage; Dictionary<UUID, Metadata> metadataStorage;
Dictionary<UUID, string> filenames; Dictionary<UUID, string> filenames;
public SimpleStorage() public SimpleStorage()
{ {
} }
#region Required Interfaces #region Required Interfaces
public void Start(AssetInventoryServer server) public void Start(AssetInventoryServer server)
{ {
this.server = server; this.server = server;
metadataStorage = new Dictionary<UUID, Metadata>(); metadataStorage = new Dictionary<UUID, Metadata>();
filenames = new Dictionary<UUID, string>(); filenames = new Dictionary<UUID, string>();
LoadFiles(DEFAULT_DATA_DIR, false); LoadFiles(DEFAULT_DATA_DIR, false);
LoadFiles(TEMP_DATA_DIR, true); LoadFiles(TEMP_DATA_DIR, true);
Logger.Log.InfoFormat("Initialized the store index with metadata for {0} assets", Logger.Log.InfoFormat("Initialized the store index with metadata for {0} assets",
metadataStorage.Count); metadataStorage.Count);
} }
public void Stop() public void Stop()
{ {
WipeTemporary(); WipeTemporary();
} }
public BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata) public BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata)
{ {
metadata = null; metadata = null;
BackendResponse ret; BackendResponse ret;
if (metadataStorage.TryGetValue(assetID, out metadata)) if (metadataStorage.TryGetValue(assetID, out metadata))
ret = BackendResponse.Success; ret = BackendResponse.Success;
else else
ret = BackendResponse.NotFound; ret = BackendResponse.NotFound;
server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
return ret; return ret;
} }
public BackendResponse TryFetchData(UUID assetID, out byte[] assetData) public BackendResponse TryFetchData(UUID assetID, out byte[] assetData)
{ {
assetData = null; assetData = null;
string filename; string filename;
BackendResponse ret; BackendResponse ret;
if (filenames.TryGetValue(assetID, out filename)) if (filenames.TryGetValue(assetID, out filename))
{ {
try try
{ {
assetData = File.ReadAllBytes(filename); assetData = File.ReadAllBytes(filename);
ret = BackendResponse.Success; ret = BackendResponse.Success;
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Log.ErrorFormat("Failed reading data for asset {0} from {1}: {2}", assetID, filename, ex.Message); Logger.Log.ErrorFormat("Failed reading data for asset {0} from {1}: {2}", assetID, filename, ex.Message);
ret = BackendResponse.Failure; ret = BackendResponse.Failure;
} }
} }
else else
{ {
ret = BackendResponse.NotFound; ret = BackendResponse.NotFound;
} }
server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now); server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now);
return ret; return ret;
} }
public BackendResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData) public BackendResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData)
{ {
metadata = null; metadata = null;
assetData = null; assetData = null;
string filename; string filename;
BackendResponse ret; BackendResponse ret;
if (metadataStorage.TryGetValue(assetID, out metadata) && if (metadataStorage.TryGetValue(assetID, out metadata) &&
filenames.TryGetValue(assetID, out filename)) filenames.TryGetValue(assetID, out filename))
{ {
try try
{ {
assetData = File.ReadAllBytes(filename); assetData = File.ReadAllBytes(filename);
ret = BackendResponse.Success; ret = BackendResponse.Success;
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Log.ErrorFormat("Failed reading data for asset {0} from {1}: {2}", assetID, filename, ex.Message); Logger.Log.ErrorFormat("Failed reading data for asset {0} from {1}: {2}", assetID, filename, ex.Message);
ret = BackendResponse.Failure; ret = BackendResponse.Failure;
} }
} }
else else
{ {
ret = BackendResponse.NotFound; ret = BackendResponse.NotFound;
} }
server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now); server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now);
return ret; return ret;
} }
public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID) public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID)
{ {
assetID = metadata.ID = UUID.Random(); assetID = metadata.ID = UUID.Random();
return TryCreateAsset(metadata, assetData); return TryCreateAsset(metadata, assetData);
} }
public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData) public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData)
{ {
BackendResponse ret; BackendResponse ret;
string path; string path;
string filename = String.Format("{0}.{1}", metadata.ID, Utils.ContentTypeToExtension(metadata.ContentType)); string filename = String.Format("{0}.{1}", metadata.ID, Utils.ContentTypeToExtension(metadata.ContentType));
if (metadata.Temporary) if (metadata.Temporary)
path = Path.Combine(TEMP_DATA_DIR, filename); path = Path.Combine(TEMP_DATA_DIR, filename);
else else
path = Path.Combine(DEFAULT_DATA_DIR, filename); path = Path.Combine(DEFAULT_DATA_DIR, filename);
try try
{ {
File.WriteAllBytes(path, assetData); File.WriteAllBytes(path, assetData);
lock (filenames) filenames[metadata.ID] = path; lock (filenames) filenames[metadata.ID] = path;
// Set the creation date to right now // Set the creation date to right now
metadata.CreationDate = DateTime.Now; metadata.CreationDate = DateTime.Now;
lock (metadataStorage) lock (metadataStorage)
metadataStorage[metadata.ID] = metadata; metadataStorage[metadata.ID] = metadata;
ret = BackendResponse.Success; ret = BackendResponse.Success;
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Log.ErrorFormat("Failed writing data for asset {0} to {1}: {2}", metadata.ID, filename, ex.Message); Logger.Log.ErrorFormat("Failed writing data for asset {0} to {1}: {2}", metadata.ID, filename, ex.Message);
ret = BackendResponse.Failure; ret = BackendResponse.Failure;
} }
server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, metadata.ID, assetData.Length, DateTime.Now); server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, metadata.ID, assetData.Length, DateTime.Now);
return ret; return ret;
} }
public int ForEach(Action<Metadata> action, int start, int count) public int ForEach(Action<Metadata> action, int start, int count)
{ {
int rowCount = 0; int rowCount = 0;
lock (metadataStorage) lock (metadataStorage)
{ {
foreach (Metadata metadata in metadataStorage.Values) foreach (Metadata metadata in metadataStorage.Values)
{ {
action(metadata); action(metadata);
++rowCount; ++rowCount;
} }
} }
return rowCount; return rowCount;
} }
#endregion Required Interfaces #endregion Required Interfaces
public void WipeTemporary() public void WipeTemporary()
{ {
if (Directory.Exists(TEMP_DATA_DIR)) if (Directory.Exists(TEMP_DATA_DIR))
{ {
try { Directory.Delete(TEMP_DATA_DIR); } try { Directory.Delete(TEMP_DATA_DIR); }
catch (Exception ex) { Logger.Log.Error(ex.Message); } catch (Exception ex) { Logger.Log.Error(ex.Message); }
} }
} }
void LoadFiles(string folder, bool temporary) void LoadFiles(string folder, bool temporary)
{ {
// Try to create the directory if it doesn't already exist // Try to create the directory if it doesn't already exist
if (!Directory.Exists(folder)) if (!Directory.Exists(folder))
{ {
try { Directory.CreateDirectory(folder); } try { Directory.CreateDirectory(folder); }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Log.Warn(ex.Message); Logger.Log.Warn(ex.Message);
return; return;
} }
} }
lock (metadataStorage) lock (metadataStorage)
{ {
try try
{ {
string[] assets = Directory.GetFiles(folder); string[] assets = Directory.GetFiles(folder);
for (int i = 0; i < assets.Length; i++) for (int i = 0; i < assets.Length; i++)
{ {
string filename = assets[i]; string filename = assets[i];
byte[] data = File.ReadAllBytes(filename); byte[] data = File.ReadAllBytes(filename);
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
metadata.CreationDate = File.GetCreationTime(filename); metadata.CreationDate = File.GetCreationTime(filename);
metadata.Description = String.Empty; metadata.Description = String.Empty;
metadata.ID = SimpleUtils.ParseUUIDFromFilename(filename); metadata.ID = SimpleUtils.ParseUUIDFromFilename(filename);
metadata.Name = SimpleUtils.ParseNameFromFilename(filename); metadata.Name = SimpleUtils.ParseNameFromFilename(filename);
metadata.SHA1 = OpenMetaverse.Utils.SHA1(data); metadata.SHA1 = OpenMetaverse.Utils.SHA1(data);
metadata.Temporary = false; metadata.Temporary = false;
metadata.ContentType = Utils.ExtensionToContentType(Path.GetExtension(filename).TrimStart('.')); metadata.ContentType = Utils.ExtensionToContentType(Path.GetExtension(filename).TrimStart('.'));
// Store the loaded data // Store the loaded data
metadataStorage[metadata.ID] = metadata; metadataStorage[metadata.ID] = metadata;
filenames[metadata.ID] = filename; filenames[metadata.ID] = filename;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Log.Warn(ex.Message); Logger.Log.Warn(ex.Message);
} }
} }
} }
} }
} }

View File

@ -1,44 +1,44 @@
using System; using System;
using System.IO; using System.IO;
using OpenMetaverse; using OpenMetaverse;
namespace OpenSim.Grid.AssetInventoryServer.Extensions namespace OpenSim.Grid.AssetInventoryServer.Extensions
{ {
public static class SimpleUtils public static class SimpleUtils
{ {
public static string ParseNameFromFilename(string filename) public static string ParseNameFromFilename(string filename)
{ {
filename = Path.GetFileName(filename); filename = Path.GetFileName(filename);
int dot = filename.LastIndexOf('.'); int dot = filename.LastIndexOf('.');
int firstDash = filename.IndexOf('-'); int firstDash = filename.IndexOf('-');
if (dot - 37 > 0 && firstDash > 0) if (dot - 37 > 0 && firstDash > 0)
return filename.Substring(0, firstDash); return filename.Substring(0, firstDash);
else else
return String.Empty; return String.Empty;
} }
public static UUID ParseUUIDFromFilename(string filename) public static UUID ParseUUIDFromFilename(string filename)
{ {
int dot = filename.LastIndexOf('.'); int dot = filename.LastIndexOf('.');
if (dot > 35) if (dot > 35)
{ {
// Grab the last 36 characters of the filename // Grab the last 36 characters of the filename
string uuidString = filename.Substring(dot - 36, 36); string uuidString = filename.Substring(dot - 36, 36);
UUID uuid; UUID uuid;
UUID.TryParse(uuidString, out uuid); UUID.TryParse(uuidString, out uuid);
return uuid; return uuid;
} }
else else
{ {
UUID uuid; UUID uuid;
if (UUID.TryParse(Path.GetFileName(filename), out uuid)) if (UUID.TryParse(Path.GetFileName(filename), out uuid))
return uuid; return uuid;
else else
return UUID.Zero; return UUID.Zero;
} }
} }
} }
} }

View File

@ -1,157 +1,157 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.StructuredData; using OpenMetaverse.StructuredData;
using OpenSim.Framework; using OpenSim.Framework;
namespace OpenSim.Grid.AssetInventoryServer namespace OpenSim.Grid.AssetInventoryServer
{ {
/// <summary> /// <summary>
/// Response from a call to a backend provider /// Response from a call to a backend provider
/// </summary> /// </summary>
public enum BackendResponse public enum BackendResponse
{ {
/// <summary>The call succeeded</summary> /// <summary>The call succeeded</summary>
Success, Success,
/// <summary>The resource requested was not found</summary> /// <summary>The resource requested was not found</summary>
NotFound, NotFound,
/// <summary>A server failure prevented the call from /// <summary>A server failure prevented the call from
/// completing</summary> /// completing</summary>
Failure Failure
} }
public class AssetInventoryServerPluginInitialiser : PluginInitialiserBase public class AssetInventoryServerPluginInitialiser : PluginInitialiserBase
{ {
private AssetInventoryServer server; private AssetInventoryServer server;
public AssetInventoryServerPluginInitialiser (AssetInventoryServer server) public AssetInventoryServerPluginInitialiser (AssetInventoryServer server)
{ {
this.server = server; this.server = server;
} }
public override void Initialise (IPlugin plugin) public override void Initialise (IPlugin plugin)
{ {
IAssetInventoryServerPlugin p = plugin as IAssetInventoryServerPlugin; IAssetInventoryServerPlugin p = plugin as IAssetInventoryServerPlugin;
p.Initialise (server); p.Initialise (server);
} }
} }
#region Interfaces #region Interfaces
public interface IAssetInventoryServerPlugin : IPlugin public interface IAssetInventoryServerPlugin : IPlugin
{ {
void Initialise(AssetInventoryServer server); void Initialise(AssetInventoryServer server);
} }
public interface IStorageProvider public interface IStorageProvider
{ {
BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata); BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata);
BackendResponse TryFetchData(UUID assetID, out byte[] assetData); BackendResponse TryFetchData(UUID assetID, out byte[] assetData);
BackendResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData); BackendResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData);
BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData); BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData);
BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID); BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID);
int ForEach(Action<Metadata> action, int start, int count); int ForEach(Action<Metadata> action, int start, int count);
} }
public interface IAssetStorageProvider : IAssetInventoryServerPlugin public interface IAssetStorageProvider : IAssetInventoryServerPlugin
{ {
BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata); BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata);
BackendResponse TryFetchData(UUID assetID, out byte[] assetData); BackendResponse TryFetchData(UUID assetID, out byte[] assetData);
BackendResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData); BackendResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData);
BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData); BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData);
BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID); BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID);
int ForEach(Action<Metadata> action, int start, int count); int ForEach(Action<Metadata> action, int start, int count);
} }
public interface IInventoryProvider public interface IInventoryProvider
{ {
BackendResponse TryFetchItem(Uri owner, UUID itemID, out InventoryItem item); BackendResponse TryFetchItem(Uri owner, UUID itemID, out InventoryItem item);
BackendResponse TryFetchFolder(Uri owner, UUID folderID, out InventoryFolder folder); BackendResponse TryFetchFolder(Uri owner, UUID folderID, out InventoryFolder folder);
BackendResponse TryFetchFolderContents(Uri owner, UUID folderID, out InventoryCollection contents); BackendResponse TryFetchFolderContents(Uri owner, UUID folderID, out InventoryCollection contents);
BackendResponse TryFetchFolderList(Uri owner, out List<InventoryFolder> folders); BackendResponse TryFetchFolderList(Uri owner, out List<InventoryFolder> folders);
BackendResponse TryFetchInventory(Uri owner, out InventoryCollection inventory); BackendResponse TryFetchInventory(Uri owner, out InventoryCollection inventory);
BackendResponse TryFetchActiveGestures(Uri owner, out List<InventoryItem> gestures); BackendResponse TryFetchActiveGestures(Uri owner, out List<InventoryItem> gestures);
BackendResponse TryCreateItem(Uri owner, InventoryItem item); BackendResponse TryCreateItem(Uri owner, InventoryItem item);
BackendResponse TryCreateFolder(Uri owner, InventoryFolder folder); BackendResponse TryCreateFolder(Uri owner, InventoryFolder folder);
BackendResponse TryCreateInventory(Uri owner, InventoryFolder rootFolder); BackendResponse TryCreateInventory(Uri owner, InventoryFolder rootFolder);
BackendResponse TryDeleteItem(Uri owner, UUID itemID); BackendResponse TryDeleteItem(Uri owner, UUID itemID);
BackendResponse TryDeleteFolder(Uri owner, UUID folderID); BackendResponse TryDeleteFolder(Uri owner, UUID folderID);
BackendResponse TryPurgeFolder(Uri owner, UUID folderID); BackendResponse TryPurgeFolder(Uri owner, UUID folderID);
} }
public interface IAuthenticationProvider public interface IAuthenticationProvider
{ {
void AddIdentifier(UUID authToken, Uri identifier); void AddIdentifier(UUID authToken, Uri identifier);
bool RemoveIdentifier(UUID authToken); bool RemoveIdentifier(UUID authToken);
bool TryGetIdentifier(UUID authToken, out Uri identifier); bool TryGetIdentifier(UUID authToken, out Uri identifier);
} }
public interface IAuthorizationProvider public interface IAuthorizationProvider
{ {
bool IsMetadataAuthorized(UUID authToken, UUID assetID); bool IsMetadataAuthorized(UUID authToken, UUID assetID);
/// <summary> /// <summary>
/// Authorizes access to the data for an asset. Access to asset data /// Authorizes access to the data for an asset. Access to asset data
/// also implies access to the metadata for that asset /// also implies access to the metadata for that asset
/// </summary> /// </summary>
/// <param name="authToken">Authentication token to check for access</param> /// <param name="authToken">Authentication token to check for access</param>
/// <param name="assetID">ID of the requested asset</param> /// <param name="assetID">ID of the requested asset</param>
/// <returns>True if access is granted, otherwise false</returns> /// <returns>True if access is granted, otherwise false</returns>
bool IsDataAuthorized(UUID authToken, UUID assetID); bool IsDataAuthorized(UUID authToken, UUID assetID);
bool IsCreateAuthorized(UUID authToken); bool IsCreateAuthorized(UUID authToken);
bool IsInventoryReadAuthorized(UUID authToken, Uri owner); bool IsInventoryReadAuthorized(UUID authToken, Uri owner);
bool IsInventoryWriteAuthorized(UUID authToken, Uri owner); bool IsInventoryWriteAuthorized(UUID authToken, Uri owner);
} }
public interface IMetricsProvider public interface IMetricsProvider
{ {
void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time); void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time);
void LogAssetDataFetch(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time); void LogAssetDataFetch(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time);
void LogAssetCreate(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time); void LogAssetCreate(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time);
void LogInventoryFetch(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time); void LogInventoryFetch(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time);
void LogInventoryFetchFolderContents(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time); void LogInventoryFetchFolderContents(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time);
void LogInventoryFetchFolderList(string extension, BackendResponse response, Uri owner, DateTime time); void LogInventoryFetchFolderList(string extension, BackendResponse response, Uri owner, DateTime time);
void LogInventoryFetchInventory(string extension, BackendResponse response, Uri owner, DateTime time); void LogInventoryFetchInventory(string extension, BackendResponse response, Uri owner, DateTime time);
void LogInventoryFetchActiveGestures(string extension, BackendResponse response, Uri owner, DateTime time); void LogInventoryFetchActiveGestures(string extension, BackendResponse response, Uri owner, DateTime time);
void LogInventoryCreate(string extension, BackendResponse response, Uri owner, bool folder, DateTime time); void LogInventoryCreate(string extension, BackendResponse response, Uri owner, bool folder, DateTime time);
void LogInventoryCreateInventory(string extension, BackendResponse response, DateTime time); void LogInventoryCreateInventory(string extension, BackendResponse response, DateTime time);
void LogInventoryDelete(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time); void LogInventoryDelete(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time);
void LogInventoryPurgeFolder(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time); void LogInventoryPurgeFolder(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time);
} }
#endregion Interfaces #endregion Interfaces
} }

View File

@ -1,107 +1,107 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenMetaverse; using OpenMetaverse;
namespace OpenSim.Grid.AssetInventoryServer namespace OpenSim.Grid.AssetInventoryServer
{ {
public class InventoryBase public class InventoryBase
{ {
} }
public class InventoryFolder : InventoryBase public class InventoryFolder : InventoryBase
{ {
public string Name; public string Name;
public UUID Owner; public UUID Owner;
public UUID ParentID; public UUID ParentID;
public UUID ID; public UUID ID;
public short Type; public short Type;
public ushort Version; public ushort Version;
[NonSerialized] [NonSerialized]
public Dictionary<UUID, InventoryBase> Children = new Dictionary<UUID, InventoryBase>(); public Dictionary<UUID, InventoryBase> Children = new Dictionary<UUID, InventoryBase>();
public InventoryFolder() public InventoryFolder()
{ {
} }
public InventoryFolder(string name, UUID ownerID, UUID parentID, short assetType) public InventoryFolder(string name, UUID ownerID, UUID parentID, short assetType)
{ {
ID = UUID.Random(); ID = UUID.Random();
Name = name; Name = name;
Owner = ownerID; Owner = ownerID;
ParentID = parentID; ParentID = parentID;
Type = assetType; Type = assetType;
Version = 1; Version = 1;
} }
public override string ToString() public override string ToString()
{ {
return String.Format("{0} ({1})", Name, ID); return String.Format("{0} ({1})", Name, ID);
} }
} }
public class InventoryItem : InventoryBase public class InventoryItem : InventoryBase
{ {
public UUID ID; public UUID ID;
public int InvType; public int InvType;
public UUID Folder; public UUID Folder;
public UUID Owner; public UUID Owner;
public UUID Creator; public UUID Creator;
public string Name; public string Name;
public string Description; public string Description;
public uint NextPermissions; public uint NextPermissions;
public uint CurrentPermissions; public uint CurrentPermissions;
public uint BasePermissions; public uint BasePermissions;
public uint EveryOnePermissions; public uint EveryOnePermissions;
public uint GroupPermissions; public uint GroupPermissions;
public int AssetType; public int AssetType;
public UUID AssetID; public UUID AssetID;
public UUID GroupID; public UUID GroupID;
public bool GroupOwned; public bool GroupOwned;
public int SalePrice; public int SalePrice;
public byte SaleType; public byte SaleType;
public uint Flags; public uint Flags;
public int CreationDate; public int CreationDate;
public override string ToString() public override string ToString()
{ {
return String.Format("{0} ({1})", Name, ID); return String.Format("{0} ({1})", Name, ID);
} }
} }
public class InventoryCollection public class InventoryCollection
{ {
public Dictionary<UUID, InventoryFolder> Folders; public Dictionary<UUID, InventoryFolder> Folders;
public Dictionary<UUID, InventoryItem> Items; public Dictionary<UUID, InventoryItem> Items;
public UUID UserID; public UUID UserID;
} }
} }

View File

@ -1,62 +1,62 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using log4net; using log4net;
using log4net.Config; using log4net.Config;
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "log4net")] [assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "log4net")]
namespace OpenSim.Grid.AssetInventoryServer namespace OpenSim.Grid.AssetInventoryServer
{ {
/// <summary> /// <summary>
/// Singleton logging class for the entire library /// Singleton logging class for the entire library
/// </summary> /// </summary>
public static class Logger public static class Logger
{ {
/// <summary>log4net logging engine</summary> /// <summary>log4net logging engine</summary>
public static ILog Log; public static ILog Log;
static Logger() static Logger()
{ {
Log = LogManager.GetLogger(System.Reflection.Assembly.GetExecutingAssembly().FullName); Log = LogManager.GetLogger(System.Reflection.Assembly.GetExecutingAssembly().FullName);
// If error level reporting isn't enabled we assume no logger is configured and initialize a default // If error level reporting isn't enabled we assume no logger is configured and initialize a default
// ConsoleAppender // ConsoleAppender
if (!Log.Logger.IsEnabledFor(log4net.Core.Level.Error)) if (!Log.Logger.IsEnabledFor(log4net.Core.Level.Error))
{ {
log4net.Appender.ConsoleAppender appender = new log4net.Appender.ConsoleAppender(); log4net.Appender.ConsoleAppender appender = new log4net.Appender.ConsoleAppender();
appender.Layout = new log4net.Layout.PatternLayout("%timestamp [%thread] %-5level - %message%newline"); appender.Layout = new log4net.Layout.PatternLayout("%timestamp [%thread] %-5level - %message%newline");
BasicConfigurator.Configure(appender); BasicConfigurator.Configure(appender);
Log.Info("No log configuration found, defaulting to console logging"); Log.Info("No log configuration found, defaulting to console logging");
} }
} }
} }
} }

View File

@ -1,62 +1,62 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.ServiceProcess; using System.ServiceProcess;
namespace OpenSim.Grid.AssetInventoryServer namespace OpenSim.Grid.AssetInventoryServer
{ {
class MainEntry class MainEntry
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
#if DEBUG #if DEBUG
AssetInventoryServer server = new AssetInventoryServer(); AssetInventoryServer server = new AssetInventoryServer();
if (server.Start()) if (server.Start())
{ {
Console.WriteLine("Asset server is running. Press CTRL+C to quit"); Console.WriteLine("Asset server is running. Press CTRL+C to quit");
Console.CancelKeyPress += Console.CancelKeyPress +=
delegate(object sender, ConsoleCancelEventArgs e) delegate(object sender, ConsoleCancelEventArgs e)
{ {
Console.WriteLine("Asset server is shutting down..."); Console.WriteLine("Asset server is shutting down...");
server.Shutdown(); server.Shutdown();
Environment.Exit(0); Environment.Exit(0);
}; };
while (true) while (true)
Console.ReadLine(); Console.ReadLine();
} }
#else #else
ServiceBase[] servicesToRun = new ServiceBase[] { new AssetInventoryServer() }; ServiceBase[] servicesToRun = new ServiceBase[] { new AssetInventoryServer() };
ServiceBase.Run(servicesToRun); ServiceBase.Run(servicesToRun);
#endif #endif
} }
} }
} }

View File

@ -1,85 +1,85 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Xml; using System.Xml;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.StructuredData; using OpenMetaverse.StructuredData;
namespace OpenSim.Grid.AssetInventoryServer namespace OpenSim.Grid.AssetInventoryServer
{ {
public class Metadata public class Metadata
{ {
public UUID ID; public UUID ID;
public string Name; public string Name;
public string Description; public string Description;
public DateTime CreationDate; public DateTime CreationDate;
public string ContentType; public string ContentType;
public byte[] SHA1; public byte[] SHA1;
public bool Temporary; public bool Temporary;
public Dictionary<string, Uri> Methods = new Dictionary<string, Uri>(); public Dictionary<string, Uri> Methods = new Dictionary<string, Uri>();
public OSDMap ExtraData; public OSDMap ExtraData;
public OSDMap SerializeToOSD() public OSDMap SerializeToOSD()
{ {
OSDMap osdata = new OSDMap(); OSDMap osdata = new OSDMap();
if (ID != UUID.Zero) osdata["id"] = OSD.FromUUID(ID); if (ID != UUID.Zero) osdata["id"] = OSD.FromUUID(ID);
osdata["name"] = OSD.FromString(Name); osdata["name"] = OSD.FromString(Name);
osdata["description"] = OSD.FromString(Description); osdata["description"] = OSD.FromString(Description);
osdata["creation_date"] = OSD.FromDate(CreationDate); osdata["creation_date"] = OSD.FromDate(CreationDate);
osdata["type"] = OSD.FromString(ContentType); osdata["type"] = OSD.FromString(ContentType);
osdata["sha1"] = OSD.FromBinary(SHA1); osdata["sha1"] = OSD.FromBinary(SHA1);
osdata["temporary"] = OSD.FromBoolean(Temporary); osdata["temporary"] = OSD.FromBoolean(Temporary);
OSDMap methods = new OSDMap(Methods.Count); OSDMap methods = new OSDMap(Methods.Count);
foreach (KeyValuePair<string, Uri> kvp in Methods) foreach (KeyValuePair<string, Uri> kvp in Methods)
methods.Add(kvp.Key, OSD.FromUri(kvp.Value)); methods.Add(kvp.Key, OSD.FromUri(kvp.Value));
osdata["methods"] = methods; osdata["methods"] = methods;
if (ExtraData != null) osdata["extra_data"] = ExtraData; if (ExtraData != null) osdata["extra_data"] = ExtraData;
return osdata; return osdata;
} }
public byte[] SerializeToBytes() public byte[] SerializeToBytes()
{ {
LitJson.JsonData jsonData = OSDParser.SerializeJson(SerializeToOSD()); LitJson.JsonData jsonData = OSDParser.SerializeJson(SerializeToOSD());
return System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson()); return System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson());
} }
public void Deserialize(byte[] data) public void Deserialize(byte[] data)
{ {
OSD osdata = OSDParser.DeserializeJson(System.Text.Encoding.UTF8.GetString(data)); OSD osdata = OSDParser.DeserializeJson(System.Text.Encoding.UTF8.GetString(data));
Deserialize(osdata); Deserialize(osdata);
} }
public void Deserialize(string data) public void Deserialize(string data)
{ {
OSD osdata = OSDParser.DeserializeJson(data); OSD osdata = OSDParser.DeserializeJson(data);
Deserialize(osdata); Deserialize(osdata);
} }
public void Deserialize(OSD osdata) public void Deserialize(OSD osdata)
{ {
if (osdata.Type == OSDType.Map) if (osdata.Type == OSDType.Map)
{ {
OSDMap map = (OSDMap)osdata; OSDMap map = (OSDMap)osdata;
ID = map["id"].AsUUID(); ID = map["id"].AsUUID();
Name = map["name"].AsString(); Name = map["name"].AsString();
Description = map["description"].AsString(); Description = map["description"].AsString();
CreationDate = map["creation_date"].AsDate(); CreationDate = map["creation_date"].AsDate();
ContentType = map["type"].AsString(); ContentType = map["type"].AsString();
SHA1 = map["sha1"].AsBinary(); SHA1 = map["sha1"].AsBinary();
Temporary = map["temporary"].AsBoolean(); Temporary = map["temporary"].AsBoolean();
OSDMap methods = map["methods"] as OSDMap; OSDMap methods = map["methods"] as OSDMap;
if (methods != null) if (methods != null)
{ {
foreach (KeyValuePair<string, OSD> kvp in methods) foreach (KeyValuePair<string, OSD> kvp in methods)
Methods.Add(kvp.Key, kvp.Value.AsUri()); Methods.Add(kvp.Key, kvp.Value.AsUri());
} }
ExtraData = map["extra_data"] as OSDMap; ExtraData = map["extra_data"] as OSDMap;
} }
} }
} }
} }

View File

@ -1,240 +1,240 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.IO; using System.IO;
using System.Xml; using System.Xml;
using ExtensionLoader; using ExtensionLoader;
using OpenMetaverse; using OpenMetaverse;
using HttpServer; using HttpServer;
using OpenSim.Framework; using OpenSim.Framework;
namespace OpenSim.Grid.AssetInventoryServer.Plugins namespace OpenSim.Grid.AssetInventoryServer.Plugins
{ {
public class OpenSimAssetFrontendPlugin : IAssetInventoryServerPlugin public class OpenSimAssetFrontendPlugin : IAssetInventoryServerPlugin
{ {
AssetInventoryServer server; AssetInventoryServer server;
public OpenSimAssetFrontendPlugin() public OpenSimAssetFrontendPlugin()
{ {
} }
#region IPlugin implementation #region IPlugin implementation
public void Initialise(AssetInventoryServer server) public void Initialise(AssetInventoryServer server)
{ {
this.server = server; this.server = server;
// Asset request // Asset request
server.HttpServer.AddHandler("get", null, @"^/assets/", AssetRequestHandler); server.HttpServer.AddHandler("get", null, @"^/assets/", AssetRequestHandler);
// Asset creation // Asset creation
server.HttpServer.AddHandler("post", null, @"^/assets/", AssetPostHandler); server.HttpServer.AddHandler("post", null, @"^/assets/", AssetPostHandler);
} }
/// <summary> /// <summary>
/// <para>Initialises asset interface</para> /// <para>Initialises asset interface</para>
/// </summary> /// </summary>
public void Initialise() public void Initialise()
{ {
Logger.Log.InfoFormat("[ASSET]: {0} cannot be default-initialized!", Name); Logger.Log.InfoFormat("[ASSET]: {0} cannot be default-initialized!", Name);
throw new PluginNotInitialisedException(Name); throw new PluginNotInitialisedException(Name);
} }
public void Dispose() public void Dispose()
{ {
} }
public string Version public string Version
{ {
// TODO: this should be something meaningful and not hardcoded? // TODO: this should be something meaningful and not hardcoded?
get { return "0.1"; } get { return "0.1"; }
} }
public string Name public string Name
{ {
get { return "AssetInventoryServer OpenSim asset frontend"; } get { return "AssetInventoryServer OpenSim asset frontend"; }
} }
#endregion IPlugin implementation #endregion IPlugin implementation
bool AssetRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) bool AssetRequestHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
{ {
UUID assetID; UUID assetID;
// Split the URL up to get the asset ID out // Split the URL up to get the asset ID out
string[] rawUrl = request.Uri.PathAndQuery.Split('/'); string[] rawUrl = request.Uri.PathAndQuery.Split('/');
if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out assetID)) if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out assetID))
{ {
Metadata metadata; Metadata metadata;
byte[] assetData; byte[] assetData;
BackendResponse dataResponse; BackendResponse dataResponse;
if ((dataResponse = server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success) if ((dataResponse = server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success)
{ {
MemoryStream stream = new MemoryStream(); MemoryStream stream = new MemoryStream();
XmlWriterSettings settings = new XmlWriterSettings(); XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true; settings.Indent = true;
XmlWriter writer = XmlWriter.Create(stream, settings); XmlWriter writer = XmlWriter.Create(stream, settings);
writer.WriteStartDocument(); writer.WriteStartDocument();
writer.WriteStartElement("AssetBase"); writer.WriteStartElement("AssetBase");
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
writer.WriteStartElement("FullID"); writer.WriteStartElement("FullID");
writer.WriteStartElement("Guid"); writer.WriteStartElement("Guid");
writer.WriteString(assetID.ToString()); writer.WriteString(assetID.ToString());
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteStartElement("ID"); writer.WriteStartElement("ID");
writer.WriteString(assetID.ToString()); writer.WriteString(assetID.ToString());
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteStartElement("Data"); writer.WriteStartElement("Data");
writer.WriteBase64(assetData, 0, assetData.Length); writer.WriteBase64(assetData, 0, assetData.Length);
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteStartElement("Type"); writer.WriteStartElement("Type");
writer.WriteValue(Utils.ContentTypeToSLAssetType(metadata.ContentType)); writer.WriteValue(Utils.ContentTypeToSLAssetType(metadata.ContentType));
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteStartElement("Name"); writer.WriteStartElement("Name");
writer.WriteString(metadata.Name); writer.WriteString(metadata.Name);
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteStartElement("Description"); writer.WriteStartElement("Description");
writer.WriteString(metadata.Description); writer.WriteString(metadata.Description);
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteStartElement("Local"); writer.WriteStartElement("Local");
writer.WriteValue(false); writer.WriteValue(false);
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteStartElement("Temporary"); writer.WriteStartElement("Temporary");
writer.WriteValue(metadata.Temporary); writer.WriteValue(metadata.Temporary);
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteEndDocument(); writer.WriteEndDocument();
writer.Flush(); writer.Flush();
byte[] buffer = stream.GetBuffer(); byte[] buffer = stream.GetBuffer();
response.Status = HttpStatusCode.OK; response.Status = HttpStatusCode.OK;
response.ContentType = "application/xml"; response.ContentType = "application/xml";
response.ContentLength = stream.Length; response.ContentLength = stream.Length;
response.Body.Write(buffer, 0, (int)stream.Length); response.Body.Write(buffer, 0, (int)stream.Length);
response.Body.Flush(); response.Body.Flush();
} }
else else
{ {
Logger.Log.WarnFormat("Failed to fetch asset data or metadata for {0}: {1}", assetID, dataResponse); Logger.Log.WarnFormat("Failed to fetch asset data or metadata for {0}: {1}", assetID, dataResponse);
response.Status = HttpStatusCode.NotFound; response.Status = HttpStatusCode.NotFound;
} }
} }
else else
{ {
Logger.Log.Warn("Unrecognized OpenSim asset request: " + request.Uri.PathAndQuery); Logger.Log.Warn("Unrecognized OpenSim asset request: " + request.Uri.PathAndQuery);
} }
return true; return true;
} }
bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response) bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
{ {
byte[] assetData = null; byte[] assetData = null;
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
Logger.Log.Debug("Handling OpenSim asset upload"); Logger.Log.Debug("Handling OpenSim asset upload");
try try
{ {
using (XmlReader reader = XmlReader.Create(request.Body)) using (XmlReader reader = XmlReader.Create(request.Body))
{ {
reader.MoveToContent(); reader.MoveToContent();
reader.ReadStartElement("AssetBase"); reader.ReadStartElement("AssetBase");
reader.ReadStartElement("FullID"); reader.ReadStartElement("FullID");
UUID.TryParse(reader.ReadElementContentAsString("Guid", String.Empty), out metadata.ID); UUID.TryParse(reader.ReadElementContentAsString("Guid", String.Empty), out metadata.ID);
reader.ReadEndElement(); reader.ReadEndElement();
reader.ReadStartElement("ID"); reader.ReadStartElement("ID");
reader.Skip(); reader.Skip();
reader.ReadEndElement(); reader.ReadEndElement();
// HACK: Broken on Mono. https://bugzilla.novell.com/show_bug.cgi?id=464229 // HACK: Broken on Mono. https://bugzilla.novell.com/show_bug.cgi?id=464229
//int readBytes = 0; //int readBytes = 0;
//byte[] buffer = new byte[1024]; //byte[] buffer = new byte[1024];
//MemoryStream stream = new MemoryStream(); //MemoryStream stream = new MemoryStream();
//BinaryWriter writer = new BinaryWriter(stream); //BinaryWriter writer = new BinaryWriter(stream);
//while ((readBytes = reader.ReadElementContentAsBase64(buffer, 0, buffer.Length)) > 0) //while ((readBytes = reader.ReadElementContentAsBase64(buffer, 0, buffer.Length)) > 0)
// writer.Write(buffer, 0, readBytes); // writer.Write(buffer, 0, readBytes);
//writer.Flush(); //writer.Flush();
//assetData = stream.GetBuffer(); //assetData = stream.GetBuffer();
//Array.Resize<byte>(ref assetData, (int)stream.Length); //Array.Resize<byte>(ref assetData, (int)stream.Length);
assetData = Convert.FromBase64String(reader.ReadElementContentAsString()); assetData = Convert.FromBase64String(reader.ReadElementContentAsString());
int type; int type;
Int32.TryParse(reader.ReadElementContentAsString("Type", String.Empty), out type); Int32.TryParse(reader.ReadElementContentAsString("Type", String.Empty), out type);
metadata.ContentType = Utils.SLAssetTypeToContentType(type); metadata.ContentType = Utils.SLAssetTypeToContentType(type);
metadata.Name = reader.ReadElementContentAsString("Name", String.Empty); metadata.Name = reader.ReadElementContentAsString("Name", String.Empty);
metadata.Description = reader.ReadElementContentAsString("Description", String.Empty); metadata.Description = reader.ReadElementContentAsString("Description", String.Empty);
Boolean.TryParse(reader.ReadElementContentAsString("Local", String.Empty), out metadata.Temporary); Boolean.TryParse(reader.ReadElementContentAsString("Local", String.Empty), out metadata.Temporary);
Boolean.TryParse(reader.ReadElementContentAsString("Temporary", String.Empty), out metadata.Temporary); Boolean.TryParse(reader.ReadElementContentAsString("Temporary", String.Empty), out metadata.Temporary);
reader.ReadEndElement(); reader.ReadEndElement();
} }
if (assetData != null && assetData.Length > 0) if (assetData != null && assetData.Length > 0)
{ {
metadata.SHA1 = OpenMetaverse.Utils.SHA1(assetData); metadata.SHA1 = OpenMetaverse.Utils.SHA1(assetData);
metadata.CreationDate = DateTime.Now; metadata.CreationDate = DateTime.Now;
BackendResponse storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData); BackendResponse storageResponse = server.StorageProvider.TryCreateAsset(metadata, assetData);
if (storageResponse == BackendResponse.Success) if (storageResponse == BackendResponse.Success)
response.Status = HttpStatusCode.Created; response.Status = HttpStatusCode.Created;
else if (storageResponse == BackendResponse.NotFound) else if (storageResponse == BackendResponse.NotFound)
response.Status = HttpStatusCode.NotFound; response.Status = HttpStatusCode.NotFound;
else else
response.Status = HttpStatusCode.InternalServerError; response.Status = HttpStatusCode.InternalServerError;
} }
else else
{ {
Logger.Log.Warn("AssetPostHandler called with no asset data"); Logger.Log.Warn("AssetPostHandler called with no asset data");
response.Status = HttpStatusCode.BadRequest; response.Status = HttpStatusCode.BadRequest;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Log.Warn("Failed to parse POST data (expecting AssetBase): " + ex.Message); Logger.Log.Warn("Failed to parse POST data (expecting AssetBase): " + ex.Message);
response.Status = HttpStatusCode.BadRequest; response.Status = HttpStatusCode.BadRequest;
} }
Logger.Log.Debug("Finished handling OpenSim asset upload, Status: " + response.Status.ToString()); Logger.Log.Debug("Finished handling OpenSim asset upload, Status: " + response.Status.ToString());
return true; return true;
} }
} }
} }

View File

@ -1,370 +1,370 @@
/* /*
* Copyright (c) 2008 Intel Corporation * Copyright (c) 2008 Intel Corporation
* All rights reserved. * All rights reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* *
* -- Redistributions of source code must retain the above copyright * -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright * -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its * -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Data; using System.Data;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using ExtensionLoader; using ExtensionLoader;
using ExtensionLoader.Config; using ExtensionLoader.Config;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.StructuredData; using OpenMetaverse.StructuredData;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Grid.AssetInventoryServer.Extensions; using OpenSim.Grid.AssetInventoryServer.Extensions;
namespace OpenSim.Grid.AssetInventoryServer.Plugins namespace OpenSim.Grid.AssetInventoryServer.Plugins
{ {
public class OpenSimAssetStoragePlugin : IAssetStorageProvider public class OpenSimAssetStoragePlugin : IAssetStorageProvider
{ {
const string EXTENSION_NAME = "OpenSimAssetStorage"; // Used in metrics reporting const string EXTENSION_NAME = "OpenSimAssetStorage"; // Used in metrics reporting
private AssetInventoryServer server; private AssetInventoryServer server;
private IAssetProviderPlugin m_assetProvider; private IAssetProviderPlugin m_assetProvider;
public OpenSimAssetStoragePlugin() public OpenSimAssetStoragePlugin()
{ {
} }
#region IAssetStorageProvider implementation #region IAssetStorageProvider implementation
public BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata) public BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata)
{ {
metadata = null; metadata = null;
BackendResponse ret; BackendResponse ret;
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
{ {
IDataReader reader; IDataReader reader;
try try
{ {
dbConnection.Open(); dbConnection.Open();
IDbCommand command = dbConnection.CreateCommand(); IDbCommand command = dbConnection.CreateCommand();
command.CommandText = String.Format("SELECT name,description,assetType,temporary FROM assets WHERE id='{0}'", assetID.ToString()); command.CommandText = String.Format("SELECT name,description,assetType,temporary FROM assets WHERE id='{0}'", assetID.ToString());
reader = command.ExecuteReader(); reader = command.ExecuteReader();
if (reader.Read()) if (reader.Read())
{ {
metadata = new Metadata(); metadata = new Metadata();
metadata.CreationDate = OpenMetaverse.Utils.Epoch; metadata.CreationDate = OpenMetaverse.Utils.Epoch;
metadata.SHA1 = null; metadata.SHA1 = null;
metadata.ID = assetID; metadata.ID = assetID;
metadata.Name = reader.GetString(0); metadata.Name = reader.GetString(0);
metadata.Description = reader.GetString(1); metadata.Description = reader.GetString(1);
metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2));
metadata.Temporary = reader.GetBoolean(3); metadata.Temporary = reader.GetBoolean(3);
ret = BackendResponse.Success; ret = BackendResponse.Success;
} }
else else
{ {
ret = BackendResponse.NotFound; ret = BackendResponse.NotFound;
} }
} }
catch (MySqlException ex) catch (MySqlException ex)
{ {
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message);
ret = BackendResponse.Failure; ret = BackendResponse.Failure;
} }
} }
server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
return ret; return ret;
} }
public BackendResponse TryFetchData(UUID assetID, out byte[] assetData) public BackendResponse TryFetchData(UUID assetID, out byte[] assetData)
{ {
assetData = null; assetData = null;
BackendResponse ret; BackendResponse ret;
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
{ {
IDataReader reader; IDataReader reader;
try try
{ {
dbConnection.Open(); dbConnection.Open();
IDbCommand command = dbConnection.CreateCommand(); IDbCommand command = dbConnection.CreateCommand();
command.CommandText = String.Format("SELECT data FROM assets WHERE id='{0}'", assetID.ToString()); command.CommandText = String.Format("SELECT data FROM assets WHERE id='{0}'", assetID.ToString());
reader = command.ExecuteReader(); reader = command.ExecuteReader();
if (reader.Read()) if (reader.Read())
{ {
assetData = (byte[])reader.GetValue(0); assetData = (byte[])reader.GetValue(0);
ret = BackendResponse.Success; ret = BackendResponse.Success;
} }
else else
{ {
ret = BackendResponse.NotFound; ret = BackendResponse.NotFound;
} }
} }
catch (MySqlException ex) catch (MySqlException ex)
{ {
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message);
ret = BackendResponse.Failure; ret = BackendResponse.Failure;
} }
} }
server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now); server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now);
return ret; return ret;
} }
public BackendResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData) public BackendResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData)
{ {
metadata = null; metadata = null;
assetData = null; assetData = null;
//BackendResponse ret; //BackendResponse ret;
AssetBase asset_base = m_assetProvider.FetchAsset(assetID); AssetBase asset_base = m_assetProvider.FetchAsset(assetID);
if (asset_base != null) if (asset_base != null)
{ {
metadata = new Metadata(); metadata = new Metadata();
metadata.CreationDate = OpenMetaverse.Utils.Epoch; metadata.CreationDate = OpenMetaverse.Utils.Epoch;
metadata.SHA1 = null; metadata.SHA1 = null;
metadata.Name = asset_base.Name; metadata.Name = asset_base.Name;
metadata.Description = asset_base.Description; metadata.Description = asset_base.Description;
metadata.ContentType = Utils.SLAssetTypeToContentType(asset_base.Type); metadata.ContentType = Utils.SLAssetTypeToContentType(asset_base.Type);
metadata.Temporary = asset_base.Temporary; metadata.Temporary = asset_base.Temporary;
assetData = asset_base.Data; assetData = asset_base.Data;
} }
else return BackendResponse.NotFound; else return BackendResponse.NotFound;
return BackendResponse.Success; return BackendResponse.Success;
//using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) //using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
//{ //{
// IDataReader reader; // IDataReader reader;
// try // try
// { // {
// dbConnection.Open(); // dbConnection.Open();
// IDbCommand command = dbConnection.CreateCommand(); // IDbCommand command = dbConnection.CreateCommand();
// command.CommandText = String.Format("SELECT name,description,assetType,temporary,data FROM assets WHERE id='{0}'", assetID.ToString()); // command.CommandText = String.Format("SELECT name,description,assetType,temporary,data FROM assets WHERE id='{0}'", assetID.ToString());
// reader = command.ExecuteReader(); // reader = command.ExecuteReader();
// if (reader.Read()) // if (reader.Read())
// { // {
// metadata = new Metadata(); // metadata = new Metadata();
// metadata.CreationDate = OpenMetaverse.Utils.Epoch; // metadata.CreationDate = OpenMetaverse.Utils.Epoch;
// metadata.SHA1 = null; // metadata.SHA1 = null;
// metadata.ID = assetID; // metadata.ID = assetID;
// metadata.Name = reader.GetString(0); // metadata.Name = reader.GetString(0);
// metadata.Description = reader.GetString(1); // metadata.Description = reader.GetString(1);
// metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); // metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2));
// metadata.Temporary = reader.GetBoolean(3); // metadata.Temporary = reader.GetBoolean(3);
// assetData = (byte[])reader.GetValue(4); // assetData = (byte[])reader.GetValue(4);
// ret = BackendResponse.Success; // ret = BackendResponse.Success;
// } // }
// else // else
// { // {
// ret = BackendResponse.NotFound; // ret = BackendResponse.NotFound;
// } // }
// } // }
// catch (MySqlException ex) // catch (MySqlException ex)
// { // {
// Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); // Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message);
// ret = BackendResponse.Failure; // ret = BackendResponse.Failure;
// } // }
//} //}
//server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); //server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
//server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now); //server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now);
//return ret; //return ret;
} }
public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID) public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID)
{ {
assetID = metadata.ID = UUID.Random(); assetID = metadata.ID = UUID.Random();
return TryCreateAsset(metadata, assetData); return TryCreateAsset(metadata, assetData);
} }
public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData) public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData)
{ {
BackendResponse ret; BackendResponse ret;
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
{ {
try try
{ {
dbConnection.Open(); dbConnection.Open();
MySqlCommand command = new MySqlCommand( MySqlCommand command = new MySqlCommand(
"REPLACE INTO assets (name,description,assetType,local,temporary,data,id) VALUES " + "REPLACE INTO assets (name,description,assetType,local,temporary,data,id) VALUES " +
"(?name,?description,?assetType,?local,?temporary,?data,?id)", dbConnection); "(?name,?description,?assetType,?local,?temporary,?data,?id)", dbConnection);
command.Parameters.AddWithValue("?name", metadata.Name); command.Parameters.AddWithValue("?name", metadata.Name);
command.Parameters.AddWithValue("?description", metadata.Description); command.Parameters.AddWithValue("?description", metadata.Description);
command.Parameters.AddWithValue("?assetType", Utils.ContentTypeToSLAssetType(metadata.ContentType)); command.Parameters.AddWithValue("?assetType", Utils.ContentTypeToSLAssetType(metadata.ContentType));
command.Parameters.AddWithValue("?local", 0); command.Parameters.AddWithValue("?local", 0);
command.Parameters.AddWithValue("?temporary", metadata.Temporary); command.Parameters.AddWithValue("?temporary", metadata.Temporary);
command.Parameters.AddWithValue("?data", assetData); command.Parameters.AddWithValue("?data", assetData);
command.Parameters.AddWithValue("?id", metadata.ID.ToString()); command.Parameters.AddWithValue("?id", metadata.ID.ToString());
int rowsAffected = command.ExecuteNonQuery(); int rowsAffected = command.ExecuteNonQuery();
if (rowsAffected == 1) if (rowsAffected == 1)
{ {
ret = BackendResponse.Success; ret = BackendResponse.Success;
} }
else if (rowsAffected == 2) else if (rowsAffected == 2)
{ {
Logger.Log.Info("Replaced asset " + metadata.ID.ToString()); Logger.Log.Info("Replaced asset " + metadata.ID.ToString());
ret = BackendResponse.Success; ret = BackendResponse.Success;
} }
else else
{ {
Logger.Log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected); Logger.Log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected);
ret = BackendResponse.Failure; ret = BackendResponse.Failure;
} }
} }
catch (MySqlException ex) catch (MySqlException ex)
{ {
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message);
ret = BackendResponse.Failure; ret = BackendResponse.Failure;
} }
} }
server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, metadata.ID, assetData.Length, DateTime.Now); server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, metadata.ID, assetData.Length, DateTime.Now);
return ret; return ret;
} }
public int ForEach(Action<Metadata> action, int start, int count) public int ForEach(Action<Metadata> action, int start, int count)
{ {
int rowCount = 0; int rowCount = 0;
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile)))
{ {
MySqlDataReader reader; MySqlDataReader reader;
try try
{ {
dbConnection.Open(); dbConnection.Open();
MySqlCommand command = dbConnection.CreateCommand(); MySqlCommand command = dbConnection.CreateCommand();
command.CommandText = String.Format("SELECT name,description,assetType,temporary,data,id FROM assets LIMIT {0}, {1}", command.CommandText = String.Format("SELECT name,description,assetType,temporary,data,id FROM assets LIMIT {0}, {1}",
start, count); start, count);
reader = command.ExecuteReader(); reader = command.ExecuteReader();
} }
catch (MySqlException ex) catch (MySqlException ex)
{ {
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message);
return 0; return 0;
} }
while (reader.Read()) while (reader.Read())
{ {
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
metadata.CreationDate = OpenMetaverse.Utils.Epoch; metadata.CreationDate = OpenMetaverse.Utils.Epoch;
metadata.Description = reader.GetString(1); metadata.Description = reader.GetString(1);
metadata.ID = UUID.Parse(reader.GetString(5)); metadata.ID = UUID.Parse(reader.GetString(5));
metadata.Name = reader.GetString(0); metadata.Name = reader.GetString(0);
metadata.SHA1 = OpenMetaverse.Utils.SHA1((byte[])reader.GetValue(4)); metadata.SHA1 = OpenMetaverse.Utils.SHA1((byte[])reader.GetValue(4));
metadata.Temporary = reader.GetBoolean(3); metadata.Temporary = reader.GetBoolean(3);
metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2));
action(metadata); action(metadata);
++rowCount; ++rowCount;
} }
reader.Close(); reader.Close();
} }
return rowCount; return rowCount;
} }
#endregion IAssetStorageProvider implementation #endregion IAssetStorageProvider implementation
#region IPlugin implementation #region IPlugin implementation
public void Initialise(AssetInventoryServer server) public void Initialise(AssetInventoryServer server)
{ {
this.server = server; this.server = server;
try try
{ {
m_assetProvider = LoadDatabasePlugin("OpenSim.Data.MySQL.dll", server.ConfigFile.Configs["MySQL"].GetString("database_connect", null)); m_assetProvider = LoadDatabasePlugin("OpenSim.Data.MySQL.dll", server.ConfigFile.Configs["MySQL"].GetString("database_connect", null));
if (m_assetProvider == null) if (m_assetProvider == null)
{ {
Logger.Log.Error("[ASSET]: Failed to load a database plugin, server halting."); Logger.Log.Error("[ASSET]: Failed to load a database plugin, server halting.");
Environment.Exit(-1); Environment.Exit(-1);
} }
else else
Logger.Log.InfoFormat("[ASSET]: Loaded storage backend: {0}", Version); Logger.Log.InfoFormat("[ASSET]: Loaded storage backend: {0}", Version);
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Log.WarnFormat("[ASSET]: Failure loading data plugin: {0}", e.ToString()); Logger.Log.WarnFormat("[ASSET]: Failure loading data plugin: {0}", e.ToString());
} }
} }
/// <summary> /// <summary>
/// <para>Initialises asset interface</para> /// <para>Initialises asset interface</para>
/// </summary> /// </summary>
public void Initialise() public void Initialise()
{ {
Logger.Log.InfoFormat("[ASSET]: {0} cannot be default-initialized!", Name); Logger.Log.InfoFormat("[ASSET]: {0} cannot be default-initialized!", Name);
throw new PluginNotInitialisedException(Name); throw new PluginNotInitialisedException(Name);
} }
public void Dispose() public void Dispose()
{ {
} }
public string Version public string Version
{ {
get { return m_assetProvider.Version; } get { return m_assetProvider.Version; }
} }
public string Name public string Name
{ {
get { return "AssetInventoryServer OpenSim asset storage provider"; } get { return "AssetInventoryServer OpenSim asset storage provider"; }
} }
#endregion IPlugin implementation #endregion IPlugin implementation
private IAssetProviderPlugin LoadDatabasePlugin(string provider, string connect) private IAssetProviderPlugin LoadDatabasePlugin(string provider, string connect)
{ {
PluginLoader<IAssetProviderPlugin> loader = new PluginLoader<IAssetProviderPlugin>(new AssetDataInitialiser(connect)); PluginLoader<IAssetProviderPlugin> loader = new PluginLoader<IAssetProviderPlugin>(new AssetDataInitialiser(connect));
// Loader will try to load all providers (MySQL, MSSQL, etc) // Loader will try to load all providers (MySQL, MSSQL, etc)
// unless it is constrainted to the correct "Provider" entry in the addin.xml // unless it is constrainted to the correct "Provider" entry in the addin.xml
loader.Add("/OpenSim/AssetData", new PluginProviderFilter (provider)); loader.Add("/OpenSim/AssetData", new PluginProviderFilter (provider));
loader.Load(); loader.Load();
return loader.Plugin; return loader.Plugin;
} }
} }
} }

File diff suppressed because it is too large Load Diff