diff options
author | Alexander Tkachev | 2016-07-26 14:53:44 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | fc8e29d5832728a513cab0f10be218c6a632758a (patch) | |
tree | e581a31eaadd1dc40c4db9c49e58e471e18768aa /backends/cloud/onedrive | |
parent | d34b9b91add07c8bed2d2cef6421fc1b93b2e09e (diff) | |
download | scummvm-rg350-fc8e29d5832728a513cab0f10be218c6a632758a.tar.gz scummvm-rg350-fc8e29d5832728a513cab0f10be218c6a632758a.tar.bz2 scummvm-rg350-fc8e29d5832728a513cab0f10be218c6a632758a.zip |
CLOUD: Update OneDrive
Added JSON checks.
New jsonContainsObject() method added to CurlJsonRequest.
Diffstat (limited to 'backends/cloud/onedrive')
-rw-r--r-- | backends/cloud/onedrive/onedrivecreatedirectoryrequest.cpp | 11 | ||||
-rw-r--r-- | backends/cloud/onedrive/onedrivestorage.cpp | 74 |
2 files changed, 64 insertions, 21 deletions
diff --git a/backends/cloud/onedrive/onedrivecreatedirectoryrequest.cpp b/backends/cloud/onedrive/onedrivecreatedirectoryrequest.cpp index 4d6d8fceda..fc7e4f58b0 100644 --- a/backends/cloud/onedrive/onedrivecreatedirectoryrequest.cpp +++ b/backends/cloud/onedrive/onedrivecreatedirectoryrequest.cpp @@ -101,12 +101,19 @@ void OneDriveCreateDirectoryRequest::responseCallback(Networking::JsonResponse r if (rq && rq->getNetworkReadStream()) error.httpResponseCode = rq->getNetworkReadStream()->httpResponseCode(); - if (!json) { - warning("OneDriveCreateDirectoryRequest: NULL passed instead of JSON"); + if (json == nullptr) { + error.response = "Failed to parse JSON, null passed!"; finishError(error); return; } + if (!json->isObject()) { + error.response = "Passed JSON is not an object!"; + finishError(error); + delete json; + return; + } + Common::JSONObject info = json->asObject(); if (info.contains("id")) { finishCreation(true); diff --git a/backends/cloud/onedrive/onedrivestorage.cpp b/backends/cloud/onedrive/onedrivestorage.cpp index 9fde2ed2c7..4b70bb73b9 100644 --- a/backends/cloud/onedrive/onedrivestorage.cpp +++ b/backends/cloud/onedrive/onedrivestorage.cpp @@ -116,12 +116,24 @@ void OneDriveStorage::tokenRefreshed(BoolCallback callback, Networking::JsonResp Common::JSONValue *json = response.value; if (!json) { warning("OneDriveStorage: got NULL instead of JSON"); - if (callback) (*callback)(BoolResponse(nullptr, false)); + if (callback) + (*callback)(BoolResponse(nullptr, false)); + delete callback; + return; + } + + if (!Networking::CurlJsonRequest::jsonIsObject(json, "OneDriveStorage")) { + if (callback) + (*callback)(BoolResponse(nullptr, false)); + delete json; + delete callback; return; } Common::JSONObject result = json->asObject(); - if (!result.contains("access_token") || !result.contains("user_id") || !result.contains("refresh_token")) { + if (!Networking::CurlJsonRequest::jsonContainsString(result, "access_token", "OneDriveStorage") || + !Networking::CurlJsonRequest::jsonContainsString(result, "user_id", "OneDriveStorage") || + !Networking::CurlJsonRequest::jsonContainsString(result, "refresh_token", "OneDriveStorage")) { warning("OneDriveStorage: bad response, no token or user_id passed"); debug(9, "%s", json->stringify().c_str()); if (callback) @@ -135,6 +147,7 @@ void OneDriveStorage::tokenRefreshed(BoolCallback callback, Networking::JsonResp (*callback)(BoolResponse(nullptr, true)); } delete json; + delete callback; } void OneDriveStorage::codeFlowComplete(BoolResponse response) { @@ -168,7 +181,13 @@ Common::String OneDriveStorage::name() const { void OneDriveStorage::infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse response) { Common::JSONValue *json = response.value; if (!json) { - warning("OneDriveStorage: NULL passed instead of JSON"); + warning("OneDriveStorage::infoInnerCallback: NULL passed instead of JSON"); + delete outerCallback; + return; + } + + if (!Networking::CurlJsonRequest::jsonIsObject(json, "OneDriveStorage::infoInnerCallback")) { + delete json; delete outerCallback; return; } @@ -178,16 +197,18 @@ void OneDriveStorage::infoInnerCallback(StorageInfoCallback outerCallback, Netwo Common::String uid, name, email; uint64 quotaUsed = 0, quotaAllocated = 26843545600L; // 25 GB, because I actually don't know any way to find out the real one - if (info.contains("createdBy") && info.getVal("createdBy")->isObject()) { + if (Networking::CurlJsonRequest::jsonContainsObject(info, "createdBy", "OneDriveStorage::infoInnerCallback")) { Common::JSONObject createdBy = info.getVal("createdBy")->asObject(); - if (createdBy.contains("user") && createdBy.getVal("user")->isObject()) { + if (Networking::CurlJsonRequest::jsonContainsObject(createdBy, "user", "OneDriveStorage::infoInnerCallback")) { Common::JSONObject user = createdBy.getVal("user")->asObject(); - uid = user.getVal("id")->asString(); - name = user.getVal("displayName")->asString(); + if (Networking::CurlJsonRequest::jsonContainsString(user, "id", "OneDriveStorage::infoInnerCallback")) + uid = user.getVal("id")->asString(); + if (Networking::CurlJsonRequest::jsonContainsString(user, "displayName", "OneDriveStorage::infoInnerCallback")) + name = user.getVal("displayName")->asString(); } } - if (info.contains("size") && info.getVal("size")->isIntegerNumber()) { + if (Networking::CurlJsonRequest::jsonContainsIntegerNumber(info, "size", "OneDriveStorage::infoInnerCallback")) { quotaUsed = info.getVal("size")->asIntegerNumber(); } @@ -207,28 +228,43 @@ void OneDriveStorage::infoInnerCallback(StorageInfoCallback outerCallback, Netwo } void OneDriveStorage::fileInfoCallback(Networking::NetworkReadStreamCallback outerCallback, Networking::JsonResponse response) { - if (!response.value) { - warning("OneDriveStorage::fileInfoCallback: NULL, not JSON"); + Common::JSONValue *json = response.value; + if (!json) { + warning("OneDriveStorage::fileInfoCallback: NULL passed instead of JSON"); if (outerCallback) (*outerCallback)(Networking::NetworkReadStreamResponse(response.request, nullptr)); + delete outerCallback; return; } - Common::JSONObject result = response.value->asObject(); - if (result.contains("@content.downloadUrl")) { - const char *url = result.getVal("@content.downloadUrl")->asString().c_str(); + if (!Networking::CurlJsonRequest::jsonIsObject(json, "OneDriveStorage::fileInfoCallback")) { if (outerCallback) - (*outerCallback)(Networking::NetworkReadStreamResponse( - response.request, - new Networking::NetworkReadStream(url, nullptr, "") - )); - } else { + (*outerCallback)(Networking::NetworkReadStreamResponse(response.request, nullptr)); + delete json; + delete outerCallback; + return; + } + + Common::JSONObject result = response.value->asObject(); + if (!Networking::CurlJsonRequest::jsonContainsString(result, "@content.downloadUrl", "OneDriveStorage::fileInfoCallback")) { warning("OneDriveStorage: downloadUrl not found in passed JSON"); debug(9, "%s", response.value->stringify().c_str()); if (outerCallback) (*outerCallback)(Networking::NetworkReadStreamResponse(response.request, nullptr)); + delete json; + delete outerCallback; + return; } - delete response.value; + + const char *url = result.getVal("@content.downloadUrl")->asString().c_str(); + if (outerCallback) + (*outerCallback)(Networking::NetworkReadStreamResponse( + response.request, + new Networking::NetworkReadStream(url, nullptr, "") + )); + + delete json; + delete outerCallback; } Networking::Request *OneDriveStorage::listDirectory(Common::String path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive) { |