RESTinio
ip_blocker.hpp
Go to the documentation of this file.
1 /*
2  * RESTinio
3  */
4 
5 /*!
6  * @file
7  * @brief Stuff related to IP blockers.
8  *
9  * @since v.0.5.1
10  */
11 
12 #pragma once
13 
14 #include <restinio/common_types.hpp>
15 
16 namespace restinio
17 {
18 
19 namespace ip_blocker
20 {
21 
22 //
23 // inspection_result_t
24 //
25 /*!
26  * @brief Enumeration of result of inspecting new incoming connection.
27  *
28  * @since v.0.5.1
29  */
31 {
32  //! New connection is disabled and should be closed.
33  deny,
34  //! New connection is allowed to be processed further.
35  allow
36 };
37 
38 /*!
39  * @brief Shorthand for inspection_result_t::deny.
40  *
41  * @since v.0.5.1
42  */
43 inline constexpr inspection_result_t
44 deny() noexcept { return inspection_result_t::deny; }
45 
46 /*!
47  * @brief Shorthand for inspection_result_t::allow.
48  *
49  * @since v.0.5.1
50  */
51 inline constexpr inspection_result_t
52 allow() noexcept { return inspection_result_t::allow; }
53 
54 //
55 // incoming_info_t
56 //
57 /*!
58  * @brief An information about new incoming connection to be passed
59  * to IP-blocker object.
60  *
61  * @since v.0.5.1
62  */
64 {
66 
67 public :
68  //! Initializing constructor.
70  endpoint_t remote_endpoint )
72  {}
73 
74  //! Remote endpoint of the new connection.
76  remote_endpoint() const noexcept { return m_remote_endpoint; }
77 };
78 
79 //
80 // noop_ip_blocker_t
81 //
82 /*!
83  * @brief The default no-op IP-blocker.
84  *
85  * This type is used for ip_blocker_t trait by default.
86  *
87  * NOTE. When this type if used no calls to IP-blocker will be generated.
88  * It means that there won't be any performance penalties related to
89  * invoking of IP-blocker's inspect() method.
90  *
91  * @since v.0.5.1
92  */
94 {
95  // empty type by design.
96 };
97 
98 } /* namespace ip_blocker */
99 
100 } /* namespace restinio */
The default no-op IP-blocker.
Definition: ip_blocker.hpp:93
New connection is allowed to be processed further.
constexpr inspection_result_t allow() noexcept
Shorthand for inspection_result_t::allow.
Definition: ip_blocker.hpp:52
incoming_info_t(endpoint_t remote_endpoint)
Initializing constructor.
Definition: ip_blocker.hpp:69
New connection is disabled and should be closed.
inspection_result_t
Enumeration of result of inspecting new incoming connection.
Definition: ip_blocker.hpp:30
endpoint_t remote_endpoint() const noexcept
Remote endpoint of the new connection.
Definition: ip_blocker.hpp:76
An information about new incoming connection to be passed to IP-blocker object.
Definition: ip_blocker.hpp:63
constexpr inspection_result_t deny() noexcept
Shorthand for inspection_result_t::deny.
Definition: ip_blocker.hpp:44
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, optional_t< Value_Type > >::type opt_value(const Parameter_Container &params, string_view_t key)
Gets the value of a parameter specified by key wrapped in optional_t<Value_Type> if parameter exists ...
Definition: value_or.hpp:64