Send subscribe/subscribed presence from transport contact when connecting

This commit is contained in:
HanzZ 2012-10-23 18:27:04 +02:00
parent 8f7a62c727
commit 4055180802
4 changed files with 37 additions and 6 deletions

View file

@ -155,7 +155,7 @@ int create_socket(const char *host, int portno) {
stSockAddr.sin_family = AF_INET;
stSockAddr.sin_port = htons(portno);
bcopy(hos->h_addr, &(stSockAddr.sin_addr.s_addr), hos->h_length);
memcpy(&(stSockAddr.sin_addr.s_addr), hos->h_addr, hos->h_length);
if (-1 == connect(SocketFD, (struct sockaddr *)&stSockAddr, sizeof(stSockAddr))) {
close(SocketFD);

View file

@ -202,6 +202,7 @@ void BasicTest::connectUser() {
CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::DiscoInfo>());
received.clear();
receivedData.clear();
}
@ -236,6 +237,7 @@ void BasicTest::connectSecondResource() {
}
void BasicTest::disconnectUser() {
received.clear();
userManager->disconnectUser("user@localhost");
dynamic_cast<Swift::DummyTimerFactory *>(factories->getTimerFactory())->setTime(10);
loop->processEvents();

View file

@ -79,12 +79,20 @@ class UserManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
dynamic_cast<Swift::ServerStanzaChannel *>(component->getStanzaChannel())->onPresenceReceived(response);
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
CPPUNIT_ASSERT_EQUAL(4, (int) received.size());
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::DiscoInfo>());
Swift::Presence *presence = dynamic_cast<Swift::Presence *>(getStanza(received[1]));
CPPUNIT_ASSERT(presence);
CPPUNIT_ASSERT_EQUAL(Swift::Presence::Unavailable, presence->getType());
presence = dynamic_cast<Swift::Presence *>(getStanza(received[2]));
CPPUNIT_ASSERT(presence);
CPPUNIT_ASSERT_EQUAL(Swift::Presence::Subscribe, presence->getType());
presence = dynamic_cast<Swift::Presence *>(getStanza(received[3]));
CPPUNIT_ASSERT(presence);
CPPUNIT_ASSERT_EQUAL(Swift::Presence::Subscribed, presence->getType());
}
void connectTwoResources() {

View file

@ -184,14 +184,33 @@ void UserManager::handlePresence(Swift::Presence::ref presence) {
}
}
UserInfo res;
bool registered = m_storageBackend ? m_storageBackend->getUser(userkey, res) : false;
// No user and unavailable presence -> answer with unavailable
if (presence->getType() == Swift::Presence::Unavailable) {
if (presence->getType() == Swift::Presence::Unavailable || presence->getType() == Swift::Presence::Probe) {
Swift::Presence::ref response = Swift::Presence::create();
response->setTo(presence->getFrom());
response->setFrom(presence->getTo());
response->setType(Swift::Presence::Unavailable);
m_component->getStanzaChannel()->sendPresence(response);
// bother him with subscribe presence, just to be
// sure he is subscribed to us.
if (/*registered && */presence->getType() == Swift::Presence::Probe) {
Swift::Presence::ref response = Swift::Presence::create();
response->setTo(presence->getFrom());
response->setFrom(presence->getTo());
response->setType(Swift::Presence::Subscribe);
m_component->getStanzaChannel()->sendPresence(response);
response = Swift::Presence::create();
response->setTo(presence->getFrom());
response->setFrom(presence->getTo());
response->setType(Swift::Presence::Subscribed);
m_component->getStanzaChannel()->sendPresence(response);
}
// Set user offline in database
if (m_storageBackend) {
UserInfo res;
@ -203,9 +222,6 @@ void UserManager::handlePresence(Swift::Presence::ref presence) {
return;
}
UserInfo res;
bool registered = m_storageBackend ? m_storageBackend->getUser(userkey, res) : false;
// In server mode, we don't need registration normally, but for networks like IRC
// or Twitter where there's no real authorization using password, we have to force
// registration otherwise some data (like bookmarked rooms) could leak.
@ -378,6 +394,11 @@ void UserManager::handleGeneralPresenceReceived(Swift::Presence::ref presence) {
}
void UserManager::handleProbePresence(Swift::Presence::ref presence) {
// Don't let RosterManager to handle presences for us
if (presence->getTo().getNode().empty()) {
return;
}
User *user = getUser(presence->getFrom().toBare().toString());
if (user) {