summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/modules/cap.h10
-rw-r--r--src/modules/m_cap.cpp20
2 files changed, 26 insertions, 4 deletions
diff --git a/include/modules/cap.h b/include/modules/cap.h
index 1ad2ff2f1..e242720b5 100644
--- a/include/modules/cap.h
+++ b/include/modules/cap.h
@@ -25,6 +25,7 @@ namespace Cap
{
static const unsigned int MAX_CAPS = (sizeof(intptr_t) * 8) - 1;
static const intptr_t CAP_302_BIT = (intptr_t)1 << MAX_CAPS;
+ static const unsigned int MAX_VALUE_LENGTH = 100;
typedef intptr_t Ext;
typedef LocalIntExt ExtItem;
@@ -232,5 +233,14 @@ namespace Cap
{
return true;
}
+
+ /** Query the value of this capability for a user
+ * @param user User who will get the value of the capability
+ * @return Value to show to the user. If NULL, the capability has no value (default).
+ */
+ virtual const std::string* GetValue(LocalUser* user) const
+ {
+ return NULL;
+ }
};
}
diff --git a/src/modules/m_cap.cpp b/src/modules/m_cap.cpp
index 8ba28001e..12de0de08 100644
--- a/src/modules/m_cap.cpp
+++ b/src/modules/m_cap.cpp
@@ -149,7 +149,7 @@ class Cap::ManagerImpl : public Cap::Manager
return true;
}
- void HandleList(std::string& out, LocalUser* user, bool show_all, bool minus_prefix = false) const
+ void HandleList(std::string& out, LocalUser* user, bool show_all, bool show_values, bool minus_prefix = false) const
{
Ext show_caps = (show_all ? ~0 : capext.get(user));
@@ -164,13 +164,24 @@ class Cap::ManagerImpl : public Cap::Manager
if (minus_prefix)
out.push_back('-');
- out.append(cap->GetName()).push_back(' ');
+ out.append(cap->GetName());
+
+ if (show_values)
+ {
+ const std::string* capvalue = cap->GetValue(user);
+ if ((capvalue) && (!capvalue->empty()) && (capvalue->find(' ') == std::string::npos))
+ {
+ out.push_back('=');
+ out.append(*capvalue, 0, MAX_VALUE_LENGTH);
+ }
+ }
+ out.push_back(' ');
}
}
void HandleClear(LocalUser* user, std::string& result)
{
- HandleList(result, user, false, true);
+ HandleList(result, user, false, false, true);
capext.unset(user);
}
};
@@ -225,7 +236,8 @@ class CommandCap : public SplitCommand
manager.Set302Protocol(user);
std::string result = subcommand + " :";
- manager.HandleList(result, user, is_ls);
+ // Show values only if supports v3.2 and doing LS
+ manager.HandleList(result, user, is_ls, ((is_ls) && (manager.GetProtocol(user) != Cap::CAP_LEGACY)));
DisplayResult(user, result);
}
else if ((subcommand == "CLEAR") && (manager.GetProtocol(user) == Cap::CAP_LEGACY))