aboutsummaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorMelvin Keskin <melvo@olomono.de>2021-06-30 17:38:22 +0200
committerLinus Jahn <lnj@kaidan.im>2021-07-06 22:35:53 +0200
commit92427f63b3458fac76f64f2993db81d8c4c5d84c (patch)
tree4b8aefb1fe5df7610f539331866f825bdfdda8ba /src/base
parentcf1cc5326e1526dbee697ed45200a2c05bc98e01 (diff)
downloadqxmpp-92427f63b3458fac76f64f2993db81d8c4c5d84c.tar.gz
Add QXmppTrustMessageKeyOwner
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/QXmppTrustMessageKeyOwner.cpp178
-rw-r--r--src/base/QXmppTrustMessageKeyOwner.h66
4 files changed, 248 insertions, 0 deletions
diff --git a/src/base/QXmppConstants.cpp b/src/base/QXmppConstants.cpp
index 1df63f68..ff7a7de8 100644
--- a/src/base/QXmppConstants.cpp
+++ b/src/base/QXmppConstants.cpp
@@ -176,3 +176,5 @@ const char* ns_mix_presence = "urn:xmpp:presence:0";
const char* ns_mix_misc = "urn:xmpp:mix:misc:0";
// XEP-0428: Fallback Indication
const char* ns_fallback_indication = "urn:xmpp:fallback:0";
+// XEP-0434: Trust Messages (TM)
+const char* ns_tm = "urn:xmpp:tm:0";
diff --git a/src/base/QXmppConstants_p.h b/src/base/QXmppConstants_p.h
index 3a95ce82..cdef36ee 100644
--- a/src/base/QXmppConstants_p.h
+++ b/src/base/QXmppConstants_p.h
@@ -188,5 +188,7 @@ extern const char* ns_mix_presence;
extern const char* ns_mix_misc;
// XEP-0428: Fallback Indication
extern const char* ns_fallback_indication;
+// XEP-0434: Trust Messages (TM)
+extern const char* ns_tm;
#endif // QXMPPCONSTANTS_H
diff --git a/src/base/QXmppTrustMessageKeyOwner.cpp b/src/base/QXmppTrustMessageKeyOwner.cpp
new file mode 100644
index 00000000..d2633cde
--- /dev/null
+++ b/src/base/QXmppTrustMessageKeyOwner.cpp
@@ -0,0 +1,178 @@
+/*
+ * 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 "QXmppTrustMessageKeyOwner.h"
+
+#include "QXmppConstants_p.h"
+#include "QXmppUtils.h"
+
+#include <QDomElement>
+
+///
+/// \class QXmppTrustMessageKeyOwner
+///
+/// \brief The QXmppTrustMessageKeyOwner class represents a key owner of the
+/// trust message as defined by \xep{0434, Trust Messages (TM)}.
+///
+/// \since QXmpp 1.5
+///
+
+class QXmppTrustMessageKeyOwnerPrivate : public QSharedData
+{
+public:
+ QString jid;
+ QList<QString> trustedKeys;
+ QList<QString> distrustedKeys;
+};
+
+///
+/// Constructs a trust message key owner.
+///
+QXmppTrustMessageKeyOwner::QXmppTrustMessageKeyOwner()
+ : d(new QXmppTrustMessageKeyOwnerPrivate)
+{
+}
+
+///
+/// Constructs a copy of \a other.
+///
+/// \param other
+///
+QXmppTrustMessageKeyOwner::QXmppTrustMessageKeyOwner(const QXmppTrustMessageKeyOwner &other) = default;
+
+QXmppTrustMessageKeyOwner::~QXmppTrustMessageKeyOwner() = default;
+
+///
+/// Assigns \a other to this trust message key owner.
+///
+/// \param other
+///
+QXmppTrustMessageKeyOwner &QXmppTrustMessageKeyOwner::operator=(const QXmppTrustMessageKeyOwner &other) = default;
+
+///
+/// Returns the bare JID of the key owner.
+///
+/// \return the key owner's bare JID
+///
+QString QXmppTrustMessageKeyOwner::jid() const
+{
+ return d->jid;
+}
+
+///
+/// Sets the bare JID of the key owner.
+///
+/// If a full JID is passed, it is converted into a bare JID.
+///
+/// \param jid key owner's bare JID
+///
+void QXmppTrustMessageKeyOwner::setJid(const QString &jid)
+{
+ d->jid = QXmppUtils::jidToBareJid(jid);
+}
+
+///
+/// Returns the IDs of the keys that are trusted.
+///
+/// \return the IDs of trusted keys
+///
+QList<QString> QXmppTrustMessageKeyOwner::trustedKeys() const
+{
+ return d->trustedKeys;
+}
+
+///
+/// Sets the IDs of keys that are trusted.
+///
+/// \param keyIds IDs of trusted keys
+///
+void QXmppTrustMessageKeyOwner::setTrustedKeys(const QList<QString> &keyIds)
+{
+ d->trustedKeys = keyIds;
+}
+
+///
+/// Returns the IDs of the keys that are distrusted.
+///
+/// \return the IDs of distrusted keys
+///
+QList<QString> QXmppTrustMessageKeyOwner::distrustedKeys() const
+{
+ return d->distrustedKeys;
+}
+
+///
+/// Sets the IDs of keys that are distrusted.
+///
+/// \param keyIds IDs of distrusted keys
+///
+void QXmppTrustMessageKeyOwner::setDistrustedKeys(const QList<QString> &keyIds)
+{
+ d->distrustedKeys = keyIds;
+}
+
+/// \cond
+void QXmppTrustMessageKeyOwner::parse(const QDomElement &element)
+{
+ d->jid = element.attribute("jid");
+
+ for (auto childElement = element.firstChildElement();
+ !childElement.isNull();
+ childElement = childElement.nextSiblingElement()) {
+ if (childElement.tagName() == "trust") {
+ d->trustedKeys.append(childElement.text());
+ } else if (childElement.tagName() == "distrust") {
+ d->distrustedKeys.append(childElement.text());
+ }
+ }
+}
+
+void QXmppTrustMessageKeyOwner::toXml(QXmlStreamWriter *writer) const
+{
+ writer->writeStartElement("key-owner");
+ writer->writeAttribute("jid", d->jid);
+
+ for (const auto &keyIdentifier : d->trustedKeys) {
+ writer->writeTextElement("trust", keyIdentifier);
+ }
+
+ for (const auto &keyIdentifier : d->distrustedKeys) {
+ writer->writeTextElement("distrust", keyIdentifier);
+ }
+
+ writer->writeEndElement();
+}
+/// \endcond
+
+///
+/// Determines whether the given DOM element is a trust message key owner.
+///
+/// \param element DOM element being checked
+///
+/// \return true if element is a trust message key owner, otherwise false
+///
+bool QXmppTrustMessageKeyOwner::isTrustMessageKeyOwner(const QDomElement &element)
+{
+ return element.tagName() == QStringLiteral("key-owner") &&
+ element.namespaceURI() == ns_tm;
+}
diff --git a/src/base/QXmppTrustMessageKeyOwner.h b/src/base/QXmppTrustMessageKeyOwner.h
new file mode 100644
index 00000000..c4350a4b
--- /dev/null
+++ b/src/base/QXmppTrustMessageKeyOwner.h
@@ -0,0 +1,66 @@
+/*
+ * 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 QXMPPTRUSTMESSAGEKEYOWNER_H
+#define QXMPPTRUSTMESSAGEKEYOWNER_H
+
+#include "QXmppGlobal.h"
+
+#include <QDomElement>
+#include <QSharedDataPointer>
+#include <QXmlStreamWriter>
+
+class QXmppTrustMessageKeyOwnerPrivate;
+
+class QXMPP_EXPORT QXmppTrustMessageKeyOwner
+{
+public:
+ QXmppTrustMessageKeyOwner();
+ QXmppTrustMessageKeyOwner(const QXmppTrustMessageKeyOwner &other);
+ ~QXmppTrustMessageKeyOwner();
+
+ QXmppTrustMessageKeyOwner &operator=(const QXmppTrustMessageKeyOwner &other);
+
+ QString jid() const;
+ void setJid(const QString &jid);
+
+ QList<QString> trustedKeys() const;
+ void setTrustedKeys(const QList<QString> &keyIds);
+
+ QList<QString> distrustedKeys() const;
+ void setDistrustedKeys(const QList<QString> &keyIds);
+
+ /// \cond
+ void parse(const QDomElement &element);
+ void toXml(QXmlStreamWriter *writer) const;
+ /// \endcond
+
+ static bool isTrustMessageKeyOwner(const QDomElement &element);
+
+private:
+ QSharedDataPointer<QXmppTrustMessageKeyOwnerPrivate> d;
+};
+
+Q_DECLARE_TYPEINFO(QXmppTrustMessageKeyOwner, Q_MOVABLE_TYPE);
+
+#endif // QXMPPTRUSTMESSAGEKEYOWNER_H