diff options
author | aquanight <aquanight@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-09-05 17:37:02 +0000 |
---|---|---|
committer | aquanight <aquanight@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-09-05 17:37:02 +0000 |
commit | 1a1cdd989a95e55ee41eed6976fc62b31fd26a2a (patch) | |
tree | 4ea01ef98425e3bde27e777fdee1bc192e73b13e /src/modules | |
parent | 739c665e2cd75584f3711d7570cebafde4878fd7 (diff) |
Framework for central regex module, and a bare-bone implementation based on InspIRCd::Match().
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10395 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/extra/m_regex.h | 63 | ||||
-rw-r--r-- | src/modules/extra/m_regex_glob.cpp | 66 |
2 files changed, 129 insertions, 0 deletions
diff --git a/src/modules/extra/m_regex.h b/src/modules/extra/m_regex.h new file mode 100644 index 000000000..361d54831 --- /dev/null +++ b/src/modules/extra/m_regex.h @@ -0,0 +1,63 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd: (C) 2002-2008 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + +#ifndef _REGEX_H +#define _REGEX_H + +#include "inspircd.h" + +class Regex : public classbase +{ +protected: + std::string regex_string; // The raw uncompiled regex string. + InspIRCd* ServerInstance; + + // Constructor may as well be protected, as this class is abstract. + Regex(const std::string& rx, InspIRCd* Me) : regex_string(rx), ServerInstance(Me) + { + } + +public: + + virtual ~Regex() + { + } + + virtual bool Matches(const std::string& text) = 0; +}; + +class RegexFactoryRequest : public Request +{ +private: + std::string regex; + +public: + RegexFactoryRequest(Module* Me, Module* Target, const std::string& rx) : Request(Me, Target, "REGEX"), regex(rx) + { + } + + const std::string& GetRegex() const + { + return regex; + } +}; + +class RegexNameRequest : public Request +{ +public: + RegexNameRequest(Module* Me, Module* Target) : Request(Me, Target, "REGEX-NAME") + { + } +}; + +#endif diff --git a/src/modules/extra/m_regex_glob.cpp b/src/modules/extra/m_regex_glob.cpp new file mode 100644 index 000000000..8d81b9a03 --- /dev/null +++ b/src/modules/extra/m_regex_glob.cpp @@ -0,0 +1,66 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd: (C) 2002-2008 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + +#include "m_regex.h" +#include "inspircd.h" + +/* $ModDesc: Regex module using plain wildcard matching. */ +/* $ModDep: m_regex.h */ + +class GlobRegex : public Regex +{ +public: + GlobRegex(const std::string& rx, InspIRCd* Me) : Regex(rx, Me) + { + } + + virtual ~GlobRegex() + { + } + + virtual bool Matches(const std::string& text) + { + return InspIRCd::Match(this->regex_string, text); + } +}; + +class ModuleRegexGlob : public Module +{ +public: + ModuleRegexGlob(InspIRCd* Me) : Module(Me) + { + Me->Modules->PublishInterface("RegularExpression", this); + Implementation eventlist[] = { I_OnRequest }; + Me->Modules->Attach(eventlist, this, 1); + } + + virtual ~ModuleRegexGlob() + { + ServerInstance->Modules->UnpublishInterface("RegularExpression", this); + } + + virtual const char* OnRequest(Request* request) + { + if (strcmp("REGEX-NAME", request->GetId()) == 0) + { + return "glob"; + } + else if (strcmp("REGEX", request->GetId()) == 0) + { + RegexFactoryRequest* rfr = (RegexFactoryRequest*)request; + std::string rx = rfr->GetRegex(); + Regex* rxo = (Regex*)new GlobRegex(rx, ServerInstance); // Cast to base class first, since theoretically the pointer could change by that. + return (const char*)(rxo); + } + } +}; |