diff options
| author | rburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-02-15 15:20:47 +0000 |
|---|---|---|
| committer | rburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-02-15 15:20:47 +0000 |
| commit | b10305ef3b568a43541213b3ab102f85695d7d37 (patch) | |
| tree | 0ba9817f190c9b080b81e3974e89476448299c58 /src | |
| parent | e1828057c322f6e905bcc55a9b5613853d394081 (diff) | |
Convert to use new, (drastically) faster matching algorithm, from InspIRCd. This adds Anope::Match(), and marks match_wild() and match_wild_nocase() deprecated.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2059 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile | 4 | ||||
| -rw-r--r-- | src/misc.c | 60 | ||||
| -rw-r--r-- | src/svsopers.cpp | 17 | ||||
| -rw-r--r-- | src/wildcard.cpp | 81 |
4 files changed, 102 insertions, 60 deletions
diff --git a/src/Makefile b/src/Makefile index 533c89cde..51e469933 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,8 @@ OBJS = actions.o base64.o bots.o botserv.o channels.o chanserv.o commands.o compat.o \ config.o datafiles.o encrypt.o events.o hashcomp.o helpserv.o hostserv.o init.o ircd.o language.o log.o mail.o main.o \ memory.o memoserv.o messages.o misc.o modules.o news.o nickserv.o operserv.o \ - process.o protocol.o send.o servers.o sessions.o slist.o sockutil.o svsopers.o timeout.o users.o module.o modulemanager.o configreader.o + process.o protocol.o send.o servers.o sessions.o slist.o sockutil.o svsopers.o timeout.o users.o module.o modulemanager.o configreader.o \ + wildcard.o INCLUDES = ../include/commands.h ../include/defs.h ../include/language.h \ ../include/pseudo.h ../include/sysconf.h ../include/config.h \ @@ -73,6 +74,7 @@ svsopers.o: svsopers.cpp $(INCLUDES) timeout.o: timeout.c $(INCLUDES) users.o: users.c $(INCLUDES) vsnprintf.o: vsnprintf.c $(INCLUDES) +wildcard.o: wildcard.cpp $(INCLUDES) mod_version: mod_version.c $(INCLUDES) @$(MAKEBIN) $(CC) $(CDEFS) $(CFLAGS) $(MODULEFLAGS) -I../include/ -c mod_version.c diff --git a/src/misc.c b/src/misc.c index 4d4a31a3a..858cb0ebc 100644 --- a/src/misc.c +++ b/src/misc.c @@ -211,68 +211,15 @@ const char *merge_args(int argc, char **argv) /*************************************************************************/ /** - * do_match_wild: Attempt to match a string to a pattern which might contain - * '*' or '?' wildcards. Return 1 if the string matches the - * pattern, 0 if not. - * @param pattern To be matched - * @param str String in which the pattern is to be matched - * @param docase Case In/Senstive - * @return 1 if the string matches the pattern, 0 if not. - */ -static int do_match_wild(const char *pattern, const char *str, int docase) -{ - char c; - const char *s; - - if (!str || !*str || !pattern || !*pattern) { - return 0; - } - - /* This WILL eventually terminate: either by *pattern == 0, or by a - * trailing '*'. */ - - for (;;) { - switch (c = *pattern++) { - case 0: - if (!*str) - return 1; - return 0; - case '?': - if (!*str) - return 0; - str++; - break; - case '*': - if (!*pattern) - return 1; /* trailing '*' matches everything else */ - s = str; - while (*s) { - if ((docase ? (*s == *pattern) - : (tolower(*s) == tolower(*pattern))) - && do_match_wild(pattern, s, docase)) - return 1; - s++; - } - break; - default: - if (docase ? (*str++ != c) : (tolower(*str++) != tolower(c))) - return 0; - break; - } /* switch */ - } -} - -/*************************************************************************/ - -/** * match_wild: Case Senstive wild card search * @param pattern To be matched * @param str String in which the pattern is to be matched * @return 1 if the string matches the pattern, 0 if not. + * NOTE: Deprecated by Anope::Match(). */ int match_wild(const char *pattern, const char *str) { - return do_match_wild(pattern, str, 1); + return Anope::Match(str, pattern, true); } /*************************************************************************/ @@ -282,10 +229,11 @@ int match_wild(const char *pattern, const char *str) * @param pattern To be matched * @param str String in which the pattern is to be matched * @return 1 if the string matches the pattern, 0 if not. + * NOTE: Deprecated by Anope::Match(). */ int match_wild_nocase(const char *pattern, const char *str) { - return do_match_wild(pattern, str, 0); + return Anope::Match(pattern, str, false); } /*************************************************************************/ diff --git a/src/svsopers.cpp b/src/svsopers.cpp index 5e59467b6..8b2adee5b 100644 --- a/src/svsopers.cpp +++ b/src/svsopers.cpp @@ -1,4 +1,15 @@ -#include "services.h" +/* + * Copyright (C) 2008-2009 Robin Burchell <w00t@inspircd.org> + * Copyright (C) 2008-2009 Anope Team <team@anope.org> + * + * Please read COPYING and README for further details. + * + * + * $Id$ + * + */ + + #include "services.h" bool SVSOper::HasCommand(const std::string &cmdstr) { @@ -12,11 +23,11 @@ bool SVSOper::HasPriv(const std::string &privstr) void SVSOper::AddCommand(const std::string &cmdstr) { - + this->commands.push_back(cmdstr); } void SVSOper::AddPriv(const std::string &privstr) { - + this->privs.push_back(privstr); } diff --git a/src/wildcard.cpp b/src/wildcard.cpp new file mode 100644 index 000000000..f2e9d5e9f --- /dev/null +++ b/src/wildcard.cpp @@ -0,0 +1,81 @@ +#include "services.h"
+
+static bool match_internal(const unsigned char *str, const unsigned char *mask, bool case_sensitive)
+{
+ unsigned char *cp = NULL, *mp = NULL;
+ unsigned char* string = (unsigned char*)str;
+ unsigned char* wild = (unsigned char*)mask;
+
+ while ((*string) && (*wild != '*'))
+ {
+ if (case_sensitive)
+ {
+ if (*wild != *string && *wild != '?')
+ return false;
+ }
+ else
+ {
+ if (tolower(*wild) != tolower(*string) && *wild != '?')
+ return false;
+ }
+
+ wild++;
+ string++;
+ }
+
+ while (*string)
+ {
+ if (*wild == '*')
+ {
+ if (!*++wild)
+ {
+ return 1;
+ }
+
+ mp = wild;
+ cp = string+1;
+ }
+ else
+ {
+ if (case_sensitive)
+ {
+ if (*wild == *string || *wild == '?')
+ {
+ wild++;
+ string++;
+ }
+ else
+ {
+ wild = mp;
+ string = cp++;
+ }
+ }
+ else
+ {
+ if (tolower(*wild) == tolower(*string) || *wild == '?')
+ {
+ wild++;
+ string++;
+ }
+ else
+ {
+ wild = mp;
+ string = cp++;
+ }
+ }
+ }
+
+ }
+
+ while (*wild == '*')
+ {
+ wild++;
+ }
+
+ return !*wild;
+}
+
+CoreExport bool Anope::Match(const std::string &str, const std::string &mask, bool case_sensitive = false)
+{
+ return match_internal(str.c_str(), mask.c_str(), case_sensitive);
+}
|
