The migration pipeline dropped the leading @RDE_HEADER@ comment blocks from 243 target source files (and 2 cmake macros). Restore them byte-for-byte from the legacy Qt5 tree (qt5-before/qt5-legatus-legacy): the exact legacy header is re-inserted at the top of each file (block-comment, '#'-style, line-comment '//' styles, BOM and surrounding blank lines included). File bodies are untouched. Scope: all in-scope target code, unit-test directories excluded. 190 files already kept their legacy header through the migration and were left as-is; legacy files without an RDE header were not given one. Special cases: 3 headers sitting after a '#pragma once' line, 1 BOM-prefixed file, 4 '//'-style TetraIF headers. *.grantlee template files were not in scope and remain untouched. Verified: every restored file is byte-exact (legacy preamble + original body) and the ctest baseline is unchanged (20/23 passed, 3 Not Run as before).
157 lines
5.0 KiB
C++
157 lines
5.0 KiB
C++
/**
|
|
* @RDE_HEADER@
|
|
* Licence Library
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by hjl, SLSE, 2016-06-01
|
|
*/
|
|
|
|
|
|
#include "lts_licence.h"
|
|
|
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
#include <QtXml/QDomDocument>
|
|
#include <QtCore/QObject>
|
|
|
|
namespace LtsLicence
|
|
{
|
|
static bool extractLicence(const QDomElement& licenceElement, QVector<Licence>& licenceVec);
|
|
|
|
static NGL::INGLLogger& getLogger()
|
|
{
|
|
return NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("LtsLicence");
|
|
}
|
|
|
|
QVector<Licence> readLicences(const QByteArray& unencryptedXmlData)
|
|
{
|
|
QVector<Licence> licenceVec;
|
|
|
|
QDomDocument xmlDoc;
|
|
|
|
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;
|
|
}
|
|
|
|
INFO_LOG(getLogger()) << "Try to extract licences";
|
|
|
|
QDomElement licenceElement = xmlDoc.documentElement().firstChildElement(QLatin1String("licence"));
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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("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 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;
|
|
}
|
|
|
|
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
|