diff options
author | UbitUmarov | 2018-12-01 23:13:24 +0000 |
---|---|---|
committer | UbitUmarov | 2018-12-01 23:13:24 +0000 |
commit | 4ced4fed33c35599502c67a060139475fadafdb6 (patch) | |
tree | bc64d0439e461af4a264132daf7001e3c9f04c29 /OpenSim/Capabilities/Handlers | |
parent | clean a bit (diff) | |
download | opensim-SC-4ced4fed33c35599502c67a060139475fadafdb6.zip opensim-SC-4ced4fed33c35599502c67a060139475fadafdb6.tar.gz opensim-SC-4ced4fed33c35599502c67a060139475fadafdb6.tar.bz2 opensim-SC-4ced4fed33c35599502c67a060139475fadafdb6.tar.xz |
replace GetMeshModule and GetTextureModule
Diffstat (limited to 'OpenSim/Capabilities/Handlers')
-rw-r--r-- | OpenSim/Capabilities/Handlers/GetAssets/GetAssetsHandler.cs | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/OpenSim/Capabilities/Handlers/GetAssets/GetAssetsHandler.cs b/OpenSim/Capabilities/Handlers/GetAssets/GetAssetsHandler.cs new file mode 100644 index 0000000..1f4e4dd --- /dev/null +++ b/OpenSim/Capabilities/Handlers/GetAssets/GetAssetsHandler.cs | |||
@@ -0,0 +1,199 @@ | |||
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.Generic; | ||
31 | using System.Collections.Specialized; | ||
32 | using System.Reflection; | ||
33 | using System.IO; | ||
34 | using System.Web; | ||
35 | using log4net; | ||
36 | using Nini.Config; | ||
37 | using OpenMetaverse; | ||
38 | using OpenMetaverse.StructuredData; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.Servers; | ||
41 | using OpenSim.Framework.Servers.HttpServer; | ||
42 | using OpenSim.Services.Interfaces; | ||
43 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
44 | |||
45 | namespace OpenSim.Capabilities.Handlers | ||
46 | { | ||
47 | public class GetAssetsHandler | ||
48 | { | ||
49 | private static readonly ILog m_log = | ||
50 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private static readonly Dictionary<string, AssetType> queryTypes = new Dictionary<string, AssetType>() | ||
53 | { | ||
54 | {"texture_id", AssetType.Texture}, | ||
55 | {"sound_id", AssetType.Sound}, | ||
56 | {"callcard_id", AssetType.CallingCard}, | ||
57 | {"landmark_id", AssetType.Landmark}, | ||
58 | {"script_id", AssetType.LSLText}, | ||
59 | {"clothing_id", AssetType.Clothing}, | ||
60 | {"object_id", AssetType.Object}, | ||
61 | {"notecard_id", AssetType.Notecard}, | ||
62 | {"lsltext_id", AssetType.LSLText}, | ||
63 | {"lslbyte_id", AssetType.LSLBytecode}, | ||
64 | {"txtr_tga_id", AssetType.TextureTGA}, | ||
65 | {"bodypart_id", AssetType.Bodypart}, | ||
66 | {"snd_wav_id", AssetType.SoundWAV}, | ||
67 | {"img_tga_id", AssetType.ImageTGA}, | ||
68 | {"jpeg_id", AssetType.ImageJPEG}, | ||
69 | {"animatn_id", AssetType.Animation}, | ||
70 | {"gesture_id", AssetType.Gesture}, | ||
71 | {"mesh_id", AssetType.Mesh} | ||
72 | }; | ||
73 | |||
74 | private IAssetService m_assetService; | ||
75 | |||
76 | public GetAssetsHandler(IAssetService assService) | ||
77 | { | ||
78 | m_assetService = assService; | ||
79 | } | ||
80 | |||
81 | public Hashtable Handle(Hashtable request) | ||
82 | { | ||
83 | Hashtable responsedata = new Hashtable(); | ||
84 | responsedata["content_type"] = "text/plain"; | ||
85 | responsedata["int_bytes"] = 0; | ||
86 | |||
87 | if (m_assetService == null) | ||
88 | { | ||
89 | responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.ServiceUnavailable; | ||
90 | responsedata["str_response_string"] = "The asset service is unavailable"; | ||
91 | responsedata["keepalive"] = false; | ||
92 | return responsedata; | ||
93 | } | ||
94 | |||
95 | responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.BadRequest; | ||
96 | |||
97 | string[] queries = null; | ||
98 | if(request.Contains("querystringkeys")) | ||
99 | queries = (string[])request["querystringkeys"]; | ||
100 | |||
101 | if(queries == null || queries.Length == 0) | ||
102 | return responsedata; | ||
103 | |||
104 | string query = queries[0]; | ||
105 | if(!queryTypes.ContainsKey(query)) | ||
106 | { | ||
107 | m_log.Warn("[GETASSET]: Unknown type: " + query); | ||
108 | return responsedata; | ||
109 | } | ||
110 | |||
111 | AssetType type = queryTypes[query]; | ||
112 | |||
113 | string assetStr = string.Empty; | ||
114 | if (request.ContainsKey(query)) | ||
115 | assetStr = request[query].ToString(); | ||
116 | |||
117 | if (String.IsNullOrEmpty(assetStr)) | ||
118 | return responsedata; | ||
119 | |||
120 | UUID assetID = UUID.Zero; | ||
121 | if(!UUID.TryParse(assetStr, out assetID)) | ||
122 | return responsedata; | ||
123 | |||
124 | AssetBase asset = m_assetService.Get(assetID.ToString()); | ||
125 | if(asset == null) | ||
126 | { | ||
127 | m_log.Warn("[GETASSET]: not found: " + query + " " + assetStr); | ||
128 | responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound; | ||
129 | responsedata["str_response_string"] = "Asset not found."; | ||
130 | return responsedata; | ||
131 | } | ||
132 | |||
133 | if (asset.Type != (sbyte)type) | ||
134 | { | ||
135 | responsedata["str_response_string"] = "Got wrong asset type"; | ||
136 | return responsedata; | ||
137 | } | ||
138 | |||
139 | if(type != AssetType.Mesh && type != AssetType.Texture) | ||
140 | m_log.Warn("[GETASSETS]: type: " + query); | ||
141 | |||
142 | string range = String.Empty; | ||
143 | if (((Hashtable)request["headers"])["range"] != null) | ||
144 | range = (string)((Hashtable)request["headers"])["range"]; | ||
145 | else if (((Hashtable)request["headers"])["Range"] != null) | ||
146 | range = (string)((Hashtable)request["headers"])["Range"]; | ||
147 | |||
148 | responsedata["content_type"] = asset.Metadata.ContentType; | ||
149 | |||
150 | if (String.IsNullOrEmpty(range)) | ||
151 | { | ||
152 | // full asset | ||
153 | responsedata["bin_response_data"] = asset.Data; | ||
154 | responsedata["int_bytes"] = asset.Data.Length; | ||
155 | responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK; | ||
156 | return responsedata; | ||
157 | } | ||
158 | |||
159 | // range request | ||
160 | int start, end; | ||
161 | if (Util.TryParseHttpRange(range, out start, out end)) | ||
162 | { | ||
163 | // Before clamping start make sure we can satisfy it in order to avoid | ||
164 | // sending back the last byte instead of an error status | ||
165 | if (start >= asset.Data.Length) | ||
166 | { | ||
167 | responsedata["str_response_string"] = "This range doesnt exist."; | ||
168 | return responsedata; | ||
169 | } | ||
170 | |||
171 | if (end == -1) | ||
172 | end = asset.Data.Length - 1; | ||
173 | else | ||
174 | end = Utils.Clamp(end, 0, asset.Data.Length - 1); | ||
175 | |||
176 | start = Utils.Clamp(start, 0, end); | ||
177 | int len = end - start + 1; | ||
178 | |||
179 | //m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); | ||
180 | Hashtable headers = new Hashtable(); | ||
181 | headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, asset.Data.Length); | ||
182 | responsedata["headers"] = headers; | ||
183 | responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.PartialContent; | ||
184 | |||
185 | byte[] d = new byte[len]; | ||
186 | Array.Copy(asset.Data, start, d, 0, len); | ||
187 | responsedata["bin_response_data"] = d; | ||
188 | responsedata["int_bytes"] = len; | ||
189 | return responsedata; | ||
190 | } | ||
191 | |||
192 | m_log.Warn("[GETASSETS]: Failed to parse a range, sending full asset: " + assetStr); | ||
193 | responsedata["bin_response_data"] = asset.Data; | ||
194 | responsedata["int_bytes"] = asset.Data.Length; | ||
195 | responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK; | ||
196 | return responsedata; | ||
197 | } | ||
198 | } | ||
199 | } \ No newline at end of file | ||