Add capAvailable to Network akin to capEnabled
authorShane Synan <digitalcircuit36939@gmail.com>
Sun, 4 Dec 2016 05:43:10 +0000 (23:43 -0600)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 12 Apr 2017 21:30:16 +0000 (23:30 +0200)
Add capAvailable to Network, checking if the server advertised the
given capability.  This mimics capEnabled, but applies regardless of
whether or not Quassel requested the capability.

This is useful for showing elsewhere whether or not a certain
capability could've been requested.

Use this in Network::saslMaybeSupports to avoid falsely claiming SASL
support when the SASL capability wasn't advertised.  This matches the
behavior of CoreNetwork.

src/common/network.cpp
src/common/network.h

index cb4adb5..885cc50 100644 (file)
@@ -243,6 +243,14 @@ QString Network::support(const QString &param) const
 
 bool Network::saslMaybeSupports(const QString &saslMechanism) const
 {
+    if (!capAvailable(IrcCap::SASL)) {
+        // If SASL's not advertised at all, it's likely the mechanism isn't supported, as per specs.
+        // Unfortunately, we don't know for sure, but Quassel won't request SASL without it being
+        // advertised, anyways.
+        // This may also occur if the network's disconnected or negotiation hasn't yet happened.
+        return false;
+    }
+
     // 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,
index a56b093..5ad42e9 100644 (file)
@@ -263,6 +263,19 @@ public :
     bool supports(const QString &param) const { return _supports.contains(param); }
     QString support(const QString &param) const;
 
+    /**
+     * Checks if a given capability is advertised by the server.
+     *
+     * These results aren't valid if the network is disconnected or capability negotiation hasn't
+     * happened, and some servers might not correctly advertise capabilities.  Don't treat this as
+     * a guarentee.
+     *
+     * @param[in] capability Name of capability
+     * @returns True if connected and advertised by the server, otherwise false
+     */
+    inline bool capAvailable(const QString &capability) const { return _caps.contains(capability.toLower()); }
+    // IRCv3 specs all use lowercase capability names
+
     /**
      * Checks if a given capability is acknowledged and active.
      *