diff options
author | Alexander Tkachev | 2016-07-26 13:34:12 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | 9d96d40b3d78d987d414e0dc77f43c09ef4421ba (patch) | |
tree | 968e297bab60320d164fb206862ae280711428b5 /backends/cloud/box | |
parent | 2c34864a06f31d1d909f7abe62d8047409fe9f00 (diff) | |
download | scummvm-rg350-9d96d40b3d78d987d414e0dc77f43c09ef4421ba.tar.gz scummvm-rg350-9d96d40b3d78d987d414e0dc77f43c09ef4421ba.tar.bz2 scummvm-rg350-9d96d40b3d78d987d414e0dc77f43c09ef4421ba.zip |
CLOUD: Add JSON-related checks in BoxStorage
Diffstat (limited to 'backends/cloud/box')
-rw-r--r-- | backends/cloud/box/boxstorage.cpp | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/backends/cloud/box/boxstorage.cpp b/backends/cloud/box/boxstorage.cpp index 7d67ba1676..6209de0b70 100644 --- a/backends/cloud/box/boxstorage.cpp +++ b/backends/cloud/box/boxstorage.cpp @@ -119,11 +119,21 @@ void BoxStorage::tokenRefreshed(BoolCallback callback, Networking::JsonResponse if (!json) { warning("BoxStorage: got NULL instead of JSON"); if (callback) (*callback)(BoolResponse(nullptr, false)); + delete callback; + return; + } + + if (!Networking::CurlJsonRequest::jsonIsObject(json, "BoxStorage")) { + if (callback) + (*callback)(BoolResponse(nullptr, false)); + delete json; + delete callback; return; } Common::JSONObject result = json->asObject(); - if (!result.contains("access_token") || !result.contains("refresh_token")) { + if (!Networking::CurlJsonRequest::jsonContainsString(result, "access_token", "BoxStorage") || + !Networking::CurlJsonRequest::jsonContainsString(result, "refresh_token", "BoxStorage")) { warning("BoxStorage: bad response, no token passed"); debug(9, "%s", json->stringify().c_str()); if (callback) @@ -136,6 +146,7 @@ void BoxStorage::tokenRefreshed(BoolCallback callback, Networking::JsonResponse (*callback)(BoolResponse(nullptr, true)); } delete json; + delete callback; } void BoxStorage::codeFlowComplete(BoolResponse response) { @@ -172,6 +183,12 @@ void BoxStorage::infoInnerCallback(StorageInfoCallback outerCallback, Networking return; } + if (!Networking::CurlJsonRequest::jsonIsObject(json, "BoxStorage::infoInnerCallback")) { + delete json; + delete outerCallback; + return; + } + Common::JSONObject info = json->asObject(); Common::String uid, name, email; @@ -180,19 +197,19 @@ void BoxStorage::infoInnerCallback(StorageInfoCallback outerCallback, Networking // can check that "type": "user" // there is also "max_upload_size", "phone" and "avatar_url" - if (info.contains("id") && info.getVal("id")->isString()) + if (Networking::CurlJsonRequest::jsonContainsString(info, "id", "BoxStorage::infoInnerCallback")) uid = info.getVal("id")->asString(); - if (info.contains("name") && info.getVal("name")->isString()) + if (Networking::CurlJsonRequest::jsonContainsString(info, "name", "BoxStorage::infoInnerCallback")) name = info.getVal("name")->asString(); - if (info.contains("login") && info.getVal("login")->isString()) + if (Networking::CurlJsonRequest::jsonContainsString(info, "login", "BoxStorage::infoInnerCallback")) email = info.getVal("login")->asString(); - if (info.contains("space_amount") && info.getVal("space_amount")->isIntegerNumber()) + if (Networking::CurlJsonRequest::jsonContainsIntegerNumber(info, "space_amount", "BoxStorage::infoInnerCallback")) quotaAllocated = info.getVal("space_amount")->asIntegerNumber(); - if (info.contains("space_used") && info.getVal("space_used")->isIntegerNumber()) + if (Networking::CurlJsonRequest::jsonContainsIntegerNumber(info, "space_used", "BoxStorage::infoInnerCallback")) quotaUsed = info.getVal("space_used")->asIntegerNumber(); Common::String username = email; @@ -225,8 +242,12 @@ void BoxStorage::createDirectoryInnerCallback(BoolCallback outerCallback, Networ } if (outerCallback) { - Common::JSONObject info = json->asObject(); - (*outerCallback)(BoolResponse(nullptr, info.contains("id"))); + if (Networking::CurlJsonRequest::jsonIsObject(json, "BoxStorage::createDirectoryInnerCallback")) { + Common::JSONObject info = json->asObject(); + (*outerCallback)(BoolResponse(nullptr, info.contains("id"))); + } else { + (*outerCallback)(BoolResponse(nullptr, false)); + } delete outerCallback; } |