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/QXmppMessage.cpp | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'source/QXmppMessage.cpp') diff --git a/source/QXmppMessage.cpp b/source/QXmppMessage.cpp index 54f599bb..65d5bece 100644 --- a/source/QXmppMessage.cpp +++ b/source/QXmppMessage.cpp @@ -24,7 +24,7 @@ #include "QXmppMessage.h" #include "QXmppUtils.h" -#include +#include QXmppMessage::QXmppMessage(const QString& from, const QString& to, const QString& body, const QString& thread) @@ -108,30 +108,20 @@ void QXmppMessage::setTypeFromStr(const QString& str) } } -QByteArray QXmppMessage::toXml() const +void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const { -// yet to take care of escaping xml chars -// and what if there are multiple bodies in diff langs -// also error - - // why not qbytearray getback - // or use bytearray without text stream..using append - QString data; - QTextStream stream(&data); - - stream << ""; - helperToXmlAddElement(stream, "subject", escapeString(getSubject())); - helperToXmlAddElement(stream, "body", escapeString(getBody())); - helperToXmlAddElement(stream, "thread", getThread()); - stream << getError().toXml(); - stream << ""; - return data.toAscii(); + + xmlWriter->writeStartElement("message"); + helperToXmlAddAttribute(xmlWriter, "xml:lang", getLang()); + helperToXmlAddAttribute(xmlWriter, "id", getId()); + helperToXmlAddAttribute(xmlWriter, "to", getTo()); + helperToXmlAddAttribute(xmlWriter, "from", getFrom()); + helperToXmlAddAttribute(xmlWriter, "type", getTypeStr()); + helperToXmlAddTextElement(xmlWriter, "subject", getSubject()); + helperToXmlAddTextElement(xmlWriter,"body", getBody()); + helperToXmlAddTextElement(xmlWriter,"thread", getThread()); + getError().toXml(xmlWriter); + xmlWriter->writeEndElement(); } QString QXmppMessage::getBody() const -- cgit v1.2.3