diff options
| author | 2020-07-28 16:43:59 +0100 | |
|---|---|---|
| committer | 2020-07-28 19:22:59 +0100 | |
| commit | 1621a84f963c9fbfd61a52a85015fd8f2255dbf4 (patch) | |
| tree | de9f7fefa992a87319b62773d865a72b3d66a185 /src/modules/m_rline.cpp | |
| parent | Work around RE2 specifying -std=c++11 in its pkg-config file. (diff) | |
Rewrite the regex system from scratch.
* Move everything to the Regex namespace:
- Regex -> Regex::Pattern
- RegexException -> Regex::Exception
- RegexFactory -> Regex::Engine
* Add support for regex flags.
- Regex::OPT_CASE_INSENSITIVE performs case-insensitive matching.
* Add the Regex::EngineReference class as a friendly wrapper around
dynamic_reference_nocheck<Regex::Engine>.
* Add the Regex::SimpleEngine template class for automating the
implementation of regex factory classes.
* Use std::shared_ptr for Regex::Pattern objects instead of making
users manage memory manually.
Diffstat (limited to 'src/modules/m_rline.cpp')
| -rw-r--r-- | src/modules/m_rline.cpp | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/src/modules/m_rline.cpp b/src/modules/m_rline.cpp index ce271df23..eb152d7c0 100644 --- a/src/modules/m_rline.cpp +++ b/src/modules/m_rline.cpp @@ -46,7 +46,7 @@ class RLine : public XLine * @param regex Pattern to match with * @ */ - RLine(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& regexs, dynamic_reference<RegexFactory>& rxfactory) + RLine(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& regexs, Regex::EngineReference& rxfactory) : XLine(s_time, d, src, re, "R") , matchtext(regexs) { @@ -56,13 +56,6 @@ class RLine : public XLine regex = rxfactory->Create(regexs); } - /** Destructor - */ - ~RLine() - { - delete regex; - } - bool Matches(User* u) override { LocalUser* lu = IS_LOCAL(u); @@ -71,12 +64,12 @@ class RLine : public XLine const std::string host = u->nick + "!" + u->ident + "@" + u->GetRealHost() + " " + u->GetRealName(); const std::string ip = u->nick + "!" + u->ident + "@" + u->GetIPString() + " " + u->GetRealName(); - return (regex->Matches(host) || regex->Matches(ip)); + return (regex->IsMatch(host) || regex->IsMatch(ip)); } bool Matches(const std::string& compare) override { - return regex->Matches(compare); + return regex->IsMatch(compare); } void Apply(User* u) override @@ -104,7 +97,7 @@ class RLine : public XLine std::string matchtext; - Regex *regex; + Regex::PatternPtr regex; }; @@ -113,8 +106,8 @@ class RLine : public XLine class RLineFactory : public XLineFactory { public: - dynamic_reference<RegexFactory>& rxfactory; - RLineFactory(dynamic_reference<RegexFactory>& rx) : XLineFactory("R"), rxfactory(rx) + Regex::EngineReference& rxfactory; + RLineFactory(Regex::EngineReference& rx) : XLineFactory("R"), rxfactory(rx) { } @@ -226,18 +219,18 @@ class ModuleRLine , public Stats::EventListener { private: - dynamic_reference<RegexFactory> rxfactory; + Regex::EngineReference rxfactory; RLineFactory f; CommandRLine r; bool MatchOnNickChange; bool initing = true; - RegexFactory* factory; + Regex::Engine* factory; public: ModuleRLine() : Module(VF_VENDOR | VF_COMMON, "Adds the /RLINE command which allows server operators to prevent users matching a nickname!username@hostname+realname regular expression from connecting to the server.") , Stats::EventListener(this) - , rxfactory(this, "regex") + , rxfactory(this) , f(rxfactory) , r(this, f) { @@ -284,11 +277,7 @@ class ModuleRLine factory = rxfactory ? (rxfactory.operator->()) : NULL; - if (newrxengine.empty()) - rxfactory.SetProvider("regex"); - else - rxfactory.SetProvider("regex/" + newrxengine); - + rxfactory.SetEngine(newrxengine); if (!rxfactory) { if (newrxengine.empty()) |
