diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Scripting')
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | 20 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs | 152 |
2 files changed, 120 insertions, 52 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs index 43672d1..84ff22b 100644 --- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs +++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | |||
@@ -366,6 +366,10 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
366 | try | 366 | try |
367 | { | 367 | { |
368 | Request = (HttpWebRequest) WebRequest.Create(Url); | 368 | Request = (HttpWebRequest) WebRequest.Create(Url); |
369 | |||
370 | //This works around some buggy HTTP Servers like Lighttpd | ||
371 | Request.ServicePoint.Expect100Continue = false; | ||
372 | |||
369 | Request.Method = HttpMethod; | 373 | Request.Method = HttpMethod; |
370 | Request.ContentType = HttpMIMEType; | 374 | Request.ContentType = HttpMIMEType; |
371 | 375 | ||
@@ -429,10 +433,12 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
429 | 433 | ||
430 | // continue building the string | 434 | // continue building the string |
431 | sb.Append(tempString); | 435 | sb.Append(tempString); |
436 | if (sb.Length > 2048) | ||
437 | break; | ||
432 | } | 438 | } |
433 | } while (count > 0); // any more data to read? | 439 | } while (count > 0); // any more data to read? |
434 | 440 | ||
435 | ResponseBody = sb.ToString(); | 441 | ResponseBody = sb.ToString().Replace("\r", ""); |
436 | } | 442 | } |
437 | catch (Exception e) | 443 | catch (Exception e) |
438 | { | 444 | { |
@@ -440,7 +446,17 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
440 | { | 446 | { |
441 | HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response; | 447 | HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response; |
442 | Status = (int)webRsp.StatusCode; | 448 | Status = (int)webRsp.StatusCode; |
443 | ResponseBody = webRsp.StatusDescription; | 449 | try |
450 | { | ||
451 | using (Stream responseStream = webRsp.GetResponseStream()) | ||
452 | { | ||
453 | ResponseBody = responseStream.GetStreamString(); | ||
454 | } | ||
455 | } | ||
456 | catch | ||
457 | { | ||
458 | ResponseBody = webRsp.StatusDescription; | ||
459 | } | ||
444 | } | 460 | } |
445 | else | 461 | else |
446 | { | 462 | { |
diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs index 7377ceb..458426b 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; |
@@ -156,7 +157,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
156 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); | 157 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); |
157 | return urlcode; | 158 | return urlcode; |
158 | } | 159 | } |
159 | string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/"; | 160 | string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString(); |
160 | 161 | ||
161 | UrlData urlData = new UrlData(); | 162 | UrlData urlData = new UrlData(); |
162 | urlData.hostID = host.UUID; | 163 | urlData.hostID = host.UUID; |
@@ -166,10 +167,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
166 | urlData.urlcode = urlcode; | 167 | urlData.urlcode = urlcode; |
167 | urlData.requests = new Dictionary<UUID, RequestData>(); | 168 | urlData.requests = new Dictionary<UUID, RequestData>(); |
168 | 169 | ||
169 | |||
170 | m_UrlMap[url] = urlData; | 170 | m_UrlMap[url] = urlData; |
171 | 171 | ||
172 | string uri = "/lslhttp/" + urlcode.ToString() + "/"; | 172 | string uri = "/lslhttp/" + urlcode.ToString(); |
173 | 173 | ||
174 | m_HttpServer.AddPollServiceHTTPHandler(uri,HandleHttpPoll, | 174 | m_HttpServer.AddPollServiceHTTPHandler(uri,HandleHttpPoll, |
175 | new PollServiceEventArgs(HttpRequestHandler,HasEvents, GetEvents, NoEvents, | 175 | new PollServiceEventArgs(HttpRequestHandler,HasEvents, GetEvents, NoEvents, |
@@ -234,9 +234,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
234 | return; | 234 | return; |
235 | } | 235 | } |
236 | 236 | ||
237 | foreach (UUID req in data.requests.Keys) | 237 | lock (m_RequestMap) |
238 | m_RequestMap.Remove(req); | 238 | { |
239 | 239 | foreach (UUID req in data.requests.Keys) | |
240 | m_RequestMap.Remove(req); | ||
241 | } | ||
242 | |||
240 | RemoveUrl(data); | 243 | RemoveUrl(data); |
241 | m_UrlMap.Remove(url); | 244 | m_UrlMap.Remove(url); |
242 | } | 245 | } |
@@ -244,32 +247,42 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
244 | 247 | ||
245 | public void HttpResponse(UUID request, int status, string body) | 248 | public void HttpResponse(UUID request, int status, string body) |
246 | { | 249 | { |
247 | if (m_RequestMap.ContainsKey(request)) | 250 | lock (m_RequestMap) |
248 | { | ||
249 | UrlData urlData = m_RequestMap[request]; | ||
250 | urlData.requests[request].responseCode = status; | ||
251 | urlData.requests[request].responseBody = body; | ||
252 | //urlData.requests[request].ev.Set(); | ||
253 | urlData.requests[request].requestDone =true; | ||
254 | } | ||
255 | else | ||
256 | { | 251 | { |
257 | m_log.Info("[HttpRequestHandler] There is no http-in request with id " + request.ToString()); | 252 | if (m_RequestMap.ContainsKey(request)) |
253 | { | ||
254 | UrlData urlData = m_RequestMap[request]; | ||
255 | if (!urlData.requests[request].responseSent) | ||
256 | { | ||
257 | urlData.requests[request].responseCode = status; | ||
258 | urlData.requests[request].responseBody = body; | ||
259 | //urlData.requests[request].ev.Set(); | ||
260 | urlData.requests[request].requestDone = true; | ||
261 | urlData.requests[request].responseSent = true; | ||
262 | } | ||
263 | } | ||
264 | else | ||
265 | { | ||
266 | m_log.Info("[HttpRequestHandler] There is no http-in request with id " + request.ToString()); | ||
267 | } | ||
258 | } | 268 | } |
259 | } | 269 | } |
260 | 270 | ||
261 | public string GetHttpHeader(UUID requestId, string header) | 271 | public string GetHttpHeader(UUID requestId, string header) |
262 | { | 272 | { |
263 | if (m_RequestMap.ContainsKey(requestId)) | 273 | lock (m_RequestMap) |
264 | { | ||
265 | UrlData urlData=m_RequestMap[requestId]; | ||
266 | string value; | ||
267 | if (urlData.requests[requestId].headers.TryGetValue(header,out value)) | ||
268 | return value; | ||
269 | } | ||
270 | else | ||
271 | { | 274 | { |
272 | m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId); | 275 | if (m_RequestMap.ContainsKey(requestId)) |
276 | { | ||
277 | UrlData urlData = m_RequestMap[requestId]; | ||
278 | string value; | ||
279 | if (urlData.requests[requestId].headers.TryGetValue(header, out value)) | ||
280 | return value; | ||
281 | } | ||
282 | else | ||
283 | { | ||
284 | m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId); | ||
285 | } | ||
273 | } | 286 | } |
274 | return String.Empty; | 287 | return String.Empty; |
275 | } | 288 | } |
@@ -291,8 +304,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
291 | { | 304 | { |
292 | RemoveUrl(url.Value); | 305 | RemoveUrl(url.Value); |
293 | removeURLs.Add(url.Key); | 306 | removeURLs.Add(url.Key); |
294 | foreach (UUID req in url.Value.requests.Keys) | 307 | lock (m_RequestMap) |
295 | m_RequestMap.Remove(req); | 308 | { |
309 | foreach (UUID req in url.Value.requests.Keys) | ||
310 | m_RequestMap.Remove(req); | ||
311 | } | ||
296 | } | 312 | } |
297 | } | 313 | } |
298 | 314 | ||
@@ -313,8 +329,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
313 | { | 329 | { |
314 | RemoveUrl(url.Value); | 330 | RemoveUrl(url.Value); |
315 | removeURLs.Add(url.Key); | 331 | removeURLs.Add(url.Key); |
316 | foreach (UUID req in url.Value.requests.Keys) | 332 | lock (m_RequestMap) |
317 | m_RequestMap.Remove(req); | 333 | { |
334 | foreach (UUID req in url.Value.requests.Keys) | ||
335 | m_RequestMap.Remove(req); | ||
336 | } | ||
318 | } | 337 | } |
319 | } | 338 | } |
320 | 339 | ||
@@ -333,14 +352,16 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
333 | { | 352 | { |
334 | Hashtable response = new Hashtable(); | 353 | Hashtable response = new Hashtable(); |
335 | UrlData url; | 354 | UrlData url; |
355 | int startTime = 0; | ||
336 | lock (m_RequestMap) | 356 | lock (m_RequestMap) |
337 | { | 357 | { |
338 | if (!m_RequestMap.ContainsKey(requestID)) | 358 | if (!m_RequestMap.ContainsKey(requestID)) |
339 | return response; | 359 | return response; |
340 | url = m_RequestMap[requestID]; | 360 | url = m_RequestMap[requestID]; |
361 | startTime = url.requests[requestID].startTime; | ||
341 | } | 362 | } |
342 | 363 | ||
343 | if (System.Environment.TickCount - url.requests[requestID].startTime > 25000) | 364 | if (System.Environment.TickCount - startTime > 25000) |
344 | { | 365 | { |
345 | response["int_response_code"] = 500; | 366 | response["int_response_code"] = 500; |
346 | response["str_response_string"] = "Script timeout"; | 367 | response["str_response_string"] = "Script timeout"; |
@@ -349,9 +370,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
349 | response["reusecontext"] = false; | 370 | response["reusecontext"] = false; |
350 | 371 | ||
351 | //remove from map | 372 | //remove from map |
352 | lock (url) | 373 | lock (url.requests) |
353 | { | 374 | { |
354 | url.requests.Remove(requestID); | 375 | url.requests.Remove(requestID); |
376 | } | ||
377 | lock (m_RequestMap) | ||
378 | { | ||
355 | m_RequestMap.Remove(requestID); | 379 | m_RequestMap.Remove(requestID); |
356 | } | 380 | } |
357 | 381 | ||
@@ -373,22 +397,25 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
373 | return false; | 397 | return false; |
374 | } | 398 | } |
375 | url = m_RequestMap[requestID]; | 399 | url = m_RequestMap[requestID]; |
400 | } | ||
401 | lock (url.requests) | ||
402 | { | ||
376 | if (!url.requests.ContainsKey(requestID)) | 403 | if (!url.requests.ContainsKey(requestID)) |
377 | { | 404 | { |
378 | return false; | 405 | return false; |
379 | } | 406 | } |
407 | else | ||
408 | { | ||
409 | if (System.Environment.TickCount - url.requests[requestID].startTime > 25000) | ||
410 | { | ||
411 | return true; | ||
412 | } | ||
413 | if (url.requests[requestID].requestDone) | ||
414 | return true; | ||
415 | else | ||
416 | return false; | ||
417 | } | ||
380 | } | 418 | } |
381 | |||
382 | if (System.Environment.TickCount-url.requests[requestID].startTime>25000) | ||
383 | { | ||
384 | return true; | ||
385 | } | ||
386 | |||
387 | if (url.requests[requestID].requestDone) | ||
388 | return true; | ||
389 | else | ||
390 | return false; | ||
391 | |||
392 | } | 419 | } |
393 | private Hashtable GetEvents(UUID requestID, UUID sessionID, string request) | 420 | private Hashtable GetEvents(UUID requestID, UUID sessionID, string request) |
394 | { | 421 | { |
@@ -400,9 +427,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
400 | if (!m_RequestMap.ContainsKey(requestID)) | 427 | if (!m_RequestMap.ContainsKey(requestID)) |
401 | return NoEvents(requestID,sessionID); | 428 | return NoEvents(requestID,sessionID); |
402 | url = m_RequestMap[requestID]; | 429 | url = m_RequestMap[requestID]; |
430 | } | ||
431 | lock (url.requests) | ||
432 | { | ||
403 | requestData = url.requests[requestID]; | 433 | requestData = url.requests[requestID]; |
404 | } | 434 | } |
405 | 435 | ||
406 | if (!requestData.requestDone) | 436 | if (!requestData.requestDone) |
407 | return NoEvents(requestID,sessionID); | 437 | return NoEvents(requestID,sessionID); |
408 | 438 | ||
@@ -425,14 +455,18 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
425 | response["reusecontext"] = false; | 455 | response["reusecontext"] = false; |
426 | 456 | ||
427 | //remove from map | 457 | //remove from map |
428 | lock (url) | 458 | lock (url.requests) |
429 | { | 459 | { |
430 | url.requests.Remove(requestID); | 460 | url.requests.Remove(requestID); |
461 | } | ||
462 | lock (m_RequestMap) | ||
463 | { | ||
431 | m_RequestMap.Remove(requestID); | 464 | m_RequestMap.Remove(requestID); |
432 | } | 465 | } |
433 | 466 | ||
434 | return response; | 467 | return response; |
435 | } | 468 | } |
469 | |||
436 | public void HttpRequestHandler(UUID requestID, Hashtable request) | 470 | public void HttpRequestHandler(UUID requestID, Hashtable request) |
437 | { | 471 | { |
438 | lock (request) | 472 | lock (request) |
@@ -448,8 +482,8 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
448 | 482 | ||
449 | int pos1 = uri.IndexOf("/");// /lslhttp | 483 | int pos1 = uri.IndexOf("/");// /lslhttp |
450 | int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/ | 484 | int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/ |
451 | int pos3 = uri.IndexOf("/", pos2 + 1);// /lslhttp/<UUID>/ | 485 | int pos3 = pos2 + 37; // /lslhttp/urlcode |
452 | string uri_tmp = uri.Substring(0, pos3 + 1); | 486 | string uri_tmp = uri.Substring(0, pos3); |
453 | //HTTP server code doesn't provide us with QueryStrings | 487 | //HTTP server code doesn't provide us with QueryStrings |
454 | string pathInfo; | 488 | string pathInfo; |
455 | string queryString; | 489 | string queryString; |
@@ -458,10 +492,21 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
458 | pathInfo = uri.Substring(pos3); | 492 | pathInfo = uri.Substring(pos3); |
459 | 493 | ||
460 | UrlData url = null; | 494 | UrlData url = null; |
495 | string urlkey; | ||
461 | if (!is_ssl) | 496 | if (!is_ssl) |
462 | url = m_UrlMap["http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp]; | 497 | urlkey = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp; |
498 | //m_UrlMap[]; | ||
463 | else | 499 | else |
464 | url = m_UrlMap["https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp]; | 500 | urlkey = "https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp; |
501 | |||
502 | if (m_UrlMap.ContainsKey(urlkey)) | ||
503 | { | ||
504 | url = m_UrlMap[urlkey]; | ||
505 | } | ||
506 | else | ||
507 | { | ||
508 | m_log.Warn("[HttpRequestHandler]: http-in request failed; no such url: "+urlkey.ToString()); | ||
509 | } | ||
465 | 510 | ||
466 | //for llGetHttpHeader support we need to store original URI here | 511 | //for llGetHttpHeader support we need to store original URI here |
467 | //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers | 512 | //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers |
@@ -491,7 +536,14 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
491 | if (request.ContainsKey(key)) | 536 | if (request.ContainsKey(key)) |
492 | { | 537 | { |
493 | string val = (String)request[key]; | 538 | string val = (String)request[key]; |
494 | queryString = queryString + key + "=" + val + "&"; | 539 | if (key != "") |
540 | { | ||
541 | queryString = queryString + key + "=" + val + "&"; | ||
542 | } | ||
543 | else | ||
544 | { | ||
545 | queryString = queryString + val + "&"; | ||
546 | } | ||
495 | } | 547 | } |
496 | } | 548 | } |
497 | if (queryString.Length > 1) | 549 | if (queryString.Length > 1) |