aboutsummaryrefslogtreecommitdiff
path: root/src/QXmppNonSASLAuth.cpp
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-08-12 08:24:29 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-08-12 08:24:29 +0000
commitf312239c8cae0a2aa58edcdc0589479229c98b55 (patch)
treef777e7bdfcfdaba9aab80c5dd559d444553d921d /src/QXmppNonSASLAuth.cpp
parent4e6d4908fdf5168fbd0ad4025f00a8d133622b4d (diff)
downloadqxmpp-f312239c8cae0a2aa58edcdc0589479229c98b55.tar.gz
make QXmppNonSASLAuthIq parsing/serialisation symetric
Diffstat (limited to 'src/QXmppNonSASLAuth.cpp')
-rw-r--r--src/QXmppNonSASLAuth.cpp42
1 files changed, 16 insertions, 26 deletions
diff --git a/src/QXmppNonSASLAuth.cpp b/src/QXmppNonSASLAuth.cpp
index 7e33fa43..7fa1e9e8 100644
--- a/src/QXmppNonSASLAuth.cpp
+++ b/src/QXmppNonSASLAuth.cpp
@@ -30,17 +30,22 @@
#include "QXmppUtils.h"
QXmppNonSASLAuthIq::QXmppNonSASLAuthIq()
- : QXmppIq(QXmppIq::Set),
- m_useplaintext(false)
+ : QXmppIq(QXmppIq::Set)
{
}
+bool QXmppNonSASLAuthIq::isNonSASLAuthIq(const QDomElement &element)
+{
+ QDomElement queryElement = element.firstChildElement("query");
+ return queryElement.namespaceURI() == ns_auth;
+}
+
void QXmppNonSASLAuthIq::parseElementFromChild(const QDomElement &element)
{
QDomElement queryElement = element.firstChildElement("query");
m_username = queryElement.firstChildElement("username").text();
m_password = queryElement.firstChildElement("password").text();
- m_digest = queryElement.firstChildElement("digest").text();
+ m_digest = QByteArray::fromHex(queryElement.firstChildElement("digest").text().toAscii());
m_resource = queryElement.firstChildElement("resource").text();
}
@@ -50,18 +55,8 @@ void QXmppNonSASLAuthIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
writer->writeAttribute("xmlns", ns_auth);
if (!m_username.isEmpty())
writer->writeTextElement("username", m_username);
- if (!m_password.isEmpty())
- {
- if ( m_useplaintext )
- writer->writeTextElement("password", m_password);
- else
- {//SHA1(concat(sid, password)).
- QByteArray textSid = m_sid.toUtf8();
- QByteArray encodedPassword = m_password.toUtf8();
- QByteArray digest = QCryptographicHash::hash(textSid + encodedPassword, QCryptographicHash::Sha1 ).toHex();
- writer->writeTextElement("digest", digest);
- }
- }
+ if (!m_digest.isEmpty())
+ writer->writeTextElement("digest", m_digest.toHex());
if (!m_resource.isEmpty())
writer->writeTextElement("resource", m_resource);
writer->writeEndElement();
@@ -77,11 +72,16 @@ void QXmppNonSASLAuthIq::setUsername( const QString &username )
m_username = username;
}
-QString QXmppNonSASLAuthIq::digest() const
+QByteArray QXmppNonSASLAuthIq::digest() const
{
return m_digest;
}
+void QXmppNonSASLAuthIq::setDigest(const QString &streamId, const QString &password)
+{
+ m_digest = QCryptographicHash::hash(streamId.toUtf8() + password.toUtf8(), QCryptographicHash::Sha1);
+}
+
QString QXmppNonSASLAuthIq::password() const
{
return m_password;
@@ -102,13 +102,3 @@ void QXmppNonSASLAuthIq::setResource(const QString &resource)
m_resource = resource;
}
-void QXmppNonSASLAuthIq::setStreamId(const QString &sid)
-{
- m_sid = sid;
-}
-
-void QXmppNonSASLAuthIq::setUsePlainText(bool use)
-{
- m_useplaintext = use;
-}
-