diff options
Diffstat (limited to 'src/Server')
-rw-r--r-- | src/Server/ConnectionManager.cpp | 41 | ||||
-rw-r--r-- | src/Server/ConnectionManager.h | 2 |
2 files changed, 27 insertions, 16 deletions
diff --git a/src/Server/ConnectionManager.cpp b/src/Server/ConnectionManager.cpp index 96f383a..8fe6408 100644 --- a/src/Server/ConnectionManager.cpp +++ b/src/Server/ConnectionManager.cpp @@ -71,31 +71,42 @@ void* ConnectionManager::ServerConnection::getPeerCertificate(size_t *size) cons return cert->data; }*/ -boost::asio::ip::tcp::endpoint ConnectionManager::parseAddress(const std::string &str) { - // TODO IPv6 +boost::asio::ip::tcp::endpoint ConnectionManager::parseAddress(const std::string &str) throw(Core::Exception) { + try { + if(str == "*") + return boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), DEFAULT_PORT); - if(str == "*") - return boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), DEFAULT_PORT); + boost::smatch match; - 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::v6(), std::atoi(match[1].str().c_str())); - 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_v6::from_string(match[1].str()), + std::atoi(match[2].str().c_str())); + + static const boost::regex r3("\\[(.+)\\]", boost::regex_constants::perl); + if(boost::regex_match(str, match, r3)) + return boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v6::from_string(match[1].str()), DEFAULT_PORT); - 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())); + static const boost::regex r4("((?:\\d{1,3}\\.){3}\\d{1,3}):(\\d+)", boost::regex_constants::perl); + if(boost::regex_match(str, match, r4)) + return boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4::from_string(match[1].str()), std::atoi(match[2].str().c_str())); + + static const boost::regex r5("((?:\\d{1,3}\\.){3}\\d{1,3})", boost::regex_constants::perl); + if(boost::regex_match(str, match, r5)) + return boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4::from_string(match[1].str()), DEFAULT_PORT); } + catch(...) {} - return boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(str), DEFAULT_PORT); + throw Core::Exception(Core::Exception::INVALID_INPUT); } void ConnectionManager::updateState(Common::HostInfo *hostInfo, Common::HostInfo::State state) { hostInfo->setState(state); - for(std::set<boost::shared_ptr<ServerConnection> >::iterator con = connections.begin(); con != connections.end(); ++con) { if((*con)->getConnectionType() == ServerConnection::CLIENT) { boost::shared_ptr<Requests::DaemonStateUpdateRequest> request(new Requests::DaemonStateUpdateRequest(application, hostInfo->getName(), state)); @@ -113,7 +124,7 @@ bool ConnectionManager::handleConfigEntry(const Core::ConfigEntry &entry, bool h listenerAddresses.push_back(parseAddress(entry[0][0])); } catch(Core::Exception &e) { - // TODO Log error + application->logf(Core::LoggerBase::WARNING, "ConnectionManager: Invalid listen address '%s'", entry[0][0].c_str()); } return true; diff --git a/src/Server/ConnectionManager.h b/src/Server/ConnectionManager.h index 5f41afa..6fc6013 100644 --- a/src/Server/ConnectionManager.h +++ b/src/Server/ConnectionManager.h @@ -109,7 +109,7 @@ class ConnectionManager : public Core::Configurable, private boost::noncopyable boost::shared_ptr<Common::RequestHandlerGroup> daemonRequestHandlerGroup; boost::shared_ptr<Common::RequestHandlerGroup> userRequestHandlerGroup; - static boost::asio::ip::tcp::endpoint parseAddress(const std::string &str); + static boost::asio::ip::tcp::endpoint parseAddress(const std::string &str) throw(Core::Exception); void updateState(Common::HostInfo *hostInfo, Common::HostInfo::State state); |