X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fwildcard.cpp;h=f888b68cfb7943883d54ab7d86bb73ba264c1161;hb=b0e469b0bbdbc76692364e1f52ef613cc02a2a06;hp=f99054939056b230550e27aebf3dffc45f8c9292;hpb=1552f3918ac0dad7fef9b86b70c0f4a63d4e37a7;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/wildcard.cpp b/src/wildcard.cpp index f99054939..f888b68cf 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -28,6 +28,55 @@ using irc::sockets::MatchCIDR; // (unattributed to any author) all over the 'net. // For now, we'll just consider this public domain. +bool csmatch(const char *str, const char *mask) +{ + unsigned char *cp = NULL, *mp = NULL; + unsigned char* string = (unsigned char*)str; + unsigned char* wild = (unsigned char*)mask; + + while ((*string) && (*wild != '*')) + { + if ((*wild != *string) && (*wild != '?')) + { + return 0; + } + wild++; + string++; + } + + while (*string) + { + if (*wild == '*') + { + if (!*++wild) + { + return 1; + } + mp = wild; + cp = string+1; + } + else + if ((*wild == *string) || (*wild == '?')) + { + wild++; + string++; + } + else + { + wild = mp; + string = cp++; + } + + } + + while (*wild == '*') + { + wild++; + } + + return !*wild; +} + bool match(const char *str, const char *mask) { unsigned char *cp = NULL, *mp = NULL; @@ -84,3 +133,16 @@ bool match(const char *str, const char *mask, bool use_cidr_match) return true; return match(str, mask); } + +bool match(bool case_sensitive, const char *str, const char *mask, bool use_cidr_match) +{ + if (use_cidr_match && MatchCIDR(str, mask, true)) + return true; + return csmatch(str, mask); +} + +bool match(bool case_sensitive, const char *str, const char *mask) +{ + return case_sensitive ? csmatch(str, mask) : match(str, mask); +} +