Apply clang-format to Lts/Common and DTC/enum headers

- Formatted all CodeGen module files (9 files)
- Formatted LtsAppDescriptor module files
- Formatted LtsAppManager/AppChooser files
- Applied clang-format to all DTC and enum headers across modules
- Removed coordTransTests from CommonUnitTestsPlaceholder (moved to tests/)

Cosmetic changes only, no functional modifications.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
torstenandCopilot committed 2026-08-19 14:46:29 +02:00
1 parent 1881d68aef
commit d6b6ffce7c
848 files changed
+89305 -100020

No files matched your search

+142 -189
View File
@@ -1,232 +1,185 @@
#include "aes_crypt.h"
#include <QtCore/QByteArray>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <QtCore/QByteArray>
#include <openssl/err.h>
#include <openssl/evp.h>
namespace LtsLicence
{
struct AesCryptPrivate
{
AesCryptPrivate()
: passPhrase(QLatin1String("LTS " LTS_VERSION_MAJOR "." LTS_VERSION_MINOR))
, logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicenceLib.AesCrypt"))
{
qsrand(time(nullptr));
AesCryptPrivate()
: passPhrase(QLatin1String("LTS " LTS_VERSION_MAJOR "." LTS_VERSION_MINOR)),
logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicenceLib.AesCrypt"))
{
qsrand(time(nullptr));
#if OPENSSL_VERSION_NUMBER < 0x1010000fL
ERR_load_crypto_strings();
ERR_load_crypto_strings();
#endif
}
~AesCryptPrivate()
{
#if OPENSSL_VERSION_NUMBER < 0x1010000fL
ERR_free_strings();
#endif
}
}
QString passPhrase;
NGL::INGLLogger &logger;
~AesCryptPrivate()
{
#if OPENSSL_VERSION_NUMBER < 0x1010000fL
ERR_free_strings();
#endif
}
QString passPhrase;
NGL::INGLLogger& logger;
};
Q_GLOBAL_STATIC(AesCryptPrivate, s_Private)
void setPassPhrase(const QString &passPhrase)
void setPassPhrase(const QString& passPhrase)
{
s_Private->passPhrase = passPhrase;
s_Private->passPhrase = passPhrase;
}
QString passPhrase()
{
return s_Private->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;
if (bOk)
*bOk = false;
int ret;
int outSize1 = 0;
int outSize2 = 0;
unsigned char key[32];
int ret;
int outSize1 = 0;
int outSize2 = 0;
unsigned char key[32];
const QByteArray baPassword = pw.toUtf8();
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();
}
const QByteArray baPassword = pw.toUtf8();
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();
}
const QByteArray baSalt = dataToDecrypt.left(EVP_MAX_IV_LENGTH);
const unsigned char *salt = reinterpret_cast<const unsigned char *>(baSalt.data());
const QByteArray baSalt = dataToDecrypt.left(EVP_MAX_IV_LENGTH);
const unsigned char* salt = reinterpret_cast<const unsigned char*>(baSalt.data());
const QByteArray bufEncrypted = dataToDecrypt.mid(EVP_MAX_IV_LENGTH);
const QByteArray bufEncrypted = dataToDecrypt.mid(EVP_MAX_IV_LENGTH);
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();
}
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());
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();
}
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 *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();
}
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());
bufDecrypted.resize(outSize1 + outSize2);
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();
}
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);
bufDecrypted.resize(outSize1 + outSize2);
if (bOk)
*bOk = true;
return bufDecrypted;
if (bOk)
*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;
if (bOk)
*bOk = false;
int ret;
int outSize1 = 0;
int outSize2 = 0;
unsigned char key[32];
QByteArray bufEncrypted;
int ret;
int outSize1 = 0;
int outSize2 = 0;
unsigned char key[32];
QByteArray bufEncrypted;
const QByteArray baPassword = pw.toUtf8();
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();
}
const QByteArray baPassword = pw.toUtf8();
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();
}
QByteArray baSalt(EVP_MAX_IV_LENGTH, 0);
for (int i = 0; i < EVP_MAX_IV_LENGTH; ++i)
baSalt[i] = qrand();
const unsigned char *salt = reinterpret_cast<const unsigned char *>(baSalt.data());
QByteArray baSalt(EVP_MAX_IV_LENGTH, 0);
for (int i = 0; i < EVP_MAX_IV_LENGTH; ++i)
baSalt[i] = qrand();
const unsigned char* salt = reinterpret_cast<const unsigned char*>(baSalt.data());
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();
}
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());
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();
}
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 *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();
}
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());
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();
}
bufEncrypted.resize(outSize1 + outSize2 + baSalt.size());
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);
bufEncrypted.resize(outSize1 + outSize2 + baSalt.size());
if (bOk)
*bOk = true;
return bufEncrypted;
if (bOk)
*bOk = true;
return bufEncrypted;
}
}
} // namespace LtsLicence
+8 -10
View File
@@ -1,22 +1,20 @@
#pragma once
#include <QtCore/QString>
#include "ltslicence_export.h"
#include <QtCore/QString>
namespace LtsLicence
{
LTSLICENCE_EXPORT void setPassPhrase(const 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
+33 -34
View File
@@ -1,54 +1,53 @@
#include <QtCore/QCoreApplication>
#include <QtTest/QTest>
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <openssl/evp.h>
#include "aes_crypt_test.h"
#include "aes_crypt.h"
#include "aes_crypt_test.h"
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <QtCore/QCoreApplication>
#include <QtTest/QTest>
#include <openssl/evp.h>
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...");
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);
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);
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());
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());
}
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...");
}
+5 -7
View File
@@ -1,16 +1,14 @@
#pragma once
#include <QObject>
#include <QtCore/QObject>
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();
};
+113 -136
View File
@@ -1,173 +1,150 @@
#include "lts_licence.h"
#include <QDomDocument>
#include <NGLLogger/NGLLoggerBootstrap.h>
#include <QDomDocument>
#include <QObject>
namespace LtsLicence
{
static bool extractLicence(const QDomElement &licenceElement, QVector<Licence> &licenceVec);
static NGL::INGLLogger &getLogger()
static bool extractLicence(const QDomElement& licenceElement, QVector<Licence>& licenceVec);
static NGL::INGLLogger& getLogger()
{
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicence");
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicence");
}
QVector<Licence> readLicences(const QByteArray &unencryptedXmlData)
QVector<Licence> readLicences(const QByteArray& unencryptedXmlData)
{
QVector<Licence> licenceVec;
QVector<Licence> licenceVec;
QDomDocument xmlDoc;
QString errorMsg;
int errorLine = 0;
int errorColumn = 0;
QDomDocument xmlDoc;
QString errorMsg;
int errorLine = 0;
int errorColumn = 0;
if (!xmlDoc.setContent(unencryptedXmlData, &errorMsg, &errorLine, &errorColumn))
{
ERROR_LOG(getLogger()) << "Error reading xml data, " << "error in line " << errorLine
<< ", column " << errorColumn
<< ", message: " << errorMsg;
return licenceVec;
}
INFO_LOG(getLogger()) << "Try to extract licences";
QDomElement licenceElement = xmlDoc.documentElement().firstChildElement(QLatin1String("licence"));
while (!licenceElement.isNull())
{
if (!extractLicence(licenceElement, licenceVec))
if (!xmlDoc.setContent(unencryptedXmlData, &errorMsg, &errorLine, &errorColumn))
{
licenceVec.clear();
return licenceVec;
ERROR_LOG(getLogger()) << "Error reading xml data, "
<< "error in line " << errorLine << ", column " << errorColumn
<< ", message: " << errorMsg;
return licenceVec;
}
licenceElement = licenceElement.nextSiblingElement(QLatin1String("licence"));
}
return licenceVec;
}
INFO_LOG(getLogger()) << "Try to extract licences";
QDomElement licenceElement = xmlDoc.documentElement().firstChildElement(QLatin1String("licence"));
QByteArray writeUnencryptedLicences(const QVector<Licence> &licences)
while (!licenceElement.isNull())
{
if (!extractLicence(licenceElement, licenceVec))
{
licenceVec.clear();
return licenceVec;
}
licenceElement = licenceElement.nextSiblingElement(QLatin1String("licence"));
}
return licenceVec;
}
QByteArray writeUnencryptedLicences(const QVector<Licence>& licences)
{
QDomDocument xmlDoc;
QDomDocument xmlDoc;
QDomProcessingInstruction instr = xmlDoc.createProcessingInstruction(QLatin1String("xml"),
QLatin1String("version='1.0' encoding='UTF-8' standalone='yes'"));
xmlDoc.appendChild(instr);
QDomProcessingInstruction instr = xmlDoc.createProcessingInstruction(
QLatin1String("xml"), QLatin1String("version='1.0' encoding='UTF-8' standalone='yes'"));
xmlDoc.appendChild(instr);
QDomElement root = xmlDoc.createElement(QLatin1String("licences"));
xmlDoc.appendChild(root);
QDomElement root = xmlDoc.createElement(QLatin1String("licences"));
xmlDoc.appendChild(root);
for (int i = 0; i < licences.size(); ++i)
{
QDomElement lic = xmlDoc.createElement(QLatin1String("licence"));
root.appendChild(lic);
for (int i = 0; i < licences.size(); ++i)
{
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);
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)
{
Licence licence;
QDomElement tag = licenceElement.firstChildElement(QLatin1String("name"));
licence.name = tag.text();
tag = licenceElement.firstChildElement(QLatin1String("ignoreMaxCount"));
licence.ignoreMaxCount = tag.text().toInt();
tag = licenceElement.firstChildElement(QLatin1String("ignoreExpiration"));
licence.ignoreExpiration = tag.text().toInt();
tag = licenceElement.firstChildElement(QLatin1String("maxCount"));
licence.maxCount = tag.text().toInt();
tag = licenceElement.firstChildElement(QLatin1String("expiration"));
const QString qs(tag.text());
const QLatin1String format("dd.MM.yyyy hh:mm:ss");
const QString qs = licences[i].expiration.toString(format);
const QDateTime qdt = QDateTime::fromString(qs, format);
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)
{
Licence licence;
QDomElement tag = licenceElement.firstChildElement(QLatin1String("name"));
licence.name = tag.text();
tag = licenceElement.firstChildElement(QLatin1String("ignoreMaxCount"));
licence.ignoreMaxCount = tag.text().toInt();
tag = licenceElement.firstChildElement(QLatin1String("ignoreExpiration"));
licence.ignoreExpiration = tag.text().toInt();
tag = licenceElement.firstChildElement(QLatin1String("maxCount"));
licence.maxCount = tag.text().toInt();
tag = licenceElement.firstChildElement(QLatin1String("expiration"));
const QString qs(tag.text());
const QLatin1String format("dd.MM.yyyy hh:mm:ss");
const QDateTime qdt = QDateTime::fromString(qs, format);
if (!qdt.isValid())
{
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
;
licenceVec.append(licence);
return true;
}
if (!qdt.isValid())
{
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;
licenceVec.append(licence);
return true;
}
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);
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
+12 -16
View File
@@ -1,33 +1,29 @@
#pragma once
#include "ltslicence_export.h"
#include <QDateTime>
#include <QString>
#include <QVector>
#include <QDateTime>
namespace LtsLicence
{
struct LTSLICENCE_EXPORT Licence
{
QString name;
bool ignoreMaxCount = false;
bool ignoreExpiration = false;
int maxCount = 0;
QDateTime expiration;
int licenceRefCount = 0;
QString name;
bool ignoreMaxCount = false;
bool ignoreExpiration = false;
int maxCount = 0;
QDateTime expiration;
int licenceRefCount = 0;
QString toString() const;
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