aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Littow <sami.littow@qt.io>2022-11-24 08:27:21 +0200
committerSami Littow <sami.littow@qt.io>2022-11-24 08:27:21 +0200
commite9e31d1e843c6156b3085d562e0e36b47e1da259 (patch)
tree7ecc45dcbc58327570f401ce49cb9658102ce355
parent13cea54d190d949f881c089eb8d3ffd04ced5981 (diff)
Expiry date calculation/comparison adjusted
Some Ooopses corrected
-rw-r--r--httpclient.cpp11
-rw-r--r--include/commonsetup.h1
-rw-r--r--include/httpclient.h10
-rw-r--r--licenser.cpp11
-rw-r--r--utils.cpp2
5 files changed, 13 insertions, 22 deletions
diff --git a/httpclient.cpp b/httpclient.cpp
index 83a0914..33329c6 100644
--- a/httpclient.cpp
+++ b/httpclient.cpp
@@ -72,7 +72,6 @@ int HttpClient::sendRequest(std::string &reply, const std::string &payload,
CURL *curl = curl_easy_init();
try {
if (doRequest(curl, request) != 0) {
- m_lastError += "Server not reachable ";
retVal = 1;
}
} catch(...) {
@@ -97,14 +96,14 @@ int HttpClient::sendRequest(std::string &reply, const std::string &payload,
int HttpClient::doRequest(CURL *curl, HttpRequest &request)
{
- /* send all data to this function */
+ // Set all received data to be send to our callback function
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
std::string readBuffer;
- /* we pass our 'chunk' struct to the callback function */
+ // Pass the buffer to a callback
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
- // Set the URL
+ // Set the URL / headers
curl_easy_setopt(curl, CURLOPT_URL, request.url.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, request.headers);
if (!request.payload.empty()) {
@@ -116,11 +115,11 @@ int HttpClient::doRequest(CURL *curl, HttpRequest &request)
}
curl_easy_setopt(curl, CURLOPT_TIMEOUT, SERVER_CONN_TIMEOUT);
- /* get it! */
+ // get it
CURLcode res;
res = curl_easy_perform(curl);
- /* check for errors */
+ // check for errors
if (res != CURLE_OK) {
std::cout << "HTTP transfer failed, URL: " << request.url << std::endl;
m_lastError = curl_easy_strerror(res);
diff --git a/include/commonsetup.h b/include/commonsetup.h
index 1622503..f523216 100644
--- a/include/commonsetup.h
+++ b/include/commonsetup.h
@@ -39,3 +39,4 @@
#define LICENSE_FILE_BASE WORKING_DIR "/lic_"
#define SHA256_HASH_SIZE 32
#define SECS_IN_HOUR 3600
+#define SECS_IN_DAY (SECS_IN_HOUR * 24)
diff --git a/include/httpclient.h b/include/httpclient.h
index a861ae6..6ee1f86 100644
--- a/include/httpclient.h
+++ b/include/httpclient.h
@@ -12,17 +12,7 @@
#define SERVER_CONN_TIMEOUT 10
#if _WIN32
- //#include <windows.h>
#include "curl/curl.h"
- //#pragma comment(lib, "../3rdParty/curl/lib/libcurl.lib")
- //#pragma comment(lib, "ws2_32.lib")
- //#pragma comment(lib, "winmm.lib")
- //pragma comment(lib, "wldap32.lib")
- //#include <winsock2.h>
- //#include <ws2tcpip.h>
- //#include <iphlpapi.h>
- //#include <ws2def.h>
- //#include <io.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
diff --git a/licenser.cpp b/licenser.cpp
index 142164d..35059c5 100644
--- a/licenser.cpp
+++ b/licenser.cpp
@@ -281,9 +281,9 @@ bool Licenser::checkLicenseExpiryDate(std::string &reply, const RequestInfo &req
reply = replyString[e_bad_connection];
return false;
}
- // Expiry date
+ // Expiry date. Add 1 day to expiry date to get the end actually at the beginning of the next day
std::string expDate = license.get("expiry_date");
- std::time_t expEpoch = utils::stringToEpoch(expDate.c_str());
+ std::time_t expEpoch = utils::stringToEpoch(expDate.c_str()) + SECS_IN_DAY;
// Current date
std::time_t current = std::time(0);
// See if the time has expire
@@ -291,14 +291,14 @@ bool Licenser::checkLicenseExpiryDate(std::string &reply, const RequestInfo &req
// License expired
if (request.appName == MOCWRAPPER_APP_NAME) {
// For MOC, allow some leeway time
- int leewayTimeLeft = expEpoch + (license.getInt("leeway_time") * SECS_IN_HOUR) - current;
+ int leewayTimeLeft = expEpoch + (license.getInt("leeway_hours") * SECS_IN_HOUR) - current;
std::cout << "Leeway time left: " << leewayTimeLeft << std::endl;
if (leewayTimeLeft > 0) {
std::stringstream ss;
ss << "Warning: No connection to server. "
<< "Leeway time left: "
<< std::fixed << std::setprecision(1)
- << (float)leewayTimeLeft / (24 * SECS_IN_HOUR) << " days";
+ << (float)leewayTimeLeft / SECS_IN_DAY << " days";
reply = ss.str();
return true;
}
@@ -380,9 +380,10 @@ void Licenser::doHmacHashSha256(const std::string &payload, const std::string &s
}
authKey = ss_result.str();
+ JsonHandler pay(payload);
// Print out the result
- std::cout << "Message: " << payload << std::endl;
+ std::cout << "Message: " << pay.dump(4) << std::endl;
std::cout << "Key: " << secret << std::endl;
std::cout << "HMAC: " << authKey << std::endl;
}
diff --git a/utils.cpp b/utils.cpp
index b60295b..2a8696f 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -83,7 +83,7 @@ std::string getUserHomeDir()
const char* homedir;
#if __linux__ || __APPLE__ || __MACH__
// Linux and Mac
- homedir = std::getenv("PATH");
+ homedir = std::getenv("HOME");
if (homedir == nullptr) {
homedir = getpwuid(getuid())->pw_dir;
}