Formats minimally release source files based on former clang-format
This commit is contained in:
387 files changed
+37323
-38074
No files matched your search
@@ -10,43 +10,43 @@
|
||||
|
||||
namespace LtsLicence
|
||||
{
|
||||
struct AesCryptPrivate
|
||||
{
|
||||
struct AesCryptPrivate
|
||||
{
|
||||
AesCryptPrivate()
|
||||
: passPhrase(QLatin1String("LTS " LTS_VERSION_MAJOR "." LTS_VERSION_MINOR)),
|
||||
logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicenceLib.AesCrypt"))
|
||||
: passPhrase(QLatin1String("LTS " LTS_VERSION_MAJOR "." LTS_VERSION_MINOR))
|
||||
, logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicenceLib.AesCrypt"))
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER < 0x1010000fL
|
||||
ERR_load_crypto_strings();
|
||||
ERR_load_crypto_strings();
|
||||
#endif
|
||||
}
|
||||
|
||||
~AesCryptPrivate()
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER < 0x1010000fL
|
||||
ERR_free_strings();
|
||||
ERR_free_strings();
|
||||
#endif
|
||||
}
|
||||
|
||||
QString passPhrase;
|
||||
NGL::INGLLogger& logger;
|
||||
};
|
||||
Q_GLOBAL_STATIC(AesCryptPrivate, s_Private)
|
||||
NGL::INGLLogger &logger;
|
||||
};
|
||||
Q_GLOBAL_STATIC(AesCryptPrivate, s_Private)
|
||||
|
||||
void setPassPhrase(const QString& passPhrase)
|
||||
{
|
||||
void setPassPhrase(const QString &passPhrase)
|
||||
{
|
||||
s_Private->passPhrase = passPhrase;
|
||||
}
|
||||
}
|
||||
|
||||
QString passPhrase()
|
||||
{
|
||||
QString passPhrase()
|
||||
{
|
||||
return s_Private->passPhrase;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray decryptData(const QByteArray& dataToDecrypt, const QString& pw, bool* bOk)
|
||||
{
|
||||
QByteArray decryptData(const QByteArray &dataToDecrypt, const QString &pw, bool *bOk)
|
||||
{
|
||||
if (bOk)
|
||||
*bOk = false;
|
||||
*bOk = false;
|
||||
|
||||
int ret;
|
||||
int outSize1 = 0;
|
||||
@@ -54,53 +54,53 @@ QByteArray decryptData(const QByteArray& dataToDecrypt, const QString& pw, bool*
|
||||
unsigned char key[32];
|
||||
|
||||
const QByteArray baPassword = pw.toUtf8();
|
||||
const unsigned char* dataPw = reinterpret_cast<const unsigned char*>(baPassword.data());
|
||||
const unsigned char *dataPw = reinterpret_cast<const unsigned char *>(baPassword.data());
|
||||
int i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), nullptr, dataPw, baPassword.size(), 5, key, nullptr);
|
||||
if (i != 32)
|
||||
{
|
||||
ERROR_LOG(s_Private->logger) << "Wrong key size - should be 256 bits";
|
||||
return QByteArray();
|
||||
ERROR_LOG(s_Private->logger) << "Wrong key size - should be 256 bits";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
const QByteArray baSalt = dataToDecrypt.left(EVP_MAX_IV_LENGTH);
|
||||
const unsigned char* salt = reinterpret_cast<const unsigned char*>(baSalt.data());
|
||||
const unsigned char *salt = reinterpret_cast<const unsigned char *>(baSalt.data());
|
||||
|
||||
const QByteArray bufEncrypted = dataToDecrypt.mid(EVP_MAX_IV_LENGTH);
|
||||
|
||||
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
|
||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
||||
ret = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, key, salt);
|
||||
if (ret == 0)
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_DecryptInit_ex failed";
|
||||
return QByteArray();
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_DecryptInit_ex failed";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
QByteArray bufDecrypted;
|
||||
bufDecrypted.resize(bufEncrypted.size() + EVP_CIPHER_CTX_block_size(ctx));
|
||||
const unsigned char* dataIn = reinterpret_cast<const unsigned char*>(bufEncrypted.data());
|
||||
unsigned char* dataOut = reinterpret_cast<unsigned char*>(bufDecrypted.data());
|
||||
const unsigned char *dataIn = reinterpret_cast<const unsigned char *>(bufEncrypted.data());
|
||||
unsigned char *dataOut = reinterpret_cast<unsigned char *>(bufDecrypted.data());
|
||||
|
||||
ret = EVP_DecryptUpdate(ctx, dataOut, &outSize1, dataIn, bufEncrypted.size());
|
||||
if (ret == 0)
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_DecryptUpdate failed";
|
||||
return QByteArray();
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_DecryptUpdate failed";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
ret = EVP_DecryptFinal_ex(ctx, dataOut + outSize1, &outSize2);
|
||||
if (ret == 0)
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_DecryptFinal_ex failed";
|
||||
return QByteArray();
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_DecryptFinal_ex failed";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
@@ -108,14 +108,14 @@ QByteArray decryptData(const QByteArray& dataToDecrypt, const QString& pw, bool*
|
||||
bufDecrypted.resize(outSize1 + outSize2);
|
||||
|
||||
if (bOk)
|
||||
*bOk = true;
|
||||
*bOk = true;
|
||||
return bufDecrypted;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray encryptData(const QByteArray& dataToEncrypt, const QString& pw, bool* bOk)
|
||||
{
|
||||
QByteArray encryptData(const QByteArray &dataToEncrypt, const QString &pw, bool *bOk)
|
||||
{
|
||||
if (bOk)
|
||||
*bOk = false;
|
||||
*bOk = false;
|
||||
|
||||
int ret;
|
||||
int outSize1 = 0;
|
||||
@@ -124,53 +124,53 @@ QByteArray encryptData(const QByteArray& dataToEncrypt, const QString& pw, bool*
|
||||
QByteArray bufEncrypted;
|
||||
|
||||
const QByteArray baPassword = pw.toUtf8();
|
||||
const unsigned char* dataPw = reinterpret_cast<const unsigned char*>(baPassword.data());
|
||||
const unsigned char *dataPw = reinterpret_cast<const unsigned char *>(baPassword.data());
|
||||
int i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), nullptr, dataPw, baPassword.size(), 5, key, nullptr);
|
||||
if (i != 32)
|
||||
{
|
||||
ERROR_LOG(s_Private->logger) << "Wrong key size - should be 256 bits";
|
||||
return QByteArray();
|
||||
ERROR_LOG(s_Private->logger) << "Wrong key size - should be 256 bits";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
QByteArray baSalt(EVP_MAX_IV_LENGTH, 0);
|
||||
for (int i = 0; i < EVP_MAX_IV_LENGTH; ++i)
|
||||
baSalt[i] = static_cast<char>(QRandomGenerator::global()->bounded(256));
|
||||
const unsigned char* salt = reinterpret_cast<const unsigned char*>(baSalt.data());
|
||||
baSalt[i] = static_cast<char>(QRandomGenerator::global()->bounded(256));
|
||||
const unsigned char *salt = reinterpret_cast<const unsigned char *>(baSalt.data());
|
||||
|
||||
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
|
||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
||||
ret = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, key, salt);
|
||||
if (ret == 0)
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_EncryptInit_ex failed";
|
||||
return QByteArray();
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_EncryptInit_ex failed";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
bufEncrypted = QByteArray::fromRawData(reinterpret_cast<const char*>(salt), EVP_MAX_IV_LENGTH);
|
||||
bufEncrypted = QByteArray::fromRawData(reinterpret_cast<const char *>(salt), EVP_MAX_IV_LENGTH);
|
||||
bufEncrypted.resize(bufEncrypted.size() + dataToEncrypt.size() + EVP_CIPHER_CTX_block_size(ctx));
|
||||
const unsigned char* dataIn = reinterpret_cast<const unsigned char*>(dataToEncrypt.data());
|
||||
unsigned char* dataOut = reinterpret_cast<unsigned char*>(bufEncrypted.data());
|
||||
const unsigned char *dataIn = reinterpret_cast<const unsigned char *>(dataToEncrypt.data());
|
||||
unsigned char *dataOut = reinterpret_cast<unsigned char *>(bufEncrypted.data());
|
||||
dataOut += baSalt.size();
|
||||
ret = EVP_EncryptUpdate(ctx, dataOut, &outSize1, dataIn, dataToEncrypt.size());
|
||||
if (ret == 0)
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_EncryptUpdate failed";
|
||||
return QByteArray();
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_EncryptUpdate failed";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
ret = EVP_EncryptFinal_ex(ctx, dataOut + outSize1, &outSize2);
|
||||
if (ret == 0)
|
||||
{
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_EncryptFinal_ex failed";
|
||||
return QByteArray();
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
char errbuf[256];
|
||||
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
|
||||
ERROR_LOG(s_Private->logger) << "EVP_EncryptFinal_ex failed";
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
@@ -178,8 +178,8 @@ QByteArray encryptData(const QByteArray& dataToEncrypt, const QString& pw, bool*
|
||||
bufEncrypted.resize(outSize1 + outSize2 + baSalt.size());
|
||||
|
||||
if (bOk)
|
||||
*bOk = true;
|
||||
*bOk = true;
|
||||
return bufEncrypted;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace LtsLicence
|
||||
@@ -9,12 +9,10 @@
|
||||
namespace LtsLicence
|
||||
{
|
||||
|
||||
LTSLICENCE_EXPORT void setPassPhrase(const QString& passPhrase);
|
||||
LTSLICENCE_EXPORT QString passPhrase();
|
||||
LTSLICENCE_EXPORT void setPassPhrase(const QString &passPhrase);
|
||||
LTSLICENCE_EXPORT QString passPhrase();
|
||||
|
||||
LTSLICENCE_EXPORT QByteArray decryptData(const QByteArray& dataToDecrypt, const QString& pw = passPhrase(),
|
||||
bool* bOk = nullptr);
|
||||
LTSLICENCE_EXPORT QByteArray decryptData(const QByteArray &dataToDecrypt, const QString &pw = passPhrase(), bool *bOk = nullptr);
|
||||
|
||||
LTSLICENCE_EXPORT QByteArray encryptData(const QByteArray& dataToEncrypt, const QString& pw = passPhrase(),
|
||||
bool* bOk = nullptr);
|
||||
LTSLICENCE_EXPORT QByteArray encryptData(const QByteArray &dataToEncrypt, const QString &pw = passPhrase(), bool *bOk = nullptr);
|
||||
} // namespace LtsLicence
|
||||
@@ -13,41 +13,41 @@ QTEST_MAIN(aes_crypt_test)
|
||||
|
||||
void aes_crypt_test::initTestCase()
|
||||
{
|
||||
NGL::NGLLoggerBootstrap::createNGLRootLogger("log4cxx.props", false);
|
||||
NGL::NGLLoggerBootstrap::createNGLRootLogger("log4cxx.props", false);
|
||||
}
|
||||
|
||||
void aes_crypt_test::truePassTest()
|
||||
{
|
||||
qDebug("Simple TestCase");
|
||||
bool bOk;
|
||||
const QByteArray content("30.06.2013");
|
||||
const QString pw(QStringLiteral("aes_crypt_test"));
|
||||
const QByteArray enc = LtsLicence::encryptData(content, pw, &bOk);
|
||||
QVERIFY2(bOk, "Error encrypting data...");
|
||||
qDebug("Simple TestCase");
|
||||
bool bOk;
|
||||
const QByteArray content("30.06.2013");
|
||||
const QString pw(QStringLiteral("aes_crypt_test"));
|
||||
const QByteArray enc = LtsLicence::encryptData(content, pw, &bOk);
|
||||
QVERIFY2(bOk, "Error encrypting data...");
|
||||
|
||||
QCOMPARE(((content.size() + 15 + EVP_MAX_IV_LENGTH) / 18) * 16, enc.size());
|
||||
const QByteArray dec = LtsLicence::decryptData(enc, pw, &bOk);
|
||||
QVERIFY2(bOk, "Error encrypting data...");
|
||||
QCOMPARE(dec, content);
|
||||
QCOMPARE(((content.size() + 15 + EVP_MAX_IV_LENGTH) / 18) * 16, enc.size());
|
||||
const QByteArray dec = LtsLicence::decryptData(enc, pw, &bOk);
|
||||
QVERIFY2(bOk, "Error encrypting data...");
|
||||
QCOMPARE(dec, content);
|
||||
|
||||
const QByteArray bigContent(12345, '1');
|
||||
const QByteArray bigEnc = LtsLicence::encryptData(bigContent, pw, &bOk);
|
||||
QVERIFY2(bOk, "Error encrypting data...");
|
||||
const QByteArray bigContent(12345, '1');
|
||||
const QByteArray bigEnc = LtsLicence::encryptData(bigContent, pw, &bOk);
|
||||
QVERIFY2(bOk, "Error encrypting data...");
|
||||
|
||||
QCOMPARE(((bigContent.size() + 15 + EVP_MAX_IV_LENGTH) / 16) * 16, bigEnc.size());
|
||||
QCOMPARE(((bigContent.size() + 15 + EVP_MAX_IV_LENGTH) / 16) * 16, bigEnc.size());
|
||||
}
|
||||
|
||||
void aes_crypt_test::falsePassTest()
|
||||
{
|
||||
qDebug("False Password TestCase");
|
||||
bool bOk;
|
||||
const QByteArray content("30.06.2013");
|
||||
const QString pw(QStringLiteral("aes_crypt_test"));
|
||||
const QString pw2(QStringLiteral("aes_crypt_test2"));
|
||||
const QByteArray enc = LtsLicence::encryptData(content, pw, &bOk);
|
||||
QVERIFY2(bOk, "Error encrypting data...");
|
||||
QVERIFY2(enc.size() != 20, "Error encrypting data...");
|
||||
const QByteArray dec = LtsLicence::decryptData(enc, pw2, &bOk);
|
||||
QVERIFY2(!bOk, "Error encrypting data...");
|
||||
QVERIFY2(dec.isEmpty(), "decrypted data is not empty...");
|
||||
qDebug("False Password TestCase");
|
||||
bool bOk;
|
||||
const QByteArray content("30.06.2013");
|
||||
const QString pw(QStringLiteral("aes_crypt_test"));
|
||||
const QString pw2(QStringLiteral("aes_crypt_test2"));
|
||||
const QByteArray enc = LtsLicence::encryptData(content, pw, &bOk);
|
||||
QVERIFY2(bOk, "Error encrypting data...");
|
||||
QVERIFY2(enc.size() != 20, "Error encrypting data...");
|
||||
const QByteArray dec = LtsLicence::decryptData(enc, pw2, &bOk);
|
||||
QVERIFY2(!bOk, "Error encrypting data...");
|
||||
QVERIFY2(dec.isEmpty(), "decrypted data is not empty...");
|
||||
}
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
class aes_crypt_test : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void truePassTest();
|
||||
void falsePassTest();
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void truePassTest();
|
||||
void falsePassTest();
|
||||
};
|
||||
@@ -8,15 +8,15 @@
|
||||
|
||||
namespace LtsLicence
|
||||
{
|
||||
static bool extractLicence(const QDomElement& licenceElement, QVector<Licence>& licenceVec);
|
||||
static bool extractLicence(const QDomElement &licenceElement, QVector<Licence> &licenceVec);
|
||||
|
||||
static NGL::INGLLogger& getLogger()
|
||||
{
|
||||
static NGL::INGLLogger &getLogger()
|
||||
{
|
||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicence");
|
||||
}
|
||||
}
|
||||
|
||||
QVector<Licence> readLicences(const QByteArray& unencryptedXmlData)
|
||||
{
|
||||
QVector<Licence> readLicences(const QByteArray &unencryptedXmlData)
|
||||
{
|
||||
QVector<Licence> licenceVec;
|
||||
|
||||
QDomDocument xmlDoc;
|
||||
@@ -24,10 +24,10 @@ QVector<Licence> readLicences(const QByteArray& unencryptedXmlData)
|
||||
const auto parseResult = xmlDoc.setContent(unencryptedXmlData);
|
||||
if (!parseResult)
|
||||
{
|
||||
ERROR_LOG(getLogger()) << "Error reading xml data, "
|
||||
<< "error in line " << int(parseResult.errorLine) << ", column " << int(parseResult.errorColumn)
|
||||
<< ", message: " << parseResult.errorMessage;
|
||||
return licenceVec;
|
||||
ERROR_LOG(getLogger()) << "Error reading xml data, "
|
||||
<< "error in line " << int(parseResult.errorLine) << ", column " << int(parseResult.errorColumn)
|
||||
<< ", message: " << parseResult.errorMessage;
|
||||
return licenceVec;
|
||||
}
|
||||
|
||||
INFO_LOG(getLogger()) << "Try to extract licences";
|
||||
@@ -36,23 +36,22 @@ QVector<Licence> readLicences(const QByteArray& unencryptedXmlData)
|
||||
|
||||
while (!licenceElement.isNull())
|
||||
{
|
||||
if (!extractLicence(licenceElement, licenceVec))
|
||||
{
|
||||
licenceVec.clear();
|
||||
return licenceVec;
|
||||
}
|
||||
if (!extractLicence(licenceElement, licenceVec))
|
||||
{
|
||||
licenceVec.clear();
|
||||
return licenceVec;
|
||||
}
|
||||
|
||||
licenceElement = licenceElement.nextSiblingElement(QLatin1String("licence"));
|
||||
licenceElement = licenceElement.nextSiblingElement(QLatin1String("licence"));
|
||||
}
|
||||
return licenceVec;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray writeUnencryptedLicences(const QVector<Licence>& licences)
|
||||
{
|
||||
QByteArray writeUnencryptedLicences(const QVector<Licence> &licences)
|
||||
{
|
||||
QDomDocument xmlDoc;
|
||||
|
||||
QDomProcessingInstruction instr = xmlDoc.createProcessingInstruction(
|
||||
QLatin1String("xml"), QLatin1String("version='1.0' encoding='UTF-8' standalone='yes'"));
|
||||
QDomProcessingInstruction instr = xmlDoc.createProcessingInstruction(QLatin1String("xml"), QLatin1String("version='1.0' encoding='UTF-8' standalone='yes'"));
|
||||
xmlDoc.appendChild(instr);
|
||||
|
||||
QDomElement root = xmlDoc.createElement(QLatin1String("licences"));
|
||||
@@ -60,43 +59,43 @@ QByteArray writeUnencryptedLicences(const QVector<Licence>& licences)
|
||||
|
||||
for (int i = 0; i < licences.size(); ++i)
|
||||
{
|
||||
QDomElement lic = xmlDoc.createElement(QLatin1String("licence"));
|
||||
root.appendChild(lic);
|
||||
QDomElement lic = xmlDoc.createElement(QLatin1String("licence"));
|
||||
root.appendChild(lic);
|
||||
|
||||
QDomElement element = xmlDoc.createElement(QLatin1String("name"));
|
||||
QDomText text = xmlDoc.createTextNode(licences[i].name);
|
||||
element.appendChild(text);
|
||||
lic.appendChild(element);
|
||||
QDomElement element = xmlDoc.createElement(QLatin1String("name"));
|
||||
QDomText text = xmlDoc.createTextNode(licences[i].name);
|
||||
element.appendChild(text);
|
||||
lic.appendChild(element);
|
||||
|
||||
element = xmlDoc.createElement(QLatin1String("ignoreMaxCount"));
|
||||
text = xmlDoc.createTextNode(QString::number(licences[i].ignoreMaxCount));
|
||||
element.appendChild(text);
|
||||
lic.appendChild(element);
|
||||
element = xmlDoc.createElement(QLatin1String("ignoreMaxCount"));
|
||||
text = xmlDoc.createTextNode(QString::number(licences[i].ignoreMaxCount));
|
||||
element.appendChild(text);
|
||||
lic.appendChild(element);
|
||||
|
||||
element = xmlDoc.createElement(QLatin1String("ignoreExpiration"));
|
||||
text = xmlDoc.createTextNode(QString::number(licences[i].ignoreExpiration));
|
||||
element.appendChild(text);
|
||||
lic.appendChild(element);
|
||||
element = xmlDoc.createElement(QLatin1String("ignoreExpiration"));
|
||||
text = xmlDoc.createTextNode(QString::number(licences[i].ignoreExpiration));
|
||||
element.appendChild(text);
|
||||
lic.appendChild(element);
|
||||
|
||||
element = xmlDoc.createElement(QLatin1String("maxCount"));
|
||||
text = xmlDoc.createTextNode(QString::number(licences[i].maxCount));
|
||||
element.appendChild(text);
|
||||
lic.appendChild(element);
|
||||
element = xmlDoc.createElement(QLatin1String("maxCount"));
|
||||
text = xmlDoc.createTextNode(QString::number(licences[i].maxCount));
|
||||
element.appendChild(text);
|
||||
lic.appendChild(element);
|
||||
|
||||
const QLatin1String format("dd.MM.yyyy hh:mm:ss");
|
||||
const QString qs = licences[i].expiration.toString(format);
|
||||
const QLatin1String format("dd.MM.yyyy hh:mm:ss");
|
||||
const QString qs = licences[i].expiration.toString(format);
|
||||
|
||||
element = xmlDoc.createElement(QLatin1String("expiration"));
|
||||
text = xmlDoc.createTextNode(qs);
|
||||
element.appendChild(text);
|
||||
lic.appendChild(element);
|
||||
element = xmlDoc.createElement(QLatin1String("expiration"));
|
||||
text = xmlDoc.createTextNode(qs);
|
||||
element.appendChild(text);
|
||||
lic.appendChild(element);
|
||||
}
|
||||
INFO_LOG(getLogger()) << "Generated XML Data...\n" << xmlDoc.toByteArray();
|
||||
return xmlDoc.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
bool extractLicence(const QDomElement& licenceElement, QVector<Licence>& licenceVec)
|
||||
{
|
||||
bool extractLicence(const QDomElement &licenceElement, QVector<Licence> &licenceVec)
|
||||
{
|
||||
Licence licence;
|
||||
|
||||
QDomElement tag = licenceElement.firstChildElement(QLatin1String("name"));
|
||||
@@ -120,29 +119,28 @@ bool extractLicence(const QDomElement& licenceElement, QVector<Licence>& licence
|
||||
|
||||
if (!qdt.isValid())
|
||||
{
|
||||
ERROR_LOG(getLogger()) << "Invalid expiration format! " << qs << " used format: " << format;
|
||||
return false;
|
||||
ERROR_LOG(getLogger()) << "Invalid expiration format! " << qs << " used format: " << format;
|
||||
return false;
|
||||
}
|
||||
|
||||
licence.expiration = qdt;
|
||||
INFO_LOG(getLogger()) << "Read licence for:'" << licence.name << "'"
|
||||
<< " IgnoreMaxCount: " << licence.ignoreMaxCount
|
||||
<< " IgnoreExpiration: " << licence.ignoreExpiration << " MaxCount: " << licence.maxCount
|
||||
<< " Expiration: " << licence.expiration.date().toString() << " "
|
||||
<< licence.expiration.time().toString() << " RefCount: " << licence.licenceRefCount;
|
||||
<< " IgnoreMaxCount: " << licence.ignoreMaxCount << " IgnoreExpiration: " << licence.ignoreExpiration << " MaxCount: " << licence.maxCount
|
||||
<< " Expiration: " << licence.expiration.date().toString() << " " << licence.expiration.time().toString()
|
||||
<< " RefCount: " << licence.licenceRefCount;
|
||||
|
||||
licenceVec.append(licence);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
QString Licence::toString() const
|
||||
{
|
||||
QString Licence::toString() const
|
||||
{
|
||||
return QObject::tr("Name: %1, Count: %2, ExpireDate: %3, Expires: %4, UseMaxCount: %5")
|
||||
.arg(name)
|
||||
.arg(maxCount)
|
||||
.arg(expiration.toString())
|
||||
.arg(ignoreExpiration)
|
||||
.arg(ignoreMaxCount);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace LtsLicence
|
||||
@@ -11,8 +11,8 @@
|
||||
namespace LtsLicence
|
||||
{
|
||||
|
||||
struct LTSLICENCE_EXPORT Licence
|
||||
{
|
||||
struct LTSLICENCE_EXPORT Licence
|
||||
{
|
||||
QString name;
|
||||
bool ignoreMaxCount = false;
|
||||
bool ignoreExpiration = false;
|
||||
@@ -21,9 +21,9 @@ struct LTSLICENCE_EXPORT Licence
|
||||
int licenceRefCount = 0;
|
||||
|
||||
QString toString() const;
|
||||
};
|
||||
};
|
||||
|
||||
LTSLICENCE_EXPORT QVector<Licence> readLicences(const QByteArray& unencryptedXmlData);
|
||||
LTSLICENCE_EXPORT QVector<Licence> readLicences(const QByteArray &unencryptedXmlData);
|
||||
|
||||
LTSLICENCE_EXPORT QByteArray writeUnencryptedLicences(const QVector<Licence>& licences);
|
||||
LTSLICENCE_EXPORT QByteArray writeUnencryptedLicences(const QVector<Licence> &licences);
|
||||
} // namespace LtsLicence
|
||||
Reference in new issue
Block a user