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 "localdatabasemanager_p.h"
8#include "searchfullhashjob.h"
9#include "updatedatabaseinfo.h"
10#include "urlhashing.h"
11#include "webengineviewer_debug.h"
12
13#include <KSharedConfig>
14
15#include <QCryptographicHash>
16
17using namespace WebEngineViewer;
18
19Q_GLOBAL_STATIC(LocalDataBaseManagerPrivate, s_localDataBaseManager)
20
21LocalDataBaseManager::LocalDataBaseManager(LocalDataBaseManagerPrivate *impl, QObject *parent)
22 : QObject(parent)
23 , d(impl)
24{
25 qRegisterMetaType<WebEngineViewer::UpdateDataBaseInfo>();
26 qRegisterMetaType<WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult>();
27 qRegisterMetaType<WebEngineViewer::CreatePhishingUrlDataBaseJob::ContraintsCompressionType>();
28}
29
30LocalDataBaseManager::LocalDataBaseManager(QObject *parent)
31 : LocalDataBaseManager(s_localDataBaseManager, parent)
32{
33}
34
35LocalDataBaseManager::~LocalDataBaseManager() = default;
36
37void LocalDataBaseManager::initialize()
38{
39 d->initialize();
40}
41
42void LocalDataBaseManager::checkUrl(const QUrl &url)
43{
44 if (d->mDataBaseOk) {
45 // TODO fixme short hash! we don't need to use it.
46 WebEngineViewer::UrlHashing urlHashing(url);
47 QHash<QByteArray, QByteArray> hashList = urlHashing.hashList();
49
51 while (i.hasNext()) {
52 i.next();
53 const QByteArray ba = i.value();
54 QByteArray result = d->mFile.searchHash(ba);
55 if (ba.contains(result)) {
56 conflictHashs.insert(i.key().toBase64(), ba.toBase64());
57 }
58 }
59 if (conflictHashs.isEmpty()) {
60 Q_EMIT checkUrlFinished(url, WebEngineViewer::CheckPhishingUrlUtil::Ok);
61 } else {
62 // qCWarning(WEBENGINEVIEWER_LOG) << " We need to Check Server Database";
63 if (d->mNewClientState.isEmpty()) {
64 qCWarning(WEBENGINEVIEWER_LOG) << "Database client state is unknown";
65 Q_EMIT checkUrlFinished(url, WebEngineViewer::CheckPhishingUrlUtil::Unknown);
66 } else {
67 auto job = new WebEngineViewer::SearchFullHashJob(this);
68 job->setDatabaseState(QStringList() << d->mNewClientState);
69 job->setSearchHashs(conflictHashs);
70 job->setSearchFullHashForUrl(url);
71 connect(job, &SearchFullHashJob::result, this, [this](CheckPhishingUrlUtil::UrlStatus status, const QUrl &url) {
72 Q_EMIT checkUrlFinished(url, status);
73 });
74 job->start();
75 }
76 }
77 } else {
78 qCWarning(WEBENGINEVIEWER_LOG) << "Database not ok";
79 Q_EMIT checkUrlFinished(url, WebEngineViewer::CheckPhishingUrlUtil::Unknown);
80 }
81 if (d->mFile.checkFileChanged()) {
82 d->mFile.reload();
83 }
84}
85
86#include "moc_localdatabasemanager.cpp"
The LocalDataBaseManager class.
The SearchFullHashJob class.
Q_SCRIPTABLE CaptureState status()
bool contains(QByteArrayView bv) const const
QByteArray toBase64(Base64Options options) const const
iterator insert(const Key &key, const T &value)
bool isEmpty() const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.