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 * ---------------------------------------------------
14 /* $Core: libIRCDwildcard */
18 #include "inspstring.h"
20 using irc::sockets::MatchCIDR;
22 // Wed 27 Apr 2005 - Brain
23 // I've taken our our old wildcard routine -
24 // although comprehensive, it was topheavy and very
25 // slow, and ate masses of cpu when doing lots of
26 // comparisons. This is the 'de-facto' routine used
27 // by many, nobody really knows who wrote it first
28 // or what license its under, i've seen examples of it
29 // (unattributed to any author) all over the 'net.
30 // For now, we'll just consider this public domain.
32 CoreExport bool csmatch(const char *str, const char *mask)
34 unsigned char *cp = NULL, *mp = NULL;
35 unsigned char* string = (unsigned char*)str;
36 unsigned char* wild = (unsigned char*)mask;
38 while ((*string) && (*wild != '*'))
40 if ((*wild != *string) && (*wild != '?'))
60 if ((*wild == *string) || (*wild == '?'))
81 CoreExport bool match(const char *str, const char *mask)
83 unsigned char *cp = NULL, *mp = NULL;
84 unsigned char* string = (unsigned char*)str;
85 unsigned char* wild = (unsigned char*)mask;
87 while ((*string) && (*wild != '*'))
89 if ((lowermap[*wild] != lowermap[*string]) && (*wild != '?'))
109 if ((lowermap[*wild] == lowermap[*string]) || (*wild == '?'))
130 /* Overloaded function that has the option of using cidr */
131 CoreExport bool match(const char *str, const char *mask, bool use_cidr_match)
133 if (use_cidr_match && MatchCIDR(str, mask, true))
135 return match(str, mask);
138 CoreExport bool match(bool case_sensitive, const char *str, const char *mask, bool use_cidr_match)
140 if (use_cidr_match && MatchCIDR(str, mask, true))
143 return case_sensitive ? csmatch(str, mask) : match(str, mask);
146 CoreExport bool match(bool case_sensitive, const char *str, const char *mask)
148 return case_sensitive ? csmatch(str, mask) : match(str, mask);