Loading src/plugin/PluginManager.cpp +10 −38 Changes for src/plugin/PluginManager.cpp: 10 added lines, 38 removed lines. Original line number Diff line number Diff line Loading @@ -34,10 +34,7 @@ void PluginManager::loadDirectory(const std::string &dir, const std::map<std::st void *handle = ::dlopen(path.c_str(), RTLD_NOW | RTLD_LOCAL); dlerror(); if (!handle) { std::cerr << "Failed to load plugin " << fname << ": " << ::dlerror() << std::endl; _errors.push_back(fname + ": " + std::string(::dlerror() ? ::dlerror() : "dlopen failed")); continue; } Loading @@ -54,6 +51,8 @@ void PluginManager::loadDirectory(const std::string &dir, const std::map<std::st continue; } if (abiFn() != PROXYPLUS_PLUGIN_ABI_VERSION) { std::cerr << "[plugin] skipping " << fname << ": ABI version mismatch (plugin=" << abiFn() << ", host=" << PROXYPLUS_PLUGIN_ABI_VERSION << ")" << std::endl; _errors.push_back(fname + ": ABI version mismatch (plugin=" + std::to_string(abiFn()) + ", host=" + std::to_string(PROXYPLUS_PLUGIN_ABI_VERSION) + ")"); ::dlclose(handle); Loading @@ -73,56 +72,29 @@ void PluginManager::loadDirectory(const std::string &dir, const std::map<std::st ::closedir(d); } namespace { template <typename Iface> std::vector<Iface *> collect(const std::vector<IPlugin *> &plugins) { std::vector<Iface *> out; for (auto *p : plugins) { if (auto *iface = dynamic_cast<Iface *>(p)) out.push_back(iface); } return out; } } // namespace std::vector<IHttpAuthPlugin *> PluginManager::httpAuthPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<IHttpAuthPlugin>(all); return collect<IHttpAuthPlugin>(); } std::vector<IHttpRequestFilterPlugin *> PluginManager::httpRequestFilterPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<IHttpRequestFilterPlugin>(all); return collect<IHttpRequestFilterPlugin>(); } std::vector<IHttpResponseFilterPlugin *> PluginManager::httpResponseFilterPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<IHttpResponseFilterPlugin>(all); return collect<IHttpResponseFilterPlugin>(); } std::vector<ISmtpConnectionCheckPlugin *> PluginManager::smtpConnectionCheckPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<ISmtpConnectionCheckPlugin>(all); return collect<ISmtpConnectionCheckPlugin>(); } std::vector<ISmtpSenderCheckPlugin *> PluginManager::smtpSenderCheckPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<ISmtpSenderCheckPlugin>(all); return collect<ISmtpSenderCheckPlugin>(); } std::vector<ISmtpRecipientCheckPlugin *> PluginManager::smtpRecipientCheckPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<ISmtpRecipientCheckPlugin>(all); return collect<ISmtpRecipientCheckPlugin>(); } std::vector<ISmtpContentCheckPlugin *> PluginManager::smtpContentCheckPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<ISmtpContentCheckPlugin>(all); return collect<ISmtpContentCheckPlugin>(); } std::vector<ICertificateProviderPlugin *> PluginManager::certificateProviderPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<ICertificateProviderPlugin>(all); return collect<ICertificateProviderPlugin>(); } } // namespace proxyplus::plugin src/plugin/PluginManager.h +9 −0 Changes for src/plugin/PluginManager.h: 9 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -42,6 +42,15 @@ private: void (*destroy)(IPlugin *) = nullptr; }; template <typename Iface> std::vector<Iface *> collect() const { std::vector<Iface *> out; for (auto &p : _plugins) { if (auto *iface = dynamic_cast<Iface *>(p.instance)) out.push_back(iface); } return out; } IPluginAuthFacade &_authFacade; std::vector<LoadedPlugin> _plugins; std::vector<std::string> _errors; Loading Loading
src/plugin/PluginManager.cpp +10 −38 Changes for src/plugin/PluginManager.cpp: 10 added lines, 38 removed lines. Original line number Diff line number Diff line Loading @@ -34,10 +34,7 @@ void PluginManager::loadDirectory(const std::string &dir, const std::map<std::st void *handle = ::dlopen(path.c_str(), RTLD_NOW | RTLD_LOCAL); dlerror(); if (!handle) { std::cerr << "Failed to load plugin " << fname << ": " << ::dlerror() << std::endl; _errors.push_back(fname + ": " + std::string(::dlerror() ? ::dlerror() : "dlopen failed")); continue; } Loading @@ -54,6 +51,8 @@ void PluginManager::loadDirectory(const std::string &dir, const std::map<std::st continue; } if (abiFn() != PROXYPLUS_PLUGIN_ABI_VERSION) { std::cerr << "[plugin] skipping " << fname << ": ABI version mismatch (plugin=" << abiFn() << ", host=" << PROXYPLUS_PLUGIN_ABI_VERSION << ")" << std::endl; _errors.push_back(fname + ": ABI version mismatch (plugin=" + std::to_string(abiFn()) + ", host=" + std::to_string(PROXYPLUS_PLUGIN_ABI_VERSION) + ")"); ::dlclose(handle); Loading @@ -73,56 +72,29 @@ void PluginManager::loadDirectory(const std::string &dir, const std::map<std::st ::closedir(d); } namespace { template <typename Iface> std::vector<Iface *> collect(const std::vector<IPlugin *> &plugins) { std::vector<Iface *> out; for (auto *p : plugins) { if (auto *iface = dynamic_cast<Iface *>(p)) out.push_back(iface); } return out; } } // namespace std::vector<IHttpAuthPlugin *> PluginManager::httpAuthPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<IHttpAuthPlugin>(all); return collect<IHttpAuthPlugin>(); } std::vector<IHttpRequestFilterPlugin *> PluginManager::httpRequestFilterPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<IHttpRequestFilterPlugin>(all); return collect<IHttpRequestFilterPlugin>(); } std::vector<IHttpResponseFilterPlugin *> PluginManager::httpResponseFilterPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<IHttpResponseFilterPlugin>(all); return collect<IHttpResponseFilterPlugin>(); } std::vector<ISmtpConnectionCheckPlugin *> PluginManager::smtpConnectionCheckPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<ISmtpConnectionCheckPlugin>(all); return collect<ISmtpConnectionCheckPlugin>(); } std::vector<ISmtpSenderCheckPlugin *> PluginManager::smtpSenderCheckPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<ISmtpSenderCheckPlugin>(all); return collect<ISmtpSenderCheckPlugin>(); } std::vector<ISmtpRecipientCheckPlugin *> PluginManager::smtpRecipientCheckPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<ISmtpRecipientCheckPlugin>(all); return collect<ISmtpRecipientCheckPlugin>(); } std::vector<ISmtpContentCheckPlugin *> PluginManager::smtpContentCheckPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<ISmtpContentCheckPlugin>(all); return collect<ISmtpContentCheckPlugin>(); } std::vector<ICertificateProviderPlugin *> PluginManager::certificateProviderPlugins() const { std::vector<IPlugin *> all; for (auto &p : _plugins) all.push_back(p.instance); return collect<ICertificateProviderPlugin>(all); return collect<ICertificateProviderPlugin>(); } } // namespace proxyplus::plugin
src/plugin/PluginManager.h +9 −0 Changes for src/plugin/PluginManager.h: 9 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -42,6 +42,15 @@ private: void (*destroy)(IPlugin *) = nullptr; }; template <typename Iface> std::vector<Iface *> collect() const { std::vector<Iface *> out; for (auto &p : _plugins) { if (auto *iface = dynamic_cast<Iface *>(p.instance)) out.push_back(iface); } return out; } IPluginAuthFacade &_authFacade; std::vector<LoadedPlugin> _plugins; std::vector<std::string> _errors; Loading