diff options
author | BlueWall | 2012-11-25 17:03:14 -0500 |
---|---|---|
committer | BlueWall | 2012-11-25 17:03:14 -0500 |
commit | c754003944d0166bf50b4f94b0c0eea642503bb0 (patch) | |
tree | dfa1c2020d5500d510519d5b2b3236600692f277 /OpenSim/Server/Handlers | |
parent | Merge branch 'master' into connector_plugin (diff) | |
parent | Combine TestDeleteSceneObjectAsync() with TestDeRezSceneObject() as they are ... (diff) | |
download | opensim-SC_OLD-c754003944d0166bf50b4f94b0c0eea642503bb0.zip opensim-SC_OLD-c754003944d0166bf50b4f94b0c0eea642503bb0.tar.gz opensim-SC_OLD-c754003944d0166bf50b4f94b0c0eea642503bb0.tar.bz2 opensim-SC_OLD-c754003944d0166bf50b4f94b0c0eea642503bb0.tar.xz |
Merge branch 'master' into connector_plugin
Conflicts:
OpenSim/Server/Base/ServicesServerBase.cs
Diffstat (limited to 'OpenSim/Server/Handlers')
5 files changed, 214 insertions, 11 deletions
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 46b0c67..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 | |||
67 | throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); | 67 | throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); |
68 | 68 | ||
69 | bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false); | 69 | bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false); |
70 | bool allowDeleteAllTypes = serverConfig.GetBoolean("AllowRemoteDeleteAllTypes", false); | ||
71 | |||
72 | AllowedRemoteDeleteTypes allowedRemoteDeleteTypes; | ||
73 | |||
74 | if (!allowDelete) | ||
75 | { | ||
76 | allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.None; | ||
77 | } | ||
78 | else | ||
79 | { | ||
80 | if (allowDeleteAllTypes) | ||
81 | allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.All; | ||
82 | else | ||
83 | allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.MapTile; | ||
84 | } | ||
70 | 85 | ||
71 | server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); | 86 | server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); |
72 | server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); | 87 | server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); |
73 | server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowDelete)); | 88 | server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes)); |
74 | 89 | ||
75 | MainConsole.Instance.Commands.AddCommand("Assets", false, | 90 | MainConsole.Instance.Commands.AddCommand("Assets", false, |
76 | "show asset", | 91 | "show asset", |
@@ -141,6 +156,9 @@ namespace OpenSim.Server.Handlers.Asset | |||
141 | } | 156 | } |
142 | 157 | ||
143 | string fileName = rawAssetId; | 158 | string fileName = rawAssetId; |
159 | |||
160 | if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, fileName)) | ||
161 | return; | ||
144 | 162 | ||
145 | using (FileStream fs = new FileStream(fileName, FileMode.CreateNew)) | 163 | using (FileStream fs = new FileStream(fileName, FileMode.CreateNew)) |
146 | { | 164 | { |
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs index 0cfe5b1..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; | |||
42 | 42 | ||
43 | namespace OpenSim.Server.Handlers.Asset | 43 | namespace OpenSim.Server.Handlers.Asset |
44 | { | 44 | { |
45 | /// <summary> | ||
46 | /// Remote deletes allowed. | ||
47 | /// </summary> | ||
48 | public enum AllowedRemoteDeleteTypes | ||
49 | { | ||
50 | None, | ||
51 | MapTile, | ||
52 | All | ||
53 | } | ||
54 | |||
45 | public class AssetServerDeleteHandler : BaseStreamHandler | 55 | public class AssetServerDeleteHandler : BaseStreamHandler |
46 | { | 56 | { |
47 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 57 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
48 | 58 | ||
49 | private IAssetService m_AssetService; | 59 | private IAssetService m_AssetService; |
50 | protected bool m_allowDelete; | ||
51 | 60 | ||
52 | public AssetServerDeleteHandler(IAssetService service, bool allowDelete) : | 61 | /// <summary> |
62 | /// Asset types that can be deleted remotely. | ||
63 | /// </summary> | ||
64 | private AllowedRemoteDeleteTypes m_allowedTypes; | ||
65 | |||
66 | public AssetServerDeleteHandler(IAssetService service, AllowedRemoteDeleteTypes allowedTypes) : | ||
53 | base("DELETE", "/assets") | 67 | base("DELETE", "/assets") |
54 | { | 68 | { |
55 | m_AssetService = service; | 69 | m_AssetService = service; |
56 | m_allowDelete = allowDelete; | 70 | m_allowedTypes = allowedTypes; |
57 | } | 71 | } |
58 | 72 | ||
59 | public override byte[] Handle(string path, Stream request, | 73 | public override byte[] Handle(string path, Stream request, |
@@ -63,13 +77,32 @@ namespace OpenSim.Server.Handlers.Asset | |||
63 | 77 | ||
64 | string[] p = SplitParams(path); | 78 | string[] p = SplitParams(path); |
65 | 79 | ||
66 | if (p.Length > 0 && m_allowDelete) | 80 | if (p.Length > 0) |
67 | { | 81 | { |
68 | result = m_AssetService.Delete(p[0]); | 82 | if (m_allowedTypes != AllowedRemoteDeleteTypes.None) |
83 | { | ||
84 | string assetID = p[0]; | ||
85 | |||
86 | AssetBase asset = m_AssetService.Get(assetID); | ||
87 | if (asset != null) | ||
88 | { | ||
89 | if (m_allowedTypes == AllowedRemoteDeleteTypes.All | ||
90 | || (int)(asset.Flags & AssetFlags.Maptile) != 0) | ||
91 | { | ||
92 | result = m_AssetService.Delete(assetID); | ||
93 | } | ||
94 | else | ||
95 | { | ||
96 | m_log.DebugFormat( | ||
97 | "[ASSET SERVER DELETE HANDLER]: Request to delete asset {0}, but type is {1} and allowed remote delete types are {2}", | ||
98 | assetID, (AssetFlags)asset.Flags, m_allowedTypes); | ||
99 | } | ||
100 | } | ||
101 | } | ||
69 | } | 102 | } |
70 | 103 | ||
71 | XmlSerializer xs = new XmlSerializer(typeof(bool)); | 104 | XmlSerializer xs = new XmlSerializer(typeof(bool)); |
72 | return ServerUtils.SerializeResult(xs, result); | 105 | return ServerUtils.SerializeResult(xs, result); |
73 | } | 106 | } |
74 | } | 107 | } |
75 | } | 108 | } \ No newline at end of file |
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 | |||
57 | public override byte[] Handle(string path, Stream request, | 57 | public override byte[] Handle(string path, Stream request, |
58 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 58 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) |
59 | { | 59 | { |
60 | AssetBase asset; | ||
60 | XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); | 61 | XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); |
61 | AssetBase asset = (AssetBase) xs.Deserialize(request); | 62 | |
63 | try | ||
64 | { | ||
65 | asset = (AssetBase)xs.Deserialize(request); | ||
66 | } | ||
67 | catch (XmlException) | ||
68 | { | ||
69 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
70 | return null; | ||
71 | } | ||
62 | 72 | ||
63 | string[] p = SplitParams(path); | 73 | string[] p = SplitParams(path); |
64 | if (p.Length > 1) | 74 | if (p.Length > 1) |
65 | { | 75 | { |
66 | bool result = | 76 | bool result = m_AssetService.UpdateContent(p[1], asset.Data); |
67 | m_AssetService.UpdateContent(p[1], asset.Data); | ||
68 | 77 | ||
69 | xs = new XmlSerializer(typeof(bool)); | 78 | xs = new XmlSerializer(typeof(bool)); |
70 | return ServerUtils.SerializeResult(xs, result); | 79 | return ServerUtils.SerializeResult(xs, result); |
diff --git a/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs new file mode 100644 index 0000000..427fa16 --- /dev/null +++ b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Net; | ||
31 | using System.Text; | ||
32 | using System.Xml; | ||
33 | using System.Xml.Serialization; | ||
34 | using Nini.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Server.Handlers.Asset; | ||
39 | using OpenSim.Services.AssetService; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Tests.Common; | ||
42 | using OpenSim.Tests.Common.Mock; | ||
43 | |||
44 | namespace OpenSim.Server.Handlers.Asset.Test | ||
45 | { | ||
46 | [TestFixture] | ||
47 | public class AssetServerPostHandlerTests : OpenSimTestCase | ||
48 | { | ||
49 | [Test] | ||
50 | public void TestGoodAssetStoreRequest() | ||
51 | { | ||
52 | TestHelpers.InMethod(); | ||
53 | |||
54 | UUID assetId = TestHelpers.ParseTail(0x1); | ||
55 | |||
56 | IConfigSource config = new IniConfigSource(); | ||
57 | config.AddConfig("AssetService"); | ||
58 | config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
59 | |||
60 | AssetService assetService = new AssetService(config); | ||
61 | |||
62 | AssetServerPostHandler asph = new AssetServerPostHandler(assetService); | ||
63 | |||
64 | AssetBase asset = AssetHelpers.CreateNotecardAsset(assetId, "Hello World"); | ||
65 | |||
66 | MemoryStream buffer = new MemoryStream(); | ||
67 | |||
68 | XmlWriterSettings settings = new XmlWriterSettings(); | ||
69 | settings.Encoding = Encoding.UTF8; | ||
70 | |||
71 | using (XmlWriter writer = XmlWriter.Create(buffer, settings)) | ||
72 | { | ||
73 | XmlSerializer serializer = new XmlSerializer(typeof(AssetBase)); | ||
74 | serializer.Serialize(writer, asset); | ||
75 | writer.Flush(); | ||
76 | } | ||
77 | |||
78 | buffer.Position = 0; | ||
79 | asph.Handle(null, buffer, null, null); | ||
80 | |||
81 | AssetBase retrievedAsset = assetService.Get(assetId.ToString()); | ||
82 | |||
83 | Assert.That(retrievedAsset, Is.Not.Null); | ||
84 | } | ||
85 | |||
86 | [Test] | ||
87 | public void TestBadXmlAssetStoreRequest() | ||
88 | { | ||
89 | TestHelpers.InMethod(); | ||
90 | |||
91 | IConfigSource config = new IniConfigSource(); | ||
92 | config.AddConfig("AssetService"); | ||
93 | config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
94 | |||
95 | AssetService assetService = new AssetService(config); | ||
96 | |||
97 | AssetServerPostHandler asph = new AssetServerPostHandler(assetService); | ||
98 | |||
99 | MemoryStream buffer = new MemoryStream(); | ||
100 | byte[] badData = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f }; | ||
101 | buffer.Write(badData, 0, badData.Length); | ||
102 | buffer.Position = 0; | ||
103 | |||
104 | TestOSHttpResponse response = new TestOSHttpResponse(); | ||
105 | asph.Handle(null, buffer, null, response); | ||
106 | |||
107 | Assert.That(response.StatusCode, Is.EqualTo((int)HttpStatusCode.BadRequest)); | ||
108 | } | ||
109 | } | ||
110 | } \ No newline at end of file | ||
diff --git a/OpenSim/Server/Handlers/Properties/AssemblyInfo.cs b/OpenSim/Server/Handlers/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..53e9737 --- /dev/null +++ b/OpenSim/Server/Handlers/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,33 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.Server.Handlers")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
12 | [assembly: AssemblyProduct("OpenSim")] | ||
13 | [assembly: AssemblyCopyright("OpenSimulator developers")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("6319afca-d740-4468-a95d-d7f87a081cb3")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | [assembly: AssemblyVersion("0.7.5.*")] | ||
33 | [assembly: AssemblyFileVersion("1.0.0.0")] | ||