]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/helperfuncs.cpp
m_spanningtree atoi() to ConvToInt() conversion, add const where possible
[user/henk/code/inspircd.git] / src / helperfuncs.cpp
index 3795e63987cbb5c4b46708e9b665989c00502bda..fba76805c0495b1ae9ef5f0463783318b6f69332 100644 (file)
@@ -140,7 +140,7 @@ Channel* InspIRCd::FindChan(const std::string &chan)
 /* Send an error notice to all users, registered or not */
 void InspIRCd::SendError(const std::string &s)
 {
-       for (std::vector<LocalUser*>::const_iterator i = this->Users->local_users.begin(); i != this->Users->local_users.end(); i++)
+       for (LocalUserList::const_iterator i = this->Users->local_users.begin(); i != this->Users->local_users.end(); i++)
        {
                User* u = *i;
                if (u->registered == REG_ALL)
@@ -281,47 +281,35 @@ void InspIRCd::ProcessColors(file_cache& input)
 }
 
 /* true for valid channel name, false else */
-bool IsChannelHandler::Call(const char *chname, size_t max)
+bool IsChannelHandler::Call(const std::string& chname, size_t max)
 {
-       const char *c = chname + 1;
+       if (chname.empty() || chname.length() > max)
+               return false;
 
-       /* check for no name - don't check for !*chname, as if it is empty, it won't be '#'! */
-       if (!chname || *chname != '#')
-       {
+       if (chname[0] != '#')
                return false;
-       }
 
-       while (*c)
+       for (std::string::const_iterator i = chname.begin()+1; i != chname.end(); ++i)
        {
-               switch (*c)
+               switch (*i)
                {
                        case ' ':
                        case ',':
                        case 7:
                                return false;
                }
-
-               c++;
-       }
-
-       size_t len = c - chname;
-       /* too long a name - note funky pointer arithmetic here. */
-       if (len > max)
-       {
-                       return false;
        }
 
        return true;
 }
 
 /* true for valid nickname, false else */
-bool IsNickHandler::Call(const char* n, size_t max)
+bool IsNickHandler::Call(const std::string& n, size_t max)
 {
-       if (!n || !*n)
+       if (n.empty() || n.length() > max)
                return false;
 
-       unsigned int p = 0;
-       for (const char* i = n; *i; i++, p++)
+       for (std::string::const_iterator i = n.begin(); i != n.end(); ++i)
        {
                if ((*i >= 'A') && (*i <= '}'))
                {
@@ -329,7 +317,7 @@ bool IsNickHandler::Call(const char* n, size_t max)
                        continue;
                }
 
-               if ((((*i >= '0') && (*i <= '9')) || (*i == '-')) && (i > n))
+               if ((((*i >= '0') && (*i <= '9')) || (*i == '-')) && (i != n.begin()))
                {
                        /* "0"-"9", "-" can occur anywhere BUT the first char of a nickname */
                        continue;
@@ -339,17 +327,16 @@ bool IsNickHandler::Call(const char* n, size_t max)
                return false;
        }
 
-       /* too long? or not -- pointer arithmetic rocks */
-       return (p < max);
+       return true;
 }
 
 /* return true for good ident, false else */
-bool IsIdentHandler::Call(const char* n)
+bool IsIdentHandler::Call(const std::string& n)
 {
-       if (!n || !*n)
+       if (n.empty())
                return false;
 
-       for (const char* i = n; *i; i++)
+       for (std::string::const_iterator i = n.begin(); i != n.end(); ++i)
        {
                if ((*i >= 'A') && (*i <= '}'))
                {
@@ -367,7 +354,7 @@ bool IsIdentHandler::Call(const char* n)
        return true;
 }
 
-bool IsSIDHandler::Call(const std::string &str)
+bool InspIRCd::IsSID(const std::string &str)
 {
        /* Returns true if the string given is exactly 3 characters long,
         * starts with a digit, and the other two characters are A-Z or digits
@@ -392,7 +379,7 @@ bool InspIRCd::OpenLog(char**, int)
        }
 
        FileWriter* fw = new FileWriter(startup);
-       FileLogStream *f = new FileLogStream((Config->cmdline.forcedebug ? DEBUG : DEFAULT), fw);
+       FileLogStream *f = new FileLogStream((Config->cmdline.forcedebug ? LOG_DEBUG : LOG_DEFAULT), fw);
 
        this->Logs->AddLogType("*", f, true);
 
@@ -405,7 +392,7 @@ void InspIRCd::CheckRoot()
        if (geteuid() == 0)
        {
                std::cout << "ERROR: You are running an irc server as root! DO NOT DO THIS!" << std::endl << std::endl;
-               this->Logs->Log("STARTUP",DEFAULT,"Can't start as root");
+               this->Logs->Log("STARTUP",LOG_DEFAULT,"Can't start as root");
                Exit(EXIT_STATUS_ROOT);
        }
 #endif
@@ -436,7 +423,7 @@ void InspIRCd::SendWhoisLine(User* user, User* dest, int numeric, const char* fo
 /** Refactored by Brain, Jun 2009. Much faster with some clever O(1) array
  * lookups and pointer maths.
  */
-long InspIRCd::Duration(const std::string &str)
+unsigned long InspIRCd::Duration(const std::string &str)
 {
        unsigned char multiplier = 0;
        long total = 0;
@@ -498,26 +485,6 @@ std::string InspIRCd::TimeString(time_t curtime)
        return std::string(ctime(&curtime),24);
 }
 
-// You should only pass a single character to this.
-void InspIRCd::AddExtBanChar(char c)
-{
-       std::string &tok = Config->data005;
-       std::string::size_type ebpos = tok.find(" EXTBAN=,");
-
-       if (ebpos == std::string::npos)
-       {
-               tok.append(" EXTBAN=,");
-               tok.push_back(c);
-       }
-       else
-       {
-               ebpos += 9;
-               while (isalpha(tok[ebpos]) && tok[ebpos] < c)
-                       ebpos++;
-               tok.insert(ebpos, 1, c);
-       }
-}
-
 std::string InspIRCd::GenRandomStr(int length, bool printable)
 {
        char* buf = new char[length];