irccd  3.0.3
rule.hpp
1 /*
2  * rule.hpp -- rule for server and channels
3  *
4  * Copyright (c) 2013-2019 David Demelier <markand@malikania.fr>
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef IRCCD_DAEMON_RULE_HPP
20 #define IRCCD_DAEMON_RULE_HPP
21 
27 #include <irccd/sysconfig.hpp>
28 
29 #include <cassert>
30 #include <set>
31 #include <string>
32 #include <system_error>
33 
34 namespace irccd::daemon {
35 
39 struct rule {
43  using set = std::set<std::string>;
44 
48  enum class action_type {
49  accept,
50  drop
51  };
52 
57  set events{};
58 
63 
72  auto match_set(const set& set, const std::string& value) const noexcept -> bool;
73 
84  auto match(std::string_view server,
85  std::string_view channel,
86  std::string_view origin,
87  std::string_view plugin,
88  std::string_view event) const noexcept -> bool;
89 };
90 
98 auto operator==(const rule& lhs, const rule& rhs) noexcept -> bool;
99 
107 auto operator!=(const rule& lhs, const rule& rhs) noexcept -> bool;
108 
112 class rule_error : public std::system_error {
113 public:
117  enum error {
119  no_error = 0,
120 
123 
126  };
127 
131  using system_error::system_error;
132 };
133 
139 auto rule_category() -> const std::error_category&;
140 
147 auto make_error_code(rule_error::error e) -> std::error_code;
148 
149 } // !irccd::daemon
150 
155 namespace std {
156 
157 template <>
158 struct is_error_code_enum<irccd::daemon::rule_error::error> : public std::true_type {
159 };
160 
161 } // !std
162 
167 #endif // !IRCCD_DAEMON_RULE_HPP
irccd::daemon::rule_error::error
error
Rule related errors.
Definition: rule.hpp:117
irccd::daemon::operator!=
auto operator!=(const rule &lhs, const rule &rhs) noexcept -> bool
irccd::daemon::rule::action
action_type action
Definition: rule.hpp:62
irccd::daemon::rule::action_type
action_type
Rule action type.
Definition: rule.hpp:48
irccd::daemon::rule::origins
set origins
The list of originators.
Definition: rule.hpp:55
irccd::daemon::operator==
auto operator==(const rule &lhs, const rule &rhs) noexcept -> bool
irccd::daemon::plugin
Abstract plugin.
Definition: plugin.hpp:61
irccd::daemon::rule_error::invalid_index
@ invalid_index
Definition: rule.hpp:125
irccd::daemon::event
std::variant< std::monostate, connect_event, disconnect_event, invite_event, join_event, kick_event, me_event, message_event, mode_event, names_event, nick_event, notice_event, part_event, topic_event, whois_event > event
Store all possible events.
Definition: server.hpp:247
irccd::daemon::rule::action_type::drop
@ drop
The event is dropped.
irccd::daemon::make_error_code
auto make_error_code(bot_error::error e) noexcept -> std::error_code
irccd::daemon::rule::set
std::set< std::string > set
Definition: rule.hpp:43
irccd::daemon::rule_error
Rule error.
Definition: rule.hpp:112
irccd::daemon::rule::servers
set servers
The list of servers.
Definition: rule.hpp:53
irccd::daemon::channel
A channel to join with an optional password.
Definition: server.hpp:63
irccd::daemon::rule::match
auto match(std::string_view server, std::string_view channel, std::string_view origin, std::string_view plugin, std::string_view event) const noexcept -> bool
irccd::daemon::rule::action_type::accept
@ accept
The event is accepted (default)
irccd::daemon::server
The class that connect to a IRC server.
Definition: server.hpp:256
irccd
Parent namespace.
Definition: acceptor.hpp:43
std
Definition: bot.hpp:253
irccd::daemon::rule::events
set events
The list of events.
Definition: rule.hpp:57
irccd::daemon::rule
Manage rule to activate or deactive events.
Definition: rule.hpp:39
irccd::daemon
Main irccd namespace.
Definition: bot.hpp:41
irccd::daemon::rule_error::invalid_action
@ invalid_action
Invalid rule index.
Definition: rule.hpp:122
irccd::daemon::rule_error::no_error
@ no_error
No error.
Definition: rule.hpp:119
irccd::daemon::rule::match_set
auto match_set(const set &set, const std::string &value) const noexcept -> bool
irccd::daemon::rule_category
auto rule_category() -> const std::error_category &
irccd::daemon::rule::channels
set channels
The list of channels.
Definition: rule.hpp:54
irccd::daemon::rule::plugins
set plugins
The list of plugins.
Definition: rule.hpp:56