From 09d19cbbd3183d947732b0ed56910d41f6d39ff9 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 31 Jul 2016 18:39:19 -0500 Subject: [PATCH] capability: clean up CAP_REQUIRED and CAP_ORPHANED flags, use bool variables instead --- include/ircd/capability.h | 8 +++----- ircd/capability.cc | 14 +++++++------- modules/m_cap.cc | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/include/ircd/capability.h b/include/ircd/capability.h index 01c7ce691..c82431b2e 100644 --- a/include/ircd/capability.h +++ b/include/ircd/capability.h @@ -24,17 +24,15 @@ #include #include -#define CAP_ORPHANED 0x1 -#define CAP_REQUIRED 0x2 - struct CapabilityEntry { std::string cap; unsigned int value; - unsigned int flags; + bool require; + bool orphan; void *ownerdata; CapabilityEntry(std::string cap_, unsigned int value_, void *ownerdata_) - : cap(cap_), value(value_), flags(0), ownerdata(ownerdata_) { } + : cap(cap_), value(value_), require(false), orphan(false), ownerdata(ownerdata_) { } }; struct CapabilityIndex { diff --git a/ircd/capability.cc b/ircd/capability.cc index b2437df54..2423fe927 100644 --- a/ircd/capability.cc +++ b/ircd/capability.cc @@ -56,7 +56,7 @@ CapabilityIndex::get(std::string cap, void **ownerdata) std::shared_ptr entry; entry = find(cap); - if (entry != NULL && !(entry->flags & CAP_ORPHANED)) + if (entry != NULL && !entry->orphan) { if (ownerdata != NULL) *ownerdata = entry->ownerdata; @@ -76,7 +76,7 @@ CapabilityIndex::put(std::string cap, void *ownerdata) if ((entry = find(cap)) != NULL) { - entry->flags &= ~CAP_ORPHANED; + entry->orphan = false; return (1 << entry->value); } @@ -113,8 +113,8 @@ CapabilityIndex::orphan(std::string cap) entry = cap_dict[cap]; if (entry != NULL) { - entry->flags &= ~CAP_REQUIRED; - entry->flags |= CAP_ORPHANED; + entry->require = false; + entry->orphan = true; entry->ownerdata = NULL; } } @@ -126,7 +126,7 @@ CapabilityIndex::require(std::string cap) entry = cap_dict[cap]; if (entry != NULL) - entry->flags |= CAP_REQUIRED; + entry->require = true; } const char * @@ -157,7 +157,7 @@ CapabilityIndex::mask() for (auto it = cap_dict.begin(); it != cap_dict.end(); it++) { auto entry = it->second; - if (!(entry->flags & CAP_ORPHANED)) + if (!entry->orphan) mask |= (1 << entry->value); } @@ -172,7 +172,7 @@ CapabilityIndex::required() for (auto it = cap_dict.begin(); it != cap_dict.end(); it++) { auto entry = it->second; - if (!(entry->flags & CAP_ORPHANED) && (entry->flags & CAP_REQUIRED)) + if (!entry->orphan && entry->require) mask |= (1 << entry->value); } diff --git a/modules/m_cap.cc b/modules/m_cap.cc index a470eeab4..515d8a41e 100644 --- a/modules/m_cap.cc +++ b/modules/m_cap.cc @@ -68,7 +68,7 @@ clicap_visible(struct Client *client_p, const std::shared_ptr c struct ClientCapability *clicap; /* orphaned caps shouldn't be visible */ - if (cap->flags & CAP_ORPHANED) + if (cap->orphan) return 0; if (cap->ownerdata == NULL)