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/curljsonrequest.cpp | |
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/curljsonrequest.cpp')
-rw-r--r-- | backends/networking/curl/curljsonrequest.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
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 |