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 
11 using namespace WebEngineViewer;
12 QString CheckPhishingUrlUtil::apiKey()
13 {
14  return QStringLiteral("AIzaSyBS62pXATjabbH2RM_jO2EzDg1mTMHlnyo");
15 }
16 
17 QString CheckPhishingUrlUtil::versionApps()
18 {
19  return QStringLiteral(WEBENGINEVIEWER_VERSION_STRING);
20 }
21 
22 QString CheckPhishingUrlUtil::databaseFileName()
23 {
24  return QStringLiteral("malware.db");
25 }
26 
27 quint16 CheckPhishingUrlUtil::majorVersion()
28 {
29  return 1;
30 }
31 
32 quint16 CheckPhishingUrlUtil::minorVersion()
33 {
34  return 0;
35 }
36 
37 QString CheckPhishingUrlUtil::configFileName()
38 {
39  return QStringLiteral("phishingurlrc");
40 }
41 
42 double 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 
59 uint 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 
68 bool CheckPhishingUrlUtil::cachedValueStillValid(uint seconds)
69 {
71 }
72 
73 int 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 }
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
QDateTime addMSecs(qint64 msecs) const const
QDateTime currentDateTime()
QDateTime currentDateTimeUtc()
bool isEmpty() const const
int length() const const
double toDouble(bool *ok) const const
qint64 toSecsSinceEpoch() const const
QString left(int n) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:55:19 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.