aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs140
1 files changed, 135 insertions, 5 deletions
diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs
index 720640e..da59294 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,83 @@ 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 return responsedata;
156 }
157 else
158 {
159 end = Utils.Clamp(end, 0, mesh.Data.Length - 1);
160 start = Utils.Clamp(start, 0, end);
161 int len = end - start + 1;
162
163 //m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID);
164
165
166
167 if (start == 0 && len == mesh.Data.Length) // well redudante maybe
168 {
169 responsedata["int_response_code"] = (int) System.Net.HttpStatusCode.OK;
170 responsedata["bin_response_data"] = mesh.Data;
171 responsedata["int_bytes"] = mesh.Data.Length;
172 responsedata["reusecontext"] = false;
173 }
174 else
175 {
176 responsedata["int_response_code"] =
177 (int) System.Net.HttpStatusCode.PartialContent;
178 headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end,
179 mesh.Data.Length);
180
181 byte[] d = new byte[len];
182 Array.Copy(mesh.Data, start, d, 0, len);
183 responsedata["bin_response_data"] = d;
184 responsedata["int_bytes"] = len;
185 responsedata["reusecontext"] = false;
186 }
187 }
188 }
189 else
190 {
191 m_log.Warn("[GETMESH]: Failed to parse a range from GetMesh request, sending full asset: " + (string)request["uri"]);
192 responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data);
193 responsedata["content_type"] = "application/vnd.ll.mesh";
194 responsedata["int_response_code"] = 200;
195 responsedata["reusecontext"] = false;
196 }
197 }
198 else
199 {
200 responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data);
201 responsedata["content_type"] = "application/vnd.ll.mesh";
202 responsedata["int_response_code"] = 200;
203 responsedata["reusecontext"] = false;
204 }
92 } 205 }
93 // Optionally add additional mesh types here 206 // Optionally add additional mesh types here
94 else 207 else
@@ -97,6 +210,7 @@ namespace OpenSim.Capabilities.Handlers
97 responsedata["content_type"] = "text/plain"; 210 responsedata["content_type"] = "text/plain";
98 responsedata["keepalive"] = false; 211 responsedata["keepalive"] = false;
99 responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; 212 responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh.";
213 responsedata["reusecontext"] = false;
100 return responsedata; 214 return responsedata;
101 } 215 }
102 } 216 }
@@ -106,11 +220,27 @@ namespace OpenSim.Capabilities.Handlers
106 responsedata["content_type"] = "text/plain"; 220 responsedata["content_type"] = "text/plain";
107 responsedata["keepalive"] = false; 221 responsedata["keepalive"] = false;
108 responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; 222 responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!";
223 responsedata["reusecontext"] = false;
109 return responsedata; 224 return responsedata;
110 } 225 }
111 } 226 }
112 227
113 return responsedata; 228 return responsedata;
114 } 229 }
230 private bool TryParseRange(string header, out int start, out int end)
231 {
232 if (header.StartsWith("bytes="))
233 {
234 string[] rangeValues = header.Substring(6).Split('-');
235 if (rangeValues.Length == 2)
236 {
237 if (Int32.TryParse(rangeValues[0], out start) && Int32.TryParse(rangeValues[1], out end))
238 return true;
239 }
240 }
241
242 start = end = 0;
243 return false;
244 }
115 } 245 }
116} \ No newline at end of file 246} \ No newline at end of file