aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Capabilities/Handlers/GetTexture
diff options
context:
space:
mode:
authorUbitUmarov2015-09-01 14:54:35 +0100
committerUbitUmarov2015-09-01 14:54:35 +0100
commit371c9dd2af01a2e7422ec901ee1f80757284a78c (patch)
tree058d2a513cacb12efcce0c0df0ae14ad135dbfe2 /OpenSim/Capabilities/Handlers/GetTexture
parentremove lixo (diff)
parentdont change camera on crossings (diff)
downloadopensim-SC-371c9dd2af01a2e7422ec901ee1f80757284a78c.zip
opensim-SC-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.gz
opensim-SC-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.bz2
opensim-SC-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.xz
bad merge?
Diffstat (limited to 'OpenSim/Capabilities/Handlers/GetTexture')
-rw-r--r--OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs224
-rw-r--r--OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs4
-rw-r--r--OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs4
3 files changed, 119 insertions, 113 deletions
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
index 828e943..a8e0fb5 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
48namespace OpenSim.Capabilities.Handlers 48namespace 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,8 +59,8 @@ 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 m_RedirectURL = redirectURL;
@@ -67,19 +68,22 @@ namespace OpenSim.Capabilities.Handlers
67 m_RedirectURL += "/"; 68 m_RedirectURL += "/";
68 } 69 }
69 70
70 protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 71 public Hashtable Handle(Hashtable request)
71 { 72 {
72 // Try to parse the texture ID from the request URL 73 Hashtable ret = new Hashtable();
73 NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); 74 ret["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound;
74 string textureStr = query.GetOne("texture_id"); 75 ret["content_type"] = "text/plain";
75 string format = query.GetOne("format"); 76 ret["keepalive"] = false;
77 ret["reusecontext"] = false;
78 ret["int_bytes"] = 0;
79 string textureStr = (string)request["texture_id"];
80 string format = (string)request["format"];
76 81
77 //m_log.DebugFormat("[GETTEXTURE]: called {0}", textureStr); 82 //m_log.DebugFormat("[GETTEXTURE]: called {0}", textureStr);
78 83
79 if (m_assetService == null) 84 if (m_assetService == null)
80 { 85 {
81 m_log.Error("[GETTEXTURE]: Cannot fetch texture " + textureStr + " without an asset service"); 86 m_log.Error("[GETTEXTURE]: Cannot fetch texture " + textureStr + " without an asset service");
82 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
83 } 87 }
84 88
85 UUID textureID; 89 UUID textureID;
@@ -94,30 +98,41 @@ namespace OpenSim.Capabilities.Handlers
94 } 98 }
95 else 99 else
96 { 100 {
97 formats = WebUtil.GetPreferredImageTypes(httpRequest.Headers.Get("Accept")); 101 formats = new string[1] { DefaultFormat }; // default
102 if (((Hashtable)request["headers"])["Accept"] != null)
103 formats = WebUtil.GetPreferredImageTypes((string)((Hashtable)request["headers"])["Accept"]);
98 if (formats.Length == 0) 104 if (formats.Length == 0)
99 formats = new string[1] { DefaultFormat }; // default 105 formats = new string[1] { DefaultFormat }; // default
100 106
101 } 107 }
102 // OK, we have an array with preferred formats, possibly with only one entry 108 // OK, we have an array with preferred formats, possibly with only one entry
103 109 bool foundtexture = false;
104 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
105 foreach (string f in formats) 110 foreach (string f in formats)
106 { 111 {
107 if (FetchTexture(httpRequest, httpResponse, textureID, f)) 112 foundtexture = FetchTexture(request, ret, textureID, f);
113 if (foundtexture)
108 break; 114 break;
109 } 115 }
116 if (!foundtexture)
117 {
118 ret["int_response_code"] = 404;
119 ret["error_status_text"] = "not found";
120 ret["str_response_string"] = "not found";
121 ret["content_type"] = "text/plain";
122 ret["keepalive"] = false;
123 ret["reusecontext"] = false;
124 ret["int_bytes"] = 0;
125 }
110 } 126 }
111 else 127 else
112 { 128 {
113 m_log.Warn("[GETTEXTURE]: Failed to parse a texture_id from GetTexture request: " + httpRequest.Url); 129 m_log.Warn("[GETTEXTURE]: Failed to parse a texture_id from GetTexture request: " + (string)request["uri"]);
114 } 130 }
115 131
116// m_log.DebugFormat( 132// m_log.DebugFormat(
117// "[GETTEXTURE]: For texture {0} sending back response {1}, data length {2}", 133// "[GETTEXTURE]: For texture {0} sending back response {1}, data length {2}",
118// textureID, httpResponse.StatusCode, httpResponse.ContentLength); 134// textureID, httpResponse.StatusCode, httpResponse.ContentLength);
119 135 return ret;
120 return null;
121 } 136 }
122 137
123 /// <summary> 138 /// <summary>
@@ -128,7 +143,7 @@ namespace OpenSim.Capabilities.Handlers
128 /// <param name="textureID"></param> 143 /// <param name="textureID"></param>
129 /// <param name="format"></param> 144 /// <param name="format"></param>
130 /// <returns>False for "caller try another codec"; true otherwise</returns> 145 /// <returns>False for "caller try another codec"; true otherwise</returns>
131 private bool FetchTexture(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID textureID, string format) 146 private bool FetchTexture(Hashtable request, Hashtable response, UUID textureID, string format)
132 { 147 {
133// m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format); 148// m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format);
134 AssetBase texture; 149 AssetBase texture;
@@ -137,86 +152,70 @@ namespace OpenSim.Capabilities.Handlers
137 if (format != DefaultFormat) 152 if (format != DefaultFormat)
138 fullID = fullID + "-" + format; 153 fullID = fullID + "-" + format;
139 154
140 if (!String.IsNullOrEmpty(m_RedirectURL)) 155 // try the cache
156 texture = m_assetService.GetCached(fullID);
157
158 if (texture == null)
141 { 159 {
142 // Only try to fetch locally cached textures. Misses are redirected 160 //m_log.DebugFormat("[GETTEXTURE]: texture was not in the cache");
143 texture = m_assetService.GetCached(fullID); 161
162 // Fetch locally or remotely. Misses return a 404
163 texture = m_assetService.Get(textureID.ToString());
144 164
145 if (texture != null) 165 if (texture != null)
146 { 166 {
147 if (texture.Type != (sbyte)AssetType.Texture) 167 if (texture.Type != (sbyte)AssetType.Texture)
168 return true;
169
170 if (format == DefaultFormat)
148 { 171 {
149 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; 172 WriteTextureData(request, response, texture, format);
150 return true; 173 return true;
151 } 174 }
152 WriteTextureData(httpRequest, httpResponse, texture, format); 175 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 { 176 {
177 if (texture.Type != (sbyte)AssetType.Texture) 177 AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID);
178 { 178 newTexture.Data = ConvertTextureData(texture, format);
179 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; 179 if (newTexture.Data.Length == 0)
180 return true; 180 return false; // !!! Caller try another codec, please!
181 } 181
182 if (format == DefaultFormat) 182 newTexture.Flags = AssetFlags.Collectable;
183 { 183 newTexture.Temporary = true;
184 WriteTextureData(httpRequest, httpResponse, texture, format); 184 newTexture.Local = true;
185 return true; 185 m_assetService.Store(newTexture);
186 } 186 WriteTextureData(request, response, newTexture, format);
187 else 187 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 } 188 }
202 } 189 }
203 else // it was on the cache 190 }
204 { 191 else // it was on the cache
205// m_log.DebugFormat("[GETTEXTURE]: texture was in the cache"); 192 {
206 WriteTextureData(httpRequest, httpResponse, texture, format); 193 //m_log.DebugFormat("[GETTEXTURE]: texture was in the cache");
207 return true; 194 WriteTextureData(request, response, texture, format);
208 } 195 return true;
209 } 196 }
210 197
198 //response = new Hashtable();
199
200
201 //WriteTextureData(request,response,null,format);
211 // not found 202 // not found
212// m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found"); 203 //m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found");
213 httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; 204 return false;
214 return true;
215 } 205 }
216 206
217 private void WriteTextureData(IOSHttpRequest request, IOSHttpResponse response, AssetBase texture, string format) 207 private void WriteTextureData(Hashtable request, Hashtable response, AssetBase texture, string format)
218 { 208 {
219 string range = request.Headers.GetOne("Range"); 209 Hashtable headers = new Hashtable();
210 response["headers"] = headers;
211
212 string range = String.Empty;
213
214 if (((Hashtable)request["headers"])["range"] != null)
215 range = (string)((Hashtable)request["headers"])["range"];
216
217 else if (((Hashtable)request["headers"])["Range"] != null)
218 range = (string)((Hashtable)request["headers"])["Range"];
220 219
221 if (!String.IsNullOrEmpty(range)) // JP2's only 220 if (!String.IsNullOrEmpty(range)) // JP2's only
222 { 221 {
@@ -244,10 +243,8 @@ namespace OpenSim.Capabilities.Handlers
244 // However, if we return PartialContent (or OK) instead, the viewer will display that resolution. 243 // However, if we return PartialContent (or OK) instead, the viewer will display that resolution.
245 244
246// response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable; 245// response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable;
247// response.AddHeader("Content-Range", String.Format("bytes */{0}", texture.Data.Length)); 246 // viewers don't seem to handle RequestedRangeNotSatisfiable and keep retrying with same parameters
248// response.StatusCode = (int)System.Net.HttpStatusCode.OK; 247 response["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound;
249 response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent;
250 response.ContentType = texture.Metadata.ContentType;
251 } 248 }
252 else 249 else
253 { 250 {
@@ -262,41 +259,46 @@ namespace OpenSim.Capabilities.Handlers
262 259
263// m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); 260// m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID);
264 261
265 // Always return PartialContent, even if the range covered the entire data length 262 response["content-type"] = texture.Metadata.ContentType;
266 // We were accidentally sending back 404 before in this situation 263
267 // https://issues.apache.org/bugzilla/show_bug.cgi?id=51878 supports sending 206 even if the 264 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. 265 {
269 // 266 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 267 response["bin_response_data"] = texture.Data;
271 // HTTP textures on at least Imprudence 1.4.0-beta2 to never display the final texture quality. 268 response["int_bytes"] = texture.Data.Length;
272// if (end > maxEnd) 269 }
273// response.StatusCode = (int)System.Net.HttpStatusCode.OK; 270 else
274// else 271 {
275 response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; 272 response["int_response_code"] = (int)System.Net.HttpStatusCode.PartialContent;
276 273 headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length);
277 response.ContentLength = len; 274
278 response.ContentType = texture.Metadata.ContentType; 275 byte[] d = new byte[len];
279 response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length)); 276 Array.Copy(texture.Data, start, d, 0, len);
280 277 response["bin_response_data"] = d;
281 response.Body.Write(texture.Data, start, len); 278 response["int_bytes"] = len;
279 }
280// response.Body.Write(texture.Data, start, len);
282 } 281 }
283 } 282 }
284 else 283 else
285 { 284 {
286 m_log.Warn("[GETTEXTURE]: Malformed Range header: " + range); 285 m_log.Warn("[GETTEXTURE]: Malformed Range header: " + range);
287 response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; 286 response["int_response_code"] = (int)System.Net.HttpStatusCode.BadRequest;
288 } 287 }
289 } 288 }
290 else // JP2's or other formats 289 else // JP2's or other formats
291 { 290 {
292 // Full content request 291 // Full content request
293 response.StatusCode = (int)System.Net.HttpStatusCode.OK; 292 response["int_response_code"] = (int)System.Net.HttpStatusCode.OK;
294 response.ContentLength = texture.Data.Length;
295 if (format == DefaultFormat) 293 if (format == DefaultFormat)
296 response.ContentType = texture.Metadata.ContentType; 294 response["content_type"] = texture.Metadata.ContentType;
297 else 295 else
298 response.ContentType = "image/" + format; 296 response["content_type"] = "image/" + format;
299 response.Body.Write(texture.Data, 0, texture.Data.Length); 297
298 response["bin_response_data"] = texture.Data;
299 response["int_bytes"] = texture.Data.Length;
300
301// response.Body.Write(texture.Data, 0, texture.Data.Length);
300 } 302 }
301 303
302// if (response.StatusCode < 200 || response.StatusCode > 299) 304// if (response.StatusCode < 200 || response.StatusCode > 299)
@@ -428,4 +430,4 @@ namespace OpenSim.Capabilities.Handlers
428 return null; 430 return null;
429 } 431 }
430 } 432 }
431} \ No newline at end of file 433}
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs
index fa0b228..d55e0ff 100644
--- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs
+++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs
@@ -33,6 +33,7 @@ using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base; 33using OpenSim.Server.Handlers.Base;
34using OpenMetaverse; 34using OpenMetaverse;
35 35
36/*
36namespace OpenSim.Capabilities.Handlers 37namespace OpenSim.Capabilities.Handlers
37{ 38{
38 public class GetTextureServerConnector : ServiceConnector 39 public class GetTextureServerConnector : ServiceConnector
@@ -68,4 +69,5 @@ namespace OpenSim.Capabilities.Handlers
68 new GetTextureHandler("/CAPS/GetTexture/" /*+ UUID.Random() */, m_AssetService, "GetTexture", null, rurl)); 69 new GetTextureHandler("/CAPS/GetTexture/" /*+ UUID.Random() */, 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;
38using OpenSim.Region.Framework.Scenes; 38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Tests.Common; 39using OpenSim.Tests.Common;
40 40
41/*
41namespace OpenSim.Capabilities.Handlers.GetTexture.Tests 42namespace 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*/