fixed formatting for real this time

This commit is contained in:
Darchigh 2013-01-10 14:49:18 +01:00
parent 5e0208ef29
commit 7c2cb5c4b3
3 changed files with 78 additions and 78 deletions

View file

@ -70,8 +70,8 @@ class UserRegistration : public Swift::Responder<Swift::InBandRegistrationPayloa
private:
virtual bool handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::InBandRegistrationPayload> payload);
virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::InBandRegistrationPayload> payload);
void handleRegisterRemoteRosterResponse(boost::shared_ptr<Swift::RosterPayload> payload, Swift::ErrorPayload::ref error, const UserInfo &row);
void handleRegisterRemoteRosterResponse(boost::shared_ptr<Swift::RosterPayload> payload, Swift::ErrorPayload::ref error, const UserInfo &row);
void handleUnregisterRemoteRosterResponse(boost::shared_ptr<Swift::RosterPayload> payload, Swift::ErrorPayload::ref error, const std::string &barejid);
Component *m_component;

View file

@ -26,7 +26,7 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
CPPUNIT_TEST(getForm);
CPPUNIT_TEST(getFormRegistered);
CPPUNIT_TEST(registerUser);
CPPUNIT_TEST(registerUserWithoutRR);
CPPUNIT_TEST(registerUserWithoutRR);
CPPUNIT_TEST(unregisterUser);
CPPUNIT_TEST(unregisterEmptyPayload);
CPPUNIT_TEST(registerUserNotify);
@ -87,64 +87,64 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
}
void registerUser() {
Swift::InBandRegistrationPayload *reg = new Swift::InBandRegistrationPayload();
Swift::InBandRegistrationPayload *reg = new Swift::InBandRegistrationPayload();
reg->setUsername("legacyname");
reg->setPassword("password");
boost::shared_ptr<Swift::IQ> iq = Swift::IQ::createRequest(Swift::IQ::Set, Swift::JID("localhost"), "id", boost::shared_ptr<Swift::Payload>(reg));
iq->setFrom("user@localhost");
injectIQ(iq);
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[1])));
CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast<Swift::IQ *>(getStanza(received[1]))->getType());
iq = Swift::IQ::createResult(Swift::JID("localhost"), getStanza(received[0])->getTo(), getStanza(received[0])->getID(), boost::shared_ptr<Swift::Payload>(new Swift::RosterPayload()));
iq = Swift::IQ::createResult(Swift::JID("localhost"), getStanza(received[0])->getTo(), getStanza(received[0])->getID(), boost::shared_ptr<Swift::Payload>(new Swift::RosterPayload()));
received.clear();
injectIQ(iq);
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[0])));
CPPUNIT_ASSERT_EQUAL(Swift::IQ::Set, dynamic_cast<Swift::IQ *>(getStanza(received[0]))->getType());
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), getStanza(received[0])->getPayload<Swift::RosterPayload>()->getItems()[0].getJID().toString());
UserInfo user;
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), getStanza(received[0])->getPayload<Swift::RosterPayload>()->getItems()[0].getJID().toString());
UserInfo user;
CPPUNIT_ASSERT_EQUAL(true, storage->getUser("user@localhost", user));
CPPUNIT_ASSERT_EQUAL(std::string("legacyname"), user.uin);
CPPUNIT_ASSERT_EQUAL(std::string("password"), user.password);
}
void registerUserWithoutRR(){
Swift::InBandRegistrationPayload *reg = new Swift::InBandRegistrationPayload();
}
void registerUserWithoutRR(){
Swift::InBandRegistrationPayload *reg = new Swift::InBandRegistrationPayload();
reg->setUsername("legacyname");
reg->setPassword("password");
boost::shared_ptr<Swift::IQ> iq = Swift::IQ::createRequest(Swift::IQ::Set, Swift::JID("localhost"), "id", boost::shared_ptr<Swift::Payload>(reg));
iq->setFrom("user@localhost");
injectIQ(iq);
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[1])));
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[1])));
CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast<Swift::IQ *>(getStanza(received[1]))->getType());
iq = Swift::IQ::createError(Swift::JID("localhost"), getStanza(received[0])->getTo(), getStanza(received[0])->getID());
received.clear();
iq = Swift::IQ::createError(Swift::JID("localhost"), getStanza(received[0])->getTo(), getStanza(received[0])->getID());
received.clear();
injectIQ(iq);
loop->processEvents();
CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
CPPUNIT_ASSERT_EQUAL(Swift::Presence::Subscribe, dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getType());
}
}
void unregisterUser() {
registerUser();
received.clear();
@ -155,11 +155,11 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
iq->setFrom("user@localhost");
injectIQ(iq);
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[1])));
CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast<Swift::IQ *>(getStanza(received[1]))->getType());
@ -167,7 +167,7 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
received.clear();
injectIQ(iq);
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[0])));
CPPUNIT_ASSERT_EQUAL(Swift::IQ::Set, dynamic_cast<Swift::IQ *>(getStanza(received[0]))->getType());
@ -188,25 +188,25 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
iq->setFrom("user@localhost");
injectIQ(iq);
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[1])));
CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast<Swift::IQ *>(getStanza(received[1]))->getType());
iq = Swift::IQ::createResult(Swift::JID("localhost"), getStanza(received[0])->getTo(), getStanza(received[0])->getID(), boost::shared_ptr<Swift::Payload>(new Swift::RosterPayload()));
iq = Swift::IQ::createResult(Swift::JID("localhost"), getStanza(received[0])->getTo(), getStanza(received[0])->getID(), boost::shared_ptr<Swift::Payload>(new Swift::RosterPayload()));
received.clear();
injectIQ(iq);
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[0])));
CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[0])));
CPPUNIT_ASSERT_EQUAL(Swift::IQ::Set, dynamic_cast<Swift::IQ *>(getStanza(received[0]))->getType());
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), getStanza(received[0])->getPayload<Swift::RosterPayload>()->getItems()[0].getJID().toString());
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), getStanza(received[0])->getPayload<Swift::RosterPayload>()->getItems()[0].getJID().toString());
CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[1])));
CPPUNIT_ASSERT_EQUAL(std::string("registered: user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getBody());
@ -342,18 +342,18 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[1])));
CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast<Swift::IQ *>(getStanza(received[1]))->getType());
iq = Swift::IQ::createResult(Swift::JID("localhost"), getStanza(received[0])->getTo(), getStanza(received[0])->getID(), boost::shared_ptr<Swift::Payload>(new Swift::RosterPayload()));
iq = Swift::IQ::createResult(Swift::JID("localhost"), getStanza(received[0])->getTo(), getStanza(received[0])->getID(), boost::shared_ptr<Swift::Payload>(new Swift::RosterPayload()));
received.clear();
injectIQ(iq);
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[0])));
CPPUNIT_ASSERT_EQUAL(Swift::IQ::Set, dynamic_cast<Swift::IQ *>(getStanza(received[0]))->getType());
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), getStanza(received[0])->getPayload<Swift::RosterPayload>()->getItems()[0].getJID().toString());
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), getStanza(received[0])->getPayload<Swift::RosterPayload>()->getItems()[0].getJID().toString());
UserInfo user;
CPPUNIT_ASSERT_EQUAL(true, storage->getUser("user@localhost", user));

View file

@ -55,11 +55,11 @@ bool UserRegistration::registerUser(const UserInfo &row) {
return false;
m_storageBackend->setUser(row);
//same as in unregisterUser but here we have to pass UserInfo to handleRegisterRRResponse
AddressedRosterRequest::ref request = AddressedRosterRequest::ref(new AddressedRosterRequest(m_component->getIQRouter(),row.jid));
request->onResponse.connect(boost::bind(&UserRegistration::handleRegisterRemoteRosterResponse, this, _1, _2, row));
request->send();
//same as in unregisterUser but here we have to pass UserInfo to handleRegisterRRResponse
AddressedRosterRequest::ref request = AddressedRosterRequest::ref(new AddressedRosterRequest(m_component->getIQRouter(),row.jid));
request->onResponse.connect(boost::bind(&UserRegistration::handleRegisterRemoteRosterResponse, this, _1, _2, row));
request->send();
return true;
}
@ -82,31 +82,31 @@ bool UserRegistration::unregisterUser(const std::string &barejid) {
}
void UserRegistration::handleRegisterRemoteRosterResponse(boost::shared_ptr<Swift::RosterPayload> payload, Swift::ErrorPayload::ref remoteRosterNotSupported /*error*/, const UserInfo &row){
if (remoteRosterNotSupported || !payload) {
Swift::Presence::ref response = Swift::Presence::create();
response->setFrom(m_component->getJID());
response->setTo(Swift::JID(row.jid));
response->setType(Swift::Presence::Subscribe);
m_component->getStanzaChannel()->sendPresence(response);
}
else{
Swift::RosterPayload::ref payload = Swift::RosterPayload::ref(new Swift::RosterPayload());
Swift::RosterItemPayload item;
item.setJID(m_component->getJID());
item.setSubscription(Swift::RosterItemPayload::Both);
payload->addItem(item);
Swift::SetRosterRequest::ref request = Swift::SetRosterRequest::create(payload, row.jid, m_component->getIQRouter());
request->send();
}
onUserRegistered(row);
BOOST_FOREACH(const std::string &notify_jid, CONFIG_VECTOR(m_component->getConfig(),"registration.notify_jid")) {
if (remoteRosterNotSupported || !payload) {
Swift::Presence::ref response = Swift::Presence::create();
response->setFrom(m_component->getJID());
response->setTo(Swift::JID(row.jid));
response->setType(Swift::Presence::Subscribe);
m_component->getStanzaChannel()->sendPresence(response);
}
else{
Swift::RosterPayload::ref payload = Swift::RosterPayload::ref(new Swift::RosterPayload());
Swift::RosterItemPayload item;
item.setJID(m_component->getJID());
item.setSubscription(Swift::RosterItemPayload::Both);
payload->addItem(item);
Swift::SetRosterRequest::ref request = Swift::SetRosterRequest::create(payload, row.jid, m_component->getIQRouter());
request->send();
}
onUserRegistered(row);
BOOST_FOREACH(const std::string &notify_jid, CONFIG_VECTOR(m_component->getConfig(),"registration.notify_jid")) {
boost::shared_ptr<Swift::Message> msg(new Swift::Message());
msg->setBody(std::string("registered: ") + row.jid);
msg->setTo(notify_jid);
msg->setFrom(m_component->getJID());
m_component->getStanzaChannel()->sendMessage(msg);
}
}
}
void UserRegistration::handleUnregisterRemoteRosterResponse(boost::shared_ptr<Swift::RosterPayload> payload, Swift::ErrorPayload::ref remoteRosterNotSupported /*error*/, const std::string &barejid) {