aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2020-02-10 16:44:55 +0100
committerLNJ <lnj@kaidan.im>2020-02-10 20:29:19 +0100
commitbfd26369d1ef032837fbd2b52ea0ed4cc04abe91 (patch)
tree64aa6d70c44eada4c891c6c5272dd6b5af3ba5bd
parent964e7458191f615abe2ee4eb0b27c7680c7be2f3 (diff)
downloadqxmpp-bfd26369d1ef032837fbd2b52ea0ed4cc04abe91.tar.gz
Implement XEP-0428: Fallback Indication
This adds support of XEP-0428: Fallback Indication in version 0.1.0. https://xmpp.org/extensions/xep-0428.html
-rw-r--r--doc/xep.doc1
-rw-r--r--src/base/QXmppConstants.cpp2
-rw-r--r--src/base/QXmppConstants_p.h2
-rw-r--r--src/base/QXmppMessage.cpp44
-rw-r--r--src/base/QXmppMessage.h4
-rw-r--r--tests/qxmppmessage/tst_qxmppmessage.cpp19
6 files changed, 71 insertions, 1 deletions
diff --git a/doc/xep.doc b/doc/xep.doc
index 2bb50793..7233b788 100644
--- a/doc/xep.doc
+++ b/doc/xep.doc
@@ -47,6 +47,7 @@ Complete:
- XEP-0367: Message Attaching (v0.3.0)
- XEP-0380: Explicit Message Encryption (v0.3.0)
- XEP-0382: Spoiler messages (v0.2.0)
+- XEP-0428: Fallback Indication (v0.1.0)
Ongoing:
- XEP-0009: Jabber-RPC (API is not finalized yet)
diff --git a/src/base/QXmppConstants.cpp b/src/base/QXmppConstants.cpp
index a9d5612d..794ce14c 100644
--- a/src/base/QXmppConstants.cpp
+++ b/src/base/QXmppConstants.cpp
@@ -166,3 +166,5 @@ const char* ns_omemo = "eu.siacs.conversations.axolotl";
const char* ns_mix_pam = "urn:xmpp:mix:pam:1";
const char* ns_mix_roster = "urn:xmpp:mix:roster:0";
const char* ns_mix_presence = "urn:xmpp:presence:0";
+// XEP-0428: Fallback Indication
+const char* ns_fallback_indication = "urn:xmpp:fallback:0";
diff --git a/src/base/QXmppConstants_p.h b/src/base/QXmppConstants_p.h
index 28ad6da8..c7811811 100644
--- a/src/base/QXmppConstants_p.h
+++ b/src/base/QXmppConstants_p.h
@@ -178,5 +178,7 @@ extern const char* ns_omemo;
extern const char* ns_mix_pam;
extern const char* ns_mix_roster;
extern const char* ns_mix_presence;
+// XEP-0428: Fallback Indication
+extern const char* ns_fallback_indication;
#endif // QXMPPCONSTANTS_H
diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp
index 3544c55b..e877e5c1 100644
--- a/src/base/QXmppMessage.cpp
+++ b/src/base/QXmppMessage.cpp
@@ -155,6 +155,9 @@ public:
// XEP-0382: Spoiler messages
bool isSpoiler;
QString spoilerHint;
+
+ // XEP-0428: Fallback Indication
+ bool isFallback;
};
QXmppMessagePrivate::QXmppMessagePrivate()
@@ -167,7 +170,8 @@ QXmppMessagePrivate::QXmppMessagePrivate()
marker(QXmppMessage::NoMarker),
privatemsg(false),
hints(0),
- isSpoiler(false)
+ isSpoiler(false),
+ isFallback(false)
{
}
@@ -796,6 +800,34 @@ void QXmppMessage::setSpoilerHint(const QString &spoilerHint)
d->isSpoiler = true;
}
+///
+/// Sets whether this message is only a fallback according to \xep{0428}:
+/// Fallback Indication.
+///
+/// This is useful for clients not supporting end-to-end encryption to indicate
+/// that the message body does not contain the intended text of the author.
+///
+/// \since QXmpp 1.3
+///
+bool QXmppMessage::isFallback() const
+{
+ return d->isFallback;
+}
+
+///
+/// Sets whether this message is only a fallback according to \xep{0428}:
+/// Fallback Indication.
+///
+/// This is useful for clients not supporting end-to-end encryption to indicate
+/// that the message body does not contain the intended text of the author.
+///
+/// \since QXmpp 1.3
+///
+void QXmppMessage::setIsFallback(bool isFallback)
+{
+ d->isFallback = isFallback;
+}
+
/// \cond
void QXmppMessage::parse(const QDomElement &element)
{
@@ -999,6 +1031,13 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const
xmlWriter->writeEndElement();
}
+ // XEP-0428: Fallback Indication
+ if (d->isFallback) {
+ xmlWriter->writeStartElement(QStringLiteral("fallback"));
+ xmlWriter->writeDefaultNamespace(ns_fallback_indication);
+ xmlWriter->writeEndElement();
+ }
+
// other extensions
QXmppStanza::extensionsToXml(xmlWriter);
@@ -1093,6 +1132,9 @@ void QXmppMessage::parseExtension(const QDomElement &element, QXmppElementList &
} else if (checkElement(element, QStringLiteral("spoiler"), ns_spoiler)) {
d->isSpoiler = true;
d->spoilerHint = element.text();
+ } else if (checkElement(element, QStringLiteral("fallback"), ns_fallback_indication)) {
+ // XEP-0428: Fallback Indication
+ d->isFallback = true;
} else {
// other extensions
unknownExtensions << QXmppElement(element);
diff --git a/src/base/QXmppMessage.h b/src/base/QXmppMessage.h
index 970395aa..cd24c25a 100644
--- a/src/base/QXmppMessage.h
+++ b/src/base/QXmppMessage.h
@@ -205,6 +205,10 @@ public:
QString spoilerHint() const;
void setSpoilerHint(const QString &);
+ // XEP-0428: Fallback Indication
+ bool isFallback() const;
+ void setIsFallback(bool isFallback);
+
/// \cond
void parse(const QDomElement &element) override;
void toXml(QXmlStreamWriter *writer) const override;
diff --git a/tests/qxmppmessage/tst_qxmppmessage.cpp b/tests/qxmppmessage/tst_qxmppmessage.cpp
index 4c7f99fc..84e9f5fe 100644
--- a/tests/qxmppmessage/tst_qxmppmessage.cpp
+++ b/tests/qxmppmessage/tst_qxmppmessage.cpp
@@ -59,6 +59,7 @@ private slots:
void testSpoiler();
void testProcessingHints();
void testBobData();
+ void testFallbackIndication();
};
void tst_QXmppMessage::testBasic_data()
@@ -131,6 +132,7 @@ void tst_QXmppMessage::testBasic()
QVERIFY(!message.hasHint(QXmppMessage::NoCopy));
QVERIFY(!message.hasHint(QXmppMessage::Store));
QCOMPARE(message.bitsOfBinaryData(), QXmppBitsOfBinaryDataList());
+ QVERIFY(!message.isFallback());
message = QXmppMessage();
message.setTo(QStringLiteral("foo@example.com/QXmpp"));
@@ -966,5 +968,22 @@ void tst_QXmppMessage::testBobData()
QCOMPARE(constMessage.bitsOfBinaryData(), msg.bitsOfBinaryData());
}
+void tst_QXmppMessage::testFallbackIndication()
+{
+ const QByteArray xml = QByteArrayLiteral(
+ "<message type=\"chat\">"
+ "<fallback xmlns=\"urn:xmpp:fallback:0\"/>"
+ "</message>");
+
+ QXmppMessage message;
+ parsePacket(message, xml);
+ QVERIFY(message.isFallback());
+ serializePacket(message, xml);
+
+ QXmppMessage message2;
+ message2.setIsFallback(true);
+ serializePacket(message2, xml);
+}
+
QTEST_MAIN(tst_QXmppMessage)
#include "tst_qxmppmessage.moc"