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.
This commit is contained in:
Alexander Tkachev 2016-05-26 21:40:01 +06:00
parent b246c17850
commit 8f6bcdf55d
10 changed files with 222 additions and 26 deletions

View file

@ -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