aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2012-09-12 13:54:12 +0200
committerJeremy Lainé <jeremy.laine@m4x.org>2012-09-12 13:54:12 +0200
commit80f977677d9cc579ad957a91e8f4931176526d80 (patch)
tree2873ddeb3e8c3b9439fac5a1a4fe4945b7f13608
parent8c743b33c7baccd4910b68acdee6d2b8dccd6642 (diff)
downloadqxmpp-80f977677d9cc579ad957a91e8f4931176526d80.tar.gz
explicitly parse XEP-0249: Direct MUC Invitations message attributes
-rw-r--r--CHANGELOG1
-rw-r--r--src/base/QXmppMessage.cpp70
-rw-r--r--src/base/QXmppMessage.h9
-rw-r--r--src/client/QXmppMucManager.cpp15
-rw-r--r--tests/message.cpp15
-rw-r--r--tests/message.h1
6 files changed, 101 insertions, 10 deletions
diff --git a/CHANGELOG b/CHANGELOG
index c9c0f170..f2687792 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,7 @@ QXmpp 0.7.4 (UNRELEASED)
------------------------
- Move server statistics to a counter / gauge system.
+ - Add XEP-0249: Direct MUC Invitations attributes to QXmppMessage.
QXmpp 0.7.3 (Sep 7, 2012)
------------------------
diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp
index 8c692605..4952fb54 100644
--- a/src/base/QXmppMessage.cpp
+++ b/src/base/QXmppMessage.cpp
@@ -74,6 +74,11 @@ public:
// Request message receipt as per XEP-0184.
QString receiptId;
bool receiptRequested;
+
+ // XEP-0249: Direct MUC Invitations
+ QString mucInvitationJid;
+ QString mucInvitationPassword;
+ QString mucInvitationReason;
};
/// Constructs a QXmppMessage.
@@ -190,6 +195,54 @@ void QXmppMessage::setReceiptId(const QString &id)
d->receiptId = id;
}
+/// Returns the JID for a multi-user chat direct invitation as defined
+/// by XEP-0249: Direct MUC Invitations.
+
+QString QXmppMessage::mucInvitationJid() const
+{
+ return d->mucInvitationJid;
+}
+
+/// Sets the JID for a multi-user chat direct invitation as defined
+/// by XEP-0249: Direct MUC Invitations.
+
+void QXmppMessage::setMucInvitationJid(const QString &jid)
+{
+ d->mucInvitationJid = jid;
+}
+
+/// Returns the password for a multi-user chat direct invitation as defined
+/// by XEP-0249: Direct MUC Invitations.
+
+QString QXmppMessage::mucInvitationPassword() const
+{
+ return d->mucInvitationPassword;
+}
+
+/// Sets the \a password for a multi-user chat direct invitation as defined
+/// by XEP-0249: Direct MUC Invitations.
+
+void QXmppMessage::setMucInvitationPassword(const QString &password)
+{
+ d->mucInvitationPassword = password;
+}
+
+/// Returns the reason for a multi-user chat direct invitation as defined
+/// by XEP-0249: Direct MUC Invitations.
+
+QString QXmppMessage::mucInvitationReason() const
+{
+ return d->mucInvitationReason;
+}
+
+/// Sets the \a reason for a multi-user chat direct invitation as defined
+/// by XEP-0249: Direct MUC Invitations.
+
+void QXmppMessage::setMucInvitationReason(const QString &reason)
+{
+ d->mucInvitationReason = reason;
+}
+
/// Returns the message's type.
///
@@ -370,6 +423,11 @@ void QXmppMessage::parse(const QDomElement &element)
d->stamp = QDateTime::fromString(str, "yyyyMMddThh:mm:ss");
d->stamp.setTimeSpec(Qt::UTC);
d->stampType = LegacyDelayedDelivery;
+ } else if (xElement.namespaceURI() == ns_conference) {
+ // XEP-0249: Direct MUC Invitations
+ d->mucInvitationJid = xElement.attribute("jid");
+ d->mucInvitationPassword = xElement.attribute("password");
+ d->mucInvitationReason = xElement.attribute("reason");
} else {
// other extensions
extensions << QXmppElement(xElement);
@@ -455,6 +513,18 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const
xmlWriter->writeEndElement();
}
+ // XEP-0249: Direct MUC Invitations
+ if (!d->mucInvitationJid.isEmpty()) {
+ xmlWriter->writeStartElement("x");
+ xmlWriter->writeAttribute("xmlns", ns_conference);
+ xmlWriter->writeAttribute("jid", d->mucInvitationJid);
+ if (!d->mucInvitationPassword.isEmpty())
+ xmlWriter->writeAttribute("password", d->mucInvitationPassword);
+ if (!d->mucInvitationReason.isEmpty())
+ xmlWriter->writeAttribute("reason", d->mucInvitationReason);
+ xmlWriter->writeEndElement();
+ }
+
// other extensions
QXmppStanza::extensionsToXml(xmlWriter);
diff --git a/src/base/QXmppMessage.h b/src/base/QXmppMessage.h
index c0ac487a..e864a20f 100644
--- a/src/base/QXmppMessage.h
+++ b/src/base/QXmppMessage.h
@@ -76,6 +76,15 @@ public:
bool isReceiptRequested() const;
void setReceiptRequested(bool requested);
+ QString mucInvitationJid() const;
+ void setMucInvitationJid(const QString &jid);
+
+ QString mucInvitationPassword() const;
+ void setMucInvitationPassword(const QString &password);
+
+ QString mucInvitationReason() const;
+ void setMucInvitationReason(const QString &reason);
+
QString receiptId() const;
void setReceiptId(const QString &id);
diff --git a/src/client/QXmppMucManager.cpp b/src/client/QXmppMucManager.cpp
index e1fbed0e..7669a834 100644
--- a/src/client/QXmppMucManager.cpp
+++ b/src/client/QXmppMucManager.cpp
@@ -162,15 +162,9 @@ void QXmppMucManager::_q_messageReceived(const QXmppMessage &msg)
return;
// process room invitations
- foreach (const QXmppElement &extension, msg.extensions())
- {
- if (extension.tagName() == "x" && extension.attribute("xmlns") == ns_conference)
- {
- const QString roomJid = extension.attribute("jid");
- if (!roomJid.isEmpty() && (!d->rooms.contains(roomJid) || !d->rooms.value(roomJid)->isJoined()))
- emit invitationReceived(roomJid, msg.from(), extension.attribute("reason"));
- break;
- }
+ const QString roomJid = msg.mucInvitationJid();
+ if (!roomJid.isEmpty() && (!d->rooms.contains(roomJid) || !d->rooms.value(roomJid)->isJoined())) {
+ emit invitationReceived(roomJid, msg.from(), msg.mucInvitationReason());
}
}
@@ -373,7 +367,8 @@ bool QXmppMucRoom::sendInvitation(const QString &jid, const QString &reason)
QXmppMessage message;
message.setTo(jid);
message.setType(QXmppMessage::Normal);
- message.setExtensions(QXmppElementList() << x);
+ message.setMucInvitationJid(jid);
+ message.setMucInvitationReason(reason);
return d->client->sendPacket(message);
}
diff --git a/tests/message.cpp b/tests/message.cpp
index 1cf9a5bb..b7198a82 100644
--- a/tests/message.cpp
+++ b/tests/message.cpp
@@ -218,6 +218,21 @@ void tst_QXmppMessage::testExtendedAddresses()
serializePacket(message, xml);
}
+void tst_QXmppMessage::testMucInvitation()
+{
+ QByteArray xml(
+ "<message to=\"hecate@shakespeare.lit\" from=\"crone1@shakespeare.lit/desktop\" type=\"normal\">"
+ "<x xmlns=\"jabber:x:conference\" jid=\"darkcave@macbeth.shakespeare.lit\" password=\"cauldronburn\" reason=\"Hey Hecate, this is the place for all good witches!\"/>"
+ "</message>");
+
+ QXmppMessage message;
+ parsePacket(message, xml);
+ QCOMPARE(message.mucInvitationJid(), QLatin1String("darkcave@macbeth.shakespeare.lit"));
+ QCOMPARE(message.mucInvitationPassword(), QLatin1String("cauldronburn"));
+ QCOMPARE(message.mucInvitationReason(), QLatin1String("Hey Hecate, this is the place for all good witches!"));
+ serializePacket(message, xml);
+}
+
void tst_QXmppMessage::testState_data()
{
QTest::addColumn<QByteArray>("xml");
diff --git a/tests/message.h b/tests/message.h
index ac1fb3a4..08c71283 100644
--- a/tests/message.h
+++ b/tests/message.h
@@ -36,6 +36,7 @@ private slots:
void testDelay_data();
void testDelay();
void testExtendedAddresses();
+ void testMucInvitation();
void testState_data();
void testState();
void testXhtml();