diff options
| author | Alexander Tkachev | 2016-07-26 14:13:38 +0600 | 
|---|---|---|
| committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 | 
| commit | 364c74df930633bf897cacf391f6dc24dbc183b8 (patch) | |
| tree | 29b11a84de32740ce1aaa969875dbdec7c203bd1 | |
| parent | 6be736b5ed92800e1cd329d0de4ed0bb7ff2ea38 (diff) | |
| download | scummvm-rg350-364c74df930633bf897cacf391f6dc24dbc183b8.tar.gz scummvm-rg350-364c74df930633bf897cacf391f6dc24dbc183b8.tar.bz2 scummvm-rg350-364c74df930633bf897cacf391f6dc24dbc183b8.zip  | |
CLOUD: Update DropboxStorage
JSON checks added.
| -rw-r--r-- | backends/cloud/dropbox/dropboxstorage.cpp | 39 | 
1 files changed, 24 insertions, 15 deletions
diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp index 789f6b497c..d12070316b 100644 --- a/backends/cloud/dropbox/dropboxstorage.cpp +++ b/backends/cloud/dropbox/dropboxstorage.cpp @@ -92,25 +92,34 @@ void DropboxStorage::getAccessToken(Common::String code) {  void DropboxStorage::codeFlowComplete(Networking::JsonResponse response) {  	Common::JSONValue *json = (Common::JSONValue *)response.value; -	if (json) { -		Common::JSONObject result = json->asObject(); -		if (!result.contains("access_token") || !result.contains("uid")) { -			warning("DropboxStorage: bad response, no token/uid passed"); -			debug(9, "%s", json->stringify(true).c_str()); -			CloudMan.removeStorage(this); -		} else { -			_token = result.getVal("access_token")->asString(); -			_uid = result.getVal("uid")->asString(); -			ConfMan.removeKey("dropbox_code", ConfMan.kCloudDomain); -			CloudMan.replaceStorage(this, kStorageDropboxId); -			ConfMan.flushToDisk(); -		} +	if (json == nullptr) { +		debug(9, "DropboxStorage::codeFlowComplete: got NULL instead of JSON!"); +		CloudMan.removeStorage(this); +		return; +	} +	if (!json->isObject()) { +		debug(9, "DropboxStorage::codeFlowComplete: Passed JSON is not an object!"); +		CloudMan.removeStorage(this);  		delete json; -	} else { -		debug(9, "DropboxStorage::codeFlowComplete: got NULL instead of JSON!"); +		return; +	} + +	Common::JSONObject result = json->asObject(); +	if (!Networking::CurlJsonRequest::jsonContainsString(result, "access_token", "DropboxStorage::codeFlowComplete") || +		!Networking::CurlJsonRequest::jsonContainsString(result, "uid", "DropboxStorage::codeFlowComplete")) { +		warning("DropboxStorage: bad response, no token/uid passed"); +		debug(9, "%s", json->stringify(true).c_str());  		CloudMan.removeStorage(this); +	} else { +		_token = result.getVal("access_token")->asString(); +		_uid = result.getVal("uid")->asString(); +		ConfMan.removeKey("dropbox_code", ConfMan.kCloudDomain); +		CloudMan.replaceStorage(this, kStorageDropboxId); +		ConfMan.flushToDisk();  	} + +	delete json;  }  void DropboxStorage::codeFlowFailed(Networking::ErrorResponse error) {  | 
