diff options
| author | Linus Jahn <lnj@kaidan.im> | 2020-04-05 13:53:04 +0200 |
|---|---|---|
| committer | LNJ <lnj@kaidan.im> | 2020-04-05 16:31:44 +0200 |
| commit | f3aa893f5165feb3020b691434c7ce17119559fd (patch) | |
| tree | accedbb24846aa77af1e6cafa80082d7ded9ce61 | |
| parent | 420fddae862b0f67e7d8fe712006525c0239154e (diff) | |
| download | qxmpp-f3aa893f5165feb3020b691434c7ce17119559fd.tar.gz | |
Add pre-approved presence subscriptions stream feature
| -rw-r--r-- | src/base/QXmppConstants.cpp | 1 | ||||
| -rw-r--r-- | src/base/QXmppConstants_p.h | 1 | ||||
| -rw-r--r-- | src/base/QXmppStreamFeatures.cpp | 43 | ||||
| -rw-r--r-- | src/base/QXmppStreamFeatures.h | 3 | ||||
| -rw-r--r-- | tests/qxmppstreamfeatures/tst_qxmppstreamfeatures.cpp | 15 |
5 files changed, 62 insertions, 1 deletions
diff --git a/src/base/QXmppConstants.cpp b/src/base/QXmppConstants.cpp index 9cfd532c..a98a7ff0 100644 --- a/src/base/QXmppConstants.cpp +++ b/src/base/QXmppConstants.cpp @@ -32,6 +32,7 @@ const char* ns_sasl = "urn:ietf:params:xml:ns:xmpp-sasl"; const char* ns_bind = "urn:ietf:params:xml:ns:xmpp-bind"; const char* ns_session = "urn:ietf:params:xml:ns:xmpp-session"; const char* ns_stanza = "urn:ietf:params:xml:ns:xmpp-stanzas"; +const char* ns_pre_approval = "urn:xmpp:features:pre-approval"; // XEP-0009: Jabber-RPC const char* ns_rpc = "jabber:iq:rpc"; // XEP-0020: Feature Negotiation diff --git a/src/base/QXmppConstants_p.h b/src/base/QXmppConstants_p.h index 3cc2ca67..125e6d19 100644 --- a/src/base/QXmppConstants_p.h +++ b/src/base/QXmppConstants_p.h @@ -44,6 +44,7 @@ extern const char* ns_sasl; extern const char* ns_bind; extern const char* ns_session; extern const char* ns_stanza; +extern const char* ns_pre_approval; // XEP-0009: Jabber-RPC extern const char* ns_rpc; // XEP-0020: Feature Negotiation diff --git a/src/base/QXmppStreamFeatures.cpp b/src/base/QXmppStreamFeatures.cpp index a2ed180d..25626aa0 100644 --- a/src/base/QXmppStreamFeatures.cpp +++ b/src/base/QXmppStreamFeatures.cpp @@ -39,6 +39,7 @@ public: QXmppStreamFeatures::Mode streamManagementMode; QXmppStreamFeatures::Mode csiMode; QXmppStreamFeatures::Mode registerMode; + bool preApprovedSubscriptionsSupported; QStringList authMechanisms; QStringList compressionMethods; }; @@ -50,7 +51,8 @@ QXmppStreamFeaturesPrivate::QXmppStreamFeaturesPrivate() tlsMode(QXmppStreamFeatures::Disabled), streamManagementMode(QXmppStreamFeatures::Disabled), csiMode(QXmppStreamFeatures::Disabled), - registerMode(QXmppStreamFeatures::Disabled) + registerMode(QXmppStreamFeatures::Disabled), + preApprovedSubscriptionsSupported(false) { } @@ -184,6 +186,26 @@ void QXmppStreamFeatures::setRegisterMode(const QXmppStreamFeatures::Mode ®is d->registerMode = registerMode; } +/// +/// Returns whether usage of Pre-Approved roster subscriptions is supported. +/// +/// \since QXmpp 1.3 +/// +bool QXmppStreamFeatures::preApprovedSubscriptionsSupported() const +{ + return d->preApprovedSubscriptionsSupported; +} + +/// +/// Sets whether usage of Pre-Approved roster subscriptions is supported. +/// +/// \since QXmpp 1.3 +/// +void QXmppStreamFeatures::setPreApprovedSubscriptionsSupported(bool supported) +{ + d->preApprovedSubscriptionsSupported = supported; +} + /// \cond bool QXmppStreamFeatures::isStreamFeatures(const QDomElement &element) { @@ -207,6 +229,18 @@ static QXmppStreamFeatures::Mode readFeature(const QDomElement &element, const c return mode; } +static bool readBooleanFeature(const QDomElement &element, const QString &tagName, const QString &xmlns) +{ + auto childElement = element.firstChildElement(tagName); + while (!childElement.isNull()) { + if (childElement.namespaceURI() == xmlns) { + return true; + } + childElement = childElement.nextSiblingElement(tagName); + } + return false; +} + void QXmppStreamFeatures::parse(const QDomElement &element) { d->bindMode = readFeature(element, "bind", ns_bind); @@ -216,6 +250,7 @@ void QXmppStreamFeatures::parse(const QDomElement &element) d->streamManagementMode = readFeature(element, "sm", ns_stream_management); d->csiMode = readFeature(element, "csi", ns_csi); d->registerMode = readFeature(element, "register", ns_register_feature); + d->preApprovedSubscriptionsSupported = readBooleanFeature(element, QStringLiteral("sub"), ns_pre_approval); // parse advertised compression methods QDomElement compression = element.firstChildElement(QStringLiteral("compression")); @@ -260,6 +295,12 @@ void QXmppStreamFeatures::toXml(QXmlStreamWriter *writer) const writeFeature(writer, "csi", ns_csi, d->csiMode); writeFeature(writer, "register", ns_register_feature, d->registerMode); + if (d->preApprovedSubscriptionsSupported) { + writer->writeStartElement(QStringLiteral("sub")); + writer->writeDefaultNamespace(ns_pre_approval); + writer->writeEndElement(); + } + if (!d->compressionMethods.isEmpty()) { writer->writeStartElement(QStringLiteral("compression")); writer->writeDefaultNamespace(ns_compressFeature); diff --git a/src/base/QXmppStreamFeatures.h b/src/base/QXmppStreamFeatures.h index 6a56af49..ed439788 100644 --- a/src/base/QXmppStreamFeatures.h +++ b/src/base/QXmppStreamFeatures.h @@ -76,6 +76,9 @@ public: Mode registerMode() const; void setRegisterMode(const Mode ®isterMode); + bool preApprovedSubscriptionsSupported() const; + void setPreApprovedSubscriptionsSupported(bool); + /// \cond void parse(const QDomElement &element) override; void toXml(QXmlStreamWriter *writer) const override; diff --git a/tests/qxmppstreamfeatures/tst_qxmppstreamfeatures.cpp b/tests/qxmppstreamfeatures/tst_qxmppstreamfeatures.cpp index 028a20ef..72a0e31d 100644 --- a/tests/qxmppstreamfeatures/tst_qxmppstreamfeatures.cpp +++ b/tests/qxmppstreamfeatures/tst_qxmppstreamfeatures.cpp @@ -48,6 +48,7 @@ void tst_QXmppStreamFeatures::testEmpty() QCOMPARE(features.tlsMode(), QXmppStreamFeatures::Disabled); QCOMPARE(features.clientStateIndicationMode(), QXmppStreamFeatures::Disabled); QCOMPARE(features.registerMode(), QXmppStreamFeatures::Disabled); + QCOMPARE(features.preApprovedSubscriptionsSupported(), false); QCOMPARE(features.authMechanisms(), QStringList()); QCOMPARE(features.compressionMethods(), QStringList()); serializePacket(features, xml); @@ -77,6 +78,7 @@ void tst_QXmppStreamFeatures::testFull() "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>" "<csi xmlns=\"urn:xmpp:csi:0\"/>" "<register xmlns=\"http://jabber.org/features/iq-register\"/>" + "<sub xmlns=\"urn:xmpp:features:pre-approval\"/>" "<compression xmlns=\"http://jabber.org/features/compress\"><method>zlib</method></compression>" "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"><mechanism>PLAIN</mechanism></mechanisms>" "</stream:features>"); @@ -89,9 +91,22 @@ void tst_QXmppStreamFeatures::testFull() QCOMPARE(features.tlsMode(), QXmppStreamFeatures::Enabled); QCOMPARE(features.clientStateIndicationMode(), QXmppStreamFeatures::Enabled); QCOMPARE(features.registerMode(), QXmppStreamFeatures::Enabled); + QCOMPARE(features.preApprovedSubscriptionsSupported(), true); QCOMPARE(features.authMechanisms(), QStringList() << "PLAIN"); QCOMPARE(features.compressionMethods(), QStringList() << "zlib"); serializePacket(features, xml); + + features = QXmppStreamFeatures(); + features.setBindMode(QXmppStreamFeatures::Enabled); + features.setSessionMode(QXmppStreamFeatures::Enabled); + features.setNonSaslAuthMode(QXmppStreamFeatures::Enabled); + features.setTlsMode(QXmppStreamFeatures::Enabled); + features.setClientStateIndicationMode(QXmppStreamFeatures::Enabled); + features.setRegisterMode(QXmppStreamFeatures::Enabled); + features.setPreApprovedSubscriptionsSupported(true); + features.setAuthMechanisms(QStringList { QStringLiteral("PLAIN") }); + features.setCompressionMethods(QStringList { QStringLiteral("zlib") }); + serializePacket(features, xml); } void tst_QXmppStreamFeatures::testSetters() |
