SYNERGY-324 Replace tabs with spaces.
This commit is contained in:
parent
836e0444d3
commit
90fce9af2a
6 changed files with 319 additions and 319 deletions
|
|
@ -30,10 +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(m_LicenseManager->getLicenseNotice().toStdString().c_str()));
|
ui->m_trialLabel->setText(tr(m_LicenseManager->getLicenseNotice().toStdString().c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ActivationDialog::~ActivationDialog()
|
ActivationDialog::~ActivationDialog()
|
||||||
|
|
@ -43,15 +43,15 @@ ActivationDialog::~ActivationDialog()
|
||||||
|
|
||||||
void ActivationDialog::reject()
|
void ActivationDialog::reject()
|
||||||
{
|
{
|
||||||
if (m_LicenseManager->activeEdition() == kUnregistered) {
|
if (m_LicenseManager->activeEdition() == kUnregistered) {
|
||||||
CancelActivationDialog cancelActivationDialog(this);
|
CancelActivationDialog cancelActivationDialog(this);
|
||||||
if (QDialog::Accepted == cancelActivationDialog.exec()) {
|
if (QDialog::Accepted == cancelActivationDialog.exec()) {
|
||||||
m_LicenseManager->skipActivation();
|
m_LicenseManager->skipActivation();
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QDialog::reject();
|
QDialog::reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActivationDialog::accept()
|
void ActivationDialog::accept()
|
||||||
|
|
|
||||||
|
|
@ -23,208 +23,208 @@
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
LicenseManager::LicenseManager(AppConfig* appConfig) :
|
LicenseManager::LicenseManager(AppConfig* appConfig) :
|
||||||
m_AppConfig(appConfig),
|
m_AppConfig(appConfig),
|
||||||
m_serialKey(appConfig->edition()) {
|
m_serialKey(appConfig->edition()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<bool, QString>
|
std::pair<bool, QString>
|
||||||
LicenseManager::setSerialKey(SerialKey serialKey, bool acceptExpired)
|
LicenseManager::setSerialKey(SerialKey serialKey, bool acceptExpired)
|
||||||
{
|
{
|
||||||
std::pair<bool, QString> ret (true, "");
|
std::pair<bool, QString> ret (true, "");
|
||||||
time_t currentTime = ::time(0);
|
time_t currentTime = ::time(0);
|
||||||
|
|
||||||
if (!acceptExpired && serialKey.isExpired(currentTime)) {
|
if (!acceptExpired && serialKey.isExpired(currentTime)) {
|
||||||
ret.first = false;
|
ret.first = false;
|
||||||
ret.second = "Serial key expired";
|
ret.second = "Serial key expired";
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serialKey != m_serialKey) {
|
if (serialKey != m_serialKey) {
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap (serialKey, m_serialKey);
|
swap (serialKey, m_serialKey);
|
||||||
m_AppConfig->setSerialKey(QString::fromStdString
|
m_AppConfig->setSerialKey(QString::fromStdString
|
||||||
(m_serialKey.toString()));
|
(m_serialKey.toString()));
|
||||||
emit serialKeyChanged(m_serialKey);
|
emit serialKeyChanged(m_serialKey);
|
||||||
|
|
||||||
emit showLicenseNotice(getLicenseNotice());
|
emit showLicenseNotice(getLicenseNotice());
|
||||||
if (!m_serialKey.isValid()) {
|
if (!m_serialKey.isValid()) {
|
||||||
emit InvalidLicense();
|
emit InvalidLicense();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_serialKey.edition() != serialKey.edition()) {
|
if (m_serialKey.edition() != serialKey.edition()) {
|
||||||
m_AppConfig->setEdition(m_serialKey.edition());
|
m_AppConfig->setEdition(m_serialKey.edition());
|
||||||
emit editionChanged(m_serialKey.edition());
|
emit editionChanged(m_serialKey.edition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LicenseManager::notifyUpdate(QString fromVersion, QString toVersion) const {
|
LicenseManager::notifyUpdate(QString fromVersion, QString toVersion) const {
|
||||||
if ((fromVersion == "Unknown")
|
if ((fromVersion == "Unknown")
|
||||||
&& (m_serialKey == SerialKey(kUnregistered))) {
|
&& (m_serialKey == SerialKey(kUnregistered))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActivationNotifier* notifier = new ActivationNotifier();
|
ActivationNotifier* notifier = new ActivationNotifier();
|
||||||
notifier->setUpdateInfo (fromVersion, toVersion,
|
notifier->setUpdateInfo (fromVersion, toVersion,
|
||||||
QString::fromStdString(m_serialKey.toString()));
|
QString::fromStdString(m_serialKey.toString()));
|
||||||
|
|
||||||
QThread* thread = new QThread();
|
QThread* thread = new QThread();
|
||||||
connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
|
connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
|
||||||
connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
|
connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
|
||||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||||
|
|
||||||
notifier->moveToThread(thread);
|
notifier->moveToThread(thread);
|
||||||
thread->start();
|
thread->start();
|
||||||
|
|
||||||
QMetaObject::invokeMethod(notifier, "notifyUpdate",
|
QMetaObject::invokeMethod(notifier, "notifyUpdate",
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
Edition
|
Edition
|
||||||
LicenseManager::activeEdition() const
|
LicenseManager::activeEdition() const
|
||||||
{
|
{
|
||||||
return m_serialKey.edition();
|
return m_serialKey.edition();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
LicenseManager::activeEditionName() const
|
LicenseManager::activeEditionName() const
|
||||||
{
|
{
|
||||||
return getEditionName(activeEdition(), m_serialKey.isTrial());
|
return getEditionName(activeEdition(), m_serialKey.isTrial());
|
||||||
}
|
}
|
||||||
|
|
||||||
SerialKey
|
SerialKey
|
||||||
LicenseManager::serialKey() const
|
LicenseManager::serialKey() const
|
||||||
{
|
{
|
||||||
return m_serialKey;
|
return m_serialKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LicenseManager::refresh()
|
LicenseManager::refresh()
|
||||||
{
|
{
|
||||||
if (!m_AppConfig->serialKey().isEmpty()) {
|
if (!m_AppConfig->serialKey().isEmpty()) {
|
||||||
try {
|
try {
|
||||||
SerialKey serialKey (m_AppConfig->serialKey().toStdString());
|
SerialKey serialKey (m_AppConfig->serialKey().toStdString());
|
||||||
setSerialKey(serialKey, true);
|
setSerialKey(serialKey, true);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
m_AppConfig->clearSerialKey();
|
m_AppConfig->clearSerialKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!m_serialKey.isValid()) {
|
if (!m_serialKey.isValid()) {
|
||||||
emit InvalidLicense();
|
emit InvalidLicense();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LicenseManager::skipActivation() const
|
LicenseManager::skipActivation() const
|
||||||
{
|
{
|
||||||
notifyActivation ("skip:unknown");
|
notifyActivation ("skip:unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
LicenseManager::getEditionName(Edition const edition, bool trial)
|
LicenseManager::getEditionName(Edition const edition, bool trial)
|
||||||
{
|
{
|
||||||
SerialKeyEdition KeyEdition(edition);
|
SerialKeyEdition KeyEdition(edition);
|
||||||
std::string name = KeyEdition.getDisplayName();
|
std::string name = KeyEdition.getDisplayName();
|
||||||
|
|
||||||
if (trial) {
|
if (trial) {
|
||||||
name += " (Trial)";
|
name += " (Trial)";
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString::fromUtf8 (name.c_str(), static_cast<int>(name.size()));
|
return QString::fromUtf8 (name.c_str(), static_cast<int>(name.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LicenseManager::notifyActivation(QString identity) const
|
LicenseManager::notifyActivation(QString identity) const
|
||||||
{
|
{
|
||||||
ActivationNotifier* notifier = new ActivationNotifier();
|
ActivationNotifier* notifier = new ActivationNotifier();
|
||||||
notifier->setIdentity(identity);
|
notifier->setIdentity(identity);
|
||||||
|
|
||||||
QThread* thread = new QThread();
|
QThread* thread = new QThread();
|
||||||
connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
|
connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
|
||||||
connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
|
connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
|
||||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||||
|
|
||||||
notifier->moveToThread(thread);
|
notifier->moveToThread(thread);
|
||||||
thread->start();
|
thread->start();
|
||||||
|
|
||||||
QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
LicenseManager::getLicenseNotice() const
|
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
|
QString
|
||||||
LicenseManager::getTrialNotice() const
|
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://members.symless.com/purchase\">"
|
"\"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.arg(LicenseManager::getEditionName(activeEdition()));
|
Notice = Notice.arg(LicenseManager::getEditionName(activeEdition()));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Notice = "<html><head/><body><p><span style=\""
|
Notice = "<html><head/><body><p><span style=\""
|
||||||
"font-weight:600;\">%1</span> day%3 of "
|
"font-weight:600;\">%1</span> day%3 of "
|
||||||
"your %2 trial remain%5. <a href="
|
"your %2 trial remain%5. <a href="
|
||||||
"\"https://members.symless.com/purchase\">"
|
"\"https://members.symless.com/purchase\">"
|
||||||
"<span style=\"text-decoration: underline;"
|
"<span style=\"text-decoration: underline;"
|
||||||
" color:#0000ff;\">Buy now!</span></a>"
|
" color:#0000ff;\">Buy now!</span></a>"
|
||||||
"</p></body></html>";
|
"</p></body></html>";
|
||||||
|
|
||||||
time_t daysLeft = m_serialKey.daysLeft(::time(0));
|
time_t daysLeft = m_serialKey.daysLeft(::time(0));
|
||||||
Notice = Notice
|
Notice = Notice
|
||||||
.arg (daysLeft)
|
.arg (daysLeft)
|
||||||
.arg (LicenseManager::getEditionName(activeEdition()))
|
.arg (LicenseManager::getEditionName(activeEdition()))
|
||||||
.arg ((daysLeft == 1) ? "" : "s")
|
.arg ((daysLeft == 1) ? "" : "s")
|
||||||
.arg ((daysLeft == 1) ? "s" : "");
|
.arg ((daysLeft == 1) ? "s" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Notice;
|
return Notice;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
LicenseManager::getTemporaryNotice() const
|
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 license has expired. <a href="
|
Notice = "<html><head/><body><p>Your license has expired. <a href="
|
||||||
"\"https://members.symless.com/purchase\">"
|
"\"https://members.symless.com/purchase\">"
|
||||||
"<span style=\"text-decoration: underline;color:#0000ff;\">"
|
"<span style=\"text-decoration: underline;color:#0000ff;\">"
|
||||||
"Renew now!</span></a></p></body></html>";
|
"Renew now!</span></a></p></body></html>";
|
||||||
}
|
}
|
||||||
else if (m_serialKey.isExpiring(::time(0))) {
|
else if (m_serialKey.isExpiring(::time(0))) {
|
||||||
Notice = "<html><head/><body><p><span style=\""
|
Notice = "<html><head/><body><p><span style=\""
|
||||||
"font-weight:600;\">%1</span> day%2 "
|
"font-weight:600;\">%1</span> day%2 "
|
||||||
"before your license expires.<a href="
|
"before your license expires.<a href="
|
||||||
"\"https://members.symless.com/purchase\">"
|
"\"https://members.symless.com/purchase\">"
|
||||||
"<span style=\"text-decoration: underline;"
|
"<span style=\"text-decoration: underline;"
|
||||||
" color:#0000ff;\">Renew now!</span></a>"
|
" color:#0000ff;\">Renew now!</span></a>"
|
||||||
"</p></body></html>";
|
"</p></body></html>";
|
||||||
|
|
||||||
time_t daysLeft = m_serialKey.daysLeft(::time(0));
|
time_t daysLeft = m_serialKey.daysLeft(::time(0));
|
||||||
Notice = Notice.arg (daysLeft).arg ((daysLeft == 1) ? "" : "s");
|
Notice = Notice.arg (daysLeft).arg ((daysLeft == 1) ? "" : "s");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Notice;
|
return Notice;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,10 +37,10 @@ public:
|
||||||
Edition activeEdition() const;
|
Edition activeEdition() const;
|
||||||
QString activeEditionName() const;
|
QString activeEditionName() const;
|
||||||
SerialKey serialKey() const;
|
SerialKey serialKey() const;
|
||||||
void skipActivation() const;
|
void skipActivation() const;
|
||||||
void notifyUpdate(QString fromVersion, QString toVersion) const;
|
void notifyUpdate(QString fromVersion, QString toVersion) const;
|
||||||
static QString getEditionName(Edition edition, bool trial = false);
|
static QString getEditionName(Edition edition, bool trial = false);
|
||||||
void notifyActivation(QString identity) const;
|
void notifyActivation(QString identity) const;
|
||||||
QString getLicenseNotice() const;
|
QString getLicenseNotice() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -50,7 +50,7 @@ private:
|
||||||
signals:
|
signals:
|
||||||
void serialKeyChanged (SerialKey) const;
|
void serialKeyChanged (SerialKey) const;
|
||||||
void editionChanged (Edition) const;
|
void editionChanged (Edition) const;
|
||||||
void InvalidLicense () const;
|
void InvalidLicense () const;
|
||||||
void showLicenseNotice(const QString& notice) const;
|
void showLicenseNotice(const QString& notice) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -174,8 +174,8 @@ MainWindow::MainWindow (AppConfig& appConfig,
|
||||||
connect (m_LicenseManager, SIGNAL(showLicenseNotice(QString)),
|
connect (m_LicenseManager, SIGNAL(showLicenseNotice(QString)),
|
||||||
this, SLOT(showLicenseNotice(QString)), Qt::QueuedConnection);
|
this, SLOT(showLicenseNotice(QString)), Qt::QueuedConnection);
|
||||||
|
|
||||||
connect (m_LicenseManager, SIGNAL(InvalidLicense()),
|
connect (m_LicenseManager, SIGNAL(InvalidLicense()),
|
||||||
this, SLOT(InvalidLicense()), Qt::QueuedConnection);
|
this, SLOT(InvalidLicense()), Qt::QueuedConnection);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
connect (m_AppConfig, SIGNAL(sslToggled(bool)),
|
connect (m_AppConfig, SIGNAL(sslToggled(bool)),
|
||||||
|
|
@ -569,8 +569,8 @@ void MainWindow::checkSecureSocket(const QString& line)
|
||||||
// obviously not very secure, since this can be tricked by injecting something
|
// obviously not very secure, since this can be tricked by injecting something
|
||||||
// into the log. however, since we don't have IPC between core and GUI... patches welcome.
|
// into the log. however, since we don't have IPC between core and GUI... patches welcome.
|
||||||
const int index = line.indexOf(tlsCheckString, 0, Qt::CaseInsensitive);
|
const int index = line.indexOf(tlsCheckString, 0, Qt::CaseInsensitive);
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
secureSocket(true);
|
secureSocket(true);
|
||||||
|
|
||||||
//Get the protocol version from the line
|
//Get the protocol version from the line
|
||||||
m_SecureSocketVersion = line.mid(index + strlen(tlsCheckString));
|
m_SecureSocketVersion = line.mid(index + strlen(tlsCheckString));
|
||||||
|
|
@ -613,7 +613,7 @@ void MainWindow::startSynergy()
|
||||||
{
|
{
|
||||||
#ifndef SYNERGY_ENTERPRISE
|
#ifndef SYNERGY_ENTERPRISE
|
||||||
SerialKey serialKey = m_LicenseManager->serialKey();
|
SerialKey serialKey = m_LicenseManager->serialKey();
|
||||||
if (!serialKey.isValid()) {
|
if (!serialKey.isValid()) {
|
||||||
if (QDialog::Rejected == raiseActivationDialog()) {
|
if (QDialog::Rejected == raiseActivationDialog()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,88 +31,88 @@ using namespace std;
|
||||||
static std::string hexEncode (std::string const& str);
|
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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SerialKey::isValid() const
|
SerialKey::isValid() const
|
||||||
{
|
{
|
||||||
bool Valid = true;
|
bool Valid = true;
|
||||||
|
|
||||||
if (m_edition.getType() == kUnregistered || isExpired(::time(0)))
|
if (m_edition.getType() == kUnregistered || isExpired(::time(0)))
|
||||||
{
|
{
|
||||||
Valid = false;
|
Valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Valid;
|
return Valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
Edition
|
Edition
|
||||||
SerialKey::edition() const
|
SerialKey::edition() const
|
||||||
{
|
{
|
||||||
return m_edition.getType();
|
return m_edition.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string
|
static std::string
|
||||||
|
|
@ -131,134 +131,134 @@ 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::SUBSCRIPTION << ";";
|
oss << "v2;" << SerialKeyType::SUBSCRIPTION << ";";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
oss << "v1;";
|
oss << "v1;";
|
||||||
}
|
}
|
||||||
oss << m_edition.getName() << ";";
|
oss << m_edition.getName() << ";";
|
||||||
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.setType(parts.at(1));
|
m_edition.setType(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.setType(parts.at(2));
|
m_edition.setType(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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ TEST(SerialKeyTests, parse_validV2Serial_valid)
|
||||||
bool r = serial.parse("{v2;trial;pro;Bob;1;email;company name;0;86400}");
|
bool r = serial.parse("{v2;trial;pro;Bob;1;email;company name;0;86400}");
|
||||||
EXPECT_EQ(true, r);
|
EXPECT_EQ(true, r);
|
||||||
EXPECT_EQ(kPro, serial.edition());
|
EXPECT_EQ(kPro, serial.edition());
|
||||||
EXPECT_FALSE(serial.isExpired(0));
|
EXPECT_FALSE(serial.isExpired(0));
|
||||||
EXPECT_EQ(true, serial.daysLeft(0));
|
EXPECT_EQ(true, serial.daysLeft(0));
|
||||||
EXPECT_EQ(true, serial.isExpiring(1));
|
EXPECT_EQ(true, serial.isExpiring(1));
|
||||||
EXPECT_EQ(true, serial.isTrial());
|
EXPECT_EQ(true, serial.isTrial());
|
||||||
|
|
@ -156,74 +156,74 @@ TEST(SerialKeyTests, daysLeft_expiredV2TrialBasicSerial_returnZero)
|
||||||
//Subscription license tests
|
//Subscription license tests
|
||||||
TEST(SerialKeyTests, isExpiring_validV2SubscriptionBasicSerial_returnFalse)
|
TEST(SerialKeyTests, isExpiring_validV2SubscriptionBasicSerial_returnFalse)
|
||||||
{
|
{
|
||||||
// {v2;subscription;basic;Bob;1;email;company name;1;86400}
|
// {v2;subscription;basic;Bob;1;email;company name;1;86400}
|
||||||
SerialKey serial("7B76323B737562736372697074696F6E3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B313B38363430307D");
|
SerialKey serial("7B76323B737562736372697074696F6E3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B313B38363430307D");
|
||||||
EXPECT_EQ(false, serial.isTrial());
|
EXPECT_EQ(false, serial.isTrial());
|
||||||
EXPECT_EQ(true, serial.isTemporary());
|
EXPECT_EQ(true, serial.isTemporary());
|
||||||
EXPECT_FALSE(serial.isExpiring(0));
|
EXPECT_FALSE(serial.isExpiring(0));
|
||||||
EXPECT_EQ(kBasic, serial.edition());
|
EXPECT_EQ(kBasic, serial.edition());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SerialKeyTests, isExpiring_expiringV2SubscriptionBasicSerial_returnTrue)
|
TEST(SerialKeyTests, isExpiring_expiringV2SubscriptionBasicSerial_returnTrue)
|
||||||
{
|
{
|
||||||
// {v2;subscription;basic;Bob;1;email;company name;0;86400}
|
// {v2;subscription;basic;Bob;1;email;company name;0;86400}
|
||||||
SerialKey serial("7B76323B737562736372697074696F6E3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
SerialKey serial("7B76323B737562736372697074696F6E3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||||
EXPECT_EQ(false, serial.isTrial());
|
EXPECT_EQ(false, serial.isTrial());
|
||||||
EXPECT_EQ(true, serial.isTemporary());
|
EXPECT_EQ(true, serial.isTemporary());
|
||||||
EXPECT_EQ(true, serial.isExpiring(1));
|
EXPECT_EQ(true, serial.isExpiring(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SerialKeyTests, isExpired_expiredV2SubscriptionBasicSerial_returnTrue)
|
TEST(SerialKeyTests, isExpired_expiredV2SubscriptionBasicSerial_returnTrue)
|
||||||
{
|
{
|
||||||
// {v2;subscription;basic;Bob;1;email;company name;0;86400}
|
// {v2;subscription;basic;Bob;1;email;company name;0;86400}
|
||||||
SerialKey serial("7B76323B737562736372697074696F6E3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
SerialKey serial("7B76323B737562736372697074696F6E3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||||
EXPECT_EQ(false, serial.isTrial());
|
EXPECT_EQ(false, serial.isTrial());
|
||||||
EXPECT_EQ(true, serial.isTemporary());
|
EXPECT_EQ(true, serial.isTemporary());
|
||||||
EXPECT_EQ(true, serial.isExpired(86401));
|
EXPECT_EQ(true, serial.isExpired(86401));
|
||||||
}
|
}
|
||||||
|
|
||||||
//toString method tests
|
//toString method tests
|
||||||
TEST(SerialKeyTests, toStringV2SubscriptionBasicSerialKey)
|
TEST(SerialKeyTests, toStringV2SubscriptionBasicSerialKey)
|
||||||
{
|
{
|
||||||
//{v2;subscription;basic;Bob;1;email;company name;0;86400}
|
//{v2;subscription;basic;Bob;1;email;company name;0;86400}
|
||||||
const std::string Expected = "7B76323B737562736372697074696F6E3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D";
|
const std::string Expected = "7B76323B737562736372697074696F6E3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D";
|
||||||
SerialKey serial(Expected);
|
SerialKey serial(Expected);
|
||||||
EXPECT_EQ(Expected, serial.toString());
|
EXPECT_EQ(Expected, serial.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SerialKeyTests, toStringV2TrialBasicSerialKey)
|
TEST(SerialKeyTests, toStringV2TrialBasicSerialKey)
|
||||||
{
|
{
|
||||||
//{v2;trial;basic;Bob;1;email;company name;0;86400}
|
//{v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||||
const std::string Expected = "7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D";
|
const std::string Expected = "7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D";
|
||||||
SerialKey serial(Expected);
|
SerialKey serial(Expected);
|
||||||
EXPECT_EQ(Expected, serial.toString());
|
EXPECT_EQ(Expected, serial.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SerialKeyTests, toStringV1BasicSerialKey)
|
TEST(SerialKeyTests, toStringV1BasicSerialKey)
|
||||||
{
|
{
|
||||||
//{v1;basic;Bob;1;email;company name;0;0}
|
//{v1;basic;Bob;1;email;company name;0;0}
|
||||||
const std::string Expected = "7B76313B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B307D";
|
const std::string Expected = "7B76313B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B307D";
|
||||||
SerialKey serial(Expected);
|
SerialKey serial(Expected);
|
||||||
EXPECT_EQ(Expected, serial.toString());
|
EXPECT_EQ(Expected, serial.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SerialKeyTests, IsValidKey_false)
|
TEST(SerialKeyTests, IsValidKey_false)
|
||||||
{
|
{
|
||||||
//{v1;basic;Bob;1;email;company name;0;0}
|
//{v1;basic;Bob;1;email;company name;0;0}
|
||||||
SerialKey serial(kUnregistered);
|
SerialKey serial(kUnregistered);
|
||||||
EXPECT_EQ(false, serial.isValid());
|
EXPECT_EQ(false, serial.isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SerialKeyTests, IsValidKey_true)
|
TEST(SerialKeyTests, IsValidKey_true)
|
||||||
{
|
{
|
||||||
SerialKey serial(kBasic);
|
SerialKey serial(kBasic);
|
||||||
EXPECT_EQ(true, serial.isValid());
|
EXPECT_EQ(true, serial.isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SerialKeyTests, IsValidExpiredKey_false)
|
TEST(SerialKeyTests, IsValidExpiredKey_false)
|
||||||
{
|
{
|
||||||
SerialKey serial("7B76323B737562736372697074696F6E3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
SerialKey serial("7B76323B737562736372697074696F6E3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||||
EXPECT_EQ(false, serial.isValid());
|
EXPECT_EQ(false, serial.isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue