diff options
| author | Linus Jahn <lnj@kaidan.im> | 2020-03-31 22:26:44 +0200 |
|---|---|---|
| committer | LNJ <lnj@kaidan.im> | 2020-04-04 23:39:10 +0200 |
| commit | 2197c188f21d563a192be711d13db7d0d1600681 (patch) | |
| tree | c47c515a5f7865d2647f993889de755d41a938b7 | |
| parent | 318f2a88a31c675dd7c4e2ffccbd28582bc2a0c3 (diff) | |
| download | qxmpp-2197c188f21d563a192be711d13db7d0d1600681.tar.gz | |
QXmppStanza::Error: Add 'by' attribute from RFC6120
This adds parsing and serialization and unit tests for the by attribute
for QXmppStanza::Errors. The protocol is defined in RFC6120.
| -rw-r--r-- | src/base/QXmppStanza.cpp | 29 | ||||
| -rw-r--r-- | src/base/QXmppStanza.h | 3 | ||||
| -rw-r--r-- | tests/qxmppstanza/tst_qxmppstanza.cpp | 42 |
3 files changed, 66 insertions, 8 deletions
diff --git a/src/base/QXmppStanza.cpp b/src/base/QXmppStanza.cpp index c4fae8de..2c2af1d5 100644 --- a/src/base/QXmppStanza.cpp +++ b/src/base/QXmppStanza.cpp @@ -165,6 +165,7 @@ public: QXmppStanza::Error::Type type; QXmppStanza::Error::Condition condition; QString text; + QString by; QString redirectionUri; // XEP-0363: HTTP File Upload @@ -284,6 +285,32 @@ QXmppStanza::Error::Type QXmppStanza::Error::type() const } /// +/// Returns the optional JID of the creator of the error. +/// +/// This is useful to ditinguish between errors generated by the local server +/// and by the remote server for example. However, the value is optional. +/// +/// \since QXmpp 1.3 +/// +QString QXmppStanza::Error::by() const +{ + return d->by; +} + +/// +/// Sets the optional JID of the creator of the error. +/// +/// This is useful to ditinguish between errors generated by the local server +/// and by the remote server for example. However, the value is optional. +/// +/// \since QXmpp 1.3 +/// +void QXmppStanza::Error::setBy(const QString &by) +{ + d->by = by; +} + +/// /// Sets the type of the error. /// void QXmppStanza::Error::setType(QXmppStanza::Error::Type type) @@ -424,6 +451,7 @@ void QXmppStanza::Error::parse(const QDomElement &errorElement) { setCode(errorElement.attribute(QStringLiteral("code")).toInt()); setTypeFromStr(errorElement.attribute(QStringLiteral("type"))); + setBy(errorElement.attribute(QStringLiteral("by"))); QDomElement element = errorElement.firstChildElement(); while (!element.isNull()) { @@ -469,6 +497,7 @@ void QXmppStanza::Error::toXml(QXmlStreamWriter *writer) const return; writer->writeStartElement(QStringLiteral("error")); + helperToXmlAddAttribute(writer, QStringLiteral("by"), d->by); helperToXmlAddAttribute(writer, QStringLiteral("type"), type); if (d->code > 0) diff --git a/src/base/QXmppStanza.h b/src/base/QXmppStanza.h index 9bbc9634..caf6d6df 100644 --- a/src/base/QXmppStanza.h +++ b/src/base/QXmppStanza.h @@ -168,6 +168,9 @@ public: void setType(Type type); Type type() const; + QString by() const; + void setBy(const QString &by); + QString redirectionUri() const; void setRedirectionUri(const QString &redirectionUri); diff --git a/tests/qxmppstanza/tst_qxmppstanza.cpp b/tests/qxmppstanza/tst_qxmppstanza.cpp index 45cc8997..1b5710bf 100644 --- a/tests/qxmppstanza/tst_qxmppstanza.cpp +++ b/tests/qxmppstanza/tst_qxmppstanza.cpp @@ -87,11 +87,19 @@ void tst_QXmppStanza::testErrorCases_data() QTest::addColumn<QXmppStanza::Error::Condition>("condition"); QTest::addColumn<QString>("text"); QTest::addColumn<QString>("redirectionUri"); + QTest::addColumn<QString>("by"); + +#define ROW(name, xml, type, condition, text, redirect, by) \ + QTest::newRow(QT_STRINGIFY(name)) \ + << QByteArrayLiteral(xml) \ + << QXmppStanza::Error::type \ + << QXmppStanza::Error::condition \ + << text \ + << redirect \ + << by -#define ROW(name, xml, type, condition, text, redirect) \ - QTest::newRow(QT_STRINGIFY(name)) << QByteArrayLiteral(xml) << QXmppStanza::Error::type << QXmppStanza::Error::condition << text << redirect #define BASIC(xml, type, condition) \ - ROW(condition, xml, type, condition, QString(), QString()) + ROW(condition, xml, type, condition, QString(), QString(), QString()) ROW( empty-text, @@ -101,10 +109,11 @@ void tst_QXmppStanza::testErrorCases_data() Modify, BadRequest, QString(), + QString(), QString()); ROW( redirection-uri-gone, - "<error type=\"cancel\">" + "<error by=\"example.net\" type=\"cancel\">" "<gone xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">" "xmpp:romeo@afterlife.example.net" "</gone>" @@ -112,7 +121,8 @@ void tst_QXmppStanza::testErrorCases_data() Cancel, Gone, QString(), - "xmpp:romeo@afterlife.example.net"); + "xmpp:romeo@afterlife.example.net", + "example.net"); ROW( redirection-uri-redirect, "<error type=\"cancel\">" @@ -123,7 +133,8 @@ void tst_QXmppStanza::testErrorCases_data() Cancel, Redirect, QString(), - "xmpp:rms@afterlife.example.net"); + "xmpp:rms@afterlife.example.net", + QString()); ROW( redirection-uri-empty, "<error type=\"cancel\">" @@ -132,17 +143,29 @@ void tst_QXmppStanza::testErrorCases_data() Cancel, Redirect, QString(), + QString(), QString()); ROW( policy-violation-text, - "<error type=\"modify\">" + "<error by=\"example.net\" type=\"modify\">" "<policy-violation xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>" "<text xml:lang=\"en\" xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">The used words are not allowed on this server.</text>" "</error>", Modify, PolicyViolation, "The used words are not allowed on this server.", - QString()); + QString(), + "example.net"); + ROW( + jid-malformed-with-by, + "<error by=\"muc.example.com\" type=\"modify\">" + "<jid-malformed xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>" + "</error>", + Modify, + JidMalformed, + QString(), + QString(), + "muc.example.com"); BASIC( "<error type=\"modify\">" @@ -282,6 +305,7 @@ void tst_QXmppStanza::testErrorCases() QFETCH(QXmppStanza::Error::Condition, condition); QFETCH(QString, text); QFETCH(QString, redirectionUri); + QFETCH(QString, by); // parsing QXmppStanza::Error error; @@ -290,6 +314,7 @@ void tst_QXmppStanza::testErrorCases() QCOMPARE(error.condition(), condition); QCOMPARE(error.text(), text); QCOMPARE(error.redirectionUri(), redirectionUri); + QCOMPARE(error.by(), by); // check parsed error results in the same xml serializePacket(error, xml); @@ -299,6 +324,7 @@ void tst_QXmppStanza::testErrorCases() error.setCondition(condition); error.setText(text); error.setRedirectionUri(redirectionUri); + error.setBy(by); serializePacket(error, xml); } |
