diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-08-26 07:39:14 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-08-26 07:39:14 +0000 |
| commit | 4ecc0dcf7934dd0d43be634d03da799af82f91e1 (patch) | |
| tree | edf7ba529e0e8b537f367261d6ca4cc022331824 /src | |
| parent | 3a3f0d343cc4c2c01ab118098717a6c02543f7cd (diff) | |
| download | qxmpp-4ecc0dcf7934dd0d43be634d03da799af82f91e1.tar.gz | |
improve QXmppPasswordChecker class
Diffstat (limited to 'src')
| -rw-r--r-- | src/QXmppIncomingClient.cpp | 9 | ||||
| -rw-r--r-- | src/QXmppIncomingClient.h | 18 |
2 files changed, 21 insertions, 6 deletions
diff --git a/src/QXmppIncomingClient.cpp b/src/QXmppIncomingClient.cpp index 1a8f4f3c..6e425b74 100644 --- a/src/QXmppIncomingClient.cpp +++ b/src/QXmppIncomingClient.cpp @@ -142,11 +142,12 @@ void QXmppIncomingClient::handleStream(const QDomElement &streamElement) features.setBindAvailable(true); features.setSessionAvailable(true); } - else + else if (d->passwordChecker) { QList<QXmppConfiguration::SASLAuthMechanism> mechanisms; mechanisms << QXmppConfiguration::SASLPlain; - mechanisms << QXmppConfiguration::SASLDigestMD5; + if (d->passwordChecker->hasPasswords()) + mechanisms << QXmppConfiguration::SASLDigestMD5; features.setAuthMechanisms(mechanisms); } sendPacket(features); @@ -182,7 +183,7 @@ void QXmppIncomingClient::handleStanza(const QDomElement &nodeRecv) const QString username = QString::fromUtf8(auth[1]); const QString password = QString::fromUtf8(auth[2]); - if (d->passwordChecker && d->passwordChecker->check(username, password)) + if (d->passwordChecker && d->passwordChecker->checkCredentials(username, password)) { d->username = username; sendData("<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>"); @@ -226,7 +227,7 @@ void QXmppIncomingClient::handleStanza(const QDomElement &nodeRecv) // check credentials const QString username = QString::fromUtf8(response.value("username")); QString password; - if (!d->passwordChecker || !d->passwordChecker->get(username, password)) + if (!d->passwordChecker || !d->passwordChecker->getPassword(username, password)) { sendData("<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><not-authorized/></failure>"); disconnectFromHost(); diff --git a/src/QXmppIncomingClient.h b/src/QXmppIncomingClient.h index 65acf842..a6be0a54 100644 --- a/src/QXmppIncomingClient.h +++ b/src/QXmppIncomingClient.h @@ -35,10 +35,24 @@ class QXmppPasswordChecker { public: /// Checks that the given credentials are valid. - virtual bool check(const QString &username, const QString &password) = 0; + virtual bool checkCredentials(const QString &username, const QString &password) = 0; /// Retrieves the password for the given username. - virtual bool get(const QString &username, QString &password) = 0; + /// + /// Reimplement this method to support DIGEST-MD5 authentication. + virtual bool getPassword(const QString &username, QString &password) + { + return false; + }; + + /// Returns true if it is possible to retrieve passwords. + /// + /// Reimplement this method and return true if you provided a + /// getPassword() method. + virtual bool hasPasswords() const + { + return false; + }; }; /// \brief The QXmppIncomingClient class represents an incoming XMPP stream |
