Messagelib

localdatabasemanager.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#include "localdatabasemanager.h"
7#include "backoffmodemanager.h"
8#include "checkphishingurlutil.h"
9#include "createdatabasefilejob.h"
10#include "localdatabasemanager_p.h"
11#include "urlhashing.h"
12#include "webengineviewer_debug.h"
13
14#include <KSharedConfig>
15
16#include <QCryptographicHash>
17
18using namespace WebEngineViewer;
19
20Q_GLOBAL_STATIC(LocalDataBaseManagerPrivate, s_localDataBaseManager)
21
22LocalDataBaseManager::LocalDataBaseManager(LocalDataBaseManagerPrivate *impl, QObject *parent)
23 : QObject(parent)
24 , d(impl)
25{
26 qRegisterMetaType<WebEngineViewer::UpdateDataBaseInfo>();
27 qRegisterMetaType<WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult>();
28 qRegisterMetaType<WebEngineViewer::CreatePhishingUrlDataBaseJob::ContraintsCompressionType>();
29}
30
31LocalDataBaseManager::LocalDataBaseManager(QObject *parent)
32 : LocalDataBaseManager(s_localDataBaseManager, parent)
33{
34}
35
36LocalDataBaseManager::~LocalDataBaseManager() = default;
37
38void LocalDataBaseManager::initialize()
39{
40 d->initialize();
41}
42
43void LocalDataBaseManager::checkUrl(const QUrl &url)
44{
45 if (d->mDataBaseOk) {
46 // TODO fixme short hash! we don't need to use it.
47 WebEngineViewer::UrlHashing urlHashing(url);
48 QHash<QByteArray, QByteArray> hashList = urlHashing.hashList();
50
52 while (i.hasNext()) {
53 i.next();
54 const QByteArray ba = i.value();
55 QByteArray result = d->mFile.searchHash(ba);
56 if (ba.contains(result)) {
57 conflictHashs.insert(i.key().toBase64(), ba.toBase64());
58 }
59 }
60 if (conflictHashs.isEmpty()) {
61 Q_EMIT checkUrlFinished(url, WebEngineViewer::CheckPhishingUrlUtil::Ok);
62 } else {
63 // qCWarning(WEBENGINEVIEWER_LOG) << " We need to Check Server Database";
64 if (d->mNewClientState.isEmpty()) {
65 qCWarning(WEBENGINEVIEWER_LOG) << "Database client state is unknown";
66 Q_EMIT checkUrlFinished(url, WebEngineViewer::CheckPhishingUrlUtil::Unknown);
67 } else {
68 auto job = new WebEngineViewer::SearchFullHashJob(this);
69 job->setDatabaseState(QStringList() << d->mNewClientState);
70 job->setSearchHashs(conflictHashs);
71 job->setSearchFullHashForUrl(url);
72 connect(job, &SearchFullHashJob::result, this, [this](CheckPhishingUrlUtil::UrlStatus status, const QUrl &url) {
73 Q_EMIT checkUrlFinished(url, status);
74 });
75 job->start();
76 }
77 }
78 } else {
79 qCWarning(WEBENGINEVIEWER_LOG) << "Database not ok";
80 Q_EMIT checkUrlFinished(url, WebEngineViewer::CheckPhishingUrlUtil::Unknown);
81 }
82 if (d->mFile.checkFileChanged()) {
83 d->mFile.reload();
84 }
85}
86
87#include "moc_localdatabasemanager.cpp"
The LocalDataBaseManager class.
The SearchFullHashJob class.
Q_SCRIPTABLE CaptureState status()
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
T qobject_cast(QObject *object)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:37:31 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.