File indexing completed on 2025-01-26 04:57:22
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QNetworkReply> 0010 #include <QObject> 0011 #include <QSslError> 0012 0013 #include "webengineviewer_export.h" 0014 namespace WebEngineViewer 0015 { 0016 struct UpdateDataBaseInfo; 0017 class CreatePhishingUrlDataBaseJobPrivate; 0018 /* https://developers.google.com/safe-browsing/v4/update-api */ 0019 /** 0020 * @brief The CreatePhishingUrlDataBaseJob class 0021 * @author Laurent Montel <montel@kde.org> 0022 */ 0023 class WEBENGINEVIEWER_EXPORT CreatePhishingUrlDataBaseJob : public QObject 0024 { 0025 Q_OBJECT 0026 public: 0027 enum DataBaseDownloadType { 0028 FullDataBase = 0, 0029 UpdateDataBase = 1, 0030 }; 0031 0032 enum DataBaseDownloadResult { 0033 InvalidData = 0, 0034 ValidData = 1, 0035 UnknownError = 2, 0036 BrokenNetwork = 3, 0037 }; 0038 0039 enum ContraintsCompressionType { RawCompression = 0, RiceCompression = 1 }; 0040 0041 explicit CreatePhishingUrlDataBaseJob(QObject *parent = nullptr); 0042 ~CreatePhishingUrlDataBaseJob() override; 0043 0044 void start(); 0045 0046 void setDataBaseState(const QString &value); 0047 0048 void setDataBaseDownloadNeeded(WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadType type); 0049 0050 [[nodiscard]] QByteArray jsonRequest() const; 0051 0052 void parseResult(const QByteArray &value); 0053 0054 void setContraintsCompressionType(CreatePhishingUrlDataBaseJob::ContraintsCompressionType type); 0055 0056 Q_SIGNALS: 0057 void finished(const WebEngineViewer::UpdateDataBaseInfo &infoDataBase, WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult status); 0058 void debugJsonResult(const QByteArray &ba); 0059 void debugJson(const QByteArray &ba); 0060 0061 private: 0062 WEBENGINEVIEWER_NO_EXPORT void slotDownloadDataBaseFinished(QNetworkReply *reply); 0063 WEBENGINEVIEWER_NO_EXPORT void slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error); 0064 WEBENGINEVIEWER_NO_EXPORT void slotError(QNetworkReply::NetworkError error); 0065 0066 std::unique_ptr<CreatePhishingUrlDataBaseJobPrivate> const d; 0067 }; 0068 } 0069 Q_DECLARE_METATYPE(WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadType) 0070 Q_DECLARE_METATYPE(WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult) 0071 Q_DECLARE_METATYPE(WebEngineViewer::CreatePhishingUrlDataBaseJob::ContraintsCompressionType)