aboutsummaryrefslogtreecommitdiff
path: root/source/QXmppMessage.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/QXmppMessage.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/QXmppMessage.cpp')
-rw-r--r--source/QXmppMessage.cpp38
1 files changed, 14 insertions, 24 deletions
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 <QTextStream>
+#include <QXmlStreamWriter>
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 << "<message";
- helperToXmlAddAttribute(stream, "xml:lang", getLang());
- helperToXmlAddAttribute(stream, "id", getId());
- helperToXmlAddAttribute(stream, "to", getTo());
- helperToXmlAddAttribute(stream, "from", getFrom());
- helperToXmlAddAttribute(stream, "type", getTypeStr());
- stream << ">";
- helperToXmlAddElement(stream, "subject", escapeString(getSubject()));
- helperToXmlAddElement(stream, "body", escapeString(getBody()));
- helperToXmlAddElement(stream, "thread", getThread());
- stream << getError().toXml();
- stream << "</message>";
- 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