1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
18 #include "inspstring.h"
21 * Wildcard matching, the third (and probably final) iteration!
24 static bool match_internal(const unsigned char *str, const unsigned char *mask, unsigned const char *map)
26 const unsigned char *wild = str;
27 const unsigned char *string = mask;
28 const unsigned char *cp = NULL;
29 const unsigned char *mp = NULL;
31 while ((*string) && (*wild != '*'))
35 if ((*wild != *string) && (*wild != '?'))
42 if (map[*wild] != map[*string] && (*wild != '?'))
64 // if there is no charmap and str == wild OR
65 // there is a map and mapped char == mapped wild AND
67 else if (((!map && *wild == *string) || (map && map[*wild] == map[*string])) && (*wild == '?'))
87 CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map)
89 return match_internal((const unsigned char *)str.c_str(), (const unsigned char *)mask.c_str(), map);
92 CoreExport bool InspIRCd::Match(const char *str, const char *mask, unsigned const char *map)
94 return match_internal((const unsigned char *)str, (const unsigned char *)mask, map);
98 CoreExport bool InspIRCd::MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map)
100 if (irc::sockets::MatchCIDR(str, mask, true))
103 // Fall back to regular match
104 return InspIRCd::Match(str, mask, NULL);
107 CoreExport bool InspIRCd::MatchCIDR(const char *str, const char *mask, unsigned const char *map)
109 if (irc::sockets::MatchCIDR(str, mask, true))
112 // Fall back to regular match
113 return InspIRCd::Match(str, mask, NULL);