]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
m_cap Add Capability::GetCapValue(), list capabilities with values
authorAttila Molnar <attilamolnar@hush.com>
Sat, 5 Dec 2015 14:50:07 +0000 (15:50 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Sat, 5 Dec 2015 14:50:07 +0000 (15:50 +0100)
include/modules/cap.h
src/modules/m_cap.cpp

index 1ad2ff2f120b0fc629e47f0853b53c91ae5886bb..e242720b58dec7c6ed0823bd837217c6868e26b7 100644 (file)
@@ -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;
+               }
        };
 }
index 8ba28001e410ac0224bd95cd4269168625ef78f7..12de0de08a6a068df49da224a59b27c4b1a53312 100644 (file)
@@ -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))