X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fwildcard.cpp;h=eb9151293d8e185747de8ba4a3caaa729a5b1588;hb=4e3d7a6e30eadf714483994681b8b2534229f4a8;hp=2df7a5bec10e769b3e3445e8ebc18132fbfaee0c;hpb=03fe9de7ac49af62e95b6dd3341b2012c9a530cf;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/wildcard.cpp b/src/wildcard.cpp index 2df7a5bec..eb9151293 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -1,161 +1,119 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * InspIRCd: (C) 2002-2008 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * Copyright (C) 2008 Robin Burchell + * Copyright (C) 2003, 2006-2008 Craig Edwards + * Copyright (C) 2007-2008 Dennis Friis * - * This program is free but copyrighted software; see - * the file COPYING for details. + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. * - * --------------------------------------------------- + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ -/* $Core: libIRCDwildcard */ + +/* $Core */ #include "inspircd.h" #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 - */ - -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(); + unsigned char *cp = NULL, *mp = NULL; + unsigned char* string = (unsigned char*)str; + unsigned char* wild = (unsigned char*)mask; - if (mask.empty()) - return false; - - while ((string != str.end()) && (wild != mask.end()) && (*wild != '*')) + while ((*string) && (*wild != '*')) { - if ((*wild != *string) && (*wild != '?')) + if ((map[*wild] != map[*string]) && (*wild != '?')) + { return 0; - + } wild++; string++; } - while (string != str.end()) + while (*string) { - if (wild != mask.end() && *wild == '*') + if (*wild == '*') { - if (++wild == mask.end()) + if (!*++wild) + { return 1; - + } mp = wild; - cp = string; - - if (cp != str.end()) - cp++; + cp = string+1; } else - if ((string != str.end() && wild != mask.end()) && ((*wild == *string) || (*wild == '?'))) - { - wild++; - string++; - } - else - { - wild = mp; - if (cp == str.end()) - cp = str.end(); + if ((map[*wild] == map[*string]) || (*wild == '?')) + { + wild++; + string++; + } else + { + wild = mp; string = cp++; - } + } } - 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 != '*')) + while (*wild == '*') { - if ((lowermap[(unsigned char)*wild] != lowermap[(unsigned char)*string]) && (*wild != '?')) - return 0; - wild++; - string++; } - while (string != str.end()) - { - if (wild != mask.end() && *wild == '*') - { - if (++wild == mask.end()) - return 1; - - mp = wild; - cp = string; - - if (cp != str.end()) - cp++; - - } - else - if ((string != str.end() && wild != mask.end()) && ((lowermap[(unsigned char)*wild] == lowermap[(unsigned char)*string]) || (*wild == '?'))) - { - wild++; - string++; - } - else - { - wild = mp; - if (cp == str.end()) - string = str.end(); - else - string = cp++; - } + return !*wild; +} - } +/******************************************************************** + * Below here is all wrappers around match_internal + ********************************************************************/ - while ((wild != mask.end()) && (*wild == '*')) - wild++; +CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map) +{ + if (!map) + map = national_case_insensitive_map; - return wild == mask.end(); + return match_internal((const unsigned char *)str.c_str(), (const unsigned char *)mask.c_str(), map); } -/* 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 char *str, const char *mask, unsigned const char *map) { - if (use_cidr_match && MatchCIDR(str, mask, true)) - return true; - return match(str, mask); + if (!map) + map = national_case_insensitive_map; + return match_internal((const unsigned char *)str, (const unsigned char *)mask, map); } -CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask, bool use_cidr_match) +CoreExport bool InspIRCd::MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map) { - if (use_cidr_match && MatchCIDR(str, mask, true)) + if (irc::sockets::MatchCIDR(str, mask, true)) return true; - return case_sensitive ? csmatch(str, mask) : match(str, mask); + if (!map) + map = national_case_insensitive_map; + + // Fall back to regular match + return InspIRCd::Match(str, mask, map); } -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; + + if (!map) + map = national_case_insensitive_map; + + // Fall back to regular match + return InspIRCd::Match(str, mask, map); }