aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Scripting
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Scripting')
-rw-r--r--OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs31
-rw-r--r--OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs159
2 files changed, 134 insertions, 56 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs
index d328eb3..9dac6b9 100644
--- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs
+++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs
@@ -382,6 +382,10 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
382 try 382 try
383 { 383 {
384 Request = (HttpWebRequest) WebRequest.Create(Url); 384 Request = (HttpWebRequest) WebRequest.Create(Url);
385
386 //This works around some buggy HTTP Servers like Lighttpd
387 Request.ServicePoint.Expect100Continue = false;
388
385 Request.Method = HttpMethod; 389 Request.Method = HttpMethod;
386 Request.ContentType = HttpMIMEType; 390 Request.ContentType = HttpMIMEType;
387 391
@@ -458,15 +462,36 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
458 462
459 // continue building the string 463 // continue building the string
460 sb.Append(tempString); 464 sb.Append(tempString);
465 if (sb.Length > 2048)
466 break;
461 } 467 }
462 } while (count > 0); // any more data to read? 468 } while (count > 0); // any more data to read?
463 469
464 ResponseBody = sb.ToString(); 470 ResponseBody = sb.ToString().Replace("\r", "");
465 } 471 }
466 catch (Exception e) 472 catch (Exception e)
467 { 473 {
468 Status = (int)OSHttpStatusCode.ClientErrorJoker; 474 if (e is WebException && ((WebException)e).Status == WebExceptionStatus.ProtocolError)
469 ResponseBody = e.Message; 475 {
476 HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response;
477 Status = (int)webRsp.StatusCode;
478 try
479 {
480 using (Stream responseStream = webRsp.GetResponseStream())
481 {
482 ResponseBody = responseStream.GetStreamString();
483 }
484 }
485 catch
486 {
487 ResponseBody = webRsp.StatusDescription;
488 }
489 }
490 else
491 {
492 Status = (int)OSHttpStatusCode.ClientErrorJoker;
493 ResponseBody = e.Message;
494 }
470 495
471 _finished = true; 496 _finished = true;
472 return; 497 return;
diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
index d2cd163..1865ab8 100644
--- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
@@ -61,6 +61,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
61 //public ManualResetEvent ev; 61 //public ManualResetEvent ev;
62 public bool requestDone; 62 public bool requestDone;
63 public int startTime; 63 public int startTime;
64 public bool responseSent;
64 public string uri; 65 public string uri;
65 } 66 }
66 67
@@ -77,7 +78,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
77 new Dictionary<string, UrlData>(); 78 new Dictionary<string, UrlData>();
78 79
79 80
80 private int m_TotalUrls = 100; 81 private int m_TotalUrls = 5000;
81 82
82 private uint https_port = 0; 83 private uint https_port = 0;
83 private IHttpServer m_HttpServer = null; 84 private IHttpServer m_HttpServer = null;
@@ -162,7 +163,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
162 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); 163 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
163 return urlcode; 164 return urlcode;
164 } 165 }
165 string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/"; 166 string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString();
166 167
167 UrlData urlData = new UrlData(); 168 UrlData urlData = new UrlData();
168 urlData.hostID = host.UUID; 169 urlData.hostID = host.UUID;
@@ -171,10 +172,10 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
171 urlData.url = url; 172 urlData.url = url;
172 urlData.urlcode = urlcode; 173 urlData.urlcode = urlcode;
173 urlData.requests = new Dictionary<UUID, RequestData>(); 174 urlData.requests = new Dictionary<UUID, RequestData>();
174 175
175 m_UrlMap[url] = urlData; 176 m_UrlMap[url] = urlData;
176 177
177 string uri = "/lslhttp/" + urlcode.ToString() + "/"; 178 string uri = "/lslhttp/" + urlcode.ToString();
178 179
179 m_HttpServer.AddPollServiceHTTPHandler( 180 m_HttpServer.AddPollServiceHTTPHandler(
180 uri, 181 uri,
@@ -247,12 +248,15 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
247 return; 248 return;
248 } 249 }
249 250
250 foreach (UUID req in data.requests.Keys) 251 lock (m_RequestMap)
251 m_RequestMap.Remove(req); 252 {
252 253 foreach (UUID req in data.requests.Keys)
253 m_log.DebugFormat( 254 m_RequestMap.Remove(req);
254 "[URL MODULE]: Releasing url {0} for {1} in {2}", 255 }
255 url, data.itemID, data.hostID); 256
257// m_log.DebugFormat(
258// "[URL MODULE]: Releasing url {0} for {1} in {2}",
259// url, data.itemID, data.hostID);
256 260
257 RemoveUrl(data); 261 RemoveUrl(data);
258 m_UrlMap.Remove(url); 262 m_UrlMap.Remove(url);
@@ -261,32 +265,42 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
261 265
262 public void HttpResponse(UUID request, int status, string body) 266 public void HttpResponse(UUID request, int status, string body)
263 { 267 {
264 if (m_RequestMap.ContainsKey(request)) 268 lock (m_RequestMap)
265 {
266 UrlData urlData = m_RequestMap[request];
267 urlData.requests[request].responseCode = status;
268 urlData.requests[request].responseBody = body;
269 //urlData.requests[request].ev.Set();
270 urlData.requests[request].requestDone =true;
271 }
272 else
273 { 269 {
274 m_log.Info("[HttpRequestHandler] There is no http-in request with id " + request.ToString()); 270 if (m_RequestMap.ContainsKey(request))
271 {
272 UrlData urlData = m_RequestMap[request];
273 if (!urlData.requests[request].responseSent)
274 {
275 urlData.requests[request].responseCode = status;
276 urlData.requests[request].responseBody = body;
277 //urlData.requests[request].ev.Set();
278 urlData.requests[request].requestDone = true;
279 urlData.requests[request].responseSent = true;
280 }
281 }
282 else
283 {
284 m_log.Info("[HttpRequestHandler] There is no http-in request with id " + request.ToString());
285 }
275 } 286 }
276 } 287 }
277 288
278 public string GetHttpHeader(UUID requestId, string header) 289 public string GetHttpHeader(UUID requestId, string header)
279 { 290 {
280 if (m_RequestMap.ContainsKey(requestId)) 291 lock (m_RequestMap)
281 {
282 UrlData urlData=m_RequestMap[requestId];
283 string value;
284 if (urlData.requests[requestId].headers.TryGetValue(header,out value))
285 return value;
286 }
287 else
288 { 292 {
289 m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId); 293 if (m_RequestMap.ContainsKey(requestId))
294 {
295 UrlData urlData = m_RequestMap[requestId];
296 string value;
297 if (urlData.requests[requestId].headers.TryGetValue(header, out value))
298 return value;
299 }
300 else
301 {
302 m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId);
303 }
290 } 304 }
291 return String.Empty; 305 return String.Empty;
292 } 306 }
@@ -310,8 +324,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
310 { 324 {
311 RemoveUrl(url.Value); 325 RemoveUrl(url.Value);
312 removeURLs.Add(url.Key); 326 removeURLs.Add(url.Key);
313 foreach (UUID req in url.Value.requests.Keys) 327 lock (m_RequestMap)
314 m_RequestMap.Remove(req); 328 {
329 foreach (UUID req in url.Value.requests.Keys)
330 m_RequestMap.Remove(req);
331 }
315 } 332 }
316 } 333 }
317 334
@@ -332,8 +349,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
332 { 349 {
333 RemoveUrl(url.Value); 350 RemoveUrl(url.Value);
334 removeURLs.Add(url.Key); 351 removeURLs.Add(url.Key);
335 foreach (UUID req in url.Value.requests.Keys) 352 lock (m_RequestMap)
336 m_RequestMap.Remove(req); 353 {
354 foreach (UUID req in url.Value.requests.Keys)
355 m_RequestMap.Remove(req);
356 }
337 } 357 }
338 } 358 }
339 359
@@ -352,14 +372,16 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
352 { 372 {
353 Hashtable response = new Hashtable(); 373 Hashtable response = new Hashtable();
354 UrlData url; 374 UrlData url;
375 int startTime = 0;
355 lock (m_RequestMap) 376 lock (m_RequestMap)
356 { 377 {
357 if (!m_RequestMap.ContainsKey(requestID)) 378 if (!m_RequestMap.ContainsKey(requestID))
358 return response; 379 return response;
359 url = m_RequestMap[requestID]; 380 url = m_RequestMap[requestID];
381 startTime = url.requests[requestID].startTime;
360 } 382 }
361 383
362 if (System.Environment.TickCount - url.requests[requestID].startTime > 25000) 384 if (System.Environment.TickCount - startTime > 25000)
363 { 385 {
364 response["int_response_code"] = 500; 386 response["int_response_code"] = 500;
365 response["str_response_string"] = "Script timeout"; 387 response["str_response_string"] = "Script timeout";
@@ -368,9 +390,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
368 response["reusecontext"] = false; 390 response["reusecontext"] = false;
369 391
370 //remove from map 392 //remove from map
371 lock (url) 393 lock (url.requests)
372 { 394 {
373 url.requests.Remove(requestID); 395 url.requests.Remove(requestID);
396 }
397 lock (m_RequestMap)
398 {
374 m_RequestMap.Remove(requestID); 399 m_RequestMap.Remove(requestID);
375 } 400 }
376 401
@@ -392,22 +417,25 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
392 return false; 417 return false;
393 } 418 }
394 url = m_RequestMap[requestID]; 419 url = m_RequestMap[requestID];
420 }
421 lock (url.requests)
422 {
395 if (!url.requests.ContainsKey(requestID)) 423 if (!url.requests.ContainsKey(requestID))
396 { 424 {
397 return false; 425 return false;
398 } 426 }
427 else
428 {
429 if (System.Environment.TickCount - url.requests[requestID].startTime > 25000)
430 {
431 return true;
432 }
433 if (url.requests[requestID].requestDone)
434 return true;
435 else
436 return false;
437 }
399 } 438 }
400
401 if (System.Environment.TickCount-url.requests[requestID].startTime>25000)
402 {
403 return true;
404 }
405
406 if (url.requests[requestID].requestDone)
407 return true;
408 else
409 return false;
410
411 } 439 }
412 private Hashtable GetEvents(UUID requestID, UUID sessionID, string request) 440 private Hashtable GetEvents(UUID requestID, UUID sessionID, string request)
413 { 441 {
@@ -419,9 +447,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
419 if (!m_RequestMap.ContainsKey(requestID)) 447 if (!m_RequestMap.ContainsKey(requestID))
420 return NoEvents(requestID,sessionID); 448 return NoEvents(requestID,sessionID);
421 url = m_RequestMap[requestID]; 449 url = m_RequestMap[requestID];
450 }
451 lock (url.requests)
452 {
422 requestData = url.requests[requestID]; 453 requestData = url.requests[requestID];
423 } 454 }
424 455
425 if (!requestData.requestDone) 456 if (!requestData.requestDone)
426 return NoEvents(requestID,sessionID); 457 return NoEvents(requestID,sessionID);
427 458
@@ -444,14 +475,18 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
444 response["reusecontext"] = false; 475 response["reusecontext"] = false;
445 476
446 //remove from map 477 //remove from map
447 lock (url) 478 lock (url.requests)
448 { 479 {
449 url.requests.Remove(requestID); 480 url.requests.Remove(requestID);
481 }
482 lock (m_RequestMap)
483 {
450 m_RequestMap.Remove(requestID); 484 m_RequestMap.Remove(requestID);
451 } 485 }
452 486
453 return response; 487 return response;
454 } 488 }
489
455 public void HttpRequestHandler(UUID requestID, Hashtable request) 490 public void HttpRequestHandler(UUID requestID, Hashtable request)
456 { 491 {
457 lock (request) 492 lock (request)
@@ -467,8 +502,8 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
467 502
468 int pos1 = uri.IndexOf("/");// /lslhttp 503 int pos1 = uri.IndexOf("/");// /lslhttp
469 int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/ 504 int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/
470 int pos3 = uri.IndexOf("/", pos2 + 1);// /lslhttp/<UUID>/ 505 int pos3 = pos2 + 37; // /lslhttp/urlcode
471 string uri_tmp = uri.Substring(0, pos3 + 1); 506 string uri_tmp = uri.Substring(0, pos3);
472 //HTTP server code doesn't provide us with QueryStrings 507 //HTTP server code doesn't provide us with QueryStrings
473 string pathInfo; 508 string pathInfo;
474 string queryString; 509 string queryString;
@@ -477,10 +512,21 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
477 pathInfo = uri.Substring(pos3); 512 pathInfo = uri.Substring(pos3);
478 513
479 UrlData url = null; 514 UrlData url = null;
515 string urlkey;
480 if (!is_ssl) 516 if (!is_ssl)
481 url = m_UrlMap["http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp]; 517 urlkey = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp;
518 //m_UrlMap[];
482 else 519 else
483 url = m_UrlMap["https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp]; 520 urlkey = "https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp;
521
522 if (m_UrlMap.ContainsKey(urlkey))
523 {
524 url = m_UrlMap[urlkey];
525 }
526 else
527 {
528 m_log.Warn("[HttpRequestHandler]: http-in request failed; no such url: "+urlkey.ToString());
529 }
484 530
485 //for llGetHttpHeader support we need to store original URI here 531 //for llGetHttpHeader support we need to store original URI here
486 //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers 532 //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers
@@ -510,7 +556,14 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
510 if (request.ContainsKey(key)) 556 if (request.ContainsKey(key))
511 { 557 {
512 string val = (String)request[key]; 558 string val = (String)request[key];
513 queryString = queryString + key + "=" + val + "&"; 559 if (key != "")
560 {
561 queryString = queryString + key + "=" + val + "&";
562 }
563 else
564 {
565 queryString = queryString + val + "&";
566 }
514 } 567 }
515 } 568 }
516 if (queryString.Length > 1) 569 if (queryString.Length > 1)