*/
void SendMode(const std::vector<std::string>& parameters, User *user);
- /** Match two strings using pattern matching.
- * This operates identically to the global function match(),
- * except for that it takes std::string arguments rather than
- * const char* ones.
- * @param sliteral The literal string to match against
- * @param spattern The pattern to match against. CIDR and globs are supported.
- */
- bool MatchText(const std::string &sliteral, const std::string &spattern);
+ /** Match two strings using pattern matching, optionally, with a map
+ * to check case against (may be NULL).
+ * @param str The literal string to match against
+ * @param mask The glob pattern to match against.
+ */
+ static bool Match(const std::string &str, const std::string &mask, unsigned const char *map);
+ static bool Match(const char *str, const char *mask, unsigned const char *map);
+
+ /** Match two strings using pattern matching, optionally, with a map
+ * to check case against (may be NULL). Supports CIDR patterns as well as globs.
+ * @param str The literal string to match against
+ * @param mask The glob or CIDR pattern to match against.
+ */
+ static bool MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map);
+ static bool MatchCIDR(const char *str, const char *mask, unsigned const char *map);
/** Call the handler for a given command.
* @param commandname The command whos handler you wish to call
+++ /dev/null
-/* +------------------------------------+
- * | Inspire Internet Relay Chat Daemon |
- * +------------------------------------+
- *
- * InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
- *
- * This program is free but copyrighted software; see
- * the file COPYING for details.
- *
- * ---------------------------------------------------
- */
-
-/** Match a string against a mask.
- * @param str The string to check
- * @param mask the mask to check against
- * @return true if the strings match
- */
-CoreExport bool match(const std::string &str, const std::string &mask);
-/** Match a string against a mask, and define wether or not to use CIDR rules
- * @param str The string to check
- * @param mask the mask to check against
- * @param use_cidr_match True if CIDR matching rules should be applied first
- * @return true if the strings match
- */
-CoreExport bool match(const std::string &str, const std::string &mask, bool use_cidr_match);
-/** Match a string against a mask, defining wether case sensitivity applies.
- * @param str The string to check
- * @param mask the mask to check against
- * @param case_sensitive True if the match is case sensitive
- * @return True if the strings match
- */
-CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask);
-/** Match a string against a mask, defining wether case sensitivity applies,
- * and defining wether or not to use CIDR rules first.
- * @param case_sensitive True if the match is case sensitive
- * @param str The string to check
- * @param mask the mask to check against
- * @param use_cidr_match True if CIDR matching rules should be applied first
- * @return true if the strings match
- */
-CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask, bool use_cidr_match);
-
#include "inspircd.h"
#include <cstdarg>
-#include "wildcard.h"
#include "mode.h"
Channel::Channel(InspIRCd* Instance, const std::string &cname, time_t ts) : ServerInstance(Instance)
snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
{
- /* This allows CIDR ban matching
- *
- * Full masked host Full unmasked host IP with/without CIDR
- */
- if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true)))
+ if ((InspIRCd::Match(user->GetFullHost(),i->data, NULL)) || // host
+ (InspIRCd::Match(user->GetFullRealHost(),i->data, NULL)) || // uncloaked host
+ (InspIRCd::MatchCIDR(mask, i->data, NULL))) // ip
{
return true;
}
std::string maskptr = i->data.substr(2);
ServerInstance->Logs->Log("EXTBANS", DEBUG, "Checking %s against %s, type is %c", str.c_str(), maskptr.c_str(), type);
- if (match(str, maskptr))
+ if (InspIRCd::Match(str, maskptr, NULL))
return true;
}
}
/* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
{
- if (match(this->name,n->first))
+ if (InspIRCd::Match(this->name, n->first, NULL))
{
this->maxbans = n->second;
return n->second;
/* $Core */
#include "inspircd.h"
-#include "wildcard.h"
/* Used when comparing CIDR masks for the modulus bits left over.
* A lot of ircd's seem to do this:
* symbols, and recursively call MatchCIDR without
* username matching enabled to match the host part.
*/
- return (match(address.substr(0, username_addr_pos), cidr_mask.substr(0, username_mask_pos)) &&
+ return (InspIRCd::Match(address.substr(0, username_addr_pos), cidr_mask.substr(0, username_mask_pos), NULL) &&
MatchCIDR(address.substr(username_addr_pos + 1), cidr_mask.substr(username_mask_pos + 1), false));
}
else
/* $Core */
#include "inspircd.h"
-#include "wildcard.h"
#include "xline.h"
#include "socketengine.h"
#include "socket.h"
dirent* entry = NULL;
while (0 != (entry = readdir(library)))
{
- if (match(entry->d_name, "cmd_*.so"))
+ if (InspIRCd::Match(entry->d_name, "cmd_*.so", NULL))
{
if (!user)
{
/* $Core */
#include "inspircd.h"
-#include "wildcard.h"
#include "xline.h"
#include "command_parse.h"
for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
{
- if ((match(u->second->MakeHost(), mask, true)) || (match(u->second->MakeHostIP(), mask, true)))
+ if ((InspIRCd::Match(u->second->MakeHost(), mask, lowermap)) ||
+ (InspIRCd::Match(u->second->MakeHostIP(), mask, lowermap)))
{
matches++;
}
for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
{
- if (match(u->second->GetIPString(),ip,true))
+ if (InspIRCd::Match(u->second->GetIPString(), ip, lowermap))
matches++;
}
for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++)
{
- if (match(u->second->nick,nick))
+ if (InspIRCd::Match(u->second->nick, nick, lowermap))
matches++;
}
#include "inspircd.h"
#include "commands/cmd_list.h"
-#include "wildcard.h"
/** Handle /LIST
*/
if (parameters.size() && (parameters[0][0] != '<' || parameters[0][0] == '>'))
{
- if (!match(i->second->name, parameters[0]) && !match(i->second->topic, parameters[0]))
+ if (!InspIRCd::Match(i->second->name, parameters[0], lowermap) && !InspIRCd::Match(i->second->topic, parameters[0], lowermap))
continue;
}
*/
#include "inspircd.h"
-#include "wildcard.h"
#include "commands/cmd_modules.h"
const char* itab[] = {
*/
#include "inspircd.h"
-#include "wildcard.h"
#include "commands/cmd_notice.h"
extern "C" DllExport Command* init_command(InspIRCd* Instance)
const char* servermask = (parameters[0].c_str()) + 1;
FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, exempt_list));
- if (match(ServerInstance->Config->ServerName,servermask))
+ if (InspIRCd::Match(ServerInstance->Config->ServerName,servermask, NULL))
{
user->SendAll("NOTICE", "%s", text);
}
*/
#include "inspircd.h"
-#include "wildcard.h"
#include "commands/cmd_oper.h"
#include "hashcomp.h"
std::string xhost;
while (hl >> xhost)
{
- if (match(host, xhost) || match(ip,xhost, true))
+ if (InspIRCd::MatchCIDR(host, xhost, NULL) || InspIRCd::MatchCIDR(ip, xhost, NULL))
{
return true;
}
*/
#include "inspircd.h"
-#include "wildcard.h"
#include "commands/cmd_privmsg.h"
extern "C" DllExport Command* init_command(InspIRCd* Instance)
const char* servermask = (parameters[0].c_str()) + 1;
FOREACH_MOD(I_OnText,OnText(user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list));
- if (match(ServerInstance->Config->ServerName,servermask))
+ if (InspIRCd::Match(ServerInstance->Config->ServerName, servermask, NULL))
{
user->SendAll("PRIVMSG", "%s", text);
}
if (parameters.size() && parameters[0][0] != '-')
{
- if (!ServerInstance->MatchText(ServerInstance->Config->ServerName, parameters[0]))
+ if (!InspIRCd::Match(ServerInstance->Config->ServerName, parameters[0], lowermap))
{
FOREACH_MOD(I_OnRehash,OnRehash(user, parameters[0]));
return CMD_SUCCESS; // rehash for a server, and not for us
*/
#include "inspircd.h"
-#include "wildcard.h"
#include "commands/cmd_who.h"
static const std::string star = "*";
else
{
if (opt_realname)
- realname = match(user->fullname, matchtext);
+ realname = InspIRCd::Match(user->fullname, matchtext, lowermap);
else
{
if (opt_showrealhost)
- realhost = match(user->host, matchtext);
+ realhost = InspIRCd::Match(user->host, matchtext, lowermap);
else
{
if (opt_ident)
- ident = match(user->ident, matchtext);
+ ident = InspIRCd::Match(user->ident, matchtext, lowermap);
else
{
if (opt_port)
else
{
if (opt_away)
- away = match(user->awaymsg, matchtext);
+ away = InspIRCd::Match(user->awaymsg, matchtext, lowermap);
}
}
}
}
}
- return ((port) || (away) || (ident) || (metadata) || (realname) || (realhost) || (match(user->dhost, matchtext)) || (match(user->nick, matchtext)) || (match(user->server, matchtext)));
+ return ((port) || (away) || (ident) || (metadata) || (realname) || (realhost) || (InspIRCd::Match(user->dhost, matchtext, lowermap)) || (InspIRCd::Match(user->nick, matchtext, lowermap)) || (InspIRCd::Match(user->server, matchtext, lowermap)));
}
}
/* $Core */
#include "inspircd.h"
-#include "wildcard.h"
#include "xline.h"
#include "exitcodes.h"
/* $Core */
#include "inspircd.h"
-#include "wildcard.h"
#include "xline.h"
#include "socket.h"
#include "socketengine.h"
dirent* entry = NULL;
while (0 != (entry = readdir(library)))
{
- if (Instance->MatchText(entry->d_name, filename))
+ if (InspIRCd::Match(entry->d_name, filename, NULL))
{
if (!this->Load(entry->d_name))
n_match++;
return NULL;
}
-bool InspIRCd::MatchText(const std::string &sliteral, const std::string &spattern)
-{
- return match(sliteral, spattern);
-}
-
CmdResult InspIRCd::CallCommandHandler(const std::string &commandname, const std::vector<std::string>& parameters, User* user)
{
return this->Parser->CallHandler(commandname, parameters, user);
#include "inspircd.h"
#include "testsuite.h"
#include "threadengine.h"
-#include "wildcard.h"
#include <iostream>
using namespace std;
}
/* Test that x matches y with match() */
-#define WCTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\") " << ((passed = (match(x, y))) ? " SUCCESS!\n" : " FAILURE\n")
+#define WCTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\") " << ((passed = (InspIRCd::Match(x, y, NULL))) ? " SUCCESS!\n" : " FAILURE\n")
/* Test that x does not match y with match() */
-#define WCTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\") " << ((passed = ((!match(x, y)))) ? " SUCCESS!\n" : " FAILURE\n")
+#define WCTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\") " << ((passed = ((!InspIRCd::Match(x, y, NULL)))) ? " SUCCESS!\n" : " FAILURE\n")
/* Test that x matches y with match() and cidr enabled */
-#define CIDRTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\", true) " << ((passed = (match(x, y, true))) ? " SUCCESS!\n" : " FAILURE\n")
+#define CIDRTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\", true) " << ((passed = (InspIRCd::MatchCIDR(x, y, NULL))) ? " SUCCESS!\n" : " FAILURE\n")
/* Test that x does not match y with match() and cidr enabled */
-#define CIDRTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\", true) " << ((passed = ((!match(x, y, true)))) ? " SUCCESS!\n" : " FAILURE\n")
+#define CIDRTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\", true) " << ((passed = ((!InspIRCd::MatchCIDR(x, y, NULL)))) ? " SUCCESS!\n" : " FAILURE\n")
bool TestSuite::DoWildTests()
{
/* $Core */
#include "inspircd.h"
-#include "wildcard.h"
#include "xline.h"
#include "socketengine.h"
#include "command_parse.h"
#include "inspircd.h"
#include <stdarg.h>
#include "socketengine.h"
-#include "wildcard.h"
#include "xline.h"
#include "bancache.h"
#include "commands/cmd_whowas.h"
}
/* check if host matches.. */
- if (((!match(this->GetIPString(),c->GetHost(),true)) && (!match(this->host,c->GetHost()))))
+ if (!InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) &&
+ !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL))
{
ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "No host match (for %s)", c->GetHost().c_str());
continue;
#include "hashcomp.h"
#include "inspstring.h"
-using irc::sockets::MatchCIDR;
-
-/* Rewritten to operate on more effective C++ std::string types
- * rather than char* to avoid data copies.
- * - Brain
+/*
+ * Wildcard matching, the third (and probably final) iteration!
+ *
*/
-
-CoreExport bool csmatch(const std::string &str, const std::string &mask)
+static bool match_internal(const unsigned char *str, const unsigned char *mask, unsigned const char *map)
{
- std::string::const_iterator cp, mp;
-
- //unsigned char *cp = NULL, *mp = NULL;
- //unsigned char* string = (unsigned char*)str;
- //unsigned char* wild = (unsigned char*)mask;
-
- std::string::const_iterator wild = mask.begin();
- std::string::const_iterator string = str.begin();
-
- if (mask.empty())
- return false;
-
- while ((string != str.end()) && (wild != mask.end()) && (*wild != '*'))
- {
- if ((*wild != *string) && (*wild != '?'))
- return false;
-
- wild++;
- string++;
- }
-
- if (wild == mask.end() && string != str.end())
- return false;
+ const unsigned char *wild = str;
+ const unsigned char *string = mask;
+ const unsigned char *cp = NULL;
+ const unsigned char *mp = NULL;
- while (string != str.end())
+ while ((*string) && (*wild != '*'))
{
- if (wild != mask.end() && *wild == '*')
+ if (!map)
{
- if (++wild == mask.end())
- return true;
-
- mp = wild;
- cp = string;
-
- if (cp != str.end())
- cp++;
- }
- else
- if ((string != str.end() && wild != mask.end()) && ((*wild == *string) || (*wild == '?')))
- {
- wild++;
- string++;
+ if ((*wild != *string) && (*wild != '?'))
+ {
+ return false;
+ }
}
else
{
- wild = mp;
- if (cp == str.end())
- cp = str.end();
- else
- string = cp++;
+ if (map[*wild] != map[*string] && (*wild != '?'))
+ {
+ return false;
+ }
}
+ ++wild;
+ ++string;
}
- while ((wild != mask.end()) && (*wild == '*'))
- wild++;
-
- return wild == mask.end();
-}
-
-CoreExport bool match(const std::string &str, const std::string &mask)
-{
- std::string::const_iterator cp, mp;
- std::string::const_iterator wild = mask.begin();
- std::string::const_iterator string = str.begin();
-
- if (mask.empty())
- return false;
-
- while ((string != str.end()) && (wild != mask.end()) && (*wild != '*'))
- {
- if ((lowermap[(unsigned char)*wild] != lowermap[(unsigned char)*string]) && (*wild != '?'))
- return false;
-
- wild++;
- string++;
- //printf("Iterate first loop\n");
- }
-
- if (wild == mask.end() && string != str.end())
- return false;
-
- while (string != str.end())
+ while (*string)
{
- //printf("outer\n %c", *string);
- if (wild != mask.end() && *wild == '*')
+ if (*wild == '*')
{
-
- //printf("inner %c\n", *wild);
- if (++wild == mask.end())
+ if (!*++wild)
+ {
return true;
+ }
mp = wild;
- cp = string;
-
- if (cp != str.end())
- cp++;
-
+ cp = string+1;
}
- else
- if ((string != str.end() && wild != mask.end()) && ((lowermap[(unsigned char)*wild] == lowermap[(unsigned char)*string]) || (*wild == '?')))
+ // if there is no charmap and str == wild OR
+ // there is a map and mapped char == mapped wild AND
+ // wild is NOT ?
+ else if (((!map && *wild == *string) || (map && map[*wild] == map[*string])) && (*wild == '?'))
{
- if (wild != mask.end())
- wild++;
-
- if (string != str.end())
- string++;
+ ++wild;
+ ++string;
}
else
{
wild = mp;
- if (cp == str.end())
- string = str.end();
- else
- string = cp++;
+ string = cp++;
}
-
}
- while ((wild != mask.end()) && (*wild == '*'))
+ while (*wild == '*')
+ {
wild++;
+ }
- return wild == mask.end();
+ return (*wild == 0);
}
-/* Overloaded function that has the option of using cidr */
-CoreExport bool match(const std::string &str, const std::string &mask, bool use_cidr_match)
+CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map)
{
- if (use_cidr_match && MatchCIDR(str, mask, true))
- return true;
- return match(str, mask);
+ return match_internal((const unsigned char *)str.c_str(), (const unsigned char *)mask.c_str(), map);
}
-CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask, bool use_cidr_match)
+CoreExport bool InspIRCd::Match(const char *str, const char *mask, unsigned const char *map)
{
- if (use_cidr_match && MatchCIDR(str, mask, true))
+ return match_internal((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)
+{
+ if (irc::sockets::MatchCIDR(str, mask, true))
return true;
- return case_sensitive ? csmatch(str, mask) : match(str, mask);
+ // Fall back to regular match
+ return InspIRCd::Match(str, mask, NULL);
}
-CoreExport bool match(bool case_sensitive, const std::string &str, const std::string &mask)
+CoreExport bool InspIRCd::MatchCIDR(const char *str, const char *mask, unsigned const char *map)
{
- return case_sensitive ? csmatch(str, mask) : match(str, mask);
+ if (irc::sockets::MatchCIDR(str, mask, true))
+ return true;
+
+ // Fall back to regular match
+ return InspIRCd::Match(str, mask, NULL);
}
/* $Core */
#include "inspircd.h"
-#include "wildcard.h"
#include "xline.h"
#include "bancache.h"
if (u->exempt)
return false;
- if ((match(u->ident, this->identmask)))
+ if (InspIRCd::Match(u->ident, this->identmask, NULL))
{
- if ((match(u->host, this->hostmask, true)) || (match(u->GetIPString(), this->hostmask, true)))
+ if (InspIRCd::MatchCIDR(u->host, this->hostmask, NULL) ||
+ InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask, NULL))
{
return true;
}
if (u->exempt)
return false;
- if ((match(u->ident, this->identmask)))
+ if (InspIRCd::Match(u->ident, this->identmask, NULL))
{
- if ((match(u->host, this->hostmask, true)) || (match(u->GetIPString(), this->hostmask, true)))
+ if (InspIRCd::MatchCIDR(u->host, this->hostmask, NULL) ||
+ InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask, NULL))
{
return true;
}
if (u->exempt)
return false;
- if ((match(u->ident, this->identmask)))
+ if (InspIRCd::Match(u->ident, this->identmask, NULL))
{
- if ((match(u->host, this->hostmask, true)) || (match(u->GetIPString(), this->hostmask, true)))
+ if (InspIRCd::MatchCIDR(u->host, this->hostmask, NULL) ||
+ InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask, NULL))
{
return true;
}
if (u->exempt)
return false;
- if (match(u->GetIPString(), this->ipaddr, true))
+ if (InspIRCd::MatchCIDR(u->GetIPString(), this->ipaddr, NULL))
return true;
else
return false;
if (u->exempt)
return false;
- if (match(u->nick, this->nick))
+ if (InspIRCd::Match(u->nick, this->nick, lowermap))
return true;
return false;
bool ZLine::Matches(const std::string &str)
{
- if (match(str, this->ipaddr, true))
+ if (InspIRCd::MatchCIDR(str, this->ipaddr, NULL))
return true;
else
return false;
bool QLine::Matches(const std::string &str)
{
- if (match(str, this->nick))
+ if (InspIRCd::Match(str, this->nick, lowermap))
return true;
return false;
bool ELine::Matches(const std::string &str)
{
- return ((match(str, matchtext, true)));
+ return (InspIRCd::MatchCIDR(str, matchtext, NULL));
}
bool KLine::Matches(const std::string &str)
{
- return ((match(str.c_str(), matchtext, true)));
+ return (InspIRCd::MatchCIDR(str.c_str(), matchtext, NULL));
}
bool GLine::Matches(const std::string &str)
{
- return ((match(str, matchtext, true)));
+ return (InspIRCd::MatchCIDR(str, matchtext, NULL));
}
void ELine::OnAdd()