diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs | 159 |
1 files changed, 154 insertions, 5 deletions
diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs index 720640e..380705f 100644 --- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs | |||
@@ -45,16 +45,53 @@ namespace OpenSim.Capabilities.Handlers | |||
45 | { | 45 | { |
46 | public class GetMeshHandler | 46 | public class GetMeshHandler |
47 | { | 47 | { |
48 | // private static readonly ILog m_log = | 48 | private static readonly ILog m_log = |
49 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 49 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
50 | 50 | ||
51 | private IAssetService m_assetService; | 51 | private IAssetService m_assetService; |
52 | 52 | ||
53 | public const string DefaultFormat = "vnd.ll.mesh"; | ||
54 | |||
53 | public GetMeshHandler(IAssetService assService) | 55 | public GetMeshHandler(IAssetService assService) |
54 | { | 56 | { |
55 | m_assetService = assService; | 57 | m_assetService = assService; |
56 | } | 58 | } |
59 | public Hashtable Handle(Hashtable request) | ||
60 | { | ||
61 | Hashtable ret = new Hashtable(); | ||
62 | ret["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound; | ||
63 | ret["content_type"] = "text/plain"; | ||
64 | ret["keepalive"] = false; | ||
65 | ret["reusecontext"] = false; | ||
66 | ret["int_bytes"] = 0; | ||
67 | string MeshStr = (string)request["mesh_id"]; | ||
68 | |||
69 | |||
70 | //m_log.DebugFormat("[GETMESH]: called {0}", MeshStr); | ||
71 | |||
72 | if (m_assetService == null) | ||
73 | { | ||
74 | m_log.Error("[GETMESH]: Cannot fetch mesh " + MeshStr + " without an asset service"); | ||
75 | } | ||
76 | |||
77 | UUID meshID; | ||
78 | if (!String.IsNullOrEmpty(MeshStr) && UUID.TryParse(MeshStr, out meshID)) | ||
79 | { | ||
80 | // m_log.DebugFormat("[GETMESH]: Received request for mesh id {0}", meshID); | ||
57 | 81 | ||
82 | |||
83 | ret = ProcessGetMesh(request, UUID.Zero, null); | ||
84 | |||
85 | |||
86 | } | ||
87 | else | ||
88 | { | ||
89 | m_log.Warn("[GETMESH]: Failed to parse a mesh_id from GetMesh request: " + (string)request["uri"]); | ||
90 | } | ||
91 | |||
92 | |||
93 | return ret; | ||
94 | } | ||
58 | public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap) | 95 | public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap) |
59 | { | 96 | { |
60 | Hashtable responsedata = new Hashtable(); | 97 | Hashtable responsedata = new Hashtable(); |
@@ -62,6 +99,7 @@ namespace OpenSim.Capabilities.Handlers | |||
62 | responsedata["content_type"] = "text/plain"; | 99 | responsedata["content_type"] = "text/plain"; |
63 | responsedata["keepalive"] = false; | 100 | responsedata["keepalive"] = false; |
64 | responsedata["str_response_string"] = "Request wasn't what was expected"; | 101 | responsedata["str_response_string"] = "Request wasn't what was expected"; |
102 | responsedata["reusecontext"] = false; | ||
65 | 103 | ||
66 | string meshStr = string.Empty; | 104 | string meshStr = string.Empty; |
67 | 105 | ||
@@ -77,6 +115,7 @@ namespace OpenSim.Capabilities.Handlers | |||
77 | responsedata["content_type"] = "text/plain"; | 115 | responsedata["content_type"] = "text/plain"; |
78 | responsedata["keepalive"] = false; | 116 | responsedata["keepalive"] = false; |
79 | responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh."; | 117 | responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh."; |
118 | responsedata["reusecontext"] = false; | ||
80 | return responsedata; | 119 | return responsedata; |
81 | } | 120 | } |
82 | 121 | ||
@@ -86,9 +125,100 @@ namespace OpenSim.Capabilities.Handlers | |||
86 | { | 125 | { |
87 | if (mesh.Type == (SByte)AssetType.Mesh) | 126 | if (mesh.Type == (SByte)AssetType.Mesh) |
88 | { | 127 | { |
89 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | 128 | |
90 | responsedata["content_type"] = "application/vnd.ll.mesh"; | 129 | Hashtable headers = new Hashtable(); |
91 | responsedata["int_response_code"] = 200; | 130 | responsedata["headers"] = headers; |
131 | |||
132 | string range = String.Empty; | ||
133 | |||
134 | if (((Hashtable)request["headers"])["range"] != null) | ||
135 | range = (string)((Hashtable)request["headers"])["range"]; | ||
136 | |||
137 | else if (((Hashtable)request["headers"])["Range"] != null) | ||
138 | range = (string)((Hashtable)request["headers"])["Range"]; | ||
139 | |||
140 | if (!String.IsNullOrEmpty(range)) // Mesh Asset LOD // Physics | ||
141 | { | ||
142 | // Range request | ||
143 | int start, end; | ||
144 | if (TryParseRange(range, out start, out end)) | ||
145 | { | ||
146 | // Before clamping start make sure we can satisfy it in order to avoid | ||
147 | // sending back the last byte instead of an error status | ||
148 | if (start >= mesh.Data.Length) | ||
149 | { | ||
150 | responsedata["int_response_code"] = 404; //501; //410; //404; | ||
151 | responsedata["content_type"] = "text/plain"; | ||
152 | responsedata["keepalive"] = false; | ||
153 | responsedata["str_response_string"] = "This range doesnt exist."; | ||
154 | responsedata["reusecontext"] = false; | ||
155 | responsedata["int_lod"] = 3; | ||
156 | return responsedata; | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | end = Utils.Clamp(end, 0, mesh.Data.Length - 1); | ||
161 | start = Utils.Clamp(start, 0, end); | ||
162 | int len = end - start + 1; | ||
163 | |||
164 | //m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); | ||
165 | |||
166 | if (start > 20000) | ||
167 | { | ||
168 | responsedata["int_lod"] = 3; | ||
169 | } | ||
170 | else if (start < 4097) | ||
171 | { | ||
172 | responsedata["int_lod"] = 1; | ||
173 | } | ||
174 | else | ||
175 | { | ||
176 | responsedata["int_lod"] = 2; | ||
177 | } | ||
178 | |||
179 | |||
180 | if (start == 0 && len == mesh.Data.Length) // well redudante maybe | ||
181 | { | ||
182 | responsedata["int_response_code"] = (int) System.Net.HttpStatusCode.OK; | ||
183 | responsedata["bin_response_data"] = mesh.Data; | ||
184 | responsedata["int_bytes"] = mesh.Data.Length; | ||
185 | responsedata["reusecontext"] = false; | ||
186 | responsedata["int_lod"] = 3; | ||
187 | |||
188 | } | ||
189 | else | ||
190 | { | ||
191 | responsedata["int_response_code"] = | ||
192 | (int) System.Net.HttpStatusCode.PartialContent; | ||
193 | headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, | ||
194 | mesh.Data.Length); | ||
195 | |||
196 | byte[] d = new byte[len]; | ||
197 | Array.Copy(mesh.Data, start, d, 0, len); | ||
198 | responsedata["bin_response_data"] = d; | ||
199 | responsedata["int_bytes"] = len; | ||
200 | responsedata["reusecontext"] = false; | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | else | ||
205 | { | ||
206 | m_log.Warn("[GETMESH]: Failed to parse a range from GetMesh request, sending full asset: " + (string)request["uri"]); | ||
207 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | ||
208 | responsedata["content_type"] = "application/vnd.ll.mesh"; | ||
209 | responsedata["int_response_code"] = 200; | ||
210 | responsedata["reusecontext"] = false; | ||
211 | responsedata["int_lod"] = 3; | ||
212 | } | ||
213 | } | ||
214 | else | ||
215 | { | ||
216 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | ||
217 | responsedata["content_type"] = "application/vnd.ll.mesh"; | ||
218 | responsedata["int_response_code"] = 200; | ||
219 | responsedata["reusecontext"] = false; | ||
220 | responsedata["int_lod"] = 3; | ||
221 | } | ||
92 | } | 222 | } |
93 | // Optionally add additional mesh types here | 223 | // Optionally add additional mesh types here |
94 | else | 224 | else |
@@ -97,6 +227,8 @@ namespace OpenSim.Capabilities.Handlers | |||
97 | responsedata["content_type"] = "text/plain"; | 227 | responsedata["content_type"] = "text/plain"; |
98 | responsedata["keepalive"] = false; | 228 | responsedata["keepalive"] = false; |
99 | responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; | 229 | responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; |
230 | responsedata["reusecontext"] = false; | ||
231 | responsedata["int_lod"] = 1; | ||
100 | return responsedata; | 232 | return responsedata; |
101 | } | 233 | } |
102 | } | 234 | } |
@@ -106,11 +238,28 @@ namespace OpenSim.Capabilities.Handlers | |||
106 | responsedata["content_type"] = "text/plain"; | 238 | responsedata["content_type"] = "text/plain"; |
107 | responsedata["keepalive"] = false; | 239 | responsedata["keepalive"] = false; |
108 | responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; | 240 | responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; |
241 | responsedata["reusecontext"] = false; | ||
242 | responsedata["int_lod"] = 0; | ||
109 | return responsedata; | 243 | return responsedata; |
110 | } | 244 | } |
111 | } | 245 | } |
112 | 246 | ||
113 | return responsedata; | 247 | return responsedata; |
114 | } | 248 | } |
249 | private bool TryParseRange(string header, out int start, out int end) | ||
250 | { | ||
251 | if (header.StartsWith("bytes=")) | ||
252 | { | ||
253 | string[] rangeValues = header.Substring(6).Split('-'); | ||
254 | if (rangeValues.Length == 2) | ||
255 | { | ||
256 | if (Int32.TryParse(rangeValues[0], out start) && Int32.TryParse(rangeValues[1], out end)) | ||
257 | return true; | ||
258 | } | ||
259 | } | ||
260 | |||
261 | start = end = 0; | ||
262 | return false; | ||
263 | } | ||
115 | } | 264 | } |
116 | } \ No newline at end of file | 265 | } \ No newline at end of file |