summaryrefslogtreecommitdiffstats
path: root/src/Server/ConnectionManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Server/ConnectionManager.cpp')
-rw-r--r--src/Server/ConnectionManager.cpp43
1 files changed, 27 insertions, 16 deletions
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 <http://www.gnu.org/licenses/>.
*/
+#include <config.h>
#include "ConnectionManager.h"
#include "Application.h"
#include <Core/ConfigEntry.h>
@@ -25,7 +26,6 @@
#include <Common/RequestHandlers/FSInfoRequestHandler.h>
#include <Common/RequestHandlers/StatusRequestHandler.h>
#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<boost::asio::ip::tcp::endpoint>::const_iterator address = listenerAddresses.begin(); address != listenerAddresses.end(); ++address) {
try {
- boost::shared_ptr<Net::Listener> listener(new Net::Listener(application, x509CertFile, x509KeyFile));
+ boost::shared_ptr<Net::Listener> 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<boost::asio::ip::tcp::endpoint>::const_iterator address = listenerAddresses.begin(); address != listenerAddresses.end(); ++address) {
- try {
- boost::shared_ptr<Net::Listener> 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<Net::Connection> con) {