From 1f101ee2a3494565275deac8ab63a1a4c6512eb0 Mon Sep 17 00:00:00 2001
From: Roxie Linden <roxie@lindenlab.com>
Date: Thu, 27 May 2010 11:52:39 -0700
Subject: EXT-7388 - --grid command-line argument does nothing QAR-3119 --grid
 command-line argument does nothing

Made --grid specifier case insensitive.
Fixed some issues with specifying non-well-known-grids
Fixed some issues with specifying --loginuri, --loginpage and --helperuri
---
 indra/newview/llviewernetwork.cpp | 177 ++++++++++++++++++++------------------
 1 file changed, 93 insertions(+), 84 deletions(-)

(limited to 'indra/newview/llviewernetwork.cpp')

diff --git a/indra/newview/llviewernetwork.cpp b/indra/newview/llviewernetwork.cpp
index c76eee80f7..619deaf50b 100644
--- a/indra/newview/llviewernetwork.cpp
+++ b/indra/newview/llviewernetwork.cpp
@@ -226,11 +226,11 @@ void LLGridManager::initialize(const std::string& grid_file)
 					LLSD grid = grid_itr->second;
 					// TODO:  Make sure gridfile specified label is not 
 					// a system grid label
-					LL_INFOS("GridManager") << "reading: " << key_name << LL_ENDL;
+					LL_DEBUGS("GridManager") << "reading: " << key_name << LL_ENDL;
 					if (mGridList.has(key_name) &&
 						mGridList[key_name].has(GRID_IS_SYSTEM_GRID_VALUE))
 					{
-						LL_INFOS("GridManager") << "Cannot override grid " << key_name << " as it's a system grid" << LL_ENDL;
+						LL_DEBUGS("GridManager") << "Cannot override grid " << key_name << " as it's a system grid" << LL_ENDL;
 						// If the system grid does exist in the grids file, and it's marked as a favorite, set it as a favorite.
 						if(grid_itr->second.has(GRID_IS_FAVORITE_VALUE) && grid_itr->second[GRID_IS_FAVORITE_VALUE].asBoolean() )
 						{
@@ -242,7 +242,7 @@ void LLGridManager::initialize(const std::string& grid_file)
 						try
 						{
 							addGrid(grid);
-							LL_INFOS("GridManager") << "Added grid: " << key_name << LL_ENDL;
+							LL_DEBUGS("GridManager") << "Added grid: " << key_name << LL_ENDL;
 						}
 						catch (...)
 						{
@@ -260,84 +260,90 @@ void LLGridManager::initialize(const std::string& grid_file)
 	std::string cmd_line_grid = gSavedSettings.getString("CmdLineGridChoice");
 	if(!cmd_line_grid.empty())
 	{
+		// try to find the grid assuming the command line parameter is
+		// the case-insensitive 'label' of the grid.  ie 'Agni'
 		mGrid = getGridByLabel(cmd_line_grid);
+		if(mGrid.empty())
+		{
+			// if we couldn't find it, assume the
+			// requested grid is the actual grid 'name' or index,
+			// which would be the dns name of the grid (for non
+			// linden hosted grids)
+			// If the grid isn't there, that's ok, as it will be
+			// automatically added later.
+			mGrid = cmd_line_grid;
+		}
+		
+	}
+	else
+	{
+		// if a grid was not passed in via the command line, grab it from the CurrentGrid setting.
+		// if there's no current grid, that's ok as it'll be either set by the value passed
+		// in via the login uri if that's specified, or will default to maingrid
+		mGrid = gSavedSettings.getString("CurrentGrid");
+	}
+	
+	if(mGrid.empty())
+	{
+		// no grid was specified so default to maingrid
+		LL_DEBUGS("GridManager") << "Setting grid to MAINGRID as no grid has been specified " << LL_ENDL;
+		mGrid = MAINGRID;
+		
+	}
+	
+	// generate a 'grid list' entry for any command line parameter overrides
+	// or setting overides that we'll add to the grid list or override
+	// any grid list entries with.
+	LLSD grid = LLSD::emptyMap();	
+	
+	bool grid_dirty = false;
+	if(mGridList.has(mGrid))
+	{
+		grid = mGridList[mGrid];
+	}
+	else
+	{
+		grid[GRID_VALUE] = mGrid;
+		grid_dirty = true;
 	}
-	LL_INFOS("GridManager") << "Grid Name: " << mGrid << LL_ENDL;		
 	
-	// If a command line login URI was passed in, so we should add the command
-	// line grid to the list of grids
-
 	LLSD cmd_line_login_uri = gSavedSettings.getLLSD("CmdLineLoginURI");
 	if (cmd_line_login_uri.isString())
 	{
-		LL_INFOS("GridManager") << "adding cmd line login uri" << LL_ENDL;
-		// grab the other related URI values
-		std::string cmd_line_helper_uri = gSavedSettings.getString("CmdLineHelperURI");
-		std::string cmd_line_login_page = gSavedSettings.getString("LoginPage");
-		
-		// we've a cmd line login, so add a grid for the command line,
-		// overwriting any existing grids
-		LLSD grid = LLSD::emptyMap();
+		grid_dirty = true;				
 		grid[GRID_LOGIN_URI_VALUE] = LLSD::emptyArray();
 		grid[GRID_LOGIN_URI_VALUE].append(cmd_line_login_uri);
-		LL_INFOS("GridManager") << "cmd line login uri: " << cmd_line_login_uri.asString() << LL_ENDL;
-		LLURI uri(cmd_line_login_uri.asString());
-		if (mGrid.empty())
-		{
-			// if a grid name was not passed in via the command line,
-			// then set the grid name based on the hostname of the 
-			// login uri
-			mGrid = uri.hostName();
-		}
-
-		grid[GRID_VALUE] = mGrid;
-
-		if (mGridList.has(mGrid) && mGridList[mGrid].has(GRID_LABEL_VALUE))
-		{
-			grid[GRID_LABEL_VALUE] = mGridList[mGrid][GRID_LABEL_VALUE];
-		}
-		else
-		{
-			grid[GRID_LABEL_VALUE] = mGrid;			
-		}
-		if(!cmd_line_helper_uri.empty())
-		{
-			grid[GRID_HELPER_URI_VALUE] = cmd_line_helper_uri;
-		}
-
-		if(!cmd_line_login_page.empty())
-		{
-			grid[GRID_LOGIN_PAGE_VALUE] = cmd_line_login_page;
-		}
-		// if the login page, helper URI value, and so on are not specified,
-		// add grid will generate them.
-
-		// Also, we will override a system grid if values are passed in via the command
-		// line, for testing.  These values will not be remembered though.
-		if (mGridList.has(mGrid) && mGridList[mGrid].has(GRID_IS_SYSTEM_GRID_VALUE))
-		{
-			grid[GRID_IS_SYSTEM_GRID_VALUE] = TRUE;
-		}
-		addGrid(grid);
 	}
 	
-	// if a grid was not passed in via the command line, grab it from the CurrentGrid setting.
-	if (mGrid.empty())
+	// override the helper uri if it was passed in
+	std::string cmd_line_helper_uri = gSavedSettings.getString("CmdLineHelperURI");
+	if(!cmd_line_helper_uri.empty())
 	{
-
-		mGrid = gSavedSettings.getString("CurrentGrid");
+		grid[GRID_HELPER_URI_VALUE] = cmd_line_helper_uri;
+		grid_dirty = true;		
 	}
-
-	if (mGrid.empty() || !mGridList.has(mGrid))
+	
+	// override the login page if it was passed in
+	std::string cmd_line_login_page = gSavedSettings.getString("LoginPage");
+	if(!cmd_line_login_page.empty())
 	{
-		// the grid name was empty, or the grid isn't actually in the list, then set it to the
-		// appropriate default.
-		LL_INFOS("GridManager") << "Resetting grid as grid name " << mGrid << " is not in the list" << LL_ENDL;
-		mGrid = MAINGRID;
+		grid[GRID_LOGIN_PAGE_VALUE] = cmd_line_login_page;
+		grid_dirty = true;		
 	}
-	LL_INFOS("GridManager") << "Selected grid is " << mGrid << LL_ENDL;		
-	gSavedSettings.setString("CurrentGrid", mGrid);
+	
 
+	if(grid_dirty)
+	{
+		// add the grid with the additional values, or update the
+		// existing grid if it exists with the given values
+		addGrid(grid);
+	}
+	LL_DEBUGS("GridManager") << "Selected grid is " << mGrid << LL_ENDL;		
+	setGridChoice(mGrid);
+	if(mGridList[mGrid][GRID_LOGIN_URI_VALUE].isArray())
+	{
+		llinfos << "is array" << llendl;
+	}
 }
 
 LLGridManager::~LLGridManager()
@@ -401,7 +407,7 @@ void LLGridManager::addGrid(LLSD& grid_data)
 			grid_data[GRID_LOGIN_IDENTIFIER_TYPES].append(CRED_IDENTIFIER_TYPE_ACCOUNT);
 		}
 		
-		LL_INFOS("GridManager") << "ADDING: " << grid << LL_ENDL;
+		LL_DEBUGS("GridManager") << "ADDING: " << grid << LL_ENDL;
 		mGridList[grid] = grid_data;		
 	}
 }
@@ -467,6 +473,7 @@ std::map<std::string, std::string> LLGridManager::getKnownGrids(bool favorite_on
 	return result;
 }
 
+
 void LLGridManager::setGridChoice(const std::string& grid)
 {
 	// Set the grid choice based on a string.
@@ -477,35 +484,37 @@ void LLGridManager::setGridChoice(const std::string& grid)
 
 	// loop through.  We could do just a hash lookup but we also want to match
 	// on label
-	for(LLSD::map_iterator grid_iter = mGridList.beginMap();
-		grid_iter != mGridList.endMap();
-		grid_iter++) 
+	std::string grid_name = grid;
+	if(!mGridList.has(grid_name))
 	{
-		if((grid == grid_iter->first) || 
-		   (grid == grid_iter->second[GRID_LABEL_VALUE].asString()))
-		{
-			mGrid = grid_iter->second[GRID_VALUE].asString();
-			gSavedSettings.setString("CurrentGrid", grid_iter->second[GRID_VALUE]);			
-			return; 
-
-		}
+		// case insensitive
+		grid_name = getGridByLabel(grid);
+	}
+	
+	if(grid_name.empty())
+	{
+		// the grid was not in the list of grids.
+		LLSD grid_data = LLSD::emptyMap();
+		grid_data[GRID_VALUE] = grid;
+		addGrid(grid_data);		
 	}
-	LLSD grid_data = LLSD::emptyMap();
-	grid_data[GRID_VALUE] = grid;
-	addGrid(grid_data);
 	mGrid = grid;
 	gSavedSettings.setString("CurrentGrid", grid);
 }
 
-std::string LLGridManager::getGridByLabel( const std::string &grid_label)
+std::string LLGridManager::getGridByLabel( const std::string &grid_label, bool case_sensitive)
 {
 	for(LLSD::map_iterator grid_iter = mGridList.beginMap();
 		grid_iter != mGridList.endMap();
 		grid_iter++) 
 	{
-		if (grid_iter->second.has(GRID_LABEL_VALUE) && (grid_iter->second[GRID_LABEL_VALUE].asString() == grid_label))
+		if (grid_iter->second.has(GRID_LABEL_VALUE))
 		{
-			return grid_iter->first;
+			if (0 == (case_sensitive?LLStringUtil::compareStrings(grid_label, grid_iter->second[GRID_LABEL_VALUE].asString()):
+				LLStringUtil::compareInsensitive(grid_label, grid_iter->second[GRID_LABEL_VALUE].asString())))
+			{
+				return grid_iter->first;
+			}
 		}
 	}
 	return std::string();
-- 
cgit v1.2.3