From 0d1a7cb65b7b0f5ecc8e3cd6fbabdebab7f47f7f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 6 Aug 2009 21:28:41 +0200 Subject: Revised server config format --- src/Server/ConnectionManager.cpp | 43 +++++++++++++++++++++++++--------------- src/Server/ConnectionManager.h | 2 ++ 2 files changed, 29 insertions(+), 16 deletions(-) (limited to 'src/Server') diff --git a/src/Server/ConnectionManager.cpp b/src/Server/ConnectionManager.cpp index 4ac4f7c..96f383a 100644 --- a/src/Server/ConnectionManager.cpp +++ b/src/Server/ConnectionManager.cpp @@ -17,6 +17,7 @@ * with this program. If not, see . */ +#include #include "ConnectionManager.h" #include "Application.h" #include @@ -25,7 +26,6 @@ #include #include #include "Requests/DaemonStateUpdateRequest.h" -//#include "RequestHandlers/GSSAPIAuthRequestHandler.h" #include "RequestHandlers/ConnectionRequestHandlerGroup.h" #include "RequestHandlers/DaemonRequestHandlerGroup.h" #include "RequestHandlers/UserRequestHandlerGroup.h" @@ -71,6 +71,27 @@ void* ConnectionManager::ServerConnection::getPeerCertificate(size_t *size) cons return cert->data; }*/ +boost::asio::ip::tcp::endpoint ConnectionManager::parseAddress(const std::string &str) { + // TODO IPv6 + + if(str == "*") + return boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), DEFAULT_PORT); + + boost::smatch match; + + static const boost::regex r1("\\*:(\\d+)", boost::regex_constants::perl); + if(boost::regex_match(str, match, r1)) { + return boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), std::atoi(match[1].str().c_str())); + } + + static const boost::regex r2("(.+):(\\d+)", boost::regex_constants::perl); + if(boost::regex_match(str, match, r2)) { + return boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(match[1].str()), std::atoi(match[2].str().c_str())); + } + + return boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(str), DEFAULT_PORT); +} + void ConnectionManager::updateState(Common::HostInfo *hostInfo, Common::HostInfo::State state) { hostInfo->setState(state); @@ -89,7 +110,7 @@ bool ConnectionManager::handleConfigEntry(const Core::ConfigEntry &entry, bool h if(entry[0].getKey().matches("Listen") && entry[1].empty()) { try { - listenerAddresses.push_back(boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(entry[0][0]), 6666)); + listenerAddresses.push_back(parseAddress(entry[0][0])); } catch(Core::Exception &e) { // TODO Log error @@ -136,9 +157,11 @@ bool ConnectionManager::handleConfigEntry(const Core::ConfigEntry &entry, bool h } void ConnectionManager::configFinished() { - if(listenerAddresses.empty()) { + if(listenerAddresses.empty()) + listenerAddresses.push_back(parseAddress("*")); + for(std::vector::const_iterator address = listenerAddresses.begin(); address != listenerAddresses.end(); ++address) { try { - boost::shared_ptr listener(new Net::Listener(application, x509CertFile, x509KeyFile)); + boost::shared_ptr listener(new Net::Listener(application, x509CertFile, x509KeyFile, *address)); listener->connectSignalNewConnection(boost::bind(&ConnectionManager::handleNewConnection, this, _1)); listeners.push_back(listener); } @@ -146,18 +169,6 @@ void ConnectionManager::configFinished() { // TODO Log error } } - else { - for(std::vector::const_iterator address = listenerAddresses.begin(); address != listenerAddresses.end(); ++address) { - try { - boost::shared_ptr listener(new Net::Listener(application, x509CertFile, x509KeyFile, *address)); - listener->connectSignalNewConnection(boost::bind(&ConnectionManager::handleNewConnection, this, _1)); - listeners.push_back(listener); - } - catch(Core::Exception &e) { - // TODO Log error - } - } - } } void ConnectionManager::handleNewConnection(boost::shared_ptr con) { diff --git a/src/Server/ConnectionManager.h b/src/Server/ConnectionManager.h index 6e3603b..5f41afa 100644 --- a/src/Server/ConnectionManager.h +++ b/src/Server/ConnectionManager.h @@ -109,6 +109,8 @@ class ConnectionManager : public Core::Configurable, private boost::noncopyable boost::shared_ptr daemonRequestHandlerGroup; boost::shared_ptr userRequestHandlerGroup; + static boost::asio::ip::tcp::endpoint parseAddress(const std::string &str); + void updateState(Common::HostInfo *hostInfo, Common::HostInfo::State state); void handleNewConnection(boost::shared_ptr con); -- cgit v1.2.3