summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-08-01 10:07:16 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-08-01 10:22:55 (GMT)
commit5a15e4df671aac30bba332801528a6283c2e4874 (patch)
tree8668089b7b9db89451b8b06ba7be29056a805f53 /Slimber
parent336aa7d1c0a5aa223a6543d50ee17d82560c2b84 (diff)
downloadswift-contrib-5a15e4df671aac30bba332801528a6283c2e4874.zip
swift-contrib-5a15e4df671aac30bba332801528a6283c2e4874.tar.bz2
Made Slimber fully functional again.
Diffstat (limited to 'Slimber')
-rw-r--r--Slimber/LinkLocalPresenceManager.cpp19
-rw-r--r--Slimber/LinkLocalPresenceManager.h3
-rw-r--r--Slimber/Server.cpp47
-rw-r--r--Slimber/Server.h14
-rw-r--r--Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp23
5 files changed, 64 insertions, 42 deletions
diff --git a/Slimber/LinkLocalPresenceManager.cpp b/Slimber/LinkLocalPresenceManager.cpp
index b964786..d5834c7 100644
--- a/Slimber/LinkLocalPresenceManager.cpp
+++ b/Slimber/LinkLocalPresenceManager.cpp
@@ -18,6 +18,15 @@ LinkLocalPresenceManager::LinkLocalPresenceManager(LinkLocalServiceBrowser* brow
boost::bind(&LinkLocalPresenceManager::handleServiceRemoved, this, _1));
}
+boost::optional<LinkLocalService> LinkLocalPresenceManager::getServiceForJID(const JID& j) const {
+ foreach(const LinkLocalService& service, browser->getServices()) {
+ if (service.getJID() == j) {
+ return service;
+ }
+ }
+ return boost::optional<LinkLocalService>();
+}
+
void LinkLocalPresenceManager::handleServiceAdded(const LinkLocalService& service) {
boost::shared_ptr<RosterPayload> roster(new RosterPayload());
roster->addItem(getRosterItem(service));
@@ -31,7 +40,7 @@ void LinkLocalPresenceManager::handleServiceChanged(const LinkLocalService& serv
void LinkLocalPresenceManager::handleServiceRemoved(const LinkLocalService& service) {
boost::shared_ptr<RosterPayload> roster(new RosterPayload());
- roster->addItem(RosterItemPayload(getJIDForService(service), "", RosterItemPayload::Remove));
+ roster->addItem(RosterItemPayload(service.getJID(), "", RosterItemPayload::Remove));
onRosterChanged(roster);
}
@@ -52,7 +61,7 @@ std::vector<boost::shared_ptr<Presence> > LinkLocalPresenceManager::getAllPresen
}
RosterItemPayload LinkLocalPresenceManager::getRosterItem(const LinkLocalService& service) const {
- return RosterItemPayload(getJIDForService(service), getRosterName(service), RosterItemPayload::Both);
+ return RosterItemPayload(service.getJID(), getRosterName(service), RosterItemPayload::Both);
}
String LinkLocalPresenceManager::getRosterName(const LinkLocalService& service) const {
@@ -73,13 +82,9 @@ String LinkLocalPresenceManager::getRosterName(const LinkLocalService& service)
return "";
}
-JID LinkLocalPresenceManager::getJIDForService(const LinkLocalService& service) const {
- return JID(service.getName());
-}
-
boost::shared_ptr<Presence> LinkLocalPresenceManager::getPresence(const LinkLocalService& service) const {
boost::shared_ptr<Presence> presence(new Presence());
- presence->setFrom(getJIDForService(service));
+ presence->setFrom(service.getJID());
switch (service.getInfo().getStatus()) {
case LinkLocalServiceInfo::Available:
presence->setShow(StatusShow::Online);
diff --git a/Slimber/LinkLocalPresenceManager.h b/Slimber/LinkLocalPresenceManager.h
index 2af2313..c9be5a7 100644
--- a/Slimber/LinkLocalPresenceManager.h
+++ b/Slimber/LinkLocalPresenceManager.h
@@ -20,6 +20,8 @@ namespace Swift {
boost::shared_ptr<RosterPayload> getRoster() const;
std::vector<boost::shared_ptr<Presence> > getAllPresence() const;
+ boost::optional<LinkLocalService> getServiceForJID(const JID&) const;
+
boost::signal<void (boost::shared_ptr<RosterPayload>)> onRosterChanged;
boost::signal<void (boost::shared_ptr<Presence>)> onPresenceChanged;
@@ -30,7 +32,6 @@ namespace Swift {
RosterItemPayload getRosterItem(const LinkLocalService& service) const;
String getRosterName(const LinkLocalService& service) const;
- JID getJIDForService(const LinkLocalService& service) const;
boost::shared_ptr<Presence> getPresence(const LinkLocalService& service) const;
private:
diff --git a/Slimber/Server.cpp b/Slimber/Server.cpp
index a63201b..36595b1 100644
--- a/Slimber/Server.cpp
+++ b/Slimber/Server.cpp
@@ -54,14 +54,12 @@ Server::Server(
linkLocalServiceBrowser->onServiceRegistered.connect(
boost::bind(&Server::handleServiceRegistered, this, _1));
- /*
serverFromNetworkConnectionServer =
boost::shared_ptr<BoostConnectionServer>(new BoostConnectionServer(
linkLocalConnectionPort, &boostIOServiceThread.getIOService()));
serverFromNetworkConnectionServer->onNewConnection.connect(
boost::bind(&Server::handleNewLinkLocalConnection, this, _1));
serverFromNetworkConnectionServer->start();
- */
}
Server::~Server() {
@@ -168,7 +166,6 @@ void Server::handleElementReceived(boost::shared_ptr<Element> element, boost::sh
}
}
}
- /*
else {
JID toJID = stanza->getTo();
boost::shared_ptr<Session> outgoingSession =
@@ -177,20 +174,20 @@ void Server::handleElementReceived(boost::shared_ptr<Element> element, boost::sh
outgoingSession->sendElement(stanza);
}
else {
- if (linkLocalServiceBrowser->hasItem(toJID)) {
+ boost::optional<LinkLocalService> service =
+ presenceManager->getServiceForJID(toJID);
+ if (service) {
boost::shared_ptr<LinkLocalConnector> connector =
getLinkLocalConnectorForJID(toJID);
if (!connector) {
connector = boost::shared_ptr<LinkLocalConnector>(
new LinkLocalConnector(
- toJID,
- linkLocalServiceBrowser->getHostname(toJID),
- linkLocalServiceBrowser->getPort(toJID),
- linkLocalServiceBrowser,
+ *service,
+ linkLocalServiceBrowser->getQuerier(),
boost::shared_ptr<BoostConnection>(new BoostConnection(&boostIOServiceThread.getIOService()))));
connector->onConnectFinished.connect(
boost::bind(&Server::handleConnectFinished, this, connector, _1));
- connectors_.push_back(connector);
+ connectors.push_back(connector);
connector->connect();
}
connector->queueElement(element);
@@ -202,10 +199,8 @@ void Server::handleElementReceived(boost::shared_ptr<Element> element, boost::sh
}
}
}
- */
}
-/*
void Server::handleNewLinkLocalConnection(boost::shared_ptr<Connection> connection) {
boost::shared_ptr<IncomingLinkLocalSession> session(
new IncomingLinkLocalSession(
@@ -216,14 +211,16 @@ void Server::handleNewLinkLocalConnection(boost::shared_ptr<Connection> connecti
void Server::handleLinkLocalSessionFinished(boost::shared_ptr<Session> session) {
std::cout << "Link local session from " << session->getRemoteJID() << " ended" << std::endl;
- linkLocalSessions_.erase(std::remove(linkLocalSessions_.begin(), linkLocalSessions_.end(), session), linkLocalSessions_.end());
+ linkLocalSessions.erase(
+ std::remove(linkLocalSessions.begin(), linkLocalSessions.end(), session),
+ linkLocalSessions.end());
}
void Server::handleLinkLocalElementReceived(boost::shared_ptr<Element> element, boost::shared_ptr<Session> session) {
if (boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element)) {
JID fromJID = session->getRemoteJID();
- if (!linkLocalServiceBrowser->hasItem(fromJID)) {
- return; // TODO: Queue
+ if (!presenceManager->getServiceForJID(fromJID.toBare())) {
+ return; // TODO: Send error back
}
stanza->setFrom(fromJID);
serverFromClientSession->sendElement(stanza);
@@ -238,27 +235,28 @@ void Server::handleConnectFinished(boost::shared_ptr<LinkLocalConnector> connect
else {
boost::shared_ptr<OutgoingLinkLocalSession> outgoingSession(
new OutgoingLinkLocalSession(
- selfJID, connector->getRemoteJID(), connector->getConnection(),
+ selfJID, connector->getService().getJID(), connector->getConnection(),
&payloadParserFactories, &payloadSerializers));
foreach(const boost::shared_ptr<Element> element, connector->getQueuedElements()) {
outgoingSession->queueElement(element);
}
registerLinkLocalSession(outgoingSession);
}
- connectors_.erase(std::remove(connectors_.begin(), connectors_.end(), connector), connectors_.end());
+ connectors.erase(std::remove(connectors.begin(), connectors.end(), connector), connectors.end());
}
-
void Server::registerLinkLocalSession(boost::shared_ptr<Session> session) {
- session->onSessionFinished.connect(boost::bind(&Server::handleLinkLocalSessionFinished, this, session));
- session->onElementReceived.connect(boost::bind(&Server::handleLinkLocalElementReceived, this, _1, session));
- linkLocalSessions_.push_back(session);
- //tracers.push_back(boost::shared_ptr<SessionTracer>(new SessionTracer(session)));
+ session->onSessionFinished.connect(
+ boost::bind(&Server::handleLinkLocalSessionFinished, this, session));
+ session->onElementReceived.connect(
+ boost::bind(&Server::handleLinkLocalElementReceived, this, _1, session));
+ linkLocalSessions.push_back(session);
+ tracers.push_back(boost::shared_ptr<SessionTracer>(new SessionTracer(session)));
session->startSession();
}
boost::shared_ptr<Session> Server::getLinkLocalSessionForJID(const JID& jid) {
- foreach(const boost::shared_ptr<Session> session, linkLocalSessions_) {
+ foreach(const boost::shared_ptr<Session> session, linkLocalSessions) {
if (session->getRemoteJID() == jid) {
return session;
}
@@ -267,14 +265,13 @@ boost::shared_ptr<Session> Server::getLinkLocalSessionForJID(const JID& jid) {
}
boost::shared_ptr<LinkLocalConnector> Server::getLinkLocalConnectorForJID(const JID& jid) {
- foreach(const boost::shared_ptr<LinkLocalConnector> connector, connectors_) {
- if (connector->getRemoteJID() == jid) {
+ foreach(const boost::shared_ptr<LinkLocalConnector> connector, connectors) {
+ if (connector->getService().getJID() == jid) {
return connector;
}
}
return boost::shared_ptr<LinkLocalConnector>();
}
-*/
void Server::handleServiceRegistered(const DNSSDServiceID& service) {
selfJID = JID(service.getName());
diff --git a/Slimber/Server.h b/Slimber/Server.h
index 3ed0a58..38c45de 100644
--- a/Slimber/Server.h
+++ b/Slimber/Server.h
@@ -16,6 +16,7 @@ namespace Swift {
class DNSSDServiceID;
class String;
class VCardCollection;
+ class LinkLocalConnector;
class LinkLocalServiceBrowser;
class LinkLocalPresenceManager;
class BoostConnectionServer;
@@ -42,16 +43,13 @@ namespace Swift {
void handleRosterChanged(boost::shared_ptr<RosterPayload> roster);
void handlePresenceChanged(boost::shared_ptr<Presence> presence);
void handleServiceRegistered(const DNSSDServiceID& service);
-/*
void handleNewLinkLocalConnection(boost::shared_ptr<Connection> connection);
void handleLinkLocalSessionFinished(boost::shared_ptr<Session> session);
void handleLinkLocalElementReceived(boost::shared_ptr<Element> element, boost::shared_ptr<Session> session);
void handleConnectFinished(boost::shared_ptr<LinkLocalConnector> connector, bool error);
- void registerLinkLocalSession(boost::shared_ptr<Session> session);
boost::shared_ptr<Session> getLinkLocalSessionForJID(const JID& jid);
boost::shared_ptr<LinkLocalConnector> getLinkLocalConnectorForJID(const JID& jid);
- */
-
+ void registerLinkLocalSession(boost::shared_ptr<Session> session);
void unregisterService();
LinkLocalServiceInfo getLinkLocalServiceInfo(boost::shared_ptr<Presence> presence);
@@ -82,11 +80,9 @@ namespace Swift {
boost::shared_ptr<ServerFromClientSession> serverFromClientSession;
boost::shared_ptr<Presence> lastPresence;
JID selfJID;
- /*
- boost::shared_ptr<BoostConnectionServer> serverFromNetworkConnectionServer_;
- std::vector< boost::shared_ptr<Session> > linkLocalSessions_;
- std::vector< boost::shared_ptr<LinkLocalConnector> > connectors_;
-*/
+ boost::shared_ptr<BoostConnectionServer> serverFromNetworkConnectionServer;
+ std::vector< boost::shared_ptr<Session> > linkLocalSessions;
+ std::vector< boost::shared_ptr<LinkLocalConnector> > connectors;
std::vector< boost::shared_ptr<SessionTracer> > tracers;
};
}
diff --git a/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp b/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp
index f15daf4..f77a8cb 100644
--- a/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp
+++ b/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp
@@ -29,6 +29,8 @@ class LinkLocalPresenceManagerTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testGetRoster_InfoWithLastName);
CPPUNIT_TEST(testGetRoster_InfoWithFirstAndLastName);
CPPUNIT_TEST(testGetRoster_NoInfo);
+ CPPUNIT_TEST(testGetServiceForJID);
+ CPPUNIT_TEST(testGetServiceForJID_NoMatch);
CPPUNIT_TEST_SUITE_END();
public:
@@ -176,6 +178,27 @@ class LinkLocalPresenceManagerTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(String(""), item->getName());
}
+ void testGetServiceForJID() {
+ std::auto_ptr<LinkLocalPresenceManager> testling(createTestling());
+
+ addService("alice@wonderland");
+ addService("rabbit@teaparty");
+ addService("queen@garden");
+
+ boost::optional<LinkLocalService> service = testling->getServiceForJID(JID("rabbit@teaparty"));
+ CPPUNIT_ASSERT(service);
+ CPPUNIT_ASSERT_EQUAL(String("rabbit@teaparty"), service->getID().getName());
+ }
+
+ void testGetServiceForJID_NoMatch() {
+ std::auto_ptr<LinkLocalPresenceManager> testling(createTestling());
+
+ addService("alice@wonderland");
+ addService("queen@garden");
+
+ CPPUNIT_ASSERT(!testling->getServiceForJID(JID("rabbit@teaparty")));
+ }
+
private:
std::auto_ptr<LinkLocalPresenceManager> createTestling() {
std::auto_ptr<LinkLocalPresenceManager> testling(