aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Asset
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Server/Handlers/Asset
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Server/Handlers/Asset')
-rw-r--r--OpenSim/Server/Handlers/Asset/AssetServerConnector.cs26
-rw-r--r--OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs9
-rw-r--r--OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs100
-rw-r--r--OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs28
-rw-r--r--OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs87
-rw-r--r--OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs1
6 files changed, 202 insertions, 49 deletions
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs
index ff45d94..ab81dd6 100644
--- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs
+++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs
@@ -30,6 +30,7 @@ using System.IO;
30using Nini.Config; 30using Nini.Config;
31using OpenMetaverse; 31using OpenMetaverse;
32using OpenSim.Framework; 32using OpenSim.Framework;
33using OpenSim.Framework.ServiceAuth;
33using OpenSim.Framework.Console; 34using OpenSim.Framework.Console;
34using OpenSim.Server.Base; 35using OpenSim.Server.Base;
35using OpenSim.Services.Interfaces; 36using OpenSim.Services.Interfaces;
@@ -69,6 +70,8 @@ namespace OpenSim.Server.Handlers.Asset
69 bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false); 70 bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false);
70 bool allowDeleteAllTypes = serverConfig.GetBoolean("AllowRemoteDeleteAllTypes", false); 71 bool allowDeleteAllTypes = serverConfig.GetBoolean("AllowRemoteDeleteAllTypes", false);
71 72
73 string redirectURL = serverConfig.GetString("RedirectURL", string.Empty);
74
72 AllowedRemoteDeleteTypes allowedRemoteDeleteTypes; 75 AllowedRemoteDeleteTypes allowedRemoteDeleteTypes;
73 76
74 if (!allowDelete) 77 if (!allowDelete)
@@ -83,9 +86,12 @@ namespace OpenSim.Server.Handlers.Asset
83 allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.MapTile; 86 allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.MapTile;
84 } 87 }
85 88
86 server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); 89 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
87 server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); 90
88 server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes)); 91 server.AddStreamHandler(new AssetServerGetHandler(m_AssetService, auth, redirectURL));
92 server.AddStreamHandler(new AssetServerPostHandler(m_AssetService, auth));
93 server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes, auth));
94 server.AddStreamHandler(new AssetsExistHandler(m_AssetService));
89 95
90 MainConsole.Instance.Commands.AddCommand("Assets", false, 96 MainConsole.Instance.Commands.AddCommand("Assets", false,
91 "show asset", 97 "show asset",
@@ -119,16 +125,14 @@ namespace OpenSim.Server.Handlers.Asset
119 125
120 if (asset == null || asset.Data.Length == 0) 126 if (asset == null || asset.Data.Length == 0)
121 { 127 {
122 MainConsole.Instance.Output("Asset not found"); 128 MainConsole.Instance.OutputFormat("Could not find asset with ID {0}", args[2]);
123 return; 129 return;
124 } 130 }
125 131
126 m_AssetService.Delete(args[2]); 132 if (!m_AssetService.Delete(asset.ID))
127 133 MainConsole.Instance.OutputFormat("ERROR: Could not delete asset {0} {1}", asset.ID, asset.Name);
128 //MainConsole.Instance.Output("Asset deleted"); 134 else
129 // TODO: Implement this 135 MainConsole.Instance.OutputFormat("Deleted asset {0} {1}", asset.ID, asset.Name);
130
131 MainConsole.Instance.Output("Asset deletion not supported by database");
132 } 136 }
133 137
134 void HandleDumpAsset(string module, string[] args) 138 void HandleDumpAsset(string module, string[] args)
@@ -214,4 +218,4 @@ namespace OpenSim.Server.Handlers.Asset
214 } 218 }
215 } 219 }
216 } 220 }
217} \ No newline at end of file 221}
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs
index 986394b..d85d471 100644
--- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs
+++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs
@@ -38,6 +38,7 @@ using System.Xml.Serialization;
38using OpenSim.Server.Base; 38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces; 39using OpenSim.Services.Interfaces;
40using OpenSim.Framework; 40using OpenSim.Framework;
41using OpenSim.Framework.ServiceAuth;
41using OpenSim.Framework.Servers.HttpServer; 42using OpenSim.Framework.Servers.HttpServer;
42 43
43namespace OpenSim.Server.Handlers.Asset 44namespace OpenSim.Server.Handlers.Asset
@@ -70,7 +71,13 @@ namespace OpenSim.Server.Handlers.Asset
70 m_allowedTypes = allowedTypes; 71 m_allowedTypes = allowedTypes;
71 } 72 }
72 73
73 public override byte[] Handle(string path, Stream request, 74 public AssetServerDeleteHandler(IAssetService service, AllowedRemoteDeleteTypes allowedTypes, IServiceAuth auth) :
75 base("DELETE", "/assets", auth)
76 {
77 m_AssetService = service;
78 m_allowedTypes = allowedTypes;
79 }
80 protected override byte[] ProcessRequest(string path, Stream request,
74 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 81 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
75 { 82 {
76 bool result = false; 83 bool result = false;
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
index 8f7412b..91c5c54 100644
--- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
+++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
@@ -38,23 +38,34 @@ using System.Xml.Serialization;
38using OpenSim.Server.Base; 38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces; 39using OpenSim.Services.Interfaces;
40using OpenSim.Framework; 40using OpenSim.Framework;
41using OpenSim.Framework.ServiceAuth;
41using OpenSim.Framework.Servers.HttpServer; 42using OpenSim.Framework.Servers.HttpServer;
42 43
43namespace OpenSim.Server.Handlers.Asset 44namespace OpenSim.Server.Handlers.Asset
44{ 45{
45 public class AssetServerGetHandler : BaseStreamHandler 46 public class AssetServerGetHandler : BaseStreamHandler
46 { 47 {
47 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 49
49 private IAssetService m_AssetService; 50 private IAssetService m_AssetService;
51 private string m_RedirectURL;
50 52
51 public AssetServerGetHandler(IAssetService service) : 53 public AssetServerGetHandler(IAssetService service) :
52 base("GET", "/assets") 54 base("GET", "/assets")
53 { 55 {
56 m_AssetService = service;
57 }
58
59 public AssetServerGetHandler(IAssetService service, IServiceAuth auth, string redirectURL) :
60 base("GET", "/assets", auth)
61 {
54 m_AssetService = service; 62 m_AssetService = service;
63 m_RedirectURL = redirectURL;
64 if (!m_RedirectURL.EndsWith("/"))
65 m_RedirectURL = m_RedirectURL.TrimEnd('/');
55 } 66 }
56 67
57 public override byte[] Handle(string path, Stream request, 68 protected override byte[] ProcessRequest(string path, Stream request,
58 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 69 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
59 { 70 {
60 byte[] result = new byte[0]; 71 byte[] result = new byte[0];
@@ -64,45 +75,62 @@ namespace OpenSim.Server.Handlers.Asset
64 if (p.Length == 0) 75 if (p.Length == 0)
65 return result; 76 return result;
66 77
67 if (p.Length > 1 && p[1] == "data") 78 string id = string.Empty;
79 if (p.Length > 1)
68 { 80 {
69 result = m_AssetService.GetData(p[0]); 81 id = p[0];
70 if (result == null) 82 string cmd = p[1];
83
84 if (cmd == "data")
71 { 85 {
72 httpResponse.StatusCode = (int)HttpStatusCode.NotFound; 86 result = m_AssetService.GetData(id);
73 httpResponse.ContentType = "text/plain"; 87 if (result == null)
74 result = new byte[0]; 88 {
89 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
90 httpResponse.ContentType = "text/plain";
91 result = new byte[0];
92 }
93 else
94 {
95 httpResponse.StatusCode = (int)HttpStatusCode.OK;
96 httpResponse.ContentType = "application/octet-stream";
97 }
75 } 98 }
76 else 99 else if (cmd == "metadata")
77 { 100 {
78 httpResponse.StatusCode = (int)HttpStatusCode.OK; 101 AssetMetadata metadata = m_AssetService.GetMetadata(id);
79 httpResponse.ContentType = "application/octet-stream";
80 }
81 }
82 else if (p.Length > 1 && p[1] == "metadata")
83 {
84 AssetMetadata metadata = m_AssetService.GetMetadata(p[0]);
85 102
86 if (metadata != null) 103 if (metadata != null)
87 { 104 {
88 XmlSerializer xs = 105 XmlSerializer xs =
89 new XmlSerializer(typeof(AssetMetadata)); 106 new XmlSerializer(typeof(AssetMetadata));
90 result = ServerUtils.SerializeResult(xs, metadata); 107 result = ServerUtils.SerializeResult(xs, metadata);
91 108
92 httpResponse.StatusCode = (int)HttpStatusCode.OK; 109 httpResponse.StatusCode = (int)HttpStatusCode.OK;
93 httpResponse.ContentType = 110 httpResponse.ContentType =
94 SLUtil.SLAssetTypeToContentType(metadata.Type); 111 SLUtil.SLAssetTypeToContentType(metadata.Type);
112 }
113 else
114 {
115 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
116 httpResponse.ContentType = "text/plain";
117 result = new byte[0];
118 }
95 } 119 }
96 else 120 else
97 { 121 {
98 httpResponse.StatusCode = (int)HttpStatusCode.NotFound; 122 // Unknown request
123 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
99 httpResponse.ContentType = "text/plain"; 124 httpResponse.ContentType = "text/plain";
100 result = new byte[0]; 125 result = new byte[0];
101 } 126 }
102 } 127 }
103 else 128 else if (p.Length == 1)
104 { 129 {
105 AssetBase asset = m_AssetService.Get(p[0]); 130 // Get the entire asset (metadata + data)
131
132 id = p[0];
133 AssetBase asset = m_AssetService.Get(id);
106 134
107 if (asset != null) 135 if (asset != null)
108 { 136 {
@@ -120,6 +148,24 @@ namespace OpenSim.Server.Handlers.Asset
120 result = new byte[0]; 148 result = new byte[0];
121 } 149 }
122 } 150 }
151 else
152 {
153 // Unknown request
154 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
155 httpResponse.ContentType = "text/plain";
156 result = new byte[0];
157 }
158
159 if (httpResponse.StatusCode == (int)HttpStatusCode.NotFound && !string.IsNullOrEmpty(m_RedirectURL) && !string.IsNullOrEmpty(id))
160 {
161 httpResponse.StatusCode = (int)HttpStatusCode.Redirect;
162 string rurl = m_RedirectURL;
163 if (!path.StartsWith("/"))
164 rurl += "/";
165 rurl += path;
166 httpResponse.AddHeader("Location", rurl);
167 m_log.DebugFormat("[ASSET GET HANDLER]: Asset not found, redirecting to {0} ({1})", rurl, httpResponse.StatusCode);
168 }
123 return result; 169 return result;
124 } 170 }
125 } 171 }
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs
index a006fa8..1c706a7 100644
--- a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs
@@ -38,6 +38,7 @@ using System.Xml.Serialization;
38using OpenSim.Server.Base; 38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces; 39using OpenSim.Services.Interfaces;
40using OpenSim.Framework; 40using OpenSim.Framework;
41using OpenSim.Framework.ServiceAuth;
41using OpenSim.Framework.Servers.HttpServer; 42using OpenSim.Framework.Servers.HttpServer;
42 43
43namespace OpenSim.Server.Handlers.Asset 44namespace OpenSim.Server.Handlers.Asset
@@ -54,35 +55,44 @@ namespace OpenSim.Server.Handlers.Asset
54 m_AssetService = service; 55 m_AssetService = service;
55 } 56 }
56 57
57 public override byte[] Handle(string path, Stream request, 58 public AssetServerPostHandler(IAssetService service, IServiceAuth auth) :
59 base("POST", "/assets", auth)
60 {
61 m_AssetService = service;
62 }
63
64 protected override byte[] ProcessRequest(string path, Stream request,
58 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 65 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
59 { 66 {
60 AssetBase asset; 67 AssetBase asset;
61 XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); 68 XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
62 69
63 try 70 try
64 { 71 {
65 asset = (AssetBase)xs.Deserialize(request); 72 asset = (AssetBase)xs.Deserialize(request);
66 } 73 }
67 catch (XmlException) 74 catch (Exception)
68 { 75 {
69 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; 76 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
70 return null; 77 return null;
71 } 78 }
72 79
73 string[] p = SplitParams(path); 80 string[] p = SplitParams(path);
74 if (p.Length > 1) 81 if (p.Length > 0)
75 { 82 {
76 bool result = m_AssetService.UpdateContent(p[1], asset.Data); 83 string id = p[0];
84 bool result = m_AssetService.UpdateContent(id, asset.Data);
77 85
78 xs = new XmlSerializer(typeof(bool)); 86 xs = new XmlSerializer(typeof(bool));
79 return ServerUtils.SerializeResult(xs, result); 87 return ServerUtils.SerializeResult(xs, result);
80 } 88 }
89 else
90 {
91 string id = m_AssetService.Store(asset);
81 92
82 string id = m_AssetService.Store(asset); 93 xs = new XmlSerializer(typeof(string));
83 94 return ServerUtils.SerializeResult(xs, id);
84 xs = new XmlSerializer(typeof(string)); 95 }
85 return ServerUtils.SerializeResult(xs, id);
86 } 96 }
87 } 97 }
88} 98}
diff --git a/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs b/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs
new file mode 100644
index 0000000..32901b3
--- /dev/null
+++ b/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs
@@ -0,0 +1,87 @@
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
28using Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces;
40using OpenSim.Framework;
41using OpenSim.Framework.ServiceAuth;
42using OpenSim.Framework.Servers.HttpServer;
43using OpenMetaverse;
44
45namespace OpenSim.Server.Handlers.Asset
46{
47 public class AssetsExistHandler : BaseStreamHandler
48 {
49 //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IAssetService m_AssetService;
52
53 public AssetsExistHandler(IAssetService service) :
54 base("POST", "/get_assets_exist")
55 {
56 m_AssetService = service;
57 }
58
59 public AssetsExistHandler(IAssetService service, IServiceAuth auth) :
60 base("POST", "/get_assets_exist", auth)
61 {
62 m_AssetService = service;
63 }
64
65 protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
66 {
67 XmlSerializer xs;
68
69 string[] ids;
70 try
71 {
72 xs = new XmlSerializer(typeof(string[]));
73 ids = (string[])xs.Deserialize(request);
74 }
75 catch (Exception)
76 {
77 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
78 return null;
79 }
80
81 bool[] exist = m_AssetService.AssetsExist(ids);
82
83 xs = new XmlSerializer(typeof(bool[]));
84 return ServerUtils.SerializeResult(xs, exist);
85 }
86 }
87}
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;
39using OpenSim.Services.AssetService; 39using OpenSim.Services.AssetService;
40using OpenSim.Services.Interfaces; 40using OpenSim.Services.Interfaces;
41using OpenSim.Tests.Common; 41using OpenSim.Tests.Common;
42using OpenSim.Tests.Common.Mock;
43 42
44namespace OpenSim.Server.Handlers.Asset.Test 43namespace OpenSim.Server.Handlers.Asset.Test
45{ 44{