aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2019-01-03 22:48:07 +0100
committerJeremy Lainé <jeremy.laine@m4x.org>2019-01-20 15:03:40 +0100
commit95063b18660246efe91391d71dd08ec5ab69810d (patch)
tree6b5dce8294352fe459ca590cfb21751e45579f67
parent2a34abcd74d8d8369d81d9e4131d34185d9154a5 (diff)
downloadqxmpp-95063b18660246efe91391d71dd08ec5ab69810d.tar.gz
Implement XEP-0369/XEP-0405 (MIX): IQ queries
This implements all used IQ queries of XEP-0369: Mediated Information eXchange (MIX) (v0.14.1) and XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements (v0.3.1), including unit tests.
-rw-r--r--doc/xep.doc2
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/base/QXmppConstants.cpp12
-rw-r--r--src/base/QXmppConstants_p.h12
-rw-r--r--src/base/QXmppMixIq.cpp183
-rw-r--r--src/base/QXmppMixIq.h84
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/qxmppmixiq/tst_qxmppmixiq.cpp419
8 files changed, 715 insertions, 0 deletions
diff --git a/doc/xep.doc b/doc/xep.doc
index 1a5bd147..aecbac65 100644
--- a/doc/xep.doc
+++ b/doc/xep.doc
@@ -46,5 +46,7 @@ Ongoing:
- XEP-0009: Jabber-RPC (API is not finalized yet)
- XEP-0060: Publish-Subscribe (Only basic IQ implemented)
- XEP-0077: In-Band Registration (Only basic IQ implemented)
+- XEP-0369: Mediated Information eXchange (MIX) (Only IQ queries implemented) (v0.14.1)
+- XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements (Only IQ queries implemented) (v0.3.1)
*/
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 976f069e..2e48bffa 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -25,6 +25,7 @@ set(INSTALL_HEADER_FILES
base/QXmppLogger.h
base/QXmppMamIq.h
base/QXmppMessage.h
+ base/QXmppMixIq.h
base/QXmppMucIq.h
base/QXmppNonSASLAuth.h
base/QXmppPingIq.h
@@ -99,6 +100,7 @@ set(SOURCE_FILES
base/QXmppLogger.cpp
base/QXmppMamIq.cpp
base/QXmppMessage.cpp
+ base/QXmppMixIq.cpp
base/QXmppMucIq.cpp
base/QXmppNonSASLAuth.cpp
base/QXmppPingIq.cpp
diff --git a/src/base/QXmppConstants.cpp b/src/base/QXmppConstants.cpp
index 513476de..5cbc5024 100644
--- a/src/base/QXmppConstants.cpp
+++ b/src/base/QXmppConstants.cpp
@@ -132,3 +132,15 @@ const char* ns_idle = "urn:xmpp:idle:1";
const char* ns_chat_markers = "urn:xmpp:chat-markers:0";
// XEP-0352: Client State Indication
const char* ns_csi = "urn:xmpp:csi:0";
+// XEP-0369: Mediated Information eXchange (MIX)
+const char* ns_mix = "urn:xmpp:mix:core:0";
+const char* ns_mix_create_channel = "urn:xmpp:mix:core:0#create-channel";
+const char* ns_mix_searchable = "urn:xmpp:mix:core:0#searchable";
+const char* ns_mix_node_messages = "urn:xmpp:mix:nodes:messages";
+const char* ns_mix_node_participants = "urn:xmpp:mix:nodes:participants";
+const char* ns_mix_node_presence = "urn:xmpp:mix:nodes:presence";
+const char* ns_mix_node_config = "urn:xmpp:mix:nodes:config";
+const char* ns_mix_node_info = "urn:xmpp:mix:nodes:info";
+// XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
+const char* ns_mix_pam = "urn:xmpp:mix:pam:0";
+const char* ns_mix_roster = "urn:xmpp:mix:roster:0";
diff --git a/src/base/QXmppConstants_p.h b/src/base/QXmppConstants_p.h
index 1de6355d..5821a05a 100644
--- a/src/base/QXmppConstants_p.h
+++ b/src/base/QXmppConstants_p.h
@@ -144,5 +144,17 @@ extern const char* ns_idle;
extern const char* ns_chat_markers;
// XEP-0352: Client State Indication
extern const char* ns_csi;
+// XEP-0369: Mediated Information eXchange (MIX)
+extern const char* ns_mix;
+extern const char* ns_mix_create_channel;
+extern const char* ns_mix_searchable;
+extern const char* ns_mix_node_messages;
+extern const char* ns_mix_node_participants;
+extern const char* ns_mix_node_presence;
+extern const char* ns_mix_node_config;
+extern const char* ns_mix_node_info;
+// XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
+extern const char* ns_mix_pam;
+extern const char* ns_mix_roster;
#endif // QXMPPCONSTANTS_H
diff --git a/src/base/QXmppMixIq.cpp b/src/base/QXmppMixIq.cpp
new file mode 100644
index 00000000..a081ba9f
--- /dev/null
+++ b/src/base/QXmppMixIq.cpp
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2008-2019 The QXmpp developers
+ *
+ * Author:
+ * Linus Jahn <lnj@kaidan.im>
+ *
+ * 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 "QXmppMixIq.h"
+#include "QXmppDataForm.h"
+#include "QXmppConstants_p.h"
+#include "QXmppUtils.h"
+#include <QDomElement>
+
+static const QStringList MIX_ACTION_TYPES = QStringList() << ""
+ << "client-join" << "client-leave" << "join" << "leave"
+ << "update-subscription" << "setnick" << "create" << "destroy";
+
+/// Returns the channel JID. It also contains a participant id for Join/
+/// ClientJoin results.
+
+QString QXmppMixIq::jid() const
+{
+ return m_jid;
+}
+
+/// Sets the channel JID. For results of Join/ClientJoin queries this also
+/// needs to contain a participant id.
+
+void QXmppMixIq::setJid(const QString& jid)
+{
+ m_jid = jid;
+}
+
+/// Returns the channel name (the name part of the channel JID). This may still
+/// be empty, if a JID was set.
+
+QString QXmppMixIq::channelName() const
+{
+ return m_channelName;
+}
+
+/// Sets the channel name for creating/destroying specific channels. When you
+/// create a new channel, this can also be left empty to let the server
+/// generate a name.
+
+void QXmppMixIq::setChannelName(const QString& channelName)
+{
+ m_channelName = channelName;
+}
+
+/// Returns the list of nodes to subscribe to.
+
+QStringList QXmppMixIq::nodes() const
+{
+ return m_nodes;
+}
+
+/// Sets the nodes to subscribe to. Note that for UpdateSubscription queries
+/// you only need to include the new subscriptions.
+
+void QXmppMixIq::setNodes(const QStringList& nodes)
+{
+ m_nodes = nodes;
+}
+
+/// Returns the user's nickname in the channel.
+
+QString QXmppMixIq::nick() const
+{
+ return m_nick;
+}
+
+/// Sets the nickname for the channel.
+
+void QXmppMixIq::setNick(const QString& nick)
+{
+ m_nick = nick;
+}
+
+/// Returns the MIX channel action type.
+
+QXmppMixIq::Type QXmppMixIq::actionType() const
+{
+ return m_actionType;
+}
+
+/// Sets the channel action.
+
+void QXmppMixIq::setActionType(QXmppMixIq::Type type)
+{
+ m_actionType = type;
+}
+
+/// \cond
+bool QXmppMixIq::isMixIq(const QDomElement& element)
+{
+ const QDomElement& child = element.firstChildElement();
+ return !child.isNull() && (child.namespaceURI() == ns_mix
+ || child.namespaceURI() == ns_mix_pam);
+}
+
+void QXmppMixIq::parseElementFromChild(const QDomElement& element)
+{
+ QDomElement child = element.firstChildElement();
+ // determine action type
+ m_actionType = (QXmppMixIq::Type) MIX_ACTION_TYPES.indexOf(child.tagName());
+
+ if (child.namespaceURI() == ns_mix_pam) {
+ if (child.hasAttribute("channel"))
+ m_jid = child.attribute("channel");
+
+ child = child.firstChildElement();
+ }
+
+ if (!child.isNull() && child.namespaceURI() == ns_mix) {
+ if (child.hasAttribute("jid"))
+ m_jid = child.attribute("jid");
+ if (child.hasAttribute("channel"))
+ m_channelName = child.attribute("channel");
+
+ QDomElement subChild = child.firstChildElement();
+ while (!subChild.isNull()) {
+ if (subChild.tagName() == "subscribe")
+ m_nodes << subChild.attribute("node");
+ else if (subChild.tagName() == "nick")
+ m_nick = subChild.text();
+
+ subChild = subChild.nextSiblingElement();
+ }
+ }
+}
+
+void QXmppMixIq::toXmlElementFromChild(QXmlStreamWriter* writer) const
+{
+ if (m_actionType == None)
+ return;
+
+ writer->writeStartElement(MIX_ACTION_TYPES.at(m_actionType));
+ if (m_actionType == ClientJoin || m_actionType == ClientLeave) {
+ writer->writeAttribute("xmlns", ns_mix_pam);
+ if (type() == Set)
+ helperToXmlAddAttribute(writer, "channel", m_jid);
+
+ if (m_actionType == ClientJoin)
+ writer->writeStartElement("join");
+ else if (m_actionType == ClientLeave)
+ writer->writeStartElement("leave");
+ }
+
+ writer->writeAttribute("xmlns", ns_mix);
+ helperToXmlAddAttribute(writer, "channel", m_channelName);
+ if (type() == Result)
+ helperToXmlAddAttribute(writer, "jid", m_jid);
+
+ for (auto node : m_nodes) {
+ writer->writeStartElement("subscribe");
+ writer->writeAttribute("node", node);
+ writer->writeEndElement();
+ }
+ if (!m_nick.isEmpty())
+ writer->writeTextElement("nick", m_nick);
+
+ writer->writeEndElement();
+ if (m_actionType == ClientJoin || m_actionType == ClientLeave)
+ writer->writeEndElement();
+}
+/// \endcond
diff --git a/src/base/QXmppMixIq.h b/src/base/QXmppMixIq.h
new file mode 100644
index 00000000..d91fa29c
--- /dev/null
+++ b/src/base/QXmppMixIq.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2008-2019 The QXmpp developers
+ *
+ * Author:
+ * Linus Jahn <lnj@kaidan.im>
+ *
+ * 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 QXMPPMIXIQ_H
+#define QXMPPMIXIQ_H
+
+#include "QXmppIq.h"
+
+/// \brief The QXmppMixIq class represents an IQ used to do actions on a MIX
+/// channel as defined by XEP-0369: Mediated Information eXchange (MIX)
+/// (v0.14.1) and XEP-0405: Mediated Information eXchange (MIX): Participant
+/// Server Requirements (v0.3.1).
+///
+/// \ingroup Stanzas
+
+class QXMPP_EXPORT QXmppMixIq : public QXmppIq
+{
+public:
+ enum Type {
+ None,
+ ClientJoin,
+ ClientLeave,
+ Join,
+ Leave,
+ UpdateSubscription,
+ SetNick,
+ Create,
+ Destroy
+ };
+
+ QXmppMixIq::Type actionType() const;
+ void setActionType(QXmppMixIq::Type);
+
+ QString jid() const;
+ void setJid(const QString&);
+
+ QString channelName() const;
+ void setChannelName(const QString&);
+
+ QStringList nodes() const;
+ void setNodes(const QStringList&);
+
+ QString nick() const;
+ void setNick(const QString&);
+
+ /// \cond
+ static bool isMixIq(const QDomElement&);
+ /// \endcond
+
+protected:
+ /// \cond
+ void parseElementFromChild(const QDomElement&);
+ void toXmlElementFromChild(QXmlStreamWriter*) const;
+ /// \endcond
+
+private:
+ QString m_jid;
+ QString m_channelName;
+ QStringList m_nodes;
+ QString m_nick;
+ QXmppMixIq::Type m_actionType = QXmppMixIq::None;
+};
+
+#endif // QXMPPMIXIQ_H
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index df125219..223a198c 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -26,6 +26,7 @@ add_simple_test(qxmppiq)
add_simple_test(qxmppjingleiq)
add_simple_test(qxmppmammanager)
add_simple_test(qxmppmessage)
+add_simple_test(qxmppmixiq)
add_simple_test(qxmppnonsaslauthiq)
add_simple_test(qxmpppresence)
add_simple_test(qxmpppubsubiq)
diff --git a/tests/qxmppmixiq/tst_qxmppmixiq.cpp b/tests/qxmppmixiq/tst_qxmppmixiq.cpp
new file mode 100644
index 00000000..bbb484a2
--- /dev/null
+++ b/tests/qxmppmixiq/tst_qxmppmixiq.cpp
@@ -0,0 +1,419 @@
+/*
+ * Copyright (C) 2008-2019 The QXmpp developers
+ *
+ * Author:
+ * Linus Jahn <lnj@kaidan.im>
+ *
+ * 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 <QObject>
+
+#include "QXmppMixIq.h"
+#include "util.h"
+
+Q_DECLARE_METATYPE(QXmppIq::Type);
+Q_DECLARE_METATYPE(QXmppMixIq::Type);
+
+class tst_QXmppMixIq : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testBase_data();
+ void testBase();
+ void testDefaults();
+ void testSetters();
+ void testIsMixIq();
+};
+
+void tst_QXmppMixIq::testBase_data()
+{
+ QByteArray joinC2sSetXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example\" "
+ "from=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "type=\"set\">"
+ "<client-join xmlns=\"urn:xmpp:mix:pam:0\" channel=\"coven@mix.shakespeare.example\">"
+ "<join xmlns=\"urn:xmpp:mix:core:0\">"
+ "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:participants\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:info\"/>"
+ "<nick>third witch</nick>"
+ "</join>"
+ "</client-join>"
+ "</iq>"
+ );
+ QByteArray joinS2sSetXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"coven@mix.shakespeare.example\" "
+ "from=\"hag66@shakespeare.example\" "
+ "type=\"set\">"
+ "<join xmlns=\"urn:xmpp:mix:core:0\">"
+ "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:participants\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:info\"/>"
+ "<nick>stpeter</nick>"
+ "</join>"
+ "</iq>"
+ );
+ QByteArray joinS2sResultXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example\" "
+ "from=\"coven@mix.shakespeare.example\" "
+ "type=\"result\">"
+ "<join xmlns=\"urn:xmpp:mix:core:0\" jid=\"123456#coven@mix.shakespeare.example\">"
+ "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:participants\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:info\"/>"
+ "<nick>third witch</nick>"
+ "</join>"
+ "</iq>"
+ );
+ QByteArray joinC2sResultXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "from=\"hag66@shakespeare.example\" "
+ "type=\"result\">"
+ "<client-join xmlns=\"urn:xmpp:mix:pam:0\">"
+ "<join xmlns=\"urn:xmpp:mix:core:0\" "
+ "jid=\"123456#coven@mix.shakespeare.example\">"
+ "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:participants\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:info\"/>"
+ "</join>"
+ "</client-join>"
+ "</iq>"
+ );
+ QByteArray leaveC2sSetXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example\" "
+ "from=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "type=\"set\">"
+ "<client-leave xmlns=\"urn:xmpp:mix:pam:0\" channel=\"coven@mix.shakespeare.example\">"
+ "<leave xmlns=\"urn:xmpp:mix:core:0\"/>"
+ "</client-leave>"
+ "</iq>"
+ );
+ QByteArray leaveS2sSetXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"coven@mix.shakespeare.example\" "
+ "from=\"hag66@shakespeare.example\" "
+ "type=\"set\">"
+ "<leave xmlns=\"urn:xmpp:mix:core:0\"/>"
+ "</iq>"
+ );
+ QByteArray leaveS2sResultXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example\" "
+ "from=\"coven@mix.shakespeare.example\" "
+ "type=\"result\">"
+ "<leave xmlns=\"urn:xmpp:mix:core:0\"/>"
+ "</iq>"
+ );
+ QByteArray leaveC2sResultXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "from=\"hag66@shakespeare.example\" "
+ "type=\"result\">"
+ "<client-leave xmlns=\"urn:xmpp:mix:pam:0\">"
+ "<leave xmlns=\"urn:xmpp:mix:core:0\"/>"
+ "</client-leave>"
+ "</iq>"
+ );
+ QByteArray updateSubscriptionSetXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example\" "
+ "from=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "type=\"set\">"
+ "<update-subscription xmlns=\"urn:xmpp:mix:core:0\">"
+ "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
+ "</update-subscription>"
+ "</iq>"
+ );
+ QByteArray updateSubscriptionResultXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "from=\"hag66@shakespeare.example\" "
+ "type=\"result\">"
+ "<update-subscription xmlns=\"urn:xmpp:mix:core:0\" jid=\"hag66@shakespeare.example\">"
+ "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
+ "</update-subscription>"
+ "</iq>"
+ );
+ QByteArray setNickSetXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example\" "
+ "from=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "type=\"set\">"
+ "<setnick xmlns=\"urn:xmpp:mix:core:0\">"
+ "<nick>thirdwitch</nick>"
+ "</setnick>"
+ "</iq>"
+ );
+ QByteArray setNickResultXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "from=\"hag66@shakespeare.example\" "
+ "type=\"result\">"
+ "<setnick xmlns=\"urn:xmpp:mix:core:0\">"
+ "<nick>thirdwitch</nick>"
+ "</setnick>"
+ "</iq>"
+ );
+ QByteArray createXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example\" "
+ "from=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "type=\"set\">"
+ "<create xmlns=\"urn:xmpp:mix:core:0\" channel=\"coven\"/>"
+ "</iq>"
+ );
+ QByteArray createWithoutNameXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example\" "
+ "from=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "type=\"set\">"
+ "<create xmlns=\"urn:xmpp:mix:core:0\"/>"
+ "</iq>"
+ );
+ QByteArray destroyXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example\" "
+ "from=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "type=\"set\">"
+ "<destroy xmlns=\"urn:xmpp:mix:core:0\" channel=\"coven\"/>"
+ "</iq>"
+ );
+ QByteArray emptyXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example\" "
+ "from=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "type=\"set\"/>"
+ );
+
+ QStringList emptyNodes;
+ QStringList defaultNodes;
+ defaultNodes << "urn:xmpp:mix:nodes:messages" << "urn:xmpp:mix:nodes:presence"
+ << "urn:xmpp:mix:nodes:participants" << "urn:xmpp:mix:nodes:info";
+
+ QTest::addColumn<QByteArray>("xml");
+ QTest::addColumn<QXmppIq::Type>("type");
+ QTest::addColumn<QXmppMixIq::Type>("actionType");
+ QTest::addColumn<QString>("jid");
+ QTest::addColumn<QString>("channelName");
+ QTest::addColumn<QStringList>("nodes");
+ QTest::addColumn<QString>("nick");
+
+ QTest::newRow("join-c2s-set")
+ << joinC2sSetXml
+ << QXmppIq::Set
+ << QXmppMixIq::ClientJoin
+ << "coven@mix.shakespeare.example"
+ << ""
+ << defaultNodes
+ << "third witch";
+ QTest::newRow("join-s2s-set")
+ << joinS2sSetXml
+ << QXmppIq::Set
+ << QXmppMixIq::Join
+ << ""
+ << ""
+ << defaultNodes
+ << "stpeter";
+ QTest::newRow("join-s2s-result")
+ << joinS2sResultXml
+ << QXmppIq::Result
+ << QXmppMixIq::Join
+ << "123456#coven@mix.shakespeare.example"
+ << ""
+ << defaultNodes
+ << "third witch";
+ QTest::newRow("join-c2s-result")
+ << joinC2sResultXml
+ << QXmppIq::Result
+ << QXmppMixIq::ClientJoin
+ << "123456#coven@mix.shakespeare.example"
+ << ""
+ << defaultNodes
+ << "";
+ QTest::newRow("leave-c2s-set")
+ << leaveC2sSetXml
+ << QXmppIq::Set
+ << QXmppMixIq::ClientLeave
+ << "coven@mix.shakespeare.example"
+ << "" << emptyNodes << "";
+ QTest::newRow("leave-s2s-set")
+ << leaveS2sSetXml
+ << QXmppIq::Set
+ << QXmppMixIq::Leave
+ << "" << "" << emptyNodes << "";
+ QTest::newRow("leave-s2s-result")
+ << leaveS2sResultXml
+ << QXmppIq::Result
+ << QXmppMixIq::Leave
+ << "" << "" << emptyNodes << "";
+ QTest::newRow("leave-c2s-result")
+ << leaveC2sResultXml
+ << QXmppIq::Result
+ << QXmppMixIq::ClientLeave
+ << "" << "" << emptyNodes << "";
+ QTest::newRow("update-subscription-set")
+ << updateSubscriptionSetXml
+ << QXmppIq::Set
+ << QXmppMixIq::UpdateSubscription
+ << ""
+ << ""
+ << (QStringList() << "urn:xmpp:mix:nodes:messages")
+ << "";
+ QTest::newRow("update-subscription-result")
+ << updateSubscriptionResultXml
+ << QXmppIq::Result
+ << QXmppMixIq::UpdateSubscription
+ << "hag66@shakespeare.example"
+ << ""
+ << (QStringList() << "urn:xmpp:mix:nodes:messages")
+ << "";
+ QTest::newRow("setnick-set")
+ << setNickSetXml
+ << QXmppIq::Set
+ << QXmppMixIq::SetNick
+ << "" << "" << emptyNodes
+ << "thirdwitch";
+ QTest::newRow("setnick-result")
+ << setNickResultXml
+ << QXmppIq::Result
+ << QXmppMixIq::SetNick
+ << "" << "" << emptyNodes
+ << "thirdwitch";
+ QTest::newRow("create")
+ << createXml
+ << QXmppIq::Set
+ << QXmppMixIq::Create
+ << "" << "coven" << emptyNodes << "";
+ QTest::newRow("create-without-name")
+ << createWithoutNameXml
+ << QXmppIq::Set
+ << QXmppMixIq::Create
+ << "" << "" << emptyNodes << "";
+ QTest::newRow("destroy")
+ << destroyXml
+ << QXmppIq::Set
+ << QXmppMixIq::Destroy
+ << "" << "coven" << emptyNodes << "";
+ QTest::newRow("empty")
+ << emptyXml
+ << QXmppIq::Set
+ << QXmppMixIq::None
+ << "" << "" << emptyNodes << "";
+}
+
+void tst_QXmppMixIq::testBase()
+{
+ QFETCH(QByteArray, xml);
+ QFETCH(QXmppIq::Type, type);
+ QFETCH(QXmppMixIq::Type, actionType);
+ QFETCH(QString, jid);
+ QFETCH(QString, channelName);
+ QFETCH(QStringList, nodes);
+ QFETCH(QString, nick);
+
+ QXmppMixIq iq;
+ parsePacket(iq, xml);
+ QCOMPARE(iq.type(), type);
+ QCOMPARE(iq.actionType(), actionType);
+ QCOMPARE(iq.jid(), jid);
+ QCOMPARE(iq.channelName(), channelName);
+ QCOMPARE(iq.nodes(), nodes);
+ QCOMPARE(iq.nick(), nick);
+ serializePacket(iq, xml);
+}
+
+void tst_QXmppMixIq::testDefaults()
+{
+ QXmppMixIq iq;
+ QCOMPARE(iq.actionType(), QXmppMixIq::None);
+ QCOMPARE(iq.jid(), QString());
+ QCOMPARE(iq.channelName(), QString());
+ QCOMPARE(iq.nodes(), QStringList());
+ QCOMPARE(iq.nick(), QString());
+}
+
+void tst_QXmppMixIq::testSetters()
+{
+ QXmppMixIq iq;
+ iq.setActionType(QXmppMixIq::Join);
+ QCOMPARE(iq.actionType(), QXmppMixIq::Join);
+ iq.setJid("interestingnews@mix.example.com");
+ QCOMPARE(iq.jid(), QString("interestingnews@mix.example.com"));
+ iq.setChannelName("interestingnews");
+ QCOMPARE(iq.channelName(), QString("interestingnews"));
+ iq.setNodes(QStringList() << "com:example:mix:node:custom");
+ QCOMPARE(iq.nodes(), QStringList() << "com:example:mix:node:custom");
+ iq.setNick("SMUDO");
+ QCOMPARE(iq.nick(), QString("SMUDO"));
+}
+
+void tst_QXmppMixIq::testIsMixIq()
+{
+ const QByteArray trueXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example\" "
+ "from=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "type=\"set\">"
+ "<destroy xmlns=\"urn:xmpp:mix:core:0\" channel=\"coven\"/>"
+ "</iq>"
+ );
+ const QByteArray truePamXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example\" "
+ "from=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "type=\"set\">"
+ "<client-leave xmlns=\"urn:xmpp:mix:pam:0\" channel=\"coven@mix.shakespeare.example\">"
+ "<leave xmlns=\"urn:xmpp:mix:core:0\"/>"
+ "</client-leave>"
+ "</iq>"
+ );
+ const QByteArray falseXml(
+ "<iq id=\"E6E10350-76CF-40C6-B91B-1EA08C332FC7\" "
+ "to=\"hag66@shakespeare.example\" "
+ "from=\"hag66@shakespeare.example/UUID-a1j/7533\" "
+ "type=\"set\">"
+ "<destroy xmlns=\"something:else\" channel=\"coven\"/>"
+ "</iq>"
+ );
+
+ QDomDocument doc;
+ doc.setContent(trueXml, true);
+ QDomElement trueElement = doc.documentElement();
+ QVERIFY(QXmppMixIq::isMixIq(trueElement));
+
+ doc.setContent(truePamXml, true);
+ QDomElement truePamElement = doc.documentElement();
+ QVERIFY(QXmppMixIq::isMixIq(truePamElement));
+
+ doc.setContent(falseXml, true);
+ QDomElement falseElement = doc.documentElement();
+ QVERIFY(!QXmppMixIq::isMixIq(falseElement));
+}
+
+QTEST_MAIN(tst_QXmppMixIq)
+#include "tst_qxmppmixiq.moc"