]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/u_listmode.h
Fix mistakenly using Clang instead of GCC on older FreeBSD versions.
[user/henk/code/inspircd.git] / src / modules / u_listmode.h
index f7ab783cc04742c5430da998413ef477b6958981..a728eb8397e3c1a21552731bd585a762c79794b8 100644 (file)
@@ -1,16 +1,22 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@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/>.
  */
 
+
 #ifndef INSPIRCD_LISTMODE_PROVIDER
 #define INSPIRCD_LISTMODE_PROVIDER
 
@@ -94,8 +100,6 @@ class ListModeBase : public ModeHandler
                configtag(ctag), extItem("listbase_mode_" + name + "_list", Creator)
        {
                list = true;
-               this->DoRehash();
-               ServerInstance->Extensions.Register(&extItem);
        }
 
        /** See mode.h
@@ -182,35 +186,38 @@ class ListModeBase : public ModeHandler
         */
        virtual void DoRehash()
        {
-               ConfigReader Conf;
+               ConfigTagList tags = ServerInstance->Config->ConfTags(configtag);
 
                chanlimits.clear();
 
-               for (int i = 0; i < Conf.Enumerate(configtag); i++)
+               for (ConfigIter i = tags.first; i != tags.second; i++)
                {
                        // For each <banlist> tag
+                       ConfigTag* c = i->second;
                        ListLimit limit;
-                       limit.mask = Conf.ReadValue(configtag, "chan", i);
-                       limit.limit = Conf.ReadInteger(configtag, "limit", i, true);
+                       limit.mask = c->getString("chan");
+                       limit.limit = c->getInt("limit");
 
                        if (limit.mask.size() && limit.limit > 0)
                                chanlimits.push_back(limit);
                }
-               if (chanlimits.size() == 0)
-               {
-                       ListLimit limit;
-                       limit.mask = "*";
-                       limit.limit = 64;
-                       chanlimits.push_back(limit);
-               }
+
+               // Add the default entry. This is inserted last so if the user specifies a
+               // wildcard record in the config it will take precedence over this entry.
+               ListLimit limit;
+               limit.mask = "*";
+               limit.limit = 64;
+               chanlimits.push_back(limit);
        }
 
        /** Populate the Implements list with the correct events for a List Mode
         */
        virtual void DoImplements(Module* m)
        {
+               ServerInstance->Modules->AddService(extItem);
+               this->DoRehash();
                Implementation eventlist[] = { I_OnSyncChannel, I_OnRehash };
-               ServerInstance->Modules->Attach(eventlist, m, 2);
+               ServerInstance->Modules->Attach(eventlist, m, sizeof(eventlist)/sizeof(Implementation));
        }
 
        /** Handle the list mode.
@@ -223,6 +230,12 @@ class ListModeBase : public ModeHandler
 
                if (adding)
                {
+                       if (tidy)
+                               ModeParser::CleanMask(parameter);
+
+                       if (parameter.length() > 250)
+                               return MODEACTION_DENY;
+
                        // If there was no list
                        if (!el)
                        {
@@ -231,10 +244,6 @@ class ListModeBase : public ModeHandler
                                extItem.set(channel, el);
                        }
 
-                       // Clean the mask up
-                       if (this->tidy)
-                               ModeParser::CleanMask(parameter);
-
                        // Check if the item already exists in the list
                        for (modelist::iterator it = el->begin(); it != el->end(); it++)
                        {
@@ -256,7 +265,7 @@ class ListModeBase : public ModeHandler
                                {
                                        // We have a pattern matching the channel...
                                        maxsize = el->size();
-                                       if (IS_LOCAL(source) || (maxsize < it->limit))
+                                       if (!IS_LOCAL(source) || (maxsize < it->limit))
                                        {
                                                /* Ok, it *could* be allowed, now give someone subclassing us
                                                 * a chance to validate the parameter.
@@ -285,6 +294,8 @@ class ListModeBase : public ModeHandler
                                                        return MODEACTION_DENY;
                                                }
                                        }
+                                       else
+                                               break;
                                }
                        }
 
@@ -294,7 +305,7 @@ class ListModeBase : public ModeHandler
                                source->WriteNumeric(478, "%s %s %s :Channel ban/ignore list is full", source->nick.c_str(), channel->name.c_str(), parameter.c_str());
                        }
 
-                       parameter = "";
+                       parameter.clear();
                        return MODEACTION_DENY;
                }
                else
@@ -307,7 +318,7 @@ class ListModeBase : public ModeHandler
                                        if (parameter == it->mask)
                                        {
                                                el->erase(it);
-                                               if (el->size() == 0)
+                                               if (el->empty())
                                                {
                                                        extItem.unset(channel);
                                                }
@@ -316,14 +327,14 @@ class ListModeBase : public ModeHandler
                                }
                                /* Tried to remove something that wasn't set */
                                TellNotSet(source, channel, parameter);
-                               parameter = "";
+                               parameter.clear();
                                return MODEACTION_DENY;
                        }
                        else
                        {
                                /* Hmm, taking an exception off a non-existant list, DIE */
                                TellNotSet(source, channel, parameter);
-                               parameter = "";
+                               parameter.clear();
                                return MODEACTION_DENY;
                        }
                }