summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-05-26 12:07:22 +0200
committerAttila Molnar <attilamolnar@hush.com>2014-05-26 12:07:22 +0200
commit0b3f568a7506fb7ddc9a24d6ab12a969befb923d (patch)
tree3351ce34fb05378f5d0269ce505de2a4c7498d82 /src/modules
parente3bcf95ee996c058c73879c12ac5a487f8dcdf46 (diff)
Switch to std::string::compare() from substr() in a couple of places
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_abbreviation.cpp17
-rw-r--r--src/modules/m_alias.cpp10
-rw-r--r--src/modules/m_exemptchanops.cpp2
-rw-r--r--src/modules/m_passforward.cpp8
-rw-r--r--src/modules/m_password_hash.cpp4
-rw-r--r--src/modules/m_spanningtree/compat.cpp2
-rw-r--r--src/modules/m_spanningtree/uid.cpp2
7 files changed, 17 insertions, 28 deletions
diff --git a/src/modules/m_abbreviation.cpp b/src/modules/m_abbreviation.cpp
index 5fa0f55fc..f69d26749 100644
--- a/src/modules/m_abbreviation.cpp
+++ b/src/modules/m_abbreviation.cpp
@@ -38,19 +38,13 @@ class ModuleAbbreviation : public Module
if (validated || command.empty() || *command.rbegin() != '.')
return MOD_RES_PASSTHRU;
- /* Whack the . off the end */
- command.erase(command.end() - 1);
-
/* Look for any command that starts with the same characters, if it does, replace the command string with it */
- size_t clen = command.length();
+ size_t clen = command.length() - 1;
std::string foundcommand, matchlist;
bool foundmatch = false;
for (Commandtable::iterator n = ServerInstance->Parser->cmdlist.begin(); n != ServerInstance->Parser->cmdlist.end(); ++n)
{
- if (n->first.length() < clen)
- continue;
-
- if (command == n->first.substr(0, clen))
+ if (!command.compare(0, clen, n->first, 0, clen))
{
if (matchlist.length() > 450)
{
@@ -76,12 +70,7 @@ class ModuleAbbreviation : public Module
return MOD_RES_DENY;
}
- if (foundcommand.empty())
- {
- /* No match, we have to put the . back again so that the invalid command numeric looks correct. */
- command += '.';
- }
- else
+ if (!foundcommand.empty())
{
command = foundcommand;
}
diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp
index 9055a8bf8..764761099 100644
--- a/src/modules/m_alias.cpp
+++ b/src/modules/m_alias.cpp
@@ -302,28 +302,28 @@ class ModuleAlias : public Module
result.append(GetVar(var, original_line));
i += len - 1;
}
- else if (newline.substr(i, 5) == "$nick")
+ else if (!newline.compare(i, 5, "$nick", 5))
{
result.append(user->nick);
i += 4;
}
- else if (newline.substr(i, 5) == "$host")
+ else if (!newline.compare(i, 5, "$host", 5))
{
result.append(user->host);
i += 4;
}
- else if (newline.substr(i, 5) == "$chan")
+ else if (!newline.compare(i, 5, "$chan", 5))
{
if (chan)
result.append(chan->name);
i += 4;
}
- else if (newline.substr(i, 6) == "$ident")
+ else if (!newline.compare(i, 6, "$ident", 6))
{
result.append(user->ident);
i += 5;
}
- else if (newline.substr(i, 6) == "$vhost")
+ else if (!newline.compare(i, 6, "$vhost", 6))
{
result.append(user->dhost);
i += 5;
diff --git a/src/modules/m_exemptchanops.cpp b/src/modules/m_exemptchanops.cpp
index 14050430f..43ae21a1c 100644
--- a/src/modules/m_exemptchanops.cpp
+++ b/src/modules/m_exemptchanops.cpp
@@ -83,7 +83,7 @@ class ExemptHandler : public HandlerBase3<ModResult, User*, Channel*, const std:
std::string::size_type pos = (*i).mask.find(':');
if (pos == std::string::npos)
continue;
- if ((*i).mask.substr(0,pos) == restriction)
+ if (!i->mask.compare(0, pos, restriction))
minmode = (*i).mask.substr(pos + 1);
}
}
diff --git a/src/modules/m_passforward.cpp b/src/modules/m_passforward.cpp
index 7cf49fd04..8cdd343b1 100644
--- a/src/modules/m_passforward.cpp
+++ b/src/modules/m_passforward.cpp
@@ -44,22 +44,22 @@ class ModulePassForward : public Module
char c = format[i];
if (c == '$')
{
- if (format.substr(i, 13) == "$nickrequired")
+ if (!format.compare(i, 13, "$nickrequired", 13))
{
result.append(nickrequired);
i += 12;
}
- else if (format.substr(i, 5) == "$nick")
+ else if (!format.compare(i, 5, "$nick", 5))
{
result.append(user->nick);
i += 4;
}
- else if (format.substr(i, 5) == "$user")
+ else if (!format.compare(i, 5, "$user", 5))
{
result.append(user->ident);
i += 4;
}
- else if (format.substr(i,5) == "$pass")
+ else if (!format.compare(i, 5, "$pass", 5))
{
result.append(user->password);
i += 4;
diff --git a/src/modules/m_password_hash.cpp b/src/modules/m_password_hash.cpp
index 0e3afb966..89b6605b9 100644
--- a/src/modules/m_password_hash.cpp
+++ b/src/modules/m_password_hash.cpp
@@ -34,7 +34,7 @@ class CommandMkpasswd : public Command
void MakeHash(User* user, const std::string& algo, const std::string& stuff)
{
- if (algo.substr(0,5) == "hmac-")
+ if (!algo.compare(0, 5, "hmac-", 5))
{
std::string type = algo.substr(5);
HashProvider* hp = ServerInstance->Modules->FindDataService<HashProvider>("hash/" + type);
@@ -82,7 +82,7 @@ class ModuleOperHash : public Module
ModResult OnPassCompare(Extensible* ex, const std::string &data, const std::string &input, const std::string &hashtype) CXX11_OVERRIDE
{
- if (hashtype.substr(0,5) == "hmac-")
+ if (!hashtype.compare(0, 5, "hmac-", 5))
{
std::string type = hashtype.substr(5);
HashProvider* hp = ServerInstance->Modules->FindDataService<HashProvider>("hash/" + type);
diff --git a/src/modules/m_spanningtree/compat.cpp b/src/modules/m_spanningtree/compat.cpp
index 1d573b8b4..857e95da9 100644
--- a/src/modules/m_spanningtree/compat.cpp
+++ b/src/modules/m_spanningtree/compat.cpp
@@ -114,7 +114,7 @@ void TreeSocket::WriteLine(const std::string& original_line)
// We're sending channel metadata
line.erase(c, d-c);
}
- else if (line.substr(c, d-c) == " operquit")
+ else if (!line.compare(c, d-c, " operquit", 9))
{
// ":22D METADATA 22DAAAAAX operquit :message" -> ":22DAAAAAX OPERQUIT :message"
line = ":" + line.substr(b+1, c-b) + "OPERQUIT" + line.substr(d);
diff --git a/src/modules/m_spanningtree/uid.cpp b/src/modules/m_spanningtree/uid.cpp
index 51f7026dd..e9e3e217d 100644
--- a/src/modules/m_spanningtree/uid.cpp
+++ b/src/modules/m_spanningtree/uid.cpp
@@ -37,7 +37,7 @@ CmdResult CommandUID::HandleServer(TreeServer* remoteserver, std::vector<std::st
const std::string& modestr = params[8];
/* Is this a valid UID, and not misrouted? */
- if (params[0].length() != UIDGenerator::UUID_LENGTH || params[0].substr(0, 3) != remoteserver->GetID())
+ if (params[0].length() != UIDGenerator::UUID_LENGTH || params[0].compare(0, 3, remoteserver->GetID()))
throw ProtocolException("Bogus UUID");
/* Check parameters for validity before introducing the client, discovered by dmb */
if (modestr[0] != '+')