]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_regex_glob.cpp
...because every now and again, i have to do a massive commit.
[user/henk/code/inspircd.git] / src / modules / m_regex_glob.cpp
index 7977c77f105c2555b44cf03b1885868efe76b043..a3d1b32ecf88a38f84b5fa9bbe7c76fa4e6e9726 100644 (file)
@@ -2,8 +2,8 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
  *          the file COPYING for details.
 #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)
+       GlobRegex(const std::string& rx) : Regex(rx)
        {
        }
 
@@ -30,38 +29,33 @@ public:
 
        virtual bool Matches(const std::string& text)
        {
-               return InspIRCd::Match(this->regex_string, text);
+               return InspIRCd::Match(text, this->regex_string);
        }
 };
 
-class ModuleRegexGlob : public Module
+class GlobFactory : public RegexFactory
 {
-public:
-       ModuleRegexGlob(InspIRCd* Me) : Module(Me)
+ public:
+       Regex* Create(const std::string& expr)
        {
-               Me->Modules->PublishInterface("RegularExpression", this);
-               Implementation eventlist[] = { I_OnRequest };
-               Me->Modules->Attach(eventlist, this, 1);
+               return new GlobRegex(expr);
        }
 
-       virtual ~ModuleRegexGlob()
-       {
-               ServerInstance->Modules->UnpublishInterface("RegularExpression", this);
+       GlobFactory(Module* m) : RegexFactory(m, "regex/glob") {}
+};
+
+class ModuleRegexGlob : public Module
+{
+       GlobFactory gf;
+public:
+       ModuleRegexGlob() : gf(this) {
+               ServerInstance->Modules->AddService(gf);
        }
 
-       virtual const char* OnRequest(Request* request)
+       Version GetVersion()
        {
-               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();
-                       rfr->result = (Regex*)new GlobRegex(rx, ServerInstance);
-                       return "OK";
-               }
-               return NULL;
+               return Version("Regex module using plain wildcard matching.", VF_OPTCOMMON | VF_VENDOR);
        }
 };
+
+MODULE_INIT(ModuleRegexGlob)