aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorGravatar Sadie Powell2026-04-30 22:29:38 +0100
committerGravatar Sadie Powell2026-04-30 23:20:14 +0100
commit9bb55626d51f217466bc08104d2f32eb0bf57c02 (patch)
tree44d8c00b97674cd4e35c5a1def208047bf02bcfa /include
parentMove CommandLine from ServerConfig to InspIRCd. (diff)
Switch ascii comparisons over to our own casemap functions.
Diffstat (limited to 'include')
-rw-r--r--include/casemap.h33
-rw-r--r--include/configreader.h2
-rw-r--r--include/modules/hash.h2
-rw-r--r--include/utility/string.h27
4 files changed, 31 insertions, 33 deletions
diff --git a/include/casemap.h b/include/casemap.h
index b31c7ed18..74c2b01c5 100644
--- a/include/casemap.h
+++ b/include/casemap.h
@@ -56,20 +56,20 @@ namespace insp
using casemapped_unordered_map = std::unordered_map<Key, Value, casemapped_hash_obj<Key>, casemapped_equals_obj<Key, Key>>;
/** Determines if \p str1 and \p str2 are equivalent when compared case insensitively using the
- * configured IRC casemapping.
+ * specified IRC casemapping.
* @param str1 The first string to compare.
* @param str2 The second string to compare.
* @return True if \p str1 and \p str2 are equivalent; otherwise, false.
*/
- CoreExport bool casemapped_equals(const std::string_view& str1, const std::string_view& str2);
+ CoreExport bool casemapped_equals(const std::string_view& str1, const std::string_view& str2, const casemap* map = nullptr);
/** Determines if \p str1 is lexographically less than \p str2 when compared insensitively using
- * the configured IRC casemapping.
+ * the specified IRC casemapping.
* @param str1 The first string to compare.
* @param str2 The second string to compare.
* @return True if \p str1 is ranked lower than \p str2; otherwise, false.
*/
- CoreExport bool casemapped_less(const std::string_view& str1, const std::string_view& str2);
+ CoreExport bool casemapped_less(const std::string_view& str1, const std::string_view& str2, const casemap* map = nullptr);
/** Determines the unique hash of \p str for use in a hash map when hashed insensitively using
* the configured IRC casemapping.
@@ -85,6 +85,31 @@ extern CoreExport const insp::casemap ascii_case_insensitive_map[256];
/** The currently configured casemapping. This defaults to \ref ascii_case_insensitive_map. */
extern CoreExport const insp::casemap* national_case_insensitive_map;
+namespace insp
+{
+ /** Determines if \p str1 and \p str2 are equivalent when compared case insensitively using
+ * ASCII casemapping.
+ * @param str1 The first string to compare.
+ * @param str2 The second string to compare.
+ * @return True if \p str1 and \p str2 are equivalent; otherwise, false.
+ */
+ inline bool ascii_equals(const std::string_view& str1, const std::string_view& str2)
+ {
+ return casemapped_equals(str1, str2, ascii_case_insensitive_map);
+ }
+
+ /** Determines if \p str1 is lexographically less than \p str2 when compared insensitively using
+ * ASCII casemapping.
+ * @param str1 The first string to compare.
+ * @param str2 The second string to compare.
+ * @return True if \p str1 is ranked lower than \p str2; otherwise, false.
+ */
+ inline bool ascii_less(const std::string_view& str1, const std::string_view& str2)
+ {
+ return casemapped_less(str1, str2, ascii_case_insensitive_map);
+ }
+}
+
/** IRC casemapping variant of \p std::equal_to<String>. */
template<typename String1, typename String2>
struct insp::casemapped_equals_obj
diff --git a/include/configreader.h b/include/configreader.h
index 22e6bd6b1..b7352fdca 100644
--- a/include/configreader.h
+++ b/include/configreader.h
@@ -149,7 +149,7 @@ public:
return def;
for (const auto& [enumkey, enumval] : enumvals)
- if (strcasecmp(val.c_str(), enumkey) == 0)
+ if (insp::ascii_equals(val, enumkey))
return enumval;
// Unfortunately we have to iterate this twice.
diff --git a/include/modules/hash.h b/include/modules/hash.h
index c25ef3fcd..ee9e7b5c7 100644
--- a/include/modules/hash.h
+++ b/include/modules/hash.h
@@ -275,7 +275,7 @@ inline bool Hash::CheckPassword(const std::string& password, const std::string&
// The hash algorithm wasn't provided by any modules. If its plain
// text then we can check it internally.
- if (algorithm.empty() || insp::equalsci(algorithm, "plaintext"))
+ if (algorithm.empty() || insp::ascii_equals(algorithm, "plaintext"))
return InspIRCd::TimingSafeCompare(password, value);
ServerInstance->Logs.Debug("HASH", "Unable to check password hashed with an unknown algorithm: {}", algorithm);
diff --git a/include/utility/string.h b/include/utility/string.h
index dc432b0f2..d70990cf0 100644
--- a/include/utility/string.h
+++ b/include/utility/string.h
@@ -43,31 +43,4 @@ namespace insp
joined.shrink_to_fit();
return joined;
}
-
- /** Get underlying C string of the string passed as parameter. Useful in template functions.
- * @param str A `const char*` string.
- */
- 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 A `std::string` string.
- */
- 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; otherwise, false.
- */
- template <typename S1, typename S2>
- inline bool equalsci(const S1& str1, const S2& str2)
- {
- return (!strcasecmp(tocstr(str1), tocstr(str2)));
- }
}