PageRenderTime 113ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llviewernetwork.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 642 lines | 471 code | 65 blank | 106 comment | 56 complexity | 38d109fceb0845566376ff975a67f25f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewernetwork.cpp
  3. * @author James Cook, Richard Nelson
  4. * @brief Networking constants and globals for viewer.
  5. *
  6. * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "llviewerprecompiledheaders.h"
  28. #include "llviewernetwork.h"
  29. #include "llviewercontrol.h"
  30. #include "llsdserialize.h"
  31. #include "llsecapi.h"
  32. #include "lltrans.h"
  33. #include "llweb.h"
  34. const char* DEFAULT_LOGIN_PAGE = "http://viewer-login.agni.lindenlab.com/";
  35. const char* SYSTEM_GRID_SLURL_BASE = "secondlife://%s/secondlife/";
  36. const char* MAIN_GRID_SLURL_BASE = "http://maps.secondlife.com/secondlife/";
  37. const char* SYSTEM_GRID_APP_SLURL_BASE = "secondlife:///app";
  38. const char* DEFAULT_SLURL_BASE = "https://%s/region/";
  39. const char* DEFAULT_APP_SLURL_BASE = "x-grid-location-info://%s/app";
  40. LLGridManager::LLGridManager()
  41. : mIsInProductionGrid(false)
  42. {
  43. // by default, we use the 'grids.xml' file in the user settings directory
  44. // this file is an LLSD file containing multiple grid definitions.
  45. // This file does not contain definitions for secondlife.com grids,
  46. // as that would be a security issue when they are overwritten by
  47. // an attacker. Don't want someone snagging a password.
  48. std::string grid_file = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS,
  49. "grids.xml");
  50. initialize(grid_file);
  51. }
  52. LLGridManager::LLGridManager(const std::string& grid_file)
  53. {
  54. // initialize with an explicity grid file for testing.
  55. initialize(grid_file);
  56. }
  57. //
  58. // LLGridManager - class for managing the list of known grids, and the current
  59. // selection
  60. //
  61. //
  62. // LLGridManager::initialze - initialize the list of known grids based
  63. // on the fixed list of linden grids (fixed for security reasons)
  64. // the grids.xml file
  65. // and the command line.
  66. void LLGridManager::initialize(const std::string& grid_file)
  67. {
  68. // default grid list.
  69. // Don't move to a modifiable file for security reasons,
  70. mGrid.clear() ;
  71. // set to undefined
  72. mGridList = LLSD();
  73. mGridFile = grid_file;
  74. // as we don't want an attacker to override our grid list
  75. // to point the default grid to an invalid grid
  76. addSystemGrid("None", "", "", "", DEFAULT_LOGIN_PAGE);
  77. addSystemGrid("Agni",
  78. MAINGRID,
  79. "https://login.agni.lindenlab.com/cgi-bin/login.cgi",
  80. "https://secondlife.com/helpers/",
  81. DEFAULT_LOGIN_PAGE);
  82. addSystemGrid("Aditi",
  83. "util.aditi.lindenlab.com",
  84. "https://login.aditi.lindenlab.com/cgi-bin/login.cgi",
  85. "http://aditi-secondlife.webdev.lindenlab.com/helpers/",
  86. DEFAULT_LOGIN_PAGE);
  87. addSystemGrid("Aruna",
  88. "util.aruna.lindenlab.com",
  89. "https://login.aruna.lindenlab.com/cgi-bin/login.cgi",
  90. "http://aruna-secondlife.webdev.lindenlab.com/helpers/",
  91. DEFAULT_LOGIN_PAGE);
  92. addSystemGrid("Bharati",
  93. "util.bharati.lindenlab.com",
  94. "https://login.bharati.lindenlab.com/cgi-bin/login.cgi",
  95. "http://bharati-secondlife.webdev.lindenlab.com/helpers/",
  96. DEFAULT_LOGIN_PAGE);
  97. addSystemGrid("Chandra",
  98. "util.chandra.lindenlab.com",
  99. "https://login.chandra.lindenlab.com/cgi-bin/login.cgi",
  100. "http://chandra-secondlife.webdev.lindenlab.com/helpers/",
  101. DEFAULT_LOGIN_PAGE);
  102. addSystemGrid("Damballah",
  103. "util.damballah.lindenlab.com",
  104. "https://login.damballah.lindenlab.com/cgi-bin/login.cgi",
  105. "http://damballah-secondlife.webdev.lindenlab.com/helpers/",
  106. DEFAULT_LOGIN_PAGE);
  107. addSystemGrid("Danu",
  108. "util.danu.lindenlab.com",
  109. "https://login.danu.lindenlab.com/cgi-bin/login.cgi",
  110. "http://danu-secondlife.webdev.lindenlab.com/helpers/",
  111. DEFAULT_LOGIN_PAGE);
  112. addSystemGrid("Durga",
  113. "util.durga.lindenlab.com",
  114. "https://login.durga.lindenlab.com/cgi-bin/login.cgi",
  115. "http://durga-secondlife.webdev.lindenlab.com/helpers/",
  116. DEFAULT_LOGIN_PAGE);
  117. addSystemGrid("Ganga",
  118. "util.ganga.lindenlab.com",
  119. "https://login.ganga.lindenlab.com/cgi-bin/login.cgi",
  120. "http://ganga-secondlife.webdev.lindenlab.com/helpers/",
  121. DEFAULT_LOGIN_PAGE);
  122. addSystemGrid("Mitra",
  123. "util.mitra.lindenlab.com",
  124. "https://login.mitra.lindenlab.com/cgi-bin/login.cgi",
  125. "http://mitra-secondlife.webdev.lindenlab.com/helpers/",
  126. DEFAULT_LOGIN_PAGE);
  127. addSystemGrid("Mohini",
  128. "util.mohini.lindenlab.com",
  129. "https://login.mohini.lindenlab.com/cgi-bin/login.cgi",
  130. "http://mohini-secondlife.webdev.lindenlab.com/helpers/",
  131. DEFAULT_LOGIN_PAGE);
  132. addSystemGrid("Nandi",
  133. "util.nandi.lindenlab.com",
  134. "https://login.nandi.lindenlab.com/cgi-bin/login.cgi",
  135. "http://nandi-secondlife.webdev.lindenlab.com/helpers/",
  136. DEFAULT_LOGIN_PAGE);
  137. addSystemGrid("Parvati",
  138. "util.parvati.lindenlab.com",
  139. "https://login.parvati.lindenlab.com/cgi-bin/login.cgi",
  140. "http://parvati-secondlife.webdev.lindenlab.com/helpers/",
  141. DEFAULT_LOGIN_PAGE);
  142. addSystemGrid("Radha",
  143. "util.radha.lindenlab.com",
  144. "https://login.radha.lindenlab.com/cgi-bin/login.cgi",
  145. "http://radha-secondlife.webdev.lindenlab.com/helpers/",
  146. DEFAULT_LOGIN_PAGE);
  147. addSystemGrid("Ravi",
  148. "util.ravi.lindenlab.com",
  149. "https://login.ravi.lindenlab.com/cgi-bin/login.cgi",
  150. "http://ravi-secondlife.webdev.lindenlab.com/helpers/",
  151. DEFAULT_LOGIN_PAGE);
  152. addSystemGrid("Siva",
  153. "util.siva.lindenlab.com",
  154. "https://login.siva.lindenlab.com/cgi-bin/login.cgi",
  155. "http://siva-secondlife.webdev.lindenlab.com/helpers/",
  156. DEFAULT_LOGIN_PAGE);
  157. addSystemGrid("Shakti",
  158. "util.shakti.lindenlab.com",
  159. "https://login.shakti.lindenlab.com/cgi-bin/login.cgi",
  160. "http://shakti-secondlife.webdev.lindenlab.com/helpers/",
  161. DEFAULT_LOGIN_PAGE);
  162. addSystemGrid("Soma",
  163. "util.soma.lindenlab.com",
  164. "https://login.soma.lindenlab.com/cgi-bin/login.cgi",
  165. "http://soma-secondlife.webdev.lindenlab.com/helpers/",
  166. DEFAULT_LOGIN_PAGE);
  167. addSystemGrid("Uma",
  168. "util.uma.lindenlab.com",
  169. "https://login.uma.lindenlab.com/cgi-bin/login.cgi",
  170. "http://uma-secondlife.webdev.lindenlab.com/helpers/",
  171. DEFAULT_LOGIN_PAGE);
  172. addSystemGrid("Vaak",
  173. "util.vaak.lindenlab.com",
  174. "https://login.vaak.lindenlab.com/cgi-bin/login.cgi",
  175. "http://vaak-secondlife.webdev.lindenlab.com/helpers/",
  176. DEFAULT_LOGIN_PAGE);
  177. addSystemGrid("Yami",
  178. "util.yami.lindenlab.com",
  179. "https://login.yami.lindenlab.com/cgi-bin/login.cgi",
  180. "http://yami-secondlife.webdev.lindenlab.com/helpers/",
  181. DEFAULT_LOGIN_PAGE);
  182. addSystemGrid("Local (Linden)",
  183. "localhost",
  184. "https://login.dmz.lindenlab.com/cgi-bin/login.cgi",
  185. "",
  186. DEFAULT_LOGIN_PAGE);
  187. LLSD other_grids;
  188. llifstream llsd_xml;
  189. if (!grid_file.empty())
  190. {
  191. llsd_xml.open( grid_file.c_str(), std::ios::in | std::ios::binary );
  192. // parse through the gridfile, inserting grids into the list unless
  193. // they overwrite a linden grid.
  194. if( llsd_xml.is_open())
  195. {
  196. LLSDSerialize::fromXMLDocument( other_grids, llsd_xml );
  197. if(other_grids.isMap())
  198. {
  199. for(LLSD::map_iterator grid_itr = other_grids.beginMap();
  200. grid_itr != other_grids.endMap();
  201. ++grid_itr)
  202. {
  203. LLSD::String key_name = grid_itr->first;
  204. LLSD grid = grid_itr->second;
  205. // TODO: Make sure gridfile specified label is not
  206. // a system grid label
  207. LL_DEBUGS("GridManager") << "reading: " << key_name << LL_ENDL;
  208. if (mGridList.has(key_name) &&
  209. mGridList[key_name].has(GRID_IS_SYSTEM_GRID_VALUE))
  210. {
  211. LL_DEBUGS("GridManager") << "Cannot override grid " << key_name << " as it's a system grid" << LL_ENDL;
  212. // If the system grid does exist in the grids file, and it's marked as a favorite, set it as a favorite.
  213. if(grid_itr->second.has(GRID_IS_FAVORITE_VALUE) && grid_itr->second[GRID_IS_FAVORITE_VALUE].asBoolean() )
  214. {
  215. mGridList[key_name][GRID_IS_FAVORITE_VALUE] = TRUE;
  216. }
  217. }
  218. else
  219. {
  220. try
  221. {
  222. addGrid(grid);
  223. LL_DEBUGS("GridManager") << "Added grid: " << key_name << LL_ENDL;
  224. }
  225. catch (...)
  226. {
  227. }
  228. }
  229. }
  230. llsd_xml.close();
  231. }
  232. }
  233. }
  234. // load a grid from the command line.
  235. // if the actual grid name is specified from the command line,
  236. // set it as the 'selected' grid.
  237. std::string cmd_line_grid = gSavedSettings.getString("CmdLineGridChoice");
  238. if(!cmd_line_grid.empty())
  239. {
  240. // try to find the grid assuming the command line parameter is
  241. // the case-insensitive 'label' of the grid. ie 'Agni'
  242. mGrid = getGridByLabel(cmd_line_grid);
  243. if(mGrid.empty())
  244. {
  245. // if we couldn't find it, assume the
  246. // requested grid is the actual grid 'name' or index,
  247. // which would be the dns name of the grid (for non
  248. // linden hosted grids)
  249. // If the grid isn't there, that's ok, as it will be
  250. // automatically added later.
  251. mGrid = cmd_line_grid;
  252. }
  253. }
  254. else
  255. {
  256. // if a grid was not passed in via the command line, grab it from the CurrentGrid setting.
  257. // if there's no current grid, that's ok as it'll be either set by the value passed
  258. // in via the login uri if that's specified, or will default to maingrid
  259. mGrid = gSavedSettings.getString("CurrentGrid");
  260. }
  261. if(mGrid.empty())
  262. {
  263. // no grid was specified so default to maingrid
  264. LL_DEBUGS("GridManager") << "Setting grid to MAINGRID as no grid has been specified " << LL_ENDL;
  265. mGrid = MAINGRID;
  266. }
  267. // generate a 'grid list' entry for any command line parameter overrides
  268. // or setting overides that we'll add to the grid list or override
  269. // any grid list entries with.
  270. LLSD grid = LLSD::emptyMap();
  271. if(mGridList.has(mGrid))
  272. {
  273. grid = mGridList[mGrid];
  274. }
  275. else
  276. {
  277. grid[GRID_VALUE] = mGrid;
  278. // add the grid with the additional values, or update the
  279. // existing grid if it exists with the given values
  280. addGrid(grid);
  281. }
  282. LLControlVariablePtr grid_control = gSavedSettings.getControl("CurrentGrid");
  283. if (grid_control.notNull())
  284. {
  285. grid_control->getSignal()->connect(boost::bind(&LLGridManager::updateIsInProductionGrid, this));
  286. }
  287. // since above only triggers on changes, trigger the callback manually to initialize state
  288. updateIsInProductionGrid();
  289. LL_DEBUGS("GridManager") << "Selected grid is " << mGrid << LL_ENDL;
  290. setGridChoice(mGrid);
  291. if(mGridList[mGrid][GRID_LOGIN_URI_VALUE].isArray())
  292. {
  293. llinfos << "is array" << llendl;
  294. }
  295. }
  296. LLGridManager::~LLGridManager()
  297. {
  298. saveFavorites();
  299. }
  300. void LLGridManager::getGridInfo(const std::string &grid, LLSD& grid_info)
  301. {
  302. grid_info = mGridList[grid];
  303. // override any grid data with the command line info.
  304. LLSD cmd_line_login_uri = gSavedSettings.getLLSD("CmdLineLoginURI");
  305. if (cmd_line_login_uri.isString())
  306. {
  307. grid_info[GRID_LOGIN_URI_VALUE] = LLSD::emptyArray();
  308. grid_info[GRID_LOGIN_URI_VALUE].append(cmd_line_login_uri);
  309. }
  310. // override the helper uri if it was passed in
  311. std::string cmd_line_helper_uri = gSavedSettings.getString("CmdLineHelperURI");
  312. if(!cmd_line_helper_uri.empty())
  313. {
  314. grid_info[GRID_HELPER_URI_VALUE] = cmd_line_helper_uri;
  315. }
  316. // override the login page if it was passed in
  317. std::string cmd_line_login_page = gSavedSettings.getString("LoginPage");
  318. if(!cmd_line_login_page.empty())
  319. {
  320. grid_info[GRID_LOGIN_PAGE_VALUE] = cmd_line_login_page;
  321. }
  322. }
  323. //
  324. // LLGridManager::addGrid - add a grid to the grid list, populating the needed values
  325. // if they're not populated yet.
  326. //
  327. void LLGridManager::addGrid(LLSD& grid_data)
  328. {
  329. if (grid_data.isMap() && grid_data.has(GRID_VALUE))
  330. {
  331. std::string grid = utf8str_tolower(grid_data[GRID_VALUE]);
  332. // grid should be in the form of a dns address
  333. if (!grid.empty() &&
  334. grid.find_first_not_of("abcdefghijklmnopqrstuvwxyz1234567890-_. ") != std::string::npos)
  335. {
  336. printf("grid name: %s", grid.c_str());
  337. throw LLInvalidGridName(grid);
  338. }
  339. // populate the other values if they don't exist
  340. if (!grid_data.has(GRID_LABEL_VALUE))
  341. {
  342. grid_data[GRID_LABEL_VALUE] = grid;
  343. }
  344. if (!grid_data.has(GRID_ID_VALUE))
  345. {
  346. grid_data[GRID_ID_VALUE] = grid;
  347. }
  348. // if the grid data doesn't include any of the URIs, then
  349. // generate them from the grid, which should be a dns address
  350. if (!grid_data.has(GRID_LOGIN_URI_VALUE))
  351. {
  352. grid_data[GRID_LOGIN_URI_VALUE] = LLSD::emptyArray();
  353. grid_data[GRID_LOGIN_URI_VALUE].append(std::string("https://") +
  354. grid + "/cgi-bin/login.cgi");
  355. }
  356. // Populate to the default values
  357. if (!grid_data.has(GRID_LOGIN_PAGE_VALUE))
  358. {
  359. grid_data[GRID_LOGIN_PAGE_VALUE] = std::string("http://") + grid + "/app/login/";
  360. }
  361. if (!grid_data.has(GRID_HELPER_URI_VALUE))
  362. {
  363. grid_data[GRID_HELPER_URI_VALUE] = std::string("https://") + grid + "/helpers/";
  364. }
  365. if (!grid_data.has(GRID_LOGIN_IDENTIFIER_TYPES))
  366. {
  367. // non system grids and grids that haven't already been configured with values
  368. // get both types of credentials.
  369. grid_data[GRID_LOGIN_IDENTIFIER_TYPES] = LLSD::emptyArray();
  370. grid_data[GRID_LOGIN_IDENTIFIER_TYPES].append(CRED_IDENTIFIER_TYPE_AGENT);
  371. grid_data[GRID_LOGIN_IDENTIFIER_TYPES].append(CRED_IDENTIFIER_TYPE_ACCOUNT);
  372. }
  373. LL_DEBUGS("GridManager") << "ADDING: " << grid << LL_ENDL;
  374. mGridList[grid] = grid_data;
  375. }
  376. }
  377. //
  378. // LLGridManager::addSystemGrid - helper for adding a system grid.
  379. void LLGridManager::addSystemGrid(const std::string& label,
  380. const std::string& name,
  381. const std::string& login,
  382. const std::string& helper,
  383. const std::string& login_page,
  384. const std::string& login_id)
  385. {
  386. LLSD grid = LLSD::emptyMap();
  387. grid[GRID_VALUE] = name;
  388. grid[GRID_LABEL_VALUE] = label;
  389. grid[GRID_HELPER_URI_VALUE] = helper;
  390. grid[GRID_LOGIN_URI_VALUE] = LLSD::emptyArray();
  391. grid[GRID_LOGIN_URI_VALUE].append(login);
  392. grid[GRID_LOGIN_PAGE_VALUE] = login_page;
  393. grid[GRID_IS_SYSTEM_GRID_VALUE] = TRUE;
  394. grid[GRID_LOGIN_IDENTIFIER_TYPES] = LLSD::emptyArray();
  395. grid[GRID_LOGIN_IDENTIFIER_TYPES].append(CRED_IDENTIFIER_TYPE_AGENT);
  396. grid[GRID_APP_SLURL_BASE] = SYSTEM_GRID_APP_SLURL_BASE;
  397. if (login_id.empty())
  398. {
  399. grid[GRID_ID_VALUE] = name;
  400. }
  401. else
  402. {
  403. grid[GRID_ID_VALUE] = login_id;
  404. }
  405. // only add the system grids beyond agni to the visible list
  406. // if we're building a debug version.
  407. if (name == std::string(MAINGRID))
  408. {
  409. grid[GRID_SLURL_BASE] = MAIN_GRID_SLURL_BASE;
  410. grid[GRID_IS_FAVORITE_VALUE] = TRUE;
  411. }
  412. else
  413. {
  414. grid[GRID_SLURL_BASE] = llformat(SYSTEM_GRID_SLURL_BASE, label.c_str());
  415. }
  416. addGrid(grid);
  417. }
  418. // return a list of grid name -> grid label mappings for UI purposes
  419. std::map<std::string, std::string> LLGridManager::getKnownGrids(bool favorite_only)
  420. {
  421. std::map<std::string, std::string> result;
  422. for(LLSD::map_iterator grid_iter = mGridList.beginMap();
  423. grid_iter != mGridList.endMap();
  424. grid_iter++)
  425. {
  426. if(!favorite_only || grid_iter->second.has(GRID_IS_FAVORITE_VALUE))
  427. {
  428. result[grid_iter->first] = grid_iter->second[GRID_LABEL_VALUE].asString();
  429. }
  430. }
  431. return result;
  432. }
  433. void LLGridManager::setGridChoice(const std::string& grid)
  434. {
  435. // Set the grid choice based on a string.
  436. // The string can be:
  437. // - a grid label from the gGridInfo table
  438. // - a hostname
  439. // - an ip address
  440. // loop through. We could do just a hash lookup but we also want to match
  441. // on label
  442. std::string grid_name = grid;
  443. if(!mGridList.has(grid_name))
  444. {
  445. // case insensitive
  446. grid_name = getGridByLabel(grid);
  447. }
  448. if(grid_name.empty())
  449. {
  450. // the grid was not in the list of grids.
  451. LLSD grid_data = LLSD::emptyMap();
  452. grid_data[GRID_VALUE] = grid;
  453. addGrid(grid_data);
  454. }
  455. mGrid = grid;
  456. gSavedSettings.setString("CurrentGrid", grid);
  457. updateIsInProductionGrid();
  458. }
  459. std::string LLGridManager::getGridByLabel( const std::string &grid_label, bool case_sensitive)
  460. {
  461. for(LLSD::map_iterator grid_iter = mGridList.beginMap();
  462. grid_iter != mGridList.endMap();
  463. grid_iter++)
  464. {
  465. if (grid_iter->second.has(GRID_LABEL_VALUE))
  466. {
  467. if (0 == (case_sensitive?LLStringUtil::compareStrings(grid_label, grid_iter->second[GRID_LABEL_VALUE].asString()):
  468. LLStringUtil::compareInsensitive(grid_label, grid_iter->second[GRID_LABEL_VALUE].asString())))
  469. {
  470. return grid_iter->first;
  471. }
  472. }
  473. }
  474. return std::string();
  475. }
  476. void LLGridManager::getLoginURIs(std::vector<std::string>& uris)
  477. {
  478. uris.clear();
  479. LLSD cmd_line_login_uri = gSavedSettings.getLLSD("CmdLineLoginURI");
  480. if (cmd_line_login_uri.isString())
  481. {
  482. uris.push_back(cmd_line_login_uri);
  483. return;
  484. }
  485. for (LLSD::array_iterator llsd_uri = mGridList[mGrid][GRID_LOGIN_URI_VALUE].beginArray();
  486. llsd_uri != mGridList[mGrid][GRID_LOGIN_URI_VALUE].endArray();
  487. llsd_uri++)
  488. {
  489. uris.push_back(llsd_uri->asString());
  490. }
  491. }
  492. std::string LLGridManager::getHelperURI()
  493. {
  494. std::string cmd_line_helper_uri = gSavedSettings.getString("CmdLineHelperURI");
  495. if(!cmd_line_helper_uri.empty())
  496. {
  497. return cmd_line_helper_uri;
  498. }
  499. return mGridList[mGrid][GRID_HELPER_URI_VALUE];
  500. }
  501. std::string LLGridManager::getLoginPage()
  502. {
  503. // override the login page if it was passed in
  504. std::string cmd_line_login_page = gSavedSettings.getString("LoginPage");
  505. if(!cmd_line_login_page.empty())
  506. {
  507. return cmd_line_login_page;
  508. }
  509. return mGridList[mGrid][GRID_LOGIN_PAGE_VALUE];
  510. }
  511. void LLGridManager::updateIsInProductionGrid()
  512. {
  513. mIsInProductionGrid = false;
  514. // *NOTE:Mani This used to compare GRID_INFO_AGNI to gGridChoice,
  515. // but it seems that loginURI trumps that.
  516. std::vector<std::string> uris;
  517. getLoginURIs(uris);
  518. if (uris.empty())
  519. {
  520. mIsInProductionGrid = true;
  521. return;
  522. }
  523. LLStringUtil::toLower(uris[0]);
  524. if((uris[0].find("agni") != std::string::npos))
  525. {
  526. mIsInProductionGrid = true;
  527. return;
  528. }
  529. }
  530. bool LLGridManager::isInProductionGrid()
  531. {
  532. return mIsInProductionGrid;
  533. }
  534. void LLGridManager::saveFavorites()
  535. {
  536. // filter out just those marked as favorites
  537. LLSD output_grid_list = LLSD::emptyMap();
  538. for(LLSD::map_iterator grid_iter = mGridList.beginMap();
  539. grid_iter != mGridList.endMap();
  540. grid_iter++)
  541. {
  542. if(grid_iter->second.has(GRID_IS_FAVORITE_VALUE))
  543. {
  544. output_grid_list[grid_iter->first] = grid_iter->second;
  545. }
  546. }
  547. llofstream llsd_xml;
  548. llsd_xml.open( mGridFile.c_str(), std::ios::out | std::ios::binary);
  549. LLSDSerialize::toPrettyXML(output_grid_list, llsd_xml);
  550. llsd_xml.close();
  551. }
  552. // build a slurl for the given region within the selected grid
  553. std::string LLGridManager::getSLURLBase(const std::string& grid)
  554. {
  555. std::string grid_base;
  556. if(mGridList.has(grid) && mGridList[grid].has(GRID_SLURL_BASE))
  557. {
  558. return mGridList[grid][GRID_SLURL_BASE].asString();
  559. }
  560. else
  561. {
  562. return llformat(DEFAULT_SLURL_BASE, grid.c_str());
  563. }
  564. }
  565. // build a slurl for the given region within the selected grid
  566. std::string LLGridManager::getAppSLURLBase(const std::string& grid)
  567. {
  568. std::string grid_base;
  569. if(mGridList.has(grid) && mGridList[grid].has(GRID_APP_SLURL_BASE))
  570. {
  571. return mGridList[grid][GRID_APP_SLURL_BASE].asString();
  572. }
  573. else
  574. {
  575. return llformat(DEFAULT_APP_SLURL_BASE, grid.c_str());
  576. }
  577. }