From a11edceb00b5b86f825bd957bdac9edb91f893dd Mon Sep 17 00:00:00 2001
From: UbitUmarov
Date: Wed, 2 Sep 2015 19:54:53 +0100
Subject: seems to compile ( tests comented out)
---
.../Handlers/GetMesh/GetMeshHandler.cs | 218 +++++----------------
.../Handlers/GetMesh/GetMeshServerConnector.cs | 16 +-
2 files changed, 60 insertions(+), 174 deletions(-)
(limited to 'OpenSim/Capabilities/Handlers/GetMesh')
diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs
index 7fcc798..a9b81f3 100644
--- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs
+++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs
@@ -25,37 +25,39 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Reflection;
+using System.IO;
+using System.Web;
using log4net;
+using Nini.Config;
using OpenMetaverse;
-using OpenMetaverse.Imaging;
+using OpenMetaverse.StructuredData;
using OpenSim.Framework;
+using OpenSim.Framework.Servers;
using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Services.Interfaces;
-using System;
-using System.Collections.Specialized;
-using System.Drawing;
-using System.Drawing.Imaging;
-using System.IO;
-using System.Reflection;
-using System.Web;
+using Caps = OpenSim.Framework.Capabilities.Caps;
+
+
+
namespace OpenSim.Capabilities.Handlers
{
- public class GetMeshHandler : BaseStreamHandler
+ public class GetMeshHandler
{
private static readonly ILog m_log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
-
+
private IAssetService m_assetService;
public const string DefaultFormat = "vnd.ll.mesh";
-
+
public GetMeshHandler(IAssetService assService)
{
m_assetService = assService;
- m_RedirectURL = redirectURL;
- if (m_RedirectURL != null && !m_RedirectURL.EndsWith("/"))
- m_RedirectURL += "/";
}
public Hashtable Handle(Hashtable request)
{
@@ -67,7 +69,7 @@ namespace OpenSim.Capabilities.Handlers
ret["int_bytes"] = 0;
ret["int_lod"] = 0;
string MeshStr = (string)request["mesh_id"];
-
+
//m_log.DebugFormat("[GETMESH]: called {0}", MeshStr);
@@ -81,122 +83,53 @@ namespace OpenSim.Capabilities.Handlers
{
// m_log.DebugFormat("[GETMESH]: Received request for mesh id {0}", meshID);
-
+
ret = ProcessGetMesh(request, UUID.Zero, null);
-
-
+
+
}
else
{
m_log.Warn("[GETMESH]: Failed to parse a mesh_id from GetMesh request: " + (string)request["uri"]);
}
-
+
return ret;
}
public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap)
{
- // Try to parse the texture ID from the request URL
- NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query);
- string textureStr = query.GetOne("mesh_id");
+ Hashtable responsedata = new Hashtable();
+ responsedata["int_response_code"] = 400; //501; //410; //404;
+ responsedata["content_type"] = "text/plain";
+ responsedata["keepalive"] = false;
+ responsedata["str_response_string"] = "Request wasn't what was expected";
responsedata["reusecontext"] = false;
responsedata["int_lod"] = 0;
responsedata["int_bytes"] = 0;
- if (m_assetService == null)
- {
- m_log.Error("[GETMESH]: Cannot fetch mesh " + textureStr + " without an asset service");
- httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
- }
-
- UUID meshID;
- if (!String.IsNullOrEmpty(textureStr) && UUID.TryParse(textureStr, out meshID))
- {
- // OK, we have an array with preferred formats, possibly with only one entry
-
- httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
- AssetBase mesh;
+ string meshStr = string.Empty;
- if (!String.IsNullOrEmpty(m_RedirectURL))
- {
- // Only try to fetch locally cached meshes. Misses are redirected
- mesh = m_assetService.GetCached(meshID.ToString());
+ if (request.ContainsKey("mesh_id"))
+ meshStr = request["mesh_id"].ToString();
- if (mesh != null)
- {
- if (mesh.Type != (sbyte)AssetType.Mesh)
- {
- httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
- }
- WriteMeshData(httpRequest, httpResponse, mesh);
- }
- else
- {
- string textureUrl = m_RedirectURL + "?mesh_id="+ meshID.ToString();
- m_log.Debug("[GETMESH]: Redirecting mesh request to " + textureUrl);
- httpResponse.StatusCode = (int)OSHttpStatusCode.RedirectMovedPermanently;
- httpResponse.RedirectLocation = textureUrl;
- return null;
- }
- }
- else // no redirect
+ UUID meshID = UUID.Zero;
+ if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID))
+ {
+ if (m_assetService == null)
{
- // try the cache
- mesh = m_assetService.GetCached(meshID.ToString());
-
- if (mesh == null)
- {
- // Fetch locally or remotely. Misses return a 404
- mesh = m_assetService.Get(meshID.ToString());
-
- if (mesh != null)
- {
- if (mesh.Type != (sbyte)AssetType.Mesh)
- {
- httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
- return null;
- }
- WriteMeshData(httpRequest, httpResponse, mesh);
- return null;
- }
- }
- else // it was on the cache
- {
- if (mesh.Type != (sbyte)AssetType.Mesh)
- {
- httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
- return null;
- }
- WriteMeshData(httpRequest, httpResponse, mesh);
- return null;
- }
+ responsedata["int_response_code"] = 404; //501; //410; //404;
+ responsedata["content_type"] = "text/plain";
+ responsedata["keepalive"] = false;
+ responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh.";
+ responsedata["reusecontext"] = false;
+ return responsedata;
}
- // not found
- httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
- return null;
- }
- else
- {
- m_log.Warn("[GETTEXTURE]: Failed to parse a mesh_id from GetMesh request: " + httpRequest.Url);
- }
-
- return null;
- }
-
- private void WriteMeshData(IOSHttpRequest request, IOSHttpResponse response, AssetBase texture)
- {
- string range = request.Headers.GetOne("Range");
+ AssetBase mesh = m_assetService.Get(meshID.ToString());
- if (!String.IsNullOrEmpty(range))
- {
- // Range request
- int start, end;
- if (TryParseRange(range, out start, out end))
+ if (mesh != null)
{
- // Before clamping start make sure we can satisfy it in order to avoid
- // sending back the last byte instead of an error status
- if (start >= texture.Data.Length)
+ if (mesh.Type == (SByte)AssetType.Mesh)
{
Hashtable headers = new Hashtable();
@@ -212,12 +145,12 @@ namespace OpenSim.Capabilities.Handlers
if (!String.IsNullOrEmpty(range)) // Mesh Asset LOD // Physics
{
- // Range request
+ // Range request
int start, end;
if (TryParseRange(range, out start, out end))
{
- // Before clamping start make sure we can satisfy it in order to avoid
- // sending back the last byte instead of an error status
+ // Before clamping start make sure we can satisfy it in order to avoid
+ // sending back the last byte instead of an error status
if (start >= mesh.Data.Length)
{
responsedata["int_response_code"] = 404; //501; //410; //404;
@@ -249,20 +182,20 @@ namespace OpenSim.Capabilities.Handlers
responsedata["int_lod"] = 2;
}
-
+
if (start == 0 && len == mesh.Data.Length) // well redudante maybe
{
- responsedata["int_response_code"] = (int) System.Net.HttpStatusCode.OK;
+ responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK;
responsedata["bin_response_data"] = mesh.Data;
responsedata["int_bytes"] = mesh.Data.Length;
responsedata["reusecontext"] = false;
responsedata["int_lod"] = 3;
-
+
}
else
{
responsedata["int_response_code"] =
- (int) System.Net.HttpStatusCode.PartialContent;
+ (int)System.Net.HttpStatusCode.PartialContent;
headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end,
mesh.Data.Length);
@@ -293,6 +226,7 @@ namespace OpenSim.Capabilities.Handlers
responsedata["int_lod"] = 3;
}
}
+ // Optionally add additional mesh types here
else
{
responsedata["int_response_code"] = 404; //501; //410; //404;
@@ -315,58 +249,8 @@ namespace OpenSim.Capabilities.Handlers
return responsedata;
}
}
- else
- {
- // Full content request
- response.StatusCode = (int)System.Net.HttpStatusCode.OK;
- response.ContentLength = texture.Data.Length;
- response.ContentType = "application/vnd.ll.mesh";
- response.Body.Write(texture.Data, 0, texture.Data.Length);
- }
- }
- ///
- /// Parse a range header.
- ///
- ///
- /// As per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html,
- /// this obeys range headers with two values (e.g. 533-4165) and no second value (e.g. 533-).
- /// Where there is no value, -1 is returned.
- /// FIXME: Need to cover the case where only a second value is specified (e.g. -4165), probably by returning -1
- /// for start.
- ///
- ///
- /// Start of the range. Undefined if this was not a number.
- /// End of the range. Will be -1 if no end specified. Undefined if there was a raw string but this was not a number.
- private bool TryParseRange(string header, out int start, out int end)
- {
- start = end = 0;
-
- if (header.StartsWith("bytes="))
- {
- string[] rangeValues = header.Substring(6).Split('-');
-
- if (rangeValues.Length == 2)
- {
- if (!Int32.TryParse(rangeValues[0], out start))
- return false;
-
- string rawEnd = rangeValues[1];
-
- if (rawEnd == "")
- {
- end = -1;
- return true;
- }
- else if (Int32.TryParse(rawEnd, out end))
- {
- return true;
- }
- }
- }
-
- start = end = 0;
- return false;
+ return responsedata;
}
private bool TryParseRange(string header, out int start, out int end)
{
diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs
index 19de3cf..b494aa4 100644
--- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs
+++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs
@@ -64,13 +64,15 @@ namespace OpenSim.Capabilities.Handlers
string rurl = serverConfig.GetString("GetMeshRedirectURL");
- server.AddStreamHandler(
- new GetTextureHandler("/CAPS/GetMesh/" /*+ UUID.Random() */, m_AssetService, "GetMesh", null, rurl));
-
- rurl = serverConfig.GetString("GetMesh2RedirectURL");
-
- server.AddStreamHandler(
- new GetTextureHandler("/CAPS/GetMesh2/" /*+ UUID.Random() */, m_AssetService, "GetMesh2", null, rurl));
+ GetMeshHandler gmeshHandler = new GetMeshHandler(m_AssetService);
+ IRequestHandler reqHandler
+ = new RestHTTPHandler(
+ "GET",
+ "/CAPS/" + UUID.Random(),
+ httpMethod => gmeshHandler.ProcessGetMesh(httpMethod, UUID.Zero, null),
+ "GetMesh",
+ null);
+ server.AddStreamHandler(reqHandler); ;
}
}
}
\ No newline at end of file
--
cgit v1.1