diff --git a/IRCSock.cpp b/IRCSock.cpp index 44a30ba1..1e7dd3b2 100644 --- a/IRCSock.cpp +++ b/IRCSock.cpp @@ -62,7 +62,7 @@ void CIRCSock::ReadLine(const string& sData) { if (strncasecmp(sLine.c_str(), "PING ", 5) == 0) { PutServ("PONG " + sLine.substr(5)); - } else if (CUtils::WildCmp(":* * *", sLine.c_str())) { //"^:(\\S+) (\\d\\d\\d) (.*?) (.*)$", vCap)) { + } else if (CUtils::wildcmp(":* * *", sLine.c_str())) { //"^:(\\S+) (\\d\\d\\d) (.*?) (.*)$", vCap)) { string sCmd = CUtils::Token(sLine, 1); if ((sCmd.length() == 3) && (isdigit(sCmd[0])) && (isdigit(sCmd[1])) && (isdigit(sCmd[2]))) { @@ -284,7 +284,7 @@ void CIRCSock::ReadLine(const string& sData) { return; // return so we don't send them the raw twice } } - } else { //if (CUtils::WildCmp(":*!*@* * *", sLine.c_str())) { + } else { //if (CUtils::wildcmp(":*!*@* * *", sLine.c_str())) { string sNickMask = CUtils::Token(sLine, 0); CUtils::LeftChomp(sNickMask); @@ -428,7 +428,7 @@ void CIRCSock::ReadLine(const string& sData) { string sMsg = CUtils::Token(sRest, 1, true); CUtils::LeftChomp(sMsg); - if (CUtils::WildCmp("\001*\001", sMsg.c_str())) { + if (CUtils::wildcmp("\001*\001", sMsg.c_str())) { CUtils::LeftChomp(sMsg); CUtils::RightChomp(sMsg); @@ -465,7 +465,7 @@ void CIRCSock::ReadLine(const string& sData) { CUtils::LeftChomp(sMsg); } - if (CUtils::WildCmp("\001*\001", sMsg.c_str())) { + if (CUtils::wildcmp("\001*\001", sMsg.c_str())) { CUtils::LeftChomp(sMsg); CUtils::RightChomp(sMsg); diff --git a/User.cpp b/User.cpp index 7de493f1..68cbb5eb 100644 --- a/User.cpp +++ b/User.cpp @@ -56,7 +56,7 @@ bool CUser::AddAllowedHost(const string& sHostMask) { bool CUser::IsHostAllowed(const string& sHostMask) { for (set::iterator a = m_ssAllowedHosts.begin(); a != m_ssAllowedHosts.end(); a++) { - if (CUtils::WildCmp(*a, sHostMask)) { + if (CUtils::wildcmp(*a, sHostMask)) { return true; } } diff --git a/UserSock.cpp b/UserSock.cpp index cd19a209..0fefe864 100644 --- a/UserSock.cpp +++ b/UserSock.cpp @@ -131,7 +131,7 @@ void CUserSock::ReadLine(const string& sData) { return; } - if (CUtils::WildCmp("DCC * (*)", sMsg.c_str())) { + if (CUtils::wildcmp("DCC * (*)", sMsg.c_str())) { sMsg = "DCC " + CUtils::Token(sLine, 3) + " (" + ((m_pIRCSock) ? m_pIRCSock->GetLocalIP() : GetLocalIP()) + ")"; } @@ -142,7 +142,7 @@ void CUserSock::ReadLine(const string& sData) { } #ifdef _MODULES - if (CUtils::WildCmp("\001*\001", sMsg.c_str())) { + if (CUtils::wildcmp("\001*\001", sMsg.c_str())) { string sCTCP = sMsg; CUtils::LeftChomp(sCTCP); CUtils::RightChomp(sCTCP); @@ -169,7 +169,7 @@ void CUserSock::ReadLine(const string& sData) { CUtils::LeftChomp(sMsg); } - if (CUtils::WildCmp("\001*\001", sMsg.c_str())) { + if (CUtils::wildcmp("\001*\001", sMsg.c_str())) { string sCTCP = sMsg; CUtils::LeftChomp(sCTCP); CUtils::RightChomp(sCTCP); diff --git a/Utils.cpp b/Utils.cpp index 86fc63c4..4e8fb5b4 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -212,51 +212,42 @@ string CUtils::Ellipsize(const string& s, unsigned int uLen) { return sRet; } -bool CUtils::WildCmp(const string& sWild, const string& sString) { - char *wild = (char*) sWild.c_str(); - char *string = (char*) sString.c_str(); +bool CUtils::wildcmp(const string& sWild, const string& sString) { + // Written by Jack Handy - jakkhandy@hotmail.com + const char *wild = sWild.c_str(), *string = sString.c_str(); + const char *cp = NULL, *mp = NULL; - register int i, len; - char *copy, *cp, *p, *lastmatch = string; - - if ((p = strchr (wild, '*')) == NULL) { - return (strcasecmp(wild, string) ? false : true); - } - - if (wild[0] != '*' && strncasecmp(string, wild, p-wild)) { - return false; - } - - len = strlen(wild) + 1; - - if (wild[len -2] != '*') { - p = strrchr(wild, '*') + 1; - if (strcasecmp(string + strlen(string) - strlen(p), p) != 0) { + while ((*string) && (*wild != '*')) { + if ((*wild != *string) && (*wild != '?')) { return false; } + + wild++; + string++; } - cp = copy = (char*) malloc(len); - memset((char*) copy, 0, len); - - for (i=0; i