From 9ac2eae1f0d663cb3b2fc05d6d37b07dcfd9025e Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sat, 5 Dec 2015 15:45:20 +0100 Subject: m_cap Learn the supported capability negotiation protocol of a client from CAP LS Let modules implementing caps query this information --- include/modules/cap.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/modules/cap.h b/include/modules/cap.h index a00089260..1ad2ff2f1 100644 --- a/include/modules/cap.h +++ b/include/modules/cap.h @@ -23,11 +23,24 @@ 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 -- cgit v1.2.3