diff options
| -rw-r--r-- | Makefile | 22 | ||||
| -rw-r--r-- | config.cpp | 15 | ||||
| -rw-r--r-- | config.h | 4 | ||||
| -rw-r--r-- | plugin.cpp | 36 | ||||
| -rw-r--r-- | plugin.h | 5 | ||||
| -rw-r--r-- | plugin_interface.h | 12 | ||||
| -rw-r--r-- | webserver.conf | 3 | ||||
| -rw-r--r-- | webserver.cpp | 3 | 
8 files changed, 89 insertions, 11 deletions
@@ -9,7 +9,7 @@ CXX=clang++  endif  ifeq ($(shell which $(CXX)),) -CXX=g++-9 +#CXX=g++-9  endif  ifeq ($(CXXFLAGS),) @@ -23,7 +23,7 @@ CXXFLAGS+= -Wall -I.  CXXFLAGS+= -pthread  ifeq ($(CXX),clang++-10) -CXXFLAGS+=-std=c++20 -stdlib=libc++ +CXXFLAGS+=-std=c++20 #-stdlib=libc++  else  CXXFLAGS+=-std=c++2a  endif @@ -39,16 +39,17 @@ LIBS=\  -lboost_filesystem \  -lboost_regex \  -lpthread \ --lssl -lcrypto +-lssl -lcrypto \ +-ldl  ifeq ($(CXX),clang++-10)  LIBS+= \  -fuse-ld=lld-10 \ --lc++ \ --lc++abi +-lstdc++ +#-lc++ \ +#-lc++abi  #-lc++fs -#-lstdc++ \ -#-lstdc++fs \ +#-lstdc++fs  else  LIBS+= \  -lstdc++ @@ -58,7 +59,8 @@ endif  PROGSRC=\      config.cpp \      http.cpp \ -    http_debian10.cpp +    http_debian10.cpp \ +    plugin.cpp  TESTSRC=\      test-webserver.cpp \ @@ -68,7 +70,7 @@ TESTSRC=\  SRC=$(PROGSRC) webserver.cpp -all: test-$(PROJECTNAME) $(PROJECTNAME) +all: $(PROJECTNAME) test-$(PROJECTNAME)  	./test-$(PROJECTNAME)  	./webserver -c webserver.conf @@ -126,8 +128,6 @@ zip: clean  	zip -r ../$(PROJECTNAME).zip *  	ls -l ../$(PROJECTNAME).zip - -  .PHONY: clean all zip install deb deb-src debs all $(DISTROS)  -include $(wildcard $(SRC:.cpp=.d)) @@ -102,6 +102,21 @@ std::string Config::Group() const   return m_group;  } +const std::vector<std::string>& Config::PluginDirectories() const +{ + return m_plugin_directories; +} + +const std::vector<Site>& Config::Sites() const +{ + return m_sites; +} + +const std::vector<Socket>& Config::Sockets() const +{ + return m_sockets; +} +  void Config::dump() const  {   std::cout << "=== Configuration ===========================" << std::endl; @@ -56,6 +56,10 @@ class Config    std::string User() const;    std::string Group() const; +  const std::vector<std::string>& PluginDirectories() const; +  const std::vector<Site>& Sites() const; +  const std::vector<Socket>& Sockets() const; +    void dump() const;  }; diff --git a/plugin.cpp b/plugin.cpp new file mode 100644 index 0000000..9c47ed2 --- /dev/null +++ b/plugin.cpp @@ -0,0 +1,36 @@ +#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) +{ + const auto& plugin_directories{config.PluginDirectories()}; + + for (const auto& dir: plugin_directories) { +  for (auto& path: fs::recursive_directory_iterator(dir)) { +   if (path.is_regular_file()) { + +    dll::fs::path lib_path{path.path()}; + +    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"); + +    std::cout << "Plugin: " << plugin->generate_page("a") << std::endl; +   } +  } + } + +} + diff --git a/plugin.h b/plugin.h new file mode 100644 index 0000000..1c88ff9 --- /dev/null +++ b/plugin.h @@ -0,0 +1,5 @@ +#pragma once + +#include "config.h" + +void load_plugins(Config& config); diff --git a/plugin_interface.h b/plugin_interface.h new file mode 100644 index 0000000..72da0b9 --- /dev/null +++ b/plugin_interface.h @@ -0,0 +1,12 @@ +#pragma once + +#include <boost/config.hpp> + +#include <string> + +class BOOST_SYMBOL_VISIBLE webserver_plugin_interface { +public: + virtual std::string generate_page(std::string path) = 0; + virtual ~webserver_plugin_interface(){} +}; + diff --git a/webserver.conf b/webserver.conf index 42bc383..91ea90b 100644 --- a/webserver.conf +++ b/webserver.conf @@ -1,8 +1,11 @@  <webserver>   <user>www-data</user>   <group>www-data</group> + <!--   <plugin-directory><a c="d">b<e>f</e></a>/usr/lib/webserver/plugins</plugin-directory>   <plugin-directory>/usr/local/lib/webserver/plugins</plugin-directory> + --> + <plugin-directory>plugins</plugin-directory>   <sites>    <site>     <name>antcom.de</name> diff --git a/webserver.cpp b/webserver.cpp index b079707..2574272 100644 --- a/webserver.cpp +++ b/webserver.cpp @@ -1,5 +1,6 @@  #include "config.h"  #include "http.h" +#include "plugin.h"  #include <exception>  #include <iostream> @@ -32,9 +33,11 @@ int main(int argc, char* argv[])   try {    Config config{config_filename}; +  load_plugins(config);    return http_server(argc, argv);   } catch (const std::exception& ex) {    std::cout << "Error: " << ex.what() << std::endl;    return 1;   }  } +  | 
