Messagelib

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

KDE's Doxygen guidelines are available online.