llgridmanager.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. /**
  2. * @file llgridmanager.cpp
  3. * @brief Grids management.
  4. *
  5. * $LicenseInfo:firstyear=2006&license=viewergpl$
  6. *
  7. * Copyright (c) 2006-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llgridmanager.h"
  34. #include "lldir.h"
  35. #include "llhost.h"
  36. #include "llsd.h"
  37. #include "llsdserialize.h"
  38. #include "llstartup.h"
  39. #include "llviewercontrol.h"
  40. #include "llviewermenu.h"
  41. // Assume SL production grid by default (strictest policy).
  42. bool gIsInSecondLife = true;
  43. bool gIsInSecondLifeProductionGrid = true;
  44. bool gIsInSecondLifeBetaGrid = false;
  45. bool gIsInProductionGrid = true;
  46. bool gPacificDaylightTime = false;
  47. EGridInfo GRID_INFO_OTHER;
  48. ///////////////////////////////////////////////////////////////////////////////
  49. // SecondLife URLs
  50. ///////////////////////////////////////////////////////////////////////////////
  51. const std::string CREATE_ACCOUNT_URL("https://join.secondlife.com/");
  52. const std::string AUCTION_URL(
  53. "https://secondlife.com/auctions/auction-detail.php?id=");
  54. const std::string EVENTS_URL("http://events.secondlife.com/viewer/embed/event/");
  55. const std::string SUPPORT_URL("https://support.secondlife.com/");
  56. const std::string FORGOTTEN_PASSWORD_URL(
  57. "https://secondlife.com/account/request.php");
  58. const std::string BUY_CURRENCY_URL("https://secondlife.com/my/lindex/");
  59. const std::string LSL_DOC_URL("http://wiki.secondlife.com/wiki/LSL_Portal");
  60. const std::string RELEASE_NOTES_BASE_URL(
  61. "http://secondlife.com/app/releasenotes/");
  62. const std::string AGNI_LOGIN_URI(
  63. "https://login.agni.lindenlab.com/cgi-bin/login.cgi");
  64. const std::string ADITI_LOGIN_URI(
  65. "https://login.aditi.lindenlab.com/cgi-bin/login.cgi");
  66. const std::string AGNI_HELPER_URI("https://secondlife.com/helpers/");
  67. const std::string ADITI_HELPER_URI(
  68. "https://secondlife.aditi.lindenlab.com/helpers/");
  69. const std::string SL_LOGIN_PAGE_URL("https://viewer-splash.secondlife.com/");
  70. const std::string AGNI_VALIDATE_MESH_UPLOAD_PAGE_URL(
  71. "https://secondlife.com/my/account/ip/index.php");
  72. const std::string ADITI_VALIDATE_MESH_UPLOAD_PAGE_URL(
  73. "https://secondlife.aditi.lindenlab.com/my/account/mesh.php");
  74. const std::string SL_GRID_STATUS_URL("https://status.secondlifegrid.net/");
  75. const std::string MAIN_GRID_SLURL_BASE = "https://maps.secondlife.com/secondlife/";
  76. const std::string SYSTEM_GRID_APP_SLURL_BASE = "secondlife:///app";
  77. const char* SYSTEM_GRID_SLURL_BASE = "secondlife://%s/secondlife/";
  78. const char* DEFAULT_SLURL_BASE = "x-grid-info://%s/region/";
  79. const char* DEFAULT_APP_SLURL_BASE = "x-grid-info://%s/app";
  80. ///////////////////////////////////////////////////////////////////////////////
  81. // LLGridManager class
  82. ///////////////////////////////////////////////////////////////////////////////
  83. LLGridManager::LLGridManager()
  84. : mGridChoice(DEFAULT_GRID_CHOICE),
  85. mNameEdited(false)
  86. {
  87. loadGridsList();
  88. parseCommandLineURIs();
  89. }
  90. void LLGridManager::loadGridsList()
  91. {
  92. if (LLStartUp::isLoggedIn())
  93. {
  94. // Never change the grids list once started, else bad things will
  95. // happen because the grid choice is done on an index in the list...
  96. return;
  97. }
  98. mGridList.clear();
  99. LLSD array = mGridList.emptyArray();
  100. LLSD entry = mGridList.emptyMap();
  101. entry.insert("label", "None");
  102. entry.insert("name", "");
  103. entry.insert("login_uri", "");
  104. entry.insert("helper_uri", "");
  105. entry.insert("login_page", "");
  106. entry.insert("can_edit", "never");
  107. array.append(entry);
  108. // Add SecondLife servers (main and beta grid):
  109. entry = mGridList.emptyMap();
  110. entry.insert("label", "SecondLife");
  111. entry.insert("name", "agni.lindenlab.com");
  112. entry.insert("login_uri", AGNI_LOGIN_URI);
  113. entry.insert("helper_uri", AGNI_HELPER_URI);
  114. entry.insert("support_url", SUPPORT_URL);
  115. entry.insert("register_url", CREATE_ACCOUNT_URL);
  116. entry.insert("password_url", FORGOTTEN_PASSWORD_URL);
  117. entry.insert("login_page", SL_LOGIN_PAGE_URL);
  118. entry.insert("can_edit", "never");
  119. array.append(entry);
  120. entry = mGridList.emptyMap();
  121. entry.insert("label", "SecondLife Beta");
  122. entry.insert("name", "aditi.lindenlab.com");
  123. entry.insert("login_uri", ADITI_LOGIN_URI);
  124. entry.insert("helper_uri", ADITI_HELPER_URI);
  125. entry.insert("support_url", SUPPORT_URL);
  126. entry.insert("register_url", CREATE_ACCOUNT_URL);
  127. entry.insert("password_url", FORGOTTEN_PASSWORD_URL);
  128. entry.insert("login_page", SL_LOGIN_PAGE_URL);
  129. entry.insert("can_edit", "never");
  130. array.append(entry);
  131. mGridList.insert("grids", array);
  132. mVerbose = true;
  133. // See if we have a grids_custom.xml file to append
  134. loadGridsLLSD(mGridList,
  135. gDirUtil.getFullPath(LL_PATH_USER_SETTINGS,
  136. "grids_custom.xml"),
  137. true);
  138. // Load the additional grids if available
  139. loadGridsLLSD(mGridList,
  140. gDirUtil.getFullPath(LL_PATH_APP_SETTINGS, "grids.xml"));
  141. mVerbose = false;
  142. entry = mGridList.emptyMap();
  143. entry.insert("label", "Other");
  144. entry.insert("name", "");
  145. entry.insert("login_uri", "");
  146. entry.insert("helper_uri", "");
  147. entry.insert("can_edit", "never");
  148. mGridList["grids"].append(entry);
  149. GRID_INFO_OTHER = (EGridInfo)mGridList["grids"].size() - 1;
  150. }
  151. const EGridInfo LLGridManager::gridIndexInList(LLSD& grids,
  152. std::string name,
  153. std::string label)
  154. {
  155. bool has_name = !name.empty();
  156. bool has_label = !label.empty();
  157. if (!has_name && !has_label) return -1;
  158. LLStringUtil::toLower(name);
  159. LLStringUtil::toLower(label);
  160. for (LLSD::map_iterator it = grids.beginMap(); it != grids.endMap(); ++it)
  161. {
  162. LLSD::String key_name = it->first;
  163. LLSD grid_array = it->second;
  164. if (key_name == "grids" && grid_array.isArray())
  165. {
  166. std::string temp;
  167. for (size_t i = 0; i < grid_array.size(); ++i)
  168. {
  169. if (has_name)
  170. {
  171. temp = grid_array[i]["name"].asString();
  172. LLStringUtil::toLower(temp);
  173. if (temp == name)
  174. {
  175. return i;
  176. }
  177. }
  178. if (has_label)
  179. {
  180. temp = grid_array[i]["label"].asString();
  181. LLStringUtil::toLower(temp);
  182. if (temp == label)
  183. {
  184. return i;
  185. }
  186. }
  187. }
  188. }
  189. }
  190. return -1;
  191. }
  192. void LLGridManager::loadGridsLLSD(LLSD& grids,
  193. const std::string& xml_filename,
  194. bool can_edit)
  195. {
  196. LLSD other_grids;
  197. llifstream llsd_xml(xml_filename.c_str(), std::ios::in | std::ios::binary);
  198. if (llsd_xml.is_open())
  199. {
  200. if (mVerbose)
  201. {
  202. llinfos << "Reading grid info: " << xml_filename << llendl;
  203. }
  204. LLSDSerialize::fromXML(other_grids, llsd_xml);
  205. for (LLSD::map_iterator it = other_grids.beginMap();
  206. it != other_grids.endMap(); ++it)
  207. {
  208. LLSD::String key_name = it->first;
  209. LLSD grid_array = it->second;
  210. if (mVerbose)
  211. {
  212. llinfos << "reading: " << key_name << llendl;
  213. }
  214. if (key_name == "grids" && grid_array.isArray())
  215. {
  216. for (size_t i = 0; i < grid_array.size(); ++i)
  217. {
  218. LLSD gmap = grid_array[i];
  219. if (gmap.has("name") && gmap.has("label") &&
  220. gmap.has("login_uri") && gmap.has("helper_uri"))
  221. {
  222. if (gridIndexInList(grids, gmap["name"].asString(),
  223. gmap["label"].asString()) != -1)
  224. {
  225. if (mVerbose)
  226. {
  227. llinfos << "Skipping overridden grid parameters for: "
  228. << gmap.get("name") << llendl;
  229. }
  230. }
  231. else
  232. {
  233. gmap.insert("can_edit", can_edit ? "true" : "false");
  234. grids["grids"].append(gmap);
  235. if (mVerbose)
  236. {
  237. llinfos << "Added grid: " << gmap.get("name") << llendl;
  238. }
  239. }
  240. }
  241. else
  242. {
  243. if (mVerbose)
  244. {
  245. if (gmap.has("name"))
  246. {
  247. llwarns << "Incomplete grid definition for: "
  248. << gmap.get("name") << llendl;
  249. }
  250. else
  251. {
  252. llwarns << "Incomplete grid definition: no name specified"
  253. << llendl;
  254. }
  255. }
  256. }
  257. }
  258. }
  259. else if (mVerbose)
  260. {
  261. llwarns << "\"" << key_name << "\" is not an array" << llendl;
  262. }
  263. }
  264. llsd_xml.close();
  265. }
  266. }
  267. void LLGridManager::setMenuColor() const
  268. {
  269. if (mGridList["grids"][mGridChoice].has("menu_color"))
  270. {
  271. std::string colorName = mGridList["grids"][mGridChoice].get("menu_color").asString();
  272. LLColor4 color4;
  273. LLColor4::parseColor(colorName.c_str(), &color4);
  274. if (color4 != LLColor4::black)
  275. {
  276. gMenuBarViewp->setBackgroundColor(color4);
  277. }
  278. }
  279. }
  280. void LLGridManager::setGridChoice(EGridInfo grid)
  281. {
  282. if (grid < 0 || grid > GRID_INFO_OTHER)
  283. {
  284. llwarns << "Invalid grid index specified." << llendl;
  285. grid = DEFAULT_GRID_CHOICE;
  286. }
  287. mGridChoice = grid;
  288. std::string name = mGridList["grids"][grid].get("label").asString();
  289. LLStringUtil::toLower(name);
  290. if (name == "other")
  291. {
  292. // *FIX: Mani - could this possibly be valid?
  293. mGridName = "other";
  294. mGridHost = "other";
  295. setHelperURI("");
  296. setLoginPageURI("");
  297. }
  298. else
  299. {
  300. mGridName = mGridList["grids"][grid].get("label").asString();
  301. mGridHost = mGridList["grids"][grid].get("name").asString();
  302. setGridURI(mGridList["grids"][grid].get("login_uri").asString());
  303. setHelperURI(mGridList["grids"][grid].get("helper_uri").asString());
  304. setLoginPageURI(mGridList["grids"][grid].get("login_page").asString());
  305. mWebsiteURL = mGridList["grids"][grid].get("website_url").asString();
  306. mSupportURL = mGridList["grids"][grid].get("support_url").asString();
  307. mAccountURL = mGridList["grids"][grid].get("register_url").asString();
  308. mPasswordURL = mGridList["grids"][grid].get("password_url").asString();
  309. }
  310. gSavedSettings.setS32("ServerChoice", mGridChoice);
  311. gSavedSettings.setString("CustomServer", mGridName);
  312. }
  313. void LLGridManager::setGridChoice(const std::string& grid_name)
  314. {
  315. // Set the grid choice based on a string.
  316. // The string can be:
  317. // - a grid label from the gGridInfo table
  318. // - an ip address
  319. if (!grid_name.empty())
  320. {
  321. // Find the grid choice from the user setting.
  322. std::string pattern(grid_name);
  323. LLStringUtil::toLower(pattern);
  324. for (EGridInfo grid_index = GRID_INFO_NONE;
  325. grid_index < GRID_INFO_OTHER; ++grid_index)
  326. {
  327. std::string label = mGridList["grids"][grid_index].get("label").asString();
  328. std::string name = mGridList["grids"][grid_index].get("name").asString();
  329. LLStringUtil::toLower(label);
  330. LLStringUtil::toLower(name);
  331. if (label.find(pattern) == 0 || name.find(pattern) == 0)
  332. {
  333. // Found a matching label in the list...
  334. setGridChoice(grid_index);
  335. return;
  336. }
  337. }
  338. mGridChoice = GRID_INFO_OTHER;
  339. mGridName = grid_name;
  340. gSavedSettings.setS32("ServerChoice", mGridChoice);
  341. gSavedSettings.setString("CustomServer", mGridName);
  342. }
  343. }
  344. std::string LLGridManager::getGridLabel()
  345. {
  346. if (mGridChoice == GRID_INFO_NONE)
  347. {
  348. return "None";
  349. }
  350. if (mGridChoice < GRID_INFO_OTHER)
  351. {
  352. return mGridList["grids"][mGridChoice].get("label").asString();
  353. }
  354. if (!mGridName.empty())
  355. {
  356. return mGridName;
  357. }
  358. return LLURI(getGridURI()).hostName();
  359. }
  360. std::string LLGridManager::getKnownGridLabel(EGridInfo grid) const
  361. {
  362. if (grid > GRID_INFO_NONE && grid < GRID_INFO_OTHER)
  363. {
  364. return mGridList["grids"][grid].get("label").asString();
  365. }
  366. return mGridList["grids"][GRID_INFO_NONE].get("label").asString();
  367. }
  368. const std::vector<std::string>& LLGridManager::getCommandLineURIs()
  369. {
  370. return mCommandLineURIs;
  371. }
  372. void LLGridManager::parseCommandLineURIs()
  373. {
  374. // Return the login uri set on the command line.
  375. LLControlVariable* c = gSavedSettings.getControl("CmdLineLoginURI");
  376. if (c)
  377. {
  378. LLSD v = c->getValue();
  379. if (!v.isUndefined())
  380. {
  381. bool found_real_uri = false;
  382. if (v.isArray())
  383. {
  384. for (LLSD::array_const_iterator itr = v.beginArray();
  385. itr != v.endArray(); ++itr)
  386. {
  387. std::string uri = itr->asString();
  388. if (!uri.empty())
  389. {
  390. found_real_uri = true;
  391. mCommandLineURIs.emplace_back(uri);
  392. }
  393. }
  394. }
  395. else if (v.isString())
  396. {
  397. std::string uri = v.asString();
  398. if (!uri.empty())
  399. {
  400. found_real_uri = true;
  401. mCommandLineURIs.emplace_back(uri);
  402. }
  403. }
  404. if (found_real_uri)
  405. {
  406. mGridChoice = GRID_INFO_OTHER;
  407. mGridName = getGridLabel();
  408. }
  409. }
  410. }
  411. setLoginPageURI(gSavedSettings.getString("LoginPage"));
  412. setHelperURI(gSavedSettings.getString("CmdLineHelperURI"));
  413. }
  414. const std::string LLGridManager::getStaticGridHelperURI(const EGridInfo grid) const
  415. {
  416. std::string helper_uri;
  417. // grab URI from selected grid
  418. if (grid > GRID_INFO_NONE && grid < GRID_INFO_OTHER)
  419. {
  420. helper_uri = mGridList["grids"][grid].get("helper_uri").asString();
  421. }
  422. if (helper_uri.empty())
  423. {
  424. // What do we do with unnamed/miscellaneous grids ? For now, operations
  425. // that rely on the helper URI (currency/land purchasing) will fail.
  426. llwarns << "Missing Helper URI for this grid ! Currency/land purchasing operations will fail..."
  427. << llendl;
  428. }
  429. return helper_uri;
  430. }
  431. const std::string LLGridManager::getHelperURI() const
  432. {
  433. return mHelperURI;
  434. }
  435. void LLGridManager::setHelperURI(const std::string& uri)
  436. {
  437. mHelperURI = uri;
  438. }
  439. const std::string LLGridManager::getLoginPageURI() const
  440. {
  441. return mLoginPageURI;
  442. }
  443. void LLGridManager::setLoginPageURI(const std::string& uri)
  444. {
  445. mLoginPageURI = uri;
  446. }
  447. const std::string LLGridManager::getStaticGridURI(const EGridInfo grid) const
  448. {
  449. // If its a known grid choice, get the uri from the table,
  450. // else try the grid name.
  451. if (grid > GRID_INFO_NONE && grid < GRID_INFO_OTHER)
  452. {
  453. return mGridList["grids"][grid].get("login_uri").asString();
  454. }
  455. else
  456. {
  457. return std::string("");
  458. }
  459. }
  460. #if 0
  461. const std::string LLGridManager::getGridIP() const
  462. {
  463. std::string domain = getDomain(getGridURI());
  464. // Get the IP
  465. LLHost host;
  466. host.setHostByName(domain);
  467. return host.getIPString();
  468. }
  469. #endif
  470. void LLGridManager::setIsInSecondlife()
  471. {
  472. // NOTE: with the migration of SL servers to AWS, it becomes harder to
  473. // distinguish SL from OpenSim grids based on the sole IP (not working any
  474. // more) or login URI (since some rogue OpenSim grid could try and use
  475. // "lindenlab" or "secondlife" in their grid URI to fake SL).
  476. gIsInSecondLife = mGridURI.find(".lindenlab.com/") != std::string::npos ||
  477. mGridURI.find(".secondlife.com/") != std::string::npos ||
  478. mGridURI.find(".lindenlab.io/") != std::string::npos;
  479. // AFAIK, there is no universal way to detect an OpenSim beta grid...
  480. gIsInProductionGrid = !gIsInSecondLife ||
  481. mGridURI.find("aditi.") == std::string::npos;
  482. gIsInSecondLifeProductionGrid = gIsInSecondLife && gIsInProductionGrid;
  483. gIsInSecondLifeBetaGrid = gIsInSecondLife && !gIsInProductionGrid;
  484. if (gIsInSecondLifeBetaGrid)
  485. {
  486. llinfos << "Second Life beta grid assumed." << llendl;
  487. }
  488. else if (gIsInSecondLife)
  489. {
  490. llinfos << "Second Life grid assumed." << llendl;
  491. }
  492. else
  493. {
  494. llinfos << "OpenSim grid assumed." << llendl;
  495. }
  496. }
  497. std::string LLGridManager::getGridId(const std::string& name)
  498. {
  499. std::string domain;
  500. if (name.empty())
  501. {
  502. if (gIsInSecondLifeProductionGrid)
  503. {
  504. domain = "secondlife";
  505. return domain;
  506. }
  507. else if (gIsInSecondLife)
  508. {
  509. domain = "aditi";
  510. return domain;
  511. }
  512. else
  513. {
  514. domain = mGridHost;
  515. }
  516. }
  517. else
  518. {
  519. std::string grid = name;
  520. LLStringUtil::trim(grid);
  521. LLStringUtil::toLower(grid);
  522. if (grid == "secondlife" || grid.find("agni") == 0)
  523. {
  524. return "secondlife";
  525. }
  526. if (grid == "secondlife_beta" || grid.find("aditi") == 0)
  527. {
  528. return "aditi";
  529. }
  530. for (LLSD::map_iterator it = mGridList.beginMap();
  531. it != mGridList.endMap(); ++it)
  532. {
  533. LLSD::String key_name = it->first;
  534. LLSD grid_array = it->second;
  535. if (key_name == "grids" && grid_array.isArray())
  536. {
  537. std::string temp;
  538. for (size_t i = 0; i < grid_array.size(); ++i)
  539. {
  540. temp = grid_array[i]["name"].asString();
  541. LLStringUtil::toLower(temp);
  542. if (temp == grid)
  543. {
  544. domain = temp;
  545. }
  546. }
  547. }
  548. }
  549. }
  550. if (domain.empty())
  551. {
  552. return LLStringUtil::null;
  553. }
  554. // Remove trailing ".suffix" and any leading "prefix." from the domain name
  555. // Get rid of any leading "grid." or "world."
  556. size_t i = domain.find("grid.");
  557. if (i == 0)
  558. {
  559. domain = domain.substr(5);
  560. }
  561. i = domain.find("world.");
  562. if (i == 0)
  563. {
  564. domain = domain.substr(6);
  565. }
  566. // Get rid of trailing ".com", ".net", ".org", etc...
  567. i = domain.rfind('.');
  568. if (i > 0)
  569. {
  570. domain = domain.substr(0, i);
  571. }
  572. // Get rid of any trailing sub-domain
  573. i = domain.rfind('.');
  574. if (i > 0)
  575. {
  576. domain = domain.substr(0, i);
  577. }
  578. return domain;
  579. }
  580. std::string LLGridManager::getGridHost(std::string grid)
  581. {
  582. if (grid.empty())
  583. {
  584. if (gIsInSecondLifeProductionGrid)
  585. {
  586. return "secondlife";
  587. }
  588. else if (gIsInSecondLifeBetaGrid)
  589. {
  590. return "aditi";
  591. }
  592. else
  593. {
  594. return mGridHost;
  595. }
  596. }
  597. else
  598. {
  599. LLStringUtil::trim(grid);
  600. LLStringUtil::toLower(grid);
  601. if (grid == "secondlife" || grid.find("agni") == 0)
  602. {
  603. return "secondlife";
  604. }
  605. if (grid == "secondlife_beta" || grid.find("aditi") == 0)
  606. {
  607. return "aditi";
  608. }
  609. // When it is a domain name, get the corresponding grid Id
  610. if (grid.find('.') != std::string::npos)
  611. {
  612. grid = getGridId(grid);
  613. }
  614. std::string best_match;
  615. for (LLSD::map_iterator it = mGridList.beginMap();
  616. it != mGridList.endMap(); ++it)
  617. {
  618. LLSD::String key_name = it->first;
  619. LLSD grid_array = it->second;
  620. if (key_name == "grids" && grid_array.isArray())
  621. {
  622. std::string temp;
  623. for (size_t i = 0; i < grid_array.size(); ++i)
  624. {
  625. temp = grid_array[i]["name"].asString();
  626. LLStringUtil::toLower(temp);
  627. if (temp == grid)
  628. {
  629. return grid;
  630. }
  631. else if (temp.find(grid) != std::string::npos)
  632. {
  633. // Keep the shorter matching grid name
  634. size_t len = best_match.size();
  635. if (len == 0 || temp.size() < len)
  636. {
  637. best_match = temp;
  638. }
  639. }
  640. }
  641. }
  642. }
  643. if (best_match.find("agni") == 0)
  644. {
  645. return "secondlife";
  646. }
  647. if (best_match.find("aditi") == 0)
  648. {
  649. return "aditi";
  650. }
  651. return best_match;
  652. }
  653. }
  654. // Build a slurl for the given region within the selected grid
  655. std::string LLGridManager::getSLURLBase(const std::string& grid)
  656. {
  657. std::string grid_base;
  658. std::string name = grid;
  659. LLStringUtil::toLower(name);
  660. if (grid.empty() ||
  661. (gIsInSecondLifeProductionGrid &&
  662. (name == "secondlife" || name.find("agni") == 0)) ||
  663. (gIsInSecondLifeBetaGrid &&
  664. (name == "secondlife_beta" || name.find("aditi") == 0)))
  665. {
  666. if (gIsInSecondLifeProductionGrid)
  667. {
  668. grid_base = MAIN_GRID_SLURL_BASE;
  669. }
  670. else if (gIsInSecondLifeBetaGrid)
  671. {
  672. grid_base = llformat(SYSTEM_GRID_SLURL_BASE, "aditi");
  673. }
  674. else
  675. {
  676. grid_base = llformat(DEFAULT_SLURL_BASE, mGridHost.c_str());
  677. }
  678. }
  679. else
  680. {
  681. std::string host = getGridHost(grid);
  682. if (!host.empty())
  683. {
  684. grid_base = llformat(DEFAULT_SLURL_BASE, host.c_str());
  685. }
  686. }
  687. return grid_base;
  688. }
  689. // Build an app slurl for the given region within the selected grid
  690. std::string LLGridManager::getAppSLURLBase(const std::string& grid)
  691. {
  692. std::string grid_base;
  693. std::string name = grid;
  694. LLStringUtil::toLower(name);
  695. if (grid.empty() ||
  696. (gIsInSecondLifeProductionGrid &&
  697. (name == "secondlife" || name.find("agni") == 0)) ||
  698. (gIsInSecondLifeBetaGrid &&
  699. (name == "secondlife_beta" || name.find("aditi") == 0)))
  700. {
  701. if (gIsInSecondLife)
  702. {
  703. grid_base = SYSTEM_GRID_APP_SLURL_BASE;
  704. }
  705. else
  706. {
  707. grid_base = llformat(DEFAULT_APP_SLURL_BASE, mGridHost.c_str());
  708. }
  709. }
  710. else
  711. {
  712. std::string host = getGridHost(grid);
  713. if (!host.empty())
  714. {
  715. grid_base = llformat(DEFAULT_APP_SLURL_BASE, host.c_str());
  716. }
  717. }
  718. return grid_base;
  719. }
  720. //static
  721. std::string LLGridManager::getDomain(const std::string& url)
  722. {
  723. if (url.empty())
  724. {
  725. return url;
  726. }
  727. std::string domain = url;
  728. LLStringUtil::toLower(domain);
  729. size_t pos = domain.find("//");
  730. if (pos != std::string::npos)
  731. {
  732. size_t count = domain.size() - pos + 2;
  733. domain = domain.substr(pos + 2, count);
  734. }
  735. // Check that there is at least one slash in the URL and add a trailing
  736. // one if not
  737. if (domain.find('/') == std::string::npos)
  738. {
  739. domain += '/';
  740. }
  741. // Paranoia: If there is a user:password@ part, remove it
  742. pos = domain.find('@');
  743. if (pos != std::string::npos &&
  744. // if '@' is not before the first '/', then it is not a user:password
  745. pos < domain.find('/'))
  746. {
  747. size_t count = domain.size() - pos + 1;
  748. domain = domain.substr(pos + 1, count);
  749. }
  750. pos = domain.find(':');
  751. if (pos != std::string::npos && pos < domain.find('/'))
  752. {
  753. // Keep anything before the port number and strip the rest off
  754. domain = domain.substr(0, pos);
  755. }
  756. else
  757. {
  758. pos = domain.find('/'); // We earlier made sure that there is one
  759. domain = domain.substr(0, pos);
  760. }
  761. return domain;
  762. }
  763. //static
  764. std::string LLGridManager::getTimeStamp(time_t t_utc, const std::string& fmt,
  765. bool append_tz)
  766. {
  767. struct tm* timep;
  768. if (gIsInSecondLife)
  769. {
  770. // Convert to Pacific, based on server opinion of whether it is
  771. // daylight savings time there.
  772. timep = utc_to_pacific_time(t_utc, gPacificDaylightTime);
  773. }
  774. else // OpenSim grids do not always use US time zones... HB
  775. {
  776. timep = utc_time_to_tm(t_utc);
  777. }
  778. std::string timestamp;
  779. timeStructToFormattedString(timep, fmt, timestamp);
  780. if (append_tz)
  781. {
  782. timestamp += gIsInSecondLife ? (gPacificDaylightTime ? " PDT" : " PST")
  783. : " UTC";
  784. }
  785. return timestamp;
  786. }