2009-06-24 09:54:56 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2023-01-28 10:16:34 +01:00
|
|
|
* Copyright (C) 2007-2023 Cppcheck team.
|
2009-06-24 09:54:56 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-24 09:54:56 +02:00
|
|
|
*/
|
|
|
|
|
2021-04-03 21:30:50 +02:00
|
|
|
#include "xmlreport.h"
|
|
|
|
|
2022-02-02 16:17:28 +01:00
|
|
|
#include "report.h"
|
|
|
|
|
2011-02-05 11:12:34 +01:00
|
|
|
#include <QFile>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QIODevice>
|
|
|
|
#include <QXmlStreamAttributes>
|
2011-02-05 11:12:34 +01:00
|
|
|
#include <QXmlStreamReader>
|
2009-06-24 09:54:56 +02:00
|
|
|
|
2023-04-08 16:08:47 +02:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
|
|
|
#include <QStringRef>
|
|
|
|
#endif
|
|
|
|
|
2011-02-05 11:12:34 +01:00
|
|
|
static const char ResultElementName[] = "results";
|
|
|
|
static const char VersionAttribute[] = "version";
|
2010-07-10 15:37:36 +02:00
|
|
|
|
2012-10-27 12:22:56 +02:00
|
|
|
XmlReport::XmlReport(const QString &filename) :
|
|
|
|
Report(filename)
|
2021-08-07 20:51:18 +02:00
|
|
|
{}
|
2009-06-24 09:54:56 +02:00
|
|
|
|
2011-02-04 23:23:25 +01:00
|
|
|
QString XmlReport::quoteMessage(const QString &message)
|
|
|
|
{
|
|
|
|
QString quotedMessage(message);
|
|
|
|
quotedMessage.replace("&", "&");
|
|
|
|
quotedMessage.replace("\"", """);
|
|
|
|
quotedMessage.replace("'", "'");
|
|
|
|
quotedMessage.replace("<", "<");
|
|
|
|
quotedMessage.replace(">", ">");
|
|
|
|
return quotedMessage;
|
|
|
|
}
|
2011-02-05 11:12:34 +01:00
|
|
|
|
2011-02-05 15:07:59 +01:00
|
|
|
QString XmlReport::unquoteMessage(const QString &message)
|
|
|
|
{
|
|
|
|
QString quotedMessage(message);
|
|
|
|
quotedMessage.replace("&", "&");
|
|
|
|
quotedMessage.replace(""", "\"");
|
|
|
|
quotedMessage.replace("'", "'");
|
|
|
|
quotedMessage.replace("<", "<");
|
|
|
|
quotedMessage.replace(">", ">");
|
|
|
|
return quotedMessage;
|
|
|
|
}
|
|
|
|
|
2011-02-05 11:12:34 +01:00
|
|
|
int XmlReport::determineVersion(const QString &filename)
|
|
|
|
{
|
|
|
|
QFile file;
|
|
|
|
file.setFileName(filename);
|
2022-10-02 07:12:40 +02:00
|
|
|
const bool succeed = file.open(QIODevice::ReadOnly | QIODevice::Text);
|
2011-02-05 11:12:34 +01:00
|
|
|
if (!succeed)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
QXmlStreamReader reader(&file);
|
2011-10-13 20:53:06 +02:00
|
|
|
while (!reader.atEnd()) {
|
|
|
|
switch (reader.readNext()) {
|
2011-02-05 11:12:34 +01:00
|
|
|
case QXmlStreamReader::StartElement:
|
2022-02-07 17:35:25 +01:00
|
|
|
if (reader.name() == QString(ResultElementName)) {
|
2011-02-05 11:12:34 +01:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
2011-10-13 20:53:06 +02:00
|
|
|
if (attribs.hasAttribute(QString(VersionAttribute))) {
|
2022-10-02 07:12:40 +02:00
|
|
|
const int ver = attribs.value(QString(), VersionAttribute).toString().toInt();
|
2011-02-05 11:12:34 +01:00
|
|
|
return ver;
|
2023-06-20 18:43:21 +02:00
|
|
|
}
|
|
|
|
return 1;
|
2011-02-05 11:12:34 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-12-17 15:40:54 +01:00
|
|
|
// Not handled
|
2011-02-05 11:12:34 +01:00
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|