From f01f67f0ad0dbe4ef04f1bbc018b8f2e188bf7d0 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 4 Feb 2012 02:00:33 -0600 Subject: [PATCH] capability: add capability_require(). --- include/capability.h | 2 ++ src/capability.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/capability.h b/include/capability.h index e8e029f3..75192633 100644 --- a/include/capability.h +++ b/include/capability.h @@ -27,10 +27,12 @@ struct CapabilityEntry; extern unsigned int capability_get(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_require(struct CapabilityIndex *index, const char *cap); extern struct CapabilityIndex *capability_index_create(void); extern void capability_index_destroy(struct CapabilityIndex *); 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_get_required(struct CapabilityIndex *); #endif diff --git a/src/capability.c b/src/capability.c index de124f2e..44d55794 100644 --- a/src/capability.c +++ b/src/capability.c @@ -28,6 +28,7 @@ struct CapabilityIndex { }; #define CAP_ORPHANED 0x1 +#define CAP_REQUIRED 0x2 struct CapabilityEntry { unsigned int value; @@ -85,7 +86,22 @@ capability_orphan(struct CapabilityIndex *index, const char *cap) entry = irc_dictionary_retrieve(index->cap_dict, cap); if (entry != NULL) + { + entry->flags &= ~CAP_REQUIRED; 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 @@ -162,3 +178,21 @@ capability_index_mask(struct CapabilityIndex *index) 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; +}