]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
match() is no longer a function+no header, now a static method of InspIRCd class...
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 21 Aug 2008 20:56:16 +0000 (20:56 +0000)
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 21 Aug 2008 20:56:16 +0000 (20:56 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10212 e03df62e-2008-0410-955e-edbf42e46eb7

20 files changed:
include/inspircd.h
include/wildcard.h [deleted file]
src/channels.cpp
src/cidr.cpp
src/command_parse.cpp
src/commands.cpp
src/commands/cmd_list.cpp
src/commands/cmd_modules.cpp
src/commands/cmd_notice.cpp
src/commands/cmd_oper.cpp
src/commands/cmd_privmsg.cpp
src/commands/cmd_rehash.cpp
src/commands/cmd_who.cpp
src/helperfuncs.cpp
src/modules.cpp
src/testsuite.cpp
src/userprocess.cpp
src/users.cpp
src/wildcard.cpp
src/xline.cpp

index 81a9f3cbea274b9d81d405a29fcde87c99449471..85800f4da75736f6f1a0db6fc4231446c95de4db 100644 (file)
@@ -712,14 +712,21 @@ class CoreExport InspIRCd : public classbase
         */
        void SendMode(const std::vector<std::string>& parameters, User *user);
 
-       /** Match two strings using pattern matching.
-        * This operates identically to the global function match(),
-        * except for that it takes std::string arguments rather than
-        * const char* ones.
-        * @param sliteral The literal string to match against
-        * @param spattern The pattern to match against. CIDR and globs are supported.
-        */
-       bool MatchText(const std::string &sliteral, const std::string &spattern);
+       /** Match two strings using pattern matching, optionally, with a map
+        * to check case against (may be NULL).
+        * @param str The literal string to match against
+        * @param mask The glob pattern to match against.
+        */
+       static bool Match(const std::string &str, const std::string &mask, unsigned const char *map);
+       static bool Match(const  char *str, const char *mask, unsigned const char *map);
+
+       /** Match two strings using pattern matching, optionally, with a map
+        * to check case against (may be NULL). Supports CIDR patterns as well as globs.
+        * @param str The literal string to match against
+        * @param mask The glob or CIDR pattern to match against.
+        */
+       static bool MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map);
+       static bool MatchCIDR(const  char *str, const char *mask, unsigned const char *map);
 
        /** Call the handler for a given command.
         * @param commandname The command whos handler you wish to call
diff --git a/include/wildcard.h b/include/wildcard.h
deleted file mode 100644 (file)
index 8c99b8d..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
- *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
- *
- * This program is free but copyrighted software; see
- *            the file COPYING for details.
- *
- * ---------------------------------------------------
- */
-
-/** Match a string against a mask.
- * @param str The string to check
- * @param mask the mask to check against
- * @return true if the strings match
- */
-CoreExport bool match(const std::string &str, const std::string &mask);
-/** Match a string against a mask, and define wether or not to use CIDR rules
- * @param str The string to check
- * @param mask the mask to check against
- * @param use_cidr_match True if CIDR matching rules should be applied first
- * @return true if the strings match
- */
-CoreExport bool match(const std::string &str, const std::string &mask, bool use_cidr_match);
-/** Match a string against a mask, defining wether case sensitivity applies.
- * @param str The string to check
- * @param mask the mask to check against
- * @param case_sensitive True if the match is case sensitive
- * @return True if the strings match
- */
-CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask);
-/** Match a string against a mask, defining wether case sensitivity applies,
- * and defining wether or not to use CIDR rules first.
- * @param case_sensitive True if the match is case sensitive
- * @param str The string to check
- * @param mask the mask to check against
- * @param use_cidr_match True if CIDR matching rules should be applied first
- * @return true if the strings match
- */
-CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask, bool use_cidr_match);
-
index 6eda54a9dd270e4b83e11c4af1806aaef02d00f4..ac7c461d6e12377bb047bfa6fd3d2dbf84b56024 100644 (file)
@@ -15,7 +15,6 @@
 
 #include "inspircd.h"
 #include <cstdarg>
-#include "wildcard.h"
 #include "mode.h"
 
 Channel::Channel(InspIRCd* Instance, const std::string &cname, time_t ts) : ServerInstance(Instance)
@@ -489,11 +488,9 @@ bool Channel::IsBanned(User* user)
                snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
                for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
                {
-                       /* This allows CIDR ban matching
-                        *
-                        *        Full masked host                      Full unmasked host                   IP with/without CIDR
-                        */
-                       if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true)))
+                       if ((InspIRCd::Match(user->GetFullHost(),i->data, NULL)) || // host
+                               (InspIRCd::Match(user->GetFullRealHost(),i->data, NULL)) || // uncloaked host
+                               (InspIRCd::MatchCIDR(mask, i->data, NULL))) // ip
                        {
                                return true;
                        }
@@ -520,7 +517,7 @@ bool Channel::IsExtBanned(const std::string &str, char type)
                        std::string maskptr = i->data.substr(2);
                        ServerInstance->Logs->Log("EXTBANS", DEBUG, "Checking %s against %s, type is %c", str.c_str(), maskptr.c_str(), type);
 
-                       if (match(str, maskptr))
+                       if (InspIRCd::Match(str, maskptr, NULL))
                                return true;
                }
        }
@@ -1038,7 +1035,7 @@ long Channel::GetMaxBans()
        /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
        for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
        {
-               if (match(this->name,n->first))
+               if (InspIRCd::Match(this->name, n->first, NULL))
                {
                        this->maxbans = n->second;
                        return n->second;
index fb4ab447bebc2626b2cdeeb4aa4d6341685e7026..91f4d02376d1157be4a18bdef86b9f392cdc17d5 100644 (file)
@@ -14,7 +14,6 @@
 /* $Core */
 
 #include "inspircd.h"
-#include "wildcard.h"
 
 /* Used when comparing CIDR masks for the modulus bits left over.
  * A lot of ircd's seem to do this:
@@ -91,7 +90,7 @@ bool irc::sockets::MatchCIDR(const std::string &address, const std::string &cidr
                         * symbols, and recursively call MatchCIDR without
                         * username matching enabled to match the host part.
                         */
-                       return (match(address.substr(0, username_addr_pos), cidr_mask.substr(0, username_mask_pos)) &&
+                       return (InspIRCd::Match(address.substr(0, username_addr_pos), cidr_mask.substr(0, username_mask_pos), NULL) &&
                                        MatchCIDR(address.substr(username_addr_pos + 1), cidr_mask.substr(username_mask_pos + 1), false));
                }
                else
index 995ef694b4ed7c61e62b9e9d45eb6e89b44af650..4063edf385246e0f67387a17a9bfdf3c63158b00 100644 (file)
@@ -14,7 +14,6 @@
 /* $Core */
 
 #include "inspircd.h"
-#include "wildcard.h"
 #include "xline.h"
 #include "socketengine.h"
 #include "socket.h"
@@ -545,7 +544,7 @@ void CommandParser::SetupCommandTable(User* user)
                dirent* entry = NULL;
                while (0 != (entry = readdir(library)))
                {
-                       if (match(entry->d_name, "cmd_*.so"))
+                       if (InspIRCd::Match(entry->d_name, "cmd_*.so", NULL))
                        {
                                if (!user)
                                {
index a9a81f177e976911b1bcf656c44c3b866000f932..68ad224ae18fdd1494e3784a729e16353a10c72b 100644 (file)
@@ -14,7 +14,6 @@
 /* $Core */
 
 #include "inspircd.h"
-#include "wildcard.h"
 #include "xline.h"
 #include "command_parse.h"
 
@@ -33,7 +32,8 @@ bool InspIRCd::HostMatchesEveryone(const std::string &mask, User* user)
        
        for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
        {
-               if ((match(u->second->MakeHost(), mask, true)) || (match(u->second->MakeHostIP(), mask, true)))
+               if ((InspIRCd::Match(u->second->MakeHost(), mask, lowermap)) ||
+                   (InspIRCd::Match(u->second->MakeHostIP(), mask, lowermap)))
                {
                        matches++;
                }
@@ -64,7 +64,7 @@ bool InspIRCd::IPMatchesEveryone(const std::string &ip, User* user)
        
        for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
        {
-               if (match(u->second->GetIPString(),ip,true))
+               if (InspIRCd::Match(u->second->GetIPString(), ip, lowermap))
                        matches++;
        }
 
@@ -93,7 +93,7 @@ bool InspIRCd::NickMatchesEveryone(const std::string &nick, User* user)
 
        for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
        {
-               if (match(u->second->nick,nick))
+               if (InspIRCd::Match(u->second->nick, nick, lowermap))
                        matches++;
        }
 
index b2ec1941bed766da04e4c0f6845c2a54148f0b51..d4abfd437b2c79ee4e70dc530dfd2243a9e8a67f 100644 (file)
@@ -13,7 +13,6 @@
 
 #include "inspircd.h"
 #include "commands/cmd_list.h"
-#include "wildcard.h"
 
 /** Handle /LIST
  */
@@ -54,7 +53,7 @@ CmdResult CommandList::Handle (const std::vector<std::string>& parameters, User
 
                if (parameters.size() && (parameters[0][0] != '<' || parameters[0][0] == '>'))
                {
-                       if (!match(i->second->name, parameters[0]) && !match(i->second->topic, parameters[0]))
+                       if (!InspIRCd::Match(i->second->name, parameters[0], lowermap) && !InspIRCd::Match(i->second->topic, parameters[0], lowermap))
                                continue;
                }
 
index 9474dece45bcfed53ff1dfa0accbf73b676f1d52..0b7ce2577b0e836f85a99547ea255e54cc00254b 100644 (file)
@@ -12,7 +12,6 @@
  */
 
 #include "inspircd.h"
-#include "wildcard.h"
 #include "commands/cmd_modules.h"
 
 const char* itab[] = {
index 9cf4800a437200aa4e9f418cdbf9abde0db511f3..37f11eeb9d74d2139053b499d145dc4aa6d07748 100644 (file)
@@ -12,7 +12,6 @@
  */
 
 #include "inspircd.h"
-#include "wildcard.h"
 #include "commands/cmd_notice.h"
 
 extern "C" DllExport Command* init_command(InspIRCd* Instance)
@@ -42,7 +41,7 @@ CmdResult CommandNotice::Handle (const std::vector<std::string>& parameters, Use
                const char* servermask = (parameters[0].c_str()) + 1;
 
                FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
-               if (match(ServerInstance->Config->ServerName,servermask))
+               if (InspIRCd::Match(ServerInstance->Config->ServerName,servermask, NULL))
                {
                        user->SendAll("NOTICE", "%s", text);
                }
index 97134f0389fa5116e2e85c6c6098571c519c1629..8522890e0266bb56235f8859a4a797d407c1693d 100644 (file)
@@ -12,7 +12,6 @@
  */
 
 #include "inspircd.h"
-#include "wildcard.h"
 #include "commands/cmd_oper.h"
 #include "hashcomp.h"
 
@@ -22,7 +21,7 @@ bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
        std::string xhost;
        while (hl >> xhost)
        {
-               if (match(host, xhost) || match(ip,xhost, true))
+               if (InspIRCd::MatchCIDR(host, xhost, NULL) || InspIRCd::MatchCIDR(ip, xhost, NULL))
                {
                        return true;
                }
index 0086bb72debb4264baa8995f578b2a1cce83b8d9..135ab809e81718667bee64a7810758a654a3895d 100644 (file)
@@ -12,7 +12,6 @@
  */
 
 #include "inspircd.h"
-#include "wildcard.h"
 #include "commands/cmd_privmsg.h"
 
 extern "C" DllExport  Command* init_command(InspIRCd* Instance)
@@ -43,7 +42,7 @@ CmdResult CommandPrivmsg::Handle (const std::vector<std::string>& parameters, Us
                const char* servermask = (parameters[0].c_str()) + 1;
 
                FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list));
-               if (match(ServerInstance->Config->ServerName,servermask))
+               if (InspIRCd::Match(ServerInstance->Config->ServerName, servermask, NULL))
                {
                        user->SendAll("PRIVMSG", "%s", text);
                }
index cab5934572b01433ad778833213508fef700e913..28ae32a0d9bf7f76f9022fe6290cd946485325f2 100644 (file)
@@ -28,7 +28,7 @@ CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, Use
 
        if (parameters.size() && parameters[0][0] != '-')
        {
-               if (!ServerInstance->MatchText(ServerInstance->Config->ServerName, parameters[0]))
+               if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0], lowermap))
                {
                        FOREACH_MOD(I_OnRehash,OnRehash(user, parameters[0]));
                        return CMD_SUCCESS; // rehash for a server, and not for us
index a9f27de83c7cb725644ec74cf0d241859652de10..845670acf7f67cd1dc9693619569a3e9f3c839dd 100644 (file)
@@ -12,7 +12,6 @@
  */
 
 #include "inspircd.h"
-#include "wildcard.h"
 #include "commands/cmd_who.h"
 
 static const std::string star = "*";
@@ -75,15 +74,15 @@ bool CommandWho::whomatch(User* user, const char* matchtext)
                else
                {
                        if (opt_realname)
-                               realname = match(user->fullname, matchtext);
+                               realname = InspIRCd::Match(user->fullname, matchtext, lowermap);
                        else
                        {
                                if (opt_showrealhost)
-                                       realhost = match(user->host, matchtext);
+                                       realhost = InspIRCd::Match(user->host, matchtext, lowermap);
                                else
                                {
                                        if (opt_ident)
-                                               ident = match(user->ident, matchtext);
+                                               ident = InspIRCd::Match(user->ident, matchtext, lowermap);
                                        else
                                        {
                                                if (opt_port)
@@ -97,13 +96,13 @@ bool CommandWho::whomatch(User* user, const char* matchtext)
                                                else
                                                {
                                                        if (opt_away)
-                                                               away = match(user->awaymsg, matchtext);
+                                                               away = InspIRCd::Match(user->awaymsg, matchtext, lowermap);
                                                }
                                        }
                                }
                        }
                }
-               return ((port) || (away) || (ident) || (metadata) || (realname) || (realhost) || (match(user->dhost, matchtext)) || (match(user->nick, matchtext)) || (match(user->server, matchtext)));
+               return ((port) || (away) || (ident) || (metadata) || (realname) || (realhost) || (InspIRCd::Match(user->dhost, matchtext, lowermap)) || (InspIRCd::Match(user->nick, matchtext, lowermap)) || (InspIRCd::Match(user->server, matchtext, lowermap)));
        }
 }
 
index 31f486a48c753ac06739410dd90edc4caa4f75e4..53529f5395b8e35117bbf444da46631dc9972434 100644 (file)
@@ -14,7 +14,6 @@
 /* $Core */
 
 #include "inspircd.h"
-#include "wildcard.h"
 #include "xline.h"
 #include "exitcodes.h"
 
index 8061248d24b89d60b961e97fb25051b588fe4761..bc72f9f97b8a059778287b686f9d5081f401fc2f 100644 (file)
@@ -14,7 +14,6 @@
 /* $Core */
 
 #include "inspircd.h"
-#include "wildcard.h"
 #include "xline.h"
 #include "socket.h"
 #include "socketengine.h"
@@ -374,7 +373,7 @@ bool ModuleManager::Load(const char* filename)
                        dirent* entry = NULL;
                        while (0 != (entry = readdir(library)))
                        {
-                               if (Instance->MatchText(entry->d_name, filename))
+                               if (InspIRCd::Match(entry->d_name, filename, NULL))
                                {
                                        if (!this->Load(entry->d_name))
                                                n_match++;
@@ -729,11 +728,6 @@ Channel* InspIRCd::GetChannelIndex(long index)
        return NULL;
 }
 
-bool InspIRCd::MatchText(const std::string &sliteral, const std::string &spattern)
-{
-       return match(sliteral, spattern);
-}
-
 CmdResult InspIRCd::CallCommandHandler(const std::string &commandname, const std::vector<std::string>& parameters, User* user)
 {
        return this->Parser->CallHandler(commandname, parameters, user);
index 9ab30ff2d2b1a2c7805f74392593e8326ee421a9..5d957e984527a3fe9b4541762b1155cfd8b1d5c7 100644 (file)
@@ -16,7 +16,6 @@
 #include "inspircd.h"
 #include "testsuite.h"
 #include "threadengine.h"
-#include "wildcard.h"
 #include <iostream>
 
 using namespace std;
@@ -98,14 +97,14 @@ TestSuite::TestSuite(InspIRCd* Instance) : ServerInstance(Instance)
 }
 
 /* Test that x matches y with match() */
-#define WCTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\") " << ((passed = (match(x, y))) ? " SUCCESS!\n" : " FAILURE\n")
+#define WCTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\") " << ((passed = (InspIRCd::Match(x, y, NULL))) ? " SUCCESS!\n" : " FAILURE\n")
 /* Test that x does not match y with match() */
-#define WCTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\") " << ((passed = ((!match(x, y)))) ? " SUCCESS!\n" : " FAILURE\n")
+#define WCTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\") " << ((passed = ((!InspIRCd::Match(x, y, NULL)))) ? " SUCCESS!\n" : " FAILURE\n")
 
 /* Test that x matches y with match() and cidr enabled */
-#define CIDRTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\", true) " << ((passed = (match(x, y, true))) ? " SUCCESS!\n" : " FAILURE\n")
+#define CIDRTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\", true) " << ((passed = (InspIRCd::MatchCIDR(x, y, NULL))) ? " SUCCESS!\n" : " FAILURE\n")
 /* Test that x does not match y with match() and cidr enabled */
-#define CIDRTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\", true) " << ((passed = ((!match(x, y, true)))) ? " SUCCESS!\n" : " FAILURE\n")
+#define CIDRTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\", true) " << ((passed = ((!InspIRCd::MatchCIDR(x, y, NULL)))) ? " SUCCESS!\n" : " FAILURE\n")
 
 bool TestSuite::DoWildTests()
 {
index fe6a25c251535b0d1a81ed1d8e99a79ed39abd29..bdd7e7e8a563bf84b27391ac1c0a306bb8d8584d 100644 (file)
@@ -14,7 +14,6 @@
 /* $Core */
 
 #include "inspircd.h"
-#include "wildcard.h"
 #include "xline.h"
 #include "socketengine.h"
 #include "command_parse.h"
index f631420fe9ab7a716d61b931efc6eb892e39a53b..943503ff1a6500d7243ed5e08c8b181ae2a4b23c 100644 (file)
@@ -16,7 +16,6 @@
 #include "inspircd.h"
 #include <stdarg.h>
 #include "socketengine.h"
-#include "wildcard.h"
 #include "xline.h"
 #include "bancache.h"
 #include "commands/cmd_whowas.h"
@@ -1811,7 +1810,8 @@ ConnectClass* User::SetClass(const std::string &explicit_name)
                        }
 
                        /* check if host matches.. */
-                       if (((!match(this->GetIPString(),c->GetHost(),true)) && (!match(this->host,c->GetHost()))))
+                       if (!InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) && 
+                           !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL))
                        {
                                ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "No host match (for %s)", c->GetHost().c_str());
                                continue;
index b230ab147daf8245a1e62ad4858e56f6c21d4aa6..199b439653d11306a78722704795915c6eefd5c4 100644 (file)
 #include "hashcomp.h"
 #include "inspstring.h"
 
-using irc::sockets::MatchCIDR;
-
-/* Rewritten to operate on more effective C++ std::string types
- * rather than char* to avoid data copies.
- * - Brain
+/*
+ * Wildcard matching, the third (and probably final) iteration!
+ *
  */
-
-CoreExport bool csmatch(const std::string &str, const std::string &mask)
+static bool match_internal(const unsigned char *str, const unsigned char *mask, unsigned const char *map)
 {
-       std::string::const_iterator cp, mp;
-
-       //unsigned char *cp = NULL, *mp = NULL;
-       //unsigned char* string = (unsigned char*)str;
-       //unsigned char* wild = (unsigned char*)mask;
-
-       std::string::const_iterator wild = mask.begin();
-       std::string::const_iterator string = str.begin();
-
-       if (mask.empty())
-               return false;
-
-       while ((string != str.end()) && (wild != mask.end()) && (*wild != '*'))
-       {
-               if ((*wild != *string) && (*wild != '?'))
-                       return false;
-
-               wild++;
-               string++;
-       }
-
-       if (wild == mask.end() && string != str.end())
-               return false;
+       const unsigned char *wild = str;
+       const unsigned char *string = mask;
+       const unsigned char *cp = NULL;
+       const unsigned char *mp = NULL;
 
-       while (string != str.end())
+       while ((*string) && (*wild != '*'))
        {
-               if (wild != mask.end() && *wild == '*')
+               if (!map)
                {
-                       if (++wild == mask.end())
-                               return true;
-
-                       mp = wild;
-                       cp = string;
-
-                       if (cp != str.end())
-                               cp++;
-               }
-               else
-               if ((string != str.end() && wild != mask.end()) && ((*wild == *string) || (*wild == '?')))
-               {
-                       wild++;
-                       string++;
+                       if ((*wild != *string) && (*wild != '?'))
+                       {
+                               return false;
+                       }
                }
                else
                {
-                       wild = mp;
-                       if (cp == str.end())
-                               cp = str.end();
-                       else
-                               string = cp++;
+                       if (map[*wild] != map[*string] && (*wild != '?'))
+                       {
+                               return false;
+                       }
                }
 
+               ++wild;
+               ++string;
        }
 
-       while ((wild != mask.end()) && (*wild == '*'))
-               wild++;
-
-       return wild == mask.end();
-}
-
-CoreExport bool match(const std::string &str, const std::string &mask)
-{
-       std::string::const_iterator cp, mp;
-       std::string::const_iterator wild = mask.begin();
-       std::string::const_iterator string = str.begin();
-
-       if (mask.empty())
-               return false;
-
-       while ((string != str.end()) && (wild != mask.end()) && (*wild != '*'))
-       {
-               if ((lowermap[(unsigned char)*wild] != lowermap[(unsigned char)*string]) && (*wild != '?'))
-                       return false;
-
-               wild++;
-               string++;
-               //printf("Iterate first loop\n");
-       }
-
-       if (wild == mask.end() && string != str.end())
-               return false;
-
-       while (string != str.end())
+       while (*string)
        {
-               //printf("outer\n %c", *string);
-               if (wild != mask.end() && *wild == '*')
+               if (*wild == '*')
                {
-
-                       //printf("inner %c\n", *wild);
-                       if (++wild == mask.end())
+                       if (!*++wild)
+                       {
                                return true;
+                       }
 
                        mp = wild;
-                       cp = string;
-
-                       if (cp != str.end())
-                               cp++;
-
+                       cp = string+1;
                }
-               else
-               if ((string != str.end() && wild != mask.end()) && ((lowermap[(unsigned char)*wild] == lowermap[(unsigned char)*string]) || (*wild == '?')))
+               // if there is no charmap and str == wild OR
+               // there is a map and mapped char == mapped wild AND
+               // wild is NOT ?
+               else if (((!map && *wild == *string) || (map && map[*wild] == map[*string])) && (*wild == '?'))
                {
-                       if (wild != mask.end())
-                               wild++;
-
-                       if (string != str.end())
-                               string++;
+                       ++wild;
+                       ++string;
                }
                else
                {
                        wild = mp;
-                       if (cp == str.end())
-                               string = str.end();
-                       else
-                               string = cp++;
+                       string = cp++;
                }
-
        }
 
-       while ((wild != mask.end()) && (*wild == '*'))
+       while (*wild == '*')
+       {
                wild++;
+       }
 
-       return wild == mask.end();
+       return (*wild == 0);
 }
 
-/* Overloaded function that has the option of using cidr */
-CoreExport bool match(const std::string &str, const std::string &mask, bool use_cidr_match)
+CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map)
 {
-       if (use_cidr_match && MatchCIDR(str, mask, true))
-               return true;
-       return match(str, mask);
+       return match_internal((const unsigned char *)str.c_str(), (const unsigned char *)mask.c_str(), map);
 }
 
-CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask, bool use_cidr_match)
+CoreExport bool InspIRCd::Match(const  char *str, const char *mask, unsigned const char *map)
 {
-       if (use_cidr_match && MatchCIDR(str, mask, true))
+       return match_internal((const unsigned char *)str, (const unsigned char *)mask, map);
+}
+
+
+CoreExport bool InspIRCd::MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map)
+{
+       if (irc::sockets::MatchCIDR(str, mask, true))
                return true;
 
-       return case_sensitive ? csmatch(str, mask) : match(str, mask);
+       // Fall back to regular match
+       return InspIRCd::Match(str, mask, NULL);
 }
 
-CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask)
+CoreExport bool InspIRCd::MatchCIDR(const  char *str, const char *mask, unsigned const char *map)
 {
-       return case_sensitive ? csmatch(str, mask) : match(str, mask);
+       if (irc::sockets::MatchCIDR(str, mask, true))
+               return true;
+
+       // Fall back to regular match
+       return InspIRCd::Match(str, mask, NULL);
 }
 
index 8843b99898908babdc5cecacfbc3fd025caf8315..53493b59e72888701d6d55879792e9983b05d004 100644 (file)
@@ -14,7 +14,6 @@
 /* $Core */
 
 #include "inspircd.h"
-#include "wildcard.h"
 #include "xline.h"
 #include "bancache.h"
 
@@ -458,9 +457,10 @@ bool KLine::Matches(User *u)
        if (u->exempt)
                return false;
 
-       if ((match(u->ident, this->identmask)))
+       if (InspIRCd::Match(u->ident, this->identmask, NULL))
        {
-               if ((match(u->host, this->hostmask, true)) || (match(u->GetIPString(), this->hostmask, true)))
+               if (InspIRCd::MatchCIDR(u->host, this->hostmask, NULL) ||
+                   InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask, NULL))
                {
                        return true;
                }
@@ -479,9 +479,10 @@ bool GLine::Matches(User *u)
        if (u->exempt)
                return false;
 
-       if ((match(u->ident, this->identmask)))
+       if (InspIRCd::Match(u->ident, this->identmask, NULL))
        {
-               if ((match(u->host, this->hostmask, true)) || (match(u->GetIPString(), this->hostmask, true)))
+               if (InspIRCd::MatchCIDR(u->host, this->hostmask, NULL) ||
+                   InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask, NULL))
                {
                        return true;
                }
@@ -500,9 +501,10 @@ bool ELine::Matches(User *u)
        if (u->exempt)
                return false;
 
-       if ((match(u->ident, this->identmask)))
+       if (InspIRCd::Match(u->ident, this->identmask, NULL))
        {
-               if ((match(u->host, this->hostmask, true)) || (match(u->GetIPString(), this->hostmask, true)))
+               if (InspIRCd::MatchCIDR(u->host, this->hostmask, NULL) ||
+                   InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask, NULL))
                {
                        return true;
                }
@@ -516,7 +518,7 @@ bool ZLine::Matches(User *u)
        if (u->exempt)
                return false;
 
-       if (match(u->GetIPString(), this->ipaddr, true))
+       if (InspIRCd::MatchCIDR(u->GetIPString(), this->ipaddr, NULL))
                return true;
        else
                return false;
@@ -533,7 +535,7 @@ bool QLine::Matches(User *u)
        if (u->exempt)
                return false;
 
-       if (match(u->nick, this->nick))
+       if (InspIRCd::Match(u->nick, this->nick, lowermap))
                return true;
 
        return false;
@@ -548,7 +550,7 @@ void QLine::Apply(User* u)
 
 bool ZLine::Matches(const std::string &str)
 {
-       if (match(str, this->ipaddr, true))
+       if (InspIRCd::MatchCIDR(str, this->ipaddr, NULL))
                return true;
        else
                return false;
@@ -556,7 +558,7 @@ bool ZLine::Matches(const std::string &str)
 
 bool QLine::Matches(const std::string &str)
 {
-       if (match(str, this->nick))
+       if (InspIRCd::Match(str, this->nick, lowermap))
                return true;
 
        return false;
@@ -564,17 +566,17 @@ bool QLine::Matches(const std::string &str)
 
 bool ELine::Matches(const std::string &str)
 {
-       return ((match(str, matchtext, true)));
+       return (InspIRCd::MatchCIDR(str, matchtext, NULL));
 }
 
 bool KLine::Matches(const std::string &str)
 {
-       return ((match(str.c_str(), matchtext, true)));
+       return (InspIRCd::MatchCIDR(str.c_str(), matchtext, NULL));
 }
 
 bool GLine::Matches(const std::string &str)
 {
-       return ((match(str, matchtext, true)));
+       return (InspIRCd::MatchCIDR(str, matchtext, NULL));
 }
 
 void ELine::OnAdd()