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)
49 while (*wild && *wild == '*')
56 else if (*wild != '?')
61 if ((map[*wild] == map[*s]))
64 if (*(wild+1) || !*(s+1))
74 else if ( (map[*wild] == map[*string]) || (*wild == '?') )
82 while (*wild && *wild == '*')
88 /********************************************************************
89 * Below here is all wrappers around match_internal
90 ********************************************************************/
92 CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map)
94 return match_internal((const unsigned char *)str.c_str(), (const unsigned char *)mask.c_str(), map);
97 CoreExport bool InspIRCd::Match(const char *str, const char *mask, unsigned const char *map)
99 return match_internal((const unsigned char *)str, (const unsigned char *)mask, map);
102 CoreExport bool InspIRCd::MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map)
104 if (irc::sockets::MatchCIDR(str, mask, true))
107 // Fall back to regular match
108 return InspIRCd::Match(str, mask, NULL);
111 CoreExport bool InspIRCd::MatchCIDR(const char *str, const char *mask, unsigned const char *map)
113 if (irc::sockets::MatchCIDR(str, mask, true))
116 // Fall back to regular match
117 return InspIRCd::Match(str, mask, NULL);