From 2534078380dffc4f47b82a4d28879c4bf699d09f Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Mon, 18 May 2009 12:36:59 +0000 Subject: Refactor: Change "Servers" to "Server", since the can only be one. Break the handlers out of the asset server context into a generic scope. --- .../Server/Handlers/Asset/AssetServerConnector.cs | 61 ++++++++++++ .../Handlers/Asset/AssetServerDeleteHandler.cs | 75 ++++++++++++++ .../Server/Handlers/Asset/AssetServerGetHandler.cs | 110 +++++++++++++++++++++ .../Handlers/Asset/AssetServerPostHandler.cs | 81 +++++++++++++++ 4 files changed, 327 insertions(+) create mode 100644 OpenSim/Server/Handlers/Asset/AssetServerConnector.cs create mode 100644 OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs create mode 100644 OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs create mode 100644 OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs new file mode 100644 index 0000000..64014f5 --- /dev/null +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -0,0 +1,61 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using Nini.Config; +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; +using OpenSim.Framework.Servers.HttpServer; + +namespace OpenSim.Server.Handlers.Asset +{ + public class AssetServiceConnector + { + private IAssetService m_AssetService; + + public AssetServiceConnector(IConfigSource config, IHttpServer server) + { + IConfig serverConfig = config.Configs["AssetService"]; + if (serverConfig == null) + throw new Exception("No section 'Server' in config file"); + + string assetService = serverConfig.GetString("LocalServiceModule", + String.Empty); + + if (assetService == String.Empty) + throw new Exception("No AssetService in config file"); + + Object[] args = new Object[] { config }; + m_AssetService = + ServerUtils.LoadPlugin(assetService, args); + + server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); + server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); + server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService)); + } + } +} diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs new file mode 100644 index 0000000..f9eceeb --- /dev/null +++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs @@ -0,0 +1,75 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using Nini.Config; +using log4net; +using System; +using System.Reflection; +using System.IO; +using System.Net; +using System.Text; +using System.Text.RegularExpressions; +using System.Xml; +using System.Xml.Serialization; +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; +using OpenSim.Framework; +using OpenSim.Framework.Servers.HttpServer; + +namespace OpenSim.Server.Handlers.Asset +{ + public class AssetServerDeleteHandler : BaseStreamHandler + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private IAssetService m_AssetService; + + public AssetServerDeleteHandler(IAssetService service) : + base("DELETE", "/assets") + { + m_AssetService = service; + } + + public override byte[] Handle(string path, Stream request, + OSHttpRequest httpRequest, OSHttpResponse httpResponse) + { + bool result = false; + + string[] p = SplitParams(path); + + if (p.Length > 0) + { + result = m_AssetService.Delete(p[0]); + } + + XmlSerializer xs = new XmlSerializer(typeof(bool)); + return ServerUtils.SerializeResult(xs, result); + } + } +} diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs new file mode 100644 index 0000000..0ededca --- /dev/null +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs @@ -0,0 +1,110 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using Nini.Config; +using log4net; +using System; +using System.IO; +using System.Reflection; +using System.Net; +using System.Text; +using System.Text.RegularExpressions; +using System.Xml; +using System.Xml.Serialization; +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; +using OpenSim.Framework; +using OpenSim.Framework.Servers.HttpServer; + +namespace OpenSim.Server.Handlers.Asset +{ + public class AssetServerGetHandler : BaseStreamHandler + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private IAssetService m_AssetService; + + public AssetServerGetHandler(IAssetService service) : + base("GET", "/assets") + { + m_AssetService = service; + } + + public override byte[] Handle(string path, Stream request, + OSHttpRequest httpRequest, OSHttpResponse httpResponse) + { + byte[] result = new byte[0]; + + string[] p = SplitParams(path); + + if (p.Length == 0) + return result; + + if (p.Length > 1 && p[1] == "data") + { + result = m_AssetService.GetData(p[0]); + if (result == null) + result = new byte[0]; + + httpResponse.StatusCode = (int)HttpStatusCode.OK; + httpResponse.ContentType = "application/octet-stream"; + } + else if(p.Length > 1 && p[1] == "metadata") + { + AssetMetadata metadata = m_AssetService.GetMetadata(p[0]); + + if (metadata != null) + { + XmlSerializer xs = + new XmlSerializer(typeof(AssetMetadata)); + result = ServerUtils.SerializeResult(xs, metadata); + + httpResponse.StatusCode = (int)HttpStatusCode.OK; + httpResponse.ContentType = + ServerUtils.SLAssetTypeToContentType(metadata.Type); + } + } + else + { + AssetBase asset = m_AssetService.Get(p[0]); + + if (asset != null) + { + XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); + result = ServerUtils.SerializeResult(xs, asset); + + httpResponse.StatusCode = (int)HttpStatusCode.OK; + httpResponse.ContentType = + ServerUtils.SLAssetTypeToContentType(asset.Type); + } + } + return result; + } + } +} diff --git a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs new file mode 100644 index 0000000..5ca9eae --- /dev/null +++ b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs @@ -0,0 +1,81 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using Nini.Config; +using log4net; +using System; +using System.Reflection; +using System.IO; +using System.Net; +using System.Text; +using System.Text.RegularExpressions; +using System.Xml; +using System.Xml.Serialization; +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; +using OpenSim.Framework; +using OpenSim.Framework.Servers.HttpServer; + +namespace OpenSim.Server.Handlers.Asset +{ + public class AssetServerPostHandler : BaseStreamHandler + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private IAssetService m_AssetService; + + public AssetServerPostHandler(IAssetService service) : + base("POST", "/assets") + { + m_AssetService = service; + } + + public override byte[] Handle(string path, Stream request, + OSHttpRequest httpRequest, OSHttpResponse httpResponse) + { + XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); + AssetBase asset = (AssetBase) xs.Deserialize(request); + + string[] p = SplitParams(path); + if (p.Length > 1) + { + bool result = + m_AssetService.UpdateContent(p[1], asset.Data); + + xs = new XmlSerializer(typeof(bool)); + return ServerUtils.SerializeResult(xs, result); + } + + string id = m_AssetService.Store(asset); + + xs = new XmlSerializer(typeof(string)); + return ServerUtils.SerializeResult(xs, id); + } + } +} -- cgit v1.1 From f7dbfe63e55ca875c1079084c4ca153f9a815327 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Mon, 18 May 2009 21:04:25 +0000 Subject: This commit changes the way the new server works. There is no longer a server exe for each function, rather each function is a connector and the server ini loads them. If you like your multiple processes, use -inifile with the server. Otherwise, you get one server process that serves all configured funcions, see example .ini. The new exe is OpenSim.Server.exe. Clean your bin, loads of names have changed! --- OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 64014f5..686e6dd 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -30,14 +30,16 @@ using Nini.Config; using OpenSim.Server.Base; using OpenSim.Services.Interfaces; using OpenSim.Framework.Servers.HttpServer; +using OpenSim.Server.Handlers.Base; namespace OpenSim.Server.Handlers.Asset { - public class AssetServiceConnector + public class AssetServiceConnector : ServiceConnector { private IAssetService m_AssetService; - public AssetServiceConnector(IConfigSource config, IHttpServer server) + public AssetServiceConnector(IConfigSource config, IHttpServer server) : + base(config, server) { IConfig serverConfig = config.Configs["AssetService"]; if (serverConfig == null) -- cgit v1.1 From e0bc5c5db2b88691c04b06be2fa73a75746126cb Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Wed, 20 May 2009 01:32:06 +0000 Subject: Add copyright headers, formatting cleanup. --- OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs index 0ededca..be71f6b 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs @@ -75,7 +75,7 @@ namespace OpenSim.Server.Handlers.Asset httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = "application/octet-stream"; } - else if(p.Length > 1 && p[1] == "metadata") + else if (p.Length > 1 && p[1] == "metadata") { AssetMetadata metadata = m_AssetService.GetMetadata(p[0]); -- cgit v1.1 From da170cde4684ea0f8ed90ea4ed0b30172ad9981d Mon Sep 17 00:00:00 2001 From: diva Date: Fri, 22 May 2009 04:23:59 +0000 Subject: Cleaning up a few HG things. HG Posts may now work in grids, but if the home grid is a standalone, this still doesn't work -- something wrong with RegionAssetService's DB connection. --- OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 686e6dd..39780e1 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -55,6 +55,7 @@ namespace OpenSim.Server.Handlers.Asset m_AssetService = ServerUtils.LoadPlugin(assetService, args); + //System.Console.WriteLine("XXXXXXXXXXXXXXXXXXX m_AssetSetvice == null? " + ((m_AssetService == null) ? "yes" : "no")); server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService)); -- cgit v1.1 From 1d02636c27de64f8acec5bb9a76f8659f0bfdd2b Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Fri, 22 May 2009 14:57:00 +0000 Subject: cleaning out warnings. NOTE: we currently have a gazillion warnings caused stuff flagged as "obsolete" (OGS1 stuff) --- what's up with that? --- OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs | 4 +--- OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs | 4 +--- OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs index f9eceeb..e3795ac 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs @@ -44,9 +44,7 @@ namespace OpenSim.Server.Handlers.Asset { public class AssetServerDeleteHandler : BaseStreamHandler { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); + // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAssetService m_AssetService; diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs index be71f6b..97460d7 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs @@ -44,9 +44,7 @@ namespace OpenSim.Server.Handlers.Asset { public class AssetServerGetHandler : BaseStreamHandler { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); + // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAssetService m_AssetService; diff --git a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs index 5ca9eae..31f3529 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs @@ -44,9 +44,7 @@ namespace OpenSim.Server.Handlers.Asset { public class AssetServerPostHandler : BaseStreamHandler { - private static readonly ILog m_log = - LogManager.GetLogger( - MethodBase.GetCurrentMethod().DeclaringType); + // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAssetService m_AssetService; -- cgit v1.1 From 840de6c036570d559ec6924cd8405d3f34a99fdd Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Mon, 1 Jun 2009 06:37:14 +0000 Subject: Minor: Change OpenSim to OpenSimulator in older copyright headers and LICENSE.txt. --- OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 2 +- OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs | 2 +- OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs | 2 +- OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 39780e1..7c74e05 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the + * * Neither the name of the OpenSimulator Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs index e3795ac..3f33da6 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the + * * Neither the name of the OpenSimulator Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs index 97460d7..7e650f0 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the + * * Neither the name of the OpenSimulator Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * diff --git a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs index 31f3529..1fcd3ed 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the + * * Neither the name of the OpenSimulator Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * -- cgit v1.1 From fe1e9ac5c3b860be4b7dcba42b95970ba5dbbe5e Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Tue, 7 Jul 2009 17:45:02 +0000 Subject: Make the asset IN connector return HTTP 404 if an asset is not found, and also make it return a non-xml content type so a browser can be used for testing it. --- .../Server/Handlers/Asset/AssetServerGetHandler.cs | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs index 7e650f0..fe0da0b 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs @@ -68,10 +68,16 @@ namespace OpenSim.Server.Handlers.Asset { result = m_AssetService.GetData(p[0]); if (result == null) + { + httpResponse.StatusCode = (int)HttpStatusCode.NotFound; + httpResponse.ContentType = "text/plain"; result = new byte[0]; - - httpResponse.StatusCode = (int)HttpStatusCode.OK; - httpResponse.ContentType = "application/octet-stream"; + } + else + { + httpResponse.StatusCode = (int)HttpStatusCode.OK; + httpResponse.ContentType = "application/octet-stream"; + } } else if (p.Length > 1 && p[1] == "metadata") { @@ -87,6 +93,12 @@ namespace OpenSim.Server.Handlers.Asset httpResponse.ContentType = ServerUtils.SLAssetTypeToContentType(metadata.Type); } + else + { + httpResponse.StatusCode = (int)HttpStatusCode.NotFound; + httpResponse.ContentType = "text/plain"; + result = new byte[0]; + } } else { @@ -101,6 +113,12 @@ namespace OpenSim.Server.Handlers.Asset httpResponse.ContentType = ServerUtils.SLAssetTypeToContentType(asset.Type); } + else + { + httpResponse.StatusCode = (int)HttpStatusCode.NotFound; + httpResponse.ContentType = "text/plain"; + result = new byte[0]; + } } return result; } -- cgit v1.1 From 691f1e8aa08db84b689793ea9cd2c72bcfdd9b17 Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 29 Sep 2009 09:56:17 +0100 Subject: Fix loading modules with alternate configurations and ports into ROBUST. Make all current modules support the configuration name option --- OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 7c74e05..f7eb292 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -37,13 +37,17 @@ namespace OpenSim.Server.Handlers.Asset public class AssetServiceConnector : ServiceConnector { private IAssetService m_AssetService; + private string m_ConfigName = "AssetService"; - public AssetServiceConnector(IConfigSource config, IHttpServer server) : - base(config, server) + public AssetServiceConnector(IConfigSource config, IHttpServer server, string configName) : + base(config, server, configName) { - IConfig serverConfig = config.Configs["AssetService"]; + if (configName != String.Empty) + m_ConfigName = configName; + + IConfig serverConfig = config.Configs[m_ConfigName]; if (serverConfig == null) - throw new Exception("No section 'Server' in config file"); + throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); string assetService = serverConfig.GetString("LocalServiceModule", String.Empty); @@ -55,7 +59,6 @@ namespace OpenSim.Server.Handlers.Asset m_AssetService = ServerUtils.LoadPlugin(assetService, args); - //System.Console.WriteLine("XXXXXXXXXXXXXXXXXXX m_AssetSetvice == null? " + ((m_AssetService == null) ? "yes" : "no")); server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService)); -- cgit v1.1 From 2257431cba74f8a184c65e3d4ebc7c1befbd349c Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 18 Jan 2010 17:35:49 +0000 Subject: Comment the asset deletion handler. It can be abused and is not currently needed. --- OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs index 3f33da6..f33bb90 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs @@ -63,7 +63,7 @@ namespace OpenSim.Server.Handlers.Asset if (p.Length > 0) { - result = m_AssetService.Delete(p[0]); + // result = m_AssetService.Delete(p[0]); } XmlSerializer xs = new XmlSerializer(typeof(bool)); -- cgit v1.1 From 845a390e9308f6b6823c85ac319ecb211f968d4b Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Sat, 20 Feb 2010 16:21:13 -0800 Subject: * Added a sanity check for missing asset data in LLClientView * Moved the SL asset type to content type conversion methods from ServerUtils to OpenSim.Framework.SLUtil * Linked content type to asset type in AssetMetadata --- OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs index fe0da0b..43c1693 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs @@ -91,7 +91,7 @@ namespace OpenSim.Server.Handlers.Asset httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = - ServerUtils.SLAssetTypeToContentType(metadata.Type); + SLUtil.SLAssetTypeToContentType(metadata.Type); } else { @@ -111,7 +111,7 @@ namespace OpenSim.Server.Handlers.Asset httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = - ServerUtils.SLAssetTypeToContentType(asset.Type); + SLUtil.SLAssetTypeToContentType(asset.Type); } else { -- cgit v1.1 From 60357d3778c95a47481f790803b7af39c70cde9c Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 9 May 2010 17:56:52 +0100 Subject: Implement the "delete" path for assets. Adds a new option to allow remote asset deletion in robust handler. --- OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 4 +++- OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index f7eb292..b6425f4 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -59,9 +59,11 @@ namespace OpenSim.Server.Handlers.Asset m_AssetService = ServerUtils.LoadPlugin(assetService, args); + bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false); + server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); - server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService)); + server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowDelete)); } } } diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs index f33bb90..8014fb5 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs @@ -47,11 +47,13 @@ namespace OpenSim.Server.Handlers.Asset // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAssetService m_AssetService; + protected bool m_allowDelete; - public AssetServerDeleteHandler(IAssetService service) : + public AssetServerDeleteHandler(IAssetService service, bool allowDelete) : base("DELETE", "/assets") { m_AssetService = service; + m_allowDelete = allowDelete; } public override byte[] Handle(string path, Stream request, @@ -61,9 +63,9 @@ namespace OpenSim.Server.Handlers.Asset string[] p = SplitParams(path); - if (p.Length > 0) + if (p.Length > 0 && m_allowDelete) { - // result = m_AssetService.Delete(p[0]); + result = m_AssetService.Delete(p[0]); } XmlSerializer xs = new XmlSerializer(typeof(bool)); -- cgit v1.1 From ae4b02e1152b775dc1cdccd1abfbff44ab1a8949 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 25 Nov 2010 11:14:16 -0800 Subject: WARNING: LOTS OF CONFIGURATION CHANGES AFFECTING PRIMARILY HG CONFIGS. Added capability to preserve creator information on HG asset transfers. Added a new HGAssetService that is intended to be the one outside the firewall. It processes and filters the assets that go out of the grid. Also fixed the normal AssetService to do special things for the main instance (console commands, etc). Moved HGInventoryService to OpenSim.Services.HypergridService. Changed the way the login service gets the ServiceURL configs. --- OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index b6425f4..df571fa 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -53,12 +53,15 @@ namespace OpenSim.Server.Handlers.Asset String.Empty); if (assetService == String.Empty) - throw new Exception("No AssetService in config file"); + throw new Exception("No LocalServiceModule in config file"); Object[] args = new Object[] { config }; m_AssetService = ServerUtils.LoadPlugin(assetService, args); + if (m_AssetService == null) + throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); + bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false); server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); -- cgit v1.1 From 4567555c49cb560dd6f109bbfec42086af3de56f Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 5 Dec 2011 20:44:20 +0000 Subject: Implement IOSHttpRequest and IOSHttpResponse http interfaces and use instead of OSHttpRequest/OSHttpResponse. This is required for the substitution of different HTTP servers or the newer HttpServer.dll without having to commit to a particular implementation. This is also required to write regression tests that involve the HTTP layer. If you need to recompile, all you need to do is replace OSHttpRequest/OSHttpResponse references with IOSHttpRequest/IOSHttpResponse. --- OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs | 2 +- OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs | 2 +- OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs index 8014fb5..0cfe5b1 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs @@ -57,7 +57,7 @@ namespace OpenSim.Server.Handlers.Asset } public override byte[] Handle(string path, Stream request, - OSHttpRequest httpRequest, OSHttpResponse httpResponse) + IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { bool result = false; diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs index 43c1693..8f7412b 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs @@ -55,7 +55,7 @@ namespace OpenSim.Server.Handlers.Asset } public override byte[] Handle(string path, Stream request, - OSHttpRequest httpRequest, OSHttpResponse httpResponse) + IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { byte[] result = new byte[0]; diff --git a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs index 1fcd3ed..87b3d2d 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs @@ -55,7 +55,7 @@ namespace OpenSim.Server.Handlers.Asset } public override byte[] Handle(string path, Stream request, - OSHttpRequest httpRequest, OSHttpResponse httpResponse) + IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); AssetBase asset = (AssetBase) xs.Deserialize(request); -- cgit v1.1 From f2ff6d5186420ed4bbf7379ad6dc92f46b7907a9 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 5 Jan 2012 20:31:46 +0000 Subject: Move asset commands from AssetService to AssetServerConnector so that we can harmonise the same commands on the simulator side. No functional change. --- .../Server/Handlers/Asset/AssetServerConnector.cs | 127 ++++++++++++++++++++- 1 file changed, 126 insertions(+), 1 deletion(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index df571fa..9960228 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -26,7 +26,11 @@ */ using System; +using System.IO; using Nini.Config; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Framework.Console; using OpenSim.Server.Base; using OpenSim.Services.Interfaces; using OpenSim.Framework.Servers.HttpServer; @@ -67,6 +71,127 @@ namespace OpenSim.Server.Handlers.Asset server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowDelete)); + + MainConsole.Instance.Commands.AddCommand("kfs", false, + "show digest", + "show digest ", + "Show asset digest", + HandleShowDigest); + + MainConsole.Instance.Commands.AddCommand("kfs", false, + "delete asset", + "delete asset ", + "Delete asset from database", + HandleDeleteAsset); + + MainConsole.Instance.Commands.AddCommand("kfs", false, + "dump asset", + "dump asset ", + "Dump asset to a file", + "The filename is the same as the ID given.", + HandleDumpAsset); + } + + void HandleDeleteAsset(string module, string[] args) + { + if (args.Length < 3) + { + MainConsole.Instance.Output("Syntax: delete asset "); + return; + } + + AssetBase asset = m_AssetService.Get(args[2]); + + if (asset == null || asset.Data.Length == 0) + { + MainConsole.Instance.Output("Asset not found"); + return; + } + + m_AssetService.Delete(args[2]); + + //MainConsole.Instance.Output("Asset deleted"); + // TODO: Implement this + + MainConsole.Instance.Output("Asset deletion not supported by database"); + } + + void HandleDumpAsset(string module, string[] args) + { + if (args.Length < 3) + { + MainConsole.Instance.Output("Usage is dump asset "); + return; + } + + UUID assetId; + string rawAssetId = args[2]; + + if (!UUID.TryParse(rawAssetId, out assetId)) + { + MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid ID format", rawAssetId); + return; + } + + AssetBase asset = m_AssetService.Get(assetId.ToString()); + if (asset == null) + { + MainConsole.Instance.OutputFormat("ERROR: No asset found with ID {0}", assetId); + return; + } + + string fileName = rawAssetId; + + using (FileStream fs = new FileStream(fileName, FileMode.CreateNew)) + { + using (BinaryWriter bw = new BinaryWriter(fs)) + { + bw.Write(asset.Data); + } + } + + MainConsole.Instance.OutputFormat("Asset dumped to file {0}", fileName); + } + + void HandleShowDigest(string module, string[] args) + { + if (args.Length < 3) + { + MainConsole.Instance.Output("Syntax: show digest "); + return; + } + + AssetBase asset = m_AssetService.Get(args[2]); + + if (asset == null || asset.Data.Length == 0) + { + MainConsole.Instance.Output("Asset not found"); + return; + } + + int i; + + MainConsole.Instance.OutputFormat("Name: {0}", asset.Name); + MainConsole.Instance.OutputFormat("Description: {0}", asset.Description); + MainConsole.Instance.OutputFormat("Type: {0} (type number = {1})", (AssetType)asset.Type, asset.Type); + MainConsole.Instance.OutputFormat("Content-type: {0}", asset.Metadata.ContentType); + MainConsole.Instance.OutputFormat("Flags: {0}", asset.Metadata.Flags); + + for (i = 0 ; i < 5 ; i++) + { + int off = i * 16; + if (asset.Data.Length <= off) + break; + int len = 16; + if (asset.Data.Length < off + len) + len = asset.Data.Length - off; + + byte[] line = new byte[len]; + Array.Copy(asset.Data, off, line, 0, len); + + string text = BitConverter.ToString(line); + MainConsole.Instance.Output(String.Format("{0:x4}: {1}", off, text)); + } } } -} +} \ No newline at end of file -- cgit v1.1 From 5b160f5b7b2abf41e518e3974098b1bc82268c2a Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 5 Jan 2012 20:56:29 +0000 Subject: Rename 'show digest' console command to 'show asset' --- OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 9960228..61718f1 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -157,7 +157,7 @@ namespace OpenSim.Server.Handlers.Asset { if (args.Length < 3) { - MainConsole.Instance.Output("Syntax: show digest "); + MainConsole.Instance.Output("Syntax: show asset "); return; } -- cgit v1.1 From f06acc0a854980fd66426103892742580e057974 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 5 Jan 2012 21:05:10 +0000 Subject: Add size and temporary information to "show asset" command --- OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 61718f1..5dcb33b 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -175,6 +175,8 @@ namespace OpenSim.Server.Handlers.Asset MainConsole.Instance.OutputFormat("Description: {0}", asset.Description); MainConsole.Instance.OutputFormat("Type: {0} (type number = {1})", (AssetType)asset.Type, asset.Type); MainConsole.Instance.OutputFormat("Content-type: {0}", asset.Metadata.ContentType); + MainConsole.Instance.OutputFormat("Size: {0} bytes", asset.Data.Length); + MainConsole.Instance.OutputFormat("Temporary: {0}", asset.Temporary ? "yes" : "no"); MainConsole.Instance.OutputFormat("Flags: {0}", asset.Metadata.Flags); for (i = 0 ; i < 5 ; i++) -- cgit v1.1 From da0fc3c8f572adba69e52e1d7f528946ab1f6f23 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 5 Jan 2012 21:11:32 +0000 Subject: Make "show asset" command available simulator side. Actually make the service command be "show asset" instead of "show digest" this time. Last time I accidnetally just changed the usage message. --- OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 5dcb33b..9b80245 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -73,10 +73,10 @@ namespace OpenSim.Server.Handlers.Asset server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowDelete)); MainConsole.Instance.Commands.AddCommand("kfs", false, - "show digest", - "show digest ", - "Show asset digest", - HandleShowDigest); + "show asset", + "show asset ", + "Show asset information", + HandleShowAsset); MainConsole.Instance.Commands.AddCommand("kfs", false, "delete asset", @@ -153,7 +153,7 @@ namespace OpenSim.Server.Handlers.Asset MainConsole.Instance.OutputFormat("Asset dumped to file {0}", fileName); } - void HandleShowDigest(string module, string[] args) + void HandleShowAsset(string module, string[] args) { if (args.Length < 3) { -- cgit v1.1 From 749c3fef8ad2d3af97fcd9ab9c72740675e46715 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 8 Mar 2012 01:51:37 +0000 Subject: Change "help" to display categories/module list then "help " to display commands in a category. This is to deal with the hundred lines of command splurge when one previously typed "help" Modelled somewhat on the mysql console One can still type help to get per command help at any point. Categories capitalized to avoid conflict with the all-lowercase commands (except for commander system, as of yet). Does not affect command parsing or any other aspects of the console apart from the help system. Backwards compatible with existing modules. --- OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 9b80245..8b9e749 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -72,19 +72,19 @@ namespace OpenSim.Server.Handlers.Asset server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowDelete)); - MainConsole.Instance.Commands.AddCommand("kfs", false, + MainConsole.Instance.Commands.AddCommand("Assets", false, "show asset", "show asset ", "Show asset information", HandleShowAsset); - MainConsole.Instance.Commands.AddCommand("kfs", false, + MainConsole.Instance.Commands.AddCommand("Assets", false, "delete asset", "delete asset ", "Delete asset from database", HandleDeleteAsset); - MainConsole.Instance.Commands.AddCommand("kfs", false, + MainConsole.Instance.Commands.AddCommand("Assets", false, "dump asset", "dump asset ", "Dump asset to a file", -- cgit v1.1 From 8131a24cde3f3877b3b8dd850871c57c17b2b216 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Tue, 27 Mar 2012 10:08:13 -0700 Subject: Send the config section name up to the service classes themselves (XInventory and Assets). --- OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 8b9e749..46b0c67 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -59,7 +59,7 @@ namespace OpenSim.Server.Handlers.Asset if (assetService == String.Empty) throw new Exception("No LocalServiceModule in config file"); - Object[] args = new Object[] { config }; + Object[] args = new Object[] { config, m_ConfigName }; m_AssetService = ServerUtils.LoadPlugin(assetService, args); -- cgit v1.1 From f76dceb90b5a76a7b6a5243c9032996c007c0cf5 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 24 Oct 2012 03:08:58 +0100 Subject: Get "save oar" and "save iar" to tell you in a more friendly manner if the filename to save already exists, rather than exception throwing. Also changes ConsoleUtil.CheckFileExists to CheckFileDoesNotExist() since this is more meaningful in the context, even though it does result in double negatives. --- OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 46b0c67..4123f49 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -141,6 +141,9 @@ namespace OpenSim.Server.Handlers.Asset } string fileName = rawAssetId; + + if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, fileName)) + return; using (FileStream fs = new FileStream(fileName, FileMode.CreateNew)) { -- cgit v1.1 From 462ad336dcd59dfc4325aed9e6d635aa866cd094 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 2 Nov 2012 00:02:10 +0000 Subject: Move check to allow only deletion of maptiles up to AssetServerDeleteHandler from AssetService. This allows us to use a common check for both AssetService and XAssetService. It also allows future console commands to delete an asset. As before, deletion of maptile assets is not allowed remotely unless this is explicitly configured. --- .../Server/Handlers/Asset/AssetServerDeleteHandler.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs index 0cfe5b1..9a8aee6 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs @@ -44,7 +44,7 @@ namespace OpenSim.Server.Handlers.Asset { public class AssetServerDeleteHandler : BaseStreamHandler { - // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAssetService m_AssetService; protected bool m_allowDelete; @@ -65,11 +65,22 @@ namespace OpenSim.Server.Handlers.Asset if (p.Length > 0 && m_allowDelete) { - result = m_AssetService.Delete(p[0]); + string assetID = p[0]; + + AssetBase asset = m_AssetService.Get(assetID); + if (asset != null && (int)(asset.Flags & AssetFlags.Maptile) != 0) + { + result = m_AssetService.Delete(assetID); + } + else + { + m_log.DebugFormat( + "[ASSET SERVER DELETE HANDLER]: Request to delete asset {0}, but flags are not Maptile", assetID); + } } XmlSerializer xs = new XmlSerializer(typeof(bool)); return ServerUtils.SerializeResult(xs, result); } } -} +} \ No newline at end of file -- cgit v1.1 From ce7beb6f20cb09e19e0f695f445cfa860b9e9c78 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 2 Nov 2012 01:41:38 +0000 Subject: Add [AssetService] AllowRemoteDeleteAllTypes (default false). This allows a closed grid to delete asset types other than maptile remotely. Only operational if AllowRemoteDelete = true also. Defaults to false - do not enable if anybody other than you can make asset service requests. --- .../Server/Handlers/Asset/AssetServerConnector.cs | 17 +++++++- .../Handlers/Asset/AssetServerDeleteHandler.cs | 50 ++++++++++++++++------ 2 files changed, 52 insertions(+), 15 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 4123f49..ff45d94 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -67,10 +67,25 @@ namespace OpenSim.Server.Handlers.Asset throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false); + bool allowDeleteAllTypes = serverConfig.GetBoolean("AllowRemoteDeleteAllTypes", false); + + AllowedRemoteDeleteTypes allowedRemoteDeleteTypes; + + if (!allowDelete) + { + allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.None; + } + else + { + if (allowDeleteAllTypes) + allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.All; + else + allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.MapTile; + } server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); - server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowDelete)); + server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes)); MainConsole.Instance.Commands.AddCommand("Assets", false, "show asset", diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs index 9a8aee6..986394b 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs @@ -42,18 +42,32 @@ using OpenSim.Framework.Servers.HttpServer; namespace OpenSim.Server.Handlers.Asset { + /// + /// Remote deletes allowed. + /// + public enum AllowedRemoteDeleteTypes + { + None, + MapTile, + All + } + public class AssetServerDeleteHandler : BaseStreamHandler { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAssetService m_AssetService; - protected bool m_allowDelete; - public AssetServerDeleteHandler(IAssetService service, bool allowDelete) : + /// + /// Asset types that can be deleted remotely. + /// + private AllowedRemoteDeleteTypes m_allowedTypes; + + public AssetServerDeleteHandler(IAssetService service, AllowedRemoteDeleteTypes allowedTypes) : base("DELETE", "/assets") { m_AssetService = service; - m_allowDelete = allowDelete; + m_allowedTypes = allowedTypes; } public override byte[] Handle(string path, Stream request, @@ -63,19 +77,27 @@ namespace OpenSim.Server.Handlers.Asset string[] p = SplitParams(path); - if (p.Length > 0 && m_allowDelete) + if (p.Length > 0) { - string assetID = p[0]; - - AssetBase asset = m_AssetService.Get(assetID); - if (asset != null && (int)(asset.Flags & AssetFlags.Maptile) != 0) - { - result = m_AssetService.Delete(assetID); - } - else + if (m_allowedTypes != AllowedRemoteDeleteTypes.None) { - m_log.DebugFormat( - "[ASSET SERVER DELETE HANDLER]: Request to delete asset {0}, but flags are not Maptile", assetID); + string assetID = p[0]; + + AssetBase asset = m_AssetService.Get(assetID); + if (asset != null) + { + if (m_allowedTypes == AllowedRemoteDeleteTypes.All + || (int)(asset.Flags & AssetFlags.Maptile) != 0) + { + result = m_AssetService.Delete(assetID); + } + else + { + m_log.DebugFormat( + "[ASSET SERVER DELETE HANDLER]: Request to delete asset {0}, but type is {1} and allowed remote delete types are {2}", + assetID, (AssetFlags)asset.Flags, m_allowedTypes); + } + } } } -- cgit v1.1 From bac8ac32dae4049e84f74d276bb5ce83a2a512ac Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 21 Nov 2012 23:42:34 +0000 Subject: Add regression test for a good request made to the asset service post handler. Adds new OpenSim.Server.Handlers.Tests.dll to test suite --- .../Asset/Tests/AssetServerPostHandlerTests.cs | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs new file mode 100644 index 0000000..9e82576 --- /dev/null +++ b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs @@ -0,0 +1,84 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.IO; +using System.Text; +using System.Xml; +using System.Xml.Serialization; +using Nini.Config; +using NUnit.Framework; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Server.Handlers.Asset; +using OpenSim.Services.AssetService; +using OpenSim.Services.Interfaces; +using OpenSim.Tests.Common; + +namespace OpenSim.Server.Handlers.Asset.Test +{ + [TestFixture] + public class AssetServerPostHandlerTests : OpenSimTestCase + { + [Test] + public void TestGoodAssetStoreRequest() + { + TestHelpers.InMethod(); + + UUID assetId = TestHelpers.ParseTail(0x1); + + IConfigSource config = new IniConfigSource(); + config.AddConfig("AssetService"); + config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); + + AssetService assetService = new AssetService(config); + + AssetServerPostHandler asph = new AssetServerPostHandler(assetService); + + AssetBase asset = AssetHelpers.CreateNotecardAsset(assetId, "Hello World"); + + MemoryStream buffer = new MemoryStream(); + + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Encoding = Encoding.UTF8; + + using (XmlWriter writer = XmlWriter.Create(buffer, settings)) + { + XmlSerializer serializer = new XmlSerializer(typeof(AssetBase)); + serializer.Serialize(writer, asset); + writer.Flush(); + } + + buffer.Position = 0; + asph.Handle(null, buffer, null, null); + + AssetBase retrievedAsset = assetService.Get(assetId.ToString()); + + Assert.That(retrievedAsset, Is.Not.Null); + } + } +} \ No newline at end of file -- cgit v1.1 From 448811ccddfa6fb3dbbd7279e240ff9ef805d218 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 22 Nov 2012 03:01:57 +0000 Subject: If an asset POST does not contain well-formed XML, return a 400 (Bad Request) HTTP status rather than simply dropping the request. --- .../Handlers/Asset/AssetServerPostHandler.cs | 15 ++++++++++--- .../Asset/Tests/AssetServerPostHandlerTests.cs | 26 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs index 87b3d2d..a006fa8 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs @@ -57,14 +57,23 @@ namespace OpenSim.Server.Handlers.Asset public override byte[] Handle(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { + AssetBase asset; XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); - AssetBase asset = (AssetBase) xs.Deserialize(request); + + try + { + asset = (AssetBase)xs.Deserialize(request); + } + catch (XmlException) + { + httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; + return null; + } string[] p = SplitParams(path); if (p.Length > 1) { - bool result = - m_AssetService.UpdateContent(p[1], asset.Data); + bool result = m_AssetService.UpdateContent(p[1], asset.Data); xs = new XmlSerializer(typeof(bool)); return ServerUtils.SerializeResult(xs, result); diff --git a/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs index 9e82576..427fa16 100644 --- a/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs +++ b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs @@ -27,6 +27,7 @@ using System; using System.IO; +using System.Net; using System.Text; using System.Xml; using System.Xml.Serialization; @@ -38,6 +39,7 @@ using OpenSim.Server.Handlers.Asset; using OpenSim.Services.AssetService; using OpenSim.Services.Interfaces; using OpenSim.Tests.Common; +using OpenSim.Tests.Common.Mock; namespace OpenSim.Server.Handlers.Asset.Test { @@ -80,5 +82,29 @@ namespace OpenSim.Server.Handlers.Asset.Test Assert.That(retrievedAsset, Is.Not.Null); } + + [Test] + public void TestBadXmlAssetStoreRequest() + { + TestHelpers.InMethod(); + + IConfigSource config = new IniConfigSource(); + config.AddConfig("AssetService"); + config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); + + AssetService assetService = new AssetService(config); + + AssetServerPostHandler asph = new AssetServerPostHandler(assetService); + + MemoryStream buffer = new MemoryStream(); + byte[] badData = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f }; + buffer.Write(badData, 0, badData.Length); + buffer.Position = 0; + + TestOSHttpResponse response = new TestOSHttpResponse(); + asph.Handle(null, buffer, null, response); + + Assert.That(response.StatusCode, Is.EqualTo((int)HttpStatusCode.BadRequest)); + } } } \ No newline at end of file -- cgit v1.1 From e26e8b882965430f66c6459987a8b219d68e5da1 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 28 Jun 2013 19:19:38 +0100 Subject: Remove "Asset deletion not supported by database" message from "delete asset" robust/standalone console command since it actually was implemented and performed. Improve other associated messages. --- OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index ff45d94..cc4325a 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -119,16 +119,14 @@ namespace OpenSim.Server.Handlers.Asset if (asset == null || asset.Data.Length == 0) { - MainConsole.Instance.Output("Asset not found"); + MainConsole.Instance.OutputFormat("Could not find asset with ID {0}", args[2]); return; } - m_AssetService.Delete(args[2]); - - //MainConsole.Instance.Output("Asset deleted"); - // TODO: Implement this - - MainConsole.Instance.Output("Asset deletion not supported by database"); + if (!m_AssetService.Delete(asset.ID)) + MainConsole.Instance.OutputFormat("ERROR: Could not delete asset {0} {1}", asset.ID, asset.Name); + else + MainConsole.Instance.OutputFormat("Deleted asset {0} {1}", asset.ID, asset.Name); } void HandleDumpAsset(string module, string[] args) -- cgit v1.1 From e19defde36ddbd5ff90d8304c6fe3b57110f8078 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 8 Jul 2013 22:03:07 +0100 Subject: Add "show caps stats by user" and "show caps stats by cap" console commands to print various counts of capability invocation by user and by cap This currently prints caps requests received and handled, so that overload of received compared to handled or deadlock can be detected. This involves making BaseStreamHandler and BaseOutputStream record the ints, which means inheritors should subclass ProcessRequest() instead of Handle() However, existing inheriting classes overriding Handle() will still work, albeit without stats recording. "show caps" becomes "show caps list" to disambiguate between show caps commands --- OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs | 2 +- OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs | 2 +- OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs index 986394b..941b97d 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs @@ -70,7 +70,7 @@ namespace OpenSim.Server.Handlers.Asset m_allowedTypes = allowedTypes; } - public override byte[] Handle(string path, Stream request, + protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { bool result = false; diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs index 8f7412b..8b23a83 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs @@ -54,7 +54,7 @@ namespace OpenSim.Server.Handlers.Asset m_AssetService = service; } - public override byte[] Handle(string path, Stream request, + protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { byte[] result = new byte[0]; diff --git a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs index a006fa8..8eebc61 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs @@ -54,7 +54,7 @@ namespace OpenSim.Server.Handlers.Asset m_AssetService = service; } - public override byte[] Handle(string path, Stream request, + protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { AssetBase asset; -- cgit v1.1 From d1c3f8eef58b29eb8760eeb1ac03852a2387f927 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Mon, 31 Mar 2014 11:53:12 +0300 Subject: Added assets service method AssetsExist(), which returns whether the given list of assets exist. This method is used to optimize sending assets with embedded assets: e.g., when a Hypergrid visitor takes an item into the inventory. --- .../Server/Handlers/Asset/AssetServerConnector.cs | 3 +- .../Server/Handlers/Asset/AssetServerGetHandler.cs | 74 +++++++++++++------- .../Server/Handlers/Asset/AssetsExistHandler.cs | 80 ++++++++++++++++++++++ 3 files changed, 131 insertions(+), 26 deletions(-) create mode 100644 OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index cc4325a..9b86986 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -86,6 +86,7 @@ namespace OpenSim.Server.Handlers.Asset server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes)); + server.AddStreamHandler(new AssetsExistHandler(m_AssetService)); MainConsole.Instance.Commands.AddCommand("Assets", false, "show asset", @@ -212,4 +213,4 @@ namespace OpenSim.Server.Handlers.Asset } } } -} \ No newline at end of file +} diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs index 8b23a83..ed3b4af 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs @@ -64,45 +64,61 @@ namespace OpenSim.Server.Handlers.Asset if (p.Length == 0) return result; - if (p.Length > 1 && p[1] == "data") + if (p.Length > 1) { - result = m_AssetService.GetData(p[0]); - if (result == null) + string id = p[0]; + string cmd = p[1]; + + if (cmd == "data") { - httpResponse.StatusCode = (int)HttpStatusCode.NotFound; - httpResponse.ContentType = "text/plain"; - result = new byte[0]; + result = m_AssetService.GetData(id); + if (result == null) + { + httpResponse.StatusCode = (int)HttpStatusCode.NotFound; + httpResponse.ContentType = "text/plain"; + result = new byte[0]; + } + else + { + httpResponse.StatusCode = (int)HttpStatusCode.OK; + httpResponse.ContentType = "application/octet-stream"; + } } - else + else if (cmd == "metadata") { - httpResponse.StatusCode = (int)HttpStatusCode.OK; - httpResponse.ContentType = "application/octet-stream"; - } - } - else if (p.Length > 1 && p[1] == "metadata") - { - AssetMetadata metadata = m_AssetService.GetMetadata(p[0]); + AssetMetadata metadata = m_AssetService.GetMetadata(id); - if (metadata != null) - { - XmlSerializer xs = - new XmlSerializer(typeof(AssetMetadata)); - result = ServerUtils.SerializeResult(xs, metadata); + if (metadata != null) + { + XmlSerializer xs = + new XmlSerializer(typeof(AssetMetadata)); + result = ServerUtils.SerializeResult(xs, metadata); - httpResponse.StatusCode = (int)HttpStatusCode.OK; - httpResponse.ContentType = - SLUtil.SLAssetTypeToContentType(metadata.Type); + httpResponse.StatusCode = (int)HttpStatusCode.OK; + httpResponse.ContentType = + SLUtil.SLAssetTypeToContentType(metadata.Type); + } + else + { + httpResponse.StatusCode = (int)HttpStatusCode.NotFound; + httpResponse.ContentType = "text/plain"; + result = new byte[0]; + } } else { - httpResponse.StatusCode = (int)HttpStatusCode.NotFound; + // Unknown request + httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; httpResponse.ContentType = "text/plain"; result = new byte[0]; } } - else + else if (p.Length == 1) { - AssetBase asset = m_AssetService.Get(p[0]); + // Get the entire asset (metadata + data) + + string id = p[0]; + AssetBase asset = m_AssetService.Get(id); if (asset != null) { @@ -120,6 +136,14 @@ namespace OpenSim.Server.Handlers.Asset result = new byte[0]; } } + else + { + // Unknown request + httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; + httpResponse.ContentType = "text/plain"; + result = new byte[0]; + } + return result; } } diff --git a/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs b/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs new file mode 100644 index 0000000..6d01f86 --- /dev/null +++ b/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs @@ -0,0 +1,80 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using Nini.Config; +using log4net; +using System; +using System.Reflection; +using System.IO; +using System.Net; +using System.Text; +using System.Text.RegularExpressions; +using System.Xml; +using System.Xml.Serialization; +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; +using OpenSim.Framework; +using OpenSim.Framework.Servers.HttpServer; +using OpenMetaverse; + +namespace OpenSim.Server.Handlers.Asset +{ + public class AssetsExistHandler : BaseStreamHandler + { + //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private IAssetService m_AssetService; + + public AssetsExistHandler(IAssetService service) : + base("POST", "/get_assets_exist") + { + m_AssetService = service; + } + + protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) + { + XmlSerializer xs; + + string[] ids; + try + { + xs = new XmlSerializer(typeof(string[])); + ids = (string[])xs.Deserialize(request); + } + catch (Exception) + { + httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; + return null; + } + + bool[] exist = m_AssetService.AssetsExist(ids); + + xs = new XmlSerializer(typeof(bool[])); + return ServerUtils.SerializeResult(xs, exist); + } + } +} -- cgit v1.1 From fad0fd7f75a5829303944bb59c940afba3448b17 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Tue, 1 Apr 2014 14:58:34 +0300 Subject: Fixed the "Update Asset" handler: it was looking for the Asset ID in the wrong parameter. This doesn't actually matter because the "Update Asset" operation isn't implemented in AssetsServer. But still, the handler should do the right thing... --- OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs index 8eebc61..5122a77 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs @@ -58,7 +58,7 @@ namespace OpenSim.Server.Handlers.Asset IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { AssetBase asset; - XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); + XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); try { @@ -71,18 +71,21 @@ namespace OpenSim.Server.Handlers.Asset } string[] p = SplitParams(path); - if (p.Length > 1) + if (p.Length > 0) { - bool result = m_AssetService.UpdateContent(p[1], asset.Data); + string id = p[0]; + bool result = m_AssetService.UpdateContent(id, asset.Data); xs = new XmlSerializer(typeof(bool)); return ServerUtils.SerializeResult(xs, result); } + else + { + string id = m_AssetService.Store(asset); - string id = m_AssetService.Store(asset); - - xs = new XmlSerializer(typeof(string)); - return ServerUtils.SerializeResult(xs, id); + xs = new XmlSerializer(typeof(string)); + return ServerUtils.SerializeResult(xs, id); + } } } } -- cgit v1.1 From ef262799ca2795cabf9e2f63e29698872e0c9414 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Tue, 6 May 2014 09:43:07 +0300 Subject: Better error handling in AssetServerPostHandler. Invalid XML causes an InvalidOperationException, not an XmlException --- OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs index 5122a77..a77e67d 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs @@ -64,7 +64,7 @@ namespace OpenSim.Server.Handlers.Asset { asset = (AssetBase)xs.Deserialize(request); } - catch (XmlException) + catch (Exception) { httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; return null; -- cgit v1.1 From 20f20895cf1444071d5edc42e11a1fb94b1b1079 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 23 May 2014 16:19:43 -0700 Subject: Adds optional HTTP Basic Authentication to Robust service connectors. --- OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | 9 ++++++--- OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs | 7 +++++++ OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs | 9 ++++++++- OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs | 7 +++++++ OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs | 7 +++++++ 5 files changed, 35 insertions(+), 4 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 9b86986..df9a51b 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -30,6 +30,7 @@ using System.IO; using Nini.Config; using OpenMetaverse; using OpenSim.Framework; +using OpenSim.Framework.ServiceAuth; using OpenSim.Framework.Console; using OpenSim.Server.Base; using OpenSim.Services.Interfaces; @@ -83,9 +84,11 @@ namespace OpenSim.Server.Handlers.Asset allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.MapTile; } - server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); - server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); - server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes)); + IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); + + server.AddStreamHandler(new AssetServerGetHandler(m_AssetService, auth)); + server.AddStreamHandler(new AssetServerPostHandler(m_AssetService, auth)); + server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes, auth)); server.AddStreamHandler(new AssetsExistHandler(m_AssetService)); MainConsole.Instance.Commands.AddCommand("Assets", false, diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs index 941b97d..d85d471 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs @@ -38,6 +38,7 @@ using System.Xml.Serialization; using OpenSim.Server.Base; using OpenSim.Services.Interfaces; using OpenSim.Framework; +using OpenSim.Framework.ServiceAuth; using OpenSim.Framework.Servers.HttpServer; namespace OpenSim.Server.Handlers.Asset @@ -70,6 +71,12 @@ namespace OpenSim.Server.Handlers.Asset m_allowedTypes = allowedTypes; } + public AssetServerDeleteHandler(IAssetService service, AllowedRemoteDeleteTypes allowedTypes, IServiceAuth auth) : + base("DELETE", "/assets", auth) + { + m_AssetService = service; + m_allowedTypes = allowedTypes; + } protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs index ed3b4af..500ec50 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs @@ -38,19 +38,26 @@ using System.Xml.Serialization; using OpenSim.Server.Base; using OpenSim.Services.Interfaces; using OpenSim.Framework; +using OpenSim.Framework.ServiceAuth; using OpenSim.Framework.Servers.HttpServer; namespace OpenSim.Server.Handlers.Asset { public class AssetServerGetHandler : BaseStreamHandler { - // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAssetService m_AssetService; public AssetServerGetHandler(IAssetService service) : base("GET", "/assets") { + m_AssetService = service; + } + + public AssetServerGetHandler(IAssetService service, IServiceAuth auth) : + base("GET", "/assets", auth) + { m_AssetService = service; } diff --git a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs index a77e67d..1c706a7 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs @@ -38,6 +38,7 @@ using System.Xml.Serialization; using OpenSim.Server.Base; using OpenSim.Services.Interfaces; using OpenSim.Framework; +using OpenSim.Framework.ServiceAuth; using OpenSim.Framework.Servers.HttpServer; namespace OpenSim.Server.Handlers.Asset @@ -54,6 +55,12 @@ namespace OpenSim.Server.Handlers.Asset m_AssetService = service; } + public AssetServerPostHandler(IAssetService service, IServiceAuth auth) : + base("POST", "/assets", auth) + { + m_AssetService = service; + } + protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { diff --git a/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs b/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs index 6d01f86..32901b3 100644 --- a/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs @@ -38,6 +38,7 @@ using System.Xml.Serialization; using OpenSim.Server.Base; using OpenSim.Services.Interfaces; using OpenSim.Framework; +using OpenSim.Framework.ServiceAuth; using OpenSim.Framework.Servers.HttpServer; using OpenMetaverse; @@ -55,6 +56,12 @@ namespace OpenSim.Server.Handlers.Asset m_AssetService = service; } + public AssetsExistHandler(IAssetService service, IServiceAuth auth) : + base("POST", "/get_assets_exist", auth) + { + m_AssetService = service; + } + protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { XmlSerializer xs; -- cgit v1.1 From 449548d7a4e3571597b5e4bec53e3f42ebdf6015 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 26 May 2014 08:13:49 -0700 Subject: Adds an optional redirect URL to the asset server handler for when assets are not found locally. --- .../Server/Handlers/Asset/AssetServerConnector.cs | 4 +++- .../Server/Handlers/Asset/AssetServerGetHandler.cs | 21 ++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index df9a51b..ab81dd6 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -70,6 +70,8 @@ namespace OpenSim.Server.Handlers.Asset bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false); bool allowDeleteAllTypes = serverConfig.GetBoolean("AllowRemoteDeleteAllTypes", false); + string redirectURL = serverConfig.GetString("RedirectURL", string.Empty); + AllowedRemoteDeleteTypes allowedRemoteDeleteTypes; if (!allowDelete) @@ -86,7 +88,7 @@ namespace OpenSim.Server.Handlers.Asset IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); - server.AddStreamHandler(new AssetServerGetHandler(m_AssetService, auth)); + server.AddStreamHandler(new AssetServerGetHandler(m_AssetService, auth, redirectURL)); server.AddStreamHandler(new AssetServerPostHandler(m_AssetService, auth)); server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes, auth)); server.AddStreamHandler(new AssetsExistHandler(m_AssetService)); diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs index 500ec50..91c5c54 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs @@ -48,6 +48,7 @@ namespace OpenSim.Server.Handlers.Asset private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAssetService m_AssetService; + private string m_RedirectURL; public AssetServerGetHandler(IAssetService service) : base("GET", "/assets") @@ -55,10 +56,13 @@ namespace OpenSim.Server.Handlers.Asset m_AssetService = service; } - public AssetServerGetHandler(IAssetService service, IServiceAuth auth) : + public AssetServerGetHandler(IAssetService service, IServiceAuth auth, string redirectURL) : base("GET", "/assets", auth) { m_AssetService = service; + m_RedirectURL = redirectURL; + if (!m_RedirectURL.EndsWith("/")) + m_RedirectURL = m_RedirectURL.TrimEnd('/'); } protected override byte[] ProcessRequest(string path, Stream request, @@ -71,9 +75,10 @@ namespace OpenSim.Server.Handlers.Asset if (p.Length == 0) return result; + string id = string.Empty; if (p.Length > 1) { - string id = p[0]; + id = p[0]; string cmd = p[1]; if (cmd == "data") @@ -124,7 +129,7 @@ namespace OpenSim.Server.Handlers.Asset { // Get the entire asset (metadata + data) - string id = p[0]; + id = p[0]; AssetBase asset = m_AssetService.Get(id); if (asset != null) @@ -151,6 +156,16 @@ namespace OpenSim.Server.Handlers.Asset result = new byte[0]; } + if (httpResponse.StatusCode == (int)HttpStatusCode.NotFound && !string.IsNullOrEmpty(m_RedirectURL) && !string.IsNullOrEmpty(id)) + { + httpResponse.StatusCode = (int)HttpStatusCode.Redirect; + string rurl = m_RedirectURL; + if (!path.StartsWith("/")) + rurl += "/"; + rurl += path; + httpResponse.AddHeader("Location", rurl); + m_log.DebugFormat("[ASSET GET HANDLER]: Asset not found, redirecting to {0} ({1})", rurl, httpResponse.StatusCode); + } return result; } } -- cgit v1.1 From fc878a33edcb403018e485ba0e8b7a6b3a8c3a16 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 8 Oct 2014 21:09:25 +0100 Subject: refactor: consistently put all test classes in the OpenSim.Tests.Common package rather than some in OpenSim.Tests.Common.Mock the separate mock package was not useful and was just another using line to always add --- OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'OpenSim/Server/Handlers/Asset') diff --git a/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs index 427fa16..faa6fb7 100644 --- a/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs +++ b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs @@ -39,7 +39,6 @@ using OpenSim.Server.Handlers.Asset; using OpenSim.Services.AssetService; using OpenSim.Services.Interfaces; using OpenSim.Tests.Common; -using OpenSim.Tests.Common.Mock; namespace OpenSim.Server.Handlers.Asset.Test { -- cgit v1.1