1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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 * ---------------------------------------------------
17 #include "inspstring.h"
19 using irc::sockets::MatchCIDR;
21 // Wed 27 Apr 2005 - Brain
22 // I've taken our our old wildcard routine -
23 // although comprehensive, it was topheavy and very
24 // slow, and ate masses of cpu when doing lots of
25 // comparisons. This is the 'de-facto' routine used
26 // by many, nobody really knows who wrote it first
27 // or what license its under, i've seen examples of it
28 // (unattributed to any author) all over the 'net.
29 // For now, we'll just consider this public domain.
31 CoreExport bool csmatch(const char *str, const char *mask)
33 unsigned char *cp = NULL, *mp = NULL;
34 unsigned char* string = (unsigned char*)str;
35 unsigned char* wild = (unsigned char*)mask;
37 while ((*string) && (*wild != '*'))
39 if ((*wild != *string) && (*wild != '?'))
59 if ((*wild == *string) || (*wild == '?'))
80 CoreExport bool match(const char *str, const char *mask)
82 unsigned char *cp = NULL, *mp = NULL;
83 unsigned char* string = (unsigned char*)str;
84 unsigned char* wild = (unsigned char*)mask;
86 while ((*string) && (*wild != '*'))
88 if ((lowermap[*wild] != lowermap[*string]) && (*wild != '?'))
108 if ((lowermap[*wild] == lowermap[*string]) || (*wild == '?'))
129 /* Overloaded function that has the option of using cidr */
130 CoreExport bool match(const char *str, const char *mask, bool use_cidr_match)
132 if (use_cidr_match && MatchCIDR(str, mask, true))
134 return match(str, mask);
137 CoreExport bool match(bool case_sensitive, const char *str, const char *mask, bool use_cidr_match)
139 if (use_cidr_match && MatchCIDR(str, mask, true))
141 return csmatch(str, mask);
144 CoreExport bool match(bool case_sensitive, const char *str, const char *mask)
146 return case_sensitive ? csmatch(str, mask) : match(str, mask);