From f15d28a636da7b6d2784d9301e7a030b5bd38a8c Mon Sep 17 00:00:00 2001
From: Logan Dethrow <log@lindenlab.com>
Date: Thu, 28 Jul 2011 13:47:20 -0400
Subject: [PATCH] Proxy cleanup in llstartup.cpp and llproxy.cpp.

---
 indra/llmessage/llcurl.h                      |  2 +
 indra/llmessage/llproxy.cpp                   | 45 ++---------
 indra/newview/llstartup.cpp                   | 79 +++++++++++--------
 .../skins/default/xui/en/notifications.xml    | 11 +++
 4 files changed, 62 insertions(+), 75 deletions(-)

diff --git a/indra/llmessage/llcurl.h b/indra/llmessage/llcurl.h
index 79f5eeb9278..d60d3b6f401 100644
--- a/indra/llmessage/llcurl.h
+++ b/indra/llmessage/llcurl.h
@@ -355,6 +355,8 @@ class LLCurlEasyRequest
 	bool getResult(CURLcode* result, LLCurl::TransferInfo* info = NULL);
 	std::string getErrorString();
 
+	LLCurl::Easy* getEasy() const { return mEasy; }
+
 private:
 	CURLMsg* info_read(S32* queue, LLCurl::TransferInfo* info);
 	
diff --git a/indra/llmessage/llproxy.cpp b/indra/llmessage/llproxy.cpp
index d34ad1a8116..e1970f13685 100644
--- a/indra/llmessage/llproxy.cpp
+++ b/indra/llmessage/llproxy.cpp
@@ -278,50 +278,15 @@ void LLProxy::cleanupClass()
 }
 
 // Apply proxy settings to CuRL request if either type of HTTP proxy is enabled.
-void LLProxy::applyProxySettings(LLCurl::Easy* handle)
+void LLProxy::applyProxySettings(LLCurlEasyRequest* handle)
 {
-	if (sHTTPProxyEnabled)
-	{
-		std::string address = mHTTPProxy.getIPString();
-		U16 port = mHTTPProxy.getPort();
-		handle->setoptString(CURLOPT_PROXY, address.c_str());
-		handle->setopt(CURLOPT_PROXYPORT, port);
-		if (mProxyType == LLPROXY_SOCKS)
-		{
-			handle->setopt(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
-			if (mAuthMethodSelected == METHOD_PASSWORD)
-			{
-				handle->setoptString(CURLOPT_PROXYUSERPWD, getProxyUserPwdCURL());
-			}
-		}
-		else
-		{
-			handle->setopt(CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
-		}
-	}
+	applyProxySettings(handle->getEasy());
 }
 
-void LLProxy::applyProxySettings(LLCurlEasyRequest* handle)
+
+void LLProxy::applyProxySettings(LLCurl::Easy* handle)
 {
-	if (sHTTPProxyEnabled)
-	{
-		std::string address = mHTTPProxy.getIPString();
-		U16 port = mHTTPProxy.getPort();
-		handle->setoptString(CURLOPT_PROXY, address.c_str());
-		handle->setopt(CURLOPT_PROXYPORT, port);
-		if (mProxyType == LLPROXY_SOCKS)
-		{
-			handle->setopt(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
-			if (mAuthMethodSelected == METHOD_PASSWORD)
-			{
-				handle->setoptString(CURLOPT_PROXYUSERPWD, getProxyUserPwdCURL());
-			}
-		}
-		else
-		{
-			handle->setopt(CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
-		}
-	}
+	applyProxySettings(handle->getCurlHandle());
 }
 
 void LLProxy::applyProxySettings(CURL* handle)
diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp
index 1fe241a8cef..eca3e5439ed 100644
--- a/indra/newview/llstartup.cpp
+++ b/indra/newview/llstartup.cpp
@@ -2793,8 +2793,8 @@ bool LLStartUp::handleSocksProxy()
 		LLProxy::getInstance()->disableHTTPProxy();
 	}
 	
-	bool use_socks_proxy = gSavedSettings.getBOOL("Socks5ProxyEnabled");
-	if (use_socks_proxy)
+	// Set up SOCKS proxy (if needed)
+	if (gSavedSettings.getBOOL("Socks5ProxyEnabled"))
 	{	
 
 		// Determine and update LLProxy with the saved authentication system
@@ -2826,45 +2826,54 @@ bool LLStartUp::handleSocksProxy()
 		// Start the proxy and check for errors
 		// If status != SOCKS_OK, stopProxy() will already have been called when startProxy() returns.
 		int status = LLProxy::getInstance()->startProxy(gSavedSettings.getString("Socks5ProxyHost"), gSavedSettings.getU32("Socks5ProxyPort"));
-		LLSD subs;
-		subs["HOST"] = gSavedSettings.getString("Socks5ProxyHost");
-		subs["PORT"] = (S32)gSavedSettings.getU32("Socks5ProxyPort");
 
-		std::string error_string;
-
-		switch(status)
+		if (status == SOCKS_OK)
 		{
-			case SOCKS_OK:
-				return true;
-				break;
-
-			case SOCKS_CONNECT_ERROR: // TCP Fail
-				error_string = "SOCKS_CONNECT_ERROR";
-				break;
-
-			case SOCKS_NOT_PERMITTED: // SOCKS 5 server rule set refused connection
-				error_string = "SOCKS_NOT_PERMITTED";
-				break;
-					
-			case SOCKS_NOT_ACCEPTABLE: // Selected authentication is not acceptable to server
-				error_string = "SOCKS_NOT_ACCEPTABLE";
-				break;
+			return true;
+		}
+		else
+		{
+			LLSD subs;
+			subs["HOST"] = gSavedSettings.getString("Socks5ProxyHost");
+			subs["PORT"] = (S32)gSavedSettings.getU32("Socks5ProxyPort");
 
-			case SOCKS_AUTH_FAIL: // Authentication failed
-				error_string = "SOCKS_AUTH_FAIL";
-				break;
+			std::string error_string;
 
-			case SOCKS_UDP_FWD_NOT_GRANTED: // UDP forward request failed
-				error_string = "SOCKS_UDP_FWD_NOT_GRANTED";
-				break;
+			switch(status)
+			{
+				case SOCKS_CONNECT_ERROR: // TCP Fail
+					error_string = "SOCKS_CONNECT_ERROR";
+					break;
+
+				case SOCKS_NOT_PERMITTED: // SOCKS 5 server rule set refused connection
+					error_string = "SOCKS_NOT_PERMITTED";
+					break;
+
+				case SOCKS_NOT_ACCEPTABLE: // Selected authentication is not acceptable to server
+					error_string = "SOCKS_NOT_ACCEPTABLE";
+					break;
+
+				case SOCKS_AUTH_FAIL: // Authentication failed
+					error_string = "SOCKS_AUTH_FAIL";
+					break;
+
+				case SOCKS_UDP_FWD_NOT_GRANTED: // UDP forward request failed
+					error_string = "SOCKS_UDP_FWD_NOT_GRANTED";
+					break;
+
+				case SOCKS_HOST_CONNECT_FAILED: // Failed to open a TCP channel to the socks server
+					error_string = "SOCKS_HOST_CONNECT_FAILED";
+					break;
+
+				default:
+					error_string = "SOCKS_UNKNOWN_STATUS"; // Something strange happened,
+					LL_WARNS("Proxy") << "Unknown return from LLProxy::startProxy(): " << status << LL_ENDL;
+					break;
+			}
 
-			case SOCKS_HOST_CONNECT_FAILED: // Failed to open a TCP channel to the socks server
-				error_string = "SOCKS_HOST_CONNECT_FAILED";
-				break;
+			LLNotificationsUtil::add(error_string, subs);
+			return false;
 		}
-
-		LLNotificationsUtil::add(error_string, subs);
-		return false;
 	}
 	else
 	{
diff --git a/indra/newview/skins/default/xui/en/notifications.xml b/indra/newview/skins/default/xui/en/notifications.xml
index 78685dbd794..8b7e6d8c4e8 100644
--- a/indra/newview/skins/default/xui/en/notifications.xml
+++ b/indra/newview/skins/default/xui/en/notifications.xml
@@ -7207,6 +7207,17 @@ Click and drag anywhere on the world to rotate your view
      name="okbutton"
      yestext="OK"/>
   </notification>
+  
+  <notification
+   icon="alertmodal.tga"
+   name="SOCKS_UNKNOWN_STATUS"
+   type="alertmodal">
+	Unknown SOCKS error with server "[HOST]:[PORT]"
+	<tag>fail</tag>
+   <usetemplate
+     name="okbutton"
+     yestext="OK"/>
+  </notification>
 
   <notification
    icon="alertmodal.tga"
-- 
GitLab