capability: add capability_require().

This commit is contained in:
William Pitcock 2012-02-04 02:00:33 -06:00
parent 0582290f21
commit f01f67f0ad
2 changed files with 36 additions and 0 deletions

View file

@ -27,10 +27,12 @@ struct CapabilityEntry;
extern unsigned int capability_get(struct CapabilityIndex *index, const char *cap); extern unsigned int capability_get(struct CapabilityIndex *index, const char *cap);
extern unsigned int capability_put(struct CapabilityIndex *index, const char *cap); extern unsigned int capability_put(struct CapabilityIndex *index, const char *cap);
extern void capability_orphan(struct CapabilityIndex *index, const char *cap); extern void capability_orphan(struct CapabilityIndex *index, const char *cap);
extern void capability_require(struct CapabilityIndex *index, const char *cap);
extern struct CapabilityIndex *capability_index_create(void); extern struct CapabilityIndex *capability_index_create(void);
extern void capability_index_destroy(struct CapabilityIndex *); extern void capability_index_destroy(struct CapabilityIndex *);
extern const char *capability_index_list(struct CapabilityIndex *, unsigned int capability_mask); extern const char *capability_index_list(struct CapabilityIndex *, unsigned int capability_mask);
extern unsigned int capability_index_mask(struct CapabilityIndex *); extern unsigned int capability_index_mask(struct CapabilityIndex *);
extern unsigned int capability_index_get_required(struct CapabilityIndex *);
#endif #endif

View file

@ -28,6 +28,7 @@ struct CapabilityIndex {
}; };
#define CAP_ORPHANED 0x1 #define CAP_ORPHANED 0x1
#define CAP_REQUIRED 0x2
struct CapabilityEntry { struct CapabilityEntry {
unsigned int value; unsigned int value;
@ -85,7 +86,22 @@ capability_orphan(struct CapabilityIndex *index, const char *cap)
entry = irc_dictionary_retrieve(index->cap_dict, cap); entry = irc_dictionary_retrieve(index->cap_dict, cap);
if (entry != NULL) if (entry != NULL)
{
entry->flags &= ~CAP_REQUIRED;
entry->flags |= CAP_ORPHANED; entry->flags |= CAP_ORPHANED;
}
}
void
capability_require(struct CapabilityIndex *index, const char *cap)
{
struct CapabilityEntry *entry;
s_assert(index != NULL);
entry = irc_dictionary_retrieve(index->cap_dict, cap);
if (entry != NULL)
entry->flags |= CAP_REQUIRED;
} }
static void static void
@ -162,3 +178,21 @@ capability_index_mask(struct CapabilityIndex *index)
return mask; return mask;
} }
unsigned int
capability_index_get_required(struct CapabilityIndex *index)
{
struct DictionaryIter iter;
struct CapabilityEntry *entry;
unsigned int mask = 0;
s_assert(index != NULL);
DICTIONARY_FOREACH(entry, &iter, index->cap_dict)
{
if (!(entry->flags & CAP_ORPHANED) && (entry->flags & CAP_REQUIRED))
mask |= entry->value;
}
return mask;
}