change usermanagement user homeurl verification and local grid detection, using new GridInfo and OSHHTPHost

This commit is contained in:
UbitUmarov
2020-11-21 00:36:47 +00:00
parent 2f66a82cbe
commit 2fbd14722d
4 changed files with 146 additions and 104 deletions

View File

@@ -120,7 +120,8 @@ namespace OpenSim.Framework
List<Tkey1> expired = new List<Tkey1>(m_dictionary.Count);
foreach(KeyValuePair<Tkey1,int> kvp in m_dictionary)
{
if(kvp.Value < now)
int expire = kvp.Value;
if (expire > 0 && expire < now)
expired.Add(kvp.Key);
}
@@ -186,8 +187,14 @@ namespace OpenSim.Framework
public void Add(Tkey1 key, int expireMS)
{
bool gotLock = false;
expireMS = (expireMS > m_expire) ? expireMS : m_expire;
int now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS;
int now;
if (expireMS > 0)
{
expireMS = (expireMS > m_expire) ? expireMS : m_expire;
now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS;
}
else
now = int.MinValue;
try
{
@@ -303,8 +310,14 @@ namespace OpenSim.Framework
m_rwLock.EnterWriteLock();
gotWriteLock = true;
}
expireMS = (expireMS > m_expire) ? expireMS : m_expire;
int now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS;
int now;
if (expireMS > 0)
{
expireMS = (expireMS > m_expire) ? expireMS : m_expire;
now = (int)(Util.GetTimeStampMS() - m_startTS) + expireMS;
}
else
now = int.MinValue;
m_dictionary[key] = now;
return true;

View File

@@ -317,6 +317,11 @@ namespace OpenSim.Framework
get { return (Flags == OSHTTPURIFlags.None) ? "" : URI + "/"; }
}
public string HostAndPort
{
get { return (Flags == OSHTTPURIFlags.None) ? "" : Host + ":" + Port.ToString(); }
}
public int CompareTo(OSHHTPHost other)
{
if (Port == other.Port && ((Flags & other.Flags) & OSHTTPURIFlags.ValidHost) != 0)
@@ -337,7 +342,7 @@ namespace OpenSim.Framework
public override int GetHashCode()
{
return URI.GetHashCode();
return Host.GetHashCode() + Port;
}
}
@@ -606,6 +611,17 @@ namespace OpenSim.Framework
return 0;
}
public int IsLocalGrid(OSHHTPHost othergatekeeper)
{
if (!othergatekeeper.IsValidHost)
return -1;
if (othergatekeeper.Equals(m_gateKeeperURL))
return 1;
if (m_gateKeeperAlias != null && m_gateKeeperAlias.Contains(othergatekeeper))
return 1;
return 0;
}
public int IsLocalHome(string otherhome)
{
OSHHTPHost tmp = new OSHHTPHost(otherhome, false);

View File

@@ -475,6 +475,8 @@ namespace OpenSim.Framework
return false;
}
public static bool buildHGRegionURI(string inputName, out string serverURI, out string regionName)
{
serverURI = string.Empty;
@@ -490,7 +492,7 @@ namespace OpenSim.Framework
// grid.example.com
string host;
uint port = 80;
int port = 80;
string[] parts = inputName.Split(new char[] { ':' });
int indx;
@@ -518,7 +520,7 @@ namespace OpenSim.Framework
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))
if (!int.TryParse(parts[1], out port))
{
port = 80;
regionName = parts[1];
@@ -529,7 +531,7 @@ namespace OpenSim.Framework
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))
if (!int.TryParse(portstr, out port))
port = 80;
}
}
@@ -3596,28 +3598,53 @@ namespace OpenSim.Framework
/// <param name="secret">the secret part</param>
public static bool ParseUniversalUserIdentifier(string value, out UUID uuid, out string url, out string firstname, out string lastname, out string secret)
{
uuid = UUID.Zero; url = string.Empty; firstname = "Unknown"; lastname = "UserUPUUI"; secret = string.Empty;
uuid = UUID.Zero;
url = string.Empty;
firstname = "Unknown";
lastname = "UserUPUUI";
secret = string.Empty;
string[] parts = value.Split(';');
if (parts.Length >= 1)
if (!UUID.TryParse(parts[0], out uuid))
return false;
if (parts.Length < 1)
return false;
if (!UUID.TryParse(parts[0], out uuid))
return false;
if (parts.Length >= 2)
url = parts[1];
if (parts.Length >= 3)
{
string[] name = parts[2].Split();
if (name.Length == 2)
url = parts[1].ToLower();
if (parts.Length >= 3)
{
firstname = name[0];
lastname = name[1];
string[] name = parts[2].Split();
if (name.Length == 2)
{
firstname = name[0];
lastname = name[1];
}
if (parts.Length >= 4)
secret = parts[3];
}
}
if (parts.Length >= 4)
secret = parts[3];
return true;
}
public static bool ParseUniversalUserIdentifier(string value, out UUID uuid, out string url)
{
uuid = UUID.Zero;
url = string.Empty;
string[] parts = value.Split(';');
if (parts.Length < 1)
return false;
if (!UUID.TryParse(parts[0], out uuid))
return false;
if (parts.Length >= 2)
url = parts[1].ToLower();
return true;
}