summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorRider Linden <none@none>2015-04-20 11:57:51 -0700
committerRider Linden <none@none>2015-04-20 11:57:51 -0700
commit27258d370be634630299a59ab9bea51e55b37bbb (patch)
tree953e13de3982f53fe80cc665ee804024df48d9b4 /indra
parent75a6ed716cfe0b5c1ea15c53026999474d55b550 (diff)
Flickr conversion.
Diffstat (limited to 'indra')
-rw-r--r--indra/llmessage/llcorehttputil.h15
-rwxr-xr-xindra/newview/llfacebookconnect.cpp15
-rw-r--r--indra/newview/llflickrconnect.cpp573
-rw-r--r--indra/newview/llflickrconnect.h11
4 files changed, 332 insertions, 282 deletions
diff --git a/indra/llmessage/llcorehttputil.h b/indra/llmessage/llcorehttputil.h
index cd137dbbe1..1e2b50e189 100644
--- a/indra/llmessage/llcorehttputil.h
+++ b/indra/llmessage/llcorehttputil.h
@@ -261,8 +261,8 @@ public:
typedef boost::shared_ptr<HttpCoroutineAdapter> ptr_t;
typedef boost::weak_ptr<HttpCoroutineAdapter> wptr_t;
- HttpCoroutineAdapter(const std::string &name, LLCore::HttpRequest::policy_t policyId,
- LLCore::HttpRequest::priority_t priority = 0L);
+ HttpCoroutineAdapter(const std::string &name, LLCore::HttpRequest::policy_t policyId,
+ LLCore::HttpRequest::priority_t priority = 0L);
~HttpCoroutineAdapter();
/// Execute a Post transaction on the supplied URL and yield execution of
@@ -271,7 +271,7 @@ public:
/// @Note: the request's smart pointer is passed by value so that it will
/// not be deallocated during the yield.
LLSD postAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request,
- const std::string & url, const LLSD & body,
+ const std::string & url, const LLSD & body,
LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false),
LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders(), false));
LLSD postAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request,
@@ -290,7 +290,7 @@ public:
const std::string & url, LLCore::BufferArray::ptr_t &rawbody,
LLCore::HttpHeaders::ptr_t &headers)
{
- return postAndYield(self, request, url, rawbody,
+ return postAndYield(self, request, url, rawbody,
LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false), headers);
}
@@ -313,6 +313,13 @@ public:
const std::string & url,
LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false),
LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders(), false));
+ LLSD getAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t &request,
+ const std::string & url, LLCore::HttpHeaders::ptr_t &headers)
+ {
+ return getAndYield(self, request, url,
+ LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false),
+ headers);
+ }
/// Execute a DELETE transaction on the supplied URL and yield execution of
/// the coroutine until a result is available.
diff --git a/indra/newview/llfacebookconnect.cpp b/indra/newview/llfacebookconnect.cpp
index 680b7677af..ec9efe0c7d 100755
--- a/indra/newview/llfacebookconnect.cpp
+++ b/indra/newview/llfacebookconnect.cpp
@@ -218,10 +218,13 @@ void LLFacebookConnect::facebookShareCoro(LLCoros::self& self, std::string route
LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("FacebookConnect", httpPolicy));
LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
+ LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions);
+
+ httpOpts->setWantHeaders(true);
setConnectionState(LLFacebookConnect::FB_POSTING);
- LLSD result = httpAdapter->postAndYield(self, httpRequest, getFacebookConnectURL(route, true), share);
+ LLSD result = httpAdapter->postAndYield(self, httpRequest, getFacebookConnectURL(route, true), share, httpOpts);
if (testShareStatus(result))
{
@@ -238,6 +241,9 @@ void LLFacebookConnect::facebookShareImageCoro(LLCoros::self& self, std::string
httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("FacebookConnect", httpPolicy));
LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
LLCore::HttpHeaders::ptr_t httpHeaders(new LLCore::HttpHeaders);
+ LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions);
+
+ httpOpts->setWantHeaders(true);
std::string imageFormat;
if (dynamic_cast<LLImagePNG*>(image.get()))
@@ -284,7 +290,7 @@ void LLFacebookConnect::facebookShareImageCoro(LLCoros::self& self, std::string
setConnectionState(LLFacebookConnect::FB_POSTING);
- LLSD result = httpAdapter->postAndYield(self, httpRequest, getFacebookConnectURL(route, true), raw, httpHeaders);
+ LLSD result = httpAdapter->postAndYield(self, httpRequest, getFacebookConnectURL(route, true), raw, httpOpts, httpHeaders);
if (testShareStatus(result))
{
@@ -381,8 +387,11 @@ void LLFacebookConnect::facebookConnectInfoCoro(LLCoros::self& self)
LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("FacebookConnect", httpPolicy));
LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
+ LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions);
+
+ httpOpts->setWantHeaders(true);
- LLSD result = httpAdapter->getAndYield(self, httpRequest, getFacebookConnectURL("/info", true));
+ LLSD result = httpAdapter->getAndYield(self, httpRequest, getFacebookConnectURL("/info", true), httpOpts);
LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroHandler::getStatusFromLLSD(httpResults);
diff --git a/indra/newview/llflickrconnect.cpp b/indra/newview/llflickrconnect.cpp
index b75660ea00..bad37bef6e 100644
--- a/indra/newview/llflickrconnect.cpp
+++ b/indra/newview/llflickrconnect.cpp
@@ -43,6 +43,7 @@
#include "llfloaterwebcontent.h"
#include "llfloaterreg.h"
+#include "llcorehttputil.h"
boost::scoped_ptr<LLEventPump> LLFlickrConnect::sStateWatcher(new LLEventStream("FlickrConnectState"));
boost::scoped_ptr<LLEventPump> LLFlickrConnect::sInfoWatcher(new LLEventStream("FlickrConnectInfo"));
@@ -67,228 +68,315 @@ void toast_user_for_flickr_success()
///////////////////////////////////////////////////////////////////////////////
//
-class LLFlickrConnectResponder : public LLHTTPClient::Responder
+void LLFlickrConnect::flickrConnectCoro(LLCoros::self& self, std::string requestToken, std::string oauthVerifier)
{
- LOG_CLASS(LLFlickrConnectResponder);
-public:
-
- LLFlickrConnectResponder()
+ LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
+ LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
+ httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("FlickrConnect", httpPolicy));
+ LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
+ LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions);
+
+ httpOpts->setWantHeaders(true);
+
+ LLSD body;
+ if (!requestToken.empty())
+ body["request_token"] = requestToken;
+ if (!oauthVerifier.empty())
+ body["oauth_verifier"] = oauthVerifier;
+
+ setConnectionState(LLFlickrConnect::FLICKR_CONNECTION_IN_PROGRESS);
+
+ LLSD result = httpAdapter->putAndYield(self, httpRequest, getFlickrConnectURL("/connection"), body, httpOpts);
+
+ LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+ LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroHandler::getStatusFromLLSD(httpResults);
+
+ if (!status)
+ {
+ if ( status == LLCore::HttpStatus(HTTP_FOUND) )
+ {
+ std::string location = httpResults[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS_HEADERS][HTTP_IN_HEADER_LOCATION];
+ if (location.empty())
+ {
+ LL_WARNS("FlickrConnect") << "Missing Location header " << LL_ENDL;
+ }
+ else
+ {
+ openFlickrWeb(location);
+ }
+ }
+ else
+ {
+ LL_WARNS("FlickrConnect") << "Connection failed " << status.toString() << LL_ENDL;
+ setConnectionState(LLFlickrConnect::FLICKR_CONNECTION_FAILED);
+ log_flickr_connect_error("Connect", status.getStatus(), status.toString(),
+ result.get("error_code"), result.get("error_description"));
+ }
+ }
+ else
{
- LLFlickrConnect::instance().setConnectionState(LLFlickrConnect::FLICKR_CONNECTION_IN_PROGRESS);
+ LL_DEBUGS("FlickrConnect") << "Connect successful. " << LL_ENDL;
+ setConnectionState(LLFlickrConnect::FLICKR_CONNECTED);
}
-
- /* virtual */ void httpSuccess()
- {
- LL_DEBUGS("FlickrConnect") << "Connect successful. " << dumpResponse() << LL_ENDL;
- LLFlickrConnect::instance().setConnectionState(LLFlickrConnect::FLICKR_CONNECTED);
- }
-
- /* virtual */ void httpFailure()
- {
- if ( HTTP_FOUND == getStatus() )
- {
- const std::string& location = getResponseHeader(HTTP_IN_HEADER_LOCATION);
- if (location.empty())
- {
- LL_WARNS("FlickrConnect") << "Missing Location header " << dumpResponse()
- << "[headers:" << getResponseHeaders() << "]" << LL_ENDL;
- }
- else
- {
- LLFlickrConnect::instance().openFlickrWeb(location);
- }
- }
- else
- {
- LL_WARNS("FlickrConnect") << dumpResponse() << LL_ENDL;
- LLFlickrConnect::instance().setConnectionState(LLFlickrConnect::FLICKR_CONNECTION_FAILED);
- const LLSD& content = getContent();
- log_flickr_connect_error("Connect", getStatus(), getReason(),
- content.get("error_code"), content.get("error_description"));
- }
- }
-};
+}
///////////////////////////////////////////////////////////////////////////////
//
-class LLFlickrShareResponder : public LLHTTPClient::Responder
+bool LLFlickrConnect::testShareStatus(LLSD &result)
{
- LOG_CLASS(LLFlickrShareResponder);
-public:
-
- LLFlickrShareResponder()
- {
- LLFlickrConnect::instance().setConnectionState(LLFlickrConnect::FLICKR_POSTING);
- }
-
- /* virtual */ void httpSuccess()
- {
+ LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+ LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroHandler::getStatusFromLLSD(httpResults);
+
+ if (status)
+ return true;
+
+ if (status == LLCore::HttpStatus(HTTP_FOUND))
+ {
+ std::string location = httpResults[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS_HEADERS][HTTP_IN_HEADER_LOCATION];
+ if (location.empty())
+ {
+ LL_WARNS("FlickrConnect") << "Missing Location header " << LL_ENDL;
+ }
+ else
+ {
+ openFlickrWeb(location);
+ }
+ }
+ if (status == LLCore::HttpStatus(HTTP_NOT_FOUND))
+ {
+ LL_DEBUGS("FlickrConnect") << "Not connected. " << LL_ENDL;
+ connectToFlickr();
+ }
+ else
+ {
+ LL_WARNS("FlickrConnect") << "HTTP Status error " << status.toString() << LL_ENDL;
+ setConnectionState(LLFlickrConnect::FLICKR_POST_FAILED);
+ log_flickr_connect_error("Share", status.getStatus(), status.toString(),
+ result.get("error_code"), result.get("error_description"));
+ }
+ return false;
+}
+
+void LLFlickrConnect::flickrShareCoro(LLCoros::self& self, LLSD share)
+{
+ LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
+ LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
+ httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("FlickrConnect", httpPolicy));
+ LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
+ LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions);
+
+ httpOpts->setWantHeaders(true);
+
+ setConnectionState(LLFlickrConnect::FLICKR_POSTING);
+
+ LLSD result = httpAdapter->postAndYield(self, httpRequest, getFlickrConnectURL("/share/photo", true), share, httpOpts);
+
+ if (testShareStatus(result))
+ {
toast_user_for_flickr_success();
- LL_DEBUGS("FlickrConnect") << "Post successful. " << dumpResponse() << LL_ENDL;
- LLFlickrConnect::instance().setConnectionState(LLFlickrConnect::FLICKR_POSTED);
- }
-
- /* virtual */ void httpFailure()
- {
- if ( HTTP_FOUND == getStatus() )
- {
- const std::string& location = getResponseHeader(HTTP_IN_HEADER_LOCATION);
- if (location.empty())
- {
- LL_WARNS("FlickrConnect") << "Missing Location header " << dumpResponse()
- << "[headers:" << getResponseHeaders() << "]" << LL_ENDL;
- }
- else
- {
- LLFlickrConnect::instance().openFlickrWeb(location);
- }
- }
- else if ( HTTP_NOT_FOUND == getStatus() )
- {
- LLFlickrConnect::instance().connectToFlickr();
- }
- else
- {
- LL_WARNS("FlickrConnect") << dumpResponse() << LL_ENDL;
- LLFlickrConnect::instance().setConnectionState(LLFlickrConnect::FLICKR_POST_FAILED);
- const LLSD& content = getContent();
- log_flickr_connect_error("Share", getStatus(), getReason(),
- content.get("error_code"), content.get("error_description"));
- }
- }
-};
+ LL_DEBUGS("FlickrConnect") << "Post successful. " << LL_ENDL;
+ setConnectionState(LLFlickrConnect::FLICKR_POSTED);
+ }
+
+}
+
+void LLFlickrConnect::flickrShareImageCoro(LLCoros::self& self, LLPointer<LLImageFormatted> image, std::string title, std::string description, std::string tags, int safetyLevel)
+{
+ LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
+ LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
+ httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("FlickrConnect", httpPolicy));
+ LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
+ LLCore::HttpHeaders::ptr_t httpHeaders(new LLCore::HttpHeaders);
+ LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions);
+
+ httpOpts->setWantHeaders(true);
+
+ std::string imageFormat;
+ if (dynamic_cast<LLImagePNG*>(image.get()))
+ {
+ imageFormat = "png";
+ }
+ else if (dynamic_cast<LLImageJPEG*>(image.get()))
+ {
+ imageFormat = "jpg";
+ }
+ else
+ {
+ LL_WARNS() << "Image to upload is not a PNG or JPEG" << LL_ENDL;
+ return;
+ }
+
+ // All this code is mostly copied from LLWebProfile::post()
+ const std::string boundary = "----------------------------0123abcdefab";
+
+ std::string contentType = "multipart/form-data; boundary=" + boundary;
+ httpHeaders->append("Content-Type", contentType.c_str());
+
+ LLCore::BufferArray::ptr_t raw = LLCore::BufferArray::ptr_t(new LLCore::BufferArray(), false); //
+ LLCore::BufferArrayStream body(raw.get());
+
+ // *NOTE: The order seems to matter.
+ body << "--" << boundary << "\r\n"
+ << "Content-Disposition: form-data; name=\"title\"\r\n\r\n"
+ << title << "\r\n";
+
+ body << "--" << boundary << "\r\n"
+ << "Content-Disposition: form-data; name=\"description\"\r\n\r\n"
+ << description << "\r\n";
+
+ body << "--" << boundary << "\r\n"
+ << "Content-Disposition: form-data; name=\"tags\"\r\n\r\n"
+ << tags << "\r\n";
+
+ body << "--" << boundary << "\r\n"
+ << "Content-Disposition: form-data; name=\"safety_level\"\r\n\r\n"
+ << safetyLevel << "\r\n";
+
+ body << "--" << boundary << "\r\n"
+ << "Content-Disposition: form-data; name=\"image\"; filename=\"Untitled." << imageFormat << "\"\r\n"
+ << "Content-Type: image/" << imageFormat << "\r\n\r\n";
+
+ // Insert the image data.
+ // *FIX: Treating this as a string will probably screw it up ...
+ U8* image_data = image->getData();
+ for (S32 i = 0; i < image->getDataSize(); ++i)
+ {
+ body << image_data[i];
+ }
+
+ body << "\r\n--" << boundary << "--\r\n";
+
+ LLSD result = httpAdapter->postAndYield(self, httpRequest, getFlickrConnectURL("/share/photo", true), raw, httpOpts, httpHeaders);
+
+ if (testShareStatus(result))
+ {
+ toast_user_for_flickr_success();
+ LL_DEBUGS("FlickrConnect") << "Post successful. " << LL_ENDL;
+ setConnectionState(LLFlickrConnect::FLICKR_POSTED);
+ }
+}
///////////////////////////////////////////////////////////////////////////////
//
-class LLFlickrDisconnectResponder : public LLHTTPClient::Responder
+void LLFlickrConnect::flickrDisconnectCoro(LLCoros::self& self)
{
- LOG_CLASS(LLFlickrDisconnectResponder);
-public:
-
- LLFlickrDisconnectResponder()
- {
- LLFlickrConnect::instance().setConnectionState(LLFlickrConnect::FLICKR_DISCONNECTING);
- }
+ LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
+ LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
+ httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("FlickrConnect", httpPolicy));
+ LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
- void setUserDisconnected()
- {
- // Clear data
- LLFlickrConnect::instance().clearInfo();
+ setConnectionState(LLFlickrConnect::FLICKR_DISCONNECTING);
- //Notify state change
- LLFlickrConnect::instance().setConnectionState(LLFlickrConnect::FLICKR_NOT_CONNECTED);
- }
+ LLSD result = httpAdapter->deleteAndYield(self, httpRequest, getFlickrConnectURL("/connection"));
- /* virtual */ void httpSuccess()
- {
- LL_DEBUGS("FlickrConnect") << "Disconnect successful. " << dumpResponse() << LL_ENDL;
- setUserDisconnected();
- }
-
- /* virtual */ void httpFailure()
- {
- //User not found so already disconnected
- if ( HTTP_NOT_FOUND == getStatus() )
- {
- LL_DEBUGS("FlickrConnect") << "Already disconnected. " << dumpResponse() << LL_ENDL;
- setUserDisconnected();
- }
- else
- {
- LL_WARNS("FlickrConnect") << dumpResponse() << LL_ENDL;
- LLFlickrConnect::instance().setConnectionState(LLFlickrConnect::FLICKR_DISCONNECT_FAILED);
- const LLSD& content = getContent();
- log_flickr_connect_error("Disconnect", getStatus(), getReason(),
- content.get("error_code"), content.get("error_description"));
- }
- }
-};
+ LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+ LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroHandler::getStatusFromLLSD(httpResults);
+
+ if (!status && (status != LLCore::HttpStatus(HTTP_NOT_FOUND)))
+ {
+ LL_WARNS("FlickrConnect") << "Disconnect failed!" << LL_ENDL;
+ setConnectionState(LLFlickrConnect::FLICKR_DISCONNECT_FAILED);
+
+ log_flickr_connect_error("Disconnect", status.getStatus(), status.toString(),
+ result.get("error_code"), result.get("error_description"));
+ }
+ else
+ {
+ LL_DEBUGS("FlickrConnect") << "Disconnect successful. " << LL_ENDL;
+ clearInfo();
+ setConnectionState(LLFlickrConnect::FLICKR_NOT_CONNECTED);
+ }
+}
///////////////////////////////////////////////////////////////////////////////
//
-class LLFlickrConnectedResponder : public LLHTTPClient::Responder
+void LLFlickrConnect::flickrConnectedCoro(LLCoros::self& self, bool autoConnect)
{
- LOG_CLASS(LLFlickrConnectedResponder);
-public:
-
- LLFlickrConnectedResponder(bool auto_connect) : mAutoConnect(auto_connect)
+ LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
+ LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
+ httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("FacebookConnect", httpPolicy));
+ LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
+
+ setConnectionState(LLFlickrConnect::FLICKR_CONNECTION_IN_PROGRESS);
+
+ LLSD result = httpAdapter->getAndYield(self, httpRequest, getFlickrConnectURL("/connection", true));
+
+ LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+ LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroHandler::getStatusFromLLSD(httpResults);
+
+ if (!status)
{
- LLFlickrConnect::instance().setConnectionState(LLFlickrConnect::FLICKR_CONNECTION_IN_PROGRESS);
+ if (status == LLCore::HttpStatus(HTTP_NOT_FOUND))
+ {
+ LL_DEBUGS("FlickrConnect") << "Not connected. " << LL_ENDL;
+ if (autoConnect)
+ {
+ connectToFlickr();
+ }
+ else
+ {
+ setConnectionState(LLFlickrConnect::FLICKR_NOT_CONNECTED);
+ }
+ }
+ else
+ {
+ LL_WARNS("FlickrConnect") << "Failed to test connection:" << status.toTerseString() << LL_ENDL;
+
+ setConnectionState(LLFlickrConnect::FLICKR_CONNECTION_FAILED);
+ log_flickr_connect_error("Connected", status.getStatus(), status.toString(),
+ result.get("error_code"), result.get("error_description"));
+ }
}
-
- /* virtual */ void httpSuccess()
- {
- LL_DEBUGS("FlickrConnect") << "Connect successful. " << dumpResponse() << LL_ENDL;
- LLFlickrConnect::instance().setConnectionState(LLFlickrConnect::FLICKR_CONNECTED);
- }
-
- /* virtual */ void httpFailure()
- {
- // show the facebook login page if not connected yet
- if ( HTTP_NOT_FOUND == getStatus() )
- {
- LL_DEBUGS("FlickrConnect") << "Not connected. " << dumpResponse() << LL_ENDL;
- if (mAutoConnect)
- {
- LLFlickrConnect::instance().connectToFlickr();
- }
- else
- {
- LLFlickrConnect::instance().setConnectionState(LLFlickrConnect::FLICKR_NOT_CONNECTED);
- }
- }
- else
- {
- LL_WARNS("FlickrConnect") << dumpResponse() << LL_ENDL;
- LLFlickrConnect::instance().setConnectionState(LLFlickrConnect::FLICKR_CONNECTION_FAILED);
- const LLSD& content = getContent();
- log_flickr_connect_error("Connected", getStatus(), getReason(),
- content.get("error_code"), content.get("error_description"));
- }
- }
-
-private:
- bool mAutoConnect;
-};
+ else
+ {
+ LL_DEBUGS("FlickrConnect") << "Connect successful. " << LL_ENDL;
+ setConnectionState(LLFlickrConnect::FLICKR_CONNECTED);
+ }
+
+}
///////////////////////////////////////////////////////////////////////////////
//
-class LLFlickrInfoResponder : public LLHTTPClient::Responder
+void LLFlickrConnect::flickrInfoCoro(LLCoros::self& self)
{
- LOG_CLASS(LLFlickrInfoResponder);
-public:
+ LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
+ LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
+ httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("FacebookConnect", httpPolicy));
+ LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
+ LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions);
- /* virtual */ void httpSuccess()
- {
- LL_INFOS("FlickrConnect") << "Flickr: Info received" << LL_ENDL;
- LL_DEBUGS("FlickrConnect") << "Getting Flickr info successful. " << dumpResponse() << LL_ENDL;
- LLFlickrConnect::instance().storeInfo(getContent());
- }
-
- /* virtual */ void httpFailure()
- {
- if ( HTTP_FOUND == getStatus() )
- {
- const std::string& location = getResponseHeader(HTTP_IN_HEADER_LOCATION);
- if (location.empty())
- {
- LL_WARNS("FlickrConnect") << "Missing Location header " << dumpResponse()
- << "[headers:" << getResponseHeaders() << "]" << LL_ENDL;
- }
- else
- {
- LLFlickrConnect::instance().openFlickrWeb(location);
- }
- }
- else
- {
- LL_WARNS("FlickrConnect") << dumpResponse() << LL_ENDL;
- const LLSD& content = getContent();
- log_flickr_connect_error("Info", getStatus(), getReason(),
- content.get("error_code"), content.get("error_description"));
- }
- }
-};
+ httpOpts->setWantHeaders(true);
+
+ LLSD result = httpAdapter->getAndYield(self, httpRequest, getFlickrConnectURL("/info", true), httpOpts);
+
+ LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+ LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroHandler::getStatusFromLLSD(httpResults);
+
+ if (status == LLCore::HttpStatus(HTTP_FOUND))
+ {
+ std::string location = httpResults[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS_HEADERS][HTTP_IN_HEADER_LOCATION];
+ if (location.empty())
+ {
+ LL_WARNS("FlickrConnect") << "Missing Location header " << LL_ENDL;
+ }
+ else
+ {
+ openFlickrWeb(location);
+ }
+ }
+ else if (!status)
+ {
+ LL_WARNS("FlickrConnect") << "Flickr Info failed: " << status.toString() << LL_ENDL;
+ log_flickr_connect_error("Info", status.getStatus(), status.toString(),
+ result.get("error_code"), result.get("error_description"));
+ }
+ else
+ {
+ LL_INFOS("FlickrConnect") << "Flickr: Info received" << LL_ENDL;
+ result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS);
+ storeInfo(result);
+ }
+}
///////////////////////////////////////////////////////////////////////////////
//
@@ -341,36 +429,28 @@ std::string LLFlickrConnect::getFlickrConnectURL(const std::string& route, bool
void LLFlickrConnect::connectToFlickr(const std::string& request_token, const std::string& oauth_verifier)
{
- LLSD body;
- if (!request_token.empty())
- body["request_token"] = request_token;
- if (!oauth_verifier.empty())
- body["oauth_verifier"] = oauth_verifier;
-
- LLHTTPClient::put(getFlickrConnectURL("/connection"), body, new LLFlickrConnectResponder());
+ LLCoros::instance().launch("LLFlickrConnect::flickrConnectCoro",
+ boost::bind(&LLFlickrConnect::flickrConnectCoro, this, _1, request_token, oauth_verifier));
}
void LLFlickrConnect::disconnectFromFlickr()
{
- LLHTTPClient::del(getFlickrConnectURL("/connection"), new LLFlickrDisconnectResponder());
+ LLCoros::instance().launch("LLFlickrConnect::flickrDisconnectCoro",
+ boost::bind(&LLFlickrConnect::flickrDisconnectCoro, this, _1));
}
void LLFlickrConnect::checkConnectionToFlickr(bool auto_connect)
{
- const bool follow_redirects = false;
- const F32 timeout = HTTP_REQUEST_EXPIRY_SECS;
- LLHTTPClient::get(getFlickrConnectURL("/connection", true), new LLFlickrConnectedResponder(auto_connect),
- LLSD(), timeout, follow_redirects);
+ LLCoros::instance().launch("LLFlickrConnect::flickrConnectedCoro",
+ boost::bind(&LLFlickrConnect::flickrConnectedCoro, this, _1, auto_connect));
}
void LLFlickrConnect::loadFlickrInfo()
{
if(mRefreshInfo)
{
- const bool follow_redirects = false;
- const F32 timeout = HTTP_REQUEST_EXPIRY_SECS;
- LLHTTPClient::get(getFlickrConnectURL("/info", true), new LLFlickrInfoResponder(),
- LLSD(), timeout, follow_redirects);
+ LLCoros::instance().launch("LLFlickrConnect::flickrInfoCoro",
+ boost::bind(&LLFlickrConnect::flickrInfoCoro, this, _1));
}
}
@@ -382,74 +462,17 @@ void LLFlickrConnect::uploadPhoto(const std::string& image_url, const std::strin
body["description"] = description;
body["tags"] = tags;
body["safety_level"] = safety_level;
-
- // Note: we can use that route for different publish action. We should be able to use the same responder.
- LLHTTPClient::post(getFlickrConnectURL("/share/photo", true), body, new LLFlickrShareResponder());
+
+ LLCoros::instance().launch("LLFlickrConnect::flickrShareCoro",
+ boost::bind(&LLFlickrConnect::flickrShareCoro, this, _1, body));
}
void LLFlickrConnect::uploadPhoto(LLPointer<LLImageFormatted> image, const std::string& title, const std::string& description, const std::string& tags, int safety_level)
{
- std::string imageFormat;
- if (dynamic_cast<LLImagePNG*>(image.get()))
- {
- imageFormat = "png";
- }
- else if (dynamic_cast<LLImageJPEG*>(image.get()))
- {
- imageFormat = "jpg";
- }
- else
- {
- LL_WARNS() << "Image to upload is not a PNG or JPEG" << LL_ENDL;
- return;
- }
-
- // All this code is mostly copied from LLWebProfile::post()
- const std::string boundary = "----------------------------0123abcdefab";
-
- LLSD headers;
- headers["Content-Type"] = "multipart/form-data; boundary=" + boundary;
-
- std::ostringstream body;
-
- // *NOTE: The order seems to matter.
- body << "--" << boundary << "\r\n"
- << "Content-Disposition: form-data; name=\"title\"\r\n\r\n"
- << title << "\r\n";
-
- body << "--" << boundary << "\r\n"
- << "Content-Disposition: form-data; name=\"description\"\r\n\r\n"
- << description << "\r\n";
-
- body << "--" << boundary << "\r\n"
- << "Content-Disposition: form-data; name=\"tags\"\r\n\r\n"
- << tags << "\r\n";
-
- body << "--" << boundary << "\r\n"
- << "Content-Disposition: form-data; name=\"safety_level\"\r\n\r\n"
- << safety_level << "\r\n";
-
- body << "--" << boundary << "\r\n"
- << "Content-Disposition: form-data; name=\"image\"; filename=\"Untitled." << imageFormat << "\"\r\n"
- << "Content-Type: image/" << imageFormat << "\r\n\r\n";
-
- // Insert the image data.
- // *FIX: Treating this as a string will probably screw it up ...
- U8* image_data = image->getData();
- for (S32 i = 0; i < image->getDataSize(); ++i)
- {
- body << image_data[i];
- }
-
- body << "\r\n--" << boundary << "--\r\n";
- // postRaw() takes ownership of the buffer and releases it later.
- size_t size = body.str().size();
- U8 *data = new U8[size];
- memcpy(data, body.str().data(), size);
-
- // Note: we can use that route for different publish action. We should be able to use the same responder.
- LLHTTPClient::postRaw(getFlickrConnectURL("/share/photo", true), data, size, new LLFlickrShareResponder(), headers);
+ LLCoros::instance().launch("LLFlickrConnect::flickrShareImageCoro",
+ boost::bind(&LLFlickrConnect::flickrShareImageCoro, this, _1, image,
+ title, description, tags, safety_level));
}
void LLFlickrConnect::storeInfo(const LLSD& info)
diff --git a/indra/newview/llflickrconnect.h b/indra/newview/llflickrconnect.h
index b127e6e104..26c63f8b08 100644
--- a/indra/newview/llflickrconnect.h
+++ b/indra/newview/llflickrconnect.h
@@ -30,6 +30,8 @@
#include "llsingleton.h"
#include "llimage.h"
+#include "llcoros.h"
+#include "lleventcoro.h"
class LLEventPump;
@@ -93,6 +95,15 @@ private:
static boost::scoped_ptr<LLEventPump> sStateWatcher;
static boost::scoped_ptr<LLEventPump> sInfoWatcher;
static boost::scoped_ptr<LLEventPump> sContentWatcher;
+
+ bool testShareStatus(LLSD &result);
+ void flickrConnectCoro(LLCoros::self& self, std::string requestToken, std::string oauthVerifier);
+ void flickrShareCoro(LLCoros::self& self, LLSD share);
+ void flickrShareImageCoro(LLCoros::self& self, LLPointer<LLImageFormatted> image, std::string title, std::string description, std::string tags, int safetyLevel);
+ void flickrDisconnectCoro(LLCoros::self& self);
+ void flickrConnectedCoro(LLCoros::self& self, bool autoConnect);
+ void flickrInfoCoro(LLCoros::self& self);
+
};
#endif // LL_LLFLICKRCONNECT_H