diff options
| author | Linus Jahn <lnj@kaidan.im> | 2020-02-11 10:56:00 +0100 |
|---|---|---|
| committer | LNJ <lnj@kaidan.im> | 2020-02-11 16:20:08 +0100 |
| commit | 776f028d9f3f51e9dbba834a01d1decd737c4a27 (patch) | |
| tree | 6ea444c840812d001ea2f259ae50c0aa38c50fdd | |
| parent | f583f1a71459f413f9f869b8f1616722054dbea8 (diff) | |
| download | qxmpp-776f028d9f3f51e9dbba834a01d1decd737c4a27.tar.gz | |
Implement XEP-0359: Unique and Stable Stanza IDs
This adds support of XEP-0359: Unique and Stable Stanza IDs in version
0.6.0.
| -rw-r--r-- | doc/xep.doc | 1 | ||||
| -rw-r--r-- | src/base/QXmppConstants.cpp | 2 | ||||
| -rw-r--r-- | src/base/QXmppConstants_p.h | 2 | ||||
| -rw-r--r-- | src/base/QXmppMessage.cpp | 96 | ||||
| -rw-r--r-- | src/base/QXmppMessage.h | 10 | ||||
| -rw-r--r-- | tests/qxmppmessage/tst_qxmppmessage.cpp | 26 |
6 files changed, 136 insertions, 1 deletions
diff --git a/doc/xep.doc b/doc/xep.doc index 7233b788..30f741a0 100644 --- a/doc/xep.doc +++ b/doc/xep.doc @@ -43,6 +43,7 @@ Complete: - XEP-0319: Last User Interaction in Presence - XEP-0334: Message Processing Hints (v0.3.0) - XEP-0352: Client State Indication +- XEP-0359: Unique and Stable Stanza IDs (v0.6.0) - XEP-0363: HTTP File Upload (v0.9.0) - XEP-0367: Message Attaching (v0.3.0) - XEP-0380: Explicit Message Encryption (v0.3.0) diff --git a/src/base/QXmppConstants.cpp b/src/base/QXmppConstants.cpp index 794ce14c..b88bccf6 100644 --- a/src/base/QXmppConstants.cpp +++ b/src/base/QXmppConstants.cpp @@ -139,6 +139,8 @@ const char* ns_chat_markers = "urn:xmpp:chat-markers:0"; const char* ns_message_processing_hints = "urn:xmpp:hints"; // XEP-0352: Client State Indication const char* ns_csi = "urn:xmpp:csi:0"; +// XEP-0359: Unique and Stable Stanza IDs +const char* ns_sid = "urn:xmpp:sid:0"; // XEP-0363: HTTP File Upload const char* ns_http_upload = "urn:xmpp:http:upload:0"; // XEP-0364: Current Off-the-Record Messaging Usage diff --git a/src/base/QXmppConstants_p.h b/src/base/QXmppConstants_p.h index c7811811..23b0fcdd 100644 --- a/src/base/QXmppConstants_p.h +++ b/src/base/QXmppConstants_p.h @@ -151,6 +151,8 @@ extern const char* ns_chat_markers; extern const char* ns_message_processing_hints; // XEP-0352: Client State Indication extern const char* ns_csi; +// XEP-0359: Unique and Stable Stanza IDs +extern const char* ns_sid; // XEP-0363: HTTP File Upload extern const char* ns_http_upload; // XEP-0364: Current Off-the-Record Messaging Usage diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp index e877e5c1..9084d957 100644 --- a/src/base/QXmppMessage.cpp +++ b/src/base/QXmppMessage.cpp @@ -141,6 +141,11 @@ public: // XEP-0334: Message Processing Hints quint8 hints; + // XEP-0359: Unique and Stable Stanza IDs + QString stanzaId; + QString stanzaIdBy; + QString originId; + // XEP-0367: Message Attaching QString attachId; @@ -607,6 +612,72 @@ void QXmppMessage::removeAllHints() d->hints = 0; } +/// +/// Returns the stanza ID of the message according to \xep{0359}: Unique and +/// Stable Stanza IDs. +/// +/// \since QXmpp 1.3 +/// +QString QXmppMessage::stanzaId() const +{ + return d->stanzaId; +} + +/// +/// Sets the stanza ID of the message according to \xep{0359}: Unique and +/// Stable Stanza IDs. +/// +/// \since QXmpp 1.3 +/// +void QXmppMessage::setStanzaId(const QString& id) +{ + d->stanzaId = id; +} + +/// +/// Returns the creator of the stanza ID according to \xep{0359}: Unique and +/// Stable Stanza IDs. +/// +/// \since QXmpp 1.3 +/// +QString QXmppMessage::stanzaIdBy() const +{ + return d->stanzaIdBy; +} + +/// +/// Sets the creator of the stanza ID according to \xep{0359}: Unique and +/// Stable Stanza IDs. +/// +/// \since QXmpp 1.3 +/// +void QXmppMessage::setStanzaIdBy(const QString &by) +{ + d->stanzaIdBy = by; +} + +/// +/// Returns the origin ID of the message according to \xep{0359}: Unique and +/// Stable Stanza IDs. +/// +/// \since QXmpp 1.3 +/// +QString QXmppMessage::originId() const +{ + return d->originId; +} + +/// +/// Sets the origin ID of the message according to \xep{0359}: Unique and +/// Stable Stanza IDs. +/// +/// \since QXmpp 1.3 +/// +void QXmppMessage::setOriginId(const QString &id) +{ + d->originId = id; +} + /// Returns the message id this message is linked/attached to. See XEP-0367: /// Message Attaching for details. /// @@ -997,6 +1068,23 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const } } + // XEP-0359: Unique and Stable Stanza IDs + if (!d->stanzaId.isNull()) { + xmlWriter->writeStartElement(QStringLiteral("stanza-id")); + xmlWriter->writeDefaultNamespace(ns_sid); + xmlWriter->writeAttribute(QStringLiteral("id"), d->stanzaId); + if (!d->stanzaIdBy.isNull()) + xmlWriter->writeAttribute(QStringLiteral("by"), d->stanzaIdBy); + xmlWriter->writeEndElement(); + } + + if (!d->originId.isNull()) { + xmlWriter->writeStartElement(QStringLiteral("origin-id")); + xmlWriter->writeDefaultNamespace(ns_sid); + xmlWriter->writeAttribute(QStringLiteral("id"), d->originId); + xmlWriter->writeEndElement(); + } + // XEP-0367: Message Attaching if (!d->attachId.isEmpty()) { xmlWriter->writeStartElement(QStringLiteral("attach-to")); @@ -1117,8 +1205,14 @@ void QXmppMessage::parseExtension(const QDomElement &element, QXmppElementList & } else if (element.namespaceURI() == ns_message_processing_hints && HINT_TYPES.contains(element.tagName())) { addHint(Hint(1 << HINT_TYPES.indexOf(element.tagName()))); - // XEP-0367: Message Attaching + } else if (checkElement(element, QStringLiteral("stanza-id"), ns_sid)) { + // XEP-0359: Unique and Stable Stanza IDs + d->stanzaId = element.attribute(QStringLiteral("id")); + d->stanzaIdBy = element.attribute(QStringLiteral("by")); + } else if (checkElement(element, QStringLiteral("origin-id"), ns_sid)) { + d->originId = element.attribute(QStringLiteral("id")); } else if (checkElement(element, QStringLiteral("attach-to"), ns_message_attaching)) { + // XEP-0367: Message Attaching d->attachId = element.attribute(QStringLiteral("id")); // XEP-0369: Mediated Information eXchange (MIX) } else if (checkElement(element, QStringLiteral("mix"), ns_mix)) { diff --git a/src/base/QXmppMessage.h b/src/base/QXmppMessage.h index cd24c25a..7b43a651 100644 --- a/src/base/QXmppMessage.h +++ b/src/base/QXmppMessage.h @@ -178,6 +178,16 @@ public: void removeHint(const Hint hint); void removeAllHints(); + // XEP-0359: Unique and Stable Stanza IDs + QString stanzaId() const; + void setStanzaId(const QString &id); + + QString stanzaIdBy() const; + void setStanzaIdBy(const QString &id); + + QString originId() const; + void setOriginId(const QString &id); + // XEP-0367: Message Attaching QString attachId() const; void setAttachId(const QString &); diff --git a/tests/qxmppmessage/tst_qxmppmessage.cpp b/tests/qxmppmessage/tst_qxmppmessage.cpp index 84e9f5fe..147b0c22 100644 --- a/tests/qxmppmessage/tst_qxmppmessage.cpp +++ b/tests/qxmppmessage/tst_qxmppmessage.cpp @@ -60,6 +60,7 @@ private slots: void testProcessingHints(); void testBobData(); void testFallbackIndication(); + void testStanzaIds(); }; void tst_QXmppMessage::testBasic_data() @@ -133,6 +134,9 @@ void tst_QXmppMessage::testBasic() QVERIFY(!message.hasHint(QXmppMessage::Store)); QCOMPARE(message.bitsOfBinaryData(), QXmppBitsOfBinaryDataList()); QVERIFY(!message.isFallback()); + QVERIFY(message.stanzaId().isNull()); + QVERIFY(message.stanzaIdBy().isNull()); + QVERIFY(message.originId().isNull()); message = QXmppMessage(); message.setTo(QStringLiteral("foo@example.com/QXmpp")); @@ -985,5 +989,27 @@ void tst_QXmppMessage::testFallbackIndication() serializePacket(message2, xml); } +void tst_QXmppMessage::testStanzaIds() +{ + const QByteArray xml = QByteArrayLiteral( + "<message type=\"chat\">" + "<stanza-id xmlns=\"urn:xmpp:sid:0\" id=\"1236\" by=\"server.tld\"/>" + "<origin-id xmlns=\"urn:xmpp:sid:0\" id=\"5678\"/>" + "</message>"); + + QXmppMessage msg; + parsePacket(msg, xml); + QCOMPARE(msg.stanzaId(), QStringLiteral("1236")); + QCOMPARE(msg.stanzaIdBy(), QStringLiteral("server.tld")); + QCOMPARE(msg.originId(), QStringLiteral("5678")); + serializePacket(msg, xml); + + QXmppMessage msg2; + msg2.setStanzaId(QStringLiteral("1236")); + msg2.setStanzaIdBy(QStringLiteral("server.tld")); + msg2.setOriginId(QStringLiteral("5678")); + serializePacket(msg2, xml); +} + QTEST_MAIN(tst_QXmppMessage) #include "tst_qxmppmessage.moc" |
