summaryrefslogtreecommitdiff
path: root/src/wildcard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wildcard.cpp')
-rw-r--r--src/wildcard.cpp46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/wildcard.cpp b/src/wildcard.cpp
index eb9151293..4a313af76 100644
--- a/src/wildcard.cpp
+++ b/src/wildcard.cpp
@@ -19,15 +19,12 @@
*/
-/* $Core */
-
#include "inspircd.h"
-#include "hashcomp.h"
-#include "inspstring.h"
-static bool match_internal(const unsigned char *str, const unsigned char *mask, unsigned const char *map)
+static bool MatchInternal(const unsigned char* str, const unsigned char* mask, unsigned const char* map)
{
- unsigned char *cp = NULL, *mp = NULL;
+ unsigned char* cp = NULL;
+ unsigned char* mp = NULL;
unsigned char* string = (unsigned char*)str;
unsigned char* wild = (unsigned char*)mask;
@@ -74,46 +71,53 @@ static bool match_internal(const unsigned char *str, const unsigned char *mask,
return !*wild;
}
-/********************************************************************
- * Below here is all wrappers around match_internal
- ********************************************************************/
+// Below here is all wrappers around MatchInternal
-CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map)
+bool InspIRCd::Match(const std::string& str, const std::string& mask, unsigned const char* map)
{
if (!map)
map = national_case_insensitive_map;
- return match_internal((const unsigned char *)str.c_str(), (const unsigned char *)mask.c_str(), map);
+ return MatchInternal((const unsigned char*)str.c_str(), (const unsigned char*)mask.c_str(), map);
}
-CoreExport bool InspIRCd::Match(const char *str, const char *mask, unsigned const char *map)
+bool InspIRCd::Match(const char* str, const char* mask, unsigned const char* map)
{
if (!map)
map = national_case_insensitive_map;
- return match_internal((const unsigned char *)str, (const unsigned char *)mask, map);
+
+ return MatchInternal((const unsigned char*)str, (const unsigned char*)mask, map);
}
-CoreExport bool InspIRCd::MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map)
+bool InspIRCd::MatchCIDR(const std::string& str, const std::string& mask, unsigned const char* map)
{
if (irc::sockets::MatchCIDR(str, mask, true))
return true;
- if (!map)
- map = national_case_insensitive_map;
-
// Fall back to regular match
return InspIRCd::Match(str, mask, map);
}
-CoreExport bool InspIRCd::MatchCIDR(const char *str, const char *mask, unsigned const char *map)
+bool InspIRCd::MatchCIDR(const char* str, const char* mask, unsigned const char* map)
{
if (irc::sockets::MatchCIDR(str, mask, true))
return true;
- if (!map)
- map = national_case_insensitive_map;
-
// Fall back to regular match
return InspIRCd::Match(str, mask, map);
}
+bool InspIRCd::MatchMask(const std::string& masks, const std::string& hostname, const std::string& ipaddr)
+{
+ irc::spacesepstream masklist(masks);
+ std::string mask;
+ while (masklist.GetToken(mask))
+ {
+ if (InspIRCd::Match(hostname, mask, ascii_case_insensitive_map) ||
+ InspIRCd::MatchCIDR(ipaddr, mask, ascii_case_insensitive_map))
+ {
+ return true;
+ }
+ }
+ return false;
+}