# HG changeset patch # User David Demelier # Date 1455279314 -3600 # Node ID f113796cfbf95150f629a751926179f4e84bbdcc # Parent 73b7d6dbe5762c0bc677d275a23a0af5e91e514a Irccd: fix compilation with WITH_JS=Off, #415 diff -r 73b7d6dbe576 -r f113796cfbf9 CMakeLists.txt --- 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) diff -r 73b7d6dbe576 -r f113796cfbf9 doc/html/CMakeLists.txt --- 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) diff -r 73b7d6dbe576 -r f113796cfbf9 irccd/command-plugin-info.cpp --- 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 } diff -r 73b7d6dbe576 -r f113796cfbf9 irccd/command-plugin-list.cpp --- 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 } diff -r 73b7d6dbe576 -r f113796cfbf9 irccd/command-plugin-load.cpp --- 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 } diff -r 73b7d6dbe576 -r f113796cfbf9 irccd/command-plugin-reload.cpp --- 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 } diff -r 73b7d6dbe576 -r f113796cfbf9 irccd/command-plugin-unload.cpp --- 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 } diff -r 73b7d6dbe576 -r f113796cfbf9 irccd/config.cpp --- 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 diff -r 73b7d6dbe576 -r f113796cfbf9 irccd/irccd.cpp --- 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(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) diff -r 73b7d6dbe576 -r f113796cfbf9 irccd/irccd.h --- 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 #include -#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 name; std::function exec; +#endif }; class TransportEvent { diff -r 73b7d6dbe576 -r f113796cfbf9 irccd/server.cpp --- 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("\xff""\xff""Server-proto"); } +#endif + } // !irccd diff -r 73b7d6dbe576 -r f113796cfbf9 tests/CMakeLists.txt --- 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 ()