summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2013-04-01 16:20:35 +0200
committerattilamolnar <attilamolnar@hush.com>2013-04-01 16:20:35 +0200
commit713416ddfc182873d29e65161f76c89b961413a2 (patch)
tree28da3b5dc9ef441c3dc74e07f7aae50b1202da38
parent6a080dfd911e9463d35aad226384aa2a94f38057 (diff)
Change IsNickHandler()/IsIdentHandler()/IsChannelHandler() to use C++ strings as arguments instead of C strings
-rw-r--r--include/inspircd.h12
-rw-r--r--src/commands/cmd_nick.cpp2
-rw-r--r--src/configreader.cpp2
-rw-r--r--src/helperfuncs.cpp41
-rw-r--r--src/modules/m_channames.cpp29
-rw-r--r--src/modules/m_nationalchars.cpp13
-rw-r--r--src/modules/m_nicklock.cpp2
-rw-r--r--src/modules/m_sanick.cpp2
8 files changed, 45 insertions, 58 deletions
diff --git a/include/inspircd.h b/include/inspircd.h
index 456a78d40..6b7a01b95 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -263,10 +263,10 @@ class serverstats
}
};
-DEFINE_HANDLER2(IsNickHandler, bool, const char*, size_t);
+DEFINE_HANDLER2(IsNickHandler, bool, const std::string&, size_t);
DEFINE_HANDLER2(GenRandomHandler, void, char*, size_t);
-DEFINE_HANDLER1(IsIdentHandler, bool, const char*);
-DEFINE_HANDLER2(IsChannelHandler, bool, const char*, size_t);
+DEFINE_HANDLER1(IsIdentHandler, bool, const std::string&);
+DEFINE_HANDLER2(IsChannelHandler, bool, const std::string&, size_t);
DEFINE_HANDLER1(RehashHandler, void, const std::string&);
DEFINE_HANDLER3(OnCheckExemptionHandler, ModResult, User*, Channel*, const std::string&);
@@ -566,7 +566,7 @@ class CoreExport InspIRCd
* @param chname A channel name to verify
* @return True if the name is valid
*/
- caller2<bool, const char*, size_t> IsChannel;
+ caller2<bool, const std::string&, size_t> IsChannel;
/** Return true if str looks like a server ID
* @param string to check against
@@ -614,13 +614,13 @@ class CoreExport InspIRCd
* @param n A nickname to verify
* @return True if the nick is valid
*/
- caller2<bool, const char*, size_t> IsNick;
+ caller2<bool, const std::string&, size_t> IsNick;
/** Return true if an ident is valid
* @param An ident to verify
* @return True if the ident is valid
*/
- caller1<bool, const char*> IsIdent;
+ caller1<bool, const std::string&> IsIdent;
/** Add a dns Resolver class to this server's active set
* @param r The resolver to add
diff --git a/src/commands/cmd_nick.cpp b/src/commands/cmd_nick.cpp
index a079e59d0..4c26d947f 100644
--- a/src/commands/cmd_nick.cpp
+++ b/src/commands/cmd_nick.cpp
@@ -66,7 +66,7 @@ CmdResult CommandNick::Handle (const std::vector<std::string>& parameters, User
{
newnick = user->uuid;
}
- else if (!ServerInstance->IsNick(newnick.c_str(), ServerInstance->Config->Limits.NickMax))
+ else if (!ServerInstance->IsNick(newnick, ServerInstance->Config->Limits.NickMax))
{
user->WriteNumeric(432, "%s %s :Erroneous Nickname", user->nick.c_str(),newnick.c_str());
return CMD_FAILURE;
diff --git a/src/configreader.cpp b/src/configreader.cpp
index df78fcab8..668290f4d 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -241,7 +241,7 @@ void ServerConfig::CrossCheckOperClassType()
std::string name = tag->getString("name");
if (name.empty())
throw CoreException("<type:name> is missing from tag at " + tag->getTagLocation());
- if (!ServerInstance->IsNick(name.c_str(), Limits.NickMax))
+ if (!ServerInstance->IsNick(name, Limits.NickMax))
throw CoreException("<type:name> is invalid (value '" + name + "')");
if (oper_blocks.find(" " + name) != oper_blocks.end())
throw CoreException("Duplicate type block with name " + name + " at " + tag->getTagLocation());
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 7ee78c46e..42cb55cfd 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -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 */
- 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 <= '}'))
{
diff --git a/src/modules/m_channames.cpp b/src/modules/m_channames.cpp
index e78171c4a..e9e5ba305 100644
--- a/src/modules/m_channames.cpp
+++ b/src/modules/m_channames.cpp
@@ -23,35 +23,34 @@
static std::bitset<256> allowedmap;
-class NewIsChannelHandler : public HandlerBase2<bool, const char*, size_t>
+class NewIsChannelHandler : public HandlerBase2<bool, const std::string&, size_t>
{
public:
NewIsChannelHandler() { }
virtual ~NewIsChannelHandler() { }
- virtual bool Call(const char*, size_t);
+ virtual bool Call(const std::string&, size_t);
};
-bool NewIsChannelHandler::Call(const char* c, size_t max)
+bool NewIsChannelHandler::Call(const std::string& channame, size_t max)
{
- /* check for no name - don't check for !*chname, as if it is empty, it won't be '#'! */
- if (!c || *c++ != '#')
+ if (channame.empty() || channame.length() > max || channame[0] != '#')
+ return false;
+
+ for (std::string::const_iterator c = channame.begin(); c != channame.end(); ++c)
+ {
+ unsigned int i = *c & 0xFF;
+ if (!allowedmap[i])
return false;
+ }
- while (*c && --max)
- {
- unsigned int i = *c++ & 0xFF;
- if (!allowedmap[i])
- return false;
- }
- // a name of exactly max length will have max = 1 here; the null does not trigger --max
- return max;
+ return true;
}
class ModuleChannelNames : public Module
{
private:
NewIsChannelHandler myhandler;
- caller2<bool, const char*, size_t> rememberer;
+ caller2<bool, const std::string&, size_t> rememberer;
bool badchan;
public:
@@ -73,7 +72,7 @@ class ModuleChannelNames : public Module
std::vector<Channel*> chanvec;
for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); ++i)
{
- if (!ServerInstance->IsChannel(i->second->name.c_str(), MAXBUF))
+ if (!ServerInstance->IsChannel(i->second->name, MAXBUF))
chanvec.push_back(i->second);
}
std::vector<Channel*>::reverse_iterator c2 = chanvec.rbegin();
diff --git a/src/modules/m_nationalchars.cpp b/src/modules/m_nationalchars.cpp
index b43b6e2b6..59277bb9e 100644
--- a/src/modules/m_nationalchars.cpp
+++ b/src/modules/m_nationalchars.cpp
@@ -31,12 +31,12 @@
/* $ModDesc: Provides an ability to have non-RFC1459 nicks & support for national CASEMAPPING */
-class lwbNickHandler : public HandlerBase2<bool, const char*, size_t>
+class lwbNickHandler : public HandlerBase2<bool, const std::string&, size_t>
{
public:
lwbNickHandler() { }
virtual ~lwbNickHandler() { }
- virtual bool Call(const char*, size_t);
+ virtual bool Call(const std::string&, size_t);
};
/*,m_reverse_additionalUp[256];*/
@@ -71,11 +71,12 @@ char utf8size(unsigned char * mb)
/* Conditions added */
-bool lwbNickHandler::Call(const char* n, size_t max)
+bool lwbNickHandler::Call(const std::string& nick, size_t max)
{
- if (!n || !*n)
+ if (nick.empty())
return false;
+ const char* n = nick.c_str();
unsigned int p = 0;
for (const char* i = n; *i; i++, p++)
{
@@ -225,7 +226,7 @@ class ModuleNationalChars : public Module
lwbNickHandler myhandler;
std::string charset, casemapping;
unsigned char m_additional[256], m_additionalUp[256], m_lower[256], m_upper[256];
- caller2<bool, const char*, size_t> rememberer;
+ caller2<bool, const std::string&, size_t> rememberer;
bool forcequit;
const unsigned char * lowermap_rememberer;
@@ -276,7 +277,7 @@ class ModuleNationalChars : public Module
{
/* Fix by Brain: Dont quit UID users */
User* n = *iter;
- if (!isdigit(n->nick[0]) && !ServerInstance->IsNick(n->nick.c_str(), ServerInstance->Config->Limits.NickMax))
+ if (!isdigit(n->nick[0]) && !ServerInstance->IsNick(n->nick, ServerInstance->Config->Limits.NickMax))
ServerInstance->Users->QuitUser(n, message);
}
}
diff --git a/src/modules/m_nicklock.cpp b/src/modules/m_nicklock.cpp
index abeb25869..b5564f215 100644
--- a/src/modules/m_nicklock.cpp
+++ b/src/modules/m_nicklock.cpp
@@ -51,7 +51,7 @@ class CommandNicklock : public Command
/* Do local sanity checks and bails */
if (IS_LOCAL(user))
{
- if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
+ if (!ServerInstance->IsNick(parameters[1], ServerInstance->Config->Limits.NickMax))
{
user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str());
return CMD_FAILURE;
diff --git a/src/modules/m_sanick.cpp b/src/modules/m_sanick.cpp
index 4e4be77ae..ba4fdc033 100644
--- a/src/modules/m_sanick.cpp
+++ b/src/modules/m_sanick.cpp
@@ -54,7 +54,7 @@ class CommandSanick : public Command
return CMD_FAILURE;
}
- if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
+ if (!ServerInstance->IsNick(parameters[1], ServerInstance->Config->Limits.NickMax))
{
user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str());
return CMD_FAILURE;