From d51c6b146d8ca9d1a39bf2fbb6b7d5124dedf09b Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Mon, 3 Sep 2012 13:50:21 +0200 Subject: make it possible to disable non-SASL authentication --- src/client/QXmppConfiguration.cpp | 31 ++++++++++++++++++++----------- src/client/QXmppConfiguration.h | 3 +++ src/client/QXmppOutgoingClient.cpp | 10 +++------- 3 files changed, 26 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/client/QXmppConfiguration.cpp b/src/client/QXmppConfiguration.cpp index b9452f38..d8a4b82e 100644 --- a/src/client/QXmppConfiguration.cpp +++ b/src/client/QXmppConfiguration.cpp @@ -58,10 +58,9 @@ public: int keepAliveTimeout; // will keep reconnecting if disconnected, default is true bool autoReconnectionEnabled; - bool useSASLAuthentication; ///< flag to specify what authentication system - ///< to be used - ///< defualt is true and use SASL - ///< false would use NonSASL if available + // which authentication systems to use (if any) + bool useSASLAuthentication; + bool useNonSASLAuthentication; // default is true bool ignoreSslErrors; @@ -84,6 +83,7 @@ QXmppConfigurationPrivate::QXmppConfigurationPrivate() , keepAliveTimeout(20) , autoReconnectionEnabled(true) , useSASLAuthentication(true) + , useNonSASLAuthentication(true) , ignoreSslErrors(true) , streamSecurityMode(QXmppConfiguration::TLSEnabled) , nonSASLAuthMechanism(QXmppConfiguration::NonSASLDigest) @@ -410,25 +410,34 @@ void QXmppConfiguration::setIgnoreSslErrors(bool value) d->ignoreSslErrors = value; } -/// Returns the type of authentication system specified by the user. -/// \return true if SASL was specified else false. If the specified -/// system is not available QXmpp will resort to the other one. +/// Returns whether to make use of SASL authentication. bool QXmppConfiguration::useSASLAuthentication() const { return d->useSASLAuthentication; } -/// Returns the type of authentication system specified by the user. -/// \param useSASL to hint to use SASL authentication system if available. -/// false will specify to use NonSASL XEP-0078: Non-SASL Authentication -/// If the specified one is not availbe, library will use the othe one +/// Sets whether to make use of SASL authentication. void QXmppConfiguration::setUseSASLAuthentication(bool useSASL) { d->useSASLAuthentication = useSASL; } +/// Returns whether to make use of non-SASL authentication. + +bool QXmppConfiguration::useNonSASLAuthentication() const +{ + return d->useNonSASLAuthentication; +} + +/// Sets whether to make use of non-SASL authentication. + +void QXmppConfiguration::setUseNonSASLAuthentication(bool useNonSASL) +{ + d->useNonSASLAuthentication = useNonSASL; +} + /// Returns the specified security mode for the stream. The default value is /// QXmppConfiguration::TLSEnabled. /// \return StreamSecurityMode diff --git a/src/client/QXmppConfiguration.h b/src/client/QXmppConfiguration.h index 34017973..4a690edf 100644 --- a/src/client/QXmppConfiguration.h +++ b/src/client/QXmppConfiguration.h @@ -119,6 +119,9 @@ public: bool useSASLAuthentication() const; void setUseSASLAuthentication(bool); + bool useNonSASLAuthentication() const; + void setUseNonSASLAuthentication(bool); + bool ignoreSslErrors() const; void setIgnoreSslErrors(bool); diff --git a/src/client/QXmppOutgoingClient.cpp b/src/client/QXmppOutgoingClient.cpp index c3e6c1f9..370cd2aa 100644 --- a/src/client/QXmppOutgoingClient.cpp +++ b/src/client/QXmppOutgoingClient.cpp @@ -353,13 +353,7 @@ void QXmppOutgoingClient::handleStanza(const QDomElement &nodeRecv) // handle authentication const bool nonSaslAvailable = features.nonSaslAuthMode() != QXmppStreamFeatures::Disabled; const bool saslAvailable = !features.authMechanisms().isEmpty(); - const bool useSasl = configuration().useSASLAuthentication(); - if((saslAvailable && nonSaslAvailable && !useSasl) || - (!saslAvailable && nonSaslAvailable)) - { - sendNonSASLAuthQuery(); - } - else if(saslAvailable) + if (saslAvailable && configuration().useSASLAuthentication()) { // supported and preferred SASL auth mechanisms const QStringList supportedMechanisms = QXmppSaslClient::availableMechanisms(); @@ -410,6 +404,8 @@ void QXmppOutgoingClient::handleStanza(const QDomElement &nodeRecv) return; } sendPacket(QXmppSaslAuth(d->saslClient->mechanism(), response)); + } else if(nonSaslAvailable && configuration().useNonSASLAuthentication()) { + sendNonSASLAuthQuery(); } // check whether bind is available -- cgit v1.2.3