Commit 336e8ca4 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Astyle kdelibs

parent c09a8f09
......@@ -21,7 +21,6 @@
#include "../checkphishingurlfromlocaldatabasejob.h"
#include <QTest>
CheckPhishingUrlFromLocalDataBaseJobTest::CheckPhishingUrlFromLocalDataBaseJobTest(QObject *parent)
: QObject(parent)
{
......@@ -33,5 +32,4 @@ CheckPhishingUrlFromLocalDataBaseJobTest::~CheckPhishingUrlFromLocalDataBaseJobT
}
QTEST_MAIN(CheckPhishingUrlFromLocalDataBaseJobTest)
......@@ -33,7 +33,6 @@ QByteArray readJsonFile(const QString &jsonFile)
return data;
}
CreatePhishingUrlDataBaseJobTest::CreatePhishingUrlDataBaseJobTest(QObject *parent)
: QObject(parent)
{
......@@ -102,9 +101,9 @@ void CreatePhishingUrlDataBaseJobTest::shouldCreateRequest_data()
void CreatePhishingUrlDataBaseJobTest::shouldCreateRequest()
{
QFETCH (QString, databasestate);
QFETCH (WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownload, downloadtype);
QFETCH (QByteArray, request);
QFETCH(QString, databasestate);
QFETCH(WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownload, downloadtype);
QFETCH(QByteArray, request);
WebEngineViewer::CreatePhishingUrlDataBaseJob job;
job.setDataBaseState(databasestate);
......@@ -165,7 +164,7 @@ void CreatePhishingUrlDataBaseJobTest::shouldParseResult_data()
void CreatePhishingUrlDataBaseJobTest::shouldParseResult()
{
QFETCH (QString, filename);
QFETCH(QString, filename);
QFETCH(WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult, parseResult);
QFETCH(WebEngineViewer::UpdateDataBaseInfo, parseInfo);
const QByteArray ba = readJsonFile(filename);
......@@ -177,5 +176,4 @@ void CreatePhishingUrlDataBaseJobTest::shouldParseResult()
QCOMPARE(spy1.at(0).at(0).value<WebEngineViewer::UpdateDataBaseInfo>(), parseInfo);
}
QTEST_MAIN(CreatePhishingUrlDataBaseJobTest)
......@@ -22,8 +22,10 @@
#include <QString>
namespace WebEngineViewer {
namespace CheckPhishingUrlUtil {
namespace WebEngineViewer
{
namespace CheckPhishingUrlUtil
{
QString apiKey();
}
}
......
......@@ -17,7 +17,6 @@
Boston, MA 02110-1301, USA.
*/
#include "createphishingurldatabasejob.h"
#include "checkphishingurlutil.h"
#include "webengineviewer_debug.h"
......@@ -87,22 +86,22 @@ QByteArray CreatePhishingUrlDataBaseJob::jsonRequest() const
{
#if 0
{
"client": {
"client": {
"clientId": "yourcompanyname",
"clientVersion": "1.5.2"
},
"listUpdateRequests": [{
},
"listUpdateRequests": [{
"threatType": "MALWARE",
"platformType": "WINDOWS",
"threatEntryType": "URL",
"state": "Gg4IBBADIgYQgBAiAQEoAQ==",
"constraints": {
"maxUpdateEntries": 2048,
"maxDatabaseEntries": 4096,
"region": "US",
"supportedCompressions": ["RAW"]
}
}]
"maxUpdateEntries": 2048,
"maxDatabaseEntries": 4096,
"region": "US",
"supportedCompressions": ["RAW"]
}
}]
}
#endif
QVariantMap clientMap;
......@@ -120,7 +119,7 @@ QByteArray CreatePhishingUrlDataBaseJob::jsonRequest() const
threatMap.insert(QStringLiteral("threatEntryType"), QStringLiteral("URL"));
//Define state when we want to define update database. Empty is full.
switch(mDataBaseDownloadNeeded) {
switch (mDataBaseDownloadNeeded) {
case FullDataBase:
threatMap.insert(QStringLiteral("state"), QString());
break;
......@@ -135,7 +134,6 @@ QByteArray CreatePhishingUrlDataBaseJob::jsonRequest() const
listUpdateRequests.append(threatMap);
//TODO define contraints
map.insert(QStringLiteral("listUpdateRequests"), listUpdateRequests);
const QJsonDocument postData = QJsonDocument::fromVariant(map);
......@@ -143,7 +141,6 @@ QByteArray CreatePhishingUrlDataBaseJob::jsonRequest() const
return baPostData;
}
void CreatePhishingUrlDataBaseJob::setDataBaseDownloadNeeded(CreatePhishingUrlDataBaseJob::DataBaseDownload type)
{
mDataBaseDownloadNeeded = type;
......@@ -160,7 +157,7 @@ void CreatePhishingUrlDataBaseJob::slotDownloadDataBaseFinished(QNetworkReply *r
QVector<Addition> CreatePhishingUrlDataBaseJob::parseAdditions(const QVariantList &lst)
{
QVector<Addition> additionList;
Q_FOREACH(const QVariant &v, lst) {
Q_FOREACH (const QVariant &v, lst) {
if (v.canConvert<QVariantMap>()) {
QMapIterator<QString, QVariant> mapIt(v.toMap());
while (mapIt.hasNext()) {
......@@ -192,7 +189,7 @@ QVector<Addition> CreatePhishingUrlDataBaseJob::parseAdditions(const QVariantLis
}
}
} else {
qDebug() << " CreatePhishingUrlDataBaseJob::parseAdditions not parsing type "<<v.typeName();
qDebug() << " CreatePhishingUrlDataBaseJob::parseAdditions not parsing type " << v.typeName();
}
}
return additionList;
......@@ -206,7 +203,7 @@ void CreatePhishingUrlDataBaseJob::setUseCompactJson(bool useCompactJson)
QVector<Removal> CreatePhishingUrlDataBaseJob::parseRemovals(const QVariantList &lst)
{
QVector<Removal> removalList;
Q_FOREACH(const QVariant &v, lst) {
Q_FOREACH (const QVariant &v, lst) {
if (v.canConvert<QVariantMap>()) {
Removal tmp;
QMapIterator<QString, QVariant> mapIt(v.toMap());
......@@ -223,7 +220,7 @@ QVector<Removal> CreatePhishingUrlDataBaseJob::parseRemovals(const QVariantList
if (rawIndicesIt.key() == QStringLiteral("indices")) {
const QVariantList lst = rawIndicesIt.value().toList();
QList<int> indexList;
Q_FOREACH(const QVariant &var, lst) {
Q_FOREACH (const QVariant &var, lst) {
indexList.append(var.toInt());
}
tmp.indexes = indexList;
......@@ -239,7 +236,7 @@ QVector<Removal> CreatePhishingUrlDataBaseJob::parseRemovals(const QVariantList
removalList.append(tmp);
}
} else {
qDebug() << " CreatePhishingUrlDataBaseJob::parseRemovals not parsing type "<<v.typeName();
qDebug() << " CreatePhishingUrlDataBaseJob::parseRemovals not parsing type " << v.typeName();
}
}
return removalList;
......@@ -254,7 +251,7 @@ void CreatePhishingUrlDataBaseJob::parseResult(const QByteArray &value)
} else {
const QVariantMap answer = document.toVariant().toMap();
if (answer.isEmpty()) {
Q_EMIT finished(databaseInfo,InvalidData);
Q_EMIT finished(databaseInfo, InvalidData);
} else {
QMapIterator<QString, QVariant> i(answer);
while (i.hasNext()) {
......@@ -309,7 +306,7 @@ void CreatePhishingUrlDataBaseJob::parseResult(const QByteArray &value)
} else if (i.key() == QLatin1String("minimumWaitDuration")) {
databaseInfo.minimumWaitDuration = i.value().toString();
} else {
qDebug() <<" map key unknown " << i.key();
qDebug() << " map key unknown " << i.key();
}
}
Q_EMIT finished(databaseInfo, ValidData);
......@@ -333,45 +330,48 @@ void UpdateDataBaseInfo::clear()
}
bool UpdateDataBaseInfo::operator==(const UpdateDataBaseInfo &other) const {
bool UpdateDataBaseInfo::operator==(const UpdateDataBaseInfo &other) const
{
const bool val = (additionList == other.additionList) &&
(removalList == other.removalList) &&
(minimumWaitDuration == other.minimumWaitDuration) &&
(threatType == other.threatType) &&
(threatEntryType == other.threatEntryType) &&
(responseType == other.responseType) &&
(platformType == other.platformType) &&
(newClientState == other.newClientState) &&
(sha256 == other.sha256);
(removalList == other.removalList) &&
(minimumWaitDuration == other.minimumWaitDuration) &&
(threatType == other.threatType) &&
(threatEntryType == other.threatEntryType) &&
(responseType == other.responseType) &&
(platformType == other.platformType) &&
(newClientState == other.newClientState) &&
(sha256 == other.sha256);
if (!val) {
qDebug() << " sha256 "<<sha256 << " other.sha256 "<< other.sha256;
qDebug() << " minimumWaitDuration "<<minimumWaitDuration << " other.minimumWaitDuration "<< other.minimumWaitDuration;
qDebug() << " threatType "<<threatType << " other.threatType "<< other.threatType;
qDebug() << " threatEntryType "<<threatEntryType << " other.threatEntryType "<< other.threatEntryType;
qDebug() << " responseType "<<responseType << " other.responseType "<< other.responseType;
qDebug() << " platformType "<<platformType << " other.platformType "<< other.platformType;
qDebug() << " newClientState "<<newClientState << " other.newClientState "<< other.newClientState;
qDebug() << " threatType "<<threatType << " other.threatType "<< other.threatType;
qDebug() << " sha256 " << sha256 << " other.sha256 " << other.sha256;
qDebug() << " minimumWaitDuration " << minimumWaitDuration << " other.minimumWaitDuration " << other.minimumWaitDuration;
qDebug() << " threatType " << threatType << " other.threatType " << other.threatType;
qDebug() << " threatEntryType " << threatEntryType << " other.threatEntryType " << other.threatEntryType;
qDebug() << " responseType " << responseType << " other.responseType " << other.responseType;
qDebug() << " platformType " << platformType << " other.platformType " << other.platformType;
qDebug() << " newClientState " << newClientState << " other.newClientState " << other.newClientState;
qDebug() << " threatType " << threatType << " other.threatType " << other.threatType;
qDebug() << " removalList" << removalList.count() << " other.removalList " << other.removalList.count();
qDebug() << " additionList" << additionList.count() << " other.additionList " << other.additionList.count();
}
return val;
}
bool Removal::operator==(const Removal &other) const {
bool Removal::operator==(const Removal &other) const
{
bool value = (indexes == other.indexes);
if (!value) {
qDebug() << " indexes "<<indexes << " other.indexes " << other.indexes;
qDebug() << " indexes " << indexes << " other.indexes " << other.indexes;
}
return value;
}
bool Addition::operator==(const Addition &other) const {
bool Addition::operator==(const Addition &other) const
{
bool value = (hashString == other.hashString) &&
(prefixSize == other.prefixSize);
(prefixSize == other.prefixSize);
if (!value) {
qDebug() << "hashString " << hashString << " other.hashString "<<other.hashString;
qDebug() << "prefixSize " << prefixSize << " other.prefixSize "<<other.prefixSize;
qDebug() << "hashString " << hashString << " other.hashString " << other.hashString;
qDebug() << "prefixSize " << prefixSize << " other.prefixSize " << other.prefixSize;
}
return value;
}
......@@ -17,7 +17,6 @@
Boston, MA 02110-1301, USA.
*/
#ifndef CREATEPHISHINGURLDATABASEJOB_H
#define CREATEPHISHINGURLDATABASEJOB_H
......@@ -35,7 +34,8 @@ struct Addition {
{
}
bool isValid() const {
bool isValid() const
{
return !hashString.isEmpty() && (prefixSize > 0);
}
bool operator==(const Addition &other) const;
......@@ -51,7 +51,8 @@ struct Removal {
}
bool operator==(const Removal &other) const;
bool isValid() const {
bool isValid() const
{
return !indexes.isEmpty();
}
QList<int> indexes;
......
......@@ -56,8 +56,9 @@ QSqlError LocalDataBaseManager::initDb()
QSqlDatabase db = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"));
db.setDatabaseName(QStringLiteral(":phishingurl:"));
if (!db.open())
if (!db.open()) {
return db.lastError();
}
//TODO
return QSqlError();
}
......
......@@ -33,7 +33,6 @@ CreatePhisingUrlDataBaseGui::CreatePhisingUrlDataBaseGui(QWidget *parent)
{
QVBoxLayout *layout = new QVBoxLayout(this);
mResult = new QTextEdit(this);
mResult->setReadOnly(true);
mResult->setAcceptRichText(false);
......
......@@ -24,16 +24,16 @@ using namespace WebEngineViewer;
QString WebEngineScript::findAllImages()
{
const QString source = QStringLiteral("(function() {"
"var out = [];"
"var imgs = document.getElementsByTagName('img');"
"for (var i = 0; i < imgs.length; ++i) {"
" var e = imgs[i];"
" out.push({"
" src: e.src"
" });"
"}"
"return out;"
"})()");
"var out = [];"
"var imgs = document.getElementsByTagName('img');"
"for (var i = 0; i < imgs.length; ++i) {"
" var e = imgs[i];"
" out.push({"
" src: e.src"
" });"
"}"
"return out;"
"})()");
return source;
}
......@@ -41,16 +41,16 @@ QString WebEngineScript::findAllImages()
QString WebEngineScript::findAllScripts()
{
const QString source = QStringLiteral("(function() {"
"var out = [];"
"var scripts = document.getElementsByTagName('script');"
"for (var i = 0; i < scripts.length; ++i) {"
" var e = scripts[i];"
" out.push({"
" src: e.src"
" });"
"}"
"return out;"
"})()");
"var out = [];"
"var scripts = document.getElementsByTagName('script');"
"for (var i = 0; i < scripts.length; ++i) {"
" var e = scripts[i];"
" out.push({"
" src: e.src"
" });"
"}"
"return out;"
"})()");
return source;
}
......@@ -58,18 +58,18 @@ QString WebEngineScript::findAllScripts()
QString WebEngineScript::findAllAnchors()
{
const QString source = QStringLiteral("(function() {"
"var out = [];"
"var anchors = document.getElementsByTagName('a');"
"for (var i = 0; i < anchors.length; ++i) {"
" var r = anchors[i].getBoundingClientRect();"
" out.push({"
" src: anchors[i].href,"
" title: anchors[i].title,"
" boudingRect: [r.top, r.left, r.width, r.height]"
" });"
"}"
"return out;"
"})()");
"var out = [];"
"var anchors = document.getElementsByTagName('a');"
"for (var i = 0; i < anchors.length; ++i) {"
" var r = anchors[i].getBoundingClientRect();"
" out.push({"
" src: anchors[i].href,"
" title: anchors[i].title,"
" boudingRect: [r.top, r.left, r.width, r.height]"
" });"
"}"
"return out;"
"})()");
return source;
}
......@@ -77,22 +77,22 @@ QString WebEngineScript::findAllAnchors()
QString WebEngineScript::findAllAnchorsAndForms()
{
const QString source = QStringLiteral("(function() {"
"var res = [];"
"var out = [];"
"var anchors = document.getElementsByTagName('a');"
"for (var i = 0; i < anchors.length; ++i) {"
" out.push({"
" src: anchors[i].href,"
" title: anchors[i].title"
" });"
"}"
"var forms = document.getElementsByTagName('form');"
"res.push({"
" anchors: out,"
" forms: forms.length"
" });"
"return res;"
"})()");
"var res = [];"
"var out = [];"
"var anchors = document.getElementsByTagName('a');"
"for (var i = 0; i < anchors.length; ++i) {"
" out.push({"
" src: anchors[i].href,"
" title: anchors[i].title"
" });"
"}"
"var forms = document.getElementsByTagName('form');"
"res.push({"
" anchors: out,"
" forms: forms.length"
" });"
"return res;"
"})()");
return source;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment