diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-07-21 12:40:49 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-07-21 12:40:49 +0200 |
| commit | 6c82a7dd1f6290df5a0d54dcda8e5d57ee2d9c43 (patch) | |
| tree | 77218518ac78d5e0a2addaf398fc72f67fc6535f /src/base/QXmppMessage.cpp | |
| parent | a17a1899b9885b1edd5f12043b5040bdde67d9c4 (diff) | |
| download | qxmpp-6c82a7dd1f6290df5a0d54dcda8e5d57ee2d9c43.tar.gz | |
add support for XEP-0071: XHTML-IM (fixes issue: #143)
Diffstat (limited to 'src/base/QXmppMessage.cpp')
| -rw-r--r-- | src/base/QXmppMessage.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp index c0928c61..ab9a9cb6 100644 --- a/src/base/QXmppMessage.cpp +++ b/src/base/QXmppMessage.cpp @@ -23,6 +23,7 @@ */ #include <QDomElement> +#include <QTextStream> #include <QXmlStreamWriter> #include "QXmppConstants.h" @@ -38,6 +39,8 @@ static const char* chat_states[] = { "paused", }; +static const char *ns_xhtml = "http://www.w3.org/1999/xhtml"; + /// Constructs a QXmppMessage. /// /// \param from @@ -266,6 +269,21 @@ void QXmppMessage::parse(const QDomElement &element) } } + // XEP-0071: XHTML-IM + QDomElement htmlElement = element.firstChildElement("html"); + if (!htmlElement.isNull() && htmlElement.namespaceURI() == ns_xhtml_im) { + QDomElement bodyElement = htmlElement.firstChildElement("body"); + if (!bodyElement.isNull() && bodyElement.namespaceURI() == ns_xhtml) { + QTextStream stream(&m_xhtml, QIODevice::WriteOnly); + bodyElement.save(stream, 0); + + m_xhtml = m_xhtml.mid(m_xhtml.indexOf('>') + 1); + m_xhtml.replace(" xmlns=\"http://www.w3.org/1999/xhtml\"", ""); + m_xhtml.replace("</body>", ""); + m_xhtml = m_xhtml.trimmed(); + } + } + // XEP-0184: Message Delivery Receipts QDomElement receivedElement = element.firstChildElement("received"); if (!receivedElement.isNull() && receivedElement.namespaceURI() == ns_message_receipts) { @@ -336,6 +354,18 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const xmlWriter->writeEndElement(); } + // XEP-0071: XHTML-IM + if (!m_xhtml.isEmpty()) { + xmlWriter->writeStartElement("html"); + xmlWriter->writeAttribute("xmlns", ns_xhtml_im); + xmlWriter->writeStartElement("body"); + xmlWriter->writeAttribute("xmlns", ns_xhtml); + xmlWriter->writeCharacters(""); + xmlWriter->device()->write(m_xhtml.toUtf8()); + xmlWriter->writeEndElement(); + xmlWriter->writeEndElement(); + } + // time stamp if (m_stamp.isValid()) { @@ -415,3 +445,18 @@ void QXmppMessage::setThread(const QString& thread) m_thread = thread; } +/// Returns the message's XHTML body as defined by +/// XEP-0071: XHTML-IM. + +QString QXmppMessage::xhtml() const +{ + return m_xhtml; +} + +/// Sets the message's XHTML body as defined by +/// XEP-0071: XHTML-IM. + +void QXmppMessage::setXhtml(const QString &xhtml) +{ + m_xhtml = xhtml; +} |
