From a04f3f45fe4b03ede4f1f89b7610e50714e347b6 Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Fri, 12 Feb 2010 10:09:33 +0000 Subject: make it possible to attach an extension element to messages and presences --- source/QXmppElement.cpp | 6 ++++++ source/QXmppMessage.cpp | 1 + source/QXmppStanza.cpp | 10 ++++++++++ source/QXmppStanza.h | 6 +++++- source/QXmppStream.cpp | 9 +++++++++ 5 files changed, 31 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/QXmppElement.cpp b/source/QXmppElement.cpp index a793a999..2dcb87ad 100644 --- a/source/QXmppElement.cpp +++ b/source/QXmppElement.cpp @@ -32,6 +32,9 @@ QXmppElement::QXmppElement() QXmppElement::QXmppElement(const QDomElement &element) { + if (element.isNull()) + return; + m_tagName = element.tagName(); QString xmlns = element.namespaceURI(); QString parentns = element.parentNode().namespaceURI(); @@ -94,6 +97,9 @@ void QXmppElement::setTagName(const QString &tagName) void QXmppElement::toXml(QXmlStreamWriter *writer) const { + if (isNull()) + return; + writer->writeStartElement(m_tagName); foreach (const QString &attr, m_attributes.keys()) helperToXmlAddAttribute(writer, attr, m_attributes.value(attr)); diff --git a/source/QXmppMessage.cpp b/source/QXmppMessage.cpp index 65c5de7f..9fb0037b 100644 --- a/source/QXmppMessage.cpp +++ b/source/QXmppMessage.cpp @@ -123,6 +123,7 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const if (!getThread().isEmpty()) helperToXmlAddTextElement(xmlWriter,"thread", getThread()); getError().toXml(xmlWriter); + getExtension().toXml(xmlWriter); xmlWriter->writeEndElement(); } diff --git a/source/QXmppStanza.cpp b/source/QXmppStanza.cpp index c78aeed8..5c5fadbe 100644 --- a/source/QXmppStanza.cpp +++ b/source/QXmppStanza.cpp @@ -315,6 +315,16 @@ void QXmppStanza::setError(QXmppStanza::Error& error) m_error = error; } +QXmppElement QXmppStanza::getExtension() const +{ + return m_extension; +} + +void QXmppStanza::setExtension(const QXmppElement &extension) +{ + m_extension = extension; +} + bool QXmppStanza::isErrorStanza() { return !(m_error.getTypeStr().isEmpty() && diff --git a/source/QXmppStanza.h b/source/QXmppStanza.h index 8546aea8..05ccf024 100644 --- a/source/QXmppStanza.h +++ b/source/QXmppStanza.h @@ -25,6 +25,7 @@ #ifndef QXMPPSTANZA_H #define QXMPPSTANZA_H +#include "QXmppElement.h" #include "QXmppPacket.h" #include @@ -105,13 +106,15 @@ public: QString getId() const; QString getLang() const; QXmppStanza::Error getError() const; + QXmppElement getExtension() const; void setTo(const QString&); void setFrom(const QString&); void setId(const QString&); void generateAndSetNextId(); void setLang(const QString&); - void setError(QXmppStanza::Error& error); + void setError(QXmppStanza::Error& error); + void setExtension(const QXmppElement &element); bool isErrorStanza(); private: @@ -121,6 +124,7 @@ private: QString m_id; QString m_lang; QXmppStanza::Error m_error; + QXmppElement m_extension; }; #endif // QXMPPSTANZA_H diff --git a/source/QXmppStream.cpp b/source/QXmppStream.cpp index f0b9f91c..4c6321dc 100644 --- a/source/QXmppStream.cpp +++ b/source/QXmppStream.cpp @@ -674,6 +674,10 @@ void QXmppStream::parser(const QByteArray& data) presence.setError(error); } + QDomElement xElement = nodeRecv.firstChildElement("x"); + if(!xElement.isNull()) + presence.setExtension(QXmppElement(xElement)); + processPresence(presence); } else if(nodeRecv.tagName() == "message") @@ -697,6 +701,11 @@ void QXmppStream::parser(const QByteArray& data) QXmppStanza::Error error = parseStanzaError(errorElement); message.setError(error); } + + QDomElement xElement = nodeRecv.firstChildElement("x"); + if(!xElement.isNull()) + message.setExtension(QXmppElement(xElement)); + processMessage(message); } } -- cgit v1.2.3