diff options
Diffstat (limited to 'OpenSim/Capabilities')
16 files changed, 917 insertions, 301 deletions
diff --git a/OpenSim/Capabilities/Caps.cs b/OpenSim/Capabilities/Caps.cs index 049afab..3efab8e 100644 --- a/OpenSim/Capabilities/Caps.cs +++ b/OpenSim/Capabilities/Caps.cs | |||
@@ -30,6 +30,7 @@ using System.Collections; | |||
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.IO; | 31 | using System.IO; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using System.Threading; | ||
33 | using log4net; | 34 | using log4net; |
34 | using Nini.Config; | 35 | using Nini.Config; |
35 | using OpenMetaverse; | 36 | using OpenMetaverse; |
@@ -71,6 +72,7 @@ namespace OpenSim.Framework.Capabilities | |||
71 | private IHttpServer m_httpListener; | 72 | private IHttpServer m_httpListener; |
72 | private UUID m_agentID; | 73 | private UUID m_agentID; |
73 | private string m_regionName; | 74 | private string m_regionName; |
75 | private ManualResetEvent m_capsActive = new ManualResetEvent(false); | ||
74 | 76 | ||
75 | public UUID AgentID | 77 | public UUID AgentID |
76 | { | 78 | { |
@@ -136,6 +138,7 @@ namespace OpenSim.Framework.Capabilities | |||
136 | m_agentID = agent; | 138 | m_agentID = agent; |
137 | m_capsHandlers = new CapsHandlers(httpServer, httpListen, httpPort, (httpServer == null) ? false : httpServer.UseSSL); | 139 | m_capsHandlers = new CapsHandlers(httpServer, httpListen, httpPort, (httpServer == null) ? false : httpServer.UseSSL); |
138 | m_regionName = regionName; | 140 | m_regionName = regionName; |
141 | m_capsActive.Reset(); | ||
139 | } | 142 | } |
140 | 143 | ||
141 | /// <summary> | 144 | /// <summary> |
@@ -255,5 +258,16 @@ namespace OpenSim.Framework.Capabilities | |||
255 | 258 | ||
256 | return caps; | 259 | return caps; |
257 | } | 260 | } |
261 | |||
262 | public void Activate() | ||
263 | { | ||
264 | m_capsActive.Set(); | ||
265 | } | ||
266 | |||
267 | public bool WaitForActivation() | ||
268 | { | ||
269 | // Wait for 30s. If that elapses, return false and run without caps | ||
270 | return m_capsActive.WaitOne(120000); | ||
271 | } | ||
258 | } | 272 | } |
259 | } \ No newline at end of file | 273 | } \ No newline at end of file |
diff --git a/OpenSim/Capabilities/CapsHandlers.cs b/OpenSim/Capabilities/CapsHandlers.cs index 890df90..04cede1 100644 --- a/OpenSim/Capabilities/CapsHandlers.cs +++ b/OpenSim/Capabilities/CapsHandlers.cs | |||
@@ -90,6 +90,7 @@ namespace OpenSim.Framework.Capabilities | |||
90 | lock (m_capsHandlers) | 90 | lock (m_capsHandlers) |
91 | { | 91 | { |
92 | m_httpListener.RemoveStreamHandler("POST", m_capsHandlers[capsName].Path); | 92 | m_httpListener.RemoveStreamHandler("POST", m_capsHandlers[capsName].Path); |
93 | m_httpListener.RemoveStreamHandler("PUT", m_capsHandlers[capsName].Path); | ||
93 | m_httpListener.RemoveStreamHandler("GET", m_capsHandlers[capsName].Path); | 94 | m_httpListener.RemoveStreamHandler("GET", m_capsHandlers[capsName].Path); |
94 | m_capsHandlers.Remove(capsName); | 95 | m_capsHandlers.Remove(capsName); |
95 | } | 96 | } |
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs index 7197049..4da6c3d 100644 --- a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs +++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs | |||
@@ -416,7 +416,7 @@ namespace OpenSim.Capabilities.Handlers | |||
416 | 416 | ||
417 | version = containingFolder.Version; | 417 | version = containingFolder.Version; |
418 | 418 | ||
419 | if (fetchItems) | 419 | if (fetchItems && containingFolder.Type != (short)FolderType.Trash) |
420 | { | 420 | { |
421 | List<InventoryItemBase> itemsToReturn = contents.Items; | 421 | List<InventoryItemBase> itemsToReturn = contents.Items; |
422 | List<InventoryItemBase> originalItems = new List<InventoryItemBase>(itemsToReturn); | 422 | List<InventoryItemBase> originalItems = new List<InventoryItemBase>(itemsToReturn); |
@@ -441,6 +441,10 @@ namespace OpenSim.Capabilities.Handlers | |||
441 | } | 441 | } |
442 | 442 | ||
443 | // Now scan for folder links and insert the items they target and those links at the head of the return data | 443 | // Now scan for folder links and insert the items they target and those links at the head of the return data |
444 | |||
445 | /* dont send contents of LinkFolders. | ||
446 | from docs seems this was never a spec | ||
447 | |||
444 | foreach (InventoryItemBase item in originalItems) | 448 | foreach (InventoryItemBase item in originalItems) |
445 | { | 449 | { |
446 | if (item.AssetType == (int)AssetType.LinkFolder) | 450 | if (item.AssetType == (int)AssetType.LinkFolder) |
@@ -471,6 +475,7 @@ namespace OpenSim.Capabilities.Handlers | |||
471 | } | 475 | } |
472 | } | 476 | } |
473 | } | 477 | } |
478 | */ | ||
474 | } | 479 | } |
475 | 480 | ||
476 | // foreach (InventoryItemBase item in contents.Items) | 481 | // foreach (InventoryItemBase item in contents.Items) |
@@ -723,8 +728,8 @@ namespace OpenSim.Capabilities.Handlers | |||
723 | if (item.AssetType == (int)AssetType.Link) | 728 | if (item.AssetType == (int)AssetType.Link) |
724 | itemIDs.Add(item.AssetID); | 729 | itemIDs.Add(item.AssetID); |
725 | 730 | ||
726 | else if (item.AssetType == (int)AssetType.LinkFolder) | 731 | // else if (item.AssetType == (int)AssetType.LinkFolder) |
727 | folderIDs.Add(item.AssetID); | 732 | // folderIDs.Add(item.AssetID); |
728 | } | 733 | } |
729 | 734 | ||
730 | //m_log.DebugFormat("[XXX]: folder {0} has {1} links and {2} linkfolders", contents.FolderID, itemIDs.Count, folderIDs.Count); | 735 | //m_log.DebugFormat("[XXX]: folder {0} has {1} links and {2} linkfolders", contents.FolderID, itemIDs.Count, folderIDs.Count); |
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs index c904392..1753f60 100644 --- a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs +++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs | |||
@@ -64,21 +64,36 @@ namespace OpenSim.Capabilities.Handlers | |||
64 | 64 | ||
65 | UUID[] itemIDs = new UUID[itemsRequested.Count]; | 65 | UUID[] itemIDs = new UUID[itemsRequested.Count]; |
66 | int i = 0; | 66 | int i = 0; |
67 | |||
67 | foreach (OSDMap osdItemId in itemsRequested) | 68 | foreach (OSDMap osdItemId in itemsRequested) |
68 | { | 69 | { |
69 | itemIDs[i++] = osdItemId["item_id"].AsUUID(); | 70 | itemIDs[i++] = osdItemId["item_id"].AsUUID(); |
70 | } | 71 | } |
71 | 72 | ||
72 | InventoryItemBase[] items = m_inventoryService.GetMultipleItems(m_agentID, itemIDs); | 73 | InventoryItemBase[] items = null; |
73 | 74 | ||
74 | if (items == null) | 75 | if (m_agentID != UUID.Zero) |
76 | { | ||
77 | items = m_inventoryService.GetMultipleItems(m_agentID, itemIDs); | ||
78 | |||
79 | if (items == null) | ||
80 | { | ||
81 | // OMG!!! One by one!!! This is fallback code, in case the backend isn't updated | ||
82 | m_log.WarnFormat("[FETCH INVENTORY HANDLER]: GetMultipleItems failed. Falling back to fetching inventory items one by one."); | ||
83 | items = new InventoryItemBase[itemsRequested.Count]; | ||
84 | InventoryItemBase item = new InventoryItemBase(); | ||
85 | item.Owner = m_agentID; | ||
86 | foreach (UUID id in itemIDs) | ||
87 | { | ||
88 | item.ID = id; | ||
89 | items[i++] = m_inventoryService.GetItem(item); | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | else | ||
75 | { | 94 | { |
76 | // OMG!!! One by one!!! This is fallback code, in case the backend isn't updated | ||
77 | m_log.WarnFormat("[FETCH INVENTORY HANDLER]: GetMultipleItems failed. Falling back to fetching inventory items one by one."); | ||
78 | items = new InventoryItemBase[itemsRequested.Count]; | 95 | items = new InventoryItemBase[itemsRequested.Count]; |
79 | i = 0; | ||
80 | InventoryItemBase item = new InventoryItemBase(); | 96 | InventoryItemBase item = new InventoryItemBase(); |
81 | item.Owner = m_agentID; | ||
82 | foreach (UUID id in itemIDs) | 97 | foreach (UUID id in itemIDs) |
83 | { | 98 | { |
84 | item.ID = id; | 99 | item.ID = id; |
@@ -93,7 +108,6 @@ namespace OpenSim.Capabilities.Handlers | |||
93 | // We don't know the agent that this request belongs to so we'll use the agent id of the item | 108 | // We don't know the agent that this request belongs to so we'll use the agent id of the item |
94 | // which will be the same for all items. | 109 | // which will be the same for all items. |
95 | llsdReply.agent_id = item.Owner; | 110 | llsdReply.agent_id = item.Owner; |
96 | |||
97 | llsdReply.items.Array.Add(ConvertInventoryItem(item)); | 111 | llsdReply.items.Array.Add(ConvertInventoryItem(item)); |
98 | } | 112 | } |
99 | } | 113 | } |
@@ -114,7 +128,7 @@ namespace OpenSim.Capabilities.Handlers | |||
114 | llsdItem.asset_id = invItem.AssetID; | 128 | llsdItem.asset_id = invItem.AssetID; |
115 | llsdItem.created_at = invItem.CreationDate; | 129 | llsdItem.created_at = invItem.CreationDate; |
116 | llsdItem.desc = invItem.Description; | 130 | llsdItem.desc = invItem.Description; |
117 | llsdItem.flags = (int)invItem.Flags; | 131 | llsdItem.flags = ((int)invItem.Flags) & 0xff; |
118 | llsdItem.item_id = invItem.ID; | 132 | llsdItem.item_id = invItem.ID; |
119 | llsdItem.name = invItem.Name; | 133 | llsdItem.name = invItem.Name; |
120 | llsdItem.parent_id = invItem.Folder; | 134 | llsdItem.parent_id = invItem.Folder; |
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2ServerConnector.cs b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2ServerConnector.cs new file mode 100644 index 0000000..618f075 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2ServerConnector.cs | |||
@@ -0,0 +1,71 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | using OpenSim.Server.Handlers.Base; | ||
34 | using OpenMetaverse; | ||
35 | |||
36 | namespace OpenSim.Capabilities.Handlers | ||
37 | { | ||
38 | public class FetchInventory2ServerConnector : ServiceConnector | ||
39 | { | ||
40 | private IInventoryService m_InventoryService; | ||
41 | private string m_ConfigName = "CapsService"; | ||
42 | |||
43 | public FetchInventory2ServerConnector(IConfigSource config, IHttpServer server, string configName) | ||
44 | : base(config, server, configName) | ||
45 | { | ||
46 | if (configName != String.Empty) | ||
47 | m_ConfigName = configName; | ||
48 | |||
49 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
50 | if (serverConfig == null) | ||
51 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
52 | |||
53 | string invService = serverConfig.GetString("InventoryService", String.Empty); | ||
54 | |||
55 | if (invService == String.Empty) | ||
56 | throw new Exception("No InventoryService in config file"); | ||
57 | |||
58 | Object[] args = new Object[] { config }; | ||
59 | m_InventoryService = ServerUtils.LoadPlugin<IInventoryService>(invService, args); | ||
60 | |||
61 | if (m_InventoryService == null) | ||
62 | throw new Exception(String.Format("Failed to load InventoryService from {0}; config is {1}", invService, m_ConfigName)); | ||
63 | |||
64 | FetchInventory2Handler fiHandler = new FetchInventory2Handler(m_InventoryService, UUID.Zero); | ||
65 | IRequestHandler reqHandler | ||
66 | = new RestStreamHandler( | ||
67 | "POST", "/CAPS/FetchInventory/", fiHandler.FetchInventoryRequest, "FetchInventory", null); | ||
68 | server.AddStreamHandler(reqHandler); | ||
69 | } | ||
70 | } | ||
71 | } | ||
diff --git a/OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesHandler.cs b/OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesHandler.cs index 589602d..f7f9da9 100644 --- a/OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesHandler.cs | |||
@@ -65,7 +65,7 @@ namespace OpenSim.Capabilities.Handlers | |||
65 | 65 | ||
66 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 66 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) |
67 | { | 67 | { |
68 | m_log.DebugFormat("[GET_DISPLAY_NAMES]: called {0}", httpRequest.Url.Query); | 68 | // m_log.DebugFormat("[GET_DISPLAY_NAMES]: called {0}", httpRequest.Url.Query); |
69 | 69 | ||
70 | NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); | 70 | NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); |
71 | string[] ids = query.GetValues("ids"); | 71 | string[] ids = query.GetValues("ids"); |
@@ -92,8 +92,11 @@ namespace OpenSim.Capabilities.Handlers | |||
92 | { | 92 | { |
93 | string[] parts = name.Split(new char[] {' '}); | 93 | string[] parts = name.Split(new char[] {' '}); |
94 | OSDMap osdname = new OSDMap(); | 94 | OSDMap osdname = new OSDMap(); |
95 | osdname["display_name_next_update"] = OSD.FromDate(DateTime.MinValue); | 95 | // a date that is valid |
96 | osdname["display_name_expires"] = OSD.FromDate(DateTime.Now.AddMonths(1)); | 96 | // osdname["display_name_next_update"] = OSD.FromDate(new DateTime(1970,1,1)); |
97 | // but send one that blocks edition, since we actually don't suport this | ||
98 | osdname["display_name_next_update"] = OSD.FromDate(DateTime.UtcNow.AddDays(8)); | ||
99 | osdname["display_name_expires"] = OSD.FromDate(DateTime.UtcNow.AddMonths(1)); | ||
97 | osdname["display_name"] = OSD.FromString(name); | 100 | osdname["display_name"] = OSD.FromString(name); |
98 | osdname["legacy_first_name"] = parts[0]; | 101 | osdname["legacy_first_name"] = parts[0]; |
99 | osdname["legacy_last_name"] = parts[1]; | 102 | osdname["legacy_last_name"] = parts[1]; |
diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs index 6b67da1..a9b81f3 100644 --- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs | |||
@@ -25,224 +25,242 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Specialized; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Web; | ||
28 | using log4net; | 34 | using log4net; |
35 | using Nini.Config; | ||
29 | using OpenMetaverse; | 36 | using OpenMetaverse; |
30 | using OpenMetaverse.Imaging; | 37 | using OpenMetaverse.StructuredData; |
31 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
39 | using OpenSim.Framework.Servers; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | 40 | using OpenSim.Framework.Servers.HttpServer; |
33 | using OpenSim.Services.Interfaces; | 41 | using OpenSim.Services.Interfaces; |
34 | using System; | 42 | using Caps = OpenSim.Framework.Capabilities.Caps; |
35 | using System.Collections.Specialized; | 43 | |
36 | using System.Drawing; | 44 | |
37 | using System.Drawing.Imaging; | 45 | |
38 | using System.IO; | ||
39 | using System.Reflection; | ||
40 | using System.Web; | ||
41 | 46 | ||
42 | namespace OpenSim.Capabilities.Handlers | 47 | namespace OpenSim.Capabilities.Handlers |
43 | { | 48 | { |
44 | public class GetMeshHandler : BaseStreamHandler | 49 | public class GetMeshHandler |
45 | { | 50 | { |
46 | private static readonly ILog m_log = | 51 | private static readonly ILog m_log = |
47 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 52 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
53 | |||
48 | private IAssetService m_assetService; | 54 | private IAssetService m_assetService; |
49 | 55 | ||
50 | // TODO: Change this to a config option | 56 | public const string DefaultFormat = "vnd.ll.mesh"; |
51 | private string m_RedirectURL = null; | ||
52 | 57 | ||
53 | public GetMeshHandler(string path, IAssetService assService, string name, string description, string redirectURL) | 58 | public GetMeshHandler(IAssetService assService) |
54 | : base("GET", path, name, description) | ||
55 | { | 59 | { |
56 | m_assetService = assService; | 60 | m_assetService = assService; |
57 | m_RedirectURL = redirectURL; | ||
58 | if (m_RedirectURL != null && !m_RedirectURL.EndsWith("/")) | ||
59 | m_RedirectURL += "/"; | ||
60 | } | 61 | } |
61 | 62 | public Hashtable Handle(Hashtable request) | |
62 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
63 | { | 63 | { |
64 | // Try to parse the texture ID from the request URL | 64 | Hashtable ret = new Hashtable(); |
65 | NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); | 65 | ret["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound; |
66 | string textureStr = query.GetOne("mesh_id"); | 66 | ret["content_type"] = "text/plain"; |
67 | ret["keepalive"] = false; | ||
68 | ret["reusecontext"] = false; | ||
69 | ret["int_bytes"] = 0; | ||
70 | ret["int_lod"] = 0; | ||
71 | string MeshStr = (string)request["mesh_id"]; | ||
72 | |||
73 | |||
74 | //m_log.DebugFormat("[GETMESH]: called {0}", MeshStr); | ||
67 | 75 | ||
68 | if (m_assetService == null) | 76 | if (m_assetService == null) |
69 | { | 77 | { |
70 | m_log.Error("[GETMESH]: Cannot fetch mesh " + textureStr + " without an asset service"); | 78 | m_log.Error("[GETMESH]: Cannot fetch mesh " + MeshStr + " without an asset service"); |
71 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
72 | } | 79 | } |
73 | 80 | ||
74 | UUID meshID; | 81 | UUID meshID; |
75 | if (!String.IsNullOrEmpty(textureStr) && UUID.TryParse(textureStr, out meshID)) | 82 | if (!String.IsNullOrEmpty(MeshStr) && UUID.TryParse(MeshStr, out meshID)) |
76 | { | 83 | { |
77 | // OK, we have an array with preferred formats, possibly with only one entry | 84 | // m_log.DebugFormat("[GETMESH]: Received request for mesh id {0}", meshID); |
78 | |||
79 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
80 | AssetBase mesh; | ||
81 | |||
82 | if (!String.IsNullOrEmpty(m_RedirectURL)) | ||
83 | { | ||
84 | // Only try to fetch locally cached meshes. Misses are redirected | ||
85 | mesh = m_assetService.GetCached(meshID.ToString()); | ||
86 | 85 | ||
87 | if (mesh != null) | ||
88 | { | ||
89 | if (mesh.Type != (sbyte)AssetType.Mesh) | ||
90 | { | ||
91 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
92 | } | ||
93 | WriteMeshData(httpRequest, httpResponse, mesh); | ||
94 | } | ||
95 | else | ||
96 | { | ||
97 | string textureUrl = m_RedirectURL + "?mesh_id="+ meshID.ToString(); | ||
98 | m_log.Debug("[GETMESH]: Redirecting mesh request to " + textureUrl); | ||
99 | httpResponse.StatusCode = (int)OSHttpStatusCode.RedirectMovedPermanently; | ||
100 | httpResponse.RedirectLocation = textureUrl; | ||
101 | return null; | ||
102 | } | ||
103 | } | ||
104 | else // no redirect | ||
105 | { | ||
106 | // try the cache | ||
107 | mesh = m_assetService.GetCached(meshID.ToString()); | ||
108 | 86 | ||
109 | if (mesh == null) | 87 | ret = ProcessGetMesh(request, UUID.Zero, null); |
110 | { | ||
111 | // Fetch locally or remotely. Misses return a 404 | ||
112 | mesh = m_assetService.Get(meshID.ToString()); | ||
113 | 88 | ||
114 | if (mesh != null) | ||
115 | { | ||
116 | if (mesh.Type != (sbyte)AssetType.Mesh) | ||
117 | { | ||
118 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
119 | return null; | ||
120 | } | ||
121 | WriteMeshData(httpRequest, httpResponse, mesh); | ||
122 | return null; | ||
123 | } | ||
124 | } | ||
125 | else // it was on the cache | ||
126 | { | ||
127 | if (mesh.Type != (sbyte)AssetType.Mesh) | ||
128 | { | ||
129 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
130 | return null; | ||
131 | } | ||
132 | WriteMeshData(httpRequest, httpResponse, mesh); | ||
133 | return null; | ||
134 | } | ||
135 | } | ||
136 | 89 | ||
137 | // not found | ||
138 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
139 | return null; | ||
140 | } | 90 | } |
141 | else | 91 | else |
142 | { | 92 | { |
143 | m_log.Warn("[GETTEXTURE]: Failed to parse a mesh_id from GetMesh request: " + httpRequest.Url); | 93 | m_log.Warn("[GETMESH]: Failed to parse a mesh_id from GetMesh request: " + (string)request["uri"]); |
144 | } | 94 | } |
145 | 95 | ||
146 | return null; | ||
147 | } | ||
148 | 96 | ||
149 | private void WriteMeshData(IOSHttpRequest request, IOSHttpResponse response, AssetBase texture) | 97 | return ret; |
98 | } | ||
99 | public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap) | ||
150 | { | 100 | { |
151 | string range = request.Headers.GetOne("Range"); | 101 | Hashtable responsedata = new Hashtable(); |
102 | responsedata["int_response_code"] = 400; //501; //410; //404; | ||
103 | responsedata["content_type"] = "text/plain"; | ||
104 | responsedata["keepalive"] = false; | ||
105 | responsedata["str_response_string"] = "Request wasn't what was expected"; | ||
106 | responsedata["reusecontext"] = false; | ||
107 | responsedata["int_lod"] = 0; | ||
108 | responsedata["int_bytes"] = 0; | ||
109 | |||
110 | string meshStr = string.Empty; | ||
152 | 111 | ||
153 | if (!String.IsNullOrEmpty(range)) | 112 | if (request.ContainsKey("mesh_id")) |
113 | meshStr = request["mesh_id"].ToString(); | ||
114 | |||
115 | UUID meshID = UUID.Zero; | ||
116 | if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID)) | ||
154 | { | 117 | { |
155 | // Range request | 118 | if (m_assetService == null) |
156 | int start, end; | ||
157 | if (TryParseRange(range, out start, out end)) | ||
158 | { | 119 | { |
159 | // Before clamping start make sure we can satisfy it in order to avoid | 120 | responsedata["int_response_code"] = 404; //501; //410; //404; |
160 | // sending back the last byte instead of an error status | 121 | responsedata["content_type"] = "text/plain"; |
161 | if (start >= texture.Data.Length) | 122 | responsedata["keepalive"] = false; |
162 | { | 123 | responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh."; |
163 | response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; | 124 | responsedata["reusecontext"] = false; |
164 | response.ContentType = texture.Metadata.ContentType; | 125 | return responsedata; |
165 | } | 126 | } |
166 | else | 127 | |
128 | AssetBase mesh = m_assetService.Get(meshID.ToString()); | ||
129 | |||
130 | if (mesh != null) | ||
131 | { | ||
132 | if (mesh.Type == (SByte)AssetType.Mesh) | ||
167 | { | 133 | { |
168 | // Handle the case where no second range value was given. This is equivalent to requesting | ||
169 | // the rest of the entity. | ||
170 | if (end == -1) | ||
171 | end = int.MaxValue; | ||
172 | 134 | ||
173 | end = Utils.Clamp(end, 0, texture.Data.Length - 1); | 135 | Hashtable headers = new Hashtable(); |
174 | start = Utils.Clamp(start, 0, end); | 136 | responsedata["headers"] = headers; |
175 | int len = end - start + 1; | 137 | |
138 | string range = String.Empty; | ||
139 | |||
140 | if (((Hashtable)request["headers"])["range"] != null) | ||
141 | range = (string)((Hashtable)request["headers"])["range"]; | ||
176 | 142 | ||
177 | if (0 == start && len == texture.Data.Length) | 143 | else if (((Hashtable)request["headers"])["Range"] != null) |
144 | range = (string)((Hashtable)request["headers"])["Range"]; | ||
145 | |||
146 | if (!String.IsNullOrEmpty(range)) // Mesh Asset LOD // Physics | ||
178 | { | 147 | { |
179 | response.StatusCode = (int)System.Net.HttpStatusCode.OK; | 148 | // Range request |
149 | int start, end; | ||
150 | if (TryParseRange(range, out start, out end)) | ||
151 | { | ||
152 | // Before clamping start make sure we can satisfy it in order to avoid | ||
153 | // sending back the last byte instead of an error status | ||
154 | if (start >= mesh.Data.Length) | ||
155 | { | ||
156 | responsedata["int_response_code"] = 404; //501; //410; //404; | ||
157 | responsedata["content_type"] = "text/plain"; | ||
158 | responsedata["keepalive"] = false; | ||
159 | responsedata["str_response_string"] = "This range doesnt exist."; | ||
160 | responsedata["reusecontext"] = false; | ||
161 | responsedata["int_lod"] = 3; | ||
162 | return responsedata; | ||
163 | } | ||
164 | else | ||
165 | { | ||
166 | end = Utils.Clamp(end, 0, mesh.Data.Length - 1); | ||
167 | start = Utils.Clamp(start, 0, end); | ||
168 | int len = end - start + 1; | ||
169 | |||
170 | //m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); | ||
171 | |||
172 | if (start > 20000) | ||
173 | { | ||
174 | responsedata["int_lod"] = 3; | ||
175 | } | ||
176 | else if (start < 4097) | ||
177 | { | ||
178 | responsedata["int_lod"] = 1; | ||
179 | } | ||
180 | else | ||
181 | { | ||
182 | responsedata["int_lod"] = 2; | ||
183 | } | ||
184 | |||
185 | |||
186 | if (start == 0 && len == mesh.Data.Length) // well redudante maybe | ||
187 | { | ||
188 | responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK; | ||
189 | responsedata["bin_response_data"] = mesh.Data; | ||
190 | responsedata["int_bytes"] = mesh.Data.Length; | ||
191 | responsedata["reusecontext"] = false; | ||
192 | responsedata["int_lod"] = 3; | ||
193 | |||
194 | } | ||
195 | else | ||
196 | { | ||
197 | responsedata["int_response_code"] = | ||
198 | (int)System.Net.HttpStatusCode.PartialContent; | ||
199 | headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, | ||
200 | mesh.Data.Length); | ||
201 | |||
202 | byte[] d = new byte[len]; | ||
203 | Array.Copy(mesh.Data, start, d, 0, len); | ||
204 | responsedata["bin_response_data"] = d; | ||
205 | responsedata["int_bytes"] = len; | ||
206 | responsedata["reusecontext"] = false; | ||
207 | } | ||
208 | } | ||
209 | } | ||
210 | else | ||
211 | { | ||
212 | m_log.Warn("[GETMESH]: Failed to parse a range from GetMesh request, sending full asset: " + (string)request["uri"]); | ||
213 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | ||
214 | responsedata["content_type"] = "application/vnd.ll.mesh"; | ||
215 | responsedata["int_response_code"] = 200; | ||
216 | responsedata["reusecontext"] = false; | ||
217 | responsedata["int_lod"] = 3; | ||
218 | } | ||
180 | } | 219 | } |
181 | else | 220 | else |
182 | { | 221 | { |
183 | response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; | 222 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); |
184 | response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length)); | 223 | responsedata["content_type"] = "application/vnd.ll.mesh"; |
224 | responsedata["int_response_code"] = 200; | ||
225 | responsedata["reusecontext"] = false; | ||
226 | responsedata["int_lod"] = 3; | ||
185 | } | 227 | } |
186 | 228 | } | |
187 | response.ContentLength = len; | 229 | // Optionally add additional mesh types here |
188 | response.ContentType = "application/vnd.ll.mesh"; | 230 | else |
189 | 231 | { | |
190 | response.Body.Write(texture.Data, start, len); | 232 | responsedata["int_response_code"] = 404; //501; //410; //404; |
233 | responsedata["content_type"] = "text/plain"; | ||
234 | responsedata["keepalive"] = false; | ||
235 | responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; | ||
236 | responsedata["reusecontext"] = false; | ||
237 | responsedata["int_lod"] = 1; | ||
238 | return responsedata; | ||
191 | } | 239 | } |
192 | } | 240 | } |
193 | else | 241 | else |
194 | { | 242 | { |
195 | m_log.Warn("[GETMESH]: Malformed Range header: " + range); | 243 | responsedata["int_response_code"] = 404; //501; //410; //404; |
196 | response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; | 244 | responsedata["content_type"] = "text/plain"; |
245 | responsedata["keepalive"] = false; | ||
246 | responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; | ||
247 | responsedata["reusecontext"] = false; | ||
248 | responsedata["int_lod"] = 0; | ||
249 | return responsedata; | ||
197 | } | 250 | } |
198 | } | 251 | } |
199 | else | ||
200 | { | ||
201 | // Full content request | ||
202 | response.StatusCode = (int)System.Net.HttpStatusCode.OK; | ||
203 | response.ContentLength = texture.Data.Length; | ||
204 | response.ContentType = "application/vnd.ll.mesh"; | ||
205 | response.Body.Write(texture.Data, 0, texture.Data.Length); | ||
206 | } | ||
207 | } | ||
208 | 252 | ||
209 | /// <summary> | 253 | return responsedata; |
210 | /// Parse a range header. | 254 | } |
211 | /// </summary> | ||
212 | /// <remarks> | ||
213 | /// As per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, | ||
214 | /// this obeys range headers with two values (e.g. 533-4165) and no second value (e.g. 533-). | ||
215 | /// Where there is no value, -1 is returned. | ||
216 | /// FIXME: Need to cover the case where only a second value is specified (e.g. -4165), probably by returning -1 | ||
217 | /// for start.</remarks> | ||
218 | /// <returns></returns> | ||
219 | /// <param name='header'></param> | ||
220 | /// <param name='start'>Start of the range. Undefined if this was not a number.</param> | ||
221 | /// <param name='end'>End of the range. Will be -1 if no end specified. Undefined if there was a raw string but this was not a number.</param> | ||
222 | private bool TryParseRange(string header, out int start, out int end) | 255 | private bool TryParseRange(string header, out int start, out int end) |
223 | { | 256 | { |
224 | start = end = 0; | ||
225 | |||
226 | if (header.StartsWith("bytes=")) | 257 | if (header.StartsWith("bytes=")) |
227 | { | 258 | { |
228 | string[] rangeValues = header.Substring(6).Split('-'); | 259 | string[] rangeValues = header.Substring(6).Split('-'); |
229 | |||
230 | if (rangeValues.Length == 2) | 260 | if (rangeValues.Length == 2) |
231 | { | 261 | { |
232 | if (!Int32.TryParse(rangeValues[0], out start)) | 262 | if (Int32.TryParse(rangeValues[0], out start) && Int32.TryParse(rangeValues[1], out end)) |
233 | return false; | ||
234 | |||
235 | string rawEnd = rangeValues[1]; | ||
236 | |||
237 | if (rawEnd == "") | ||
238 | { | ||
239 | end = -1; | ||
240 | return true; | 263 | return true; |
241 | } | ||
242 | else if (Int32.TryParse(rawEnd, out end)) | ||
243 | { | ||
244 | return true; | ||
245 | } | ||
246 | } | 264 | } |
247 | } | 265 | } |
248 | 266 | ||
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 | |||
64 | 64 | ||
65 | string rurl = serverConfig.GetString("GetMeshRedirectURL"); | 65 | string rurl = serverConfig.GetString("GetMeshRedirectURL"); |
66 | 66 | ||
67 | server.AddStreamHandler( | 67 | GetMeshHandler gmeshHandler = new GetMeshHandler(m_AssetService); |
68 | new GetTextureHandler("/CAPS/GetMesh/" /*+ UUID.Random() */, m_AssetService, "GetMesh", null, rurl)); | 68 | IRequestHandler reqHandler |
69 | 69 | = new RestHTTPHandler( | |
70 | rurl = serverConfig.GetString("GetMesh2RedirectURL"); | 70 | "GET", |
71 | 71 | "/CAPS/" + UUID.Random(), | |
72 | server.AddStreamHandler( | 72 | httpMethod => gmeshHandler.ProcessGetMesh(httpMethod, UUID.Zero, null), |
73 | new GetTextureHandler("/CAPS/GetMesh2/" /*+ UUID.Random() */, m_AssetService, "GetMesh2", null, rurl)); | 73 | "GetMesh", |
74 | null); | ||
75 | server.AddStreamHandler(reqHandler); ; | ||
74 | } | 76 | } |
75 | } | 77 | } |
76 | } \ No newline at end of file | 78 | } \ No newline at end of file |
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs index 828e943..59d8b9a 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs | |||
@@ -47,10 +47,11 @@ using Caps = OpenSim.Framework.Capabilities.Caps; | |||
47 | 47 | ||
48 | namespace OpenSim.Capabilities.Handlers | 48 | namespace OpenSim.Capabilities.Handlers |
49 | { | 49 | { |
50 | public class GetTextureHandler : BaseStreamHandler | 50 | public class GetTextureHandler |
51 | { | 51 | { |
52 | private static readonly ILog m_log = | 52 | private static readonly ILog m_log = |
53 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 53 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
54 | |||
54 | private IAssetService m_assetService; | 55 | private IAssetService m_assetService; |
55 | 56 | ||
56 | public const string DefaultFormat = "x-j2c"; | 57 | public const string DefaultFormat = "x-j2c"; |
@@ -58,28 +59,28 @@ namespace OpenSim.Capabilities.Handlers | |||
58 | // TODO: Change this to a config option | 59 | // TODO: Change this to a config option |
59 | private string m_RedirectURL = null; | 60 | private string m_RedirectURL = null; |
60 | 61 | ||
61 | public GetTextureHandler(string path, IAssetService assService, string name, string description, string redirectURL) | 62 | |
62 | : base("GET", path, name, description) | 63 | public GetTextureHandler(IAssetService assService) |
63 | { | 64 | { |
64 | m_assetService = assService; | 65 | m_assetService = assService; |
65 | m_RedirectURL = redirectURL; | ||
66 | if (m_RedirectURL != null && !m_RedirectURL.EndsWith("/")) | ||
67 | m_RedirectURL += "/"; | ||
68 | } | 66 | } |
69 | 67 | ||
70 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 68 | public Hashtable Handle(Hashtable request) |
71 | { | 69 | { |
72 | // Try to parse the texture ID from the request URL | 70 | Hashtable ret = new Hashtable(); |
73 | NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); | 71 | ret["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound; |
74 | string textureStr = query.GetOne("texture_id"); | 72 | ret["content_type"] = "text/plain"; |
75 | string format = query.GetOne("format"); | 73 | ret["keepalive"] = false; |
74 | ret["reusecontext"] = false; | ||
75 | ret["int_bytes"] = 0; | ||
76 | string textureStr = (string)request["texture_id"]; | ||
77 | string format = (string)request["format"]; | ||
76 | 78 | ||
77 | //m_log.DebugFormat("[GETTEXTURE]: called {0}", textureStr); | 79 | //m_log.DebugFormat("[GETTEXTURE]: called {0}", textureStr); |
78 | 80 | ||
79 | if (m_assetService == null) | 81 | if (m_assetService == null) |
80 | { | 82 | { |
81 | m_log.Error("[GETTEXTURE]: Cannot fetch texture " + textureStr + " without an asset service"); | 83 | m_log.Error("[GETTEXTURE]: Cannot fetch texture " + textureStr + " without an asset service"); |
82 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
83 | } | 84 | } |
84 | 85 | ||
85 | UUID textureID; | 86 | UUID textureID; |
@@ -94,30 +95,41 @@ namespace OpenSim.Capabilities.Handlers | |||
94 | } | 95 | } |
95 | else | 96 | else |
96 | { | 97 | { |
97 | formats = WebUtil.GetPreferredImageTypes(httpRequest.Headers.Get("Accept")); | 98 | formats = new string[1] { DefaultFormat }; // default |
99 | if (((Hashtable)request["headers"])["Accept"] != null) | ||
100 | formats = WebUtil.GetPreferredImageTypes((string)((Hashtable)request["headers"])["Accept"]); | ||
98 | if (formats.Length == 0) | 101 | if (formats.Length == 0) |
99 | formats = new string[1] { DefaultFormat }; // default | 102 | formats = new string[1] { DefaultFormat }; // default |
100 | 103 | ||
101 | } | 104 | } |
102 | // OK, we have an array with preferred formats, possibly with only one entry | 105 | // OK, we have an array with preferred formats, possibly with only one entry |
103 | 106 | bool foundtexture = false; | |
104 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
105 | foreach (string f in formats) | 107 | foreach (string f in formats) |
106 | { | 108 | { |
107 | if (FetchTexture(httpRequest, httpResponse, textureID, f)) | 109 | foundtexture = FetchTexture(request, ret, textureID, f); |
110 | if (foundtexture) | ||
108 | break; | 111 | break; |
109 | } | 112 | } |
113 | if (!foundtexture) | ||
114 | { | ||
115 | ret["int_response_code"] = 404; | ||
116 | ret["error_status_text"] = "not found"; | ||
117 | ret["str_response_string"] = "not found"; | ||
118 | ret["content_type"] = "text/plain"; | ||
119 | ret["keepalive"] = false; | ||
120 | ret["reusecontext"] = false; | ||
121 | ret["int_bytes"] = 0; | ||
122 | } | ||
110 | } | 123 | } |
111 | else | 124 | else |
112 | { | 125 | { |
113 | m_log.Warn("[GETTEXTURE]: Failed to parse a texture_id from GetTexture request: " + httpRequest.Url); | 126 | m_log.Warn("[GETTEXTURE]: Failed to parse a texture_id from GetTexture request: " + (string)request["uri"]); |
114 | } | 127 | } |
115 | 128 | ||
116 | // m_log.DebugFormat( | 129 | // m_log.DebugFormat( |
117 | // "[GETTEXTURE]: For texture {0} sending back response {1}, data length {2}", | 130 | // "[GETTEXTURE]: For texture {0} sending back response {1}, data length {2}", |
118 | // textureID, httpResponse.StatusCode, httpResponse.ContentLength); | 131 | // textureID, httpResponse.StatusCode, httpResponse.ContentLength); |
119 | 132 | return ret; | |
120 | return null; | ||
121 | } | 133 | } |
122 | 134 | ||
123 | /// <summary> | 135 | /// <summary> |
@@ -128,7 +140,7 @@ namespace OpenSim.Capabilities.Handlers | |||
128 | /// <param name="textureID"></param> | 140 | /// <param name="textureID"></param> |
129 | /// <param name="format"></param> | 141 | /// <param name="format"></param> |
130 | /// <returns>False for "caller try another codec"; true otherwise</returns> | 142 | /// <returns>False for "caller try another codec"; true otherwise</returns> |
131 | private bool FetchTexture(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID textureID, string format) | 143 | private bool FetchTexture(Hashtable request, Hashtable response, UUID textureID, string format) |
132 | { | 144 | { |
133 | // m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format); | 145 | // m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format); |
134 | AssetBase texture; | 146 | AssetBase texture; |
@@ -137,86 +149,70 @@ namespace OpenSim.Capabilities.Handlers | |||
137 | if (format != DefaultFormat) | 149 | if (format != DefaultFormat) |
138 | fullID = fullID + "-" + format; | 150 | fullID = fullID + "-" + format; |
139 | 151 | ||
140 | if (!String.IsNullOrEmpty(m_RedirectURL)) | 152 | // try the cache |
153 | texture = m_assetService.GetCached(fullID); | ||
154 | |||
155 | if (texture == null) | ||
141 | { | 156 | { |
142 | // Only try to fetch locally cached textures. Misses are redirected | 157 | //m_log.DebugFormat("[GETTEXTURE]: texture was not in the cache"); |
143 | texture = m_assetService.GetCached(fullID); | 158 | |
159 | // Fetch locally or remotely. Misses return a 404 | ||
160 | texture = m_assetService.Get(textureID.ToString()); | ||
144 | 161 | ||
145 | if (texture != null) | 162 | if (texture != null) |
146 | { | 163 | { |
147 | if (texture.Type != (sbyte)AssetType.Texture) | 164 | if (texture.Type != (sbyte)AssetType.Texture) |
165 | return true; | ||
166 | |||
167 | if (format == DefaultFormat) | ||
148 | { | 168 | { |
149 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | 169 | WriteTextureData(request, response, texture, format); |
150 | return true; | 170 | return true; |
151 | } | 171 | } |
152 | WriteTextureData(httpRequest, httpResponse, texture, format); | 172 | else |
153 | } | ||
154 | else | ||
155 | { | ||
156 | string textureUrl = m_RedirectURL + "?texture_id="+ textureID.ToString(); | ||
157 | m_log.Debug("[GETTEXTURE]: Redirecting texture request to " + textureUrl); | ||
158 | httpResponse.StatusCode = (int)OSHttpStatusCode.RedirectMovedPermanently; | ||
159 | httpResponse.RedirectLocation = textureUrl; | ||
160 | return true; | ||
161 | } | ||
162 | } | ||
163 | else // no redirect | ||
164 | { | ||
165 | // try the cache | ||
166 | texture = m_assetService.GetCached(fullID); | ||
167 | |||
168 | if (texture == null) | ||
169 | { | ||
170 | // m_log.DebugFormat("[GETTEXTURE]: texture was not in the cache"); | ||
171 | |||
172 | // Fetch locally or remotely. Misses return a 404 | ||
173 | texture = m_assetService.Get(textureID.ToString()); | ||
174 | |||
175 | if (texture != null) | ||
176 | { | 173 | { |
177 | if (texture.Type != (sbyte)AssetType.Texture) | 174 | AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID); |
178 | { | 175 | newTexture.Data = ConvertTextureData(texture, format); |
179 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | 176 | if (newTexture.Data.Length == 0) |
180 | return true; | 177 | return false; // !!! Caller try another codec, please! |
181 | } | 178 | |
182 | if (format == DefaultFormat) | 179 | newTexture.Flags = AssetFlags.Collectable; |
183 | { | 180 | newTexture.Temporary = true; |
184 | WriteTextureData(httpRequest, httpResponse, texture, format); | 181 | newTexture.Local = true; |
185 | return true; | 182 | m_assetService.Store(newTexture); |
186 | } | 183 | WriteTextureData(request, response, newTexture, format); |
187 | else | 184 | return true; |
188 | { | ||
189 | AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID); | ||
190 | newTexture.Data = ConvertTextureData(texture, format); | ||
191 | if (newTexture.Data.Length == 0) | ||
192 | return false; // !!! Caller try another codec, please! | ||
193 | |||
194 | newTexture.Flags = AssetFlags.Collectable; | ||
195 | newTexture.Temporary = true; | ||
196 | newTexture.Local = true; | ||
197 | m_assetService.Store(newTexture); | ||
198 | WriteTextureData(httpRequest, httpResponse, newTexture, format); | ||
199 | return true; | ||
200 | } | ||
201 | } | 185 | } |
202 | } | 186 | } |
203 | else // it was on the cache | 187 | } |
204 | { | 188 | else // it was on the cache |
205 | // m_log.DebugFormat("[GETTEXTURE]: texture was in the cache"); | 189 | { |
206 | WriteTextureData(httpRequest, httpResponse, texture, format); | 190 | //m_log.DebugFormat("[GETTEXTURE]: texture was in the cache"); |
207 | return true; | 191 | WriteTextureData(request, response, texture, format); |
208 | } | 192 | return true; |
209 | } | 193 | } |
210 | 194 | ||
195 | //response = new Hashtable(); | ||
196 | |||
197 | |||
198 | //WriteTextureData(request,response,null,format); | ||
211 | // not found | 199 | // not found |
212 | // m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found"); | 200 | //m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found"); |
213 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | 201 | return false; |
214 | return true; | ||
215 | } | 202 | } |
216 | 203 | ||
217 | private void WriteTextureData(IOSHttpRequest request, IOSHttpResponse response, AssetBase texture, string format) | 204 | private void WriteTextureData(Hashtable request, Hashtable response, AssetBase texture, string format) |
218 | { | 205 | { |
219 | string range = request.Headers.GetOne("Range"); | 206 | Hashtable headers = new Hashtable(); |
207 | response["headers"] = headers; | ||
208 | |||
209 | string range = String.Empty; | ||
210 | |||
211 | if (((Hashtable)request["headers"])["range"] != null) | ||
212 | range = (string)((Hashtable)request["headers"])["range"]; | ||
213 | |||
214 | else if (((Hashtable)request["headers"])["Range"] != null) | ||
215 | range = (string)((Hashtable)request["headers"])["Range"]; | ||
220 | 216 | ||
221 | if (!String.IsNullOrEmpty(range)) // JP2's only | 217 | if (!String.IsNullOrEmpty(range)) // JP2's only |
222 | { | 218 | { |
@@ -244,10 +240,8 @@ namespace OpenSim.Capabilities.Handlers | |||
244 | // However, if we return PartialContent (or OK) instead, the viewer will display that resolution. | 240 | // However, if we return PartialContent (or OK) instead, the viewer will display that resolution. |
245 | 241 | ||
246 | // response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable; | 242 | // response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable; |
247 | // response.AddHeader("Content-Range", String.Format("bytes */{0}", texture.Data.Length)); | 243 | // viewers don't seem to handle RequestedRangeNotSatisfiable and keep retrying with same parameters |
248 | // response.StatusCode = (int)System.Net.HttpStatusCode.OK; | 244 | response["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound; |
249 | response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; | ||
250 | response.ContentType = texture.Metadata.ContentType; | ||
251 | } | 245 | } |
252 | else | 246 | else |
253 | { | 247 | { |
@@ -262,41 +256,46 @@ namespace OpenSim.Capabilities.Handlers | |||
262 | 256 | ||
263 | // m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); | 257 | // m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); |
264 | 258 | ||
265 | // Always return PartialContent, even if the range covered the entire data length | 259 | response["content-type"] = texture.Metadata.ContentType; |
266 | // We were accidentally sending back 404 before in this situation | 260 | |
267 | // https://issues.apache.org/bugzilla/show_bug.cgi?id=51878 supports sending 206 even if the | 261 | if (start == 0 && len == texture.Data.Length) // well redudante maybe |
268 | // entire range is requested, and viewer 3.2.2 (and very probably earlier) seems fine with this. | 262 | { |
269 | // | 263 | response["int_response_code"] = (int)System.Net.HttpStatusCode.OK; |
270 | // We also do not want to send back OK even if the whole range was satisfiable since this causes | 264 | response["bin_response_data"] = texture.Data; |
271 | // HTTP textures on at least Imprudence 1.4.0-beta2 to never display the final texture quality. | 265 | response["int_bytes"] = texture.Data.Length; |
272 | // if (end > maxEnd) | 266 | } |
273 | // response.StatusCode = (int)System.Net.HttpStatusCode.OK; | 267 | else |
274 | // else | 268 | { |
275 | response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; | 269 | response["int_response_code"] = (int)System.Net.HttpStatusCode.PartialContent; |
276 | 270 | headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length); | |
277 | response.ContentLength = len; | 271 | |
278 | response.ContentType = texture.Metadata.ContentType; | 272 | byte[] d = new byte[len]; |
279 | response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length)); | 273 | Array.Copy(texture.Data, start, d, 0, len); |
280 | 274 | response["bin_response_data"] = d; | |
281 | response.Body.Write(texture.Data, start, len); | 275 | response["int_bytes"] = len; |
276 | } | ||
277 | // response.Body.Write(texture.Data, start, len); | ||
282 | } | 278 | } |
283 | } | 279 | } |
284 | else | 280 | else |
285 | { | 281 | { |
286 | m_log.Warn("[GETTEXTURE]: Malformed Range header: " + range); | 282 | m_log.Warn("[GETTEXTURE]: Malformed Range header: " + range); |
287 | response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; | 283 | response["int_response_code"] = (int)System.Net.HttpStatusCode.BadRequest; |
288 | } | 284 | } |
289 | } | 285 | } |
290 | else // JP2's or other formats | 286 | else // JP2's or other formats |
291 | { | 287 | { |
292 | // Full content request | 288 | // Full content request |
293 | response.StatusCode = (int)System.Net.HttpStatusCode.OK; | 289 | response["int_response_code"] = (int)System.Net.HttpStatusCode.OK; |
294 | response.ContentLength = texture.Data.Length; | ||
295 | if (format == DefaultFormat) | 290 | if (format == DefaultFormat) |
296 | response.ContentType = texture.Metadata.ContentType; | 291 | response["content_type"] = texture.Metadata.ContentType; |
297 | else | 292 | else |
298 | response.ContentType = "image/" + format; | 293 | response["content_type"] = "image/" + format; |
299 | response.Body.Write(texture.Data, 0, texture.Data.Length); | 294 | |
295 | response["bin_response_data"] = texture.Data; | ||
296 | response["int_bytes"] = texture.Data.Length; | ||
297 | |||
298 | // response.Body.Write(texture.Data, 0, texture.Data.Length); | ||
300 | } | 299 | } |
301 | 300 | ||
302 | // if (response.StatusCode < 200 || response.StatusCode > 299) | 301 | // if (response.StatusCode < 200 || response.StatusCode > 299) |
@@ -428,4 +427,4 @@ namespace OpenSim.Capabilities.Handlers | |||
428 | return null; | 427 | return null; |
429 | } | 428 | } |
430 | } | 429 | } |
431 | } \ No newline at end of file | 430 | } |
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureRobustHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureRobustHandler.cs new file mode 100644 index 0000000..f813471 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureRobustHandler.cs | |||
@@ -0,0 +1,431 @@ | |||
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.Specialized; | ||
31 | using System.Drawing; | ||
32 | using System.Drawing.Imaging; | ||
33 | using System.Reflection; | ||
34 | using System.IO; | ||
35 | using System.Web; | ||
36 | using log4net; | ||
37 | using Nini.Config; | ||
38 | using OpenMetaverse; | ||
39 | using OpenMetaverse.StructuredData; | ||
40 | using OpenMetaverse.Imaging; | ||
41 | using OpenSim.Framework; | ||
42 | using OpenSim.Framework.Servers; | ||
43 | using OpenSim.Framework.Servers.HttpServer; | ||
44 | using OpenSim.Region.Framework.Interfaces; | ||
45 | using OpenSim.Services.Interfaces; | ||
46 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
47 | |||
48 | namespace OpenSim.Capabilities.Handlers | ||
49 | { | ||
50 | public class GetTextureRobustHandler : BaseStreamHandler | ||
51 | { | ||
52 | private static readonly ILog m_log = | ||
53 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | private IAssetService m_assetService; | ||
55 | |||
56 | public const string DefaultFormat = "x-j2c"; | ||
57 | |||
58 | // TODO: Change this to a config option | ||
59 | private string m_RedirectURL = null; | ||
60 | |||
61 | public GetTextureRobustHandler(string path, IAssetService assService, string name, string description, string redirectURL) | ||
62 | : base("GET", path, name, description) | ||
63 | { | ||
64 | m_assetService = assService; | ||
65 | m_RedirectURL = redirectURL; | ||
66 | if (m_RedirectURL != null && !m_RedirectURL.EndsWith("/")) | ||
67 | m_RedirectURL += "/"; | ||
68 | } | ||
69 | |||
70 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
71 | { | ||
72 | // Try to parse the texture ID from the request URL | ||
73 | NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); | ||
74 | string textureStr = query.GetOne("texture_id"); | ||
75 | string format = query.GetOne("format"); | ||
76 | |||
77 | //m_log.DebugFormat("[GETTEXTURE]: called {0}", textureStr); | ||
78 | |||
79 | if (m_assetService == null) | ||
80 | { | ||
81 | m_log.Error("[GETTEXTURE]: Cannot fetch texture " + textureStr + " without an asset service"); | ||
82 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
83 | } | ||
84 | |||
85 | UUID textureID; | ||
86 | if (!String.IsNullOrEmpty(textureStr) && UUID.TryParse(textureStr, out textureID)) | ||
87 | { | ||
88 | // m_log.DebugFormat("[GETTEXTURE]: Received request for texture id {0}", textureID); | ||
89 | |||
90 | string[] formats; | ||
91 | if (!string.IsNullOrEmpty(format)) | ||
92 | { | ||
93 | formats = new string[1] { format.ToLower() }; | ||
94 | } | ||
95 | else | ||
96 | { | ||
97 | formats = WebUtil.GetPreferredImageTypes(httpRequest.Headers.Get("Accept")); | ||
98 | if (formats.Length == 0) | ||
99 | formats = new string[1] { DefaultFormat }; // default | ||
100 | |||
101 | } | ||
102 | // OK, we have an array with preferred formats, possibly with only one entry | ||
103 | |||
104 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
105 | foreach (string f in formats) | ||
106 | { | ||
107 | if (FetchTexture(httpRequest, httpResponse, textureID, f)) | ||
108 | break; | ||
109 | } | ||
110 | } | ||
111 | else | ||
112 | { | ||
113 | m_log.Warn("[GETTEXTURE]: Failed to parse a texture_id from GetTexture request: " + httpRequest.Url); | ||
114 | } | ||
115 | |||
116 | // m_log.DebugFormat( | ||
117 | // "[GETTEXTURE]: For texture {0} sending back response {1}, data length {2}", | ||
118 | // textureID, httpResponse.StatusCode, httpResponse.ContentLength); | ||
119 | |||
120 | return null; | ||
121 | } | ||
122 | |||
123 | /// <summary> | ||
124 | /// | ||
125 | /// </summary> | ||
126 | /// <param name="httpRequest"></param> | ||
127 | /// <param name="httpResponse"></param> | ||
128 | /// <param name="textureID"></param> | ||
129 | /// <param name="format"></param> | ||
130 | /// <returns>False for "caller try another codec"; true otherwise</returns> | ||
131 | private bool FetchTexture(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID textureID, string format) | ||
132 | { | ||
133 | // m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format); | ||
134 | AssetBase texture; | ||
135 | |||
136 | string fullID = textureID.ToString(); | ||
137 | if (format != DefaultFormat) | ||
138 | fullID = fullID + "-" + format; | ||
139 | |||
140 | if (!String.IsNullOrEmpty(m_RedirectURL)) | ||
141 | { | ||
142 | // Only try to fetch locally cached textures. Misses are redirected | ||
143 | texture = m_assetService.GetCached(fullID); | ||
144 | |||
145 | if (texture != null) | ||
146 | { | ||
147 | if (texture.Type != (sbyte)AssetType.Texture) | ||
148 | { | ||
149 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
150 | return true; | ||
151 | } | ||
152 | WriteTextureData(httpRequest, httpResponse, texture, format); | ||
153 | } | ||
154 | else | ||
155 | { | ||
156 | string textureUrl = m_RedirectURL + "?texture_id="+ textureID.ToString(); | ||
157 | m_log.Debug("[GETTEXTURE]: Redirecting texture request to " + textureUrl); | ||
158 | httpResponse.StatusCode = (int)OSHttpStatusCode.RedirectMovedPermanently; | ||
159 | httpResponse.RedirectLocation = textureUrl; | ||
160 | return true; | ||
161 | } | ||
162 | } | ||
163 | else // no redirect | ||
164 | { | ||
165 | // try the cache | ||
166 | texture = m_assetService.GetCached(fullID); | ||
167 | |||
168 | if (texture == null) | ||
169 | { | ||
170 | // m_log.DebugFormat("[GETTEXTURE]: texture was not in the cache"); | ||
171 | |||
172 | // Fetch locally or remotely. Misses return a 404 | ||
173 | texture = m_assetService.Get(textureID.ToString()); | ||
174 | |||
175 | if (texture != null) | ||
176 | { | ||
177 | if (texture.Type != (sbyte)AssetType.Texture) | ||
178 | { | ||
179 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
180 | return true; | ||
181 | } | ||
182 | if (format == DefaultFormat) | ||
183 | { | ||
184 | WriteTextureData(httpRequest, httpResponse, texture, format); | ||
185 | return true; | ||
186 | } | ||
187 | else | ||
188 | { | ||
189 | AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID); | ||
190 | newTexture.Data = ConvertTextureData(texture, format); | ||
191 | if (newTexture.Data.Length == 0) | ||
192 | return false; // !!! Caller try another codec, please! | ||
193 | |||
194 | newTexture.Flags = AssetFlags.Collectable; | ||
195 | newTexture.Temporary = true; | ||
196 | newTexture.Local = true; | ||
197 | m_assetService.Store(newTexture); | ||
198 | WriteTextureData(httpRequest, httpResponse, newTexture, format); | ||
199 | return true; | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | else // it was on the cache | ||
204 | { | ||
205 | // m_log.DebugFormat("[GETTEXTURE]: texture was in the cache"); | ||
206 | WriteTextureData(httpRequest, httpResponse, texture, format); | ||
207 | return true; | ||
208 | } | ||
209 | } | ||
210 | |||
211 | // not found | ||
212 | // m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found"); | ||
213 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
214 | return true; | ||
215 | } | ||
216 | |||
217 | private void WriteTextureData(IOSHttpRequest request, IOSHttpResponse response, AssetBase texture, string format) | ||
218 | { | ||
219 | string range = request.Headers.GetOne("Range"); | ||
220 | |||
221 | if (!String.IsNullOrEmpty(range)) // JP2's only | ||
222 | { | ||
223 | // Range request | ||
224 | int start, end; | ||
225 | if (TryParseRange(range, out start, out end)) | ||
226 | { | ||
227 | // Before clamping start make sure we can satisfy it in order to avoid | ||
228 | // sending back the last byte instead of an error status | ||
229 | if (start >= texture.Data.Length) | ||
230 | { | ||
231 | // m_log.DebugFormat( | ||
232 | // "[GETTEXTURE]: Client requested range for texture {0} starting at {1} but texture has end of {2}", | ||
233 | // texture.ID, start, texture.Data.Length); | ||
234 | |||
235 | // Stricly speaking, as per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, we should be sending back | ||
236 | // Requested Range Not Satisfiable (416) here. However, it appears that at least recent implementations | ||
237 | // of the Linden Lab viewer (3.2.1 and 3.3.4 and probably earlier), a viewer that has previously | ||
238 | // received a very small texture may attempt to fetch bytes from the server past the | ||
239 | // range of data that it received originally. Whether this happens appears to depend on whether | ||
240 | // the viewer's estimation of how large a request it needs to make for certain discard levels | ||
241 | // (http://wiki.secondlife.com/wiki/Image_System#Discard_Level_and_Mip_Mapping), chiefly discard | ||
242 | // level 2. If this estimate is greater than the total texture size, returning a RequestedRangeNotSatisfiable | ||
243 | // here will cause the viewer to treat the texture as bad and never display the full resolution | ||
244 | // However, if we return PartialContent (or OK) instead, the viewer will display that resolution. | ||
245 | |||
246 | // response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable; | ||
247 | // response.AddHeader("Content-Range", String.Format("bytes */{0}", texture.Data.Length)); | ||
248 | // response.StatusCode = (int)System.Net.HttpStatusCode.OK; | ||
249 | response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; | ||
250 | response.ContentType = texture.Metadata.ContentType; | ||
251 | } | ||
252 | else | ||
253 | { | ||
254 | // Handle the case where no second range value was given. This is equivalent to requesting | ||
255 | // the rest of the entity. | ||
256 | if (end == -1) | ||
257 | end = int.MaxValue; | ||
258 | |||
259 | end = Utils.Clamp(end, 0, texture.Data.Length - 1); | ||
260 | start = Utils.Clamp(start, 0, end); | ||
261 | int len = end - start + 1; | ||
262 | |||
263 | // m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); | ||
264 | |||
265 | // Always return PartialContent, even if the range covered the entire data length | ||
266 | // We were accidentally sending back 404 before in this situation | ||
267 | // https://issues.apache.org/bugzilla/show_bug.cgi?id=51878 supports sending 206 even if the | ||
268 | // entire range is requested, and viewer 3.2.2 (and very probably earlier) seems fine with this. | ||
269 | // | ||
270 | // We also do not want to send back OK even if the whole range was satisfiable since this causes | ||
271 | // HTTP textures on at least Imprudence 1.4.0-beta2 to never display the final texture quality. | ||
272 | // if (end > maxEnd) | ||
273 | // response.StatusCode = (int)System.Net.HttpStatusCode.OK; | ||
274 | // else | ||
275 | response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; | ||
276 | |||
277 | response.ContentLength = len; | ||
278 | response.ContentType = texture.Metadata.ContentType; | ||
279 | response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length)); | ||
280 | |||
281 | response.Body.Write(texture.Data, start, len); | ||
282 | } | ||
283 | } | ||
284 | else | ||
285 | { | ||
286 | m_log.Warn("[GETTEXTURE]: Malformed Range header: " + range); | ||
287 | response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; | ||
288 | } | ||
289 | } | ||
290 | else // JP2's or other formats | ||
291 | { | ||
292 | // Full content request | ||
293 | response.StatusCode = (int)System.Net.HttpStatusCode.OK; | ||
294 | response.ContentLength = texture.Data.Length; | ||
295 | if (format == DefaultFormat) | ||
296 | response.ContentType = texture.Metadata.ContentType; | ||
297 | else | ||
298 | response.ContentType = "image/" + format; | ||
299 | response.Body.Write(texture.Data, 0, texture.Data.Length); | ||
300 | } | ||
301 | |||
302 | // if (response.StatusCode < 200 || response.StatusCode > 299) | ||
303 | // m_log.WarnFormat( | ||
304 | // "[GETTEXTURE]: For texture {0} requested range {1} responded {2} with content length {3} (actual {4})", | ||
305 | // texture.FullID, range, response.StatusCode, response.ContentLength, texture.Data.Length); | ||
306 | // else | ||
307 | // m_log.DebugFormat( | ||
308 | // "[GETTEXTURE]: For texture {0} requested range {1} responded {2} with content length {3} (actual {4})", | ||
309 | // texture.FullID, range, response.StatusCode, response.ContentLength, texture.Data.Length); | ||
310 | } | ||
311 | |||
312 | /// <summary> | ||
313 | /// Parse a range header. | ||
314 | /// </summary> | ||
315 | /// <remarks> | ||
316 | /// As per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, | ||
317 | /// this obeys range headers with two values (e.g. 533-4165) and no second value (e.g. 533-). | ||
318 | /// Where there is no value, -1 is returned. | ||
319 | /// FIXME: Need to cover the case where only a second value is specified (e.g. -4165), probably by returning -1 | ||
320 | /// for start.</remarks> | ||
321 | /// <returns></returns> | ||
322 | /// <param name='header'></param> | ||
323 | /// <param name='start'>Start of the range. Undefined if this was not a number.</param> | ||
324 | /// <param name='end'>End of the range. Will be -1 if no end specified. Undefined if there was a raw string but this was not a number.</param> | ||
325 | private bool TryParseRange(string header, out int start, out int end) | ||
326 | { | ||
327 | start = end = 0; | ||
328 | |||
329 | if (header.StartsWith("bytes=")) | ||
330 | { | ||
331 | string[] rangeValues = header.Substring(6).Split('-'); | ||
332 | |||
333 | if (rangeValues.Length == 2) | ||
334 | { | ||
335 | if (!Int32.TryParse(rangeValues[0], out start)) | ||
336 | return false; | ||
337 | |||
338 | string rawEnd = rangeValues[1]; | ||
339 | |||
340 | if (rawEnd == "") | ||
341 | { | ||
342 | end = -1; | ||
343 | return true; | ||
344 | } | ||
345 | else if (Int32.TryParse(rawEnd, out end)) | ||
346 | { | ||
347 | return true; | ||
348 | } | ||
349 | } | ||
350 | } | ||
351 | |||
352 | start = end = 0; | ||
353 | return false; | ||
354 | } | ||
355 | |||
356 | private byte[] ConvertTextureData(AssetBase texture, string format) | ||
357 | { | ||
358 | m_log.DebugFormat("[GETTEXTURE]: Converting texture {0} to {1}", texture.ID, format); | ||
359 | byte[] data = new byte[0]; | ||
360 | |||
361 | MemoryStream imgstream = new MemoryStream(); | ||
362 | Bitmap mTexture = new Bitmap(1, 1); | ||
363 | ManagedImage managedImage; | ||
364 | Image image = (Image)mTexture; | ||
365 | |||
366 | try | ||
367 | { | ||
368 | // Taking our jpeg2000 data, decoding it, then saving it to a byte array with regular data | ||
369 | |||
370 | imgstream = new MemoryStream(); | ||
371 | |||
372 | // Decode image to System.Drawing.Image | ||
373 | if (OpenJPEG.DecodeToImage(texture.Data, out managedImage, out image)) | ||
374 | { | ||
375 | // Save to bitmap | ||
376 | mTexture = new Bitmap(image); | ||
377 | |||
378 | EncoderParameters myEncoderParameters = new EncoderParameters(); | ||
379 | myEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 95L); | ||
380 | |||
381 | // Save bitmap to stream | ||
382 | ImageCodecInfo codec = GetEncoderInfo("image/" + format); | ||
383 | if (codec != null) | ||
384 | { | ||
385 | mTexture.Save(imgstream, codec, myEncoderParameters); | ||
386 | // Write the stream to a byte array for output | ||
387 | data = imgstream.ToArray(); | ||
388 | } | ||
389 | else | ||
390 | m_log.WarnFormat("[GETTEXTURE]: No such codec {0}", format); | ||
391 | |||
392 | } | ||
393 | } | ||
394 | catch (Exception e) | ||
395 | { | ||
396 | m_log.WarnFormat("[GETTEXTURE]: Unable to convert texture {0} to {1}: {2}", texture.ID, format, e.Message); | ||
397 | } | ||
398 | finally | ||
399 | { | ||
400 | // Reclaim memory, these are unmanaged resources | ||
401 | // If we encountered an exception, one or more of these will be null | ||
402 | if (mTexture != null) | ||
403 | mTexture.Dispose(); | ||
404 | |||
405 | if (image != null) | ||
406 | image.Dispose(); | ||
407 | |||
408 | if (imgstream != null) | ||
409 | { | ||
410 | imgstream.Close(); | ||
411 | imgstream.Dispose(); | ||
412 | } | ||
413 | } | ||
414 | |||
415 | return data; | ||
416 | } | ||
417 | |||
418 | // From msdn | ||
419 | private static ImageCodecInfo GetEncoderInfo(String mimeType) | ||
420 | { | ||
421 | ImageCodecInfo[] encoders; | ||
422 | encoders = ImageCodecInfo.GetImageEncoders(); | ||
423 | for (int j = 0; j < encoders.Length; ++j) | ||
424 | { | ||
425 | if (encoders[j].MimeType == mimeType) | ||
426 | return encoders[j]; | ||
427 | } | ||
428 | return null; | ||
429 | } | ||
430 | } | ||
431 | } | ||
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs index fa0b228..479cebb 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs | |||
@@ -33,6 +33,7 @@ using OpenSim.Framework.Servers.HttpServer; | |||
33 | using OpenSim.Server.Handlers.Base; | 33 | using OpenSim.Server.Handlers.Base; |
34 | using OpenMetaverse; | 34 | using OpenMetaverse; |
35 | 35 | ||
36 | |||
36 | namespace OpenSim.Capabilities.Handlers | 37 | namespace OpenSim.Capabilities.Handlers |
37 | { | 38 | { |
38 | public class GetTextureServerConnector : ServiceConnector | 39 | public class GetTextureServerConnector : ServiceConnector |
@@ -65,7 +66,8 @@ namespace OpenSim.Capabilities.Handlers | |||
65 | string rurl = serverConfig.GetString("GetTextureRedirectURL"); | 66 | string rurl = serverConfig.GetString("GetTextureRedirectURL"); |
66 | ; | 67 | ; |
67 | server.AddStreamHandler( | 68 | server.AddStreamHandler( |
68 | new GetTextureHandler("/CAPS/GetTexture/" /*+ UUID.Random() */, m_AssetService, "GetTexture", null, rurl)); | 69 | new GetTextureRobustHandler("/CAPS/GetTexture/", m_AssetService, "GetTexture", null, rurl)); |
69 | } | 70 | } |
70 | } | 71 | } |
71 | } \ No newline at end of file | 72 | } |
73 | |||
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs b/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs index e5d9618..61aa689 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs | |||
@@ -38,6 +38,7 @@ using OpenSim.Framework.Servers.HttpServer; | |||
38 | using OpenSim.Region.Framework.Scenes; | 38 | using OpenSim.Region.Framework.Scenes; |
39 | using OpenSim.Tests.Common; | 39 | using OpenSim.Tests.Common; |
40 | 40 | ||
41 | /* | ||
41 | namespace OpenSim.Capabilities.Handlers.GetTexture.Tests | 42 | namespace OpenSim.Capabilities.Handlers.GetTexture.Tests |
42 | { | 43 | { |
43 | [TestFixture] | 44 | [TestFixture] |
@@ -59,4 +60,5 @@ namespace OpenSim.Capabilities.Handlers.GetTexture.Tests | |||
59 | Assert.That(resp.StatusCode, Is.EqualTo((int)System.Net.HttpStatusCode.NotFound)); | 60 | Assert.That(resp.StatusCode, Is.EqualTo((int)System.Net.HttpStatusCode.NotFound)); |
60 | } | 61 | } |
61 | } | 62 | } |
62 | } \ No newline at end of file | 63 | } |
64 | */ | ||
diff --git a/OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureHandler.cs b/OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureHandler.cs index 8849a59..5536564 100644 --- a/OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureHandler.cs +++ b/OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureHandler.cs | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | ||
30 | using System.Collections.Specialized; | 31 | using System.Collections.Specialized; |
31 | using System.Drawing; | 32 | using System.Drawing; |
32 | using System.Drawing.Imaging; | 33 | using System.Drawing.Imaging; |
@@ -50,6 +51,7 @@ namespace OpenSim.Capabilities.Handlers | |||
50 | { | 51 | { |
51 | public class UploadBakedTextureHandler | 52 | public class UploadBakedTextureHandler |
52 | { | 53 | { |
54 | |||
53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 55 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
54 | 56 | ||
55 | private Caps m_HostCapsObj; | 57 | private Caps m_HostCapsObj; |
@@ -79,9 +81,9 @@ namespace OpenSim.Capabilities.Handlers | |||
79 | { | 81 | { |
80 | string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath; | 82 | string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath; |
81 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); | 83 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); |
82 | 84 | ||
83 | BakedTextureUploader uploader = | 85 | BakedTextureUploader uploader = |
84 | new BakedTextureUploader(capsBase + uploaderPath, m_HostCapsObj.HttpListener); | 86 | new BakedTextureUploader(capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_HostCapsObj.AgentID); |
85 | uploader.OnUpLoad += BakedTextureUploaded; | 87 | uploader.OnUpLoad += BakedTextureUploaded; |
86 | 88 | ||
87 | m_HostCapsObj.HttpListener.AddStreamHandler( | 89 | m_HostCapsObj.HttpListener.AddStreamHandler( |
@@ -117,7 +119,7 @@ namespace OpenSim.Capabilities.Handlers | |||
117 | /// <param name="data"></param> | 119 | /// <param name="data"></param> |
118 | private void BakedTextureUploaded(UUID assetID, byte[] data) | 120 | private void BakedTextureUploaded(UUID assetID, byte[] data) |
119 | { | 121 | { |
120 | // m_log.DebugFormat("[UPLOAD BAKED TEXTURE HANDLER]: Received baked texture {0}", assetID.ToString()); | 122 | m_log.DebugFormat("[UPLOAD BAKED TEXTURE HANDLER]: Received baked texture {0}", assetID.ToString()); |
121 | 123 | ||
122 | AssetBase asset; | 124 | AssetBase asset; |
123 | asset = new AssetBase(assetID, "Baked Texture", (sbyte)AssetType.Texture, m_HostCapsObj.AgentID.ToString()); | 125 | asset = new AssetBase(assetID, "Baked Texture", (sbyte)AssetType.Texture, m_HostCapsObj.AgentID.ToString()); |
@@ -125,6 +127,7 @@ namespace OpenSim.Capabilities.Handlers | |||
125 | asset.Temporary = true; | 127 | asset.Temporary = true; |
126 | asset.Local = !m_persistBakedTextures; // Local assets aren't persisted, non-local are | 128 | asset.Local = !m_persistBakedTextures; // Local assets aren't persisted, non-local are |
127 | m_assetService.Store(asset); | 129 | m_assetService.Store(asset); |
130 | |||
128 | } | 131 | } |
129 | } | 132 | } |
130 | 133 | ||
@@ -137,15 +140,19 @@ namespace OpenSim.Capabilities.Handlers | |||
137 | private string uploaderPath = String.Empty; | 140 | private string uploaderPath = String.Empty; |
138 | private UUID newAssetID; | 141 | private UUID newAssetID; |
139 | private IHttpServer httpListener; | 142 | private IHttpServer httpListener; |
143 | private UUID AgentId = UUID.Zero; | ||
140 | 144 | ||
141 | public BakedTextureUploader(string path, IHttpServer httpServer) | 145 | public BakedTextureUploader(string path, IHttpServer httpServer, UUID uUID) |
142 | { | 146 | { |
143 | newAssetID = UUID.Random(); | 147 | newAssetID = UUID.Random(); |
144 | uploaderPath = path; | 148 | uploaderPath = path; |
145 | httpListener = httpServer; | 149 | httpListener = httpServer; |
150 | AgentId = uUID; | ||
146 | // m_log.InfoFormat("[CAPS] baked texture upload starting for {0}",newAssetID); | 151 | // m_log.InfoFormat("[CAPS] baked texture upload starting for {0}",newAssetID); |
147 | } | 152 | } |
148 | 153 | ||
154 | |||
155 | |||
149 | /// <summary> | 156 | /// <summary> |
150 | /// Handle raw uploaded baked texture data. | 157 | /// Handle raw uploaded baked texture data. |
151 | /// </summary> | 158 | /// </summary> |
diff --git a/OpenSim/Capabilities/LLSDAssetUploadComplete.cs b/OpenSim/Capabilities/LLSDAssetUploadComplete.cs index ab6cee5..ae8eb09 100644 --- a/OpenSim/Capabilities/LLSDAssetUploadComplete.cs +++ b/OpenSim/Capabilities/LLSDAssetUploadComplete.cs | |||
@@ -30,12 +30,15 @@ using OpenMetaverse; | |||
30 | 30 | ||
31 | namespace OpenSim.Framework.Capabilities | 31 | namespace OpenSim.Framework.Capabilities |
32 | { | 32 | { |
33 | |||
33 | [LLSDType("MAP")] | 34 | [LLSDType("MAP")] |
34 | public class LLSDAssetUploadComplete | 35 | public class LLSDAssetUploadComplete |
35 | { | 36 | { |
36 | public string new_asset = String.Empty; | 37 | public string new_asset = String.Empty; |
37 | public UUID new_inventory_item = UUID.Zero; | 38 | public UUID new_inventory_item = UUID.Zero; |
39 | // public UUID new_texture_folder_id = UUID.Zero; | ||
38 | public string state = String.Empty; | 40 | public string state = String.Empty; |
41 | public LLSDAssetUploadError error = null; | ||
39 | //public bool success = false; | 42 | //public bool success = false; |
40 | 43 | ||
41 | public LLSDAssetUploadComplete() | 44 | public LLSDAssetUploadComplete() |
diff --git a/OpenSim/Capabilities/LLSDAssetUploadRequest.cs b/OpenSim/Capabilities/LLSDAssetUploadRequest.cs index 6e66f0a..6779cc1 100644 --- a/OpenSim/Capabilities/LLSDAssetUploadRequest.cs +++ b/OpenSim/Capabilities/LLSDAssetUploadRequest.cs | |||
@@ -31,14 +31,27 @@ using OpenMetaverse; | |||
31 | namespace OpenSim.Framework.Capabilities | 31 | namespace OpenSim.Framework.Capabilities |
32 | { | 32 | { |
33 | [OSDMap] | 33 | [OSDMap] |
34 | public class LLSDAssetResource | ||
35 | { | ||
36 | public OSDArray instance_list = new OSDArray(); | ||
37 | public OSDArray texture_list = new OSDArray(); | ||
38 | public OSDArray mesh_list = new OSDArray(); | ||
39 | public string metric = String.Empty; | ||
40 | } | ||
41 | |||
42 | [OSDMap] | ||
34 | public class LLSDAssetUploadRequest | 43 | public class LLSDAssetUploadRequest |
35 | { | 44 | { |
36 | public string asset_type = String.Empty; | 45 | public string asset_type = String.Empty; |
37 | public string description = String.Empty; | 46 | public string description = String.Empty; |
38 | public UUID folder_id = UUID.Zero; | 47 | public UUID folder_id = UUID.Zero; |
48 | public UUID texture_folder_id = UUID.Zero; | ||
49 | public int next_owner_mask = 0; | ||
50 | public int group_mask = 0; | ||
51 | public int everyone_mask = 0; | ||
39 | public string inventory_type = String.Empty; | 52 | public string inventory_type = String.Empty; |
40 | public string name = String.Empty; | 53 | public string name = String.Empty; |
41 | 54 | public LLSDAssetResource asset_resources = new LLSDAssetResource(); | |
42 | public LLSDAssetUploadRequest() | 55 | public LLSDAssetUploadRequest() |
43 | { | 56 | { |
44 | } | 57 | } |
diff --git a/OpenSim/Capabilities/LLSDAssetUploadResponse.cs b/OpenSim/Capabilities/LLSDAssetUploadResponse.cs index 0d6f7f9..7c4bc97 100644 --- a/OpenSim/Capabilities/LLSDAssetUploadResponse.cs +++ b/OpenSim/Capabilities/LLSDAssetUploadResponse.cs | |||
@@ -26,20 +26,51 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using OpenMetaverse; | ||
29 | 30 | ||
30 | namespace OpenSim.Framework.Capabilities | 31 | namespace OpenSim.Framework.Capabilities |
31 | { | 32 | { |
32 | [OSDMap] | 33 | [OSDMap] |
34 | public class LLSDAssetUploadError | ||
35 | { | ||
36 | public string message = String.Empty; | ||
37 | public UUID identifier = UUID.Zero; | ||
38 | } | ||
39 | |||
40 | [OSDMap] | ||
41 | public class LLSDAssetUploadResponsePricebrkDown | ||
42 | { | ||
43 | public int mesh_streaming; | ||
44 | public int mesh_physics; | ||
45 | public int mesh_instance; | ||
46 | public int texture; | ||
47 | public int model; | ||
48 | } | ||
49 | |||
50 | [OSDMap] | ||
51 | public class LLSDAssetUploadResponseData | ||
52 | { | ||
53 | public double resource_cost; | ||
54 | public double model_streaming_cost; | ||
55 | public double simulation_cost; | ||
56 | public double physics_cost; | ||
57 | public LLSDAssetUploadResponsePricebrkDown upload_price_breakdown = new LLSDAssetUploadResponsePricebrkDown(); | ||
58 | } | ||
59 | |||
60 | [OSDMap] | ||
33 | public class LLSDAssetUploadResponse | 61 | public class LLSDAssetUploadResponse |
34 | { | 62 | { |
35 | public string uploader = String.Empty; | 63 | public string uploader = String.Empty; |
36 | public string state = String.Empty; | 64 | public string state = String.Empty; |
37 | 65 | public int upload_price = 0; | |
66 | public LLSDAssetUploadResponseData data = null; | ||
67 | public LLSDAssetUploadError error = null; | ||
38 | public LLSDAssetUploadResponse() | 68 | public LLSDAssetUploadResponse() |
39 | { | 69 | { |
40 | } | 70 | } |
41 | } | 71 | } |
42 | 72 | ||
73 | |||
43 | [OSDMap] | 74 | [OSDMap] |
44 | public class LLSDNewFileAngentInventoryVariablePriceReplyResponse | 75 | public class LLSDNewFileAngentInventoryVariablePriceReplyResponse |
45 | { | 76 | { |