SNode.C
Loading...
Searching...
No Matches
ConfigAddress.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/*
21 * MIT License
22 *
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated documentation files (the "Software"), to deal
25 * in the Software without restriction, including without limitation the rights
26 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 * copies of the Software, and to permit persons to whom the Software is
28 * furnished to do so, subject to the following conditions:
29 *
30 * The above copyright notice and this permission notice shall be included in
31 * all copies or substantial portions of the Software.
32 *
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39 * THE SOFTWARE.
40 */
41
42#ifndef NET_IN6_CONFIG_CONFIGADDRESS_H
43#define NET_IN6_CONFIG_CONFIGADDRESS_H
44
45#include "net/config/ConfigAddressLocal.h"
46#include "net/config/ConfigAddressRemote.h"
47#include "net/config/ConfigAddressReverse.h"
48#include "net/in6/SocketAddress.h"
49
50namespace net::config {
51 class ConfigInstance;
52}
53
54// IWYU pragma: no_include "net/config/ConfigAddress.hpp"
55
56#ifndef DOXYGEN_SHOULD_SKIP_THIS
57
58#include <cstdint>
59#include <string>
60
61namespace CLI {
62 class Option;
63} // namespace CLI
64
65#endif /* DOXYGEN_SHOULD_SKIP_THIS */
66
67namespace net::in6::config {
68
69 template <template <typename SocketAddressT> typename ConfigAddressTypeT>
70 class ConfigAddressReverse : public ConfigAddressTypeT<net::in6::SocketAddress> {
71 private:
72 using Super = ConfigAddressTypeT<SocketAddress>;
73
74 protected:
75 explicit ConfigAddressReverse(net::config::ConfigInstance* instance,
76 const std::string& addressOptionName,
77 const std::string& addressOptionDescription);
78
79 public:
80 SocketAddress getSocketAddress(const SocketAddress::SockAddr& sockAddr, SocketAddress::SockLen sockAddrLen);
81
82 ConfigAddressReverse& setNumericReverse(bool numeric = true);
83 bool getNumericReverse() const;
84
85 private:
86 CLI::Option* numericReverseOpt = nullptr;
87 };
88
89 template <template <typename SocketAddressT> typename ConfigAddressTypeT>
90 class ConfigAddress : public ConfigAddressTypeT<net::in6::SocketAddress> {
91 private:
92 using Super = ConfigAddressTypeT<SocketAddress>;
93
94 protected:
95 explicit ConfigAddress(net::config::ConfigInstance* instance,
96 const std::string& addressOptionName,
97 const std::string& addressOptionDescription);
98
99 private:
100 SocketAddress* init() final;
101
102 public:
103 using Super::getSocketAddress;
104 SocketAddress getSocketAddress(const SocketAddress::SockAddr& sockAddr, SocketAddress::SockLen sockAddrLen);
105
106 ConfigAddress& setSocketAddress(const SocketAddress& socketAddress);
107
108 ConfigAddress& setHost(const std::string& ipOrHostname);
109 std::string getHost() const;
110
111 ConfigAddress& setPort(uint16_t port);
112 uint16_t getPort() const;
113
114 ConfigAddress& setNumeric(bool numeric = true);
115 bool getNumeric() const;
116
117 ConfigAddress& setNumericReverse(bool numeric = true);
118 bool getNumericReverse() const;
119
120 protected:
121 ConfigAddress& setIpv4Mapped(bool ipv4Mapped = true);
122 bool getIpv4Mapped() const;
123
124 ConfigAddress& setAiFlags(int aiFlags);
125 int getAiFlags() const;
126
127 ConfigAddress& setAiSockType(int aiSocktype);
128 int getAiSockType() const;
129
130 ConfigAddress& setAiProtocol(int aiProtocol);
131 int getAiProtocol() const;
132
133 ConfigAddress& setHostRequired(bool required = true);
134 ConfigAddress& setPortRequired(bool required = true);
135
136 private:
137 CLI::Option* hostOpt = nullptr;
138 CLI::Option* portOpt = nullptr;
139 CLI::Option* numericOpt = nullptr;
140 CLI::Option* numericReverseOpt = nullptr;
141 CLI::Option* ipv4MappedOpt = nullptr;
142
143 int aiFlags = 0;
144 int aiSockType = 0;
145 int aiProtocol = 0;
146 };
147
148} // namespace net::in6::config
149
150extern template class net::config::ConfigAddress<net::in6::SocketAddress>;
151extern template class net::config::ConfigAddressLocal<net::in6::SocketAddress>;
152extern template class net::config::ConfigAddressRemote<net::in6::SocketAddress>;
153extern template class net::config::ConfigAddressReverse<net::in6::SocketAddress>;
154extern template class net::config::ConfigAddressBase<net::in6::SocketAddress>;
155extern template class net::in6::config::ConfigAddress<net::config::ConfigAddressLocal>;
156extern template class net::in6::config::ConfigAddress<net::config::ConfigAddressRemote>;
157extern template class net::in6::config::ConfigAddressReverse<net::config::ConfigAddressReverse>;
158
159#endif // NET_IN6_CONFIG_CONFIGADDRESS_H
#define APPLICATION(req, res)
Definition Router.h:68
Config & getConfig() const
Definition Socket.hpp:60
static constexpr int DISABLED
Definition State.h:56
static constexpr int ERROR
Definition State.h:57
std::string what() const
Definition State.cpp:114
static constexpr int FATAL
Definition State.h:58
static constexpr int OK
Definition State.h:55
void send(const std::string &chunk)
Definition Response.cpp:165
Response & status(int status)
Definition Response.cpp:113
WebAppT(const std::string &name)
Definition WebAppT.h:76
static void init(int argc, char *argv[])
Definition WebApp.cpp:56
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
Definition WebApp.cpp:60
friend class BasicAuthentication & BasicAuthentication(const std::string &userName, const std::string &password, const std::string &realm)
const std::string & getInstanceName() const
SocketAddress(uint16_t port)
SocketAddress & setHost(const std::string &ipOrHostname)
SocketAddress & setPort(uint16_t port)
void init(const Hints &hints={.aiFlags=0,.aiSockType=0,.aiProtocol=0})
std::string getCanonName() const
SocketAddress(const std::string &ipOrHostname)
std::string getHost() const
std::string toString(bool expanded=true) const override
std::shared_ptr< SocketAddrInfo > socketAddrInfo
SocketAddress(const std::string &ipOrHostname, uint16_t port)
SocketAddress(const SockAddr &sockAddr, SockLen sockAddrLen, bool numeric=true)
ConfigAddressReverse(net::config::ConfigInstance *instance, const std::string &addressOptionName, const std::string &addressOptionDescription)
ConfigAddressReverse & setNumericReverse(bool numeric=true)
SocketAddress getSocketAddress(const SocketAddress::SockAddr &sockAddr, SocketAddress::SockLen sockAddrLen)
ConfigAddress & setIpv4Mapped(bool ipv4Mapped=true)
ConfigAddress & setNumericReverse(bool numeric=true)
ConfigAddress & setAiFlags(int aiFlags)
ConfigAddress & setPortRequired(bool required=true)
SocketAddress getSocketAddress(const SocketAddress::SockAddr &sockAddr, SocketAddress::SockLen sockAddrLen)
ConfigAddress(net::config::ConfigInstance *instance, const std::string &addressOptionName, const std::string &addressOptionDescription)
ConfigAddress & setNumeric(bool numeric=true)
ConfigAddress & setPort(uint16_t port)
ConfigAddress & setSocketAddress(const SocketAddress &socketAddress)
SocketAddress * init() final
ConfigAddress & setHost(const std::string &ipOrHostname)
ConfigAddress & setAiSockType(int aiSocktype)
ConfigAddress & setHostRequired(bool required=true)
ConfigAddress & setAiProtocol(int aiProtocol)
PhysicalSocket(int type, int protocol)
PhysicalSocket(PhysicalSocket &&) noexcept=default
PhysicalSocketServer(PhysicalSocketServer &&) noexcept=default
PhysicalSocket(PhysicalSocket &&) noexcept=default
void listen(const std::string &ipOrHostname, uint16_t port, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
void listen(uint16_t port, int backlog, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
void listen(uint16_t port, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
void listen(const std::string &ipOrHostname, uint16_t port, int backlog, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
ConfigSocketServer & setDisableNagleAlgorithm(bool disableNagleAlgorithm=true)
ConfigSocketServer & setIPv6Only(bool iPv6Only=true)
ConfigSocketServer(net::config::ConfigInstance *instance)
ConfigSocketServer & setReusePort(bool reusePort=true)
ConfigSocketServer & setReuseAddress(bool reuseAddress=true)
int main(int argc, char *argv[])
Router getRouter(const std::string &webRoot)