]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_regex_posix.cpp
Merge insp20
[user/henk/code/inspircd.git] / src / modules / extra / m_regex_posix.cpp
index 2c1295fd85ffd715505383eed6c9b9366aaa2f31..b5fddfab8f2c0e748aa35cb22fcc861bc2eeb90f 100644 (file)
 #include <sys/types.h>
 #include <regex.h>
 
-/* $ModDesc: Regex Provider Module for POSIX Regular Expressions */
-/* $ModDep: modules/regex.h */
-
-class POSIXRegexException : public ModuleException
-{
- public:
-       POSIXRegexException(const std::string& rx, const std::string& error)
-               : ModuleException("Error in regex " + rx + ": " + error)
-       {
-       }
-};
-
 class POSIXRegex : public Regex
 {
        regex_t regbuf;
@@ -57,23 +45,18 @@ class POSIXRegex : public Regex
                        error = errbuf;
                        delete[] errbuf;
                        regfree(&regbuf);
-                       throw POSIXRegexException(rx, error);
+                       throw RegexException(rx, error);
                }
        }
 
-       virtual ~POSIXRegex()
+       ~POSIXRegex()
        {
                regfree(&regbuf);
        }
 
-       virtual bool Matches(const std::string& text)
+       bool Matches(const std::string& text) CXX11_OVERRIDE
        {
-               if (regexec(&regbuf, text.c_str(), 0, NULL, 0) == 0)
-               {
-                       // Bang. :D
-                       return true;
-               }
-               return false;
+               return (regexec(&regbuf, text.c_str(), 0, NULL, 0) == 0);
        }
 };
 
@@ -82,7 +65,7 @@ class PosixFactory : public RegexFactory
  public:
        bool extended;
        PosixFactory(Module* m) : RegexFactory(m, "regex/posix") {}
-       Regex* Create(const std::string& expr)
+       Regex* Create(const std::string& expr) CXX11_OVERRIDE
        {
                return new POSIXRegex(expr, extended);
        }
@@ -95,18 +78,14 @@ class ModuleRegexPOSIX : public Module
  public:
        ModuleRegexPOSIX() : ref(this)
        {
-               ServerInstance->Modules->AddService(ref);
-               Implementation eventlist[] = { I_OnRehash };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
-               OnRehash(NULL);
        }
 
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Regex Provider Module for POSIX Regular Expressions", VF_VENDOR);
        }
 
-       void OnRehash(User* u)
+       void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                ref.extended = ServerInstance->Config->ConfValue("posix")->getBool("extended");
        }