aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelvin Keskin <melvo@olomono.de>2021-04-07 21:19:41 +0200
committerLinus Jahn <lnj@kaidan.im>2021-04-17 23:28:17 +0200
commitdb1b9a4c0b49efa170a50c3be3053e83db9566f0 (patch)
tree732967a5cb4777659d0f87cab799e38e9ce68712
parent518db4b0ef2da153edc7358c204bbd9c32f656c5 (diff)
downloadqxmpp-db1b9a4c0b49efa170a50c3be3053e83db9566f0.tar.gz
RegisterIq: Add out-of-band URL
-rw-r--r--src/base/QXmppRegisterIq.cpp40
-rw-r--r--src/base/QXmppRegisterIq.h3
-rw-r--r--tests/qxmppregisteriq/tst_qxmppregisteriq.cpp87
3 files changed, 129 insertions, 1 deletions
diff --git a/src/base/QXmppRegisterIq.cpp b/src/base/QXmppRegisterIq.cpp
index 27447f6d..18a92573 100644
--- a/src/base/QXmppRegisterIq.cpp
+++ b/src/base/QXmppRegisterIq.cpp
@@ -46,6 +46,7 @@ public:
bool isRegistered;
bool isRemove;
QXmppBitsOfBinaryDataList bitsOfBinaryData;
+ QString outOfBandUrl;
};
QXmppRegisterIqPrivate::QXmppRegisterIqPrivate()
@@ -259,6 +260,26 @@ void QXmppRegisterIq::setBitsOfBinaryData(const QXmppBitsOfBinaryDataList &bitsO
d->bitsOfBinaryData = bitsOfBinaryData;
}
+///
+/// Returns a \xep{0066, Out of Band Data} URL used for out-of-band registration.
+///
+/// \since QXmpp 1.5
+///
+QString QXmppRegisterIq::outOfBandUrl() const
+{
+ return d->outOfBandUrl;
+}
+
+///
+/// Sets a \xep{0066, Out of Band Data} URL used for out-of-band registration.
+///
+/// \since QXmpp 1.5
+///
+void QXmppRegisterIq::setOutOfBandUrl(const QString &outOfBandUrl)
+{
+ d->outOfBandUrl = outOfBandUrl;
+}
+
/// \cond
bool QXmppRegisterIq::isRegisterIq(const QDomElement &element)
{
@@ -272,7 +293,17 @@ void QXmppRegisterIq::parseElementFromChild(const QDomElement &element)
d->username = queryElement.firstChildElement(QStringLiteral("username")).text();
d->password = queryElement.firstChildElement(QStringLiteral("password")).text();
d->email = queryElement.firstChildElement(QStringLiteral("email")).text();
- d->form.parse(queryElement.firstChildElement(QStringLiteral("x")));
+
+ for (auto xElement = queryElement.firstChildElement(QStringLiteral("x"));
+ !xElement.isNull();
+ xElement = xElement.nextSiblingElement(QStringLiteral("x"))) {
+ if (xElement.namespaceURI() == ns_data) {
+ d->form.parse(xElement);
+ } else if (xElement.namespaceURI() == ns_oob) {
+ d->outOfBandUrl = xElement.firstChildElement(QStringLiteral("url")).text();
+ }
+ }
+
d->isRegistered = !queryElement.firstChildElement(ELEMENT_REGISTERED).isNull();
d->isRemove = !queryElement.firstChildElement(ELEMENT_REMOVE).isNull();
d->bitsOfBinaryData.parse(queryElement);
@@ -309,6 +340,13 @@ void QXmppRegisterIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
d->form.toXml(writer);
d->bitsOfBinaryData.toXml(writer);
+ if (!d->outOfBandUrl.isEmpty()) {
+ writer->writeStartElement(QStringLiteral("x"));
+ writer->writeDefaultNamespace(ns_oob);
+ writer->writeTextElement(QStringLiteral("url"), d->outOfBandUrl);
+ writer->writeEndElement();
+ }
+
writer->writeEndElement();
}
diff --git a/src/base/QXmppRegisterIq.h b/src/base/QXmppRegisterIq.h
index 2e82576d..58e73e08 100644
--- a/src/base/QXmppRegisterIq.h
+++ b/src/base/QXmppRegisterIq.h
@@ -75,6 +75,9 @@ public:
QXmppBitsOfBinaryDataList &bitsOfBinaryData();
void setBitsOfBinaryData(const QXmppBitsOfBinaryDataList &bitsOfBinaryData);
+ QString outOfBandUrl() const;
+ void setOutOfBandUrl(const QString &outOfBandUrl);
+
/// \cond
static bool isRegisterIq(const QDomElement &element);
/// \endcond
diff --git a/tests/qxmppregisteriq/tst_qxmppregisteriq.cpp b/tests/qxmppregisteriq/tst_qxmppregisteriq.cpp
index 7071ac2a..fc962d80 100644
--- a/tests/qxmppregisteriq/tst_qxmppregisteriq.cpp
+++ b/tests/qxmppregisteriq/tst_qxmppregisteriq.cpp
@@ -38,6 +38,8 @@ private slots:
void testGet();
void testResult();
void testResultWithForm();
+ void testResultWithRedirection();
+ void testResultWithFormAndRedirection();
void testSet();
void testSetWithForm();
void testBobData();
@@ -67,6 +69,7 @@ void tst_QXmppRegisterIq::testGet()
QVERIFY(iq.password().isNull());
QVERIFY(iq.email().isNull());
QVERIFY(iq.form().isNull());
+ QVERIFY(iq.outOfBandUrl().isNull());
serializePacket(iq, xml);
}
@@ -96,6 +99,7 @@ void tst_QXmppRegisterIq::testResult()
QVERIFY(!iq.email().isNull());
QVERIFY(iq.email().isEmpty());
QVERIFY(iq.form().isNull());
+ QVERIFY(iq.outOfBandUrl().isNull());
serializePacket(iq, xml);
}
@@ -143,6 +147,87 @@ void tst_QXmppRegisterIq::testResultWithForm()
QVERIFY(iq.email().isNull());
QVERIFY(!iq.form().isNull());
QCOMPARE(iq.form().title(), QLatin1String("Contest Registration"));
+ QVERIFY(iq.outOfBandUrl().isNull());
+ serializePacket(iq, xml);
+}
+
+void tst_QXmppRegisterIq::testResultWithRedirection()
+{
+ const QByteArray xml(
+ "<iq id=\"reg3\" type=\"result\">"
+ "<query xmlns=\"jabber:iq:register\">"
+ "<instructions>"
+ "To register, visit http://www.shakespeare.lit/contests.php"
+ "</instructions>"
+ "<x xmlns=\"jabber:x:oob\">"
+ "<url>http://www.shakespeare.lit/contests.php</url>"
+ "</x>"
+ "</query>"
+ "</iq>");
+
+ QXmppRegisterIq iq;
+ parsePacket(iq, xml);
+ QCOMPARE(iq.id(), QLatin1String("reg3"));
+ QCOMPARE(iq.to(), QString());
+ QCOMPARE(iq.from(), QString());
+ QCOMPARE(iq.type(), QXmppIq::Result);
+ QCOMPARE(iq.instructions(), QLatin1String("To register, visit http://www.shakespeare.lit/contests.php"));
+ QVERIFY(iq.username().isNull());
+ QVERIFY(iq.password().isNull());
+ QVERIFY(iq.email().isNull());
+ QVERIFY(iq.form().isNull());
+ QCOMPARE(iq.outOfBandUrl(), QLatin1String("http://www.shakespeare.lit/contests.php"));
+ serializePacket(iq, xml);
+}
+
+void tst_QXmppRegisterIq::testResultWithFormAndRedirection()
+{
+ const QByteArray xml(
+ "<iq id=\"reg3\" to=\"juliet@capulet.com/balcony\" from=\"contests.shakespeare.lit\" type=\"result\">"
+ "<query xmlns=\"jabber:iq:register\">"
+ "<instructions>Use the enclosed form to register. If your Jabber client does not support Data Forms, visit http://www.shakespeare.lit/contests.php</instructions>"
+ "<x xmlns=\"jabber:x:data\" type=\"form\">"
+ "<title>Contest Registration</title>"
+ "<instructions>"
+ "Please provide the following information"
+ "to sign up for our special contests!"
+ "</instructions>"
+ "<field type=\"hidden\" var=\"FORM_TYPE\">"
+ "<value>jabber:iq:register</value>"
+ "</field>"
+ "<field type=\"text-single\" label=\"Given Name\" var=\"first\">"
+ "<required/>"
+ "</field>"
+ "<field type=\"text-single\" label=\"Family Name\" var=\"last\">"
+ "<required/>"
+ "</field>"
+ "<field type=\"text-single\" label=\"Email Address\" var=\"email\">"
+ "<required/>"
+ "</field>"
+ "<field type=\"list-single\" label=\"Gender\" var=\"x-gender\">"
+ "<option label=\"Male\"><value>M</value></option>"
+ "<option label=\"Female\"><value>F</value></option>"
+ "</field>"
+ "</x>"
+ "<x xmlns=\"jabber:x:oob\">"
+ "<url>http://www.shakespeare.lit/contests.php</url>"
+ "</x>"
+ "</query>"
+ "</iq>");
+
+ QXmppRegisterIq iq;
+ parsePacket(iq, xml);
+ QCOMPARE(iq.id(), QLatin1String("reg3"));
+ QCOMPARE(iq.to(), QLatin1String("juliet@capulet.com/balcony"));
+ QCOMPARE(iq.from(), QLatin1String("contests.shakespeare.lit"));
+ QCOMPARE(iq.type(), QXmppIq::Result);
+ QCOMPARE(iq.instructions(), QLatin1String("Use the enclosed form to register. If your Jabber client does not support Data Forms, visit http://www.shakespeare.lit/contests.php"));
+ QVERIFY(iq.username().isNull());
+ QVERIFY(iq.password().isNull());
+ QVERIFY(iq.email().isNull());
+ QVERIFY(!iq.form().isNull());
+ QCOMPARE(iq.form().title(), QLatin1String("Contest Registration"));
+ QCOMPARE(iq.outOfBandUrl(), QLatin1String("http://www.shakespeare.lit/contests.php"));
serializePacket(iq, xml);
}
@@ -167,6 +252,7 @@ void tst_QXmppRegisterIq::testSet()
QCOMPARE(iq.password(), QLatin1String("Calliope"));
QCOMPARE(iq.email(), QLatin1String("bard@shakespeare.lit"));
QVERIFY(iq.form().isNull());
+ QVERIFY(iq.outOfBandUrl().isNull());
serializePacket(iq, xml);
}
@@ -205,6 +291,7 @@ void tst_QXmppRegisterIq::testSetWithForm()
QVERIFY(iq.password().isNull());
QVERIFY(iq.email().isNull());
QVERIFY(!iq.form().isNull());
+ QVERIFY(iq.outOfBandUrl().isNull());
serializePacket(iq, xml);
QXmppRegisterIq sIq;