summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-08-06 23:41:04 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-08-06 23:41:04 +0200
commit94c00010a0280b8adc220377916a65b8dba08b62 (patch)
tree6a21a59277616b8d04dcb89da48f7ca79622e110
parent0d1a7cb65b7b0f5ecc8e3cd6fbabdebab7f47f7f (diff)
downloadmad-94c00010a0280b8adc220377916a65b8dba08b62.tar
mad-94c00010a0280b8adc220377916a65b8dba08b62.zip
Added IPv6 support
-rw-r--r--config.h.in2
-rw-r--r--src/Server/ConnectionManager.cpp41
-rw-r--r--src/Server/ConnectionManager.h2
3 files changed, 28 insertions, 17 deletions
diff --git a/config.h.in b/config.h.in
index 80e4694..5e7ba50 100644
--- a/config.h.in
+++ b/config.h.in
@@ -1,3 +1,3 @@
#define MODULE_SUFFIX "${CMAKE_SHARED_MODULE_SUFFIX}"
-#define DEFAULT_PORT 6666 \ No newline at end of file
+#define DEFAULT_PORT 6666
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);