summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Slimber')
-rw-r--r--Slimber/Server.cpp6
-rw-r--r--Slimber/Server.h2
2 files changed, 5 insertions, 3 deletions
diff --git a/Slimber/Server.cpp b/Slimber/Server.cpp
index 84b33fa..769217f 100644
--- a/Slimber/Server.cpp
+++ b/Slimber/Server.cpp
@@ -115,71 +115,71 @@ void Server::stop(boost::optional<ServerError> e) {
}
linkLocalSessions.clear();
foreach(boost::shared_ptr<LinkLocalConnector> connector, connectors) {
connector->cancel();
}
connectors.clear();
tracers.clear();
if (serverFromNetworkConnectionServer) {
serverFromNetworkConnectionServer->stop();
foreach(boost::bsignals::connection& connection, serverFromNetworkConnectionServerSignalConnections) {
connection.disconnect();
}
serverFromNetworkConnectionServerSignalConnections.clear();
serverFromNetworkConnectionServer.reset();
}
if (serverFromClientConnectionServer) {
serverFromClientConnectionServer->stop();
foreach(boost::bsignals::connection& connection, serverFromClientConnectionServerSignalConnections) {
connection.disconnect();
}
serverFromClientConnectionServerSignalConnections.clear();
serverFromClientConnectionServer.reset();
}
stopping = false;
onStopped(e);
}
void Server::handleNewClientConnection(boost::shared_ptr<Connection> connection) {
if (serverFromClientSession) {
connection->disconnect();
}
serverFromClientSession = boost::shared_ptr<ServerFromClientSession>(
new ServerFromClientSession(idGenerator.generateID(), connection,
- &payloadParserFactories, &payloadSerializers, &userRegistry));
+ &payloadParserFactories, &payloadSerializers, &xmlParserFactory, &userRegistry));
serverFromClientSession->setAllowSASLEXTERNAL();
serverFromClientSession->onSessionStarted.connect(
boost::bind(&Server::handleSessionStarted, this));
serverFromClientSession->onElementReceived.connect(
boost::bind(&Server::handleElementReceived, this, _1,
serverFromClientSession));
serverFromClientSession->onSessionFinished.connect(
boost::bind(&Server::handleSessionFinished, this,
serverFromClientSession));
//tracers.push_back(boost::shared_ptr<SessionTracer>(
// new SessionTracer(serverFromClientSession)));
serverFromClientSession->startSession();
}
void Server::handleSessionStarted() {
onSelfConnected(true);
}
void Server::handleSessionFinished(boost::shared_ptr<ServerFromClientSession>) {
serverFromClientSession.reset();
unregisterService();
selfJID = JID();
rosterRequested = false;
onSelfConnected(false);
lastPresence.reset();
}
void Server::unregisterService() {
if (linkLocalServiceRegistered) {
linkLocalServiceRegistered = false;
linkLocalServiceBrowser->unregisterService();
}
}
void Server::handleElementReceived(boost::shared_ptr<Element> element, boost::shared_ptr<ServerFromClientSession> session) {
@@ -249,102 +249,102 @@ void Server::handleElementReceived(boost::shared_ptr<Element> element, boost::sh
if (outgoingSession) {
outgoingSession->sendElement(stanza);
}
else {
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(
*service,
linkLocalServiceBrowser->getQuerier(),
BoostConnection::create(boostIOServiceThread.getIOService(), eventLoop)));
connector->onConnectFinished.connect(
boost::bind(&Server::handleConnectFinished, this, connector, _1));
connectors.push_back(connector);
connector->connect();
}
connector->queueElement(element);
}
else {
session->sendElement(IQ::createError(
stanza->getFrom(), stanza->getID(),
ErrorPayload::RecipientUnavailable, ErrorPayload::Wait));
}
}
}
}
void Server::handleNewLinkLocalConnection(boost::shared_ptr<Connection> connection) {
boost::shared_ptr<IncomingLinkLocalSession> session(
new IncomingLinkLocalSession(
selfJID, connection,
- &payloadParserFactories, &payloadSerializers));
+ &payloadParserFactories, &payloadSerializers, &xmlParserFactory));
registerLinkLocalSession(session);
}
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());
}
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 (!presenceManager->getServiceForJID(fromJID.toBare())) {
return; // TODO: Send error back
}
stanza->setFrom(fromJID);
serverFromClientSession->sendElement(stanza);
}
}
void Server::handleConnectFinished(boost::shared_ptr<LinkLocalConnector> connector, bool error) {
if (error) {
std::cerr << "Error connecting" << std::endl;
// TODO: Send back queued stanzas
}
else {
boost::shared_ptr<OutgoingLinkLocalSession> outgoingSession(
new OutgoingLinkLocalSession(
selfJID, connector->getService().getJID(), connector->getConnection(),
- &payloadParserFactories, &payloadSerializers));
+ &payloadParserFactories, &payloadSerializers, &xmlParserFactory));
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());
}
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->startSession();
}
boost::shared_ptr<Session> Server::getLinkLocalSessionForJID(const JID& jid) {
foreach(const boost::shared_ptr<Session> session, linkLocalSessions) {
if (session->getRemoteJID() == jid) {
return session;
}
}
return boost::shared_ptr<Session>();
}
boost::shared_ptr<LinkLocalConnector> Server::getLinkLocalConnectorForJID(const JID& jid) {
foreach(const boost::shared_ptr<LinkLocalConnector> connector, connectors) {
if (connector->getService().getJID() == jid) {
return connector;
}
}
return boost::shared_ptr<LinkLocalConnector>();
}
diff --git a/Slimber/Server.h b/Slimber/Server.h
index 58b1e7c..96401d9 100644
--- a/Slimber/Server.h
+++ b/Slimber/Server.h
@@ -1,51 +1,52 @@
/*
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
#include <vector>
#include "Swiften/Network/BoostIOServiceThread.h"
#include "Swiften/Network/BoostConnectionServer.h"
#include "Limber/Server/UserRegistry.h"
#include "Swiften/Base/IDGenerator.h"
+#include "Swiften/Parser/PlatformXMLParserFactory.h"
#include "Limber/Server/ServerFromClientSession.h"
#include "Swiften/JID/JID.h"
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h"
#include "Swiften/LinkLocal/LinkLocalServiceInfo.h"
#include "Slimber/ServerError.h"
namespace Swift {
class DNSSDServiceID;
class VCardCollection;
class LinkLocalConnector;
class LinkLocalServiceBrowser;
class LinkLocalPresenceManager;
class BoostConnectionServer;
class SessionTracer;
class RosterPayload;
class Presence;
class EventLoop;
class Server {
public:
Server(
int clientConnectionPort,
int linkLocalConnectionPort,
LinkLocalServiceBrowser* browser,
VCardCollection* vCardCollection,
EventLoop* eventLoop);
~Server();
void start();
void stop();
int getLinkLocalPort() const {
return linkLocalConnectionPort;
@@ -66,56 +67,57 @@ namespace Swift {
void handleSessionFinished(boost::shared_ptr<ServerFromClientSession>);
void handleElementReceived(boost::shared_ptr<Element> element, boost::shared_ptr<ServerFromClientSession> session);
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 handleClientConnectionServerStopped(
boost::optional<BoostConnectionServer::Error>);
void handleLinkLocalConnectionServerStopped(
boost::optional<BoostConnectionServer::Error>);
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);
private:
class DummyUserRegistry : public UserRegistry {
public:
DummyUserRegistry() {}
virtual bool isValidUserPassword(const JID&, const SafeByteArray&) const {
return true;
}
};
private:
IDGenerator idGenerator;
FullPayloadParserFactoryCollection payloadParserFactories;
FullPayloadSerializerCollection payloadSerializers;
BoostIOServiceThread boostIOServiceThread;
DummyUserRegistry userRegistry;
+ PlatformXMLParserFactory xmlParserFactory;
bool linkLocalServiceRegistered;
bool rosterRequested;
int clientConnectionPort;
int linkLocalConnectionPort;
LinkLocalServiceBrowser* linkLocalServiceBrowser;
VCardCollection* vCardCollection;
EventLoop* eventLoop;
LinkLocalPresenceManager* presenceManager;
bool stopping;
boost::shared_ptr<BoostConnectionServer> serverFromClientConnectionServer;
std::vector<boost::bsignals::connection> serverFromClientConnectionServerSignalConnections;
boost::shared_ptr<ServerFromClientSession> serverFromClientSession;
boost::shared_ptr<Presence> lastPresence;
JID selfJID;
boost::shared_ptr<BoostConnectionServer> serverFromNetworkConnectionServer;
std::vector<boost::bsignals::connection> serverFromNetworkConnectionServerSignalConnections;
std::vector< boost::shared_ptr<Session> > linkLocalSessions;
std::vector< boost::shared_ptr<LinkLocalConnector> > connectors;
std::vector< boost::shared_ptr<SessionTracer> > tracers;
};
}