diff --git a/src/utils/cryptoconfig.cpp b/src/utils/cryptoconfig.cpp index 9434ddf00..5d35d7436 100644 --- a/src/utils/cryptoconfig.cpp +++ b/src/utils/cryptoconfig.cpp @@ -1,98 +1,113 @@ /* utils/cryptoconfig.cpp This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2021 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #include "cryptoconfig.h" #include "cryptoconfig_p.h" #include "utils/compat.h" #include #include #include using namespace QGpgME; static std::unordered_map> fakeCryptoConfigIntValues; static std::unordered_map> fakeCryptoConfigStringValues; int Kleo::getCryptoConfigIntValue(const char *componentName, const char *entryName, int defaultValue) { if (!fakeCryptoConfigIntValues.empty()) { const auto componentIt = fakeCryptoConfigIntValues.find(componentName); if (componentIt != std::end(fakeCryptoConfigIntValues)) { const auto entryIt = componentIt->second.find(entryName); if (entryIt != std::end(componentIt->second)) { return entryIt->second; } } } const CryptoConfig *const config = cryptoConfig(); if (!config) { return defaultValue; } const CryptoConfigEntry *const entry = getCryptoConfigEntry(config, componentName, entryName); - if (!entry || entry->argType() != CryptoConfigEntry::ArgType_Int) { - return defaultValue; + if (entry && entry->argType() == CryptoConfigEntry::ArgType_Int) { + return entry->intValue(); } - return entry->intValue(); + return defaultValue; } QString Kleo::getCryptoConfigStringValue(const char *componentName, const char *entryName) { if (!fakeCryptoConfigStringValues.empty()) { const auto componentIt = fakeCryptoConfigStringValues.find(componentName); if (componentIt != std::end(fakeCryptoConfigStringValues)) { const auto entryIt = componentIt->second.find(entryName); if (entryIt != std::end(componentIt->second)) { return entryIt->second; } } } const CryptoConfig *const config = cryptoConfig(); if (!config) { return {}; } const CryptoConfigEntry *const entry = getCryptoConfigEntry(config, componentName, entryName); - if (!entry || entry->argType() != CryptoConfigEntry::ArgType_String) { - return QString(); + if (entry && entry->argType() == CryptoConfigEntry::ArgType_String) { + return entry->stringValue(); + } + return {}; +} + +QList Kleo::getCryptoConfigUrlList(const char *componentName, const char *entryName) +{ + const CryptoConfig *const config = cryptoConfig(); + if (!config) { + return {}; + } + const CryptoConfigEntry *const entry = getCryptoConfigEntry(config, componentName, entryName); + if (entry && entry->isList() + && (entry->argType() == CryptoConfigEntry::ArgType_LDAPURL + || entry->argType() == CryptoConfigEntry::ArgType_Path)) { + return entry->urlValueList(); } - return entry->stringValue(); + return {}; } void Kleo::Private::setFakeCryptoConfigIntValue(const std::string &componentName, const std::string &entryName, int fakeValue) { fakeCryptoConfigIntValues[componentName][entryName] = fakeValue; } void Kleo::Private::clearFakeCryptoConfigIntValue(const std::string &componentName, const std::string &entryName) { auto &entryMap = fakeCryptoConfigIntValues[componentName]; entryMap.erase(entryName); if (entryMap.empty()) { fakeCryptoConfigIntValues.erase(componentName); } } void Kleo::Private::setFakeCryptoConfigStringValue(const std::string &componentName, const std::string &entryName, const QString &fakeValue) { fakeCryptoConfigStringValues[componentName][entryName] = fakeValue; } void Kleo::Private::clearFakeCryptoConfigStringValue(const std::string &componentName, const std::string &entryName) { auto &entryMap = fakeCryptoConfigStringValues[componentName]; entryMap.erase(entryName); if (entryMap.empty()) { fakeCryptoConfigStringValues.erase(componentName); } } diff --git a/src/utils/cryptoconfig.h b/src/utils/cryptoconfig.h index faa057f4c..bd52ea699 100644 --- a/src/utils/cryptoconfig.h +++ b/src/utils/cryptoconfig.h @@ -1,24 +1,29 @@ /* utils/cryptoconfig.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2021 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include "kleo_export.h" +#include + class QString; +class QUrl; namespace Kleo { KLEO_EXPORT int getCryptoConfigIntValue(const char *componentName, const char *entryName, int defaultValue); KLEO_EXPORT QString getCryptoConfigStringValue(const char *componentName, const char *entryName); +KLEO_EXPORT QList getCryptoConfigUrlList(const char *componentName, const char *entryName); + }