#5657 Added version 2 trial serial key support

This commit is contained in:
Jerry (Xinyu Hou) 2016-10-13 11:15:38 +01:00
parent c7cd74ab5f
commit d92fcd2453
2 changed files with 35 additions and 11 deletions

View File

@ -27,4 +27,5 @@ struct SubscriptionKey {
int m_userLimit;
int m_warnTime;
int m_expireTime;
bool m_trial;
};

View File

@ -140,9 +140,11 @@ SubscriptionManager::parsePlainSerial(const String& plainText, SubscriptionKey&
pos += 1;
}
// e.g.: {v1;trial;Bob;1;email;company name;1398297600;1398384000}
bool validSerial = false;
if ((parts.size() == 8)
&& (parts.at(0).find("v1") != String::npos)) {
// e.g.: {v1;basic;Bob;1;email;company name;1398297600;1398384000}
key.m_type = parts.at(1);
key.m_name = parts.at(2);
sscanf(parts.at(3).c_str(), "%d", &key.m_userLimit);
@ -151,8 +153,22 @@ SubscriptionManager::parsePlainSerial(const String& plainText, SubscriptionKey&
sscanf(parts.at(6).c_str(), "%d", &key.m_warnTime);
sscanf(parts.at(7).c_str(), "%d", &key.m_expireTime);
validSerial = 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}
key.m_trial = parts.at(1) == "trial" ? true : false;
key.m_type = parts.at(2);
key.m_name = parts.at(3);
sscanf(parts.at(4).c_str(), "%d", &key.m_userLimit);
key.m_email = parts.at(5);
key.m_company = parts.at(6);
sscanf(parts.at(7).c_str(), "%d", &key.m_warnTime);
sscanf(parts.at(8).c_str(), "%d", &key.m_expireTime);
// only limit to trial version
if (key.m_type == "trial") {
if (key.m_trial) {
if (time(0) > key.m_expireTime) {
throw XSubscription("trial has expired");
}
@ -164,8 +180,15 @@ SubscriptionManager::parsePlainSerial(const String& plainText, SubscriptionKey&
dayLeft,
dayLeft == 1 ? "day" : "days"));
}
else {
}
}
validSerial = true;
}
if (validSerial) {
const char* userText = (key.m_userLimit == 1) ? "user" : "users";
LOG((CLOG_INFO "%s subscription valid is for %d %s, registered to %s",
key.m_type.c_str(),