GridInfo.cs 25 KB

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