]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/wildcard.cpp
Add <gecos> field to <server> in XML stats output, also add to ProtoServer. Fixes...
[user/henk/code/inspircd.git] / src / wildcard.cpp
index 9846b7d4f4213ee603cc6766cbacaad4b6afdf96..2df7a5bec10e769b3e3445e8ebc18132fbfaee0c 100644 (file)
@@ -35,6 +35,9 @@ CoreExport bool csmatch(const std::string &str, const std::string &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 != '?'))
@@ -46,17 +49,19 @@ CoreExport bool csmatch(const std::string &str, const std::string &mask)
 
        while (string != str.end())
        {
-               if (*wild == '*')
+               if (wild != mask.end() && *wild == '*')
                {
                        if (++wild == mask.end())
                                return 1;
 
                        mp = wild;
                        cp = string;
-                       cp++;
+
+                       if (cp != str.end())
+                               cp++;
                }
                else
-               if ((*wild == *string) || (*wild == '?'))
+               if ((string != str.end() && wild != mask.end()) && ((*wild == *string) || (*wild == '?')))
                {
                        wild++;
                        string++;
@@ -64,7 +69,10 @@ CoreExport bool csmatch(const std::string &str, const std::string &mask)
                else
                {
                        wild = mp;
-                       string = cp++;
+                       if (cp == str.end())
+                               cp = str.end();
+                       else
+                               string = cp++;
                }
 
        }
@@ -81,6 +89,9 @@ CoreExport bool match(const std::string &str, const std::string &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 ((lowermap[(unsigned char)*wild] != lowermap[(unsigned char)*string]) && (*wild != '?'))
@@ -92,17 +103,20 @@ CoreExport bool match(const std::string &str, const std::string &mask)
 
        while (string != str.end())
        {
-               if (*wild == '*')
+               if (wild != mask.end() && *wild == '*')
                {
                        if (++wild == mask.end())
                                return 1;
 
                        mp = wild;
                        cp = string;
-                       cp++;
+
+                       if (cp != str.end())
+                               cp++;
+
                }
                else
-               if ((lowermap[(unsigned char)*wild] == lowermap[(unsigned char)*string]) || (*wild == '?'))
+               if ((string != str.end() && wild != mask.end()) && ((lowermap[(unsigned char)*wild] == lowermap[(unsigned char)*string]) || (*wild == '?')))
                {
                        wild++;
                        string++;
@@ -110,7 +124,10 @@ CoreExport bool match(const std::string &str, const std::string &mask)
                else
                {
                        wild = mp;
-                       string = cp++;
+                       if (cp == str.end())
+                               string = str.end();
+                       else
+                               string = cp++;
                }
 
        }