GridInfo.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Net;
  30. using System.Reflection;
  31. using log4net;
  32. using Nini.Config;
  33. namespace OpenSim.Framework
  34. {
  35. public enum OSHTTPURIFlags : byte
  36. {
  37. None = 0,
  38. ValidHost = 1,
  39. Resolved = 1 << 1,
  40. Empty = 1 << 2,
  41. ValidResolved = ValidHost | Resolved
  42. }
  43. // full http or https schema, server host, port and possible server path any query is ignored.
  44. public struct OSHTTPURI:IComparable<OSHTTPURI>, IEquatable<OSHTTPURI>
  45. {
  46. public OSHTTPURIFlags Flags;
  47. public int Port;
  48. public IPAddress IP;
  49. public readonly string Host;
  50. public readonly string URL;
  51. public readonly string Path;
  52. public readonly string URI;
  53. public OSHTTPURI(string uri, bool withDNSResolve = false)
  54. {
  55. Flags = OSHTTPURIFlags.Empty;
  56. Port = -1;
  57. IP = null;
  58. Host = string.Empty;
  59. URI = string.Empty;
  60. URL = string.Empty;
  61. Path = string.Empty;
  62. if (string.IsNullOrEmpty(uri))
  63. return;
  64. Flags = OSHTTPURIFlags.None;
  65. try
  66. {
  67. Uri m_checkuri = new Uri(uri);
  68. if(m_checkuri.Scheme != Uri.UriSchemeHttp && m_checkuri.Scheme != Uri.UriSchemeHttps)
  69. return;
  70. Flags = OSHTTPURIFlags.ValidHost;
  71. Host = m_checkuri.DnsSafeHost.ToLowerInvariant();
  72. Port = m_checkuri.Port;
  73. Path = m_checkuri.AbsolutePath;
  74. URL = m_checkuri.Scheme + "://" + Host + ":" + Port;
  75. URI = m_checkuri.AbsoluteUri;
  76. if (withDNSResolve)
  77. {
  78. IPAddress ip = Util.GetHostFromDNS(Host);
  79. if (ip != null)
  80. {
  81. IP = ip;
  82. Flags = OSHTTPURIFlags.ValidResolved;
  83. }
  84. }
  85. }
  86. catch
  87. {
  88. Flags = OSHTTPURIFlags.None;
  89. IP = null;
  90. URI = string.Empty;
  91. }
  92. }
  93. public bool ResolveDNS()
  94. {
  95. IPAddress ip = Util.GetHostFromDNS(Host);
  96. if (ip == null)
  97. {
  98. Flags &= ~OSHTTPURIFlags.Resolved;
  99. return false;
  100. }
  101. Flags |= OSHTTPURIFlags.Resolved;
  102. return true;
  103. }
  104. public bool IsValidHost
  105. {
  106. get { return (Flags & OSHTTPURIFlags.ValidHost) != 0; }
  107. }
  108. public bool ValidAndResolved(out string error)
  109. {
  110. if ((Flags & OSHTTPURIFlags.ValidHost) == 0)
  111. {
  112. error = "failed to parse uri";
  113. return false;
  114. }
  115. if ((Flags & OSHTTPURIFlags.Resolved) == 0)
  116. {
  117. error = "failed DNS resolve of uri host";
  118. return false;
  119. }
  120. error = string.Empty;
  121. return true;
  122. }
  123. public bool IsResolvedHost
  124. {
  125. get {return (Flags & OSHTTPURIFlags.Resolved) != 0; }
  126. }
  127. public string URIwEndSlash
  128. {
  129. get { return Flags == OSHTTPURIFlags.None ? "" : URI + "/";}
  130. }
  131. public int CompareTo(OSHTTPURI other)
  132. {
  133. if (Port == other.Port && ((Flags & other.Flags) & OSHTTPURIFlags.ValidHost) != 0)
  134. {
  135. if (Path.Equals(other.Path))
  136. return Host.CompareTo(other.Host);
  137. }
  138. return -1;
  139. }
  140. public bool Equals(OSHTTPURI other)
  141. {
  142. if (Port == other.Port && ((Flags & other.Flags) & OSHTTPURIFlags.ValidHost) != 0)
  143. {
  144. if (Path.Equals(other.Path))
  145. return Host.Equals(other.Host);
  146. }
  147. return false;
  148. }
  149. public override int GetHashCode()
  150. {
  151. return URI.GetHashCode();
  152. }
  153. }
  154. //host and port. Can not have server internal path or query. http scheme is assumed if not present
  155. public struct OSHHTPHost : IComparable<OSHHTPHost>, IEquatable<OSHHTPHost>
  156. {
  157. public OSHTTPURIFlags Flags;
  158. public int Port;
  159. public IPAddress IP;
  160. public readonly string Host;
  161. public readonly string URI;
  162. public OSHHTPHost(string url, bool withDNSResolve = false)
  163. {
  164. Flags = OSHTTPURIFlags.Empty;
  165. Port = 80;
  166. IP = null;
  167. Host = string.Empty;
  168. URI = string.Empty;
  169. bool secureHTTP = false;
  170. if (string.IsNullOrEmpty(url))
  171. return;
  172. Flags = OSHTTPURIFlags.None;
  173. url = url.ToLowerInvariant();
  174. try
  175. {
  176. int urllen = url.Length;
  177. if (url[urllen - 1] == '/')
  178. --urllen;
  179. int start;
  180. if (url.StartsWith("http"))
  181. {
  182. if (url[4] == 's')
  183. {
  184. start = 8;
  185. secureHTTP = true;
  186. }
  187. else
  188. start = 7;
  189. }
  190. else
  191. start = 0;
  192. string host;
  193. UriHostNameType type;
  194. int indx = url.IndexOf(':', start, urllen - start);
  195. if (indx > 0)
  196. {
  197. host = url.Substring(start, indx - start);
  198. type = Uri.CheckHostName(host);
  199. if (type == UriHostNameType.Unknown || type == UriHostNameType.Basic)
  200. return;
  201. ++indx;
  202. string sport = url.Substring(indx, urllen - indx);
  203. int tmp;
  204. if (!int.TryParse(sport, out tmp) || tmp < 0 || tmp > 65535)
  205. return;
  206. Flags = OSHTTPURIFlags.ValidHost;
  207. Host = host;
  208. Port = tmp;
  209. URI = (secureHTTP ? "https://" : "http://") + Host + ":" + Port.ToString();
  210. }
  211. else
  212. {
  213. host = url.Substring(start, urllen - start);
  214. type = Uri.CheckHostName(host);
  215. if (type == UriHostNameType.Unknown || type == UriHostNameType.Basic)
  216. return;
  217. Flags = OSHTTPURIFlags.ValidHost;
  218. Host = host;
  219. if (secureHTTP)
  220. {
  221. Port = 443;
  222. URI = "https://" + Host + ":443";
  223. }
  224. else
  225. {
  226. Port = 80;
  227. URI = "http://" + Host + ":80";
  228. }
  229. }
  230. if (withDNSResolve)
  231. {
  232. IPAddress ip = Util.GetHostFromDNS(host);
  233. if (ip != null)
  234. {
  235. Flags = OSHTTPURIFlags.ValidResolved;
  236. IP = ip;
  237. }
  238. }
  239. }
  240. catch
  241. {
  242. Flags = OSHTTPURIFlags.None;
  243. IP = null;
  244. URI = string.Empty;
  245. }
  246. }
  247. public bool ResolveDNS()
  248. {
  249. IPAddress ip = Util.GetHostFromDNS(Host);
  250. if (ip == null)
  251. {
  252. Flags &= ~OSHTTPURIFlags.Resolved;
  253. return false;
  254. }
  255. Flags |= OSHTTPURIFlags.Resolved;
  256. return true;
  257. }
  258. public bool IsValidHost
  259. {
  260. get { return (Flags & OSHTTPURIFlags.ValidHost) != 0; }
  261. }
  262. public bool IsResolvedHost
  263. {
  264. get { return (Flags & OSHTTPURIFlags.Resolved) != 0; }
  265. }
  266. public bool ValidAndResolved(out string error)
  267. {
  268. if ((Flags & OSHTTPURIFlags.ValidHost) == 0)
  269. {
  270. error = "failed to parse uri";
  271. return false;
  272. }
  273. if ((Flags & OSHTTPURIFlags.Resolved) == 0)
  274. {
  275. error = "failed DNS resolve of uri host";
  276. return false;
  277. }
  278. error = string.Empty;
  279. return true;
  280. }
  281. public string URIwEndSlash
  282. {
  283. get { return (Flags == OSHTTPURIFlags.None) ? "" : URI + "/"; }
  284. }
  285. public string HostAndPort
  286. {
  287. get { return (Flags == OSHTTPURIFlags.None) ? "" : Host + ":" + Port.ToString(); }
  288. }
  289. public int CompareTo(OSHHTPHost other)
  290. {
  291. if (Port == other.Port && ((Flags & other.Flags) & OSHTTPURIFlags.ValidHost) != 0)
  292. {
  293. return Host.CompareTo(other.Host);
  294. }
  295. return -1;
  296. }
  297. public bool Equals(OSHHTPHost other)
  298. {
  299. if (Port == other.Port && ((Flags & other.Flags) & OSHTTPURIFlags.ValidHost) != 0)
  300. {
  301. return Host.Equals(other.Host);
  302. }
  303. return false;
  304. }
  305. public override int GetHashCode()
  306. {
  307. return Host.GetHashCode() + Port;
  308. }
  309. }
  310. public class GridInfo
  311. {
  312. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  313. private bool m_hasHGconfig;
  314. private OSHHTPHost m_gateKeeperURL;
  315. private HashSet<OSHHTPHost> m_gateKeeperAlias;
  316. private OSHHTPHost m_homeURL;
  317. private HashSet<OSHHTPHost> m_homeURLAlias;
  318. private string m_gridUrl = string.Empty;
  319. private string[] m_gridUrlAlias = null;
  320. private string m_GridName = string.Empty;
  321. private string m_GridNick = string.Empty;
  322. private string m_SearchURL = string.Empty;
  323. private string m_DestinationGuideURL = string.Empty;
  324. private string m_economyURL = string.Empty;
  325. public GridInfo (IConfigSource config, string defaultURI = "")
  326. {
  327. string[] sections = new string[] {"Const", "Startup", "Hypergrid"};
  328. string gatekeeper = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI", sections, string.Empty);
  329. if (string.IsNullOrEmpty(gatekeeper))
  330. {
  331. IConfig serverConfig = config.Configs["GatekeeperService"];
  332. if (serverConfig != null)
  333. gatekeeper = serverConfig.GetString("ExternalName", string.Empty);
  334. }
  335. if (string.IsNullOrEmpty(gatekeeper))
  336. {
  337. IConfig gridConfig = config.Configs["GridService"];
  338. if (gridConfig != null)
  339. gatekeeper = gridConfig.GetString("Gatekeeper", string.Empty);
  340. }
  341. if (string.IsNullOrEmpty(gatekeeper))
  342. {
  343. m_hasHGconfig = false;
  344. if (!string.IsNullOrEmpty(defaultURI))
  345. m_gateKeeperURL = new OSHHTPHost(defaultURI, true);
  346. }
  347. else
  348. {
  349. m_gateKeeperURL = new OSHHTPHost(gatekeeper, true);
  350. m_hasHGconfig = true;
  351. }
  352. if (!m_gateKeeperURL.IsResolvedHost)
  353. {
  354. m_log.Error(m_gateKeeperURL.IsValidHost ? "Could not resolve GatekeeperURI" : "GatekeeperURI is a invalid host");
  355. throw new Exception("GatekeeperURI configuration error");
  356. }
  357. m_gridUrl = m_gateKeeperURL.URI;
  358. string gatekeeperURIAlias = Util.GetConfigVarFromSections<string>(config, "GatekeeperURIAlias", sections, string.Empty);
  359. if (!string.IsNullOrWhiteSpace(gatekeeperURIAlias))
  360. {
  361. string[] alias = gatekeeperURIAlias.Split(',');
  362. for (int i = 0; i < alias.Length; ++i)
  363. {
  364. OSHHTPHost tmp = new OSHHTPHost(alias[i].Trim(), false);
  365. if (tmp.IsValidHost)
  366. {
  367. if (m_gateKeeperAlias == null)
  368. m_gateKeeperAlias = new HashSet<OSHHTPHost>();
  369. m_gateKeeperAlias.Add(tmp);
  370. }
  371. }
  372. }
  373. if (m_gateKeeperAlias != null && m_gateKeeperAlias.Count > 0)
  374. {
  375. m_gridUrlAlias = new string[m_gateKeeperAlias.Count];
  376. int i = 0;
  377. foreach (OSHHTPHost a in m_gateKeeperAlias)
  378. m_gridUrlAlias[i++] = a.URI;
  379. }
  380. string home = Util.GetConfigVarFromSections<string>(config, "HomeURI", sections, string.Empty);
  381. if (string.IsNullOrEmpty(home))
  382. {
  383. if (!string.IsNullOrEmpty(gatekeeper))
  384. m_homeURL = m_gateKeeperURL;
  385. else if (!string.IsNullOrEmpty(defaultURI))
  386. m_homeURL = new OSHHTPHost(defaultURI, true);
  387. }
  388. else
  389. m_homeURL = new OSHHTPHost(home, true);
  390. if (!m_homeURL.IsResolvedHost)
  391. {
  392. m_log.Error(m_homeURL.IsValidHost ? "Could not resolve HomeURI" : "HomeURI is a invalid host");
  393. throw new Exception("HomeURI configuration error");
  394. }
  395. string homeAlias = Util.GetConfigVarFromSections<string>(config, "HomeURIAlias", sections, string.Empty);
  396. if (!string.IsNullOrWhiteSpace(homeAlias))
  397. {
  398. string[] alias = homeAlias.Split(',');
  399. for (int i = 0; i < alias.Length; ++i)
  400. {
  401. OSHHTPHost tmp = new OSHHTPHost(alias[i].Trim(), false);
  402. if (tmp.IsValidHost)
  403. {
  404. if (m_homeURLAlias == null)
  405. m_homeURLAlias = new HashSet<OSHHTPHost>();
  406. m_homeURLAlias.Add(tmp);
  407. }
  408. }
  409. }
  410. string[] namessections = new string[] { "Const", "GridInfo", "SimulatorFeatures" };
  411. m_GridName = Util.GetConfigVarFromSections<string>(config, "GridName", namessections, string.Empty);
  412. if (string.IsNullOrEmpty(m_GridName))
  413. m_GridName = Util.GetConfigVarFromSections<string>(config, "gridname", namessections, string.Empty);
  414. m_GridNick = Util.GetConfigVarFromSections<string>(config, "GridNick", namessections, string.Empty);
  415. if (m_GridName == string.Empty)
  416. m_GridName = "Another bad configured grid";
  417. OSHTTPURI tmpuri;
  418. m_SearchURL = Util.GetConfigVarFromSections<string>(config,"SearchServerURI", namessections, string.Empty);
  419. if (!string.IsNullOrEmpty(m_SearchURL))
  420. {
  421. tmpuri = new OSHTTPURI(m_SearchURL.Trim(), true);
  422. if (!tmpuri.IsResolvedHost)
  423. {
  424. m_log.Error(tmpuri.IsValidHost ? "Could not resolve SearchServerURI" : "SearchServerURI is a invalid host");
  425. throw new Exception("SearchServerURI configuration error");
  426. }
  427. m_SearchURL = tmpuri.URI;
  428. }
  429. m_DestinationGuideURL = Util.GetConfigVarFromSections<string>(config, "DestinationGuideURI",namessections, string.Empty);
  430. if (string.IsNullOrEmpty(m_DestinationGuideURL)) // Make this consistent with the variable in the LoginService config
  431. m_DestinationGuideURL = Util.GetConfigVarFromSections<string>(config, "DestinationGuide", namessections, string.Empty);
  432. if (!string.IsNullOrEmpty(m_DestinationGuideURL))
  433. {
  434. tmpuri = new OSHTTPURI(m_DestinationGuideURL.Trim(), true);
  435. if (!tmpuri.IsResolvedHost)
  436. {
  437. m_log.Error(tmpuri.IsValidHost ? "Could not resolve DestinationGuideURL" : "DestinationGuideURL is a invalid host");
  438. throw new Exception("DestinationGuideURL configuration error");
  439. }
  440. m_DestinationGuideURL = tmpuri.URI;
  441. }
  442. m_economyURL = Util.GetConfigVarFromSections<string>(config, "economy", new string[] { "Economy", "GridInfo" });
  443. if (!string.IsNullOrEmpty(m_economyURL))
  444. {
  445. tmpuri = new OSHTTPURI(m_economyURL.Trim(), true);
  446. if (!tmpuri.IsResolvedHost)
  447. {
  448. m_log.Error(tmpuri.IsValidHost ? "Could not resolve economyURL" : "economyURL is a invalid host");
  449. throw new Exception("economyURL configuration error");
  450. }
  451. m_economyURL = tmpuri.URI;
  452. }
  453. }
  454. public bool HasHGConfig
  455. {
  456. get { return m_hasHGconfig; }
  457. }
  458. public string GateKeeperURL
  459. {
  460. get { return m_gateKeeperURL.URIwEndSlash; }
  461. }
  462. public string GateKeeperURLNoEndSlash
  463. {
  464. get { return m_gateKeeperURL.URI; }
  465. }
  466. public string HGGateKeeperURL
  467. {
  468. get
  469. {
  470. if (m_hasHGconfig)
  471. return m_gateKeeperURL.URIwEndSlash;
  472. return string.Empty;
  473. }
  474. }
  475. public string HGGateKeeperURLNoEndSlash
  476. {
  477. get
  478. {
  479. if (m_hasHGconfig)
  480. return m_gateKeeperURL.URI;
  481. return string.Empty;
  482. }
  483. }
  484. public string HomeURL
  485. {
  486. get { return m_homeURL.URIwEndSlash; }
  487. }
  488. public string HomeURLNoEndSlash
  489. {
  490. get { return m_homeURL.URI; }
  491. }
  492. public string HGHomeURL
  493. {
  494. get
  495. {
  496. if (m_hasHGconfig)
  497. return m_homeURL.URIwEndSlash;
  498. return string.Empty;
  499. }
  500. }
  501. public string HGHomeURLNoEndSlash
  502. {
  503. get
  504. {
  505. if (m_hasHGconfig)
  506. return m_homeURL.URI;
  507. return string.Empty;
  508. }
  509. }
  510. // -2 dns failed
  511. // -1 if bad url
  512. // 0 if not local
  513. // 1 if local
  514. public int IsLocalGrid(string othergatekeeper)
  515. {
  516. OSHHTPHost tmp = new OSHHTPHost(othergatekeeper, false);
  517. if (!tmp.IsValidHost)
  518. return ((tmp.Flags & OSHTTPURIFlags.Empty) == 0) ? -1 : 1;
  519. if (tmp.Equals(m_gateKeeperURL))
  520. return 1;
  521. if (m_gateKeeperAlias != null && m_gateKeeperAlias.Contains(tmp))
  522. return 1;
  523. return 0;
  524. }
  525. public int IsLocalGrid(string othergatekeeper, bool withResolveCheck)
  526. {
  527. OSHHTPHost tmp = new OSHHTPHost(othergatekeeper, false);
  528. if (!tmp.IsValidHost)
  529. return ((tmp.Flags & OSHTTPURIFlags.Empty) == 0) ? -1 : 1;
  530. if (tmp.Equals(m_gateKeeperURL))
  531. return 1;
  532. if (m_gateKeeperAlias != null && m_gateKeeperAlias.Contains(tmp))
  533. return 1;
  534. if (withResolveCheck)
  535. {
  536. if (tmp.IsResolvedHost)
  537. return 0;
  538. return tmp.ResolveDNS() ? 0 : -2;
  539. }
  540. return 0;
  541. }
  542. public int IsLocalGrid(OSHHTPHost othergatekeeper)
  543. {
  544. if (!othergatekeeper.IsValidHost)
  545. return ((othergatekeeper.Flags & OSHTTPURIFlags.Empty) == 0) ? -1 : 1;
  546. if (othergatekeeper.Equals(m_gateKeeperURL))
  547. return 1;
  548. if (m_gateKeeperAlias != null && m_gateKeeperAlias.Contains(othergatekeeper))
  549. return 1;
  550. return 0;
  551. }
  552. public int IsLocalHome(string otherhome)
  553. {
  554. OSHHTPHost tmp = new OSHHTPHost(otherhome, false);
  555. if (!tmp.IsValidHost)
  556. return ((tmp.Flags & OSHTTPURIFlags.Empty) == 0) ? -1 : 1;
  557. if (tmp.Equals(m_homeURL))
  558. return 1;
  559. if (m_homeURLAlias != null && m_homeURLAlias.Contains(tmp))
  560. return 1;
  561. return 0;
  562. }
  563. public int IsLocalHome(string otherhome, bool withResolveCheck)
  564. {
  565. OSHHTPHost tmp = new OSHHTPHost(otherhome, false);
  566. if (!tmp.IsValidHost)
  567. return ((tmp.Flags & OSHTTPURIFlags.Empty) == 0) ? -1 : 1;
  568. if (tmp.Equals(m_homeURL))
  569. return 1;
  570. if (m_homeURLAlias != null && m_homeURLAlias.Contains(tmp))
  571. return 1;
  572. if (withResolveCheck)
  573. {
  574. return tmp.ResolveDNS() ? 0 : -2;
  575. }
  576. return 0;
  577. }
  578. public string[] GridUrlAlias
  579. {
  580. get { return m_gridUrlAlias; }
  581. set
  582. {
  583. if(value.Length > 0)
  584. {
  585. for (int i = 0; i < value.Length; ++i)
  586. {
  587. OSHHTPHost tmp = new OSHHTPHost(value[i].Trim(), false);
  588. if (tmp.IsValidHost)
  589. {
  590. if (m_gateKeeperAlias == null)
  591. m_gateKeeperAlias = new HashSet<OSHHTPHost>();
  592. m_gateKeeperAlias.Add(tmp);
  593. }
  594. }
  595. if (m_gateKeeperAlias != null && m_gateKeeperAlias.Count > 0)
  596. {
  597. m_gridUrlAlias = new string[m_gateKeeperAlias.Count];
  598. int i = 0;
  599. foreach (OSHHTPHost a in m_gateKeeperAlias)
  600. m_gridUrlAlias[i++] = a.URI;
  601. }
  602. }
  603. }
  604. }
  605. public string GridName
  606. {
  607. get { return m_GridName; }
  608. set
  609. {
  610. if (!string.IsNullOrEmpty(value))
  611. m_GridName = value;
  612. }
  613. }
  614. public string GridNick
  615. {
  616. get { return m_GridNick; }
  617. set
  618. {
  619. if (!string.IsNullOrEmpty(value))
  620. m_GridNick = value;
  621. }
  622. }
  623. public string GridUrl
  624. {
  625. get { return m_gridUrl; }
  626. set
  627. {
  628. OSHHTPHost tmp = new OSHHTPHost(value, true);
  629. if (tmp.IsResolvedHost)
  630. m_gridUrl = tmp.URI;
  631. else
  632. m_log.Error((tmp.IsValidHost ? "Could not resolve GridUrl" : "GridUrl is a invalid host ") + value ?? "");
  633. }
  634. }
  635. public string SearchURL
  636. {
  637. get { return m_SearchURL; }
  638. set
  639. {
  640. OSHTTPURI tmp = new OSHTTPURI(value, true);
  641. if (tmp.IsResolvedHost)
  642. m_SearchURL = tmp.URI;
  643. else
  644. m_log.Error((tmp.IsValidHost ? "Could not resolve SearchURL" : "SearchURL is a invalid host ") + value??"");
  645. }
  646. }
  647. public string DestinationGuideURL
  648. {
  649. get { return m_DestinationGuideURL; }
  650. set
  651. {
  652. OSHTTPURI tmp = new OSHTTPURI(value, true);
  653. if (tmp.IsResolvedHost)
  654. m_DestinationGuideURL = tmp.URI;
  655. else
  656. m_log.Error((tmp.IsValidHost ? "Could not resolve DestinationGuideURL" : "DestinationGuideURL is a invalid host ") + value ?? "");
  657. }
  658. }
  659. public string EconomyURL
  660. {
  661. get { return m_economyURL; }
  662. set
  663. {
  664. OSHTTPURI tmp = new OSHTTPURI(value, true);
  665. if (tmp.IsResolvedHost)
  666. m_economyURL = tmp.URI;
  667. else
  668. m_log.Error((tmp.IsValidHost ? "Could not resolve EconomyURL" : "EconomyURL is a invalid host ") + value ?? "");
  669. }
  670. }
  671. }
  672. }