aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp
diff options
context:
space:
mode:
authorDmytro Ivanov <[email protected]>2024-10-02 15:07:03 +0200
committerDmytro Ivanov <[email protected]>2024-10-02 15:46:41 +0200
commit634d01ac6993a63f31eadb26ac49128ae01f9860 (patch)
treebd406b0957d3910d42f14f5ce3febcd68d192466 /src/zenhttp
parentadd cmake build config to be able to use clion (diff)
downloadzen-di/plugin-name-wip.tar.xz
zen-di/plugin-name-wip.zip
Add plugin name command line parameterdi/plugin-name-wip
Make it possible to load commandline provided plugins
Diffstat (limited to 'src/zenhttp')
-rw-r--r--src/zenhttp/httpserver.cpp4
-rw-r--r--src/zenhttp/include/zenhttp/httpserver.h1
-rw-r--r--src/zenhttp/servers/httpplugin.cpp5
-rw-r--r--src/zenhttp/transports/dlltransport.cpp44
-rw-r--r--src/zenhttp/transports/dlltransport.h1
5 files changed, 54 insertions, 1 deletions
diff --git a/src/zenhttp/httpserver.cpp b/src/zenhttp/httpserver.cpp
index a0d4ef3f3..8e12f3ec7 100644
--- a/src/zenhttp/httpserver.cpp
+++ b/src/zenhttp/httpserver.cpp
@@ -843,6 +843,10 @@ CreateHttpServerClass(HttpServerClass Class, const HttpServerConfig& Config)
Server->AddPlugin(DllPlugin);
# endif
+# if 1
+ DllPlugin->LoadDll(Config.PluginName);
+#endif
+
return Server;
}
#endif
diff --git a/src/zenhttp/include/zenhttp/httpserver.h b/src/zenhttp/include/zenhttp/httpserver.h
index 7b87cb84b..d680f8057 100644
--- a/src/zenhttp/include/zenhttp/httpserver.h
+++ b/src/zenhttp/include/zenhttp/httpserver.h
@@ -190,6 +190,7 @@ struct HttpServerConfig
std::string ServerClass; // Choice of HTTP server implementation
bool ForceLoopback = false;
unsigned int ThreadCount = 0;
+ std::string PluginName;
struct
{
diff --git a/src/zenhttp/servers/httpplugin.cpp b/src/zenhttp/servers/httpplugin.cpp
index 09cd76f3e..84cd71a48 100644
--- a/src/zenhttp/servers/httpplugin.cpp
+++ b/src/zenhttp/servers/httpplugin.cpp
@@ -300,7 +300,10 @@ HttpPluginConnectionHandler::OnBytesRead(const void* Buffer, size_t AvailableByt
{
ZEN_ASSERT(m_Server);
- ZEN_LOG_TRACE(m_Server->m_RequestLog, "connection #{} OnBytesRead: {}", m_ConnectionId, AvailableBytes);
+ if (AvailableBytes > 0)
+ {
+ ZEN_LOG_TRACE(m_Server->m_RequestLog, "connection #{} OnBytesRead: {}", m_ConnectionId, AvailableBytes);
+ }
while (AvailableBytes)
{
diff --git a/src/zenhttp/transports/dlltransport.cpp b/src/zenhttp/transports/dlltransport.cpp
index e09e62ec5..91d27a49b 100644
--- a/src/zenhttp/transports/dlltransport.cpp
+++ b/src/zenhttp/transports/dlltransport.cpp
@@ -43,6 +43,7 @@ public:
virtual bool IsAvailable() override;
virtual void LoadDll(std::string_view Name) override;
+ virtual void LoadDll(std::string_view Name, std::string_view Path) override;
virtual void ConfigureDll(std::string_view Name, const char* OptionTag, const char* OptionValue) override;
private:
@@ -181,6 +182,49 @@ DllTransportPluginImpl::LoadDll(std::string_view Name)
m_Transports.emplace_back(std::move(NewDll));
}
+void
+DllTransportPluginImpl::LoadDll(std::string_view Name, std::string_view Path)
+{
+ RwLock::ExclusiveLockScope _(m_Lock);
+
+ ExtendableStringBuilder<256> DllPath;
+ DllPath << Path;
+ if (!Path.ends_with('\\'))
+ {
+ DllPath << '\\';
+ }
+ DllPath << Name << ".dll";
+
+ HMODULE DllHandle = LoadLibraryA(DllPath.c_str());
+
+ if (!DllHandle)
+ {
+ std::error_code Ec = MakeErrorCodeFromLastError();
+
+ throw std::system_error(Ec, fmt::format("failed to load transport DLL from '{}'", DllPath));
+ }
+
+ TransportPlugin* CreateTransportPlugin();
+
+ PfnCreateTransportPlugin CreatePlugin = (PfnCreateTransportPlugin)GetProcAddress(DllHandle, "CreateTransportPlugin");
+
+ if (!CreatePlugin)
+ {
+ std::error_code Ec = MakeErrorCodeFromLastError();
+
+ FreeLibrary(DllHandle);
+
+ throw std::system_error(Ec, fmt::format("API mismatch detected in transport DLL loaded from '{}'", DllPath));
+ }
+
+ LoadedDll NewDll;
+ NewDll.Name = Name;
+ NewDll.LoadedFromPath = DllPath.c_str();
+ NewDll.Plugin = CreatePlugin();
+
+ m_Transports.emplace_back(std::move(NewDll));
+}
+
DllTransportPlugin*
CreateDllTransportPlugin()
{
diff --git a/src/zenhttp/transports/dlltransport.h b/src/zenhttp/transports/dlltransport.h
index 9346a10ce..21985bac8 100644
--- a/src/zenhttp/transports/dlltransport.h
+++ b/src/zenhttp/transports/dlltransport.h
@@ -16,6 +16,7 @@ class DllTransportPlugin : public TransportPlugin
{
public:
virtual void LoadDll(std::string_view Name) = 0;
+ virtual void LoadDll(std::string_view Name, std::string_view Path) = 0;
virtual void ConfigureDll(std::string_view Name, const char* OptionTag, const char* OptionValue) = 0;
};