diff options
Diffstat (limited to 'OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs')
-rw-r--r-- | OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs index 720640e..9fe00e0 100644 --- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs | |||
@@ -30,6 +30,7 @@ using System.Collections; | |||
30 | using System.Collections.Specialized; | 30 | using System.Collections.Specialized; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.IO; | 32 | using System.IO; |
33 | using System.Text; | ||
33 | using System.Web; | 34 | using System.Web; |
34 | using log4net; | 35 | using log4net; |
35 | using Nini.Config; | 36 | using Nini.Config; |
@@ -43,41 +44,37 @@ using Caps = OpenSim.Framework.Capabilities.Caps; | |||
43 | 44 | ||
44 | namespace OpenSim.Capabilities.Handlers | 45 | namespace OpenSim.Capabilities.Handlers |
45 | { | 46 | { |
46 | public class GetMeshHandler | 47 | public class GetMeshHandler : BaseStreamHandler |
47 | { | 48 | { |
48 | // private static readonly ILog m_log = | 49 | // private static readonly ILog m_log = |
49 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 50 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
50 | 51 | ||
51 | private IAssetService m_assetService; | 52 | private IAssetService m_assetService; |
52 | 53 | ||
53 | public GetMeshHandler(IAssetService assService) | 54 | public GetMeshHandler(string path, IAssetService assService, string name, string description) |
55 | : base("GET", path, name, description) | ||
54 | { | 56 | { |
55 | m_assetService = assService; | 57 | m_assetService = assService; |
56 | } | 58 | } |
57 | 59 | ||
58 | public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap) | 60 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) |
59 | { | 61 | { |
60 | Hashtable responsedata = new Hashtable(); | 62 | // Try to parse the texture ID from the request URL |
61 | responsedata["int_response_code"] = 400; //501; //410; //404; | 63 | NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); |
62 | responsedata["content_type"] = "text/plain"; | 64 | string meshStr = query.GetOne("mesh_id"); |
63 | responsedata["keepalive"] = false; | ||
64 | responsedata["str_response_string"] = "Request wasn't what was expected"; | ||
65 | 65 | ||
66 | string meshStr = string.Empty; | 66 | // m_log.DebugFormat("Fetching mesh {0}", meshStr); |
67 | |||
68 | if (request.ContainsKey("mesh_id")) | ||
69 | meshStr = request["mesh_id"].ToString(); | ||
70 | 67 | ||
71 | UUID meshID = UUID.Zero; | 68 | UUID meshID = UUID.Zero; |
72 | if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID)) | 69 | if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID)) |
73 | { | 70 | { |
74 | if (m_assetService == null) | 71 | if (m_assetService == null) |
75 | { | 72 | { |
76 | responsedata["int_response_code"] = 404; //501; //410; //404; | 73 | httpResponse.StatusCode = 404; |
77 | responsedata["content_type"] = "text/plain"; | 74 | httpResponse.ContentType = "text/plain"; |
78 | responsedata["keepalive"] = false; | 75 | byte[] data = Encoding.UTF8.GetBytes("The asset service is unavailable. So is your mesh."); |
79 | responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh."; | 76 | httpResponse.Body.Write(data, 0, data.Length); |
80 | return responsedata; | 77 | return null; |
81 | } | 78 | } |
82 | 79 | ||
83 | AssetBase mesh = m_assetService.Get(meshID.ToString()); | 80 | AssetBase mesh = m_assetService.Get(meshID.ToString()); |
@@ -86,31 +83,32 @@ namespace OpenSim.Capabilities.Handlers | |||
86 | { | 83 | { |
87 | if (mesh.Type == (SByte)AssetType.Mesh) | 84 | if (mesh.Type == (SByte)AssetType.Mesh) |
88 | { | 85 | { |
89 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | 86 | byte[] data = mesh.Data; |
90 | responsedata["content_type"] = "application/vnd.ll.mesh"; | 87 | httpResponse.Body.Write(data, 0, data.Length); |
91 | responsedata["int_response_code"] = 200; | 88 | httpResponse.ContentType = "application/vnd.ll.mesh"; |
89 | httpResponse.StatusCode = 200; | ||
92 | } | 90 | } |
93 | // Optionally add additional mesh types here | 91 | // Optionally add additional mesh types here |
94 | else | 92 | else |
95 | { | 93 | { |
96 | responsedata["int_response_code"] = 404; //501; //410; //404; | 94 | httpResponse.StatusCode = 404; |
97 | responsedata["content_type"] = "text/plain"; | 95 | httpResponse.ContentType = "text/plain"; |
98 | responsedata["keepalive"] = false; | 96 | byte[] data = Encoding.UTF8.GetBytes("Unfortunately, this asset isn't a mesh."); |
99 | responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; | 97 | httpResponse.Body.Write(data, 0, data.Length); |
100 | return responsedata; | 98 | httpResponse.KeepAlive = false; |
101 | } | 99 | } |
102 | } | 100 | } |
103 | else | 101 | else |
104 | { | 102 | { |
105 | responsedata["int_response_code"] = 404; //501; //410; //404; | 103 | httpResponse.StatusCode = 404; |
106 | responsedata["content_type"] = "text/plain"; | 104 | httpResponse.ContentType = "text/plain"; |
107 | responsedata["keepalive"] = false; | 105 | byte[] data = Encoding.UTF8.GetBytes("Your Mesh wasn't found. Sorry!"); |
108 | responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; | 106 | httpResponse.Body.Write(data, 0, data.Length); |
109 | return responsedata; | 107 | httpResponse.KeepAlive = false; |
110 | } | 108 | } |
111 | } | 109 | } |
112 | 110 | ||
113 | return responsedata; | 111 | return null; |
114 | } | 112 | } |
115 | } | 113 | } |
116 | } \ No newline at end of file | 114 | } \ No newline at end of file |