From f312239c8cae0a2aa58edcdc0589479229c98b55 Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Thu, 12 Aug 2010 08:24:29 +0000 Subject: make QXmppNonSASLAuthIq parsing/serialisation symetric --- src/QXmppNonSASLAuth.cpp | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) (limited to 'src/QXmppNonSASLAuth.cpp') 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; -} - -- cgit v1.2.3