1
0

GridInfo.cs 25 KB

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