mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-09 10:39:02 -04:00
Allow changing the case of cloak values in cloak_user.
This commit is contained in:
parent
5638b7bb87
commit
32e60618e1
@ -661,6 +661,11 @@
|
||||
# To use the cloak_user module you must define a <cloak> tag. This #
|
||||
# tag can have the following fields. #
|
||||
# #
|
||||
# case - The case to transform the cloak value to. Can be set #
|
||||
# to "upper" to use upper case, "lower" to use lower #
|
||||
# case, or "preserve" to not change the case. Defaults #
|
||||
# to "preserve". #
|
||||
# #
|
||||
# class - If non-empty then a comma-delimited list of connect #
|
||||
# class names that a user has to be in to get the #
|
||||
# cloak from this tag. #
|
||||
@ -671,7 +676,7 @@
|
||||
# host character, or "truncate" to truncate the cloak #
|
||||
# at the invalid host character. Defaults to "strip". #
|
||||
# #
|
||||
# length - If using the "fingerprint" method them the number of #
|
||||
# length - If using the "fingerprint" method them the number of #
|
||||
# characters of the fingerprint hash to use. Defaults #
|
||||
# to the value of <limits:maxhost> minus the length of #
|
||||
# the prefix and suffix fields. #
|
||||
@ -689,18 +694,21 @@
|
||||
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
|
||||
#
|
||||
#<cloak method="account"
|
||||
# case="preserve"
|
||||
# class=""
|
||||
# invalidchar="strip"
|
||||
# prefix=""
|
||||
# suffix=".users.example.com">
|
||||
#
|
||||
#<cloak method="account-id"
|
||||
# case="preserve"
|
||||
# class=""
|
||||
# invalidchar="strip"
|
||||
# prefix=""
|
||||
# suffix=".users.example.com">
|
||||
#
|
||||
#<cloak method="fingerprint"
|
||||
# case="preserve"
|
||||
# class=""
|
||||
# invalidchar="strip"
|
||||
# length="16"
|
||||
@ -708,12 +716,14 @@
|
||||
# suffix=".fp">
|
||||
#
|
||||
#<cloak method="nickname"
|
||||
# case="preserve"
|
||||
# class=""
|
||||
# invalidchar="strip"
|
||||
# prefix="Users/"
|
||||
# suffix="">
|
||||
#
|
||||
#<cloak method="username"
|
||||
# case="preserve"
|
||||
# class=""
|
||||
# invalidchar="strip"
|
||||
# prefix="Users/"
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user