diff options
-rw-r--r-- | include/helperfuncs.h | 2 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 33 |
2 files changed, 34 insertions, 1 deletions
diff --git a/include/helperfuncs.h b/include/helperfuncs.h index 1641575a6..70cc06da2 100644 --- a/include/helperfuncs.h +++ b/include/helperfuncs.h @@ -83,7 +83,7 @@ void ShowRULES(userrec *user); bool AllModulesReportReady(userrec* user); bool DirValid(char* dirandfile); std::string GetFullProgDir(char** argv, int argc); - int InsertMode(std::string &output, const char* modes, unsigned short section); +bool IsValidChannelName(const char *); #endif diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index e3e3db023..fc4ec970f 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -1465,3 +1465,36 @@ int InsertMode(std::string &output, const char* mode, unsigned short section) output.insert(pos, mode); return 1; } + +bool IsValidChannelName(const char *chname) +{ + char *c; + + /* check for no name - don't check for !*chname, as if it is empty, it won't be '#'! */ + if (!chname || *chname != '#') + { + return false; + } + + c = (char *)chname + 1; + while (*c) + { + switch (*c) + { + case ' ': + case ',': + case 7: + return false; + } + + c++; + } + + /* too long a name - note funky pointer arithmetic here. */ + if ((c - chname) > CHANMAX) + { + return false; + } + + return true; +} |