/* * ConnectionManager.h * * Copyright (C) 2008 Matthias Schiffer * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along * with this program. If not, see . */ #ifndef MAD_SERVER_CONNECTIONMANAGER_H_ #define MAD_SERVER_CONNECTIONMANAGER_H_ #include "export.h" #include #include #include #include #include #include #include #include #include #include #include namespace Mad { namespace Net { class Connection; class Listener; class Packet; } namespace Server { class Application; class MAD_SERVER_EXPORT ConnectionManager : public Core::Configurable, private boost::noncopyable { private: class MAD_SERVER_EXPORT ServerConnection : public Common::Connection { public: enum ConnectionType { UNKNOWN = 0, DAEMON, CLIENT }; private: Common::Application *application; boost::shared_ptr connection; ConnectionType type; Common::HostInfo *hostInfo; boost::shared_ptr authContext; protected: virtual bool send(const Net::Packet &packet); public: ServerConnection(Common::Application *application0, boost::shared_ptr connection0); bool isConnected() const; virtual bool disconnect(); //virtual void* getCertificate(size_t *size) const; //virtual void* getPeerCertificate(size_t *size) const; ConnectionType getConnectionType() const { return type; } Common::HostInfo *getHostInfo() const { return hostInfo; } bool isIdentified() const { return (type != UNKNOWN); } void identify() { type = CLIENT; } void identify(Common::HostInfo *info) { type = DAEMON; hostInfo = info; } bool isAuthenticated() const { return (authContext.get() != 0 && authContext->isAuthenticated()); } boost::shared_ptr authenticate(const std::string &method, const std::string &user, const std::vector &challenge, std::vector &response); }; friend class Application; Application *application; std::string x509TrustFile, x509CrlFile, x509CertFile, x509KeyFile; std::vector listenerAddresses; std::list > listeners; std::set > connections; std::map daemonInfo; boost::shared_ptr connectionRequestHandlerGroup; boost::shared_ptr daemonRequestHandlerGroup; boost::shared_ptr userRequestHandlerGroup; static boost::asio::ip::tcp::endpoint parseAddress(const std::string &str) throw(Core::Exception); void updateState(Common::HostInfo *hostInfo, Common::HostInfo::State state); void handleNewConnection(boost::shared_ptr con); void handleDisconnect(boost::shared_ptr con); ConnectionManager(Application *application0); ~ConnectionManager(); protected: virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool handled); virtual void configFinished(); public: boost::shared_ptr getDaemonConnection(const std::string &name) const throw (Core::Exception); std::string getDaemonName(const Common::Connection *con) const throw (Core::Exception); void identifyDaemonConnection(Common::Connection *con, const std::string &name) throw (Core::Exception); boost::shared_ptr authenticateConnection(Common::Connection *con, const std::string &method, const std::string &user, const std::vector &challenge, std::vector &response); bool isAuthenticated(Common::Connection *con) const; std::vector getDaemonList() const; }; } } #endif /*MAD_SERVER_CONNECTIONMANAGER_H_*/