aboutsummaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorMelvin Keskin <melvo@olomono.de>2021-03-08 20:11:22 +0100
committerGitHub <noreply@github.com>2021-03-08 20:11:22 +0100
commit8efc8ea6aef64455bca04b11c3c4b0e20b532484 (patch)
tree8eced49da7e56f833cfb8534f4ead5261493e67f /src/base
parent9a1134a415cd550dcb6efd35bd1cf98b8faa236e (diff)
downloadqxmpp-8efc8ea6aef64455bca04b11c3c4b0e20b532484.tar.gz
Implement MIX-MISC XEP-0407: Invitation message extension (#329)
This implements the message extension for MIX invitations from XEP-0407: Mediated Information eXchange (MIX): Miscellaneous Capabilities in version 0.1.2. https://xmpp.org/extensions/xep-0407.html#usecase-user-invite
Diffstat (limited to 'src/base')
-rw-r--r--src/base/QXmppConstants.cpp2
-rw-r--r--src/base/QXmppConstants_p.h2
-rw-r--r--src/base/QXmppMessage.cpp40
-rw-r--r--src/base/QXmppMessage.h9
-rw-r--r--src/base/QXmppMixInvitation.cpp180
-rw-r--r--src/base/QXmppMixInvitation.h74
-rw-r--r--src/base/QXmppRosterIq.cpp1
7 files changed, 306 insertions, 2 deletions
diff --git a/src/base/QXmppConstants.cpp b/src/base/QXmppConstants.cpp
index 1508dccc..1df63f68 100644
--- a/src/base/QXmppConstants.cpp
+++ b/src/base/QXmppConstants.cpp
@@ -172,5 +172,7 @@ const char* ns_omemo = "eu.siacs.conversations.axolotl";
const char* ns_mix_pam = "urn:xmpp:mix:pam:1";
const char* ns_mix_roster = "urn:xmpp:mix:roster:0";
const char* ns_mix_presence = "urn:xmpp:presence:0";
+// XEP-0407: Mediated Information eXchange (MIX): Miscellaneous Capabilities
+const char* ns_mix_misc = "urn:xmpp:mix:misc:0";
// XEP-0428: Fallback Indication
const char* ns_fallback_indication = "urn:xmpp:fallback:0";
diff --git a/src/base/QXmppConstants_p.h b/src/base/QXmppConstants_p.h
index 9ece925c..3a95ce82 100644
--- a/src/base/QXmppConstants_p.h
+++ b/src/base/QXmppConstants_p.h
@@ -184,6 +184,8 @@ extern const char* ns_omemo;
extern const char* ns_mix_pam;
extern const char* ns_mix_roster;
extern const char* ns_mix_presence;
+// XEP-0407: Mediated Information eXchange (MIX): Miscellaneous Capabilities
+extern const char* ns_mix_misc;
// XEP-0428: Fallback Indication
extern const char* ns_fallback_indication;
diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp
index c859a49a..51b373af 100644
--- a/src/base/QXmppMessage.cpp
+++ b/src/base/QXmppMessage.cpp
@@ -27,8 +27,11 @@
#include "QXmppBitsOfBinaryDataList.h"
#include "QXmppConstants_p.h"
+#include "QXmppMixInvitation.h"
#include "QXmppUtils.h"
+#include <optional>
+
#include <QDateTime>
#include <QDomElement>
#include <QTextStream>
@@ -167,6 +170,9 @@ public:
bool isSpoiler;
QString spoilerHint;
+ // XEP-0407: Mediated Information eXchange (MIX): Miscellaneous Capabilities
+ std::optional<QXmppMixInvitation> mixInvitation;
+
// XEP-0428: Fallback Indication
bool isFallback;
};
@@ -1074,6 +1080,30 @@ void QXmppMessage::setSpoilerHint(const QString &spoilerHint)
}
///
+/// Returns an included \xep{0369}: Mediated Information eXchange (MIX)
+/// invitation as defined by \xep{0407}: Mediated Information eXchange (MIX):
+/// Miscellaneous Capabilities.
+///
+/// \since QXmpp 1.4
+///
+std::optional<QXmppMixInvitation> QXmppMessage::mixInvitation() const
+{
+ return d->mixInvitation;
+}
+
+///
+/// Sets a \xep{0369}: Mediated Information eXchange (MIX) invitation as defined
+/// by \xep{0407}: Mediated Information eXchange (MIX): Miscellaneous
+/// Capabilities.
+///
+/// \since QXmpp 1.4
+///
+void QXmppMessage::setMixInvitation(const std::optional<QXmppMixInvitation> &mixInvitation)
+{
+ d->mixInvitation = mixInvitation;
+}
+
+///
/// Sets whether this message is only a fallback according to \xep{0428}:
/// Fallback Indication.
///
@@ -1327,6 +1357,11 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const
xmlWriter->writeEndElement();
}
+ // XEP-0407: Mediated Information eXchange (MIX): Miscellaneous Capabilities
+ if (d->mixInvitation) {
+ d->mixInvitation->toXml(xmlWriter);
+ }
+
// XEP-0428: Fallback Indication
if (d->isFallback) {
xmlWriter->writeStartElement(QStringLiteral("fallback"));
@@ -1436,6 +1471,11 @@ void QXmppMessage::parseExtension(const QDomElement &element, QXmppElementList &
// XEP-0382: Spoiler messages
d->isSpoiler = true;
d->spoilerHint = element.text();
+ } else if (checkElement(element, QStringLiteral("invitation"), ns_mix_misc)) {
+ // XEP-0407: Mediated Information eXchange (MIX): Miscellaneous Capabilities
+ QXmppMixInvitation mixInvitation;
+ mixInvitation.parse(element);
+ d->mixInvitation = mixInvitation;
} else if (checkElement(element, QStringLiteral("fallback"), ns_fallback_indication)) {
// XEP-0428: Fallback Indication
d->isFallback = true;
diff --git a/src/base/QXmppMessage.h b/src/base/QXmppMessage.h
index 7d7ef83b..eb650370 100644
--- a/src/base/QXmppMessage.h
+++ b/src/base/QXmppMessage.h
@@ -26,13 +26,16 @@
#ifndef QXMPPMESSAGE_H
#define QXMPPMESSAGE_H
-// Required for source compatibility
#include "QXmppStanza.h"
+// Required for source compatibility
#include <QDateTime>
+#include <optional>
+
class QXmppMessagePrivate;
class QXmppBitsOfBinaryDataList;
+class QXmppMixInvitation;
///
/// \brief The QXmppMessage class represents an XMPP message.
@@ -243,6 +246,10 @@ public:
QString spoilerHint() const;
void setSpoilerHint(const QString &);
+ // XEP-0407: Mediated Information eXchange (MIX): Miscellaneous Capabilities
+ std::optional<QXmppMixInvitation> mixInvitation() const;
+ void setMixInvitation(const std::optional<QXmppMixInvitation> &mixInvitation);
+
// XEP-0428: Fallback Indication
bool isFallback() const;
void setIsFallback(bool isFallback);
diff --git a/src/base/QXmppMixInvitation.cpp b/src/base/QXmppMixInvitation.cpp
new file mode 100644
index 00000000..c9178a21
--- /dev/null
+++ b/src/base/QXmppMixInvitation.cpp
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2008-2021 The QXmpp developers
+ *
+ * Author:
+ * Melvin Keskin
+ *
+ * Source:
+ * https://github.com/qxmpp-project/qxmpp
+ *
+ * This file is a part of QXmpp library.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ */
+
+#include "QXmppMixInvitation.h"
+
+#include "QXmppConstants_p.h"
+#include "QXmppUtils.h"
+
+#include <QDomElement>
+#include <QSharedData>
+
+class QXmppMixInvitationPrivate : public QSharedData
+{
+public:
+ QString inviterJid;
+ QString inviteeJid;
+ QString channelJid;
+ QString token;
+};
+
+///
+/// Default constructor
+///
+QXmppMixInvitation::QXmppMixInvitation()
+ : d(new QXmppMixInvitationPrivate)
+{
+}
+
+///
+/// Copy constructor
+///
+QXmppMixInvitation::QXmppMixInvitation(const QXmppMixInvitation &other) = default;
+
+///
+/// Default assignment operator.
+///
+QXmppMixInvitation &QXmppMixInvitation::operator=(const QXmppMixInvitation &other) = default;
+
+///
+/// Destructor
+///
+QXmppMixInvitation::~QXmppMixInvitation() = default;
+
+///
+/// Returns the JID of the inviter.
+///
+/// \return the inviter's JID
+///
+QString QXmppMixInvitation::inviterJid() const
+{
+ return d->inviterJid;
+}
+
+///
+/// Sets the JID of the inviter.
+///
+/// \param inviterJid inviter's JID
+///
+void QXmppMixInvitation::setInviterJid(const QString &inviterJid)
+{
+ d->inviterJid = inviterJid;
+}
+
+///
+/// Returns the JID of the invitee.
+///
+/// \return the invitee's JID
+///
+QString QXmppMixInvitation::inviteeJid() const
+{
+ return d->inviteeJid;
+}
+
+///
+/// Sets the JID of the invitee.
+///
+/// \param inviteeJid invitee's JID
+///
+void QXmppMixInvitation::setInviteeJid(const QString &inviteeJid)
+{
+ d->inviteeJid = inviteeJid;
+}
+
+///
+/// Returns the JID of the channel.
+///
+/// \return the channel's JID
+///
+QString QXmppMixInvitation::channelJid() const
+{
+ return d->channelJid;
+}
+
+///
+/// Sets the JID of the channel.
+///
+/// \param channelJid channel JID
+///
+void QXmppMixInvitation::setChannelJid(const QString &channelJid)
+{
+ d->channelJid = channelJid;
+}
+
+///
+/// Returns the token which is generated by the server and used by the invitee
+/// for authentication.
+///
+/// \return the generated token used for authentication
+///
+QString QXmppMixInvitation::token() const
+{
+ return d->token;
+}
+
+///
+/// Sets the token which is generated by the server and used by the invitee for
+/// authentication.
+///
+/// \param token authentication token
+///
+void QXmppMixInvitation::setToken(const QString &token)
+{
+ d->token = token;
+}
+
+/// \cond
+void QXmppMixInvitation::parse(const QDomElement &element)
+{
+ d->inviterJid = element.firstChildElement(QStringLiteral("inviter")).text();
+ d->inviteeJid = element.firstChildElement(QStringLiteral("invitee")).text();
+ d->channelJid = element.firstChildElement(QStringLiteral("channel")).text();
+ d->token = element.firstChildElement(QStringLiteral("token")).text();
+}
+
+void QXmppMixInvitation::toXml(QXmlStreamWriter *writer) const
+{
+ writer->writeStartElement(QStringLiteral("invitation"));
+ writer->writeDefaultNamespace(ns_mix_misc);
+
+ helperToXmlAddTextElement(writer, QStringLiteral("inviter"), d->inviterJid);
+ helperToXmlAddTextElement(writer, QStringLiteral("invitee"), d->inviteeJid);
+ helperToXmlAddTextElement(writer, QStringLiteral("channel"), d->channelJid);
+ helperToXmlAddTextElement(writer, QStringLiteral("token"), d->token);
+
+ writer->writeEndElement();
+}
+/// \endcond
+
+///
+/// Determines whether the given DOM element is a MIX invitation.
+///
+/// \param element DOM element being checked
+///
+/// \return true if element is a MIX invitation, otherwise false
+///
+bool QXmppMixInvitation::isMixInvitation(const QDomElement &element)
+{
+ return element.tagName() == QStringLiteral("invitation") &&
+ element.namespaceURI() == ns_mix_misc;
+}
diff --git a/src/base/QXmppMixInvitation.h b/src/base/QXmppMixInvitation.h
new file mode 100644
index 00000000..72691265
--- /dev/null
+++ b/src/base/QXmppMixInvitation.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2008-2021 The QXmpp developers
+ *
+ * Author:
+ * Melvin Keskin
+ *
+ * Source:
+ * https://github.com/qxmpp-project/qxmpp
+ *
+ * This file is a part of QXmpp library.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ */
+
+#ifndef QXMPPMIXINVITATION_H
+#define QXMPPMIXINVITATION_H
+
+#include "QXmppElement.h"
+
+#include <QSharedDataPointer>
+
+class QXmppMixInvitationPrivate;
+
+///
+/// \brief The QXmppMixInvitation class is used to invite a user to a
+/// \xep{0369}: Mediated Information eXchange (MIX) channel as defined by
+/// \xep{0407}: Mediated Information eXchange (MIX): Miscellaneous Capabilities.
+///
+/// \ingroup Stanzas
+///
+/// \since QXmpp 1.4
+///
+class QXMPP_EXPORT QXmppMixInvitation
+{
+public:
+ QXmppMixInvitation();
+ QXmppMixInvitation(const QXmppMixInvitation &other);
+ ~QXmppMixInvitation();
+
+ QXmppMixInvitation &operator=(const QXmppMixInvitation &other);
+
+ QString inviterJid() const;
+ void setInviterJid(const QString &inviterJid);
+
+ QString inviteeJid() const;
+ void setInviteeJid(const QString &inviteeJid);
+
+ QString channelJid() const;
+ void setChannelJid(const QString &channelJid);
+
+ QString token() const;
+ void setToken(const QString &token);
+
+ /// \cond
+ void parse(const QDomElement &element);
+ void toXml(QXmlStreamWriter *writer) const;
+ /// \endcond
+
+ static bool isMixInvitation(const QDomElement &element);
+
+private:
+ QSharedDataPointer<QXmppMixInvitationPrivate> d;
+};
+
+#endif // QXMPPMIXINVITATION_H
diff --git a/src/base/QXmppRosterIq.cpp b/src/base/QXmppRosterIq.cpp
index 83e12422..6c4999c6 100644
--- a/src/base/QXmppRosterIq.cpp
+++ b/src/base/QXmppRosterIq.cpp
@@ -289,7 +289,6 @@ QXmppRosterIq::Item::subscriptionType() const
return d->type;
}
-
///
/// Sets the subscription type of the roster entry.
///