Move SASL maybeSupports into Network class
authorShane Synan <digitalcircuit36939@gmail.com>
Sun, 4 Dec 2016 05:40:46 +0000 (23:40 -0600)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 12 Apr 2017 21:30:16 +0000 (23:30 +0200)
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
src/common/network.cpp
src/common/network.h
src/core/corenetwork.cpp

index bbee7cd..c61068e 100644 (file)
@@ -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
          */
index d768837..cb4adb5 100644 (file)
@@ -241,6 +241,20 @@ QString Network::support(const QString &param) 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());
index 969c3b9..a56b093 100644 (file)
@@ -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;
index 30896aa..fdfc869 100644 (file)
@@ -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"));