aboutsummaryrefslogtreecommitdiff
path: root/source/QXmppStream.cpp
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-08-09 10:14:07 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-08-09 10:14:07 +0000
commit9873e811b297c49a988891f7b6928d8381d5ae59 (patch)
tree0a8992c764776a7fbd7f0b17ad1be722bede2031 /source/QXmppStream.cpp
parent73b8366617e350f0da161e3a7ed734e40d7b0f52 (diff)
downloadqxmpp-9873e811b297c49a988891f7b6928d8381d5ae59.tar.gz
clarify SASL mechanism selection
Diffstat (limited to 'source/QXmppStream.cpp')
-rw-r--r--source/QXmppStream.cpp71
1 files changed, 33 insertions, 38 deletions
diff --git a/source/QXmppStream.cpp b/source/QXmppStream.cpp
index d73e1392..05e62c6a 100644
--- a/source/QXmppStream.cpp
+++ b/source/QXmppStream.cpp
@@ -346,53 +346,48 @@ void QXmppStream::parser(const QByteArray& data)
}
else if(saslAvailable)
{
- // SASL Authentication
+ // parse advertised SASL Authentication mechanisms
+ QList<QXmppConfiguration::SASLAuthMechanism> mechanisms;
QDomElement element = nodeRecv.firstChildElement("mechanisms");
- debug("Mechanisms:");
- QDomElement subElement = element.firstChildElement();
- QStringList mechanisms;
+ QDomElement subElement = element.firstChildElement("mechanism");
+ debug("SASL Authentication mechanisms:");
while(!subElement.isNull())
{
- if(subElement.tagName() == "mechanism")
- {
- debug(subElement.text());
- mechanisms << subElement.text();
- }
- subElement = subElement.nextSiblingElement();
+ debug(subElement.text());
+ if (subElement.text() == QLatin1String("PLAIN"))
+ mechanisms << QXmppConfiguration::SASLPlain;
+ else if (subElement.text() == QLatin1String("DIGEST-MD5"))
+ mechanisms << QXmppConfiguration::SASLDigestMD5;
+ else if (subElement.text() == QLatin1String("ANONYMOUS"))
+ mechanisms << QXmppConfiguration::SASLAnonymous;
+ subElement = subElement.nextSiblingElement("mechanism");
+ }
+
+ // determine SASL Authentication mechanism to use
+ QXmppConfiguration::SASLAuthMechanism mechanism = configuration().sASLAuthMechanism();
+ if (mechanisms.isEmpty())
+ {
+ warning("No supported SASL Authentication mechanism available");
+ disconnect();
+ return;
+ }
+ else if (!mechanisms.contains(mechanism))
+ {
+ info("Desired SASL Auth mechanism is not available, selecting first available one");
+ mechanism = mechanisms.first();
}
- switch(configuration().sASLAuthMechanism())
+ // send SASL Authentication request
+ switch(mechanism)
{
case QXmppConfiguration::SASLPlain:
- if(mechanisms.contains("PLAIN"))
- {
- sendAuthPlain();
- break;
- }
+ sendAuthPlain();
+ break;
case QXmppConfiguration::SASLDigestMD5:
- if(mechanisms.contains("DIGEST-MD5"))
- {
- sendAuthDigestMD5();
- break;
- }
+ sendAuthDigestMD5();
+ break;
case QXmppConfiguration::SASLAnonymous:
- if(mechanisms.contains("ANONYMOUS"))
- {
- sendToServer("<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='ANONYMOUS'/>");
- break;
- }
- default:
- info("Desired SASL Auth mechanism not available trying the available ones");
- if(mechanisms.contains("DIGEST-MD5"))
- sendAuthDigestMD5();
- else if(mechanisms.contains("PLAIN"))
- sendAuthPlain();
- else
- {
- warning("SASL Auth mechanism not available");
- disconnect();
- return;
- }
+ sendToServer("<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='ANONYMOUS'/>");
break;
}
}