#include "inspircd_config.h"
-bool match(const char* str, const char* mask);
-bool match(const char *str, const char *mask, bool use_cidr_match);
-
+bool match(const char *str, const char *mask, bool use_cidr_match = false);
+bool match(bool case_sensitive, const char *str, const char *mask, bool use_cidr_match = false);
#include "channels.h"
#include "modules.h"
#include "inspircd.h"
+#include "wildcard.h"
#include <vector>
/* $ModDesc: Provides aliases of commands. */
bool uline;
/** Requires oper? */
bool operonly;
+ /* is case sensitive params */
+ bool case_sensitive;
/** Format that must be matched for use */
std::string format;
};
a.uline = MyConf.ReadFlag("alias", "uline", i);
a.operonly = MyConf.ReadFlag("alias", "operonly", i);
a.format = MyConf.ReadValue("alias", "format", i);
+ a.case_sensitive = MyConf.ReadFlag("alias", "matchcase", i);
Aliases.push_back(a);
AliasMap[txt] = 1;
}
if (Aliases[i].text == c)
{
/* Does it match the pattern? */
- if ((!Aliases[i].format.empty()) && (!ServerInstance->MatchText(compare, Aliases[i].format)))
+ if (!Aliases[i].format.empty())
{
- continue;
+ if (!match(Aliases[i].case_sensitive, compare.c_str(), Aliases[i].format.c_str()))
+ continue;
}
if ((Aliases[i].operonly) && (!*user->oper))
// (unattributed to any author) all over the 'net.
// For now, we'll just consider this public domain.
+bool csmatch(const char *str, const char *mask)
+{
+ unsigned char *cp = NULL, *mp = NULL;
+ unsigned char* string = (unsigned char*)str;
+ unsigned char* wild = (unsigned char*)mask;
+
+ while ((*string) && (*wild != '*'))
+ {
+ if ((*wild != *string) && (*wild != '?'))
+ {
+ return 0;
+ }
+ wild++;
+ string++;
+ }
+
+ while (*string)
+ {
+ if (*wild == '*')
+ {
+ if (!*++wild)
+ {
+ return 1;
+ }
+ mp = wild;
+ cp = string+1;
+ }
+ else
+ if ((*wild == *string) || (*wild == '?'))
+ {
+ wild++;
+ string++;
+ }
+ else
+ {
+ wild = mp;
+ string = cp++;
+ }
+
+ }
+
+ while (*wild == '*')
+ {
+ wild++;
+ }
+
+ return !*wild;
+}
+
bool match(const char *str, const char *mask)
{
unsigned char *cp = NULL, *mp = NULL;
return true;
return match(str, mask);
}
+
+bool match(bool case_sensitive, const char *str, const char *mask, bool use_cidr_match)
+{
+ if (use_cidr_match && MatchCIDR(str, mask, true))
+ return true;
+ return csmatch(str, mask);
+}