aboutsummaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2019-09-22 15:42:48 +0200
committerLNJ <lnj@kaidan.im>2020-01-13 16:50:04 +0100
commit411cf3b9c06ec6e0b9af1b57c3370dae4640d460 (patch)
treebcbcbce8d269a5f7a2524c03925fc11680b3c311 /src/base
parent81b590545c590840f99fa5a96460726cb16db88a (diff)
downloadqxmpp-411cf3b9c06ec6e0b9af1b57c3370dae4640d460.tar.gz
QXmppRegisterIq: Add registerType for registered/remove
Diffstat (limited to 'src/base')
-rw-r--r--src/base/QXmppRegisterIq.cpp47
-rw-r--r--src/base/QXmppRegisterIq.h12
2 files changed, 57 insertions, 2 deletions
diff --git a/src/base/QXmppRegisterIq.cpp b/src/base/QXmppRegisterIq.cpp
index 3bd9431a..9f1c35fd 100644
--- a/src/base/QXmppRegisterIq.cpp
+++ b/src/base/QXmppRegisterIq.cpp
@@ -3,6 +3,7 @@
*
* Author:
* Jeremy Lainé
+ * Linus Jahn
*
* Source:
* https://github.com/qxmpp-project/qxmpp
@@ -22,22 +23,37 @@
*/
#include <QDomElement>
+#include <QSharedData>
#include "QXmppConstants_p.h"
#include "QXmppRegisterIq.h"
#include "QXmppBitsOfBinaryDataList.h"
+static const QStringList REGISTER_TYPES = {
+ QString(),
+ QStringLiteral("registered"),
+ QStringLiteral("remove")
+};
+
class QXmppRegisterIqPrivate : public QSharedData
{
public:
+ QXmppRegisterIqPrivate();
+
QXmppDataForm form;
QString email;
QString instructions;
QString password;
QString username;
+ QXmppRegisterIq::RegisterType registerType;
QXmppBitsOfBinaryDataList bitsOfBinaryData;
};
+QXmppRegisterIqPrivate::QXmppRegisterIqPrivate()
+ : registerType(QXmppRegisterIq::None)
+{
+}
+
QXmppRegisterIq::QXmppRegisterIq()
: d(new QXmppRegisterIqPrivate)
{
@@ -47,7 +63,7 @@ QXmppRegisterIq::QXmppRegisterIq(const QXmppRegisterIq &other) = default;
QXmppRegisterIq::~QXmppRegisterIq() = default;
-QXmppRegisterIq &QXmppRegisterIq::operator=(const QXmppRegisterIq& other) = default;
+QXmppRegisterIq &QXmppRegisterIq::operator=(const QXmppRegisterIq &other) = default;
/// Returns the email for this registration IQ.
@@ -154,6 +170,20 @@ void QXmppRegisterIq::setBitsOfBinaryData(const QXmppBitsOfBinaryDataList &bitsO
d->bitsOfBinaryData = bitsOfBinaryData;
}
+/// Returns the type of the action or registration state.
+
+QXmppRegisterIq::RegisterType QXmppRegisterIq::registerType() const
+{
+ return d->registerType;
+}
+
+/// Sets the type of the action or registration state.
+
+void QXmppRegisterIq::setRegisterType(const QXmppRegisterIq::RegisterType &type)
+{
+ d->registerType = type;
+}
+
/// \cond
bool QXmppRegisterIq::isRegisterIq(const QDomElement &element)
{
@@ -169,15 +199,30 @@ void QXmppRegisterIq::parseElementFromChild(const QDomElement &element)
d->email = queryElement.firstChildElement("email").text();
d->form.parse(queryElement.firstChildElement("x"));
d->bitsOfBinaryData.parse(queryElement);
+
+ d->registerType = QXmppRegisterIq::None;
+
+ // The loop starts with the second element, because there cannot be an
+ // empty element for QXmppRegisterIq::None
+ for (int i = 1; i < REGISTER_TYPES.size(); i++) {
+ if (!queryElement.firstChildElement(REGISTER_TYPES.at(i)).isNull()) {
+ d->registerType = RegisterType(i);
+ break;
+ }
+ }
}
void QXmppRegisterIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
{
writer->writeStartElement("query");
writer->writeAttribute("xmlns", ns_register);
+
if (!d->instructions.isEmpty())
writer->writeTextElement("instructions", d->instructions);
+ if (d->registerType != QXmppRegisterIq::None)
+ writer->writeEmptyElement(REGISTER_TYPES.at(int(d->registerType)));
+
if (!d->username.isEmpty())
writer->writeTextElement("username", d->username);
else if (!d->username.isNull())
diff --git a/src/base/QXmppRegisterIq.h b/src/base/QXmppRegisterIq.h
index 91f0d873..52b4ffba 100644
--- a/src/base/QXmppRegisterIq.h
+++ b/src/base/QXmppRegisterIq.h
@@ -3,6 +3,7 @@
*
* Author:
* Jeremy Lainé
+ * Linus Jahn
*
* Source:
* https://github.com/qxmpp-project/qxmpp
@@ -27,8 +28,8 @@
#include "QXmppDataForm.h"
#include "QXmppIq.h"
-class QXmppRegisterIqPrivate;
class QXmppBitsOfBinaryDataList;
+class QXmppRegisterIqPrivate;
/// \brief The QXmppRegisterIq class represents a registration IQ
/// as defined by XEP-0077: In-Band Registration.
@@ -40,6 +41,12 @@ class QXmppBitsOfBinaryDataList;
class QXMPP_EXPORT QXmppRegisterIq : public QXmppIq
{
public:
+ enum RegisterType {
+ None, ///< No special register IQ.
+ Registered, ///< Used by the service to indicate that an account is already registered.
+ Remove ///< Used by the client to request account removal.
+ };
+
QXmppRegisterIq();
QXmppRegisterIq(const QXmppRegisterIq &other);
~QXmppRegisterIq();
@@ -61,6 +68,9 @@ public:
QString username() const;
void setUsername(const QString &username);
+ RegisterType registerType() const;
+ void setRegisterType(const RegisterType &registerType);
+
QXmppBitsOfBinaryDataList bitsOfBinaryData() const;
QXmppBitsOfBinaryDataList &bitsOfBinaryData();
void setBitsOfBinaryData(const QXmppBitsOfBinaryDataList &bitsOfBinaryData);