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"
24 * Slow, horrible, etc.
26 * The vastly available 'public domain' one
28 * ZNC's, thought to be faster than ours, but it turned out that we could do better ;-)
30 * Largely from work by peavey and myself (w00t) :)
32 * peavey: Fix glob scan similar to 1.1, but scan ahead on glob in inner loop to retain speedup
33 * this fixes another case which we forgot to test. Add early return for obvious fail condition.
35 static bool match_internal(const unsigned char *string, const unsigned char *wild, unsigned const char *map)
37 const unsigned char *s, *m; m = wild;
39 if (*string && !*wild)
43 map = rfc_case_insensitive_map;
49 while (*wild && *wild == '*')
56 else if (*wild != '?')
61 if ((map[*wild] == map[*s]))
64 if (*(wild+1) || !*(s+1))
72 else if ( (map[*wild] == map[*string]) || (*wild == '?') )
80 while (*wild && *wild == '*')
86 /********************************************************************
87 * Below here is all wrappers around match_internal
88 ********************************************************************/
90 CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map)
92 return match_internal((const unsigned char *)str.c_str(), (const unsigned char *)mask.c_str(), map);
95 CoreExport bool InspIRCd::Match(const char *str, const char *mask, unsigned const char *map)
97 return match_internal((const unsigned char *)str, (const unsigned char *)mask, map);
100 CoreExport bool InspIRCd::MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map)
102 if (irc::sockets::MatchCIDR(str, mask, true))
105 // Fall back to regular match
106 return InspIRCd::Match(str, mask, NULL);
109 CoreExport bool InspIRCd::MatchCIDR(const char *str, const char *mask, unsigned const char *map)
111 if (irc::sockets::MatchCIDR(str, mask, true))
114 // Fall back to regular match
115 return InspIRCd::Match(str, mask, NULL);