aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2018-12-04 19:22:02 +0100
committerJeremy Lainé <jeremy.laine@m4x.org>2018-12-19 09:06:22 +0100
commitfc389736df1107245ca91ecbe0bca0526a42288a (patch)
tree162f5b422fcdfb28ce926fe3190960039886fc9c
parent5b0b6472aa5932844f87ee939e0bf11b8eadb2cd (diff)
downloadqxmpp-fc389736df1107245ca91ecbe0bca0526a42288a.tar.gz
Add partial support of XEP-0066: Out of Band Data
Today this is most important for attaching URLs generated by XEP-0363: HTTP File Upload for a very basic form of media/file sharing.
-rw-r--r--src/base/QXmppConstants.cpp2
-rw-r--r--src/base/QXmppConstants_p.h2
-rw-r--r--src/base/QXmppMessage.cpp28
-rw-r--r--src/base/QXmppMessage.h4
-rw-r--r--tests/qxmppmessage/tst_qxmppmessage.cpp28
5 files changed, 64 insertions, 0 deletions
diff --git a/src/base/QXmppConstants.cpp b/src/base/QXmppConstants.cpp
index 1ab2c70d..03260018 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-0066: Out of Band Data
+const char* ns_oob = "jabber:x:oob";
// XEP-0071: XHTML-IM
const char *ns_xhtml_im = "http://jabber.org/protocol/xhtml-im";
// XEP-0077: In-Band Registration
diff --git a/src/base/QXmppConstants_p.h b/src/base/QXmppConstants_p.h
index cc113e3d..8846145c 100644
--- a/src/base/QXmppConstants_p.h
+++ b/src/base/QXmppConstants_p.h
@@ -69,6 +69,8 @@ extern const char* ns_vcard;
extern const char* ns_rsm;
// XEP-0065: SOCKS5 Bytestreams
extern const char* ns_bytestreams;
+// XEP-0066: Out of Band Data
+extern const char* ns_oob;
// XEP-0071: XHTML-IM
extern const char *ns_xhtml_im;
// XEP-0077: In-Band Registration
diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp
index df6e6bd1..3c62bd42 100644
--- a/src/base/QXmppMessage.cpp
+++ b/src/base/QXmppMessage.cpp
@@ -96,6 +96,9 @@ public:
// XEP-0280: Message Carbons
bool privatemsg;
+
+ // XEP-0066: Out of Band Data
+ QString outOfBandUrl;
};
/// Constructs a QXmppMessage.
@@ -475,6 +478,20 @@ bool QXmppMessage::isXmppStanza() const
return true;
}
+/// Returns a possibly attached URL from XEP-0066: Out of Band Data
+
+QString QXmppMessage::outOfBandUrl() const
+{
+ return d->outOfBandUrl;
+}
+
+/// Sets the attached URL for XEP-0066: Out of Band Data
+
+void QXmppMessage::setOutOfBandUrl(const QString &url)
+{
+ d->outOfBandUrl = url;
+}
+
/// \cond
void QXmppMessage::parse(const QDomElement &element)
{
@@ -604,6 +621,9 @@ void QXmppMessage::parse(const QDomElement &element)
d->mucInvitationJid = xElement.attribute("jid");
d->mucInvitationPassword = xElement.attribute("password");
d->mucInvitationReason = xElement.attribute("reason");
+ } else if (xElement.namespaceURI() == ns_oob) {
+ // XEP-0066: Out of Band Data
+ d->outOfBandUrl = xElement.firstChildElement("url").text();
}
else {
extensions << QXmppElement(xElement);
@@ -729,6 +749,14 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const
xmlWriter->writeEndElement();
}
+ // XEP-0066: Out of Band Data
+ if (!d->outOfBandUrl.isEmpty()) {
+ xmlWriter->writeStartElement("x");
+ xmlWriter->writeAttribute("xmlns", ns_oob);
+ xmlWriter->writeTextElement("url", d->outOfBandUrl);
+ xmlWriter->writeEndElement();
+ }
+
// other extensions
QXmppStanza::extensionsToXml(xmlWriter);
diff --git a/src/base/QXmppMessage.h b/src/base/QXmppMessage.h
index fbed97e0..4ecd0d19 100644
--- a/src/base/QXmppMessage.h
+++ b/src/base/QXmppMessage.h
@@ -135,6 +135,10 @@ public:
bool isXmppStanza() const;
+ // XEP-0066: Out of Band Data
+ QString outOfBandUrl() const;
+ void setOutOfBandUrl(const QString&);
+
/// \cond
void parse(const QDomElement &element);
void toXml(QXmlStreamWriter *writer) const;
diff --git a/tests/qxmppmessage/tst_qxmppmessage.cpp b/tests/qxmppmessage/tst_qxmppmessage.cpp
index 9d3ff652..25c110c6 100644
--- a/tests/qxmppmessage/tst_qxmppmessage.cpp
+++ b/tests/qxmppmessage/tst_qxmppmessage.cpp
@@ -46,6 +46,7 @@ private slots:
void testSubextensions();
void testChatMarkers();
void testPrivateMessage();
+ void testOutOfBandUrl();
};
void tst_QXmppMessage::testBasic_data()
@@ -569,5 +570,32 @@ void tst_QXmppMessage::testPrivateMessage()
QVERIFY(!buffer.data().contains("private"));
}
+void tst_QXmppMessage::testOutOfBandUrl()
+{
+ const QByteArray oobXml(
+ "<message to=\"MaineBoy@jabber.org/home\" "
+ "from=\"stpeter@jabber.org/work\" "
+ "type=\"chat\">"
+ "<body>Yeah, but do you have a license to Jabber?</body>"
+ "<x xmlns=\"jabber:x:oob\">"
+ "<url>http://www.jabber.org/images/psa-license.jpg</url>"
+ "</x>"
+ "</message>"
+ );
+ const QString firstUrl = "http://www.jabber.org/images/psa-license.jpg";
+ const QString newUrl = "https://xmpp.org/theme/images/xmpp-logo.svg";
+
+ QXmppMessage oobMessage;
+ parsePacket(oobMessage, oobXml);
+ QCOMPARE(oobMessage.outOfBandUrl(), firstUrl);
+
+ oobMessage.setOutOfBandUrl(newUrl);
+ QCOMPARE(oobMessage.outOfBandUrl(), newUrl);
+
+ // set first url again
+ oobMessage.setOutOfBandUrl(firstUrl);
+ serializePacket(oobMessage, oobXml);
+}
+
QTEST_MAIN(tst_QXmppMessage)
#include "tst_qxmppmessage.moc"