75 lines
1.6 KiB
C++
75 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include "ircmsg.hpp"
|
|
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <regex>
|
|
#include <string_view>
|
|
#include <utility>
|
|
#include <variant>
|
|
|
|
struct hs_database;
|
|
struct hs_scratch;
|
|
|
|
enum class SnoteTag
|
|
{
|
|
ClientConnecting,
|
|
ClientExiting,
|
|
RejectingKlined,
|
|
NickChange,
|
|
CreateChannel,
|
|
TemporaryKlineExpired,
|
|
PropagatedBanExpired,
|
|
DisconnectingKlined,
|
|
NewPropagatedKline,
|
|
NewTemporaryKline,
|
|
LoginAttempts,
|
|
PossibleFlooder,
|
|
Killed,
|
|
TooManyGlobalConnections,
|
|
SetVhostOnMarkedAccount,
|
|
IsNowOper,
|
|
NickCollision,
|
|
};
|
|
|
|
class SnoteMatch
|
|
{
|
|
SnoteTag tag_;
|
|
std::variant<std::pair<const std::regex &, std::string_view>, std::match_results<std::string_view::const_iterator>> components_;
|
|
|
|
public:
|
|
SnoteMatch(SnoteTag tag, const std::regex ®ex, std::string_view full)
|
|
: tag_{tag}
|
|
, components_{std::make_pair(std::ref(regex), full)}
|
|
{
|
|
}
|
|
|
|
auto get_tag() -> SnoteTag { return tag_; }
|
|
auto get_results() -> const std::match_results<std::string_view::const_iterator> &;
|
|
};
|
|
|
|
struct SnoteCore
|
|
{
|
|
struct DbDeleter
|
|
{
|
|
auto operator()(hs_database *db) const -> void;
|
|
};
|
|
|
|
struct ScratchDeleter
|
|
{
|
|
auto operator()(hs_scratch *scratch) const -> void;
|
|
};
|
|
|
|
/// @brief Database of server notice patterns
|
|
std::unique_ptr<hs_database, DbDeleter> db_;
|
|
|
|
/// @brief HyperScan scratch space
|
|
std::unique_ptr<hs_scratch, ScratchDeleter> scratch_;
|
|
|
|
SnoteCore();
|
|
auto match(const IrcMsg &msg) -> std::optional<SnoteMatch>;
|
|
};
|
|
|
|
extern SnoteCore snoteCore;
|