summaryrefslogtreecommitdiffhomepage
path: root/plugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugin.cpp')
-rw-r--r--plugin.cpp48
1 files changed, 40 insertions, 8 deletions
diff --git a/plugin.cpp b/plugin.cpp
index 9c47ed2..c0a01fc 100644
--- a/plugin.cpp
+++ b/plugin.cpp
@@ -1,21 +1,22 @@
#include "plugin.h"
#include <boost/dll/import.hpp>
-#include <boost/shared_ptr.hpp>
#include <boost/filesystem.hpp>
#include <iostream>
#include <filesystem>
-#include "plugin_interface.h"
-
namespace dll = boost::dll;
namespace fs = std::filesystem;
using namespace std::string_literals;
-void load_plugins(Config& config)
+PluginLoader::PluginLoader(Config& config): m_config{config}
+{
+}
+
+void PluginLoader::load_plugins()
{
- const auto& plugin_directories{config.PluginDirectories()};
+ const auto& plugin_directories{m_config.PluginDirectories()};
for (const auto& dir: plugin_directories) {
for (auto& path: fs::recursive_directory_iterator(dir)) {
@@ -23,14 +24,45 @@ void load_plugins(Config& config)
dll::fs::path lib_path{path.path()};
+ try {
boost::shared_ptr<webserver_plugin_interface> plugin = dll::import<webserver_plugin_interface>(lib_path, "webserver_plugin", dll::load_mode::append_decorations);
- if (!plugin)
- throw std::runtime_error("Can't load plugin");
+ 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::cout << "Plugin: " << plugin->generate_page("a") << std::endl;
+ 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;
+ } catch (const std::exception& ex) {
+ std::cout << "Can't load plugin from " << path.path().generic_string() << ": " << ex.what() << std::endl;
+ }
}
}
}
}
+bool PluginLoader::validate_config()
+{
+ const auto& sites{m_config.Sites()};
+
+ for (const auto& site: sites) {
+ for (const auto& path: site.paths) {
+ if (path.type == Plugin) {
+ std::string plugin {path.params.at("plugin")};
+
+ if (!m_plugins.contains(plugin)) {
+ std::cout << "Configured plugin " << plugin << " not found" << std::endl;
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+}
+