diff options
author | Adam <Adam@anope.org> | 2012-02-22 18:12:02 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-02-22 18:12:02 -0500 |
commit | 3850b073ddf610415de54dced9ff134397779676 (patch) | |
tree | c1a464fba432a7a79535fac4c05cc46f8f19901e /modules/extra/m_regex_pcre.cpp | |
parent | 81e50dd1f404c9bad008fe1b569dad134df91125 (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_pcre.cpp')
-rw-r--r-- | modules/extra/m_regex_pcre.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/modules/extra/m_regex_pcre.cpp b/modules/extra/m_regex_pcre.cpp new file mode 100644 index 000000000..998a7692d --- /dev/null +++ b/modules/extra/m_regex_pcre.cpp @@ -0,0 +1,55 @@ +/* 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) anope_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, SUPPORTED), + pcre_regex_provider(this) + { + this->SetAuthor("Anope"); + this->SetPermanent(true); + } +}; + +MODULE_INIT(ModuleRegexPCRE) |