diff options
author | Alexander Tkachev | 2016-05-26 21:40:01 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | 8f6bcdf55da97db98384c2a8cb9dcdf34232ac35 (patch) | |
tree | a1ec4f773c2891cf432f05af2461ca161959a017 /backends/networking/curl | |
parent | b246c17850687e7b15b644b761fbfe835ffc1c32 (diff) | |
download | scummvm-rg350-8f6bcdf55da97db98384c2a8cb9dcdf34232ac35.tar.gz scummvm-rg350-8f6bcdf55da97db98384c2a8cb9dcdf34232ac35.tar.bz2 scummvm-rg350-8f6bcdf55da97db98384c2a8cb9dcdf34232ac35.zip |
CLOUD: Add OneDriveTokenRefresher
OneDriveTokenRefresher is a CurlJsonRequest replacement for
OneDriveStorage methods. It behaves very similarly, but checks received
JSON before passing it to user. If it contains "error" key, it attempts
to refresh the token through OneDriveStorage, and then restarts the
original request, so user won't notice that there ever was an error.
Diffstat (limited to 'backends/networking/curl')
-rw-r--r-- | backends/networking/curl/connectionmanager.cpp | 2 | ||||
-rw-r--r-- | backends/networking/curl/curljsonrequest.cpp | 9 | ||||
-rw-r--r-- | backends/networking/curl/curljsonrequest.h | 3 | ||||
-rw-r--r-- | backends/networking/curl/curlrequest.cpp | 7 | ||||
-rw-r--r-- | backends/networking/curl/curlrequest.h | 8 |
5 files changed, 24 insertions, 5 deletions
diff --git a/backends/networking/curl/connectionmanager.cpp b/backends/networking/curl/connectionmanager.cpp index b448d8e514..77a46ec518 100644 --- a/backends/networking/curl/connectionmanager.cpp +++ b/backends/networking/curl/connectionmanager.cpp @@ -76,6 +76,7 @@ void ConnectionManager::startTimer(int interval) { } void ConnectionManager::stopTimer() { + debug("timer stopped"); Common::TimerManager *manager = g_system->getTimerManager(); manager->removeTimerProc(connectionsThread); _timerStarted = false; @@ -111,6 +112,7 @@ void ConnectionManager::interateRequests() { else { info.state = PROCESSING; info.request->restart(); + debug("request restarted"); } default: diff --git a/backends/networking/curl/curljsonrequest.cpp b/backends/networking/curl/curljsonrequest.cpp index a323b34ed2..1231f9e7e8 100644 --- a/backends/networking/curl/curljsonrequest.cpp +++ b/backends/networking/curl/curljsonrequest.cpp @@ -74,11 +74,18 @@ void CurlJsonRequest::handle() { char *contents = getPreparedContents(); if (_stream->httpResponseCode() != 200) debug("%s", contents); - Common::JSONValue *json = Common::JSON::parse(contents); + Common::JSONValue *json = Common::JSON::parse(contents); (*_jsonCallback)(RequestJsonPair(_id, json)); //potential memory leak, free it in your callbacks! } } } } +void CurlJsonRequest::restart() { + if (_stream) delete _stream; + _stream = 0; + _contentsStream = Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES); + //with no stream available next handle() will create another one +} + } //end of namespace Networking diff --git a/backends/networking/curl/curljsonrequest.h b/backends/networking/curl/curljsonrequest.h index 75d4a6df81..af19ec3596 100644 --- a/backends/networking/curl/curljsonrequest.h +++ b/backends/networking/curl/curljsonrequest.h @@ -45,7 +45,8 @@ public: CurlJsonRequest(JsonCallback cb, const char *url); virtual ~CurlJsonRequest(); - virtual void handle(); + virtual void handle(); + virtual void restart(); }; } //end of namespace Networking diff --git a/backends/networking/curl/curlrequest.cpp b/backends/networking/curl/curlrequest.cpp index e30b7ce018..1b42ac5931 100644 --- a/backends/networking/curl/curlrequest.cpp +++ b/backends/networking/curl/curlrequest.cpp @@ -53,6 +53,13 @@ void CurlRequest::restart() { //with no stream available next handle() will create another one } +void CurlRequest::setHeaders(Common::Array<Common::String> &headers) { + curl_slist_free_all(_headersList); + _headersList = 0; + for (uint32 i = 0; i < headers.size(); ++i) + addHeader(headers[i]); +} + void CurlRequest::addHeader(Common::String header) { _headersList = curl_slist_append(_headersList, header.c_str()); } diff --git a/backends/networking/curl/curlrequest.h b/backends/networking/curl/curlrequest.h index 1a644e4369..c624194142 100644 --- a/backends/networking/curl/curlrequest.h +++ b/backends/networking/curl/curlrequest.h @@ -25,6 +25,7 @@ #include "backends/networking/curl/request.h" #include "common/str.h" +#include <common/array.h> struct curl_slist; @@ -46,11 +47,12 @@ public: virtual void handle(); virtual void restart(); - void addHeader(Common::String header); - void addPostField(Common::String header); + virtual void setHeaders(Common::Array<Common::String> &headers); + virtual void addHeader(Common::String header); + virtual void addPostField(Common::String field); /** Start this Request with ConnMan. Returns its ReadStream. */ - NetworkReadStream *execute(); + virtual NetworkReadStream *execute(); }; } //end of namespace Networking |