X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmodules%2Fcap.h;h=6f91f5aeefbb6575029c2109654eccb14c281f05;hb=302053cf8f5378da7f23e5d2f68a24c9d2325351;hp=a00089260295f2806b862432f32e8fe6d741215f;hpb=3e08629e8342cfbd17388aa14facf3a3a963233f;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules/cap.h b/include/modules/cap.h index a00089260..6f91f5aee 100644 --- a/include/modules/cap.h +++ b/include/modules/cap.h @@ -23,11 +23,45 @@ 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; + static const unsigned int MAX_VALUE_LENGTH = 100; + 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 EventListener : public Events::ModuleEventListener + { + public: + EventListener(Module* mod) + : ModuleEventListener(mod, "event/cap") + { + } + + /** Called whenever a new client capability becomes available or unavailable + * @param cap Capability being added or removed + * @param add If true, the capability is being added, otherwise its being removed + */ + virtual void OnCapAddDel(Capability* cap, bool add) = 0; + + /** Called whenever the value of a cap changes. + * @param cap Capability whose value changed + */ + virtual void OnCapValueChange(Capability* cap) { } + }; + class Manager : public DataProvider { public: @@ -53,6 +87,11 @@ namespace Cap * @return Capability object pointer if found, NULL otherwise */ virtual Capability* Find(const std::string& name) const = 0; + + /** Notify manager when a value of a cap changed + * @param cap Cap whose value changed + */ + virtual void NotifyValueChange(Capability* cap) = 0; }; /** Represents a client capability. @@ -106,6 +145,16 @@ namespace Cap friend class ManagerImpl; + protected: + /** Notify the manager that the value of the capability changed. + * Must be called if the value of the cap changes for any reason. + */ + void NotifyValueChange() + { + if (IsRegistered()) + manager->NotifyValueChange(this); + } + public: /** Constructor, initializes the capability. * Caps are active by default. @@ -190,6 +239,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 @@ -209,5 +268,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; + } }; }