From d6d3d3a40eec23bdd6fc73811cce40ec829c37f3 Mon Sep 17 00:00:00 2001 From: Sude Date: Mon, 27 Feb 2017 22:24:56 +0200 Subject: [PATCH] Fix some issues with GalaxyConfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix compile error: "conversion from ‘time_t {aka long int}’ to ‘const Json::Value’ is ambiguous" Add checks for missing "expires_in" value in Galaxy tokens json --- include/config.h | 14 ++++++++++++-- src/downloader.cpp | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/config.h b/include/config.h index ef66e29..a31573f 100644 --- a/include/config.h +++ b/include/config.h @@ -64,8 +64,9 @@ class GalaxyConfig { std::unique_lock lock(m); bool bExpired = false; + intmax_t time_now = time(NULL); if (this->token_json.isMember("expires_at")) - bExpired = (time(NULL) > this->token_json["expires_at"].asUInt()); + bExpired = (time_now > this->token_json["expires_at"].asLargestInt()); return bExpired; } @@ -91,7 +92,16 @@ class GalaxyConfig { std::unique_lock lock(m); if (!json.isMember("expires_at")) - json["expires_at"] = json["expires_in"].asUInt() + time(NULL); + { + intmax_t time_now = time(NULL); + Json::Value::LargestInt expires_in = 3600; + if (json.isMember("expires_in")) + if (!json["expires_in"].isNull()) + expires_in = json["expires_in"].asLargestInt(); + + Json::Value::LargestInt expires_at = time_now + expires_in; + json["expires_at"] = expires_at; + } this->token_json = json; } diff --git a/src/downloader.cpp b/src/downloader.cpp index 0dfbfbe..05bac41 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -127,7 +127,8 @@ Downloader::Downloader() if (!json.isMember("expires_at")) { std::time_t last_modified = boost::filesystem::last_write_time(Globals::galaxyConf.getFilepath()); - json["expires_at"] = json["expires_in"].asUInt() + last_modified; + Json::Value::LargestInt expires_in = json["expires_in"].asLargestInt(); + json["expires_at"] = expires_in + last_modified; } Globals::galaxyConf.setJSON(json);