]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/wildcard.cpp
Remove culllist.h from here, we no longer use it.
[user/henk/code/inspircd.git] / src / wildcard.cpp
index d0cd504fa318ce35c1bc14167835d9ee9c47b15a..eacffcb0428c6b15b60f7d640ee4cd25d54ea800 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
  * ---------------------------------------------------
  */
 
+using namespace std;
+
 #include <string>
-#include "inspircd_config.h"
 #include "inspircd.h"
+#include "hashcomp.h"
 #include "inspstring.h"
 
+using irc::sockets::MatchCIDR;
+
 // Wed 27 Apr 2005 - Brain
 // I've taken our our old wildcard routine -
 // although comprehensive, it was topheavy and very
 // (unattributed to any author) all over the 'net.
 // For now, we'll just consider this public domain.
 
-int wildcmp(char *wild, char *string)
+bool match(const char *str, const char *mask)
 {
-       char *cp, *mp;
+       unsigned char *cp, *mp;
+       unsigned char* string = (unsigned char*)str;
+       unsigned char* wild = (unsigned char*)mask;
+
        while ((*string) && (*wild != '*'))
        {
-               if ((*wild != *string) && (*wild != '?'))
+               if ((lowermap[*wild] != lowermap[*string]) && (*wild != '?'))
                {
                        return 0;
                }
@@ -54,7 +61,7 @@ int wildcmp(char *wild, char *string)
                        cp = string+1;
                }
                else
-               if ((*wild == *string) || (*wild == '?'))
+               if ((lowermap[*wild] == lowermap[*string]) || (*wild == '?'))
                {
                        wild++;
                        string++;
@@ -75,19 +82,10 @@ int wildcmp(char *wild, char *string)
        return !*wild;
 }
 
-// This wrapper function is required to convert both
-// strings to 'scandanavian lowercase' and make copies
-// of them to a safe location. It also ensures we don't
-// bite off more than we can chew with the length of
-// the string.
-
-bool match(const char* literal, const char* mask)
+/* Overloaded function that has the option of using cidr */
+bool match(const char *str, const char *mask, bool use_cidr_match)
 {
-       static char L[10240];
-       static char M[10240];
-       strlcpy(L,literal,10240);
-       strlcpy(M,mask,10240);
-       strlower(L);
-       strlower(M);
-       return wildcmp(M,L);
+       if (use_cidr_match && MatchCIDR(str, mask, true))
+               return true;
+       return match(str, mask);
 }