summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hashcomp.cpp5
-rw-r--r--src/modules/extra/m_sqlauth.cpp24
-rw-r--r--src/modules/m_alias.cpp24
-rw-r--r--src/modules/m_censor.cpp45
4 files changed, 22 insertions, 76 deletions
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp
index 0d036d528..ab4d8368d 100644
--- a/src/hashcomp.cpp
+++ b/src/hashcomp.cpp
@@ -501,7 +501,7 @@ long irc::portparser::GetToken()
}
}
-const std::string& SearchAndReplace(std::string& text, const std::string& pattern, const std::string& replace)
+/*const std::basic_string& SearchAndReplace(std::string& text, const std::string& pattern, const std::string& replace)
{
std::string replacement;
if ((!pattern.empty()) && (!text.empty()))
@@ -510,7 +510,6 @@ const std::string& SearchAndReplace(std::string& text, const std::string& patter
{
if (text.length() >= pattern.length() && text.substr(n, pattern.length()) == pattern)
{
- /* Found the pattern in the text, replace it, and advance */
replacement.append(replace);
n = n + pattern.length() - 1;
}
@@ -522,5 +521,5 @@ const std::string& SearchAndReplace(std::string& text, const std::string& patter
}
text = replacement;
return text;
-}
+}*/
diff --git a/src/modules/extra/m_sqlauth.cpp b/src/modules/extra/m_sqlauth.cpp
index f03ec08db..4d0cc6a76 100644
--- a/src/modules/extra/m_sqlauth.cpp
+++ b/src/modules/extra/m_sqlauth.cpp
@@ -89,26 +89,28 @@ public:
{
std::string thisquery = freeformquery;
std::string safepass = user->password;
+ std::string safegecos = user->fullname;
/* Search and replace the escaped nick and escaped pass into the query */
- SearchAndReplace(safepass, "\"", "");
+ SearchAndReplace(safepass, std::string("\""), std::string("\\\""));
+ SearchAndReplace(safegecos, std::string("\""), std::string("\\\""));
- SearchAndReplace(thisquery, "$nick", user->nick);
- SearchAndReplace(thisquery, "$pass", safepass);
- SearchAndReplace(thisquery, "$host", user->host);
- SearchAndReplace(thisquery, "$ip", user->GetIPString());
- SearchAndReplace(thisquery, "$gecos", user->fullname);
- SearchAndReplace(thisquery, "$ident", user->ident);
- SearchAndReplace(thisquery, "$server", user->server);
- SearchAndReplace(thisquery, "$uuid", user->uuid);
+ SearchAndReplace(thisquery, std::string("$nick"), user->nick);
+ SearchAndReplace(thisquery, std::string("$pass"), safepass);
+ SearchAndReplace(thisquery, std::string("$host"), user->host);
+ SearchAndReplace(thisquery, std::string("$ip"), std::string(user->GetIPString()));
+ SearchAndReplace(thisquery, std::string("$gecos"), safegecos);
+ SearchAndReplace(thisquery, std::string("$ident"), user->ident);
+ SearchAndReplace(thisquery, std::string("$server"), std::string(user->server));
+ SearchAndReplace(thisquery, std::string("$uuid"), user->uuid);
Module* HashMod = ServerInstance->Modules->Find("m_md5.so");
if (HashMod)
{
HashResetRequest(this, HashMod).Send();
- SearchAndReplace(thisquery, "$md5pass", HashSumRequest(this, HashMod, user->password).Send());
+ SearchAndReplace(thisquery, std::string("$md5pass"), std::string(HashSumRequest(this, HashMod, user->password).Send()));
}
HashMod = ServerInstance->Modules->Find("m_sha256.so");
@@ -116,7 +118,7 @@ public:
if (HashMod)
{
HashResetRequest(this, HashMod).Send();
- SearchAndReplace(thisquery, "$sha256pass", HashSumRequest(this, HashMod, user->password).Send());
+ SearchAndReplace(thisquery, std::string("$sha256pass"), std::string(HashSumRequest(this, HashMod, user->password).Send()));
}
/* Build the query */
diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp
index 76aceffc9..160e3cea3 100644
--- a/src/modules/m_alias.cpp
+++ b/src/modules/m_alias.cpp
@@ -155,17 +155,11 @@ class ModuleAlias : public Module
while (*(compare.c_str()) == ' ')
compare.erase(compare.begin());
- std::string safe(original_line);
-
- /* Escape out any $ symbols in the user provided text */
-
- SearchAndReplace(safe, "$", "\r");
-
while (i != upperbound)
{
if (i->second.UserCommand)
{
- if (DoAlias(user, NULL, &(i->second), compare, safe))
+ if (DoAlias(user, NULL, &(i->second), compare, original_line))
{
return 1;
}
@@ -237,9 +231,6 @@ class ModuleAlias : public Module
std::string safe(compare);
- /* Escape out any $ symbols in the user provided text (ugly, but better than crashy) */
- SearchAndReplace(safe, "$", "\r");
-
ServerInstance->Logs->Log("FANTASY", DEBUG, "fantasy: compare is %s and safe is %s", compare.c_str(), safe.c_str());
while (i != upperbound)
@@ -350,20 +341,17 @@ class ModuleAlias : public Module
}
/* Special variables */
- SearchAndReplace(newline, "$nick", user->nick);
- SearchAndReplace(newline, "$ident", user->ident);
- SearchAndReplace(newline, "$host", user->host);
- SearchAndReplace(newline, "$vhost", user->dhost);
+ SearchAndReplace(newline, std::string("$nick"), user->nick);
+ SearchAndReplace(newline, std::string("$ident"), user->ident);
+ SearchAndReplace(newline, std::string("$host"), user->host);
+ SearchAndReplace(newline, std::string("$vhost"), user->dhost);
if (c)
{
/* Channel specific variables */
- SearchAndReplace(newline, "$chan", c->name);
+ SearchAndReplace(newline, std::string("$chan"), c->name);
}
- /* Unescape any variable names in the user text before sending */
- SearchAndReplace(newline, "\r", "$");
-
irc::tokenstream ss(newline);
pars.clear();
std::string command, token;
diff --git a/src/modules/m_censor.cpp b/src/modules/m_censor.cpp
index fd5f446bd..a0b5ec1ef 100644
--- a/src/modules/m_censor.cpp
+++ b/src/modules/m_censor.cpp
@@ -71,49 +71,6 @@ class ModuleCensor : public Module
delete cc;
}
- virtual void OnRunTestSuite()
- {
- std::cout << "Test suite for m_censor:" << std::endl;
-
- irc::string text = "original text";
- irc::string pattern = "text";
- irc::string replace = "new";
- std::cout << (ReplaceLine(text, pattern, replace) == "original new" ? "\nSUCCESS!\n" : "\nFAILURE '" + text + "' \n");
- text = "original text here";
- pattern = "text";
- replace = "texts";
- std::cout << (ReplaceLine(text, pattern, replace) == "original texts here" ? "\nSUCCESS!\n" : "\nFAILURE: '" + text + "' \n");
- text = "original text";
- pattern = "original";
- replace = "new";
- std::cout << (ReplaceLine(text, pattern, replace) == "new text" ? "\nSUCCESS!\n" : "\nFAILURE '" + text + "' \n");
- std::cout << "end of test suite for m_censor" << std::endl;
- }
-
- /* This version of ReplaceLine won't loop forever if the replacement string contains the source pattern */
- virtual const irc::string& ReplaceLine(irc::string &text, irc::string pattern, irc::string replace)
- {
- irc::string replacement;
- if ((!pattern.empty()) && (!text.empty()))
- {
- for (std::string::size_type n = 0; n != text.length(); ++n)
- {
- if (text.length() >= pattern.length() && text.substr(n, pattern.length()) == pattern)
- {
- /* Found the pattern in the text, replace it, and advance */
- replacement.append(replace);
- n = n + pattern.length() - 1;
- }
- else
- {
- replacement += text[n];
- }
- }
- }
- text = replacement;
- return text;
- }
-
// format of a config entry is <badword text="shit" replace="poo">
virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
{
@@ -148,7 +105,7 @@ class ModuleCensor : public Module
return 1;
}
- this->ReplaceLine(text2,index->first,index->second);
+ SearchAndReplace(text2, index->first, index->second);
}
}
text = text2.c_str();