diff options
author | Justin Clark-Casey (justincc) | 2011-12-01 23:24:15 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2011-12-01 23:24:15 +0000 |
commit | 5460f2e035f50aade96b3daa0cb284bcb6faeea7 (patch) | |
tree | 623a22611e75c74f82fcb77664d971f463bcffb7 /OpenSim/Region/ClientStack | |
parent | Provide more user feedback when "debug http" is set (diff) | |
download | opensim-SC_OLD-5460f2e035f50aade96b3daa0cb284bcb6faeea7.zip opensim-SC_OLD-5460f2e035f50aade96b3daa0cb284bcb6faeea7.tar.gz opensim-SC_OLD-5460f2e035f50aade96b3daa0cb284bcb6faeea7.tar.bz2 opensim-SC_OLD-5460f2e035f50aade96b3daa0cb284bcb6faeea7.tar.xz |
refactor: Separate the upload baked texture handler out from BunchOfCaps
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 123 | ||||
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs | 112 |
2 files changed, 113 insertions, 122 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 07b4df3..98dda36 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs | |||
@@ -56,8 +56,6 @@ namespace OpenSim.Region.ClientStack.Linden | |||
56 | string assetName, string description, UUID assetID, UUID inventoryItem, UUID parentFolder, | 56 | string assetName, string description, UUID assetID, UUID inventoryItem, UUID parentFolder, |
57 | byte[] data, string inventoryType, string assetType); | 57 | byte[] data, string inventoryType, string assetType); |
58 | 58 | ||
59 | public delegate void UploadedBakedTexture(UUID assetID, byte[] data); | ||
60 | |||
61 | public delegate UUID UpdateItem(UUID itemID, byte[] data); | 59 | public delegate UUID UpdateItem(UUID itemID, byte[] data); |
62 | 60 | ||
63 | public delegate void UpdateTaskScript(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors); | 61 | public delegate void UpdateTaskScript(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors); |
@@ -97,7 +95,6 @@ namespace OpenSim.Region.ClientStack.Linden | |||
97 | private static readonly string m_notecardTaskUpdatePath = "0005/"; | 95 | private static readonly string m_notecardTaskUpdatePath = "0005/"; |
98 | // private static readonly string m_fetchInventoryPath = "0006/"; | 96 | // private static readonly string m_fetchInventoryPath = "0006/"; |
99 | // private static readonly string m_remoteParcelRequestPath = "0009/";// This is in the LandManagementModule. | 97 | // private static readonly string m_remoteParcelRequestPath = "0009/";// This is in the LandManagementModule. |
100 | private static readonly string m_uploadBakedTexturePath = "0010/";// This is in the LandManagementModule. | ||
101 | 98 | ||
102 | 99 | ||
103 | // These are callbacks which will be setup by the scene so that we can update scene data when we | 100 | // These are callbacks which will be setup by the scene so that we can update scene data when we |
@@ -164,8 +161,6 @@ namespace OpenSim.Region.ClientStack.Linden | |||
164 | IRequestHandler req = new RestStreamHandler("POST", capsBase + m_notecardTaskUpdatePath, ScriptTaskInventory); | 161 | IRequestHandler req = new RestStreamHandler("POST", capsBase + m_notecardTaskUpdatePath, ScriptTaskInventory); |
165 | m_HostCapsObj.RegisterHandler("UpdateScriptTaskInventory", req); | 162 | m_HostCapsObj.RegisterHandler("UpdateScriptTaskInventory", req); |
166 | m_HostCapsObj.RegisterHandler("UpdateScriptTask", req); | 163 | m_HostCapsObj.RegisterHandler("UpdateScriptTask", req); |
167 | m_HostCapsObj.RegisterHandler("UploadBakedTexture", new RestStreamHandler("POST", capsBase + m_uploadBakedTexturePath, UploadBakedTexture)); | ||
168 | |||
169 | } | 164 | } |
170 | catch (Exception e) | 165 | catch (Exception e) |
171 | { | 166 | { |
@@ -331,74 +326,6 @@ namespace OpenSim.Region.ClientStack.Linden | |||
331 | } | 326 | } |
332 | 327 | ||
333 | /// <summary> | 328 | /// <summary> |
334 | /// Handle a request from the client for a Uri to upload a baked texture. | ||
335 | /// </summary> | ||
336 | /// <param name="request"></param> | ||
337 | /// <param name="path"></param> | ||
338 | /// <param name="param"></param> | ||
339 | /// <param name="httpRequest"></param> | ||
340 | /// <param name="httpResponse"></param> | ||
341 | /// <returns>The upload response if the request is successful, null otherwise.</returns> | ||
342 | public string UploadBakedTexture(string request, string path, | ||
343 | string param, OSHttpRequest httpRequest, | ||
344 | OSHttpResponse httpResponse) | ||
345 | { | ||
346 | try | ||
347 | { | ||
348 | // m_log.Debug("[CAPS]: UploadBakedTexture Request in region: " + m_regionName); | ||
349 | |||
350 | string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath; | ||
351 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); | ||
352 | |||
353 | BakedTextureUploader uploader = | ||
354 | new BakedTextureUploader(capsBase + uploaderPath, m_HostCapsObj.HttpListener); | ||
355 | uploader.OnUpLoad += BakedTextureUploaded; | ||
356 | |||
357 | m_HostCapsObj.HttpListener.AddStreamHandler( | ||
358 | new BinaryStreamHandler("POST", capsBase + uploaderPath, | ||
359 | uploader.uploaderCaps)); | ||
360 | |||
361 | string protocol = "http://"; | ||
362 | |||
363 | if (m_HostCapsObj.SSLCaps) | ||
364 | protocol = "https://"; | ||
365 | |||
366 | string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + | ||
367 | m_HostCapsObj.Port.ToString() + capsBase + uploaderPath; | ||
368 | |||
369 | LLSDAssetUploadResponse uploadResponse = | ||
370 | new LLSDAssetUploadResponse(); | ||
371 | uploadResponse.uploader = uploaderURL; | ||
372 | uploadResponse.state = "upload"; | ||
373 | |||
374 | return LLSDHelpers.SerialiseLLSDReply(uploadResponse); | ||
375 | } | ||
376 | catch (Exception e) | ||
377 | { | ||
378 | m_log.Error("[CAPS]: " + e.ToString()); | ||
379 | } | ||
380 | |||
381 | return null; | ||
382 | } | ||
383 | |||
384 | /// <summary> | ||
385 | /// Called when a baked texture has been successfully uploaded by a client. | ||
386 | /// </summary> | ||
387 | /// <param name="assetID"></param> | ||
388 | /// <param name="data"></param> | ||
389 | public void BakedTextureUploaded(UUID assetID, byte[] data) | ||
390 | { | ||
391 | // m_log.WarnFormat("[CAPS]: Received baked texture {0}", assetID.ToString()); | ||
392 | |||
393 | AssetBase asset; | ||
394 | asset = new AssetBase(assetID, "Baked Texture", (sbyte)AssetType.Texture, m_HostCapsObj.AgentID.ToString()); | ||
395 | asset.Data = data; | ||
396 | asset.Temporary = true; | ||
397 | asset.Local = !m_persistBakedTextures; // Local assets aren't persisted, non-local are | ||
398 | m_assetService.Store(asset); | ||
399 | } | ||
400 | |||
401 | /// <summary> | ||
402 | /// Called when new asset data for an agent inventory item update has been uploaded. | 329 | /// Called when new asset data for an agent inventory item update has been uploaded. |
403 | /// </summary> | 330 | /// </summary> |
404 | /// <param name="itemID">Item to update</param> | 331 | /// <param name="itemID">Item to update</param> |
@@ -1067,6 +994,7 @@ namespace OpenSim.Region.ClientStack.Linden | |||
1067 | // XXX Maybe this should be some meaningful error packet | 994 | // XXX Maybe this should be some meaningful error packet |
1068 | return null; | 995 | return null; |
1069 | } | 996 | } |
997 | |||
1070 | ///Left this in and commented in case there are unforseen issues | 998 | ///Left this in and commented in case there are unforseen issues |
1071 | //private void SaveAssetToFile(string filename, byte[] data) | 999 | //private void SaveAssetToFile(string filename, byte[] data) |
1072 | //{ | 1000 | //{ |
@@ -1090,53 +1018,4 @@ namespace OpenSim.Region.ClientStack.Linden | |||
1090 | fs.Close(); | 1018 | fs.Close(); |
1091 | } | 1019 | } |
1092 | } | 1020 | } |
1093 | |||
1094 | public class BakedTextureUploader | ||
1095 | { | ||
1096 | public event UploadedBakedTexture OnUpLoad; | ||
1097 | private UploadedBakedTexture handlerUpLoad = null; | ||
1098 | |||
1099 | private string uploaderPath = String.Empty; | ||
1100 | private UUID newAssetID; | ||
1101 | private IHttpServer httpListener; | ||
1102 | |||
1103 | public BakedTextureUploader(string path, IHttpServer httpServer) | ||
1104 | { | ||
1105 | newAssetID = UUID.Random(); | ||
1106 | uploaderPath = path; | ||
1107 | httpListener = httpServer; | ||
1108 | // m_log.InfoFormat("[CAPS] baked texture upload starting for {0}",newAssetID); | ||
1109 | } | ||
1110 | |||
1111 | /// <summary> | ||
1112 | /// Handle raw uploaded baked texture data. | ||
1113 | /// </summary> | ||
1114 | /// <param name="data"></param> | ||
1115 | /// <param name="path"></param> | ||
1116 | /// <param name="param"></param> | ||
1117 | /// <returns></returns> | ||
1118 | public string uploaderCaps(byte[] data, string path, string param) | ||
1119 | { | ||
1120 | handlerUpLoad = OnUpLoad; | ||
1121 | if (handlerUpLoad != null) | ||
1122 | { | ||
1123 | Util.FireAndForget(delegate(object o) { handlerUpLoad(newAssetID, data); }); | ||
1124 | } | ||
1125 | |||
1126 | string res = String.Empty; | ||
1127 | LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); | ||
1128 | uploadComplete.new_asset = newAssetID.ToString(); | ||
1129 | uploadComplete.new_inventory_item = UUID.Zero; | ||
1130 | uploadComplete.state = "complete"; | ||
1131 | |||
1132 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | ||
1133 | |||
1134 | httpListener.RemoveStreamHandler("POST", uploaderPath); | ||
1135 | |||
1136 | // m_log.InfoFormat("[CAPS] baked texture upload completed for {0}",newAssetID); | ||
1137 | |||
1138 | return res; | ||
1139 | } | ||
1140 | } | ||
1141 | |||
1142 | } \ No newline at end of file | 1021 | } \ No newline at end of file |
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs new file mode 100644 index 0000000..e61815f --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs | |||
@@ -0,0 +1,112 @@ | |||
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.Collections; | ||
30 | using System.Collections.Specialized; | ||
31 | using System.Drawing; | ||
32 | using System.Drawing.Imaging; | ||
33 | using System.Reflection; | ||
34 | using System.IO; | ||
35 | using System.Web; | ||
36 | using log4net; | ||
37 | using Nini.Config; | ||
38 | using Mono.Addins; | ||
39 | using OpenMetaverse; | ||
40 | using OpenMetaverse.StructuredData; | ||
41 | using OpenMetaverse.Imaging; | ||
42 | using OpenSim.Framework; | ||
43 | using OpenSim.Framework.Servers; | ||
44 | using OpenSim.Framework.Servers.HttpServer; | ||
45 | using OpenSim.Region.Framework.Interfaces; | ||
46 | using OpenSim.Region.Framework.Scenes; | ||
47 | using OpenSim.Services.Interfaces; | ||
48 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
49 | using OpenSim.Capabilities.Handlers; | ||
50 | |||
51 | namespace OpenSim.Region.ClientStack.Linden | ||
52 | { | ||
53 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] | ||
54 | public class UploadBakedTextureModule : INonSharedRegionModule | ||
55 | { | ||
56 | // private static readonly ILog m_log = | ||
57 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
58 | |||
59 | /// <summary> | ||
60 | /// For historical reasons this is fixed, but there | ||
61 | /// </summary> | ||
62 | private static readonly string m_uploadBakedTexturePath = "0010/";// This is in the LandManagementModule. | ||
63 | |||
64 | private Scene m_scene; | ||
65 | private bool m_persistBakedTextures; | ||
66 | |||
67 | public void Initialise(IConfigSource source) | ||
68 | { | ||
69 | IConfig sconfig = source.Configs["Startup"]; | ||
70 | if (sconfig != null) | ||
71 | m_persistBakedTextures = sconfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); | ||
72 | } | ||
73 | |||
74 | public void AddRegion(Scene s) | ||
75 | { | ||
76 | m_scene = s; | ||
77 | } | ||
78 | |||
79 | public void RemoveRegion(Scene s) | ||
80 | { | ||
81 | } | ||
82 | |||
83 | public void RegionLoaded(Scene s) | ||
84 | { | ||
85 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | ||
86 | } | ||
87 | |||
88 | public void PostInitialise() | ||
89 | { | ||
90 | } | ||
91 | |||
92 | public void Close() { } | ||
93 | |||
94 | public string Name { get { return "UploadBakedTextureModule"; } } | ||
95 | |||
96 | public Type ReplaceableInterface | ||
97 | { | ||
98 | get { return null; } | ||
99 | } | ||
100 | |||
101 | public void RegisterCaps(UUID agentID, Caps caps) | ||
102 | { | ||
103 | caps.RegisterHandler( | ||
104 | "UploadBakedTexture", | ||
105 | new RestStreamHandler( | ||
106 | "POST", | ||
107 | "/CAPS/" + m_uploadBakedTexturePath, | ||
108 | new UploadBakedTextureHandler( | ||
109 | caps, m_scene.AssetService, m_persistBakedTextures).UploadBakedTexture)); | ||
110 | } | ||
111 | } | ||
112 | } \ No newline at end of file | ||