3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
43#include "core/DynamicLoader.h"
44#include "web/http/SocketContextUpgradeFactorySelector.h"
46#ifndef DOXYGEN_SHOULD_SKIP_THIS
48#include "log/Logger.h"
49#include "web/http/http_utils.h"
59 template <
typename SocketContextUpgradeFactory>
64 if (socketContextUpgradeFactory !=
nullptr) {
65 SocketContextPlugin socketContextPlugin = {.socketContextUpgradeFactory = socketContextUpgradeFactory, .handle = handle};
72 template <
typename SocketContextUpgradeFactory>
74 return add(socketContextUpgradeFactory,
nullptr);
77 template <
typename SocketContextUpgradeFactory>
82 template <
typename SocketContextUpgradeFactory>
83 SocketContextUpgradeFactory*
85 const std::string& socketContextUpgradeFactoryLibraryFile,
86 const std::string& socketContextUpgradeFactoryFunctionName) {
87 SocketContextUpgradeFactory* socketContextUpgradeFactory =
nullptr;
89 void* handle = core::DynamicLoader::
dlOpen(socketContextUpgradeFactoryLibraryFile);
91 if (handle !=
nullptr) {
92 SocketContextUpgradeFactory* (*getSocketContextUpgradeFactory)() =
reinterpret_cast<SocketContextUpgradeFactory* (*) ()>(
95 if (getSocketContextUpgradeFactory !=
nullptr) {
96 socketContextUpgradeFactory = getSocketContextUpgradeFactory();
98 if (socketContextUpgradeFactory !=
nullptr) {
99 if (add(socketContextUpgradeFactory, handle)) {
100 LOG(DEBUG) <<
"HTTP: SocketContextUpgradeFactory created successful: " << socketContextUpgradeName;
102 LOG(DEBUG) <<
"HTTP: UpgradeSocketContext already existing. Not using: " << socketContextUpgradeName;
103 delete socketContextUpgradeFactory;
104 socketContextUpgradeFactory =
nullptr;
108 LOG(ERROR) <<
"HTTP: SocketContextUpgradeFactory not created: " << socketContextUpgradeName;
112 LOG(ERROR) <<
"HTTP: Optaining function \"" << socketContextUpgradeFactoryFunctionName
118 return socketContextUpgradeFactory;
121 template <
typename SocketContextUpgradeFactory>
122 SocketContextUpgradeFactory*
124 SocketContextUpgradeFactory* socketContextUpgradeFactory =
nullptr;
130 add(socketContextUpgradeFactory);
132 socketContextUpgradeFactory = load(socketContextUpgradeName);
135 return socketContextUpgradeFactory;
138 template <
typename SocketContextUpgradeFactory>
140 SocketContextUpgradeFactory* (*linkedPlugin)()) {
148 template <
typename SocketContextUpgradeFactory>
151 std::string upgradeContextNames = socketContextUpgradeFactory->name();
157 delete socketContextUpgradeFactory;
159 if (socketContextPlugin.handle !=
nullptr) {
static int dlClose(void *handle)
static void * dlSym(void *handle, const std::string &symbol)
static void dlCloseDelayed(void *handle)
void link(const std::string &socketContextUpgradeName, SocketContextUpgradeFactory *(*linkedPlugin)())
bool add(SocketContextUpgradeFactory *socketContextUpgradeFactory, void *handler)
std::map< std::string, SocketContextUpgradeFactory *(*)()> linkedSocketContextUpgradePlugins
SocketContextUpgradeFactory * select(const std::string &socketContextUpgradeName)
void unload(SocketContextUpgradeFactory *socketContextUpgradeFactory)
SocketContextUpgradeFactory * load(const std::string &socketContextUpgradeName, const std::string &socketContextUpgradeFactoryLibraryFile, const std::string &socketContextUpgradeFactoryFunctionName)
bool add(SocketContextUpgradeFactory *socketContextUpgradeFactory)
std::map< std::string, SocketContextPlugin > socketContextUpgradePlugins
void prepare(Request &request, Response &response)
const std::string & get(const std::string &key, int i=0) const
SocketContextUpgradeFactory * select(Request &req, Response &res) override
SocketContextUpgradeFactory * load(const std::string &socketContextUpgradeName) override
static SocketContextUpgradeFactorySelector * instance()
SocketContextUpgradeFactory * select(const std::string &protocols, Request &req)
virtual void prepare(Request &request)=0
std::string::iterator to_lower(std::string &string)
std::pair< std::string, std::string > str_split(const std::string &base, char c_middle)
std::string & str_trimm(std::string &text)