]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_filter.cpp
Merge pull request #92 from Robby-/insp20-headers
[user/henk/code/inspircd.git] / src / modules / m_filter.cpp
index 55ef734ba8095059a3b7fd4c285e89a2fa90877b..d2cffdb5dd8e712ae56a68846d0e424210b62704 100644 (file)
@@ -1,16 +1,25 @@
-/*       +------------------------------------+
- *       | 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) 2004, 2008 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
  *
- * 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 "xline.h"
 #include "m_regex.h"
@@ -139,7 +148,7 @@ class ModuleFilter : public Module
        std::vector<std::string> exemptfromfilter; // List of channel names excluded from filtering.
 
        ModuleFilter();
-
+       void init();
        ~ModuleFilter();
        ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
        FilterResult* FilterMatch(User* user, const std::string &text, int flags);
@@ -155,7 +164,7 @@ class ModuleFilter : public Module
        void OnSyncNetwork(Module* proto, void* opaque);
        void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata);
        ModResult OnStats(char symbol, User* user, string_list &results);
-       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line);
+       ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line);
        bool AppliesToMe(User* user, FilterResult* filter, int flags);
        void ReadFilters(ConfigReader &MyConf);
 };
@@ -165,7 +174,8 @@ CmdResult CommandFilter::Handle(const std::vector<std::string> &parameters, User
        if (parameters.size() == 1)
        {
                /* Deleting a filter */
-               if (static_cast<ModuleFilter&>(*creator).DeleteFilter(parameters[0]))
+               Module *me = creator;
+               if (static_cast<ModuleFilter *>(me)->DeleteFilter(parameters[0]))
                {
                        user->WriteServ("NOTICE %s :*** Removed filter '%s'", user->nick.c_str(), parameters[0].c_str());
                        ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(user) ? 'a' : 'A', std::string("FILTER: ")+user->nick+" removed filter '"+parameters[0]+"'");
@@ -212,7 +222,9 @@ CmdResult CommandFilter::Handle(const std::vector<std::string> &parameters, User
                        {
                                reason = parameters[3];
                        }
-                       std::pair<bool, std::string> result = static_cast<ModuleFilter&>(*creator).AddFilter(freeform, type, reason, duration, flags);
+                       
+                       Module *me = creator;
+                       std::pair<bool, std::string> result = static_cast<ModuleFilter *>(me)->AddFilter(freeform, type, reason, duration, flags);
                        if (result.first)
                        {
                                user->WriteServ("NOTICE %s :*** Added filter '%s', type '%s'%s%s, flags '%s', reason: '%s'", user->nick.c_str(), freeform.c_str(),
@@ -254,6 +266,10 @@ bool ModuleFilter::AppliesToMe(User* user, FilterResult* filter, int iflags)
 }
 
 ModuleFilter::ModuleFilter() : filtcommand(this), RegexEngine(this, "regex")
+{
+}
+
+void ModuleFilter::init()
 {
        ServerInstance->AddCommand(&filtcommand);
        Implementation eventlist[] = { I_OnPreCommand, I_OnStats, I_OnSyncNetwork, I_OnDecodeMetaData, I_OnUserPreMessage, I_OnUserPreNotice, I_OnRehash };
@@ -335,7 +351,7 @@ ModResult ModuleFilter::OnUserPreNotice(User* user,void* dest,int target_type, s
        return MOD_RES_PASSTHRU;
 }
 
-ModResult ModuleFilter::OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+ModResult ModuleFilter::OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
 {
        flags = 0;
        if (validated && IS_LOCAL(user))
@@ -437,6 +453,8 @@ void ModuleFilter::OnRehash(User* user)
                }
        }
        std::string newrxengine = "regex/" + MyConf.ReadValue("filteropts", "engine", 0);
+       if (newrxengine == "regex/")
+               newrxengine = "regex";
        if (RegexEngine.GetProvider() == newrxengine)
                return;
 
@@ -446,14 +464,14 @@ void ModuleFilter::OnRehash(User* user)
        RegexEngine.SetProvider(newrxengine);
        if (!RegexEngine)
        {
-               ServerInstance->SNO->WriteGlobalSno('a', "WARNING: Regex engine '%s' is not loaded - Filter functionality disabled until this is corrected.", RegexEngine.GetProvider().c_str());
+               ServerInstance->SNO->WriteGlobalSno('a', "WARNING: Regex engine '%s' is not loaded - Filter functionality disabled until this is corrected.", newrxengine.c_str());
        }
        ReadFilters(MyConf);
 }
 
 Version ModuleFilter::GetVersion()
 {
-       return Version("Text (spam) filtering", VF_VENDOR | VF_COMMON);
+       return Version("Text (spam) filtering", VF_VENDOR | VF_COMMON, RegexEngine ? RegexEngine->name : "");
 }