summaryrefslogtreecommitdiffstats
path: root/src/madc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/madc.cpp')
-rw-r--r--src/madc.cpp33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/madc.cpp b/src/madc.cpp
index 762aa03..1017912 100644
--- a/src/madc.cpp
+++ b/src/madc.cpp
@@ -34,6 +34,8 @@
#include "Client/Authenticators/ChallengeResponseAuthenticator.h"
#include "Client/Authenticators/PasswordAuthenticator.h"
+#include <boost/regex.hpp>
+
#include <iostream>
#ifdef EDITLINE_FOUND
@@ -48,11 +50,11 @@ using namespace Mad;
static void usage(const std::string &cmd) {
- std::cerr << "Usage: " << cmd << " address" << std::endl;
+ std::cerr << "Usage: " << cmd << " [host[:port]]" << std::endl;
}
int main(int argc, char *argv[]) {
- if(argc != 2) {
+ if(argc > 2) {
usage(argv[0]);
std::exit(1);
}
@@ -62,13 +64,31 @@ int main(int argc, char *argv[]) {
application.getConfigManager()->finish();
Common::ClientConnection *connection = new Common::ClientConnection(&application);
+ application.getRequestManager()->registerConnection(connection);
try {
- application.getRequestManager()->registerConnection(connection);
+ std::string server = "localhost", port = "6666";
+
+ if(argc == 2) {
+ server = argv[1];
+ }
- connection->connect(boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(argv[1]), 6666));
+ static const boost::regex r("(.+):(\\d+)", boost::regex_constants::perl);
+
+ boost::smatch match;
+ if(boost::regex_match(server, match, r)) {
+ server = match[1].str();
+ port = match[2].str();
+ }
- std::cerr << "Connecting to " << argv[1] << "..." << std::flush;
+ boost::asio::ip::tcp::resolver resolver(application.getIOService());
+ boost::asio::ip::tcp::resolver::query query(server, port);
+ boost::asio::ip::tcp::resolver::iterator entry = resolver.resolve(query);
+
+
+ connection->connect(entry->endpoint());
+
+ std::cerr << "Connecting to " << entry->host_name() << "..." << std::flush;
connection->waitWhileConnecting();
@@ -121,13 +141,12 @@ int main(int argc, char *argv[]) {
connection->waitWhileConnected();
application.getUserManager()->unregisterBackend(networkUserBackend);
-
- application.getRequestManager()->unregisterConnection(connection);
}
catch(Core::Exception &e) {
application.logf(Core::Logger::LOG_CRITICAL, "Error: %s", e.what());
}
+ application.getRequestManager()->unregisterConnection(connection);
delete connection;
return 0;