File indexing completed on 2025-01-26 04:57:23
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "updatedatabaseinfo.h" 0008 #include "webengineviewer_debug.h" 0009 0010 using namespace WebEngineViewer; 0011 0012 UpdateDataBaseInfo::UpdateDataBaseInfo() = default; 0013 0014 bool UpdateDataBaseInfo::isValid() const 0015 { 0016 return responseType != Unknown; 0017 } 0018 0019 void UpdateDataBaseInfo::clear() 0020 { 0021 additionList.clear(); 0022 removalList.clear(); 0023 minimumWaitDuration.clear(); 0024 threatType.clear(); 0025 threatEntryType.clear(); 0026 responseType = UpdateDataBaseInfo::Unknown; 0027 platformType.clear(); 0028 newClientState.clear(); 0029 sha256.clear(); 0030 } 0031 0032 bool UpdateDataBaseInfo::operator==(const UpdateDataBaseInfo &other) const 0033 { 0034 const bool val = (additionList == other.additionList) && (removalList == other.removalList) && (minimumWaitDuration == other.minimumWaitDuration) 0035 && (threatType == other.threatType) && (threatEntryType == other.threatEntryType) && (responseType == other.responseType) 0036 && (platformType == other.platformType) && (newClientState == other.newClientState) && (sha256 == other.sha256); 0037 if (!val) { 0038 qCWarning(WEBENGINEVIEWER_LOG) << " sha256 " << sha256 << " other.sha256 " << other.sha256; 0039 qCWarning(WEBENGINEVIEWER_LOG) << " minimumWaitDuration " << minimumWaitDuration << " other.minimumWaitDuration " << other.minimumWaitDuration; 0040 qCWarning(WEBENGINEVIEWER_LOG) << " threatType " << threatType << " other.threatType " << other.threatType; 0041 qCWarning(WEBENGINEVIEWER_LOG) << " threatEntryType " << threatEntryType << " other.threatEntryType " << other.threatEntryType; 0042 qCWarning(WEBENGINEVIEWER_LOG) << " responseType " << responseType << " other.responseType " << other.responseType; 0043 qCWarning(WEBENGINEVIEWER_LOG) << " platformType " << platformType << " other.platformType " << other.platformType; 0044 qCWarning(WEBENGINEVIEWER_LOG) << " newClientState " << newClientState << " other.newClientState " << other.newClientState; 0045 qCWarning(WEBENGINEVIEWER_LOG) << " threatType " << threatType << " other.threatType " << other.threatType; 0046 qCWarning(WEBENGINEVIEWER_LOG) << " removalList" << removalList.count() << " other.removalList " << other.removalList.count(); 0047 qCWarning(WEBENGINEVIEWER_LOG) << " additionList" << additionList.count() << " other.additionList " << other.additionList.count(); 0048 } 0049 return val; 0050 } 0051 0052 Removal::Removal() 0053 : compressionType(UpdateDataBaseInfo::UnknownCompression) 0054 { 0055 } 0056 0057 bool Removal::operator==(const Removal &other) const 0058 { 0059 bool value = (indexes == other.indexes) && (compressionType == other.compressionType) && (riceDeltaEncoding == other.riceDeltaEncoding); 0060 if (!value) { 0061 qCWarning(WEBENGINEVIEWER_LOG) << " indexes " << indexes << " other.indexes " << other.indexes; 0062 qCWarning(WEBENGINEVIEWER_LOG) << "compressionType " << compressionType << " other.compressionType " << other.compressionType; 0063 } 0064 return value; 0065 } 0066 0067 bool Removal::isValid() const 0068 { 0069 bool valid = false; 0070 switch (compressionType) { 0071 case UpdateDataBaseInfo::UnknownCompression: 0072 qCWarning(WEBENGINEVIEWER_LOG) << "Compression Type undefined"; 0073 valid = false; 0074 break; 0075 case UpdateDataBaseInfo::RiceCompression: 0076 valid = riceDeltaEncoding.isValid(); 0077 break; 0078 case UpdateDataBaseInfo::RawCompression: 0079 valid = !indexes.isEmpty(); 0080 break; 0081 } 0082 return valid; 0083 } 0084 0085 Addition::Addition() 0086 : compressionType(UpdateDataBaseInfo::UnknownCompression) 0087 , prefixSize(0) 0088 { 0089 } 0090 0091 bool Addition::isValid() const 0092 { 0093 bool valid = false; 0094 switch (compressionType) { 0095 case UpdateDataBaseInfo::UnknownCompression: 0096 qCWarning(WEBENGINEVIEWER_LOG) << "Compression Type undefined"; 0097 valid = false; 0098 break; 0099 case UpdateDataBaseInfo::RiceCompression: 0100 valid = riceDeltaEncoding.isValid(); 0101 break; 0102 case UpdateDataBaseInfo::RawCompression: 0103 const bool hasCorrectPrefixSize = (prefixSize >= 4) && (prefixSize <= 32); 0104 if (!hasCorrectPrefixSize) { 0105 qCWarning(WEBENGINEVIEWER_LOG) << "Prefix size is not correct"; 0106 valid = false; 0107 } else if ((hashString.size() % static_cast<int>(prefixSize)) != 0) { 0108 qDebug() << " hashString.size() " << hashString.size() << "prefixSize " << prefixSize; 0109 qCWarning(WEBENGINEVIEWER_LOG) << "it's not a correct hash value"; 0110 valid = false; 0111 } else { 0112 valid = !hashString.isEmpty(); 0113 } 0114 break; 0115 } 0116 return valid; 0117 } 0118 0119 bool Addition::operator==(const Addition &other) const 0120 { 0121 bool value = (hashString == other.hashString) && (prefixSize == other.prefixSize) && (compressionType == other.compressionType) 0122 && (riceDeltaEncoding == other.riceDeltaEncoding); 0123 if (!value) { 0124 qCWarning(WEBENGINEVIEWER_LOG) << "hashString " << hashString << " other.hashString " << other.hashString; 0125 qCWarning(WEBENGINEVIEWER_LOG) << "prefixSize " << prefixSize << " other.prefixSize " << other.prefixSize; 0126 qCWarning(WEBENGINEVIEWER_LOG) << "compressionType " << compressionType << " other.compressionType " << other.compressionType; 0127 } 0128 return value; 0129 } 0130 0131 bool Addition::lessThan(const Addition &s1, const Addition &s2) 0132 { 0133 return s1.hashString < s2.hashString; 0134 } 0135 0136 RiceDeltaEncoding::RiceDeltaEncoding() 0137 : riceParameter(0) 0138 , numberEntries(0) 0139 { 0140 } 0141 0142 bool RiceDeltaEncoding::operator==(const RiceDeltaEncoding &other) const 0143 { 0144 return (firstValue == other.firstValue) && (encodingData == other.encodingData) && (riceParameter == other.riceParameter) 0145 && (numberEntries == other.numberEntries); 0146 } 0147 0148 bool RiceDeltaEncoding::isValid() const 0149 { 0150 if (!firstValue.isEmpty() && !encodingData.isEmpty() && ((riceParameter >= 2 && riceParameter <= 28) || (riceParameter == 0 && numberEntries == 0))) { 0151 return true; 0152 } 0153 return false; 0154 }