0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-28 19:58:53 +02:00

capability: clean up CAP_REQUIRED and CAP_ORPHANED flags, use bool variables instead

This commit is contained in:
William Pitcock 2016-07-31 18:39:19 -05:00
parent e7a768ca22
commit 09d19cbbd3
3 changed files with 11 additions and 13 deletions

View file

@ -24,17 +24,15 @@
#include <ircd/stdinc.h> #include <ircd/stdinc.h>
#include <ircd/util.h> #include <ircd/util.h>
#define CAP_ORPHANED 0x1
#define CAP_REQUIRED 0x2
struct CapabilityEntry { struct CapabilityEntry {
std::string cap; std::string cap;
unsigned int value; unsigned int value;
unsigned int flags; bool require;
bool orphan;
void *ownerdata; void *ownerdata;
CapabilityEntry(std::string cap_, unsigned int value_, 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 { struct CapabilityIndex {

View file

@ -56,7 +56,7 @@ CapabilityIndex::get(std::string cap, void **ownerdata)
std::shared_ptr<CapabilityEntry> entry; std::shared_ptr<CapabilityEntry> entry;
entry = find(cap); entry = find(cap);
if (entry != NULL && !(entry->flags & CAP_ORPHANED)) if (entry != NULL && !entry->orphan)
{ {
if (ownerdata != NULL) if (ownerdata != NULL)
*ownerdata = entry->ownerdata; *ownerdata = entry->ownerdata;
@ -76,7 +76,7 @@ CapabilityIndex::put(std::string cap, void *ownerdata)
if ((entry = find(cap)) != NULL) if ((entry = find(cap)) != NULL)
{ {
entry->flags &= ~CAP_ORPHANED; entry->orphan = false;
return (1 << entry->value); return (1 << entry->value);
} }
@ -113,8 +113,8 @@ CapabilityIndex::orphan(std::string cap)
entry = cap_dict[cap]; entry = cap_dict[cap];
if (entry != NULL) if (entry != NULL)
{ {
entry->flags &= ~CAP_REQUIRED; entry->require = false;
entry->flags |= CAP_ORPHANED; entry->orphan = true;
entry->ownerdata = NULL; entry->ownerdata = NULL;
} }
} }
@ -126,7 +126,7 @@ CapabilityIndex::require(std::string cap)
entry = cap_dict[cap]; entry = cap_dict[cap];
if (entry != NULL) if (entry != NULL)
entry->flags |= CAP_REQUIRED; entry->require = true;
} }
const char * const char *
@ -157,7 +157,7 @@ CapabilityIndex::mask()
for (auto it = cap_dict.begin(); it != cap_dict.end(); it++) for (auto it = cap_dict.begin(); it != cap_dict.end(); it++)
{ {
auto entry = it->second; auto entry = it->second;
if (!(entry->flags & CAP_ORPHANED)) if (!entry->orphan)
mask |= (1 << entry->value); mask |= (1 << entry->value);
} }
@ -172,7 +172,7 @@ CapabilityIndex::required()
for (auto it = cap_dict.begin(); it != cap_dict.end(); it++) for (auto it = cap_dict.begin(); it != cap_dict.end(); it++)
{ {
auto entry = it->second; auto entry = it->second;
if (!(entry->flags & CAP_ORPHANED) && (entry->flags & CAP_REQUIRED)) if (!entry->orphan && entry->require)
mask |= (1 << entry->value); mask |= (1 << entry->value);
} }

View file

@ -68,7 +68,7 @@ clicap_visible(struct Client *client_p, const std::shared_ptr<CapabilityEntry> c
struct ClientCapability *clicap; struct ClientCapability *clicap;
/* orphaned caps shouldn't be visible */ /* orphaned caps shouldn't be visible */
if (cap->flags & CAP_ORPHANED) if (cap->orphan)
return 0; return 0;
if (cap->ownerdata == NULL) if (cap->ownerdata == NULL)