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 | |
| parent | a17a1899b9885b1edd5f12043b5040bdde67d9c4 (diff) | |
| download | qxmpp-6c82a7dd1f6290df5a0d54dcda8e5d57ee2d9c43.tar.gz | |
add support for XEP-0071: XHTML-IM (fixes issue: #143)
Diffstat (limited to 'src')
| -rw-r--r-- | src/base/QXmppConstants.cpp | 2 | ||||
| -rw-r--r-- | src/base/QXmppConstants.h | 2 | ||||
| -rw-r--r-- | src/base/QXmppMessage.cpp | 45 | ||||
| -rw-r--r-- | src/base/QXmppMessage.h | 6 | ||||
| -rw-r--r-- | src/client/QXmppDiscoveryManager.cpp | 1 |
5 files changed, 56 insertions, 0 deletions
diff --git a/src/base/QXmppConstants.cpp b/src/base/QXmppConstants.cpp index feabcb5d..54d0cf0c 100644 --- a/src/base/QXmppConstants.cpp +++ b/src/base/QXmppConstants.cpp @@ -57,6 +57,8 @@ const char* ns_vcard = "vcard-temp"; const char* ns_rsm = "http://jabber.org/protocol/rsm"; // XEP-0065: SOCKS5 Bytestreams const char* ns_bytestreams = "http://jabber.org/protocol/bytestreams"; +// XEP-0071: XHTML-IM +const char *ns_xhtml_im = "http://jabber.org/protocol/xhtml-im"; // XEP-0077: In-Band Registration const char* ns_register = "jabber:iq:register"; // XEP-0078: Non-SASL Authentication diff --git a/src/base/QXmppConstants.h b/src/base/QXmppConstants.h index 2428f5dd..4ee54e34 100644 --- a/src/base/QXmppConstants.h +++ b/src/base/QXmppConstants.h @@ -58,6 +58,8 @@ extern const char* ns_vcard; extern const char* ns_rsm; // XEP-0065: SOCKS5 Bytestreams extern const char* ns_bytestreams; +// XEP-0071: XHTML-IM +extern const char *ns_xhtml_im; // XEP-0077: In-Band Registration extern const char* ns_register; // XEP-0078: Non-SASL Authentication 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; +} diff --git a/src/base/QXmppMessage.h b/src/base/QXmppMessage.h index 45f6bbe1..b7219c89 100644 --- a/src/base/QXmppMessage.h +++ b/src/base/QXmppMessage.h @@ -89,6 +89,9 @@ public: QXmppMessage::Type type() const; void setType(QXmppMessage::Type); + QString xhtml() const; + void setXhtml(const QString &xhtml); + /// \cond void parse(const QDomElement &element); void toXml(QXmlStreamWriter *writer) const; @@ -115,6 +118,9 @@ private: QString m_subject; QString m_thread; + // XEP-0071: XHTML-IM + QString m_xhtml; + // Request message receipt as per XEP-0184. QString m_receiptId; bool m_receiptRequested; diff --git a/src/client/QXmppDiscoveryManager.cpp b/src/client/QXmppDiscoveryManager.cpp index 539a27c8..4f06a4ef 100644 --- a/src/client/QXmppDiscoveryManager.cpp +++ b/src/client/QXmppDiscoveryManager.cpp @@ -140,6 +140,7 @@ QXmppDiscoveryIq QXmppDiscoveryManager::capabilities() features << ns_data // XEP-0004: Data Forms << ns_rsm // XEP-0059: Result Set Management + << ns_xhtml_im // XEP-0071: XHTML-IM << ns_chat_states // XEP-0085: Chat State Notifications << ns_capabilities // XEP-0115: Entity Capabilities << ns_ping // XEP-0199: XMPP Ping |
