2011-06-18 23:27:54 +02:00
|
|
|
/*
|
|
|
|
* 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>
|
2016-09-12 18:20:58 +02:00
|
|
|
#include <boost/signals2.hpp>
|
2011-06-18 23:27:54 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Swiften/Network/BoostIOServiceThread.h"
|
|
|
|
#include "Swiften/Network/ConnectionServer.h"
|
|
|
|
#include "Swiften/Server/UserRegistry.h"
|
|
|
|
#include "Swiften/Server/ServerSession.h"
|
|
|
|
#include "Swiften/Base/IDGenerator.h"
|
|
|
|
#include "Swiften/Server/ServerFromClientSession.h"
|
|
|
|
#include "Swiften/JID/JID.h"
|
|
|
|
#include "Swiften/Base/ByteArray.h"
|
|
|
|
#include "Swiften/Entity/Entity.h"
|
|
|
|
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
|
|
|
|
#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h"
|
2016-09-12 18:20:58 +02:00
|
|
|
#include "Swiften/SwiftenCompat.h"
|
2012-03-03 16:07:41 +04:00
|
|
|
#include <Swiften/TLS/CertificateWithKey.h>
|
2011-10-10 21:09:47 +02:00
|
|
|
#include <Swiften/Parser/PlatformXMLParserFactory.h>
|
2011-06-18 23:27:54 +02:00
|
|
|
|
|
|
|
namespace Swift {
|
|
|
|
class ConnectionServer;
|
|
|
|
class SessionTracer;
|
|
|
|
class EventLoop;
|
|
|
|
class NetworkFactories;
|
|
|
|
class StanzaChannel;
|
|
|
|
class IQRouter;
|
|
|
|
class TLSServerContextFactory;
|
|
|
|
|
|
|
|
class Server : public Entity {
|
|
|
|
public:
|
2013-01-30 18:59:14 +01:00
|
|
|
Server(EventLoop* eventLoop, NetworkFactories* networkFactories, UserRegistry *userRegistry, const JID& jid, const std::string &address, int port);
|
2011-06-18 23:27:54 +02:00
|
|
|
~Server();
|
|
|
|
|
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
int getPort() const {
|
|
|
|
return port_;
|
|
|
|
}
|
|
|
|
|
|
|
|
StanzaChannel* getStanzaChannel() const {
|
|
|
|
return stanzaChannel_;
|
|
|
|
}
|
|
|
|
|
|
|
|
IQRouter* getIQRouter() const {
|
|
|
|
return iqRouter_;
|
|
|
|
}
|
|
|
|
|
2016-09-12 18:20:58 +02:00
|
|
|
SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ConnectionServer> getConnectionServer() const {
|
2011-08-25 11:24:03 +02:00
|
|
|
return serverFromClientConnectionServer;
|
|
|
|
}
|
|
|
|
|
2011-06-18 23:27:54 +02:00
|
|
|
boost::signal<void (const SafeByteArray&)> onDataRead;
|
|
|
|
boost::signal<void (const SafeByteArray&)> onDataWritten;
|
|
|
|
|
2012-03-03 16:07:41 +04:00
|
|
|
void addTLSEncryption(TLSServerContextFactory* tlsContextFactory, CertificateWithKey::ref cert);
|
2011-06-18 23:27:54 +02:00
|
|
|
|
|
|
|
private:
|
2016-09-12 18:20:58 +02:00
|
|
|
void handleNewClientConnection(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Connection> c);
|
|
|
|
void handleSessionStarted(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ServerFromClientSession>);
|
|
|
|
void handleSessionFinished(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ServerFromClientSession>);
|
|
|
|
void handleElementReceived(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Element> element, SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ServerFromClientSession> session);
|
2011-06-18 23:27:54 +02:00
|
|
|
void handleDataRead(const SafeByteArray&);
|
|
|
|
void handleDataWritten(const SafeByteArray&);
|
|
|
|
|
|
|
|
private:
|
|
|
|
IDGenerator idGenerator;
|
|
|
|
UserRegistry *userRegistry_;
|
|
|
|
int port_;
|
|
|
|
EventLoop* eventLoop;
|
|
|
|
NetworkFactories* networkFactories_;
|
|
|
|
bool stopping;
|
2016-09-12 18:20:58 +02:00
|
|
|
SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ConnectionServer> serverFromClientConnectionServer;
|
|
|
|
std::vector<SWIFTEN_SIGNAL_NAMESPACE::connection> serverFromClientConnectionServerSignalConnections;
|
|
|
|
std::list<SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ServerFromClientSession> > serverFromClientSessions;
|
2011-06-18 23:27:54 +02:00
|
|
|
JID selfJID;
|
|
|
|
StanzaChannel *stanzaChannel_;
|
|
|
|
IQRouter *iqRouter_;
|
|
|
|
TLSServerContextFactory *tlsFactory;
|
2012-03-03 16:07:41 +04:00
|
|
|
CertificateWithKey::ref cert;
|
2011-10-10 21:09:47 +02:00
|
|
|
PlatformXMLParserFactory *parserFactory_;
|
2013-01-30 18:59:14 +01:00
|
|
|
std::string address_;
|
2011-06-18 23:27:54 +02:00
|
|
|
};
|
|
|
|
}
|