aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-26 13:45:24 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit166d1121e5973868b24aa3db6156028edb1d6a72 (patch)
treebf2da8c0b648bde8371c17a43e8c87175987ba6f /backends/cloud
parent9d96d40b3d78d987d414e0dc77f43c09ef4421ba (diff)
downloadscummvm-rg350-166d1121e5973868b24aa3db6156028edb1d6a72.tar.gz
scummvm-rg350-166d1121e5973868b24aa3db6156028edb1d6a72.tar.bz2
scummvm-rg350-166d1121e5973868b24aa3db6156028edb1d6a72.zip
CLOUD: Update TokenRefreshers
Box's, Google Drive's and OneDrive's token refreshing requests have more JSON checks now.
Diffstat (limited to 'backends/cloud')
-rw-r--r--backends/cloud/box/boxtokenrefresher.cpp67
-rw-r--r--backends/cloud/googledrive/googledrivetokenrefresher.cpp70
-rw-r--r--backends/cloud/onedrive/onedrivetokenrefresher.cpp74
3 files changed, 109 insertions, 102 deletions
diff --git a/backends/cloud/box/boxtokenrefresher.cpp b/backends/cloud/box/boxtokenrefresher.cpp
index c798b97343..ca05eef838 100644
--- a/backends/cloud/box/boxtokenrefresher.cpp
+++ b/backends/cloud/box/boxtokenrefresher.cpp
@@ -63,41 +63,44 @@ void BoxTokenRefresher::finishJson(Common::JSONValue *json) {
return;
}
- Common::JSONObject result = json->asObject();
- if (result.contains("type") && result.getVal("type")->isString() && result.getVal("type")->asString() == "error") {
- //new token needed => request token & then retry original request
- long httpCode = -1;
- if (_stream) {
- httpCode = _stream->httpResponseCode();
- debug(9, "BoxTokenRefresher: code %ld", httpCode);
- }
-
- bool irrecoverable = true;
-
- Common::String code, message;
- if (result.contains("code")) {
- code = result.getVal("code")->asString();
- debug(9, "BoxTokenRefresher: code = %s", code.c_str());
- }
-
- if (result.contains("message")) {
- message = result.getVal("message")->asString();
- debug(9, "BoxTokenRefresher: message = %s", message.c_str());
- }
-
- //TODO: decide when token refreshment will help
- //if (code == "unauthenticated") irrecoverable = false;
-
- if (irrecoverable) {
- finishError(Networking::ErrorResponse(this, false, true, json->stringify(true), httpCode));
+ if (jsonIsObject(json, "BoxTokenRefresher")) {
+ Common::JSONObject result = json->asObject();
+ if (result.contains("type") && result.getVal("type")->isString() && result.getVal("type")->asString() == "error") {
+ //new token needed => request token & then retry original request
+ long httpCode = -1;
+ if (_stream) {
+ httpCode = _stream->httpResponseCode();
+ debug(9, "BoxTokenRefresher: code %ld", httpCode);
+ }
+
+ bool irrecoverable = true;
+
+ Common::String code, message;
+ if (jsonContainsString(result, "code", "BoxTokenRefresher")) {
+ code = result.getVal("code")->asString();
+ debug(9, "BoxTokenRefresher: code = %s", code.c_str());
+ }
+
+ if (jsonContainsString(result, "message", "BoxTokenRefresher")) {
+ message = result.getVal("message")->asString();
+ debug(9, "BoxTokenRefresher: message = %s", message.c_str());
+ }
+
+ //TODO: decide when token refreshment will help
+ //for now refreshment is used only when HTTP 401 is passed in finishError()
+ //if (code == "unauthenticated") irrecoverable = false;
+
+ if (irrecoverable) {
+ finishError(Networking::ErrorResponse(this, false, true, json->stringify(true), httpCode));
+ delete json;
+ return;
+ }
+
+ pause();
delete json;
+ _parentStorage->getAccessToken(new Common::Callback<BoxTokenRefresher, Storage::BoolResponse>(this, &BoxTokenRefresher::tokenRefreshed));
return;
}
-
- pause();
- delete json;
- _parentStorage->getAccessToken(new Common::Callback<BoxTokenRefresher, Storage::BoolResponse>(this, &BoxTokenRefresher::tokenRefreshed));
- return;
}
//notify user of success
diff --git a/backends/cloud/googledrive/googledrivetokenrefresher.cpp b/backends/cloud/googledrive/googledrivetokenrefresher.cpp
index 99661c262e..7d68510655 100644
--- a/backends/cloud/googledrive/googledrivetokenrefresher.cpp
+++ b/backends/cloud/googledrive/googledrivetokenrefresher.cpp
@@ -63,43 +63,45 @@ void GoogleDriveTokenRefresher::finishJson(Common::JSONValue *json) {
return;
}
- Common::JSONObject result = json->asObject();
- long httpResponseCode = -1;
- if (result.contains("error")) {
- //new token needed => request token & then retry original request
- if (_stream) {
- httpResponseCode = _stream->httpResponseCode();
- debug(9, "GoogleDriveTokenRefresher: code = %ld", httpResponseCode);
- }
-
- Common::JSONObject error = result.getVal("error")->asObject();
- bool irrecoverable = true;
-
- uint32 code = -1;
- Common::String message;
- if (error.contains("code") && error.getVal("code")->isIntegerNumber()) {
- code = error.getVal("code")->asIntegerNumber();
- debug(9, "GoogleDriveTokenRefresher: code = %u", code);
- }
-
- if (error.contains("message")) {
- message = error.getVal("message")->asString();
- debug(9, "GoogleDriveTokenRefresher: message = %s", message.c_str());
- }
-
- if (code == 401 || message == "Invalid Credentials")
- irrecoverable = false;
-
- if (irrecoverable) {
- finishError(Networking::ErrorResponse(this, false, true, json->stringify(true), httpResponseCode));
+ if (jsonIsObject(json, "GoogleDriveTokenRefresher")) {
+ Common::JSONObject result = json->asObject();
+ long httpResponseCode = -1;
+ if (jsonContainsAttribute(result, "error", "GoogleDriveTokenRefresher") && jsonIsObject(result.getVal("error"), "GoogleDriveTokenRefresher")) {
+ //new token needed => request token & then retry original request
+ if (_stream) {
+ httpResponseCode = _stream->httpResponseCode();
+ debug(9, "GoogleDriveTokenRefresher: code = %ld", httpResponseCode);
+ }
+
+ Common::JSONObject error = result.getVal("error")->asObject();
+ bool irrecoverable = true;
+
+ uint32 code = -1;
+ Common::String message;
+ if (jsonContainsIntegerNumber(error, "code", "GoogleDriveTokenRefresher")) {
+ code = error.getVal("code")->asIntegerNumber();
+ debug(9, "GoogleDriveTokenRefresher: code = %u", code);
+ }
+
+ if (jsonContainsString(error, "message", "GoogleDriveTokenRefresher")) {
+ message = error.getVal("message")->asString();
+ debug(9, "GoogleDriveTokenRefresher: message = %s", message.c_str());
+ }
+
+ if (code == 401 || message == "Invalid Credentials")
+ irrecoverable = false;
+
+ if (irrecoverable) {
+ finishError(Networking::ErrorResponse(this, false, true, json->stringify(true), httpResponseCode));
+ delete json;
+ return;
+ }
+
+ pause();
delete json;
+ _parentStorage->getAccessToken(new Common::Callback<GoogleDriveTokenRefresher, Storage::BoolResponse>(this, &GoogleDriveTokenRefresher::tokenRefreshed));
return;
}
-
- pause();
- delete json;
- _parentStorage->getAccessToken(new Common::Callback<GoogleDriveTokenRefresher, Storage::BoolResponse>(this, &GoogleDriveTokenRefresher::tokenRefreshed));
- return;
}
//notify user of success
diff --git a/backends/cloud/onedrive/onedrivetokenrefresher.cpp b/backends/cloud/onedrive/onedrivetokenrefresher.cpp
index 5e3bce96af..5ee2772ba7 100644
--- a/backends/cloud/onedrive/onedrivetokenrefresher.cpp
+++ b/backends/cloud/onedrive/onedrivetokenrefresher.cpp
@@ -63,48 +63,50 @@ void OneDriveTokenRefresher::finishJson(Common::JSONValue *json) {
return;
}
- Common::JSONObject result = json->asObject();
- long httpResponseCode = -1;
- if (result.contains("error")) {
- //new token needed => request token & then retry original request
- if (_stream) {
- httpResponseCode = _stream->httpResponseCode();
- debug(9, "OneDriveTokenRefresher: code = %ld", httpResponseCode);
- }
-
- Common::JSONObject error = result.getVal("error")->asObject();
- bool irrecoverable = true;
-
- Common::String code, message;
- if (error.contains("code")) {
- code = error.getVal("code")->asString();
- debug(9, "OneDriveTokenRefresher: code = %s", code.c_str());
- }
-
- if (error.contains("message")) {
- message = error.getVal("message")->asString();
- debug(9, "OneDriveTokenRefresher: message = %s", message.c_str());
- }
-
- //determine whether token refreshing would help in this situation
- if (code == "itemNotFound") {
- if (message.contains("application ID"))
+ if (jsonIsObject(json, "OneDriveTokenRefresher")) {
+ Common::JSONObject result = json->asObject();
+ long httpResponseCode = -1;
+ if (jsonContainsAttribute(result, "error", "OneDriveTokenRefresher") && jsonIsObject(result.getVal("error"), "OneDriveTokenRefresher")) {
+ //new token needed => request token & then retry original request
+ if (_stream) {
+ httpResponseCode = _stream->httpResponseCode();
+ debug(9, "OneDriveTokenRefresher: code = %ld", httpResponseCode);
+ }
+
+ Common::JSONObject error = result.getVal("error")->asObject();
+ bool irrecoverable = true;
+
+ Common::String code, message;
+ if (jsonContainsString(error, "code", "OneDriveTokenRefresher")) {
+ code = error.getVal("code")->asString();
+ debug(9, "OneDriveTokenRefresher: code = %s", code.c_str());
+ }
+
+ if (jsonContainsString(error, "message", "OneDriveTokenRefresher")) {
+ message = error.getVal("message")->asString();
+ debug(9, "OneDriveTokenRefresher: message = %s", message.c_str());
+ }
+
+ //determine whether token refreshing would help in this situation
+ if (code == "itemNotFound") {
+ if (message.contains("application ID"))
+ irrecoverable = false;
+ }
+
+ if (code == "unauthenticated")
irrecoverable = false;
- }
- if (code == "unauthenticated")
- irrecoverable = false;
+ if (irrecoverable) {
+ finishError(Networking::ErrorResponse(this, false, true, json->stringify(true), httpResponseCode));
+ delete json;
+ return;
+ }
- if (irrecoverable) {
- finishError(Networking::ErrorResponse(this, false, true, json->stringify(true), httpResponseCode));
+ pause();
delete json;
+ _parentStorage->getAccessToken(new Common::Callback<OneDriveTokenRefresher, Storage::BoolResponse>(this, &OneDriveTokenRefresher::tokenRefreshed));
return;
}
-
- pause();
- delete json;
- _parentStorage->getAccessToken(new Common::Callback<OneDriveTokenRefresher, Storage::BoolResponse>(this, &OneDriveTokenRefresher::tokenRefreshed));
- return;
}
//notify user of success