summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2014-04-02 13:06:48 -0400
committerAdam <Adam@anope.org>2014-04-02 13:08:14 -0400
commit52bc8e4bc799d38e92d38d497a2bd055950841bb (patch)
treeb80ea985f1adffa43ca046c014e3b81f9404db8d /modules
parentee133c03f206a7fab78a700b183fbc8684b9d6bf (diff)
Remove regex mods, use std::regex instead
Diffstat (limited to 'modules')
-rw-r--r--modules/commands/os_akill.cpp19
-rw-r--r--modules/commands/os_sxline.cpp40
-rw-r--r--modules/extra/m_regex_pcre.cpp54
-rw-r--r--modules/extra/m_regex_posix.cpp56
-rw-r--r--modules/extra/m_regex_tre.cpp57
-rw-r--r--modules/pseudoclients/operserv.cpp8
6 files changed, 20 insertions, 214 deletions
diff --git a/modules/commands/os_akill.cpp b/modules/commands/os_akill.cpp
index 44c8fb23d..81dd69ed2 100644
--- a/modules/commands/os_akill.cpp
+++ b/modules/commands/os_akill.cpp
@@ -122,29 +122,20 @@ class CommandOSAKill : public Command
if (mask[0] == '/' && mask[mask.length() - 1] == '/')
{
- const Anope::string &regexengine = Config->GetBlock("options")->Get<const Anope::string>("regexengine");
-
- if (regexengine.empty())
+ if (!Config->regex_flags)
{
source.Reply(_("Regex is disabled."));
return;
}
- ServiceReference<RegexProvider> provider("Regex", regexengine);
- if (!provider)
- {
- source.Reply(_("Unable to find regex engine %s."), regexengine.c_str());
- return;
- }
-
+ Anope::string stripped_mask = mask.substr(1, mask.length() - 2);
try
{
- Anope::string stripped_mask = mask.substr(1, mask.length() - 2);
- delete provider->Compile(stripped_mask);
+ std::regex(stripped_mask.str(), Config->regex_flags);
}
- catch (const RegexException &ex)
+ catch (const std::regex_error &ex)
{
- source.Reply("%s", ex.GetReason().c_str());
+ source.Reply("%s", ex.what());
return;
}
}
diff --git a/modules/commands/os_sxline.cpp b/modules/commands/os_sxline.cpp
index 87d8efe5d..20b937bb0 100644
--- a/modules/commands/os_sxline.cpp
+++ b/modules/commands/os_sxline.cpp
@@ -317,29 +317,20 @@ class CommandOSSNLine : public CommandOSSXLineBase
if (mask[0] == '/' && mask[mask.length() - 1] == '/')
{
- const Anope::string &regexengine = Config->GetBlock("options")->Get<const Anope::string>("regexengine");
-
- if (regexengine.empty())
+ if (!Config->regex_flags)
{
source.Reply(_("Regex is disabled."));
return;
}
- ServiceReference<RegexProvider> provider("Regex", regexengine);
- if (!provider)
- {
- source.Reply(_("Unable to find regex engine %s."), regexengine.c_str());
- return;
- }
-
+ Anope::string stripped_mask = mask.substr(1, mask.length() - 2);
try
{
- Anope::string stripped_mask = mask.substr(1, mask.length() - 2);
- delete provider->Compile(stripped_mask);
+ std::regex(stripped_mask.str(), Config->regex_flags);
}
- catch (const RegexException &ex)
+ catch (const std::regex_error &ex)
{
- source.Reply("%s", ex.GetReason().c_str());
+ source.Reply("%s", ex.what());
return;
}
}
@@ -446,7 +437,7 @@ class CommandOSSNLine : public CommandOSSXLineBase
"\002Note\002: because the realname mask may contain spaces, the\n"
"separator between it and the reason is a colon."));
const Anope::string &regexengine = Config->GetBlock("options")->Get<const Anope::string>("regexengine");
- if (!regexengine.empty())
+ if (Config->regex_flags && !regexengine.empty())
{
source.Reply(" ");
source.Reply(_("Regex matches are also supported using the %s engine.\n"
@@ -531,29 +522,20 @@ class CommandOSSQLine : public CommandOSSXLineBase
if (mask[0] == '/' && mask[mask.length() - 1] == '/')
{
- const Anope::string &regexengine = Config->GetBlock("options")->Get<const Anope::string>("regexengine");
-
- if (regexengine.empty())
+ if (!Config->regex_flags)
{
source.Reply(_("Regex is disabled."));
return;
}
- ServiceReference<RegexProvider> provider("Regex", regexengine);
- if (!provider)
- {
- source.Reply(_("Unable to find regex engine %s."), regexengine.c_str());
- return;
- }
-
+ Anope::string stripped_mask = mask.substr(1, mask.length() - 2);
try
{
- Anope::string stripped_mask = mask.substr(1, mask.length() - 2);
- delete provider->Compile(stripped_mask);
+ std::regex(stripped_mask.str(), Config->regex_flags);
}
- catch (const RegexException &ex)
+ catch (const std::regex_error &ex)
{
- source.Reply("%s", ex.GetReason().c_str());
+ source.Reply("%s", ex.what());
return;
}
}
diff --git a/modules/extra/m_regex_pcre.cpp b/modules/extra/m_regex_pcre.cpp
deleted file mode 100644
index a7c9d4ba8..000000000
--- a/modules/extra/m_regex_pcre.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/* RequiredLibraries: pcre */
-
-#include "module.h"
-#include <pcre.h>
-
-class PCRERegex : public Regex
-{
- pcre *regex;
-
- public:
- PCRERegex(const Anope::string &expr) : Regex(expr)
- {
- const char *error;
- int erroffset;
- this->regex = pcre_compile(expr.c_str(), PCRE_CASELESS, &error, &erroffset, NULL);
- if (!this->regex)
- throw RegexException("Error in regex " + expr + " at offset " + stringify(erroffset) + ": " + error);
- }
-
- ~PCRERegex()
- {
- pcre_free(this->regex);
- }
-
- bool Matches(const Anope::string &str)
- {
- return pcre_exec(this->regex, NULL, str.c_str(), str.length(), 0, 0, NULL, 0) > -1;
- }
-};
-
-class PCRERegexProvider : public RegexProvider
-{
- public:
- PCRERegexProvider(Module *creator) : RegexProvider(creator, "regex/pcre") { }
-
- Regex *Compile(const Anope::string &expression) override
- {
- return new PCRERegex(expression);
- }
-};
-
-class ModuleRegexPCRE : public Module
-{
- PCRERegexProvider pcre_regex_provider;
-
- public:
- ModuleRegexPCRE(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR),
- pcre_regex_provider(this)
- {
- this->SetPermanent(true);
- }
-};
-
-MODULE_INIT(ModuleRegexPCRE)
diff --git a/modules/extra/m_regex_posix.cpp b/modules/extra/m_regex_posix.cpp
deleted file mode 100644
index 933ee59af..000000000
--- a/modules/extra/m_regex_posix.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-#include "module.h"
-#include <sys/types.h>
-#include <regex.h>
-
-class POSIXRegex : public Regex
-{
- regex_t regbuf;
-
- public:
- POSIXRegex(const Anope::string &expr) : Regex(expr)
- {
- int err = regcomp(&this->regbuf, expr.c_str(), REG_EXTENDED | REG_NOSUB);
- if (err)
- {
- char buf[BUFSIZE];
- regerror(err, &this->regbuf, buf, sizeof(buf));
- regfree(&this->regbuf);
- throw RegexException("Error in regex " + expr + ": " + buf);
- }
- }
-
- ~POSIXRegex()
- {
- regfree(&this->regbuf);
- }
-
- bool Matches(const Anope::string &str)
- {
- return regexec(&this->regbuf, str.c_str(), 0, NULL, 0) == 0;
- }
-};
-
-class POSIXRegexProvider : public RegexProvider
-{
- public:
- POSIXRegexProvider(Module *creator) : RegexProvider(creator, "regex/posix") { }
-
- Regex *Compile(const Anope::string &expression) override
- {
- return new POSIXRegex(expression);
- }
-};
-
-class ModuleRegexPOSIX : public Module
-{
- POSIXRegexProvider posix_regex_provider;
-
- public:
- ModuleRegexPOSIX(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR),
- posix_regex_provider(this)
- {
- this->SetPermanent(true);
- }
-};
-
-MODULE_INIT(ModuleRegexPOSIX)
diff --git a/modules/extra/m_regex_tre.cpp b/modules/extra/m_regex_tre.cpp
deleted file mode 100644
index 0f5c0eaf7..000000000
--- a/modules/extra/m_regex_tre.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/* RequiredLibraries: tre */
-
-#include "module.h"
-#include <tre/regex.h>
-
-class TRERegex : public Regex
-{
- regex_t regbuf;
-
- public:
- TRERegex(const Anope::string &expr) : Regex(expr)
- {
- int err = regcomp(&this->regbuf, expr.c_str(), REG_EXTENDED | REG_NOSUB);
- if (err)
- {
- char buf[BUFSIZE];
- regerror(err, &this->regbuf, buf, sizeof(buf));
- regfree(&this->regbuf);
- throw RegexException("Error in regex " + expr + ": " + buf);
- }
- }
-
- ~TRERegex()
- {
- regfree(&this->regbuf);
- }
-
- bool Matches(const Anope::string &str)
- {
- return regexec(&this->regbuf, str.c_str(), 0, NULL, 0) == 0;
- }
-};
-
-class TRERegexProvider : public RegexProvider
-{
- public:
- TRERegexProvider(Module *creator) : RegexProvider(creator, "regex/tre") { }
-
- Regex *Compile(const Anope::string &expression) override
- {
- return new TRERegex(expression);
- }
-};
-
-class ModuleRegexTRE : public Module
-{
- TRERegexProvider tre_regex_provider;
-
- public:
- ModuleRegexTRE(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR),
- tre_regex_provider(this)
- {
- this->SetPermanent(true);
- }
-};
-
-MODULE_INIT(ModuleRegexTRE)
diff --git a/modules/pseudoclients/operserv.cpp b/modules/pseudoclients/operserv.cpp
index 885cfcc85..7b43436f7 100644
--- a/modules/pseudoclients/operserv.cpp
+++ b/modules/pseudoclients/operserv.cpp
@@ -41,7 +41,7 @@ class SGLineManager : public XLineManager
if (x->regex)
{
Anope::string uh = u->GetIdent() + "@" + u->host, nuhr = u->nick + "!" + uh + "#" + u->realname;
- return x->regex->Matches(uh) || x->regex->Matches(nuhr);
+ return std::regex_match(uh.str(), *x->regex) || std::regex_match(nuhr.str(), *x->regex);
}
if (!x->GetNick().empty() && !Anope::Match(u->nick, x->GetNick()))
@@ -111,7 +111,7 @@ class SQLineManager : public XLineManager
bool Check(User *u, const XLine *x) override
{
if (x->regex)
- return x->regex->Matches(u->nick);
+ return std::regex_match(u->nick.c_str(), *x->regex);
return Anope::Match(u->nick, x->mask);
}
@@ -122,7 +122,7 @@ class SQLineManager : public XLineManager
XLine *x = *it;
if (x->regex)
{
- if (x->regex->Matches(c->name))
+ if (std::regex_match(c->name.str(), *x->regex))
return x;
}
else if (Anope::Match(c->name, x->mask, false, true))
@@ -165,7 +165,7 @@ class SNLineManager : public XLineManager
bool Check(User *u, const XLine *x) override
{
if (x->regex)
- return x->regex->Matches(u->realname);
+ return std::regex_match(u->realname.str(), *x->regex);
return Anope::Match(u->realname, x->mask, false, true);
}
};