]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_regex_posix.cpp
Merge pull request #92 from Robby-/insp20-headers
[user/henk/code/inspircd.git] / src / modules / extra / m_regex_posix.cpp
index ba653247a48dd262231a727f3b5ed6f8ec1c3b78..4cb1a03d57d5f8ae6f52a8cf92e11637f15f994d 100644 (file)
@@ -1,16 +1,23 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
  *
- * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #include "inspircd.h"
 #include "m_regex.h"
 #include <sys/types.h>
@@ -34,7 +41,7 @@ private:
        regex_t regbuf;
 
 public:
-       POSIXRegex(const std::string& rx, InspIRCd* Me, bool extended) : Regex(rx, Me)
+       POSIXRegex(const std::string& rx, bool extended) : Regex(rx)
        {
                int flags = (extended ? REG_EXTENDED : 0) | REG_NOSUB;
                int errcode;
@@ -71,49 +78,37 @@ public:
        }
 };
 
-class ModuleRegexPOSIX : public Module
+class PosixFactory : public RegexFactory
 {
-private:
+ public:
        bool extended;
-public:
-       ModuleRegexPOSIX(InspIRCd* Me) : Module(Me)
+       PosixFactory(Module* m) : RegexFactory(m, "regex/posix") {}
+       Regex* Create(const std::string& expr)
        {
-               Me->Modules->PublishInterface("RegularExpression", this);
-               Implementation eventlist[] = { I_OnRequest, I_OnRehash };
-               Me->Modules->Attach(eventlist, this, 2);
-               OnRehash(NULL, "");
-       }
-
-       virtual Version GetVersion()
-       {
-               return Version("$Id$", VF_COMMON | VF_VENDOR | VF_SERVICEPROVIDER, API_VERSION);
+               return new POSIXRegex(expr, extended);
        }
+};
 
-       virtual ~ModuleRegexPOSIX()
-       {
-               ServerInstance->Modules->UnpublishInterface("RegularExpression", this);
+class ModuleRegexPOSIX : public Module
+{
+       PosixFactory ref;
+public:
+       ModuleRegexPOSIX() : ref(this) {
+               ServerInstance->Modules->AddService(ref);
+               Implementation eventlist[] = { I_OnRehash };
+               ServerInstance->Modules->Attach(eventlist, this, 1);
+               OnRehash(NULL);
        }
 
-       virtual void OnRehash(User* u, const std::string& parameter)
+       Version GetVersion()
        {
-               ConfigReader Conf(ServerInstance);
-               extended = Conf.ReadFlag("posix", "extended", 0);
+               return Version("Regex Provider Module for POSIX Regular Expressions", VF_VENDOR);
        }
 
-       virtual const char* OnRequest(Request* request)
+       void OnRehash(User* u)
        {
-               if (strcmp("REGEX-NAME", request->GetId()) == 0)
-               {
-                       return "posix";
-               }
-               else if (strcmp("REGEX", request->GetId()) == 0)
-               {
-                       RegexFactoryRequest* rfr = (RegexFactoryRequest*)request;
-                       std::string rx = rfr->GetRegex();
-                       rfr->result = new POSIXRegex(rx, ServerInstance, extended);
-                       return "OK";
-               }
-               return NULL;
+               ConfigReader Conf;
+               ref.extended = Conf.ReadFlag("posix", "extended", 0);
        }
 };