summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/hashcomp.h48
-rw-r--r--src/commands.cpp8
-rw-r--r--src/commands/cmd_list.cpp2
-rw-r--r--src/commands/cmd_rehash.cpp2
-rw-r--r--src/commands/cmd_who.cpp14
-rw-r--r--src/hashcomp.cpp26
-rw-r--r--src/wildcard.cpp2
-rw-r--r--src/xline.cpp32
8 files changed, 78 insertions, 56 deletions
diff --git a/include/hashcomp.h b/include/hashcomp.h
index 9499c00e4..cc540a3af 100644
--- a/include/hashcomp.h
+++ b/include/hashcomp.h
@@ -36,23 +36,45 @@
#ifndef LOWERMAP
#define LOWERMAP
+
/** A mapping of uppercase to lowercase, including scandinavian
* 'oddities' as specified by RFC1459, e.g. { -> [, and | -> \
*/
-unsigned const char lowermap[256] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, /* 0-19 */
- 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, /* 20-39 */
- 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, /* 40-59 */
- 60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, /* 60-79 */
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 94, 95, 96, 97, 98, 99, /* 80-99 */
- 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, /* 100-119 */
- 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, /* 120-139 */
- 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, /* 140-159 */
- 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, /* 160-179 */
- 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, /* 180-199 */
- 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, /* 200-219 */
- 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, /* 220-239 */
- 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 /* 240-255 */
+unsigned const char rfc_case_insensitive_map[256] = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, /* 0-19 */
+ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, /* 20-39 */
+ 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, /* 40-59 */
+ 60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, /* 60-79 */
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 94, 95, 96, 97, 98, 99, /* 80-99 */
+ 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, /* 100-119 */
+ 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, /* 120-139 */
+ 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, /* 140-159 */
+ 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, /* 160-179 */
+ 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, /* 180-199 */
+ 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, /* 200-219 */
+ 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, /* 220-239 */
+ 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 /* 240-255 */
};
+
+/*
+ * case sensitive map.
+ */
+unsigned const char case_sensitive_map[256] = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
+ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
+ 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
+ 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
+ 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
+ 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
+ 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
+ 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180,
+ 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200,
+ 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
+ 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240,
+ 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
+};
+
#endif
/** The irc namespace contains a number of helper classes.
diff --git a/src/commands.cpp b/src/commands.cpp
index 68ad224ae..62029bd65 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -32,8 +32,8 @@ bool InspIRCd::HostMatchesEveryone(const std::string &mask, User* user)
for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
{
- if ((InspIRCd::Match(u->second->MakeHost(), mask, lowermap)) ||
- (InspIRCd::Match(u->second->MakeHostIP(), mask, lowermap)))
+ if ((InspIRCd::Match(u->second->MakeHost(), mask)) ||
+ (InspIRCd::Match(u->second->MakeHostIP(), mask)))
{
matches++;
}
@@ -64,7 +64,7 @@ bool InspIRCd::IPMatchesEveryone(const std::string &ip, User* user)
for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
{
- if (InspIRCd::Match(u->second->GetIPString(), ip, lowermap))
+ if (InspIRCd::Match(u->second->GetIPString(), ip))
matches++;
}
@@ -93,7 +93,7 @@ bool InspIRCd::NickMatchesEveryone(const std::string &nick, User* user)
for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
{
- if (InspIRCd::Match(u->second->nick, nick, lowermap))
+ if (InspIRCd::Match(u->second->nick, nick))
matches++;
}
diff --git a/src/commands/cmd_list.cpp b/src/commands/cmd_list.cpp
index d4abfd437..900946eaf 100644
--- a/src/commands/cmd_list.cpp
+++ b/src/commands/cmd_list.cpp
@@ -53,7 +53,7 @@ CmdResult CommandList::Handle (const std::vector<std::string>& parameters, User
if (parameters.size() && (parameters[0][0] != '<' || parameters[0][0] == '>'))
{
- if (!InspIRCd::Match(i->second->name, parameters[0], lowermap) && !InspIRCd::Match(i->second->topic, parameters[0], lowermap))
+ if (!InspIRCd::Match(i->second->name, parameters[0]) && !InspIRCd::Match(i->second->topic, parameters[0]))
continue;
}
diff --git a/src/commands/cmd_rehash.cpp b/src/commands/cmd_rehash.cpp
index 28ae32a0d..9a9384af5 100644
--- a/src/commands/cmd_rehash.cpp
+++ b/src/commands/cmd_rehash.cpp
@@ -28,7 +28,7 @@ CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, Use
if (parameters.size() && parameters[0][0] != '-')
{
- if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0], lowermap))
+ if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0]))
{
FOREACH_MOD(I_OnRehash,OnRehash(user, parameters[0]));
return CMD_SUCCESS; // rehash for a server, and not for us
diff --git a/src/commands/cmd_who.cpp b/src/commands/cmd_who.cpp
index 1ce4e4c28..403ec5f64 100644
--- a/src/commands/cmd_who.cpp
+++ b/src/commands/cmd_who.cpp
@@ -71,11 +71,11 @@ bool CommandWho::whomatch(User* user, const char* matchtext)
if (opt_metadata)
match = user->GetExt(matchtext, dummy);
else if (opt_realname)
- match = InspIRCd::Match(user->fullname, matchtext, lowermap);
+ match = InspIRCd::Match(user->fullname, matchtext);
else if (opt_showrealhost)
- match = InspIRCd::Match(user->host, matchtext, lowermap);
+ match = InspIRCd::Match(user->host, matchtext);
else if (opt_ident)
- match = InspIRCd::Match(user->ident, matchtext, lowermap);
+ match = InspIRCd::Match(user->ident, matchtext);
else if (opt_port)
{
irc::portparser portrange(matchtext, false);
@@ -88,7 +88,7 @@ bool CommandWho::whomatch(User* user, const char* matchtext)
}
}
else if (opt_away)
- match = InspIRCd::Match(user->awaymsg, matchtext, lowermap);
+ match = InspIRCd::Match(user->awaymsg, matchtext);
else if (opt_time)
{
long seconds = ServerInstance->Duration(matchtext);
@@ -106,13 +106,13 @@ bool CommandWho::whomatch(User* user, const char* matchtext)
* -- w00t
*/
if (!match)
- match = InspIRCd::Match(user->dhost, matchtext, lowermap);
+ match = InspIRCd::Match(user->dhost, matchtext);
if (!match)
- match = InspIRCd::Match(user->nick, matchtext, lowermap);
+ match = InspIRCd::Match(user->nick, matchtext);
if (!match)
- match = InspIRCd::Match(user->server, matchtext, lowermap);
+ match = InspIRCd::Match(user->server, matchtext);
return match;
}
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp
index f98446ba6..a9a3441b9 100644
--- a/src/hashcomp.cpp
+++ b/src/hashcomp.cpp
@@ -56,7 +56,7 @@ void nspace::strlower(char *n)
if (n)
{
for (char* t = n; *t; t++)
- *t = lowermap[(unsigned char)*t];
+ *t = rfc_case_insensitive_map[(unsigned char)*t];
}
}
@@ -73,12 +73,12 @@ void nspace::strlower(char *n)
/* XXX: NO DATA COPIES! :)
* The hash function here is practically
* a copy of the one in STL's hash_fun.h,
- * only with *x replaced with lowermap[*x].
+ * only with *x replaced with rfc_case_insensitive_map[*x].
* This avoids a copy to use hash<const char*>
*/
register size_t t = 0;
for (std::string::const_iterator x = s.begin(); x != s.end(); ++x) /* ++x not x++, as its faster */
- t = 5 * t + lowermap[(unsigned char)*x];
+ t = 5 * t + rfc_case_insensitive_map[(unsigned char)*x];
return t;
}
@@ -91,7 +91,7 @@ size_t nspace::hash_compare<irc::string, std::less<irc::string> >::operator()(co
{
register size_t t = 0;
for (irc::string::const_iterator x = s.begin(); x != s.end(); ++x) /* ++x not x++, as its faster */
- t = 5 * t + lowermap[(unsigned char)*x];
+ t = 5 * t + rfc_case_insensitive_map[(unsigned char)*x];
return t;
}
@@ -100,9 +100,9 @@ bool irc::StrHashComp::operator()(const std::string& s1, const std::string& s2)
const unsigned char* n1 = (const unsigned char*)s1.c_str();
const unsigned char* n2 = (const unsigned char*)s2.c_str();
for (; *n1 && *n2; n1++, n2++)
- if (lowermap[*n1] != lowermap[*n2])
+ if (rfc_case_insensitive_map[*n1] != rfc_case_insensitive_map[*n2])
return false;
- return (lowermap[*n1] == lowermap[*n2]);
+ return (rfc_case_insensitive_map[*n1] == rfc_case_insensitive_map[*n2]);
}
/******************************************************
@@ -112,33 +112,33 @@ bool irc::StrHashComp::operator()(const std::string& s1, const std::string& s2)
* std::string which is not only case-insensitive but
* can also do scandanavian comparisons, e.g. { = [, etc.
*
- * This class depends on the const array 'lowermap'.
+ * This class depends on the const array 'rfc_case_insensitive_map'.
*
******************************************************/
bool irc::irc_char_traits::eq(char c1st, char c2nd)
{
- return lowermap[(unsigned char)c1st] == lowermap[(unsigned char)c2nd];
+ return rfc_case_insensitive_map[(unsigned char)c1st] == rfc_case_insensitive_map[(unsigned char)c2nd];
}
bool irc::irc_char_traits::ne(char c1st, char c2nd)
{
- return lowermap[(unsigned char)c1st] != lowermap[(unsigned char)c2nd];
+ return rfc_case_insensitive_map[(unsigned char)c1st] != rfc_case_insensitive_map[(unsigned char)c2nd];
}
bool irc::irc_char_traits::lt(char c1st, char c2nd)
{
- return lowermap[(unsigned char)c1st] < lowermap[(unsigned char)c2nd];
+ return rfc_case_insensitive_map[(unsigned char)c1st] < rfc_case_insensitive_map[(unsigned char)c2nd];
}
int irc::irc_char_traits::compare(const char* str1, const char* str2, size_t n)
{
for(unsigned int i = 0; i < n; i++)
{
- if(lowermap[(unsigned char)*str1] > lowermap[(unsigned char)*str2])
+ if(rfc_case_insensitive_map[(unsigned char)*str1] > rfc_case_insensitive_map[(unsigned char)*str2])
return 1;
- if(lowermap[(unsigned char)*str1] < lowermap[(unsigned char)*str2])
+ if(rfc_case_insensitive_map[(unsigned char)*str1] < rfc_case_insensitive_map[(unsigned char)*str2])
return -1;
if(*str1 == 0 || *str2 == 0)
@@ -152,7 +152,7 @@ int irc::irc_char_traits::compare(const char* str1, const char* str2, size_t n)
const char* irc::irc_char_traits::find(const char* s1, int n, char c)
{
- while(n-- > 0 && lowermap[(unsigned char)*s1] != lowermap[(unsigned char)c])
+ while(n-- > 0 && rfc_case_insensitive_map[(unsigned char)*s1] != rfc_case_insensitive_map[(unsigned char)c])
s1++;
return s1;
}
diff --git a/src/wildcard.cpp b/src/wildcard.cpp
index 270117b65..b49ba943a 100644
--- a/src/wildcard.cpp
+++ b/src/wildcard.cpp
@@ -40,7 +40,7 @@ static bool match_internal(const unsigned char *string, const unsigned char *wil
return false;
if (!map)
- map = lowermap;
+ map = rfc_case_insensitive_map;
while (*string)
{
diff --git a/src/xline.cpp b/src/xline.cpp
index 53493b59e..b74072bff 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -457,10 +457,10 @@ bool KLine::Matches(User *u)
if (u->exempt)
return false;
- if (InspIRCd::Match(u->ident, this->identmask, NULL))
+ if (InspIRCd::Match(u->ident, this->identmask))
{
- if (InspIRCd::MatchCIDR(u->host, this->hostmask, NULL) ||
- InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask, NULL))
+ if (InspIRCd::MatchCIDR(u->host, this->hostmask) ||
+ InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask))
{
return true;
}
@@ -479,10 +479,10 @@ bool GLine::Matches(User *u)
if (u->exempt)
return false;
- if (InspIRCd::Match(u->ident, this->identmask, NULL))
+ if (InspIRCd::Match(u->ident, this->identmask))
{
- if (InspIRCd::MatchCIDR(u->host, this->hostmask, NULL) ||
- InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask, NULL))
+ if (InspIRCd::MatchCIDR(u->host, this->hostmask) ||
+ InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask))
{
return true;
}
@@ -501,10 +501,10 @@ bool ELine::Matches(User *u)
if (u->exempt)
return false;
- if (InspIRCd::Match(u->ident, this->identmask, NULL))
+ if (InspIRCd::Match(u->ident, this->identmask))
{
- if (InspIRCd::MatchCIDR(u->host, this->hostmask, NULL) ||
- InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask, NULL))
+ if (InspIRCd::MatchCIDR(u->host, this->hostmask) ||
+ InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask))
{
return true;
}
@@ -518,7 +518,7 @@ bool ZLine::Matches(User *u)
if (u->exempt)
return false;
- if (InspIRCd::MatchCIDR(u->GetIPString(), this->ipaddr, NULL))
+ if (InspIRCd::MatchCIDR(u->GetIPString(), this->ipaddr))
return true;
else
return false;
@@ -535,7 +535,7 @@ bool QLine::Matches(User *u)
if (u->exempt)
return false;
- if (InspIRCd::Match(u->nick, this->nick, lowermap))
+ if (InspIRCd::Match(u->nick, this->nick))
return true;
return false;
@@ -550,7 +550,7 @@ void QLine::Apply(User* u)
bool ZLine::Matches(const std::string &str)
{
- if (InspIRCd::MatchCIDR(str, this->ipaddr, NULL))
+ if (InspIRCd::MatchCIDR(str, this->ipaddr))
return true;
else
return false;
@@ -558,7 +558,7 @@ bool ZLine::Matches(const std::string &str)
bool QLine::Matches(const std::string &str)
{
- if (InspIRCd::Match(str, this->nick, lowermap))
+ if (InspIRCd::Match(str, this->nick))
return true;
return false;
@@ -566,17 +566,17 @@ bool QLine::Matches(const std::string &str)
bool ELine::Matches(const std::string &str)
{
- return (InspIRCd::MatchCIDR(str, matchtext, NULL));
+ return (InspIRCd::MatchCIDR(str, matchtext));
}
bool KLine::Matches(const std::string &str)
{
- return (InspIRCd::MatchCIDR(str.c_str(), matchtext, NULL));
+ return (InspIRCd::MatchCIDR(str.c_str(), matchtext));
}
bool GLine::Matches(const std::string &str)
{
- return (InspIRCd::MatchCIDR(str, matchtext, NULL));
+ return (InspIRCd::MatchCIDR(str, matchtext));
}
void ELine::OnAdd()