diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs | 421 |
1 files changed, 215 insertions, 206 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs index c9cd412..f2922d6 100644 --- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs | |||
@@ -42,40 +42,15 @@ using OpenSim.Region.Framework.Scenes; | |||
42 | 42 | ||
43 | namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | 43 | namespace OpenSim.Region.CoreModules.Scripting.LSLHttp |
44 | { | 44 | { |
45 | /// <summary> | ||
46 | /// Data describing an external URL set up by a script. | ||
47 | /// </summary> | ||
48 | public class UrlData | 45 | public class UrlData |
49 | { | 46 | { |
50 | /// <summary> | ||
51 | /// Scene object part hosting the script | ||
52 | /// </summary> | ||
53 | public UUID hostID; | 47 | public UUID hostID; |
54 | |||
55 | /// <summary> | ||
56 | /// The item ID of the script that requested the URL. | ||
57 | /// </summary> | ||
58 | public UUID itemID; | 48 | public UUID itemID; |
59 | |||
60 | /// <summary> | ||
61 | /// The script engine that runs the script. | ||
62 | /// </summary> | ||
63 | public IScriptModule engine; | 49 | public IScriptModule engine; |
64 | |||
65 | /// <summary> | ||
66 | /// The generated URL. | ||
67 | /// </summary> | ||
68 | public string url; | 50 | public string url; |
69 | |||
70 | /// <summary> | ||
71 | /// The random UUID component of the generated URL. | ||
72 | /// </summary> | ||
73 | public UUID urlcode; | 51 | public UUID urlcode; |
74 | |||
75 | /// <summary> | ||
76 | /// The external requests currently being processed or awaiting retrieval for this URL. | ||
77 | /// </summary> | ||
78 | public Dictionary<UUID, RequestData> requests; | 52 | public Dictionary<UUID, RequestData> requests; |
53 | public bool isSsl; | ||
79 | } | 54 | } |
80 | 55 | ||
81 | public class RequestData | 56 | public class RequestData |
@@ -89,6 +64,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
89 | //public ManualResetEvent ev; | 64 | //public ManualResetEvent ev; |
90 | public bool requestDone; | 65 | public bool requestDone; |
91 | public int startTime; | 66 | public int startTime; |
67 | public bool responseSent; | ||
92 | public string uri; | 68 | public string uri; |
93 | } | 69 | } |
94 | 70 | ||
@@ -102,20 +78,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
102 | LogManager.GetLogger( | 78 | LogManager.GetLogger( |
103 | MethodBase.GetCurrentMethod().DeclaringType); | 79 | MethodBase.GetCurrentMethod().DeclaringType); |
104 | 80 | ||
105 | /// <summary> | 81 | private Dictionary<UUID, UrlData> m_RequestMap = |
106 | /// Indexs the URL request metadata (which script requested it, outstanding requests, etc.) by the request ID | 82 | new Dictionary<UUID, UrlData>(); |
107 | /// randomly generated when a request is received for this URL. | ||
108 | /// </summary> | ||
109 | /// <remarks> | ||
110 | /// Manipulation or retrieval from this dictionary must be locked on m_UrlMap to preserve consistency with | ||
111 | /// m_UrlMap | ||
112 | /// </remarks> | ||
113 | private Dictionary<UUID, UrlData> m_RequestMap = new Dictionary<UUID, UrlData>(); | ||
114 | 83 | ||
115 | /// <summary> | 84 | private Dictionary<string, UrlData> m_UrlMap = |
116 | /// Indexs the URL request metadata (which script requested it, outstanding requests, etc.) by the full URL | 85 | new Dictionary<string, UrlData>(); |
117 | /// </summary> | ||
118 | private Dictionary<string, UrlData> m_UrlMap = new Dictionary<string, UrlData>(); | ||
119 | 86 | ||
120 | private uint m_HttpsPort = 0; | 87 | private uint m_HttpsPort = 0; |
121 | private IHttpServer m_HttpServer = null; | 88 | private IHttpServer m_HttpServer = null; |
@@ -126,7 +93,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
126 | /// <summary> | 93 | /// <summary> |
127 | /// The default maximum number of urls | 94 | /// The default maximum number of urls |
128 | /// </summary> | 95 | /// </summary> |
129 | public const int DefaultTotalUrls = 100; | 96 | public const int DefaultTotalUrls = 15000; |
130 | 97 | ||
131 | /// <summary> | 98 | /// <summary> |
132 | /// Maximum number of external urls that can be set up by this module. | 99 | /// Maximum number of external urls that can be set up by this module. |
@@ -221,7 +188,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
221 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); | 188 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); |
222 | return urlcode; | 189 | return urlcode; |
223 | } | 190 | } |
224 | string url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/"; | 191 | string url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString(); |
225 | 192 | ||
226 | UrlData urlData = new UrlData(); | 193 | UrlData urlData = new UrlData(); |
227 | urlData.hostID = host.UUID; | 194 | urlData.hostID = host.UUID; |
@@ -229,19 +196,20 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
229 | urlData.engine = engine; | 196 | urlData.engine = engine; |
230 | urlData.url = url; | 197 | urlData.url = url; |
231 | urlData.urlcode = urlcode; | 198 | urlData.urlcode = urlcode; |
199 | urlData.isSsl = false; | ||
232 | urlData.requests = new Dictionary<UUID, RequestData>(); | 200 | urlData.requests = new Dictionary<UUID, RequestData>(); |
233 | 201 | ||
234 | m_UrlMap[url] = urlData; | 202 | m_UrlMap[url] = urlData; |
235 | 203 | ||
236 | string uri = "/lslhttp/" + urlcode.ToString() + "/"; | 204 | string uri = "/lslhttp/" + urlcode.ToString(); |
237 | 205 | ||
238 | m_HttpServer.AddPollServiceHTTPHandler( | 206 | PollServiceEventArgs args = new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode, 25000); |
239 | uri, | 207 | args.Type = PollServiceEventArgs.EventType.LslHttp; |
240 | new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode)); | 208 | m_HttpServer.AddPollServiceHTTPHandler(uri, args); |
241 | 209 | ||
242 | m_log.DebugFormat( | 210 | // m_log.DebugFormat( |
243 | "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}", | 211 | // "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}", |
244 | uri, itemID, host.Name, host.LocalId); | 212 | // uri, itemID, host.Name, host.LocalId); |
245 | 213 | ||
246 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); | 214 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); |
247 | } | 215 | } |
@@ -266,7 +234,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
266 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); | 234 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); |
267 | return urlcode; | 235 | return urlcode; |
268 | } | 236 | } |
269 | string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/"; | 237 | string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString(); |
270 | 238 | ||
271 | UrlData urlData = new UrlData(); | 239 | UrlData urlData = new UrlData(); |
272 | urlData.hostID = host.UUID; | 240 | urlData.hostID = host.UUID; |
@@ -274,19 +242,21 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
274 | urlData.engine = engine; | 242 | urlData.engine = engine; |
275 | urlData.url = url; | 243 | urlData.url = url; |
276 | urlData.urlcode = urlcode; | 244 | urlData.urlcode = urlcode; |
245 | urlData.isSsl = true; | ||
277 | urlData.requests = new Dictionary<UUID, RequestData>(); | 246 | urlData.requests = new Dictionary<UUID, RequestData>(); |
278 | 247 | ||
248 | |||
279 | m_UrlMap[url] = urlData; | 249 | m_UrlMap[url] = urlData; |
280 | 250 | ||
281 | string uri = "/lslhttps/" + urlcode.ToString() + "/"; | 251 | string uri = "/lslhttps/" + urlcode.ToString(); |
282 | 252 | ||
283 | m_HttpsServer.AddPollServiceHTTPHandler( | 253 | PollServiceEventArgs args = new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode, 25000); |
284 | uri, | 254 | args.Type = PollServiceEventArgs.EventType.LslHttp; |
285 | new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode)); | 255 | m_HttpsServer.AddPollServiceHTTPHandler(uri, args); |
286 | 256 | ||
287 | m_log.DebugFormat( | 257 | // m_log.DebugFormat( |
288 | "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}", | 258 | // "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}", |
289 | uri, itemID, host.Name, host.LocalId); | 259 | // uri, itemID, host.Name, host.LocalId); |
290 | 260 | ||
291 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); | 261 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); |
292 | } | 262 | } |
@@ -305,12 +275,15 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
305 | return; | 275 | return; |
306 | } | 276 | } |
307 | 277 | ||
308 | foreach (UUID req in data.requests.Keys) | 278 | lock (m_RequestMap) |
309 | m_RequestMap.Remove(req); | 279 | { |
310 | 280 | foreach (UUID req in data.requests.Keys) | |
311 | m_log.DebugFormat( | 281 | m_RequestMap.Remove(req); |
312 | "[URL MODULE]: Releasing url {0} for {1} in {2}", | 282 | } |
313 | url, data.itemID, data.hostID); | 283 | |
284 | // m_log.DebugFormat( | ||
285 | // "[URL MODULE]: Releasing url {0} for {1} in {2}", | ||
286 | // url, data.itemID, data.hostID); | ||
314 | 287 | ||
315 | RemoveUrl(data); | 288 | RemoveUrl(data); |
316 | m_UrlMap.Remove(url); | 289 | m_UrlMap.Remove(url); |
@@ -335,29 +308,34 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
335 | 308 | ||
336 | public void HttpResponse(UUID request, int status, string body) | 309 | public void HttpResponse(UUID request, int status, string body) |
337 | { | 310 | { |
338 | lock (m_UrlMap) | 311 | lock (m_RequestMap) |
339 | { | 312 | { |
340 | if (m_RequestMap.ContainsKey(request)) | 313 | if (m_RequestMap.ContainsKey(request)) |
341 | { | 314 | { |
342 | UrlData urlData = m_RequestMap[request]; | 315 | UrlData urlData = m_RequestMap[request]; |
343 | string responseBody = body; | 316 | if (!urlData.requests[request].responseSent) |
344 | if (urlData.requests[request].responseType.Equals("text/plain")) | ||
345 | { | 317 | { |
346 | string value; | 318 | string responseBody = body; |
347 | if (urlData.requests[request].headers.TryGetValue("user-agent", out value)) | 319 | if (urlData.requests[request].responseType.Equals("text/plain")) |
348 | { | 320 | { |
349 | if (value != null && value.IndexOf("MSIE") >= 0) | 321 | string value; |
322 | if (urlData.requests[request].headers.TryGetValue("user-agent", out value)) | ||
350 | { | 323 | { |
351 | // wrap the html escaped response if the target client is IE | 324 | if (value != null && value.IndexOf("MSIE") >= 0) |
352 | // It ignores "text/plain" if the body is html | 325 | { |
353 | responseBody = "<html>" + System.Web.HttpUtility.HtmlEncode(body) + "</html>"; | 326 | // wrap the html escaped response if the target client is IE |
327 | // It ignores "text/plain" if the body is html | ||
328 | responseBody = "<html>" + System.Web.HttpUtility.HtmlEncode(body) + "</html>"; | ||
329 | } | ||
354 | } | 330 | } |
355 | } | 331 | } |
332 | |||
333 | urlData.requests[request].responseCode = status; | ||
334 | urlData.requests[request].responseBody = body; | ||
335 | //urlData.requests[request].ev.Set(); | ||
336 | urlData.requests[request].requestDone = true; | ||
337 | urlData.requests[request].responseSent = true; | ||
356 | } | 338 | } |
357 | urlData.requests[request].responseCode = status; | ||
358 | urlData.requests[request].responseBody = responseBody; | ||
359 | //urlData.requests[request].ev.Set(); | ||
360 | urlData.requests[request].requestDone =true; | ||
361 | } | 339 | } |
362 | else | 340 | else |
363 | { | 341 | { |
@@ -368,7 +346,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
368 | 346 | ||
369 | public string GetHttpHeader(UUID requestId, string header) | 347 | public string GetHttpHeader(UUID requestId, string header) |
370 | { | 348 | { |
371 | lock (m_UrlMap) | 349 | lock (m_RequestMap) |
372 | { | 350 | { |
373 | if (m_RequestMap.ContainsKey(requestId)) | 351 | if (m_RequestMap.ContainsKey(requestId)) |
374 | { | 352 | { |
@@ -382,7 +360,6 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
382 | m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId); | 360 | m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId); |
383 | } | 361 | } |
384 | } | 362 | } |
385 | |||
386 | return String.Empty; | 363 | return String.Empty; |
387 | } | 364 | } |
388 | 365 | ||
@@ -406,8 +383,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
406 | { | 383 | { |
407 | RemoveUrl(url.Value); | 384 | RemoveUrl(url.Value); |
408 | removeURLs.Add(url.Key); | 385 | removeURLs.Add(url.Key); |
409 | foreach (UUID req in url.Value.requests.Keys) | 386 | lock (m_RequestMap) |
410 | m_RequestMap.Remove(req); | 387 | { |
388 | foreach (UUID req in url.Value.requests.Keys) | ||
389 | m_RequestMap.Remove(req); | ||
390 | } | ||
411 | } | 391 | } |
412 | } | 392 | } |
413 | 393 | ||
@@ -428,9 +408,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
428 | { | 408 | { |
429 | RemoveUrl(url.Value); | 409 | RemoveUrl(url.Value); |
430 | removeURLs.Add(url.Key); | 410 | removeURLs.Add(url.Key); |
431 | 411 | lock (m_RequestMap) | |
432 | foreach (UUID req in url.Value.requests.Keys) | 412 | { |
433 | m_RequestMap.Remove(req); | 413 | foreach (UUID req in url.Value.requests.Keys) |
414 | m_RequestMap.Remove(req); | ||
415 | } | ||
434 | } | 416 | } |
435 | } | 417 | } |
436 | 418 | ||
@@ -439,123 +421,128 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
439 | } | 421 | } |
440 | } | 422 | } |
441 | 423 | ||
424 | |||
442 | private void RemoveUrl(UrlData data) | 425 | private void RemoveUrl(UrlData data) |
443 | { | 426 | { |
444 | m_HttpServer.RemoveHTTPHandler("", "/lslhttp/" + data.urlcode.ToString() + "/"); | 427 | if (data.isSsl) |
428 | m_HttpsServer.RemoveHTTPHandler("", "/lslhttps/"+data.urlcode.ToString()+"/"); | ||
429 | else | ||
430 | m_HttpServer.RemoveHTTPHandler("", "/lslhttp/"+data.urlcode.ToString()+"/"); | ||
445 | } | 431 | } |
446 | 432 | ||
447 | private Hashtable NoEvents(UUID requestID, UUID sessionID) | 433 | private Hashtable NoEvents(UUID requestID, UUID sessionID) |
448 | { | 434 | { |
449 | Hashtable response = new Hashtable(); | 435 | Hashtable response = new Hashtable(); |
450 | UrlData urlData; | 436 | UrlData url; |
451 | 437 | int startTime = 0; | |
452 | lock (m_UrlMap) | 438 | lock (m_RequestMap) |
453 | { | 439 | { |
454 | // We need to return a 404 here in case the request URL was removed at exactly the same time that a | ||
455 | // request was made. In this case, the request thread can outrace llRemoveURL() and still be polling | ||
456 | // for the request ID. | ||
457 | if (!m_RequestMap.ContainsKey(requestID)) | 440 | if (!m_RequestMap.ContainsKey(requestID)) |
458 | { | ||
459 | response["int_response_code"] = 404; | ||
460 | response["str_response_string"] = ""; | ||
461 | response["keepalive"] = false; | ||
462 | response["reusecontext"] = false; | ||
463 | |||
464 | return response; | 441 | return response; |
465 | } | 442 | url = m_RequestMap[requestID]; |
443 | startTime = url.requests[requestID].startTime; | ||
444 | } | ||
466 | 445 | ||
467 | urlData = m_RequestMap[requestID]; | 446 | if (System.Environment.TickCount - startTime > 25000) |
447 | { | ||
448 | response["int_response_code"] = 500; | ||
449 | response["str_response_string"] = "Script timeout"; | ||
450 | response["content_type"] = "text/plain"; | ||
451 | response["keepalive"] = false; | ||
452 | response["reusecontext"] = false; | ||
468 | 453 | ||
469 | if (System.Environment.TickCount - urlData.requests[requestID].startTime > 25000) | 454 | //remove from map |
455 | lock (url.requests) | ||
456 | { | ||
457 | url.requests.Remove(requestID); | ||
458 | } | ||
459 | lock (m_RequestMap) | ||
470 | { | 460 | { |
471 | response["int_response_code"] = 500; | ||
472 | response["str_response_string"] = "Script timeout"; | ||
473 | response["content_type"] = "text/plain"; | ||
474 | response["keepalive"] = false; | ||
475 | response["reusecontext"] = false; | ||
476 | |||
477 | //remove from map | ||
478 | urlData.requests.Remove(requestID); | ||
479 | m_RequestMap.Remove(requestID); | 461 | m_RequestMap.Remove(requestID); |
480 | |||
481 | return response; | ||
482 | } | 462 | } |
463 | |||
464 | return response; | ||
483 | } | 465 | } |
484 | 466 | ||
467 | |||
485 | return response; | 468 | return response; |
486 | } | 469 | } |
487 | 470 | ||
488 | private bool HasEvents(UUID requestID, UUID sessionID) | 471 | private bool HasEvents(UUID requestID, UUID sessionID) |
489 | { | 472 | { |
490 | lock (m_UrlMap) | 473 | UrlData url=null; |
474 | |||
475 | lock (m_RequestMap) | ||
491 | { | 476 | { |
492 | // We return true here because an external URL request that happened at the same time as an llRemoveURL() | ||
493 | // can still make it through to HttpRequestHandler(). That will return without setting up a request | ||
494 | // when it detects that the URL has been removed. The poller, however, will continue to ask for | ||
495 | // events for that request, so here we will signal that there are events and in GetEvents we will | ||
496 | // return a 404. | ||
497 | if (!m_RequestMap.ContainsKey(requestID)) | 477 | if (!m_RequestMap.ContainsKey(requestID)) |
498 | { | 478 | { |
499 | return true; | 479 | return false; |
500 | } | 480 | } |
501 | 481 | url = m_RequestMap[requestID]; | |
502 | UrlData urlData = m_RequestMap[requestID]; | 482 | } |
503 | 483 | lock (url.requests) | |
504 | if (!urlData.requests.ContainsKey(requestID)) | 484 | { |
485 | if (!url.requests.ContainsKey(requestID)) | ||
505 | { | 486 | { |
506 | return true; | 487 | return false; |
507 | } | 488 | } |
508 | 489 | else | |
509 | // Trigger return of timeout response. | ||
510 | if (System.Environment.TickCount - urlData.requests[requestID].startTime > 25000) | ||
511 | { | 490 | { |
512 | return true; | 491 | if (System.Environment.TickCount - url.requests[requestID].startTime > 25000) |
492 | { | ||
493 | return true; | ||
494 | } | ||
495 | if (url.requests[requestID].requestDone) | ||
496 | return true; | ||
497 | else | ||
498 | return false; | ||
513 | } | 499 | } |
514 | |||
515 | return urlData.requests[requestID].requestDone; | ||
516 | } | 500 | } |
517 | } | 501 | } |
518 | 502 | private Hashtable GetEvents(UUID requestID, UUID sessionID) | |
519 | private Hashtable GetEvents(UUID requestID, UUID sessionID, string request) | ||
520 | { | 503 | { |
521 | Hashtable response; | 504 | UrlData url = null; |
505 | RequestData requestData = null; | ||
522 | 506 | ||
523 | lock (m_UrlMap) | 507 | lock (m_RequestMap) |
524 | { | 508 | { |
525 | UrlData url = null; | ||
526 | RequestData requestData = null; | ||
527 | |||
528 | if (!m_RequestMap.ContainsKey(requestID)) | 509 | if (!m_RequestMap.ContainsKey(requestID)) |
529 | return NoEvents(requestID, sessionID); | 510 | return NoEvents(requestID,sessionID); |
530 | |||
531 | url = m_RequestMap[requestID]; | 511 | url = m_RequestMap[requestID]; |
512 | } | ||
513 | lock (url.requests) | ||
514 | { | ||
532 | requestData = url.requests[requestID]; | 515 | requestData = url.requests[requestID]; |
516 | } | ||
517 | |||
518 | if (!requestData.requestDone) | ||
519 | return NoEvents(requestID,sessionID); | ||
520 | |||
521 | Hashtable response = new Hashtable(); | ||
533 | 522 | ||
534 | if (!requestData.requestDone) | 523 | if (System.Environment.TickCount - requestData.startTime > 25000) |
535 | return NoEvents(requestID, sessionID); | 524 | { |
536 | 525 | response["int_response_code"] = 500; | |
537 | response = new Hashtable(); | 526 | response["str_response_string"] = "Script timeout"; |
538 | 527 | response["content_type"] = "text/plain"; | |
539 | if (System.Environment.TickCount - requestData.startTime > 25000) | ||
540 | { | ||
541 | response["int_response_code"] = 500; | ||
542 | response["str_response_string"] = "Script timeout"; | ||
543 | response["content_type"] = "text/plain"; | ||
544 | response["keepalive"] = false; | ||
545 | response["reusecontext"] = false; | ||
546 | return response; | ||
547 | } | ||
548 | |||
549 | //put response | ||
550 | response["int_response_code"] = requestData.responseCode; | ||
551 | response["str_response_string"] = requestData.responseBody; | ||
552 | response["content_type"] = requestData.responseType; | ||
553 | // response["content_type"] = "text/plain"; | ||
554 | response["keepalive"] = false; | 528 | response["keepalive"] = false; |
555 | response["reusecontext"] = false; | 529 | response["reusecontext"] = false; |
556 | 530 | return response; | |
557 | //remove from map | 531 | } |
532 | //put response | ||
533 | response["int_response_code"] = requestData.responseCode; | ||
534 | response["str_response_string"] = requestData.responseBody; | ||
535 | response["content_type"] = "text/plain"; | ||
536 | response["keepalive"] = false; | ||
537 | response["reusecontext"] = false; | ||
538 | |||
539 | //remove from map | ||
540 | lock (url.requests) | ||
541 | { | ||
558 | url.requests.Remove(requestID); | 542 | url.requests.Remove(requestID); |
543 | } | ||
544 | lock (m_RequestMap) | ||
545 | { | ||
559 | m_RequestMap.Remove(requestID); | 546 | m_RequestMap.Remove(requestID); |
560 | } | 547 | } |
561 | 548 | ||
@@ -564,41 +551,45 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
564 | 551 | ||
565 | public void HttpRequestHandler(UUID requestID, Hashtable request) | 552 | public void HttpRequestHandler(UUID requestID, Hashtable request) |
566 | { | 553 | { |
567 | string uri = request["uri"].ToString(); | 554 | lock (request) |
568 | bool is_ssl = uri.Contains("lslhttps"); | ||
569 | |||
570 | try | ||
571 | { | 555 | { |
572 | Hashtable headers = (Hashtable)request["headers"]; | 556 | string uri = request["uri"].ToString(); |
573 | 557 | bool is_ssl = uri.Contains("lslhttps"); | |
574 | // string uri_full = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/"; | ||
575 | 558 | ||
576 | int pos1 = uri.IndexOf("/");// /lslhttp | 559 | try |
577 | int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/ | ||
578 | int pos3 = uri.IndexOf("/", pos2 + 1);// /lslhttp/<UUID>/ | ||
579 | string uri_tmp = uri.Substring(0, pos3 + 1); | ||
580 | //HTTP server code doesn't provide us with QueryStrings | ||
581 | string pathInfo; | ||
582 | string queryString; | ||
583 | queryString = ""; | ||
584 | |||
585 | pathInfo = uri.Substring(pos3); | ||
586 | |||
587 | UrlData urlData = null; | ||
588 | |||
589 | lock (m_UrlMap) | ||
590 | { | 560 | { |
591 | string url; | 561 | Hashtable headers = (Hashtable)request["headers"]; |
592 | 562 | ||
593 | if (is_ssl) | 563 | // string uri_full = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/"; |
594 | url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp; | 564 | |
565 | int pos1 = uri.IndexOf("/");// /lslhttp | ||
566 | int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/ | ||
567 | int pos3 = pos2 + 37; // /lslhttp/urlcode | ||
568 | string uri_tmp = uri.Substring(0, pos3); | ||
569 | //HTTP server code doesn't provide us with QueryStrings | ||
570 | string pathInfo; | ||
571 | string queryString; | ||
572 | queryString = ""; | ||
573 | |||
574 | pathInfo = uri.Substring(pos3); | ||
575 | |||
576 | UrlData url = null; | ||
577 | string urlkey; | ||
578 | if (!is_ssl) | ||
579 | urlkey = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp; | ||
580 | //m_UrlMap[]; | ||
595 | else | 581 | else |
596 | url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp; | 582 | urlkey = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp; |
597 | 583 | ||
598 | // Avoid a race - the request URL may have been released via llRequestUrl() whilst this | 584 | if (m_UrlMap.ContainsKey(urlkey)) |
599 | // request was being processed. | 585 | { |
600 | if (!m_UrlMap.TryGetValue(url, out urlData)) | 586 | url = m_UrlMap[urlkey]; |
587 | } | ||
588 | else | ||
589 | { | ||
590 | //m_log.Warn("[HttpRequestHandler]: http-in request failed; no such url: "+urlkey.ToString()); | ||
601 | return; | 591 | return; |
592 | } | ||
602 | 593 | ||
603 | //for llGetHttpHeader support we need to store original URI here | 594 | //for llGetHttpHeader support we need to store original URI here |
604 | //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers | 595 | //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers |
@@ -618,7 +609,6 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
618 | string value = (string)header.Value; | 609 | string value = (string)header.Value; |
619 | requestData.headers.Add(key, value); | 610 | requestData.headers.Add(key, value); |
620 | } | 611 | } |
621 | |||
622 | foreach (DictionaryEntry de in request) | 612 | foreach (DictionaryEntry de in request) |
623 | { | 613 | { |
624 | if (de.Key.ToString() == "querystringkeys") | 614 | if (de.Key.ToString() == "querystringkeys") |
@@ -629,13 +619,21 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
629 | if (request.ContainsKey(key)) | 619 | if (request.ContainsKey(key)) |
630 | { | 620 | { |
631 | string val = (String)request[key]; | 621 | string val = (String)request[key]; |
632 | queryString = queryString + key + "=" + val + "&"; | 622 | if (key != "") |
623 | { | ||
624 | queryString = queryString + key + "=" + val + "&"; | ||
625 | } | ||
626 | else | ||
627 | { | ||
628 | queryString = queryString + val + "&"; | ||
629 | } | ||
633 | } | 630 | } |
634 | } | 631 | } |
635 | |||
636 | if (queryString.Length > 1) | 632 | if (queryString.Length > 1) |
637 | queryString = queryString.Substring(0, queryString.Length - 1); | 633 | queryString = queryString.Substring(0, queryString.Length - 1); |
634 | |||
638 | } | 635 | } |
636 | |||
639 | } | 637 | } |
640 | 638 | ||
641 | //if this machine is behind DNAT/port forwarding, currently this is being | 639 | //if this machine is behind DNAT/port forwarding, currently this is being |
@@ -643,23 +641,34 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
643 | requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"]; | 641 | requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"]; |
644 | requestData.headers["x-path-info"] = pathInfo; | 642 | requestData.headers["x-path-info"] = pathInfo; |
645 | requestData.headers["x-query-string"] = queryString; | 643 | requestData.headers["x-query-string"] = queryString; |
646 | requestData.headers["x-script-url"] = urlData.url; | 644 | requestData.headers["x-script-url"] = url.url; |
647 | 645 | ||
648 | urlData.requests.Add(requestID, requestData); | 646 | //requestData.ev = new ManualResetEvent(false); |
649 | m_RequestMap.Add(requestID, urlData); | 647 | lock (url.requests) |
650 | } | 648 | { |
649 | url.requests.Add(requestID, requestData); | ||
650 | } | ||
651 | lock (m_RequestMap) | ||
652 | { | ||
653 | //add to request map | ||
654 | m_RequestMap.Add(requestID, url); | ||
655 | } | ||
651 | 656 | ||
652 | urlData.engine.PostScriptEvent( | 657 | url.engine.PostScriptEvent(url.itemID, "http_request", new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() }); |
653 | urlData.itemID, | 658 | |
654 | "http_request", | 659 | //send initial response? |
655 | new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() }); | 660 | // Hashtable response = new Hashtable(); |
656 | } | 661 | |
657 | catch (Exception we) | 662 | return; |
658 | { | 663 | |
659 | //Hashtable response = new Hashtable(); | 664 | } |
660 | m_log.Warn("[HttpRequestHandler]: http-in request failed"); | 665 | catch (Exception we) |
661 | m_log.Warn(we.Message); | 666 | { |
662 | m_log.Warn(we.StackTrace); | 667 | //Hashtable response = new Hashtable(); |
668 | m_log.Warn("[HttpRequestHandler]: http-in request failed"); | ||
669 | m_log.Warn(we.Message); | ||
670 | m_log.Warn(we.StackTrace); | ||
671 | } | ||
663 | } | 672 | } |
664 | } | 673 | } |
665 | 674 | ||
@@ -668,4 +677,4 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
668 | ScriptRemoved(itemID); | 677 | ScriptRemoved(itemID); |
669 | } | 678 | } |
670 | } | 679 | } |
671 | } \ No newline at end of file | 680 | } |