License notise has been corrected.
This commit is contained in:
parent
2a8e696d53
commit
1d43ab0f7c
6 changed files with 297 additions and 285 deletions
|
|
@ -30,16 +30,10 @@ ActivationDialog::ActivationDialog(QWidget* parent, AppConfig& appConfig,
|
||||||
|
|
||||||
void ActivationDialog::refreshSerialKey()
|
void ActivationDialog::refreshSerialKey()
|
||||||
{
|
{
|
||||||
ui->m_pTextEditSerialKey->setText(m_appConfig->serialKey());
|
ui->m_pTextEditSerialKey->setText(m_appConfig->serialKey());
|
||||||
ui->m_pTextEditSerialKey->setFocus();
|
ui->m_pTextEditSerialKey->setFocus();
|
||||||
ui->m_pTextEditSerialKey->moveCursor(QTextCursor::End);
|
ui->m_pTextEditSerialKey->moveCursor(QTextCursor::End);
|
||||||
ui->m_trialLabel->setText(tr("<html><head/><body><p>Your trial has "
|
ui->m_trialLabel->setText(tr(m_LicenseManager->getLicenseNotice().toStdString().c_str()));
|
||||||
"expired. <a href=\"https://symless.com/"
|
|
||||||
"synergy/trial/thanks?id=%1\"><span "
|
|
||||||
"style=\"text-decoration: underline; "
|
|
||||||
"color:#0000ff;\">Buy now!</span></a>"
|
|
||||||
"</p></body></html>")
|
|
||||||
.arg (m_appConfig->serialKey()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ActivationDialog::~ActivationDialog()
|
ActivationDialog::~ActivationDialog()
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,10 @@ LicenseManager::setSerialKey(SerialKey serialKey, bool acceptExpired)
|
||||||
(m_serialKey.toString()));
|
(m_serialKey.toString()));
|
||||||
emit serialKeyChanged(m_serialKey);
|
emit serialKeyChanged(m_serialKey);
|
||||||
|
|
||||||
emit showLicenseNotice(getLicenseNotice());
|
emit showLicenseNotice(getLicenseNotice());
|
||||||
if (m_serialKey.isExpired(currentTime)) {
|
if (m_serialKey.isExpired(currentTime)) {
|
||||||
emit LicenseExpired();
|
emit LicenseExpired();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_serialKey.edition() != serialKey.edition()) {
|
if (m_serialKey.edition() != serialKey.edition()) {
|
||||||
m_AppConfig->setEdition(m_serialKey.edition());
|
m_AppConfig->setEdition(m_serialKey.edition());
|
||||||
|
|
@ -101,7 +101,8 @@ LicenseManager::serialKey() const
|
||||||
return m_serialKey;
|
return m_serialKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LicenseManager::refresh()
|
void
|
||||||
|
LicenseManager::refresh()
|
||||||
{
|
{
|
||||||
if (!m_AppConfig->serialKey().isEmpty()) {
|
if (!m_AppConfig->serialKey().isEmpty()) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -112,11 +113,12 @@ void LicenseManager::refresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_serialKey.isExpired(::time(0))) {
|
if (m_serialKey.isExpired(::time(0))) {
|
||||||
emit LicenseExpired();
|
emit LicenseExpired();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LicenseManager::skipActivation()
|
void
|
||||||
|
LicenseManager::skipActivation()
|
||||||
{
|
{
|
||||||
notifyActivation ("skip:unknown");
|
notifyActivation ("skip:unknown");
|
||||||
}
|
}
|
||||||
|
|
@ -124,7 +126,7 @@ void LicenseManager::skipActivation()
|
||||||
QString
|
QString
|
||||||
LicenseManager::getEditionName(Edition const edition, bool trial)
|
LicenseManager::getEditionName(Edition const edition, bool trial)
|
||||||
{
|
{
|
||||||
std::string name ("Synergy 1");
|
std::string name ("Synergy 1");
|
||||||
switch (edition) {
|
switch (edition) {
|
||||||
case kUnregistered:
|
case kUnregistered:
|
||||||
name += " (UNREGISTERED)";
|
name += " (UNREGISTERED)";
|
||||||
|
|
@ -141,7 +143,8 @@ LicenseManager::getEditionName(Edition const edition, bool trial)
|
||||||
return QString::fromUtf8 (name.c_str(), static_cast<int>(name.size()));
|
return QString::fromUtf8 (name.c_str(), static_cast<int>(name.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LicenseManager::notifyActivation(QString identity)
|
void
|
||||||
|
LicenseManager::notifyActivation(QString identity)
|
||||||
{
|
{
|
||||||
ActivationNotifier* notifier = new ActivationNotifier();
|
ActivationNotifier* notifier = new ActivationNotifier();
|
||||||
notifier->setIdentity(identity);
|
notifier->setIdentity(identity);
|
||||||
|
|
@ -157,84 +160,78 @@ void LicenseManager::notifyActivation(QString identity)
|
||||||
QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LicenseManager::getLicenseNotice() const
|
QString
|
||||||
|
LicenseManager::getLicenseNotice() const
|
||||||
{
|
{
|
||||||
QString Notice;
|
QString Notice;
|
||||||
|
|
||||||
if (m_serialKey.isTemporary()){
|
if (m_serialKey.isTemporary()){
|
||||||
if (m_serialKey.isTrial()){
|
if (m_serialKey.isTrial()){
|
||||||
Notice = getTrialNotice();
|
Notice = getTrialNotice();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Notice = getTemporaryNotice();
|
Notice = getTemporaryNotice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Notice;
|
return Notice;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LicenseManager::getTrialNotice() const
|
QString
|
||||||
|
LicenseManager::getTrialNotice() const
|
||||||
{
|
{
|
||||||
QString Notice;
|
QString Notice;
|
||||||
|
|
||||||
if (m_serialKey.isExpired(::time(0))){
|
if (m_serialKey.isExpired(::time(0))){
|
||||||
Notice = "<html><head/><body><p>Your %1 trial has expired. <a href="
|
Notice = "<html><head/><body><p>Your %1 trial has expired. <a href="
|
||||||
"\"https://symless.com/synergy/trial/thanks?id=%2\">"
|
"\"https://members.symless.com/purchase\">"
|
||||||
"<span style=\"text-decoration: underline;color:#0000ff;\">"
|
"<span style=\"text-decoration: underline;color:#0000ff;\">"
|
||||||
"Buy now!</span></a></p></body></html>";
|
"Buy now!</span></a></p></body></html>";
|
||||||
Notice = Notice
|
Notice = Notice.arg(LicenseManager::getEditionName(activeEdition()));
|
||||||
.arg(LicenseManager::getEditionName(activeEdition()))
|
}
|
||||||
.arg(QString::fromStdString(m_serialKey.toString()));
|
else{
|
||||||
}
|
Notice = "<html><head/><body><p><span style=\""
|
||||||
else{
|
"font-weight:600;\">%1</span> day%3 of "
|
||||||
time_t daysLeft = m_serialKey.daysLeft(::time(0));
|
"your %2 trial remain%5. <a href="
|
||||||
Notice = "<html><head/><body><p><span style=\""
|
"\"https://members.symless.com/purchase\">"
|
||||||
"font-weight:600;\">%1</span> day%3 of "
|
"<span style=\"text-decoration: underline;"
|
||||||
"your %2 trial remain%5. <a href="
|
" color:#0000ff;\">Buy now!</span></a>"
|
||||||
"\"https://symless.com/synergy/trial/thanks?id=%4\">"
|
"</p></body></html>";
|
||||||
"<span style=\"text-decoration: underline;"
|
|
||||||
" color:#0000ff;\">Buy now!</span></a>"
|
|
||||||
"</p></body></html>";
|
|
||||||
Notice = Notice
|
|
||||||
.arg (daysLeft)
|
|
||||||
.arg (LicenseManager::getEditionName(activeEdition()))
|
|
||||||
.arg ((daysLeft == 1) ? "" : "s")
|
|
||||||
.arg (QString::fromStdString(m_serialKey.toString()))
|
|
||||||
.arg ((daysLeft == 1) ? "s" : "");
|
|
||||||
}
|
|
||||||
|
|
||||||
return Notice;
|
time_t daysLeft = m_serialKey.daysLeft(::time(0));
|
||||||
|
Notice = Notice
|
||||||
|
.arg (daysLeft)
|
||||||
|
.arg (LicenseManager::getEditionName(activeEdition()))
|
||||||
|
.arg ((daysLeft == 1) ? "" : "s")
|
||||||
|
.arg ((daysLeft == 1) ? "s" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Notice;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LicenseManager::getTemporaryNotice() const
|
QString
|
||||||
|
LicenseManager::getTemporaryNotice() const
|
||||||
{
|
{
|
||||||
QString Notice;
|
QString Notice;
|
||||||
|
|
||||||
if (m_serialKey.isExpired(::time(0))){
|
if (m_serialKey.isExpired(::time(0))) {
|
||||||
Notice = "<html><head/><body><p>Your %1 has expired. <a href="
|
Notice = "<html><head/><body><p>Your license has expired. <a href="
|
||||||
"\"https://symless.com/synergy/trial/thanks?id=%2\">"
|
"\"https://members.symless.com/purchase\">"
|
||||||
"<span style=\"text-decoration: underline;color:#0000ff;\">"
|
"<span style=\"text-decoration: underline;color:#0000ff;\">"
|
||||||
"Buy now!</span></a></p></body></html>";
|
"Renew now!</span></a></p></body></html>";
|
||||||
Notice = Notice
|
}
|
||||||
.arg(LicenseManager::getEditionName(activeEdition()))
|
else if (m_serialKey.isExpiring(::time(0))) {
|
||||||
.arg(QString::fromStdString(m_serialKey.toString()));
|
Notice = "<html><head/><body><p><span style=\""
|
||||||
}
|
"font-weight:600;\">%1</span> day%2 / "
|
||||||
else if (m_serialKey.isExpiring(::time(0))){
|
"before your license expires.<a href="
|
||||||
time_t daysLeft = m_serialKey.daysLeft(::time(0));
|
"\"https://members.symless.com/purchase\">"
|
||||||
Notice = "<html><head/><body><p><span style=\""
|
"<span style=\"text-decoration: underline;"
|
||||||
"font-weight:600;\">%1</span> day%3 of "
|
" color:#0000ff;\">Renew now!</span></a>"
|
||||||
"your %2 remain%5. <a href="
|
"</p></body></html>";
|
||||||
"\"https://symless.com/synergy/trial/thanks?id=%4\">"
|
|
||||||
"<span style=\"text-decoration: underline;"
|
|
||||||
" color:#0000ff;\">Buy now!</span></a>"
|
|
||||||
"</p></body></html>";
|
|
||||||
Notice = Notice
|
|
||||||
.arg (daysLeft)
|
|
||||||
.arg (LicenseManager::getEditionName(activeEdition()))
|
|
||||||
.arg ((daysLeft == 1) ? "" : "s")
|
|
||||||
.arg (QString::fromStdString(m_serialKey.toString()))
|
|
||||||
.arg ((daysLeft == 1) ? "s" : "");
|
|
||||||
}
|
|
||||||
|
|
||||||
return Notice;
|
time_t daysLeft = m_serialKey.daysLeft(::time(0));
|
||||||
|
Notice = Notice.arg (daysLeft).arg ((daysLeft == 1) ? "" : "s");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Notice;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,96 +27,97 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
static std::string hexEncode (std::string const& str);
|
||||||
|
|
||||||
SerialKey::SerialKey(Edition edition):
|
SerialKey::SerialKey(Edition edition):
|
||||||
m_userLimit(1),
|
m_userLimit(1),
|
||||||
m_warnTime(ULLONG_MAX),
|
m_warnTime(ULLONG_MAX),
|
||||||
m_expireTime(ULLONG_MAX),
|
m_expireTime(ULLONG_MAX),
|
||||||
m_edition(edition),
|
m_edition(edition),
|
||||||
m_KeyType()
|
m_KeyType()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SerialKey::SerialKey(std::string serial) :
|
SerialKey::SerialKey(std::string serial) :
|
||||||
m_userLimit(1),
|
m_userLimit(1),
|
||||||
m_warnTime(0),
|
m_warnTime(0),
|
||||||
m_expireTime(0),
|
m_expireTime(0),
|
||||||
m_edition(kBasic),
|
m_edition(kBasic),
|
||||||
m_KeyType()
|
m_KeyType()
|
||||||
{
|
{
|
||||||
string plainText = decode(serial);
|
string plainText = decode(serial);
|
||||||
bool valid = false;
|
bool valid = false;
|
||||||
if (!plainText.empty()) {
|
if (!plainText.empty()) {
|
||||||
valid = parse(plainText);
|
valid = parse(plainText);
|
||||||
}
|
}
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
throw std::runtime_error ("Invalid serial key");
|
throw std::runtime_error ("Invalid serial key");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SerialKey::isExpiring(time_t currentTime) const
|
SerialKey::isExpiring(time_t currentTime) const
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (isTemporary()) {
|
if (isTemporary()) {
|
||||||
unsigned long long currentTimeAsLL = static_cast<unsigned long long>(currentTime);
|
unsigned long long currentTimeAsLL = static_cast<unsigned long long>(currentTime);
|
||||||
if ((m_warnTime <= currentTimeAsLL) && (currentTimeAsLL < m_expireTime)) {
|
if ((m_warnTime <= currentTimeAsLL) && (currentTimeAsLL < m_expireTime)) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SerialKey::isExpired(time_t currentTime) const
|
SerialKey::isExpired(time_t currentTime) const
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
std::cout<<"Current time = "<<static_cast<unsigned long long>(currentTime)<<std::endl;
|
std::cout<<"Current time = "<<static_cast<unsigned long long>(currentTime)<<std::endl;
|
||||||
|
|
||||||
if (isTemporary()) {
|
if (isTemporary()) {
|
||||||
unsigned long long currentTimeAsLL = static_cast<unsigned long long>(currentTime);
|
unsigned long long currentTimeAsLL = static_cast<unsigned long long>(currentTime);
|
||||||
if (m_expireTime <= currentTimeAsLL) {
|
if (m_expireTime <= currentTimeAsLL) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SerialKey::isTrial() const
|
SerialKey::isTrial() const
|
||||||
{
|
{
|
||||||
return m_KeyType.isTrial();
|
return m_KeyType.isTrial();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SerialKey::isTemporary() const
|
SerialKey::isTemporary() const
|
||||||
{
|
{
|
||||||
return m_KeyType.isTemporary();
|
return m_KeyType.isTemporary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Edition
|
Edition
|
||||||
SerialKey::edition() const
|
SerialKey::edition() const
|
||||||
{
|
{
|
||||||
return m_edition;
|
return m_edition;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
SerialKey::editionString() const
|
SerialKey::editionString() const
|
||||||
{
|
{
|
||||||
switch (edition()) {
|
switch (edition()) {
|
||||||
case kBasic:
|
case kBasic:
|
||||||
return "basic";
|
return "basic";
|
||||||
case kPro:
|
case kPro:
|
||||||
return "pro";
|
return "pro";
|
||||||
default: {
|
default: {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << static_cast<int>(edition());
|
oss << static_cast<int>(edition());
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string
|
static std::string
|
||||||
|
|
@ -135,145 +136,145 @@ hexEncode (std::string const& str) {
|
||||||
std::string
|
std::string
|
||||||
SerialKey::toString() const
|
SerialKey::toString() const
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "{";
|
oss << "{";
|
||||||
if (isTemporary()) {
|
if (isTemporary()) {
|
||||||
if (isTrial()){
|
if (isTrial()){
|
||||||
oss << "v2;" << SerialKeyType::TRIAL << ";";
|
oss << "v2;" << SerialKeyType::TRIAL << ";";
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
oss << "v2;" << SerialKeyType::TEMPORARY << ";";
|
oss << "v2;" << SerialKeyType::TEMPORARY << ";";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
oss << "v1;";
|
oss << "v1;";
|
||||||
}
|
}
|
||||||
oss << editionString() << ";";
|
oss << editionString() << ";";
|
||||||
oss << m_name << ";";
|
oss << m_name << ";";
|
||||||
oss << m_userLimit << ";";
|
oss << m_userLimit << ";";
|
||||||
oss << m_email << ";";
|
oss << m_email << ";";
|
||||||
oss << m_company << ";";
|
oss << m_company << ";";
|
||||||
oss << (isTemporary() ? m_warnTime : 0) << ";";
|
oss << (isTemporary() ? m_warnTime : 0) << ";";
|
||||||
oss << (isTemporary() ? m_expireTime : 0);
|
oss << (isTemporary() ? m_expireTime : 0);
|
||||||
oss << "}";
|
oss << "}";
|
||||||
return hexEncode(oss.str());
|
return hexEncode(oss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t
|
time_t
|
||||||
SerialKey::daysLeft(time_t currentTime) const
|
SerialKey::daysLeft(time_t currentTime) const
|
||||||
{
|
{
|
||||||
unsigned long long timeLeft = 0;
|
unsigned long long timeLeft = 0;
|
||||||
unsigned long long const day = 60 * 60 * 24;
|
unsigned long long const day = 60 * 60 * 24;
|
||||||
|
|
||||||
unsigned long long currentTimeAsLL = static_cast<unsigned long long>(currentTime);
|
unsigned long long currentTimeAsLL = static_cast<unsigned long long>(currentTime);
|
||||||
if (currentTimeAsLL < m_expireTime) {
|
if (currentTimeAsLL < m_expireTime) {
|
||||||
timeLeft = m_expireTime - currentTimeAsLL;
|
timeLeft = m_expireTime - currentTimeAsLL;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long long daysLeft = 0;
|
unsigned long long daysLeft = 0;
|
||||||
daysLeft = timeLeft % day != 0 ? 1 : 0;
|
daysLeft = timeLeft % day != 0 ? 1 : 0;
|
||||||
|
|
||||||
return timeLeft / day + daysLeft;
|
return timeLeft / day + daysLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
SerialKey::email() const
|
SerialKey::email() const
|
||||||
{
|
{
|
||||||
return m_email;
|
return m_email;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
SerialKey::decode(const std::string& serial)
|
SerialKey::decode(const std::string& serial)
|
||||||
{
|
{
|
||||||
static const char* const lut = "0123456789ABCDEF";
|
static const char* const lut = "0123456789ABCDEF";
|
||||||
string output;
|
string output;
|
||||||
size_t len = serial.length();
|
size_t len = serial.length();
|
||||||
if (len & 1) {
|
if (len & 1) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
output.reserve(len / 2);
|
output.reserve(len / 2);
|
||||||
for (size_t i = 0; i < len; i += 2) {
|
for (size_t i = 0; i < len; i += 2) {
|
||||||
|
|
||||||
char a = serial[i];
|
char a = serial[i];
|
||||||
char b = serial[i + 1];
|
char b = serial[i + 1];
|
||||||
|
|
||||||
const char* p = std::lower_bound(lut, lut + 16, a);
|
const char* p = std::lower_bound(lut, lut + 16, a);
|
||||||
const char* q = std::lower_bound(lut, lut + 16, b);
|
const char* q = std::lower_bound(lut, lut + 16, b);
|
||||||
|
|
||||||
if (*q != b || *p != a) {
|
if (*q != b || *p != a) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
output.push_back(static_cast<char>(((p - lut) << 4) | (q - lut)));
|
output.push_back(static_cast<char>(((p - lut) << 4) | (q - lut)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SerialKey::parse(std::string plainSerial)
|
SerialKey::parse(std::string plainSerial)
|
||||||
{
|
{
|
||||||
string parityStart = plainSerial.substr(0, 1);
|
string parityStart = plainSerial.substr(0, 1);
|
||||||
string parityEnd = plainSerial.substr(plainSerial.length() - 1, 1);
|
string parityEnd = plainSerial.substr(plainSerial.length() - 1, 1);
|
||||||
|
|
||||||
bool valid = false;
|
bool valid = false;
|
||||||
|
|
||||||
// check for parity chars { and }, record parity result, then remove them.
|
// check for parity chars { and }, record parity result, then remove them.
|
||||||
if (parityStart == "{" && parityEnd == "}") {
|
if (parityStart == "{" && parityEnd == "}") {
|
||||||
plainSerial = plainSerial.substr(1, plainSerial.length() - 2);
|
plainSerial = plainSerial.substr(1, plainSerial.length() - 2);
|
||||||
|
|
||||||
// tokenize serialised subscription.
|
// tokenize serialised subscription.
|
||||||
vector<string> parts;
|
vector<string> parts;
|
||||||
std::string::size_type pos = 0;
|
std::string::size_type pos = 0;
|
||||||
bool look = true;
|
bool look = true;
|
||||||
while (look) {
|
while (look) {
|
||||||
std::string::size_type start = pos;
|
std::string::size_type start = pos;
|
||||||
pos = plainSerial.find(";", pos);
|
pos = plainSerial.find(";", pos);
|
||||||
if (pos == string::npos) {
|
if (pos == string::npos) {
|
||||||
pos = plainSerial.length();
|
pos = plainSerial.length();
|
||||||
look = false;
|
look = false;
|
||||||
}
|
}
|
||||||
parts.push_back(plainSerial.substr(start, pos - start));
|
parts.push_back(plainSerial.substr(start, pos - start));
|
||||||
pos += 1;
|
pos += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((parts.size() == 8)
|
if ((parts.size() == 8)
|
||||||
&& (parts.at(0).find("v1") != string::npos)) {
|
&& (parts.at(0).find("v1") != string::npos)) {
|
||||||
// e.g.: {v1;basic;Bob;1;email;company name;1398297600;1398384000}
|
// e.g.: {v1;basic;Bob;1;email;company name;1398297600;1398384000}
|
||||||
m_edition = parseEdition(parts.at(1));
|
m_edition = parseEdition(parts.at(1));
|
||||||
m_name = parts.at(2);
|
m_name = parts.at(2);
|
||||||
sscanf(parts.at(3).c_str(), "%d", &m_userLimit);
|
sscanf(parts.at(3).c_str(), "%d", &m_userLimit);
|
||||||
m_email = parts.at(4);
|
m_email = parts.at(4);
|
||||||
m_company = parts.at(5);
|
m_company = parts.at(5);
|
||||||
sscanf(parts.at(6).c_str(), "%lld", &m_warnTime);
|
sscanf(parts.at(6).c_str(), "%lld", &m_warnTime);
|
||||||
sscanf(parts.at(7).c_str(), "%lld", &m_expireTime);
|
sscanf(parts.at(7).c_str(), "%lld", &m_expireTime);
|
||||||
valid = true;
|
valid = true;
|
||||||
}
|
}
|
||||||
else if ((parts.size() == 9)
|
else if ((parts.size() == 9)
|
||||||
&& (parts.at(0).find("v2") != string::npos)) {
|
&& (parts.at(0).find("v2") != string::npos)) {
|
||||||
// e.g.: {v2;trial;basic;Bob;1;email;company name;1398297600;1398384000}
|
// e.g.: {v2;trial;basic;Bob;1;email;company name;1398297600;1398384000}
|
||||||
m_KeyType.setKeyType(parts.at(1));
|
m_KeyType.setKeyType(parts.at(1));
|
||||||
m_edition = parseEdition(parts.at(2));
|
m_edition = parseEdition(parts.at(2));
|
||||||
m_name = parts.at(3);
|
m_name = parts.at(3);
|
||||||
sscanf(parts.at(4).c_str(), "%d", &m_userLimit);
|
sscanf(parts.at(4).c_str(), "%d", &m_userLimit);
|
||||||
m_email = parts.at(5);
|
m_email = parts.at(5);
|
||||||
m_company = parts.at(6);
|
m_company = parts.at(6);
|
||||||
sscanf(parts.at(7).c_str(), "%lld", &m_warnTime);
|
sscanf(parts.at(7).c_str(), "%lld", &m_warnTime);
|
||||||
sscanf(parts.at(8).c_str(), "%lld", &m_expireTime);
|
sscanf(parts.at(8).c_str(), "%lld", &m_expireTime);
|
||||||
valid = true;
|
valid = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
Edition
|
Edition
|
||||||
SerialKey::parseEdition(std::string const& editionStr)
|
SerialKey::parseEdition(std::string const& editionStr)
|
||||||
{
|
{
|
||||||
Edition e = kBasic;
|
Edition e = kBasic;
|
||||||
if (editionStr == "pro") {
|
if (editionStr == "pro") {
|
||||||
e = kPro;
|
e = kPro;
|
||||||
}
|
}
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,62 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2015 Synergy Seamless Inc.
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "SerialKeyType.h"
|
#include "SerialKeyType.h"
|
||||||
|
|
||||||
const std::string SerialKeyType::TRIAL = "trial";
|
const std::string SerialKeyType::TRIAL = "trial";
|
||||||
const std::string SerialKeyType::TEMPORARY = "temp";
|
const std::string SerialKeyType::TEMPORARY = "temp";
|
||||||
|
|
||||||
SerialKeyType::SerialKeyType() :
|
SerialKeyType::SerialKeyType() :
|
||||||
m_isTrial(false),
|
m_isTrial(false),
|
||||||
m_isTemporary(false)
|
m_isTemporary(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialKeyType::setKeyType(const std::string& Type)
|
void
|
||||||
|
SerialKeyType::setKeyType(const std::string& Type)
|
||||||
{
|
{
|
||||||
m_isTrial = false;
|
m_isTrial = false;
|
||||||
m_isTemporary = false;
|
m_isTemporary = false;
|
||||||
|
|
||||||
if (Type == SerialKeyType::TRIAL){
|
if (Type == SerialKeyType::TRIAL){
|
||||||
m_isTrial = true;
|
m_isTrial = true;
|
||||||
m_isTemporary = true;
|
m_isTemporary = true;
|
||||||
}
|
}
|
||||||
else if (Type == SerialKeyType::TEMPORARY){
|
else if (Type == SerialKeyType::TEMPORARY){
|
||||||
m_isTemporary = true;
|
m_isTemporary = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SerialKeyType::isTrial() const
|
bool
|
||||||
|
SerialKeyType::isTrial() const
|
||||||
{
|
{
|
||||||
return m_isTrial;
|
return m_isTrial;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SerialKeyType::isTemporary() const
|
bool
|
||||||
|
SerialKeyType::isTemporary() const
|
||||||
{
|
{
|
||||||
return m_isTemporary;
|
return m_isTemporary;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SerialKeyType::isPermanent() const
|
bool
|
||||||
|
SerialKeyType::isPermanent() const
|
||||||
{
|
{
|
||||||
return (!m_isTemporary);
|
return (!m_isTemporary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,40 +14,38 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef SERIALKEYTYPE_H
|
#pragma once
|
||||||
#define SERIALKEYTYPE_H
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class SerialKeyType
|
class SerialKeyType
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
friend bool operator== (SerialKeyType const&, SerialKeyType const&);
|
friend bool operator== (SerialKeyType const&, SerialKeyType const&);
|
||||||
public:
|
public:
|
||||||
static const std::string TRIAL;
|
static const std::string TRIAL;
|
||||||
static const std::string TEMPORARY;
|
static const std::string TEMPORARY;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SerialKeyType();
|
SerialKeyType();
|
||||||
|
|
||||||
void setKeyType(const std::string& Type);
|
void setKeyType(const std::string& Type);
|
||||||
bool isTrial() const;
|
bool isTrial() const;
|
||||||
bool isTemporary() const;
|
bool isTemporary() const;
|
||||||
bool isPermanent() const;
|
bool isPermanent() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_isTrial;
|
bool m_isTrial;
|
||||||
bool m_isTemporary;
|
bool m_isTemporary;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
operator== (SerialKeyType const& lhs, SerialKeyType const& rhs) {
|
operator== (SerialKeyType const& lhs, SerialKeyType const& rhs) {
|
||||||
return (lhs.m_isTrial == rhs.m_isTrial) && (lhs.m_isTemporary == rhs.m_isTemporary);
|
return (lhs.m_isTrial == rhs.m_isTrial) && (lhs.m_isTemporary == rhs.m_isTemporary);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
operator!= (SerialKeyType const& lhs, SerialKeyType const& rhs) {
|
operator!= (SerialKeyType const& lhs, SerialKeyType const& rhs) {
|
||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // SERIALKEYTYPE_H
|
|
||||||
|
|
|
||||||
|
|
@ -23,35 +23,35 @@
|
||||||
|
|
||||||
TEST(SerialKeyTypeTests, TrialTemporaryKeyType_false)
|
TEST(SerialKeyTypeTests, TrialTemporaryKeyType_false)
|
||||||
{
|
{
|
||||||
SerialKeyType KeyType;
|
SerialKeyType KeyType;
|
||||||
EXPECT_EQ(false, KeyType.isTrial());
|
EXPECT_EQ(false, KeyType.isTrial());
|
||||||
EXPECT_EQ(false, KeyType.isTemporary());
|
EXPECT_EQ(false, KeyType.isTemporary());
|
||||||
EXPECT_EQ(true, KeyType.isPermanent());
|
EXPECT_EQ(true, KeyType.isPermanent());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SerialKeyTypeTests, TrialTemporaryKeyType_true)
|
TEST(SerialKeyTypeTests, TrialTemporaryKeyType_true)
|
||||||
{
|
{
|
||||||
SerialKeyType KeyType;
|
SerialKeyType KeyType;
|
||||||
KeyType.setKeyType("trial");
|
KeyType.setKeyType("trial");
|
||||||
EXPECT_EQ(true, KeyType.isTrial());
|
EXPECT_EQ(true, KeyType.isTrial());
|
||||||
EXPECT_EQ(true, KeyType.isTemporary());
|
EXPECT_EQ(true, KeyType.isTemporary());
|
||||||
EXPECT_EQ(false, KeyType.isPermanent());
|
EXPECT_EQ(false, KeyType.isPermanent());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SerialKeyTypeTests, TemporaryKeyType_true)
|
TEST(SerialKeyTypeTests, TemporaryKeyType_true)
|
||||||
{
|
{
|
||||||
SerialKeyType KeyType;
|
SerialKeyType KeyType;
|
||||||
KeyType.setKeyType("temp");
|
KeyType.setKeyType("temp");
|
||||||
EXPECT_EQ(false, KeyType.isTrial());
|
EXPECT_EQ(false, KeyType.isTrial());
|
||||||
EXPECT_EQ(true, KeyType.isTemporary());
|
EXPECT_EQ(true, KeyType.isTemporary());
|
||||||
EXPECT_EQ(false, KeyType.isPermanent());
|
EXPECT_EQ(false, KeyType.isPermanent());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SerialKeyTypeTests, PermanentKeyType_true)
|
TEST(SerialKeyTypeTests, PermanentKeyType_true)
|
||||||
{
|
{
|
||||||
SerialKeyType KeyType;
|
SerialKeyType KeyType;
|
||||||
KeyType.setKeyType("");
|
KeyType.setKeyType("");
|
||||||
EXPECT_EQ(false, KeyType.isTrial());
|
EXPECT_EQ(false, KeyType.isTrial());
|
||||||
EXPECT_EQ(false, KeyType.isTemporary());
|
EXPECT_EQ(false, KeyType.isTemporary());
|
||||||
EXPECT_EQ(true, KeyType.isPermanent());
|
EXPECT_EQ(true, KeyType.isPermanent());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue