aboutsummaryrefslogtreecommitdiff
path: root/source/QXmppNonSASLAuth.cpp
diff options
context:
space:
mode:
authorManjeet Dahiya <manjeetdahiya@gmail.com>2009-10-20 11:43:45 +0000
committerManjeet Dahiya <manjeetdahiya@gmail.com>2009-10-20 11:43:45 +0000
commite2be03e254a956024c9d67b19b8a809c9692b6f1 (patch)
tree4da3e5da19d109bf34d02ed9359065c73be176ab /source/QXmppNonSASLAuth.cpp
parenta9d542be47e91ae39390247f8c8bbb21d588388f (diff)
downloadqxmpp-e2be03e254a956024c9d67b19b8a809c9692b6f1.tar.gz
Using QXmlStreamWriter for directly writing to the socket. This will avoid string concatenations and problems with XML escaping rules.
and Fix for Issue 19: XMPP Version < 1.0 send NonSASL Auth query
Diffstat (limited to 'source/QXmppNonSASLAuth.cpp')
-rw-r--r--source/QXmppNonSASLAuth.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/source/QXmppNonSASLAuth.cpp b/source/QXmppNonSASLAuth.cpp
index 883bdc0d..7f9c9791 100644
--- a/source/QXmppNonSASLAuth.cpp
+++ b/source/QXmppNonSASLAuth.cpp
@@ -1,6 +1,7 @@
#include "QXmppNonSASLAuth.h"
#include "QXmppUtils.h"
#include <QCryptographicHash>
+#include <QXmlStreamWriter>
QXmppNonSASLAuthTypesRequestIq::QXmppNonSASLAuthTypesRequestIq() : QXmppIq(QXmppIq::Get)
{
@@ -12,13 +13,12 @@ void QXmppNonSASLAuthTypesRequestIq::setUsername( const QString &username )
m_username = username;
}
-QByteArray QXmppNonSASLAuthTypesRequestIq::toXmlElementFromChild() const
+void QXmppNonSASLAuthTypesRequestIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
{
- QByteArray resultingXml;
- resultingXml += "<query xmlns=\"jabber:iq:auth\">";
- resultingXml += "<username>" + escapeString(m_username).toUtf8() + "</username>";
- resultingXml += "</query>";
- return resultingXml;
+ writer->writeStartElement("query");
+ writer->writeAttribute( "xmlns","jabber:iq:auth");
+ writer->writeTextElement("username", m_username );
+ writer->writeEndElement();
}
QXmppNonSASLAuthIq::QXmppNonSASLAuthIq() : QXmppIq(QXmppIq::Set), m_useplaintext(false)
@@ -26,23 +26,22 @@ QXmppNonSASLAuthIq::QXmppNonSASLAuthIq() : QXmppIq(QXmppIq::Set), m_useplaintext
}
-QByteArray QXmppNonSASLAuthIq::toXmlElementFromChild() const
+void QXmppNonSASLAuthIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
{
- QByteArray resultingXml;
- resultingXml += "<query xmlns=\"jabber:iq:auth\">";
- resultingXml += "<username>" + escapeString(m_username).toUtf8() + "</username>";
+ writer->writeStartElement("query");
+ writer->writeAttribute( "xmlns","jabber:iq:auth");
+ writer->writeTextElement("username", m_username );
if ( m_useplaintext )
- resultingXml += "<password>" + escapeString(m_password).toUtf8() + "</password>";
+ 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();
- resultingXml += "<digest>" + digest + "</digest>";
+ writer->writeTextElement("digest", digest );
}
- resultingXml += "<resource>" + escapeString(m_resource).toUtf8() + "</resource>";
- resultingXml += "</query>";
- return resultingXml;
+ writer->writeTextElement("resource", m_resource );
+ writer->writeEndElement();
}
void QXmppNonSASLAuthIq::setUsername( const QString &username )