SNode.C
Loading...
Searching...
No Matches
SocketContextUpgradeFactorySelector.h
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "web/http/SocketContextUpgrade.h"
21
22#ifndef DOXYGEN_SHOULD_SKIP_THIS
23
24#include <map>
25#include <string> // IWYU pragma: export
26
27#endif /* DOXYGEN_SHOULD_SKIP_THIS */
28
29#ifndef WEB_HTTP_SOCKETCONTEXTUPGRADEFACTORYSELECTOR_H
30#define WEB_HTTP_SOCKETCONTEXTUPGRADEFACTORYSELECTOR_H
31
32namespace web::http {
33
34 template <typename SocketContextUpgradeFactoryT>
35 class SocketContextUpgradeFactorySelector {
36 public:
37 using SocketContextUpgradeFactory = SocketContextUpgradeFactoryT;
38 using Request = typename SocketContextUpgradeFactory::Request;
39 using Response = typename SocketContextUpgradeFactory::Response;
40
41 protected:
42 SocketContextUpgradeFactorySelector() = default;
43 virtual ~SocketContextUpgradeFactorySelector() = default;
44
45 private:
46 struct SocketContextPlugin {
47 SocketContextUpgradeFactory* socketContextUpgradeFactory;
48 void* handle = nullptr;
49 };
50
51 public:
52 virtual SocketContextUpgradeFactory* select(Request& req, Response& res) = 0;
53
54 bool add(SocketContextUpgradeFactory* socketContextUpgradeFactory);
55
56 void link(const std::string& socketContextUpgradeName, SocketContextUpgradeFactory* (*linkedPlugin)());
57
58 void allowDlOpen();
59
60 void unload(SocketContextUpgradeFactory* socketContextUpgradeFactory);
61
62 protected:
63 SocketContextUpgradeFactory* select(const std::string& socketContextUpgradeName);
64
65 virtual SocketContextUpgradeFactory* load(const std::string& socketContextUpgradeName) = 0;
66
67 SocketContextUpgradeFactory* load(const std::string& socketContextUpgradeName,
68 const std::string& socketContextUpgradeFactoryLibraryFile,
69 const std::string& socketContextUpgradeFactoryFunctionName);
70
71 bool add(SocketContextUpgradeFactory* socketContextUpgradeFactory, void* handler);
72
73 private:
74 std::map<std::string, SocketContextPlugin> socketContextUpgradePlugins;
75 std::map<std::string, SocketContextUpgradeFactory* (*) ()> linkedSocketContextUpgradePlugins;
76
77 bool onlyLinked = false;
78 };
79
80} // namespace web::http
81
82#endif // WEB_HTTP_SOCKETCONTEXTUPGRADEFACTORYSELECTOR_H
virtual void stop()=0
virtual void start()=0
Request & set(const std::string &field, const std::string &value, bool overwrite=true)
Definition Request.cpp:137
void onSourceEof() override
Definition Request.cpp:597
Request & cookie(const std::string &name, const std::string &value)
Definition Request.cpp:197
Request(Request &&) noexcept
Definition Request.cpp:59
void onSourceError(int errnum) override
Definition Request.cpp:605
std::string header(const std::string &field)
Definition Request.cpp:616
Request & sendFragment(const std::string &data)
Definition Request.cpp:390
bool sendFile(const std::string &file, const std::function< void(int errnum)> &onStatus, const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError)
Definition Request.cpp:352
Request & query(const std::string &key, const std::string &value)
Definition Request.cpp:211
bool upgrade(const std::string &url, const std::string &protocols, const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError)
Definition Request.cpp:279
void onSourceData(const char *chunk, std::size_t chunkLen) override
Definition Request.cpp:593
bool executeSendFragment(const char *chunk, std::size_t chunkLen)
Definition Request.cpp:537
const CiStringMap< std::string > & getQueries() const
Definition Request.cpp:620
const CiStringMap< std::string > & getCookies() const
Definition Request.cpp:628
Request & setTrailer(const std::string &field, const std::string &value, bool overwrite=true)
Definition Request.cpp:217
Request & cookie(const std::map< std::string, std::string > &cookies)
Definition Request.cpp:203
web::http::client::SocketContext * getSocketContext() const
Definition Request.cpp:632
void setMasterRequest(const std::shared_ptr< Request > &masterRequest)
Definition Request.cpp:91
Request & set(const std::map< std::string, std::string > &headers, bool overwrite=true)
Definition Request.cpp:183
Request & append(const std::string &field, const std::string &value)
Definition Request.cpp:125
Request & sendFragment(const char *chunk, std::size_t chunkLen)
Definition Request.cpp:380
bool send(const char *chunk, std::size_t chunkLen, const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError)
Definition Request.cpp:242
const CiStringMap< std::string > & getHeaders() const
Definition Request.cpp:624
Request & host(const std::string &hostFieldValue)
Definition Request.cpp:119
bool send(const std::string &chunk, const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError)
Definition Request.cpp:269
Request & type(const std::string &type)
Definition Request.cpp:191
bool end(const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError)
Definition Request.cpp:394
void deliverResponseParseError(const std::shared_ptr< Request > &request, const std::string &message)
Definition Request.cpp:562
bool executeSendFile(const std::string &file, const std::function< void(int)> &onStatus)
Definition Request.cpp:439
bool executeUpgrade(const std::string &url, const std::string &protocols)
Definition Request.cpp:481
#define to_hex_str(int_val)
Definition Request.cpp:49