]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
m_cap Learn the supported capability negotiation protocol of a client from CAP LS
authorAttila Molnar <attilamolnar@hush.com>
Sat, 5 Dec 2015 14:45:20 +0000 (15:45 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Sat, 5 Dec 2015 14:45:20 +0000 (15:45 +0100)
Let modules implementing caps query this information

include/modules/cap.h
src/modules/m_cap.cpp

index a00089260295f2806b862432f32e8fe6d741215f..1ad2ff2f120b0fc629e47f0853b53c91ae5886bb 100644 (file)
 
 namespace Cap
 {
-       static const unsigned int MAX_CAPS = sizeof(intptr_t) * 8;
+       static const unsigned int MAX_CAPS = (sizeof(intptr_t) * 8) - 1;
+       static const intptr_t CAP_302_BIT = (intptr_t)1 << MAX_CAPS;
+
        typedef intptr_t Ext;
        typedef LocalIntExt ExtItem;
        class Capability;
 
+       enum Protocol
+       {
+               /** Supports capability negotiation protocol v3.1, or none
+                */
+               CAP_LEGACY,
+
+               /** Supports capability negotiation v3.2
+                */
+               CAP_302
+       };
+
        class Manager : public DataProvider
        {
         public:
@@ -190,6 +203,16 @@ namespace Cap
                 */
                bool IsRegistered() const { return (extitem != NULL); }
 
+               /** Get the CAP negotiation protocol version of a user.
+                * The cap must be registered for this to return anything other than CAP_LEGACY.
+                * @param user User whose negotiation protocol version to query
+                * @return One of the Capability::Protocol enum indicating the highest supported capability negotiation protocol version
+                */
+               Protocol GetProtocol(LocalUser* user) const
+               {
+                       return ((IsRegistered() && (extitem->get(user) & CAP_302_BIT)) ? CAP_302 : CAP_LEGACY);
+               }
+
                /** Called when a user requests to turn this capability on or off.
                 * @param user User requesting to change the state of the cap
                 * @param add True if requesting to turn the cap on, false if requesting to turn it off
index 2b4055e3cf0805dd11b1f68550a6789df75a2594..4411306ed54e40dd330a4fbffc3c942ac0b898ca 100644 (file)
@@ -115,6 +115,16 @@ class Cap::ManagerImpl : public Cap::Manager
                return NULL;
        }
 
+       Protocol GetProtocol(LocalUser* user) const
+       {
+               return ((capext.get(user) & CAP_302_BIT) ? CAP_302 : CAP_LEGACY);
+       }
+
+       void Set302Protocol(LocalUser* user)
+       {
+               capext.set(user, capext.get(user) | CAP_302_BIT);
+       }
+
        bool HandleReq(LocalUser* user, const std::string& reqlist)
        {
                Ext usercaps = capext.get(user);
@@ -211,6 +221,8 @@ class CommandCap : public SplitCommand
                else if ((subcommand == "LS") || (subcommand == "LIST"))
                {
                        const bool is_ls = (subcommand.length() == 2);
+                       if ((is_ls) && (parameters.size() > 1) && (parameters[1] == "302"))
+                               manager.Set302Protocol(user);
 
                        std::string result = subcommand + " :";
                        manager.HandleList(result, user, is_ls);