From e2be03e254a956024c9d67b19b8a809c9692b6f1 Mon Sep 17 00:00:00 2001 From: Manjeet Dahiya Date: Tue, 20 Oct 2009 11:43:45 +0000 Subject: 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 --- source/QXmppNonSASLAuth.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'source/QXmppNonSASLAuth.cpp') 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 +#include 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 += ""; - resultingXml += "" + escapeString(m_username).toUtf8() + ""; - resultingXml += ""; - 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 += ""; - resultingXml += "" + escapeString(m_username).toUtf8() + ""; + writer->writeStartElement("query"); + writer->writeAttribute( "xmlns","jabber:iq:auth"); + writer->writeTextElement("username", m_username ); if ( m_useplaintext ) - resultingXml += "" + escapeString(m_password).toUtf8() + ""; + 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 + ""; + writer->writeTextElement("digest", digest ); } - resultingXml += "" + escapeString(m_resource).toUtf8() + ""; - resultingXml += ""; - return resultingXml; + writer->writeTextElement("resource", m_resource ); + writer->writeEndElement(); } void QXmppNonSASLAuthIq::setUsername( const QString &username ) -- cgit v1.2.3