aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs402
1 files changed, 202 insertions, 200 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
index a654477..da59eab 100644
--- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
@@ -42,39 +42,13 @@ using OpenSim.Region.Framework.Scenes;
42 42
43namespace OpenSim.Region.CoreModules.Scripting.LSLHttp 43namespace 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;
79 } 53 }
80 54
@@ -89,6 +63,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
89 //public ManualResetEvent ev; 63 //public ManualResetEvent ev;
90 public bool requestDone; 64 public bool requestDone;
91 public int startTime; 65 public int startTime;
66 public bool responseSent;
92 public string uri; 67 public string uri;
93 } 68 }
94 69
@@ -102,25 +77,16 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
102 LogManager.GetLogger( 77 LogManager.GetLogger(
103 MethodBase.GetCurrentMethod().DeclaringType); 78 MethodBase.GetCurrentMethod().DeclaringType);
104 79
105 /// <summary> 80 private Dictionary<UUID, UrlData> m_RequestMap =
106 /// Indexs the URL request metadata (which script requested it, outstanding requests, etc.) by the request ID 81 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 82
115 /// <summary> 83 private Dictionary<string, UrlData> m_UrlMap =
116 /// Indexs the URL request metadata (which script requested it, outstanding requests, etc.) by the full URL 84 new Dictionary<string, UrlData>();
117 /// </summary>
118 private Dictionary<string, UrlData> m_UrlMap = new Dictionary<string, UrlData>();
119 85
120 /// <summary> 86 /// <summary>
121 /// Maximum number of external urls that can be set up by this module. 87 /// Maximum number of external urls that can be set up by this module.
122 /// </summary> 88 /// </summary>
123 private int m_TotalUrls = 100; 89 private int m_TotalUrls = 15000;
124 90
125 private uint https_port = 0; 91 private uint https_port = 0;
126 private IHttpServer m_HttpServer = null; 92 private IHttpServer m_HttpServer = null;
@@ -146,9 +112,10 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
146 { 112 {
147 m_ExternalHostNameForLSL = config.Configs["Network"].GetString("ExternalHostNameForLSL", System.Environment.MachineName); 113 m_ExternalHostNameForLSL = config.Configs["Network"].GetString("ExternalHostNameForLSL", System.Environment.MachineName);
148 bool ssl_enabled = config.Configs["Network"].GetBoolean("https_listener",false); 114 bool ssl_enabled = config.Configs["Network"].GetBoolean("https_listener",false);
149
150 if (ssl_enabled) 115 if (ssl_enabled)
116 {
151 https_port = (uint) config.Configs["Network"].GetInt("https_port",0); 117 https_port = (uint) config.Configs["Network"].GetInt("https_port",0);
118 }
152 119
153 IConfig llFunctionsConfig = config.Configs["LL-Functions"]; 120 IConfig llFunctionsConfig = config.Configs["LL-Functions"];
154 121
@@ -209,7 +176,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
209 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); 176 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
210 return urlcode; 177 return urlcode;
211 } 178 }
212 string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/"; 179 string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString();
213 180
214 UrlData urlData = new UrlData(); 181 UrlData urlData = new UrlData();
215 urlData.hostID = host.UUID; 182 urlData.hostID = host.UUID;
@@ -218,18 +185,18 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
218 urlData.url = url; 185 urlData.url = url;
219 urlData.urlcode = urlcode; 186 urlData.urlcode = urlcode;
220 urlData.requests = new Dictionary<UUID, RequestData>(); 187 urlData.requests = new Dictionary<UUID, RequestData>();
221 188
222 m_UrlMap[url] = urlData; 189 m_UrlMap[url] = urlData;
223 190
224 string uri = "/lslhttp/" + urlcode.ToString() + "/"; 191 string uri = "/lslhttp/" + urlcode.ToString();
225 192
226 m_HttpServer.AddPollServiceHTTPHandler( 193 PollServiceEventArgs args = new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode, 25000);
227 uri, 194 args.Type = PollServiceEventArgs.EventType.LslHttp;
228 new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode)); 195 m_HttpServer.AddPollServiceHTTPHandler(uri, args);
229 196
230 m_log.DebugFormat( 197// m_log.DebugFormat(
231 "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}", 198// "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}",
232 uri, itemID, host.Name, host.LocalId); 199// uri, itemID, host.Name, host.LocalId);
233 200
234 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); 201 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
235 } 202 }
@@ -254,7 +221,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
254 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); 221 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
255 return urlcode; 222 return urlcode;
256 } 223 }
257 string url = "https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/"; 224 string url = "https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString();
258 225
259 UrlData urlData = new UrlData(); 226 UrlData urlData = new UrlData();
260 urlData.hostID = host.UUID; 227 urlData.hostID = host.UUID;
@@ -264,17 +231,18 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
264 urlData.urlcode = urlcode; 231 urlData.urlcode = urlcode;
265 urlData.requests = new Dictionary<UUID, RequestData>(); 232 urlData.requests = new Dictionary<UUID, RequestData>();
266 233
234
267 m_UrlMap[url] = urlData; 235 m_UrlMap[url] = urlData;
268 236
269 string uri = "/lslhttps/" + urlcode.ToString() + "/"; 237 string uri = "/lslhttps/" + urlcode.ToString();
270 238
271 m_HttpsServer.AddPollServiceHTTPHandler( 239 PollServiceEventArgs args = new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode, 25000);
272 uri, 240 args.Type = PollServiceEventArgs.EventType.LslHttp;
273 new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode)); 241 m_HttpsServer.AddPollServiceHTTPHandler(uri, args);
274 242
275 m_log.DebugFormat( 243// m_log.DebugFormat(
276 "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}", 244// "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}",
277 uri, itemID, host.Name, host.LocalId); 245// uri, itemID, host.Name, host.LocalId);
278 246
279 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); 247 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
280 } 248 }
@@ -293,12 +261,15 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
293 return; 261 return;
294 } 262 }
295 263
296 foreach (UUID req in data.requests.Keys) 264 lock (m_RequestMap)
297 m_RequestMap.Remove(req); 265 {
298 266 foreach (UUID req in data.requests.Keys)
299 m_log.DebugFormat( 267 m_RequestMap.Remove(req);
300 "[URL MODULE]: Releasing url {0} for {1} in {2}", 268 }
301 url, data.itemID, data.hostID); 269
270// m_log.DebugFormat(
271// "[URL MODULE]: Releasing url {0} for {1} in {2}",
272// url, data.itemID, data.hostID);
302 273
303 RemoveUrl(data); 274 RemoveUrl(data);
304 m_UrlMap.Remove(url); 275 m_UrlMap.Remove(url);
@@ -323,15 +294,19 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
323 294
324 public void HttpResponse(UUID request, int status, string body) 295 public void HttpResponse(UUID request, int status, string body)
325 { 296 {
326 lock (m_UrlMap) 297 lock (m_RequestMap)
327 { 298 {
328 if (m_RequestMap.ContainsKey(request)) 299 if (m_RequestMap.ContainsKey(request))
329 { 300 {
330 UrlData urlData = m_RequestMap[request]; 301 UrlData urlData = m_RequestMap[request];
331 urlData.requests[request].responseCode = status; 302 if (!urlData.requests[request].responseSent)
332 urlData.requests[request].responseBody = body; 303 {
333 //urlData.requests[request].ev.Set(); 304 urlData.requests[request].responseCode = status;
334 urlData.requests[request].requestDone =true; 305 urlData.requests[request].responseBody = body;
306 //urlData.requests[request].ev.Set();
307 urlData.requests[request].requestDone = true;
308 urlData.requests[request].responseSent = true;
309 }
335 } 310 }
336 else 311 else
337 { 312 {
@@ -342,7 +317,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
342 317
343 public string GetHttpHeader(UUID requestId, string header) 318 public string GetHttpHeader(UUID requestId, string header)
344 { 319 {
345 lock (m_UrlMap) 320 lock (m_RequestMap)
346 { 321 {
347 if (m_RequestMap.ContainsKey(requestId)) 322 if (m_RequestMap.ContainsKey(requestId))
348 { 323 {
@@ -356,14 +331,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
356 m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId); 331 m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId);
357 } 332 }
358 } 333 }
359
360 return String.Empty; 334 return String.Empty;
361 } 335 }
362 336
363 public int GetFreeUrls() 337 public int GetFreeUrls()
364 { 338 {
365 lock (m_UrlMap) 339 return m_TotalUrls - m_UrlMap.Count;
366 return m_TotalUrls - m_UrlMap.Count;
367 } 340 }
368 341
369 public void ScriptRemoved(UUID itemID) 342 public void ScriptRemoved(UUID itemID)
@@ -380,8 +353,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
380 { 353 {
381 RemoveUrl(url.Value); 354 RemoveUrl(url.Value);
382 removeURLs.Add(url.Key); 355 removeURLs.Add(url.Key);
383 foreach (UUID req in url.Value.requests.Keys) 356 lock (m_RequestMap)
384 m_RequestMap.Remove(req); 357 {
358 foreach (UUID req in url.Value.requests.Keys)
359 m_RequestMap.Remove(req);
360 }
385 } 361 }
386 } 362 }
387 363
@@ -402,9 +378,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
402 { 378 {
403 RemoveUrl(url.Value); 379 RemoveUrl(url.Value);
404 removeURLs.Add(url.Key); 380 removeURLs.Add(url.Key);
405 381 lock (m_RequestMap)
406 foreach (UUID req in url.Value.requests.Keys) 382 {
407 m_RequestMap.Remove(req); 383 foreach (UUID req in url.Value.requests.Keys)
384 m_RequestMap.Remove(req);
385 }
408 } 386 }
409 } 387 }
410 388
@@ -413,123 +391,125 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
413 } 391 }
414 } 392 }
415 393
394
416 private void RemoveUrl(UrlData data) 395 private void RemoveUrl(UrlData data)
417 { 396 {
418 m_HttpServer.RemoveHTTPHandler("", "/lslhttp/" + data.urlcode.ToString() + "/"); 397 m_HttpServer.RemoveHTTPHandler("", "/lslhttp/"+data.urlcode.ToString()+"/");
419 } 398 }
420 399
421 private Hashtable NoEvents(UUID requestID, UUID sessionID) 400 private Hashtable NoEvents(UUID requestID, UUID sessionID)
422 { 401 {
423 Hashtable response = new Hashtable(); 402 Hashtable response = new Hashtable();
424 UrlData urlData; 403 UrlData url;
425 404 int startTime = 0;
426 lock (m_UrlMap) 405 lock (m_RequestMap)
427 { 406 {
428 // We need to return a 404 here in case the request URL was removed at exactly the same time that a
429 // request was made. In this case, the request thread can outrace llRemoveURL() and still be polling
430 // for the request ID.
431 if (!m_RequestMap.ContainsKey(requestID)) 407 if (!m_RequestMap.ContainsKey(requestID))
432 {
433 response["int_response_code"] = 404;
434 response["str_response_string"] = "";
435 response["keepalive"] = false;
436 response["reusecontext"] = false;
437
438 return response; 408 return response;
439 } 409 url = m_RequestMap[requestID];
410 startTime = url.requests[requestID].startTime;
411 }
440 412
441 urlData = m_RequestMap[requestID]; 413 if (System.Environment.TickCount - startTime > 25000)
414 {
415 response["int_response_code"] = 500;
416 response["str_response_string"] = "Script timeout";
417 response["content_type"] = "text/plain";
418 response["keepalive"] = false;
419 response["reusecontext"] = false;
442 420
443 if (System.Environment.TickCount - urlData.requests[requestID].startTime > 25000) 421 //remove from map
422 lock (url.requests)
423 {
424 url.requests.Remove(requestID);
425 }
426 lock (m_RequestMap)
444 { 427 {
445 response["int_response_code"] = 500;
446 response["str_response_string"] = "Script timeout";
447 response["content_type"] = "text/plain";
448 response["keepalive"] = false;
449 response["reusecontext"] = false;
450
451 //remove from map
452 urlData.requests.Remove(requestID);
453 m_RequestMap.Remove(requestID); 428 m_RequestMap.Remove(requestID);
454
455 return response;
456 } 429 }
430
431 return response;
457 } 432 }
458 433
434
459 return response; 435 return response;
460 } 436 }
461 437
462 private bool HasEvents(UUID requestID, UUID sessionID) 438 private bool HasEvents(UUID requestID, UUID sessionID)
463 { 439 {
464 lock (m_UrlMap) 440 UrlData url=null;
441
442 lock (m_RequestMap)
465 { 443 {
466 // We return true here because an external URL request that happened at the same time as an llRemoveURL()
467 // can still make it through to HttpRequestHandler(). That will return without setting up a request
468 // when it detects that the URL has been removed. The poller, however, will continue to ask for
469 // events for that request, so here we will signal that there are events and in GetEvents we will
470 // return a 404.
471 if (!m_RequestMap.ContainsKey(requestID)) 444 if (!m_RequestMap.ContainsKey(requestID))
472 { 445 {
473 return true; 446 return false;
474 } 447 }
475 448 url = m_RequestMap[requestID];
476 UrlData urlData = m_RequestMap[requestID]; 449 }
477 450 lock (url.requests)
478 if (!urlData.requests.ContainsKey(requestID)) 451 {
452 if (!url.requests.ContainsKey(requestID))
479 { 453 {
480 return true; 454 return false;
481 } 455 }
482 456 else
483 // Trigger return of timeout response.
484 if (System.Environment.TickCount - urlData.requests[requestID].startTime > 25000)
485 { 457 {
486 return true; 458 if (System.Environment.TickCount - url.requests[requestID].startTime > 25000)
459 {
460 return true;
461 }
462 if (url.requests[requestID].requestDone)
463 return true;
464 else
465 return false;
487 } 466 }
488
489 return urlData.requests[requestID].requestDone;
490 } 467 }
491 } 468 }
492 469 private Hashtable GetEvents(UUID requestID, UUID sessionID)
493 private Hashtable GetEvents(UUID requestID, UUID sessionID, string request)
494 { 470 {
495 Hashtable response; 471 UrlData url = null;
472 RequestData requestData = null;
496 473
497 lock (m_UrlMap) 474 lock (m_RequestMap)
498 { 475 {
499 UrlData url = null;
500 RequestData requestData = null;
501
502 if (!m_RequestMap.ContainsKey(requestID)) 476 if (!m_RequestMap.ContainsKey(requestID))
503 return NoEvents(requestID, sessionID); 477 return NoEvents(requestID,sessionID);
504
505 url = m_RequestMap[requestID]; 478 url = m_RequestMap[requestID];
479 }
480 lock (url.requests)
481 {
506 requestData = url.requests[requestID]; 482 requestData = url.requests[requestID];
483 }
484
485 if (!requestData.requestDone)
486 return NoEvents(requestID,sessionID);
487
488 Hashtable response = new Hashtable();
507 489
508 if (!requestData.requestDone) 490 if (System.Environment.TickCount - requestData.startTime > 25000)
509 return NoEvents(requestID, sessionID); 491 {
510 492 response["int_response_code"] = 500;
511 response = new Hashtable(); 493 response["str_response_string"] = "Script timeout";
512 494 response["content_type"] = "text/plain";
513 if (System.Environment.TickCount - requestData.startTime > 25000)
514 {
515 response["int_response_code"] = 500;
516 response["str_response_string"] = "Script timeout";
517 response["content_type"] = "text/plain";
518 response["keepalive"] = false;
519 response["reusecontext"] = false;
520 return response;
521 }
522
523 //put response
524 response["int_response_code"] = requestData.responseCode;
525 response["str_response_string"] = requestData.responseBody;
526 response["content_type"] = requestData.responseType;
527 // response["content_type"] = "text/plain";
528 response["keepalive"] = false; 495 response["keepalive"] = false;
529 response["reusecontext"] = false; 496 response["reusecontext"] = false;
530 497 return response;
531 //remove from map 498 }
499 //put response
500 response["int_response_code"] = requestData.responseCode;
501 response["str_response_string"] = requestData.responseBody;
502 response["content_type"] = "text/plain";
503 response["keepalive"] = false;
504 response["reusecontext"] = false;
505
506 //remove from map
507 lock (url.requests)
508 {
532 url.requests.Remove(requestID); 509 url.requests.Remove(requestID);
510 }
511 lock (m_RequestMap)
512 {
533 m_RequestMap.Remove(requestID); 513 m_RequestMap.Remove(requestID);
534 } 514 }
535 515
@@ -538,41 +518,45 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
538 518
539 public void HttpRequestHandler(UUID requestID, Hashtable request) 519 public void HttpRequestHandler(UUID requestID, Hashtable request)
540 { 520 {
541 string uri = request["uri"].ToString(); 521 lock (request)
542 bool is_ssl = uri.Contains("lslhttps");
543
544 try
545 { 522 {
546 Hashtable headers = (Hashtable)request["headers"]; 523 string uri = request["uri"].ToString();
547 524 bool is_ssl = uri.Contains("lslhttps");
548// string uri_full = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/";
549 525
550 int pos1 = uri.IndexOf("/");// /lslhttp 526 try
551 int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/
552 int pos3 = uri.IndexOf("/", pos2 + 1);// /lslhttp/<UUID>/
553 string uri_tmp = uri.Substring(0, pos3 + 1);
554 //HTTP server code doesn't provide us with QueryStrings
555 string pathInfo;
556 string queryString;
557 queryString = "";
558
559 pathInfo = uri.Substring(pos3);
560
561 UrlData urlData = null;
562
563 lock (m_UrlMap)
564 { 527 {
565 string url; 528 Hashtable headers = (Hashtable)request["headers"];
529
530// string uri_full = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/";
566 531
567 if (is_ssl) 532 int pos1 = uri.IndexOf("/");// /lslhttp
568 url = "https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp; 533 int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/
534 int pos3 = pos2 + 37; // /lslhttp/urlcode
535 string uri_tmp = uri.Substring(0, pos3);
536 //HTTP server code doesn't provide us with QueryStrings
537 string pathInfo;
538 string queryString;
539 queryString = "";
540
541 pathInfo = uri.Substring(pos3);
542
543 UrlData url = null;
544 string urlkey;
545 if (!is_ssl)
546 urlkey = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp;
547 //m_UrlMap[];
569 else 548 else
570 url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp; 549 urlkey = "https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp;
571 550
572 // Avoid a race - the request URL may have been released via llRequestUrl() whilst this 551 if (m_UrlMap.ContainsKey(urlkey))
573 // request was being processed. 552 {
574 if (!m_UrlMap.TryGetValue(url, out urlData)) 553 url = m_UrlMap[urlkey];
554 }
555 else
556 {
557 //m_log.Warn("[HttpRequestHandler]: http-in request failed; no such url: "+urlkey.ToString());
575 return; 558 return;
559 }
576 560
577 //for llGetHttpHeader support we need to store original URI here 561 //for llGetHttpHeader support we need to store original URI here
578 //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers 562 //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers
@@ -592,7 +576,6 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
592 string value = (string)header.Value; 576 string value = (string)header.Value;
593 requestData.headers.Add(key, value); 577 requestData.headers.Add(key, value);
594 } 578 }
595
596 foreach (DictionaryEntry de in request) 579 foreach (DictionaryEntry de in request)
597 { 580 {
598 if (de.Key.ToString() == "querystringkeys") 581 if (de.Key.ToString() == "querystringkeys")
@@ -603,13 +586,21 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
603 if (request.ContainsKey(key)) 586 if (request.ContainsKey(key))
604 { 587 {
605 string val = (String)request[key]; 588 string val = (String)request[key];
606 queryString = queryString + key + "=" + val + "&"; 589 if (key != "")
590 {
591 queryString = queryString + key + "=" + val + "&";
592 }
593 else
594 {
595 queryString = queryString + val + "&";
596 }
607 } 597 }
608 } 598 }
609
610 if (queryString.Length > 1) 599 if (queryString.Length > 1)
611 queryString = queryString.Substring(0, queryString.Length - 1); 600 queryString = queryString.Substring(0, queryString.Length - 1);
601
612 } 602 }
603
613 } 604 }
614 605
615 //if this machine is behind DNAT/port forwarding, currently this is being 606 //if this machine is behind DNAT/port forwarding, currently this is being
@@ -617,23 +608,34 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
617 requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"]; 608 requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"];
618 requestData.headers["x-path-info"] = pathInfo; 609 requestData.headers["x-path-info"] = pathInfo;
619 requestData.headers["x-query-string"] = queryString; 610 requestData.headers["x-query-string"] = queryString;
620 requestData.headers["x-script-url"] = urlData.url; 611 requestData.headers["x-script-url"] = url.url;
621 612
622 urlData.requests.Add(requestID, requestData); 613 //requestData.ev = new ManualResetEvent(false);
623 m_RequestMap.Add(requestID, urlData); 614 lock (url.requests)
624 } 615 {
616 url.requests.Add(requestID, requestData);
617 }
618 lock (m_RequestMap)
619 {
620 //add to request map
621 m_RequestMap.Add(requestID, url);
622 }
625 623
626 urlData.engine.PostScriptEvent( 624 url.engine.PostScriptEvent(url.itemID, "http_request", new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() });
627 urlData.itemID, 625
628 "http_request", 626 //send initial response?
629 new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() }); 627// Hashtable response = new Hashtable();
630 } 628
631 catch (Exception we) 629 return;
632 { 630
633 //Hashtable response = new Hashtable(); 631 }
634 m_log.Warn("[HttpRequestHandler]: http-in request failed"); 632 catch (Exception we)
635 m_log.Warn(we.Message); 633 {
636 m_log.Warn(we.StackTrace); 634 //Hashtable response = new Hashtable();
635 m_log.Warn("[HttpRequestHandler]: http-in request failed");
636 m_log.Warn(we.Message);
637 m_log.Warn(we.StackTrace);
638 }
637 } 639 }
638 } 640 }
639 641
@@ -642,4 +644,4 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
642 ScriptRemoved(itemID); 644 ScriptRemoved(itemID);
643 } 645 }
644 } 646 }
645} \ No newline at end of file 647}