diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Scripting')
11 files changed, 628 insertions, 179 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs index 9d77b19..a686a4d 100644 --- a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs | |||
@@ -514,9 +514,11 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
514 | scene.RegionInfo.RegionID.ToString()); | 514 | scene.RegionInfo.RegionID.ToString()); |
515 | asset.Data = assetData; | 515 | asset.Data = assetData; |
516 | asset.Description = String.Format("URL image : {0}", Url); | 516 | asset.Description = String.Format("URL image : {0}", Url); |
517 | asset.Local = false; | 517 | if (asset.Description.Length > 128) |
518 | asset.Description = asset.Description.Substring(0, 128); | ||
519 | asset.Local = true; // dynamic images aren't saved in the assets server | ||
518 | asset.Temporary = ((Disp & DISP_TEMP) != 0); | 520 | asset.Temporary = ((Disp & DISP_TEMP) != 0); |
519 | scene.AssetService.Store(asset); | 521 | scene.AssetService.Store(asset); // this will only save the asset in the local asset cache |
520 | 522 | ||
521 | IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface<IJ2KDecoder>(); | 523 | IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface<IJ2KDecoder>(); |
522 | if (cacheLayerDecode != null) | 524 | if (cacheLayerDecode != null) |
diff --git a/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs b/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs index d943b20..4e7ad75 100644 --- a/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs | |||
@@ -213,8 +213,8 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules | |||
213 | if (part != null) | 213 | if (part != null) |
214 | { | 214 | { |
215 | ObjectRegionName = s.RegionInfo.RegionName; | 215 | ObjectRegionName = s.RegionInfo.RegionName; |
216 | uint localX = (s.RegionInfo.RegionLocX * (int)Constants.RegionSize); | 216 | uint localX = s.RegionInfo.WorldLocX; |
217 | uint localY = (s.RegionInfo.RegionLocY * (int)Constants.RegionSize); | 217 | uint localY = s.RegionInfo.WorldLocY; |
218 | ObjectRegionName = ObjectRegionName + " (" + localX + ", " + localY + ")"; | 218 | ObjectRegionName = ObjectRegionName + " (" + localX + ", " + localY + ")"; |
219 | return part; | 219 | return part; |
220 | } | 220 | } |
diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs index a676971..9dfeb96 100644 --- a/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs +++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/ScriptsHttpRequests.cs | |||
@@ -28,12 +28,15 @@ | |||
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; | ||
31 | using System.Net; | 32 | using System.Net; |
32 | using System.Net.Mail; | 33 | using System.Net.Mail; |
33 | using System.Net.Security; | 34 | using System.Net.Security; |
35 | using System.Reflection; | ||
34 | using System.Text; | 36 | using System.Text; |
35 | using System.Threading; | 37 | using System.Threading; |
36 | using System.Security.Cryptography.X509Certificates; | 38 | using System.Security.Cryptography.X509Certificates; |
39 | using log4net; | ||
37 | using Nini.Config; | 40 | using Nini.Config; |
38 | using OpenMetaverse; | 41 | using OpenMetaverse; |
39 | using OpenSim.Framework; | 42 | using OpenSim.Framework; |
@@ -91,10 +94,13 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
91 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HttpRequestModule")] | 94 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HttpRequestModule")] |
92 | public class HttpRequestModule : ISharedRegionModule, IHttpRequestModule | 95 | public class HttpRequestModule : ISharedRegionModule, IHttpRequestModule |
93 | { | 96 | { |
97 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
98 | |||
94 | private object HttpListLock = new object(); | 99 | private object HttpListLock = new object(); |
95 | private int httpTimeout = 30000; | 100 | private int httpTimeout = 30000; |
96 | private string m_name = "HttpScriptRequests"; | 101 | private string m_name = "HttpScriptRequests"; |
97 | 102 | ||
103 | private OutboundUrlFilter m_outboundUrlFilter; | ||
98 | private string m_proxyurl = ""; | 104 | private string m_proxyurl = ""; |
99 | private string m_proxyexcepts = ""; | 105 | private string m_proxyexcepts = ""; |
100 | 106 | ||
@@ -132,10 +138,12 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
132 | return false; | 138 | return false; |
133 | 139 | ||
134 | // Check for policy and execute it if defined | 140 | // Check for policy and execute it if defined |
141 | #pragma warning disable 0618 | ||
135 | if (ServicePointManager.CertificatePolicy != null) | 142 | if (ServicePointManager.CertificatePolicy != null) |
136 | { | 143 | { |
137 | return ServicePointManager.CertificatePolicy.CheckValidationResult (sp, certificate, Request, 0); | 144 | return ServicePointManager.CertificatePolicy.CheckValidationResult (sp, certificate, Request, 0); |
138 | } | 145 | } |
146 | #pragma warning restore 0618 | ||
139 | 147 | ||
140 | return true; | 148 | return true; |
141 | } | 149 | } |
@@ -153,7 +161,9 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
153 | return UUID.Zero; | 161 | return UUID.Zero; |
154 | } | 162 | } |
155 | 163 | ||
156 | public UUID StartHttpRequest(uint localID, UUID itemID, string url, List<string> parameters, Dictionary<string, string> headers, string body) | 164 | public UUID StartHttpRequest( |
165 | uint localID, UUID itemID, string url, List<string> parameters, Dictionary<string, string> headers, string body, | ||
166 | out HttpInitialRequestStatus status) | ||
157 | { | 167 | { |
158 | UUID reqID = UUID.Random(); | 168 | UUID reqID = UUID.Random(); |
159 | HttpRequestClass htc = new HttpRequestClass(); | 169 | HttpRequestClass htc = new HttpRequestClass(); |
@@ -187,10 +197,50 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
187 | case (int)HttpRequestConstants.HTTP_VERIFY_CERT: | 197 | case (int)HttpRequestConstants.HTTP_VERIFY_CERT: |
188 | htc.HttpVerifyCert = (int.Parse(parms[i + 1]) != 0); | 198 | htc.HttpVerifyCert = (int.Parse(parms[i + 1]) != 0); |
189 | break; | 199 | break; |
200 | |||
201 | case (int)HttpRequestConstants.HTTP_VERBOSE_THROTTLE: | ||
202 | |||
203 | // TODO implement me | ||
204 | break; | ||
205 | |||
206 | case (int)HttpRequestConstants.HTTP_CUSTOM_HEADER: | ||
207 | //Parameters are in pairs and custom header takes | ||
208 | //arguments in pairs so adjust for header marker. | ||
209 | ++i; | ||
210 | |||
211 | //Maximum of 8 headers are allowed based on the | ||
212 | //Second Life documentation for llHTTPRequest. | ||
213 | for (int count = 1; count <= 8; ++count) | ||
214 | { | ||
215 | //Not enough parameters remaining for a header? | ||
216 | if (parms.Length - i < 2) | ||
217 | break; | ||
218 | |||
219 | //Have we reached the end of the list of headers? | ||
220 | //End is marked by a string with a single digit. | ||
221 | //We already know we have at least one parameter | ||
222 | //so it is safe to do this check at top of loop. | ||
223 | if (Char.IsDigit(parms[i][0])) | ||
224 | break; | ||
225 | |||
226 | if (htc.HttpCustomHeaders == null) | ||
227 | htc.HttpCustomHeaders = new List<string>(); | ||
228 | |||
229 | htc.HttpCustomHeaders.Add(parms[i]); | ||
230 | htc.HttpCustomHeaders.Add(parms[i+1]); | ||
231 | |||
232 | i += 2; | ||
233 | } | ||
234 | break; | ||
235 | |||
236 | case (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE: | ||
237 | htc.HttpPragmaNoCache = (int.Parse(parms[i + 1]) != 0); | ||
238 | break; | ||
190 | } | 239 | } |
191 | } | 240 | } |
192 | } | 241 | } |
193 | 242 | ||
243 | htc.RequestModule = this; | ||
194 | htc.LocalID = localID; | 244 | htc.LocalID = localID; |
195 | htc.ItemID = itemID; | 245 | htc.ItemID = itemID; |
196 | htc.Url = url; | 246 | htc.Url = url; |
@@ -201,28 +251,68 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
201 | htc.proxyurl = m_proxyurl; | 251 | htc.proxyurl = m_proxyurl; |
202 | htc.proxyexcepts = m_proxyexcepts; | 252 | htc.proxyexcepts = m_proxyexcepts; |
203 | 253 | ||
254 | // Same number as default HttpWebRequest.MaximumAutomaticRedirections | ||
255 | htc.MaxRedirects = 50; | ||
256 | |||
257 | if (StartHttpRequest(htc)) | ||
258 | { | ||
259 | status = HttpInitialRequestStatus.OK; | ||
260 | return htc.ReqID; | ||
261 | } | ||
262 | else | ||
263 | { | ||
264 | status = HttpInitialRequestStatus.DISALLOWED_BY_FILTER; | ||
265 | return UUID.Zero; | ||
266 | } | ||
267 | } | ||
268 | |||
269 | /// <summary> | ||
270 | /// Would a caller to this module be allowed to make a request to the given URL? | ||
271 | /// </summary> | ||
272 | /// <returns></returns> | ||
273 | public bool CheckAllowed(Uri url) | ||
274 | { | ||
275 | return m_outboundUrlFilter.CheckAllowed(url); | ||
276 | } | ||
277 | |||
278 | public bool StartHttpRequest(HttpRequestClass req) | ||
279 | { | ||
280 | if (!CheckAllowed(new Uri(req.Url))) | ||
281 | return false; | ||
282 | |||
204 | lock (HttpListLock) | 283 | lock (HttpListLock) |
205 | { | 284 | { |
206 | m_pendingRequests.Add(reqID, htc); | 285 | m_pendingRequests.Add(req.ReqID, req); |
207 | } | 286 | } |
208 | 287 | ||
209 | htc.Process(); | 288 | req.Process(); |
210 | 289 | ||
211 | return reqID; | 290 | return true; |
212 | } | 291 | } |
213 | 292 | ||
214 | public void StopHttpRequest(uint m_localID, UUID m_itemID) | 293 | public void StopHttpRequestsForScript(UUID id) |
215 | { | 294 | { |
216 | if (m_pendingRequests != null) | 295 | if (m_pendingRequests != null) |
217 | { | 296 | { |
297 | List<UUID> keysToRemove = null; | ||
298 | |||
218 | lock (HttpListLock) | 299 | lock (HttpListLock) |
219 | { | 300 | { |
220 | HttpRequestClass tmpReq; | 301 | foreach (HttpRequestClass req in m_pendingRequests.Values) |
221 | if (m_pendingRequests.TryGetValue(m_itemID, out tmpReq)) | ||
222 | { | 302 | { |
223 | tmpReq.Stop(); | 303 | if (req.ItemID == id) |
224 | m_pendingRequests.Remove(m_itemID); | 304 | { |
305 | req.Stop(); | ||
306 | |||
307 | if (keysToRemove == null) | ||
308 | keysToRemove = new List<UUID>(); | ||
309 | |||
310 | keysToRemove.Add(req.ReqID); | ||
311 | } | ||
225 | } | 312 | } |
313 | |||
314 | if (keysToRemove != null) | ||
315 | keysToRemove.ForEach(keyToRemove => m_pendingRequests.Remove(keyToRemove)); | ||
226 | } | 316 | } |
227 | } | 317 | } |
228 | } | 318 | } |
@@ -240,19 +330,13 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
240 | { | 330 | { |
241 | lock (HttpListLock) | 331 | lock (HttpListLock) |
242 | { | 332 | { |
243 | foreach (UUID luid in m_pendingRequests.Keys) | 333 | foreach (HttpRequestClass req in m_pendingRequests.Values) |
244 | { | 334 | { |
245 | HttpRequestClass tmpReq; | 335 | if (req.Finished) |
246 | 336 | return req; | |
247 | if (m_pendingRequests.TryGetValue(luid, out tmpReq)) | ||
248 | { | ||
249 | if (tmpReq.Finished) | ||
250 | { | ||
251 | return tmpReq; | ||
252 | } | ||
253 | } | ||
254 | } | 337 | } |
255 | } | 338 | } |
339 | |||
256 | return null; | 340 | return null; |
257 | } | 341 | } |
258 | 342 | ||
@@ -279,6 +363,8 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
279 | m_proxyurl = config.Configs["Startup"].GetString("HttpProxy"); | 363 | m_proxyurl = config.Configs["Startup"].GetString("HttpProxy"); |
280 | m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions"); | 364 | m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions"); |
281 | 365 | ||
366 | m_outboundUrlFilter = new OutboundUrlFilter("Script HTTP request module", config); | ||
367 | |||
282 | m_pendingRequests = new Dictionary<UUID, HttpRequestClass>(); | 368 | m_pendingRequests = new Dictionary<UUID, HttpRequestClass>(); |
283 | } | 369 | } |
284 | 370 | ||
@@ -321,16 +407,27 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
321 | #endregion | 407 | #endregion |
322 | } | 408 | } |
323 | 409 | ||
324 | public class HttpRequestClass: IServiceRequest | 410 | public class HttpRequestClass : IServiceRequest |
325 | { | 411 | { |
412 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
413 | |||
326 | // Constants for parameters | 414 | // Constants for parameters |
327 | // public const int HTTP_BODY_MAXLENGTH = 2; | 415 | // public const int HTTP_BODY_MAXLENGTH = 2; |
328 | // public const int HTTP_METHOD = 0; | 416 | // public const int HTTP_METHOD = 0; |
329 | // public const int HTTP_MIMETYPE = 1; | 417 | // public const int HTTP_MIMETYPE = 1; |
330 | // public const int HTTP_VERIFY_CERT = 3; | 418 | // public const int HTTP_VERIFY_CERT = 3; |
419 | // public const int HTTP_VERBOSE_THROTTLE = 4; | ||
420 | // public const int HTTP_CUSTOM_HEADER = 5; | ||
421 | // public const int HTTP_PRAGMA_NO_CACHE = 6; | ||
422 | |||
423 | /// <summary> | ||
424 | /// Module that made this request. | ||
425 | /// </summary> | ||
426 | public HttpRequestModule RequestModule { get; set; } | ||
427 | |||
331 | private bool _finished; | 428 | private bool _finished; |
332 | public bool Finished | 429 | public bool Finished |
333 | { | 430 | { |
334 | get { return _finished; } | 431 | get { return _finished; } |
335 | } | 432 | } |
336 | // public int HttpBodyMaxLen = 2048; // not implemented | 433 | // public int HttpBodyMaxLen = 2048; // not implemented |
@@ -340,11 +437,13 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
340 | public string HttpMIMEType = "text/plain;charset=utf-8"; | 437 | public string HttpMIMEType = "text/plain;charset=utf-8"; |
341 | public int HttpTimeout; | 438 | public int HttpTimeout; |
342 | public bool HttpVerifyCert = true; | 439 | public bool HttpVerifyCert = true; |
343 | private Thread httpThread; | 440 | //public bool HttpVerboseThrottle = true; // not implemented |
441 | public List<string> HttpCustomHeaders = null; | ||
442 | public bool HttpPragmaNoCache = true; | ||
344 | 443 | ||
345 | // Request info | 444 | // Request info |
346 | private UUID _itemID; | 445 | private UUID _itemID; |
347 | public UUID ItemID | 446 | public UUID ItemID |
348 | { | 447 | { |
349 | get { return _itemID; } | 448 | get { return _itemID; } |
350 | set { _itemID = value; } | 449 | set { _itemID = value; } |
@@ -358,9 +457,20 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
358 | public DateTime Next; | 457 | public DateTime Next; |
359 | public string proxyurl; | 458 | public string proxyurl; |
360 | public string proxyexcepts; | 459 | public string proxyexcepts; |
460 | |||
461 | /// <summary> | ||
462 | /// Number of HTTP redirects that this request has been through. | ||
463 | /// </summary> | ||
464 | public int Redirects { get; private set; } | ||
465 | |||
466 | /// <summary> | ||
467 | /// Maximum number of HTTP redirects allowed for this request. | ||
468 | /// </summary> | ||
469 | public int MaxRedirects { get; set; } | ||
470 | |||
361 | public string OutboundBody; | 471 | public string OutboundBody; |
362 | private UUID _reqID; | 472 | private UUID _reqID; |
363 | public UUID ReqID | 473 | public UUID ReqID |
364 | { | 474 | { |
365 | get { return _reqID; } | 475 | get { return _reqID; } |
366 | set { _reqID = value; } | 476 | set { _reqID = value; } |
@@ -374,34 +484,19 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
374 | 484 | ||
375 | public void Process() | 485 | public void Process() |
376 | { | 486 | { |
377 | httpThread = new Thread(SendRequest); | 487 | SendRequest(); |
378 | httpThread.Name = "HttpRequestThread"; | ||
379 | httpThread.Priority = ThreadPriority.BelowNormal; | ||
380 | httpThread.IsBackground = true; | ||
381 | _finished = false; | ||
382 | httpThread.Start(); | ||
383 | } | 488 | } |
384 | 489 | ||
385 | /* | ||
386 | * TODO: More work on the response codes. Right now | ||
387 | * returning 200 for success or 499 for exception | ||
388 | */ | ||
389 | |||
390 | public void SendRequest() | 490 | public void SendRequest() |
391 | { | 491 | { |
392 | HttpWebResponse response = null; | ||
393 | StringBuilder sb = new StringBuilder(); | ||
394 | byte[] buf = new byte[8192]; | ||
395 | string tempString = null; | ||
396 | int count = 0; | ||
397 | |||
398 | try | 492 | try |
399 | { | 493 | { |
400 | Request = (HttpWebRequest) WebRequest.Create(Url); | 494 | Request = (HttpWebRequest)WebRequest.Create(Url); |
495 | Request.AllowAutoRedirect = false; | ||
401 | Request.Method = HttpMethod; | 496 | Request.Method = HttpMethod; |
402 | Request.ContentType = HttpMIMEType; | 497 | Request.ContentType = HttpMIMEType; |
403 | 498 | ||
404 | if(!HttpVerifyCert) | 499 | if (!HttpVerifyCert) |
405 | { | 500 | { |
406 | // We could hijack Connection Group Name to identify | 501 | // We could hijack Connection Group Name to identify |
407 | // a desired security exception. But at the moment we'll use a dummy header instead. | 502 | // a desired security exception. But at the moment we'll use a dummy header instead. |
@@ -412,41 +507,57 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
412 | // { | 507 | // { |
413 | // Request.ConnectionGroupName="Verify"; | 508 | // Request.ConnectionGroupName="Verify"; |
414 | // } | 509 | // } |
415 | if (proxyurl != null && proxyurl.Length > 0) | 510 | |
511 | if (!HttpPragmaNoCache) | ||
512 | { | ||
513 | Request.Headers.Add("Pragma", "no-cache"); | ||
514 | } | ||
515 | |||
516 | if (HttpCustomHeaders != null) | ||
517 | { | ||
518 | for (int i = 0; i < HttpCustomHeaders.Count; i += 2) | ||
519 | Request.Headers.Add(HttpCustomHeaders[i], | ||
520 | HttpCustomHeaders[i+1]); | ||
521 | } | ||
522 | |||
523 | if (!string.IsNullOrEmpty(proxyurl)) | ||
416 | { | 524 | { |
417 | if (proxyexcepts != null && proxyexcepts.Length > 0) | 525 | if (!string.IsNullOrEmpty(proxyexcepts)) |
418 | { | 526 | { |
419 | string[] elist = proxyexcepts.Split(';'); | 527 | string[] elist = proxyexcepts.Split(';'); |
420 | Request.Proxy = new WebProxy(proxyurl, true, elist); | 528 | Request.Proxy = new WebProxy(proxyurl, true, elist); |
421 | } | 529 | } |
422 | else | 530 | else |
423 | { | 531 | { |
424 | Request.Proxy = new WebProxy(proxyurl, true); | 532 | Request.Proxy = new WebProxy(proxyurl, true); |
425 | } | 533 | } |
426 | } | 534 | } |
427 | 535 | ||
428 | foreach (KeyValuePair<string, string> entry in ResponseHeaders) | 536 | if (ResponseHeaders != null) |
429 | if (entry.Key.ToLower().Equals("user-agent")) | 537 | { |
430 | Request.UserAgent = entry.Value; | 538 | foreach (KeyValuePair<string, string> entry in ResponseHeaders) |
431 | else | 539 | if (entry.Key.ToLower().Equals("user-agent") && Request is HttpWebRequest) |
432 | Request.Headers[entry.Key] = entry.Value; | 540 | ((HttpWebRequest)Request).UserAgent = entry.Value; |
541 | else | ||
542 | Request.Headers[entry.Key] = entry.Value; | ||
543 | } | ||
433 | 544 | ||
434 | // Encode outbound data | 545 | // Encode outbound data |
435 | if (OutboundBody.Length > 0) | 546 | if (!string.IsNullOrEmpty(OutboundBody)) |
436 | { | 547 | { |
437 | byte[] data = Util.UTF8.GetBytes(OutboundBody); | 548 | byte[] data = Util.UTF8.GetBytes(OutboundBody); |
438 | 549 | ||
439 | Request.ContentLength = data.Length; | 550 | Request.ContentLength = data.Length; |
440 | Stream bstream = Request.GetRequestStream(); | 551 | using (Stream bstream = Request.GetRequestStream()) |
441 | bstream.Write(data, 0, data.Length); | 552 | bstream.Write(data, 0, data.Length); |
442 | bstream.Close(); | ||
443 | } | 553 | } |
444 | 554 | ||
445 | Request.Timeout = HttpTimeout; | ||
446 | try | 555 | try |
447 | { | 556 | { |
448 | // execute the request | 557 | IAsyncResult result = (IAsyncResult)Request.BeginGetResponse(ResponseCallback, null); |
449 | response = (HttpWebResponse) Request.GetResponse(); | 558 | |
559 | ThreadPool.RegisterWaitForSingleObject( | ||
560 | result.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), null, HttpTimeout, true); | ||
450 | } | 561 | } |
451 | catch (WebException e) | 562 | catch (WebException e) |
452 | { | 563 | { |
@@ -454,57 +565,127 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest | |||
454 | { | 565 | { |
455 | throw; | 566 | throw; |
456 | } | 567 | } |
457 | response = (HttpWebResponse)e.Response; | 568 | |
569 | HttpWebResponse response = (HttpWebResponse)e.Response; | ||
570 | |||
571 | Status = (int)response.StatusCode; | ||
572 | ResponseBody = response.StatusDescription; | ||
573 | _finished = true; | ||
458 | } | 574 | } |
575 | } | ||
576 | catch (Exception e) | ||
577 | { | ||
578 | // m_log.Debug( | ||
579 | // string.Format("[SCRIPTS HTTP REQUESTS]: Exception on request to {0} for {1} ", Url, ItemID), e); | ||
459 | 580 | ||
460 | Status = (int)response.StatusCode; | 581 | Status = (int)OSHttpStatusCode.ClientErrorJoker; |
582 | ResponseBody = e.Message; | ||
583 | _finished = true; | ||
584 | } | ||
585 | } | ||
461 | 586 | ||
462 | Stream resStream = response.GetResponseStream(); | 587 | private void ResponseCallback(IAsyncResult ar) |
588 | { | ||
589 | HttpWebResponse response = null; | ||
463 | 590 | ||
464 | do | 591 | try |
592 | { | ||
593 | try | ||
465 | { | 594 | { |
466 | // fill the buffer with data | 595 | response = (HttpWebResponse)Request.EndGetResponse(ar); |
467 | count = resStream.Read(buf, 0, buf.Length); | 596 | } |
468 | 597 | catch (WebException e) | |
469 | // make sure we read some data | 598 | { |
470 | if (count != 0) | 599 | if (e.Status != WebExceptionStatus.ProtocolError) |
471 | { | 600 | { |
472 | // translate from bytes to ASCII text | 601 | throw; |
473 | tempString = Util.UTF8.GetString(buf, 0, count); | ||
474 | |||
475 | // continue building the string | ||
476 | sb.Append(tempString); | ||
477 | } | 602 | } |
478 | } while (count > 0); // any more data to read? | ||
479 | 603 | ||
480 | ResponseBody = sb.ToString(); | 604 | response = (HttpWebResponse)e.Response; |
605 | } | ||
606 | |||
607 | Status = (int)response.StatusCode; | ||
608 | |||
609 | using (Stream stream = response.GetResponseStream()) | ||
610 | { | ||
611 | StreamReader reader = new StreamReader(stream, Encoding.UTF8); | ||
612 | ResponseBody = reader.ReadToEnd(); | ||
613 | } | ||
481 | } | 614 | } |
482 | catch (Exception e) | 615 | catch (Exception e) |
483 | { | 616 | { |
484 | Status = (int)OSHttpStatusCode.ClientErrorJoker; | 617 | Status = (int)OSHttpStatusCode.ClientErrorJoker; |
485 | ResponseBody = e.Message; | 618 | ResponseBody = e.Message; |
486 | 619 | ||
487 | _finished = true; | 620 | // m_log.Debug( |
488 | return; | 621 | // string.Format("[SCRIPTS HTTP REQUESTS]: Exception on response to {0} for {1} ", Url, ItemID), e); |
489 | } | 622 | } |
490 | finally | 623 | finally |
491 | { | 624 | { |
492 | if (response != null) | 625 | if (response != null) |
493 | response.Close(); | 626 | response.Close(); |
627 | |||
628 | // We need to resubmit | ||
629 | if ( | ||
630 | (Status == (int)HttpStatusCode.MovedPermanently | ||
631 | || Status == (int)HttpStatusCode.Found | ||
632 | || Status == (int)HttpStatusCode.SeeOther | ||
633 | || Status == (int)HttpStatusCode.TemporaryRedirect)) | ||
634 | { | ||
635 | if (Redirects >= MaxRedirects) | ||
636 | { | ||
637 | Status = (int)OSHttpStatusCode.ClientErrorJoker; | ||
638 | ResponseBody = "Number of redirects exceeded max redirects"; | ||
639 | _finished = true; | ||
640 | } | ||
641 | else | ||
642 | { | ||
643 | string location = response.Headers["Location"]; | ||
644 | |||
645 | if (location == null) | ||
646 | { | ||
647 | Status = (int)OSHttpStatusCode.ClientErrorJoker; | ||
648 | ResponseBody = "HTTP redirect code but no location header"; | ||
649 | _finished = true; | ||
650 | } | ||
651 | else if (!RequestModule.CheckAllowed(new Uri(location))) | ||
652 | { | ||
653 | Status = (int)OSHttpStatusCode.ClientErrorJoker; | ||
654 | ResponseBody = "URL from HTTP redirect blocked: " + location; | ||
655 | _finished = true; | ||
656 | } | ||
657 | else | ||
658 | { | ||
659 | Status = 0; | ||
660 | Url = response.Headers["Location"]; | ||
661 | Redirects++; | ||
662 | ResponseBody = null; | ||
663 | |||
664 | // m_log.DebugFormat("Redirecting to [{0}]", Url); | ||
665 | |||
666 | Process(); | ||
667 | } | ||
668 | } | ||
669 | } | ||
670 | else | ||
671 | { | ||
672 | _finished = true; | ||
673 | } | ||
494 | } | 674 | } |
675 | } | ||
495 | 676 | ||
496 | _finished = true; | 677 | private void TimeoutCallback(object state, bool timedOut) |
678 | { | ||
679 | if (timedOut) | ||
680 | Request.Abort(); | ||
497 | } | 681 | } |
498 | 682 | ||
499 | public void Stop() | 683 | public void Stop() |
500 | { | 684 | { |
501 | try | 685 | // m_log.DebugFormat("[SCRIPTS HTTP REQUESTS]: Stopping request to {0} for {1} ", Url, ItemID); |
502 | { | 686 | |
503 | httpThread.Abort(); | 687 | if (Request != null) |
504 | } | 688 | Request.Abort(); |
505 | catch (Exception) | ||
506 | { | ||
507 | } | ||
508 | } | 689 | } |
509 | } | 690 | } |
510 | } | 691 | } \ No newline at end of file |
diff --git a/OpenSim/Region/CoreModules/Scripting/HttpRequest/Tests/ScriptsHttpRequestsTests.cs b/OpenSim/Region/CoreModules/Scripting/HttpRequest/Tests/ScriptsHttpRequestsTests.cs new file mode 100644 index 0000000..d22487e --- /dev/null +++ b/OpenSim/Region/CoreModules/Scripting/HttpRequest/Tests/ScriptsHttpRequestsTests.cs | |||
@@ -0,0 +1,199 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Runtime.Serialization; | ||
34 | using System.Text; | ||
35 | using System.Threading; | ||
36 | using log4net.Config; | ||
37 | using NUnit.Framework; | ||
38 | using OpenMetaverse; | ||
39 | using OpenMetaverse.Assets; | ||
40 | using OpenSim.Framework; | ||
41 | using OpenSim.Region.CoreModules.Scripting.HttpRequest; | ||
42 | using OpenSim.Region.Framework.Scenes; | ||
43 | using OpenSim.Tests.Common; | ||
44 | |||
45 | namespace OpenSim.Region.CoreModules.Scripting.HttpRequest.Tests | ||
46 | { | ||
47 | class TestWebRequestCreate : IWebRequestCreate | ||
48 | { | ||
49 | public TestWebRequest NextRequest { get; set; } | ||
50 | |||
51 | public WebRequest Create(Uri uri) | ||
52 | { | ||
53 | // NextRequest.RequestUri = uri; | ||
54 | |||
55 | return NextRequest; | ||
56 | |||
57 | // return new TestWebRequest(new SerializationInfo(typeof(TestWebRequest), new FormatterConverter()), new StreamingContext()); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | class TestWebRequest : WebRequest | ||
62 | { | ||
63 | public override string ContentType { get; set; } | ||
64 | public override string Method { get; set; } | ||
65 | |||
66 | public Func<IAsyncResult, WebResponse> OnEndGetResponse { get; set; } | ||
67 | |||
68 | public TestWebRequest() : base() | ||
69 | { | ||
70 | // Console.WriteLine("created"); | ||
71 | } | ||
72 | |||
73 | // public TestWebRequest(SerializationInfo serializationInfo, StreamingContext streamingContext) | ||
74 | // : base(serializationInfo, streamingContext) | ||
75 | // { | ||
76 | // Console.WriteLine("created"); | ||
77 | // } | ||
78 | |||
79 | public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state) | ||
80 | { | ||
81 | // Console.WriteLine("bish"); | ||
82 | TestAsyncResult tasr = new TestAsyncResult(); | ||
83 | callback(tasr); | ||
84 | |||
85 | return tasr; | ||
86 | } | ||
87 | |||
88 | public override WebResponse EndGetResponse(IAsyncResult asyncResult) | ||
89 | { | ||
90 | // Console.WriteLine("bosh"); | ||
91 | return OnEndGetResponse(asyncResult); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | class TestHttpWebResponse : HttpWebResponse | ||
96 | { | ||
97 | public string Response { get; set; } | ||
98 | |||
99 | #pragma warning disable 0618 | ||
100 | public TestHttpWebResponse(SerializationInfo serializationInfo, StreamingContext streamingContext) | ||
101 | : base(serializationInfo, streamingContext) {} | ||
102 | #pragma warning restore 0618 | ||
103 | |||
104 | public override Stream GetResponseStream() | ||
105 | { | ||
106 | return new MemoryStream(Encoding.UTF8.GetBytes(Response)); | ||
107 | } | ||
108 | } | ||
109 | |||
110 | class TestAsyncResult : IAsyncResult | ||
111 | { | ||
112 | WaitHandle m_wh = new ManualResetEvent(true); | ||
113 | |||
114 | object IAsyncResult.AsyncState | ||
115 | { | ||
116 | get { | ||
117 | throw new System.NotImplementedException (); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | WaitHandle IAsyncResult.AsyncWaitHandle | ||
122 | { | ||
123 | get { return m_wh; } | ||
124 | } | ||
125 | |||
126 | bool IAsyncResult.CompletedSynchronously | ||
127 | { | ||
128 | get { return false; } | ||
129 | } | ||
130 | |||
131 | bool IAsyncResult.IsCompleted | ||
132 | { | ||
133 | get { return true; } | ||
134 | } | ||
135 | } | ||
136 | |||
137 | /// <summary> | ||
138 | /// Test script http request code. | ||
139 | /// </summary> | ||
140 | /// <remarks> | ||
141 | /// This class uses some very hacky workarounds in order to mock HttpWebResponse which are Mono dependent (though | ||
142 | /// alternative code can be written to make this work for Windows). However, the value of being able to | ||
143 | /// regression test this kind of code is very high. | ||
144 | /// </remarks> | ||
145 | [TestFixture] | ||
146 | public class ScriptsHttpRequestsTests : OpenSimTestCase | ||
147 | { | ||
148 | /// <summary> | ||
149 | /// Test what happens when we get a 404 response from a call. | ||
150 | /// </summary> | ||
151 | // [Test] | ||
152 | public void Test404Response() | ||
153 | { | ||
154 | TestHelpers.InMethod(); | ||
155 | TestHelpers.EnableLogging(); | ||
156 | |||
157 | if (!Util.IsPlatformMono) | ||
158 | Assert.Ignore("Ignoring test since can only currently run on Mono"); | ||
159 | |||
160 | string rawResponse = "boom"; | ||
161 | |||
162 | TestWebRequestCreate twrc = new TestWebRequestCreate(); | ||
163 | |||
164 | TestWebRequest twr = new TestWebRequest(); | ||
165 | //twr.OnEndGetResponse += ar => new TestHttpWebResponse(null, new StreamingContext()); | ||
166 | twr.OnEndGetResponse += ar => | ||
167 | { | ||
168 | SerializationInfo si = new SerializationInfo(typeof(HttpWebResponse), new FormatterConverter()); | ||
169 | StreamingContext sc = new StreamingContext(); | ||
170 | // WebHeaderCollection headers = new WebHeaderCollection(); | ||
171 | // si.AddValue("m_HttpResponseHeaders", headers); | ||
172 | si.AddValue("uri", new Uri("test://arrg")); | ||
173 | // si.AddValue("m_Certificate", null); | ||
174 | si.AddValue("version", HttpVersion.Version11); | ||
175 | si.AddValue("statusCode", HttpStatusCode.NotFound); | ||
176 | si.AddValue("contentLength", 0); | ||
177 | si.AddValue("method", "GET"); | ||
178 | si.AddValue("statusDescription", "Not Found"); | ||
179 | si.AddValue("contentType", null); | ||
180 | si.AddValue("cookieCollection", new CookieCollection()); | ||
181 | |||
182 | TestHttpWebResponse thwr = new TestHttpWebResponse(si, sc); | ||
183 | thwr.Response = rawResponse; | ||
184 | |||
185 | throw new WebException("no message", null, WebExceptionStatus.ProtocolError, thwr); | ||
186 | }; | ||
187 | |||
188 | twrc.NextRequest = twr; | ||
189 | |||
190 | WebRequest.RegisterPrefix("test", twrc); | ||
191 | HttpRequestClass hr = new HttpRequestClass(); | ||
192 | hr.Url = "test://something"; | ||
193 | hr.SendRequest(); | ||
194 | |||
195 | Assert.That(hr.Status, Is.EqualTo((int)HttpStatusCode.NotFound)); | ||
196 | Assert.That(hr.ResponseBody, Is.EqualTo(rawResponse)); | ||
197 | } | ||
198 | } | ||
199 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs index a654477..99a3122 100644 --- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs | |||
@@ -117,20 +117,21 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
117 | /// </summary> | 117 | /// </summary> |
118 | private Dictionary<string, UrlData> m_UrlMap = new Dictionary<string, UrlData>(); | 118 | private Dictionary<string, UrlData> m_UrlMap = new Dictionary<string, UrlData>(); |
119 | 119 | ||
120 | /// <summary> | 120 | private uint m_HttpsPort = 0; |
121 | /// Maximum number of external urls that can be set up by this module. | ||
122 | /// </summary> | ||
123 | private int m_TotalUrls = 100; | ||
124 | |||
125 | private uint https_port = 0; | ||
126 | private IHttpServer m_HttpServer = null; | 121 | private IHttpServer m_HttpServer = null; |
127 | private IHttpServer m_HttpsServer = null; | 122 | private IHttpServer m_HttpsServer = null; |
128 | 123 | ||
129 | private string m_ExternalHostNameForLSL = ""; | 124 | public string ExternalHostNameForLSL { get; private set; } |
130 | public string ExternalHostNameForLSL | 125 | |
131 | { | 126 | /// <summary> |
132 | get { return m_ExternalHostNameForLSL; } | 127 | /// The default maximum number of urls |
133 | } | 128 | /// </summary> |
129 | public const int DefaultTotalUrls = 100; | ||
130 | |||
131 | /// <summary> | ||
132 | /// Maximum number of external urls that can be set up by this module. | ||
133 | /// </summary> | ||
134 | public int TotalUrls { get; set; } | ||
134 | 135 | ||
135 | public Type ReplaceableInterface | 136 | public Type ReplaceableInterface |
136 | { | 137 | { |
@@ -144,16 +145,27 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
144 | 145 | ||
145 | public void Initialise(IConfigSource config) | 146 | public void Initialise(IConfigSource config) |
146 | { | 147 | { |
147 | m_ExternalHostNameForLSL = config.Configs["Network"].GetString("ExternalHostNameForLSL", System.Environment.MachineName); | 148 | IConfig networkConfig = config.Configs["Network"]; |
148 | bool ssl_enabled = config.Configs["Network"].GetBoolean("https_listener",false); | 149 | |
150 | if (networkConfig != null) | ||
151 | { | ||
152 | ExternalHostNameForLSL = config.Configs["Network"].GetString("ExternalHostNameForLSL", null); | ||
153 | |||
154 | bool ssl_enabled = config.Configs["Network"].GetBoolean("https_listener", false); | ||
155 | |||
156 | if (ssl_enabled) | ||
157 | m_HttpsPort = (uint)config.Configs["Network"].GetInt("https_port", (int)m_HttpsPort); | ||
158 | } | ||
149 | 159 | ||
150 | if (ssl_enabled) | 160 | if (ExternalHostNameForLSL == null) |
151 | https_port = (uint) config.Configs["Network"].GetInt("https_port",0); | 161 | ExternalHostNameForLSL = System.Environment.MachineName; |
152 | 162 | ||
153 | IConfig llFunctionsConfig = config.Configs["LL-Functions"]; | 163 | IConfig llFunctionsConfig = config.Configs["LL-Functions"]; |
154 | 164 | ||
155 | if (llFunctionsConfig != null) | 165 | if (llFunctionsConfig != null) |
156 | m_TotalUrls = llFunctionsConfig.GetInt("max_external_urls_per_simulator", m_TotalUrls); | 166 | TotalUrls = llFunctionsConfig.GetInt("max_external_urls_per_simulator", DefaultTotalUrls); |
167 | else | ||
168 | TotalUrls = DefaultTotalUrls; | ||
157 | } | 169 | } |
158 | 170 | ||
159 | public void PostInitialise() | 171 | public void PostInitialise() |
@@ -169,9 +181,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
169 | m_HttpServer = MainServer.Instance; | 181 | m_HttpServer = MainServer.Instance; |
170 | // | 182 | // |
171 | // We can use the https if it is enabled | 183 | // We can use the https if it is enabled |
172 | if (https_port > 0) | 184 | if (m_HttpsPort > 0) |
173 | { | 185 | { |
174 | m_HttpsServer = MainServer.GetHttpServer(https_port); | 186 | m_HttpsServer = MainServer.GetHttpServer(m_HttpsPort); |
175 | } | 187 | } |
176 | } | 188 | } |
177 | 189 | ||
@@ -204,12 +216,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
204 | 216 | ||
205 | lock (m_UrlMap) | 217 | lock (m_UrlMap) |
206 | { | 218 | { |
207 | if (m_UrlMap.Count >= m_TotalUrls) | 219 | if (m_UrlMap.Count >= TotalUrls) |
208 | { | 220 | { |
209 | 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", "" }); |
210 | return urlcode; | 222 | return urlcode; |
211 | } | 223 | } |
212 | string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/"; | 224 | string url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/"; |
213 | 225 | ||
214 | UrlData urlData = new UrlData(); | 226 | UrlData urlData = new UrlData(); |
215 | urlData.hostID = host.UUID; | 227 | urlData.hostID = host.UUID; |
@@ -223,9 +235,10 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
223 | 235 | ||
224 | string uri = "/lslhttp/" + urlcode.ToString() + "/"; | 236 | string uri = "/lslhttp/" + urlcode.ToString() + "/"; |
225 | 237 | ||
226 | m_HttpServer.AddPollServiceHTTPHandler( | 238 | PollServiceEventArgs args |
227 | uri, | 239 | = new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, urlcode, 25000); |
228 | new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode)); | 240 | args.Type = PollServiceEventArgs.EventType.LslHttp; |
241 | m_HttpServer.AddPollServiceHTTPHandler(uri, args); | ||
229 | 242 | ||
230 | m_log.DebugFormat( | 243 | m_log.DebugFormat( |
231 | "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}", | 244 | "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}", |
@@ -249,12 +262,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
249 | 262 | ||
250 | lock (m_UrlMap) | 263 | lock (m_UrlMap) |
251 | { | 264 | { |
252 | if (m_UrlMap.Count >= m_TotalUrls) | 265 | if (m_UrlMap.Count >= TotalUrls) |
253 | { | 266 | { |
254 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); | 267 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); |
255 | return urlcode; | 268 | return urlcode; |
256 | } | 269 | } |
257 | string url = "https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/"; | 270 | string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/"; |
258 | 271 | ||
259 | UrlData urlData = new UrlData(); | 272 | UrlData urlData = new UrlData(); |
260 | urlData.hostID = host.UUID; | 273 | urlData.hostID = host.UUID; |
@@ -268,9 +281,10 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
268 | 281 | ||
269 | string uri = "/lslhttps/" + urlcode.ToString() + "/"; | 282 | string uri = "/lslhttps/" + urlcode.ToString() + "/"; |
270 | 283 | ||
271 | m_HttpsServer.AddPollServiceHTTPHandler( | 284 | PollServiceEventArgs args |
272 | uri, | 285 | = new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, urlcode, 25000); |
273 | new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode)); | 286 | args.Type = PollServiceEventArgs.EventType.LslHttp; |
287 | m_HttpsServer.AddPollServiceHTTPHandler(uri, args); | ||
274 | 288 | ||
275 | m_log.DebugFormat( | 289 | m_log.DebugFormat( |
276 | "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}", | 290 | "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}", |
@@ -328,8 +342,22 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
328 | if (m_RequestMap.ContainsKey(request)) | 342 | if (m_RequestMap.ContainsKey(request)) |
329 | { | 343 | { |
330 | UrlData urlData = m_RequestMap[request]; | 344 | UrlData urlData = m_RequestMap[request]; |
345 | string responseBody = body; | ||
346 | if (urlData.requests[request].responseType.Equals("text/plain")) | ||
347 | { | ||
348 | string value; | ||
349 | if (urlData.requests[request].headers.TryGetValue("user-agent", out value)) | ||
350 | { | ||
351 | if (value != null && value.IndexOf("MSIE") >= 0) | ||
352 | { | ||
353 | // wrap the html escaped response if the target client is IE | ||
354 | // It ignores "text/plain" if the body is html | ||
355 | responseBody = "<html>" + System.Web.HttpUtility.HtmlEncode(body) + "</html>"; | ||
356 | } | ||
357 | } | ||
358 | } | ||
331 | urlData.requests[request].responseCode = status; | 359 | urlData.requests[request].responseCode = status; |
332 | urlData.requests[request].responseBody = body; | 360 | urlData.requests[request].responseBody = responseBody; |
333 | //urlData.requests[request].ev.Set(); | 361 | //urlData.requests[request].ev.Set(); |
334 | urlData.requests[request].requestDone =true; | 362 | urlData.requests[request].requestDone =true; |
335 | } | 363 | } |
@@ -363,7 +391,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
363 | public int GetFreeUrls() | 391 | public int GetFreeUrls() |
364 | { | 392 | { |
365 | lock (m_UrlMap) | 393 | lock (m_UrlMap) |
366 | return m_TotalUrls - m_UrlMap.Count; | 394 | return TotalUrls - m_UrlMap.Count; |
367 | } | 395 | } |
368 | 396 | ||
369 | public void ScriptRemoved(UUID itemID) | 397 | public void ScriptRemoved(UUID itemID) |
@@ -490,7 +518,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
490 | } | 518 | } |
491 | } | 519 | } |
492 | 520 | ||
493 | private Hashtable GetEvents(UUID requestID, UUID sessionID, string request) | 521 | private Hashtable GetEvents(UUID requestID, UUID sessionID) |
494 | { | 522 | { |
495 | Hashtable response; | 523 | Hashtable response; |
496 | 524 | ||
@@ -565,9 +593,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
565 | string url; | 593 | string url; |
566 | 594 | ||
567 | if (is_ssl) | 595 | if (is_ssl) |
568 | url = "https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp; | 596 | url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp; |
569 | else | 597 | else |
570 | url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp; | 598 | url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp; |
571 | 599 | ||
572 | // Avoid a race - the request URL may have been released via llRequestUrl() whilst this | 600 | // Avoid a race - the request URL may have been released via llRequestUrl() whilst this |
573 | // request was being processed. | 601 | // request was being processed. |
@@ -642,4 +670,4 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
642 | ScriptRemoved(itemID); | 670 | ScriptRemoved(itemID); |
643 | } | 671 | } |
644 | } | 672 | } |
645 | } \ No newline at end of file | 673 | } |
diff --git a/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs b/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs index 65737fa..d45962f 100644 --- a/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs | |||
@@ -32,6 +32,7 @@ using System.Net; | |||
32 | using Nini.Config; | 32 | using Nini.Config; |
33 | using OpenMetaverse; | 33 | using OpenMetaverse; |
34 | using OpenMetaverse.Imaging; | 34 | using OpenMetaverse.Imaging; |
35 | using OpenSim.Framework; | ||
35 | using OpenSim.Region.CoreModules.Scripting.DynamicTexture; | 36 | using OpenSim.Region.CoreModules.Scripting.DynamicTexture; |
36 | using OpenSim.Region.Framework.Interfaces; | 37 | using OpenSim.Region.Framework.Interfaces; |
37 | using OpenSim.Region.Framework.Scenes; | 38 | using OpenSim.Region.Framework.Scenes; |
@@ -50,6 +51,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LoadImageURL | |||
50 | private Scene m_scene; | 51 | private Scene m_scene; |
51 | private IDynamicTextureManager m_textureManager; | 52 | private IDynamicTextureManager m_textureManager; |
52 | 53 | ||
54 | private OutboundUrlFilter m_outboundUrlFilter; | ||
53 | private string m_proxyurl = ""; | 55 | private string m_proxyurl = ""; |
54 | private string m_proxyexcepts = ""; | 56 | private string m_proxyexcepts = ""; |
55 | 57 | ||
@@ -88,8 +90,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LoadImageURL | |||
88 | 90 | ||
89 | public bool AsyncConvertUrl(UUID id, string url, string extraParams) | 91 | public bool AsyncConvertUrl(UUID id, string url, string extraParams) |
90 | { | 92 | { |
91 | MakeHttpRequest(url, id); | 93 | return MakeHttpRequest(url, id); |
92 | return true; | ||
93 | } | 94 | } |
94 | 95 | ||
95 | public bool AsyncConvertData(UUID id, string bodyData, string extraParams) | 96 | public bool AsyncConvertData(UUID id, string bodyData, string extraParams) |
@@ -110,6 +111,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LoadImageURL | |||
110 | 111 | ||
111 | public void Initialise(IConfigSource config) | 112 | public void Initialise(IConfigSource config) |
112 | { | 113 | { |
114 | m_outboundUrlFilter = new OutboundUrlFilter("Script dynamic texture image module", config); | ||
113 | m_proxyurl = config.Configs["Startup"].GetString("HttpProxy"); | 115 | m_proxyurl = config.Configs["Startup"].GetString("HttpProxy"); |
114 | m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions"); | 116 | m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions"); |
115 | } | 117 | } |
@@ -157,13 +159,17 @@ namespace OpenSim.Region.CoreModules.Scripting.LoadImageURL | |||
157 | 159 | ||
158 | #endregion | 160 | #endregion |
159 | 161 | ||
160 | private void MakeHttpRequest(string url, UUID requestID) | 162 | private bool MakeHttpRequest(string url, UUID requestID) |
161 | { | 163 | { |
162 | WebRequest request = HttpWebRequest.Create(url); | 164 | if (!m_outboundUrlFilter.CheckAllowed(new Uri(url))) |
165 | return false; | ||
166 | |||
167 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); | ||
168 | request.AllowAutoRedirect = false; | ||
163 | 169 | ||
164 | if (m_proxyurl != null && m_proxyurl.Length > 0) | 170 | if (!string.IsNullOrEmpty(m_proxyurl)) |
165 | { | 171 | { |
166 | if (m_proxyexcepts != null && m_proxyexcepts.Length > 0) | 172 | if (!string.IsNullOrEmpty(m_proxyexcepts)) |
167 | { | 173 | { |
168 | string[] elist = m_proxyexcepts.Split(';'); | 174 | string[] elist = m_proxyexcepts.Split(';'); |
169 | request.Proxy = new WebProxy(m_proxyurl, true, elist); | 175 | request.Proxy = new WebProxy(m_proxyurl, true, elist); |
@@ -174,12 +180,14 @@ namespace OpenSim.Region.CoreModules.Scripting.LoadImageURL | |||
174 | } | 180 | } |
175 | } | 181 | } |
176 | 182 | ||
177 | RequestState state = new RequestState((HttpWebRequest) request, requestID); | 183 | RequestState state = new RequestState(request, requestID); |
178 | // IAsyncResult result = request.BeginGetResponse(new AsyncCallback(HttpRequestReturn), state); | 184 | // IAsyncResult result = request.BeginGetResponse(new AsyncCallback(HttpRequestReturn), state); |
179 | request.BeginGetResponse(new AsyncCallback(HttpRequestReturn), state); | 185 | request.BeginGetResponse(new AsyncCallback(HttpRequestReturn), state); |
180 | 186 | ||
181 | TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1)); | 187 | TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1)); |
182 | state.TimeOfRequest = (int) t.TotalSeconds; | 188 | state.TimeOfRequest = (int) t.TotalSeconds; |
189 | |||
190 | return true; | ||
183 | } | 191 | } |
184 | 192 | ||
185 | private void HttpRequestReturn(IAsyncResult result) | 193 | private void HttpRequestReturn(IAsyncResult result) |
@@ -195,10 +203,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LoadImageURL | |||
195 | Stream stream = null; | 203 | Stream stream = null; |
196 | byte[] imageJ2000 = new byte[0]; | 204 | byte[] imageJ2000 = new byte[0]; |
197 | Size newSize = new Size(0, 0); | 205 | Size newSize = new Size(0, 0); |
206 | HttpWebResponse response = null; | ||
198 | 207 | ||
199 | try | 208 | try |
200 | { | 209 | { |
201 | HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result); | 210 | response = (HttpWebResponse)request.EndGetResponse(result); |
202 | if (response != null && response.StatusCode == HttpStatusCode.OK) | 211 | if (response != null && response.StatusCode == HttpStatusCode.OK) |
203 | { | 212 | { |
204 | stream = response.GetResponseStream(); | 213 | stream = response.GetResponseStream(); |
@@ -262,18 +271,32 @@ namespace OpenSim.Region.CoreModules.Scripting.LoadImageURL | |||
262 | finally | 271 | finally |
263 | { | 272 | { |
264 | if (stream != null) | 273 | if (stream != null) |
265 | { | ||
266 | stream.Close(); | 274 | stream.Close(); |
267 | } | ||
268 | } | ||
269 | 275 | ||
270 | m_log.DebugFormat("[LOADIMAGEURLMODULE]: Returning {0} bytes of image data for request {1}", | 276 | if (response != null) |
271 | imageJ2000.Length, state.RequestID); | 277 | response.Close(); |
272 | 278 | ||
273 | m_textureManager.ReturnData( | 279 | if ( |
274 | state.RequestID, | 280 | response.StatusCode == HttpStatusCode.MovedPermanently |
275 | new OpenSim.Region.CoreModules.Scripting.DynamicTexture.DynamicTexture( | 281 | || response.StatusCode == HttpStatusCode.Found |
276 | request.RequestUri, null, imageJ2000, newSize, false)); | 282 | || response.StatusCode == HttpStatusCode.SeeOther |
283 | || response.StatusCode == HttpStatusCode.TemporaryRedirect) | ||
284 | { | ||
285 | string redirectedUrl = response.Headers["Location"]; | ||
286 | |||
287 | MakeHttpRequest(redirectedUrl, state.RequestID); | ||
288 | } | ||
289 | else | ||
290 | { | ||
291 | m_log.DebugFormat("[LOADIMAGEURLMODULE]: Returning {0} bytes of image data for request {1}", | ||
292 | imageJ2000.Length, state.RequestID); | ||
293 | |||
294 | m_textureManager.ReturnData( | ||
295 | state.RequestID, | ||
296 | new OpenSim.Region.CoreModules.Scripting.DynamicTexture.DynamicTexture( | ||
297 | request.RequestUri, null, imageJ2000, newSize, false)); | ||
298 | } | ||
299 | } | ||
277 | } | 300 | } |
278 | 301 | ||
279 | #region Nested type: RequestState | 302 | #region Nested type: RequestState |
diff --git a/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index f6e1d39..6da2222 100644 --- a/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | |||
@@ -41,10 +41,11 @@ using System.Linq.Expressions; | |||
41 | namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | 41 | namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms |
42 | { | 42 | { |
43 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ScriptModuleCommsModule")] | 43 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ScriptModuleCommsModule")] |
44 | class ScriptModuleCommsModule : INonSharedRegionModule, IScriptModuleComms | 44 | public class ScriptModuleCommsModule : INonSharedRegionModule, IScriptModuleComms |
45 | { | 45 | { |
46 | private static readonly ILog m_log = | 46 | private static readonly ILog m_log = |
47 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 47 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
48 | private static string LogHeader = "[MODULE COMMS]"; | ||
48 | 49 | ||
49 | private Dictionary<string,object> m_constants = new Dictionary<string,object>(); | 50 | private Dictionary<string,object> m_constants = new Dictionary<string,object>(); |
50 | 51 | ||
@@ -148,7 +149,7 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | |||
148 | MethodInfo mi = GetMethodInfoFromType(target.GetType(), meth, true); | 149 | MethodInfo mi = GetMethodInfoFromType(target.GetType(), meth, true); |
149 | if (mi == null) | 150 | if (mi == null) |
150 | { | 151 | { |
151 | m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}", meth); | 152 | m_log.WarnFormat("{0} Failed to register method {1}", LogHeader, meth); |
152 | return; | 153 | return; |
153 | } | 154 | } |
154 | 155 | ||
@@ -163,9 +164,9 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | |||
163 | 164 | ||
164 | public void RegisterScriptInvocation(object target, MethodInfo mi) | 165 | public void RegisterScriptInvocation(object target, MethodInfo mi) |
165 | { | 166 | { |
166 | m_log.DebugFormat("[MODULE COMMANDS] Register method {0} from type {1}", mi.Name, (target is Type) ? ((Type)target).Name : target.GetType().Name); | 167 | // m_log.DebugFormat("[MODULE COMMANDS] Register method {0} from type {1}", mi.Name, (target is Type) ? ((Type)target).Name : target.GetType().Name); |
167 | 168 | ||
168 | Type delegateType; | 169 | Type delegateType = typeof(void); |
169 | List<Type> typeArgs = mi.GetParameters() | 170 | List<Type> typeArgs = mi.GetParameters() |
170 | .Select(p => p.ParameterType) | 171 | .Select(p => p.ParameterType) |
171 | .ToList(); | 172 | .ToList(); |
@@ -176,8 +177,16 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | |||
176 | } | 177 | } |
177 | else | 178 | else |
178 | { | 179 | { |
179 | typeArgs.Add(mi.ReturnType); | 180 | try |
180 | delegateType = Expression.GetFuncType(typeArgs.ToArray()); | 181 | { |
182 | typeArgs.Add(mi.ReturnType); | ||
183 | delegateType = Expression.GetFuncType(typeArgs.ToArray()); | ||
184 | } | ||
185 | catch (Exception e) | ||
186 | { | ||
187 | m_log.ErrorFormat("{0} Failed to create function signature. Most likely more than 5 parameters. Method={1}. Error={2}", | ||
188 | LogHeader, mi.Name, e); | ||
189 | } | ||
181 | } | 190 | } |
182 | 191 | ||
183 | Delegate fcall; | 192 | Delegate fcall; |
@@ -323,7 +332,7 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | |||
323 | /// </summary> | 332 | /// </summary> |
324 | public void RegisterConstant(string cname, object value) | 333 | public void RegisterConstant(string cname, object value) |
325 | { | 334 | { |
326 | m_log.DebugFormat("[MODULE COMMANDS] register constant <{0}> with value {1}",cname,value.ToString()); | 335 | // m_log.DebugFormat("[MODULE COMMANDS] register constant <{0}> with value {1}",cname,value.ToString()); |
327 | lock (m_constants) | 336 | lock (m_constants) |
328 | { | 337 | { |
329 | m_constants.Add(cname,value); | 338 | m_constants.Add(cname,value); |
diff --git a/OpenSim/Region/CoreModules/Scripting/VectorRender/Tests/VectorRenderModuleTests.cs b/OpenSim/Region/CoreModules/Scripting/VectorRender/Tests/VectorRenderModuleTests.cs index 41baccc..ed255bf 100644 --- a/OpenSim/Region/CoreModules/Scripting/VectorRender/Tests/VectorRenderModuleTests.cs +++ b/OpenSim/Region/CoreModules/Scripting/VectorRender/Tests/VectorRenderModuleTests.cs | |||
@@ -40,7 +40,6 @@ using OpenSim.Region.CoreModules.Scripting.VectorRender; | |||
40 | using OpenSim.Region.Framework.Scenes; | 40 | using OpenSim.Region.Framework.Scenes; |
41 | using OpenSim.Region.Framework.Scenes.Serialization; | 41 | using OpenSim.Region.Framework.Scenes.Serialization; |
42 | using OpenSim.Tests.Common; | 42 | using OpenSim.Tests.Common; |
43 | using OpenSim.Tests.Common.Mock; | ||
44 | 43 | ||
45 | namespace OpenSim.Region.CoreModules.Scripting.VectorRender.Tests | 44 | namespace OpenSim.Region.CoreModules.Scripting.VectorRender.Tests |
46 | { | 45 | { |
@@ -152,7 +151,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender.Tests | |||
152 | TestHelpers.InMethod(); | 151 | TestHelpers.InMethod(); |
153 | 152 | ||
154 | string dtText | 153 | string dtText |
155 | = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World; Image http://localhost/shouldnotexist.png"; | 154 | = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World; Image http://0.0.0.0/shouldnotexist.png"; |
156 | 155 | ||
157 | SetupScene(false); | 156 | SetupScene(false); |
158 | SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene); | 157 | SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene); |
@@ -307,7 +306,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender.Tests | |||
307 | TestHelpers.InMethod(); | 306 | TestHelpers.InMethod(); |
308 | 307 | ||
309 | string dtText | 308 | string dtText |
310 | = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World; Image http://localhost/shouldnotexist.png"; | 309 | = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World; Image http://0.0.0.0/shouldnotexist.png"; |
311 | 310 | ||
312 | SetupScene(true); | 311 | SetupScene(true); |
313 | SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene); | 312 | SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene); |
diff --git a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs index 689e8a7..4cecd85 100644 --- a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs | |||
@@ -516,6 +516,9 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender | |||
516 | foreach (string line in GetLines(data, dataDelim)) | 516 | foreach (string line in GetLines(data, dataDelim)) |
517 | { | 517 | { |
518 | string nextLine = line.Trim(); | 518 | string nextLine = line.Trim(); |
519 | |||
520 | // m_log.DebugFormat("[VECTOR RENDER MODULE]: Processing line '{0}'", nextLine); | ||
521 | |||
519 | //replace with switch, or even better, do some proper parsing | 522 | //replace with switch, or even better, do some proper parsing |
520 | if (nextLine.StartsWith("MoveTo")) | 523 | if (nextLine.StartsWith("MoveTo")) |
521 | { | 524 | { |
@@ -829,6 +832,8 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender | |||
829 | float y = Convert.ToSingle(yVal, CultureInfo.InvariantCulture); | 832 | float y = Convert.ToSingle(yVal, CultureInfo.InvariantCulture); |
830 | PointF point = new PointF(x, y); | 833 | PointF point = new PointF(x, y); |
831 | points[i / 2] = point; | 834 | points[i / 2] = point; |
835 | |||
836 | // m_log.DebugFormat("[VECTOR RENDER MODULE]: Got point {0}", points[i / 2]); | ||
832 | } | 837 | } |
833 | } | 838 | } |
834 | } | 839 | } |
@@ -838,13 +843,17 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender | |||
838 | try | 843 | try |
839 | { | 844 | { |
840 | WebRequest request = HttpWebRequest.Create(url); | 845 | WebRequest request = HttpWebRequest.Create(url); |
841 | //Ckrinke: Comment out for now as 'str' is unused. Bring it back into play later when it is used. | 846 | |
842 | //Ckrinke Stream str = null; | 847 | using (HttpWebResponse response = (HttpWebResponse)(request).GetResponse()) |
843 | HttpWebResponse response = (HttpWebResponse)(request).GetResponse(); | ||
844 | if (response.StatusCode == HttpStatusCode.OK) | ||
845 | { | 848 | { |
846 | Bitmap image = new Bitmap(response.GetResponseStream()); | 849 | if (response.StatusCode == HttpStatusCode.OK) |
847 | return image; | 850 | { |
851 | using (Stream s = response.GetResponseStream()) | ||
852 | { | ||
853 | Bitmap image = new Bitmap(s); | ||
854 | return image; | ||
855 | } | ||
856 | } | ||
848 | } | 857 | } |
849 | } | 858 | } |
850 | catch { } | 859 | catch { } |
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs index 2c2c99c..3484387 100644 --- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs | |||
@@ -379,15 +379,9 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm | |||
379 | if (sp.IsChildAgent) | 379 | if (sp.IsChildAgent) |
380 | return; | 380 | return; |
381 | 381 | ||
382 | // Send message to the avatar. | ||
383 | // Channel zero only goes to the avatar | 382 | // Channel zero only goes to the avatar |
384 | // non zero channel messages only go to the attachments | 383 | // non zero channel messages only go to the attachments of the avatar. |
385 | if (channel == 0) | 384 | if (channel != 0) |
386 | { | ||
387 | m_scene.SimChatToAgent(target, Utils.StringToBytes(msg), | ||
388 | pos, name, id, false); | ||
389 | } | ||
390 | else | ||
391 | { | 385 | { |
392 | List<SceneObjectGroup> attachments = sp.GetAttachments(); | 386 | List<SceneObjectGroup> attachments = sp.GetAttachments(); |
393 | if (attachments.Count == 0) | 387 | if (attachments.Count == 0) |
diff --git a/OpenSim/Region/CoreModules/Scripting/XMLRPC/XMLRPCModule.cs b/OpenSim/Region/CoreModules/Scripting/XMLRPC/XMLRPCModule.cs index 385f5ad..87f4277 100644 --- a/OpenSim/Region/CoreModules/Scripting/XMLRPC/XMLRPCModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/XMLRPC/XMLRPCModule.cs | |||
@@ -36,6 +36,7 @@ using Nini.Config; | |||
36 | using Nwc.XmlRpc; | 36 | using Nwc.XmlRpc; |
37 | using OpenMetaverse; | 37 | using OpenMetaverse; |
38 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
39 | using OpenSim.Framework.Monitoring; | ||
39 | using OpenSim.Framework.Servers; | 40 | using OpenSim.Framework.Servers; |
40 | using OpenSim.Framework.Servers.HttpServer; | 41 | using OpenSim.Framework.Servers.HttpServer; |
41 | using OpenSim.Region.Framework.Interfaces; | 42 | using OpenSim.Region.Framework.Interfaces; |
@@ -111,13 +112,15 @@ namespace OpenSim.Region.CoreModules.Scripting.XMLRPC | |||
111 | m_rpcPending = new Dictionary<UUID, RPCRequestInfo>(); | 112 | m_rpcPending = new Dictionary<UUID, RPCRequestInfo>(); |
112 | m_rpcPendingResponses = new Dictionary<UUID, RPCRequestInfo>(); | 113 | m_rpcPendingResponses = new Dictionary<UUID, RPCRequestInfo>(); |
113 | m_pendingSRDResponses = new Dictionary<UUID, SendRemoteDataRequest>(); | 114 | m_pendingSRDResponses = new Dictionary<UUID, SendRemoteDataRequest>(); |
114 | 115 | if (config.Configs["XMLRPC"] != null) | |
115 | try | ||
116 | { | ||
117 | m_remoteDataPort = config.Configs["XMLRPC"].GetInt("XmlRpcPort", m_remoteDataPort); | ||
118 | } | ||
119 | catch (Exception) | ||
120 | { | 116 | { |
117 | try | ||
118 | { | ||
119 | m_remoteDataPort = config.Configs["XMLRPC"].GetInt("XmlRpcPort", m_remoteDataPort); | ||
120 | } | ||
121 | catch (Exception) | ||
122 | { | ||
123 | } | ||
121 | } | 124 | } |
122 | } | 125 | } |
123 | 126 | ||
@@ -654,12 +657,8 @@ namespace OpenSim.Region.CoreModules.Scripting.XMLRPC | |||
654 | 657 | ||
655 | public void Process() | 658 | public void Process() |
656 | { | 659 | { |
657 | httpThread = new Thread(SendRequest); | ||
658 | httpThread.Name = "HttpRequestThread"; | ||
659 | httpThread.Priority = ThreadPriority.BelowNormal; | ||
660 | httpThread.IsBackground = true; | ||
661 | _finished = false; | 660 | _finished = false; |
662 | httpThread.Start(); | 661 | httpThread = WorkManager.StartThread(SendRequest, "HttpRequestThread", ThreadPriority.BelowNormal, true, false); |
663 | } | 662 | } |
664 | 663 | ||
665 | /* | 664 | /* |
@@ -675,7 +674,7 @@ namespace OpenSim.Region.CoreModules.Scripting.XMLRPC | |||
675 | // if not, use as method name | 674 | // if not, use as method name |
676 | UUID parseUID; | 675 | UUID parseUID; |
677 | string mName = "llRemoteData"; | 676 | string mName = "llRemoteData"; |
678 | if ((Channel != null) && (Channel != "")) | 677 | if (!string.IsNullOrEmpty(Channel)) |
679 | if (!UUID.TryParse(Channel, out parseUID)) | 678 | if (!UUID.TryParse(Channel, out parseUID)) |
680 | mName = Channel; | 679 | mName = Channel; |
681 | else | 680 | else |
@@ -731,13 +730,19 @@ namespace OpenSim.Region.CoreModules.Scripting.XMLRPC | |||
731 | } | 730 | } |
732 | 731 | ||
733 | _finished = true; | 732 | _finished = true; |
733 | |||
734 | Watchdog.RemoveThread(); | ||
734 | } | 735 | } |
735 | 736 | ||
736 | public void Stop() | 737 | public void Stop() |
737 | { | 738 | { |
738 | try | 739 | try |
739 | { | 740 | { |
740 | httpThread.Abort(); | 741 | if (httpThread != null) |
742 | { | ||
743 | Watchdog.AbortThread(httpThread.ManagedThreadId); | ||
744 | httpThread = null; | ||
745 | } | ||
741 | } | 746 | } |
742 | catch (Exception) | 747 | catch (Exception) |
743 | { | 748 | { |