11#include <config-libkleo.h>
13#include "keyserverconfig.h"
15#include <libkleo/algorithm.h>
22class KeyserverConfig::Private
29 KeyserverAuthentication authentication = KeyserverAuthentication::Anonymous;
32 KeyserverConnection connection = KeyserverConnection::Default;
37KeyserverConfig::Private::Private()
41KeyserverConfig::KeyserverConfig()
42 : d{std::make_unique<Private>()}
46KeyserverConfig::~KeyserverConfig() =
default;
48KeyserverConfig::KeyserverConfig(
const KeyserverConfig &other)
49 : d{std::make_unique<Private>(*other.d)}
53KeyserverConfig &KeyserverConfig::operator=(
const KeyserverConfig &other)
59KeyserverConfig::KeyserverConfig(KeyserverConfig &&other) =
default;
61KeyserverConfig &KeyserverConfig::operator=(KeyserverConfig &&other) =
default;
63KeyserverConfig KeyserverConfig::fromUrl(
const QUrl &url)
65 KeyserverConfig config;
67 config.d->host = url.
host();
68 config.d->port = url.
port();
71 if (!config.d->user.isEmpty()) {
72 config.d->authentication = KeyserverAuthentication::Password;
76 return flag.trimmed().toLower();
78 for (
const auto &flag : flags) {
80 config.d->connection = KeyserverConnection::UseSTARTTLS;
82 config.d->connection = KeyserverConnection::TunnelThroughTLS;
84 config.d->connection = KeyserverConnection::Plain;
86 config.d->authentication = KeyserverAuthentication::ActiveDirectory;
88 config.d->additionalFlags.push_back(flag);
93 config.d->baseDn = url.
query();
99QUrl KeyserverConfig::toUrl()
const
105 url.
setHost(d->host.isNull() ? QStringLiteral(
"") : d->host);
109 if (!d->user.isEmpty()) {
112 if (!d->password.isEmpty()) {
115 if (!d->baseDn.isEmpty()) {
120 switch (d->connection) {
121 case KeyserverConnection::UseSTARTTLS:
122 flags.
push_back(QStringLiteral(
"starttls"));
124 case KeyserverConnection::TunnelThroughTLS:
125 flags.
push_back(QStringLiteral(
"ldaptls"));
127 case KeyserverConnection::Plain:
128 flags.
push_back(QStringLiteral(
"plain"));
130 case KeyserverConnection::Default:;
132 if (d->authentication == KeyserverAuthentication::ActiveDirectory) {
135 std::copy(std::cbegin(d->additionalFlags), std::cend(d->additionalFlags), std::back_inserter(flags));
143QString KeyserverConfig::host()
const
148void KeyserverConfig::setHost(
const QString &host)
153int KeyserverConfig::port()
const
158void KeyserverConfig::setPort(
int port)
163KeyserverAuthentication KeyserverConfig::authentication()
const
165 return d->authentication;
168void KeyserverConfig::setAuthentication(KeyserverAuthentication authentication)
170 d->authentication = authentication;
173QString KeyserverConfig::user()
const
178void KeyserverConfig::setUser(
const QString &user)
183QString KeyserverConfig::password()
const
188void KeyserverConfig::setPassword(
const QString &password)
190 d->password = password;
193KeyserverConnection KeyserverConfig::connection()
const
195 return d->connection;
198void KeyserverConfig::setConnection(KeyserverConnection connection)
200 d->connection = connection;
203QString KeyserverConfig::ldapBaseDn()
const
208void KeyserverConfig::setLdapBaseDn(
const QString &baseDn)
213QStringList KeyserverConfig::additionalFlags()
const
215 return d->additionalFlags;
218void KeyserverConfig::setAdditionalFlags(
const QStringList &flags)
220 d->additionalFlags = flags;
bool isEmpty() const const
void push_back(parameter_type value)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString join(QChar separator) const const
QString fragment(ComponentFormattingOptions options) const const
bool hasFragment() const const
bool hasQuery() const const
QString host(ComponentFormattingOptions options) const const
QString password(ComponentFormattingOptions options) const const
int port(int defaultPort) const const
QString query(ComponentFormattingOptions options) const const
void setFragment(const QString &fragment, ParsingMode mode)
void setHost(const QString &host, ParsingMode mode)
void setPassword(const QString &password, ParsingMode mode)
void setQuery(const QString &query, ParsingMode mode)
void setScheme(const QString &scheme)
void setUserName(const QString &userName, ParsingMode mode)
QString userName(ComponentFormattingOptions options) const const