summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2016-08-22 16:46:44 +0200
committerAttila Molnar <attilamolnar@hush.com>2016-08-22 16:46:44 +0200
commit90ea1b01b78a94486b8142808c06aacff543ca64 (patch)
tree50d3582ff28f56a3816307cc6e10fc4f775d2e2a
parent0562561425f133874685789269c8ab1aa053c95f (diff)
Add stdalgo::string::equalsci and use it instead of irc::string for case-insensitive comparison
-rw-r--r--include/stdalgo.h32
-rw-r--r--src/configreader.cpp4
-rw-r--r--src/modules/m_dccallow.cpp6
-rw-r--r--src/modules/m_filter.cpp12
-rw-r--r--src/modules/m_knock.cpp6
5 files changed, 44 insertions, 16 deletions
diff --git a/include/stdalgo.h b/include/stdalgo.h
index 3e00a4cdc..12ec76275 100644
--- a/include/stdalgo.h
+++ b/include/stdalgo.h
@@ -64,6 +64,38 @@ namespace stdalgo
}
}
+ namespace string
+ {
+ /** Get underlying C string of the string passed as parameter. Useful in template functions.
+ * @param str C string
+ * @return Same as input
+ */
+ inline const char* tocstr(const char* str)
+ {
+ return str;
+ }
+
+ /** Get underlying C string of the string passed as parameter. Useful in template functions.
+ * @param str std::string object
+ * @return str.c_str()
+ */
+ inline const char* tocstr(const std::string& str)
+ {
+ return str.c_str();
+ }
+
+ /** Check if two strings are equal case insensitively.
+ * @param str1 First string to compare.
+ * @param str2 Second string to compare.
+ * @return True if the strings are equal case-insensitively, false otherwise.
+ */
+ template <typename S1, typename S2>
+ inline bool equalsci(const S1& str1, const S2& str2)
+ {
+ return (!strcasecmp(tocstr(str1), tocstr(str2)));
+ }
+ }
+
/**
* Deleter that uses operator delete to delete the item
*/
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 8a432e82f..0299b326a 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -433,11 +433,11 @@ void ServerConfig::Fill()
throw CoreException(Network + " is not a valid network name. A network name must not contain spaces.");
std::string defbind = options->getString("defaultbind");
- if (assign(defbind) == "ipv4")
+ if (stdalgo::string::equalsci(defbind, "ipv4"))
{
WildcardIPv6 = false;
}
- else if (assign(defbind) == "ipv6")
+ else if (stdalgo::string::equalsci(defbind, "ipv6"))
{
WildcardIPv6 = true;
}
diff --git a/src/modules/m_dccallow.cpp b/src/modules/m_dccallow.cpp
index d8fbef69a..edf9d012f 100644
--- a/src/modules/m_dccallow.cpp
+++ b/src/modules/m_dccallow.cpp
@@ -328,12 +328,12 @@ class ModuleDCCAllow : public Module
if (s == std::string::npos)
return MOD_RES_PASSTHRU;
- irc::string type = assign(buf.substr(0, s));
+ const std::string type = buf.substr(0, s);
ConfigTag* conftag = ServerInstance->Config->ConfValue("dccallow");
bool blockchat = conftag->getBool("blockchat");
- if (type == "SEND")
+ if (stdalgo::string::equalsci(type, "SEND"))
{
size_t first;
@@ -386,7 +386,7 @@ class ModuleDCCAllow : public Module
u->WriteNotice("If you trust " + user->nick + " and were expecting this, you can type /DCCALLOW HELP for information on the DCCALLOW system.");
return MOD_RES_DENY;
}
- else if ((type == "CHAT") && (blockchat))
+ else if ((blockchat) && (stdalgo::string::equalsci(type, "CHAT")))
{
user->WriteNotice("The user " + u->nick + " is not accepting DCC CHAT requests from you.");
u->WriteNotice(user->nick + " (" + user->ident + "@" + user->dhost + ") attempted to initiate a DCC CHAT session, which was blocked.");
diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp
index a3e30ecb4..bd19a60ba 100644
--- a/src/modules/m_filter.cpp
+++ b/src/modules/m_filter.cpp
@@ -632,17 +632,15 @@ std::pair<bool, std::string> ModuleFilter::AddFilter(const std::string &freeform
bool ModuleFilter::StringToFilterAction(const std::string& str, FilterAction& fa)
{
- irc::string s(str.c_str());
-
- if (s == "gline")
+ if (stdalgo::string::equalsci(str, "gline"))
fa = FA_GLINE;
- else if (s == "block")
+ else if (stdalgo::string::equalsci(str, "block"))
fa = FA_BLOCK;
- else if (s == "silent")
+ else if (stdalgo::string::equalsci(str, "silent"))
fa = FA_SILENT;
- else if (s == "kill")
+ else if (stdalgo::string::equalsci(str, "kill"))
fa = FA_KILL;
- else if (s == "none")
+ else if (stdalgo::string::equalsci(str, "none"))
fa = FA_NONE;
else
return false;
diff --git a/src/modules/m_knock.cpp b/src/modules/m_knock.cpp
index a6352749f..cf623c4ab 100644
--- a/src/modules/m_knock.cpp
+++ b/src/modules/m_knock.cpp
@@ -98,14 +98,12 @@ class ModuleKnock : public Module
void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
{
std::string knocknotify = ServerInstance->Config->ConfValue("knock")->getString("notify");
- irc::string notify(knocknotify.c_str());
-
- if (notify == "numeric")
+ if (stdalgo::string::equalsci(knocknotify, "numeric"))
{
cmd.sendnotice = false;
cmd.sendnumeric = true;
}
- else if (notify == "both")
+ else if (stdalgo::string::equalsci(knocknotify, "both"))
{
cmd.sendnotice = true;
cmd.sendnumeric = true;