From 3555423633e1accae18bd804b4c4f9cd69ad33e9 Mon Sep 17 00:00:00 2001 From: brain Date: Wed, 13 Apr 2005 17:22:46 +0000 Subject: Added IsValidHostMask git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1078 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/modules.h | 3 +++ src/modules.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/modules.h b/include/modules.h index 0e8a6a865..a7a42991e 100644 --- a/include/modules.h +++ b/include/modules.h @@ -774,6 +774,9 @@ class Server : public classbase */ virtual long CalcDuration(std::string duration); + /** Returns true if a nick!ident@host string is correctly formatted, false if otherwise. + */ + virtual bool IsValidMask(std::string mask); }; #define CONF_NOT_A_NUMBER 0x000010 diff --git a/src/modules.cpp b/src/modules.cpp index 1bed5bd18..3d4972a2d 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -671,6 +671,34 @@ long Server::CalcDuration(std::string delta) return duration(delta.c_str()); } +bool Server::IsValidMask(std::string mask) +{ + const char* dest = mask.c_str(); + if (strchr(dest,'!')==0) + return false; + if (strchr(dest,'@')==0) + return false; + for (int i = 0; i < strlen(dest); i++) + if (dest[i] < 32) + return false; + for (int i = 0; i < strlen(dest); i++) + if (dest[i] > 126) + return false; + int c = 0; + for (int i = 0; i < strlen(dest); i++) + if (dest[i] == '!') + c++; + if (c>1) + return false; + c = 0; + for (int i = 0; i < strlen(dest); i++) + if (dest[i] == '@') + c++; + if (c>1) + return false; + + return true; +} ConfigReader::ConfigReader() { -- cgit v1.2.3