summaryrefslogtreecommitdiff
path: root/modules/extra/m_regex_tre.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-02-22 18:12:02 -0500
committerAdam <Adam@anope.org>2012-02-22 18:12:02 -0500
commit3850b073ddf610415de54dced9ff134397779676 (patch)
treec1a464fba432a7a79535fac4c05cc46f8f19901e /modules/extra/m_regex_tre.cpp
parent81e50dd1f404c9bad008fe1b569dad134df91125 (diff)
Added regex support for many commands, such as akill, sqline, snline,
all of the */list commands, etc. Also extended the ability of akill to match a full nick!user@host and real name of users.
Diffstat (limited to 'modules/extra/m_regex_tre.cpp')
-rw-r--r--modules/extra/m_regex_tre.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/modules/extra/m_regex_tre.cpp b/modules/extra/m_regex_tre.cpp
new file mode 100644
index 000000000..8cfbd3b18
--- /dev/null
+++ b/modules/extra/m_regex_tre.cpp
@@ -0,0 +1,58 @@
+/* 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) anope_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, SUPPORTED),
+ tre_regex_provider(this)
+ {
+ this->SetAuthor("Anope");
+ this->SetPermanent(true);
+ }
+};
+
+MODULE_INIT(ModuleRegexTRE)