Messagelib

checkphishingurlutil.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "checkphishingurlutil.h"
8#include <QDateTime>
9#include <QtMath>
10
11using namespace WebEngineViewer;
12QString CheckPhishingUrlUtil::apiKey()
13{
14 return QStringLiteral("AIzaSyBS62pXATjabbH2RM_jO2EzDg1mTMHlnyo");
15}
16
17QString CheckPhishingUrlUtil::versionApps()
18{
19 return QStringLiteral(WEBENGINEVIEWER_VERSION_STRING);
20}
21
22QString CheckPhishingUrlUtil::databaseFileName()
23{
24 return QStringLiteral("malware.db");
25}
26
27quint16 CheckPhishingUrlUtil::majorVersion()
28{
29 return 1;
30}
31
32quint16 CheckPhishingUrlUtil::minorVersion()
33{
34 return 0;
35}
36
37QString CheckPhishingUrlUtil::configFileName()
38{
39 return QStringLiteral("phishingurlrc");
40}
41
42double CheckPhishingUrlUtil::convertToSecond(const QString &str)
43{
44 QString minimumDuration = str;
45
46 if (!minimumDuration.isEmpty()) {
47 if (minimumDuration.endsWith(QLatin1Char('s'))) {
48 minimumDuration = minimumDuration.left(minimumDuration.length() - 1);
49 }
50 bool ok;
51 double val = minimumDuration.toDouble(&ok);
52 if (ok) {
53 return val;
54 }
55 }
56 return -1;
57}
58
59uint CheckPhishingUrlUtil::refreshingCacheAfterThisTime(double seconds)
60{
61 if (seconds > 0) {
62 return QDateTime::currentDateTime().addMSecs(seconds * 1000).toSecsSinceEpoch();
63 } else {
64 return 0;
65 }
66}
67
68bool CheckPhishingUrlUtil::cachedValueStillValid(uint seconds)
69{
71}
72
73int CheckPhishingUrlUtil::generateRandomSecondValue(int numberOfFailed)
74{
75 // Random between 0-1
76 float r = static_cast<float>(rand()) / static_cast<float>(RAND_MAX) + 1;
77
78 const int numberOfSecondByDay = 24 * 60 * 60;
79 // MIN(((2^(n-1))*15 minutes) * (RAND + 1), 24 hours)
80 int seconds = 0;
81 if (numberOfFailed >= 1 && numberOfFailed < 9) {
82 seconds = static_cast<int>(qMin(static_cast<int>(qPow(2, numberOfFailed - 1)) * (15 * 60) * r, static_cast<float>(numberOfSecondByDay)));
83 } else if (numberOfFailed >= 9) {
84 seconds = numberOfSecondByDay;
85 }
86 return seconds;
87}
QDateTime addMSecs(qint64 msecs) const const
QDateTime currentDateTime()
QDateTime currentDateTimeUtc()
qint64 toSecsSinceEpoch() const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString left(qsizetype n) const const
qsizetype length() const const
double toDouble(bool *ok) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:12:44 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.