aboutsummaryrefslogtreecommitdiff
path: root/src/modules/m_cloak_user.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2024-02-19 13:01:22 +0000
committerGravatar Sadie Powell2024-02-19 13:01:52 +0000
commit32e60618e1c8751dd417d6b95b6b993d72350b33 (patch)
tree70d9eb47cc02205461d8945d7d288a3a32bb878e /src/modules/m_cloak_user.cpp
parentFix a missing include in core_oper. (diff)
Allow changing the case of cloak values in cloak_user.
Diffstat (limited to 'src/modules/m_cloak_user.cpp')
-rw-r--r--src/modules/m_cloak_user.cpp40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/modules/m_cloak_user.cpp b/src/modules/m_cloak_user.cpp
index ace5eaad4..6b45eb8ef 100644
--- a/src/modules/m_cloak_user.cpp
+++ b/src/modules/m_cloak_user.cpp
@@ -26,7 +26,7 @@ class UserMethodBase
{
protected:
// The action to take when an invalid character is encountered.
- enum InvalidChar
+ enum class InvalidChar
: uint8_t
{
// Reject the value as a valid cloak,
@@ -39,6 +39,20 @@ protected:
TRUNCATE,
};
+ // The action to perform to the cloak value.
+ enum class TransformCase
+ : uint8_t
+ {
+ // Preserve the case of the cloak.
+ PRESERVE,
+
+ // Convert the cloak to upper case.
+ UPPER,
+
+ // Convert the cloak to lower case.
+ LOWER,
+ };
+
// The characters which are valid in a hostname.
const CharState& hostmap;
@@ -51,6 +65,9 @@ protected:
// The suffix for IP cloaks (e.g. .example.org).
const std::string suffix;
+ // The case to transform cloaks to.
+ TransformCase transformcase;
+
// Retrieves the middle segment of the cloak.
virtual std::string GetMiddle(LocalUser* user) = 0;
@@ -65,6 +82,11 @@ protected:
{ "strip", InvalidChar::STRIP },
{ "truncate", InvalidChar::TRUNCATE },
});
+ transformcase = tag->getEnum("case", TransformCase::PRESERVE, {
+ { "lower", TransformCase::LOWER },
+ { "preserve", TransformCase::PRESERVE },
+ { "upper", TransformCase::UPPER },
+ });
}
public:
@@ -79,8 +101,22 @@ public:
std::string safemiddle;
safemiddle.reserve(middle.length());
- for (const auto chr : middle)
+ for (auto chr : middle)
{
+ switch (transformcase)
+ {
+ case TransformCase::LOWER:
+ chr = tolower(chr);
+ break;
+
+ case TransformCase::PRESERVE:
+ break; // We don't need to do anything here.
+
+ case TransformCase::UPPER:
+ chr = toupper(chr);
+ break;
+ }
+
if (hostmap.test(static_cast<unsigned char>(chr)))
{
safemiddle.push_back(chr);