X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fwildcard.cpp;h=161bb81a6c3df0964555aab26203ea3e3bf5e658;hb=26cd5393c9308fabe73c41870f06f73a5b001cd7;hp=bf20ec7827b748114fe034084096547a1d8222c1;hpb=eb4229deed0281ae566ef7e55a144e5d3183a4b2;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/wildcard.cpp b/src/wildcard.cpp index bf20ec782..161bb81a6 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -2,40 +2,30 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * Inspire is copyright (C) 2002-2004 ChatSpike-Dev. - * E-mail: - * - * - * - * Written by Craig Edwards, Craig McLure, and others. + * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * See: http://wiki.inspircd.org/Credits + * * This program is free but copyrighted software; see * the file COPYING for details. * * --------------------------------------------------- */ -#include -#include "inspircd_config.h" +/* $Core */ + #include "inspircd.h" -#include "helperfuncs.h" +#include "hashcomp.h" #include "inspstring.h" -// Wed 27 Apr 2005 - Brain -// I've taken our our old wildcard routine - -// although comprehensive, it was topheavy and very -// slow, and ate masses of cpu when doing lots of -// comparisons. This is the 'de-facto' routine used -// by many, nobody really knows who wrote it first -// or what license its under, i've seen examples of it -// (unattributed to any author) all over the 'net. -// For now, we'll just consider this public domain. - -int wildcmp(char *wild, char *string) +static bool match_internal(const unsigned char *str, const unsigned char *mask, unsigned const char *map) { - char *cp, *mp; + 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 != '?')) + if ((map[*wild] != map[*string]) && (*wild != '?')) { return 0; } @@ -55,16 +45,16 @@ int wildcmp(char *wild, char *string) cp = string+1; } else - if ((*wild == *string) || (*wild == '?')) - { - wild++; - string++; - } - else - { - wild = mp; - string = cp++; - } + if ((map[*wild] == map[*string]) || (*wild == '?')) + { + wild++; + string++; + } + else + { + wild = mp; + string = cp++; + } } @@ -76,19 +66,46 @@ 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. +/******************************************************************** + * Below here is all wrappers around match_internal + ********************************************************************/ -bool match(const char* literal, const char* mask) +CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map) { - 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 (!map) + map = national_case_insensitive_map; + + return match_internal((const unsigned char *)str.c_str(), (const unsigned char *)mask.c_str(), map); } + +CoreExport bool InspIRCd::Match(const char *str, const char *mask, unsigned const char *map) +{ + if (!map) + map = national_case_insensitive_map; + 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; + + if (!map) + map = national_case_insensitive_map; + + // Fall back to regular match + return InspIRCd::Match(str, mask, map); +} + +CoreExport bool InspIRCd::MatchCIDR(const char *str, const char *mask, unsigned const char *map) +{ + if (irc::sockets::MatchCIDR(str, mask, true)) + return true; + + if (!map) + map = national_case_insensitive_map; + + // Fall back to regular match + return InspIRCd::Match(str, mask, map); +} +