aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2019-11-16 23:19:21 +0100
committerLNJ <lnj@kaidan.im>2019-12-06 22:26:12 +0100
commit0e06c636f90e5f2a8501816ddb36e22eca54f207 (patch)
tree6bf5a008582e0b1a7f78a60c7c604d0927fe7c86
parent46e148fb2d3396ca33bba1aa400e55651c7a9c61 (diff)
downloadqxmpp-0e06c636f90e5f2a8501816ddb36e22eca54f207.tar.gz
Implement XEP-0231: Bits of Binary: register IQ extension
This adds support for XEP-0231: Bits of Binary attachments in registration forms.
-rw-r--r--src/base/QXmppRegisterIq.cpp39
-rw-r--r--src/base/QXmppRegisterIq.h5
-rw-r--r--tests/qxmppregisteriq/tst_qxmppregisteriq.cpp99
3 files changed, 143 insertions, 0 deletions
diff --git a/src/base/QXmppRegisterIq.cpp b/src/base/QXmppRegisterIq.cpp
index 96ecb7f6..cee9fd7f 100644
--- a/src/base/QXmppRegisterIq.cpp
+++ b/src/base/QXmppRegisterIq.cpp
@@ -25,6 +25,7 @@
#include "QXmppConstants_p.h"
#include "QXmppRegisterIq.h"
+#include "QXmppBitsOfBinaryDataList.h"
class QXmppRegisterIqPrivate : public QSharedData
{
@@ -34,6 +35,7 @@ public:
QString instructions;
QString password;
QString username;
+ QXmppBitsOfBinaryDataList bitsOfBinaryData;
};
QXmppRegisterIq::QXmppRegisterIq()
@@ -119,6 +121,39 @@ void QXmppRegisterIq::setUsername(const QString &username)
d->username = username;
}
+/// Returns a list of data packages attached using XEP-0231: Bits of Binary.
+///
+/// This could be used to resolve a \c cid: URL of an CAPTCHA field of the
+/// form.
+///
+/// \since QXmpp 1.2
+
+QXmppBitsOfBinaryDataList QXmppRegisterIq::bitsOfBinaryData() const
+{
+ return d->bitsOfBinaryData;
+}
+
+/// Returns a list of data attached using XEP-0231: Bits of Binary.
+///
+/// This could be used to resolve a \c cid: URL of an CAPTCHA field of the
+/// form.
+///
+/// \since QXmpp 1.2
+
+QXmppBitsOfBinaryDataList &QXmppRegisterIq::bitsOfBinaryData()
+{
+ return d->bitsOfBinaryData;
+}
+
+/// Sets a list of XEP-0231: Bits of Binary attachments to be included.
+///
+/// \since QXmpp 1.2
+
+void QXmppRegisterIq::setBitsOfBinaryData(const QXmppBitsOfBinaryDataList &bitsOfBinaryData)
+{
+ d->bitsOfBinaryData = bitsOfBinaryData;
+}
+
/// \cond
bool QXmppRegisterIq::isRegisterIq(const QDomElement &element)
{
@@ -133,6 +168,7 @@ void QXmppRegisterIq::parseElementFromChild(const QDomElement &element)
d->password = queryElement.firstChildElement("password").text();
d->email = queryElement.firstChildElement("email").text();
d->form.parse(queryElement.firstChildElement("x"));
+ d->bitsOfBinaryData.parse(queryElement);
}
void QXmppRegisterIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
@@ -158,6 +194,9 @@ void QXmppRegisterIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
writer->writeEmptyElement("email");
d->form.toXml(writer);
+ d->bitsOfBinaryData.toXml(writer);
+
writer->writeEndElement();
}
+
/// \endcond
diff --git a/src/base/QXmppRegisterIq.h b/src/base/QXmppRegisterIq.h
index 5e443506..4292b485 100644
--- a/src/base/QXmppRegisterIq.h
+++ b/src/base/QXmppRegisterIq.h
@@ -28,6 +28,7 @@
#include "QXmppIq.h"
class QXmppRegisterIqPrivate;
+class QXmppBitsOfBinaryDataList;
/// \brief The QXmppRegisterIq class represents a registration IQ
/// as defined by XEP-0077: In-Band Registration.
@@ -60,6 +61,10 @@ public:
QString username() const;
void setUsername(const QString &username);
+ QXmppBitsOfBinaryDataList bitsOfBinaryData() const;
+ QXmppBitsOfBinaryDataList &bitsOfBinaryData();
+ void setBitsOfBinaryData(const QXmppBitsOfBinaryDataList &bitsOfBinaryData);
+
/// \cond
static bool isRegisterIq(const QDomElement &element);
/// \endcond
diff --git a/tests/qxmppregisteriq/tst_qxmppregisteriq.cpp b/tests/qxmppregisteriq/tst_qxmppregisteriq.cpp
index 9882b06b..fc3263fe 100644
--- a/tests/qxmppregisteriq/tst_qxmppregisteriq.cpp
+++ b/tests/qxmppregisteriq/tst_qxmppregisteriq.cpp
@@ -22,6 +22,10 @@
*/
#include <QObject>
+
+#include "QXmppBitsOfBinaryContentId.h"
+#include "QXmppBitsOfBinaryData.h"
+#include "QXmppBitsOfBinaryDataList.h"
#include "QXmppRegisterIq.h"
#include "util.h"
@@ -35,6 +39,7 @@ private slots:
void testResultWithForm();
void testSet();
void testSetWithForm();
+ void testBobData();
};
void tst_QXmppRegisterIq::testGet()
@@ -196,5 +201,99 @@ void tst_QXmppRegisterIq::testSetWithForm()
serializePacket(iq, xml);
}
+void tst_QXmppRegisterIq::testBobData()
+{
+ const QByteArray xml = QByteArrayLiteral(
+ "<iq type=\"result\">"
+ "<query xmlns=\"jabber:iq:register\">"
+ "<data xmlns=\"urn:xmpp:bob\" "
+ "cid=\"sha1+5a4c38d44fc64805cbb2d92d8b208be13ff40c0f@bob.xmpp.org\" "
+ "type=\"image/png\">"
+ "iVBORw0KGgoAAAANSUhEUgAAALQAAAA8BAMAAAA9AI20AAAAG1BMVEX///8AAADf39+"
+ "/v79/f39fX1+fn58/Pz8fHx/8ACGJAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADS0lEQV"
+ "RYhe2WS3MSQRCAYTf7OKY1kT0CxsRjHmh5BENIjqEk6pHVhFzdikqO7CGyP9t59Ox2z"
+ "y6UeWBVqugLzM70Nz39mqnV1lIWgBWiYXV0BYfNZ0mvwypds1r62vH/gf76ZL/88Qlc"
+ "41zeAnQrpx5H3z1Npfr5ovmHusa9SpRiNNIOcdrto6PJ5LLfb5bp9zM+VDq/vptxDEa"
+ "a1sql9I3R5KhtfQsA5gNCWYyulV3TyTUDdfL56BvdDl4x7RiybDq9uBgxh1TTPUHDvA"
+ "qNQb+LpT5sWehxJZKKcU2MZ6sDE7PMgW2mdlBGdy6ODe6fJFdMI+us95dNqftDMdwU6"
+ "+MhpuTS9slcy5TFAcwq0Jt6qssJMTQGp4BGURlmSsNoo5oHL4kqc66NdkDO75mIfCxm"
+ "RAlvHxMLdcb7JONavMJbttXXKoMSneYu3OQTlwkUh4mNayi6js55/2VcsZOQfXIYelz"
+ "xLcntEGc3WVCsCORJVCc5r0ajAcq+EO1Q0oPm7n7+X/3jEReGdL6qT7Ml6FCjY+quJC"
+ "r+D01f6BG0SaHG56ZG32DnY2jcEV1+pU0kxTaEwaGcekN7jyu50U/TV4q6YeieyiNTu"
+ "klDKZLukyjKVNwotCUB3B0XO1WjHT3c0DHSO2zACwut8GOiljJIHaJsrlof/fpWNzGM"
+ "os6TgIY0hZNpJshzSi4igOhy3cl4qK+YgnqHkAYcZEgdW6/HyrEK7afoY7RCFzArLl2"
+ "LLDdrdmmHZfROajwIDfWj8yQG+rzwlA3WvdJiMHtjUekiNrp1oCbmyZDEyKROGjFVDr"
+ "PRzlkR9UAfG/OErnPxrop5BwpoEpXQorq2zcGxbnBJndx8Bh0yljGiGv0B4E8+YP3Xp"
+ "2rGydZNy4csW8W2pIvWhvijoujRJ0luXsoymV+8AXvE9HjII72+oReS6OfomHe3xWg/"
+ "f2coSbDa1XZ1CvGMjy1nH9KBl83oPnQKi+vAXKLjCrRvvT2WCMkPmSFbquiVuTH1qjv"
+ "p4j/u7CWyI5/Hn3KAaJJ90eP0Zp1Kjets4WPaElkxheF7cpBESzXuIdLwyFjSub07tB"
+ "6JjxH3DGiu+zwHHimdtFsMvKqG/nBxm2TwbvyU6LWs5RnJX4dSldg3QhDLAAAAAElFT"
+ "kSuQmCC"
+ "</data>"
+ "</query>"
+ "</iq>"
+ );
+
+ QXmppBitsOfBinaryData data;
+ data.setCid(QXmppBitsOfBinaryContentId::fromContentId(
+ QStringLiteral("sha1+5a4c38d44fc64805cbb2d92d8b208be13ff40c0f@bob.xmpp.org")
+ ));
+ data.setContentType(QMimeDatabase().mimeTypeForName(QStringLiteral("image/png")));
+ data.setData(QByteArray::fromBase64(QByteArrayLiteral(
+ "iVBORw0KGgoAAAANSUhEUgAAALQAA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vE9HjII72+oReS6OfomHe3xWg/"
+ "f2coSbDa1XZ1CvGMjy1nH9KBl83oPnQKi+vAXKLjCrRvvT2WCMkPmSFbquiVuTH1qjv"
+ "p4j/u7CWyI5/Hn3KAaJJ90eP0Zp1Kjets4WPaElkxheF7cpBESzXuIdLwyFjSub07tB"
+ "6JjxH3DGiu+zwHHimdtFsMvKqG/nBxm2TwbvyU6LWs5RnJX4dSldg3QhDLAAAAAElFT"
+ "kSuQmCC"
+ )));
+
+ QXmppRegisterIq parsedIq;
+ parsePacket(parsedIq, xml);
+ QCOMPARE(parsedIq.type(), QXmppIq::Result);
+ QCOMPARE(parsedIq.id(), QStringLiteral(""));
+ QCOMPARE(parsedIq.bitsOfBinaryData().size(), 1);
+ QCOMPARE(parsedIq.bitsOfBinaryData().first().cid().algorithm(), data.cid().algorithm());
+ QCOMPARE(parsedIq.bitsOfBinaryData().first().cid().hash(), data.cid().hash());
+ QCOMPARE(parsedIq.bitsOfBinaryData().first().cid(), data.cid());
+ QCOMPARE(parsedIq.bitsOfBinaryData().first().contentType(), data.contentType());
+ QCOMPARE(parsedIq.bitsOfBinaryData().first().maxAge(), data.maxAge());
+ QCOMPARE(parsedIq.bitsOfBinaryData().first().data(), data.data());
+ QCOMPARE(parsedIq.bitsOfBinaryData().first(), data);
+ serializePacket(parsedIq, xml);
+
+ QXmppRegisterIq iq;
+ iq.setType(QXmppIq::Result);
+ iq.setId(QStringLiteral(""));
+ QXmppBitsOfBinaryDataList bobDataList;
+ bobDataList << data;
+ iq.setBitsOfBinaryData(bobDataList);
+ serializePacket(iq, xml);
+
+ QXmppRegisterIq iq2;
+ iq2.setType(QXmppIq::Result);
+ iq2.setId(QStringLiteral(""));
+ iq2.bitsOfBinaryData() << data;
+ serializePacket(iq2, xml);
+
+ // test const getter
+ const QXmppRegisterIq constIq = iq;
+ QCOMPARE(constIq.bitsOfBinaryData(), iq.bitsOfBinaryData());
+}
+
QTEST_MAIN(tst_QXmppRegisterIq)
#include "tst_qxmppregisteriq.moc"