diff --git a/OpenSim/Framework/GridInfo.cs b/OpenSim/Framework/GridInfo.cs index 58a1b66e2f..b635691505 100644 --- a/OpenSim/Framework/GridInfo.cs +++ b/OpenSim/Framework/GridInfo.cs @@ -34,25 +34,149 @@ using Nini.Config; namespace OpenSim.Framework { - public struct OSHostURL:IComparable, IEquatable + // full http or https schema, server host, port and possible server path any query is ignored. + public struct OSHTTPURI:IComparable, IEquatable { public string Host; public int Port; - public string URL; - public UriHostNameType URLType; + public UriHostNameType HostType; + public IPAddress IP; + private string m_URI; + public string Path; + + public OSHTTPURI(string uri, bool withDNSResolve = false) + { + Host = string.Empty; + Port = -1; + m_URI = string.Empty; + Path = string.Empty; + + HostType = UriHostNameType.Unknown; + IP = null; + + if (string.IsNullOrEmpty(uri)) + return; + + try + { + Uri m_checkuri = new Uri(uri); + + if(m_checkuri.Scheme != Uri.UriSchemeHttp && m_checkuri.Scheme != Uri.UriSchemeHttps) + return; + + Host = m_checkuri.DnsSafeHost.ToLowerInvariant(); + HostType = m_checkuri.HostNameType; + Port = m_checkuri.Port; + Path = m_checkuri.AbsolutePath; + if (Path[Path.Length - 1] == '/') + Path = Path.Substring(0, Path.Length - 1); + + m_URI = m_checkuri.Scheme + "://" + Host + ":" + Port + Path; + + if (withDNSResolve) + { + IPAddress ip = Util.GetHostFromDNS(Host); + if (ip != null) + IP = ip; + } + } + catch + { + HostType = UriHostNameType.Unknown; + IP = null; + } + } + + public bool ResolveDNS() + { + IPAddress ip = Util.GetHostFromDNS(Host); + if (ip == null) + return false; + return true; + } + + public bool IsValidHost + { + get { return (HostType != UriHostNameType.Unknown);} + } + + public bool ValidAndResolved(out string error) + { + if (HostType == UriHostNameType.Unknown) + { + error = "failed to parse uri"; + return false; + } + if (IP == null) + { + error = "failed DNS resolve of uri host"; + return false; + } + error = string.Empty; + return true; + } + + public bool IsResolvedHost + { + get {return (HostType != UriHostNameType.Unknown) && (IP != null);} + } + + public string URI + { + get { return (HostType == UriHostNameType.Unknown) ? "" : m_URI;} + } + + public string URIwEndSlash + { + get { return (HostType == UriHostNameType.Unknown) ? "" : m_URI + "/";} + } + + public int CompareTo(OSHTTPURI other) + { + if (Port == other.Port && other.HostType != UriHostNameType.Unknown) + { + if (Path.Equals(other.Path) && HostType == other.HostType) + return Host.CompareTo(other.Host); + } + return -1; + } + + public bool Equals(OSHTTPURI other) + { + if (Port == other.Port && other.HostType != UriHostNameType.Unknown) + { + if (Path.Equals(other.Path) && HostType == other.HostType) + return Host.Equals(other.Host); + } + return false; + } + + public override int GetHashCode() + { + return URI.GetHashCode(); + } + } + + //host and port. Can not have server internal path or query. http scheme is assumed if not present + public struct OSHHTPHost : IComparable, IEquatable + { + public string Host; + public int Port; + private string m_URI; + public UriHostNameType HostType; public bool SecureHTTP; public IPAddress IP; - public OSHostURL(string url, bool withDNSResolve = false) + public OSHHTPHost(string url, bool withDNSResolve = false) { Host = string.Empty; Port = 80; - URL = string.Empty; - URLType = UriHostNameType.Unknown; + m_URI = string.Empty; + HostType = UriHostNameType.Unknown; IP = null; SecureHTTP = false; - if (String.IsNullOrEmpty(url)) + if (string.IsNullOrEmpty(url)) return; url = url.ToLowerInvariant(); @@ -63,11 +187,11 @@ namespace OpenSim.Framework if (url[urllen - 1] == '/') --urllen; int start; - if(url.StartsWith("http")) + if (url.StartsWith("http")) { - if(url[4] == 's') + if (url[4] == 's') { - start = 8; + start = 8; SecureHTTP = true; } else @@ -90,10 +214,10 @@ namespace OpenSim.Framework int tmp; if (!int.TryParse(sport, out tmp) || tmp < 0 || tmp > 65535) return; - URLType = type; + HostType = type; Host = host; Port = tmp; - URL = (SecureHTTP ? "https://" : "http://") + Host + ":" + Port.ToString() + "/"; + m_URI = (SecureHTTP ? "https://" : "http://") + Host + ":" + Port.ToString(); } else { @@ -101,12 +225,12 @@ namespace OpenSim.Framework type = Uri.CheckHostName(host); if (type == UriHostNameType.Unknown || type == UriHostNameType.Basic) return; - URLType = type; + HostType = type; Host = host; if (SecureHTTP) - URL = "https://" + Host + ":443/"; + m_URI = "https://" + Host + ":443"; else - URL = "http://" + Host + ":80/"; + m_URI = "http://" + Host + ":80"; } if (withDNSResolve) @@ -118,7 +242,7 @@ namespace OpenSim.Framework } catch { - URLType = UriHostNameType.Unknown; + HostType = UriHostNameType.Unknown; IP = null; } } @@ -131,31 +255,57 @@ namespace OpenSim.Framework return true; } - public bool IsValidHost() + public bool IsValidHost { - return URLType != UriHostNameType.Unknown; + get { return HostType != UriHostNameType.Unknown; } } - public bool IsResolvedHost() + public bool IsResolvedHost { - return (URLType != UriHostNameType.Unknown) && (IP != null); + get { return (HostType != UriHostNameType.Unknown) && (IP != null); } } - public int CompareTo(OSHostURL other) + public bool ValidAndResolved(out string error) { - if (Port == other.Port && other.URLType != UriHostNameType.Unknown) + if (HostType == UriHostNameType.Unknown) { - if (URLType == other.URLType) + error = "failed to parse uri"; + return false; + } + if (IP == null) + { + error = "failed DNS resolve of uri host"; + return false; + } + error = string.Empty; + return true; + } + + public string URI + { + get { return (HostType == UriHostNameType.Unknown) ? "" : m_URI; } + } + + public string URIwEndSlash + { + get { return (HostType == UriHostNameType.Unknown) ? "" : m_URI + "/"; } + } + + public int CompareTo(OSHHTPHost other) + { + if (Port == other.Port && other.HostType != UriHostNameType.Unknown) + { + if (HostType == other.HostType) return Host.CompareTo(other.Host); } return -1; } - public bool Equals(OSHostURL other) + public bool Equals(OSHHTPHost other) { - if (Port == other.Port && other.URLType != UriHostNameType.Unknown) + if (Port == other.Port && other.HostType != UriHostNameType.Unknown) { - if (URLType == other.URLType) + if (HostType == other.HostType) return Host.Equals(other.Host); } return false; @@ -163,7 +313,7 @@ namespace OpenSim.Framework public override int GetHashCode() { - return URL.GetHashCode(); + return URI.GetHashCode(); } } @@ -172,11 +322,11 @@ namespace OpenSim.Framework private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private bool m_hasHGconfig; - private OSHostURL m_gateKeeperURL; - private HashSet m_gateKeeperAlias; + private OSHHTPHost m_gateKeeperURL; + private HashSet m_gateKeeperAlias; - private OSHostURL m_homeURL; - private HashSet m_homeURLAlias; + private OSHHTPHost m_homeURL; + private HashSet m_homeURLAlias; public GridInfo (IConfigSource config, string defaultURI = "") { @@ -199,18 +349,19 @@ namespace OpenSim.Framework { m_hasHGconfig = false; if (!string.IsNullOrEmpty(defaultURI)) - m_gateKeeperURL = new OSHostURL(defaultURI, true); + m_gateKeeperURL = new OSHHTPHost(defaultURI, true); } else { - m_gateKeeperURL = new OSHostURL(gatekeeper, true); + m_gateKeeperURL = new OSHHTPHost(gatekeeper, true); m_hasHGconfig = true; } - if (m_gateKeeperURL.URLType == UriHostNameType.Unknown) - throw new Exception(String.Format("could not find gatekeeper URL")); - if (m_gateKeeperURL.IP == null) - throw new Exception(String.Format("could not resolve gatekeeper hostname")); + if (!m_gateKeeperURL.IsResolvedHost) + { + m_log.Error(m_gateKeeperURL.IsValidHost ? "Could not resolve GatekeeperURI" : "GatekeeperURI is a invalid host"); + throw new Exception("GatekeeperURI configuration error"); + } string gatekeeperURIAlias = Util.GetConfigVarFromSections(config, "GatekeeperURIAlias", sections, String.Empty); @@ -219,11 +370,11 @@ namespace OpenSim.Framework string[] alias = gatekeeperURIAlias.Split(','); for (int i = 0; i < alias.Length; ++i) { - OSHostURL tmp = new OSHostURL(alias[i].Trim(), false); - if (tmp.URLType != UriHostNameType.Unknown) + OSHHTPHost tmp = new OSHHTPHost(alias[i].Trim(), false); + if (tmp.HostType != UriHostNameType.Unknown) { if (m_gateKeeperAlias == null) - m_gateKeeperAlias = new HashSet(); + m_gateKeeperAlias = new HashSet(); m_gateKeeperAlias.Add(tmp); } } @@ -236,15 +387,16 @@ namespace OpenSim.Framework if (!string.IsNullOrEmpty(gatekeeper)) m_homeURL = m_gateKeeperURL; else if (!string.IsNullOrEmpty(defaultURI)) - m_homeURL = new OSHostURL(defaultURI, true); + m_homeURL = new OSHHTPHost(defaultURI, true); } else - m_homeURL = new OSHostURL(home, true); + m_homeURL = new OSHHTPHost(home, true); - if (m_homeURL.URLType == UriHostNameType.Unknown) - throw new Exception(String.Format("could not find home(UserAgentsService) URL")); - if (m_homeURL.IP == null) - throw new Exception(String.Format("could not resolve home(UserAgentsService) hostname")); + if (!m_homeURL.IsResolvedHost) + { + m_log.Error(m_homeURL.IsValidHost ? "Could not resolve HomeURI" : "HomeURI is a invalid host"); + throw new Exception("HomeURI configuration error"); + } string homeAlias = Util.GetConfigVarFromSections(config, "HomeURIAlias", sections, String.Empty); if (!string.IsNullOrWhiteSpace(homeAlias)) @@ -252,11 +404,11 @@ namespace OpenSim.Framework string[] alias = homeAlias.Split(','); for (int i = 0; i < alias.Length; ++i) { - OSHostURL tmp = new OSHostURL(alias[i].Trim(), false); - if (tmp.URLType != UriHostNameType.Unknown) + OSHHTPHost tmp = new OSHHTPHost(alias[i].Trim(), false); + if (tmp.HostType != UriHostNameType.Unknown) { if (m_homeURLAlias == null) - m_homeURLAlias = new HashSet(); + m_homeURLAlias = new HashSet(); m_homeURLAlias.Add(tmp); } } @@ -265,38 +417,25 @@ namespace OpenSim.Framework public bool HasHGConfig { - get - { - return m_hasHGconfig; - } + get { return m_hasHGconfig; } } public string GateKeeperURL { - get - { - if (m_gateKeeperURL.URLType != UriHostNameType.Unknown) - return m_gateKeeperURL.URL; - return string.Empty; - } + get { return m_gateKeeperURL.URIwEndSlash; } } public string GateKeeperURLNoEndSlash { - get - { - if (m_gateKeeperURL.URLType != UriHostNameType.Unknown) - return m_gateKeeperURL.URL.Substring(0, m_gateKeeperURL.URL.Length - 1); - return string.Empty; - } + get { return m_gateKeeperURL.URI; } } public string HGGateKeeperURL { get { - if (m_gateKeeperURL.URLType != UriHostNameType.Unknown && m_hasHGconfig) - return m_gateKeeperURL.URL; + if (m_gateKeeperURL.HostType != UriHostNameType.Unknown && m_hasHGconfig) + return m_gateKeeperURL.URIwEndSlash; return string.Empty; } } @@ -305,39 +444,29 @@ namespace OpenSim.Framework { get { - if (m_gateKeeperURL.URLType != UriHostNameType.Unknown && m_hasHGconfig) - return m_gateKeeperURL.URL.Substring(0, m_gateKeeperURL.URL.Length - 1); + if (m_hasHGconfig) + return m_gateKeeperURL.URI; return string.Empty; } } public string HomeURL { - get - { - if (m_homeURL.URLType != UriHostNameType.Unknown) - return m_homeURL.URL; - return null; - } + get { return m_homeURL.URIwEndSlash; } } public string HomeURLNoEndSlash { - get - { - if (m_homeURL.URLType != UriHostNameType.Unknown) - return m_homeURL.URL.Substring(0, m_gateKeeperURL.URL.Length - 1); - return null; - } + get { return m_homeURL.URI; } } public string HGHomeURL { get { - if (m_homeURL.URLType != UriHostNameType.Unknown && m_hasHGconfig) - return m_homeURL.URL; - return null; + if (m_hasHGconfig) + return m_homeURL.URIwEndSlash; + return string.Empty; } } @@ -345,9 +474,9 @@ namespace OpenSim.Framework { get { - if (m_homeURL.URLType != UriHostNameType.Unknown && m_hasHGconfig) - return m_homeURL.URL.Substring(0, m_gateKeeperURL.URL.Length - 1); - return null; + if (m_hasHGconfig) + return m_homeURL.URI; + return string.Empty; } } @@ -355,10 +484,10 @@ namespace OpenSim.Framework // -1 if bad url // 0 if not local // 1 if local - public int IsLocalGrid(string gatekeeper, bool withResolveCheck = false) + public int IsLocalGrid(string othergatekeeper, bool withResolveCheck = false) { - OSHostURL tmp = new OSHostURL(gatekeeper, false); - if(tmp.URLType == UriHostNameType.Unknown) + OSHHTPHost tmp = new OSHHTPHost(othergatekeeper, false); + if(tmp.HostType == UriHostNameType.Unknown) return -1; if (tmp.Equals(m_gateKeeperURL)) return 1; @@ -371,10 +500,10 @@ namespace OpenSim.Framework return 0; } - public int IsLocalHome(string home) + public int IsLocalHome(string otherhome) { - OSHostURL tmp = new OSHostURL(home, false); - if (tmp.URLType == UriHostNameType.Unknown) + OSHHTPHost tmp = new OSHHTPHost(otherhome, false); + if (tmp.HostType == UriHostNameType.Unknown) return -1; if (tmp.Equals(m_homeURL)) return 1; diff --git a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs index 1a252817ef..9e465598b7 100644 --- a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs @@ -214,7 +214,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles } catch (Exception e) { - m_log.ErrorFormat("[ProfileModule]: Process fail {0} : {1}", e.Message, e.StackTrace); + m_log.ErrorFormat("[UserProfileModule]: Process fail {0} : {1}", e.Message, e.StackTrace); } } m_asyncRequestsRunning = false; @@ -301,17 +301,19 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles // If we find ProfileURL then we configure for FULL support // else we setup for BASIC support ProfileServerUri = profileConfig.GetString("ProfileServiceURL", ""); - OSHostURL tmp = new OSHostURL(ProfileServerUri, true); - if(tmp.IP == null) + + OSHTTPURI tmp = new OSHTTPURI(ProfileServerUri, true); + if (!tmp.IsResolvedHost) { - m_log.Debug("[PROFILES]: Fail to resolve [UserProfiles] ProfileServiceURL. UserProfiles disabled"); - Enabled = false; - return; + m_log.ErrorFormat("[UserProfileModule: {0}", tmp.IsValidHost ? "Could not resolve ProfileServiceURL" : "ProfileServiceURL is a invalid host"); + throw new Exception("UserProfileModule init error"); } + ProfileServerUri = tmp.URI; + m_allowUserProfileWebURLs = profileConfig.GetBoolean("AllowUserProfileWebURLs", m_allowUserProfileWebURLs); - m_log.Debug("[PROFILES]: Full Profiles Enabled"); + m_log.Debug("[UserProfileModule]: Full Profiles Enabled"); ReplaceableInterface = null; Enabled = true; } diff --git a/OpenSim/Services/Connectors/GridUser/GridUserServicesConnector.cs b/OpenSim/Services/Connectors/GridUser/GridUserServicesConnector.cs index b5ca1adb7a..cc967e1b81 100644 --- a/OpenSim/Services/Connectors/GridUser/GridUserServicesConnector.cs +++ b/OpenSim/Services/Connectors/GridUser/GridUserServicesConnector.cs @@ -72,15 +72,23 @@ namespace OpenSim.Services.Connectors throw new Exception("GridUser connector init error"); } - string serviceURI = gridConfig.GetString("GridUserServerURI", - String.Empty); + string serviceURI = gridConfig.GetString("GridUserServerURI", string.Empty); - if (serviceURI == String.Empty) + if (string.IsNullOrWhiteSpace(serviceURI)) { - m_log.Error("[GRID USER CONNECTOR]: No Server URI named in section GridUserService"); + m_log.Error("[GRIDUSER CONNECTOR]: GridUserServerURI not found section GridUserService"); throw new Exception("GridUser connector init error"); } - m_ServerURI = serviceURI; + + OSHHTPHost tmp = new OSHHTPHost(serviceURI, true); + if (!tmp.IsResolvedHost) + { + m_log.ErrorFormat("[GRIDUSER CONNECTOR]: {0}", tmp.IsValidHost ? "Could not resolve GridUserServerURI" : "GridUserServerURI is a invalid host"); + throw new Exception("User account connector init error"); + } + + m_ServerURI = tmp.URI; + base.Initialise(source, "GridUserService"); } diff --git a/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs b/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs index 68ae7bb2ec..174099fd01 100644 --- a/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs +++ b/OpenSim/Services/Connectors/UserAccounts/UserAccountServicesConnector.cs @@ -71,15 +71,22 @@ namespace OpenSim.Services.Connectors throw new Exception("User account connector init error"); } - string serviceURI = assetConfig.GetString("UserAccountServerURI", - String.Empty); + string serviceURI = assetConfig.GetString("UserAccountServerURI", string.Empty); - if (serviceURI == String.Empty) + if (string.IsNullOrWhiteSpace(serviceURI)) { - m_log.Error("[ACCOUNT CONNECTOR]: No Server URI named in section UserAccountService"); + m_log.Error("[ACCOUNT CONNECTOR]: UserAccountServerURI not found in section UserAccountService"); throw new Exception("User account connector init error"); } - m_ServerURI = serviceURI; + + OSHHTPHost tmp = new OSHHTPHost(serviceURI, true); + if (!tmp.IsResolvedHost) + { + m_log.ErrorFormat("[ACCOUNT CONNECTOR]: {0}", tmp.IsValidHost ? "Could not resolve UserAccountServerURI" : "UserAccountServerURI is a invalid host"); + throw new Exception("User account connector init error"); + } + + m_ServerURI = tmp.URI; base.Initialise(source, "UserAccountService"); } diff --git a/bin/config-include/GridCommon.ini.example b/bin/config-include/GridCommon.ini.example index f75081a724..e5d291ef55 100644 --- a/bin/config-include/GridCommon.ini.example +++ b/bin/config-include/GridCommon.ini.example @@ -163,7 +163,7 @@ [GridUserService] ; - ; Change this to your grid-wide user accounts server + ; Change this to your grid-wide user server ; GridUserServerURI = "${Const|PrivURL}:${Const|PrivatePort}"