changeset 19:6b8ca778e589

Irccd: fix usage without SSL, #416
author David Demelier <markand@malikania.fr>
date Fri, 12 Feb 2016 13:51:42 +0100
parents f113796cfbf9
children 8384df86e195
files irccd/command-server-connect.cpp irccd/config.cpp irccd/server-state.cpp
diffstat 3 files changed, 36 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/irccd/command-server-connect.cpp	Fri Feb 12 13:15:14 2016 +0100
+++ b/irccd/command-server-connect.cpp	Fri Feb 12 13:51:42 2016 +0100
@@ -76,7 +76,12 @@
 	info.port = readInfoPort(object);
 
 	if (object.valueOr("ssl", json::Type::Boolean, false).toBool())
+#if defined(WITH_SSL)
 		info.flags |= ServerInfo::Ssl;
+#else
+		throw std::invalid_argument("ssl is disabled");
+#endif
+
 	if (object.valueOr("sslVerify", json::Type::Boolean, false).toBool())
 		info.flags |= ServerInfo::SslVerify;
 
--- a/irccd/config.cpp	Fri Feb 12 13:15:14 2016 +0100
+++ b/irccd/config.cpp	Fri Feb 12 13:51:42 2016 +0100
@@ -224,17 +224,17 @@
 	ini::Section::const_iterator it;
 
 	if ((it = sc.find("name")) == sc.end()) 
-		throw invalid_argument("missing name");
+		throw std::invalid_argument("server: missing name");
 	else if (!util::isIdentifierValid(it->value()))
-		throw invalid_argument("name is not valid");
+		throw std::invalid_argument("server " + it->value() + ": name is not valid");
 	else if (irccd.hasServer(it->value()))
-		throw invalid_argument("server already exists");
+		throw std::invalid_argument("server " + it->value() + ": already exists");
 
 	info.name = it->value();
 
 	/* Host */
 	if ((it = sc.find("host")) == sc.end())
-		throw invalid_argument("missing host");
+		throw std::invalid_argument("server " + info.name + ": missing host");
 
 	info.host = it->value();
 
@@ -245,9 +245,9 @@
 	/* Optional port */
 	if ((it = sc.find("port")) != sc.end()) {
 		try {
-			info.port = stoi(it->value());
+			info.port = std::stoi(it->value());
 		} catch (const std::exception &) {
-			log::warning() << "irccd: invalid port number: " << it->value() << std::endl;
+			throw std::invalid_argument("server " + info.name + ": invalid port number: " + it->value());
 		}
 	}
 
@@ -258,10 +258,21 @@
 	/* Optional flags */
 	if ((it = sc.find("ipv6")) != sc.end() && util::isBoolean(it->value()))
 		info.flags |= ServerInfo::Ipv6;
-	if ((it = sc.find("ssl")) != sc.end() && util::isBoolean(it->value()))
-		info.flags |= ServerInfo::Ssl;
-	if ((it = sc.find("ssl-verify")) != sc.end() && util::isBoolean(it->value()))
-		info.flags |= ServerInfo::SslVerify;
+	if ((it = sc.find("ssl")) != sc.end())
+		if (util::isBoolean(it->value()))
+#if defined(WITH_SSL)
+			info.flags |= ServerInfo::Ssl;
+#else
+			throw std::invalid_argument("server " + info.name + ": ssl is disabled");
+#endif
+
+	if ((it = sc.find("ssl-verify")) != sc.end())
+		if (util::isBoolean(it->value()))
+#if defined(WITH_SSL)
+			info.flags |= ServerInfo::SslVerify;
+#else
+			throw std::invalid_argument("server " + info.name + ": ssl is disabled");
+#endif
 
 	/* Options */
 	if ((it = sc.find("auto-rejoin")) != sc.end() && util::isBoolean(it->value()))
@@ -271,17 +282,17 @@
 
 	/* Channels */
 	if ((it = sc.find("channels")) != sc.end()) {
-		for (const string &s : *it) {
+		for (const std::string &s : *it) {
 			ServerChannel channel;
 
-			if (auto pos = s.find(":") != string::npos) {
+			if (auto pos = s.find(":") != std::string::npos) {
 				channel.name = s.substr(0, pos);
 				channel.password = s.substr(pos + 1);
 			} else {
 				channel.name = s;
 			}
 
-			settings.channels.push_back(move(channel));
+			settings.channels.push_back(std::move(channel));
 		}
 	}
 	if ((it = sc.find("command-char")) != sc.end())
@@ -290,14 +301,14 @@
 	/* Reconnect */
 	try {
 		if ((it = sc.find("reconnect-tries")) != sc.end())
-			settings.recotries = stoi(it->value());
+			settings.recotries = std::stoi(it->value());
 		if ((it = sc.find("reconnect-timeout")) != sc.end())
-			settings.recotimeout = stoi(it->value());
+			settings.recotimeout = std::stoi(it->value());
 	} catch (const std::exception &) {
-		log::warning() << "irccd: invalid number for " << it->key() << ": " << it->value() << std::endl;
+		throw std::invalid_argument("server " + info.name + ": invalid number for " + it->key() + ": " + it->value());
 	}
 
-	irccd.addServer(make_shared<Server>(move(info), move(identity), move(settings)));
+	irccd.addServer(std::make_shared<Server>(std::move(info), std::move(identity), std::move(settings)));
 }
 
 void Config::loadServers(Irccd &irccd, const ini::Document &config) const
@@ -307,7 +318,7 @@
 			try {
 				loadServer(irccd, section);
 			} catch (const exception &ex) {
-				log::warning() << "server: " << ex.what() << endl;
+				log::warning() << ex.what() << endl;
 			}
 		}
 	}
--- a/irccd/server-state.cpp	Fri Feb 12 13:15:14 2016 +0100
+++ b/irccd/server-state.cpp	Fri Feb 12 13:51:42 2016 +0100
@@ -41,10 +41,12 @@
 	int code;
 
 	/* libircclient requires # for SSL connection */
+#if defined(WITH_SSL)
 	if (info.flags & ServerInfo::Ssl)
 		host.insert(0, 1, '#');
 	if (!(info.flags & ServerInfo::SslVerify))
 		irc_option_set(server.session(), LIBIRC_OPTION_SSL_NO_VERIFY);
+#endif
 
 	if (info.flags & ServerInfo::Ipv6) {
 		code = irc_connect6(server.session(), host.c_str(), info.port, password,