void LLGridManager::addGrid(LLSD& grid_data) { if (grid_data.isMap() && grid_data.has(GRID_VALUE)) { std::string grid = utf8str_tolower(grid_data[GRID_VALUE]); // grid should be in the form of a dns address if (!grid.empty() && grid.find_first_not_of("abcdefghijklmnopqrstuvwxyz1234567890-_. ") != std::string::npos) { printf("grid name: %s", grid.c_str()); throw LLInvalidGridName(grid); } // populate the other values if they don't exist if (!grid_data.has(GRID_LABEL_VALUE)) { grid_data[GRID_LABEL_VALUE] = grid; } if (!grid_data.has(GRID_ID_VALUE)) { grid_data[GRID_ID_VALUE] = grid; } // if the grid data doesn't include any of the URIs, then // generate them from the grid, which should be a dns address if (!grid_data.has(GRID_LOGIN_URI_VALUE)) { grid_data[GRID_LOGIN_URI_VALUE] = LLSD::emptyArray(); grid_data[GRID_LOGIN_URI_VALUE].append(std::string("https://") + grid + "/cgi-bin/login.cgi"); } // Populate to the default values if (!grid_data.has(GRID_LOGIN_PAGE_VALUE)) { grid_data[GRID_LOGIN_PAGE_VALUE] = std::string("http://") + grid + "/app/login/"; } if (!grid_data.has(GRID_HELPER_URI_VALUE)) { grid_data[GRID_HELPER_URI_VALUE] = std::string("https://") + grid + "/helpers/"; } if (!grid_data.has(GRID_LOGIN_IDENTIFIER_TYPES)) { // non system grids and grids that haven't already been configured with values // get both types of credentials. grid_data[GRID_LOGIN_IDENTIFIER_TYPES] = LLSD::emptyArray(); grid_data[GRID_LOGIN_IDENTIFIER_TYPES].append(CRED_IDENTIFIER_TYPE_AGENT); grid_data[GRID_LOGIN_IDENTIFIER_TYPES].append(CRED_IDENTIFIER_TYPE_ACCOUNT); } LL_DEBUGS("GridManager") << "ADDING: " << grid << LL_ENDL; mGridList[grid] = grid_data; } }
// // LLGridManager::addGrid - add a grid to the grid list, populating the needed values // if they're not populated yet. // void LLGridManager::addGrid(GridEntry* grid_entry, AddState state) { if(!grid_entry) { llwarns << "addGrid called with NULL grid_entry. Please send a bug report." << llendl; state = FAIL; } if(!grid_entry->grid.has(GRID_VALUE)) { state = FAIL; } else if(grid_entry->grid[GRID_VALUE].asString().empty()) { state = FAIL; } else if(!grid_entry->grid.isMap()) { state = FAIL; } if ((FETCH == state) ||(FETCHTEMP == state) || (SYSTEM == state)) { std::string grid = utf8str_tolower(grid_entry->grid[GRID_VALUE]); // grid should be in the form of a dns address // but also support localhost:9000 or localhost:9000/login if ( !grid.empty() && grid.find_first_not_of("abcdefghijklmnopqrstuvwxyz1234567890-_.:/@% ") != std::string::npos) { printf("grid name: %s", grid.c_str()); if (grid_entry) { state = FAIL; delete grid_entry; grid_entry = NULL; } throw LLInvalidGridName(grid); } size_t find_last_slash = grid.find_last_of("/"); if ( (grid.length()-1) == find_last_slash ) { grid.erase(find_last_slash); grid_entry->grid[GRID_VALUE] = grid; } if (FETCHTEMP == state) { grid_entry->grid["FLAG_TEMPORARY"] = "TRUE"; state = FETCH; } } if ((FETCH == state) || (RETRY == state)) { std::string grid = utf8str_tolower(grid_entry->grid[GRID_VALUE]); std::string match = "://"; size_t find_scheme = grid.find(match); if ( std::string::npos != find_scheme) { // We only support http so just remove anything the user might have chosen grid.erase(0,find_scheme+match.length()); grid_entry->grid[GRID_VALUE] = grid; } std::string uri = "http://"+grid; if (std::string::npos != uri.find("lindenlab.com")) { state = SYSTEM; } else { if ( std::string::npos == uri.find(".") || std::string::npos != uri.find("127.0.0.1") || std::string::npos != uri.find("localhost") ) { state = LOCAL; } grid_entry->grid[GRID_LOGIN_URI_VALUE] = LLSD::emptyArray(); grid_entry->grid[GRID_LOGIN_URI_VALUE].append(uri); size_t find_last_slash = uri.find_last_of("/"); if ( (uri.length()-1) != find_last_slash ) { uri.append("/"); } uri.append("get_grid_info"); LL_DEBUGS("GridManager") << "get_grid_info uri: " << uri << LL_ENDL; time_t last_modified = 0; if(grid_entry->grid.has("LastModified")) { LLDate saved_value = grid_entry->grid["LastModified"]; last_modified = (time_t)saved_value.secondsSinceEpoch(); } LLHTTPClient::getIfModified(uri, new GridInfoRequestResponder(this, grid_entry, state), last_modified); return; } } if(TRYLEGACY == state) { std::string grid = utf8str_tolower(grid_entry->grid[GRID_VALUE]); std::string uri = "https://" + grid + "/cgi-bin/login.cgi"; llwarns << "No gridinfo found. Trying if legacy login page exists: " << uri << llendl; LLHTTPClient::get(uri, new GridInfoRequestResponder(this, grid_entry, state)); return; } if(FAIL != state) { std::string grid = utf8str_tolower(grid_entry->grid[GRID_VALUE]); // populate the other values if they don't exist if (!grid_entry->grid.has(GRID_LABEL_VALUE)) { grid_entry->grid[GRID_LABEL_VALUE] = grid; llwarns << "No \"gridname\" found in grid info, setting to " << grid_entry->grid[GRID_LABEL_VALUE].asString() << llendl; } if (!grid_entry->grid.has(GRID_NICK_VALUE)) { grid_entry->grid[GRID_NICK_VALUE] = grid; llwarns << "No \"gridnick\" found in grid info, setting to " << grid_entry->grid[GRID_NICK_VALUE].asString() << llendl; } } if (SYSTEM == state) { std::string grid = utf8str_tolower(grid_entry->grid[GRID_VALUE]); // if the grid data doesn't include any of the URIs, then // generate them from the grid if (!grid_entry->grid.has(GRID_LOGIN_URI_VALUE)) { grid_entry->grid[GRID_LOGIN_URI_VALUE] = LLSD::emptyArray(); grid_entry->grid[GRID_LOGIN_URI_VALUE].append(std::string("https://") + grid + "/cgi-bin/login.cgi"); llwarns << "Adding Legacy Login Service at:" << grid_entry->grid[GRID_LOGIN_URI_VALUE].asString() << llendl; } // Populate to the default values if (!grid_entry->grid.has(GRID_LOGIN_PAGE_VALUE)) { grid_entry->grid[GRID_LOGIN_PAGE_VALUE] = std::string("http://") + grid + "/app/login/"; llwarns << "Adding Legacy Login Screen at:" << grid_entry->grid[GRID_LOGIN_PAGE_VALUE].asString() << llendl; } if (!grid_entry->grid.has(GRID_HELPER_URI_VALUE)) { llwarns << "Adding Legacy Economy at:" << grid_entry->grid[GRID_HELPER_URI_VALUE].asString() << llendl; grid_entry->grid[GRID_HELPER_URI_VALUE] = std::string("https://") + grid + "/helpers/"; } } if(FAIL != state) { std::string grid = utf8str_tolower(grid_entry->grid[GRID_VALUE]); if (!grid_entry->grid.has(GRID_LOGIN_IDENTIFIER_TYPES)) { // non system grids and grids that haven't already been configured with values // get both types of credentials. grid_entry->grid[GRID_LOGIN_IDENTIFIER_TYPES] = LLSD::emptyArray(); grid_entry->grid[GRID_LOGIN_IDENTIFIER_TYPES].append(CRED_IDENTIFIER_TYPE_AGENT); grid_entry->grid[GRID_LOGIN_IDENTIFIER_TYPES].append(CRED_IDENTIFIER_TYPE_ACCOUNT); } bool is_current = grid_entry->set_current; grid_entry->set_current = false; if(!grid.empty())// { if (!mGridList.has(grid)) //new grid { //finally add the grid \o/ mGridList[grid] = grid_entry->grid; ++mGridEntries; LL_DEBUGS("GridManager") << "Adding new entry: " << grid << LL_ENDL; } else { LLSD existing_grid = mGridList[grid]; if (!existing_grid.has("LastModified")) { //lack of "LastModified" means existing_grid is from fallback list, // assume its anyway older and override with the new entry mGridList[grid] = grid_entry->grid; //number of mGridEntries doesn't change LL_DEBUGS("GridManager") << "Using custom entry: " << grid << LL_ENDL; } else if (grid_entry->grid.has("LastModified")) { // (time_t)saved_value.secondsSinceEpoch(); LLDate testing_newer = grid_entry->grid["LastModified"]; LLDate existing = existing_grid["LastModified"]; LL_DEBUGS("GridManager") << "testing_newer " << testing_newer << " existing " << existing << LL_ENDL; if(testing_newer.secondsSinceEpoch() > existing.secondsSinceEpoch()) { //existing_grid is older, override. mGridList[grid] = grid_entry->grid; //number of mGridEntries doesn't change LL_DEBUGS("GridManager") << "Updating entry: " << grid << LL_ENDL; } } else { LL_DEBUGS("GridManager") << "Same or newer entry already present: " << grid << LL_ENDL; } } if(is_current) { mGrid = grid; LL_DEBUGS("GridManager") << "Selected grid is " << mGrid << LL_ENDL; setGridChoice(mGrid); } } } // This is only of use if we want to fetch infos of entire gridlists at startup /* if(grid_entry && FINISH == state || FAIL == state) { if((FINISH == state && !mCommandLineDone && 0 == mResponderCount) ||(FAIL == state && grid_entry->set_current) ) { LL_DEBUGS("GridManager") << "init CmdLineGrids" << LL_ENDL; initCmdLineGrids(); } } */ if (grid_entry) { if(!grid_entry->mOnDoneCallback.empty()) { grid_entry->mOnDoneCallback(); } delete grid_entry; grid_entry = NULL; } }