diff options
author | Merov Linden <merov@lindenlab.com> | 2014-06-17 15:12:31 -0700 |
---|---|---|
committer | Merov Linden <merov@lindenlab.com> | 2014-06-17 15:12:31 -0700 |
commit | e3e1a527ccbab17e140f91267c847d7e799dbe6f (patch) | |
tree | 2e093acb5b77fe45e7bff78e598d2d7adc26d2b9 /indra/newview/lltwitterconnect.cpp | |
parent | c4c8debfc230b4ec6d28c7a84cd2a9bb81d6c894 (diff) |
DRTVWR-354 : Rewrite Responders for Twitter and Flickr to conform to new LLHTTPClient interface. Fix merge error in Facebook connect as well
Diffstat (limited to 'indra/newview/lltwitterconnect.cpp')
-rw-r--r-- | indra/newview/lltwitterconnect.cpp | 185 |
1 files changed, 107 insertions, 78 deletions
diff --git a/indra/newview/lltwitterconnect.cpp b/indra/newview/lltwitterconnect.cpp index cfdbca1b81..7088558b83 100644 --- a/indra/newview/lltwitterconnect.cpp +++ b/indra/newview/lltwitterconnect.cpp @@ -77,28 +77,36 @@ public: LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_CONNECTION_IN_PROGRESS); } - virtual void completed(U32 status, const std::string& reason, const LLSD& content) + /* virtual */ void httpSuccess() { - if (isGoodStatus(status)) + LL_DEBUGS("TwitterConnect") << "Connect successful. " << dumpResponse() << LL_ENDL; + LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_CONNECTED); + } + + /* virtual */ void httpFailure() + { + if ( HTTP_FOUND == getStatus() ) { - LL_DEBUGS("TwitterConnect") << "Connect successful. content: " << content << LL_ENDL; - - LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_CONNECTED); + const std::string& location = getResponseHeader(HTTP_IN_HEADER_LOCATION); + if (location.empty()) + { + LL_WARNS("TwitterConnect") << "Missing Location header " << dumpResponse() + << "[headers:" << getResponseHeaders() << "]" << LL_ENDL; + } + else + { + LLTwitterConnect::instance().openTwitterWeb(location); + } } - else if (status != 302) + else { - LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_CONNECTION_FAILED); - log_twitter_connect_error("Connect", status, reason, content.get("error_code"), content.get("error_description")); + LL_WARNS("TwitterConnect") << dumpResponse() << LL_ENDL; + LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_CONNECTION_FAILED); + const LLSD& content = getContent(); + log_twitter_connect_error("Connect", getStatus(), getReason(), + content.get("error_code"), content.get("error_description")); } } - - void completedHeader(U32 status, const std::string& reason, const LLSD& content) - { - if (status == 302) - { - LLTwitterConnect::instance().openTwitterWeb(content["location"]); - } - } }; /////////////////////////////////////////////////////////////////////////////// @@ -113,33 +121,41 @@ public: LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_POSTING); } - virtual void completed(U32 status, const std::string& reason, const LLSD& content) + /* virtual */ void httpSuccess() { - if (isGoodStatus(status)) + toast_user_for_twitter_success(); + LL_DEBUGS("TwitterConnect") << "Post successful. " << dumpResponse() << LL_ENDL; + LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_POSTED); + } + + /* virtual */ void httpFailure() + { + if ( HTTP_FOUND == getStatus() ) { - toast_user_for_twitter_success(); - LL_DEBUGS("TwitterConnect") << "Post successful. content: " << content << LL_ENDL; - - LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_POSTED); + const std::string& location = getResponseHeader(HTTP_IN_HEADER_LOCATION); + if (location.empty()) + { + LL_WARNS("TwitterConnect") << "Missing Location header " << dumpResponse() + << "[headers:" << getResponseHeaders() << "]" << LL_ENDL; + } + else + { + LLTwitterConnect::instance().openTwitterWeb(location); + } } - else if (status == 404) + else if ( HTTP_NOT_FOUND == getStatus() ) { LLTwitterConnect::instance().connectToTwitter(); } else { + LL_WARNS("TwitterConnect") << dumpResponse() << LL_ENDL; LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_POST_FAILED); - log_twitter_connect_error("Share", status, reason, content.get("error_code"), content.get("error_description")); + const LLSD& content = getContent(); + log_twitter_connect_error("Share", getStatus(), getReason(), + content.get("error_code"), content.get("error_description")); } } - - void completedHeader(U32 status, const std::string& reason, const LLSD& content) - { - if (status == 302) - { - LLTwitterConnect::instance().openTwitterWeb(content["location"]); - } - } }; /////////////////////////////////////////////////////////////////////////////// @@ -163,24 +179,27 @@ public: LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_NOT_CONNECTED); } - virtual void completed(U32 status, const std::string& reason, const LLSD& content) + /* virtual */ void httpSuccess() + { + LL_DEBUGS("TwitterConnect") << "Disconnect successful. " << dumpResponse() << LL_ENDL; + setUserDisconnected(); + } + + /* virtual */ void httpFailure() { - if (isGoodStatus(status)) - { - LL_DEBUGS("TwitterConnect") << "Disconnect successful. content: " << content << LL_ENDL; - setUserDisconnected(); - - } //User not found so already disconnected - else if(status == 404) + if ( HTTP_NOT_FOUND == getStatus() ) { - LL_DEBUGS("TwitterConnect") << "Already disconnected. content: " << content << LL_ENDL; + LL_DEBUGS("TwitterConnect") << "Already disconnected. " << dumpResponse() << LL_ENDL; setUserDisconnected(); } else { + LL_WARNS("TwitterConnect") << dumpResponse() << LL_ENDL; LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_DISCONNECT_FAILED); - log_twitter_connect_error("Disconnect", status, reason, content.get("error_code"), content.get("error_description")); + const LLSD& content = getContent(); + log_twitter_connect_error("Disconnect", getStatus(), getReason(), + content.get("error_code"), content.get("error_description")); } } }; @@ -197,33 +216,34 @@ public: LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_CONNECTION_IN_PROGRESS); } - virtual void completed(U32 status, const std::string& reason, const LLSD& content) + /* virtual */ void httpSuccess() + { + LL_DEBUGS("TwitterConnect") << "Connect successful. " << dumpResponse() << LL_ENDL; + LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_CONNECTED); + } + + /* virtual */ void httpFailure() { - if (isGoodStatus(status)) + // show the facebook login page if not connected yet + if ( HTTP_NOT_FOUND == getStatus() ) { - LL_DEBUGS("TwitterConnect") << "Connect successful. content: " << content << LL_ENDL; - - LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_CONNECTED); + LL_DEBUGS("TwitterConnect") << "Not connected. " << dumpResponse() << LL_ENDL; + if (mAutoConnect) + { + LLTwitterConnect::instance().connectToTwitter(); + } + else + { + LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_NOT_CONNECTED); + } } else { - // show the twitter login page if not connected yet - if (status == 404) - { - if (mAutoConnect) - { - LLTwitterConnect::instance().connectToTwitter(); - } - else - { - LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_NOT_CONNECTED); - } - } - else - { - LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_CONNECTION_FAILED); - log_twitter_connect_error("Connected", status, reason, content.get("error_code"), content.get("error_description")); - } + LL_WARNS("TwitterConnect") << dumpResponse() << LL_ENDL; + LLTwitterConnect::instance().setConnectionState(LLTwitterConnect::TWITTER_CONNECTION_FAILED); + const LLSD& content = getContent(); + log_twitter_connect_error("Connected", getStatus(), getReason(), + content.get("error_code"), content.get("error_description")); } } @@ -238,25 +258,34 @@ class LLTwitterInfoResponder : public LLHTTPClient::Responder LOG_CLASS(LLTwitterInfoResponder); public: - virtual void completed(U32 status, const std::string& reason, const LLSD& info) + /* virtual */ void httpSuccess() + { + LL_INFOS("TwitterConnect") << "Twitter: Info received" << LL_ENDL; + LL_DEBUGS("TwitterConnect") << "Getting Twitter info successful. " << dumpResponse() << LL_ENDL; + LLTwitterConnect::instance().storeInfo(getContent()); + } + + /* virtual */ void httpFailure() { - if (isGoodStatus(status)) + if ( HTTP_FOUND == getStatus() ) { - llinfos << "Twitter: Info received" << llendl; - LL_DEBUGS("TwitterConnect") << "Getting Twitter info successful. info: " << info << LL_ENDL; - LLTwitterConnect::instance().storeInfo(info); + const std::string& location = getResponseHeader(HTTP_IN_HEADER_LOCATION); + if (location.empty()) + { + LL_WARNS("TwitterConnect") << "Missing Location header " << dumpResponse() + << "[headers:" << getResponseHeaders() << "]" << LL_ENDL; + } + else + { + LLTwitterConnect::instance().openTwitterWeb(location); + } } else { - log_twitter_connect_error("Info", status, reason, info.get("error_code"), info.get("error_description")); - } - } - - void completedHeader(U32 status, const std::string& reason, const LLSD& content) - { - if (status == 302) - { - LLTwitterConnect::instance().openTwitterWeb(content["location"]); + LL_WARNS("TwitterConnect") << dumpResponse() << LL_ENDL; + const LLSD& content = getContent(); + log_twitter_connect_error("Info", getStatus(), getReason(), + content.get("error_code"), content.get("error_description")); } } }; |