diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Scripting')
5 files changed, 410 insertions, 313 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs index 6793fc8..6eb25ef 100644 --- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs +++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | |||
@@ -28,15 +28,12 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.IO; | 30 | using System.IO; |
31 | using System.Linq; | ||
32 | using System.Net; | 31 | using System.Net; |
33 | using System.Net.Mail; | 32 | using System.Net.Mail; |
34 | using System.Net.Security; | 33 | using System.Net.Security; |
35 | using System.Reflection; | ||
36 | using System.Text; | 34 | using System.Text; |
37 | using System.Threading; | 35 | using System.Threading; |
38 | using System.Security.Cryptography.X509Certificates; | 36 | using System.Security.Cryptography.X509Certificates; |
39 | using log4net; | ||
40 | using Nini.Config; | 37 | using Nini.Config; |
41 | using OpenMetaverse; | 38 | using OpenMetaverse; |
42 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
@@ -45,6 +42,7 @@ using OpenSim.Framework.Servers.HttpServer; | |||
45 | using OpenSim.Region.Framework.Interfaces; | 42 | using OpenSim.Region.Framework.Interfaces; |
46 | using OpenSim.Region.Framework.Scenes; | 43 | using OpenSim.Region.Framework.Scenes; |
47 | using Mono.Addins; | 44 | using Mono.Addins; |
45 | using Amib.Threading; | ||
48 | 46 | ||
49 | /***************************************************** | 47 | /***************************************************** |
50 | * | 48 | * |
@@ -105,6 +103,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
105 | private Dictionary<UUID, HttpRequestClass> m_pendingRequests; | 103 | private Dictionary<UUID, HttpRequestClass> m_pendingRequests; |
106 | private Scene m_scene; | 104 | private Scene m_scene; |
107 | // private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>(); | 105 | // private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>(); |
106 | public static SmartThreadPool ThreadPool = null; | ||
108 | 107 | ||
109 | public HttpRequestModule() | 108 | public HttpRequestModule() |
110 | { | 109 | { |
@@ -253,29 +252,18 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
253 | return reqID; | 252 | return reqID; |
254 | } | 253 | } |
255 | 254 | ||
256 | public void StopHttpRequestsForScript(UUID id) | 255 | public void StopHttpRequest(uint m_localID, UUID m_itemID) |
257 | { | 256 | { |
258 | if (m_pendingRequests != null) | 257 | if (m_pendingRequests != null) |
259 | { | 258 | { |
260 | List<UUID> keysToRemove = null; | ||
261 | |||
262 | lock (HttpListLock) | 259 | lock (HttpListLock) |
263 | { | 260 | { |
264 | foreach (HttpRequestClass req in m_pendingRequests.Values) | 261 | HttpRequestClass tmpReq; |
262 | if (m_pendingRequests.TryGetValue(m_itemID, out tmpReq)) | ||
265 | { | 263 | { |
266 | if (req.ItemID == id) | 264 | tmpReq.Stop(); |
267 | { | 265 | m_pendingRequests.Remove(m_itemID); |
268 | req.Stop(); | ||
269 | |||
270 | if (keysToRemove == null) | ||
271 | keysToRemove = new List<UUID>(); | ||
272 | |||
273 | keysToRemove.Add(req.ReqID); | ||
274 | } | ||
275 | } | 266 | } |
276 | |||
277 | if (keysToRemove != null) | ||
278 | keysToRemove.ForEach(keyToRemove => m_pendingRequests.Remove(keyToRemove)); | ||
279 | } | 267 | } |
280 | } | 268 | } |
281 | } | 269 | } |
@@ -293,13 +281,19 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
293 | { | 281 | { |
294 | lock (HttpListLock) | 282 | lock (HttpListLock) |
295 | { | 283 | { |
296 | foreach (HttpRequestClass req in m_pendingRequests.Values) | 284 | foreach (UUID luid in m_pendingRequests.Keys) |
297 | { | 285 | { |
298 | if (req.Finished) | 286 | HttpRequestClass tmpReq; |
299 | return req; | 287 | |
288 | if (m_pendingRequests.TryGetValue(luid, out tmpReq)) | ||
289 | { | ||
290 | if (tmpReq.Finished) | ||
291 | { | ||
292 | return tmpReq; | ||
293 | } | ||
294 | } | ||
300 | } | 295 | } |
301 | } | 296 | } |
302 | |||
303 | return null; | 297 | return null; |
304 | } | 298 | } |
305 | 299 | ||
@@ -326,7 +320,30 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
326 | m_proxyurl = config.Configs["Startup"].GetString("HttpProxy"); | 320 | m_proxyurl = config.Configs["Startup"].GetString("HttpProxy"); |
327 | m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions"); | 321 | m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions"); |
328 | 322 | ||
323 | int maxThreads = 50; | ||
324 | |||
325 | IConfig httpConfig = config.Configs["HttpRequestModule"]; | ||
326 | if (httpConfig != null) | ||
327 | { | ||
328 | maxThreads = httpConfig.GetInt("MaxPoolThreads", maxThreads); | ||
329 | } | ||
330 | |||
329 | m_pendingRequests = new Dictionary<UUID, HttpRequestClass>(); | 331 | m_pendingRequests = new Dictionary<UUID, HttpRequestClass>(); |
332 | |||
333 | // First instance sets this up for all sims | ||
334 | if (ThreadPool == null) | ||
335 | { | ||
336 | STPStartInfo startInfo = new STPStartInfo(); | ||
337 | startInfo.IdleTimeout = 20000; | ||
338 | startInfo.MaxWorkerThreads = maxThreads; | ||
339 | startInfo.MinWorkerThreads = 5; | ||
340 | startInfo.ThreadPriority = ThreadPriority.BelowNormal; | ||
341 | startInfo.StartSuspended = true; | ||
342 | |||
343 | ThreadPool = new SmartThreadPool(startInfo); | ||
344 | |||
345 | ThreadPool.Start(); | ||
346 | } | ||
330 | } | 347 | } |
331 | 348 | ||
332 | public void AddRegion(Scene scene) | 349 | public void AddRegion(Scene scene) |
@@ -370,8 +387,6 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
370 | 387 | ||
371 | public class HttpRequestClass: IServiceRequest | 388 | public class HttpRequestClass: IServiceRequest |
372 | { | 389 | { |
373 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
374 | |||
375 | // Constants for parameters | 390 | // Constants for parameters |
376 | // public const int HTTP_BODY_MAXLENGTH = 2; | 391 | // public const int HTTP_BODY_MAXLENGTH = 2; |
377 | // public const int HTTP_METHOD = 0; | 392 | // public const int HTTP_METHOD = 0; |
@@ -392,6 +407,8 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
392 | public string HttpMIMEType = "text/plain;charset=utf-8"; | 407 | public string HttpMIMEType = "text/plain;charset=utf-8"; |
393 | public int HttpTimeout; | 408 | public int HttpTimeout; |
394 | public bool HttpVerifyCert = true; | 409 | public bool HttpVerifyCert = true; |
410 | public IWorkItemResult WorkItem = null; | ||
411 | |||
395 | //public bool HttpVerboseThrottle = true; // not implemented | 412 | //public bool HttpVerboseThrottle = true; // not implemented |
396 | public List<string> HttpCustomHeaders = null; | 413 | public List<string> HttpCustomHeaders = null; |
397 | public bool HttpPragmaNoCache = true; | 414 | public bool HttpPragmaNoCache = true; |
@@ -428,7 +445,16 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
428 | 445 | ||
429 | public void Process() | 446 | public void Process() |
430 | { | 447 | { |
448 | _finished = false; | ||
449 | |||
450 | lock (HttpRequestModule.ThreadPool) | ||
451 | WorkItem = HttpRequestModule.ThreadPool.QueueWorkItem(new WorkItemCallback(StpSendWrapper), null); | ||
452 | } | ||
453 | |||
454 | private object StpSendWrapper(object o) | ||
455 | { | ||
431 | SendRequest(); | 456 | SendRequest(); |
457 | return null; | ||
432 | } | 458 | } |
433 | 459 | ||
434 | /* | 460 | /* |
@@ -439,10 +465,18 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
439 | public void SendRequest() | 465 | public void SendRequest() |
440 | { | 466 | { |
441 | HttpWebResponse response = null; | 467 | HttpWebResponse response = null; |
468 | StringBuilder sb = new StringBuilder(); | ||
469 | byte[] buf = new byte[8192]; | ||
470 | string tempString = null; | ||
471 | int count = 0; | ||
442 | 472 | ||
443 | try | 473 | try |
444 | { | 474 | { |
445 | Request = (HttpWebRequest) WebRequest.Create(Url); | 475 | Request = (HttpWebRequest) WebRequest.Create(Url); |
476 | |||
477 | //This works around some buggy HTTP Servers like Lighttpd | ||
478 | Request.ServicePoint.Expect100Continue = false; | ||
479 | |||
446 | Request.Method = HttpMethod; | 480 | Request.Method = HttpMethod; |
447 | Request.ContentType = HttpMIMEType; | 481 | Request.ContentType = HttpMIMEType; |
448 | 482 | ||
@@ -450,7 +484,6 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
450 | { | 484 | { |
451 | // We could hijack Connection Group Name to identify | 485 | // We could hijack Connection Group Name to identify |
452 | // a desired security exception. But at the moment we'll use a dummy header instead. | 486 | // a desired security exception. But at the moment we'll use a dummy header instead. |
453 | // Request.ConnectionGroupName = "NoVerify"; | ||
454 | Request.Headers.Add("NoVerifyCert", "true"); | 487 | Request.Headers.Add("NoVerifyCert", "true"); |
455 | } | 488 | } |
456 | // else | 489 | // else |
@@ -497,12 +530,11 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
497 | bstream.Close(); | 530 | bstream.Close(); |
498 | } | 531 | } |
499 | 532 | ||
533 | Request.Timeout = HttpTimeout; | ||
500 | try | 534 | try |
501 | { | 535 | { |
502 | IAsyncResult result = (IAsyncResult)Request.BeginGetResponse(ResponseCallback, null); | 536 | // execute the request |
503 | 537 | response = (HttpWebResponse) Request.GetResponse(); | |
504 | ThreadPool.RegisterWaitForSingleObject( | ||
505 | result.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), null, HttpTimeout, true); | ||
506 | } | 538 | } |
507 | catch (WebException e) | 539 | catch (WebException e) |
508 | { | 540 | { |
@@ -511,31 +543,11 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
511 | throw; | 543 | throw; |
512 | } | 544 | } |
513 | response = (HttpWebResponse)e.Response; | 545 | response = (HttpWebResponse)e.Response; |
514 | _finished = true; | ||
515 | } | 546 | } |
516 | } | ||
517 | catch (Exception e) | ||
518 | { | ||
519 | Status = (int)OSHttpStatusCode.ClientErrorJoker; | ||
520 | ResponseBody = e.Message; | ||
521 | _finished = true; | ||
522 | } | ||
523 | } | ||
524 | 547 | ||
525 | private void ResponseCallback(IAsyncResult ar) | ||
526 | { | ||
527 | HttpWebResponse response = null; | ||
528 | |||
529 | try | ||
530 | { | ||
531 | response = (HttpWebResponse)Request.EndGetResponse(ar); | ||
532 | Status = (int)response.StatusCode; | 548 | Status = (int)response.StatusCode; |
533 | 549 | ||
534 | Stream resStream = response.GetResponseStream(); | 550 | Stream resStream = response.GetResponseStream(); |
535 | StringBuilder sb = new StringBuilder(); | ||
536 | byte[] buf = new byte[8192]; | ||
537 | string tempString = null; | ||
538 | int count = 0; | ||
539 | 551 | ||
540 | do | 552 | do |
541 | { | 553 | { |
@@ -550,41 +562,71 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
550 | 562 | ||
551 | // continue building the string | 563 | // continue building the string |
552 | sb.Append(tempString); | 564 | sb.Append(tempString); |
565 | if (sb.Length > 2048) | ||
566 | break; | ||
553 | } | 567 | } |
554 | } | 568 | } while (count > 0); // any more data to read? |
555 | while (count > 0); // any more data to read? | ||
556 | 569 | ||
557 | ResponseBody = sb.ToString(); | 570 | ResponseBody = sb.ToString().Replace("\r", ""); |
558 | } | 571 | } |
559 | catch (Exception e) | 572 | catch (WebException e) |
560 | { | 573 | { |
561 | Status = (int)OSHttpStatusCode.ClientErrorJoker; | 574 | if (e.Status == WebExceptionStatus.ProtocolError) |
562 | ResponseBody = e.Message; | 575 | { |
576 | HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response; | ||
577 | Status = (int)webRsp.StatusCode; | ||
578 | try | ||
579 | { | ||
580 | using (Stream responseStream = webRsp.GetResponseStream()) | ||
581 | { | ||
582 | ResponseBody = responseStream.GetStreamString(); | ||
583 | } | ||
584 | } | ||
585 | catch | ||
586 | { | ||
587 | ResponseBody = webRsp.StatusDescription; | ||
588 | } | ||
589 | } | ||
590 | else | ||
591 | { | ||
592 | Status = (int)OSHttpStatusCode.ClientErrorJoker; | ||
593 | ResponseBody = e.Message; | ||
594 | } | ||
563 | 595 | ||
564 | // m_log.Debug( | 596 | if (ResponseBody == null) |
565 | // string.Format("[SCRIPTS HTTP REQUESTS]: Exception on response to {0} for {1} ", Url, ItemID), e); | 597 | ResponseBody = String.Empty; |
598 | |||
599 | _finished = true; | ||
600 | return; | ||
601 | } | ||
602 | catch (Exception e) | ||
603 | { | ||
604 | // Don't crash on anything else | ||
566 | } | 605 | } |
567 | finally | 606 | finally |
568 | { | 607 | { |
569 | if (response != null) | 608 | if (response != null) |
570 | response.Close(); | 609 | response.Close(); |
571 | |||
572 | _finished = true; | ||
573 | } | 610 | } |
574 | } | ||
575 | 611 | ||
576 | private void TimeoutCallback(object state, bool timedOut) | 612 | if (ResponseBody == null) |
577 | { | 613 | ResponseBody = String.Empty; |
578 | if (timedOut) | 614 | |
579 | Request.Abort(); | 615 | _finished = true; |
580 | } | 616 | } |
581 | 617 | ||
582 | public void Stop() | 618 | public void Stop() |
583 | { | 619 | { |
584 | // m_log.DebugFormat("[SCRIPTS HTTP REQUESTS]: Stopping request to {0} for {1} ", Url, ItemID); | 620 | try |
585 | 621 | { | |
586 | if (Request != null) | 622 | if (!WorkItem.Cancel()) |
587 | Request.Abort(); | 623 | { |
624 | WorkItem.Cancel(true); | ||
625 | } | ||
626 | } | ||
627 | catch (Exception) | ||
628 | { | ||
629 | } | ||
588 | } | 630 | } |
589 | } | 631 | } |
590 | } | 632 | } |
diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs index def8162..2a4d440 100644 --- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs | |||
@@ -42,40 +42,16 @@ 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; | ||
54 | public Scene scene; | ||
79 | } | 55 | } |
80 | 56 | ||
81 | public class RequestData | 57 | public class RequestData |
@@ -89,7 +65,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
89 | //public ManualResetEvent ev; | 65 | //public ManualResetEvent ev; |
90 | public bool requestDone; | 66 | public bool requestDone; |
91 | public int startTime; | 67 | public int startTime; |
68 | public bool responseSent; | ||
92 | public string uri; | 69 | public string uri; |
70 | public bool allowResponseType = false; | ||
71 | public UUID hostID; | ||
72 | public Scene scene; | ||
93 | } | 73 | } |
94 | 74 | ||
95 | /// <summary> | 75 | /// <summary> |
@@ -102,20 +82,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
102 | LogManager.GetLogger( | 82 | LogManager.GetLogger( |
103 | MethodBase.GetCurrentMethod().DeclaringType); | 83 | MethodBase.GetCurrentMethod().DeclaringType); |
104 | 84 | ||
105 | /// <summary> | 85 | private Dictionary<UUID, UrlData> m_RequestMap = |
106 | /// Indexs the URL request metadata (which script requested it, outstanding requests, etc.) by the request ID | 86 | 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 | 87 | ||
115 | /// <summary> | 88 | private Dictionary<string, UrlData> m_UrlMap = |
116 | /// Indexs the URL request metadata (which script requested it, outstanding requests, etc.) by the full URL | 89 | new Dictionary<string, UrlData>(); |
117 | /// </summary> | ||
118 | private Dictionary<string, UrlData> m_UrlMap = new Dictionary<string, UrlData>(); | ||
119 | 90 | ||
120 | private uint m_HttpsPort = 0; | 91 | private uint m_HttpsPort = 0; |
121 | private IHttpServer m_HttpServer = null; | 92 | private IHttpServer m_HttpServer = null; |
@@ -126,7 +97,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
126 | /// <summary> | 97 | /// <summary> |
127 | /// The default maximum number of urls | 98 | /// The default maximum number of urls |
128 | /// </summary> | 99 | /// </summary> |
129 | public const int DefaultTotalUrls = 100; | 100 | public const int DefaultTotalUrls = 15000; |
130 | 101 | ||
131 | /// <summary> | 102 | /// <summary> |
132 | /// Maximum number of external urls that can be set up by this module. | 103 | /// Maximum number of external urls that can be set up by this module. |
@@ -204,6 +175,17 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
204 | 175 | ||
205 | public void RemoveRegion(Scene scene) | 176 | public void RemoveRegion(Scene scene) |
206 | { | 177 | { |
178 | // Drop references to that scene | ||
179 | foreach (KeyValuePair<string, UrlData> kvp in m_UrlMap) | ||
180 | { | ||
181 | if (kvp.Value.scene == scene) | ||
182 | kvp.Value.scene = null; | ||
183 | } | ||
184 | foreach (KeyValuePair<UUID, UrlData> kvp in m_RequestMap) | ||
185 | { | ||
186 | if (kvp.Value.scene == scene) | ||
187 | kvp.Value.scene = null; | ||
188 | } | ||
207 | } | 189 | } |
208 | 190 | ||
209 | public void Close() | 191 | public void Close() |
@@ -221,7 +203,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
221 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); | 203 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); |
222 | return urlcode; | 204 | return urlcode; |
223 | } | 205 | } |
224 | string url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/"; | 206 | string url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString(); |
225 | 207 | ||
226 | UrlData urlData = new UrlData(); | 208 | UrlData urlData = new UrlData(); |
227 | urlData.hostID = host.UUID; | 209 | urlData.hostID = host.UUID; |
@@ -229,19 +211,21 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
229 | urlData.engine = engine; | 211 | urlData.engine = engine; |
230 | urlData.url = url; | 212 | urlData.url = url; |
231 | urlData.urlcode = urlcode; | 213 | urlData.urlcode = urlcode; |
214 | urlData.isSsl = false; | ||
232 | urlData.requests = new Dictionary<UUID, RequestData>(); | 215 | urlData.requests = new Dictionary<UUID, RequestData>(); |
233 | 216 | urlData.scene = host.ParentGroup.Scene; | |
217 | |||
234 | m_UrlMap[url] = urlData; | 218 | m_UrlMap[url] = urlData; |
235 | 219 | ||
236 | string uri = "/lslhttp/" + urlcode.ToString() + "/"; | 220 | string uri = "/lslhttp/" + urlcode.ToString(); |
237 | 221 | ||
238 | PollServiceEventArgs args = new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode, 25000); | 222 | PollServiceEventArgs args = new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode, 25000); |
239 | args.Type = PollServiceEventArgs.EventType.LslHttp; | 223 | args.Type = PollServiceEventArgs.EventType.LslHttp; |
240 | m_HttpServer.AddPollServiceHTTPHandler(uri, args); | 224 | m_HttpServer.AddPollServiceHTTPHandler(uri, args); |
241 | 225 | ||
242 | m_log.DebugFormat( | 226 | // m_log.DebugFormat( |
243 | "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}", | 227 | // "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}", |
244 | uri, itemID, host.Name, host.LocalId); | 228 | // uri, itemID, host.Name, host.LocalId); |
245 | 229 | ||
246 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); | 230 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); |
247 | } | 231 | } |
@@ -266,7 +250,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
266 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); | 250 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); |
267 | return urlcode; | 251 | return urlcode; |
268 | } | 252 | } |
269 | string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/"; | 253 | string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString(); |
270 | 254 | ||
271 | UrlData urlData = new UrlData(); | 255 | UrlData urlData = new UrlData(); |
272 | urlData.hostID = host.UUID; | 256 | urlData.hostID = host.UUID; |
@@ -274,19 +258,21 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
274 | urlData.engine = engine; | 258 | urlData.engine = engine; |
275 | urlData.url = url; | 259 | urlData.url = url; |
276 | urlData.urlcode = urlcode; | 260 | urlData.urlcode = urlcode; |
261 | urlData.isSsl = true; | ||
277 | urlData.requests = new Dictionary<UUID, RequestData>(); | 262 | urlData.requests = new Dictionary<UUID, RequestData>(); |
278 | 263 | ||
264 | |||
279 | m_UrlMap[url] = urlData; | 265 | m_UrlMap[url] = urlData; |
280 | 266 | ||
281 | string uri = "/lslhttps/" + urlcode.ToString() + "/"; | 267 | string uri = "/lslhttps/" + urlcode.ToString(); |
282 | 268 | ||
283 | PollServiceEventArgs args = new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode, 25000); | 269 | PollServiceEventArgs args = new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode, 25000); |
284 | args.Type = PollServiceEventArgs.EventType.LslHttp; | 270 | args.Type = PollServiceEventArgs.EventType.LslHttp; |
285 | m_HttpsServer.AddPollServiceHTTPHandler(uri, args); | 271 | m_HttpsServer.AddPollServiceHTTPHandler(uri, args); |
286 | 272 | ||
287 | m_log.DebugFormat( | 273 | // m_log.DebugFormat( |
288 | "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}", | 274 | // "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}", |
289 | uri, itemID, host.Name, host.LocalId); | 275 | // uri, itemID, host.Name, host.LocalId); |
290 | 276 | ||
291 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); | 277 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); |
292 | } | 278 | } |
@@ -305,12 +291,15 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
305 | return; | 291 | return; |
306 | } | 292 | } |
307 | 293 | ||
308 | foreach (UUID req in data.requests.Keys) | 294 | lock (m_RequestMap) |
309 | m_RequestMap.Remove(req); | 295 | { |
310 | 296 | foreach (UUID req in data.requests.Keys) | |
311 | m_log.DebugFormat( | 297 | m_RequestMap.Remove(req); |
312 | "[URL MODULE]: Releasing url {0} for {1} in {2}", | 298 | } |
313 | url, data.itemID, data.hostID); | 299 | |
300 | // m_log.DebugFormat( | ||
301 | // "[URL MODULE]: Releasing url {0} for {1} in {2}", | ||
302 | // url, data.itemID, data.hostID); | ||
314 | 303 | ||
315 | RemoveUrl(data); | 304 | RemoveUrl(data); |
316 | m_UrlMap.Remove(url); | 305 | m_UrlMap.Remove(url); |
@@ -335,29 +324,39 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
335 | 324 | ||
336 | public void HttpResponse(UUID request, int status, string body) | 325 | public void HttpResponse(UUID request, int status, string body) |
337 | { | 326 | { |
338 | lock (m_UrlMap) | 327 | lock (m_RequestMap) |
339 | { | 328 | { |
340 | if (m_RequestMap.ContainsKey(request)) | 329 | if (m_RequestMap.ContainsKey(request)) |
341 | { | 330 | { |
342 | UrlData urlData = m_RequestMap[request]; | 331 | UrlData urlData = m_RequestMap[request]; |
343 | string responseBody = body; | 332 | if (!urlData.requests[request].responseSent) |
344 | if (urlData.requests[request].responseType.Equals("text/plain")) | ||
345 | { | 333 | { |
346 | string value; | 334 | string responseBody = body; |
347 | if (urlData.requests[request].headers.TryGetValue("user-agent", out value)) | 335 | |
336 | // If we have no OpenID from built-in browser, disable this | ||
337 | if (!urlData.requests[request].allowResponseType) | ||
338 | urlData.requests[request].responseType = "text/plain"; | ||
339 | |||
340 | if (urlData.requests[request].responseType.Equals("text/plain")) | ||
348 | { | 341 | { |
349 | if (value != null && value.IndexOf("MSIE") >= 0) | 342 | string value; |
343 | if (urlData.requests[request].headers.TryGetValue("user-agent", out value)) | ||
350 | { | 344 | { |
351 | // wrap the html escaped response if the target client is IE | 345 | if (value != null && value.IndexOf("MSIE") >= 0) |
352 | // It ignores "text/plain" if the body is html | 346 | { |
353 | responseBody = "<html>" + System.Web.HttpUtility.HtmlEncode(body) + "</html>"; | 347 | // wrap the html escaped response if the target client is IE |
348 | // It ignores "text/plain" if the body is html | ||
349 | responseBody = "<html>" + System.Web.HttpUtility.HtmlEncode(body) + "</html>"; | ||
350 | } | ||
354 | } | 351 | } |
355 | } | 352 | } |
353 | |||
354 | urlData.requests[request].responseCode = status; | ||
355 | urlData.requests[request].responseBody = body; | ||
356 | //urlData.requests[request].ev.Set(); | ||
357 | urlData.requests[request].requestDone = true; | ||
358 | urlData.requests[request].responseSent = true; | ||
356 | } | 359 | } |
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 | } | 360 | } |
362 | else | 361 | else |
363 | { | 362 | { |
@@ -368,7 +367,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
368 | 367 | ||
369 | public string GetHttpHeader(UUID requestId, string header) | 368 | public string GetHttpHeader(UUID requestId, string header) |
370 | { | 369 | { |
371 | lock (m_UrlMap) | 370 | lock (m_RequestMap) |
372 | { | 371 | { |
373 | if (m_RequestMap.ContainsKey(requestId)) | 372 | if (m_RequestMap.ContainsKey(requestId)) |
374 | { | 373 | { |
@@ -382,7 +381,6 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
382 | m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId); | 381 | m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId); |
383 | } | 382 | } |
384 | } | 383 | } |
385 | |||
386 | return String.Empty; | 384 | return String.Empty; |
387 | } | 385 | } |
388 | 386 | ||
@@ -406,8 +404,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
406 | { | 404 | { |
407 | RemoveUrl(url.Value); | 405 | RemoveUrl(url.Value); |
408 | removeURLs.Add(url.Key); | 406 | removeURLs.Add(url.Key); |
409 | foreach (UUID req in url.Value.requests.Keys) | 407 | lock (m_RequestMap) |
410 | m_RequestMap.Remove(req); | 408 | { |
409 | foreach (UUID req in url.Value.requests.Keys) | ||
410 | m_RequestMap.Remove(req); | ||
411 | } | ||
411 | } | 412 | } |
412 | } | 413 | } |
413 | 414 | ||
@@ -428,9 +429,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
428 | { | 429 | { |
429 | RemoveUrl(url.Value); | 430 | RemoveUrl(url.Value); |
430 | removeURLs.Add(url.Key); | 431 | removeURLs.Add(url.Key); |
431 | 432 | lock (m_RequestMap) | |
432 | foreach (UUID req in url.Value.requests.Keys) | 433 | { |
433 | m_RequestMap.Remove(req); | 434 | foreach (UUID req in url.Value.requests.Keys) |
435 | m_RequestMap.Remove(req); | ||
436 | } | ||
434 | } | 437 | } |
435 | } | 438 | } |
436 | 439 | ||
@@ -439,123 +442,128 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
439 | } | 442 | } |
440 | } | 443 | } |
441 | 444 | ||
445 | |||
442 | private void RemoveUrl(UrlData data) | 446 | private void RemoveUrl(UrlData data) |
443 | { | 447 | { |
444 | m_HttpServer.RemoveHTTPHandler("", "/lslhttp/" + data.urlcode.ToString() + "/"); | 448 | if (data.isSsl) |
449 | m_HttpsServer.RemoveHTTPHandler("", "/lslhttps/"+data.urlcode.ToString()+"/"); | ||
450 | else | ||
451 | m_HttpServer.RemoveHTTPHandler("", "/lslhttp/"+data.urlcode.ToString()+"/"); | ||
445 | } | 452 | } |
446 | 453 | ||
447 | private Hashtable NoEvents(UUID requestID, UUID sessionID) | 454 | private Hashtable NoEvents(UUID requestID, UUID sessionID) |
448 | { | 455 | { |
449 | Hashtable response = new Hashtable(); | 456 | Hashtable response = new Hashtable(); |
450 | UrlData urlData; | 457 | UrlData url; |
451 | 458 | int startTime = 0; | |
452 | lock (m_UrlMap) | 459 | lock (m_RequestMap) |
453 | { | 460 | { |
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)) | 461 | 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; | 462 | return response; |
465 | } | 463 | url = m_RequestMap[requestID]; |
464 | startTime = url.requests[requestID].startTime; | ||
465 | } | ||
466 | 466 | ||
467 | urlData = m_RequestMap[requestID]; | 467 | if (System.Environment.TickCount - startTime > 25000) |
468 | { | ||
469 | response["int_response_code"] = 500; | ||
470 | response["str_response_string"] = "Script timeout"; | ||
471 | response["content_type"] = "text/plain"; | ||
472 | response["keepalive"] = false; | ||
473 | response["reusecontext"] = false; | ||
468 | 474 | ||
469 | if (System.Environment.TickCount - urlData.requests[requestID].startTime > 25000) | 475 | //remove from map |
476 | lock (url.requests) | ||
477 | { | ||
478 | url.requests.Remove(requestID); | ||
479 | } | ||
480 | lock (m_RequestMap) | ||
470 | { | 481 | { |
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); | 482 | m_RequestMap.Remove(requestID); |
480 | |||
481 | return response; | ||
482 | } | 483 | } |
484 | |||
485 | return response; | ||
483 | } | 486 | } |
484 | 487 | ||
488 | |||
485 | return response; | 489 | return response; |
486 | } | 490 | } |
487 | 491 | ||
488 | private bool HasEvents(UUID requestID, UUID sessionID) | 492 | private bool HasEvents(UUID requestID, UUID sessionID) |
489 | { | 493 | { |
490 | lock (m_UrlMap) | 494 | UrlData url=null; |
495 | |||
496 | lock (m_RequestMap) | ||
491 | { | 497 | { |
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)) | 498 | if (!m_RequestMap.ContainsKey(requestID)) |
498 | { | 499 | { |
499 | return true; | 500 | return false; |
500 | } | 501 | } |
501 | 502 | url = m_RequestMap[requestID]; | |
502 | UrlData urlData = m_RequestMap[requestID]; | 503 | } |
503 | 504 | lock (url.requests) | |
504 | if (!urlData.requests.ContainsKey(requestID)) | 505 | { |
506 | if (!url.requests.ContainsKey(requestID)) | ||
505 | { | 507 | { |
506 | return true; | 508 | return false; |
507 | } | 509 | } |
508 | 510 | else | |
509 | // Trigger return of timeout response. | ||
510 | if (System.Environment.TickCount - urlData.requests[requestID].startTime > 25000) | ||
511 | { | 511 | { |
512 | return true; | 512 | if (System.Environment.TickCount - url.requests[requestID].startTime > 25000) |
513 | { | ||
514 | return true; | ||
515 | } | ||
516 | if (url.requests[requestID].requestDone) | ||
517 | return true; | ||
518 | else | ||
519 | return false; | ||
513 | } | 520 | } |
514 | |||
515 | return urlData.requests[requestID].requestDone; | ||
516 | } | 521 | } |
517 | } | 522 | } |
518 | |||
519 | private Hashtable GetEvents(UUID requestID, UUID sessionID) | 523 | private Hashtable GetEvents(UUID requestID, UUID sessionID) |
520 | { | 524 | { |
521 | Hashtable response; | 525 | UrlData url = null; |
526 | RequestData requestData = null; | ||
522 | 527 | ||
523 | lock (m_UrlMap) | 528 | lock (m_RequestMap) |
524 | { | 529 | { |
525 | UrlData url = null; | ||
526 | RequestData requestData = null; | ||
527 | |||
528 | if (!m_RequestMap.ContainsKey(requestID)) | 530 | if (!m_RequestMap.ContainsKey(requestID)) |
529 | return NoEvents(requestID, sessionID); | 531 | return NoEvents(requestID,sessionID); |
530 | |||
531 | url = m_RequestMap[requestID]; | 532 | url = m_RequestMap[requestID]; |
533 | } | ||
534 | lock (url.requests) | ||
535 | { | ||
532 | requestData = url.requests[requestID]; | 536 | requestData = url.requests[requestID]; |
537 | } | ||
538 | |||
539 | if (!requestData.requestDone) | ||
540 | return NoEvents(requestID,sessionID); | ||
541 | |||
542 | Hashtable response = new Hashtable(); | ||
533 | 543 | ||
534 | if (!requestData.requestDone) | 544 | if (System.Environment.TickCount - requestData.startTime > 25000) |
535 | return NoEvents(requestID, sessionID); | 545 | { |
536 | 546 | response["int_response_code"] = 500; | |
537 | response = new Hashtable(); | 547 | response["str_response_string"] = "Script timeout"; |
538 | 548 | 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; | 549 | response["keepalive"] = false; |
555 | response["reusecontext"] = false; | 550 | response["reusecontext"] = false; |
556 | 551 | return response; | |
557 | //remove from map | 552 | } |
553 | //put response | ||
554 | response["int_response_code"] = requestData.responseCode; | ||
555 | response["str_response_string"] = requestData.responseBody; | ||
556 | response["content_type"] = requestData.responseType; | ||
557 | response["keepalive"] = false; | ||
558 | response["reusecontext"] = false; | ||
559 | |||
560 | //remove from map | ||
561 | lock (url.requests) | ||
562 | { | ||
558 | url.requests.Remove(requestID); | 563 | url.requests.Remove(requestID); |
564 | } | ||
565 | lock (m_RequestMap) | ||
566 | { | ||
559 | m_RequestMap.Remove(requestID); | 567 | m_RequestMap.Remove(requestID); |
560 | } | 568 | } |
561 | 569 | ||
@@ -564,41 +572,45 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
564 | 572 | ||
565 | public void HttpRequestHandler(UUID requestID, Hashtable request) | 573 | public void HttpRequestHandler(UUID requestID, Hashtable request) |
566 | { | 574 | { |
567 | string uri = request["uri"].ToString(); | 575 | lock (request) |
568 | bool is_ssl = uri.Contains("lslhttps"); | ||
569 | |||
570 | try | ||
571 | { | 576 | { |
572 | Hashtable headers = (Hashtable)request["headers"]; | 577 | string uri = request["uri"].ToString(); |
578 | bool is_ssl = uri.Contains("lslhttps"); | ||
573 | 579 | ||
574 | // string uri_full = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/"; | 580 | try |
575 | |||
576 | int pos1 = uri.IndexOf("/");// /lslhttp | ||
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 | { | 581 | { |
591 | string url; | 582 | Hashtable headers = (Hashtable)request["headers"]; |
592 | 583 | ||
593 | if (is_ssl) | 584 | // string uri_full = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/"; |
594 | url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp; | 585 | |
586 | int pos1 = uri.IndexOf("/");// /lslhttp | ||
587 | int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/ | ||
588 | int pos3 = pos2 + 37; // /lslhttp/urlcode | ||
589 | string uri_tmp = uri.Substring(0, pos3); | ||
590 | //HTTP server code doesn't provide us with QueryStrings | ||
591 | string pathInfo; | ||
592 | string queryString; | ||
593 | queryString = ""; | ||
594 | |||
595 | pathInfo = uri.Substring(pos3); | ||
596 | |||
597 | UrlData url = null; | ||
598 | string urlkey; | ||
599 | if (!is_ssl) | ||
600 | urlkey = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp; | ||
601 | //m_UrlMap[]; | ||
595 | else | 602 | else |
596 | url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp; | 603 | urlkey = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp; |
597 | 604 | ||
598 | // Avoid a race - the request URL may have been released via llRequestUrl() whilst this | 605 | if (m_UrlMap.ContainsKey(urlkey)) |
599 | // request was being processed. | 606 | { |
600 | if (!m_UrlMap.TryGetValue(url, out urlData)) | 607 | url = m_UrlMap[urlkey]; |
608 | } | ||
609 | else | ||
610 | { | ||
611 | //m_log.Warn("[HttpRequestHandler]: http-in request failed; no such url: "+urlkey.ToString()); | ||
601 | return; | 612 | return; |
613 | } | ||
602 | 614 | ||
603 | //for llGetHttpHeader support we need to store original URI here | 615 | //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 | 616 | //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers |
@@ -609,6 +621,8 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
609 | requestData.requestDone = false; | 621 | requestData.requestDone = false; |
610 | requestData.startTime = System.Environment.TickCount; | 622 | requestData.startTime = System.Environment.TickCount; |
611 | requestData.uri = uri; | 623 | requestData.uri = uri; |
624 | requestData.hostID = url.hostID; | ||
625 | requestData.scene = url.scene; | ||
612 | if (requestData.headers == null) | 626 | if (requestData.headers == null) |
613 | requestData.headers = new Dictionary<string, string>(); | 627 | requestData.headers = new Dictionary<string, string>(); |
614 | 628 | ||
@@ -617,8 +631,33 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
617 | string key = (string)header.Key; | 631 | string key = (string)header.Key; |
618 | string value = (string)header.Value; | 632 | string value = (string)header.Value; |
619 | requestData.headers.Add(key, value); | 633 | requestData.headers.Add(key, value); |
634 | if (key == "cookie") | ||
635 | { | ||
636 | string[] parts = value.Split(new char[] {'='}); | ||
637 | if (parts[0] == "agni_sl_session_id" && parts.Length > 1) | ||
638 | { | ||
639 | string cookie = Uri.UnescapeDataString(parts[1]); | ||
640 | string[] crumbs = cookie.Split(new char[] {':'}); | ||
641 | UUID owner; | ||
642 | if (crumbs.Length == 2 && UUID.TryParse(crumbs[0], out owner)) | ||
643 | { | ||
644 | if (crumbs[1].Length == 32) | ||
645 | { | ||
646 | Scene scene = requestData.scene; | ||
647 | if (scene != null) | ||
648 | { | ||
649 | SceneObjectPart host = scene.GetSceneObjectPart(requestData.hostID); | ||
650 | if (host != null) | ||
651 | { | ||
652 | if (host.OwnerID == owner) | ||
653 | requestData.allowResponseType = true; | ||
654 | } | ||
655 | } | ||
656 | } | ||
657 | } | ||
658 | } | ||
659 | } | ||
620 | } | 660 | } |
621 | |||
622 | foreach (DictionaryEntry de in request) | 661 | foreach (DictionaryEntry de in request) |
623 | { | 662 | { |
624 | if (de.Key.ToString() == "querystringkeys") | 663 | if (de.Key.ToString() == "querystringkeys") |
@@ -629,13 +668,21 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
629 | if (request.ContainsKey(key)) | 668 | if (request.ContainsKey(key)) |
630 | { | 669 | { |
631 | string val = (String)request[key]; | 670 | string val = (String)request[key]; |
632 | queryString = queryString + key + "=" + val + "&"; | 671 | if (key != "") |
672 | { | ||
673 | queryString = queryString + key + "=" + val + "&"; | ||
674 | } | ||
675 | else | ||
676 | { | ||
677 | queryString = queryString + val + "&"; | ||
678 | } | ||
633 | } | 679 | } |
634 | } | 680 | } |
635 | |||
636 | if (queryString.Length > 1) | 681 | if (queryString.Length > 1) |
637 | queryString = queryString.Substring(0, queryString.Length - 1); | 682 | queryString = queryString.Substring(0, queryString.Length - 1); |
683 | |||
638 | } | 684 | } |
685 | |||
639 | } | 686 | } |
640 | 687 | ||
641 | //if this machine is behind DNAT/port forwarding, currently this is being | 688 | //if this machine is behind DNAT/port forwarding, currently this is being |
@@ -643,23 +690,34 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
643 | requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"]; | 690 | requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"]; |
644 | requestData.headers["x-path-info"] = pathInfo; | 691 | requestData.headers["x-path-info"] = pathInfo; |
645 | requestData.headers["x-query-string"] = queryString; | 692 | requestData.headers["x-query-string"] = queryString; |
646 | requestData.headers["x-script-url"] = urlData.url; | 693 | requestData.headers["x-script-url"] = url.url; |
647 | 694 | ||
648 | urlData.requests.Add(requestID, requestData); | 695 | //requestData.ev = new ManualResetEvent(false); |
649 | m_RequestMap.Add(requestID, urlData); | 696 | lock (url.requests) |
650 | } | 697 | { |
698 | url.requests.Add(requestID, requestData); | ||
699 | } | ||
700 | lock (m_RequestMap) | ||
701 | { | ||
702 | //add to request map | ||
703 | m_RequestMap.Add(requestID, url); | ||
704 | } | ||
651 | 705 | ||
652 | urlData.engine.PostScriptEvent( | 706 | url.engine.PostScriptEvent(url.itemID, "http_request", new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() }); |
653 | urlData.itemID, | 707 | |
654 | "http_request", | 708 | //send initial response? |
655 | new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() }); | 709 | // Hashtable response = new Hashtable(); |
656 | } | 710 | |
657 | catch (Exception we) | 711 | return; |
658 | { | 712 | |
659 | //Hashtable response = new Hashtable(); | 713 | } |
660 | m_log.Warn("[HttpRequestHandler]: http-in request failed"); | 714 | catch (Exception we) |
661 | m_log.Warn(we.Message); | 715 | { |
662 | m_log.Warn(we.StackTrace); | 716 | //Hashtable response = new Hashtable(); |
717 | m_log.Warn("[HttpRequestHandler]: http-in request failed"); | ||
718 | m_log.Warn(we.Message); | ||
719 | m_log.Warn(we.StackTrace); | ||
720 | } | ||
663 | } | 721 | } |
664 | } | 722 | } |
665 | 723 | ||
diff --git a/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index 6bf50d2..fccf053 100644 --- a/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | |||
@@ -262,6 +262,8 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | |||
262 | return "modInvokeR"; | 262 | return "modInvokeR"; |
263 | else if (sid.ReturnType == typeof(object[])) | 263 | else if (sid.ReturnType == typeof(object[])) |
264 | return "modInvokeL"; | 264 | return "modInvokeL"; |
265 | else if (sid.ReturnType == typeof(void)) | ||
266 | return "modInvokeN"; | ||
265 | 267 | ||
266 | m_log.WarnFormat("[MODULE COMMANDS] failed to find match for {0} with return type {1}",fname,sid.ReturnType.Name); | 268 | m_log.WarnFormat("[MODULE COMMANDS] failed to find match for {0} with return type {1}",fname,sid.ReturnType.Name); |
267 | } | 269 | } |
diff --git a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs index 4cecd85..2fc89fc 100644 --- a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs | |||
@@ -861,4 +861,4 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender | |||
861 | return null; | 861 | return null; |
862 | } | 862 | } |
863 | } | 863 | } |
864 | } \ No newline at end of file | 864 | } |
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs index 2c2c99c..87a0537 100644 --- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs | |||
@@ -96,6 +96,8 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm | |||
96 | // private static readonly ILog m_log = | 96 | // private static readonly ILog m_log = |
97 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 97 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
98 | 98 | ||
99 | private const int DEBUG_CHANNEL = 2147483647; | ||
100 | |||
99 | private ListenerManager m_listenerManager; | 101 | private ListenerManager m_listenerManager; |
100 | private Queue m_pending; | 102 | private Queue m_pending; |
101 | private Queue m_pendingQ; | 103 | private Queue m_pendingQ; |
@@ -366,67 +368,60 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm | |||
366 | /// <param name='msg'> | 368 | /// <param name='msg'> |
367 | /// Message. | 369 | /// Message. |
368 | /// </param> | 370 | /// </param> |
369 | public void DeliverMessageTo(UUID target, int channel, Vector3 pos, | 371 | public bool DeliverMessageTo(UUID target, int channel, Vector3 pos, string name, UUID id, string msg, out string error) |
370 | string name, UUID id, string msg) | ||
371 | { | 372 | { |
373 | error = null; | ||
374 | |||
375 | if (channel == DEBUG_CHANNEL) | ||
376 | return true; | ||
377 | |||
372 | // Is id an avatar? | 378 | // Is id an avatar? |
373 | ScenePresence sp = m_scene.GetScenePresence(target); | 379 | ScenePresence sp = m_scene.GetScenePresence(target); |
374 | 380 | ||
375 | if (sp != null) | 381 | if (sp != null) |
376 | { | 382 | { |
377 | // ignore if a child agent this is restricted to inside one | 383 | // Send message to avatar |
378 | // region | ||
379 | if (sp.IsChildAgent) | ||
380 | return; | ||
381 | |||
382 | // Send message to the avatar. | ||
383 | // Channel zero only goes to the avatar | ||
384 | // non zero channel messages only go to the attachments | ||
385 | if (channel == 0) | 384 | if (channel == 0) |
386 | { | 385 | { |
387 | m_scene.SimChatToAgent(target, Utils.StringToBytes(msg), | 386 | // Channel 0 goes to viewer ONLY |
388 | pos, name, id, false); | 387 | m_scene.SimChat(Utils.StringToBytes(msg), ChatTypeEnum.Broadcast, 0, pos, name, id, target, false, false); |
388 | return true; | ||
389 | } | 389 | } |
390 | else | ||
391 | { | ||
392 | List<SceneObjectGroup> attachments = sp.GetAttachments(); | ||
393 | if (attachments.Count == 0) | ||
394 | return; | ||
395 | 390 | ||
396 | // Get uuid of attachments | 391 | List<SceneObjectGroup> attachments = sp.GetAttachments(); |
397 | List<UUID> targets = new List<UUID>(); | ||
398 | foreach (SceneObjectGroup sog in attachments) | ||
399 | { | ||
400 | if (!sog.IsDeleted) | ||
401 | targets.Add(sog.UUID); | ||
402 | } | ||
403 | 392 | ||
404 | // Need to check each attachment | 393 | if (attachments.Count == 0) |
405 | foreach (ListenerInfo li | 394 | return true; |
406 | in m_listenerManager.GetListeners(UUID.Zero, | ||
407 | channel, name, id, msg)) | ||
408 | { | ||
409 | if (li.GetHostID().Equals(id)) | ||
410 | continue; | ||
411 | 395 | ||
412 | if (m_scene.GetSceneObjectPart( | 396 | // Get uuid of attachments |
413 | li.GetHostID()) == null) | 397 | List<UUID> targets = new List<UUID>(); |
414 | { | 398 | foreach (SceneObjectGroup sog in attachments) |
415 | continue; | 399 | { |
416 | } | 400 | if (!sog.IsDeleted) |
401 | targets.Add(sog.UUID); | ||
402 | } | ||
417 | 403 | ||
418 | if (targets.Contains(li.GetHostID())) | 404 | // Need to check each attachment |
419 | QueueMessage(new ListenerInfo(li, name, id, msg)); | 405 | foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg)) |
420 | } | 406 | { |
407 | if (li.GetHostID().Equals(id)) | ||
408 | continue; | ||
409 | |||
410 | if (m_scene.GetSceneObjectPart(li.GetHostID()) == null) | ||
411 | continue; | ||
412 | |||
413 | if (targets.Contains(li.GetHostID())) | ||
414 | QueueMessage(new ListenerInfo(li, name, id, msg)); | ||
421 | } | 415 | } |
422 | 416 | ||
423 | return; | 417 | return true; |
424 | } | 418 | } |
425 | 419 | ||
426 | // No avatar found so look for an object | 420 | SceneObjectPart part = m_scene.GetSceneObjectPart(target); |
427 | foreach (ListenerInfo li | 421 | if (part == null) // Not even an object |
428 | in m_listenerManager.GetListeners(UUID.Zero, channel, | 422 | return true; // No error |
429 | name, id, msg)) | 423 | |
424 | foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg)) | ||
430 | { | 425 | { |
431 | // Dont process if this message is from yourself! | 426 | // Dont process if this message is from yourself! |
432 | if (li.GetHostID().Equals(id)) | 427 | if (li.GetHostID().Equals(id)) |
@@ -444,7 +439,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm | |||
444 | } | 439 | } |
445 | } | 440 | } |
446 | 441 | ||
447 | return; | 442 | return true; |
448 | } | 443 | } |
449 | 444 | ||
450 | protected void QueueMessage(ListenerInfo li) | 445 | protected void QueueMessage(ListenerInfo li) |