aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Assets
diff options
context:
space:
mode:
authorDiva Canto2011-04-30 12:23:40 -0700
committerDiva Canto2011-04-30 12:23:40 -0700
commitc062138dad42ef7e52bbcb27c346ddecab94c5af (patch)
treeedff2328b4190e464edeaaebe77c7949b31c5ec1 /OpenSim/Region/CoreModules/Avatar/Assets
parentRenamed OpenSim.Framework.Capabilities.dll to OpenSim.Capabilities.dll (diff)
downloadopensim-SC_OLD-c062138dad42ef7e52bbcb27c346ddecab94c5af.zip
opensim-SC_OLD-c062138dad42ef7e52bbcb27c346ddecab94c5af.tar.gz
opensim-SC_OLD-c062138dad42ef7e52bbcb27c346ddecab94c5af.tar.bz2
opensim-SC_OLD-c062138dad42ef7e52bbcb27c346ddecab94c5af.tar.xz
Moved several cap-based-service-providing modules from where they were into a newly created CoreModules/Caps. Not all.
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Assets')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Assets/GetMeshModule.cs211
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Assets/GetTextureModule.cs402
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Assets/NewFileAgentInventoryVariablePriceModule.cs275
3 files changed, 0 insertions, 888 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Assets/GetMeshModule.cs b/OpenSim/Region/CoreModules/Avatar/Assets/GetMeshModule.cs
deleted file mode 100644
index fc1ddef..0000000
--- a/OpenSim/Region/CoreModules/Avatar/Assets/GetMeshModule.cs
+++ /dev/null
@@ -1,211 +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;
30using System.Collections.Specialized;
31using System.Reflection;
32using System.IO;
33using System.Web;
34using Mono.Addins;
35using log4net;
36using Nini.Config;
37using OpenMetaverse;
38using OpenMetaverse.StructuredData;
39using OpenSim.Framework;
40using OpenSim.Framework.Servers;
41using OpenSim.Framework.Servers.HttpServer;
42using OpenSim.Region.Framework.Interfaces;
43using OpenSim.Region.Framework.Scenes;
44using OpenSim.Services.Interfaces;
45using Caps = OpenSim.Framework.Capabilities.Caps;
46
47namespace OpenSim.Region.CoreModules.Avatar.Assets
48{
49 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
50 public class GetMeshModule : INonSharedRegionModule
51 {
52// private static readonly ILog m_log =
53// LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54
55 private Scene m_scene;
56 private IAssetService m_assetService;
57 private bool m_enabled = true;
58
59 #region IRegionModuleBase Members
60
61
62 public Type ReplaceableInterface
63 {
64 get { return null; }
65 }
66
67 public void Initialise(IConfigSource source)
68 {
69 IConfig meshConfig = source.Configs["Mesh"];
70 if (meshConfig == null)
71 return;
72
73 m_enabled = meshConfig.GetBoolean("AllowMeshUpload", true);
74 }
75
76 public void AddRegion(Scene pScene)
77 {
78 m_scene = pScene;
79 }
80
81 public void RemoveRegion(Scene scene)
82 {
83
84 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
85 m_scene = null;
86 }
87
88 public void RegionLoaded(Scene scene)
89 {
90
91 m_assetService = m_scene.RequestModuleInterface<IAssetService>();
92 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
93 }
94
95 #endregion
96
97
98 #region IRegionModule Members
99
100
101
102 public void Close() { }
103
104 public string Name { get { return "GetMeshModule"; } }
105
106
107 public void RegisterCaps(UUID agentID, Caps caps)
108 {
109 if(!m_enabled)
110 return;
111
112 UUID capID = UUID.Random();
113
114// m_log.Info("[GETMESH]: /CAPS/" + capID);
115
116 caps.RegisterHandler("GetMesh",
117 new RestHTTPHandler("GET", "/CAPS/" + capID,
118 delegate(Hashtable m_dhttpMethod)
119 {
120 return ProcessGetMesh(m_dhttpMethod, agentID, caps);
121 }));
122 }
123
124 #endregion
125
126 public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap)
127 {
128
129 Hashtable responsedata = new Hashtable();
130 responsedata["int_response_code"] = 400; //501; //410; //404;
131 responsedata["content_type"] = "text/plain";
132 responsedata["keepalive"] = false;
133 responsedata["str_response_string"] = "Request wasn't what was expected";
134
135 string meshStr = string.Empty;
136
137 if (request.ContainsKey("mesh_id"))
138 meshStr = request["mesh_id"].ToString();
139
140
141 UUID meshID = UUID.Zero;
142 if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID))
143 {
144 if (m_assetService == null)
145 {
146 responsedata["int_response_code"] = 404; //501; //410; //404;
147 responsedata["content_type"] = "text/plain";
148 responsedata["keepalive"] = false;
149 responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh.";
150 return responsedata;
151 }
152
153 AssetBase mesh;
154 // Only try to fetch locally cached textures. Misses are redirected
155 mesh = m_assetService.GetCached(meshID.ToString());
156 if (mesh != null)
157 {
158 if (mesh.Type == (SByte)AssetType.Mesh)
159 {
160 responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data);
161 responsedata["content_type"] = "application/vnd.ll.mesh";
162 responsedata["int_response_code"] = 200;
163 }
164 // Optionally add additional mesh types here
165 else
166 {
167 responsedata["int_response_code"] = 404; //501; //410; //404;
168 responsedata["content_type"] = "text/plain";
169 responsedata["keepalive"] = false;
170 responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh.";
171 return responsedata;
172 }
173 }
174 else
175 {
176 mesh = m_assetService.Get(meshID.ToString());
177 if (mesh != null)
178 {
179 if (mesh.Type == (SByte)AssetType.Mesh)
180 {
181 responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data);
182 responsedata["content_type"] = "application/vnd.ll.mesh";
183 responsedata["int_response_code"] = 200;
184 }
185 // Optionally add additional mesh types here
186 else
187 {
188 responsedata["int_response_code"] = 404; //501; //410; //404;
189 responsedata["content_type"] = "text/plain";
190 responsedata["keepalive"] = false;
191 responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh.";
192 return responsedata;
193 }
194 }
195
196 else
197 {
198 responsedata["int_response_code"] = 404; //501; //410; //404;
199 responsedata["content_type"] = "text/plain";
200 responsedata["keepalive"] = false;
201 responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!";
202 return responsedata;
203 }
204 }
205
206 }
207
208 return responsedata;
209 }
210 }
211}
diff --git a/OpenSim/Region/CoreModules/Avatar/Assets/GetTextureModule.cs b/OpenSim/Region/CoreModules/Avatar/Assets/GetTextureModule.cs
deleted file mode 100644
index df4d561..0000000
--- a/OpenSim/Region/CoreModules/Avatar/Assets/GetTextureModule.cs
+++ /dev/null
@@ -1,402 +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;
30using System.Collections.Specialized;
31using System.Drawing;
32using System.Drawing.Imaging;
33using System.Reflection;
34using System.IO;
35using System.Web;
36using log4net;
37using Nini.Config;
38using OpenMetaverse;
39using OpenMetaverse.StructuredData;
40using OpenMetaverse.Imaging;
41using OpenSim.Framework;
42using OpenSim.Framework.Servers;
43using OpenSim.Framework.Servers.HttpServer;
44using OpenSim.Region.Framework.Interfaces;
45using OpenSim.Region.Framework.Scenes;
46using OpenSim.Services.Interfaces;
47using Caps = OpenSim.Framework.Capabilities.Caps;
48
49namespace OpenSim.Region.CoreModules.Avatar.ObjectCaps
50{
51 #region Stream Handler
52
53 public delegate byte[] StreamHandlerCallback(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse);
54
55 public class StreamHandler : BaseStreamHandler
56 {
57 StreamHandlerCallback m_callback;
58
59 public StreamHandler(string httpMethod, string path, StreamHandlerCallback callback)
60 : base(httpMethod, path)
61 {
62 m_callback = callback;
63 }
64
65 public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
66 {
67 return m_callback(path, request, httpRequest, httpResponse);
68 }
69 }
70
71 #endregion Stream Handler
72
73 public class GetTextureModule : IRegionModule
74 {
75 private static readonly ILog m_log =
76 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
77 private Scene m_scene;
78 private IAssetService m_assetService;
79
80 public const string DefaultFormat = "x-j2c";
81
82 // TODO: Change this to a config option
83 const string REDIRECT_URL = null;
84
85
86 #region IRegionModule Members
87
88 public void Initialise(Scene pScene, IConfigSource pSource)
89 {
90 m_scene = pScene;
91 }
92
93 public void PostInitialise()
94 {
95 m_assetService = m_scene.RequestModuleInterface<IAssetService>();
96 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
97 }
98
99 public void Close() { }
100
101 public string Name { get { return "GetTextureModule"; } }
102 public bool IsSharedModule { get { return false; } }
103
104 public void RegisterCaps(UUID agentID, Caps caps)
105 {
106 UUID capID = UUID.Random();
107
108// m_log.InfoFormat("[GETTEXTURE]: /CAPS/{0} in region {1}", capID, m_scene.RegionInfo.RegionName);
109 caps.RegisterHandler("GetTexture", new StreamHandler("GET", "/CAPS/" + capID, ProcessGetTexture));
110 }
111
112 #endregion
113
114 private byte[] ProcessGetTexture(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
115 {
116 //m_log.DebugFormat("[GETTEXTURE]: called in {0}", m_scene.RegionInfo.RegionName);
117
118 // Try to parse the texture ID from the request URL
119 NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query);
120 string textureStr = query.GetOne("texture_id");
121 string format = query.GetOne("format");
122
123 if (m_assetService == null)
124 {
125 m_log.Error("[GETTEXTURE]: Cannot fetch texture " + textureStr + " without an asset service");
126 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
127 return null;
128 }
129
130 UUID textureID;
131 if (!String.IsNullOrEmpty(textureStr) && UUID.TryParse(textureStr, out textureID))
132 {
133 string[] formats;
134 if (format != null && format != string.Empty)
135 {
136 formats = new string[1] { format.ToLower() };
137 }
138 else
139 {
140 formats = WebUtil.GetPreferredImageTypes(httpRequest.Headers.Get("Accept"));
141 if (formats.Length == 0)
142 formats = new string[1] { DefaultFormat }; // default
143
144 }
145 // OK, we have an array with preferred formats, possibly with only one entry
146
147 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
148 foreach (string f in formats)
149 {
150 if (FetchTexture(httpRequest, httpResponse, textureID, f))
151 break;
152 }
153
154 }
155 else
156 {
157 m_log.Warn("[GETTEXTURE]: Failed to parse a texture_id from GetTexture request: " + httpRequest.Url);
158 }
159
160 httpResponse.Send();
161 return null;
162 }
163
164 /// <summary>
165 ///
166 /// </summary>
167 /// <param name="httpRequest"></param>
168 /// <param name="httpResponse"></param>
169 /// <param name="textureID"></param>
170 /// <param name="format"></param>
171 /// <returns>False for "caller try another codec"; true otherwise</returns>
172 private bool FetchTexture(OSHttpRequest httpRequest, OSHttpResponse httpResponse, UUID textureID, string format)
173 {
174// m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format);
175 AssetBase texture;
176
177 string fullID = textureID.ToString();
178 if (format != DefaultFormat)
179 fullID = fullID + "-" + format;
180
181 if (!String.IsNullOrEmpty(REDIRECT_URL))
182 {
183 // Only try to fetch locally cached textures. Misses are redirected
184 texture = m_assetService.GetCached(fullID);
185
186 if (texture != null)
187 {
188 if (texture.Type != (sbyte)AssetType.Texture)
189 {
190 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
191 return true;
192 }
193 WriteTextureData(httpRequest, httpResponse, texture, format);
194 }
195 else
196 {
197 string textureUrl = REDIRECT_URL + textureID.ToString();
198 m_log.Debug("[GETTEXTURE]: Redirecting texture request to " + textureUrl);
199 httpResponse.RedirectLocation = textureUrl;
200 return true;
201 }
202 }
203 else // no redirect
204 {
205 // try the cache
206 texture = m_assetService.GetCached(fullID);
207
208 if (texture == null)
209 {
210 //m_log.DebugFormat("[GETTEXTURE]: texture was not in the cache");
211
212 // Fetch locally or remotely. Misses return a 404
213 texture = m_assetService.Get(textureID.ToString());
214
215 if (texture != null)
216 {
217 if (texture.Type != (sbyte)AssetType.Texture)
218 {
219 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
220 return true;
221 }
222 if (format == DefaultFormat)
223 {
224 WriteTextureData(httpRequest, httpResponse, texture, format);
225 return true;
226 }
227 else
228 {
229 AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID);
230 newTexture.Data = ConvertTextureData(texture, format);
231 if (newTexture.Data.Length == 0)
232 return false; // !!! Caller try another codec, please!
233
234 newTexture.Flags = AssetFlags.Collectable;
235 newTexture.Temporary = true;
236 m_assetService.Store(newTexture);
237 WriteTextureData(httpRequest, httpResponse, newTexture, format);
238 return true;
239 }
240 }
241 }
242 else // it was on the cache
243 {
244 //m_log.DebugFormat("[GETTEXTURE]: texture was in the cache");
245 WriteTextureData(httpRequest, httpResponse, texture, format);
246 return true;
247 }
248 }
249
250 // not found
251// m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found");
252 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
253 return true;
254 }
255
256 private void WriteTextureData(OSHttpRequest request, OSHttpResponse response, AssetBase texture, string format)
257 {
258 string range = request.Headers.GetOne("Range");
259 //m_log.DebugFormat("[GETTEXTURE]: Range {0}", range);
260 if (!String.IsNullOrEmpty(range)) // JP2's only
261 {
262 // Range request
263 int start, end;
264 if (TryParseRange(range, out start, out end))
265 {
266 // Before clamping start make sure we can satisfy it in order to avoid
267 // sending back the last byte instead of an error status
268 if (start >= texture.Data.Length)
269 {
270 response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable;
271 return;
272 }
273
274 end = Utils.Clamp(end, 0, texture.Data.Length - 1);
275 start = Utils.Clamp(start, 0, end);
276 int len = end - start + 1;
277
278 //m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID);
279
280 if (len < texture.Data.Length)
281 response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent;
282
283 response.ContentLength = len;
284 response.ContentType = texture.Metadata.ContentType;
285 response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length));
286
287 response.Body.Write(texture.Data, start, len);
288 }
289 else
290 {
291 m_log.Warn("[GETTEXTURE]: Malformed Range header: " + range);
292 response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
293 }
294 }
295 else // JP2's or other formats
296 {
297 // Full content request
298 response.StatusCode = (int)System.Net.HttpStatusCode.OK;
299 response.ContentLength = texture.Data.Length;
300 if (format == DefaultFormat)
301 response.ContentType = texture.Metadata.ContentType;
302 else
303 response.ContentType = "image/" + format;
304 response.Body.Write(texture.Data, 0, texture.Data.Length);
305 }
306 }
307
308 private bool TryParseRange(string header, out int start, out int end)
309 {
310 if (header.StartsWith("bytes="))
311 {
312 string[] rangeValues = header.Substring(6).Split('-');
313 if (rangeValues.Length == 2)
314 {
315 if (Int32.TryParse(rangeValues[0], out start) && Int32.TryParse(rangeValues[1], out end))
316 return true;
317 }
318 }
319
320 start = end = 0;
321 return false;
322 }
323
324
325 private byte[] ConvertTextureData(AssetBase texture, string format)
326 {
327 m_log.DebugFormat("[GETTEXTURE]: Converting texture {0} to {1}", texture.ID, format);
328 byte[] data = new byte[0];
329
330 MemoryStream imgstream = new MemoryStream();
331 Bitmap mTexture = new Bitmap(1, 1);
332 ManagedImage managedImage;
333 Image image = (Image)mTexture;
334
335 try
336 {
337 // Taking our jpeg2000 data, decoding it, then saving it to a byte array with regular data
338
339 imgstream = new MemoryStream();
340
341 // Decode image to System.Drawing.Image
342 if (OpenJPEG.DecodeToImage(texture.Data, out managedImage, out image))
343 {
344 // Save to bitmap
345 mTexture = new Bitmap(image);
346
347 EncoderParameters myEncoderParameters = new EncoderParameters();
348 myEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 95L);
349
350 // Save bitmap to stream
351 ImageCodecInfo codec = GetEncoderInfo("image/" + format);
352 if (codec != null)
353 {
354 mTexture.Save(imgstream, codec, myEncoderParameters);
355 // Write the stream to a byte array for output
356 data = imgstream.ToArray();
357 }
358 else
359 m_log.WarnFormat("[GETTEXTURE]: No such codec {0}", format);
360
361 }
362 }
363 catch (Exception e)
364 {
365 m_log.WarnFormat("[GETTEXTURE]: Unable to convert texture {0} to {1}: {2}", texture.ID, format, e.Message);
366 }
367 finally
368 {
369 // Reclaim memory, these are unmanaged resources
370 // If we encountered an exception, one or more of these will be null
371 if (mTexture != null)
372 mTexture.Dispose();
373
374 if (image != null)
375 image.Dispose();
376
377 if (imgstream != null)
378 {
379 imgstream.Close();
380 imgstream.Dispose();
381 }
382 }
383
384 return data;
385 }
386
387 // From msdn
388 private static ImageCodecInfo GetEncoderInfo(String mimeType)
389 {
390 ImageCodecInfo[] encoders;
391 encoders = ImageCodecInfo.GetImageEncoders();
392 for (int j = 0; j < encoders.Length; ++j)
393 {
394 if (encoders[j].MimeType == mimeType)
395 return encoders[j];
396 }
397 return null;
398 }
399
400
401 }
402}
diff --git a/OpenSim/Region/CoreModules/Avatar/Assets/NewFileAgentInventoryVariablePriceModule.cs b/OpenSim/Region/CoreModules/Avatar/Assets/NewFileAgentInventoryVariablePriceModule.cs
deleted file mode 100644
index 3d4c7b7..0000000
--- a/OpenSim/Region/CoreModules/Avatar/Assets/NewFileAgentInventoryVariablePriceModule.cs
+++ /dev/null
@@ -1,275 +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;
30using System.Collections.Specialized;
31using System.Reflection;
32using System.IO;
33using System.Web;
34using Mono.Addins;
35using log4net;
36using Nini.Config;
37using OpenMetaverse;
38using OpenMetaverse.StructuredData;
39using OpenSim.Framework;
40using OpenSim.Framework.Servers;
41using OpenSim.Framework.Servers.HttpServer;
42using OpenSim.Region.Framework.Interfaces;
43using OpenSim.Region.Framework.Scenes;
44using OpenSim.Services.Interfaces;
45using Caps = OpenSim.Framework.Capabilities.Caps;
46using OpenSim.Framework.Capabilities;
47
48namespace OpenSim.Region.CoreModules.Avatar.Assets
49{
50 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
51 public class NewFileAgentInventoryVariablePriceModule : INonSharedRegionModule
52 {
53// private static readonly ILog m_log =
54// LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55
56 private Scene m_scene;
57// private IAssetService m_assetService;
58 private bool m_dumpAssetsToFile = false;
59 private bool m_enabled = true;
60
61 #region IRegionModuleBase Members
62
63
64 public Type ReplaceableInterface
65 {
66 get { return null; }
67 }
68
69 public void Initialise(IConfigSource source)
70 {
71 IConfig meshConfig = source.Configs["Mesh"];
72 if (meshConfig == null)
73 return;
74
75 m_enabled = meshConfig.GetBoolean("AllowMeshUpload", true);
76 }
77
78 public void AddRegion(Scene pScene)
79 {
80 m_scene = pScene;
81 }
82
83 public void RemoveRegion(Scene scene)
84 {
85
86 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
87 m_scene = null;
88 }
89
90 public void RegionLoaded(Scene scene)
91 {
92
93// m_assetService = m_scene.RequestModuleInterface<IAssetService>();
94 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
95 }
96
97 #endregion
98
99
100 #region IRegionModule Members
101
102
103
104 public void Close() { }
105
106 public string Name { get { return "NewFileAgentInventoryVariablePriceModule"; } }
107
108
109 public void RegisterCaps(UUID agentID, Caps caps)
110 {
111 if(!m_enabled)
112 return;
113
114 UUID capID = UUID.Random();
115
116// m_log.Debug("[NEW FILE AGENT INVENTORY VARIABLE PRICE]: /CAPS/" + capID);
117 caps.RegisterHandler("NewFileAgentInventoryVariablePrice",
118
119 new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDNewFileAngentInventoryVariablePriceReplyResponse>("POST",
120 "/CAPS/" + capID.ToString(),
121 delegate(LLSDAssetUploadRequest req)
122 {
123 return NewAgentInventoryRequest(req,agentID);
124 }));
125
126 }
127
128 #endregion
129
130 public LLSDNewFileAngentInventoryVariablePriceReplyResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest, UUID agentID)
131 {
132
133 //TODO: The Mesh uploader uploads many types of content. If you're going to implement a Money based limit
134 // You need to be aware of this and
135
136
137 //if (llsdRequest.asset_type == "texture" ||
138 // llsdRequest.asset_type == "animation" ||
139 // llsdRequest.asset_type == "sound")
140 // {
141 IClientAPI client = null;
142
143
144 IMoneyModule mm = m_scene.RequestModuleInterface<IMoneyModule>();
145
146 if (mm != null)
147 {
148 if (m_scene.TryGetClient(agentID, out client))
149 {
150 if (!mm.UploadCovered(client, mm.UploadCharge))
151 {
152 if (client != null)
153 client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
154
155 LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse();
156 errorResponse.rsvp = "";
157 errorResponse.state = "error";
158 return errorResponse;
159 }
160 }
161 }
162 // }
163
164
165
166 string assetName = llsdRequest.name;
167 string assetDes = llsdRequest.description;
168 string capsBase = "/CAPS/NewFileAgentInventoryVariablePrice/";
169 UUID newAsset = UUID.Random();
170 UUID newInvItem = UUID.Random();
171 UUID parentFolder = llsdRequest.folder_id;
172 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000") + "/";
173
174 Caps.AssetUploader uploader =
175 new Caps.AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type,
176 llsdRequest.asset_type, capsBase + uploaderPath, MainServer.Instance, m_dumpAssetsToFile);
177 MainServer.Instance.AddStreamHandler(
178 new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps));
179
180 string protocol = "http://";
181
182 if (MainServer.Instance.UseSSL)
183 protocol = "https://";
184
185 string uploaderURL = protocol + m_scene.RegionInfo.ExternalHostName + ":" + MainServer.Instance.Port.ToString() + capsBase +
186 uploaderPath;
187
188
189 LLSDNewFileAngentInventoryVariablePriceReplyResponse uploadResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse();
190
191
192 uploadResponse.rsvp = uploaderURL;
193 uploadResponse.state = "upload";
194 uploadResponse.resource_cost = 0;
195 uploadResponse.upload_price = 0;
196
197 uploader.OnUpLoad += //UploadCompleteHandler;
198
199 delegate(
200 string passetName, string passetDescription, UUID passetID,
201 UUID pinventoryItem, UUID pparentFolder, byte[] pdata, string pinventoryType,
202 string passetType)
203 {
204 UploadCompleteHandler(passetName, passetDescription, passetID,
205 pinventoryItem, pparentFolder, pdata, pinventoryType,
206 passetType,agentID);
207 };
208 return uploadResponse;
209 }
210
211
212 public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID,
213 UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType,
214 string assetType,UUID AgentID)
215 {
216
217 sbyte assType = 0;
218 sbyte inType = 0;
219
220 if (inventoryType == "sound")
221 {
222 inType = 1;
223 assType = 1;
224 }
225 else if (inventoryType == "animation")
226 {
227 inType = 19;
228 assType = 20;
229 }
230 else if (inventoryType == "wearable")
231 {
232 inType = 18;
233 switch (assetType)
234 {
235 case "bodypart":
236 assType = 13;
237 break;
238 case "clothing":
239 assType = 5;
240 break;
241 }
242 }
243 else if (inventoryType == "mesh")
244 {
245 inType = (sbyte)InventoryType.Mesh;
246 assType = (sbyte)AssetType.Mesh;
247 }
248
249 AssetBase asset;
250 asset = new AssetBase(assetID, assetName, assType, AgentID.ToString());
251 asset.Data = data;
252
253 if (m_scene.AssetService != null)
254 m_scene.AssetService.Store(asset);
255
256 InventoryItemBase item = new InventoryItemBase();
257 item.Owner = AgentID;
258 item.CreatorId = AgentID.ToString();
259 item.ID = inventoryItem;
260 item.AssetID = asset.FullID;
261 item.Description = assetDescription;
262 item.Name = assetName;
263 item.AssetType = assType;
264 item.InvType = inType;
265 item.Folder = parentFolder;
266 item.CurrentPermissions = (uint)PermissionMask.All;
267 item.BasePermissions = (uint)PermissionMask.All;
268 item.EveryOnePermissions = 0;
269 item.NextPermissions = (uint)(PermissionMask.Move | PermissionMask.Modify | PermissionMask.Transfer);
270 item.CreationDate = Util.UnixTimeSinceEpoch();
271 m_scene.AddInventoryItem(item);
272
273 }
274 }
275}