changeset 18:f113796cfbf9

Irccd: fix compilation with WITH_JS=Off, #415
author David Demelier <markand@malikania.fr>
date Fri, 12 Feb 2016 13:15:14 +0100
parents 73b7d6dbe576
children 6b8ca778e589
files CMakeLists.txt doc/html/CMakeLists.txt irccd/command-plugin-info.cpp irccd/command-plugin-list.cpp irccd/command-plugin-load.cpp irccd/command-plugin-reload.cpp irccd/command-plugin-unload.cpp irccd/config.cpp irccd/irccd.cpp irccd/irccd.h irccd/server.cpp tests/CMakeLists.txt
diffstat 12 files changed, 168 insertions(+), 81 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Fri Feb 12 12:40:01 2016 +0100
+++ b/CMakeLists.txt	Fri Feb 12 13:15:14 2016 +0100
@@ -72,7 +72,10 @@
 add_subdirectory(irccd)
 add_subdirectory(irccdctl)
 add_subdirectory(contrib)
-add_subdirectory(plugins)
+
+if (WITH_JS)
+	add_subdirectory(plugins)
+endif ()
 
 # Platform specific.
 if (WIN32)
--- a/doc/html/CMakeLists.txt	Fri Feb 12 12:40:01 2016 +0100
+++ b/doc/html/CMakeLists.txt	Fri Feb 12 13:15:14 2016 +0100
@@ -22,5 +22,8 @@
 add_subdirectory(resources)
 
 # JavaScript API and user guide
-add_subdirectory(api)
+if (WITH_JS)
+	add_subdirectory(api)
+endif ()
+
 add_subdirectory(guide)
--- a/irccd/command-plugin-info.cpp	Fri Feb 12 12:40:01 2016 +0100
+++ b/irccd/command-plugin-info.cpp	Fri Feb 12 13:15:14 2016 +0100
@@ -38,6 +38,10 @@
 
 	tc.send(result.toJson(0));
 #else
+	(void)irccd;
+	(void)tc;
+	(void)object;
+
 	throw std::runtime_error("JavaScript disabled");
 #endif
 }
--- a/irccd/command-plugin-list.cpp	Fri Feb 12 12:40:01 2016 +0100
+++ b/irccd/command-plugin-list.cpp	Fri Feb 12 13:15:14 2016 +0100
@@ -46,6 +46,9 @@
 
 	tc.send(oss.str());
 #else
+	(void)irccd;
+	(void)tc;
+
 	throw std::runtime_error("JavaScript disabled");
 #endif
 }
--- a/irccd/command-plugin-load.cpp	Fri Feb 12 12:40:01 2016 +0100
+++ b/irccd/command-plugin-load.cpp	Fri Feb 12 13:15:14 2016 +0100
@@ -32,6 +32,10 @@
 	irccd.loadPlugin(name, name, true);
 	tc.ok("plugin-load");
 #else
+	(void)irccd;
+	(void)tc;
+	(void)object;
+
 	throw std::runtime_error("JavaScript disabled");
 #endif
 }
--- a/irccd/command-plugin-reload.cpp	Fri Feb 12 12:40:01 2016 +0100
+++ b/irccd/command-plugin-reload.cpp	Fri Feb 12 13:15:14 2016 +0100
@@ -32,6 +32,10 @@
 	irccd.requirePlugin(name)->onReload();
 	tc.ok("plugin-reload");
 #else
+	(void)irccd;
+	(void)tc;
+	(void)object;
+
 	throw std::runtime_error("JavaScript disabled");
 #endif
 }
--- a/irccd/command-plugin-unload.cpp	Fri Feb 12 12:40:01 2016 +0100
+++ b/irccd/command-plugin-unload.cpp	Fri Feb 12 13:15:14 2016 +0100
@@ -32,6 +32,10 @@
 	irccd.unloadPlugin(name);
 	tc.ok("plugin-unload");
 #else
+	(void)irccd;
+	(void)tc;
+	(void)object;
+
 	throw std::runtime_error("JavaScript disabled");
 #endif
 }
--- a/irccd/config.cpp	Fri Feb 12 12:40:01 2016 +0100
+++ b/irccd/config.cpp	Fri Feb 12 13:15:14 2016 +0100
@@ -155,6 +155,7 @@
 
 void Config::loadPlugins(Irccd &irccd, const ini::Section &sc) const
 {
+#if defined(WITH_JS)
 	for (const ini::Option &option : sc) {
 		try {
 			if (option.value().empty())
@@ -165,20 +166,31 @@
 			log::warning() << "plugin " << option.key() << ": " << ex.what() << std::endl;
 		}
 	}
+#else
+	(void)irccd;
+	(void)sc;
+#endif
 }
 
 void Config::loadPluginConfig(Irccd &irccd, const ini::Section &sc, string name) const
 {
+#if defined(WITH_JS)
 	PluginConfig config;
 
 	for (const ini::Option &option : sc)
 		config.emplace(option.key(), option.value());
 
 	irccd.addPluginConfig(std::move(name), std::move(config));
+#else
+	(void)irccd;
+	(void)sc;
+	(void)name;
+#endif
 }
 
 void Config::loadPlugins(Irccd &irccd, const ini::Document &config) const
 {
+#if defined(WITH_JS)
 	std::regex regex("^plugin\\.([A-Za-z0-9-_]+)$");
 	std::smatch match;
 
@@ -194,6 +206,12 @@
 
 	if (it != config.end())
 		loadPlugins(irccd, *it);
+#else
+	(void)irccd;
+	(void)config;
+
+	log::warning() << "irccd: JavaScript disabled, ignoring plugins" << std::endl;
+#endif
 }
 
 void Config::loadServer(Irccd &irccd, const ini::Section &sc) const
--- a/irccd/irccd.cpp	Fri Feb 12 12:40:01 2016 +0100
+++ b/irccd/irccd.cpp	Fri Feb 12 13:15:14 2016 +0100
@@ -54,13 +54,15 @@
 		{ "argument",	arg			}
 	});
 
-	postServerEvent({server->info().name, origin, channel, json.toJson(0),
-		[=] (Plugin &) -> std::string {
+	postServerEvent({server->info().name, origin, channel, json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &) -> std::string {
 			return "onChannelMode";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			plugin.onChannelMode(std::move(server), std::move(origin), std::move(channel), std::move(mode), std::move(arg));
 		}
+#endif
 	});
 }
 
@@ -84,13 +86,15 @@
 		{ "notice",	notice			}
 	});
 
-	postServerEvent({server->info().name, origin, channel, json.toJson(0),
-		[=] (Plugin &) -> std::string {
+	postServerEvent({server->info().name, origin, channel, json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &) -> std::string {
 			return "onChannelNotice";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			plugin.onChannelNotice(std::move(server), std::move(origin), std::move(channel), std::move(notice));
 		}
+#endif
 	});
 }
 
@@ -108,13 +112,15 @@
 		{ "server",	server->info().name	}
 	});
 
-	postServerEvent({server->info().name, /* origin */ "", /* channel */ "", json.toJson(0),
-		[=] (Plugin &) -> std::string {
+	postServerEvent({server->info().name, /* origin */ "", /* channel */ "", json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &) -> std::string {
 			return "onConnect";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			plugin.onConnect(std::move(server));
 		}
+#endif
 	});
 }
 
@@ -137,13 +143,15 @@
 		{ "channel",	channel			}
 	});
 
-	postServerEvent({server->info().name, origin, channel, json.toJson(0),
-		[=] (Plugin &) -> std::string {
+	postServerEvent({server->info().name, origin, channel, json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &) -> std::string {
 			return "onInvite";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			plugin.onInvite(std::move(server), std::move(origin), std::move(channel));
 		}
+#endif
 	});
 }
 
@@ -165,13 +173,15 @@
 		{ "channel",	channel			}
 	});
 
-	postServerEvent({server->info().name, origin, channel, json.toJson(0),
-		[=] (Plugin &) -> std::string {
+	postServerEvent({server->info().name, origin, channel, json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &) -> std::string {
 			return "onJoin";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			plugin.onJoin(std::move(server), std::move(origin), std::move(channel));
 		}
+#endif
 	});
 }
 
@@ -197,13 +207,15 @@
 		{ "reason",	reason			}
 	});
 
-	postServerEvent({server->info().name, origin, channel, json.toJson(0),
-		[=] (Plugin &) -> std::string {
+	postServerEvent({server->info().name, origin, channel, json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &) -> std::string {
 			return "onKick";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			plugin.onKick(std::move(server), std::move(origin), std::move(channel), std::move(target), std::move(reason));
 		}
+#endif
 	});
 }
 
@@ -227,19 +239,20 @@
 		{ "message",	message			}
 	});
 
-	postServerEvent({server->info().name, origin, channel, json.toJson(0),
-		[=] (Plugin &plugin) -> std::string {
+	postServerEvent({server->info().name, origin, channel, json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &plugin) -> std::string {
 			return util::parseMessage(message, server->settings().command, plugin.info().name).second == util::MessageType::Command ? "onCommand" : "onMessage";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			util::MessagePair pack = util::parseMessage(message, server->settings().command, plugin.info().name);
 
-			if (pack.second == util::MessageType::Command) {
+			if (pack.second == util::MessageType::Command)
 				plugin.onCommand(std::move(server), std::move(origin), std::move(channel), std::move(pack.first));
-			} else {
+			else
 				plugin.onMessage(std::move(server), std::move(origin), std::move(channel), std::move(pack.first));
-			}
 		}
+#endif
 	});
 }
 
@@ -263,13 +276,15 @@
 		{ "message",	message			}
 	});
 
-	postServerEvent({server->info().name, origin, target, json.toJson(0),
-		[=] (Plugin &) -> std::string {
+	postServerEvent({server->info().name, origin, target, json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &) -> std::string {
 			return "onMe";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			plugin.onMe(std::move(server), std::move(origin), std::move(target), std::move(message));
 		}
+#endif
 	});
 }
 
@@ -291,13 +306,15 @@
 		{ "mode",	mode			}
 	});
 
-	postServerEvent({server->info().name, origin, /* channel */ "", json.toJson(0),
-		[=] (Plugin &) -> std::string {
+	postServerEvent({server->info().name, origin, /* channel */ "", json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &) -> std::string {
 			return "onMode";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			plugin.onMode(std::move(server), std::move(origin), std::move(mode));
 		}
+#endif
 	});
 }
 
@@ -320,13 +337,15 @@
 		{ "names",	std::move(names)	}
 	});
 
-	postServerEvent({server->info().name, /* origin */ "", channel, json.toJson(0),
-		[=] (Plugin &) -> std::string {
+	postServerEvent({server->info().name, /* origin */ "", channel, json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &) -> std::string {
 			return "onNames";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			plugin.onNames(std::move(server), std::move(channel), std::vector<std::string>(nicknames.begin(), nicknames.end()));
 		}
+#endif
 	});
 }
 
@@ -348,13 +367,15 @@
 		{ "nickname",	nickname		}
 	});
 
-	postServerEvent({server->info().name, origin, /* channel */ "", json.toJson(0),
-		[=] (Plugin &) -> std::string {
+	postServerEvent({server->info().name, origin, /* channel */ "", json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &) -> std::string {
 			return "onNick";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			plugin.onNick(std::move(server), std::move(origin), std::move(nickname));
 		}
+#endif
 	});
 }
 
@@ -376,13 +397,15 @@
 		{ "notice",	message			}
 	});
 
-	postServerEvent({server->info().name, origin, /* channel */ "", json.toJson(0),
-		[=] (Plugin &) -> std::string {
+	postServerEvent({server->info().name, origin, /* channel */ "", json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &) -> std::string {
 			return "onNotice";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			plugin.onNotice(std::move(server), std::move(origin), std::move(message));
 		}
+#endif
 	});
 }
 
@@ -406,13 +429,15 @@
 		{ "reason",	reason			}
 	});
 
-	postServerEvent({server->info().name, origin, channel, json.toJson(0),
-		[=] (Plugin &) -> std::string {
+	postServerEvent({server->info().name, origin, channel, json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &) -> std::string {
 			return "onPart";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			plugin.onPart(std::move(server), std::move(origin), std::move(channel), std::move(reason));
 		}
+#endif
 	});
 }
 
@@ -434,19 +459,20 @@
 		{ "message",	message			}
 	});
 
-	postServerEvent({server->info().name, origin, /* channel */ "", json.toJson(0),
-		[=] (Plugin &plugin) -> std::string {
+	postServerEvent({server->info().name, origin, /* channel */ "", json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &plugin) -> std::string {
 			return util::parseMessage(message, server->settings().command, plugin.info().name).second == util::MessageType::Command ? "onQueryCommand" : "onQuery";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			util::MessagePair pack = util::parseMessage(message, server->settings().command, plugin.info().name);
 
-			if (pack.second == util::MessageType::Command) {
+			if (pack.second == util::MessageType::Command)
 				plugin.onQueryCommand(std::move(server), std::move(origin), std::move(pack.first));
-			} else {
+			else
 				plugin.onQuery(std::move(server), std::move(origin), std::move(pack.first));
-			}
 		}
+#endif
 	});
 }
 
@@ -470,13 +496,15 @@
 		{ "topic",	topic			}
 	});
 
-	postServerEvent({server->info().name, origin, channel, json.toJson(0),
-		[=] (Plugin &) -> std::string {
+	postServerEvent({server->info().name, origin, channel, json.toJson(0)
+#if defined(WITH_JS)
+		, [=] (Plugin &) -> std::string {
 			return "onTopic";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			plugin.onTopic(std::move(server), std::move(origin), std::move(channel), std::move(topic));
 		}
+#endif
 	});
 }
 
@@ -503,13 +531,15 @@
 		{ "channels",	""			}
 	});
 
-	postServerEvent({server->info().name, /* origin */ "", /* channel */ "", object.toJson(-1),
-		[=] (Plugin &) -> std::string {
+	postServerEvent({server->info().name, /* origin */ "", /* channel */ "", object.toJson(-1)
+#if defined(WITH_JS)
+		, [=] (Plugin &) -> std::string {
 			return "onWhois";
-		},
-		[=] (Plugin &plugin) {
+		}
+		, [=] (Plugin &plugin) {
 			plugin.onWhois(std::move(server), std::move(whois));
 		}
+#endif
 	});
 }
 
@@ -639,6 +669,7 @@
 
 void Irccd::postServerEvent(ServerEvent event) noexcept
 {
+#if defined(WITH_JS)
 	post([=] () {
 		for (auto &pair : m_plugins) {
 			auto name = event.name(*pair.second);
@@ -663,6 +694,7 @@
 			}
 		}
 	});
+#endif
 
 	/* Asynchronous send */
 	for (auto &pair : m_lookupTransportClients)
--- a/irccd/irccd.h	Fri Feb 12 12:40:01 2016 +0100
+++ b/irccd/irccd.h	Fri Feb 12 13:15:14 2016 +0100
@@ -32,7 +32,10 @@
 #include <logger.h>
 #include <sockets.h>
 
-#include "plugin.h"
+#if defined(WITH_JS)
+#  include "plugin.h"
+#endif
+
 #include "rule.h"
 #include "server.h"
 #include "transport-command.h"
@@ -40,6 +43,7 @@
 
 namespace irccd {
 
+class Plugin;
 class TransportCommand;
 
 /**
@@ -74,8 +78,10 @@
 	std::string origin;
 	std::string target;
 	std::string json;
+#if defined(WITH_JS)
 	std::function<std::string (Plugin &)> name;
 	std::function<void (Plugin &)> exec;
+#endif
 };
 
 class TransportEvent {
--- a/irccd/server.cpp	Fri Feb 12 12:40:01 2016 +0100
+++ b/irccd/server.cpp	Fri Feb 12 13:15:14 2016 +0100
@@ -436,9 +436,13 @@
 	irc_process_select_descriptors(m_session.get(), &setinput, &setoutput);
 }
 
+#if defined(WITH_JS)
+
 void Server::prototype(js::Context &ctx)
 {
 	ctx.getGlobal<void>("\xff""\xff""Server-proto");
 }
 
+#endif
+
 } // !irccd
--- a/tests/CMakeLists.txt	Fri Feb 12 12:40:01 2016 +0100
+++ b/tests/CMakeLists.txt	Fri Feb 12 13:15:14 2016 +0100
@@ -28,12 +28,14 @@
 	add_subdirectory(util)
 
 	# JS API
-	add_subdirectory(js-elapsedtimer)
-	add_subdirectory(js-file)
-	add_subdirectory(js-irccd)
-	add_subdirectory(js-logger)
-	add_subdirectory(js-system)
-	add_subdirectory(js-timer)
-	add_subdirectory(js-unicode)
-	add_subdirectory(js-util)
+	if (WITH_JS)
+		add_subdirectory(js-elapsedtimer)
+		add_subdirectory(js-file)
+		add_subdirectory(js-irccd)
+		add_subdirectory(js-logger)
+		add_subdirectory(js-system)
+		add_subdirectory(js-timer)
+		add_subdirectory(js-unicode)
+		add_subdirectory(js-util)
+	endif ()
 endif ()