]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add alias:matchcase config setting (per-alias, determines wether to match case on...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 14 Jan 2007 13:30:43 +0000 (13:30 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 14 Jan 2007 13:30:43 +0000 (13:30 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6319 e03df62e-2008-0410-955e-edbf42e46eb7

include/wildcard.h
src/modules/m_alias.cpp
src/wildcard.cpp

index f971d7b3464913da7f0e52c29842569a8681f38a..4bea2ff02e1be42f542383d8a89c95c387c13bbb 100644 (file)
@@ -13,6 +13,5 @@
 
 #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);
index ffa6c1e4603d52bdc7c44888b652c3e203479ee4..e8fe736c4d0c02103e792c711496301135389d15 100644 (file)
@@ -15,6 +15,7 @@
 #include "channels.h"
 #include "modules.h"
 #include "inspircd.h"
+#include "wildcard.h"
 #include <vector>
 
 /* $ModDesc: Provides aliases of commands. */
@@ -34,6 +35,8 @@ class Alias : public classbase
        bool uline;
        /** Requires oper? */
        bool operonly;
+       /* is case sensitive params */
+       bool case_sensitive;
        /** Format that must be matched for use */
        std::string format;
 };
@@ -63,6 +66,7 @@ class ModuleAlias : public Module
                        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;
                }
@@ -162,9 +166,10 @@ class ModuleAlias : public Module
                        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))
index f99054939056b230550e27aebf3dffc45f8c9292..2243bc88217578b4607650a0c00e081aaaa407a4 100644 (file)
@@ -28,6 +28,55 @@ using irc::sockets::MatchCIDR;
 // (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;
@@ -84,3 +133,10 @@ bool match(const char *str, const char *mask, bool use_cidr_match)
                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);
+}