From 0b983b0d9364e62db0b5e6cf25988ef8041a0c5d Mon Sep 17 00:00:00 2001 From: Shane Synan Date: Sat, 3 Dec 2016 23:40:46 -0600 Subject: [PATCH] Move SASL maybeSupports into Network class Move IrcCap::SaslMechs::maybeSupported to the Network class, simplifying usage. Now there's no need to specify the capability value, avoiding hassle for most cases when you already have the Network object. Update CoreNetwork to use the moved function. Tidy! --- src/common/irccap.h | 16 ---------------- src/common/network.cpp | 14 ++++++++++++++ src/common/network.h | 14 ++++++++++++++ src/core/corenetwork.cpp | 4 ++-- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/common/irccap.h b/src/common/irccap.h index bbee7cdd..c61068e0 100644 --- a/src/common/irccap.h +++ b/src/common/irccap.h @@ -141,22 +141,6 @@ namespace IrcCap { * http://ircv3.net/specs/extensions/sasl-3.1.html */ namespace SaslMech { - - /** - * Check if the given authentication mechanism is likely to be supported. - * - * @param[in] saslCapValue QString of SASL capability value, e.g. capValue(IrcCap::SASL) - * @param[in] saslMechanism Desired SASL mechanism - * @return True if mechanism supported or unknown, otherwise false - */ - inline bool maybeSupported(const QString &saslCapValue, const QString &saslMechanism) { return - ((saslCapValue.length() == 0) || (saslCapValue.contains(saslMechanism, Qt::CaseInsensitive))); } - // SASL mechanisms are only specified in capability values as part of SASL 3.2. In - // SASL 3.1, it's handled differently. If we don't know via capability value, assume it's - // supported to reduce the risk of breaking existing setups. - // See: http://ircv3.net/specs/extensions/sasl-3.1.html - // And: http://ircv3.net/specs/extensions/sasl-3.2.html - /** * PLAIN authentication, e.g. hashed password */ diff --git a/src/common/network.cpp b/src/common/network.cpp index d768837f..cb4adb5c 100644 --- a/src/common/network.cpp +++ b/src/common/network.cpp @@ -241,6 +241,20 @@ QString Network::support(const QString ¶m) const } +bool Network::saslMaybeSupports(const QString &saslMechanism) const +{ + // Get the SASL capability value + QString saslCapValue = capValue(IrcCap::SASL); + // SASL mechanisms are only specified in capability values as part of SASL 3.2. In SASL 3.1, + // it's handled differently. If we don't know via capability value, assume it's supported to + // reduce the risk of breaking existing setups. + // See: http://ircv3.net/specs/extensions/sasl-3.1.html + // And: http://ircv3.net/specs/extensions/sasl-3.2.html + return (saslCapValue.length() == 0) + || (saslCapValue.contains(saslMechanism, Qt::CaseInsensitive)); +} + + IrcUser *Network::newIrcUser(const QString &hostmask, const QVariantMap &initData) { QString nick(nickFromMask(hostmask).toLower()); diff --git a/src/common/network.h b/src/common/network.h index 969c3b9b..a56b0935 100644 --- a/src/common/network.h +++ b/src/common/network.h @@ -39,6 +39,9 @@ #include "ircuser.h" #include "ircchannel.h" +// IRCv3 capabilities +#include "irccap.h" + // defined below! struct NetworkInfo; @@ -280,6 +283,17 @@ public : // QHash returns the default constructed value if not found, in this case, empty string // See: https://doc.qt.io/qt-4.8/qhash.html#value + /** + * Check if the given authentication mechanism is likely to be supported. + * + * This depends on the server advertising SASL support and either declaring available mechanisms + * (SASL 3.2), or just indicating something is supported (SASL 3.1). + * + * @param[in] saslMechanism Desired SASL mechanism + * @return True if mechanism supported or unknown, otherwise false + */ + bool saslMaybeSupports(const QString &saslMechanism) const; + IrcUser *newIrcUser(const QString &hostmask, const QVariantMap &initData = QVariantMap()); inline IrcUser *newIrcUser(const QByteArray &hostmask) { return newIrcUser(decodeServerString(hostmask)); } IrcUser *ircUser(QString nickname) const; diff --git a/src/core/corenetwork.cpp b/src/core/corenetwork.cpp index 30896aa7..fdfc869c 100644 --- a/src/core/corenetwork.cpp +++ b/src/core/corenetwork.cpp @@ -1053,7 +1053,7 @@ void CoreNetwork::serverCapAcknowledged(const QString &capability) // FIXME use event #ifdef HAVE_SSL if (!identityPtr()->sslCert().isNull()) { - if (IrcCap::SaslMech::maybeSupported(capValue(IrcCap::SASL), IrcCap::SaslMech::EXTERNAL)) { + if (saslMaybeSupports(IrcCap::SaslMech::EXTERNAL)) { // EXTERNAL authentication supported, send request putRawLine(serverEncode("AUTHENTICATE EXTERNAL")); } else { @@ -1063,7 +1063,7 @@ void CoreNetwork::serverCapAcknowledged(const QString &capability) } } else { #endif - if (IrcCap::SaslMech::maybeSupported(capValue(IrcCap::SASL), IrcCap::SaslMech::PLAIN)) { + if (saslMaybeSupports(IrcCap::SaslMech::PLAIN)) { // PLAIN authentication supported, send request // Only working with PLAIN atm, blowfish later putRawLine(serverEncode("AUTHENTICATE PLAIN")); -- 2.20.1