summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2011-10-05 07:34:05 (GMT)
committerKevin Smith <git@kismith.co.uk>2011-10-05 07:34:05 (GMT)
commit3e972565e51f5b2fa7e9768d5d84a7d4b6dfc09b (patch)
treeb5b464804d169396f0cdd7348f4ae600ee2efe33 /Swiften
parent1f4be30a480818458fd841809585681597be831e (diff)
downloadswift-3e972565e51f5b2fa7e9768d5d84a7d4b6dfc09b.zip
swift-3e972565e51f5b2fa7e9768d5d84a7d4b6dfc09b.tar.bz2
Allow joining passworded MUCs.
Resolves: #991
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Elements/MUCPayload.h9
-rw-r--r--Swiften/Elements/Storage.h5
-rw-r--r--Swiften/MUC/MUC.cpp10
-rw-r--r--Swiften/MUC/MUC.h2
-rw-r--r--Swiften/MUC/MUCBookmark.h3
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp8
-rw-r--r--Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp4
8 files changed, 38 insertions, 5 deletions
diff --git a/Swiften/Elements/MUCPayload.h b/Swiften/Elements/MUCPayload.h
index 3b99111..29cab8d 100644
--- a/Swiften/Elements/MUCPayload.h
+++ b/Swiften/Elements/MUCPayload.h
@@ -40,6 +40,10 @@ namespace Swift {
since_ = since;
}
+ void setPassword(const std::string& password) {
+ password_ = password;
+ }
+
int getMaxChars() const{
return maxChars_;
}
@@ -52,6 +56,10 @@ namespace Swift {
return seconds_;
}
+ const boost::optional<std::string>& getPassword() const {
+ return password_;
+ }
+
const boost::posix_time::ptime& getSince() const {
return since_;
}
@@ -61,5 +69,6 @@ namespace Swift {
int maxStanzas_;
int seconds_;
boost::posix_time::ptime since_;
+ boost::optional<std::string> password_;
};
}
diff --git a/Swiften/Elements/Storage.h b/Swiften/Elements/Storage.h
index 8118b3b..03c958c 100644
--- a/Swiften/Elements/Storage.h
+++ b/Swiften/Elements/Storage.h
@@ -8,9 +8,12 @@
#include <vector>
+#include <boost/optional.hpp>
+
#include <Swiften/Elements/Payload.h>
#include <string>
#include <Swiften/JID/JID.h>
+#include <Swiften/Base/SafeString.h>
namespace Swift {
class Storage : public Payload {
@@ -22,7 +25,7 @@ namespace Swift {
JID jid;
bool autoJoin;
std::string nick;
- std::string password;
+ boost::optional<std::string> password;
};
struct URL {
diff --git a/Swiften/MUC/MUC.cpp b/Swiften/MUC/MUC.cpp
index 08391b4..15355ad 100644
--- a/Swiften/MUC/MUC.cpp
+++ b/Swiften/MUC/MUC.cpp
@@ -44,6 +44,13 @@ void MUC::joinAs(const std::string &nick) {
}
/**
+ * Set the password used for entering the room.
+ */
+void MUC::setPassword(const boost::optional<std::string>& newPassword) {
+ password = newPassword;
+}
+
+/**
* Join the MUC with context since date.
*/
void MUC::joinWithContextSince(const std::string &nick, const boost::posix_time::ptime& since) {
@@ -68,6 +75,9 @@ void MUC::internalJoin(const std::string &nick) {
if (joinSince_ != boost::posix_time::not_a_date_time) {
mucPayload->setSince(joinSince_);
}
+ if (password) {
+ mucPayload->setPassword(*password);
+ }
joinPresence->addPayload(mucPayload);
presenceSender->sendPresence(joinPresence);
diff --git a/Swiften/MUC/MUC.h b/Swiften/MUC/MUC.h
index adc5707..a9b42b8 100644
--- a/Swiften/MUC/MUC.h
+++ b/Swiften/MUC/MUC.h
@@ -65,6 +65,7 @@ namespace Swift {
/** Send an invite for the person to join the MUC */
void invitePerson(const JID& person, const std::string& reason = "");
void setCreateAsReservedIfNew() {createAsReservedIfNew = true;}
+ void setPassword(const boost::optional<std::string>& password);
public:
boost::signal<void (const std::string& /*nick*/)> onJoinComplete;
boost::signal<void (ErrorPayload::ref)> onJoinFailed;
@@ -110,5 +111,6 @@ namespace Swift {
boost::posix_time::ptime joinSince_;
bool createAsReservedIfNew;
bool unlocking;
+ boost::optional<std::string> password;
};
}
diff --git a/Swiften/MUC/MUCBookmark.h b/Swiften/MUC/MUCBookmark.h
index 3f612c4..3c28bdb 100644
--- a/Swiften/MUC/MUCBookmark.h
+++ b/Swiften/MUC/MUCBookmark.h
@@ -59,7 +59,8 @@ namespace Swift {
}
bool operator==(const MUCBookmark& rhs) const {
- return rhs.room_ == room_ && rhs.name_ == name_ && rhs.nick_ == nick_ && rhs.password_ == password_ && rhs.autojoin_ == autojoin_;
+ /* FIXME: not checking passwords for equality - which might make sense, perhaps */
+ return rhs.room_ == room_ && rhs.name_ == name_ && rhs.nick_ == nick_ /*&& rhs.password_ == password_*/ && rhs.autojoin_ == autojoin_;
}
Storage::Room toStorage() const {
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp
index 4fd8ae5..a378d0b 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp
+++ b/Swiften/Parser/PayloadParsers/UnitTest/StorageParserTest.cpp
@@ -42,7 +42,7 @@ class StorageParserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(JID("council@conference.underhill.org"), rooms[0].jid);
CPPUNIT_ASSERT(rooms[0].autoJoin);
CPPUNIT_ASSERT_EQUAL(std::string("Puck"), rooms[0].nick);
- CPPUNIT_ASSERT_EQUAL(std::string("MyPass"), rooms[0].password);
+ CPPUNIT_ASSERT_EQUAL(std::string("MyPass"), *rooms[0].password);
}
void testParse_MultipleRooms() {
diff --git a/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp
index 7080e14..58f78b8 100644
--- a/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp
@@ -7,9 +7,11 @@
#include <Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h>
#include <boost/lexical_cast.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <Swiften/Serializer/XML/XMLElement.h>
+#include <Swiften/Serializer/XML/XMLTextNode.h>
#include <Swiften/Base/String.h>
namespace Swift {
@@ -40,6 +42,12 @@ std::string MUCPayloadSerializer::serializePayload(boost::shared_ptr<MUCPayload>
historyElement->setAttribute("since", sinceString);
history = true;
}
+ if (muc->getPassword()) {
+ std::string password = *muc->getPassword();
+ boost::shared_ptr<XMLElement> passwordElement(new XMLElement("password"));
+ passwordElement->addNode(boost::make_shared<XMLTextNode>(password));
+ mucElement.addNode(passwordElement);
+ }
if (history) {
mucElement.addNode(historyElement);
}
diff --git a/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp b/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp
index 30adf26..77fb3c0 100644
--- a/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/StorageSerializer.cpp
@@ -30,9 +30,9 @@ std::string StorageSerializer::serializePayload(boost::shared_ptr<Storage> stora
nickElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(room.nick)));
conferenceElement->addNode(nickElement);
}
- if (!room.password.empty()) {
+ if (room.password) {
boost::shared_ptr<XMLElement> passwordElement(new XMLElement("password"));
- passwordElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(room.password)));
+ passwordElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(*room.password)));
conferenceElement->addNode(passwordElement);
}
storageElement.addNode(conferenceElement);