#5657 Rename edition to activeLicense. WSFs

This commit is contained in:
Andrew Nelless 2016-10-15 15:30:28 +01:00
parent 3b98a7b785
commit 4ad7c7fe39
7 changed files with 1317 additions and 1309 deletions

View File

@ -15,66 +15,66 @@
#include <iostream>
ActivationDialog::ActivationDialog(QWidget* parent, AppConfig& appConfig,
SubscriptionManager& subscriptionManager) :
QDialog(parent),
ui(new Ui::ActivationDialog),
m_appConfig(&appConfig),
m_subscriptionManager (&subscriptionManager)
SubscriptionManager& subscriptionManager) :
QDialog(parent),
ui(new Ui::ActivationDialog),
m_appConfig(&appConfig),
m_subscriptionManager (&subscriptionManager)
{
ui->setupUi(this);
refreshSerialKey();
ui->setupUi(this);
refreshSerialKey();
}
void ActivationDialog::refreshSerialKey()
{
ui->m_pTextEditSerialKey->setText(m_appConfig->serialKey());
ui->m_pTextEditSerialKey->setFocus();
ui->m_pTextEditSerialKey->moveCursor(QTextCursor::End);
ui->m_pTextEditSerialKey->setText(m_appConfig->serialKey());
ui->m_pTextEditSerialKey->setFocus();
ui->m_pTextEditSerialKey->moveCursor(QTextCursor::End);
}
ActivationDialog::~ActivationDialog()
{
delete ui;
delete ui;
}
void ActivationDialog::reject()
{
if (m_subscriptionManager->edition() == Edition::kUnregistered) {
CancelActivationDialog cancelActivationDialog(this);
if (QDialog::Accepted == cancelActivationDialog.exec()) {
m_subscriptionManager->skipActivation();
m_appConfig->activationHasRun(true);
m_appConfig->saveSettings();
}
}
QDialog::reject();
if (m_subscriptionManager->activeLicense() == Edition::kUnregistered) {
CancelActivationDialog cancelActivationDialog(this);
if (QDialog::Accepted == cancelActivationDialog.exec()) {
m_subscriptionManager->skipActivation();
m_appConfig->activationHasRun(true);
m_appConfig->saveSettings();
}
}
QDialog::reject();
}
void ActivationDialog::accept()
{
QMessageBox message;
QString error;
QMessageBox message;
QString error;
m_appConfig->activationHasRun(true);
m_appConfig->saveSettings();
m_appConfig->activationHasRun(true);
m_appConfig->saveSettings();
try {
QString serialKey = ui->m_pTextEditSerialKey->toPlainText();
m_subscriptionManager->setSerialKey(serialKey);
}
catch (std::exception& e) {
message.critical(this, "Unknown Error",
tr("An error occurred while trying to activate Synergy. "
"Please contact the helpdesk, and provide the "
"following details.\n\n%1").arg(e.what()));
refreshSerialKey();
return;
}
try {
QString serialKey = ui->m_pTextEditSerialKey->toPlainText();
m_subscriptionManager->setSerialKey(serialKey);
}
catch (std::exception& e) {
message.critical(this, "Unknown Error",
tr("An error occurred while trying to activate Synergy. "
"Please contact the helpdesk, and provide the "
"following details.\n\n%1").arg(e.what()));
refreshSerialKey();
return;
}
if (m_subscriptionManager->edition() != Edition::kUnregistered) {
message.information(this, "Activated!",
tr("Thanks for activating %1!").arg
(getEditionName(m_subscriptionManager->edition())));
}
QDialog::accept();
if (m_subscriptionManager->activeLicense() != Edition::kUnregistered) {
message.information(this, "Activated!",
tr("Thanks for activating %1!").arg
(getEditionName(m_subscriptionManager->activeLicense())));
}
QDialog::accept();
}

File diff suppressed because it is too large Load Diff

View File

@ -62,174 +62,174 @@ class SubscriptionManager;
class MainWindow : public QMainWindow, public Ui::MainWindowBase
{
Q_OBJECT
Q_OBJECT
friend class QSynergyApplication;
friend class SetupWizard;
friend class ActivationDialog;
friend class SettingsDialog;
friend class QSynergyApplication;
friend class SetupWizard;
friend class ActivationDialog;
friend class SettingsDialog;
public:
enum qSynergyState
{
synergyDisconnected,
synergyConnecting,
synergyConnected,
synergyTransfering
};
public:
enum qSynergyState
{
synergyDisconnected,
synergyConnecting,
synergyConnected,
synergyTransfering
};
enum qSynergyType
{
synergyClient,
synergyServer
};
enum qSynergyType
{
synergyClient,
synergyServer
};
enum qLevel {
Error,
Info
};
enum qLevel {
Error,
Info
};
enum qRuningState {
kStarted,
kStopped
};
enum qRuningState {
kStarted,
kStopped
};
public:
MainWindow(QSettings& settings, AppConfig& appConfig,
SubscriptionManager& subscriptionManager);
~MainWindow();
public:
MainWindow(QSettings& settings, AppConfig& appConfig,
SubscriptionManager& subscriptionManager);
~MainWindow();
public:
void setVisible(bool visible);
int synergyType() const { return m_pGroupClient->isChecked() ? synergyClient : synergyServer; }
int synergyState() const { return m_SynergyState; }
QString hostname() const { return m_pLineEditHostname->text(); }
QString configFilename();
QString address();
QString appPath(const QString& name);
void open();
void clearLog();
VersionChecker& versionChecker() { return m_VersionChecker; }
QString getScreenName();
ServerConfig& serverConfig() { return m_ServerConfig; }
void showConfigureServer(const QString& message);
void showConfigureServer() { showConfigureServer(""); }
void autoAddScreen(const QString name);
void updateZeroconfService();
void serverDetected(const QString name);
void updateLocalFingerprint();
SubscriptionManager& subscriptionManager() const;
public:
void setVisible(bool visible);
int synergyType() const { return m_pGroupClient->isChecked() ? synergyClient : synergyServer; }
int synergyState() const { return m_SynergyState; }
QString hostname() const { return m_pLineEditHostname->text(); }
QString configFilename();
QString address();
QString appPath(const QString& name);
void open();
void clearLog();
VersionChecker& versionChecker() { return m_VersionChecker; }
QString getScreenName();
ServerConfig& serverConfig() { return m_ServerConfig; }
void showConfigureServer(const QString& message);
void showConfigureServer() { showConfigureServer(""); }
void autoAddScreen(const QString name);
void updateZeroconfService();
void serverDetected(const QString name);
void updateLocalFingerprint();
SubscriptionManager& subscriptionManager() const;
public slots:
void setEdition(Edition edition);
void beginTrial();
void endTrial();
void appendLogRaw(const QString& text);
void appendLogInfo(const QString& text);
void appendLogDebug(const QString& text);
void appendLogError(const QString& text);
void startSynergy();
public slots:
void setEdition(Edition edition);
void beginTrial(bool isExpiring);
void endTrial(bool isExpired);
void appendLogRaw(const QString& text);
void appendLogInfo(const QString& text);
void appendLogDebug(const QString& text);
void appendLogError(const QString& text);
void startSynergy();
protected slots:
void sslToggled(bool enabled);
void on_m_pGroupClient_toggled(bool on);
void on_m_pGroupServer_toggled(bool on);
bool on_m_pButtonBrowseConfigFile_clicked();
void on_m_pButtonConfigureServer_clicked();
bool on_m_pActionSave_triggered();
void on_m_pActionAbout_triggered();
void on_m_pActionSettings_triggered();
void on_m_pActivate_triggered();
void synergyFinished(int exitCode, QProcess::ExitStatus);
void trayActivated(QSystemTrayIcon::ActivationReason reason);
void stopSynergy();
void logOutput();
void logError();
void updateFound(const QString& version);
void bonjourInstallFinished();
protected slots:
void sslToggled(bool enabled);
void on_m_pGroupClient_toggled(bool on);
void on_m_pGroupServer_toggled(bool on);
bool on_m_pButtonBrowseConfigFile_clicked();
void on_m_pButtonConfigureServer_clicked();
bool on_m_pActionSave_triggered();
void on_m_pActionAbout_triggered();
void on_m_pActionSettings_triggered();
void on_m_pActivate_triggered();
void synergyFinished(int exitCode, QProcess::ExitStatus);
void trayActivated(QSystemTrayIcon::ActivationReason reason);
void stopSynergy();
void logOutput();
void logError();
void updateFound(const QString& version);
void bonjourInstallFinished();
protected:
QSettings& settings() { return m_Settings; }
AppConfig& appConfig() { return *m_AppConfig; }
QProcess* synergyProcess() { return m_pSynergy; }
void setSynergyProcess(QProcess* p) { m_pSynergy = p; }
void initConnections();
void createMenuBar();
void createStatusBar();
void createTrayIcon();
void loadSettings();
void saveSettings();
void setIcon(qSynergyState state);
void setSynergyState(qSynergyState state);
bool checkForApp(int which, QString& app);
bool clientArgs(QStringList& args, QString& app);
bool serverArgs(QStringList& args, QString& app);
void setStatus(const QString& status);
void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors);
void onModeChanged(bool startDesktop, bool applyService);
void updateStateFromLogLine(const QString& line);
QString getIPAddresses();
void stopService();
void stopDesktop();
void changeEvent(QEvent* event);
void retranslateMenuBar();
protected:
QSettings& settings() { return m_Settings; }
AppConfig& appConfig() { return *m_AppConfig; }
QProcess* synergyProcess() { return m_pSynergy; }
void setSynergyProcess(QProcess* p) { m_pSynergy = p; }
void initConnections();
void createMenuBar();
void createStatusBar();
void createTrayIcon();
void loadSettings();
void saveSettings();
void setIcon(qSynergyState state);
void setSynergyState(qSynergyState state);
bool checkForApp(int which, QString& app);
bool clientArgs(QStringList& args, QString& app);
bool serverArgs(QStringList& args, QString& app);
void setStatus(const QString& status);
void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors);
void onModeChanged(bool startDesktop, bool applyService);
void updateStateFromLogLine(const QString& line);
QString getIPAddresses();
void stopService();
void stopDesktop();
void changeEvent(QEvent* event);
void retranslateMenuBar();
#if defined(Q_OS_WIN)
bool isServiceRunning(QString name);
bool isServiceRunning(QString name);
#else
bool isServiceRunning();
bool isServiceRunning();
#endif
bool isBonjourRunning();
void downloadBonjour();
void promptAutoConfig();
QString getProfileRootForArg();
void checkConnected(const QString& line);
void checkFingerprint(const QString& line);
bool autoHide();
QString getTimeStamp();
void restartSynergy();
void proofreadInfo();
bool isBonjourRunning();
void downloadBonjour();
void promptAutoConfig();
QString getProfileRootForArg();
void checkConnected(const QString& line);
void checkFingerprint(const QString& line);
bool autoHide();
QString getTimeStamp();
void restartSynergy();
void proofreadInfo();
void showEvent (QShowEvent*);
void showEvent (QShowEvent*);
private:
QSettings& m_Settings;
AppConfig* m_AppConfig;
SubscriptionManager* m_SubscriptionManager;
QProcess* m_pSynergy;
int m_SynergyState;
ServerConfig m_ServerConfig;
QTemporaryFile* m_pTempConfigFile;
QSystemTrayIcon* m_pTrayIcon;
QMenu* m_pTrayIconMenu;
bool m_AlreadyHidden;
VersionChecker m_VersionChecker;
IpcClient m_IpcClient;
QMenuBar* m_pMenuBar;
QMenu* m_pMenuFile;
QMenu* m_pMenuEdit;
QMenu* m_pMenuWindow;
QMenu* m_pMenuHelp;
ZeroconfService* m_pZeroconfService;
DataDownloader* m_pDataDownloader;
QMessageBox* m_DownloadMessageBox;
QAbstractButton* m_pCancelButton;
QMutex m_UpdateZeroconfMutex;
bool m_SuppressAutoConfigWarning;
CommandProcess* m_BonjourInstall;
bool m_SuppressEmptyServerWarning;
qRuningState m_ExpectedRunningState;
QMutex m_StopDesktopMutex;
SslCertificate* m_pSslCertificate;
private:
QSettings& m_Settings;
AppConfig* m_AppConfig;
SubscriptionManager* m_SubscriptionManager;
QProcess* m_pSynergy;
int m_SynergyState;
ServerConfig m_ServerConfig;
QTemporaryFile* m_pTempConfigFile;
QSystemTrayIcon* m_pTrayIcon;
QMenu* m_pTrayIconMenu;
bool m_AlreadyHidden;
VersionChecker m_VersionChecker;
IpcClient m_IpcClient;
QMenuBar* m_pMenuBar;
QMenu* m_pMenuFile;
QMenu* m_pMenuEdit;
QMenu* m_pMenuWindow;
QMenu* m_pMenuHelp;
ZeroconfService* m_pZeroconfService;
DataDownloader* m_pDataDownloader;
QMessageBox* m_DownloadMessageBox;
QAbstractButton* m_pCancelButton;
QMutex m_UpdateZeroconfMutex;
bool m_SuppressAutoConfigWarning;
CommandProcess* m_BonjourInstall;
bool m_SuppressEmptyServerWarning;
qRuningState m_ExpectedRunningState;
QMutex m_StopDesktopMutex;
SslCertificate* m_pSslCertificate;
private slots:
void on_m_pCheckBoxAutoConfig_toggled(bool checked);
void on_m_pComboServerList_currentIndexChanged(QString );
void on_m_pButtonApply_clicked();
void installBonjour();
void on_windowShown();
void on_m_pCheckBoxAutoConfig_toggled(bool checked);
void on_m_pComboServerList_currentIndexChanged(QString );
void on_m_pButtonApply_clicked();
void installBonjour();
void on_windowShown();
signals:
void windowShown();
void windowShown();
};
#endif

View File

@ -22,75 +22,82 @@
#include <QThread>
SubscriptionManager::SubscriptionManager(AppConfig* appConfig) :
m_AppConfig(appConfig),
m_serialKey(appConfig->edition()) {
try {
setSerialKey(m_AppConfig->serialKey());
} catch (...) {
m_AppConfig->setSerialKey("");
}
m_AppConfig(appConfig),
m_serialKey(appConfig->edition()) {
try {
setSerialKey(m_AppConfig->serialKey());
} catch (...) {
m_AppConfig->setSerialKey("");
m_AppConfig->saveSettings();
}
}
SerialKey
SubscriptionManager::setSerialKey(QString serialKeyString)
{
SerialKey serialKey (serialKeyString.toStdString());
if (!serialKey.isValid (::time(0))) {
throw std::runtime_error ("Invalid serial key");
}
SerialKey serialKey (serialKeyString.toStdString());
if (!serialKey.isValid (::time(0))) {
throw std::runtime_error ("Invalid serial key");
}
if (serialKey != m_serialKey) {
using std::swap;
swap (serialKey, m_serialKey);
if (serialKey != m_serialKey) {
using std::swap;
swap (serialKey, m_serialKey);
m_AppConfig->setSerialKey (serialKeyString);
notifyActivation ("serial:" + serialKeyString);
emit serialKeyChanged (m_serialKey);
m_AppConfig->setSerialKey (serialKeyString);
notifyActivation ("serial:" + serialKeyString);
emit serialKeyChanged (m_serialKey);
if (m_serialKey.edition() != serialKey.edition()) {
m_AppConfig->setEdition (m_serialKey.edition());
emit editionChanged (m_serialKey.edition());
}
if (m_serialKey.edition() != serialKey.edition()) {
m_AppConfig->setEdition (m_serialKey.edition());
emit editionChanged (m_serialKey.edition());
}
if (m_serialKey.isTrial() != serialKey.isTrial()) {
if (m_serialKey.isTrial()) {
emit beginTrial();
} else {
emit endTrial();
}
}
}
if (serialKey.isTrial()) {
emit endTrial(false);
}
return serialKey;
if (m_serialKey.isTrial()) {
emit beginTrial(m_serialKey.isExpiring(::time(0)));
}
m_AppConfig->saveSettings();
}
return serialKey;
}
Edition SubscriptionManager::edition() const
Edition SubscriptionManager::activeLicense() const
{
return m_serialKey.edition();
return m_serialKey.edition();
}
bool SubscriptionManager::isTrial() const
void SubscriptionManager::update() const
{
return m_serialKey.isTrial();
emit serialKeyChanged (m_serialKey);
emit editionChanged (m_serialKey.edition());
if (m_serialKey.isTrial()) {
emit beginTrial(m_serialKey.isExpiring(::time(0)));
}
}
void SubscriptionManager::skipActivation()
{
notifyActivation ("skip:unknown");
notifyActivation ("skip:unknown");
}
void SubscriptionManager::notifyActivation(QString identity)
{
ActivationNotifier* notifier = new ActivationNotifier();
notifier->setIdentity(identity);
ActivationNotifier* notifier = new ActivationNotifier();
notifier->setIdentity(identity);
QThread* thread = new QThread();
connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
QThread* thread = new QThread();
connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
notifier->moveToThread(thread);
thread->start();
notifier->moveToThread(thread);
thread->start();
QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection);
QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection);
}

View File

@ -25,25 +25,25 @@ class AppConfig;
class SubscriptionManager: public QObject
{
Q_OBJECT
Q_OBJECT
public:
SubscriptionManager(AppConfig* appConfig);
SerialKey setSerialKey(QString serialKey);
Edition edition() const;
bool isTrial() const;
void skipActivation();
SubscriptionManager(AppConfig* appConfig);
SerialKey setSerialKey(QString serialKey);
void update() const;
Edition activeLicense() const;
void skipActivation();
private:
void notifyActivation(QString identity);
void notifyActivation(QString identity);
private:
AppConfig* m_AppConfig;
SerialKey m_serialKey;
AppConfig* m_AppConfig;
SerialKey m_serialKey;
signals:
void serialKeyChanged (SerialKey);
void editionChanged (Edition);
void beginTrial ();
void endTrial ();
void serialKeyChanged (SerialKey) const;
void editionChanged (Edition) const;
void beginTrial (bool expiring) const;
void endTrial (bool expired) const;
};

View File

@ -26,194 +26,194 @@
using namespace std;
SerialKey::SerialKey(Edition edition):
m_userLimit(1),
m_warnTime(ULLONG_MAX),
m_expireTime(ULLONG_MAX),
m_edition(edition),
m_trial(false),
m_valid(true)
m_userLimit(1),
m_warnTime(ULLONG_MAX),
m_expireTime(ULLONG_MAX),
m_edition(edition),
m_trial(false),
m_valid(true)
{
}
SerialKey::SerialKey(std::string serial) :
m_userLimit(1),
m_warnTime(0),
m_expireTime(0),
m_edition(Edition::kBasic),
m_trial(true),
m_valid(false)
m_userLimit(1),
m_warnTime(0),
m_expireTime(0),
m_edition(Edition::kBasic),
m_trial(true),
m_valid(false)
{
string plainText = decode(serial);
if (!plainText.empty()) {
parse(plainText);
}
string plainText = decode(serial);
if (!plainText.empty()) {
parse(plainText);
}
}
bool
SerialKey::isValid(time_t currentTime) const
{
bool result = false;
bool result = false;
if (m_valid) {
if (m_trial) {
if (currentTime < m_expireTime) {
result = true;
}
}
else {
result = true;
}
}
if (m_valid) {
if (m_trial) {
if (currentTime < m_expireTime) {
result = true;
}
}
else {
result = true;
}
}
return result;
return result;
}
bool
SerialKey::isExpiring(time_t currentTime) const
{
bool result = false;
bool result = false;
if (m_valid) {
if (m_warnTime <= currentTime && currentTime < m_expireTime) {
result = true;
}
}
if (m_valid) {
if (m_warnTime <= currentTime && currentTime < m_expireTime) {
result = true;
}
}
return result;
return result;
}
bool
SerialKey::isExpired(time_t currentTime) const
{
bool result = false;
bool result = false;
if (m_valid) {
if (m_expireTime <= currentTime) {
result = true;
}
}
if (m_valid) {
if (m_expireTime <= currentTime) {
result = true;
}
}
return result;
return result;
}
bool
SerialKey::isTrial() const
{
return m_trial;
return m_trial;
}
Edition
SerialKey::edition() const
{
return m_edition;
return m_edition;
}
time_t
SerialKey::daysLeft(time_t currentTime) const
{
unsigned long long timeLeft = 0;
unsigned long long const day = 60 * 60 * 24;
unsigned long long timeLeft = 0;
unsigned long long const day = 60 * 60 * 24;
if (currentTime < m_expireTime) {
timeLeft = m_expireTime - currentTime;
}
if (currentTime < m_expireTime) {
timeLeft = m_expireTime - currentTime;
}
unsigned long long dayLeft = 0;
dayLeft = timeLeft % day != 0 ? 1 : 0;
unsigned long long dayLeft = 0;
dayLeft = timeLeft % day != 0 ? 1 : 0;
return timeLeft / day + dayLeft;
return timeLeft / day + dayLeft;
}
std::string
SerialKey::decode(const std::string& serial) const
{
static const char* const lut = "0123456789ABCDEF";
string output;
size_t len = serial.length();
if (len & 1) {
return output;
}
static const char* const lut = "0123456789ABCDEF";
string output;
size_t len = serial.length();
if (len & 1) {
return output;
}
output.reserve(len / 2);
for (size_t i = 0; i < len; i += 2) {
output.reserve(len / 2);
for (size_t i = 0; i < len; i += 2) {
char a = serial[i];
char b = serial[i + 1];
char a = serial[i];
char b = serial[i + 1];
const char* p = std::lower_bound(lut, lut + 16, a);
const char* q = std::lower_bound(lut, lut + 16, b);
const char* p = std::lower_bound(lut, lut + 16, a);
const char* q = std::lower_bound(lut, lut + 16, b);
if (*q != b || *p != a) {
return output;
}
if (*q != b || *p != a) {
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;
}
void
SerialKey::parse(std::string plainSerial)
{
string parityStart = plainSerial.substr(0, 1);
string parityEnd = plainSerial.substr(plainSerial.length() - 1, 1);
string parityStart = plainSerial.substr(0, 1);
string parityEnd = plainSerial.substr(plainSerial.length() - 1, 1);
// check for parity chars { and }, record parity result, then remove them.
if (parityStart == "{" && parityEnd == "}") {
plainSerial = plainSerial.substr(1, plainSerial.length() - 2);
// check for parity chars { and }, record parity result, then remove them.
if (parityStart == "{" && parityEnd == "}") {
plainSerial = plainSerial.substr(1, plainSerial.length() - 2);
// tokenize serialised subscription.
vector<string> parts;
std::string::size_type pos = 0;
bool look = true;
while (look) {
std::string::size_type start = pos;
pos = plainSerial.find(";", pos);
if (pos == string::npos) {
pos = plainSerial.length();
look = false;
}
parts.push_back(plainSerial.substr(start, pos - start));
pos += 1;
}
// tokenize serialised subscription.
vector<string> parts;
std::string::size_type pos = 0;
bool look = true;
while (look) {
std::string::size_type start = pos;
pos = plainSerial.find(";", pos);
if (pos == string::npos) {
pos = plainSerial.length();
look = false;
}
parts.push_back(plainSerial.substr(start, pos - start));
pos += 1;
}
if ((parts.size() == 8)
&& (parts.at(0).find("v1") != string::npos)) {
// e.g.: {v1;basic;Bob;1;email;company name;1398297600;1398384000}
m_edition = getEdition(parts.at(1));
m_name = parts.at(2);
m_trial = false;
sscanf(parts.at(3).c_str(), "%d", &m_userLimit);
m_email = parts.at(4);
m_company = parts.at(5);
sscanf(parts.at(6).c_str(), "%lld", &m_warnTime);
sscanf(parts.at(7).c_str(), "%lld", &m_expireTime);
m_valid = true;
}
else if ((parts.size() == 9)
&& (parts.at(0).find("v2") != string::npos)) {
// e.g.: {v2;trial;basic;Bob;1;email;company name;1398297600;1398384000}
m_trial = parts.at(1) == "trial" ? true : false;
m_edition = getEdition(parts.at(2));
m_name = parts.at(3);
sscanf(parts.at(4).c_str(), "%d", &m_userLimit);
m_email = parts.at(5);
m_company = parts.at(6);
sscanf(parts.at(7).c_str(), "%lld", &m_warnTime);
sscanf(parts.at(8).c_str(), "%lld", &m_expireTime);
m_valid = true;
}
}
if ((parts.size() == 8)
&& (parts.at(0).find("v1") != string::npos)) {
// e.g.: {v1;basic;Bob;1;email;company name;1398297600;1398384000}
m_edition = parseEdition(parts.at(1));
m_name = parts.at(2);
m_trial = false;
sscanf(parts.at(3).c_str(), "%d", &m_userLimit);
m_email = parts.at(4);
m_company = parts.at(5);
sscanf(parts.at(6).c_str(), "%lld", &m_warnTime);
sscanf(parts.at(7).c_str(), "%lld", &m_expireTime);
m_valid = true;
}
else if ((parts.size() == 9)
&& (parts.at(0).find("v2") != string::npos)) {
// e.g.: {v2;trial;basic;Bob;1;email;company name;1398297600;1398384000}
m_trial = parts.at(1) == "trial" ? true : false;
m_edition = parseEdition(parts.at(2));
m_name = parts.at(3);
sscanf(parts.at(4).c_str(), "%d", &m_userLimit);
m_email = parts.at(5);
m_company = parts.at(6);
sscanf(parts.at(7).c_str(), "%lld", &m_warnTime);
sscanf(parts.at(8).c_str(), "%lld", &m_expireTime);
m_valid = true;
}
}
}
Edition
SerialKey::getEdition(std::string editionStr)
SerialKey::parseEdition(std::string editionStr)
{
Edition e = Edition::kBasic;
if (editionStr == "pro") {
e = Edition::kPro;
}
Edition e = Edition::kBasic;
if (editionStr == "pro") {
e = Edition::kPro;
}
return e;
return e;
}

View File

@ -26,61 +26,61 @@
#endif
class SerialKey {
friend bool operator== (SerialKey const&, SerialKey const&);
friend bool operator== (SerialKey const&, SerialKey const&);
public:
explicit SerialKey(Edition edition = Edition::kUnregistered);
explicit SerialKey(std::string serial);
explicit SerialKey(Edition edition = Edition::kUnregistered);
explicit SerialKey(std::string serial);
bool isValid(time_t currentTime) const;
bool isExpiring(time_t currentTime) const;
bool isExpired(time_t currentTime) const;
bool isTrial() const;
time_t daysLeft(time_t currentTime) const;
Edition edition() const;
bool isValid(time_t currentTime) const;
bool isExpiring(time_t currentTime) const;
bool isExpired(time_t currentTime) const;
bool isTrial() const;
time_t daysLeft(time_t currentTime) const;
Edition edition() const;
private:
std::string decode(const std::string& serial) const;
void parse(std::string plainSerial);
Edition getEdition(std::string editionStr);
std::string decode(const std::string& serial) const;
void parse(std::string plainSerial);
Edition parseEdition(std::string editionStr);
#ifdef TEST_ENV
private:
FRIEND_TEST(SerialKeyTests, decode_empty_returnEmptyString);
FRIEND_TEST(SerialKeyTests, decode_invalidDigit_returnEmptyString);
FRIEND_TEST(SerialKeyTests, decode_validSerial_returnPlainText);
FRIEND_TEST(SerialKeyTests, parse_noParty_invalid);
FRIEND_TEST(SerialKeyTests, parse_invalidPartsLenghth_invalid);
FRIEND_TEST(SerialKeyTests, parse_validV1Serial_valid);
FRIEND_TEST(SerialKeyTests, parse_validV2Serial_valid);
FRIEND_TEST(SerialKeyTests, decode_empty_returnEmptyString);
FRIEND_TEST(SerialKeyTests, decode_invalidDigit_returnEmptyString);
FRIEND_TEST(SerialKeyTests, decode_validSerial_returnPlainText);
FRIEND_TEST(SerialKeyTests, parse_noParty_invalid);
FRIEND_TEST(SerialKeyTests, parse_invalidPartsLenghth_invalid);
FRIEND_TEST(SerialKeyTests, parse_validV1Serial_valid);
FRIEND_TEST(SerialKeyTests, parse_validV2Serial_valid);
#endif
private:
std::string m_name;
std::string m_email;
std::string m_company;
unsigned m_userLimit;
unsigned long long m_warnTime;
unsigned long long m_expireTime;
Edition m_edition;
bool m_trial;
bool m_valid;
std::string m_name;
std::string m_email;
std::string m_company;
unsigned m_userLimit;
unsigned long long m_warnTime;
unsigned long long m_expireTime;
Edition m_edition;
bool m_trial;
bool m_valid;
};
inline bool
operator== (SerialKey const& lhs, SerialKey const& rhs) {
return (lhs.m_name == rhs.m_name) &&
(lhs.m_email == rhs.m_email) &&
(lhs.m_company == rhs.m_company) &&
(lhs.m_userLimit == rhs.m_userLimit) &&
(lhs.m_warnTime == rhs.m_warnTime) &&
(lhs.m_expireTime == rhs.m_expireTime) &&
(lhs.m_edition == rhs.m_edition) &&
(lhs.m_trial == rhs.m_trial) &&
(lhs.m_valid == rhs.m_valid);
return (lhs.m_name == rhs.m_name) &&
(lhs.m_email == rhs.m_email) &&
(lhs.m_company == rhs.m_company) &&
(lhs.m_userLimit == rhs.m_userLimit) &&
(lhs.m_warnTime == rhs.m_warnTime) &&
(lhs.m_expireTime == rhs.m_expireTime) &&
(lhs.m_edition == rhs.m_edition) &&
(lhs.m_trial == rhs.m_trial) &&
(lhs.m_valid == rhs.m_valid);
}
inline bool
operator!= (SerialKey const& lhs, SerialKey const& rhs) {
return !(lhs == rhs);
return !(lhs == rhs);
}