aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-02-12 10:09:33 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-02-12 10:09:33 +0000
commita04f3f45fe4b03ede4f1f89b7610e50714e347b6 (patch)
tree2a5fdd095a40da6a359427c031cabcb38dfdc966 /source
parent4382a8afdb899e59ea8bff5caec7d70d4c64bcc6 (diff)
downloadqxmpp-a04f3f45fe4b03ede4f1f89b7610e50714e347b6.tar.gz
make it possible to attach an extension element to messages and presences
Diffstat (limited to 'source')
-rw-r--r--source/QXmppElement.cpp6
-rw-r--r--source/QXmppMessage.cpp1
-rw-r--r--source/QXmppStanza.cpp10
-rw-r--r--source/QXmppStanza.h6
-rw-r--r--source/QXmppStream.cpp9
5 files changed, 31 insertions, 1 deletions
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 <QString>
@@ -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);
}
}