Skip to content

Commit

Permalink
SYNERGY1-1555 maintenance licences (deskflow#7190)
Browse files Browse the repository at this point in the history
* SYNERGY1-1555 Remove unused files

* SYNERGY1-1555 Remove unused function isPermanent

* SYNERGY1-1555 Update SerialKeyType with maintenance type

* SYENRGY1-1555 Add method isMaintenance into SerialKey

* SYNERGY1-1555 Check maintenance licenses

* SYNERGY1-1555 Replace obsolete functions

* SYNERGY1-1555 Fix Linux builds

* Update ChangeLog

* SYNERGY1-1555 Requested changes
  • Loading branch information
SerhiiGadzhilov authored Jun 15, 2022
1 parent de48bb2 commit 8a509f4
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 63 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Bug fixes:

Enhancements:
- #7183 Refactoring for Synergy 3 licenses
- #7190 Maintenance license serial key support

1.14.4
======
Expand Down
44 changes: 38 additions & 6 deletions src/gui/src/LicenseManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,35 @@
#include <utility>
#include <QThread>
#include <QTimer>
#include <QDateTime>
#include <QLocale>

LicenseManager::LicenseManager(AppConfig* appConfig) :
m_AppConfig(appConfig),
m_serialKey(appConfig->edition()) {
namespace {

std::string
getMaintenanceMessage(const SerialKey& serialKey)
{
auto expiration = QDateTime::fromTime_t(serialKey.getExpiration()).date();
QString message = "The license key you used will only work with versions of Synergy released before %1."
"<p>To use this version, you’ll need to renew your Synergy maintenance license. "
"<a href=\"https://symless.com/synergy/account?source=gui\""
"style=\"text-decoration: none; color: #4285F4;\">Renew today</a>.</p>";
auto formatedDate = QLocale("en_US").toString(expiration, "MMM dd yyyy");
return message.arg(formatedDate).toStdString();
}

void
LicenseManager::setSerialKey(SerialKey serialKey, bool acceptExpired)
checkSerialKey(const SerialKey& serialKey, bool acceptExpired)
{
time_t currentTime = ::time(0);
if (serialKey.isMaintenance()) {
auto buildDate = QDateTime::fromString(__TIMESTAMP__).toTime_t();

if (!acceptExpired && serialKey.isExpired(currentTime)) {
if (buildDate > serialKey.getExpiration()) {
throw std::runtime_error(getMaintenanceMessage(serialKey));
}
}

if (!acceptExpired && serialKey.isExpired(::time(nullptr))) {
throw std::runtime_error("Serial key expired");
}

Expand All @@ -42,6 +59,20 @@ LicenseManager::setSerialKey(SerialKey serialKey, bool acceptExpired)
throw std::runtime_error("The serial key is not compatible with the business version of Synergy.");
}
#endif
}

}


LicenseManager::LicenseManager(AppConfig* appConfig) :
m_AppConfig(appConfig),
m_serialKey(appConfig->edition()) {
}

void
LicenseManager::setSerialKey(SerialKey serialKey, bool acceptExpired)
{
checkSerialKey(serialKey, acceptExpired);

if (serialKey != m_serialKey) {
using std::swap;
Expand Down Expand Up @@ -108,6 +139,7 @@ LicenseManager::refresh()
SerialKey serialKey (m_AppConfig->serialKey().toStdString());
setSerialKey(serialKey, true);
} catch (...) {
m_serialKey = SerialKey();
m_AppConfig->clearSerialKey();
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/lib/shared/SerialKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ SerialKey::isTemporary() const
return m_data.keyType.isTemporary();
}

bool
SerialKey::isMaintenance() const
{
return m_data.keyType.isMaintenance();
}

bool
SerialKey::isValid() const
{
Expand Down Expand Up @@ -125,6 +131,12 @@ SerialKey::daysLeft(time_t currentTime) const
return timeLeft / day + daysLeft;
}

time_t
SerialKey::getExpiration() const
{
return m_data.expireTime;
}

int
SerialKey::getSpanLeft(time_t time) const
{
Expand Down
2 changes: 2 additions & 0 deletions src/lib/shared/SerialKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ class SerialKey {
bool isExpired(time_t currentTime) const;
bool isTrial() const;
bool isTemporary() const;
bool isMaintenance() const;
bool isValid() const;
time_t daysLeft(time_t currentTime) const;
time_t getExpiration() const;
int getSpanLeft(time_t time = ::time(0)) const;
Edition edition() const;
const std::string& toString() const;
Expand Down
8 changes: 0 additions & 8 deletions src/lib/shared/SerialKeyParserV3.cpp

This file was deleted.

30 changes: 0 additions & 30 deletions src/lib/shared/SerialKeyParserV3.h

This file was deleted.

18 changes: 6 additions & 12 deletions src/lib/shared/SerialKeyType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

const std::string SerialKeyType::TRIAL = "trial";
const std::string SerialKeyType::SUBSCRIPTION = "subscription";
const std::string SerialKeyType::MAINTENANCE = "maintenance";

SerialKeyType::SerialKeyType()
{
Expand All @@ -28,16 +29,9 @@ SerialKeyType::SerialKeyType()
void
SerialKeyType::setKeyType(const std::string& Type)
{
m_isTrial = false;
m_isTemporary = false;

if (Type == SerialKeyType::TRIAL){
m_isTrial = true;
m_isTemporary = true;
}
else if (Type == SerialKeyType::SUBSCRIPTION){
m_isTemporary = true;
}
m_isTrial = (Type == SerialKeyType::TRIAL);
m_isTemporary = (m_isTrial || (Type == SerialKeyType::SUBSCRIPTION));
m_isMaintenance = (Type == SerialKeyType::MAINTENANCE);
}

bool
Expand All @@ -53,8 +47,8 @@ SerialKeyType::isTemporary() const
}

bool
SerialKeyType::isPermanent() const
SerialKeyType::isMaintenance() const
{
return (!m_isTemporary);
return m_isMaintenance;
}

4 changes: 3 additions & 1 deletion src/lib/shared/SerialKeyType.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ class SerialKeyType
public:
static const std::string TRIAL;
static const std::string SUBSCRIPTION;
static const std::string MAINTENANCE;

SerialKeyType();

void setKeyType(const std::string& Type);
bool isTrial() const;
bool isTemporary() const;
bool isPermanent() const;
bool isMaintenance() const;

private:
bool m_isTrial = false;
bool m_isTemporary = false;
bool m_isMaintenance = false;
};

inline bool
Expand Down
10 changes: 10 additions & 0 deletions src/test/unittests/shared/SerialKeyTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ TEST(SerialKeyTests, isExpiring_expiringV2SubscriptionBasicSerial_returnTrue)
EXPECT_EQ(false, serial.isTrial());
EXPECT_EQ(true, serial.isTemporary());
EXPECT_EQ(true, serial.isExpiring(1));
EXPECT_FALSE(serial.isMaintenance());
}

TEST(SerialKeyTests, isExpiring_expiringV2MentenanceSerial_returnTrue)
{
// {v2;maintenance;basic;Bob;1;email;company name;0;86400}
SerialKey serial("7B76323B6D61696E74656E616E63653B70726F3B736572686969206861647A68696C6F763B313B7365726869694073796D6C6573732E636F6D3B203B303B313635353132343139307D");
EXPECT_FALSE(serial.isTrial());
EXPECT_FALSE(serial.isTemporary());
EXPECT_TRUE(serial.isMaintenance());
}

TEST(SerialKeyTests, isExpired_expiredV2SubscriptionBasicSerial_returnTrue)
Expand Down
12 changes: 6 additions & 6 deletions src/test/unittests/shared/SerialKeyTypeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TEST(SerialKeyTypeTests, TrialTemporaryKeyType_false)
SerialKeyType KeyType;
EXPECT_EQ(false, KeyType.isTrial());
EXPECT_EQ(false, KeyType.isTemporary());
EXPECT_EQ(true, KeyType.isPermanent());
EXPECT_FALSE(KeyType.isMaintenance());
}

TEST(SerialKeyTypeTests, TrialTemporaryKeyType_true)
Expand All @@ -35,7 +35,7 @@ TEST(SerialKeyTypeTests, TrialTemporaryKeyType_true)
KeyType.setKeyType("trial");
EXPECT_EQ(true, KeyType.isTrial());
EXPECT_EQ(true, KeyType.isTemporary());
EXPECT_EQ(false, KeyType.isPermanent());
EXPECT_FALSE(KeyType.isMaintenance());
}

TEST(SerialKeyTypeTests, TemporaryKeyType_true)
Expand All @@ -44,14 +44,14 @@ TEST(SerialKeyTypeTests, TemporaryKeyType_true)
KeyType.setKeyType("subscription");
EXPECT_EQ(false, KeyType.isTrial());
EXPECT_EQ(true, KeyType.isTemporary());
EXPECT_EQ(false, KeyType.isPermanent());
EXPECT_FALSE(KeyType.isMaintenance());
}

TEST(SerialKeyTypeTests, PermanentKeyType_true)
TEST(SerialKeyTypeTests, MaintanenceKeyType_true)
{
SerialKeyType KeyType;
KeyType.setKeyType("");
KeyType.setKeyType("maintenance");
EXPECT_EQ(false, KeyType.isTrial());
EXPECT_EQ(false, KeyType.isTemporary());
EXPECT_EQ(true, KeyType.isPermanent());
EXPECT_TRUE(KeyType.isMaintenance());
}

0 comments on commit 8a509f4

Please sign in to comment.