From 2f42619303627db401e469e2fd65123cd794a378 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Thu, 9 Apr 2020 11:38:48 +0200 Subject: Load only configured plugins, add plugins --- plugin.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'plugin.cpp') diff --git a/plugin.cpp b/plugin.cpp index c0a01fc..1da89cd 100644 --- a/plugin.cpp +++ b/plugin.cpp @@ -20,24 +20,31 @@ void PluginLoader::load_plugins() for (const auto& dir: plugin_directories) { for (auto& path: fs::recursive_directory_iterator(dir)) { - if (path.is_regular_file()) { + if (path.is_regular_file() && path.path().extension() == ".so"s) { dll::fs::path lib_path{path.path()}; try { - boost::shared_ptr plugin = dll::import(lib_path, "webserver_plugin", dll::load_mode::append_decorations); - if (plugin) { - if (plugin->version() != webserver_plugin_interface::interface_version) - throw std::runtime_error("Bad interface version for "s + path.path().generic_string() + ": "s + std::to_string(plugin->version()) + " vs. "s + std::to_string(webserver_plugin_interface::interface_version)); - - if (m_plugins.contains(plugin->name())) - throw std::runtime_error("Plugin already exists: "s + plugin->name()); - - m_plugins.emplace(plugin->name(), plugin); - - std::cout << "Found plugin: " << plugin->name() << std::endl; - } else - std::cout << "Can't load plugin from " << path.path().generic_string() << std::endl; + boost::shared_ptr plugin = dll::import(lib_path, "webserver_plugin", dll::load_mode::append_decorations); + if (plugin) { + if (plugin->version() != webserver_plugin_interface::interface_version) + throw std::runtime_error("Bad interface version for "s + path.path().generic_string() + ": "s + std::to_string(plugin->version()) + " vs. "s + std::to_string(webserver_plugin_interface::interface_version)); + + std::string name{plugin->name()}; + if (m_plugins.contains(name)) + throw std::runtime_error("Plugin already exists: "s + name); + + std::cout << "Found plugin: " << name << " (" << path.path().string() << "), "; + if (m_config.PluginIsConfigured(name)) { + std::cout << "loading."; + m_plugins.emplace(plugin->name(), plugin); + } else { + std::cout << "ignored (not configured)."; + } + std::cout << std::endl; + + } else + std::cout << "Can't load plugin from " << path.path().generic_string() << std::endl; } catch (const std::exception& ex) { std::cout << "Can't load plugin from " << path.path().generic_string() << ": " << ex.what() << std::endl; } -- cgit v1.2.3