From 6c82a7dd1f6290df5a0d54dcda8e5d57ee2d9c43 Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Sat, 21 Jul 2012 12:40:49 +0200 Subject: add support for XEP-0071: XHTML-IM (fixes issue: #143) --- src/base/QXmppMessage.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/base/QXmppMessage.cpp') 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 +#include #include #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("", ""); + 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; +} -- cgit v1.2.3