]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/wildcard.cpp
Skip certificate generation if we're running non-interactive
[user/henk/code/inspircd.git] / src / wildcard.cpp
index 1b1f874ab41ba410b41d4f04bfd220894ab578ce..eacffcb0428c6b15b60f7d640ee4cd25d54ea800 100644 (file)
 using namespace std;
 
 #include <string>
-#include "inspircd_config.h"
 #include "inspircd.h"
-#include "helperfuncs.h"
+#include "hashcomp.h"
 #include "inspstring.h"
 
-extern char lowermap[255];
+using irc::sockets::MatchCIDR;
 
 // Wed 27 Apr 2005 - Brain
 // I've taken our our old wildcard routine -
@@ -34,12 +33,15 @@ extern char lowermap[255];
 // (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;
                }
@@ -59,7 +61,7 @@ int wildcmp(char *wild, char *string)
                        cp = string+1;
                }
                else
-               if ((lowermap[(unsigned)*wild] == lowermap[(unsigned)*string]) || (*wild == '?'))
+               if ((lowermap[*wild] == lowermap[*string]) || (*wild == '?'))
                {
                        wild++;
                        string++;
@@ -80,14 +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)
 {
-       return wildcmp((char*)mask, (char*)literal);
+       if (use_cidr_match && MatchCIDR(str, mask, true))
+               return true;
+       return match(str, mask);
 }
-