ok.. another try on the HG uri

melanie
UbitUmarov 2016-12-16 03:38:20 +00:00
parent 853e98d340
commit e2d46c060c
4 changed files with 160 additions and 127 deletions

View File

@ -414,6 +414,120 @@ namespace OpenSim.Framework
return regionCoord << 8;
}
public static bool buildHGRegionURI(string inputName, out string serverURI, out string regionName)
{
serverURI = string.Empty;
regionName = string.Empty;
inputName = inputName.Trim();
if (!inputName.StartsWith("http") && !inputName.StartsWith("https"))
{
// Formats: grid.example.com:8002:region name
// grid.example.com:region name
// grid.example.com:8002
// grid.example.com
string host;
uint port = 80;
string[] parts = inputName.Split(new char[] { ':' });
int indx;
if(parts.Length == 0)
return false;
if (parts.Length == 1)
{
indx = inputName.IndexOf('/');
if (indx < 0)
serverURI = "http://"+ inputName + "/";
else
{
serverURI = "http://"+ inputName.Substring(0,indx + 1);
if(indx + 2 < inputName.Length)
regionName = inputName.Substring(indx + 1);
}
}
else
{
host = parts[0];
if (parts.Length >= 2)
{
indx = parts[1].IndexOf('/');
if(indx < 0)
{
// If it's a number then assume it's a port. Otherwise, it's a region name.
if (!UInt32.TryParse(parts[1], out port))
{
port = 80;
regionName = parts[1];
}
}
else
{
string portstr = parts[1].Substring(0, indx);
if(indx + 2 < parts[1].Length)
regionName = parts[1].Substring(indx + 1);
if (!UInt32.TryParse(portstr, out port))
port = 80;
}
}
// always take the last one
if (parts.Length >= 3)
{
regionName = parts[2];
}
serverURI = "http://"+ host +":"+ port.ToString() + "/";
}
}
else
{
// Formats: http://grid.example.com region name
// http://grid.example.com "region name"
// http://grid.example.com
string[] parts = inputName.Split(new char[] { ' ' });
if (parts.Length == 0)
return false;
serverURI = parts[0];
int indx = serverURI.LastIndexOf('/');
if(indx > 10)
{
if(indx + 2 < inputName.Length)
regionName = inputName.Substring(indx + 1);
serverURI = inputName.Substring(0, indx + 1);
}
else if (parts.Length >= 2)
{
regionName = inputName.Substring(serverURI.Length);
}
}
// use better code for sanity check
Uri uri;
try
{
uri = new Uri(serverURI);
}
catch
{
return false;
}
if(!string.IsNullOrEmpty(regionName))
regionName = regionName.Trim(new char[] { '"', ' ' });
serverURI = uri.AbsoluteUri;
if(uri.Port == 80)
serverURI = serverURI.Trim(new char[] { '/', ' ' }) +":80/";
else if(uri.Port == 443)
serverURI = serverURI.Trim(new char[] { '/', ' ' }) +":443/";
return true;
}
public static T Clamp<T>(T x, T min, T max)
where T : IComparable<T>
{

View File

@ -227,11 +227,20 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
return rinfo;
}
public GridRegion GetRegionByName(UUID scopeID, string regionName)
public GridRegion GetRegionByName(UUID scopeID, string name)
{
GridRegion rinfo = m_LocalGridService.GetRegionByName(scopeID, regionName);
GridRegion rinfo = m_LocalGridService.GetRegionByName(scopeID, name);
if (rinfo != null)
return rinfo;
// HG urls should not get here, strip them
string regionName = name;
if(name.Contains("."))
{
string regionURI = "";
if(!Util.buildHGRegionURI(name, out regionURI, out regionName))
return rinfo;
}
rinfo = m_RemoteGridService.GetRegionByName(scopeID, regionName);
m_RegionInfoCache.Cache(scopeID, rinfo);
@ -242,7 +251,19 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
{
List<GridRegion> rinfo = m_LocalGridService.GetRegionsByName(scopeID, name, maxNumber);
//m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetRegionsByName {0} found {1} regions", name, rinfo.Count);
List<GridRegion> grinfo = m_RemoteGridService.GetRegionsByName(scopeID, name, maxNumber);
// HG urls should not get here, strip them
// side effect is that local regions with same name as HG may also be found
// this mb good or bad
string regionName = name;
if(name.Contains("."))
{
string regionURI = "";
if(!Util.buildHGRegionURI(name, out regionURI, out regionName))
return rinfo;
}
List<GridRegion> grinfo = m_RemoteGridService.GetRegionsByName(scopeID, regionName, maxNumber);
if (grinfo != null)
{

View File

@ -505,11 +505,16 @@ namespace OpenSim.Services.GridService
{
string regionURI = "";
string regionName = "";
if(!m_HypergridLinker.buildHGRegionURI(name, out regionURI, out regionName))
if(!Util.buildHGRegionURI(name, out regionURI, out regionName))
return null;
bool localGrid = string.IsNullOrWhiteSpace(regionURI);
string mapname = regionURI + regionName;
string mapname;
bool localGrid = m_HypergridLinker.IsLocalGrid(regionURI);
if(localGrid)
mapname = regionName;
else
mapname = regionURI + regionName;
bool haveMatch = false;
if (rdatas != null && (rdatas.Count > 0))
@ -555,7 +560,7 @@ namespace OpenSim.Services.GridService
if(haveMatch)
return rinfos;
}
if(!localGrid)
if(!localGrid && !string.IsNullOrWhiteSpace(regionURI))
{
string HGname = regionURI +" "+ regionName; // include space for compatibility
GridRegion r = m_HypergridLinker.LinkRegion(scopeID, HGname);
@ -592,15 +597,21 @@ namespace OpenSim.Services.GridService
{
string regionURI = "";
string regionName = "";
if(!m_HypergridLinker.buildHGRegionURI(name, out regionURI, out regionName))
if(!Util.buildHGRegionURI(name, out regionURI, out regionName))
return null;
string mapname = regionURI + regionName;
string mapname;
bool localGrid = m_HypergridLinker.IsLocalGrid(regionURI);
if(localGrid)
mapname = regionName;
else
mapname = regionURI + regionName;
List<RegionData> rdatas = m_Database.Get(Util.EscapeForLike(mapname), scopeID);
if ((rdatas != null) && (rdatas.Count > 0))
return RegionData2RegionInfo(rdatas[0]); // get the first
if(!string.IsNullOrWhiteSpace(regionURI))
if(!localGrid && !string.IsNullOrWhiteSpace(regionURI))
{
string HGname = regionURI +" "+ regionName;
return m_HypergridLinker.LinkRegion(scopeID, HGname);

View File

@ -196,123 +196,10 @@ namespace OpenSim.Services.GridService
{
return TryLinkRegionToCoords(scopeID, mapName, xloc, yloc, UUID.Zero, out reason);
}
public bool buildHGRegionURI(string inputName, out string serverURI, out string regionName)
public bool IsLocalGrid(string serverURI)
{
serverURI = string.Empty;
regionName = string.Empty;
inputName = inputName.Trim();
if (!inputName.StartsWith("http") && !inputName.StartsWith("https"))
{
// Formats: grid.example.com:8002:region name
// grid.example.com:region name
// grid.example.com:8002
// grid.example.com
string host;
uint port = 80;
string[] parts = inputName.Split(new char[] { ':' });
int indx;
if(parts.Length == 0)
return false;
if (parts.Length == 1)
{
indx = inputName.IndexOf('/');
if (indx < 0)
serverURI = "http://"+ inputName + "/";
else
{
serverURI = "http://"+ inputName.Substring(0,indx + 1);
if(indx + 2 < inputName.Length)
regionName = inputName.Substring(indx + 1);
}
}
else
{
host = parts[0];
if (parts.Length >= 2)
{
indx = parts[1].IndexOf('/');
if(indx < 0)
{
// If it's a number then assume it's a port. Otherwise, it's a region name.
if (!UInt32.TryParse(parts[1], out port))
{
port = 80;
regionName = parts[1];
}
}
else
{
string portstr = parts[1].Substring(0, indx);
if(indx + 2 < parts[1].Length)
regionName = parts[1].Substring(indx + 1);
if (!UInt32.TryParse(portstr, out port))
port = 80;
}
}
// always take the last one
if (parts.Length >= 3)
{
regionName = parts[2];
}
serverURI = "http://"+ host +":"+ port.ToString() + "/";
}
}
else
{
// Formats: http://grid.example.com region name
// http://grid.example.com "region name"
// http://grid.example.com
string[] parts = inputName.Split(new char[] { ' ' });
if (parts.Length == 0)
return false;
serverURI = parts[0];
int indx = serverURI.LastIndexOf('/');
if(indx > 10)
{
if(indx + 2 < inputName.Length)
regionName = inputName.Substring(indx + 1);
serverURI = inputName.Substring(0, indx + 1);
}
else if (parts.Length >= 2)
{
regionName = inputName.Substring(serverURI.Length);
}
}
// use better code for sanity check
Uri uri;
try
{
uri = new Uri(serverURI);
}
catch
{
return false;
}
if(!string.IsNullOrEmpty(regionName))
regionName = regionName.Trim(new char[] { '"', ' ' });
serverURI = uri.AbsoluteUri;
if(uri.Port == 80)
serverURI = serverURI.Trim(new char[] { '/', ' ' }) +":80/";
else if(uri.Port == 443)
serverURI = serverURI.Trim(new char[] { '/', ' ' }) +":443/";
if(serverURI == m_ThisGatekeeper)
serverURI = ""; // local grid, look for region name only
return true;
return serverURI == m_ThisGatekeeper;
}
public GridRegion TryLinkRegionToCoords(UUID scopeID, string mapName, int xloc, int yloc, UUID ownerID, out string reason)
@ -323,7 +210,7 @@ namespace OpenSim.Services.GridService
string serverURI = string.Empty;
string regionName = string.Empty;
if(!buildHGRegionURI(mapName, out serverURI, out regionName))
if(!Util.buildHGRegionURI(mapName, out serverURI, out regionName))
{
reason = "Wrong URI format for link-region";
return null;