summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2007-07-24 14:30:15 +0000
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2007-07-24 14:30:15 +0000
commit46018cde08a63132b3bbd406f8d80215b6dbb87d (patch)
treefcb9666a7bf57ea14c06081a6e8417368a0e2c56 /src
parent886c51566beb95ec568bca5273b7c9cb2c9f0e0c (diff)
Refactor some craq to not loop through a string 4-5 times for a simple operation
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7539 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/modules.cpp41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/modules.cpp b/src/modules.cpp
index 9deaa7954..00d7e7871 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -509,27 +509,30 @@ bool InspIRCd::DelELine(const std::string &hostmask)
bool InspIRCd::IsValidMask(const std::string &mask)
{
char* dest = (char*)mask.c_str();
- if (strchr(dest,'!')==0)
- return false;
- if (strchr(dest,'@')==0)
- return false;
- for (char* i = dest; *i; i++)
- if (*i < 32)
- return false;
+ int exclamation = 0;
+ int atsign = 0;
+
for (char* i = dest; *i; i++)
- if (*i > 126)
+ {
+ /* out of range character, bad mask */
+ if (*i < 32 || *i > 126)
+ {
return false;
- unsigned int c = 0;
- for (char* i = dest; *i; i++)
- if (*i == '!')
- c++;
- if (c>1)
- return false;
- c = 0;
- for (char* i = dest; *i; i++)
- if (*i == '@')
- c++;
- if (c>1)
+ }
+
+ switch (*i)
+ {
+ case '!':
+ exclamation++;
+ break;
+ case '@':
+ atsign++;
+ break;
+ }
+ }
+
+ /* valid masks only have 1 ! and @ */
+ if (exclamation != 1 || atsign != 1)
return false;
return true;