aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs205
-rw-r--r--OpenSim/Framework/Servers/GetAssetStreamHandler.cs63
-rw-r--r--OpenSim/Framework/Servers/PostAssetStreamHandler.cs72
-rw-r--r--OpenSim/Framework/Servers/VersionInfo.cs2
4 files changed, 1 insertions, 341 deletions
diff --git a/OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs b/OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs
deleted file mode 100644
index 8372ae7..0000000
--- a/OpenSim/Framework/Servers/BaseGetAssetStreamHandler.cs
+++ /dev/null
@@ -1,205 +0,0 @@
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 System;
29using System.Collections.Generic;
30using System.IO;
31using System.Net;
32using System.Reflection;
33using System.Text;
34using System.Text.RegularExpressions;
35using System.Xml;
36using System.Xml.Serialization;
37using log4net;
38using OpenMetaverse;
39using OpenSim.Framework.Servers.HttpServer;
40using OpenSim.Framework.Statistics;
41
42namespace OpenSim.Framework.Servers
43{
44 public abstract class BaseGetAssetStreamHandler : BaseStreamHandler
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 protected BaseGetAssetStreamHandler(string httpMethod, string path) : base(httpMethod, path)
49 {
50 }
51
52 protected abstract AssetBase GetAsset(UUID assetID);
53
54 public override byte[] Handle(string path, Stream request,
55 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
56 {
57 byte[] result = new byte[] { };
58
59 string[] p = SplitParams(path);
60
61 if (p.Length > 0)
62 {
63 UUID assetID;
64
65 if (!UUID.TryParse(p[0], out assetID))
66 {
67 m_log.DebugFormat(
68 "[REST]: GET:/asset ignoring request with malformed UUID {0}", p[0]);
69 return result;
70 }
71
72 if (StatsManager.AssetStats != null)
73 {
74 StatsManager.AssetStats.AddRequest();
75 }
76
77 AssetBase asset = GetAsset(assetID);
78
79 if (asset != null)
80 {
81 if (p.Length > 1 && p[1] == "data")
82 {
83 httpResponse.StatusCode = (int)HttpStatusCode.OK;
84 httpResponse.ContentType = SLAssetTypeToContentType(asset.Type);
85 result = asset.Data;
86 }
87 else
88 {
89 result = GetXml(asset);
90 }
91 }
92 else
93 {
94 m_log.DebugFormat("[REST]: GET:/asset failed to find {0}", assetID);
95
96 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
97
98 if (StatsManager.AssetStats != null)
99 {
100 StatsManager.AssetStats.AddNotFoundRequest();
101 }
102 }
103 }
104
105 return result;
106 }
107
108 public static byte[] GetXml(AssetBase asset)
109 {
110 byte[] result;
111 XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
112 MemoryStream ms = new MemoryStream();
113 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
114 xw.Formatting = Formatting.Indented;
115 xs.Serialize(xw, asset);
116 xw.Flush();
117
118 ms.Seek(0, SeekOrigin.Begin);
119 //StreamReader sr = new StreamReader(ms);
120
121 result = ms.GetBuffer();
122
123 Array.Resize<byte>(ref result, (int)ms.Length);
124 return result;
125 }
126
127 public string ProcessAssetDataString(string data)
128 {
129 Regex regex = new Regex("(creator_id|owner_id)\\s+(\\S+)");
130
131 // IUserService userService = null;
132
133 data = regex.Replace(data, delegate(Match m)
134 {
135 string result = String.Empty;
136
137// string key = m.Groups[1].Captures[0].Value;
138//
139// string value = m.Groups[2].Captures[0].Value;
140//
141// Guid userUri;
142//
143// switch (key)
144// {
145// case "creator_id":
146// userUri = new Guid(value);
147// // result = "creator_url " + userService(userService, userUri);
148// break;
149//
150// case "owner_id":
151// userUri = new Guid(value);
152// // result = "owner_url " + ResolveUserUri(userService, userUri);
153// break;
154// }
155
156 return result;
157 });
158
159 return data;
160 }
161
162 private string SLAssetTypeToContentType(int assetType)
163 {
164 switch (assetType)
165 {
166 case 0:
167 return "image/jp2";
168 case 1:
169 return "application/ogg";
170 case 2:
171 return "application/x-metaverse-callingcard";
172 case 3:
173 return "application/x-metaverse-landmark";
174 case 5:
175 return "application/x-metaverse-clothing";
176 case 6:
177 return "application/x-metaverse-primitive";
178 case 7:
179 return "application/x-metaverse-notecard";
180 case 8:
181 return "application/x-metaverse-folder";
182 case 10:
183 return "application/x-metaverse-lsl";
184 case 11:
185 return "application/x-metaverse-lso";
186 case 12:
187 return "image/tga";
188 case 13:
189 return "application/x-metaverse-bodypart";
190 case 17:
191 return "audio/x-wav";
192 case 19:
193 return "image/jpeg";
194 case 20:
195 return "application/x-metaverse-animation";
196 case 21:
197 return "application/x-metaverse-gesture";
198 case 22:
199 return "application/x-metaverse-simstate";
200 default:
201 return "application/octet-stream";
202 }
203 }
204 }
205}
diff --git a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs
deleted file mode 100644
index c6958de..0000000
--- a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs
+++ /dev/null
@@ -1,63 +0,0 @@
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 System;
29using System.IO;
30using System.Reflection;
31using System.Text;
32using System.Text.RegularExpressions;
33using System.Xml;
34using System.Xml.Serialization;
35using log4net;
36using OpenMetaverse;
37using OpenSim.Data;
38using OpenSim.Framework;
39using OpenSim.Framework.Servers;
40using OpenSim.Framework.Servers.HttpServer;
41using OpenSim.Framework.Statistics;
42using System.Net;
43
44namespace OpenSim.Framework.Servers
45{
46 public class GetAssetStreamHandler : BaseGetAssetStreamHandler
47 {
48 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49
50 private readonly IAssetDataPlugin m_assetProvider;
51
52 public GetAssetStreamHandler(IAssetDataPlugin assetProvider)
53 : base("GET", "/assets")
54 {
55 m_assetProvider = assetProvider;
56 }
57
58 protected override AssetBase GetAsset(UUID assetID)
59 {
60 return m_assetProvider.GetAsset(assetID);
61 }
62 }
63}
diff --git a/OpenSim/Framework/Servers/PostAssetStreamHandler.cs b/OpenSim/Framework/Servers/PostAssetStreamHandler.cs
deleted file mode 100644
index 8bf406c..0000000
--- a/OpenSim/Framework/Servers/PostAssetStreamHandler.cs
+++ /dev/null
@@ -1,72 +0,0 @@
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 System.IO;
29using System.Reflection;
30using System.Xml.Serialization;
31using log4net;
32using OpenMetaverse;
33using OpenSim.Data;
34using OpenSim.Framework;
35using OpenSim.Framework.Servers.HttpServer;
36
37namespace OpenSim.Framework.Servers
38{
39 public class PostAssetStreamHandler : BaseStreamHandler
40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42
43 // private OpenAsset_Main m_assetManager;
44 private IAssetDataPlugin m_assetProvider;
45
46 public override byte[] Handle(string path, Stream request,
47 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
48 {
49 string param = GetParam(path);
50
51 UUID assetId;
52 if (param.Length > 0)
53 UUID.TryParse(param, out assetId);
54 // byte[] txBuffer = new byte[4096];
55
56 XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
57 AssetBase asset = (AssetBase) xs.Deserialize(request);
58
59 m_log.InfoFormat("[REST]: Creating asset {0}", asset.FullID);
60 m_assetProvider.StoreAsset(asset);
61
62 return new byte[] {};
63 }
64
65 public PostAssetStreamHandler(IAssetDataPlugin assetProvider)
66 : base("POST", "/assets")
67 {
68 // m_assetManager = assetManager;
69 m_assetProvider = assetProvider;
70 }
71 }
72}
diff --git a/OpenSim/Framework/Servers/VersionInfo.cs b/OpenSim/Framework/Servers/VersionInfo.cs
index 743ca69..6f9b00c 100644
--- a/OpenSim/Framework/Servers/VersionInfo.cs
+++ b/OpenSim/Framework/Servers/VersionInfo.cs
@@ -69,6 +69,6 @@ namespace OpenSim
69 /// of the code that is too old. 69 /// of the code that is too old.
70 /// 70 ///
71 /// </value> 71 /// </value>
72 public readonly static int MajorInterfaceVersion = 5; 72 public readonly static int MajorInterfaceVersion = 6;
73 } 73 }
74} 74}