From 6c389362435138c1523e4aedb53938100f6b4c47 Mon Sep 17 00:00:00 2001 From: w00t Date: Sun, 7 Dec 2008 18:31:54 +0000 Subject: national_case_sensitive_map must be static, thanks to the match stuff being static (this is a bit ugly, but necessary for now). Default to national charset map instead of rfc map, as modules may change the pointer. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10857 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/inspircd.h | 2 +- src/inspircd.cpp | 2 +- src/wildcard.cpp | 108 ++++++++++++++++++++++++++++------------------------- 3 files changed, 60 insertions(+), 52 deletions(-) diff --git a/include/inspircd.h b/include/inspircd.h index 59e840b7b..19674c118 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -408,7 +408,7 @@ class CoreExport InspIRCd : public classbase * This is provided as a pointer so that modules can change it to their custom mapping tables, * e.g. for national character support. */ - unsigned const char *national_case_sensitive_map; + static unsigned const char *national_case_sensitive_map; /** Returns the next available UID for this server. */ diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 1f323e023..dd772f94e 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -444,7 +444,6 @@ InspIRCd::InspIRCd(int argc, char** argv) this->XLines = 0; this->Modes = 0; this->Res = 0; - this->national_case_sensitive_map = rfc_case_insensitive_map; // Initialise TIME this->TIME = time(NULL); @@ -986,6 +985,7 @@ void InspIRCd::SetSignal(int signal) */ ENTRYPOINT { + InspIRCd::national_case_sensitive_map = rfc_case_insensitive_map; SI = new InspIRCd(argc, argv); mysig = &SI->s_signal; SI->Run(); diff --git a/src/wildcard.cpp b/src/wildcard.cpp index 63a28b8cb..9f91d9c68 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -19,54 +19,51 @@ static bool match_internal(const unsigned char *str, const unsigned char *mask, unsigned const char *map) { - unsigned char *cp = NULL, *mp = NULL; - unsigned char* string = (unsigned char*)str; - unsigned char* wild = (unsigned char*)mask; - - if (!map) - map = rfc_case_insensitive_map; - - while ((*string) && (*wild != '*')) - { - if ((map[*wild] != map[*string]) && (*wild != '?')) - { - return 0; - } - wild++; - string++; - } - - while (*string) - { - if (*wild == '*') - { - if (!*++wild) - { - return 1; - } - mp = wild; - cp = string+1; - } - else - if ((map[*wild] == map[*string]) || (*wild == '?')) - { - wild++; - string++; - } - else - { - wild = mp; - string = cp++; - } - - } - - while (*wild == '*') - { - wild++; - } - - return !*wild; + unsigned char *cp = NULL, *mp = NULL; + unsigned char* string = (unsigned char*)str; + unsigned char* wild = (unsigned char*)mask; + + while ((*string) && (*wild != '*')) + { + if ((map[*wild] != map[*string]) && (*wild != '?')) + { + return 0; + } + wild++; + string++; + } + + while (*string) + { + if (*wild == '*') + { + if (!*++wild) + { + return 1; + } + mp = wild; + cp = string+1; + } + else + if ((map[*wild] == map[*string]) || (*wild == '?')) + { + wild++; + string++; + } + else + { + wild = mp; + string = cp++; + } + + } + + while (*wild == '*') + { + wild++; + } + + return !*wild; } /******************************************************************** @@ -75,11 +72,16 @@ static bool match_internal(const unsigned char *str, const unsigned char *mask, CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map) { + if (!map) + map = this->national_case_sensitive_map; + return match_internal((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) { + if (!map) + map = this->national_case_sensitive_map; return match_internal((const unsigned char *)str, (const unsigned char *)mask, map); } @@ -88,8 +90,11 @@ CoreExport bool InspIRCd::MatchCIDR(const std::string &str, const std::string &m if (irc::sockets::MatchCIDR(str, mask, true)) return true; + if (!map) + map = this->national_case_sensitive_map; + // Fall back to regular match - return InspIRCd::Match(str, mask, NULL); + return InspIRCd::Match(str, mask, map); } CoreExport bool InspIRCd::MatchCIDR(const char *str, const char *mask, unsigned const char *map) @@ -97,7 +102,10 @@ CoreExport bool InspIRCd::MatchCIDR(const char *str, const char *mask, unsigned if (irc::sockets::MatchCIDR(str, mask, true)) return true; + if (!map) + map = this->national_case_sensitive_map; + // Fall back to regular match - return InspIRCd::Match(str, mask, NULL); + return InspIRCd::Match(str, mask, map); } -- cgit v1.2.3