aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorUbitUmarov2016-12-16 03:38:20 +0000
committerUbitUmarov2016-12-16 03:38:20 +0000
commite2d46c060c4b9557cf596d6d828ddd296fa0af70 (patch)
treec2c44730340c9785b9b373c937a2a54b2e6ec34e /OpenSim/Framework
parentreserve constant OBJECT_ATTACHED_SLOTS_AVAILABLE from mantis 8096. But do not... (diff)
downloadopensim-SC_OLD-e2d46c060c4b9557cf596d6d828ddd296fa0af70.zip
opensim-SC_OLD-e2d46c060c4b9557cf596d6d828ddd296fa0af70.tar.gz
opensim-SC_OLD-e2d46c060c4b9557cf596d6d828ddd296fa0af70.tar.bz2
opensim-SC_OLD-e2d46c060c4b9557cf596d6d828ddd296fa0af70.tar.xz
ok.. another try on the HG uri
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Util.cs114
1 files changed, 114 insertions, 0 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index a6fd99f..5d8a5e0 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -414,6 +414,120 @@ namespace OpenSim.Framework
414 return regionCoord << 8; 414 return regionCoord << 8;
415 } 415 }
416 416
417 public static bool buildHGRegionURI(string inputName, out string serverURI, out string regionName)
418 {
419 serverURI = string.Empty;
420 regionName = string.Empty;
421
422 inputName = inputName.Trim();
423
424 if (!inputName.StartsWith("http") && !inputName.StartsWith("https"))
425 {
426 // Formats: grid.example.com:8002:region name
427 // grid.example.com:region name
428 // grid.example.com:8002
429 // grid.example.com
430
431 string host;
432 uint port = 80;
433
434 string[] parts = inputName.Split(new char[] { ':' });
435 int indx;
436 if(parts.Length == 0)
437 return false;
438 if (parts.Length == 1)
439 {
440 indx = inputName.IndexOf('/');
441 if (indx < 0)
442 serverURI = "http://"+ inputName + "/";
443 else
444 {
445 serverURI = "http://"+ inputName.Substring(0,indx + 1);
446 if(indx + 2 < inputName.Length)
447 regionName = inputName.Substring(indx + 1);
448 }
449 }
450 else
451 {
452 host = parts[0];
453
454 if (parts.Length >= 2)
455 {
456 indx = parts[1].IndexOf('/');
457 if(indx < 0)
458 {
459 // If it's a number then assume it's a port. Otherwise, it's a region name.
460 if (!UInt32.TryParse(parts[1], out port))
461 {
462 port = 80;
463 regionName = parts[1];
464 }
465 }
466 else
467 {
468 string portstr = parts[1].Substring(0, indx);
469 if(indx + 2 < parts[1].Length)
470 regionName = parts[1].Substring(indx + 1);
471 if (!UInt32.TryParse(portstr, out port))
472 port = 80;
473 }
474 }
475 // always take the last one
476 if (parts.Length >= 3)
477 {
478 regionName = parts[2];
479 }
480
481 serverURI = "http://"+ host +":"+ port.ToString() + "/";
482 }
483 }
484 else
485 {
486 // Formats: http://grid.example.com region name
487 // http://grid.example.com "region name"
488 // http://grid.example.com
489
490 string[] parts = inputName.Split(new char[] { ' ' });
491
492 if (parts.Length == 0)
493 return false;
494
495 serverURI = parts[0];
496
497 int indx = serverURI.LastIndexOf('/');
498 if(indx > 10)
499 {
500 if(indx + 2 < inputName.Length)
501 regionName = inputName.Substring(indx + 1);
502 serverURI = inputName.Substring(0, indx + 1);
503 }
504 else if (parts.Length >= 2)
505 {
506 regionName = inputName.Substring(serverURI.Length);
507 }
508 }
509
510 // use better code for sanity check
511 Uri uri;
512 try
513 {
514 uri = new Uri(serverURI);
515 }
516 catch
517 {
518 return false;
519 }
520
521 if(!string.IsNullOrEmpty(regionName))
522 regionName = regionName.Trim(new char[] { '"', ' ' });
523 serverURI = uri.AbsoluteUri;
524 if(uri.Port == 80)
525 serverURI = serverURI.Trim(new char[] { '/', ' ' }) +":80/";
526 else if(uri.Port == 443)
527 serverURI = serverURI.Trim(new char[] { '/', ' ' }) +":443/";
528 return true;
529 }
530
417 public static T Clamp<T>(T x, T min, T max) 531 public static T Clamp<T>(T x, T min, T max)
418 where T : IComparable<T> 532 where T : IComparable<T>
419 { 533 {