Messagelib

updatedatabaseinfo.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2025 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "updatedatabaseinfo.h"
8#include "webengineviewer_debug.h"
9
10using namespace WebEngineViewer;
11
12UpdateDataBaseInfo::UpdateDataBaseInfo() = default;
13
14bool UpdateDataBaseInfo::isValid() const
15{
16 return responseType != Unknown;
17}
18
19void UpdateDataBaseInfo::clear()
20{
21 additionList.clear();
22 removalList.clear();
23 minimumWaitDuration.clear();
24 threatType.clear();
25 threatEntryType.clear();
26 responseType = UpdateDataBaseInfo::Unknown;
27 platformType.clear();
28 newClientState.clear();
29 sha256.clear();
30}
31
32bool UpdateDataBaseInfo::operator==(const UpdateDataBaseInfo &other) const
33{
34 const bool val = (additionList == other.additionList) && (removalList == other.removalList) && (minimumWaitDuration == other.minimumWaitDuration)
35 && (threatType == other.threatType) && (threatEntryType == other.threatEntryType) && (responseType == other.responseType)
36 && (platformType == other.platformType) && (newClientState == other.newClientState) && (sha256 == other.sha256);
37 if (!val) {
38 qCWarning(WEBENGINEVIEWER_LOG) << " sha256 " << sha256 << " other.sha256 " << other.sha256;
39 qCWarning(WEBENGINEVIEWER_LOG) << " minimumWaitDuration " << minimumWaitDuration << " other.minimumWaitDuration " << other.minimumWaitDuration;
40 qCWarning(WEBENGINEVIEWER_LOG) << " threatType " << threatType << " other.threatType " << other.threatType;
41 qCWarning(WEBENGINEVIEWER_LOG) << " threatEntryType " << threatEntryType << " other.threatEntryType " << other.threatEntryType;
42 qCWarning(WEBENGINEVIEWER_LOG) << " responseType " << responseType << " other.responseType " << other.responseType;
43 qCWarning(WEBENGINEVIEWER_LOG) << " platformType " << platformType << " other.platformType " << other.platformType;
44 qCWarning(WEBENGINEVIEWER_LOG) << " newClientState " << newClientState << " other.newClientState " << other.newClientState;
45 qCWarning(WEBENGINEVIEWER_LOG) << " threatType " << threatType << " other.threatType " << other.threatType;
46 qCWarning(WEBENGINEVIEWER_LOG) << " removalList" << removalList.count() << " other.removalList " << other.removalList.count();
47 qCWarning(WEBENGINEVIEWER_LOG) << " additionList" << additionList.count() << " other.additionList " << other.additionList.count();
48 }
49 return val;
50}
51
52Removal::Removal()
53 : compressionType(UpdateDataBaseInfo::UnknownCompression)
54{
55}
56
57bool Removal::operator==(const Removal &other) const
58{
59 bool value = (indexes == other.indexes) && (compressionType == other.compressionType) && (riceDeltaEncoding == other.riceDeltaEncoding);
60 if (!value) {
61 qCWarning(WEBENGINEVIEWER_LOG) << " indexes " << indexes << " other.indexes " << other.indexes;
62 qCWarning(WEBENGINEVIEWER_LOG) << "compressionType " << compressionType << " other.compressionType " << other.compressionType;
63 }
64 return value;
65}
66
67bool Removal::isValid() const
68{
69 bool valid = false;
70 switch (compressionType) {
71 case UpdateDataBaseInfo::UnknownCompression:
72 qCWarning(WEBENGINEVIEWER_LOG) << "Compression Type undefined";
73 valid = false;
74 break;
75 case UpdateDataBaseInfo::RiceCompression:
76 valid = riceDeltaEncoding.isValid();
77 break;
78 case UpdateDataBaseInfo::RawCompression:
79 valid = !indexes.isEmpty();
80 break;
81 }
82 return valid;
83}
84
85Addition::Addition()
86 : compressionType(UpdateDataBaseInfo::UnknownCompression)
87 , prefixSize(0)
88{
89}
90
91bool Addition::isValid() const
92{
93 bool valid = false;
94 switch (compressionType) {
95 case UpdateDataBaseInfo::UnknownCompression:
96 qCWarning(WEBENGINEVIEWER_LOG) << "Compression Type undefined";
97 valid = false;
98 break;
99 case UpdateDataBaseInfo::RiceCompression:
100 valid = riceDeltaEncoding.isValid();
101 break;
102 case UpdateDataBaseInfo::RawCompression:
103 const bool hasCorrectPrefixSize = (prefixSize >= 4) && (prefixSize <= 32);
104 if (!hasCorrectPrefixSize) {
105 qCWarning(WEBENGINEVIEWER_LOG) << "Prefix size is not correct";
106 valid = false;
107 } else if ((hashString.size() % static_cast<int>(prefixSize)) != 0) {
108 qDebug() << " hashString.size() " << hashString.size() << "prefixSize " << prefixSize;
109 qCWarning(WEBENGINEVIEWER_LOG) << "it's not a correct hash value";
110 valid = false;
111 } else {
112 valid = !hashString.isEmpty();
113 }
114 break;
115 }
116 return valid;
117}
118
119bool Addition::operator==(const Addition &other) const
120{
121 bool value = (hashString == other.hashString) && (prefixSize == other.prefixSize) && (compressionType == other.compressionType)
122 && (riceDeltaEncoding == other.riceDeltaEncoding);
123 if (!value) {
124 qCWarning(WEBENGINEVIEWER_LOG) << "hashString " << hashString << " other.hashString " << other.hashString;
125 qCWarning(WEBENGINEVIEWER_LOG) << "prefixSize " << prefixSize << " other.prefixSize " << other.prefixSize;
126 qCWarning(WEBENGINEVIEWER_LOG) << "compressionType " << compressionType << " other.compressionType " << other.compressionType;
127 }
128 return value;
129}
130
131bool Addition::lessThan(const Addition &s1, const Addition &s2)
132{
133 return s1.hashString < s2.hashString;
134}
135
136RiceDeltaEncoding::RiceDeltaEncoding()
137 : riceParameter(0)
138 , numberEntries(0)
139{
140}
141
142bool RiceDeltaEncoding::operator==(const RiceDeltaEncoding &other) const
143{
144 return (firstValue == other.firstValue) && (encodingData == other.encodingData) && (riceParameter == other.riceParameter)
145 && (numberEntries == other.numberEntries);
146}
147
148bool RiceDeltaEncoding::isValid() const
149{
150 if (!firstValue.isEmpty() && !encodingData.isEmpty() && ((riceParameter >= 2 && riceParameter <= 28) || (riceParameter == 0 && numberEntries == 0))) {
151 return true;
152 }
153 return false;
154}
qsizetype count() const const
qsizetype count() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 31 2025 12:05:42 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.