From c16e726d0e2a8c607ce441eb5bf2419b16b41cab Mon Sep 17 00:00:00 2001
From: callum_linden <none@none>
Date: Tue, 20 Oct 2015 14:44:36 -0700
Subject: MAINT-5711 FIX2 auto login for profiles - final part retrieves the
 URL to set cookie for from the message sent over by login.cgi

---
 indra/llmessage/llcurl.cpp      |  5 +++++
 indra/llmessage/llcurl.h        |  1 +
 indra/newview/llviewermedia.cpp | 43 +++++++++++++++++++++++------------------
 indra/newview/llviewermedia.h   |  4 ++--
 4 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/indra/llmessage/llcurl.cpp b/indra/llmessage/llcurl.cpp
index 73df47b933..7e9ae8d108 100755
--- a/indra/llmessage/llcurl.cpp
+++ b/indra/llmessage/llcurl.cpp
@@ -178,6 +178,11 @@ void LLCurl::Responder::setURL(const std::string& url)
 	mURL = url;
 }
 
+const std::string& LLCurl::Responder::getURL()
+{
+	return mURL;
+}
+
 void LLCurl::Responder::successResult(const LLSD& content)
 {
 	setResult(HTTP_OK, "", content);
diff --git a/indra/llmessage/llcurl.h b/indra/llmessage/llcurl.h
index 385d9fffa8..14d4a14deb 100755
--- a/indra/llmessage/llcurl.h
+++ b/indra/llmessage/llcurl.h
@@ -147,6 +147,7 @@ public:
 	public:
 		void setHTTPMethod(EHTTPMethod method);
 		void setURL(const std::string& url);
+		const std::string& Responder::getURL();
 		void setResult(S32 status, const std::string& reason, const LLSD& content = LLSD());
 		void setResponseHeader(const std::string& header, const std::string& value);
 
diff --git a/indra/newview/llviewermedia.cpp b/indra/newview/llviewermedia.cpp
index 3342fddade..1098b2a7e1 100755
--- a/indra/newview/llviewermedia.cpp
+++ b/indra/newview/llviewermedia.cpp
@@ -285,13 +285,16 @@ public:
 		const LLChannelDescriptors& channels,
 		const LLIOPipe::buffer_ptr_t& buffer)
 	{
+		const std::string url = getURL();
+		llinfos << "@@@ URL to set cookie on" << url << llendl;
+
 		// We don't care about the content of the response, only the Set-Cookie header.
-		LL_DEBUGS("MediaAuth") << dumpResponse() 
-				<< " [headers:" << getResponseHeaders() << "]" << LL_ENDL;
+		llinfos << dumpResponse() 
+				<< " [headers:" << getResponseHeaders() << "]" << llendl;
 		const std::string& cookie = getResponseHeader(HTTP_IN_HEADER_SET_COOKIE);
 		
 		// *TODO: What about bad status codes?  Does this destroy previous cookies?
-		LLViewerMedia::openIDCookieResponse(cookie);
+		LLViewerMedia::openIDCookieResponse(url, cookie);
 	}
 
 };
@@ -1200,7 +1203,7 @@ void LLViewerMedia::clearAllCookies()
 	}
 	
 	// If we have an OpenID cookie, re-add it to the cookie store.
-	setOpenIDCookie();
+	setOpenIDCookie(std::string());
 }
 	
 /////////////////////////////////////////////////////////////////////////////////////////
@@ -1303,7 +1306,7 @@ void LLViewerMedia::loadCookieFile()
 	}
 	
 	// If we have an OpenID cookie, re-add it to the cookie store.
-	setOpenIDCookie();
+	setOpenIDCookie(std::string());
 }
 
 
@@ -1413,7 +1416,7 @@ bool LLViewerMedia::parseRawCookie(const std::string raw_cookie, std::string& na
 
 /////////////////////////////////////////////////////////////////////////////////////////
 // static
-void LLViewerMedia::setOpenIDCookie()
+void LLViewerMedia::setOpenIDCookie(const std::string& url)
 {
 	if(!sOpenIDCookie.empty())
 	{
@@ -1442,19 +1445,21 @@ void LLViewerMedia::setOpenIDCookie()
 		
 		getCookieStore()->setCookiesFromHost(sOpenIDCookie, authority.substr(host_start, host_end - host_start));
 
-		LLMediaCtrl* media_instance = LLFloaterReg::getInstance("destinations")->getChild<LLMediaCtrl>("destination_guide_contents");
-		if (media_instance)
-		{
-			std::string cookie_host = authority.substr(host_start, host_end - host_start);
-			std::string cookie_name = "";
-			std::string cookie_value = "";
-			std::string cookie_path = "";
-			if (parseRawCookie(sOpenIDCookie, cookie_name, cookie_value, cookie_path))
+		if (url.length())
+		{
+			LLMediaCtrl* media_instance = LLFloaterReg::getInstance("destinations")->getChild<LLMediaCtrl>("destination_guide_contents");
+			if (media_instance)
 			{
-				std::string url = "http://id.secondlife.com/openid/webkit";
-				media_instance->getMediaPlugin()->setCookie(url, cookie_name, cookie_value, cookie_host, cookie_path);
+				std::string cookie_host = authority.substr(host_start, host_end - host_start);
+				std::string cookie_name = "";
+				std::string cookie_value = "";
+				std::string cookie_path = "";
+				if (parseRawCookie(sOpenIDCookie, cookie_name, cookie_value, cookie_path))
+				{
+					media_instance->getMediaPlugin()->setCookie(url, cookie_name, cookie_value, cookie_host, cookie_path);
+				}
 			}
-		};
+		}
 
 		// NOTE: this is the original OpenID cookie code, so of which is no longer needed now that we
 		// are using CEF - it's very intertwined with other code so, for the moment, I'm going to 
@@ -1514,13 +1519,13 @@ void LLViewerMedia::openIDSetup(const std::string &openid_url, const std::string
 
 /////////////////////////////////////////////////////////////////////////////////////////
 // static
-void LLViewerMedia::openIDCookieResponse(const std::string &cookie)
+void LLViewerMedia::openIDCookieResponse(const std::string& url, const std::string &cookie)
 {
 	LL_DEBUGS("MediaAuth") << "Cookie received: \"" << cookie << "\"" << LL_ENDL;
 	
 	sOpenIDCookie += cookie;
 
-	setOpenIDCookie();
+	setOpenIDCookie(url);
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////
diff --git a/indra/newview/llviewermedia.h b/indra/newview/llviewermedia.h
index 0101c85e79..45d211f232 100755
--- a/indra/newview/llviewermedia.h
+++ b/indra/newview/llviewermedia.h
@@ -150,7 +150,7 @@ public:
 	static void removeCookie(const std::string &name, const std::string &domain, const std::string &path = std::string("/") );
 
 	static void openIDSetup(const std::string &openid_url, const std::string &openid_token);
-	static void openIDCookieResponse(const std::string &cookie);
+	static void openIDCookieResponse(const std::string& url, const std::string &cookie);
 	
 	static void proxyWindowOpened(const std::string &target, const std::string &uuid);
 	static void proxyWindowClosed(const std::string &uuid);
@@ -164,7 +164,7 @@ public:
 	
 private:
 	static bool parseRawCookie(const std::string raw_cookie, std::string& name, std::string& value, std::string& path);
-	static void setOpenIDCookie();
+	static void setOpenIDCookie(const std::string& url);
 	static void onTeleportFinished();
 	
 	static LLPluginCookieStore *sCookieStore;
-- 
cgit v1.2.3